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"),
|
||||
|
||||
@@ -311,3 +311,88 @@ fn xetex_default_encoding_survives_dump_and_current_line_is_already_decoded() {
|
||||
};
|
||||
assert_eq!(&data[token.span.start..token.span.end], [0xd8, 0x3d, 0xde, 0x00]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_inter_character_lists_follow_text_runs_and_shared_grouping() {
|
||||
use sha2::{Digest, Sha256};
|
||||
use texrra_tex_core::resources::{LoadedResource, ResourceKind, ResourceVersion};
|
||||
|
||||
struct TfmSource;
|
||||
impl SourceProvider for TfmSource {
|
||||
fn read(&mut self, name: &str, from: &str) -> Result<SourceFile, String> {
|
||||
NoFiles.read(name, from)
|
||||
}
|
||||
|
||||
fn resource(
|
||||
&mut self,
|
||||
kind: ResourceKind,
|
||||
name: &str,
|
||||
_: &str,
|
||||
) -> Result<LoadedResource, String> {
|
||||
assert_eq!((kind, name), (ResourceKind::Tfm, "cmr10.tfm"));
|
||||
let data = include_bytes!("../assets/cmr10.tfm").to_vec();
|
||||
let version = ResourceVersion {
|
||||
path: name.into(),
|
||||
sha256: format!("{:x}", Sha256::digest(&data)),
|
||||
bytes: data.len() as u64,
|
||||
};
|
||||
Ok(LoadedResource { version, data })
|
||||
}
|
||||
}
|
||||
|
||||
let seed = r"\catcode123=1 \catcode125=2
|
||||
\XeTeXcharclass65=1 \XeTeXcharclass66=2 \XeTeXcharclass67=4096
|
||||
\XeTeXinterchartoks1 2={\kern2pt\relax}
|
||||
\dump";
|
||||
let state = State::initex()
|
||||
.with_etex()
|
||||
.with_input_profile(InputProfile::XeTeX);
|
||||
let image = FormatImage::from_dump(run(state.clone(), seed), Vec::new(), Vec::new())
|
||||
.unwrap()
|
||||
.encode()
|
||||
.unwrap();
|
||||
let result = FormatImage::decode(&image)
|
||||
.unwrap()
|
||||
.new_job(
|
||||
state.profile(),
|
||||
InputProfile::XeTeX,
|
||||
JobTime::new(2025, 10, 9, 0).unwrap(),
|
||||
Limits::default(),
|
||||
|_| Ok(seed.as_bytes().to_vec()),
|
||||
)
|
||||
.unwrap()
|
||||
.run(
|
||||
source(
|
||||
r"\font\t=cmr10 \t
|
||||
\XeTeXinterchartoks4095 1={\kern1pt\relax}
|
||||
\XeTeXinterchartoks2 4095={\kern4pt\relax}
|
||||
\setbox0=\hbox{AB}
|
||||
\XeTeXinterchartokenstate=1
|
||||
\setbox1=\hbox{AB}
|
||||
\setbox2=\hbox{\char65 \char66 C}
|
||||
\message{[\the\wd0,\the\wd1,\the\wd2]}
|
||||
\begingroup \sfcode65=1234 \global\XeTeXcharclass65=1 \endgroup
|
||||
\message{[\the\sfcode65,\the\XeTeXcharclass65]}
|
||||
\begingroup \XeTeXcharclass65=3 \global\sfcode65=1234 \endgroup
|
||||
\message{[\the\sfcode65,\the\XeTeXcharclass65]}
|
||||
\toks2=\XeTeXinterchartoks1 2
|
||||
\begingroup \XeTeXinterchartokenstate=-1 \XeTeXinterchartoks1 2={} \endgroup
|
||||
\XeTeXinterchartoks3 2=\toks2
|
||||
\message{[\the\XeTeXinterchartokenstate,\the\XeTeXinterchartoks3 2]}
|
||||
\end",
|
||||
),
|
||||
&mut TfmSource,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
messages(&result),
|
||||
[
|
||||
"[14.58337pt,21.58337pt,24.8056pt]",
|
||||
"[1234,1]",
|
||||
"[1234,3]",
|
||||
r"[1,\kern 2pt\relax ]",
|
||||
]
|
||||
);
|
||||
assert!(result.reads.contains(&Dependency::XeCharClass(67)));
|
||||
assert!(result.reads.contains(&Dependency::XeInterCharTokens(4098)));
|
||||
}
|
||||
@@ -2175,6 +2175,37 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||
|
||||
### XeTeX 字符类别与文字运行间插入
|
||||
|
||||
XeTeX 扩展 profile 支持 `\XeTeXcharclass`、`\XeTeXinterchartoks`
|
||||
和 `\XeTeXinterchartokenstate`。字符类别与 `\sfcode` 共享同一分组
|
||||
保存项。两个字段任一处的全局赋值都会保留整个表项。成对 token 列表
|
||||
支持赋值、复制、`\the` 和分组恢复。间插通过真实输入栈执行,保留
|
||||
被延迟字符的来源、间插内容的定义位置、忽略类及运行边界。活跃的字符
|
||||
类别随水平列表恢复,查表、启用参数和输入依赖进入检查点。
|
||||
[XeTeX 运行边界和间插逻辑](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L24342-L24387)
|
||||
|
||||
同源探测分别使用实际 CMR10 和显式 `at10pt` 的 Latin Modern,
|
||||
共四项的寄存器读值、盒宽及 144 DPI 灰度逐像素一致。两项 OpenType
|
||||
探测的四个字形坐标与 XDV 一致。未指定字号的独立 OpenType 探测仍
|
||||
复现默认字号差异,原日志保留。XeTeX profile 六项定向检查通过。
|
||||
|
||||
三页原子项目中修改正文,复用 236 步并重放 6 次宿主调用;修改之前
|
||||
输入的类别与间插定义,检查点被拒绝。两次编辑均只替换第二页,PDF、
|
||||
SVG、来源映射与真实 `proof.aux` 等于同版本独立全量。间插规则指向
|
||||
子文件中的实际命令,编辑字形保留正文的来源字节。
|
||||
|
||||
原样 `xelatex.ini` 成功转储 schema70,旧 schema69 实际加载并出页。
|
||||
官方 ACL 原样进入 `\begin{document}`,Babel 字符类别分配器已执行。
|
||||
当前首处失败在 `acl_lualatex.tex:66:1`,microtype 将
|
||||
`\MT@protrudechars` 绑定到还缺少的 `\XeTeXprotrudechars`。
|
||||
下一个入口要接真实开启参数、OpenType glyph ID 的 `\lpcode` 与
|
||||
`\rpcode`、边缘悬挂和对断行的影响。已归档真实 XeTeX 的
|
||||
`protrusion-reference` 探测,其中 Unicode、glyph 名与数值选字及严格
|
||||
全局字体量赋值均可复现。回执和全部候选日志见
|
||||
`target/p3-xetex-interchar`。
|
||||
[上游字体量读取、边缘度量和断行](https://github.com/TeX-Live/texlive-source/blob/279984fab6eaed8d17e02882f2668ab5caac0f27/texk/web2c/xetexdir/xetex.web#L15435-L15489)
|
||||
|
||||
### XeTeX 逐文件输入编码与原始字节位置
|
||||
|
||||
`\XeTeXinputencoding` 切换当前物理文件之后的行,每行按读入时的编码
|
||||
|
||||
@@ -708,6 +708,14 @@ Noto Sans Arabic 及冻结 Type 1 映射。几次缺包和字体名称探测的
|
||||
原样输入摘要、格式摘要及新诊断 `target/p3-xetex-input-encoding/receipt.json`。
|
||||
[编码阶段记录](P2_M1_PROGRESS.md#xetex-逐文件输入编码与原始字节位置)
|
||||
|
||||
字符类别与间插支持接入后,使用原样 `xelatex.ini` 转储的 schema70
|
||||
重新运行同一归档。LaTeX 在真实格式中建立类别分配器。ACL
|
||||
通过 Babel 与导言区,进入 `acl_lualatex.tex:66:1` 的
|
||||
`\begin{document}`,停在 microtype 的 `\MT@protrudechars`。
|
||||
该宏通过 `\let` 引用 `\XeTeXprotrudechars`。这次仍未生成 PDF,
|
||||
诊断、原样输入与格式身份保留在 `target/p3-xetex-interchar/receipt.json`。
|
||||
[字符类别阶段记录](P2_M1_PROGRESS.md#xetex-字符类别与文字运行间插入)
|
||||
|
||||
### 原样 Elsevier CAS 双栏与 NeurIPS 2025
|
||||
|
||||
以 `767c8ff`、既有真实 schema51 和参考格式复验官方 CAS 双栏。
|
||||
|
||||
Reference in new issue
Block a user