Struct ndk::font::Font

source ·
pub struct Font { /* private fields */ }
Available on crate feature api-level-29 only.
Expand description

A native AFont *

Implementations§

source§

impl Font

source

pub unsafe fn from_ptr(ptr: NonNull<AFont>) -> Self

Assumes ownership of ptr.

§Safety

ptr must be a valid owning pointer to an Android ffi::AFont.

source

pub fn ptr(&self) -> NonNull<AFont>

Returns s the pointer to the native ffi::AFont.

source

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
source

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.

source

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.

source

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.

source

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.

source

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).

source

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.

ValueNameNDK Definition
100ThinFontWeight::THIN
200Extra Light (Ultra Light)FontWeight::EXTRA_LIGHT
300LightFontWeight::LIGHT
400Normal (Regular)FontWeight::NORMAL
500MediumFontWeight::MEDIUM
600Semi Bold (Demi Bold)FontWeight::SEMI_BOLD
700BoldFontWeight::BOLD
800Extra Bold (Ultra Bold)FontWeight::EXTRA_BOLD
900Black (Heavy)FontWeight::BLACK
source

pub fn is_italic(&self) -> bool

Returns true if the current font is italic, otherwise returns false.

Trait Implementations§

source§

impl Debug for Font

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Font

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Font

§

impl RefUnwindSafe for Font

§

impl !Send for Font

§

impl !Sync for Font

§

impl Unpin for Font

§

impl UnwindSafe for Font

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.