Skip to main content

FontFamily

Struct FontFamily 

Source
pub struct FontFamily {
    pub regular: Font,
    pub bold: Font,
    pub italic: Font,
    pub bold_italic: Font,
    pub monospace: Font,
    pub fallbacks: &'static [EmbeddedFontId],
}
Expand description

A four-cut family: Regular, Bold, Italic, BoldItalic. The layout engine picks one slot per styled run (*emphasis* → italic, **strong** → bold, raw → fixed-width family, body → regular).

Build via FontFamily::resolve, which understands Base14 family names and the bundled "Noto Sans" family. Unknown names fall back to Noto Sans and emit a MOS0018 diagnostic.

§Examples

use mos_fonts::{Font, FontFamily, EmbeddedFontId};

let family = FontFamily::noto_sans();

assert_eq!(family.regular, Font::Embedded(EmbeddedFontId::Regular));

Fields§

§regular: Font

Default upright face. Used for body text.

§bold: Font

Bold face. Used for **strong** and headings.

§italic: Font

Italic / oblique face. Used for *emphasis*.

§bold_italic: Font

Bold italic face. Used for ***bold italic*** constructs.

§monospace: Font

Monospace face. Used for `raw` runs. The four-slot family concept is upright/styled-Latin; raw is its own typeface choice that the layout engine pins independently of the family.

§fallbacks: &'static [EmbeddedFontId]

Per-glyph fallback chain shared by every style slot in this family. When shaping against any of the style-slot faces above yields .notdef for some cluster, crate::shape_with_fallback retries that cluster against each embedded face in this slice in order. The first face to cover the cluster wins the whole cluster (cluster-granular replacement). Math fallback is therefore upright even inside bold or italic text until style-aware fallback chains exist. Empty chain = primary-only shaping (Base14 families don’t have an embedded fallback target).

Implementations§

Source§

impl FontFamily

Source

pub const fn noto_sans() -> Self

The bundled Noto Sans family: embedded TTFs, real designed cuts for every style slot (no faux-bold or faux-italic). Raw runs route through the bundled Noto Sans Mono Regular cut so `Привет` and other non-WinAnsi raw content shape through the same rustybuzz + /ToUnicode pipeline as body text instead of dropping to the Base14 ? substitution.

Per-glyph fallback chain: [Math]. Codepoints not in Noto Sans (math operators like ≤ ≥ √ ∂ ∑ ∆ ◊) shape against the bundled Noto Sans Math cut.

§Examples
use mos_fonts::{EmbeddedFontId, Font, FontFamily};

let family = FontFamily::noto_sans();

assert_eq!(family.monospace, Font::Embedded(EmbeddedFontId::Mono));
Source

pub const fn helvetica() -> Self

The Base14 Helvetica family. Used when the document explicitly asks for Helvetica. Falls back through Courier for raw.

Base14 has no per-glyph fallback target; the byte-encoded content stream path can’t splice in glyph IDs from a sibling face. Non-WinAnsi codepoints silently substitute to ? in mos-pdf::encode_base14_run.

§Examples
use mos_fonts::{Base14Font, Font, FontFamily};

let family = FontFamily::helvetica();

assert_eq!(family.regular, Font::Base14(Base14Font::Helvetica));
Source

pub const fn times() -> Self

The Base14 Times Roman family. Used when the document asks for Times or Times-Roman. No per-glyph fallback: see Self::helvetica.

§Examples
use mos_fonts::{Base14Font, Font, FontFamily};

let family = FontFamily::times();

assert_eq!(family.bold, Font::Base14(Base14Font::TimesBold));
Source

pub const fn courier() -> Self

The Base14 Courier family. Used when the document asks for Courier as the body face. All four style slots route to a Courier cut. No per-glyph fallback; see Self::helvetica.

§Examples
use mos_fonts::{Base14Font, Font, FontFamily};

let family = FontFamily::courier();

assert_eq!(family.italic, Font::Base14(Base14Font::CourierOblique));
Source

pub fn resolve( name: &str, span: Option<SourceSpan>, diagnostics: &mut Vec<Diagnostic>, ) -> Self

Resolve a #set text(font: ...) name to a family.

Matching is case-insensitive on the family component. Known names: Helvetica, Times/Times-Roman/Times Roman, Courier, Noto Sans. Anything else falls back to Noto Sans and pushes a MOS0018 notice so users don’t silently get the wrong typeface.

§Examples
use mos_fonts::{Base14Font, Font, FontFamily};

let mut diagnostics = Vec::new();
let family = FontFamily::resolve("Times", None, &mut diagnostics);

assert_eq!(family.regular, Font::Base14(Base14Font::TimesRoman));
assert!(diagnostics.is_empty());

Trait Implementations§

Source§

impl Clone for FontFamily

Source§

fn clone(&self) -> FontFamily

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FontFamily

Source§

impl Debug for FontFamily

Source§

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

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

impl Eq for FontFamily

Source§

impl Hash for FontFamily

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FontFamily

Source§

fn eq(&self, other: &FontFamily) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FontFamily

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

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

Source§

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>,

Source§

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.