summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
commit8a88f71cb11565c1a78bd57f02a8df17cb2bf7a0 (patch)
tree8802c1ff48e2be118e3872d25bd2f2c1f7a21b4a /tests
parentc77c5a0f0ae6560a03a85e847006c29de9c7ae62 (diff)
Transformations
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/layout/move.pngbin693 -> 0 bytes
-rw-r--r--tests/ref/layout/transform.pngbin0 -> 54558 bytes
-rw-r--r--tests/ref/text/links.pngbin9303 -> 10708 bytes
-rw-r--r--tests/typ/layout/move.typ11
-rw-r--r--tests/typ/layout/transform.typ49
-rw-r--r--tests/typ/text/links.typ6
-rw-r--r--tests/typeset.rs17
7 files changed, 71 insertions, 12 deletions
diff --git a/tests/ref/layout/move.png b/tests/ref/layout/move.png
deleted file mode 100644
index dc2e7ab3..00000000
--- a/tests/ref/layout/move.png
+++ /dev/null
Binary files differ
diff --git a/tests/ref/layout/transform.png b/tests/ref/layout/transform.png
new file mode 100644
index 00000000..5abdef97
--- /dev/null
+++ b/tests/ref/layout/transform.png
Binary files differ
diff --git a/tests/ref/text/links.png b/tests/ref/text/links.png
index c4aeec06..18154a06 100644
--- a/tests/ref/text/links.png
+++ b/tests/ref/text/links.png
Binary files differ
diff --git a/tests/typ/layout/move.typ b/tests/typ/layout/move.typ
deleted file mode 100644
index c1f97e15..00000000
--- a/tests/typ/layout/move.typ
+++ /dev/null
@@ -1,11 +0,0 @@
-#let size = 11pt
-#let tex = [{
- [T]
- h(-0.14 * size)
- move(y: 0.22 * size)[E]
- h(-0.12 * size)
- [X]
-}]
-
-#font("Latin Modern Math", size)
-Not #tex!
diff --git a/tests/typ/layout/transform.typ b/tests/typ/layout/transform.typ
new file mode 100644
index 00000000..5b1fa2a1
--- /dev/null
+++ b/tests/typ/layout/transform.typ
@@ -0,0 +1,49 @@
+// Test transformations.
+
+---
+// Test creating the TeX and XeTeX logos.
+#let size = 11pt
+#let tex = [{
+ [T]
+ h(-0.14 * size)
+ move(y: 0.22 * size)[E]
+ h(-0.12 * size)
+ [X]
+}]
+
+#let xetex = {
+ [X]
+ h(-0.14 * size)
+ scale(x: -100%, move(y: 0.26 * size)[E])
+ h(-0.14 * size)
+ [T]
+ h(-0.14 * size)
+ move(y: 0.26 * size)[E]
+ h(-0.12 * size)
+ [X]
+}
+
+#font("Latin Modern Math", size)
+Neither #tex, \
+nor #xetex!
+
+---
+// Test combination of scaling and rotation.
+#page(height: 80pt)
+#align(center + horizon,
+ rotate(20deg, scale(70%, image("../../res/tiger.jpg")))
+)
+
+---
+// Test setting rotation origin.
+#rotate(10deg, origin: top + left,
+ image("../../res/tiger.jpg", width: 50%)
+)
+
+---
+// Test setting scaling origin.
+#let r = rect(width: 100pt, height: 10pt, fill: forest)
+#page(height: 65pt)
+#scale(r, x: 50%, y: 200%, origin: left + top)
+#scale(r, x: 50%, origin: center)
+#scale(r, x: 50%, y: 200%, origin: right + bottom)
diff --git a/tests/typ/text/links.typ b/tests/typ/text/links.typ
index bea5f93e..e5f7affc 100644
--- a/tests/typ/text/links.typ
+++ b/tests/typ/text/links.typ
@@ -14,3 +14,9 @@ Contact #link("mailto:hi@typst.app") or call #link("tel:123") for more informati
// Styled with underline and color.
#let link(url, body) = link(url, font(fill: rgb("283663"), underline(body)))
You could also make the #link("https://html5zombo.com/")[link look way more typical.]
+
+---
+// Transformed link.
+#page(height: 60pt)
+#let link = link("https://typst.app/")[LINK]
+My cool #move(x: 0.7cm, y: 0.7cm, rotate(10deg, scale(200%, link)))
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 6f85125e..289cf766 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -13,7 +13,9 @@ use typst::diag::Error;
use typst::eval::{Smart, Value};
use typst::font::Face;
use typst::frame::{Element, Frame, Geometry, Group, Shape, Stroke, Text};
-use typst::geom::{self, Color, Length, Paint, PathElement, RgbaColor, Sides, Size};
+use typst::geom::{
+ self, Color, Length, Paint, PathElement, RgbaColor, Sides, Size, Transform,
+};
use typst::image::Image;
use typst::layout::layout;
#[cfg(feature = "layout-cache")]
@@ -465,6 +467,7 @@ fn draw_group(
ctx: &Context,
group: &Group,
) {
+ let ts = ts.pre_concat(convert_typst_transform(group.transform));
if group.clips {
let w = group.frame.size.w.to_f32();
let h = group.frame.size.h.to_f32();
@@ -628,6 +631,18 @@ fn draw_image(
canvas.fill_rect(rect, &paint, ts, Some(mask));
}
+fn convert_typst_transform(transform: Transform) -> sk::Transform {
+ let Transform { sx, ky, kx, sy, tx, ty } = transform;
+ sk::Transform::from_row(
+ sx.get() as _,
+ ky.get() as _,
+ kx.get() as _,
+ sy.get() as _,
+ tx.to_f32(),
+ ty.to_f32(),
+ )
+}
+
fn convert_typst_paint(paint: Paint) -> sk::Paint<'static> {
let Paint::Solid(Color::Rgba(c)) = paint;
let mut paint = sk::Paint::default();