Execute Unicode math codes and measured OpenType math characters
This commit is contained in:
1 parent
ce8a780031
commit
d17680fcd8
24 files changed
+687
-123
No files matched your search
@@ -11,7 +11,13 @@ impl Printer<'_> {
|
||||
fn math_character(&mut self, character: MathChar) {
|
||||
self.command("fam");
|
||||
self.literal(&format!("{} ", character.family));
|
||||
self.ascii(character.slot);
|
||||
if let Ok(byte) = u8::try_from(character.slot) {
|
||||
self.ascii(byte);
|
||||
} else if let Some(c) = char::from_u32(character.slot) {
|
||||
self.literal(&c.to_string());
|
||||
} else {
|
||||
self.literal(&format!("U+{:04X}", character.slot));
|
||||
}
|
||||
}
|
||||
|
||||
fn math_field(&mut self, field: &MathField, parent: &str, part: char) -> Result<(), String> {
|
||||
|
||||
@@ -18,6 +18,7 @@ mod input;
|
||||
mod list_tail;
|
||||
mod marks;
|
||||
mod math;
|
||||
mod math_codes;
|
||||
mod nesting;
|
||||
mod page;
|
||||
mod paragraphs;
|
||||
@@ -1224,6 +1225,7 @@ impl Executor {
|
||||
&& !matches!(
|
||||
meaning,
|
||||
Meaning::Character(_) | Meaning::CharGiven(_) | Meaning::MathCharGiven(_)
|
||||
| Meaning::UnicodeMathCharGiven(_)
|
||||
)
|
||||
&& let TokenKind::Command(CommandName::Active(c)) = input.token.kind
|
||||
{
|
||||
@@ -1917,6 +1919,9 @@ impl Executor {
|
||||
}
|
||||
Meaning::MathCharGiven(code as u16)
|
||||
}
|
||||
Umathchardef | Umathcharnumdef => Meaning::UnicodeMathCharGiven(
|
||||
self.scan_unicode_math_code(primitive == Umathchardef, files)?,
|
||||
),
|
||||
Countdef => Meaning::Count(self.register_index(files)?),
|
||||
Toksdef => Meaning::Toks(self.register_index(files)?),
|
||||
Dimendef | Skipdef | Muskipdef => {
|
||||
@@ -2008,10 +2013,14 @@ impl Executor {
|
||||
Ok(Key::Delcode(c))
|
||||
}
|
||||
Meaning::Primitive(Primitive::Mathcode) => {
|
||||
let c = self.integer(files)?;
|
||||
let c = u8::try_from(c)
|
||||
.map_err(|_| self.error("mathcode index must be in 0..255", self.current))?;
|
||||
Ok(Key::Mathcode(c))
|
||||
Ok(Key::Mathcode(self.scan_math_code_index(files)?))
|
||||
}
|
||||
Meaning::Primitive(Primitive::Umathcodenum) => {
|
||||
Ok(Key::Mathcodenum(self.scan_math_code_index(files)?))
|
||||
}
|
||||
Meaning::Primitive(Primitive::Umathcode) => {
|
||||
self.scan_math_code_index(files)?;
|
||||
self.fail(r"Can't use \Umathcode as a number (try \Umathcodenum)")
|
||||
}
|
||||
Meaning::Primitive(Primitive::Catcode) => {
|
||||
let number = self.integer(files)?;
|
||||
@@ -2042,10 +2051,12 @@ impl Executor {
|
||||
self.reads.insert(Dependency::DelCode(*c));
|
||||
self.state.delcode(*c)
|
||||
}
|
||||
Key::Mathcode(c) => {
|
||||
self.reads.insert(Dependency::MathCode(*c));
|
||||
self.state.mathcode(*c) as i32
|
||||
}
|
||||
Key::Mathcode(c) => i32::from(
|
||||
self.read_math_code(*c).legacy().ok_or_else(|| {
|
||||
self.error("Extended mathchar used as mathchar", self.current)
|
||||
})?
|
||||
),
|
||||
Key::Mathcodenum(c) => self.read_math_code(*c).word(),
|
||||
Key::Parameter(p) => self.read_parameter(*p).width(),
|
||||
Key::Spacefactor => {
|
||||
if self.writing || !self.math.is_empty() {
|
||||
@@ -2166,6 +2177,7 @@ impl Executor {
|
||||
}
|
||||
Meaning::CharGiven(c) => Ok(c as i32),
|
||||
Meaning::MathCharGiven(c) => Ok(c as i32),
|
||||
Meaning::UnicodeMathCharGiven(code) => Ok(code.word()),
|
||||
Meaning::Parameter(p) if p.kind() == Some(RegisterKind::Muskip) => {
|
||||
self.fail("incompatible mu units in integer scan")
|
||||
}
|
||||
@@ -2429,7 +2441,7 @@ impl Executor {
|
||||
}
|
||||
if matches!(first.token.kind, TokenKind::Command(_)) {
|
||||
let value = self.internal_integer_from(first, files)?;
|
||||
return self.bounded(sign * value as i64);
|
||||
return if sign > 0 { Ok(value) } else { self.bounded(-i64::from(value)) };
|
||||
}
|
||||
let radix = match first.token.kind {
|
||||
TokenKind::Character('\'', CatCode::Other) => 8,
|
||||
@@ -3059,6 +3071,12 @@ impl Executor {
|
||||
Primitive::ItalicCorrection => "/".into(),
|
||||
Primitive::Etexversion => "eTeXversion".into(),
|
||||
Primitive::Etexrevision => "eTeXrevision".into(),
|
||||
Primitive::Umathcode => "Umathcode".into(),
|
||||
Primitive::Umathcodenum => "Umathcodenum".into(),
|
||||
Primitive::Umathchar => "Umathchar".into(),
|
||||
Primitive::Umathcharnum => "Umathcharnum".into(),
|
||||
Primitive::Umathchardef => "Umathchardef".into(),
|
||||
Primitive::Umathcharnumdef => "Umathcharnumdef".into(),
|
||||
_ => format!("{p:?}").to_ascii_lowercase(),
|
||||
};
|
||||
format!("{escape}{name}")
|
||||
@@ -3068,6 +3086,9 @@ impl Executor {
|
||||
Meaning::TokenParameter(p) => format!("{escape}{}", p.name()),
|
||||
Meaning::CharGiven(c) => format!("{escape}char\"{c:X}"),
|
||||
Meaning::MathCharGiven(c) => format!("{escape}mathchar\"{c:X}"),
|
||||
Meaning::UnicodeMathCharGiven(code) => format!(
|
||||
"{escape}Umathchar\"{:X}\"{:X}\"{:X}", code.class(), code.family(), code.slot()
|
||||
),
|
||||
Meaning::Register(r) => format!("{escape}{}{}", r.kind.name(), r.index),
|
||||
Meaning::Parameter(p) => format!("{escape}{}", p.name()),
|
||||
Meaning::Font(font) => format!(
|
||||
@@ -3887,7 +3908,7 @@ impl Executor {
|
||||
..token
|
||||
}));
|
||||
}
|
||||
Meaning::MathCharGiven(_) => {
|
||||
Meaning::MathCharGiven(_) | Meaning::UnicodeMathCharGiven(_) => {
|
||||
return self.fail("native math character execution requires math mode");
|
||||
}
|
||||
Meaning::Undefined => {
|
||||
@@ -4160,19 +4181,8 @@ impl Executor {
|
||||
state.assign_delcode(c, n, global);
|
||||
})?;
|
||||
}
|
||||
Some(Mathcode) => {
|
||||
let c = self.integer(files)?;
|
||||
let c = u8::try_from(c)
|
||||
.map_err(|_| self.error("mathcode index must be in 0..255", self.current))?;
|
||||
self.optional_equals(files)?;
|
||||
let n = self.integer(files)?;
|
||||
if !(0..=32768).contains(&n) {
|
||||
return self.fail("mathcode must be in 0..32768");
|
||||
};
|
||||
let equivalent = self.state.mathcode(c) == n as u16;
|
||||
self.assign_equivalence(Key::Mathcode(c), global, equivalent, files, |state| {
|
||||
state.assign_mathcode(c, n as u16, global);
|
||||
})?;
|
||||
Some(p @ (Mathcode | Umathcode | Umathcodenum)) => {
|
||||
self.scan_math_code_assignment(p, global, files)?;
|
||||
}
|
||||
Some(Parshape) => self.scan_paragraph_shape(global, files)?,
|
||||
Some(Setbox) => {
|
||||
@@ -4279,7 +4289,8 @@ impl Executor {
|
||||
)?;
|
||||
}
|
||||
Some(
|
||||
p @ (Chardef | Mathchardef | Countdef | Toksdef | Dimendef | Skipdef | Muskipdef),
|
||||
p @ (Chardef | Mathchardef | Umathchardef | Umathcharnumdef
|
||||
| Countdef | Toksdef | Dimendef | Skipdef | Muskipdef),
|
||||
) => {
|
||||
self.define_shorthand(p, global, files)?;
|
||||
}
|
||||
@@ -4359,7 +4370,8 @@ impl Executor {
|
||||
let key = self.integer_variable(files)?;
|
||||
if matches!(
|
||||
key,
|
||||
Key::Catcode(_) | Key::Mathcode(_) | Key::Sfcode(_) | Key::CaseCode(_, _)
|
||||
Key::Catcode(_) | Key::Mathcode(_) | Key::Mathcodenum(_) | Key::Sfcode(_)
|
||||
| Key::CaseCode(_, _)
|
||||
) {
|
||||
return self.fail("expected assignable integer register, not a code table");
|
||||
}
|
||||
|
||||
@@ -378,11 +378,15 @@ impl Executor {
|
||||
| Futurelet
|
||||
| Chardef
|
||||
| Mathchardef
|
||||
| Umathchardef
|
||||
| Umathcharnumdef
|
||||
| Catcode
|
||||
| Lccode
|
||||
| Uccode
|
||||
| Sfcode
|
||||
| Mathcode
|
||||
| Umathcode
|
||||
| Umathcodenum
|
||||
| Delcode
|
||||
| Count
|
||||
| Countdef
|
||||
|
||||
@@ -117,20 +117,14 @@ impl Executor {
|
||||
Meaning::Primitive(
|
||||
p @ (Primitive::Textfont | Primitive::Scriptfont | Primitive::Scriptscriptfont),
|
||||
) => {
|
||||
let family = self.integer(files)?;
|
||||
if !(0..16).contains(&family) {
|
||||
return self.fail("native math family must be in 0..15");
|
||||
}
|
||||
let family = self.scan_math_family(files)?;
|
||||
let size = match p {
|
||||
Primitive::Textfont => 0,
|
||||
Primitive::Scriptfont => 1,
|
||||
_ => 2,
|
||||
};
|
||||
self.reads.insert(Dependency::MathFamily {
|
||||
size,
|
||||
family: family as u8,
|
||||
});
|
||||
self.state.math_font(size, family as u8)
|
||||
self.reads.insert(Dependency::MathFamily { size, family });
|
||||
self.state.math_font(size, family)
|
||||
}
|
||||
_ => return self.fail("expected native font identifier"),
|
||||
};
|
||||
@@ -140,10 +134,11 @@ impl Executor {
|
||||
pub(super) fn missing_glyph(
|
||||
&mut self,
|
||||
font: FontId,
|
||||
slot: u8,
|
||||
slot: impl Into<u32>,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let slot = slot.into();
|
||||
let tracing = self.read_parameter(Parameter::Tracinglostchars).width();
|
||||
let online = self.read_parameter(Parameter::Tracingonline).width();
|
||||
let destination = if tracing <= 0 {
|
||||
@@ -156,14 +151,16 @@ impl Executor {
|
||||
// TeX print_ASCII renders nonprinting bytes in ^^ notation. This is
|
||||
// the requested slot, not a Unicode-to-font substitution.
|
||||
self.reads.insert(Dependency::NewLineChar);
|
||||
let printed = if u8::try_from(self.state.newlinechar).ok() == Some(slot) {
|
||||
let printed = if u32::try_from(self.state.newlinechar).ok() == Some(slot) {
|
||||
"\n".into()
|
||||
} else {
|
||||
match slot {
|
||||
0..=31 => format!("^^{}", char::from(slot + 64)),
|
||||
0..=31 => format!("^^{}", char::from(slot as u8 + 64)),
|
||||
127 => "^^?".into(),
|
||||
128..=255 => format!("^^{slot:02x}"),
|
||||
_ => char::from(slot).to_string(),
|
||||
_ => char::from_u32(slot)
|
||||
.map(|c| c.to_string())
|
||||
.unwrap_or_else(|| format!("U+{slot:04X}")),
|
||||
}
|
||||
};
|
||||
let newline = u8::try_from(self.state.newlinechar).ok().map(char::from);
|
||||
|
||||
@@ -83,10 +83,7 @@ impl Executor {
|
||||
global: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let family = self.integer(files)?;
|
||||
if !(0..16).contains(&family) {
|
||||
return self.fail("native math family must be in 0..15");
|
||||
};
|
||||
let family = self.scan_math_family(files)?;
|
||||
self.optional_equals(files)?;
|
||||
let font = self.font_identifier(files)?;
|
||||
let size = match p {
|
||||
@@ -94,7 +91,6 @@ impl Executor {
|
||||
Primitive::Scriptfont => 1,
|
||||
_ => 2,
|
||||
};
|
||||
let family = family as u8;
|
||||
let equivalent = self.state.math_font(size, family) == font;
|
||||
self.assign_equivalence(
|
||||
Key::Mathfont(size, family),
|
||||
@@ -112,37 +108,46 @@ impl Executor {
|
||||
c: char,
|
||||
token: &Token,
|
||||
) -> Result<Option<(NoadClass, MathChar)>, Error> {
|
||||
let c = u8::try_from(c as u32).map_err(|_| {
|
||||
self.error(
|
||||
"native 8-bit mathcode requires a byte character",
|
||||
token.span,
|
||||
)
|
||||
})?;
|
||||
self.reads.insert(Dependency::MathCode(c));
|
||||
let code = self.state.mathcode(c);
|
||||
if code == 32768 {
|
||||
let code = self.read_math_code(c as u32);
|
||||
if code.is_active() {
|
||||
let mut t = token.clone();
|
||||
t.kind = TokenKind::Command(CommandName::Active(c as char));
|
||||
t.kind = TokenKind::Command(CommandName::Active(c));
|
||||
self.unread(t.into())?;
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(self.decode_math_char(code)))
|
||||
Ok(Some(self.decode_math_code(code)))
|
||||
}
|
||||
|
||||
fn decode_math_char(&mut self, code: u16) -> (NoadClass, MathChar) {
|
||||
let raw = (code >> 12) as u8;
|
||||
let fam = self.read_parameter(Parameter::Fam).width();
|
||||
self.decode_math_code(MathCode::from_legacy(code))
|
||||
}
|
||||
|
||||
fn decode_math_code(&mut self, code: MathCode) -> (NoadClass, MathChar) {
|
||||
let class = code.class();
|
||||
let mut family = code.family();
|
||||
if class == 7 {
|
||||
let current = self.read_parameter(Parameter::Fam).width();
|
||||
if (0..self.state.math_family_count()).contains(¤t) {
|
||||
family = current as u8;
|
||||
}
|
||||
}
|
||||
if family >= 16 {
|
||||
for size in 0..3 {
|
||||
self.reads.insert(Dependency::MathFamily { size, family });
|
||||
}
|
||||
}
|
||||
(
|
||||
NoadClass::from_code(if raw == 7 { 0 } else { raw }),
|
||||
MathChar {
|
||||
family: if raw == 7 && (0..16).contains(&fam) {
|
||||
fam as u8
|
||||
} else {
|
||||
((code >> 8) & 15) as u8
|
||||
},
|
||||
slot: code as u8,
|
||||
},
|
||||
NoadClass::from_code(if class == 7 { 0 } else { class }),
|
||||
MathChar { family, slot: code.slot() },
|
||||
)
|
||||
}
|
||||
fn explicit_math_code(&mut self, code: MathCode) -> Result<(NoadClass, MathChar), Error> {
|
||||
if code.is_active() {
|
||||
return self.fail("active math code requires a character table entry");
|
||||
}
|
||||
Ok(self.decode_math_code(code))
|
||||
}
|
||||
|
||||
pub(super) fn start_math(
|
||||
&mut self,
|
||||
token: &Token,
|
||||
@@ -482,7 +487,8 @@ impl Executor {
|
||||
Meaning::Character(TokenKind::Character(_, CatCode::Letter | CatCode::Other))
|
||||
| Meaning::CharGiven(_)
|
||||
| Meaning::MathCharGiven(_)
|
||||
| Meaning::Primitive(Mathchar | Char | Delimiter) => {}
|
||||
| Meaning::UnicodeMathCharGiven(_)
|
||||
| Meaning::Primitive(Mathchar | Umathchar | Umathcharnum | Char | Delimiter) => {}
|
||||
_ => return self.fail("expected a native math field character or group"),
|
||||
}
|
||||
}
|
||||
@@ -532,6 +538,10 @@ impl Executor {
|
||||
let (class, c) = self.decode_math_char(*code);
|
||||
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token))
|
||||
}
|
||||
Meaning::UnicodeMathCharGiven(code) => {
|
||||
let (class, c) = self.explicit_math_code(*code)?;
|
||||
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token));
|
||||
}
|
||||
Meaning::Primitive(p) => match p {
|
||||
Halign => self.start_alignment(*p, token.span, files)?,
|
||||
Mathchoice => self.start_math_choice(token.span, files)?,
|
||||
@@ -558,6 +568,11 @@ impl Executor {
|
||||
self.math.last_mut().unwrap().nodes.push(MathNode::Rule(r));
|
||||
}
|
||||
Left | Right => self.left_right(*p == Left, token.span, files)?,
|
||||
Umathchar | Umathcharnum => {
|
||||
let code = self.scan_unicode_math_code(*p == Umathchar, files)?;
|
||||
let (class, c) = self.explicit_math_code(code)?;
|
||||
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token));
|
||||
}
|
||||
Mathchar | Char | Delimiter => {
|
||||
let n = self.integer(files)?;
|
||||
if *p == Char {
|
||||
@@ -778,8 +793,10 @@ impl Executor {
|
||||
}
|
||||
Noboundary => {}
|
||||
Global | Long | Outer | Protected | Def | Gdef | Edef | Xdef | Let | Futurelet
|
||||
| Afterassignment | Aftergroup | Immediate | Chardef | Mathchardef | Catcode
|
||||
| Afterassignment | Aftergroup | Immediate | Chardef | Mathchardef
|
||||
| Umathchardef | Umathcharnumdef | Catcode
|
||||
| Lccode | Uccode | Lowercase | Uppercase | Hyphenation | Patterns | Mathcode
|
||||
| Umathcode | Umathcodenum
|
||||
| Delcode | Count | Countdef | Dimen | Dimendef | Skip | Skipdef | Muskip
|
||||
| Muskipdef | Toks | Toksdef | Advance | Multiply | Divide | Read | Readline
|
||||
| Font | Fontdimen | Hyphenchar | Skewchar | Lpcode | Rpcode | Efcode | Pdffontexpand
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
use super::*;
|
||||
|
||||
impl Executor {
|
||||
pub(super) fn scan_math_code_index(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<u32, Error> {
|
||||
let value = self.integer(files)?;
|
||||
match self.state.input_profile() {
|
||||
InputProfile::TeX8Bit if !(0..=255).contains(&value) => {
|
||||
self.fail("mathcode index must be in 0..255")
|
||||
}
|
||||
InputProfile::UnicodeScalar if !(0..=0x10_ffff).contains(&value) => {
|
||||
self.fail("Bad character code")
|
||||
}
|
||||
_ => Ok(value as u32),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn scan_math_family(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<u8, Error> {
|
||||
let value = self.integer(files)?;
|
||||
let count = self.state.math_family_count();
|
||||
if !(0..count).contains(&value) {
|
||||
return self.fail(format!("native math family must be in 0..{}", count - 1));
|
||||
}
|
||||
Ok(value as u8)
|
||||
}
|
||||
|
||||
pub(super) fn scan_unicode_math_code(
|
||||
&mut self,
|
||||
fields: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<MathCode, Error> {
|
||||
let value = self.integer(files)?;
|
||||
if !fields {
|
||||
return MathCode::from_word(value).map_err(|message| self.error(message, self.current));
|
||||
}
|
||||
if !(0..=7).contains(&value) {
|
||||
return self.fail("Bad math class");
|
||||
}
|
||||
let family = self.scan_math_family(files)?;
|
||||
let character = self.scan_math_code_index(files)?;
|
||||
Ok(MathCode::new(value as u8, family, character))
|
||||
}
|
||||
|
||||
pub(super) fn read_math_code(&mut self, character: u32) -> MathCode {
|
||||
self.reads.insert(match u8::try_from(character) {
|
||||
Ok(slot) => Dependency::MathCode(slot),
|
||||
Err(_) => Dependency::UnicodeMathCode(character),
|
||||
});
|
||||
self.state.math_code(character)
|
||||
}
|
||||
|
||||
pub(super) fn scan_math_code_assignment(
|
||||
&mut self,
|
||||
primitive: Primitive,
|
||||
global: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let character = self.scan_math_code_index(files)?;
|
||||
self.optional_equals(files)?;
|
||||
let code = match primitive {
|
||||
Primitive::Mathcode => {
|
||||
let value = self.integer(files)?;
|
||||
if !(0..=32768).contains(&value) {
|
||||
return self.fail("mathcode must be in 0..32768");
|
||||
}
|
||||
MathCode::from_legacy(value as u16)
|
||||
}
|
||||
Primitive::Umathcode => self.scan_unicode_math_code(true, files)?,
|
||||
Primitive::Umathcodenum => self.scan_unicode_math_code(false, files)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let equivalent = self.state.math_code(character) == code;
|
||||
self.assign_equivalence(
|
||||
Key::Mathcode(character),
|
||||
global,
|
||||
equivalent,
|
||||
files,
|
||||
|state| {
|
||||
state.assign_mathcode(character, code, global);
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -191,12 +191,15 @@ impl Executor {
|
||||
Meaning::Count(_)
|
||||
| Meaning::CharGiven(_)
|
||||
| Meaning::MathCharGiven(_)
|
||||
| Meaning::UnicodeMathCharGiven(_)
|
||||
| Meaning::Primitive(
|
||||
Primitive::Count
|
||||
| Primitive::Lccode
|
||||
| Primitive::Uccode
|
||||
| Primitive::Sfcode
|
||||
| Primitive::Mathcode
|
||||
| Primitive::Umathcode
|
||||
| Primitive::Umathcodenum
|
||||
| Primitive::Catcode
|
||||
| Primitive::Endlinechar
|
||||
| Primitive::Newlinechar
|
||||
|
||||
@@ -218,7 +218,12 @@ impl Executor {
|
||||
let (_, value) = rendered.split_once('=').expect("box diagnostic header");
|
||||
(format!("box{index}"), value.trim_end_matches('\n').into())
|
||||
}
|
||||
Key::Mathcode(c) => (format!("mathcode{c}"), self.state.mathcode(*c).to_string()),
|
||||
Key::Mathcode(c) => {
|
||||
let code = self.state.math_code(*c);
|
||||
let value = code.legacy().map_or(code.word(), i32::from);
|
||||
(format!("mathcode{c}"), value.to_string())
|
||||
}
|
||||
Key::Mathcodenum(_) => unreachable!("packed math code reads do not create save records"),
|
||||
Key::Delcode(c) => (format!("delcode{c}"), self.state.delcode(*c).to_string()),
|
||||
Key::Sfcode(c) => (format!("sfcode{c}"), self.state.sfcode(*c).to_string()),
|
||||
Key::CaseCode(kind, c) => (
|
||||
|
||||
@@ -81,7 +81,7 @@ pub(super) fn text_glyph_from_font(
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct MissingGlyph {
|
||||
pub font: FontId,
|
||||
pub slot: u8,
|
||||
pub slot: u32,
|
||||
pub tracing: i32,
|
||||
pub destination: Option<WriteDestination>,
|
||||
pub message: Option<String>,
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 57;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 26] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, SCHEMA,
|
||||
const SCHEMA: u32 = 58;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 27] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -133,6 +133,9 @@ impl FormatImage {
|
||||
if image.schema < 55 {
|
||||
image.state.restore_legacy_font_map_commands();
|
||||
}
|
||||
if image.schema < 58 {
|
||||
image.state.restore_legacy_mathcodes()?;
|
||||
}
|
||||
image.schema = SCHEMA;
|
||||
Ok(image)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl NoadClass {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct MathChar {
|
||||
pub family: u8,
|
||||
pub slot: u8,
|
||||
pub slot: u32,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Delimiter {
|
||||
@@ -69,11 +69,11 @@ impl Delimiter {
|
||||
Self {
|
||||
small: MathChar {
|
||||
family: ((code >> 20) & 15) as u8,
|
||||
slot: (code >> 12) as u8,
|
||||
slot: (code >> 12) & 255,
|
||||
},
|
||||
large: MathChar {
|
||||
family: ((code >> 8) & 15) as u8,
|
||||
slot: code as u8,
|
||||
slot: code & 255,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ pub(super) struct Converter<'a> {
|
||||
pub state: &'a State,
|
||||
pub horizontal_packs: std::cell::Cell<usize>,
|
||||
pub last_pack_badness: std::cell::Cell<Option<i32>>,
|
||||
pub missing: std::cell::RefCell<Vec<(FontId, u8)>>,
|
||||
pub missing: std::cell::RefCell<Vec<(FontId, u32)>>,
|
||||
pub delimiter_glyphs: std::cell::Cell<usize>,
|
||||
pub delimiter_glyph_limit: usize,
|
||||
pub steps: std::cell::Cell<usize>,
|
||||
@@ -355,11 +355,14 @@ impl Converter<'_> {
|
||||
style: MathStyle,
|
||||
) -> Result<&std::sync::Arc<crate::native_font::NativeFont>, String> {
|
||||
let id = self.state.math_font(style.size_index() as u8, family);
|
||||
self.state.fonts.glyph_font(id).map_err(|_| {
|
||||
format!(
|
||||
if id == FontId::NULL {
|
||||
return Err(format!(
|
||||
"native math family {family} size {} is nullfont",
|
||||
style.size_index()
|
||||
)
|
||||
));
|
||||
}
|
||||
self.state.fonts.glyph_font(id).map_err(|_| {
|
||||
format!("native math family {family} size {} requires OpenType math layout here", style.size_index())
|
||||
})
|
||||
}
|
||||
pub fn validate(&self) -> Result<(), String> {
|
||||
@@ -392,20 +395,37 @@ impl Converter<'_> {
|
||||
|n| i64::from(extension[n]),
|
||||
))
|
||||
}
|
||||
pub(super) fn has_math_char(&self, id: FontId, slot: u32) -> Result<bool, String> {
|
||||
if let Some(font) = self.state.fonts.font(id)?.opentype() {
|
||||
let face = font.face()?;
|
||||
Ok(char::from_u32(slot).is_some_and(|c| face.glyph_index(c).is_some()))
|
||||
} else {
|
||||
Ok(u8::try_from(slot).is_ok_and(|slot| self.state.font_has_slot(id, slot)))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn glyph(
|
||||
&self,
|
||||
c: MathChar,
|
||||
style: MathStyle,
|
||||
source: &PaintSource,
|
||||
) -> Result<(MathGeometry, i64), String> {
|
||||
let id = self.font(c.family, style)?;
|
||||
let f = id.metrics();
|
||||
let slot = char::from(c.slot);
|
||||
let font = self.state.math_font(style.size_index() as u8, c.family);
|
||||
if !self.state.font_has_slot(font, c.slot) {
|
||||
if font == FontId::NULL {
|
||||
// Keep the same diagnostic as the legacy fetch path.
|
||||
self.font(c.family, style)?;
|
||||
}
|
||||
if !self.has_math_char(font, c.slot)? {
|
||||
self.missing.borrow_mut().push((font, c.slot));
|
||||
return Ok((MathGeometry::default(), 0));
|
||||
}
|
||||
if let Some(face) = self.state.fonts.font(font)?.opentype() {
|
||||
return crate::opentype::math_glyph(face, char::from_u32(c.slot).unwrap(), source);
|
||||
}
|
||||
let id = self.font(c.family, style)?;
|
||||
let f = id.metrics();
|
||||
let byte = u8::try_from(c.slot).expect("available TFM character is a byte");
|
||||
let slot = char::from(byte);
|
||||
let italic = f.italic(slot);
|
||||
Ok((
|
||||
MathGeometry {
|
||||
@@ -419,9 +439,9 @@ impl Converter<'_> {
|
||||
x: 0,
|
||||
y: 0,
|
||||
item: MathItem::NativeGlyph {
|
||||
character: char::from(c.slot),
|
||||
character: slot,
|
||||
font: id.clone(),
|
||||
slot: c.slot,
|
||||
slot: byte,
|
||||
size: id.size_sp(),
|
||||
},
|
||||
}],
|
||||
@@ -550,7 +570,7 @@ impl Converter<'_> {
|
||||
let font = self
|
||||
.state
|
||||
.math_font(style.size_index() as u8, accent.family);
|
||||
if !self.state.font_has_slot(font, accent.slot) {
|
||||
if !self.has_math_char(font, accent.slot)? {
|
||||
self.missing.borrow_mut().push((font, accent.slot));
|
||||
n.accent = None;
|
||||
}
|
||||
@@ -560,9 +580,11 @@ impl Converter<'_> {
|
||||
&& n.class != NoadClass::Op
|
||||
&& let MathField::Char(c) | MathField::TextChar(c) = n.nucleus
|
||||
{
|
||||
let _ = self.font(c.family, style)?;
|
||||
let font = self.state.math_font(style.size_index() as u8, c.family);
|
||||
if !self.state.font_has_slot(font, c.slot) {
|
||||
if font == FontId::NULL {
|
||||
self.font(c.family, style)?;
|
||||
}
|
||||
if !self.has_math_char(font, c.slot)? {
|
||||
self.missing.borrow_mut().push((font, c.slot));
|
||||
n.nucleus = MathField::Empty;
|
||||
}
|
||||
@@ -576,7 +598,7 @@ impl Converter<'_> {
|
||||
let suppress = if let MathField::TextChar(c) = n.nucleus {
|
||||
self.state
|
||||
.fonts
|
||||
.font(self.font(c.family, style)?.id)?
|
||||
.font(self.state.math_font(style.size_index() as u8, c.family))?
|
||||
.space()
|
||||
.width
|
||||
!= 0
|
||||
@@ -614,11 +636,14 @@ impl Converter<'_> {
|
||||
&& n.sup.is_none()
|
||||
&& let MathField::Char(c) | MathField::TextChar(c) = n.nucleus
|
||||
{
|
||||
let italic = g.metrics.width
|
||||
- self
|
||||
.font(c.family, style)?
|
||||
.metrics()
|
||||
.width(char::from(c.slot));
|
||||
let advance = match g.items.first().map(|item| &item.item) {
|
||||
Some(MathItem::OpenType(run)) => run.width,
|
||||
_ => {
|
||||
let slot = u8::try_from(c.slot).expect("fetched TFM character is a byte");
|
||||
self.font(c.family, style)?.metrics().width(char::from(slot))
|
||||
}
|
||||
};
|
||||
let italic = g.metrics.width - advance;
|
||||
g.metrics.width -= italic;
|
||||
noad_nodes.push(TextNode::MathChar(math_box(g)));
|
||||
if italic != 0 {
|
||||
|
||||
@@ -13,11 +13,11 @@ impl Converter<'_> {
|
||||
if let MathField::Char(c) = n.nucleus {
|
||||
let base_id = self.font(c.family, style)?;
|
||||
let base_font = self.state.math_font(style.size_index() as u8, c.family);
|
||||
if !self.state.font_has_slot(base_font, c.slot) {
|
||||
if !self.has_math_char(base_font, c.slot)? {
|
||||
self.missing.borrow_mut().push((base_font, c.slot));
|
||||
n.nucleus = MathField::Empty;
|
||||
} else if let Ok(code) = u8::try_from(self.state.font_integers(base_font).skew) {
|
||||
skew = base_id.metrics().kern(char::from(c.slot), char::from(code));
|
||||
skew = base_id.metrics().kern(char::from(c.slot as u8), char::from(code));
|
||||
}
|
||||
}
|
||||
let mut base = self.field(&n.nucleus, style.cramped_style(), &n.source.nucleus)?;
|
||||
@@ -26,14 +26,14 @@ impl Converter<'_> {
|
||||
// Larger accents are chosen by actual TFM list tags and advance widths.
|
||||
let metrics = id.metrics();
|
||||
let mut visited = std::collections::BTreeSet::new();
|
||||
while let Some(next) = metrics.next_larger(char::from(accent.slot)) {
|
||||
while let Some(next) = metrics.next_larger(char::from(accent.slot as u8)) {
|
||||
if !visited.insert(accent.slot) {
|
||||
return Err("cyclic native accent size list".into());
|
||||
}
|
||||
if !self.state.font_has_slot(font, next) || metrics.width(char::from(next)) > width {
|
||||
break;
|
||||
}
|
||||
accent.slot = next;
|
||||
accent.slot = u32::from(next);
|
||||
}
|
||||
let mut delta = height.min(i64::from(self.state.fonts.font(font)?.x_height()));
|
||||
if matches!(n.nucleus, MathField::Char(_)) && (n.sub.is_some() || n.sup.is_some()) {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
//! One code table for the classic and Unicode views of math characters.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct MathCode(u32);
|
||||
|
||||
impl MathCode {
|
||||
pub(super) const ACTIVE: Self = Self(0x1f_ffff);
|
||||
|
||||
pub(super) fn new(class: u8, family: u8, slot: u32) -> Self {
|
||||
Self((u32::from(family) << 24) | (u32::from(class) << 21) | slot)
|
||||
}
|
||||
|
||||
pub(super) fn default_for(character: u32) -> Self {
|
||||
match character {
|
||||
65..=90 | 97..=122 => Self::new(7, 1, character),
|
||||
48..=57 => Self::new(7, 0, character),
|
||||
_ => Self::new(0, 0, character),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn from_legacy(value: u16) -> Self {
|
||||
if value == 0x8000 {
|
||||
Self::ACTIVE
|
||||
} else {
|
||||
Self::new(
|
||||
(value >> 12) as u8,
|
||||
((value >> 8) & 15) as u8,
|
||||
u32::from(value & 255),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn from_word(value: i32) -> Result<Self, &'static str> {
|
||||
let code = Self(value as u32);
|
||||
if code == Self::ACTIVE || code.slot() <= 0x10_ffff {
|
||||
Ok(code)
|
||||
} else if code.is_active() {
|
||||
Err("Bad active XeTeX math code")
|
||||
} else {
|
||||
Err("Bad XeTeX math character code")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn legacy(self) -> Option<u16> {
|
||||
if self.is_active() {
|
||||
Some(0x8000)
|
||||
} else if self.slot() <= 255 && self.family() < 16 {
|
||||
Some(
|
||||
(u16::from(self.class()) << 12)
|
||||
| (u16::from(self.family()) << 8)
|
||||
| self.slot() as u16,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn word(self) -> i32 {
|
||||
self.0 as i32
|
||||
}
|
||||
|
||||
pub fn is_active(self) -> bool {
|
||||
self.slot() == Self::ACTIVE.0
|
||||
}
|
||||
|
||||
pub fn slot(self) -> u32 {
|
||||
self.0 & Self::ACTIVE.0
|
||||
}
|
||||
|
||||
pub fn class(self) -> u8 {
|
||||
((self.0 >> 21) & 7) as u8
|
||||
}
|
||||
|
||||
pub fn family(self) -> u8 {
|
||||
(self.0 >> 24) as u8
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,9 @@ impl Converter<'_> {
|
||||
continue;
|
||||
};
|
||||
let m = id.metrics();
|
||||
let mut slot = c.slot;
|
||||
let Ok(mut slot) = u8::try_from(c.slot) else {
|
||||
continue;
|
||||
};
|
||||
let mut visited = std::collections::BTreeSet::new();
|
||||
while id.has_slot(slot) {
|
||||
if !visited.insert(slot) {
|
||||
|
||||
@@ -87,21 +87,21 @@ impl Converter<'_> {
|
||||
let (mut body, italic) = if let MathField::Char(mut c) = n.nucleus {
|
||||
let face = self.font(c.family, style)?;
|
||||
let mut source = n.source.nucleus.clone();
|
||||
let (mut b, italic) = if !self.state.font_has_slot(face.id, c.slot) {
|
||||
let (mut b, italic) = if !self.has_math_char(face.id, c.slot)? {
|
||||
self.missing.borrow_mut().push((face.id, c.slot));
|
||||
(self.pack_field(Vec::new())?, 0)
|
||||
} else {
|
||||
if style.display() {
|
||||
if let Some(next) = face.metrics().next_larger(char::from(c.slot)) {
|
||||
if let Some(next) = face.metrics().next_larger(char::from(c.slot as u8)) {
|
||||
if self.state.font_has_slot(face.id, next) {
|
||||
c.slot = next;
|
||||
c.slot = u32::from(next);
|
||||
source.paint = source
|
||||
.paint
|
||||
.derived(crate::provenance::Derivation::MathVariant);
|
||||
}
|
||||
}
|
||||
}
|
||||
let italic = face.metrics().italic(char::from(c.slot));
|
||||
let italic = face.metrics().italic(char::from(c.slot as u8));
|
||||
(
|
||||
self.owned_field(&MathField::Char(c), style, &source)?,
|
||||
italic,
|
||||
|
||||
@@ -37,14 +37,21 @@ impl Converter<'_> {
|
||||
if self.steps.get() > self.step_limit {
|
||||
return Err("native math ligature instruction limit exceeded".into());
|
||||
}
|
||||
let font = self.state.math_font(style.size_index() as u8, a.family);
|
||||
if self.state.fonts.font(font)?.opentype().is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
q.nucleus = MathField::TextChar(a);
|
||||
let face = self.font(a.family, style)?;
|
||||
if !self.state.font_has_slot(face.id, a.slot) {
|
||||
if !self.has_math_char(face.id, a.slot)? {
|
||||
self.missing.borrow_mut().push((face.id, a.slot));
|
||||
q.nucleus = MathField::Empty;
|
||||
return Ok(());
|
||||
}
|
||||
match face.metrics().lig_kern(Some(a.slot), b.slot) {
|
||||
let Ok(right) = u8::try_from(b.slot) else {
|
||||
return Ok(());
|
||||
};
|
||||
match face.metrics().lig_kern(Some(a.slot as u8), right) {
|
||||
Some(LigKernCommand::Kern(amount)) => {
|
||||
if processed + pending.len() + 2 > self.node_limit {
|
||||
return Err("native math noad capacity exceeded".into());
|
||||
@@ -67,7 +74,7 @@ impl Converter<'_> {
|
||||
source.merge(&p.source.nucleus.paint);
|
||||
let source = FieldSource::paint(source.derived(Derivation::FontProgram));
|
||||
let c = MathChar {
|
||||
slot: replacement,
|
||||
slot: u32::from(replacement),
|
||||
..a
|
||||
};
|
||||
match operation {
|
||||
|
||||
@@ -22,6 +22,7 @@ mod ligature;
|
||||
mod marks;
|
||||
mod math;
|
||||
mod math_accent;
|
||||
mod math_code;
|
||||
mod math_delimiter;
|
||||
mod math_fraction;
|
||||
mod math_op;
|
||||
@@ -74,6 +75,7 @@ pub use math::{
|
||||
Delimiter, FieldSource, FractionSpec, MathChar, MathField, MathNode, MathRulePosition,
|
||||
NativeDisplay, NativeMath, Noad, NoadClass, NoadSource, OperatorLimits,
|
||||
};
|
||||
pub use math_code::MathCode;
|
||||
pub use page_builder::{NativePageState, PageTrace, PageTraceReport};
|
||||
pub use paragraph::{LineBreakCache, LineBreakWork, NativeParagraph, ParagraphMode, TextNode};
|
||||
pub use paragraph_trace::{ParagraphBreakKind, ParagraphTrace, ParagraphTraceReport};
|
||||
@@ -448,6 +450,7 @@ pub enum Dependency {
|
||||
InputPosition(usize),
|
||||
OutputStream(u8),
|
||||
ParagraphToken,
|
||||
UnicodeMathCode(u32),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -353,6 +353,12 @@ pub enum Primitive {
|
||||
Rightmarginkern,
|
||||
Pdflastlink,
|
||||
Special,
|
||||
Umathcode,
|
||||
Umathcodenum,
|
||||
Umathchar,
|
||||
Umathcharnum,
|
||||
Umathchardef,
|
||||
Umathcharnumdef,
|
||||
}
|
||||
|
||||
impl Primitive {
|
||||
@@ -483,6 +489,7 @@ pub enum Meaning {
|
||||
Register(Register),
|
||||
Parameter(Parameter),
|
||||
Font(FontId),
|
||||
UnicodeMathCharGiven(super::MathCode),
|
||||
}
|
||||
|
||||
/// Explicit bootstrap language selection. EtexBootstrap implements the native
|
||||
@@ -517,11 +524,12 @@ pub(super) enum Key {
|
||||
ParagraphShape,
|
||||
Spacefactor,
|
||||
Box(u16),
|
||||
Mathcode(u8),
|
||||
Mathcode(u32),
|
||||
Delcode(u8),
|
||||
Sfcode(u8),
|
||||
CaseCode(super::CaseCode, char),
|
||||
Mathfont(u8, u8),
|
||||
Mathcodenum(u32),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
@@ -537,7 +545,7 @@ pub(super) enum Saved {
|
||||
ParagraphShape(std::sync::Arc<[super::paragraph::ParagraphShapeLine]>),
|
||||
Font(FontId),
|
||||
Box(Option<NativeBox>),
|
||||
Mathcode(Option<u16>),
|
||||
Mathcode(Option<super::MathCode>),
|
||||
Delcode(Option<i32>),
|
||||
Sfcode(Option<u16>),
|
||||
CaseCode(Option<u32>),
|
||||
@@ -654,7 +662,7 @@ pub struct State {
|
||||
boxes: BTreeMap<u16, NativeBox>,
|
||||
pub(super) split_marks: BTreeMap<u16, super::SplitMarks>,
|
||||
pub(super) page_marks: BTreeMap<u16, super::PageMarks>,
|
||||
mathcodes: BTreeMap<u8, u16>,
|
||||
mathcodes: BTreeMap<u32, super::MathCode>,
|
||||
delcodes: BTreeMap<u8, i32>,
|
||||
#[serde(default)]
|
||||
sfcodes: BTreeMap<u8, u16>,
|
||||
@@ -1124,6 +1132,7 @@ impl Default for State {
|
||||
] {
|
||||
state.parameters.insert(p, v);
|
||||
}
|
||||
state.install_unicode_math_commands();
|
||||
state
|
||||
}
|
||||
}
|
||||
@@ -1543,8 +1552,36 @@ impl State {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.install_unicode_math_commands();
|
||||
self
|
||||
}
|
||||
|
||||
fn install_unicode_math_commands(&mut self) {
|
||||
use Primitive::*;
|
||||
for (name, primitive) in [
|
||||
("Umathcode", Umathcode),
|
||||
("XeTeXmathcode", Umathcode),
|
||||
("Umathcodenum", Umathcodenum),
|
||||
("XeTeXmathcodenum", Umathcodenum),
|
||||
("Umathchar", Umathchar),
|
||||
("XeTeXmathchar", Umathchar),
|
||||
("Umathcharnum", Umathcharnum),
|
||||
("XeTeXmathcharnum", Umathcharnum),
|
||||
("Umathchardef", Umathchardef),
|
||||
("XeTeXmathchardef", Umathchardef),
|
||||
("Umathcharnumdef", Umathcharnumdef),
|
||||
("XeTeXmathcharnumdef", Umathcharnumdef),
|
||||
] {
|
||||
let name = CommandName::Control(name.into());
|
||||
let meaning = Meaning::Primitive(primitive);
|
||||
if self.input_profile == super::InputProfile::UnicodeScalar {
|
||||
self.commands.insert(name, meaning);
|
||||
} else if self.commands.get(&name) == Some(&meaning) {
|
||||
self.commands.remove(&name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_profile(&self) -> super::InputProfile {
|
||||
self.input_profile
|
||||
}
|
||||
@@ -1583,16 +1620,35 @@ impl State {
|
||||
.cloned()
|
||||
.unwrap_or(Meaning::Undefined)
|
||||
}
|
||||
pub fn mathcode(&self, c: u8) -> u16 {
|
||||
self.mathcodes.get(&c).copied().unwrap_or_else(|| {
|
||||
if c.is_ascii_alphabetic() {
|
||||
0x7100 + c as u16
|
||||
} else if c.is_ascii_digit() {
|
||||
0x7000 + c as u16
|
||||
} else {
|
||||
c as u16
|
||||
}
|
||||
})
|
||||
/// Classic projection for byte-table consumers. A code outside the
|
||||
/// representable classic range has TeX's recovery value of zero.
|
||||
pub fn mathcode(&self, character: u8) -> u16 {
|
||||
self.math_code(u32::from(character)).legacy().unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn math_code(&self, character: u32) -> super::MathCode {
|
||||
self.mathcodes
|
||||
.get(&character)
|
||||
.copied()
|
||||
.unwrap_or_else(|| super::MathCode::default_for(character))
|
||||
}
|
||||
|
||||
pub(super) fn restore_legacy_mathcodes(&mut self) -> Result<(), String> {
|
||||
for value in self.mathcodes.values_mut() {
|
||||
let legacy = u16::try_from(value.word())
|
||||
.ok()
|
||||
.filter(|&code| code <= 0x8000)
|
||||
.ok_or("invalid legacy mathcode in native format")?;
|
||||
*value = super::MathCode::from_legacy(legacy);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn math_family_count(&self) -> i32 {
|
||||
match self.input_profile {
|
||||
super::InputProfile::TeX8Bit => 16,
|
||||
super::InputProfile::UnicodeScalar => 256,
|
||||
}
|
||||
}
|
||||
pub fn math_font(&self, size: u8, family: u8) -> FontId {
|
||||
self.mathfonts
|
||||
@@ -1642,7 +1698,7 @@ impl State {
|
||||
self.save(Key::Delcode(c), global);
|
||||
self.delcodes.insert(c, n);
|
||||
}
|
||||
pub(super) fn assign_mathcode(&mut self, c: u8, n: u16, global: bool) {
|
||||
pub(super) fn assign_mathcode(&mut self, c: u32, n: super::MathCode, global: bool) {
|
||||
self.save(Key::Mathcode(c), global);
|
||||
self.mathcodes.insert(c, n);
|
||||
}
|
||||
@@ -1917,6 +1973,7 @@ impl State {
|
||||
Key::Font => Saved::Font(self.text_font),
|
||||
Key::Box(n) => Saved::Box(self.boxes.get(n).cloned()),
|
||||
Key::Mathcode(c) => Saved::Mathcode(self.mathcodes.get(c).copied()),
|
||||
Key::Mathcodenum(_) => unreachable!("packed math code reads do not create save records"),
|
||||
Key::Delcode(c) => Saved::Delcode(self.delcodes.get(c).copied()),
|
||||
Key::Sfcode(c) => Saved::Sfcode(self.sfcodes.get(c).copied()),
|
||||
Key::CaseCode(kind, c) => Saved::CaseCode(self.case_codes.get(&(*kind, *c)).copied()),
|
||||
|
||||
Reference in new issue
Block a user