pub struct FontDesc<'a> { /* private fields */ }
Expand description
Describes a font
Implementations§
Source§impl<'a> FontDesc<'a>
impl<'a> FontDesc<'a>
Sourcepub fn new(family: FontFamily<'a>, size: f64, style: FontStyle) -> Self
pub fn new(family: FontFamily<'a>, size: f64, style: FontStyle) -> Self
Create a new font
family
: The font family namesize
: The size of the fontstyle
: The font variations- returns The newly created font description
Sourcepub fn resize(&self, size: f64) -> Self
pub fn resize(&self, size: f64) -> Self
Create a new font desc with the same font but different size
size
: The new size to set- returns The newly created font descriptor with a new size
Sourcepub fn style(&self, style: FontStyle) -> Self
pub fn style(&self, style: FontStyle) -> Self
Set the style of the font
style
: The new style- returns The new font description with this style applied
Sourcepub fn transform(&self, trans: FontTransform) -> Self
pub fn transform(&self, trans: FontTransform) -> Self
Set the font transformation
trans
: The new transformation- returns The new font description with this font transformation applied
Sourcepub fn get_transform(&self) -> FontTransform
pub fn get_transform(&self) -> FontTransform
Get the font transformation description
Sourcepub fn color<C: Color>(&self, color: &C) -> TextStyle<'a>
pub fn color<C: Color>(&self, color: &C) -> TextStyle<'a>
Returns a new text style object with the specified color
.
§Example
use plotters::prelude::*;
let text_style = ("sans-serif", 20).into_font().color(&RED);
let drawing_area = SVGBackend::new("font_desc_color.svg", (200, 100)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
drawing_area.draw_text("This is a big red label", &text_style, (10, 50));
The result is a text label colorized accordingly:
§See also
IntoTextStyle::into_text_style()
for a more succinct example
Sourcepub fn get_family(&self) -> FontFamily<'_>
pub fn get_family(&self) -> FontFamily<'_>
Returns the font family
Sourcepub fn layout_box(&self, text: &str) -> FontResult<((i32, i32), (i32, i32))>
pub fn layout_box(&self, text: &str) -> FontResult<((i32, i32), (i32, i32))>
Get the size of the text if rendered in this font
For a TTF type, zero point of the layout box is the left most baseline char of the string Thus the upper bound of the box is most likely be negative
Trait Implementations§
Source§impl<'a, T: Into<f64>> From<(FontFamily<'a>, T)> for FontDesc<'a>
impl<'a, T: Into<f64>> From<(FontFamily<'a>, T)> for FontDesc<'a>
Source§fn from((family, size): (FontFamily<'a>, T)) -> FontDesc<'a>
fn from((family, size): (FontFamily<'a>, T)) -> FontDesc<'a>
Source§impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(FontFamily<'a>, T, S)> for FontDesc<'a>
impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(FontFamily<'a>, T, S)> for FontDesc<'a>
Source§fn from((family, size, style): (FontFamily<'a>, T, S)) -> FontDesc<'a>
fn from((family, size, style): (FontFamily<'a>, T, S)) -> FontDesc<'a>
Source§impl<'a> From<FontFamily<'a>> for FontDesc<'a>
impl<'a> From<FontFamily<'a>> for FontDesc<'a>
Source§fn from(family: FontFamily<'a>) -> FontDesc<'a>
fn from(family: FontFamily<'a>) -> FontDesc<'a>
Source§impl<'a> IntoTextStyle<'a> for FontDesc<'a>
impl<'a> IntoTextStyle<'a> for FontDesc<'a>
Auto Trait Implementations§
impl<'a> Freeze for FontDesc<'a>
impl<'a> RefUnwindSafe for FontDesc<'a>
impl<'a> Send for FontDesc<'a>
impl<'a> Sync for FontDesc<'a>
impl<'a> Unpin for FontDesc<'a>
impl<'a> UnwindSafe for FontDesc<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 88 bytes