Execute XeTeX character classes and inter-character token lists
This commit is contained in:
1 parent
d11ac0cba1
commit
5df90f113c
15 files changed
+462
-14
No files matched your search
@@ -17,6 +17,7 @@ pub enum ContextKind {
|
||||
Write,
|
||||
Mark,
|
||||
Output,
|
||||
XeInterChar,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ContextFrame {
|
||||
|
||||
@@ -15,6 +15,7 @@ mod expressions;
|
||||
mod fonts;
|
||||
mod hyphenation;
|
||||
mod input;
|
||||
mod interchar;
|
||||
mod list_tail;
|
||||
mod marks;
|
||||
mod math;
|
||||
@@ -60,6 +61,7 @@ struct InputToken {
|
||||
frozen: bool,
|
||||
end_write: bool,
|
||||
alignment: Option<alignment::Boundary>,
|
||||
xe_backed_char: bool,
|
||||
}
|
||||
impl From<Token> for InputToken {
|
||||
fn from(token: Token) -> Self {
|
||||
@@ -68,6 +70,7 @@ impl From<Token> for InputToken {
|
||||
frozen: false,
|
||||
end_write: false,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +115,7 @@ enum TokenInputKind {
|
||||
Write,
|
||||
Mark,
|
||||
Output,
|
||||
XeInterChar,
|
||||
}
|
||||
enum TheValue {
|
||||
Tokens(Vec<Token>),
|
||||
@@ -561,7 +565,8 @@ impl Executor {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn unread(&mut self, token: InputToken) -> Result<(), Error> {
|
||||
fn unread(&mut self, mut token: InputToken) -> Result<(), Error> {
|
||||
token.xe_backed_char = false;
|
||||
self.discard_exhausted_tokens();
|
||||
self.push_kind(vec![token], TokenInputKind::BackedUp)
|
||||
}
|
||||
@@ -914,6 +919,7 @@ impl Executor {
|
||||
frozen: definition_context,
|
||||
end_write: false,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
})
|
||||
.collect(),
|
||||
)?,
|
||||
@@ -948,6 +954,7 @@ impl Executor {
|
||||
frozen: definition_context,
|
||||
end_write: false,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
})
|
||||
.collect(),
|
||||
)?;
|
||||
@@ -1228,6 +1235,13 @@ impl Executor {
|
||||
Meaning::Primitive(p @ (Gluestretch | Glueshrink)) => {
|
||||
RegisterValue::Dimension(self.glue_component(p, files)?).text(false)
|
||||
}
|
||||
Meaning::Primitive(XeTeXinterchartoks) => {
|
||||
let index = self.xe_inter_char_index(files)?;
|
||||
let tokens = self
|
||||
.read_xe_inter_char_tokens(index)
|
||||
.map_or_else(Vec::new, |tokens| tokens.to_vec());
|
||||
return Ok(TheValue::Tokens(tokens));
|
||||
}
|
||||
Meaning::Primitive(Toks) => {
|
||||
let index = self.register_index(files)?;
|
||||
self.reads.insert(Dependency::Toks(index));
|
||||
@@ -1646,6 +1660,7 @@ impl Executor {
|
||||
frozen: true,
|
||||
end_write: true,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
},
|
||||
])?;
|
||||
self.push_kind(
|
||||
@@ -2318,6 +2333,10 @@ impl Executor {
|
||||
Meaning::Primitive(Primitive::Interactionmode) => Ok(self.interaction_mode_value()),
|
||||
Meaning::Primitive(Primitive::Pdftexversion) => Ok(Self::PDFTEX_VERSION),
|
||||
Meaning::Primitive(Primitive::XeTeXversion) => Ok(Self::XETEX_VERSION),
|
||||
Meaning::Primitive(Primitive::XeTeXcharclass) => {
|
||||
let character = self.character_number("XeTeXcharclass index", 0x10FFFF, files)?;
|
||||
Ok(i32::from(self.read_xe_char_class(character)))
|
||||
}
|
||||
Meaning::Primitive(Primitive::XeTeXpdfpagecount) => {
|
||||
self.xdv_pdf_page_count(&next.token, files)
|
||||
}
|
||||
@@ -3221,6 +3240,8 @@ impl Executor {
|
||||
Primitive::XeTeXpicfile => "XeTeXpicfile".into(),
|
||||
Primitive::XeTeXinputencoding => "XeTeXinputencoding".into(),
|
||||
Primitive::XeTeXdefaultencoding => "XeTeXdefaultencoding".into(),
|
||||
Primitive::XeTeXcharclass => "XeTeXcharclass".into(),
|
||||
Primitive::XeTeXinterchartoks => "XeTeXinterchartoks".into(),
|
||||
Primitive::BeginL => "beginL".into(),
|
||||
Primitive::EndL => "endL".into(),
|
||||
Primitive::BeginR => "beginR".into(),
|
||||
@@ -3711,6 +3732,7 @@ impl Executor {
|
||||
files: &mut F,
|
||||
mut capture_boundary: impl FnMut(&mut Self, usize, &mut F),
|
||||
) -> Result<(), Error> {
|
||||
let xe = self.state.input_profile() == InputProfile::XeTeX;
|
||||
loop {
|
||||
self.check_box_capacity(None)?;
|
||||
capture_boundary(self, initial_depth, files);
|
||||
@@ -3720,11 +3742,29 @@ impl Executor {
|
||||
break;
|
||||
};
|
||||
if let Some(boundary) = input.alignment {
|
||||
if xe && self.xe_end_char_run(&input)? {
|
||||
continue;
|
||||
}
|
||||
self.alignment_boundary(boundary, files)?;
|
||||
continue;
|
||||
}
|
||||
let meaning = self.meaning(&input.token);
|
||||
let frozen_expandable = Self::suppresses_meaning(&input, &meaning);
|
||||
if xe
|
||||
&& (frozen_expandable
|
||||
|| !matches!(
|
||||
&meaning,
|
||||
Meaning::Character(TokenKind::Character(
|
||||
_,
|
||||
CatCode::Letter | CatCode::Other
|
||||
)) | Meaning::CharGiven(_)
|
||||
| Meaning::Primitive(Primitive::Char | Primitive::Noboundary)
|
||||
))
|
||||
&& self.xe_end_char_run(&input)?
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let xe_backed_char = input.xe_backed_char;
|
||||
let token = input.token;
|
||||
if self.read_parameter(Parameter::Tracingcommands).width() > 0 {
|
||||
if frozen_expandable {
|
||||
@@ -3762,6 +3802,7 @@ impl Executor {
|
||||
frozen: input.frozen,
|
||||
end_write: input.end_write,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
})?;
|
||||
self.insert_paragraph_token(span)?;
|
||||
continue;
|
||||
@@ -3806,6 +3847,7 @@ impl Executor {
|
||||
frozen: input.frozen,
|
||||
end_write: input.end_write,
|
||||
alignment: None,
|
||||
xe_backed_char: false,
|
||||
})?;
|
||||
self.begin_paragraph(self.current, true)?;
|
||||
continue;
|
||||
@@ -3835,6 +3877,12 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
CatCode::Letter | CatCode::Other | CatCode::Space => {
|
||||
if xe
|
||||
&& code != CatCode::Space
|
||||
&& self.xe_start_character(c, code, &token, xe_backed_char)?
|
||||
{
|
||||
continue;
|
||||
}
|
||||
self.text_character(c, code, &token, files)?;
|
||||
self.events.push(Event::Character(Token {
|
||||
kind: TokenKind::Character(c, code),
|
||||
@@ -3847,6 +3895,9 @@ impl Executor {
|
||||
use Primitive::*;
|
||||
match primitive {
|
||||
Noboundary => {
|
||||
if xe && self.xe_native_boundary_before_noboundary(&token)? {
|
||||
continue;
|
||||
}
|
||||
self.finish_text(false)?;
|
||||
if self.paragraph.is_some() {
|
||||
if let Some(next) = self.expanded(files)? {
|
||||
@@ -3858,7 +3909,11 @@ impl Executor {
|
||||
)) | Meaning::CharGiven(_)
|
||||
| Meaning::Primitive(Char)
|
||||
);
|
||||
self.paragraph.as_mut().unwrap().cancel_boundary = cancel;
|
||||
let paragraph = self.paragraph.as_mut().unwrap();
|
||||
paragraph.cancel_boundary = cancel;
|
||||
if xe && cancel {
|
||||
paragraph.xe_char_run = None;
|
||||
}
|
||||
self.unread(next)?;
|
||||
}
|
||||
}
|
||||
@@ -4024,6 +4079,11 @@ impl Executor {
|
||||
Char => {
|
||||
let c = self.character_number("char", 0x10FFFF, files)?;
|
||||
let c = self.scalar_character(c, token.span)?;
|
||||
if xe
|
||||
&& self.xe_start_character(c, CatCode::Other, &token, xe_backed_char)?
|
||||
{
|
||||
continue;
|
||||
}
|
||||
self.text_character(c, CatCode::Other, &token, files)?;
|
||||
self.events.push(Event::Character(Token {
|
||||
kind: TokenKind::Character(c, CatCode::Other),
|
||||
@@ -4088,6 +4148,9 @@ impl Executor {
|
||||
}
|
||||
Meaning::CharGiven(c) => {
|
||||
let c = self.scalar_character(c, token.span)?;
|
||||
if xe && self.xe_start_character(c, CatCode::Other, &token, xe_backed_char)? {
|
||||
continue;
|
||||
}
|
||||
self.text_character(c, CatCode::Other, &token, files)?;
|
||||
self.events.push(Event::Character(Token {
|
||||
kind: TokenKind::Character(c, CatCode::Other),
|
||||
@@ -4351,6 +4414,8 @@ impl Executor {
|
||||
state.assign_sfcode(c, value as u16, global);
|
||||
})?;
|
||||
}
|
||||
Some(XeTeXcharclass) => self.assign_xe_char_class(global, files)?,
|
||||
Some(XeTeXinterchartoks) => self.assign_xe_inter_char_tokens(global, files)?,
|
||||
Some(p @ (Delcode | Udelcode | Udelcodenum)) => {
|
||||
self.scan_delimiter_code_assignment(p, global, files)?;
|
||||
}
|
||||
@@ -4626,6 +4691,11 @@ impl Executor {
|
||||
self.reads.insert(Dependency::Toks(other));
|
||||
self.state.tokens(other)
|
||||
}
|
||||
Meaning::Primitive(Primitive::XeTeXinterchartoks) => {
|
||||
let index = self.xe_inter_char_index(files)?;
|
||||
self.read_xe_inter_char_tokens(index)
|
||||
.map_or_else(Vec::new, |tokens| tokens.to_vec())
|
||||
}
|
||||
Meaning::Primitive(Primitive::Toks) => {
|
||||
let other = self.register_index(files)?;
|
||||
self.reads.insert(Dependency::Toks(other));
|
||||
|
||||
@@ -384,6 +384,8 @@ impl Executor {
|
||||
| Lccode
|
||||
| Uccode
|
||||
| Sfcode
|
||||
| XeTeXcharclass
|
||||
| XeTeXinterchartoks
|
||||
| Mathcode
|
||||
| Umathcode
|
||||
| Umathcodenum
|
||||
|
||||
@@ -499,6 +499,9 @@ impl Executor {
|
||||
TokenInputKind::Write => (ContextKind::Write, "<write> ".into()),
|
||||
TokenInputKind::Mark => (ContextKind::Mark, "<mark> ".into()),
|
||||
TokenInputKind::Output => (ContextKind::Output, "<output> ".into()),
|
||||
TokenInputKind::XeInterChar => {
|
||||
(ContextKind::XeInterChar, "<XeTeXinterchartoks> ".into())
|
||||
}
|
||||
TokenInputKind::BackedUp => (
|
||||
ContextKind::BackedUp { exhausted },
|
||||
if exhausted {
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
use super::*;
|
||||
|
||||
const CLASS_COUNT: u16 = 4096;
|
||||
const BOUNDARY: u16 = CLASS_COUNT - 1;
|
||||
const IGNORED: u16 = CLASS_COUNT;
|
||||
|
||||
fn transition_index(from: u16, to: u16) -> u32 {
|
||||
// The register scanner accepts 4096 in both positions, including the
|
||||
// resulting alias between a right-hand 4096 and the next left-hand class.
|
||||
u32::from(from) * u32::from(CLASS_COUNT) + u32::from(to)
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
fn scan_xe_char_class(&mut self, files: &mut impl SourceProvider) -> Result<u16, Error> {
|
||||
let value = self.integer(files)?;
|
||||
if !(0..=i32::from(CLASS_COUNT)).contains(&value) {
|
||||
return self.fail(format!("Bad character class ({value})"));
|
||||
}
|
||||
Ok(value as u16)
|
||||
}
|
||||
|
||||
pub(super) fn xe_inter_char_index(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<u32, Error> {
|
||||
let from = self.scan_xe_char_class(files)?;
|
||||
let to = self.scan_xe_char_class(files)?;
|
||||
Ok(transition_index(from, to))
|
||||
}
|
||||
|
||||
pub(super) fn read_xe_char_class(&mut self, character: u32) -> u16 {
|
||||
self.reads.insert(Dependency::XeCharClass(character));
|
||||
self.state.xe_char_class(character)
|
||||
}
|
||||
|
||||
pub(super) fn read_xe_inter_char_tokens(&mut self, index: u32) -> Option<Arc<[Token]>> {
|
||||
self.reads.insert(Dependency::XeInterCharTokens(index));
|
||||
self.state.xe_inter_char_tokens(index).cloned()
|
||||
}
|
||||
|
||||
pub(super) fn assign_xe_char_class(
|
||||
&mut self,
|
||||
global: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let character = self.character_number("XeTeXcharclass index", 0x10FFFF, files)?;
|
||||
self.optional_equals(files)?;
|
||||
let class = self.scan_xe_char_class(files)?;
|
||||
let equivalent = self.state.xe_char_class(character) == class;
|
||||
self.assign_equivalence(Key::Sfcode(character), global, equivalent, files, |state| {
|
||||
state.assign_xe_char_class(character, class, global);
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn assign_xe_inter_char_tokens(
|
||||
&mut self,
|
||||
global: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let index = self.xe_inter_char_index(files)?;
|
||||
let tokens = self.scan_token_list_value(files)?;
|
||||
let equivalent = tokens.is_empty() && self.state.xe_inter_char_tokens(index).is_none();
|
||||
self.assign_equivalence(
|
||||
Key::XeInterCharTokens(index),
|
||||
global,
|
||||
equivalent,
|
||||
files,
|
||||
|state| state.assign_xe_inter_char_tokens(index, tokens, global),
|
||||
)
|
||||
}
|
||||
|
||||
fn push_xe_inter_char_tokens(&mut self, tokens: Arc<[Token]>) -> Result<(), Error> {
|
||||
self.push_kind(
|
||||
tokens.iter().cloned().map(InputToken::from).collect(),
|
||||
TokenInputKind::XeInterChar,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn xe_start_character(
|
||||
&mut self,
|
||||
character: char,
|
||||
code: CatCode,
|
||||
token: &Token,
|
||||
backed_up: bool,
|
||||
) -> Result<bool, Error> {
|
||||
if self
|
||||
.read_parameter(Parameter::XeTeXinterchartokenstate)
|
||||
.width()
|
||||
<= 0
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
let class = self.read_xe_char_class(u32::from(character));
|
||||
let previous = self
|
||||
.paragraph
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.xe_char_run
|
||||
.map_or(BOUNDARY, |run| run.previous);
|
||||
let ignored = class == IGNORED;
|
||||
if !ignored
|
||||
&& (previous != BOUNDARY || !backed_up)
|
||||
&& let Some(tokens) = self.read_xe_inter_char_tokens(transition_index(previous, class))
|
||||
{
|
||||
// XeTeX has already updated the factor for the impending character
|
||||
// when a transition list begins executing.
|
||||
let space_factor = self.read_space_factor_code(u32::from(character));
|
||||
self.paragraph
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.adjust_space_factor(space_factor);
|
||||
self.finish_text(false)?;
|
||||
self.paragraph.as_mut().unwrap().xe_char_run = None;
|
||||
let mut character = InputToken::from(Token {
|
||||
kind: TokenKind::Character(character, code),
|
||||
..token.clone()
|
||||
});
|
||||
character.xe_backed_char = true;
|
||||
self.discard_exhausted_tokens();
|
||||
self.push_kind(vec![character], TokenInputKind::BackedUp)?;
|
||||
self.push_xe_inter_char_tokens(tokens)?;
|
||||
return Ok(true);
|
||||
}
|
||||
self.paragraph.as_mut().unwrap().xe_char_run = Some(paragraph::XeCharRun {
|
||||
previous: if ignored { previous } else { class },
|
||||
last_ignored: ignored,
|
||||
});
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub(super) fn xe_end_char_run(&mut self, next: &InputToken) -> Result<bool, Error> {
|
||||
let Some(run) = self.paragraph.as_mut().and_then(|p| p.xe_char_run.take()) else {
|
||||
return Ok(false);
|
||||
};
|
||||
if run.last_ignored || run.previous == BOUNDARY {
|
||||
return Ok(false);
|
||||
}
|
||||
let Some(tokens) = self.read_xe_inter_char_tokens(transition_index(run.previous, BOUNDARY))
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
self.finish_text(true)?;
|
||||
self.unread(next.clone())?;
|
||||
self.push_xe_inter_char_tokens(tokens)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub(super) fn xe_native_boundary_before_noboundary(
|
||||
&mut self,
|
||||
token: &Token,
|
||||
) -> Result<bool, Error> {
|
||||
if self
|
||||
.paragraph
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.xe_char_run.is_some())
|
||||
&& self
|
||||
.state
|
||||
.fonts
|
||||
.font(self.state.text_font())
|
||||
.map_err(|e| self.error(e, token.span))?
|
||||
.opentype()
|
||||
.is_some()
|
||||
{
|
||||
return self.xe_end_char_run(&InputToken::from(token.clone()));
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
@@ -199,6 +199,7 @@ impl Executor {
|
||||
| Primitive::Lccode
|
||||
| Primitive::Uccode
|
||||
| Primitive::Sfcode
|
||||
| Primitive::XeTeXcharclass
|
||||
| Primitive::Mathcode
|
||||
| Primitive::Umathcode
|
||||
| Primitive::Umathcodenum
|
||||
|
||||
@@ -227,7 +227,14 @@ impl Executor {
|
||||
unreachable!("packed code reads do not create save records")
|
||||
}
|
||||
Key::Delcode(c) => (format!("delcode{c}"), self.state.delimiter_code(*c).to_string()),
|
||||
Key::Sfcode(c) => (format!("sfcode{c}"), self.state.space_factor_code(*c).to_string()),
|
||||
Key::Sfcode(c) => (
|
||||
format!("sfcode{c}"),
|
||||
((u32::from(self.state.xe_char_class(*c)) << 16)
|
||||
| u32::from(self.state.space_factor_code(*c)))
|
||||
.to_string(),
|
||||
),
|
||||
// XeTeX uses the generic sparse-equivalence label for this table.
|
||||
Key::XeInterCharTokens(_) => return Ok("?=?".into()),
|
||||
Key::CaseCode(kind, c) => (
|
||||
format!("{}{}", kind.name(), *c as u32),
|
||||
self.state.case_code(*kind, *c).to_string(),
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 69;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 36] = [
|
||||
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, 58, 59, 60, 61, 64, 65, 66, 67, 68, SCHEMA,
|
||||
const SCHEMA: u32 = 70;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 37] = [
|
||||
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, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
|
||||
@@ -482,6 +482,8 @@ pub enum Dependency {
|
||||
UnicodeMathCode(u32),
|
||||
UnicodeSfCode(u32),
|
||||
UnicodeDelCode(u32),
|
||||
XeCharClass(u32),
|
||||
XeInterCharTokens(u32),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -110,6 +110,12 @@ pub struct NativeParagraph {
|
||||
pub hyphen_min: (usize, usize),
|
||||
pub missing_glyphs: Vec<(FontId, u8, Span)>,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(super) struct XeCharRun {
|
||||
pub previous: u16,
|
||||
pub last_ignored: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(super) struct Builder {
|
||||
pub initial_language: HyphenationLanguage,
|
||||
@@ -123,6 +129,7 @@ pub(super) struct Builder {
|
||||
run: Option<FontRun>,
|
||||
opentype: Option<PendingOpenType>,
|
||||
pub cancel_boundary: bool,
|
||||
pub xe_char_run: Option<XeCharRun>,
|
||||
pub font_steps: usize,
|
||||
pub font_step_limit: usize,
|
||||
pub ligature_carry: super::ligature::Carry,
|
||||
|
||||
@@ -123,6 +123,7 @@ pub enum Parameter {
|
||||
XeTeXdashbreakstate,
|
||||
Suppressfontnotfounderror,
|
||||
TeXXeTstate,
|
||||
XeTeXinterchartokenstate,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ParameterValue {
|
||||
@@ -155,10 +156,11 @@ impl Parameter {
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) const XETEX: [Self; 3] = [
|
||||
pub(super) const XETEX: [Self; 4] = [
|
||||
Self::XeTeXuseglyphmetrics,
|
||||
Self::XeTeXdashbreakstate,
|
||||
Self::Suppressfontnotfounderror,
|
||||
Self::XeTeXinterchartokenstate,
|
||||
];
|
||||
|
||||
pub const ALL: &'static [Self] = &[
|
||||
@@ -280,12 +282,14 @@ impl Parameter {
|
||||
Self::XeTeXdashbreakstate,
|
||||
Self::Suppressfontnotfounderror,
|
||||
Self::TeXXeTstate,
|
||||
Self::XeTeXinterchartokenstate,
|
||||
];
|
||||
pub fn name(self) -> String {
|
||||
match self {
|
||||
Self::XeTeXuseglyphmetrics => "XeTeXuseglyphmetrics".into(),
|
||||
Self::XeTeXdashbreakstate => "XeTeXdashbreakstate".into(),
|
||||
Self::TeXXeTstate => "TeXXeTstate".into(),
|
||||
Self::XeTeXinterchartokenstate => "XeTeXinterchartokenstate".into(),
|
||||
_ => format!("{self:?}").to_ascii_lowercase(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,6 +387,8 @@ pub enum Primitive {
|
||||
EndR,
|
||||
XeTeXinputencoding,
|
||||
XeTeXdefaultencoding,
|
||||
XeTeXcharclass,
|
||||
XeTeXinterchartoks,
|
||||
}
|
||||
|
||||
impl Primitive {
|
||||
@@ -587,6 +589,7 @@ pub(super) enum Key {
|
||||
Mathcode(u32),
|
||||
Delcode(u32),
|
||||
Sfcode(u32),
|
||||
XeInterCharTokens(u32),
|
||||
CaseCode(super::CaseCode, char),
|
||||
Mathfont(u8, u8),
|
||||
Mathcodenum(u32),
|
||||
@@ -608,7 +611,8 @@ pub(super) enum Saved {
|
||||
Box(Option<NativeBox>),
|
||||
Mathcode(Option<super::MathCode>),
|
||||
Delcode(Option<i32>),
|
||||
Sfcode(Option<u16>),
|
||||
Sfcode(Option<u16>, Option<u16>),
|
||||
XeInterCharTokens(Option<std::sync::Arc<[Token]>>),
|
||||
CaseCode(Option<u32>),
|
||||
Mathfont(Option<FontId>),
|
||||
}
|
||||
@@ -729,6 +733,10 @@ pub struct State {
|
||||
delcodes: BTreeMap<u32, i32>,
|
||||
#[serde(default)]
|
||||
sfcodes: BTreeMap<u32, u16>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
xe_char_classes: BTreeMap<u32, u16>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
xe_inter_char_tokens: BTreeMap<u32, std::sync::Arc<[Token]>>,
|
||||
#[serde(with = "ordered_map")]
|
||||
case_codes: BTreeMap<(super::CaseCode, char), u32>,
|
||||
#[serde(with = "ordered_map")]
|
||||
@@ -929,6 +937,8 @@ impl Default for State {
|
||||
mathcodes: BTreeMap::new(),
|
||||
delcodes: BTreeMap::new(),
|
||||
sfcodes: BTreeMap::new(),
|
||||
xe_char_classes: BTreeMap::new(),
|
||||
xe_inter_char_tokens: BTreeMap::new(),
|
||||
case_codes: BTreeMap::new(),
|
||||
mathfonts: BTreeMap::new(),
|
||||
last_badness: 0,
|
||||
@@ -1254,7 +1264,7 @@ impl State {
|
||||
.values()
|
||||
.filter(|m| matches!(m, Meaning::Macro(_)))
|
||||
.count();
|
||||
c.usage.state.token_registers = self.toks.len();
|
||||
c.usage.state.token_registers = self.toks.len() + self.xe_inter_char_tokens.len();
|
||||
c.usage.state.parameter_entries =
|
||||
self.parameters.len() + self.token_parameters.len() + self.job_parameters.len();
|
||||
c.usage.state.register_entries =
|
||||
@@ -1263,6 +1273,7 @@ impl State {
|
||||
+ self.mathcodes.len()
|
||||
+ self.delcodes.len()
|
||||
+ self.sfcodes.len()
|
||||
+ self.xe_char_classes.len()
|
||||
+ self.case_codes.len()
|
||||
+ self.mathfonts.len();
|
||||
c.usage.state.save_entries = self.groups.iter().map(|g| g.saved.len()).sum();
|
||||
@@ -1285,7 +1296,7 @@ impl State {
|
||||
for v in self.toks.values() {
|
||||
c.usage.token_list_cells += v.len();
|
||||
}
|
||||
for v in self.token_parameters.values() {
|
||||
for v in self.token_parameters.values().chain(self.xe_inter_char_tokens.values()) {
|
||||
c.shared_tokens(v);
|
||||
}
|
||||
for b in self.boxes.values() {
|
||||
@@ -1306,7 +1317,7 @@ impl State {
|
||||
match v {
|
||||
Saved::Command(Some(Meaning::Macro(m))) => c.macro_body(m),
|
||||
Saved::Tokens(Some(v)) => c.usage.token_list_cells += v.len(),
|
||||
Saved::Hook(Some(v)) => c.shared_tokens(v),
|
||||
Saved::Hook(Some(v)) | Saved::XeInterCharTokens(Some(v)) => c.shared_tokens(v),
|
||||
Saved::Box(Some(b)) => c.native_box(b, Active),
|
||||
_ => {}
|
||||
}
|
||||
@@ -1709,6 +1720,8 @@ impl State {
|
||||
("XeTeXpdfpagecount", Primitive::XeTeXpdfpagecount),
|
||||
("XeTeXinputencoding", Primitive::XeTeXinputencoding),
|
||||
("XeTeXdefaultencoding", Primitive::XeTeXdefaultencoding),
|
||||
("XeTeXcharclass", Primitive::XeTeXcharclass),
|
||||
("XeTeXinterchartoks", Primitive::XeTeXinterchartoks),
|
||||
] {
|
||||
self.update_profile_command(name, Meaning::Primitive(primitive), enabled);
|
||||
}
|
||||
@@ -1875,6 +1888,34 @@ impl State {
|
||||
self.save(Key::Sfcode(c), global);
|
||||
self.sfcodes.insert(c, value);
|
||||
}
|
||||
pub(super) fn xe_char_class(&self, c: u32) -> u16 {
|
||||
self.xe_char_classes.get(&c).copied().unwrap_or(0)
|
||||
}
|
||||
pub(super) fn assign_xe_char_class(&mut self, c: u32, value: u16, global: bool) {
|
||||
// XeTeX groups both halves of its space-factor table as one entry.
|
||||
self.save(Key::Sfcode(c), global);
|
||||
if value == 0 {
|
||||
self.xe_char_classes.remove(&c);
|
||||
} else {
|
||||
self.xe_char_classes.insert(c, value);
|
||||
}
|
||||
}
|
||||
pub(super) fn xe_inter_char_tokens(&self, index: u32) -> Option<&std::sync::Arc<[Token]>> {
|
||||
self.xe_inter_char_tokens.get(&index)
|
||||
}
|
||||
pub(super) fn assign_xe_inter_char_tokens(
|
||||
&mut self,
|
||||
index: u32,
|
||||
tokens: Vec<Token>,
|
||||
global: bool,
|
||||
) {
|
||||
self.save(Key::XeInterCharTokens(index), global);
|
||||
if tokens.is_empty() {
|
||||
self.xe_inter_char_tokens.remove(&index);
|
||||
} else {
|
||||
self.xe_inter_char_tokens.insert(index, tokens.into());
|
||||
}
|
||||
}
|
||||
pub fn case_code(&self, kind: super::CaseCode, c: char) -> u32 {
|
||||
self.case_codes.get(&(kind, c)).copied().unwrap_or_else(|| {
|
||||
if !c.is_ascii_alphabetic() {
|
||||
@@ -2106,12 +2147,24 @@ impl State {
|
||||
self.mathcodes.remove(&c);
|
||||
}
|
||||
}
|
||||
(Key::Sfcode(c), Saved::Sfcode(v)) => {
|
||||
if let Some(v) = v {
|
||||
(Key::Sfcode(c), Saved::Sfcode(factor, class)) => {
|
||||
if let Some(v) = factor {
|
||||
self.sfcodes.insert(c, v);
|
||||
} else {
|
||||
self.sfcodes.remove(&c);
|
||||
}
|
||||
if let Some(v) = class {
|
||||
self.xe_char_classes.insert(c, v);
|
||||
} else {
|
||||
self.xe_char_classes.remove(&c);
|
||||
}
|
||||
}
|
||||
(Key::XeInterCharTokens(index), Saved::XeInterCharTokens(tokens)) => {
|
||||
if let Some(tokens) = tokens {
|
||||
self.xe_inter_char_tokens.insert(index, tokens);
|
||||
} else {
|
||||
self.xe_inter_char_tokens.remove(&index);
|
||||
}
|
||||
}
|
||||
(Key::Delcode(c), Saved::Delcode(v)) => {
|
||||
if let Some(v) = v {
|
||||
@@ -2189,7 +2242,13 @@ impl State {
|
||||
unreachable!("packed 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::Sfcode(c) => Saved::Sfcode(
|
||||
self.sfcodes.get(c).copied(),
|
||||
self.xe_char_classes.get(c).copied(),
|
||||
),
|
||||
Key::XeInterCharTokens(index) => {
|
||||
Saved::XeInterCharTokens(self.xe_inter_char_tokens.get(index).cloned())
|
||||
}
|
||||
Key::CaseCode(kind, c) => Saved::CaseCode(self.case_codes.get(&(*kind, *c)).copied()),
|
||||
Key::Mathfont(s, f) => Saved::Mathfont(self.mathfonts.get(&(*s, *f)).copied()),
|
||||
Key::Spacefactor => unreachable!("spacefactor belongs to the horizontal list"),
|
||||
|
||||
Reference in new issue
Block a user