Struct riddle_font::ImgFont[][src]

pub struct ImgFont { /* fields omitted */ }

Represents an image font, which is an Image containing glyphs, glyph information specifying which parts of the image map to which glyph, and layout information.

Implementations

impl ImgFont[src]

pub fn vertical_spacing(&self) -> u32[src]

This represents the distance, in pixels, between the top of one line of text and the next line of text.

Example

let ttf_font = TTFont::load(&font_bytes[..])?;
let img_font = ImgFontGenerator::new("ABCDEF", 32).generate(&ttf_font)?;

assert!(img_font.vertical_spacing() > 0);

pub fn image(&self) -> &Image[src]

The image storing the glyph image data.

Example

let ttf_font = TTFont::load(&font_bytes[..])?;
let img_font = ImgFontGenerator::new("ABCDEF", 32).generate(&ttf_font)?;

assert!(img_font.image().width() > 0);

pub fn glyphs(&self) -> &HashMap<char, ImgFontGlyph>[src]

The mapping from char to glyphs registered with the font.

Example

let ttf_font = TTFont::load(&font_bytes[..])?;
let img_font = ImgFontGenerator::new("ABCDEF", 32).generate(&ttf_font)?;

assert_eq!(6, img_font.glyphs().len());
assert_eq!('A', img_font.glyphs().get(&'A').unwrap().character);

pub fn render_simple(&self, text: &str) -> Result<Image, FontError>[src]

Render a string to a riddle_image::Image using the font at its native scale.

Example

let ttf_font = TTFont::load(&font_bytes[..])?;
let img_font = ImgFontGenerator::new("ABCDEF", 32).generate(&ttf_font)?;

let rendered_img = img_font.render_simple("AABCA")?;

assert_eq!(rendered_img.height(), img_font.vertical_spacing());
assert!(rendered_img.width() > 0);

pub fn layout<F: FnMut(char, &Rect<u32>, Vector2<u32>)>(&self, text: &str, f: F)[src]

Layout a string using the font, relative to a (0,0) point representing the top left of the layout space.

The callback fuction is invoked once for each character, providing the part of the image to be used, and the location to draw that image.

Example

let ttf_font = TTFont::load(&font_bytes[..])?;
let img_font = ImgFontGenerator::new("ABCDEF", 32).generate(&ttf_font)?;

let mut last_x = 0;
let mut total_width = 0;
let mut string = String::from("");

img_font.layout("AABCA", |c, rect, location| {
    assert!(location.x >= last_x);
    last_x = location.x;
    total_width += rect.dimensions.x;
    string += c.to_string().as_str();
});

assert!(last_x > 0);
assert!(total_width > 0);
assert_eq!("AABCA", string);

Auto Trait Implementations

impl RefUnwindSafe for ImgFont

impl Send for ImgFont

impl Sync for ImgFont

impl Unpin for ImgFont

impl UnwindSafe for ImgFont

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.