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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user