summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-04-05 22:32:09 +0200
committerLaurenz <laurmaedje@gmail.com>2021-04-05 22:32:09 +0200
commitde20a21a584a90da682a64e9a79cd18a95195b70 (patch)
tree2c7ade7d1078111ebbce889a0fca8cee388d6135 /tests
parenta86cf7bd8c58b0ec26f8f53eb90f0dc6c95a1070 (diff)
Reshaping with unsafe-to-break ⚡
Co-Authored-By: Martin <mhaug@live.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/full/coma.pngbin59071 -> 59057 bytes
-rw-r--r--tests/ref/library/paragraph.pngbin4336 -> 4337 bytes
-rw-r--r--tests/ref/text/basic.pngbin37172 -> 37176 bytes
-rw-r--r--tests/ref/text/bidi.pngbin14839 -> 15004 bytes
-rw-r--r--tests/typeset.rs37
5 files changed, 19 insertions, 18 deletions
diff --git a/tests/ref/full/coma.png b/tests/ref/full/coma.png
index 0949e271..2d067364 100644
--- a/tests/ref/full/coma.png
+++ b/tests/ref/full/coma.png
Binary files differ
diff --git a/tests/ref/library/paragraph.png b/tests/ref/library/paragraph.png
index 791d6c0c..41742f20 100644
--- a/tests/ref/library/paragraph.png
+++ b/tests/ref/library/paragraph.png
Binary files differ
diff --git a/tests/ref/text/basic.png b/tests/ref/text/basic.png
index aa5d9664..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
index 829fba0c..0b7a8c2b 100644
--- a/tests/ref/text/bidi.png
+++ b/tests/ref/text/bidi.png
Binary files differ
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 5c35d6b4..771c86da 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,20 @@ 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) {
+ for glyph in &shaped.glyphs {
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);
+ 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 +446,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;
}
}