Add more typst-timing annotations

This commit is contained in:
Laurenz Stampfl 2025-03-28 15:07:15 +01:00
parent 986f8b2456
commit 067478a520
4 changed files with 17 additions and 3 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<krilla::text::Font> {
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<usize> {
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
}