Struct FontDesc
pub struct FontDesc<'a> { /* private fields */ }Expand description
Describes a font
Implementations§
§impl<'a> FontDesc<'a>
impl<'a> FontDesc<'a>
pub 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
pub 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
pub 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
pub 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
pub fn get_transform(&self) -> FontTransform
pub fn get_transform(&self) -> FontTransform
Get the font transformation description
pub 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
pub fn get_family(&self) -> FontFamily<'_>
pub fn get_family(&self) -> FontFamily<'_>
Returns the font family
pub 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§
§impl<'a, T> From<(FontFamily<'a>, T)> for FontDesc<'a>
impl<'a, T> From<(FontFamily<'a>, T)> for FontDesc<'a>
§fn from(_: (FontFamily<'a>, T)) -> FontDesc<'a>
fn from(_: (FontFamily<'a>, T)) -> FontDesc<'a>
Converts to this type from the input type.
§impl<'a, T, S> From<(FontFamily<'a>, T, S)> for FontDesc<'a>
impl<'a, T, S> From<(FontFamily<'a>, T, S)> for FontDesc<'a>
§fn from(_: (FontFamily<'a>, T, S)) -> FontDesc<'a>
fn from(_: (FontFamily<'a>, T, S)) -> FontDesc<'a>
Converts to this type from the input type.
§impl<'a> From<FontFamily<'a>> for FontDesc<'a>
impl<'a> From<FontFamily<'a>> for FontDesc<'a>
§fn from(family: FontFamily<'a>) -> FontDesc<'a>
fn from(family: FontFamily<'a>) -> FontDesc<'a>
Converts to this type from the input type.
§impl<'a> IntoTextStyle<'a> for FontDesc<'a>
impl<'a> IntoTextStyle<'a> for FontDesc<'a>
§fn 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
§fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>
fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>
Specifies the color of 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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more