pub struct FontDesc<'a> { /* private fields */ }
Expand description
Describes a font
Implementations
sourceimpl<'a> FontDesc<'a>
impl<'a> FontDesc<'a>
sourcepub fn new(family: FontFamily<'a>, size: f64, style: FontStyle) -> FontDesc<'a>
pub fn new(family: FontFamily<'a>, size: f64, style: FontStyle) -> FontDesc<'a>
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) -> FontDesc<'a>
pub fn resize(&self, size: f64) -> FontDesc<'a>
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) -> FontDesc<'a>
pub fn style(&self, style: FontStyle) -> FontDesc<'a>
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) -> FontDesc<'a>
pub fn transform(&self, trans: FontTransform) -> FontDesc<'a>
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>(&self, color: &C) -> TextStyle<'a>where
C: Color,
pub fn color<C>(&self, color: &C) -> TextStyle<'a>where
C: Color,
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
) -> Result<((i32, i32), (i32, i32)), <FontDataInternal as FontData>::ErrorType>
pub fn layout_box(
&self,
text: &str
) -> Result<((i32, i32), (i32, i32)), <FontDataInternal as FontData>::ErrorType>
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
sourceimpl<'a, T, S> From<(FontFamily<'a>, T, S)> for FontDesc<'a>where
T: Into<f64>,
S: Into<FontStyle>,
impl<'a, T, S> From<(FontFamily<'a>, T, S)> for FontDesc<'a>where
T: Into<f64>,
S: Into<FontStyle>,
sourcefn from((FontFamily<'a>, T, S)) -> FontDesc<'a>
fn from((FontFamily<'a>, T, S)) -> FontDesc<'a>
Converts to this type from the input type.
sourceimpl<'a, T> From<(FontFamily<'a>, T)> for FontDesc<'a>where
T: Into<f64>,
impl<'a, T> From<(FontFamily<'a>, T)> for FontDesc<'a>where
T: Into<f64>,
sourcefn from((FontFamily<'a>, T)) -> FontDesc<'a>
fn from((FontFamily<'a>, T)) -> FontDesc<'a>
Converts to this type from the input type.
sourceimpl<'a> From<FontFamily<'a>> for FontDesc<'a>
impl<'a> From<FontFamily<'a>> for FontDesc<'a>
sourcefn from(family: FontFamily<'a>) -> FontDesc<'a>
fn from(family: FontFamily<'a>) -> FontDesc<'a>
Converts to this type from the input type.
sourceimpl<'a> IntoTextStyle<'a> for FontDesc<'a>
impl<'a> IntoTextStyle<'a> for FontDesc<'a>
sourcefn into_text_style<P>(self, &P) -> TextStyle<'a>where
P: HasDimension,
fn into_text_style<P>(self, &P) -> TextStyle<'a>where
P: HasDimension,
Converts the value into a TextStyle value. Read more
sourcefn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>where
C: Color,
fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>where
C: Color,
Specifies the color of the text element Read more
sourcefn with_anchor<C>(self, pos: Pos) -> TextStyleBuilder<'a, Self>where
C: Color,
fn with_anchor<C>(self, pos: Pos) -> TextStyleBuilder<'a, Self>where
C: Color,
Specifies the position of the text anchor relative to the text element Read more
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more