pub struct Font { /* private fields */ }
api-level-29
only.Expand description
A native AFont *
Implementations§
source§impl Font
impl Font
sourcepub fn ptr(&self) -> NonNull<AFont>
pub fn ptr(&self) -> NonNull<AFont>
Returns s the pointer to the native ffi::AFont
.
sourcepub fn axis_count(&self) -> usize
pub fn axis_count(&self) -> usize
Returns a count of font variation settings associated with the current font.
The font variation settings are provided as multiple tag-value pairs.
For example, bold italic font may have following font variation settings: 'wght' 700
,
'slnt' -12
. In this case, Font::axis_count()
returns 2
and Font::axis_tag_at()
and
Font::axis_value_at()
return those variation names and the corresponding values.
use ndk::font::Font;
let font: Font = todo!();
for idx in 0..font.axis_count() {
log::debug!("{}: {}", font.axis_tag_at(idx), font.axis_value_at(idx));
}
// Output:
// wght: 700
// slnt: -12
sourcepub fn axis_tag_at(&self, idx: usize) -> AxisTag
pub fn axis_tag_at(&self, idx: usize) -> AxisTag
Returns an OpenType axis tag associated with the current font.
See Font::axis_count()
for more details.
sourcepub fn axis_value_at(&self, idx: usize) -> f32
pub fn axis_value_at(&self, idx: usize) -> f32
Returns an OpenType axis value associated with the current font.
See Font::axis_count()
for more details.
sourcepub fn collection_index(&self) -> usize
pub fn collection_index(&self) -> usize
Returns a font collection index value associated with the current font.
In case the target font file is a font collection (e.g. .ttc
or .otc
), this returns a
non-negative value as a font offset in the collection. This always returns 0 if the target
font file is a regular font.
sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Returns an absolute path to the current font file.
Here is a list of font formats returned by this method:
- OpenType
- OpenType Font Collection
- TrueType
- TrueType Collection
The file extension could be one of *.otf
, *.ttf
, *.otc
or *.ttc
.
The font file specified by the returned path is guaranteed to be openable with O_RDONLY
.
sourcepub fn locale(&self) -> Option<&CStr>
pub fn locale(&self) -> Option<&CStr>
Returns an IETF BCP47 compliant language tag associated with the current font.
For information about IETF BCP47, read Locale.forLanguageTag(java.lang.String)
.
sourcepub fn weight(&self) -> FontWeight
pub fn weight(&self) -> FontWeight
Returns a weight value associated with the current font.
The weight values are positive and less than or equal to 1000. Here are pairs of the common names and their values.
Value | Name | NDK Definition |
---|---|---|
100 | Thin | FontWeight::THIN |
200 | Extra Light (Ultra Light) | FontWeight::EXTRA_LIGHT |
300 | Light | FontWeight::LIGHT |
400 | Normal (Regular) | FontWeight::NORMAL |
500 | Medium | FontWeight::MEDIUM |
600 | Semi Bold (Demi Bold) | FontWeight::SEMI_BOLD |
700 | Bold | FontWeight::BOLD |
800 | Extra Bold (Ultra Bold) | FontWeight::EXTRA_BOLD |
900 | Black (Heavy) | FontWeight::BLACK |