plotters::style

Struct 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> 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<'a, T> IntoFont<'a> for T
where T: Into<FontDesc<'a>>,

Source§

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

Make the font description from the source type
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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