Struct plotters::style::FontDesc

source ·
pub struct FontDesc<'a> { /* private fields */ }
Expand description

Describes a font

Implementations§

source§

impl<'a> FontDesc<'a>

source

pub fn new(family: FontFamily<'a>, size: f64, style: FontStyle) -> Self

Create a new font

  • family: The font family name
  • size: The size of the font
  • style: The font variations
  • returns The newly created font description
source

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
source

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
source

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
source

pub fn get_transform(&self) -> FontTransform

Get the font transformation description

source

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::with_color()

IntoTextStyle::into_text_style() for a more succinct example

source

pub fn get_family(&self) -> FontFamily<'_>

Returns the font family

source

pub fn get_name(&self) -> &str

Get the name of the font

source

pub fn get_style(&self) -> FontStyle

Get the name of the style

source

pub fn get_size(&self) -> f64

Get the size of font

source

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

source

pub fn box_size(&self, text: &str) -> FontResult<(u32, u32)>

Get the size of the text if rendered in this font. This is similar to layout_box function, but it apply the font transformation and estimate the overall size of the font

source

pub fn draw<E, DrawFunc: FnMut(i32, i32, f32) -> Result<(), E>>( &self, text: &str, (x, y): (i32, i32), draw: DrawFunc ) -> FontResult<Result<(), E>>

Actually draws a font with a drawing function

Trait Implementations§

source§

impl<'a> Clone for FontDesc<'a>

source§

fn clone(&self) -> FontDesc<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> From<&'a str> for FontDesc<'a>

source§

fn from(from: &'a str) -> FontDesc<'a>

Converts to this type from the input type.
source§

impl<'a, T: Into<f64>> From<(&'a str, T)> for FontDesc<'a>

source§

fn from((typeface, size): (&'a str, T)) -> FontDesc<'a>

Converts to this type from the input type.
source§

impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(&'a str, T, S)> for FontDesc<'a>

source§

fn from((typeface, size, style): (&'a str, T, S)) -> FontDesc<'a>

Converts to this type from the input type.
source§

impl<'a, T: Into<f64>> From<(FontFamily<'a>, T)> for FontDesc<'a>

source§

fn from((family, size): (FontFamily<'a>, T)) -> FontDesc<'a>

Converts to this type from the input type.
source§

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>

Converts to this type from the input type.
source§

impl<'a> From<FontFamily<'a>> for FontDesc<'a>

source§

fn from(family: FontFamily<'a>) -> FontDesc<'a>

Converts to this type from the input type.
source§

impl<'a> IntoTextStyle<'a> for FontDesc<'a>

source§

fn into_text_style<P: HasDimension>(self, _: &P) -> TextStyle<'a>

Converts the value into a TextStyle value. Read more
source§

fn with_color<C: Color>(self, color: C) -> TextStyleBuilder<'a, Self>where Self: Sized,

Specifies the color of the text element Read more
source§

fn with_anchor<C: Color>(self, pos: Pos) -> TextStyleBuilder<'a, Self>where Self: Sized,

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<'a, T> IntoFont<'a> for Twhere T: Into<FontDesc<'a>>,

source§

fn into_font(self) -> FontDesc<'a>

Make the font description from the source type
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.