use crate::formula::mtef::constants::*;
#[derive(Debug, Clone)]
pub struct CharsetAttributes {
pub math_attr: i32,
pub do_lookup: bool,
pub use_codepoint: bool,
}
#[allow(dead_code)] #[derive(Debug, Clone)]
pub struct CharsetInfo {
pub attributes: CharsetAttributes,
pub name: &'static str,
}
const TYPEFACE_NAMES: &[&str] = &[
"ZERO", "TEXT", "FUNCTION", "VARIABLE", "LCGREEK", "UCGREEK", "SYMBOL",
"VECTOR", "NUMBER", "USER1", "USER2", "MTEXTRA", "UNKNOWN", "UNKNOWN",
"UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
"UNKNOWN", "TEXT_FE", "EXPAND", "MARKER", "SPACE", "UNKNOWN", "UNKNOWN",
"UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN"
];
#[allow(dead_code)] pub fn get_typeface_name(typeface_index: usize) -> &'static str {
if typeface_index < TYPEFACE_NAMES.len() {
TYPEFACE_NAMES[typeface_index]
} else {
"UNKNOWN"
}
}
const DEFAULT_CHARSET_ATTRIBUTES: &[CharsetAttributes] = &[
CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 2, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, CharsetAttributes { math_attr: 1, do_lookup: true, use_codepoint: true }, ];
pub const EMBELLISHMENT_TEMPLATES: &[&str] = &[
"", "", "\\dot{%1} ,\\.%1 ", "\\ddot{%1} ,\\\"%1 ", "\\dddot{%1} ,%1 ", "%1' ,%1 ", "%1'' ,%1 ", "\\backprime %1 , %1", "\\tilde{%1} ,\\~%1 ", "\\hat{%1} ,\\^%1 ", "", "\\vec{%1} ,%1 ", "\\overleftarrow1{%1} ,%1 ", "\\overleftrightarrow{%1} ,%1 ", "\\overrightarrow{%1} ,%1 ", "\\overleftarrow{%1} ,%1 ", "\\underline{%1} ,%1 ", "\\bar{%1} ,\\=%1 ", "%1''' ,", "\\widehat{%1} ,%1 ", "\\breve{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "\\d{%1} ,\\d{%1} ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", "{%1} ,%1 ", ];
static FUNCTION_LOOKUP_TABLE: phf::Map<&'static str, &'static str> = phf::phf_map! {
"Pr" => "\\Pr ",
"arccos" => "\\arccos ",
"arcsin" => "\\arcsin ",
"arctan" => "\\arctan ",
"arg" => "\\arg ",
"cos" => "\\cos ",
"cosh" => "\\cosh ",
"cot" => "\\cot ",
"coth" => "\\coth ",
"csc" => "\\csc ",
"deg" => "\\deg ",
"det" => "\\det ",
"dim" => "\\dim ",
"exp" => "\\exp ",
"gcd" => "\\gcd ",
"hom" => "\\hom ",
"inf" => "\\inf ",
"ker" => "\\ker ",
"lim" => "\\lim ",
"liminf" => "\\liminf ",
"limsup" => "\\limsup ",
"ln" => "\\ln ",
"log" => "\\log ",
"max" => "\\max ",
"min" => "\\min ",
"sec" => "\\sec ",
"sin" => "\\sin ",
"sinh" => "\\sinh ",
"sup" => "\\sup ",
"tan" => "\\tan ",
"tanh" => "\\tanh ",
"mod" => "\\mathop{\\rm mod} ",
"glb" => "\\mathop{\\rm glb} ",
"lub" => "\\mathop{\\rm lub} ",
"int" => "\\mathop{\\rm int} ",
"Im" => "\\mathop{\\rm Im} ",
"Re" => "\\mathop{\\rm Re} ",
"var" => "\\mathop{\\rm var} ",
"cov" => "\\mathop{\\rm cov} ",
};
static CHAR_LOOKUP_TABLE: phf::Map<&'static str, &'static str> = phf::phf_map! {
"130.91" => "\\lbrack ",
"130.95" => "\\_ ",
"131.95" => "\\_ ",
"132.74" => "\\vartheta ",
"132.86" => "\\varsigma ",
"132.97" => "\\alpha ",
"132.98" => "\\beta ",
"132.99" => "\\chi ",
"132.100" => "\\delta ",
"132.101" => "\\epsilon ",
"132.102" => "\\phi ",
"132.103" => "\\gamma ",
"132.104" => "\\eta ",
"132.105" => "\\iota ",
"132.106" => "\\varphi ",
"132.107" => "\\kappa ",
"132.108" => "\\lambda ",
"132.109" => "\\mu ",
"132.110" => "\\nu ",
"132.111" => "\\o ",
"132.112" => "\\pi ",
"132.113" => "\\theta ",
"132.114" => "\\rho ",
"132.115" => "\\sigma ",
"132.116" => "\\tau ",
"132.117" => "\\upsilon ",
"132.118" => "\\varpi ",
"132.119" => "\\omega ",
"132.120" => "\\xi ",
"132.121" => "\\psi ",
"132.122" => "\\zeta ",
"132.182" => "\\partial ",
"132.945" => "\\alpha ",
"132.946" => "\\beta ",
"132.967" => "\\chi ",
"132.948" => "\\delta ",
"132.949" => "\\epsilon ",
"132.966" => "\\phi ",
"132.947" => "\\gamma ",
"132.951" => "\\eta ",
"132.953" => "\\iota ",
"132.981" => "\\varphi ",
"132.954" => "\\kappa ",
"132.955" => "\\lambda ",
"132.956" => "\\mu ",
"132.957" => "\\nu ",
"132.959" => "\\o ",
"132.960" => "\\pi ",
"132.952" => "\\theta ",
"132.961" => "\\rho ",
"132.963" => "\\sigma ",
"132.964" => "\\tau ",
"132.965" => "\\upsilon ",
"132.969" => "\\omega ",
"132.958" => "\\xi ",
"132.968" => "\\psi ",
"132.950" => "\\zeta ",
"132.977" => "\\vartheta ",
"132.962" => "\\varsigma ",
"132.982" => "\\varpi ",
"133.65" => "A",
"133.66" => "B",
"133.67" => "X",
"133.68" => "\\Delta ",
"133.69" => "E",
"133.70" => "\\Phi ",
"133.71" => "\\Gamma ",
"133.72" => "H",
"133.73" => "I",
"133.75" => "K",
"133.76" => "\\Lambda ",
"133.77" => "M",
"133.78" => "N",
"133.79" => "O",
"133.80" => "\\Pi ",
"133.81" => "\\Theta ",
"133.82" => "P",
"133.83" => "\\Sigma ",
"133.84" => "T",
"133.85" => "Y",
"133.87" => "\\Omega ",
"133.88" => "\\Xi ",
"133.89" => "\\Psi ",
"133.90" => "Z",
"133.913" => "A",
"133.914" => "B",
"133.935" => "X",
"133.916" => "\\Delta ",
"133.917" => "E",
"133.934" => "\\Phi ",
"133.915" => "\\Gamma ",
"133.919" => "H",
"133.921" => "I",
"133.922" => "K",
"133.923" => "\\Lambda ",
"133.924" => "M",
"133.925" => "N",
"133.927" => "O",
"133.928" => "\\Pi ",
"133.920" => "\\Theta ",
"133.929" => "P",
"133.931" => "\\Sigma ",
"133.932" => "T",
"133.933" => "Y",
"133.937" => "\\Omega ",
"133.926" => "\\Xi ",
"133.936" => "\\Psi ",
"133.918" => "Z",
"134.34" => "\\forall ",
"134.36" => "\\exists ",
"134.39" => "\\ni ",
"134.42" => "*",
"134.43" => "+",
"134.45" => "-",
"134.61" => "=",
"134.64" => "\\cong ",
"134.92" => "\\therefore ",
"134.94" => "\\bot ",
"134.97" => "\\alpha ",
"134.98" => "\\beta ",
"134.99" => "\\chi ",
"134.100" => "\\delta ",
"134.101" => "\\epsilon ",
"134.102" => "\\phi ",
"134.103" => "\\gamma ",
"134.104" => "\\eta ",
"134.105" => "\\iota ",
"134.106" => "\\varphi ",
"134.107" => "\\kappa ",
"134.108" => "\\lambda ",
"134.109" => "\\mu ",
"134.110" => "\\nu ",
"134.112" => "\\pi ",
"134.113" => "\\theta ",
"134.114" => "\\rho ",
"134.115" => "\\sigma ",
"134.116" => "\\tau ",
"134.117" => "\\upsilon ",
"134.118" => "\\varpi ",
"134.119" => "\\omega ",
"134.120" => "\\xi ",
"134.121" => "\\psi ",
"134.122" => "\\zeta ",
"134.163" => "\\leq ",
"134.165" => "\\infty ",
"134.171" => "\\leftrightarrow ",
"134.172" => "\\leftarrow ",
"134.173" => "\\uparrow ",
"134.174" => "\\rightarrow ",
"134.175" => "\\downarrow ",
"134.176" => "^\\circ ",
"134.177" => "\\pm ",
"134.179" => "\\geq ",
"134.180" => "\\times ",
"134.181" => "\\propto ",
"134.182" => "\\partial ",
"134.183" => "\\bullet ",
"134.184" => "\\div ",
"134.185" => "\\neq ",
"134.186" => "\\equiv ",
"134.187" => "\\approx ",
"134.191" => "\\hookleftarrow ",
"134.192" => "\\aleph ",
"134.193" => "\\Im ",
"134.194" => "\\Re ",
"134.195" => "\\wp ",
"134.196" => "\\otimes ",
"134.197" => "\\oplus ",
"134.198" => "\\emptyset ",
"134.199" => "\\cap ",
"134.200" => "\\cup ",
"134.201" => "\\supset ",
"134.202" => "\\supseteq ",
"134.203" => "\\nsubset ",
"134.204" => "\\subset ",
"134.205" => "\\subseteq ",
"134.206" => "\\in ",
"134.207" => "\\notin ",
"134.208" => "\\angle ",
"134.209" => "\\nabla ",
"134.213" => "\\prod ",
"134.215" => "\\cdot ",
"134.216" => "\\neg ",
"134.217" => "\\wedge ",
"134.218" => "\\vee ",
"134.219" => "\\Leftrightarrow ",
"134.220" => "\\Leftarrow ",
"134.221" => "\\Uparrow ",
"134.222" => "\\Rightarrow ",
"134.223" => "\\Downarrow ",
"134.224" => "\\Diamond ",
"134.225" => "\\langle ",
"134.229" => "\\Sigma ",
"134.241" => "\\rangle ",
"134.242" => "\\smallint ",
"134.247" => "\\div ",
"134.8722" => "-",
"134.8804" => "\\leq ",
"134.8805" => "\\geq ",
"134.8800" => "\\neq ",
"134.8801" => "\\equiv ",
"134.8776" => "\\approx ",
"134.8773" => "\\cong ",
"134.8733" => "\\propto ",
"134.8727" => "\\ast ",
"134.8901" => "\\cdot ",
"134.8226" => "\\bullet ",
"134.8855" => "\\otimes ",
"134.8853" => "\\oplus ",
"134.9001" => "\\langle ",
"134.9002" => "\\rangle ",
"134.8594" => "\\rightarrow ",
"134.8592" => "\\leftarrow ",
"134.8596" => "\\leftrightarrow ",
"134.8593" => "\\uparrow ",
"134.8595" => "\\downarrow ",
"134.8658" => "\\Rightarrow ",
"134.8656" => "\\Leftarrow ",
"134.8660" => "\\Leftrightarrow ",
"134.8657" => "\\Uparrow ",
"134.8659" => "\\Downarrow ",
"134.8629" => "\\hookleftarrow ",
"134.8756" => "\\therefore ",
"134.8717" => "\\backepsilon ",
"134.8707" => "\\exists ",
"134.8704" => "\\forall ",
"134.8743" => "\\wedge ",
"134.8744" => "\\vee ",
"134.8712" => "\\in ",
"134.8713" => "\\notin ",
"134.8746" => "\\cup ",
"134.8745" => "\\cap ",
"134.8834" => "\\subset ",
"134.8835" => "\\supset ",
"134.8838" => "\\subseteq ",
"134.8839" => "\\supseteq ",
"134.8836" => "\\not\\subset ",
"134.8709" => "\\emptyset ",
"134.8706" => "\\partial ",
"134.8711" => "\\nabla ",
"134.8465" => "\\Im ",
"134.8476" => "\\Re ",
"134.8501" => "\\aleph ",
"134.8736" => "\\angle ",
"134.8869" => "\\bot ",
"134.8900" => "\\lozenge ",
"134.8734" => "\\infty ",
"134.8472" => "\\wp ",
"134.8747" => "\\smallint",
"134.8721" => "\\sum ",
"134.8719" => "\\prod ",
"139.58" => "\\sim ",
"139.59" => "\\simeq ",
"139.60" => "\\vartriangleleft ",
"139.61" => "\\ll ",
"139.62" => "\\vartriangleright ",
"139.63" => "\\gg ",
"139.66" => "\\doteq ",
"139.67" => "\\coprod ",
"139.68" => "\\lambdabar ",
"139.73" => "\\bigcap ",
"139.75" => "\\ldots ",
"139.76" => "\\cdots ",
"139.77" => "\\vdots ",
"139.78" => "\\ddots ",
"139.79" => "\\ddots ",
"139.81" => "\\because ",
"139.85" => "\\bigcup ",
"139.97" => "\\mapsto ",
"139.98" => "\\updownarrow ",
"139.99" => "\\Updownarrow ",
"139.102" => "\\succ ",
"139.104" => "\\hbar ",
"139.108" => "\\ell ",
"139.109" => "\\mp ",
"139.111" => "\\circ ",
"139.112" => "\\prec ",
"139.8230" => "\\ldots ",
"139.8943" => "\\cdots ",
"139.8942" => "\\vdots ",
"139.8944" => "\\ddots ",
"139.8945" => "\\ddots ",
"139.8826" => "\\prec ",
"139.8827" => "\\succ ",
"139.8882" => "\\vartriangleleft ",
"139.8883" => "\\vartriangleright ",
"139.8723" => "\\mp ",
"139.8728" => "\\circ ",
"139.8614" => "\\longmapsto ",
"139.8597" => "\\updownarrow ",
"139.8661" => "\\Updownarrow ",
"139.4746" => "\\bigcup ",
"139.4745" => "\\bigcap ",
"139.8757" => "\\because ",
"139.8467" => "\\ell ",
"139.8463" => "\\hbar ",
"139.411" => "\\lambdabar ",
"139.8720" => "\\coprod ",
"151.60160" => "{}",
"152.1" => "{}",
"152.8" => "\\/",
"152.2" => "\\,",
"152.4" => "\\;",
"152.5" => "\\quad ",
"152.60161" => "\\/",
"152.61168" => "@,",
"152.60162" => "\\,",
"152.60164" => "\\;",
"152.60165" => "\\quad ",
"152.61186" => "\\, ",
};
pub fn get_charset_attributes(charset_index: usize) -> CharsetAttributes {
if charset_index < DEFAULT_CHARSET_ATTRIBUTES.len() {
DEFAULT_CHARSET_ATTRIBUTES[charset_index].clone()
} else {
CharsetAttributes {
math_attr: MA_FORCE_MATH, do_lookup: true, use_codepoint: true, }
}
}
pub fn lookup_character(typeface: usize, character: u16, math_attr: i32) -> Option<&'static str> {
let key = format!("{}.{}", typeface, character);
if let Some(result) = CHAR_LOOKUP_TABLE.get(&key) {
return Some(*result);
}
if typeface == 152 && math_attr == crate::formula::mtef::constants::MA_TEXT {
let text_key = format!("{}.{}{}", typeface, character, 't');
if let Some(result) = CHAR_LOOKUP_TABLE.get(&text_key) {
return Some(*result);
}
} else if typeface == 152 && math_attr == crate::formula::mtef::constants::MA_MATH {
let math_key = format!("{}.{}{}", typeface, character, 'm');
if let Some(result) = CHAR_LOOKUP_TABLE.get(&math_key) {
return Some(*result);
}
}
None
}
pub fn lookup_function(function_name: &str) -> Option<&'static str> {
FUNCTION_LOOKUP_TABLE.get(function_name).copied()
}
pub fn get_embellishment_template(embell: u8) -> &'static str {
if (embell as usize) < EMBELLISHMENT_TEMPLATES.len() {
EMBELLISHMENT_TEMPLATES[embell as usize]
} else {
""
}
}