Skip to main content

SvgRenderer

Struct SvgRenderer 

Source
pub struct SvgRenderer<L: TextLayout> {
    palette: Palette,
    outlines: Outlines,
    shaper: Shaper,
    layout: L,
    doc: RefCell<Document>,
    bounds: Bounds,
    warned: Cell<bool>,
}

Fields§

§palette: Palette§outlines: Outlines

The ink of the typeface layout measures in.

§shaper: Shaper

The identity a layout that reports characters only cannot give.

§layout: L

The host’s text engine — the one the canvas draws through.

§doc: RefCell<Document>

The document under construction; draw calls append nodes to it.

§bounds: Bounds

Running world-space bounding box of everything drawn so far.

§warned: Cell<bool>

One Identity::ByChar warning per export, not per run.

Implementations§

Source§

impl<L: TextLayout> SvgRenderer<L>

Source

pub fn new(palette: Palette, layout: L) -> Self

The outlines are traced from the typeface layout lays text out in, so the glyphs written are the glyphs the canvas placed.

§Panics

If that typeface’s embedded bytes are not a font this can read.

Source

fn color(&self, swatch: impl Into<Swatch>) -> Color

Resolve a Swatch to a concrete color through the palette.

Source

fn resolve_stroke(&self, stroke: impl Into<PaletteStroke>) -> Ink

Resolve a palette-based stroke to the width and color the SVG states.

Source

pub fn finish(self) -> (String, Rect)

Finalize the <svg> root: set its viewBox/size to frame the content (with a small margin) and serialize it, with the viewBox rect — the exact world-space region the SVG depicts, for callers that place the output back into world coordinates (the PDF export’s page fit).

Source

fn append(&self, node: impl Into<Box<dyn Node>>)

Source

fn draw_glyphs( &self, pos: Pos2, anchor: Align2, laid: &Layout, font: &Font, color: Color, angle: Angle, ) -> Rect

Append each glyph of laid, anchored at world pos, as a filled <path>. When angle is non-zero the run is wrapped in a rotate(...) group about pos, matching the canvas’s rotated-text behaviour. Returns the unrotated anchored bounding rect.

Source

fn identify(&self, run: &[Placed<'_>]) -> Vec<Option<GlyphId>>

Which outline each glyph of run draws, in order; None draws nothing.

An engine that reports the glyph it chose has answered this already. One that records the character behind each glyph has not: fi in a font with liga arrives as a ligature filed under 'f' plus a continuation glyph for 'i' — and outlining that 'i' by cmap stacks it on the next character. Re-shaping recovers the identity the layout dropped; the positions stay the layout’s.

Trait Implementations§

Source§

impl<L: TextLayout> Renderer for SvgRenderer<L>

Source§

fn rect( &self, rect: Rect, rounding: WorldPx, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )

Source§

fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<PaletteStroke>)

Source§

fn line(&self, points: Vec<Pos2>, stroke: impl Into<PaletteStroke>)

Source§

fn circle( &self, center: Pos2, radius: WorldPx, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )

Source§

fn add_convex_polygon( &self, points: Vec<Pos2>, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )

Source§

fn text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: impl Into<Swatch>, ) -> Rect

Source§

fn rotated_text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: impl Into<Swatch>, angle: Angle, )

Source§

fn text_wrapped( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: impl Into<Swatch>, max_width: WorldPx, ) -> Rect

Like Renderer::text but wraps to max_width (word wrap); WorldPx::UNBOUNDED draws unwrapped. The default ignores max_width and draws unwrapped; backends that lay text out override it. Both the on-screen and the SVG backend break the text with the same layout engine, so they agree on the break points.
Source§

fn text_size(&self, text: impl ToString, font: &Font) -> Vec2

Source§

fn text_size_wrapped( &self, text: impl ToString, font: &Font, max_width: WorldPx, ) -> Vec2

Like Renderer::text_size but measured with word wrap at max_width. The default ignores max_width.
Source§

fn text_layout(&self, text: &str, font: &Font, max_width: WorldPx) -> Layout

text laid out in font and word-wrapped at max_width, in world units: the rows Self::text_size_wrapped measures.
Source§

fn draw_image(&self, rect: Rect, image: &Asset)

Draw image (an SVG or PNG payload) filling the world-space rect. The caller sizes rect to honor the image’s aspect ratio (see Renderer::image_intrinsic_size), so each backend simply fills rect: the on-screen painter caches the bytes in its own hash → handle table and polls the toolkit’s loader, while the SVG exporter embeds the bytes as a base64 data URI.
Source§

fn image_intrinsic_size(&self, image: &Asset) -> Option<Vec2>

The intrinsic point size of image (always strictly positive), used by the caller for aspect-fit and the resize-ring geometry. None if the bytes are not a valid SVG/PNG.
Source§

fn animator(&self) -> Option<&dyn Animator>

The frame animation this backend drives, for interactive overlays drawn on the generic render path. The on-screen canvas supplies itself; offline backends (the SVG exporter) return None, so those overlays fall back to a static draw.
Source§

fn visible_world_bounds(&self) -> Option<Rect>

The world-space rect currently visible on screen, if this backend paints into a bounded viewport. The render path uses it to viewport-cull the scene: shapes outside it are skipped. None (the default) means “no viewport — draw everything”, which is what offline backends (the SVG exporter) want, so an export is never culled.

Auto Trait Implementations§

§

impl<L> !Freeze for SvgRenderer<L>

§

impl<L> !RefUnwindSafe for SvgRenderer<L>

§

impl<L> Send for SvgRenderer<L>
where L: Send,

§

impl<L> !Sync for SvgRenderer<L>

§

impl<L> Unpin for SvgRenderer<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for SvgRenderer<L>
where L: UnsafeUnpin,

§

impl<L> !UnwindSafe for SvgRenderer<L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either [OwoColorize::fg] or a color-specific method, such as [OwoColorize::green], Read more
§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either [OwoColorize::bg] or a color-specific method, such as [OwoColorize::on_yellow], Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,