From 067478a5201897858efa53fb7acd97dfa7c08675 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Fri, 28 Mar 2025 15:07:15 +0100 Subject: [PATCH] Add more typst-timing annotations --- crates/typst-pdf/src/convert.rs | 3 +++ crates/typst-pdf/src/image.rs | 1 + crates/typst-pdf/src/shape.rs | 1 + crates/typst-pdf/src/text.rs | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/typst-pdf/src/convert.rs b/crates/typst-pdf/src/convert.rs index c19e53a6e..9eac0e661 100644 --- a/crates/typst-pdf/src/convert.rs +++ b/crates/typst-pdf/src/convert.rs @@ -34,6 +34,7 @@ use crate::text::handle_text; use crate::util::{convert_path, display_font, AbsExt, TransformExt}; use crate::PdfOptions; +#[typst_macros::time(name = "convert document")] pub fn convert( typst_document: &PagedDocument, options: &PdfOptions, @@ -247,6 +248,7 @@ impl<'a> GlobalContext<'a> { } } +#[typst_macros::time(name = "handle page")] pub(crate) fn handle_frame( fc: &mut FrameContext, frame: &Frame, @@ -322,6 +324,7 @@ pub(crate) fn handle_group( Ok(()) } +#[typst_macros::time(name = "finish export")] /// Finish a krilla document and handle export errors. fn finish( document: Document, diff --git a/crates/typst-pdf/src/image.rs b/crates/typst-pdf/src/image.rs index 36b420010..fff820c28 100644 --- a/crates/typst-pdf/src/image.rs +++ b/crates/typst-pdf/src/image.rs @@ -16,6 +16,7 @@ use typst_syntax::Span; use crate::convert::{FrameContext, GlobalContext}; use crate::util::{SizeExt, TransformExt}; +#[typst_macros::time(name = "handle image")] pub(crate) fn handle_image( gc: &mut GlobalContext, fc: &mut FrameContext, diff --git a/crates/typst-pdf/src/shape.rs b/crates/typst-pdf/src/shape.rs index 8bbf98bf8..5b9232dbe 100644 --- a/crates/typst-pdf/src/shape.rs +++ b/crates/typst-pdf/src/shape.rs @@ -8,6 +8,7 @@ use crate::convert::{FrameContext, GlobalContext}; use crate::paint; use crate::util::{convert_path, AbsExt, TransformExt}; +#[typst_macros::time(name = "handle shape")] pub(crate) fn handle_shape( fc: &mut FrameContext, shape: &Shape, diff --git a/crates/typst-pdf/src/text.rs b/crates/typst-pdf/src/text.rs index c0d3ba1b8..e5419a0eb 100644 --- a/crates/typst-pdf/src/text.rs +++ b/crates/typst-pdf/src/text.rs @@ -5,7 +5,7 @@ use bytemuck::TransparentWrapper; use krilla::surface::{Location, Surface}; use krilla::text::GlyphId; use typst_library::diag::{bail, SourceResult}; -use typst_library::layout::{Abs, Size}; +use typst_library::layout::Size; use typst_library::text::{Font, Glyph, TextItem}; use typst_library::visualize::FillRule; use typst_syntax::Span; @@ -14,6 +14,7 @@ use crate::convert::{FrameContext, GlobalContext}; use crate::paint; use crate::util::{display_font, AbsExt, TransformExt}; +#[typst_macros::time(name = "handle text")] pub(crate) fn handle_text( fc: &mut FrameContext, t: &TextItem, @@ -96,26 +97,34 @@ fn build_font(typst_font: Font) -> SourceResult { struct PdfGlyph(Glyph); impl krilla::text::Glyph for PdfGlyph { + #[inline(always)] fn glyph_id(&self) -> GlyphId { GlyphId::new(self.0.id as u32) } + #[inline(always)] fn text_range(&self) -> Range { self.0.range.start as usize..self.0.range.end as usize } + #[inline(always)] fn x_advance(&self, size: f32) -> f32 { - self.0.x_advance.at(Abs::raw(size as f64)).to_raw() as f32 + // Don't use `Em::at`, because it contains an expensive check whether the result is finite. + self.0.x_advance.get() as f32 * size } + #[inline(always)] fn x_offset(&self, size: f32) -> f32 { - self.0.x_offset.at(Abs::raw(size as f64)).to_raw() as f32 + // Don't use `Em::at`, because it contains an expensive check whether the result is finite. + self.0.x_offset.get() as f32 * size } + #[inline(always)] fn y_offset(&self, _: f32) -> f32 { 0.0 } + #[inline(always)] fn y_advance(&self, _: f32) -> f32 { 0.0 }