Skip to main content

GeneratedFontSystemAdapter

Struct GeneratedFontSystemAdapter 

Source
pub struct GeneratedFontSystemAdapter<F> { /* private fields */ }
Expand description

Adapter that resolves XeTeX native font requests through a FontSystem.

Implementations§

Source§

impl<F> GeneratedFontSystemAdapter<F>

Source

pub fn new(fonts: F) -> Self

Constructs the adapter wrapping fonts.

Examples found in repository?
examples/pack_native_format.rs (lines 101-103)
72fn main() -> ExitCode {
73    let Some(output) = output_path() else {
74        eprintln!("usage: pack_native_format <output path>");
75        return ExitCode::FAILURE;
76    };
77    let Some(texmf_root) = find_texmf_root() else {
78        eprintln!("cannot find a texmf-dist ls-R index");
79        return ExitCode::FAILURE;
80    };
81    let Some(texmf) = TexmfResources::from_root(texmf_root) else {
82        eprintln!("cannot load the texmf-dist ls-R index");
83        return ExitCode::FAILURE;
84    };
85    let texmf = Arc::new(texmf);
86
87    let latex = match texmf.read("latex.ltx", ResourceKind::TexInput) {
88        Ok(resource) => resource.bytes,
89        Err(error) => {
90            eprintln!("cannot read latex.ltx: {error:?}");
91            return ExitCode::FAILURE;
92        }
93    };
94
95    let cache = GeneratedFormatCache::initialized(pe::EngineProfile::xetex());
96    let mut engine = cache
97        .instantiate(
98            pe::EngineProfile::xetex(),
99            GeneratedResourceProvider::new(&*texmf),
100        )
101        .with_font_platform(GeneratedFontSystemAdapter::new(NativeFontSystem::new(
102            texmf.clone(),
103        )));
104
105    if !engine.begin_primary_input("latex.ltx", latex) {
106        eprintln!("failed to begin latex.ltx");
107        return ExitCode::FAILURE;
108    }
109    engine.run_format_initialization();
110    if !engine.begin_primary_input("preamble.tex", PREAMBLE.to_vec()) {
111        eprintln!("failed to begin preamble");
112        return ExitCode::FAILURE;
113    }
114    engine.run_format_initialization();
115
116    engine.finalize_trie();
117    let format_bytes = GeneratedFormatCache::from_engine(&engine).to_bytes();
118    let font_table = engine.native_font_table();
119    let packaged = mathtex_engine::generated::pack_packaged_format(&format_bytes, &font_table);
120    if let Err(error) = std::fs::write(&output, packaged) {
121        eprintln!("cannot write {}: {error}", output.display());
122        return ExitCode::FAILURE;
123    }
124    ExitCode::SUCCESS
125}
Source

pub fn font_system(&self) -> &F

Returns a reference to the wrapped font system.

Source

pub fn into_font_system(self) -> F

Unwraps and returns the inner font system.

Source

pub fn loaded_font(&self, handle: GeneratedFontHandle) -> Option<&FontData>

Returns the font data for a loaded handle, or None if not found.

Trait Implementations§

Source§

impl<F: Clone> Clone for GeneratedFontSystemAdapter<F>

Source§

fn clone(&self) -> Self

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<F: Debug> Debug for GeneratedFontSystemAdapter<F>

Source§

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

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

impl<F> FontPlatform for GeneratedFontSystemAdapter<F>
where F: FontSystem,

Source§

fn resolve_font_handle( &mut self, name: &[i32], size: i32, ) -> Option<GeneratedFontHandle>

Source§

fn release_font_handle(&mut self, font: GeneratedFontHandle, _type_flag: i32)

Source§

fn font_table(&self) -> Vec<(GeneratedFontHandle, String, i32)>

Snapshot the platform’s native-font table as (handle, spec, size) tuples. A serialized format image keeps integer font handles in fontlayoutengine, but those handles only mean something to the platform that minted them; capturing the table lets a cold load rebind them.
Source§

fn restore_font_table( &mut self, table: &[(GeneratedFontHandle, String, i32)], ) -> bool

Rebuild the native-font table from a Self::font_table snapshot, (re)loading each font at its original handle so the fontlayoutengine handles preserved in a reloaded format image resolve again. Returns false if any font failed to load.
Source§

fn font_metrics(&mut self, font: GeneratedFontHandle) -> GeneratedFontMetrics

