Skip to main content

Text

Struct Text 

Source
pub struct Text {
    pub position: Point,
    pub content: String,
    pub height: f64,
    pub rotation: f64,
    pub halign: HAlign,
    pub valign: VAlign,
}
Expand description

Text annotation. Height is the cap-to-descender line height in model units.

Fields§

§position: Point

Insertion point.

§content: String

UTF-8 content; \n separates lines.

§height: f64

Text height in model units.

§rotation: f64

Rotation in radians.

§halign: HAlign

Horizontal alignment.

§valign: VAlign

Vertical alignment.

Implementations§

Source§

impl Text

Source

pub const LINE_SPACING: f64 = 1.2

Line spacing relative to height.

Source

pub const TOP_ABOVE_BASELINE: f64 = 0.8

Top of the text block above the first baseline (relative to height) for Top, Middle and Bottom alignment — the renderer’s layout contract.

Source

pub const FONT_UNITS_PER_EM: f64 = fm::UNITS_PER_EM

Font units per em of the renderer’s default font (the unit of Text::line_pens).

Source

pub fn em_size(height: f64) -> f64

Model units per em for text of height (for renderers that place glyph outlines with Text::line_pens).

Source

pub fn line_pens(line: &str) -> (Vec<(char, f64)>, f64)

Pen positions of one line laid out with the renderer’s default font: each drawn character (after the renderer’s substitutions: tabs and no-break spaces become spaces, control characters are dropped) with its pen position in font units from the line start — advance widths plus pair kerning — and the line’s total advance in font units. The renderer places glyphs with exactly these positions, so drawn text and Text::layout_box agree.

Source

pub fn line_width(line: &str, height: f64) -> f64

Advance width of one line in model units, measured with the renderer’s default font (advance widths and pair kerning — exactly how it is drawn). Tabs count as spaces; control characters are skipped.

Source

pub fn layout_box(&self) -> Aabb

Layout box (before rotation) relative to position: each line’s advance width with its alignment, from the ascender of the first line to the descender of the last. Matches the renderer’s layout of the default font.

Source

pub fn layout_corners(&self) -> [Point; 4]

The four corners of the layout box in model space.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl<'de> Deserialize<'de> for Text

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Text

Source§

fn eq(&self, other: &Text) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Text

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Text

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin 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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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,

Source§

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

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.