From 75db98b01894d0e8fdd2cc61750cd7228a9d7893 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Sun, 7 Feb 2021 19:36:01 +0300 Subject: [PATCH] Font -> Option --- Cargo.lock | 13 +++ engine/Cargo.toml | 1 + engine/src/fmt_file.rs | 6 +- engine/src/text_layout_engine.rs | 19 ++++ engine/src/tfm.rs | 10 +-- engine/src/xetex_aatfont.rs | 10 ++- engine/src/xetex_ext.rs | 88 ++++++------------ engine/src/xetex_ini.rs | 9 +- engine/src/xetex_layout_interface.rs | 6 +- engine/src/xetex_math.rs | 130 +++++++++++++-------------- engine/src/xetex_opentype_math.rs | 29 +++--- engine/src/xetex_shipout.rs | 4 +- engine/src/xetex_xetex0.rs | 111 +++++++++++------------ 13 files changed, 211 insertions(+), 225 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69d506201..9a8b513f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,6 +481,18 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum_dispatch" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8946e241a7774d5327d92749c50806f275f57d031d2229ecbfd65469a8ad338e" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "enumn" version = "0.1.2" @@ -1900,6 +1912,7 @@ dependencies = [ "core-graphics 0.22.1", "core-text 19.1.0", "derive_more", + "enum_dispatch", "enumn", "euclid", "freetype-rs", diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 137be54c7..456f1ceb5 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -44,6 +44,7 @@ derive_more = "0.99.7" md5 = "0.7" fontconfig_sys = { package = "yeslogic-fontconfig-sys", version = "2.11.1" } once_cell = "1.5.2" +enum_dispatch = "0.3.5" [target.'cfg(target_os = "macos")'.dependencies] core-foundation = "0.9.1" diff --git a/engine/src/fmt_file.rs b/engine/src/fmt_file.rs index 2281d6aae..148502a63 100644 --- a/engine/src/fmt_file.rs +++ b/engine/src/fmt_file.rs @@ -389,9 +389,7 @@ pub(crate) unsafe fn store_fmt_file() { Esc(&PoolString::from(yhash[FONT_ID_BASE + k - hash_offset].s1).to_string()) ); - if matches!(&FONT_LAYOUT_ENGINE[k], crate::xetex_ext::Font::Native(_)) - || !(FONT_MAPPING[k]).is_null() - { + if matches!(&FONT_LAYOUT_ENGINE[k], Some(_)) || !(FONT_MAPPING[k]).is_null() { t_print!( "{:#}", FileName { @@ -854,7 +852,7 @@ pub(crate) unsafe fn load_fmt_file() -> bool { FONT_MAPPING = vec![ptr::null_mut(); FONT_MAX + 1]; for _ in 0..FONT_MAX + 1 { - FONT_LAYOUT_ENGINE.push(crate::xetex_ext::Font::None); + FONT_LAYOUT_ENGINE.push(None); } FONT_FLAGS = vec![0; FONT_MAX + 1]; FONT_LETTER_SPACE = vec![Scaled::ZERO; FONT_MAX + 1]; diff --git a/engine/src/text_layout_engine.rs b/engine/src/text_layout_engine.rs index 4b1ee9fda..9fa8e1d5e 100644 --- a/engine/src/text_layout_engine.rs +++ b/engine/src/text_layout_engine.rs @@ -6,6 +6,7 @@ use crate::xetex_font_info::{GlyphBBox, XeTeXFontInst}; //use crate::xetex_font_manager::PlatformFontRef; use crate::xetex_font_info::GlyphID; use crate::xetex_layout_interface::FixedPoint; +use crate::xetex_layout_interface::XeTeXLayoutEngine; use crate::xetex_scaledmath::Scaled; use harfbuzz_sys::hb_tag_t; @@ -174,6 +175,24 @@ impl GlyphEdge { } } +#[enum_dispatch::enum_dispatch] +pub(crate) enum NativeFont { + #[cfg(target_os = "macos")] + Aat(crate::xetex_aatfont::AATLayoutEngine), + Otgr(XeTeXLayoutEngine), +} + +impl NativeFont { + pub(crate) fn flag(&self) -> u32 { + match self { + #[cfg(target_os = "macos")] + Self::Aat(_) => 0xFFFF, + Self::Otgr(_) => 0xFFFE, + } + } +} + +#[enum_dispatch::enum_dispatch(NativeFont)] pub(crate) trait TextLayoutEngine { /// The most important trait method. Lay out some text and return its size. unsafe fn layout_text(&mut self, request: LayoutRequest) -> NodeLayout; diff --git a/engine/src/tfm.rs b/engine/src/tfm.rs index 1c3341058..2edfe52a4 100644 --- a/engine/src/tfm.rs +++ b/engine/src/tfm.rs @@ -1,7 +1,7 @@ use bridge::TTInputFormat; use crate::help; -use crate::text_layout_engine::TextLayoutEngine; +use crate::text_layout_engine::{NativeFont::*, TextLayoutEngine}; use std::ptr; use crate::{t_eprint, t_print, t_print_nl}; @@ -50,9 +50,9 @@ use crate::xetex_ini::{ }; use crate::xetex_stringpool::{pool_ptr, str_pool}; -use crate::xetex_ext::ot_get_font_metrics; -use crate::xetex_ext::{check_for_tfm_font_mapping, load_tfm_font_mapping}; -use crate::xetex_ext::{find_native_font, NativeFont::*}; +use crate::xetex_ext::{ + check_for_tfm_font_mapping, find_native_font, load_tfm_font_mapping, ot_get_font_metrics, +}; use super::xetex_io::tt_xetex_open_input; use crate::xetex_consts::get_int_par; @@ -661,7 +661,7 @@ pub(crate) unsafe fn load_native_font(name: &str, s: Scaled) -> Result CTFontRef { font_from_attributes(self.attributes) @@ -741,7 +749,7 @@ unsafe fn getLastResort() -> CFStringRef { return kLastResort; } -use crate::xetex_ext::{NativeFont, NativeFont::*}; +use crate::text_layout_engine::{NativeFont, NativeFont::*}; pub(crate) unsafe fn loadAATfont( mut descriptor: CTFontDescriptorRef, diff --git a/engine/src/xetex_ext.rs b/engine/src/xetex_ext.rs index aa3fe22e0..41cd067c1 100644 --- a/engine/src/xetex_ext.rs +++ b/engine/src/xetex_ext.rs @@ -40,39 +40,7 @@ pub(crate) use crate::xetex_scaledmath::Scaled; use crate::xetex_layout_interface::*; use harfbuzz_sys::{hb_feature_t, hb_tag_from_string, hb_tag_t}; -pub(crate) enum Font { - None, - Native(NativeFont), -} - -pub(crate) enum NativeFont { - #[cfg(target_os = "macos")] - Aat(crate::xetex_aatfont::AATLayoutEngine), - Otgr(Box), -} -impl Drop for NativeFont { - fn drop(&mut self) { - #[cfg(target_os = "macos")] - match self { - Self::Aat(engine) => unsafe { - CFRelease(engine.attributes as CFDictionaryRef as CFTypeRef) - }, - _ => {} - } - } -} - -impl NativeFont { - pub(crate) fn flag(&self) -> u32 { - match self { - #[cfg(target_os = "macos")] - Self::Aat(_) => 0xFFFF, - Self::Otgr(_) => 0xFFFE, - } - } -} - -use NativeFont::*; +use crate::text_layout_engine::{NativeFont, NativeFont::*}; /* 16.16 version number */ @@ -168,7 +136,7 @@ pub(crate) unsafe fn linebreak_start(f: usize, localeStrNum: i32, text: &[u16]) let mut status: icu::UErrorCode = icu::U_ZERO_ERROR; let locale = gettexstring(localeStrNum); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(engine)) if locale == "G" => { + Some(Otgr(engine)) if locale == "G" => { if initGraphiteBreaking(engine, text) { /* user asked for Graphite line breaking and the font supports it */ return; @@ -1107,7 +1075,7 @@ pub(crate) unsafe fn make_font_def(f: usize) -> Vec { let mut embolden: f32 = 0.; match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { filename = engine.font_filename(&mut index); assert!(!filename.is_empty()); if !CFDictionaryGetValue( @@ -1124,7 +1092,7 @@ pub(crate) unsafe fn make_font_def(f: usize) -> Vec { embolden = engine.embolden_factor(); size = Scaled::from(engine.point_size()); } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { /* fontRef = */ //getFontRef(engine); filename = engine.font_filename(&mut index); @@ -1230,11 +1198,11 @@ pub(crate) unsafe fn get_native_char_height_depth(font: usize, ch: char) -> (Sca const CAP_HEIGHT: i32 = 8; let (ht, dp) = match &FONT_LAYOUT_ENGINE[font] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { let gid = engine.map_char_to_glyph(ch) as i32; engine.glyph_height_depth(gid as u32).unwrap() } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { let gid = engine.map_char_to_glyph(ch) as i32; engine.glyph_height_depth(gid as u32).unwrap() } @@ -1289,14 +1257,14 @@ pub(crate) unsafe fn get_glyph_bounds(font: usize, edge: i32, gid: i32) -> Scale /* edge codes 1,2,3,4 => L T R B */ let (a, b) = match &FONT_LAYOUT_ENGINE[font] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { if edge.is_side() { engine.glyph_sidebearings(gid as u32).unwrap() } else { engine.glyph_height_depth(gid as u32).unwrap() } } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { if edge.is_side() { engine.glyph_sidebearings(gid as u32).unwrap() } else { @@ -1323,11 +1291,11 @@ pub(crate) unsafe fn getnativecharic(f: &NativeFont, letter_space: Scaled, c: ch pub(crate) unsafe fn getnativecharwd(f: usize, c: char) -> Scaled { match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { let gid = engine.map_char_to_glyph(c) as i32; (engine.get_glyph_width_from_engine(gid as u32) as f64).into() } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { let gid = engine.map_char_to_glyph(c) as i32; (engine.get_glyph_width_from_engine(gid as u32) as f64).into() } @@ -1346,14 +1314,14 @@ pub(crate) unsafe fn store_justified_native_glyphs(node: &mut NativeWord) { let f = node.font() as usize; match &mut FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { /* separate Mac-only codepath for AAT fonts */ let request = LayoutRequest::from_node(node, true); let layout = engine.layout_text(request); layout.write_node(node); return; } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { /* save desired width */ let savedWidth = node.width(); node.set_metrics(false); @@ -1399,11 +1367,11 @@ pub(crate) unsafe fn measure_native_node(node: &mut NativeWord, use_glyph_metric let request = LayoutRequest::from_node(node, false); let layout = match &mut FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { /* we're using this font in AAT mode, so font_layout_engine[f] is actually a CFDictionaryRef */ engine.layout_text(request) } - Font::Native(Otgr(engine)) => engine.layout_text(request), + Some(Otgr(engine)) => engine.layout_text(request), _ => panic!("bad native font flag in `measure_native_node`"), }; layout.write_node(node); @@ -1424,11 +1392,9 @@ pub(crate) unsafe fn measure_native_node(node: &mut NativeWord, use_glyph_metric let bbox = getCachedGlyphBBox(f as u16, glyph_ids[i]).unwrap_or_else(|| { let bbox = match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { - aat::GetGlyphBBox_AAT(engine.attributes, glyph_ids[i]) - .unwrap_or(GlyphBBox::zero()) - } - Font::Native(Otgr(engine)) => engine + Some(Aat(engine)) => aat::GetGlyphBBox_AAT(engine.attributes, glyph_ids[i]) + .unwrap_or(GlyphBBox::zero()), + Some(Otgr(engine)) => engine .font .get_glyph_bounds(glyph_ids[i]) .unwrap_or(GlyphBBox::zero()), @@ -1457,14 +1423,14 @@ pub(crate) unsafe fn real_get_native_italic_correction(node: &NativeWord) -> Sca let glyph_ids = node.glyph_ids(); match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { Scaled::from( engine .glyph_ital_correction(glyph_ids[n - 1] as u32) .unwrap() as f64, ) + FONT_LETTER_SPACE[f] } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { Scaled::from( engine .glyph_ital_correction(glyph_ids[n - 1] as u32) @@ -1482,12 +1448,8 @@ pub(crate) unsafe fn real_get_native_glyph_italic_correction(node: &Glyph) -> Sc let f = node.font() as usize; match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { - (engine.glyph_ital_correction(gid as u32).unwrap() as f64).into() - } - Font::Native(Otgr(engine)) => { - (engine.glyph_ital_correction(gid as u32).unwrap() as f64).into() - } + Some(Aat(engine)) => (engine.glyph_ital_correction(gid as u32).unwrap() as f64).into(), + Some(Otgr(engine)) => (engine.glyph_ital_correction(gid as u32).unwrap() as f64).into(), _ => { Scaled::ZERO /* can't actually happen */ @@ -1499,7 +1461,7 @@ pub(crate) unsafe fn measure_native_glyph(node: &mut Glyph, use_glyph_metrics: b let f = node.font() as usize; let (ht, dp) = match &FONT_LAYOUT_ENGINE[f] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => { + Some(Aat(engine)) => { node.set_width((engine.glyph_width(gid as u32)).into()); if use_glyph_metrics { engine.glyph_height_depth(gid as u32).unwrap() @@ -1507,7 +1469,7 @@ pub(crate) unsafe fn measure_native_glyph(node: &mut Glyph, use_glyph_metrics: b (0., 0.) } } - Font::Native(Otgr(engine)) => { + Some(Otgr(engine)) => { node.set_width((engine.glyph_width(gid as u32)).into()); if use_glyph_metrics { engine.glyph_height_depth(gid as u32).unwrap() @@ -1543,8 +1505,8 @@ pub(crate) unsafe fn map_glyph_to_index(font: &NativeFont, name: &str) -> i32 { pub(crate) unsafe fn get_font_char_range(font: usize, first: i32) -> i32 { match &mut FONT_LAYOUT_ENGINE[font] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => engine.font_char_range(first), - Font::Native(Otgr(engine)) => engine.font_char_range(first), + Some(Aat(engine)) => engine.font_char_range(first), + Some(Otgr(engine)) => engine.font_char_range(first), _ => panic!("bad native font flag in `get_font_char_range\'`"), } } diff --git a/engine/src/xetex_ini.rs b/engine/src/xetex_ini.rs index 8ab866cf6..f499c262c 100644 --- a/engine/src/xetex_ini.rs +++ b/engine/src/xetex_ini.rs @@ -722,9 +722,8 @@ pub(crate) static mut FONT_BCHAR: Vec = Vec::new(); #[no_mangle] pub(crate) static mut FONT_FALSE_BCHAR: Vec = Vec::new(); -use crate::xetex_ext::Font; - -pub(crate) static mut FONT_LAYOUT_ENGINE: Vec = Vec::new(); +use crate::text_layout_engine::NativeFont; +pub(crate) static mut FONT_LAYOUT_ENGINE: Vec> = Vec::new(); #[no_mangle] pub(crate) static mut FONT_MAPPING: Vec<*mut libc::c_void> = Vec::new(); #[no_mangle] @@ -2038,7 +2037,7 @@ pub(crate) unsafe fn prefixed_command( } else { SKEW_CHAR[f] = val } } _ => { - let p = if let Font::Native(nf) = &FONT_LAYOUT_ENGINE[f] { + let p = if let Some(nf) = &FONT_LAYOUT_ENGINE[f] { scan_glyph_number(input, nf) } else { scan_char_num(input) }; scan_optional_equals(input); @@ -4216,7 +4215,7 @@ pub(crate) unsafe fn tt_run_engine(dump_name: &str, input_file_name: &str) -> TT FONT_MAPPING = vec![ptr::null_mut(); FONT_MAX + 1]; FONT_LAYOUT_ENGINE.clear(); for _ in 0..FONT_MAX + 1 { - FONT_LAYOUT_ENGINE.push(Font::None); + FONT_LAYOUT_ENGINE.push(None); } FONT_FLAGS = vec![0; FONT_MAX + 1]; FONT_LETTER_SPACE = vec![Scaled::ZERO; FONT_MAX + 1]; diff --git a/engine/src/xetex_layout_interface.rs b/engine/src/xetex_layout_interface.rs index ba13b5430..af5a78448 100644 --- a/engine/src/xetex_layout_interface.rs +++ b/engine/src/xetex_layout_interface.rs @@ -1243,7 +1243,7 @@ impl XeTeXLayoutEngine { slant: f32, embolden: f32, shaperRequest: Option, - ) -> Box { + ) -> Self { let language = if shaperRequest == Some(ShaperRequest::Graphite) { hb_language_from_string(language.as_ptr() as *const i8, language.len() as _) } else { @@ -1266,7 +1266,7 @@ impl XeTeXLayoutEngine { //ptr::write(&mut (*result).shaper_list, shapers.freeze()); - Box::new(Self { + Self { fontRef, font, script, @@ -1282,7 +1282,7 @@ impl XeTeXLayoutEngine { // treat it as a OT language tag for backward compatibility with pre-0.9999 // XeTeX. language, - }) + } } pub(crate) fn release(self) -> Box { let Self { font, .. } = self; diff --git a/engine/src/xetex_math.rs b/engine/src/xetex_math.rs index 66cf32a32..fcac73cff 100644 --- a/engine/src/xetex_math.rs +++ b/engine/src/xetex_math.rs @@ -5,10 +5,10 @@ use crate::{t_eprint, t_print}; use crate::cmd::*; use crate::help; use crate::node::*; +use crate::text_layout_engine::NativeFont::*; use crate::text_layout_engine::TextLayoutEngine; use crate::xetex_consts::*; use crate::xetex_errors::{confusion, error, Confuse}; -use crate::xetex_ext::{Font, NativeFont::*}; use crate::xetex_ini::{ adjust_tail, avail, cur_dir, cur_f, cur_group, cur_i, cur_lang, cur_list, input_state_t, insert_src_special_every_math, just_box, memory_word, pre_adjust_tail, total_shrink, @@ -913,11 +913,11 @@ pub(crate) unsafe fn after_math(input: &mut input_state_t) { j = cur_list.eTeX_aux; // :1530 } if FONT_PARAMS[MATH_FONT(2 + TEXT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + TEXT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + TEXT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(2 + SCRIPT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) { t_eprint!("Math formula deleted: Insufficient symbol fonts"); @@ -930,11 +930,11 @@ pub(crate) unsafe fn after_math(input: &mut input_state_t) { flush_math(); danger = true } else if FONT_PARAMS[MATH_FONT(3 + TEXT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + TEXT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + TEXT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(3 + SCRIPT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) { t_eprint!("Math formula deleted: Insufficient extension fonts"); @@ -977,11 +977,11 @@ pub(crate) unsafe fn after_math(input: &mut input_state_t) { j = cur_list.eTeX_aux } if FONT_PARAMS[MATH_FONT(2 + TEXT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + TEXT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + TEXT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(2 + SCRIPT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)] < TOTAL_MATHSY_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(2 + SCRIPT_SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) { t_print!("Math formula deleted: Insufficient symbol fonts"); @@ -994,11 +994,11 @@ pub(crate) unsafe fn after_math(input: &mut input_state_t) { flush_math(); danger = true } else if FONT_PARAMS[MATH_FONT(3 + TEXT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + TEXT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + TEXT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(3 + SCRIPT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) || FONT_PARAMS[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)] < TOTAL_MATHEX_PARAMS - && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[MATH_FONT(3 + SCRIPT_SCRIPT_SIZE)], Some(Otgr(e)) if e.is_open_type_math_font()) { t_eprint!("Math formula deleted: Insufficient extension fonts"); @@ -1202,165 +1202,161 @@ pub(crate) unsafe fn resume_after_display(input: &mut input_state_t) { unsafe fn math_x_height(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { - get_native_mathsy_param(f, X_HEIGHT_CODE) - } + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, X_HEIGHT_CODE), _ => Scaled(FONT_INFO[(X_HEIGHT_CODE + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn math_quad(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { - get_native_mathsy_param(f, QUAD_CODE) - } + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, QUAD_CODE), _ => Scaled(FONT_INFO[(QUAD_CODE + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn num1(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 8), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 8), _ => Scaled(FONT_INFO[(8 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn num2(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 9), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 9), _ => Scaled(FONT_INFO[(9 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn num3(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 10), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 10), _ => Scaled(FONT_INFO[(10 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn denom1(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 11), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 11), _ => Scaled(FONT_INFO[(11 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn denom2(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 12), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 12), _ => Scaled(FONT_INFO[(12 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sup1(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 13), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 13), _ => Scaled(FONT_INFO[(13 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sup2(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 14), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 14), _ => Scaled(FONT_INFO[(14 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sup3(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 15), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 15), _ => Scaled(FONT_INFO[(15 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sub1(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 16), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 16), _ => Scaled(FONT_INFO[(16 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sub2(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 17), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 17), _ => Scaled(FONT_INFO[(17 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sup_drop(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 18), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 18), _ => Scaled(FONT_INFO[(18 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn sub_drop(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code) as usize; match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 19), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 19), _ => Scaled(FONT_INFO[(19 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn delim1(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 20), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 20), _ => Scaled(FONT_INFO[(20 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn delim2(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 21), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 21), _ => Scaled(FONT_INFO[(21 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn axis_height(size_code: usize) -> Scaled { let f = MATH_FONT(2 + size_code); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 22), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathsy_param(f, 22), _ => Scaled(FONT_INFO[(22 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn default_rule_thickness() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 8), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 8), _ => Scaled(FONT_INFO[(8 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn big_op_spacing1() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 9), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 9), _ => Scaled(FONT_INFO[(9 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn big_op_spacing2() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 10), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 10), _ => Scaled(FONT_INFO[(10 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn big_op_spacing3() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 11), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 11), _ => Scaled(FONT_INFO[(11 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn big_op_spacing4() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 12), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 12), _ => Scaled(FONT_INFO[(12 + PARAM_BASE[f]) as usize].b32.s1), } } unsafe fn big_op_spacing5() -> Scaled { let f = MATH_FONT(3 + cur_size); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 13), + Some(Otgr(e)) if e.is_open_type_math_font() => get_native_mathex_param(f, 13), _ => Scaled(FONT_INFO[(13 + PARAM_BASE[f]) as usize].b32.s1), } } @@ -1501,7 +1497,7 @@ pub(crate) unsafe fn fetch(a: &mut MCell) -> (usize, char) { error(); cur_i = NULL_CHARACTER; a.typ = MathCell::Empty; - } else if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f as usize] { + } else if let Some(_) = &FONT_LAYOUT_ENGINE[f as usize] { cur_i = NULL_CHARACTER } else { if c as i32 >= FONT_BC[f as usize] as i32 && c as i32 <= FONT_EC[f as usize] as i32 { @@ -1555,14 +1551,14 @@ unsafe fn make_vcenter(q: usize) { unsafe fn make_radical(q: &mut Radical) { let f = MATH_FONT(q.delimeter().chr1.family as usize + cur_size); let rule_thickness = match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { get_ot_math_constant(f, RADICALRULETHICKNESS) } _ => default_rule_thickness(), }; let x = clean_box(q.nucleus(), (cur_style.0, 1)); let mut clr = match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { if cur_style.0 == MathStyle::Display { get_ot_math_constant(f, RADICALDISPLAYSTYLEVERTICALGAP) } else { @@ -1584,7 +1580,7 @@ unsafe fn make_radical(q: &mut Radical) { x.height() + x.depth() + clr + rule_thickness, )); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { let h = y.height(); let d = y.depth(); y.set_depth(h + d - rule_thickness); @@ -1628,7 +1624,7 @@ unsafe fn make_math_accent(q: &mut Accent) { cur_f = fnt; let mut c; let f; - let x = if let Font::Native(_) = &FONT_LAYOUT_ENGINE[fnt as usize] { + let x = if let Some(_) = &FONT_LAYOUT_ENGINE[fnt as usize] { c = chr as i32; f = fnt; s = match q.accent_type() { @@ -1701,7 +1697,7 @@ unsafe fn make_math_accent(q: &mut Accent) { // :767 if let Some(mut x) = x { let mut delta = match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => match q.accent_type() { + Some(Otgr(e)) if e.is_open_type_math_font() => match q.accent_type() { AccentType::Bottom | AccentType::BottomFixed => Scaled::ZERO, _ => h.min(get_ot_math_constant(f, ACCENTBASEHEIGHT)), }, @@ -1726,7 +1722,7 @@ unsafe fn make_math_accent(q: &mut Accent) { h = x.height(); } let mut y = char_box(f, c); - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { let mut p = Glyph::new_node(); p.set_font(f as u16); let nw = NativeWord::from(y.list_ptr() as usize); @@ -1879,7 +1875,7 @@ unsafe fn make_fraction(q: &mut Fraction) { if q.thickness() == Scaled::ZERO { /*772:*/ let clr = match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { if cur_style.0 == MathStyle::Display { get_ot_math_constant(cur_f, STACKDISPLAYSTYLEGAPMIN) } else { @@ -1903,7 +1899,7 @@ unsafe fn make_fraction(q: &mut Fraction) { let delta1; let delta2; match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { delta = q.thickness().half(); let clr = if cur_style.0 == MathStyle::Display { get_ot_math_constant(cur_f, FRACTIONNUMDISPLAYSTYLEGAPMIN) @@ -1978,7 +1974,7 @@ unsafe fn make_op(q: &mut Operator) -> Scaled { let (f, _) = q.nucleus_mut().fetch(); cur_f = f; match &FONT_LAYOUT_ENGINE[f as usize] { - Font::Native(Otgr(e)) if e.using_open_type() => {} + Some(Otgr(e)) if e.using_open_type() => {} _ => { if cur_style.0 == MathStyle::Display && cur_i.s1 as i32 % 4 == LIST_TAG { let c = cur_i.s0; @@ -1993,7 +1989,7 @@ unsafe fn make_op(q: &mut Operator) -> Scaled { } let mut x = clean_box(q.nucleus(), cur_style); match &FONT_LAYOUT_ENGINE[f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { if let Some(p) = x.list_ptr().opt() { if let CharOrText::Text(TxtNode::WhatsIt(WhatsIt::Glyph(mut p))) = CharOrText::from(p) @@ -2286,7 +2282,7 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { x.set_width(w + get_dimen_par(DimenPar::script_space)); shift_down = shift_down.max(sub1(cur_size)); let clr = match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { x.height() - get_ot_math_constant(cur_f, SUBSCRIPTTOPMAX) } _ => x.height() - (math_x_height(cur_size) * 4).abs() / 5, @@ -2295,13 +2291,13 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { shift_down = clr; } x.set_shift_amount(shift_down); - if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Font::Native(Otgr(eng)) if eng.is_open_type_math_font()) + if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Some(Otgr(eng)) if eng.is_open_type_math_font()) { /*787: */ if q.subscr().typ == MathCell::MathChar { let (f, c) = q.subscr_mut().fetch(); match &FONT_LAYOUT_ENGINE[f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { let script_c = new_native_character(f, c); script_g = script_c.native_glyph(0); script_f = f; @@ -2352,7 +2348,7 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { shift_up = clr } let clr = match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { x.depth() + get_ot_math_constant(cur_f, SUPERSCRIPTBOTTOMMIN) } _ => x.depth() + math_x_height(cur_size).abs() / 4, @@ -2360,13 +2356,13 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { if shift_up < clr { shift_up = clr } - if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Some(Otgr(e)) if e.is_open_type_math_font()) { // 788: if q.supscr().typ == MathCell::MathChar { let (f, c) = q.supscr_mut().fetch(); match &FONT_LAYOUT_ENGINE[f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { let script_c = new_native_character(f, c); script_g = script_c.native_glyph(0); script_f = f @@ -2413,7 +2409,7 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { shift_down = sub2(cur_size) } let mut clr = match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { get_ot_math_constant(cur_f, SUBSUPERSCRIPTGAPMIN) - (shift_up - x.depth() - (y.height() - shift_down)) } @@ -2425,7 +2421,7 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { if clr > Scaled::ZERO { shift_down += clr; match &FONT_LAYOUT_ENGINE[cur_f as usize] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { clr = get_ot_math_constant(cur_f, SUPERSCRIPTBOTTOMMAXWITHSUBSCRIPT) - (shift_up - x.depth()) } @@ -2436,12 +2432,12 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { shift_down -= clr } } - if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Font::Native(Otgr(eng)) if eng.is_open_type_math_font()) + if matches!(&FONT_LAYOUT_ENGINE[cur_f as usize], Some(Otgr(eng)) if eng.is_open_type_math_font()) { if q.subscr().typ == MathCell::MathChar { let (f, c) = q.subscr_mut().fetch(); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { let script_c = new_native_character(f, c); script_g = script_c.native_glyph(0); script_f = f @@ -2470,7 +2466,7 @@ unsafe fn make_scripts(q: &mut BaseMath, delta: Scaled) { if q.supscr().typ == MathCell::MathChar { let (f, c) = q.supscr_mut().fetch(); match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.is_open_type_math_font() => { + Some(Otgr(e)) if e.is_open_type_math_font() => { let script_c = new_native_character(f, c); script_g = script_c.native_glyph(0); script_f = f @@ -2636,7 +2632,7 @@ unsafe fn mlist_to_hlist() { MathCell::MathChar | MathCell::MathTextChar => { let (f, c) = q.nucleus_mut().fetch(); cur_f = f; - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { let z = new_native_character(f, c); let mut p = Glyph::new_node(); p.set_font(f as u16); @@ -2645,7 +2641,7 @@ unsafe fn mlist_to_hlist() { z.free(); delta = get_ot_math_ital_corr(f, p.glyph() as i32); if q.nucleus().typ == MathCell::MathTextChar - && !matches!(&FONT_LAYOUT_ENGINE[f], Font::Native(Otgr(e)) if e.is_open_type_math_font()) + && !matches!(&FONT_LAYOUT_ENGINE[f], Some(Otgr(e)) if e.is_open_type_math_font()) { delta = Scaled::ZERO; } @@ -2993,7 +2989,7 @@ unsafe fn var_delimiter(d: &Delimeter, s: usize, v: Scaled) -> usize { if g != FONT_BASE { /*734: */ match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { x = if x >= 0xd800 && x <= 0xdfff { 0 } else { @@ -3073,7 +3069,7 @@ unsafe fn var_delimiter(d: &Delimeter, s: usize, v: Scaled) -> usize { } let mut b = if f != FONT_BASE { match &FONT_LAYOUT_ENGINE[f] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { if let Some(ot_assembly) = ot_assembly_ptr.as_ref() { build_opentype_assembly(f, ot_assembly, v, ListDir::Vertical) } else { @@ -3162,7 +3158,7 @@ unsafe fn var_delimiter(d: &Delimeter, s: usize, v: Scaled) -> usize { } unsafe fn char_box(f: usize, c: i32) -> List { let mut b; - let p = if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + let p = if let Some(_) = &FONT_LAYOUT_ENGINE[f] { b = List::from(new_null_box()); let chr = std::char::from_u32(c as u32).unwrap(); let p = new_native_character(f, chr); diff --git a/engine/src/xetex_opentype_math.rs b/engine/src/xetex_opentype_math.rs index c92b646f8..d317d4839 100644 --- a/engine/src/xetex_opentype_math.rs +++ b/engine/src/xetex_opentype_math.rs @@ -34,8 +34,7 @@ authorization from the copyright holders. use harfbuzz_sys::*; use std::ptr; -use crate::text_layout_engine::TextLayoutEngine; -use crate::xetex_ext::{Font, NativeFont::*}; +use crate::text_layout_engine::{NativeFont::*, TextLayoutEngine}; use crate::xetex_scaledmath::Scaled; use crate::xetex_layout_interface::GlyphAssembly; @@ -89,7 +88,7 @@ authorization from the copyright holders. \****************************************************************************/ pub(crate) unsafe fn get_ot_math_constant(f: usize, n: i32) -> Scaled { let constant = n as hb_ot_math_constant_t; - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let rval = hb_ot_math_get_constant(hbFont, constant); @@ -203,7 +202,7 @@ pub(crate) unsafe fn get_ot_math_variant( ) -> i32 { let mut rval = g as hb_codepoint_t; *adv = Scaled(-1); - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let mut variant: [hb_ot_math_glyph_variant_t; 1] = [hb_ot_math_glyph_variant_t { @@ -232,7 +231,7 @@ pub(crate) unsafe fn get_ot_math_variant( } pub(crate) unsafe fn get_ot_assembly_ptr(f: usize, g: i32, horiz: i32) -> Option { let mut rval = None; - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let mut count = hb_ot_math_get_glyph_assembly( @@ -271,7 +270,7 @@ pub(crate) unsafe fn get_ot_assembly_ptr(f: usize, g: i32, horiz: i32) -> Option rval } pub(crate) unsafe fn get_ot_math_ital_corr(f: usize, g: i32) -> Scaled { - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let rval = hb_ot_math_get_glyph_italics_correction(hbFont, g as hb_codepoint_t); @@ -281,7 +280,7 @@ pub(crate) unsafe fn get_ot_math_ital_corr(f: usize, g: i32) -> Scaled { } } pub(crate) unsafe fn get_ot_math_accent_pos(f: usize, g: i32) -> Scaled { - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let rval = hb_ot_math_get_glyph_top_accent_attachment(hbFont, g as hb_codepoint_t); @@ -291,7 +290,7 @@ pub(crate) unsafe fn get_ot_math_accent_pos(f: usize, g: i32) -> Scaled { } } pub(crate) unsafe fn ot_min_connector_overlap(f: usize) -> Scaled { - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); let rval = hb_ot_math_get_min_connector_overlap(hbFont, HB_DIRECTION_RTL); @@ -301,7 +300,7 @@ pub(crate) unsafe fn ot_min_connector_overlap(f: usize) -> Scaled { } } unsafe fn getMathKernAt(f: usize, g: i32, side: hb_ot_math_kern_t, height: i32) -> Scaled { - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let hbFont = font.get_hb_font(); Scaled(hb_ot_math_get_glyph_kerning( @@ -315,7 +314,7 @@ unsafe fn getMathKernAt(f: usize, g: i32, side: hb_ot_math_kern_t, height: i32) } } unsafe fn glyph_height(f: usize, g: i32) -> f32 { - if let Font::Native(Otgr(engine)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(engine)) = &FONT_LAYOUT_ENGINE[f] { let (rval, _) = engine.glyph_height_depth(g as u32).unwrap(); rval } else { @@ -323,7 +322,7 @@ unsafe fn glyph_height(f: usize, g: i32) -> f32 { } } unsafe fn glyph_depth(f: usize, g: i32) -> f32 { - if let Font::Native(Otgr(engine)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(engine)) = &FONT_LAYOUT_ENGINE[f] { let (_, rval) = engine.glyph_height_depth(g as u32).unwrap(); rval } else { @@ -338,7 +337,7 @@ pub(crate) unsafe fn get_ot_math_kern( cmd: i32, shift: Scaled, ) -> Scaled { - if let Font::Native(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { + if let Some(Otgr(e)) = &FONT_LAYOUT_ENGINE[f] { let font = e.get_font(); let mut rval; if cmd == 0 { @@ -386,7 +385,7 @@ pub(crate) fn ot_part_is_extender(a: &GlyphAssembly, i: i32) -> bool { a.parts[i as usize].flags as u32 & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER as u32 != 0 } pub(crate) fn ot_part_start_connector(f: usize, a: &GlyphAssembly, i: i32) -> Scaled { - if let Font::Native(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f] } { + if let Some(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f] } { let font = e.get_font(); (font.units_to_points(a.parts[i as usize].start_connector_length as f32) as f64).into() } else { @@ -394,7 +393,7 @@ pub(crate) fn ot_part_start_connector(f: usize, a: &GlyphAssembly, i: i32) -> Sc } } pub(crate) fn ot_part_end_connector(f: usize, a: &GlyphAssembly, i: i32) -> Scaled { - if let Font::Native(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f] } { + if let Some(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f] } { let font = e.get_font(); (font.units_to_points(a.parts[i as usize].end_connector_length as f32) as f64).into() } else { @@ -402,7 +401,7 @@ pub(crate) fn ot_part_end_connector(f: usize, a: &GlyphAssembly, i: i32) -> Scal } } pub(crate) fn ot_part_full_advance(f: usize, a: &GlyphAssembly, i: i32) -> Scaled { - if let Font::Native(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f as usize] } { + if let Some(Otgr(e)) = unsafe { &FONT_LAYOUT_ENGINE[f as usize] } { let font = e.get_font(); (font.units_to_points(a.parts[i as usize].full_advance as f32) as f64).into() } else { diff --git a/engine/src/xetex_shipout.rs b/engine/src/xetex_shipout.rs index 2b7b31c82..fb9c3def3 100644 --- a/engine/src/xetex_shipout.rs +++ b/engine/src/xetex_shipout.rs @@ -6,7 +6,7 @@ use crate::node::*; use crate::t_eprint; use crate::xetex_consts::*; use crate::xetex_errors::{confusion, error, fatal_error}; -use crate::xetex_ext::{apply_tfm_font_mapping, make_font_def, Font}; +use crate::xetex_ext::{apply_tfm_font_mapping, make_font_def}; use crate::xetex_ini::shell_escape_enabled; use crate::xetex_ini::Selector; use crate::xetex_ini::{ @@ -1783,7 +1783,7 @@ unsafe fn dvi_native_font_def(f: internal_font_number) { } unsafe fn dvi_font_def(f: internal_font_number) { - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { dvi_native_font_def(f); } else { if f <= 256 { diff --git a/engine/src/xetex_xetex0.rs b/engine/src/xetex_xetex0.rs index 97b18e20f..d6dcdca73 100644 --- a/engine/src/xetex_xetex0.rs +++ b/engine/src/xetex_xetex0.rs @@ -1,6 +1,6 @@ #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] -use crate::text_layout_engine::TextLayoutEngine; +use crate::text_layout_engine::{NativeFont, NativeFont::*, TextLayoutEngine}; use crate::xetex_output::{Cs, Esc, Roman}; use crate::{t_eprint, t_print, t_print_nl}; use std::cmp::Ordering; @@ -23,7 +23,7 @@ use crate::xetex_ext::{ get_glyph_bounds, get_native_char_height_depth, get_native_char_sidebearings, getnativechardp, getnativecharht, getnativecharic, getnativecharwd, gr_font_get_named, gr_font_get_named_1, gr_get_font_name, linebreak_next, linebreak_start, map_char_to_glyph, map_glyph_to_index, - ot_font_get, ot_font_get_1, ot_font_get_2, ot_font_get_3, Font, NativeFont, NativeFont::*, + ot_font_get, ot_font_get_1, ot_font_get_2, ot_font_get_3, }; use crate::xetex_ini::{ _xeq_level_array, active_width, adjust_tail, after_token, align_ptr, align_state, arith_error, @@ -2515,7 +2515,7 @@ impl fmt::Display for CmdChr { Cmd::SetFont => { "select font ".fmt(f)?; let font_name_str = unsafe { PoolString::from(FONT_NAME[chr_code as usize]) }; - if let Font::Native(_) = unsafe { &FONT_LAYOUT_ENGINE[chr_code as usize] } { + if let Some(_) = unsafe { &FONT_LAYOUT_ENGINE[chr_code as usize] } { let mut quote_char = '\"'; if font_name_str.as_slice().contains(&('\"' as u16)) { quote_char = '\''; @@ -6058,7 +6058,7 @@ unsafe fn restart_scan_something_internal( AssignFontInt::SkewChar => (true, SKEW_CHAR[val as usize], ValLevel::Int), _ => { let n = val; - let k = if let Font::Native(nf) = &FONT_LAYOUT_ENGINE[n as usize] { + let k = if let Some(nf) = &FONT_LAYOUT_ENGINE[n as usize] { scan_glyph_number(input, nf) } else { scan_char_num(input) @@ -6166,9 +6166,7 @@ unsafe fn restart_scan_something_internal( let val = match m { LastItemCode::XetexGlyphBounds => { /*1435:*/ - if let Font::Native(_) = - &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] - { + if let Some(_) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { let n = scan_int(input); /* shellenabledp */ if n < 1 || n > 4 { t_eprint!( @@ -6196,7 +6194,7 @@ unsafe fn restart_scan_something_internal( | LastItemCode::FontCharIc => { let q = scan_font_ident(input) as usize; let val = scan_usv_num(input); - (if let Font::Native(nq) = &FONT_LAYOUT_ENGINE[q] { + (if let Some(nq) = &FONT_LAYOUT_ENGINE[q] { let val = std::char::from_u32(val as u32).unwrap(); match m { LastItemCode::FontCharWd => getnativecharwd(q, val), @@ -6269,8 +6267,8 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => aat::aat_font_get(m.into(), e.attributes), - Font::Native(Otgr(e)) => ot_font_get((m as i32) - 14, e), + Some(Aat(e)) => aat::aat_font_get(m.into(), e.attributes), + Some(Otgr(e)) => ot_font_get((m as i32) - 14, e), _ => 0, } } @@ -6278,8 +6276,8 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => aat::aat_font_get(m.into(), e.attributes), - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Aat(e)) => aat::aat_font_get(m.into(), e.attributes), + Some(Otgr(e)) if e.using_graphite() => { ot_font_get((m as i32) - 14, e) } _ => 0, @@ -6299,11 +6297,11 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => { + Some(Aat(e)) => { let k = scan_int(input); aat::aat_font_get_1(m.into(), e.attributes, k) } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { let k = scan_int(input); ot_font_get_1((m as i32) - 14, e, k) } @@ -6317,12 +6315,12 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => { + Some(Aat(e)) => { let k = scan_int(input); let val = scan_int(input); aat::aat_font_get_2(m.into(), e.attributes, k, val) } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { let k = scan_int(input); let val = scan_int(input); ot_font_get_2((m as i32) - 14, e, k, val) @@ -6337,7 +6335,7 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => { + Some(Aat(e)) => { let name = scan_file_name(input).0.to_string(); aat::aat_font_get_named(&name, m.into(), e.attributes) } @@ -6351,11 +6349,11 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => { + Some(Aat(e)) => { let name = scan_file_name(input).0.to_string(); aat::aat_font_get_named(&name, m.into(), e.attributes) } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { let name = scan_file_name(input).0.to_string(); gr_font_get_named(&name, (m as i32) - 14, e) } @@ -6369,12 +6367,12 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => { + Some(Aat(e)) => { let k = scan_int(input); let name = scan_file_name(input).0.to_string(); aat::aat_font_get_named_1(&name, m.into(), e.attributes, k) } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { let k = scan_int(input); let name = scan_file_name(input).0.to_string(); gr_font_get_named_1(&name, (m as i32) - 14, e, k) @@ -6388,7 +6386,7 @@ unsafe fn restart_scan_something_internal( LastItemCode::XetexOTCountScripts => { let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { ot_font_get((m as i32) - 14, e) } _ => 0, @@ -6397,7 +6395,7 @@ unsafe fn restart_scan_something_internal( LastItemCode::XetexOTCountLanguages | LastItemCode::XetexOTScript => { let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { let val = scan_int(input); ot_font_get_1((m as i32) - 14, e, val) } @@ -6410,7 +6408,7 @@ unsafe fn restart_scan_something_internal( LastItemCode::XetexOTCountFeatures | LastItemCode::XetexOTLanguage => { let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { let k = scan_int(input); let val = scan_int(input); ot_font_get_2((m as i32) - 14, e, k, val) @@ -6424,7 +6422,7 @@ unsafe fn restart_scan_something_internal( LastItemCode::XetexOTFeature => { let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { - Font::Native(Otgr(e)) if e.using_open_type() => { + Some(Otgr(e)) if e.using_open_type() => { let k = scan_int(input); let kk = scan_int(input); let val = scan_int(input); @@ -6437,9 +6435,7 @@ unsafe fn restart_scan_something_internal( } } LastItemCode::XetexMapCharToGlyph => { - if let Font::Native(nf) = - &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] - { + if let Some(nf) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { let n = scan_int(input); map_char_to_glyph(nf, std::char::from_u32(n as u32).unwrap()) } else { @@ -6452,9 +6448,7 @@ unsafe fn restart_scan_something_internal( } } LastItemCode::XetexGlyphIndex => { - if let Font::Native(nf) = - &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] - { + if let Some(nf) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { let name = scan_file_name(input).0.to_string(); map_glyph_to_index(nf, &name) } else { @@ -6470,15 +6464,15 @@ unsafe fn restart_scan_something_internal( let n = scan_font_ident(input); match &FONT_LAYOUT_ENGINE[n as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(_)) => 1, - Font::Native(Otgr(e)) if e.using_open_type() => 2, - Font::Native(Otgr(e)) if e.using_graphite() => 3, + Some(Aat(_)) => 1, + Some(Otgr(e)) if e.using_open_type() => 2, + Some(Otgr(e)) if e.using_graphite() => 3, _ => 0, } } LastItemCode::XetexFirstChar | LastItemCode::XetexLastChar => { let n = scan_font_ident(input); - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[n as usize] { + if let Some(_) = &FONT_LAYOUT_ENGINE[n as usize] { get_font_char_range( n as usize, (m == LastItemCode::XetexFirstChar) as i32, @@ -7911,7 +7905,7 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { fnt = val as usize; match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(_)) => { + Some(Aat(_)) => { arg1 = scan_int(input); arg2 = 0; } @@ -7923,11 +7917,11 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { fnt = val as usize; match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(_)) => { + Some(Aat(_)) => { arg1 = scan_int(input); arg2 = 0; } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { arg1 = scan_int(input); arg2 = 0; } @@ -7939,11 +7933,11 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { fnt = val as usize; match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(_)) => { + Some(Aat(_)) => { arg1 = scan_int(input); arg2 = scan_int(input); } - Font::Native(Otgr(e)) if e.using_graphite() => { + Some(Otgr(e)) if e.using_graphite() => { arg1 = scan_int(input); arg2 = scan_int(input); } @@ -7953,7 +7947,7 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { ConvertCode::XetexGlyphName => { let val = scan_font_ident(input); fnt = val as usize; - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[fnt as usize] { + if let Some(_) = &FONT_LAYOUT_ENGINE[fnt as usize] { arg1 = scan_int(input); } else { not_native_font_error(Cmd::Convert, c as i32, fnt); @@ -7998,7 +7992,7 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { let val = oval.unwrap(); let font_name_str = PoolString::from(FONT_NAME[val as usize]); let mut s = match &FONT_LAYOUT_ENGINE[val as usize] { - Font::Native(_) => { + Some(_) => { let mut quote_char = '\"'; if font_name_str.as_slice().contains(&('\"' as u16)) { quote_char = '\''; @@ -8020,23 +8014,21 @@ pub(crate) unsafe fn conv_toks(input: &mut input_state_t, chr: i32, cs: i32) { ConvertCode::XetexRevision => ".99998".to_string(), ConvertCode::XetexVariationName => match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => aat::aat_get_font_name(c as i32, e.attributes, arg1, arg2), + Some(Aat(e)) => aat::aat_get_font_name(c as i32, e.attributes, arg1, arg2), _ => String::new(), }, ConvertCode::XetexFeatureName | ConvertCode::XetexSelectorName => { match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(e)) => aat::aat_get_font_name(c as i32, e.attributes, arg1, arg2), - Font::Native(Otgr(e)) if e.using_graphite() => { - gr_get_font_name(c as i32, e, arg1, arg2) - } + Some(Aat(e)) => aat::aat_get_font_name(c as i32, e.attributes, arg1, arg2), + Some(Otgr(e)) if e.using_graphite() => gr_get_font_name(c as i32, e, arg1, arg2), _ => String::new(), } } ConvertCode::XetexGlyphName => match &FONT_LAYOUT_ENGINE[fnt as usize] { #[cfg(target_os = "macos")] - Font::Native(Aat(engine)) => engine.glyph_name(arg1 as u16), - Font::Native(Otgr(engine)) => engine.glyph_name(arg1 as u16), + Some(Aat(engine)) => engine.glyph_name(arg1 as u16), + Some(Otgr(engine)) => engine.glyph_name(arg1 as u16), _ => panic!("bad native font flag in `print_glyph_name`"), }, ConvertCode::LeftMarginKern => { @@ -8715,7 +8707,7 @@ pub(crate) unsafe fn conditional(input: &mut input_state_t, cmd: Cmd, chr: i32) IfTestCode::IfFontChar => { let n = scan_font_ident(input) as usize; let val = scan_usv_num(input); - b = if let Font::Native(nf) = &FONT_LAYOUT_ENGINE[n] { + b = if let Some(nf) = &FONT_LAYOUT_ENGINE[n] { map_char_to_glyph(nf, std::char::from_u32(val as u32).unwrap()) > 0 } else if FONT_BC[n] as i32 <= val && FONT_EC[n] as i32 >= val { FONT_CHARACTER_INFO(n, effective_char(true, n, val as u16) as usize).s3 > 0 @@ -9226,7 +9218,7 @@ pub(crate) unsafe fn new_native_word_node(f: usize, n: i32) -> NativeWord { pub(crate) unsafe fn new_native_character(f: internal_font_number, c: char) -> NativeWord { let mut p; let nf = match &FONT_LAYOUT_ENGINE[f] { - Font::Native(nf) => nf, + Some(nf) => nf, _ => panic!("Not native font"), }; if !(FONT_MAPPING[f]).is_null() { @@ -9390,7 +9382,7 @@ pub(crate) unsafe fn get_tracing_fonts_state() -> i32 { } pub(crate) unsafe fn new_character(f: internal_font_number, c: UTF16_code) -> Option { - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { let chr = std::char::from_u32(c as u32).unwrap(); return Some(new_native_character(f, chr).ptr()); } @@ -12455,7 +12447,7 @@ pub(crate) unsafe fn make_accent(input: &mut input_state_t) { let mut rsb: Scaled = Scaled::ZERO; let x = Scaled(FONT_INFO[(X_HEIGHT_CODE + PARAM_BASE[f]) as usize].b32.s1); let s = FONT_INFO[(SLANT_CODE + PARAM_BASE[f]) as usize].b32.s1 as f64 / 65536.; - let a = if let Font::Native(nf) = &FONT_LAYOUT_ENGINE[f] { + let a = if let Some(nf) = &FONT_LAYOUT_ENGINE[f] { let a = NativeWord::from(p).width(); if a == Scaled::ZERO { let val = std::char::from_u32(val as u32).unwrap(); @@ -12486,7 +12478,7 @@ pub(crate) unsafe fn make_accent(input: &mut input_state_t) { let h; let w; let t = FONT_INFO[(SLANT_CODE + PARAM_BASE[f]) as usize].b32.s1 as f64 / 65536.; - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { w = NativeWord::from(q).width(); let val = std::char::from_u32(val as u32).unwrap(); h = get_native_char_height_depth(f, val).0; @@ -12502,7 +12494,7 @@ pub(crate) unsafe fn make_accent(input: &mut input_state_t) { p = p_box.ptr(); } let delta = match &FONT_LAYOUT_ENGINE[f] { - Font::Native(_) if a == Scaled::ZERO => { + Some(_) if a == Scaled::ZERO => { tex_round((w - lsb + rsb).0 as f64 / 2. + h.0 as f64 * t - x.0 as f64 * s) } _ => tex_round((w - a).0 as f64 / 2. + h.0 as f64 * t - x.0 as f64 * s), @@ -13199,8 +13191,7 @@ pub(crate) unsafe fn new_font(input: &mut input_state_t, a: i16) { let area = PoolString::from(file.area); let name = PoolString::from(file.name); if font_name == name - && ((area.len() == 0 && matches!(&FONT_LAYOUT_ENGINE[f], Font::Native(_))) - || font_area == area) + && ((area.len() == 0 && matches!(&FONT_LAYOUT_ENGINE[f], Some(_))) || font_area == area) { if s > Scaled::ZERO { if s == FONT_SIZE[f] { @@ -13215,7 +13206,7 @@ pub(crate) unsafe fn new_font(input: &mut input_state_t, a: i16) { append_str(file.ext); if PoolString::from(FONT_NAME[f]) == PoolString::from(make_string()) { PoolString::flush(); - if let Font::Native(_) = &FONT_LAYOUT_ENGINE[f] { + if let Some(_) = &FONT_LAYOUT_ENGINE[f] { if s > Scaled::ZERO { if s == FONT_SIZE[f] { return common_ending(a, u, f, t); @@ -13535,7 +13526,7 @@ pub(crate) unsafe fn do_extension( new_graf(input, true); } else if cur_list.mode.1 == ListMode::MMode { report_illegal_case(cmd, chr); - } else if let Font::Native(_) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { + } else if let Some(_) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { let mut g = Glyph::new_node(); *LLIST_link(cur_list.tail) = Some(g.ptr()).tex_int(); cur_list.tail = g.ptr(); @@ -14469,7 +14460,7 @@ pub(crate) unsafe fn main_control(input: &mut input_state_t) { append_src_special(); } prev_class = CHAR_CLASS_LIMIT - 1; - if let Font::Native(nf) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { + if let Some(nf) = &FONT_LAYOUT_ENGINE[EQTB[CUR_FONT_LOC].val as usize] { if !cur_list.mode.0 && get_int_par(IntPar::language) != cur_list.aux.b32.s1 { fix_language(); }