summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2021-04-07 13:50:21 +0200
committerGitHub <noreply@github.com>2021-04-07 13:50:21 +0200
commitdf58a4d89b67783b1ffc5c3b7282302d59db8c70 (patch)
tree2bdc3a7ad1704ccee7c14972df1fa3cb9c77097a /tests
parent318eb9021edc493f5181247dbb7963de34126688 (diff)
parent3d2ee54848db80a8ede7e00fd5a53bc059138122 (diff)
Merge pull request #19 from typst/shape-runs 🔀
Text work
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/comment.pngbin706 -> 708 bytes
-rw-r--r--tests/ref/control/for.pngbin2700 -> 2685 bytes
-rw-r--r--tests/ref/control/invalid.pngbin3642 -> 3647 bytes
-rw-r--r--tests/ref/control/while.pngbin880 -> 879 bytes
-rw-r--r--tests/ref/expand.pngbin1372 -> 1372 bytes
-rw-r--r--tests/ref/expr/block.pngbin1428 -> 1407 bytes
-rw-r--r--tests/ref/expr/call-invalid.pngbin2866 -> 2897 bytes
-rw-r--r--tests/ref/expr/call.pngbin6000 -> 5972 bytes
-rw-r--r--tests/ref/expr/ops.pngbin770 -> 782 bytes
-rw-r--r--tests/ref/full/coma.pngbin59402 -> 59057 bytes
-rw-r--r--tests/ref/library/circle.pngbin13642 -> 13518 bytes
-rw-r--r--tests/ref/library/ellipse.pngbin7588 -> 7608 bytes
-rw-r--r--tests/ref/library/font.pngbin21305 -> 21435 bytes
-rw-r--r--tests/ref/library/lang.pngbin1897 -> 1898 bytes
-rw-r--r--tests/ref/library/pad.pngbin1224 -> 1226 bytes
-rw-r--r--tests/ref/library/page.pngbin7438 -> 7432 bytes
-rw-r--r--tests/ref/library/pagebreak.pngbin1360 -> 1368 bytes
-rw-r--r--tests/ref/library/paragraph.pngbin4162 -> 4337 bytes
-rw-r--r--tests/ref/library/rect.pngbin2760 -> 2750 bytes
-rw-r--r--tests/ref/library/spacing.pngbin3251 -> 3247 bytes
-rw-r--r--tests/ref/library/square.pngbin7184 -> 7163 bytes
-rw-r--r--tests/ref/markup/basic.pngbin3827 -> 3788 bytes
-rw-r--r--tests/ref/markup/emph.pngbin3372 -> 3390 bytes
-rw-r--r--tests/ref/markup/escape.pngbin6517 -> 9849 bytes
-rw-r--r--tests/ref/markup/heading.pngbin5187 -> 5162 bytes
-rw-r--r--tests/ref/markup/raw.pngbin8261 -> 8225 bytes
-rw-r--r--tests/ref/markup/strong.pngbin3385 -> 3365 bytes
-rw-r--r--tests/ref/repr.pngbin10833 -> 10838 bytes
-rw-r--r--tests/ref/spacing.pngbin5212 -> 5208 bytes
-rw-r--r--tests/ref/text/align.pngbin0 -> 4008 bytes
-rw-r--r--tests/ref/text/basic.pngbin37041 -> 37176 bytes
-rw-r--r--tests/ref/text/bidi.pngbin0 -> 15004 bytes
-rw-r--r--tests/ref/text/chinese.pngbin0 -> 16068 bytes
-rw-r--r--tests/ref/text/linebreaks.pngbin0 -> 10111 bytes
-rw-r--r--tests/ref/text/shaping.pngbin12273 -> 13298 bytes
-rw-r--r--tests/ref/text/whitespace.pngbin0 -> 2084 bytes
-rw-r--r--tests/typ/library/paragraph.typ1
-rw-r--r--tests/typ/library/rect.typ2
-rw-r--r--tests/typ/markup/basic.typ2
-rw-r--r--tests/typ/text/align.typ28
-rw-r--r--tests/typ/text/basic.typ3
-rw-r--r--tests/typ/text/bidi.typ49
-rw-r--r--tests/typ/text/chinese.typ9
-rw-r--r--tests/typ/text/linebreaks.typ28
-rw-r--r--tests/typ/text/shaping.typ11
-rw-r--r--tests/typ/text/whitespace.typ17
-rw-r--r--tests/typeset.rs42
47 files changed, 166 insertions, 26 deletions
diff --git a/tests/ref/comment.png b/tests/ref/comment.png
index 6d5723ef..6654e125 100644
--- a/tests/ref/comment.png
+++ b/tests/ref/comment.png
Binary files differ
diff --git a/tests/ref/control/for.png b/tests/ref/control/for.png
index bf6b535c..f9abf074 100644
--- a/tests/ref/control/for.png
+++ b/tests/ref/control/for.png
Binary files differ
diff --git a/tests/ref/control/invalid.png b/tests/ref/control/invalid.png
index e9c64b8a..bfd3ec2c 100644
--- a/tests/ref/control/invalid.png
+++ b/tests/ref/control/invalid.png
Binary files differ
diff --git a/tests/ref/control/while.png b/tests/ref/control/while.png
index 2ea1bcb0..c0045350 100644
--- a/tests/ref/control/while.png
+++ b/tests/ref/control/while.png
Binary files differ
diff --git a/tests/ref/expand.png b/tests/ref/expand.png
index f18e929b..e07e15e8 100644
--- a/tests/ref/expand.png
+++ b/tests/ref/expand.png
Binary files differ
diff --git a/tests/ref/expr/block.png b/tests/ref/expr/block.png
index d8ea84fb..6b0dd540 100644
--- a/tests/ref/expr/block.png
+++ b/tests/ref/expr/block.png
Binary files differ
diff --git a/tests/ref/expr/call-invalid.png b/tests/ref/expr/call-invalid.png
index 8e0c5eb6..f2f90f09 100644
--- a/tests/ref/expr/call-invalid.png
+++ b/tests/ref/expr/call-invalid.png
Binary files differ
diff --git a/tests/ref/expr/call.png b/tests/ref/expr/call.png
index f05fb835..ae05f617 100644
--- a/tests/ref/expr/call.png
+++ b/tests/ref/expr/call.png
Binary files differ
diff --git a/tests/ref/expr/ops.png b/tests/ref/expr/ops.png
index e6f2edab..b566b5b7 100644
--- a/tests/ref/expr/ops.png
+++ b/tests/ref/expr/ops.png
Binary files differ
diff --git a/tests/ref/full/coma.png b/tests/ref/full/coma.png
index d869d57e..2d067364 100644
--- a/tests/ref/full/coma.png
+++ b/tests/ref/full/coma.png
Binary files differ
diff --git a/tests/ref/library/circle.png b/tests/ref/library/circle.png
index f1128642..8364d42b 100644
--- a/tests/ref/library/circle.png
+++ b/tests/ref/library/circle.png
Binary files differ
diff --git a/tests/ref/library/ellipse.png b/tests/ref/library/ellipse.png
index c78c9272..2e52b515 100644
--- a/tests/ref/library/ellipse.png
+++ b/tests/ref/library/ellipse.png
Binary files differ
diff --git a/tests/ref/library/font.png b/tests/ref/library/font.png
index 07c65726..44183b3a 100644
--- a/tests/ref/library/font.png
+++ b/tests/ref/library/font.png
Binary files differ
diff --git a/tests/ref/library/lang.png b/tests/ref/library/lang.png
index 98a63b6e..ecb8820a 100644
--- a/tests/ref/library/lang.png
+++ b/tests/ref/library/lang.png
Binary files differ
diff --git a/tests/ref/library/pad.png b/tests/ref/library/pad.png
index 3bc0ddd0..0bf0adde 100644
--- a/tests/ref/library/pad.png
+++ b/tests/ref/library/pad.png
Binary files differ
diff --git a/tests/ref/library/page.png b/tests/ref/library/page.png
index 9d2a6b95..dfe6f8cd 100644
--- a/tests/ref/library/page.png
+++ b/tests/ref/library/page.png
Binary files differ
diff --git a/tests/ref/library/pagebreak.png b/tests/ref/library/pagebreak.png
index ab990c69..b671605c 100644
--- a/tests/ref/library/pagebreak.png
+++ b/tests/ref/library/pagebreak.png
Binary files differ
diff --git a/tests/ref/library/paragraph.png b/tests/ref/library/paragraph.png
index 37898017..41742f20 100644
--- a/tests/ref/library/paragraph.png
+++ b/tests/ref/library/paragraph.png
Binary files differ
diff --git a/tests/ref/library/rect.png b/tests/ref/library/rect.png
index 56f1003f..5f6df7b6 100644
--- a/tests/ref/library/rect.png
+++ b/tests/ref/library/rect.png
Binary files differ
diff --git a/tests/ref/library/spacing.png b/tests/ref/library/spacing.png
index fa403a6d..2205809a 100644
--- a/tests/ref/library/spacing.png
+++ b/tests/ref/library/spacing.png
Binary files differ
diff --git a/tests/ref/library/square.png b/tests/ref/library/square.png
index 26469d20..def2e664 100644
--- a/tests/ref/library/square.png
+++ b/tests/ref/library/square.png
Binary files differ
diff --git a/tests/ref/markup/basic.png b/tests/ref/markup/basic.png
index a43fcbcb..ecac0e8d 100644
--- a/tests/ref/markup/basic.png
+++ b/tests/ref/markup/basic.png
Binary files differ
diff --git a/tests/ref/markup/emph.png b/tests/ref/markup/emph.png
index 9b6bda5c..a43110e9 100644
--- a/tests/ref/markup/emph.png
+++ b/tests/ref/markup/emph.png
Binary files differ
diff --git a/tests/ref/markup/escape.png b/tests/ref/markup/escape.png
index 9c6f1f59..686471c6 100644
--- a/tests/ref/markup/escape.png
+++ b/tests/ref/markup/escape.png
Binary files differ
diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png
index a7de742d..46b5b637 100644
--- a/tests/ref/markup/heading.png
+++ b/tests/ref/markup/heading.png
Binary files differ
diff --git a/tests/ref/markup/raw.png b/tests/ref/markup/raw.png
index a20ca999..cd2a4549 100644
--- a/tests/ref/markup/raw.png
+++ b/tests/ref/markup/raw.png
Binary files differ
diff --git a/tests/ref/markup/strong.png b/tests/ref/markup/strong.png
index 4bbf6ac0..ce96d6a2 100644
--- a/tests/ref/markup/strong.png
+++ b/tests/ref/markup/strong.png
Binary files differ
diff --git a/tests/ref/repr.png b/tests/ref/repr.png
index 71f415ef..b93677f1 100644
--- a/tests/ref/repr.png
+++ b/tests/ref/repr.png
Binary files differ
diff --git a/tests/ref/spacing.png b/tests/ref/spacing.png
index 454b154f..82f7e8d2 100644
--- a/tests/ref/spacing.png
+++ b/tests/ref/spacing.png
Binary files differ
diff --git a/tests/ref/text/align.png b/tests/ref/text/align.png
new file mode 100644
index 00000000..9415214b
--- /dev/null
+++ b/tests/ref/text/align.png
Binary files differ
diff --git a/tests/ref/text/basic.png b/tests/ref/text/basic.png
index a06c8763..ef265cbf 100644
--- a/tests/ref/text/basic.png
+++ b/tests/ref/text/basic.png
Binary files differ
diff --git a/tests/ref/text/bidi.png b/tests/ref/text/bidi.png
new file mode 100644
index 00000000..0b7a8c2b
--- /dev/null
+++ b/tests/ref/text/bidi.png
Binary files differ
diff --git a/tests/ref/text/chinese.png b/tests/ref/text/chinese.png
new file mode 100644
index 00000000..fa905df6
--- /dev/null
+++ b/tests/ref/text/chinese.png
Binary files differ
diff --git a/tests/ref/text/linebreaks.png b/tests/ref/text/linebreaks.png
new file mode 100644
index 00000000..c5a826bd
--- /dev/null
+++ b/tests/ref/text/linebreaks.png
Binary files differ
diff --git a/tests/ref/text/shaping.png b/tests/ref/text/shaping.png
index 9af49f16..09f154ab 100644
--- a/tests/ref/text/shaping.png
+++ b/tests/ref/text/shaping.png
Binary files differ
diff --git a/tests/ref/text/whitespace.png b/tests/ref/text/whitespace.png
new file mode 100644
index 00000000..35a21320
--- /dev/null
+++ b/tests/ref/text/whitespace.png
Binary files differ
diff --git a/tests/typ/library/paragraph.typ b/tests/typ/library/paragraph.typ
index 74fb8189..a26aed84 100644
--- a/tests/typ/library/paragraph.typ
+++ b/tests/typ/library/paragraph.typ
@@ -3,6 +3,7 @@
---
// Test configuring paragraph properties.
+// FIXME: Word spacing doesn't work due to new shaping process.
#par(spacing: 10pt, leading: 25%, word-spacing: 1pt)
But, soft! what light through yonder window breaks? It is the east, and Juliet
diff --git a/tests/typ/library/rect.typ b/tests/typ/library/rect.typ
index 40713411..9acb0975 100644
--- a/tests/typ/library/rect.typ
+++ b/tests/typ/library/rect.typ
@@ -19,7 +19,7 @@
// Not visible, but creates a gap between the boxes above and below
// due to line spacing.
-#rect(width: 2in, fill: #ff0000)
+#rect(width: 1in, fill: #ff0000)
// These are in a row!
#rect(width: 0.5in, height: 10pt, fill: #D6CD67)
diff --git a/tests/typ/markup/basic.typ b/tests/typ/markup/basic.typ
index 3e83b911..bfe3d2cb 100644
--- a/tests/typ/markup/basic.typ
+++ b/tests/typ/markup/basic.typ
@@ -3,7 +3,7 @@
---
#let linebreak() = [
// Inside the old line break definition is still active.
- #circle(radius: 2pt, fill: #000) \
+ #square(length: 3pt, fill: #000) \
]
A \ B \ C
diff --git a/tests/typ/text/align.typ b/tests/typ/text/align.typ
new file mode 100644
index 00000000..27c650a4
--- /dev/null
+++ b/tests/typ/text/align.typ
@@ -0,0 +1,28 @@
+// Test text alignment.
+
+---
+// Test that alignment depends on the paragraph's full width.
+#rect[
+ Hello World \
+ #align(right)[World]
+]
+
+---
+// Test that a line with multiple alignments respects the paragraph's full
+// width.
+#rect[
+ Hello #align(center)[World] \
+ Hello from the World
+]
+
+---
+// Test that `start` alignment after `end` alignment doesn't do anything until
+// the next line break ...
+L #align(right)[R] R
+
+// ... but make sure it resets to left after the line break.
+L #align(right)[R] \ L
+
+---
+// FIXME: There should be a line break opportunity on alignment change.
+LLLLLLLLLLLLL#align(center)[CCCC]
diff --git a/tests/typ/text/basic.typ b/tests/typ/text/basic.typ
index b424cee8..d5f0de05 100644
--- a/tests/typ/text/basic.typ
+++ b/tests/typ/text/basic.typ
@@ -1,6 +1,7 @@
// Test simple text.
-#page(width: 250pt)
+---
+#page(width: 250pt, height: 110pt)
But, soft! what light through yonder window breaks? It is the east, and Juliet
is the sun. Arise, fair sun, and kill the envious moon, Who is already sick and
diff --git a/tests/typ/text/bidi.typ b/tests/typ/text/bidi.typ
new file mode 100644
index 00000000..44f0cc15
--- /dev/null
+++ b/tests/typ/text/bidi.typ
@@ -0,0 +1,49 @@
+// Test bidirectional text.
+
+---
+// Test reordering with different top-level paragraph directions.
+#let text = [Text טֶקסט]
+#font("EB Garamond", "Noto Serif Hebrew")
+#lang("de") {text}
+#lang("he") {text}
+
+---
+// Test that consecutiv, embedded LTR runs stay LTR.
+// Here, we have two runs: "A" and italic "B".
+#let text = [أنت A_B_مطرC]
+#font("EB Garamond", "Noto Sans Arabic")
+#lang("de") {text}
+#lang("ar") {text}
+
+---
+// Test that consecutive, embedded RTL runs stay RTL.
+// Here, we have three runs: "גֶ", bold "שֶׁ", and "ם".
+#let text = [Aגֶ*שֶׁ*םB]
+#font("EB Garamond", "Noto Serif Hebrew")
+#lang("de") {text}
+#lang("he") {text}
+
+---
+// Test embedding up to level 4 with isolates.
+#font("EB Garamond", "Noto Serif Hebrew", "Twitter Color Emoji")
+#lang(dir: rtl)
+א\u{2066}A\u{2067}Bב\u{2069}?
+
+---
+// Test hard line break (leads to two paragraphs in unicode-bidi).
+#font("Noto Sans Arabic", "EB Garamond")
+#lang("ar")
+Life المطر هو الحياة \
+الحياة تمطر is rain.
+
+---
+// Test spacing.
+#font("EB Garamond", "Noto Serif Hebrew")
+L #h(1cm) ריווחR \
+Lריווח #h(1cm) R
+
+---
+// Test inline object.
+#font("Noto Serif Hebrew", "EB Garamond")
+#lang("he")
+קרנפיםRh#image("res/rhino.png", height: 11pt)inoחיים
diff --git a/tests/typ/text/chinese.typ b/tests/typ/text/chinese.typ
new file mode 100644
index 00000000..0800a220
--- /dev/null
+++ b/tests/typ/text/chinese.typ
@@ -0,0 +1,9 @@
+// Test chinese text from Wikipedia.
+
+---
+#font("Noto Serif CJK SC")
+
+是美国广播公司电视剧《迷失》第3季的第22和23集,也是全剧的第71集和72集
+由执行制作人戴蒙·林道夫和卡尔顿·库斯编剧,导演则是另一名执行制作人杰克·本德
+节目于2007年5月23日在美国和加拿大首播,共计吸引了1400万美国观众收看
+本集加上插播广告一共也持续有两个小时
diff --git a/tests/typ/text/linebreaks.typ b/tests/typ/text/linebreaks.typ
new file mode 100644
index 00000000..4d57834a
--- /dev/null
+++ b/tests/typ/text/linebreaks.typ
@@ -0,0 +1,28 @@
+// Test line breaking special cases.
+
+---
+// Test overlong word that is not directly after a hard break.
+This is a spaceexceedinglylongishy.
+
+---
+// Test two overlong words in a row.
+Supercalifragilisticexpialidocious Expialigoricmetrioxidation.
+
+---
+// Test that there are no unwanted line break opportunities on run change.
+This is partly emph_as_ized.
+
+---
+Hard \ break.
+
+---
+// Test hard break directly after normal break.
+Hard break directly after \ normal break.
+
+---
+// Test consecutive breaks.
+Two consecutive \ \ breaks and three \ \ \ more.
+
+---
+// Test trailing newline.
+Trailing break \
diff --git a/tests/typ/text/shaping.typ b/tests/typ/text/shaping.typ
index 567a208d..ba543e71 100644
--- a/tests/typ/text/shaping.typ
+++ b/tests/typ/text/shaping.typ
@@ -8,7 +8,7 @@ Le fira
// This should just shape nicely.
#font("Noto Sans Arabic")
-منش إلا بسم الله
+دع النص يمطر عليك
// This should form a three-member family.
#font("Twitter Color Emoji")
@@ -26,7 +26,7 @@ Le fira
A😀B
// Font fallback for entire text.
-منش إلا بسم الله
+دع النص يمطر عليك
// Font fallback in right-to-left text.
ب🐈😀سم
@@ -36,3 +36,10 @@ Aب😀🏞سمB
// Tofus are rendered with the first font.
A🐈中文B
+
+---
+// Test reshaping.
+
+#font("Noto Serif Hebrew")
+#lang("he")
+ס \ טֶ
diff --git a/tests/typ/text/whitespace.typ b/tests/typ/text/whitespace.typ
new file mode 100644
index 00000000..3d7dd2e2
--- /dev/null
+++ b/tests/typ/text/whitespace.typ
@@ -0,0 +1,17 @@
+// Test whitespace handling.
+
+---
+// Test that a run consisting only of whitespace isn't trimmed.
+A#font("PT Sans")[ ]B
+
+---
+// Test font change after space.
+Left #font("PT Sans")[Right].
+
+---
+// Test that space at start of line is not trimmed.
+A{"\n"} B
+
+---
+// Test that trailing space does not force a line break.
+LLLLLLLLLLLLLL R _L_
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 5c35d6b4..6aef2746 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -20,7 +20,7 @@ use typst::env::{Env, FsIndexExt, ImageResource, ResourceLoader};
use typst::eval::{EvalContext, FuncArgs, FuncValue, Scope, Value};
use typst::exec::State;
use typst::geom::{self, Length, Point, Sides, Size};
-use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape, ShapedText};
+use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape, Text};
use typst::library;
use typst::parse::{LineMap, Scanner};
use typst::pdf;
@@ -413,19 +413,19 @@ fn draw(env: &Env, frames: &[Frame], pixel_per_pt: f32) -> Pixmap {
canvas
}
-fn draw_text(canvas: &mut Pixmap, env: &Env, ts: Transform, shaped: &ShapedText) {
- let ttf = env.fonts.face(shaped.face).ttf();
+fn draw_text(canvas: &mut Pixmap, env: &Env, ts: Transform, shaped: &Text) {
+ let ttf = env.fonts.face(shaped.face_id).ttf();
+ let mut x = 0.0;
- for (&glyph, &offset) in shaped.glyphs.iter().zip(&shaped.offsets) {
- let units_per_em = ttf.units_per_em().unwrap_or(1000);
-
- let x = offset.to_pt() as f32;
- let s = (shaped.size / units_per_em as f64).to_pt() as f32;
- let ts = ts.pre_translate(x, 0.0);
+ for glyph in &shaped.glyphs {
+ let units_per_em = ttf.units_per_em();
+ let s = shaped.size.to_pt() as f32 / units_per_em as f32;
+ let dx = glyph.x_offset.to_pt() as f32;
+ let ts = ts.pre_translate(x + dx, 0.0);
// Try drawing SVG if present.
if let Some(tree) = ttf
- .glyph_svg_image(glyph)
+ .glyph_svg_image(glyph.id)
.and_then(|data| std::str::from_utf8(data).ok())
.map(|svg| {
let viewbox = format!("viewBox=\"0 0 {0} {0}\" xmlns", units_per_em);
@@ -445,19 +445,19 @@ fn draw_text(canvas: &mut Pixmap, env: &Env, ts: Transform, shaped: &ShapedText)
}
}
}
-
- continue;
+ } else {
+ // Otherwise, draw normal outline.
+ let mut builder = WrappedPathBuilder(tiny_skia::PathBuilder::new());
+ if ttf.outline_glyph(glyph.id, &mut builder).is_some() {
+ let path = builder.0.finish().unwrap();
+ let ts = ts.pre_scale(s, -s);
+ let mut paint = convert_typst_fill(shaped.color);
+ paint.anti_alias = true;
+ canvas.fill_path(&path, &paint, FillRule::default(), ts, None);
+ }
}
- // Otherwise, draw normal outline.
- let mut builder = WrappedPathBuilder(tiny_skia::PathBuilder::new());
- if ttf.outline_glyph(glyph, &mut builder).is_some() {
- let path = builder.0.finish().unwrap();
- let ts = ts.pre_scale(s, -s);
- let mut paint = convert_typst_fill(shaped.color);
- paint.anti_alias = true;
- canvas.fill_path(&path, &paint, FillRule::default(), ts, None);
- }
+ x += glyph.x_advance.to_pt() as f32;
}
}