Select a native XeTeX compatibility profile and wide spacing codes

This commit is contained in:
gloamxun committed 2026-11-21 12:17:53 +08:00
1 parent 651fab42f1
commit 752af43f32
19 files changed
+471 -115

No files matched your search

+3 -2
View File
@@ -49,8 +49,9 @@ missing resources directly.
Use `--texmf-root`, resource search environment variables and `--input-policy`
for distribution/project resources; `--resource-manifest` records actual reads,
versions and negative lookups, including failed jobs. The CLI defaults to TeX
8-bit input; `--input-profile unicode` selects scalar decoding without claiming
XeTeX fonts or shaping.
8-bit input. Use `--input-profile xetex --etex` for the native XeTeX language
and output profile, or `--input-profile unicode` for the existing scalar-input
mode. Build and load format images with the same profile.
This entry executes native tokens, expansion, scoped state, real streams,
measured h/v/math lists, paragraph breaking and display transitions without v1
+38 -13
View File
@@ -362,6 +362,10 @@ impl Executor {
// Compatibility level for the eight-bit native PDF interface.
// This is independent of the Route-D build version.
const PDFTEX_VERSION: i32 = 140;
// The selected XeTeX language and device profile targets this reference.
// The native binary's build identity remains independent.
const XETEX_VERSION: i32 = 0;
const XETEX_REVISION: &'static str = ".999998";
pub fn new(state: State, limits: Limits) -> Self {
Self {
@@ -683,7 +687,7 @@ impl Executor {
files: &mut impl SourceProvider,
) -> Result<u32, Error> {
let number = self.integer(files)?;
let maximum = if self.state.input_profile() == super::InputProfile::UnicodeScalar {
let maximum = if self.state.input_profile() != super::InputProfile::TeX8Bit {
unicode_maximum
} else {
255
@@ -1068,6 +1072,7 @@ impl Executor {
}
}
Pdftexrevision => self.print_tokens(self.state.pdftex_revision(), token)?,
XeTeXrevision => self.print_tokens(Self::XETEX_REVISION, token)?,
Etexrevision => self.print_tokens(".6", token)?,
Csname => {
let name = self.csname(files)?;
@@ -2057,9 +2062,7 @@ impl Executor {
))
}
Meaning::Primitive(Primitive::Sfcode) => {
let c = self.integer(files)?;
let c = u8::try_from(c)
.map_err(|_| self.error("sfcode index must be in 0..255", self.current))?;
let c = self.scan_space_factor_code_index(files)?;
Ok(Key::Sfcode(c))
}
Meaning::Primitive(Primitive::Delcode) => {
@@ -2093,16 +2096,34 @@ impl Executor {
)),
}
}
fn scan_space_factor_code_index(
&mut self,
files: &mut impl SourceProvider,
) -> Result<u32, Error> {
let maximum = if self.state.input_profile() == InputProfile::XeTeX {
0x10FFFF
} else {
255
};
self.character_number("sfcode index", maximum, files)
}
fn read_space_factor_code(&mut self, c: u32) -> u16 {
let dependency = match u8::try_from(c) {
Ok(slot) => Dependency::SfCode(slot),
Err(_) => Dependency::UnicodeSfCode(c),
};
self.reads.insert(dependency);
self.state.space_factor_code(c)
}
fn read_integer(&mut self, key: &Key) -> Result<i32, Error> {
Ok(match key {
Key::CaseCode(kind, c) => {
self.reads.insert(Dependency::CaseCode(*kind, *c));
self.state.case_code(*kind, *c) as i32
}
Key::Sfcode(c) => {
self.reads.insert(Dependency::SfCode(*c));
self.state.sfcode(*c) as i32
}
Key::Sfcode(c) => i32::from(self.read_space_factor_code(*c)),
Key::Delcode(c) => {
self.reads.insert(Dependency::DelCode(*c));
self.state.delcode(*c)
@@ -2270,6 +2291,7 @@ impl Executor {
Meaning::Primitive(p) if p.page_dimension().is_some() => self.page_dimension_value(p),
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::Pdfshellescape) => Ok(Self::SHELL_ESCAPE),
Meaning::Primitive(Primitive::Pdfrandomseed) => {
self.reads.insert(Dependency::PdfRandomState);
@@ -3125,6 +3147,8 @@ impl Executor {
Primitive::Explicitspace => " ".into(),
Primitive::DiscretionaryHyphen => "-".into(),
Primitive::ItalicCorrection => "/".into(),
Primitive::XeTeXversion => "XeTeXversion".into(),
Primitive::XeTeXrevision => "XeTeXrevision".into(),
Primitive::Etexversion => "eTeXversion".into(),
Primitive::Etexrevision => "eTeXrevision".into(),
Primitive::Uchar => "Uchar".into(),
@@ -3135,7 +3159,10 @@ impl Executor {
Primitive::Umathcharnum => "Umathcharnum".into(),
Primitive::Umathchardef => "Umathchardef".into(),
Primitive::Umathcharnumdef => "Umathcharnumdef".into(),
_ => format!("{p:?}").to_ascii_lowercase(),
_ => self.state
.profile_primitive_name(p)
.map(str::to_owned)
.unwrap_or_else(|| format!("{p:?}").to_ascii_lowercase()),
};
format!("{escape}{name}")
}
@@ -4207,15 +4234,13 @@ impl Executor {
}
Some(Sfcode) => {
self.finish_text(true)?;
let c = self.integer(files)?;
let c = u8::try_from(c)
.map_err(|_| self.error("sfcode index must be in 0..255", self.current))?;
let c = self.scan_space_factor_code_index(files)?;
self.optional_equals(files)?;
let value = self.integer(files)?;
if !(0..32768).contains(&value) {
return self.fail("sfcode must be in 0..32767");
}
let equivalent = self.state.sfcode(c) == value as u16;
let equivalent = self.state.space_factor_code(c) == value as u16;
self.assign_equivalence(Key::Sfcode(c), global, equivalent, files, |state| {
state.assign_sfcode(c, value as u16, global);
})?;
@@ -64,6 +64,15 @@ impl Executor {
}
}
fn pdf_output_mode(&mut self) -> i32 {
match self.state.input_profile() {
// XeTeX always sends shipouts to its device. The native job
// renders those operations without a pdfTeX mode register.
InputProfile::XeTeX => 1,
_ => self.read_parameter(Parameter::Pdfoutput).width(),
}
}
pub(super) fn validate_pdf_final_state(&mut self) -> Result<(), Error> {
if let Some(options) = self.state.pdf_file_options.clone() {
self.reads.insert(Dependency::GlyphUnicode);
@@ -73,7 +82,7 @@ impl Executor {
self.pdf_token_parameter_bytes(TokenParameter::Pdfpagesattr)?;
}
self.reads.insert(Dependency::PdfFileState);
let mode = self.read_parameter(Parameter::Pdfoutput).width();
let mode = self.pdf_output_mode();
if self.state.output_mode_set != Some(mode) {
return self.fail("native pdfoutput cannot change after output has started");
}
@@ -194,7 +203,7 @@ impl Executor {
files: &mut impl SourceProvider,
) -> Result<Option<PdfPageData>, Error> {
self.reads.insert(Dependency::PdfFileState);
let mode = self.read_parameter(Parameter::Pdfoutput).width();
let mode = self.pdf_output_mode();
if self
.state
.output_mode_set
@@ -262,7 +271,7 @@ impl Executor {
}
let driver = match self.state.input_profile() {
InputProfile::TeX8Bit => PdfDriver::PdfTeX,
InputProfile::UnicodeScalar => PdfDriver::Xdv,
InputProfile::UnicodeScalar | InputProfile::XeTeX => PdfDriver::Xdv,
};
Ok(Some(PdfPageData {
driver,
@@ -213,7 +213,7 @@ impl Executor {
let rendered = self.token_list_text(&tokens);
let profile = self.state.input_profile();
let bytes = match profile {
InputProfile::UnicodeScalar => rendered.into_bytes(),
InputProfile::UnicodeScalar | InputProfile::XeTeX => rendered.into_bytes(),
InputProfile::TeX8Bit => rendered
.chars()
.map(|c| {
@@ -10,7 +10,7 @@ impl Executor {
InputProfile::TeX8Bit if !(0..=255).contains(&value) => {
self.fail("mathcode index must be in 0..255")
}
InputProfile::UnicodeScalar if !(0..=0x10_ffff).contains(&value) => {
InputProfile::UnicodeScalar | InputProfile::XeTeX if !(0..=0x10_ffff).contains(&value) => {
self.fail("Bad character code")
}
_ => Ok(value as u32),
@@ -278,7 +278,7 @@ impl Executor {
}
let magnification = self.prepare_magnification()?;
let pdf = self.pdf_page_data(files)?;
let unicode_pages = self.state.input_profile() == InputProfile::UnicodeScalar;
let unicode_pages = self.state.input_profile() != InputProfile::TeX8Bit;
// The XDV driver uses a physical sheet and origin, then applies
// magnification to the DVI movements relative to that origin.
let origin = |value| {
@@ -351,7 +351,7 @@ impl Executor {
return Ok(());
}
let font = self.state.text_font();
let opentype = if self.state.input_profile() == super::super::InputProfile::UnicodeScalar {
let opentype = if self.state.input_profile() != super::super::InputProfile::TeX8Bit {
self.state.fonts.font(font).map_err(|e| self.error(e, token.span))?.opentype().cloned()
} else {
None
@@ -363,9 +363,8 @@ impl Executor {
if self.paragraph.is_none() {
self.begin_paragraph(token.invocation.unwrap_or(token.span), true)?;
}
let space_factor = if let Some(slot) = slot {
self.reads.insert(Dependency::SfCode(slot));
self.state.sfcode(slot)
let space_factor = if slot.is_some() || self.state.input_profile() == InputProfile::XeTeX {
self.read_space_factor_code(u32::from(c))
} else {
1000
};
@@ -664,7 +663,7 @@ impl Executor {
self.reads.insert(Dependency::FontResources);
let defaults = self.font_defaults();
let from = self.sources[self.current.source].name.clone();
let request = if self.state.input_profile() == super::super::InputProfile::UnicodeScalar {
let request = if self.state.input_profile() != super::super::InputProfile::TeX8Bit {
crate::opentype::Request::parse(&file).map_err(|e| self.error(e, self.current))?
} else {
None
@@ -220,6 +220,7 @@ impl Executor {
| Primitive::Pdflastypos
| Primitive::Numexpr
| Primitive::Etexversion
| Primitive::XeTeXversion
| Primitive::Currentgrouplevel
| Primitive::Currentgrouptype
| Primitive::Badness
@@ -225,7 +225,7 @@ impl Executor {
}
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::Sfcode(c) => (format!("sfcode{c}"), self.state.space_factor_code(*c).to_string()),
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 = 59;
const COMPATIBLE_SCHEMAS: [u32; 28] = [
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, SCHEMA,
const SCHEMA: u32 = 60;
const COMPATIBLE_SCHEMAS: [u32; 29] = [
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, SCHEMA,
];
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
@@ -1,4 +1,4 @@
//! Input decoding is a job profile, independent of e-TeX primitive availability.
//! Job input decoding and the explicit XeTeX compatibility profile.
//! Both paths retain original byte offsets; the byte path never recodes a file.
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize,
@@ -7,18 +7,22 @@ pub enum InputProfile {
TeX8Bit,
#[default]
UnicodeScalar,
/// UTF-8 input, XeTeX primitives and XDV-device semantics.
XeTeX,
}
impl InputProfile {
pub(super) fn characters(self, data: &[u8]) -> Result<Characters<'_>, std::str::Utf8Error> {
Ok(match self {
Self::TeX8Bit => Characters::Bytes(data.iter().enumerate()),
Self::UnicodeScalar => Characters::Unicode(std::str::from_utf8(data)?.char_indices()),
Self::UnicodeScalar | Self::XeTeX => {
Characters::Unicode(std::str::from_utf8(data)?.char_indices())
}
})
}
pub(super) fn width(self, c: char) -> usize {
match self {
Self::TeX8Bit => 1,
Self::UnicodeScalar => c.len_utf8(),
Self::UnicodeScalar | Self::XeTeX => c.len_utf8(),
}
}
}
@@ -451,6 +451,7 @@ pub enum Dependency {
OutputStream(u8),
ParagraphToken,
UnicodeMathCode(u32),
UnicodeSfCode(u32),
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
@@ -295,7 +295,7 @@ impl Mouth {
encoded[0] = separator as u8;
&encoded[..1]
}
super::InputProfile::UnicodeScalar => {
super::InputProfile::UnicodeScalar | super::InputProfile::XeTeX => {
separator.encode_utf8(&mut encoded).as_bytes()
}
};
@@ -126,6 +126,31 @@ pub enum ParameterValue {
Quantity(RegisterValue),
}
impl Parameter {
pub(super) fn pdftex_only(self) -> bool {
matches!(
self,
Self::Pdfoutput
| Self::Pdfmajorversion
| Self::Pdfminorversion
| Self::Pdfobjcompresslevel
| Self::Pdfcompresslevel
| Self::Pdfdecimaldigits
| Self::Pdfpkresolution
| Self::Pdfimageresolution
| Self::Pdfgentounicode
| Self::Pdfsuppresswarningdupmap
| Self::Pdfinfoomitdate
| Self::Pdfhorigin
| Self::Pdfvorigin
| Self::Pdflinkmargin
| Self::Pdfdestmargin
| Self::Pdfprotrudechars
| Self::Pdfprependkern
| Self::Pdfappendkern
| Self::Pdfadjustspacing
)
}
pub const ALL: &'static [Self] = &[
Self::Pdfoutput,
Self::Pdfmajorversion,
+165 -69
View File
@@ -361,6 +361,8 @@ pub enum Primitive {
Umathcharnumdef,
Uchar,
Ucharcat,
XeTeXversion,
XeTeXrevision,
}
impl Primitive {
@@ -413,6 +415,7 @@ impl Primitive {
| Jobname
| Pdfcreationdate
| Pdftexrevision
| XeTeXrevision
| Pdfstrcmp
| Pdfmatch
| Pdflastmatch
@@ -530,7 +533,7 @@ pub(super) enum Key {
Box(u16),
Mathcode(u32),
Delcode(u8),
Sfcode(u8),
Sfcode(u32),
CaseCode(super::CaseCode, char),
Mathfont(u8, u8),
Mathcodenum(u32),
@@ -669,7 +672,7 @@ pub struct State {
mathcodes: BTreeMap<u32, super::MathCode>,
delcodes: BTreeMap<u8, i32>,
#[serde(default)]
sfcodes: BTreeMap<u8, u16>,
sfcodes: BTreeMap<u32, u16>,
#[serde(with = "ordered_map")]
case_codes: BTreeMap<(super::CaseCode, char), u32>,
#[serde(with = "ordered_map")]
@@ -751,6 +754,82 @@ fn buffered_fingerprint_matches_the_ordered_state_hash() {
check(&state);
}
// These primitives belong to the pdfTeX command surface. Position queries,
// page dimensions and the shared margin-kern extension are installed separately.
const PDFTEX_ONLY_PRIMITIVES: &[(&str, Primitive)] = {
use Primitive::*;
&[
("knbccode", Knbccode),
("knaccode", Knaccode),
("efcode", Efcode),
("pdffontexpand", Pdffontexpand),
("letterspacefont", Letterspacefont),
("pdffilesize", Pdffilesize),
("pdffilemoddate", Pdffilemoddate),
("pdfmdfivesum", Pdfmdfivesum),
("pdfximage", Pdfximage),
("pdfrefximage", Pdfrefximage),
("pdflastximage", Pdflastximage),
("pdflastximagepages", Pdflastximagepages),
("pdflastximagecolordepth", Pdflastximagecolordepth),
("pdfcreationdate", Pdfcreationdate),
("pdfshellescape", Pdfshellescape),
("pdfstrcmp", Pdfstrcmp),
#[cfg(all(target_os = "linux", target_env = "gnu"))]
("pdfmatch", Pdfmatch),
#[cfg(all(target_os = "linux", target_env = "gnu"))]
("pdflastmatch", Pdflastmatch),
("pdfcolorstackinit", Pdfcolorstackinit),
("pdfobj", Pdfobj),
("pdfrefobj", Pdfrefobj),
("pdflastobj", Pdflastobj),
("pdflastlink", Pdflastlink),
("pdfrandomseed", Pdfrandomseed),
("pdfsetrandomseed", Pdfsetrandomseed),
("pdfuniformdeviate", Pdfuniformdeviate),
("pdfnormaldeviate", Pdfnormaldeviate),
("pdfpageref", Pdfpageref),
("pdfliteral", Pdfliteral),
("pdfcolorstack", Pdfcolorstack),
("pdfsave", Pdfsave),
("pdfstartlink", Pdfstartlink),
("pdfendlink", Pdfendlink),
("pdfrunninglinkoff", Pdfrunninglinkoff),
("pdfrunninglinkon", Pdfrunninglinkon),
("pdfinterwordspaceon", Pdfinterwordspaceon),
("pdfinterwordspaceoff", Pdfinterwordspaceoff),
("pdffakespace", Pdffakespace),
("pdfspacefont", Pdfspacefont),
("pdfdest", Pdfdest),
("pdfcatalog", Pdfcatalog),
("pdfoutline", Pdfoutline),
("pdfinfo", Pdfinfo),
("pdfsetmatrix", Pdfsetmatrix),
("pdfrestore", Pdfrestore),
("pdfglyphtounicode", Pdfglyphtounicode),
("pdfmapfile", Pdfmapfile),
("pdfmapline", Pdfmapline),
("pdffontattr", Pdffontattr),
("pdfnobuiltintounicode", Pdfnobuiltintounicode),
]
};
const XETEX_PRIMITIVE_ALIASES: &[(&str, Primitive)] = {
use Primitive::*;
&[
("creationdate", Pdfcreationdate),
("filemoddate", Pdffilemoddate),
("filesize", Pdffilesize),
("mdfivesum", Pdfmdfivesum),
("normaldeviate", Pdfnormaldeviate),
("randomseed", Pdfrandomseed),
("setrandomseed", Pdfsetrandomseed),
("shellescape", Pdfshellescape),
("strcmp", Pdfstrcmp),
("uniformdeviate", Pdfuniformdeviate),
]
};
impl Default for State {
fn default() -> Self {
use Primitive::*;
@@ -825,12 +904,7 @@ impl Default for State {
("hyphenchar", Hyphenchar),
("lpcode", Lpcode),
("rpcode", Rpcode),
("knbccode", Knbccode),
("knaccode", Knaccode),
("efcode", Efcode),
("pdffontexpand", Pdffontexpand),
("fontname", Fontname),
("letterspacefont", Letterspacefont),
("fontdimen", Fontdimen),
("skewchar", Skewchar),
("mathchar", Mathchar),
@@ -1009,60 +1083,13 @@ impl Default for State {
("message", Message),
("errmessage", Errmessage),
("end", End),
("pdffilesize", Pdffilesize),
("pdffilemoddate", Pdffilemoddate),
("pdfmdfivesum", Pdfmdfivesum),
("pdfximage", Pdfximage),
("pdfrefximage", Pdfrefximage),
("pdflastximage", Pdflastximage),
("pdflastximagepages", Pdflastximagepages),
("pdflastximagecolordepth", Pdflastximagecolordepth),
("jobname", Jobname),
("pdfcreationdate", Pdfcreationdate),
("pdfshellescape", Pdfshellescape),
("pdfstrcmp", Pdfstrcmp),
#[cfg(all(target_os = "linux", target_env = "gnu"))]
("pdfmatch", Pdfmatch),
#[cfg(all(target_os = "linux", target_env = "gnu"))]
("pdflastmatch", Pdflastmatch),
("pdfcolorstackinit", Pdfcolorstackinit),
("pdfobj", Pdfobj),
("pdfrefobj", Pdfrefobj),
("pdflastobj", Pdflastobj),
("pdflastlink", Pdflastlink),
("pdfrandomseed", Pdfrandomseed),
("pdfsetrandomseed", Pdfsetrandomseed),
("pdfuniformdeviate", Pdfuniformdeviate),
("pdfnormaldeviate", Pdfnormaldeviate),
("pdfpageref", Pdfpageref),
("partokenname", Partokenname),
("pdfliteral", Pdfliteral),
("leftmarginkern", Leftmarginkern),
("rightmarginkern", Rightmarginkern),
("pdfcolorstack", Pdfcolorstack),
("pdfsave", Pdfsave),
("pdfstartlink", Pdfstartlink),
("pdfendlink", Pdfendlink),
("pdfrunninglinkoff", Pdfrunninglinkoff),
("pdfrunninglinkon", Pdfrunninglinkon),
("pdfinterwordspaceon", Pdfinterwordspaceon),
("pdfinterwordspaceoff", Pdfinterwordspaceoff),
("pdffakespace", Pdffakespace),
("pdfspacefont", Pdfspacefont),
("pdfdest", Pdfdest),
("pdfcatalog", Pdfcatalog),
("pdfoutline", Pdfoutline),
("pdfinfo", Pdfinfo),
("pdfsetmatrix", Pdfsetmatrix),
("pdfsavepos", Pdfsavepos),
("pdflastxpos", Pdflastxpos),
("pdflastypos", Pdflastypos),
("pdfrestore", Pdfrestore),
("pdfglyphtounicode", Pdfglyphtounicode),
("pdfmapfile", Pdfmapfile),
("pdfmapline", Pdfmapline),
("pdffontattr", Pdffontattr),
("pdfnobuiltintounicode", Pdfnobuiltintounicode),
("dump", Dump),
("indent", Indent),
("noindent", Noindent),
@@ -1136,6 +1163,7 @@ impl Default for State {
] {
state.parameters.insert(p, v);
}
state.install_pdftex_primitives();
state.install_unicode_commands();
state
}
@@ -1404,6 +1432,7 @@ impl State {
Meaning::Primitive(primitive),
);
}
self.install_xetex_etex_commands();
self
}
pub fn register_limit(&self) -> u16 {
@@ -1544,22 +1573,81 @@ impl State {
("ifpdfabsnum", Primitive::Ifpdfabsnum),
("ifpdfabsdim", Primitive::Ifpdfabsdim),
] {
let name = CommandName::Control(name.into());
match profile {
super::InputProfile::TeX8Bit => {
self.commands.insert(name, Meaning::Primitive(primitive));
}
super::InputProfile::UnicodeScalar => {
if self.commands.get(&name) == Some(&Meaning::Primitive(primitive)) {
self.commands.remove(&name);
}
}
}
self.update_profile_command(
name,
Meaning::Primitive(primitive),
profile == super::InputProfile::TeX8Bit,
);
}
self.install_pdftex_primitives();
for &(name, primitive) in XETEX_PRIMITIVE_ALIASES {
self.update_profile_command(
name,
Meaning::Primitive(primitive),
profile == super::InputProfile::XeTeX,
);
}
self.install_unicode_commands();
self.install_xetex_etex_commands();
self
}
fn update_profile_command(&mut self, name: &str, meaning: Meaning, enabled: bool) {
let name = CommandName::Control(name.into());
if enabled {
self.commands.entry(name).or_insert(meaning);
} else if self.commands.get(&name) == Some(&meaning) {
self.commands.remove(&name);
}
}
fn install_pdftex_primitives(&mut self) {
let enabled = self.input_profile != super::InputProfile::XeTeX;
for &(name, primitive) in PDFTEX_ONLY_PRIMITIVES {
self.update_profile_command(name, Meaning::Primitive(primitive), enabled);
}
for parameter in [
TokenParameter::Pdfpageresources,
TokenParameter::Pdfpageattr,
TokenParameter::Pdfpagesattr,
] {
self.update_profile_command(
&parameter.name(),
Meaning::TokenParameter(parameter),
enabled,
);
}
for &parameter in Parameter::ALL {
if parameter.pdftex_only() {
self.update_profile_command(
&parameter.name(),
Meaning::Parameter(parameter),
enabled,
);
}
}
}
fn install_xetex_etex_commands(&mut self) {
let enabled = self.input_profile == super::InputProfile::XeTeX
&& self.profile == Profile::EtexBootstrap;
for (name, primitive) in [
("XeTeXversion", Primitive::XeTeXversion),
("XeTeXrevision", Primitive::XeTeXrevision),
] {
self.update_profile_command(name, Meaning::Primitive(primitive), enabled);
}
}
pub(super) fn profile_primitive_name(&self, primitive: Primitive) -> Option<&'static str> {
if self.input_profile == super::InputProfile::XeTeX {
return XETEX_PRIMITIVE_ALIASES
.iter()
.find_map(|&(name, meaning)| (meaning == primitive).then_some(name));
}
None
}
fn install_unicode_commands(&mut self) {
use Primitive::*;
for (name, primitive) in [
@@ -1580,7 +1668,7 @@ impl State {
] {
let name = CommandName::Control(name.into());
let meaning = Meaning::Primitive(primitive);
if self.input_profile == super::InputProfile::UnicodeScalar {
if self.input_profile != super::InputProfile::TeX8Bit {
self.commands.insert(name, meaning);
} else if self.commands.get(&name) == Some(&meaning) {
self.commands.remove(&name);
@@ -1653,7 +1741,7 @@ impl State {
pub(super) fn math_family_count(&self) -> i32 {
match self.input_profile {
super::InputProfile::TeX8Bit => 16,
super::InputProfile::UnicodeScalar => 256,
super::InputProfile::UnicodeScalar | super::InputProfile::XeTeX => 256,
}
}
pub fn math_font(&self, size: u8, family: u8) -> FontId {
@@ -1663,12 +1751,20 @@ impl State {
.unwrap_or(FontId::NULL)
}
pub fn sfcode(&self, c: u8) -> u16 {
self.space_factor_code(u32::from(c))
}
pub(super) fn space_factor_code(&self, c: u32) -> u16 {
self.sfcodes
.get(&c)
.copied()
.unwrap_or(if c.is_ascii_uppercase() { 999 } else { 1000 })
.unwrap_or(if (u32::from(b'A')..=u32::from(b'Z')).contains(&c) {
999
} else {
1000
})
}
pub(super) fn assign_sfcode(&mut self, c: u8, value: u16, global: bool) {
pub(super) fn assign_sfcode(&mut self, c: u32, value: u16, global: bool) {
self.save(Key::Sfcode(c), global);
self.sfcodes.insert(c, value);
}
@@ -0,0 +1,160 @@
use texrra_tex_core::execution::*;
struct TestDevice;
impl SourceProvider for TestDevice {
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
Err(format!("unexpected input {name}"))
}
fn default_pk_resolution(&mut self) -> Result<i32, String> {
Ok(600)
}
}
fn run(state: State, text: &str) -> Execution {
Executor::new(state, Limits::default())
.run(source(text), &mut NoFiles)
.unwrap()
}
fn source(text: &str) -> SourceFile {
SourceFile {
name: "profile.tex".into(),
data: text.as_bytes().into(),
}
}
fn messages(result: &Execution) -> Vec<&str> {
result
.events
.iter()
.filter_map(|event| match event {
Event::Message { text, .. } => Some(text.as_str()),
_ => None,
})
.collect()
}
#[test]
fn xetex_primitives_follow_each_profiles_language_and_device() {
let tex = r"\catcode123=1 \catcode125=2
\message{\meaning\XeTeXversion/\meaning\XeTeXrevision/\meaning\pdfoutput}
\message{\meaning\strcmp/\meaning\pdfstrcmp/\meaning\pdfsavepos}
\message{\meaning\pdftexversion/\meaning\Uchar/\meaning\pdfpagesattr}
\end";
for (profile, etex, expected) in [
(
InputProfile::XeTeX,
true,
[
r"\XeTeXversion/\XeTeXrevision/undefined",
r"\strcmp/undefined/\pdfsavepos",
r"undefined/\Uchar/undefined",
],
),
(
InputProfile::XeTeX,
false,
[
"undefined/undefined/undefined",
r"\strcmp/undefined/\pdfsavepos",
r"undefined/\Uchar/undefined",
],
),
(
InputProfile::UnicodeScalar,
true,
[
r"undefined/undefined/\pdfoutput",
r"undefined/\pdfstrcmp/\pdfsavepos",
r"undefined/\Uchar/\pdfpagesattr",
],
),
(
InputProfile::TeX8Bit,
true,
[
r"undefined/undefined/\pdfoutput",
r"undefined/\pdfstrcmp/\pdfsavepos",
r"\pdftexversion/undefined/\pdfpagesattr",
],
),
] {
let state = State::initex();
let state = if etex { state.with_etex() } else { state };
let result = run(state.with_input_profile(profile), tex);
assert_eq!(messages(&result), expected);
}
}
#[test]
fn xetex_format_preserves_internal_version_and_profile_identity() {
let seed = r#"\catcode123=1 \catcode125=2
\let\versionAlias\XeTeXversion
\let\revisionAlias\XeTeXrevision
\edef\revisionText{\revisionAlias}
\sfcode"1D6FC=3000
\dump"#;
let state = State::initex()
.with_input_profile(InputProfile::XeTeX)
.with_etex();
let dump = run(state.clone(), seed);
let bytes = FormatImage::from_dump(dump, Vec::new(), Vec::new())
.unwrap()
.encode()
.unwrap();
let time = JobTime::new(2025, 10, 9, 0).unwrap();
let load = |profile| {
FormatImage::decode(&bytes).unwrap().new_job(
state.profile(),
profile,
time,
Limits::default(),
|_| Ok(seed.as_bytes().to_vec()),
)
};
assert!(matches!(
load(InputProfile::UnicodeScalar),
Err(message) if message == "native format profile mismatch"
));
let result = load(InputProfile::XeTeX)
.unwrap()
.with_native_pages()
.run(
source(
r#"\count0=\versionAlias
\dimen0=\the\versionAlias\revisionAlias pt
\message{\the\versionAlias/\number\versionAlias/\the\count0/\revisionText/\the\dimen0}
{\sfcode"1D6FC=1500 \message{\the\sfcode"1D6FC }}
\message{\the\sfcode"1D6FC }
\shipout\hbox{\special{pdf:literal 0 0 5 5 re S}\vrule width5pt height3pt depth0pt}
\end"#,
),
&mut TestDevice,
)
.unwrap();
assert_eq!(messages(&result), ["0/0/0/.999998/1.0pt", "1500", "3000"]);
assert!(result.reads.contains(&Dependency::UnicodeSfCode(0x1D6FC)));
let page = result
.events
.iter()
.find_map(|event| match event {
Event::Shipout(page) => Some(page),
_ => None,
})
.unwrap();
assert!(matches!(
page.device.pdf.as_ref().map(|data| data.driver),
Some(texrra_tex_core::pdf_device::PdfDriver::Xdv)
));
assert!(
page.display_list()
.unwrap()
.items
.iter()
.any(|item| matches!(
item,
texrra_tex_core::render::DisplayItem::PdfGraphics { .. }
))
);
}
+17 -9
View File
@@ -4,23 +4,31 @@
正式构建、37精确诊断、原全部 PDF/字形/数学门禁及新的实际字节/文件名门禁通过。
W1 与整个 [P2-M1](NATIVE_FORMAT_ARTICLE_STAGE.md) 尚未完成。
## XeTeX 兼容入口
`--input-profile xetex --etex` 通过同一套编译请求选择 XeTeX 模式。
Rust 调用使用 `InputProfile::XeTeX`。格式、执行状态和续执行的身份包含所选模式。
XeTeX 模式使用 UTF-8、宽字符和数学编码、OpenType 与 XDV 设备语义,接受
真实的共用位置、页面和文件查询。`\XeTeXversion` 与 `\XeTeXrevision`
通过 e-TeX 扩展启用,参考级别为 XeTeX 0.999998。旧 `tex8bit` 和
`unicode` 入口仍用于相应的既有作业和格式。实际 LaTeX 迁移进度见
[阶段记录](P2_M1_PROGRESS.md#xetex-兼容入口与原样格式)。
## 数据与执行边界
- SourceFile 保存原始 `data: Vec<u8>`,不再以 String 代替文件。SourceProvider 的
read_line 返回实际 `Option<Vec<u8>>`,保留物理 CR/LF/CRLF;None 只代表真实 EOF。
文件查找/读取与流范围的 SHA-256 仍对实际原字节计算,含非法 UTF-8 字节。
- InputProfile 独立于 e-TeX 原语启用状态,选择 TeX8Bit 或 UnicodeScalar。两者走
同一个原生 mouth/执行器;按当前 profile 逐字节或逐 scalar 读取,不做 Latin-1
转码、输入重写、模板判断或宿主宏模拟。
- 原生 CLI 默认 TeX8Bit,可显式选择 `--input-profile tex8bit|unicode`。库调用可用
`State::with_input_profile` 选择;现有库默认 UnicodeScalar,调用 pdfTeX 兼容作业
时须显式选择 TeX8Bit。profile 进入真实 State 指纹/序列化和续执行状态。
- e-TeX 的启用状态独立于输入解码。TeX8Bit 逐字节读取,UnicodeScalar 和 XeTeX
逐 Unicode 标量读取,三者共用原生 mouth/执行器并保留原始字节范围。
- 原生 CLI 默认 TeX8Bit,可显式选择 `--input-profile tex8bit|unicode|xetex`。
`State::with_input_profile` 提供同样的库接口,库默认 UnicodeScalar。
profile 进入真实 State 指纹、序列化和续执行状态。
- 文件名在宿主边界将实际 byte 字符序列解码一次,避免 UTF-8 名称被重复编码;
input/openin/openout 共用此路径。当前 World 接口只接受 UTF-8 主机名称,非法
UTF-8 文件名明确失败,尚未声称任意 Unix 字节路径支持。
- TeX8Bit 的字符值为实际 0..255,类别码查询与赋值遵守该范围;UnicodeScalar
对真实 UTF-8 解码,非法输入明确失败。这个名字只表示输入解码,未宣称 XeTeX
字体、Unicode 数学、编码映射或 shaping 已经实现。
- TeX8Bit 的字符值为实际 0..255,类别码查询与赋值遵守该范围。UnicodeScalar
和 XeTeX 直接解码原始 UTF-8,遇到非法输入时给出诊断。
- 物理行按原字节边界建立,保留源范围;CR/LF/CRLF、尾空格、endlinechar 的加载
时机沿用真实 mouth。Unicode 的源范围仍是原 UTF-8 字节偏移,诊断列按 scalar
计数;TeX8Bit 列按字节计数,不再以 UTF-8 边界切片触发错误。
+26
View File
@@ -2175,6 +2175,32 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
全量编译一致。incremental-receipt.json 的 SHA-256 为
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
### XeTeX 兼容入口与原样格式
CLI 经 `--input-profile xetex --etex`、库经 `InputProfile::XeTeX`
选择同一个原生 XeTeX 模式。该模式使用既有的 Unicode 代码表、OpenType
度量和 XDV 设备,单独安装 XeTeX/e-TeX 的版本查询,并遵守参考的文件、
字符串、作业日期、随机数和设备相关命令名。对照 XeTeX 0.999998 的
94 个命令探测中,92 个的可用性和含义一致,计时的 \elapsedtime 和
\resettimer 尚待实现。真实文件大小、MD5、修改时间、字符比较、禁止
shell escape 和固定种子的随机数逐项一致。
XeTeX 的 Unicode \sfcode 接入分组恢复、数量查询、真实段落空格及
依赖记录。相同的 Latin Modern Math 字体和输入产生相同的 U+1D6FC
空格因子、句末胶宽及 600 dpi 灰度图。原有模式继续使用各自原有的范围。
schema60 保存模式和宽表。新格式重载能实际出页并执行 PDF literal。
原样 schema58 在原模式加载成功,同一旧镜像用于新的 XeTeX 模式时
报告格式身份不匹配。14 项定向回归通过,详见
target/p3-xetex-profile/targeted-profile-final.log。
发行版原样 xelatex.ini 的参考作业已生成格式。原生原样作业仍在运行,
现场位于 target/p3-xetex-profile/xelatex-native 与 xelatex-native-final。
独立 TU 字体探测用发行版原样 tex-text.tec 确认真实映射行为。原生
在解析字体映射选项时报错,保留 tex-text-reference 和 tex-text-native
的对照产物。接续实际字体映射及待核对的类包和输出路径。
[XeTeX 版本与命令类型](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/xetex.web#L28436-L28446)
[XeTeX 字体映射资源](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/xetexdir/XeTeX_ext.c#L564-L604)
### Unicode 字符定义和展开
原生 Unicode 入口的 \chardef 可保存并查询 0–U+10FFFF 的字符编号。
+4 -3
View File
@@ -30,7 +30,7 @@ fn run() -> Result<(), String> {
let mut args = env::args().skip(1);
let Some(command) = args.next() else {
return Err(
"usage: texrra serve [input.tex] [port] | texrra native [--job] [--initex] [--etex] [--dump-format | --load-format FILE] [--step-limit N] [--input-profile tex8bit|unicode] [--texmf-root DIR] [--input-policy tex|project] [--project-snapshot FILE] [--generated-initial JSON | --observe-generated-initial] [--resource-manifest JSON] [--layout-manifest JSON] [--failure-manifest JSON] input.tex [output.pdf]".into(),
"usage: texrra serve [input.tex] [port] | texrra native [--job] [--initex] [--etex] [--dump-format | --load-format FILE] [--step-limit N] [--input-profile tex8bit|unicode|xetex] [--texmf-root DIR] [--input-policy tex|project] [--project-snapshot FILE] [--generated-initial JSON | --observe-generated-initial] [--resource-manifest JSON] [--layout-manifest JSON] [--failure-manifest JSON] input.tex [output.pdf]".into(),
);
};
if command == "native" {
@@ -56,7 +56,8 @@ fn run() -> Result<(), String> {
input_profile = match args.next().as_deref() {
Some("tex8bit") => texrra_tex_core::execution::InputProfile::TeX8Bit,
Some("unicode") => texrra_tex_core::execution::InputProfile::UnicodeScalar,
_ => return Err("--input-profile requires tex8bit or unicode".into()),
Some("xetex") => texrra_tex_core::execution::InputProfile::XeTeX,
_ => return Err("--input-profile requires tex8bit, unicode or xetex".into()),
};
}
Some("--job") => native_job_target = true,
@@ -145,7 +146,7 @@ fn run() -> Result<(), String> {
.map(PathBuf::from)
.unwrap_or_else(|| input.with_extension(if dump_format { "tfx" } else { "pdf" }));
if args.next().is_some() {
return Err("usage: texrra native [--job] [--initex] [--etex] [--dump-format | --load-format FILE] [--step-limit N] [--input-profile tex8bit|unicode] [--texmf-root DIR] [--input-policy tex|project] [--project-snapshot FILE] [--generated-initial JSON | --observe-generated-initial] [--resource-manifest JSON] [--layout-manifest JSON] [--failure-manifest JSON] input.tex [output.pdf]".into());
return Err("usage: texrra native [--job] [--initex] [--etex] [--dump-format | --load-format FILE] [--step-limit N] [--input-profile tex8bit|unicode|xetex] [--texmf-root DIR] [--input-policy tex|project] [--project-snapshot FILE] [--generated-initial JSON | --observe-generated-initial] [--resource-manifest JSON] [--layout-manifest JSON] [--failure-manifest JSON] input.tex [output.pdf]".into());
}
let diagnostic = native_pdf(
&input,