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: FontDefault upright face. Used for body text.
bold: FontBold face. Used for **strong** and headings.
italic: FontItalic / oblique face. Used for *emphasis*.
bold_italic: FontBold italic face. Used for ***bold italic*** constructs.
monospace: FontMonospace 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
impl FontFamily
Sourcepub const fn noto_sans() -> Self
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));Sourcepub const fn helvetica() -> Self
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));Sourcepub const fn times() -> Self
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));Sourcepub const fn courier() -> Self
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));Sourcepub fn resolve(
name: &str,
span: Option<SourceSpan>,
diagnostics: &mut Vec<Diagnostic>,
) -> Self
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
impl Clone for FontFamily
Source§fn clone(&self) -> FontFamily
fn clone(&self) -> FontFamily
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FontFamily
impl Debug for FontFamily
Source§impl Hash for FontFamily
impl Hash for FontFamily
Source§impl PartialEq for FontFamily
impl PartialEq for FontFamily
impl Copy for FontFamily
impl Eq for FontFamily
impl StructuralPartialEq for FontFamily
Auto Trait Implementations§
impl Freeze for FontFamily
impl RefUnwindSafe for FontFamily
impl Send for FontFamily
impl Sync for FontFamily
impl Unpin for FontFamily
impl UnsafeUnpin for FontFamily
impl UnwindSafe for FontFamily
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.