Struct harfbuzz_rs::Font[][src]

pub struct Font<'a> { /* fields omitted */ }
Expand description

A type representing a single font (i.e. a specific combination of typeface and typesize).

It safely wraps hb_font_t.

Font Funcs

A font is one of the most important structures in harfbuzz. It coordinates how glyph information is accessed during shaping. This is done through so-called font funcs.

You can manually define new font funcs according to your needs, in most cases though the default font funcs provided by HarfBuzz will suffice. In that case the creation of a usable font amounts to calling the Font::new constructor with the desired Face.

Parents and Children

Every font except the empty font has a parent font. If a font does not have some font func set, it will automatically use the parent’s implementation of that font func. This behavior is useful to effectively “subclass” font objects to use different font function implementations for some font funcs while reusing the parent’s implementation for the remaining funcs.

Since every font created by Font::new by default uses HarfBuzz’s internal font funcs they can be used as a fallback mechanism by only customizing the font funcs of a sub-font.

Examples

Create a simple font from a Face using the default font funcs:

use harfbuzz_rs::*;
let face = Face::from_file(path, 0).expect("Error reading font file.");
let font = Font::new(face);

Implementations

Create a new font from the specified Face.

This is the default constructor of Font. In many cases it is the best choice if you simply want to shape some text.

The default parent of a font created by this function is the empty font.

Font Functions

The font returned by this function uses the font funcs that come with HarfBuzz for OpenType Fonts. The font funcs can be overwritten using Font::set_font_funcs.

Errors

If for some reason no valid font can be constructed this function will return the empty font.

Returns an empty font.

This can be useful when you need a dummy font for whatever reason. Any function you call on the empty font will return some reasonable default value. An empty font is the only font whose .parent() method returns None.

Create a new sub font from the current font that by default inherits its parent font’s face, scale, ppem and font funcs.

The sub-font’s parent will be the font on which this method is called.

Creating sub-fonts is especially useful if you want to overwrite some of the font funcs of an already existing font.

Examples

use harfbuzz_rs::*;
let face = Face::from_file(path, 0).expect("Error reading font file.");
let font = Font::new(face).to_shared();

let sub_font = Font::create_sub_font(font.clone());
// we know that sub_font has a parent
assert_eq!(sub_font.parent().unwrap(), font);

Returns a shared pointer to the parent font.

If self is the empty font it returns None.

See also

create_sub_font

Examples

The empty font (and only it) has no parent:

use harfbuzz_rs::Font;

let font = Font::empty();
assert_eq!(font.parent(), None);

Returns a shared pointer to the face from which this font was created.

Returns the EM scale of the font.

Sets the EM scale of the font.

Sets the font functions that this font will have from a value that implements FontFuncs.

Get the horizontal advance width of a glyph.

Get the vertical advance width of a glyph.

Trait Implementations

Formats the value using the given formatter. Read more

Type of the raw harfbuzz object.

Returns the underlying harfbuzz object pointer. Read more

Increases the reference count of the HarfBuzz object. Read more

Decreases the reference count of the HarfBuzz object and destroys it if the reference count reaches zero. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.