From fd0b89a1d8e4f811fcf3517d321a327a0cf72edf Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 8 Jul 2021 22:33:44 +0200 Subject: [PATCH] Rename Fill to Paint --- src/exec/state.rs | 14 ++-- src/export/pdf.rs | 37 +++++----- src/layout/background.rs | 15 ++--- src/layout/frame.rs | 23 ++++--- src/layout/shaping.rs | 6 +- src/library/elements.rs | 11 ++- src/library/mod.rs | 2 +- src/library/text.rs | 6 +- src/syntax/expr.rs | 4 +- tests/typ/layout/grid-1.typ | 2 +- tests/typ/layout/stack.typ | 4 +- tests/typeset.rs | 131 ++++++++++++++++++------------------ 12 files changed, 125 insertions(+), 130 deletions(-) diff --git a/src/exec/state.rs b/src/exec/state.rs index 24e4b9f37..cbd656228 100644 --- a/src/exec/state.rs +++ b/src/exec/state.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use crate::color::{Color, RgbaColor}; use crate::font::{FontStretch, FontStyle, FontVariant, FontWeight, VerticalFontMetric}; use crate::geom::*; -use crate::layout::Fill; +use crate::layout::Paint; use crate::paper::{Paper, PaperClass, PAPER_A4}; /// The execution state. @@ -117,8 +117,8 @@ pub struct FontState { pub top_edge: VerticalFontMetric, /// The bottom end of the text bounding box. pub bottom_edge: VerticalFontMetric, - /// The glyph fill color / texture. - pub fill: Fill, + /// Glyph color. + pub fill: Paint, /// Whether the strong toggle is active or inactive. This determines /// whether the next `*` adds or removes font weight. pub strong: bool, @@ -152,7 +152,7 @@ impl Default for FontState { size: Length::pt(11.0), top_edge: VerticalFontMetric::CapHeight, bottom_edge: VerticalFontMetric::Baseline, - fill: Fill::Color(Color::Rgba(RgbaColor::BLACK)), + fill: Paint::Color(Color::Rgba(RgbaColor::BLACK)), strong: false, emph: false, strikethrough: None, @@ -165,8 +165,10 @@ impl Default for FontState { /// Describes a line that could be positioned over, under or on top of text. #[derive(Debug, Copy, Clone, PartialEq, Hash)] pub struct LineState { - /// Stroke color of the line. Defaults to the text color if `None`. - pub stroke: Option, + /// Stroke color of the line. + /// + /// Defaults to the text color if `None`. + pub stroke: Option, /// Thickness of the line's stroke. Calling functions should attempt to /// read this value from the appropriate font tables if this is `None`. pub thickness: Option, diff --git a/src/export/pdf.rs b/src/export/pdf.rs index 0439702fb..7e55a6015 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -18,7 +18,7 @@ use crate::color::Color; use crate::font::{Em, FaceId}; use crate::geom::{self, Length, Size}; use crate::image::{Image, ImageId}; -use crate::layout::{Element, Fill, Frame, Shape}; +use crate::layout::{Element, Frame, Geometry, Paint}; /// Export a collection of frames into a PDF document. /// @@ -142,7 +142,7 @@ impl<'a> PdfExporter<'a> { // do that, we need to remember the active face. let mut face = None; let mut size = Length::zero(); - let mut fill: Option = None; + let mut fill: Option = None; for (pos, element) in page.elements() { let x = pos.x.to_pt() as f32; @@ -172,30 +172,32 @@ impl<'a> PdfExporter<'a> { text.show(Str(&shaped.encode_glyphs_be())); } - Element::Geometry(ref shape, fill) => { + Element::Geometry(ref geometry, paint) => { content.save_state(); - write_fill(&mut content, fill); - match *shape { - Shape::Rect(Size { width, height }) => { + match *geometry { + Geometry::Rect(Size { width, height }) => { let w = width.to_pt() as f32; let h = height.to_pt() as f32; if w > 0.0 && h > 0.0 { + write_fill(&mut content, paint); content.rect(x, y - h, w, h, false, true); } } - Shape::Ellipse(size) => { + Geometry::Ellipse(size) => { let path = geom::Path::ellipse(size); + write_fill(&mut content, paint); write_path(&mut content, x, y, &path, false, true); } - Shape::Line(target, stroke) => { - write_stroke(&mut content, fill, stroke.to_pt() as f32); + Geometry::Line(target, thickness) => { + write_stroke(&mut content, paint, thickness.to_pt() as f32); content.path(true, false).move_to(x, y).line_to( x + target.x.to_pt() as f32, y - target.y.to_pt() as f32, ); } - Shape::Path(ref path) => { + Geometry::Path(ref path) => { + write_fill(&mut content, paint); write_path(&mut content, x, y, path, false, true) } } @@ -369,18 +371,15 @@ impl<'a> PdfExporter<'a> { } /// Write a fill change into a content stream. -fn write_fill(content: &mut Content, fill: Fill) { - match fill { - Fill::Color(Color::Rgba(c)) => { - content.fill_rgb(c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0); - } - } +fn write_fill(content: &mut Content, fill: Paint) { + let Paint::Color(Color::Rgba(c)) = fill; + content.fill_rgb(c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0); } /// Write a stroke change into a content stream. -fn write_stroke(content: &mut Content, fill: Fill, thickness: f32) { - match fill { - Fill::Color(Color::Rgba(c)) => { +fn write_stroke(content: &mut Content, stroke: Paint, thickness: f32) { + match stroke { + Paint::Color(Color::Rgba(c)) => { content.stroke_rgb( c.r as f32 / 255.0, c.g as f32 / 255.0, diff --git a/src/layout/background.rs b/src/layout/background.rs index 013a887a8..0e93c06fa 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -6,8 +6,8 @@ use super::*; pub struct BackgroundNode { /// The kind of shape to use as a background. pub shape: BackgroundShape, - /// The background fill. - pub fill: Fill, + /// Background color / texture. + pub fill: Paint, /// The child node to be filled. pub child: AnyNode, } @@ -29,19 +29,16 @@ impl Layout for BackgroundNode { for frame in &mut frames { let mut new = Frame::new(frame.size, frame.baseline); - let (point, shape) = match self.shape { - BackgroundShape::Rect => (Point::zero(), Shape::Rect(frame.size)), + let (point, geometry) = match self.shape { + BackgroundShape::Rect => (Point::zero(), Geometry::Rect(frame.size)), BackgroundShape::Ellipse => { - (frame.size.to_point() / 2.0, Shape::Ellipse(frame.size)) + (frame.size.to_point() / 2.0, Geometry::Ellipse(frame.size)) } }; - let element = Element::Geometry(shape, self.fill); - new.push(point, element); - let prev = std::mem::take(&mut frame.item); + new.push(point, Element::Geometry(geometry, self.fill)); new.push_frame(Point::zero(), prev); - *Rc::make_mut(&mut frame.item) = new; } frames diff --git a/src/layout/frame.rs b/src/layout/frame.rs index b6cf46455..65a558576 100644 --- a/src/layout/frame.rs +++ b/src/layout/frame.rs @@ -110,8 +110,9 @@ enum Child { pub enum Element { /// Shaped text. Text(Text), - /// A filled geometric shape. - Geometry(Shape, Fill), + /// A geometric shape and the paint which with it should be filled or + /// stroked. + Geometry(Geometry, Paint), /// A raster image. Image(ImageId, Size), } @@ -123,8 +124,8 @@ pub struct Text { pub face_id: FaceId, /// The font size. pub size: Length, - /// The glyph's fill color. - pub fill: Fill, + /// Glyph color. + pub fill: Paint, /// The glyphs. pub glyphs: Vec, } @@ -155,20 +156,20 @@ impl Text { /// A geometric shape. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub enum Shape { - /// A rectangle with its origin in the topleft corner. +pub enum Geometry { + /// A filled rectangle with its origin in the topleft corner. Rect(Size), - /// An ellipse with its origin in the center. + /// A filled ellipse with its origin in the center. Ellipse(Size), - /// A line to a `Point` (relative to its position) with a stroke width. + /// A stroked line to a point (relative to its position) with a thickness. Line(Point, Length), - /// A bezier path. + /// A filled bezier path. Path(Path), } -/// How text and shapes are filled. +/// How a fill or stroke should be painted. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] -pub enum Fill { +pub enum Paint { /// A solid color. Color(Color), } diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index c37300f7e..9b8774ccd 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -8,7 +8,7 @@ use super::{Element, Frame, Glyph, LayoutContext, Text}; use crate::exec::{FontState, LineState}; use crate::font::{Face, FaceId, FontStyle, LineMetrics}; use crate::geom::{Dir, Length, Point, Size}; -use crate::layout::Shape; +use crate::layout::Geometry; use crate::util::SliceExt; /// The result of shaping text. @@ -412,9 +412,7 @@ fn decorate( let pos = Point::new(pos.x - extent, pos.y + offset); let target = Point::new(width + 2.0 * extent, Length::zero()); - let shape = Shape::Line(target, thickness); - let element = Element::Geometry(shape, stroke); - + let element = Element::Geometry(Geometry::Line(target, thickness), stroke); frame.push(pos, element); }; diff --git a/src/library/elements.rs b/src/library/elements.rs index 5271788fa..c57504fb4 100644 --- a/src/library/elements.rs +++ b/src/library/elements.rs @@ -3,9 +3,8 @@ use std::f64::consts::SQRT_2; use decorum::N64; use super::*; -use crate::color::Color; use crate::layout::{ - BackgroundNode, BackgroundShape, Fill, FixedNode, ImageNode, PadNode, + BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode, Paint, }; /// `image`: An image. @@ -64,10 +63,10 @@ fn rect_impl( let fixed = FixedNode { width, height, child: stack.into() }; - if let Some(color) = fill { + if let Some(fill) = fill { ctx.push_into_par(BackgroundNode { shape: BackgroundShape::Rect, - fill: Fill::Color(color), + fill: Paint::Color(fill), child: fixed.into(), }); } else { @@ -120,10 +119,10 @@ fn ellipse_impl( .into(), }; - if let Some(color) = fill { + if let Some(fill) = fill { ctx.push_into_par(BackgroundNode { shape: BackgroundShape::Ellipse, - fill: Fill::Color(color), + fill: Paint::Color(fill), child: fixed.into(), }); } else { diff --git a/src/library/mod.rs b/src/library/mod.rs index 92ee9faaa..abc9ff5fd 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -16,7 +16,7 @@ pub use utility::*; use std::fmt::{self, Display, Formatter}; use std::rc::Rc; -use crate::color::RgbaColor; +use crate::color::{Color, RgbaColor}; use crate::eval::{EvalContext, FuncArgs, Scope, TemplateValue, Value}; use crate::exec::{Exec, FontFamily}; use crate::font::{FontStyle, FontWeight, VerticalFontMetric}; diff --git a/src/library/text.rs b/src/library/text.rs index 9c2863bc9..e1fff9f30 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -1,6 +1,6 @@ use crate::exec::{FontState, LineState}; use crate::font::{FontStretch, FontStyle, FontWeight}; -use crate::layout::Fill; +use crate::layout::Paint; use super::*; @@ -57,7 +57,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { } if let Some(fill) = fill { - font.fill = Fill::Color(fill); + font.fill = Paint::Color(fill); } if let Some(FamilyDef(serif)) = &serif { @@ -244,7 +244,7 @@ fn line_impl( // Suppress any existing strikethrough if strength is explicitly zero. let state = thickness.map_or(true, |s| !s.is_zero()).then(|| { Rc::new(LineState { - stroke: stroke.map(Fill::Color), + stroke: stroke.map(Paint::Color), thickness, offset, extent, diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index c4462ff88..368fe41f9 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -33,7 +33,7 @@ pub enum Expr { Ident(Ident), /// An array expression: `(1, "hi", 12cm)`. Array(ArrayExpr), - /// A dictionary expression: `(color: #f79143, pattern: dashed)`. + /// A dictionary expression: `(thickness: 3pt, pattern: dashed)`. Dict(DictExpr), /// A template expression: `[*Hi* there!]`. Template(TemplateExpr), @@ -123,7 +123,7 @@ pub struct ArrayExpr { pub items: Vec, } -/// A dictionary expression: `(color: #f79143, pattern: dashed)`. +/// A dictionary expression: `(thickness: 3pt, pattern: dashed)`. #[derive(Debug, Clone, PartialEq)] pub struct DictExpr { /// The source code location. diff --git a/tests/typ/layout/grid-1.typ b/tests/typ/layout/grid-1.typ index ad55b53fb..fb8a76786 100644 --- a/tests/typ/layout/grid-1.typ +++ b/tests/typ/layout/grid-1.typ @@ -1,7 +1,7 @@ // Test grid layouts. --- -#let rect(width, color) = rect(width: width, height: 2cm, fill: color) +#let rect(width, fill) = rect(width: width, height: 2cm, fill: fill) #page!(width: 100pt, height: 140pt) #grid( diff --git a/tests/typ/layout/stack.typ b/tests/typ/layout/stack.typ index fd5201df1..7f434bd21 100644 --- a/tests/typ/layout/stack.typ +++ b/tests/typ/layout/stack.typ @@ -1,7 +1,7 @@ // Test stack layouts. --- -#let rect(width, color) = rect(width: width, height: 1cm, fill: color) +#let rect(width, fill) = rect(width: width, height: 1cm, fill: fill) #stack( rect(2cm, rgb("2a631a")), rect(3cm, forest), @@ -11,7 +11,7 @@ --- // Test overflowing stack. -#let rect(width, color) = rect(width: 1cm, height: 0.4cm, fill: color) +#let rect(width, fill) = rect(width: 1cm, height: 0.4cm, fill: fill) #box(height: 0.5cm, stack( rect(3cm, forest), rect(1cm, conifer), diff --git a/tests/typeset.rs b/tests/typeset.rs index d14d6a773..6cb335f37 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -6,21 +6,18 @@ use std::path::Path; use std::rc::Rc; use image::{GenericImageView, Rgba}; -use tiny_skia::{ - Color, ColorU8, FillRule, FilterQuality, Paint, Pattern, Pixmap, Rect, SpreadMode, - Stroke, Transform, -}; +use tiny_skia as sk; use ttf_parser::{GlyphId, OutlineBuilder}; use walkdir::WalkDir; use typst::cache::Cache; -use typst::color; +use typst::color::Color; use typst::diag::{Diag, DiagSet, Level}; use typst::eval::{eval, EvalContext, FuncArgs, FuncValue, Scope, Value}; use typst::exec::{exec, State}; -use typst::geom::{self, Length, Point, Sides, Size}; +use typst::geom::{self, Length, PathElement, Point, Sides, Size}; use typst::image::ImageId; -use typst::layout::{layout, Element, Fill, Frame, Shape, Text}; +use typst::layout::{layout, Element, Frame, Geometry, Paint, Text}; use typst::loading::FsLoader; use typst::parse::{parse, LineMap, Scanner}; use typst::syntax::{Location, Pos}; @@ -182,7 +179,7 @@ fn test( fs::create_dir_all(&png_path.parent().unwrap()).unwrap(); canvas.save_png(png_path).unwrap(); - if let Ok(ref_pixmap) = Pixmap::load_png(ref_path) { + if let Ok(ref_pixmap) = sk::Pixmap::load_png(ref_path) { if canvas != ref_pixmap { println!(" Does not match reference image. ❌"); ok = false; @@ -399,7 +396,7 @@ fn print_diag(diag: &Diag, map: &LineMap, lines: u32) { println!("{}: {}-{}: {}", diag.level, start, end, diag.message); } -fn draw(cache: &Cache, frames: &[Rc], dpi: f32) -> Pixmap { +fn draw(cache: &Cache, frames: &[Rc], dpi: f32) -> sk::Pixmap { let pad = Length::pt(5.0); let height = pad + frames.iter().map(|l| l.size.height + pad).sum::(); @@ -414,16 +411,16 @@ fn draw(cache: &Cache, frames: &[Rc], dpi: f32) -> Pixmap { ); } - let mut canvas = Pixmap::new(pixel_width, pixel_height).unwrap(); - let ts = Transform::from_scale(dpi, dpi); - canvas.fill(Color::BLACK); + let mut canvas = sk::Pixmap::new(pixel_width, pixel_height).unwrap(); + let ts = sk::Transform::from_scale(dpi, dpi); + canvas.fill(sk::Color::BLACK); let mut origin = Point::splat(pad); for frame in frames { - let mut paint = Paint::default(); - paint.set_color(Color::WHITE); + let mut paint = sk::Paint::default(); + paint.set_color(sk::Color::WHITE); canvas.fill_rect( - Rect::from_xywh( + sk::Rect::from_xywh( origin.x.to_pt() as f32, origin.y.to_pt() as f32, frame.size.width.to_pt() as f32, @@ -442,13 +439,13 @@ fn draw(cache: &Cache, frames: &[Rc], dpi: f32) -> Pixmap { let ts = ts.pre_translate(x, y); match *element { Element::Text(ref text) => { - draw_text(&mut canvas, cache, ts, text); + draw_text(&mut canvas, ts, cache, text); } - Element::Geometry(ref shape, fill) => { - draw_geometry(&mut canvas, ts, shape, fill); + Element::Geometry(ref geometry, paint) => { + draw_geometry(&mut canvas, ts, geometry, paint); } Element::Image(id, size) => { - draw_image(&mut canvas, cache, ts, id, size); + draw_image(&mut canvas, ts, cache, id, size); } } } @@ -459,7 +456,7 @@ fn draw(cache: &Cache, frames: &[Rc], dpi: f32) -> Pixmap { canvas } -fn draw_text(canvas: &mut Pixmap, cache: &Cache, ts: Transform, text: &Text) { +fn draw_text(canvas: &mut sk::Pixmap, ts: sk::Transform, cache: &Cache, text: &Text) { let ttf = cache.font.get(text.face_id).ttf(); let mut x = 0.0; @@ -493,13 +490,13 @@ fn draw_text(canvas: &mut Pixmap, cache: &Cache, ts: Transform, text: &Text) { } } else { // Otherwise, draw normal outline. - let mut builder = WrappedPathBuilder(tiny_skia::PathBuilder::new()); + let mut builder = WrappedPathBuilder(sk::PathBuilder::new()); if ttf.outline_glyph(GlyphId(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(text.fill); + let mut paint = convert_typst_paint(text.fill); paint.anti_alias = true; - canvas.fill_path(&path, &paint, FillRule::default(), ts, None); + canvas.fill_path(&path, &paint, sk::FillRule::default(), ts, None); } } @@ -507,33 +504,38 @@ fn draw_text(canvas: &mut Pixmap, cache: &Cache, ts: Transform, text: &Text) { } } -fn draw_geometry(canvas: &mut Pixmap, ts: Transform, shape: &Shape, fill: Fill) { - let paint = convert_typst_fill(fill); - let rule = FillRule::default(); +fn draw_geometry( + canvas: &mut sk::Pixmap, + ts: sk::Transform, + geometry: &Geometry, + paint: Paint, +) { + let paint = convert_typst_paint(paint); + let rule = sk::FillRule::default(); - match *shape { - Shape::Rect(Size { width, height }) => { + match *geometry { + Geometry::Rect(Size { width, height }) => { let w = width.to_pt() as f32; let h = height.to_pt() as f32; - let rect = Rect::from_xywh(0.0, 0.0, w, h).unwrap(); + let rect = sk::Rect::from_xywh(0.0, 0.0, w, h).unwrap(); canvas.fill_rect(rect, &paint, ts, None); } - Shape::Ellipse(size) => { + Geometry::Ellipse(size) => { let path = convert_typst_path(&geom::Path::ellipse(size)); canvas.fill_path(&path, &paint, rule, ts, None); } - Shape::Line(target, thickness) => { + Geometry::Line(target, thickness) => { let path = { - let mut builder = tiny_skia::PathBuilder::new(); + let mut builder = sk::PathBuilder::new(); builder.line_to(target.x.to_pt() as f32, target.y.to_pt() as f32); builder.finish().unwrap() }; - let mut stroke = Stroke::default(); + let mut stroke = sk::Stroke::default(); stroke.width = thickness.to_pt() as f32; canvas.stroke_path(&path, &paint, &stroke, ts, None); } - Shape::Path(ref path) => { + Geometry::Path(ref path) => { let path = convert_typst_path(path); canvas.fill_path(&path, &paint, rule, ts, None); } @@ -541,18 +543,18 @@ fn draw_geometry(canvas: &mut Pixmap, ts: Transform, shape: &Shape, fill: Fill) } fn draw_image( - canvas: &mut Pixmap, + canvas: &mut sk::Pixmap, + ts: sk::Transform, cache: &Cache, - ts: Transform, id: ImageId, size: Size, ) { let img = cache.image.get(id); - let mut pixmap = Pixmap::new(img.buf.width(), img.buf.height()).unwrap(); + let mut pixmap = sk::Pixmap::new(img.buf.width(), img.buf.height()).unwrap(); for ((_, _, src), dest) in img.buf.pixels().zip(pixmap.pixels_mut()) { let Rgba([r, g, b, a]) = src; - *dest = ColorU8::from_rgba(r, g, b, a).premultiply(); + *dest = sk::ColorU8::from_rgba(r, g, b, a).premultiply(); } let view_width = size.width.to_pt() as f32; @@ -560,44 +562,41 @@ fn draw_image( let scale_x = view_width as f32 / pixmap.width() as f32; let scale_y = view_height as f32 / pixmap.height() as f32; - let mut paint = Paint::default(); - paint.shader = Pattern::new( + let mut paint = sk::Paint::default(); + paint.shader = sk::Pattern::new( pixmap.as_ref(), - SpreadMode::Pad, - FilterQuality::Bilinear, + sk::SpreadMode::Pad, + sk::FilterQuality::Bilinear, 1.0, - Transform::from_row(scale_x, 0.0, 0.0, scale_y, 0.0, 0.0), + sk::Transform::from_row(scale_x, 0.0, 0.0, scale_y, 0.0, 0.0), ); - let rect = Rect::from_xywh(0.0, 0.0, view_width, view_height).unwrap(); + let rect = sk::Rect::from_xywh(0.0, 0.0, view_width, view_height).unwrap(); canvas.fill_rect(rect, &paint, ts, None); } -fn convert_typst_fill(fill: Fill) -> Paint<'static> { - let mut paint = Paint::default(); - match fill { - Fill::Color(color::Color::Rgba(c)) => { - paint.set_color_rgba8(c.r, c.g, c.b, c.a); - } - } +fn convert_typst_paint(paint: Paint) -> sk::Paint<'static> { + let Paint::Color(Color::Rgba(c)) = paint; + let mut paint = sk::Paint::default(); + paint.set_color_rgba8(c.r, c.g, c.b, c.a); paint } -fn convert_typst_path(path: &geom::Path) -> tiny_skia::Path { - let mut builder = tiny_skia::PathBuilder::new(); +fn convert_typst_path(path: &geom::Path) -> sk::Path { + let mut builder = sk::PathBuilder::new(); let f = |v: Length| v.to_pt() as f32; for elem in &path.0 { match elem { - geom::PathElement::MoveTo(p) => { + PathElement::MoveTo(p) => { builder.move_to(f(p.x), f(p.y)); } - geom::PathElement::LineTo(p) => { + PathElement::LineTo(p) => { builder.line_to(f(p.x), f(p.y)); } - geom::PathElement::CubicTo(p1, p2, p3) => { + PathElement::CubicTo(p1, p2, p3) => { builder.cubic_to(f(p1.x), f(p1.y), f(p2.x), f(p2.y), f(p3.x), f(p3.y)); } - geom::PathElement::ClosePath => { + PathElement::ClosePath => { builder.close(); } }; @@ -605,14 +604,14 @@ fn convert_typst_path(path: &geom::Path) -> tiny_skia::Path { builder.finish().unwrap() } -fn convert_usvg_transform(transform: usvg::Transform) -> Transform { +fn convert_usvg_transform(transform: usvg::Transform) -> sk::Transform { let g = |v: f64| v as f32; let usvg::Transform { a, b, c, d, e, f } = transform; - Transform::from_row(g(a), g(b), g(c), g(d), g(e), g(f)) + sk::Transform::from_row(g(a), g(b), g(c), g(d), g(e), g(f)) } -fn convert_usvg_fill(fill: &usvg::Fill) -> (Paint<'static>, FillRule) { - let mut paint = Paint::default(); +fn convert_usvg_fill(fill: &usvg::Fill) -> (sk::Paint<'static>, sk::FillRule) { + let mut paint = sk::Paint::default(); paint.anti_alias = true; match fill.paint { @@ -623,15 +622,15 @@ fn convert_usvg_fill(fill: &usvg::Fill) -> (Paint<'static>, FillRule) { } let rule = match fill.rule { - usvg::FillRule::NonZero => FillRule::Winding, - usvg::FillRule::EvenOdd => FillRule::EvenOdd, + usvg::FillRule::NonZero => sk::FillRule::Winding, + usvg::FillRule::EvenOdd => sk::FillRule::EvenOdd, }; (paint, rule) } -fn convert_usvg_path(path: &usvg::PathData) -> tiny_skia::Path { - let mut builder = tiny_skia::PathBuilder::new(); +fn convert_usvg_path(path: &usvg::PathData) -> sk::Path { + let mut builder = sk::PathBuilder::new(); let f = |v: f64| v as f32; for seg in path.iter() { match *seg { @@ -652,7 +651,7 @@ fn convert_usvg_path(path: &usvg::PathData) -> tiny_skia::Path { builder.finish().unwrap() } -struct WrappedPathBuilder(tiny_skia::PathBuilder); +struct WrappedPathBuilder(sk::PathBuilder); impl OutlineBuilder for WrappedPathBuilder { fn move_to(&mut self, x: f32, y: f32) {