Struct usvg::Text

source ·
pub struct Text { /* private fields */ }
Expand description

A text element.

text element in SVG.

Implementations§

source§

impl Text

source

pub fn id(&self) -> &str

Element’s ID.

Taken from the SVG itself. Isn’t automatically generated. Can be empty.

source

pub fn rendering_mode(&self) -> TextRendering

Rendering mode.

text-rendering in SVG.

source

pub fn dx(&self) -> &[f32]

A relative X axis offsets.

One offset for each Unicode codepoint. Aka char in Rust.

source

pub fn dy(&self) -> &[f32]

A relative Y axis offsets.

One offset for each Unicode codepoint. Aka char in Rust.

source

pub fn rotate(&self) -> &[f32]

A list of rotation angles.

One angle for each Unicode codepoint. Aka char in Rust.

source

pub fn writing_mode(&self) -> WritingMode

A writing mode.

source

pub fn chunks(&self) -> &[TextChunk]

A list of text chunks.

source

pub fn abs_transform(&self) -> Transform

Element’s absolute transform.

Contains all ancestors transforms including elements’s transform.

Note that this is not the relative transform present in SVG. The SVG one would be set only on groups.

source

pub fn bounding_box(&self) -> Rect

Element’s text bounding box.

Text bounding box is special in SVG and doesn’t represent tight bounds of the element’s content. You can find more about it here.

objectBoundingBox in SVG terms. Meaning it doesn’t affected by parent transforms.

Returns None when the text build feature was disabled. This is because we have to perform a text layout before calculating a bounding box.

source

pub fn abs_bounding_box(&self) -> Rect

Element’s text bounding box in canvas coordinates.

userSpaceOnUse in SVG terms.

source

pub fn stroke_bounding_box(&self) -> Rect

Element’s object bounding box including stroke.

Similar to bounding_box, but includes stroke.

Will have the same value as bounding_box when path has no stroke.

source

pub fn abs_stroke_bounding_box(&self) -> Rect

Element’s bounding box including stroke in canvas coordinates.

source

pub fn flattened(&self) -> &Group

Text converted into paths, ready to render.

Note that this is only a “best-effort” attempt: The text will be converted into group/paths/image primitives, so that they can be rendered with the existing infrastructure. This process is in general lossless and should lead to correct output, with two notable exceptions:

  1. For glyphs based on the SVG table, only glyphs that are pure SVG 1.1/2.0 are supported. Glyphs that make use of features in the OpenType specification that are not part of the original SVG specification are not supported.
  2. For glyphs based on the COLR table, there are a certain number of features that are not (correctly) supported, such as conical gradients, certain gradient transforms and some blend modes. But this shouldn’t cause any issues in 95% of the cases, as most of those are edge cases. If the two above are not acceptable, then you will need to implement your own glyph rendering logic based on the layouted glyphs (see the layouted method).
source

pub fn layouted(&self) -> &[Span]

The positioned glyphs and decoration spans of the text.

This should only be used if you need more low-level access to the glyphs that make up the text. If you just need the outlines of the text, you should use flattened instead.

Trait Implementations§

source§

impl Clone for Text

source§

fn clone(&self) -> Text

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Text

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Text

§

impl !RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl !UnwindSafe for Text

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
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.