Struct Text

Source
pub struct Text {
    pub path: Path,
    pub bounding_box: Rect<f32>,
}

Fields§

§path: Path§bounding_box: Rect<f32>

Implementations§

Source§

impl Text

Source

pub fn new(path: Path, bounding_box: Rect<f32>) -> Self

Source

pub fn builder() -> Builder<'static>

Examples found in repository?
examples/text.rs (line 29)
9fn main() {
10    let handle = SystemSource::new()
11        .select_best_match(&[FamilyName::Serif], &Properties::new())
12        .unwrap();
13
14    let font = match handle {
15        Handle::Path { path, font_index } => {
16            let mut file = File::open(path).unwrap();
17            let mut buf = Vec::new();
18            file.read_to_end(&mut buf).unwrap();
19            Font::try_from_vec_and_index(buf, font_index).unwrap()
20        }
21        Handle::Memory { bytes, font_index } => {
22            Font::try_from_vec_and_index(bytes.to_vec(), font_index).unwrap()
23        }
24    };
25
26    let x = 10.;
27    let y = 20.;
28
29    let text = Text::builder()
30        .size(50.0)
31        .start(Point { x, y })
32        .build(&font, "text-svg");
33
34    let document = Document::new()
35        .set("width", text.bounding_box.max.x + x)
36        .set("height", text.bounding_box.max.y + y)
37        .add(
38            Rectangle::new()
39                .set("fill", "#fff")
40                .set("x", 0.)
41                .set("y", 0.)
42                .set("width", text.bounding_box.max.x + x)
43                .set("height", text.bounding_box.max.y + y),
44        )
45        .add(text.path);
46
47    svg::save("image.svg", &document).unwrap();
48}

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