mirror of
https://github.com/typst/typst
synced 2025-08-23 03:04:14 +08:00
Compare commits
3 Commits
e8ce894ee7
...
74b1b10986
Author | SHA1 | Date | |
---|---|---|---|
|
74b1b10986 | ||
|
584dd5fec6 | ||
|
b9f3a95e03 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2911,7 +2911,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "typst-dev-assets"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/typst/typst-dev-assets?rev=fddbf8b#fddbf8b99506bc370ac0edcd4959add603a7fc92"
|
||||
source = "git+https://github.com/typst/typst-dev-assets?rev=bfa947f#bfa947f3433d7d13a995168c40ae788a2ebfe648"
|
||||
|
||||
[[package]]
|
||||
name = "typst-docs"
|
||||
|
@ -33,7 +33,7 @@ typst-syntax = { path = "crates/typst-syntax", version = "0.13.1" }
|
||||
typst-timing = { path = "crates/typst-timing", version = "0.13.1" }
|
||||
typst-utils = { path = "crates/typst-utils", version = "0.13.1" }
|
||||
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "c1089b4" }
|
||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "fddbf8b" }
|
||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "bfa947f" }
|
||||
arrayvec = "0.7.4"
|
||||
az = "1.2"
|
||||
base64 = "0.22"
|
||||
|
@ -219,7 +219,7 @@ fn collect_items<'a>(
|
||||
// Add fallback text to expand the line height, if necessary.
|
||||
if !items.iter().any(|item| matches!(item, Item::Text(_))) {
|
||||
if let Some(fallback) = fallback {
|
||||
items.push(fallback);
|
||||
items.push(fallback, usize::MAX);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,10 +270,10 @@ fn collect_range<'a>(
|
||||
items: &mut Items<'a>,
|
||||
fallback: &mut Option<ItemEntry<'a>>,
|
||||
) {
|
||||
for (subrange, item) in p.slice(range.clone()) {
|
||||
for (idx, (subrange, item)) in p.slice(range.clone()).enumerate() {
|
||||
// All non-text items are just kept, they can't be split.
|
||||
let Item::Text(shaped) = item else {
|
||||
items.push(item);
|
||||
items.push(item, idx);
|
||||
continue;
|
||||
};
|
||||
|
||||
@ -293,10 +293,10 @@ fn collect_range<'a>(
|
||||
} else if split {
|
||||
// When the item is split in half, reshape it.
|
||||
let reshaped = shaped.reshape(engine, sliced);
|
||||
items.push(Item::Text(reshaped));
|
||||
items.push(Item::Text(reshaped), idx);
|
||||
} else {
|
||||
// When the item is fully contained, just keep it.
|
||||
items.push(item);
|
||||
items.push(item, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -499,16 +499,16 @@ pub fn commit(
|
||||
|
||||
// Build the frames and determine the height and baseline.
|
||||
let mut frames = vec![];
|
||||
for item in line.items.iter() {
|
||||
let mut push = |offset: &mut Abs, frame: Frame| {
|
||||
for &(idx, ref item) in line.items.indexed_iter() {
|
||||
let mut push = |offset: &mut Abs, frame: Frame, idx: usize| {
|
||||
let width = frame.width();
|
||||
top.set_max(frame.baseline());
|
||||
bottom.set_max(frame.size().y - frame.baseline());
|
||||
frames.push((*offset, frame));
|
||||
frames.push((*offset, frame, idx));
|
||||
*offset += width;
|
||||
};
|
||||
|
||||
match item {
|
||||
match &**item {
|
||||
Item::Absolute(v, _) => {
|
||||
offset += *v;
|
||||
}
|
||||
@ -520,7 +520,7 @@ pub fn commit(
|
||||
layout_box(elem, engine, loc.relayout(), styles, region)
|
||||
})?;
|
||||
apply_baseline_shift(&mut frame, *styles);
|
||||
push(&mut offset, frame);
|
||||
push(&mut offset, frame, idx);
|
||||
} else {
|
||||
offset += amount;
|
||||
}
|
||||
@ -532,15 +532,15 @@ pub fn commit(
|
||||
justification_ratio,
|
||||
extra_justification,
|
||||
);
|
||||
push(&mut offset, frame);
|
||||
push(&mut offset, frame, idx);
|
||||
}
|
||||
Item::Frame(frame) => {
|
||||
push(&mut offset, frame.clone());
|
||||
push(&mut offset, frame.clone(), idx);
|
||||
}
|
||||
Item::Tag(tag) => {
|
||||
let mut frame = Frame::soft(Size::zero());
|
||||
frame.push(Point::zero(), FrameItem::Tag((*tag).clone()));
|
||||
frames.push((offset, frame));
|
||||
frames.push((offset, frame, idx));
|
||||
}
|
||||
Item::Skip(_) => {}
|
||||
}
|
||||
@ -559,8 +559,13 @@ pub fn commit(
|
||||
add_par_line_marker(&mut output, marker, engine, locator, top);
|
||||
}
|
||||
|
||||
// Ensure that the final frame's items are in logical order rather than in
|
||||
// visual order. This is important because it affects the order of elements
|
||||
// during introspection and thus things like counters.
|
||||
frames.sort_unstable_by_key(|(_, _, idx)| *idx);
|
||||
|
||||
// Construct the line's frame.
|
||||
for (offset, frame) in frames {
|
||||
for (offset, frame, _) in frames {
|
||||
let x = offset + p.config.align.position(remaining);
|
||||
let y = top - frame.baseline();
|
||||
output.push_frame(Point::new(x, y), frame);
|
||||
@ -627,7 +632,7 @@ fn overhang(c: char) -> f64 {
|
||||
}
|
||||
|
||||
/// A collection of owned or borrowed inline items.
|
||||
pub struct Items<'a>(Vec<ItemEntry<'a>>);
|
||||
pub struct Items<'a>(Vec<(usize, ItemEntry<'a>)>);
|
||||
|
||||
impl<'a> Items<'a> {
|
||||
/// Create empty items.
|
||||
@ -636,33 +641,38 @@ impl<'a> Items<'a> {
|
||||
}
|
||||
|
||||
/// Push a new item.
|
||||
pub fn push(&mut self, entry: impl Into<ItemEntry<'a>>) {
|
||||
self.0.push(entry.into());
|
||||
pub fn push(&mut self, entry: impl Into<ItemEntry<'a>>, idx: usize) {
|
||||
self.0.push((idx, entry.into()));
|
||||
}
|
||||
|
||||
/// Iterate over the items.
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Item<'a>> {
|
||||
self.0.iter().map(|item| &**item)
|
||||
self.0.iter().map(|(_, item)| &**item)
|
||||
}
|
||||
|
||||
/// Iterate over the items with indices
|
||||
pub fn indexed_iter(&self) -> impl Iterator<Item = &(usize, ItemEntry<'a>)> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
/// Access the first item.
|
||||
pub fn first(&self) -> Option<&Item<'a>> {
|
||||
self.0.first().map(|item| &**item)
|
||||
self.0.first().map(|(_, item)| &**item)
|
||||
}
|
||||
|
||||
/// Access the last item.
|
||||
pub fn last(&self) -> Option<&Item<'a>> {
|
||||
self.0.last().map(|item| &**item)
|
||||
self.0.last().map(|(_, item)| &**item)
|
||||
}
|
||||
|
||||
/// Access the first item mutably, if it is text.
|
||||
pub fn first_text_mut(&mut self) -> Option<&mut ShapedText<'a>> {
|
||||
self.0.first_mut()?.text_mut()
|
||||
self.0.first_mut()?.1.text_mut()
|
||||
}
|
||||
|
||||
/// Access the last item mutably, if it is text.
|
||||
pub fn last_text_mut(&mut self) -> Option<&mut ShapedText<'a>> {
|
||||
self.0.last_mut()?.text_mut()
|
||||
self.0.last_mut()?.1.text_mut()
|
||||
}
|
||||
|
||||
/// Reorder the items starting at the given index to RTL.
|
||||
@ -673,12 +683,12 @@ impl<'a> Items<'a> {
|
||||
|
||||
impl<'a> FromIterator<ItemEntry<'a>> for Items<'a> {
|
||||
fn from_iter<I: IntoIterator<Item = ItemEntry<'a>>>(iter: I) -> Self {
|
||||
Self(iter.into_iter().collect())
|
||||
Self(iter.into_iter().enumerate().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for Items<'a> {
|
||||
type Target = Vec<ItemEntry<'a>>;
|
||||
type Target = Vec<(usize, ItemEntry<'a>)>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
|
@ -1285,24 +1285,17 @@ fn process_stops(stops: &[Spanned<GradientStop>]) -> SourceResult<Vec<(Color, Ra
|
||||
/// Sample the stops at a given position.
|
||||
fn sample_stops(stops: &[(Color, Ratio)], mixing_space: ColorSpace, t: f64) -> Color {
|
||||
let t = t.clamp(0.0, 1.0);
|
||||
let mut low = 0;
|
||||
let mut high = stops.len();
|
||||
let mut j = stops.partition_point(|(_, ratio)| ratio.get() < t);
|
||||
|
||||
while low < high {
|
||||
let mid = (low + high) / 2;
|
||||
if stops[mid].1.get() < t {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid;
|
||||
if j == 0 {
|
||||
while stops.get(j + 1).is_some_and(|(_, r)| r.is_zero()) {
|
||||
j += 1;
|
||||
}
|
||||
return stops[j].0;
|
||||
}
|
||||
|
||||
if low == 0 {
|
||||
low = 1;
|
||||
}
|
||||
|
||||
let (col_0, pos_0) = stops[low - 1];
|
||||
let (col_1, pos_1) = stops[low];
|
||||
let (col_0, pos_0) = stops[j - 1];
|
||||
let (col_1, pos_1) = stops[j];
|
||||
let t = (t - pos_0.get()) / (pos_1.get() - pos_0.get());
|
||||
|
||||
Color::mix_iter(
|
||||
|
BIN
tests/ref/issue-5775-cite-order-rtl.png
Normal file
BIN
tests/ref/issue-5775-cite-order-rtl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
tests/ref/issue-6162-coincident-gradient-stops-export-png.png
Normal file
BIN
tests/ref/issue-6162-coincident-gradient-stops-export-png.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 522 B |
@ -34,7 +34,7 @@ To the right! Where the sunlight peeks behind the mountain.
|
||||
#align(start)[Start]
|
||||
#align(end)[Ende]
|
||||
|
||||
#set text(lang: "ar")
|
||||
#set text(lang: "ar", font: "Noto Sans Arabic")
|
||||
#align(start)[يبدأ]
|
||||
#align(end)[نهاية]
|
||||
|
||||
|
@ -45,6 +45,7 @@ Lריווח #h(1cm) R
|
||||
|
||||
--- bidi-whitespace-reset ---
|
||||
// Test whether L1 whitespace resetting destroys stuff.
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
الغالب #h(70pt) ن#" "ة
|
||||
|
||||
--- bidi-explicit-dir ---
|
||||
@ -87,7 +88,7 @@ Lריווח #h(1cm) R
|
||||
columns: (1fr, 1fr),
|
||||
lines(6),
|
||||
[
|
||||
#text(lang: "ar")[مجرد نص مؤقت لأغراض العرض التوضيحي. ]
|
||||
#text(lang: "ar", font: ("Libertinus Serif", "Noto Sans Arabic"))[مجرد نص مؤقت لأغراض العرض التوضيحي. ]
|
||||
#text(lang: "ar")[سلام]
|
||||
],
|
||||
)
|
||||
|
@ -29,6 +29,7 @@ ABCअपार्टमेंट
|
||||
\ ט
|
||||
|
||||
--- shaping-font-fallback ---
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
// Font fallback for emoji.
|
||||
A😀B
|
||||
|
||||
|
@ -80,7 +80,7 @@ I'm in#text(tracking: 0.15em + 1.5pt)[ spaace]!
|
||||
|
||||
--- text-tracking-arabic ---
|
||||
// Test tracking in arabic text (makes no sense whatsoever)
|
||||
#set text(tracking: 0.3em)
|
||||
#set text(tracking: 0.3em, font: "Noto Sans Arabic")
|
||||
النص
|
||||
|
||||
--- text-spacing ---
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
--- repeat-dots-rtl ---
|
||||
// Test dots with RTL.
|
||||
#set text(lang: "ar")
|
||||
#set text(lang: "ar", font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
مقدمة #box(width: 1fr, repeat[.]) 15
|
||||
|
||||
--- repeat-empty ---
|
||||
@ -35,7 +35,7 @@ A#box(width: 1fr, repeat(rect(width: 6em, height: 0.7em)))B
|
||||
#set align(center)
|
||||
A#box(width: 1fr, repeat(rect(width: 6em, height: 0.7em)))B
|
||||
|
||||
#set text(dir: rtl)
|
||||
#set text(dir: rtl, font: "Noto Sans Arabic")
|
||||
ريجين#box(width: 1fr, repeat(rect(width: 4em, height: 0.7em)))سون
|
||||
|
||||
--- repeat-unrestricted ---
|
||||
|
@ -147,3 +147,16 @@ B #cite(<netwok>) #cite(<arrgh>).
|
||||
// Error: 7-17 expected label, found string
|
||||
// Hint: 7-17 use `label("%@&#*!\\")` to create a label
|
||||
#cite("%@&#*!\\")
|
||||
|
||||
--- issue-5775-cite-order-rtl ---
|
||||
// Test citation order in RTL text.
|
||||
#set page(width: 300pt)
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
@netwok
|
||||
aaa
|
||||
این است
|
||||
@tolkien54
|
||||
و این یکی هست
|
||||
@arrgh
|
||||
|
||||
#bibliography("/assets/bib/works.bib")
|
||||
|
@ -231,7 +231,7 @@ Welcome \ here. Does this work well?
|
||||
|
||||
--- par-hanging-indent-rtl ---
|
||||
#set par(hanging-indent: 2em)
|
||||
#set text(dir: rtl)
|
||||
#set text(dir: rtl, font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
لآن وقد أظلم الليل وبدأت النجوم
|
||||
تنضخ وجه الطبيعة التي أعْيَتْ من طول ما انبعثت في النهار
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
--- quote-dir-author-pos ---
|
||||
// Text direction affects author positioning
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
And I quote: #quote(attribution: [René Descartes])[cogito, ergo sum].
|
||||
|
||||
#set text(lang: "ar")
|
||||
@ -9,6 +10,7 @@ And I quote: #quote(attribution: [René Descartes])[cogito, ergo sum].
|
||||
|
||||
--- quote-dir-align ---
|
||||
// Text direction affects block alignment
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
#set quote(block: true)
|
||||
#quote(attribution: [René Descartes])[cogito, ergo sum]
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
--- numbers ---
|
||||
// Test numbers in text mode.
|
||||
#set text(font: ("Libertinus Serif", "Noto Sans Arabic"))
|
||||
12 \
|
||||
12.0 \
|
||||
3.14 \
|
||||
|
@ -666,3 +666,29 @@ $ A = mat(
|
||||
#let _ = gradient.linear(..my-gradient.stops())
|
||||
#let my-gradient2 = gradient.linear(red, blue).repeat(5, mirror: true)
|
||||
#let _ = gradient.linear(..my-gradient2.stops())
|
||||
|
||||
--- issue-6162-coincident-gradient-stops-export-png ---
|
||||
// Ensure that multiple gradient stops with the same position
|
||||
// don't cause a panic.
|
||||
#rect(
|
||||
fill: gradient.linear(
|
||||
(red, 0%),
|
||||
(green, 0%),
|
||||
(blue, 100%),
|
||||
)
|
||||
)
|
||||
#rect(
|
||||
fill: gradient.linear(
|
||||
(red, 0%),
|
||||
(green, 100%),
|
||||
(blue, 100%),
|
||||
)
|
||||
)
|
||||
#rect(
|
||||
fill: gradient.linear(
|
||||
(white, 0%),
|
||||
(red, 50%),
|
||||
(green, 50%),
|
||||
(blue, 100%),
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user