Put trait into primitive

This commit is contained in:
Laurenz Stampfl 2024-12-15 22:34:48 +01:00
parent f2d4db286c
commit 6761cbc622
4 changed files with 16 additions and 18 deletions

View File

@ -1,5 +1,5 @@
use crate::primitive::{PointExt, SizeExt, TransformExt}; use crate::primitive::{AbsExt, PointExt, SizeExt, TransformExt};
use crate::{paint, AbsExt, PdfOptions}; use crate::{paint, PdfOptions};
use bytemuck::TransparentWrapper; use bytemuck::TransparentWrapper;
use ecow::EcoString; use ecow::EcoString;
use krilla::action::{Action, LinkAction}; use krilla::action::{Action, LinkAction};

View File

@ -50,15 +50,3 @@ pub struct PdfOptions<'a> {
/// A standard the PDF should conform to. /// A standard the PDF should conform to.
pub validator: Validator, pub validator: Validator,
} }
/// Additional methods for [`Abs`].
trait AbsExt {
/// Convert an to a number of points.
fn to_f32(self) -> f32;
}
impl AbsExt for Abs {
fn to_f32(self) -> f32 {
self.to_pt() as f32
}
}

View File

@ -1,8 +1,7 @@
//! Convert paint types from typst to krilla. //! Convert paint types from typst to krilla.
use crate::krilla::{process_frame, FrameContext, GlobalContext, Transforms}; use crate::krilla::{process_frame, FrameContext, GlobalContext, Transforms};
use crate::primitive::{FillRuleExt, LineCapExt, LineJoinExt, TransformExt}; use crate::primitive::{AbsExt, FillRuleExt, LineCapExt, LineJoinExt, TransformExt};
use crate::AbsExt;
use krilla::geom::NormalizedF32; use krilla::geom::NormalizedF32;
use krilla::page::{NumberingStyle, PageLabel}; use krilla::page::{NumberingStyle, PageLabel};
use krilla::paint::SpreadMethod; use krilla::paint::SpreadMethod;

View File

@ -1,9 +1,8 @@
//! Convert basic primitive types from typst to krilla. //! Convert basic primitive types from typst to krilla.
use typst_library::layout::{Point, Size, Transform}; use typst_library::layout::{Abs, Point, Size, Transform};
use typst_library::visualize::{FillRule, LineCap, LineJoin}; use typst_library::visualize::{FillRule, LineCap, LineJoin};
use crate::AbsExt;
pub(crate) trait SizeExt { pub(crate) trait SizeExt {
fn as_krilla(&self) -> krilla::geom::Size; fn as_krilla(&self) -> krilla::geom::Size;
@ -82,3 +81,15 @@ impl FillRuleExt for FillRule {
} }
} }
} }
/// Additional methods for [`Abs`].
pub(crate) trait AbsExt {
/// Convert an to a number of points.
fn to_f32(self) -> f32;
}
impl AbsExt for Abs {
fn to_f32(self) -> f32 {
self.to_pt() as f32
}
}