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 face from which this font was created.
pub fn set_font_funcs<FuncsType>(&mut self, funcs: FuncsType) where
FuncsType: 'a + Send + Sync + FontFuncs,
pub fn set_font_funcs<FuncsType>(&mut self, funcs: FuncsType) where
FuncsType: 'a + Send + Sync + FontFuncs,
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
Decreases the reference count of the HarfBuzz object and destroys it if the reference count reaches zero. Read more