Source§

fn opentype_font_metrics( &mut self, font: GeneratedFontHandle, ) -> GeneratedFontMetrics

Source§

fn is_opentype_math_font(&mut self, font: GeneratedFontHandle) -> bool

Source§

fn using_opentype(&mut self, font: GeneratedFontHandle) -> bool

Whether font is shaped through the OpenType (HarfBuzz/rustybuzz) shaper. Mirrors XeTeX’s usingOpenType, which is true for the "ot" shaper (the default). This engine always shapes native fonts with rustybuzz, so any loaded native font handle returns true.
Source§

fn math_symbol_parameter( &mut self, font: GeneratedFontHandle, parameter: i32, ) -> i32

Source§

fn math_extension_parameter( &mut self, font: GeneratedFontHandle, parameter: i32, ) -> i32

Source§

fn opentype_math_constant( &mut self, font: GeneratedFontHandle, constant: i32, ) -> i32

Source§

fn opentype_math_accent_position( &mut self, font: GeneratedFontHandle, glyph: i32, ) -> i32

Source§

fn math_glyph_italic_correction( &mut self, font: GeneratedFontHandle, glyph: i32, ) -> i32

OpenType MATH italic correction for a glyph, in scaled points.
Source§

fn math_glyph_variant( &mut self, font: GeneratedFontHandle, glyph: i32, index: u16, horizontal: bool, ) -> Option<GeneratedMathVariant>

The index-th larger MATH glyph variant of glyph (horizontal or vertical), or None when there is no such variant. The advance is in scaled points.
Source§

fn math_glyph_assembly( &mut self, font: GeneratedFontHandle, glyph: i32, horizontal: bool, ) -> Vec<GeneratedMathAssemblyPart> ⓘ

The MATH glyph-assembly parts for glyph (horizontal or vertical), each metric in scaled points. Empty when the glyph has no assembly.
Source§

fn math_min_connector_overlap(&mut self, font: GeneratedFontHandle) -> i32

The MATH minimum connector overlap for assembly parts, in scaled points.
Source§

fn math_kern_at( &mut self, font: GeneratedFontHandle, glyph: i32, corner: GeneratedMathKernCorner, correction_height: i32, ) -> i32

One MATH MathKernInfo corner evaluated at correction_height (font design units), returned in raw font design units (NOT scaled).
Source§

fn math_points_to_units( &mut self, font: GeneratedFontHandle, points: f32, ) -> f32

Convert a measurement in points to font design units for font (pointsToUnits).
Source§

fn math_units_to_scaled(&mut self, font: GeneratedFontHandle, units: i32) -> i32

Convert a measurement in font design units to scaled points for font (D2Fix(unitsToPoints(...))).
Source§

fn math_point_size(&mut self, font: GeneratedFontHandle) -> f32

The point size at which font was loaded (getPointSize).
Source§

fn map_char_to_glyph( &mut self, font: GeneratedFontHandle, codepoint: i32, ) -> i32

Source§

fn map_glyph_to_index(&mut self, font: GeneratedFontHandle, name: &str) -> i32

Source§

fn ot_font_get( &mut self, font: GeneratedFontHandle, what: i32, param1: i32, param2: i32, param3: i32, ) -> i32

OpenType layout enumeration backing the \XeTeXOT* / \XeTeXcountglyphs last_item primitives (XeTeX ot_font_get/_1/_2/_3). what is the XeTeX_ext code (1 = count glyphs, 16 = count scripts, 17 = count languages, 18 = count features, 19 = script tag, 20 = language tag, 21 = feature tag); unused params are 0.
Source§

fn font_spec(&self, font: GeneratedFontHandle) -> Option<String>

The \font spec string a loaded handle was created from (e.g. [latinmodern-math.otf]:script=math;ssty=1). Immutable so the read-only IR-building path can recover the originating font file for a glyph run.
Source§

fn shape_native_text( &mut self, font: GeneratedFontHandle, text: &[u16], _use_glyph_metrics: bool, ) -> GeneratedNativeTextMetrics

Source§

fn measure_native_glyph( &mut self, font: GeneratedFontHandle, glyph: u16, _use_glyph_metrics: bool, ) -> GeneratedNativeGlyphMetrics

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GeneratedFontPlatform for T
where T: FontPlatform,

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
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.