diff options
| author | Martin <mhaug@live.de> | 2021-03-19 22:36:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-19 22:36:13 +0100 |
| commit | 6cb9fe9064a037224b6560b69b441b72e787fa94 (patch) | |
| tree | 9a5474758e37199c7a01c6d22383ede225deab4d /tests | |
| parent | 898dc38ec153709929d2513fb9d040dd2c1ce0fe (diff) | |
Text colors 🦩 (#18)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/library/font.png | bin | 8878 -> 10697 bytes | |||
| -rw-r--r-- | tests/typ/library/font.typ | 3 | ||||
| -rw-r--r-- | tests/typeset.rs | 22 |
3 files changed, 17 insertions, 8 deletions
diff --git a/tests/ref/library/font.png b/tests/ref/library/font.png Binary files differindex 199a15f2..1cfbc499 100644 --- a/tests/ref/library/font.png +++ b/tests/ref/library/font.png diff --git a/tests/typ/library/font.typ b/tests/typ/library/font.typ index ecea303f..3e818f19 100644 --- a/tests/typ/library/font.typ +++ b/tests/typ/library/font.typ @@ -31,6 +31,9 @@ Emoji: 🐪, 🌋, 🏞 ∫ 𝛼 + 3𝛽 d𝑡 ] +// Colors. +#font(color: #239DAD)[This is #font(color: #FA644B)[way more] colorful.] + --- // Test top and bottom edge. diff --git a/tests/typeset.rs b/tests/typeset.rs index 7e7efc67..65347033 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -426,7 +426,7 @@ fn draw_text(env: &Env, canvas: &mut Canvas, pos: Point, shaped: &Shaped) { .transform(&Transform::from_row(scale, 0.0, 0.0, -scale, x, y).unwrap()) .unwrap(); - let mut paint = Paint::default(); + let mut paint = paint_from_fill(shaped.color); paint.anti_alias = true; canvas.fill_path(&placed, &paint, FillRule::default()); @@ -438,13 +438,7 @@ fn draw_geometry(_: &Env, canvas: &mut Canvas, pos: Point, element: &Geometry) { let x = pos.x.to_pt() as f32; let y = pos.y.to_pt() as f32; - let mut paint = Paint::default(); - match &element.fill { - Fill::Color(c) => match c { - typst::color::Color::Rgba(c) => paint.set_color_rgba8(c.r, c.g, c.b, c.a), - }, - Fill::Image(_) => todo!(), - }; + let paint = paint_from_fill(element.fill); match &element.shape { Shape::Rect(s) => { @@ -454,6 +448,18 @@ fn draw_geometry(_: &Env, canvas: &mut Canvas, pos: Point, element: &Geometry) { }; } +fn paint_from_fill(fill: Fill) -> Paint<'static> { + let mut paint = Paint::default(); + match fill { + Fill::Color(c) => match c { + typst::color::Color::Rgba(c) => paint.set_color_rgba8(c.r, c.g, c.b, c.a), + }, + Fill::Image(_) => todo!(), + } + + paint +} + fn draw_image(env: &Env, canvas: &mut Canvas, pos: Point, element: &Image) { let img = &env.resources.loaded::<ImageResource>(element.res); |
