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

+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);
}