pub struct Text {
pub path: Path,
pub bounding_box: Rect<f32>,
}
Fields§
§path: Path
§bounding_box: Rect<f32>
Implementations§
Source§impl Text
impl Text
pub fn new(path: Path, bounding_box: Rect<f32>) -> Self
Sourcepub fn builder() -> Builder<'static>
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> 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
Mutably borrows from an owned value. Read more