From bb7efcccec2576f010ac020f55f827ca35da802e Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Sun, 16 Mar 2025 08:52:21 +0100 Subject: [PATCH] more changes --- crates/typst-pdf/src/convert.rs | 3 +-- crates/typst-pdf/src/paint.rs | 9 ++++++--- crates/typst-pdf/src/shape.rs | 6 ++++-- crates/typst-pdf/src/text.rs | 23 +++++++++++------------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/crates/typst-pdf/src/convert.rs b/crates/typst-pdf/src/convert.rs index d4dea1dfc..80d7aa2b7 100644 --- a/crates/typst-pdf/src/convert.rs +++ b/crates/typst-pdf/src/convert.rs @@ -47,7 +47,7 @@ pub fn convert( cmyk_profile: None, configuration, enable_tagging: false, - render_svg_glyph_fn: render_svg_glyph + render_svg_glyph_fn: render_svg_glyph, }; let mut document = Document::new_with(settings); @@ -304,7 +304,6 @@ pub(crate) fn handle_group( .clip .as_ref() .and_then(|p| { - let mut builder = PathBuilder::new(); convert_path(p, &mut builder); builder.finish() diff --git a/crates/typst-pdf/src/paint.rs b/crates/typst-pdf/src/paint.rs index 3e02753ce..4d13d8904 100644 --- a/crates/typst-pdf/src/paint.rs +++ b/crates/typst-pdf/src/paint.rs @@ -190,9 +190,12 @@ fn convert_gradient( cx: radial.center.x.get() as f32, cy: radial.center.y.get() as f32, cr: radial.radius.get() as f32, - transform: base_transform.pre_concat( - Transform::scale(Ratio::new(size.x.to_f32() as f64), Ratio::new(size.y.to_f32() as f64)), - ).to_krilla(), + transform: base_transform + .pre_concat(Transform::scale( + Ratio::new(size.x.to_f32() as f64), + Ratio::new(size.y.to_f32() as f64), + )) + .to_krilla(), spread_method: SpreadMethod::Pad, stops: stops.into(), anti_alias: gradient.anti_alias(), diff --git a/crates/typst-pdf/src/shape.rs b/crates/typst-pdf/src/shape.rs index 2920f2e1f..e658ff8fc 100644 --- a/crates/typst-pdf/src/shape.rs +++ b/crates/typst-pdf/src/shape.rs @@ -31,7 +31,8 @@ pub(crate) fn handle_shape( shape.geometry.bbox_size(), )?; - surface.fill_path(&path, fill); + surface.set_fill(fill); + surface.fill_path(&path); } let stroke = shape.stroke.as_ref().and_then(|stroke| { @@ -52,7 +53,8 @@ pub(crate) fn handle_shape( shape.geometry.bbox_size(), )?; - surface.stroke_path(&path, stroke); + surface.set_stroke(stroke); + surface.stroke_path(&path); } } diff --git a/crates/typst-pdf/src/text.rs b/crates/typst-pdf/src/text.rs index 5e419f626..ad33df3e2 100644 --- a/crates/typst-pdf/src/text.rs +++ b/crates/typst-pdf/src/text.rs @@ -2,10 +2,10 @@ use std::ops::Range; use std::sync::Arc; use bytemuck::TransparentWrapper; -use krilla::font::{GlyphId, GlyphUnits}; +use krilla::font::GlyphId; use krilla::surface::{Location, Surface}; use typst_library::diag::{bail, SourceResult}; -use typst_library::layout::Size; +use typst_library::layout::{Abs, Size}; use typst_library::text::{Font, Glyph, TextItem}; use typst_library::visualize::FillRule; use typst_syntax::Span; @@ -37,14 +37,13 @@ pub(crate) fn handle_text( let glyphs: &[PdfGlyph] = TransparentWrapper::wrap_slice(t.glyphs.as_slice()); surface.push_transform(&fc.state().transform().to_krilla()); + surface.set_fill(fill); surface.fill_glyphs( krilla::geom::Point::from_xy(0.0, 0.0), - fill, glyphs, font.clone(), text, size.to_f32(), - GlyphUnits::Normalized, false, ); @@ -55,14 +54,14 @@ pub(crate) fn handle_text( { let stroke = stroke?; + surface.set_stroke(stroke); surface.stroke_glyphs( krilla::geom::Point::from_xy(0.0, 0.0), - stroke, glyphs, font, text, size.to_f32(), - GlyphUnits::Normalized, + // TODO: What if only stroke? true, ); } @@ -110,19 +109,19 @@ impl krilla::font::Glyph for PdfGlyph { self.0.range.start as usize..self.0.range.end as usize } - fn x_advance(&self) -> f32 { - self.0.x_advance.get() as f32 + fn x_advance(&self, size: f32) -> f32 { + self.0.x_advance.at(Abs::raw(size as f64)).to_raw() as f32 } - fn x_offset(&self) -> f32 { - self.0.x_offset.get() as f32 + fn x_offset(&self, size: f32) -> f32 { + self.0.x_offset.at(Abs::raw(size as f64)).to_raw() as f32 } - fn y_offset(&self) -> f32 { + fn y_offset(&self, _: f32) -> f32 { 0.0 } - fn y_advance(&self) -> f32 { + fn y_advance(&self, _: f32) -> f32 { 0.0 }