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: OutlinesThe ink of the typeface layout measures in.
shaper: ShaperThe identity a layout that reports characters only cannot give.
layout: LThe host’s text engine — the one the canvas draws through.
doc: RefCell<Document>The document under construction; draw calls append nodes to it.
bounds: BoundsRunning 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>
impl<L: TextLayout> SvgRenderer<L>
Sourcepub fn new(palette: Palette, layout: L) -> Self
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.
Sourcefn color(&self, swatch: impl Into<Swatch>) -> Color
fn color(&self, swatch: impl Into<Swatch>) -> Color
Resolve a Swatch to a concrete color through the palette.
Sourcefn resolve_stroke(&self, stroke: impl Into<PaletteStroke>) -> Ink
fn resolve_stroke(&self, stroke: impl Into<PaletteStroke>) -> Ink
Resolve a palette-based stroke to the width and color the SVG states.
Sourcepub fn finish(self) -> (String, Rect)
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).
fn append(&self, node: impl Into<Box<dyn Node>>)
Sourcefn draw_glyphs(
&self,
pos: Pos2,
anchor: Align2,
laid: &Layout,
font: &Font,
color: Color,
angle: Angle,
) -> Rect
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.
Sourcefn identify(&self, run: &[Placed<'_>]) -> Vec<Option<GlyphId>>
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>
impl<L: TextLayout> Renderer for SvgRenderer<L>
fn rect( &self, rect: Rect, rounding: WorldPx, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )
fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<PaletteStroke>)
fn line(&self, points: Vec<Pos2>, stroke: impl Into<PaletteStroke>)
fn circle( &self, center: Pos2, radius: WorldPx, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )
fn add_convex_polygon( &self, points: Vec<Pos2>, fill: impl Into<Swatch>, stroke: impl Into<PaletteStroke>, )
fn text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: impl Into<Swatch>, ) -> Rect
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
fn text_wrapped( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: impl Into<Swatch>, max_width: WorldPx, ) -> Rect
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.fn text_size(&self, text: impl ToString, font: &Font) -> Vec2
Source§fn text_layout(&self, text: &str, font: &Font, max_width: WorldPx) -> Layout
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)
fn draw_image(&self, rect: Rect, image: &Asset)
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>
fn image_intrinsic_size(&self, image: &Asset) -> Option<Vec2>
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>
fn animator(&self) -> Option<&dyn Animator>
None, so those overlays
fall back to a static draw.Source§fn visible_world_bounds(&self) -> Option<Rect>
fn visible_world_bounds(&self) -> Option<Rect>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
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,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
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>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.