diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index 6422abe..cd4c6f4 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -2564,6 +2564,16 @@ impl Executor { self.state.fonts.protrusion_code(font, slot as u8, right) }) } + Meaning::Primitive(Primitive::Tagcode) => { + let (font, slot) = self.font_character_target(files)?; + self.reads.insert(Dependency::FontResources); + self.state.fonts.tag_code(font, slot).map_err(|error| self.error(error, self.current)) + } + Meaning::Primitive(Primitive::Pdfnoligatures) => { + let font = self.font_identifier(files)?; + self.reads.insert(Dependency::FontResources); + self.state.fonts.no_ligatures(font).map_err(|error| self.error(error, self.current)) + } Meaning::Primitive(p @ (Primitive::Hyphenchar | Primitive::Skewchar)) => { let font = self.font_identifier(files)?; let values = self.state.font_integers(font); @@ -4746,6 +4756,20 @@ impl Executor { self.state.fonts.set_protrusion_code(font, slot as u8, right, code); } } + Some(Tagcode) => { + let (font, slot) = self.font_character_target(files)?; + self.optional_equals(files)?; + let mask = self.integer(files)?; + self.finish_text(true)?; + self.state.fonts.clear_tag_code(font, slot, mask) + .map_err(|error| self.error(error, self.current))?; + } + Some(Pdfnoligatures) => { + let font = self.font_identifier(files)?; + self.finish_text(true)?; + self.state.fonts.suppress_ligatures(font) + .map_err(|error| self.error(error, self.current))?; + } Some(Hyphenchar | Skewchar) => { let font = self.font_identifier(files)?; self.optional_equals(files)?; diff --git a/crates/texrra-tex-core/src/execution/engine/display.rs b/crates/texrra-tex-core/src/execution/engine/display.rs index fd03f77..b940086 100644 --- a/crates/texrra-tex-core/src/execution/engine/display.rs +++ b/crates/texrra-tex-core/src/execution/engine/display.rs @@ -418,6 +418,8 @@ impl Executor { | Knaccode | Efcode | Pdffontexpand + | Pdfnoligatures + | Tagcode | Skewchar | Textfont | Scriptfont diff --git a/crates/texrra-tex-core/src/execution/engine/math.rs b/crates/texrra-tex-core/src/execution/engine/math.rs index f64d3c5..7306624 100644 --- a/crates/texrra-tex-core/src/execution/engine/math.rs +++ b/crates/texrra-tex-core/src/execution/engine/math.rs @@ -896,7 +896,7 @@ impl Executor { | Umathcode | Umathcodenum | Delcode | Udelcode | Udelcodenum | Count | Countdef | Dimen | Dimendef | Skip | Skipdef | Muskip | Muskipdef | Toks | Toksdef | Advance | Multiply | Divide | Read | Readline - | Font | Fontdimen | Hyphenchar | Skewchar | Lpcode | Rpcode | Efcode | Pdffontexpand + | Font | Fontdimen | Hyphenchar | Skewchar | Lpcode | Rpcode | Efcode | Pdffontexpand | Pdfnoligatures | Tagcode | Knbccode | Knaccode | Letterspacefont | Textfont | Scriptfont | Scriptscriptfont | Endlinechar | Newlinechar | Escapechar | Globaldefs | Time | Day | Month | Year | BeginGroup | EndGroup | Relax | DeferredPrimitive | Message | Errmessage diff --git a/crates/texrra-tex-core/src/execution/engine/quantities.rs b/crates/texrra-tex-core/src/execution/engine/quantities.rs index c6f3c42..a30185c 100644 --- a/crates/texrra-tex-core/src/execution/engine/quantities.rs +++ b/crates/texrra-tex-core/src/execution/engine/quantities.rs @@ -242,6 +242,8 @@ impl Executor { | Primitive::LinePenalties(_) | Primitive::Prevgraf | Primitive::Spacefactor + | Primitive::Pdfnoligatures + | Primitive::Tagcode | Primitive::Hyphenchar | Primitive::Lpcode | Primitive::Rpcode diff --git a/crates/texrra-tex-core/src/execution/font_catalog.rs b/crates/texrra-tex-core/src/execution/font_catalog.rs index 7c6ec96..0120b42 100644 --- a/crates/texrra-tex-core/src/execution/font_catalog.rs +++ b/crates/texrra-tex-core/src/execution/font_catalog.rs @@ -5,7 +5,7 @@ use crate::{ native_font::{LetterspaceProgram, NativeFont}, opentype::{OpenTypeFont, Request}, resources::{LoadedResource, ResourceKind, ResourceVersion}, - tfm::{FontSize, TfmMetrics}, + tfm::{ExtensibleRecipe, FontSize, LigKernCommand, TfmMetrics}, }; use sha2::{Digest, Sha256}; use std::{collections::BTreeMap, sync::Arc}; @@ -64,6 +64,10 @@ pub struct FontInstance { opentype: Option>, parameters: Arc>, integers: FontIntegers, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + suppress_ligature_tags: bool, + #[serde(default, skip_serializing_if = "ClearedFontTags::is_empty")] + cleared_tags: ClearedFontTags, selector: CommandName, #[serde(default, skip_serializing_if = "Option::is_none")] expansion_origin: Option<(FontId, i32)>, @@ -143,6 +147,79 @@ impl FontInstance { } } +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +struct ClearedFontTags([u64; 4]); + +impl ClearedFontTags { + fn is_empty(&self) -> bool { + self.0 == [0; 4] + } + + fn contains(&self, slot: u8) -> bool { + self.0[usize::from(slot / 64)] & (1 << (slot % 64)) != 0 + } + + fn insert(&mut self, slot: u8) { + self.0[usize::from(slot / 64)] |= 1 << (slot % 64); + } +} + +/// Job-owned character programs retain the original font used for painting. +#[derive(Clone, Copy)] +pub(super) struct FontProgram<'a> { + metrics: &'a TfmMetrics, + suppress_ligature_tags: bool, + cleared_tags: &'a ClearedFontTags, +} + +impl FontProgram<'_> { + fn tag(self, slot: u8) -> i32 { + let tag = self.metrics.glyph_tag_code(slot); + if tag > 0 && (self.cleared_tags.contains(slot) || (tag == 1 && self.suppress_ligature_tags)) { + 0 + } else { + tag + } + } + + pub fn lig_kern(self, left: Option, right: u8) -> Option { + if left.is_some_and(|slot| self.suppress_ligature_tags || self.cleared_tags.contains(slot)) { + return None; + } + // The separate left-boundary program is unaffected. + self.metrics.lig_kern(left, right) + } + + pub fn kern(self, left: u8, right: u8) -> i64 { + match self.lig_kern(Some(left), right) { + Some(LigKernCommand::Kern(value)) => value, + _ => 0, + } + } + + pub fn next_larger(self, slot: u8) -> Option { + if self.cleared_tags.contains(slot) { + return None; + } + self.metrics.next_larger(char::from(slot)) + } + + pub fn extensible_recipe(self, slot: u8) -> Option { + if self.cleared_tags.contains(slot) { + return None; + } + self.metrics.extensible_recipe(char::from(slot)) + } +} + +impl std::ops::Deref for FontProgram<'_> { + type Target = TfmMetrics; + + fn deref(&self) -> &Self::Target { + self.metrics + } +} + /// Raw slot and sized integer metrics, with the identity needed by subsequent /// list/geometry consumers. Missing slots produce no character node. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] @@ -265,6 +342,8 @@ impl FontCatalog { hyphen: 45, skew: -1, }, + suppress_ligature_tags: false, + cleared_tags: ClearedFontTags::default(), selector: CommandName::Control("nullfont".into()), expansion_origin: None, automatic_expansion: false, @@ -454,6 +533,8 @@ impl FontCatalog { opentype: Some(font), parameters: Arc::new(parameters), integers: defaults, + suppress_ligature_tags: false, + cleared_tags: ClearedFontTags::default(), selector, expansion_origin: None, automatic_expansion: false, @@ -620,6 +701,8 @@ impl FontCatalog { opentype: None, parameters: Arc::new(parameters), integers: defaults, + suppress_ligature_tags: false, + cleared_tags: ClearedFontTags::default(), selector, expansion_origin: None, automatic_expansion: false, @@ -1139,6 +1222,46 @@ impl FontCatalog { } } + pub(super) fn program(&self, id: FontId) -> Result, String> { + let font = self.font(id)?; + let metrics = font.metrics().ok_or("native TFM character program is unavailable")?; + Ok(FontProgram { + metrics, + suppress_ligature_tags: font.suppress_ligature_tags, + cleared_tags: &font.cleared_tags, + }) + } + + pub(super) fn no_ligatures(&self, id: FontId) -> Result { + if self.font(id)?.metrics().is_none() { + return Ok(1); + } + let program = self.program(id)?; + Ok(i32::from(!(0..=u8::MAX).any(|slot| matches!(program.tag(slot), 1 | 4)))) + } + + pub(super) fn suppress_ligatures(&mut self, id: FontId) -> Result<(), String> { + if self.font(id)?.glyph_font.is_some() { + self.fonts[id.0 as usize].suppress_ligature_tags = true; + } + Ok(()) + } + + pub(super) fn tag_code(&self, id: FontId, slot: u8) -> Result { + if self.font(id)?.metrics().is_none() { + return Ok(-1); + } + Ok(self.program(id)?.tag(slot)) + } + + pub(super) fn clear_tag_code(&mut self, id: FontId, slot: u8, mask: i32) -> Result<(), String> { + let current = self.tag_code(id, slot)?; + if current > 0 && current & (-mask.clamp(-7, 0)) != 0 { + self.fonts[id.0 as usize].cleared_tags.insert(slot); + } + Ok(()) + } + pub fn set_integers(&mut self, id: FontId, integers: FontIntegers) -> Result<(), String> { self.font(id)?; self.fonts[id.0 as usize].integers = integers; diff --git a/crates/texrra-tex-core/src/execution/format_image.rs b/crates/texrra-tex-core/src/execution/format_image.rs index a94827e..8b978ff 100644 --- a/crates/texrra-tex-core/src/execution/format_image.rs +++ b/crates/texrra-tex-core/src/execution/format_image.rs @@ -16,9 +16,9 @@ use std::{ sync::{Arc, Mutex, OnceLock, Weak}, }; -const SCHEMA: u32 = 110; -const COMPATIBLE_SCHEMAS: [u32; 76] = [ - 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, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, SCHEMA, +const SCHEMA: u32 = 111; +const COMPATIBLE_SCHEMAS: [u32; 77] = [ + 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, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, SCHEMA, ]; const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION")); @@ -244,6 +244,9 @@ impl FormatImage { if image.schema < 110 { image.state.install_filedump_command(); } + if image.schema < 111 { + image.state.install_pdf_font_tag_commands(); + } let pdf_objects = image.state.pdf_objects.as_deref(); let mut numbered_images = 0; for (index, saved) in image.pdf_images.iter().enumerate() { diff --git a/crates/texrra-tex-core/src/execution/ligature.rs b/crates/texrra-tex-core/src/execution/ligature.rs index 42a4b9c..c865d1e 100644 --- a/crates/texrra-tex-core/src/execution/ligature.rs +++ b/crates/texrra-tex-core/src/execution/ligature.rs @@ -1,9 +1,9 @@ //! Streaming TFM cursor/ligature-stack execution. A raw input character is //! fetched only after the pending cursor asks for one; inserted ligatures can //! therefore retain or consume components without inventing source characters. -use super::{Span, font_catalog::AutoKern}; +use super::{Span, font_catalog::{AutoKern, FontProgram}}; use crate::provenance::{Derivation, PaintSource}; -use crate::tfm::{LigKernCommand, TfmMetrics}; +use crate::tfm::LigKernCommand; use std::collections::VecDeque; #[derive(Clone, Debug, PartialEq, Eq)] @@ -109,7 +109,7 @@ impl Machine { /// word. Its cursor shares the actual slots, components, ligature stack /// and boundary packing with normal text execution. pub fn reconstitute( - f: &TfmMetrics, + f: FontProgram<'_>, hu: &[Option], mut j: usize, n: usize, @@ -302,7 +302,7 @@ impl Machine { } pub fn feed( &mut self, - f: &TfmMetrics, + f: FontProgram<'_>, c: Component, cancel_left: bool, auto_kern: Option>, @@ -341,7 +341,7 @@ impl Machine { } pub fn finish( &mut self, - f: &TfmMetrics, + f: FontProgram<'_>, right_boundary: bool, auto_kern: Option>, steps: &mut usize, @@ -374,7 +374,7 @@ impl Machine { out.push(Output::Glyph(glyph)); } } - fn advance(&mut self, f: &TfmMetrics, out: &mut Vec) { + fn advance(&mut self, f: FontProgram<'_>, out: &mut Vec) { if let Some(mut right) = self.stack.pop_front() { if right.raw && !f.has_slot(right.glyph.slot) { out.push(Output::Missing( @@ -392,7 +392,7 @@ impl Machine { } fn pump( &mut self, - f: &TfmMetrics, + f: FontProgram<'_>, ending: bool, auto_kern: Option>, steps: &mut usize, diff --git a/crates/texrra-tex-core/src/execution/math_accent.rs b/crates/texrra-tex-core/src/execution/math_accent.rs index 043799c..d114e3a 100644 --- a/crates/texrra-tex-core/src/execution/math_accent.rs +++ b/crates/texrra-tex-core/src/execution/math_accent.rs @@ -22,10 +22,10 @@ impl Converter<'_> { n.nucleus = MathField::Empty; } else if opentype.is_none() && let Ok(code) = u8::try_from(self.state.font_integers(base_font).skew) - && let Ok(base_id) = self.state.fonts.glyph_font(base_font) + && let Ok(program) = self.state.fonts.program(base_font) && let Ok(slot) = u8::try_from(c.slot) { - skew = base_id.metrics().kern(char::from(slot), char::from(code)); + skew = program.kern(slot, code); } } let mut base = self.field(&n.nucleus, style.cramped_style(), &n.source.nucleus)?; @@ -99,10 +99,9 @@ impl Converter<'_> { (mark, x) } else { // Classic accents choose the last TFM list tag that fits the base. - let id = self.font(accent.family, style)?; - let metrics = id.metrics(); + let metrics = self.state.fonts.program(font)?; let mut visited = std::collections::BTreeSet::new(); - while let Some(next) = metrics.next_larger(char::from(accent.slot as u8)) { + while let Some(next) = metrics.next_larger(accent.slot as u8) { if !visited.insert(accent.slot) { return Err("cyclic native accent size list".into()); } diff --git a/crates/texrra-tex-core/src/execution/math_delimiter.rs b/crates/texrra-tex-core/src/execution/math_delimiter.rs index af1cbd2..5b99ed1 100644 --- a/crates/texrra-tex-core/src/execution/math_delimiter.rs +++ b/crates/texrra-tex-core/src/execution/math_delimiter.rs @@ -125,7 +125,7 @@ impl Converter<'_> { continue; } let id = self.state.fonts.glyph_font(font)?; - let m = id.metrics(); + let m = self.state.fonts.program(font)?; let Ok(mut slot) = u8::try_from(c.slot) else { continue; }; @@ -134,7 +134,7 @@ impl Converter<'_> { if !visited.insert(slot) { return Err("cyclic native delimiter size list".into()); } - if m.extensible_recipe(char::from(slot)).is_some() { + if m.extensible_recipe(slot).is_some() { opentype_best = None; best = Some((id, slot)); break 'search; @@ -148,7 +148,7 @@ impl Converter<'_> { break 'search; } } - let Some(next) = m.next_larger(char::from(slot)) else { + let Some(next) = m.next_larger(slot) else { break; }; slot = next; @@ -163,7 +163,7 @@ impl Converter<'_> { metrics.width, metrics.height, metrics.depth, ) } else if let Some((id, slot)) = best { - if let Some(recipe) = id.metrics().extensible_recipe(char::from(slot)) { + if let Some(recipe) = self.state.fonts.program(id.id)?.extensible_recipe(slot) { let repeat = character(id, recipe.repeat, source)?; let unit = repeat.metrics.height + repeat.metrics.depth; let mut extent = 0; diff --git a/crates/texrra-tex-core/src/execution/math_op.rs b/crates/texrra-tex-core/src/execution/math_op.rs index efbc17b..4bc063c 100644 --- a/crates/texrra-tex-core/src/execution/math_op.rs +++ b/crates/texrra-tex-core/src/execution/math_op.rs @@ -120,7 +120,7 @@ impl Converter<'_> { } else { let face = self.font(c.family, style)?; if style.display() - && let Some(next) = face.metrics().next_larger(char::from(c.slot as u8)) + && let Some(next) = self.state.fonts.program(id)?.next_larger(c.slot as u8) && self.state.font_has_slot(id, next) { c.slot = u32::from(next); diff --git a/crates/texrra-tex-core/src/execution/math_ord.rs b/crates/texrra-tex-core/src/execution/math_ord.rs index 4ba6bd0..974675e 100644 --- a/crates/texrra-tex-core/src/execution/math_ord.rs +++ b/crates/texrra-tex-core/src/execution/math_ord.rs @@ -51,7 +51,7 @@ impl Converter<'_> { let Ok(right) = u8::try_from(b.slot) else { return Ok(()); }; - match face.metrics().lig_kern(Some(a.slot as u8), right) { + match self.state.fonts.program(font)?.lig_kern(Some(a.slot as u8), right) { Some(LigKernCommand::Kern(amount)) => { if processed + pending.len() + 2 > self.node_limit { return Err("native math noad capacity exceeded".into()); diff --git a/crates/texrra-tex-core/src/execution/paragraph.rs b/crates/texrra-tex-core/src/execution/paragraph.rs index 2bfe77c..6e00818 100644 --- a/crates/texrra-tex-core/src/execution/paragraph.rs +++ b/crates/texrra-tex-core/src/execution/paragraph.rs @@ -258,7 +258,7 @@ impl Builder { run.machine .put_carry(std::mem::take(&mut self.ligature_carry)); let output = run.machine.finish( - run.font.metrics(), + state.fonts.program(run.font.id)?, right_boundary, FontCatalog::auto_kern_for(state, run.font.id), &mut self.font_steps, @@ -498,7 +498,7 @@ impl Builder { run.machine .put_carry(std::mem::take(&mut self.ligature_carry)); let output = run.machine.feed( - run.font.metrics(), + state.fonts.program(font)?, c, cancel, FontCatalog::auto_kern_for(state, font), diff --git a/crates/texrra-tex-core/src/execution/paragraph/expansion.rs b/crates/texrra-tex-core/src/execution/paragraph/expansion.rs index deccc7f..ef80c83 100644 --- a/crates/texrra-tex-core/src/execution/paragraph/expansion.rs +++ b/crates/texrra-tex-core/src/execution/paragraph/expansion.rs @@ -118,7 +118,7 @@ fn measure( } let variant = state.fonts.expansion_limit(font.id, amount)?; Ok(match right { - Some(right) => variant.metrics().kern(char::from(slot), char::from(right)), + Some(right) => state.fonts.program(variant.id)?.kern(slot, right), None => variant.advance(slot), }) }; @@ -430,7 +430,7 @@ pub(super) fn pack( let capacity = measure(state, left.font, left.slot, i64::from(width), Some(right.slot))?; let variation = if ratio < 0 { capacity.shrink } else { capacity.stretch }; if variation != 0 && ratio != 0 { - let kern = left.font.metrics().kern(char::from(left.slot), char::from(right.slot)); + let kern = state.fonts.program(left.font.id)?.kern(left.slot, right.slot); let width = i32::try_from(kern) .map_err(|_| "native font kern exceeds the scaled point range")?; material[i] = TextNode::Kern { width, explicit: false }; diff --git a/crates/texrra-tex-core/src/execution/reconstitute.rs b/crates/texrra-tex-core/src/execution/reconstitute.rs index c56adf3..bdd4044 100644 --- a/crates/texrra-tex-core/src/execution/reconstitute.rs +++ b/crates/texrra-tex-core/src/execution/reconstitute.rs @@ -49,7 +49,7 @@ pub(super) fn word( missing: &mut Vec<(FontId, u8, Span)>, ) -> Result, String> { let face = state.fonts.glyph_font(font)?.clone(); - let f = face.metrics(); + let f = state.fonts.program(font)?; let hyphen = state .hyphen_character(font) .ok_or("native reconstitution requires a valid hyphen slot")? as u8; diff --git a/crates/texrra-tex-core/src/execution/state.rs b/crates/texrra-tex-core/src/execution/state.rs index 0c8fafd..3b3a1a3 100644 --- a/crates/texrra-tex-core/src/execution/state.rs +++ b/crates/texrra-tex-core/src/execution/state.rs @@ -362,6 +362,8 @@ pub enum Primitive { Knaccode, Efcode, Pdffontexpand, + Pdfnoligatures, + Tagcode, Pdfobj, Pdfrefobj, Pdflastobj, @@ -987,6 +989,8 @@ const PDFTEX_ONLY_PRIMITIVES: &[(&str, Primitive)] = { ("knaccode", Knaccode), ("efcode", Efcode), ("pdffontexpand", Pdffontexpand), + ("pdfnoligatures", Pdfnoligatures), + ("tagcode", Tagcode), ("letterspacefont", Letterspacefont), ("pdffilesize", Pdffilesize), ("pdffilemoddate", Pdffilemoddate), @@ -2083,6 +2087,16 @@ impl State { self.update_profile_command("pdfinsertht", Meaning::Primitive(Primitive::Pdfinsertht), enabled); } + pub(super) fn install_pdf_font_tag_commands(&mut self) { + let enabled = self.input_profile != super::InputProfile::XeTeX; + for (name, primitive) in [ + ("pdfnoligatures", Primitive::Pdfnoligatures), + ("tagcode", Primitive::Tagcode), + ] { + self.update_profile_command(name, Meaning::Primitive(primitive), enabled); + } + } + pub(super) fn install_filedump_command(&mut self) { let name = if self.input_profile == super::InputProfile::XeTeX { "filedump" diff --git a/crates/texrra-tex-core/src/tfm.rs b/crates/texrra-tex-core/src/tfm.rs index 2b50778..e015146 100755 --- a/crates/texrra-tex-core/src/tfm.rs +++ b/crates/texrra-tex-core/src/tfm.rs @@ -483,6 +483,18 @@ impl TfmMetrics { } }) } + pub(crate) fn glyph_tag_code(&self, slot: u8) -> i32 { + match self.char_info(char::from(slot)) { + Some(info) if info.width_index != 0 => match info.tag { + 1 => 1, + 2 => 2, + 3 => 4, + _ => 0, + }, + _ => -1, + } + } + pub fn lig_kern_program(&self) -> &[LigKernInstruction] { &self.lig_kern } diff --git a/crates/texrra-tex-core/tests/execution_ligatures.rs b/crates/texrra-tex-core/tests/execution_ligatures.rs index d8bcfb5..3b64e55 100644 --- a/crates/texrra-tex-core/tests/execution_ligatures.rs +++ b/crates/texrra-tex-core/tests/execution_ligatures.rs @@ -91,6 +91,56 @@ fn compare(p: &std::path::Path, source: &str, labels: &[String]) -> Execution { eprintln!("{} exact native boxes matched real INITEX", labels.len()); e } +#[test] +fn pdfnoligatures_clears_character_programs_and_keeps_the_left_boundary() { + let p = directory(); + fs::write( + p.join("switch.tfm"), + font( + &[ + (Some(b'A'), b'B', Op::Lig(0, b'C')), + (Some(b'D'), b'E', Op::Kern(-12345)), + (None, b'F', Op::Lig(0, b'G')), + (Some(b'G'), 255, Op::Lig(0, b'H')), + ], + Some(255), + ), + ) + .unwrap(); + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); + fs::copy(root.join("assets/cmex10.tfm"), p.join("cmex10.tfm")).unwrap(); + let source = format!( + r"{SETUP} +\font\F=switch \font\same=switch \font\size=switch at 11pt \font\ext=cmex10 +\message{{BEFORE=\the\pdfnoligatures\F,\the\pdfnoligatures\nullfont,\the\pdfnoligatures\ext}} +\setbox0=\hbox{{\F AB DE F}}\showbox0 +\setbox0=\hbox{{\size AB DE F}}\showbox0 +{{\tagcode\F65=-1}}\tagcode\F68=1 +\message{{SELECTIVE=\the\tagcode\same65,\the\tagcode\same68,\the\tagcode\size65,\the\tagcode\same0}} +\setbox0=\hbox{{\same AB DE F}}\showbox0 +{{\pdfnoligatures\F}}\pdfnoligatures\ext +\message{{AFTER=\the\pdfnoligatures\same,\the\pdfnoligatures\size,\the\pdfnoligatures\ext}} +\message{{EXT=\the\tagcode\ext0,\the\tagcode\ext12}} +\tagcode\ext0=-2\tagcode\ext12=-4\tagcode\ext12=4 +\message{{CLEARED=\the\tagcode\ext0,\the\tagcode\ext12}} +\setbox0=\hbox{{\same AB DE F}}\showbox0 +\setbox0=\hbox{{\size AB DE F}}\showbox0 +\end", + ); + let labels = ["initial", "initial size", "selective", "disabled alias", "independent size"].map(str::to_owned); + let result = compare(&p, &source, &labels); + let messages: Vec<_> = result.events.iter().filter_map(|event| match event { + Event::Message { text, .. } => Some(text.as_str()), + _ => None, + }).collect(); + assert_eq!(messages, [ + "BEFORE=0,1,0", "SELECTIVE=0,1,1,-1", "AFTER=1,0,0", "EXT=2,4", "CLEARED=0,0", + ]); + let reference = fs::read_to_string(p.join("probe.log")).unwrap(); + assert!(messages.iter().all(|message| reference.contains(message))); + fs::remove_dir_all(p).unwrap(); +} + #[test] fn all_operation_bytes_retention_pass_and_real_character_boundaries_match_initex() { let p = directory(); diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 6c4a298..bee8dea 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -18,6 +18,33 @@ | W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 | | W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 | +## 2026-11-29 pdfTeX 字符程序标签与原样 PLOS ONE + +pdfTeX profile 接入 `\pdfnoligatures` 和 `\tagcode`。整字体操作 +清除字符的连字和字距程序入口,独立的左边界程序仍能执行。 +逐字符操作按负掩码清除连字、尺寸链或伸展配方标签。 +状态在本作业的字体身份上生效,分别进入正文、断字重构、 +数学和伸缩字距。新格式镜像可保存两种设置,旧格式保留 +已有宏定义并按 profile 接入原语。 +[原版赋值](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L15944-L15972) + +三个定向回归通过,覆盖原版原始盒、别名、字号独立性、边界 +程序、三种标签与无效槽、断字重构和原版 DVI 的数学尺寸及字形。 +schema 111 的实际 dump/load 恢复查询结果 0,1,与 pdfTeX +一致。XeTeX profile 的能力检查与之前相同。 + +PLOS ONE 官方 archive 在参考和原生端均从空辅助状态起跑。 +原生首轮生成 4 页,独立 BibTeX 后第二、三轮均为 5 页。 +三轮 aux 与参考逐字节相同,原生 bbl 与参考相同,第三轮无 +未定义引用。最终 9,827 条字形记录、1,752 个词及词框和 +144 DPI 灰度光栅相同。PDF 对象编号、字体编码字典表达和 +文件字节仍有差异。原样项目加入统一出版矩阵。 +[官方模板](https://journals.plos.org/plosone/s/latex) + +此次验证覆盖 PLOS ONE 和目标原语。完整出版矩阵、浏览器可见 +延迟与内存仍按原门禁统一验收。证据在 target/p3-new-publisher/, +SHA256SUMS 指纹为 62b5407f7db0335988ae45f83506e388af09252f9199e120e059ddbe53271e57。 + ## 2026-11-29 在子文件内部恢复检查点 原生会话在读取实际项目子文件时记录输入游标与完整 TeX 状态。 diff --git a/docs/PUBLISHER_TEMPLATE_MATRIX.md b/docs/PUBLISHER_TEMPLATE_MATRIX.md index aa7b1c0..af96cc2 100644 --- a/docs/PUBLISHER_TEMPLATE_MATRIX.md +++ b/docs/PUBLISHER_TEMPLATE_MATRIX.md @@ -7,6 +7,7 @@ | 类型 | 原样样例 | 官方来源 | | --- | --- | --- | | 预印本 | 仓库已有 arXiv fixture | `fixtures/arxiv-template` | +| 期刊单栏 | PLOS ONE plos_latex_template.tex | [PLOS 作者指南和模板](https://journals.plos.org/plosone/s/latex) | | 期刊 | Springer Nature 的 `sn-article.tex` | [Springer Nature 作者支持](https://www.springernature.com/la/authors/campaigns/latex-author-support) | | 期刊单栏 | Elsevier `cas-sc-sample.tex` | [Elsevier CAS 发布包](https://ctan.org/pkg/els-cas-templates) | | 期刊双栏 | Elsevier `cas-dc-sample.tex` | [Elsevier CAS 发布包](https://ctan.org/pkg/els-cas-templates) | @@ -1300,6 +1301,24 @@ Web2c 胶水取整后,逐轮 aux/out 仍完全一致。第二轮 12 页的 29, target/p3-xdv-device-positions/original/audit-second/comparison.json。 [阶段记录](P2_M1_PROGRESS.md#2026-11-29-xdv-设备字宽与原样-neurips-导出) +### 2026-11-29 PLOS ONE 的原样迁移 + +从官方四文件归档校验样稿、BibTeX 样例和样式,参考和原生分别运行 +三轮 LaTeX 与独立 BibTeX。参考首轮生成 4 页,书目生成后收敛至 +5 页。原生接通逐字符字体标签后,页数、9,827 条字形记录、 +1,752 个词及词框和逐页 144 DPI 灰度均与参考相同。三轮 aux +及真实生成的 bbl 逐字节一致。PDF 对象号、字体编码字典表达和 +文件字节有差异。 + +该样稿已加入脚本的 plos-one 条目。两端使用相同的原样包、同版 +书目和字体映射。测试补充的 TeX Live 资源为 changepage、cite、 +epstopdf-pkg、fancyhdr、lastpage、marvosym,保存原始包指纹。 +字体映射由冻结基线加上原版 marvosym.map 的 umvs 项组成。 +基线的字体资源和 Native 原语错误均保留。回执 +target/p3-new-publisher/plos-comparison.json 的 SHA-256 为 +ee245cfb2599b02a795eaf8bd07de03c8a9481f7c488de78bf17fadae137c01e。 +[字体标签阶段记录](P2_M1_PROGRESS.md#2026-11-29-pdftex-字符程序标签与原样-plos-one) + 单纯生成 PDF 或 DVI 只说明编译路径可达。完整验收要在参考环境闭合后比较页数、 双栏位置及跨栏材料、实际字体/字形、图表浮动、引用收敛、词框及墨迹;测试源 与容差都不得为通过而替换。类 Typst 的编辑延迟另用同批原样项目分规模测量, diff --git a/scripts/probe-publisher-templates.py b/scripts/probe-publisher-templates.py index fa18811..aad82e4 100644 --- a/scripts/probe-publisher-templates.py +++ b/scripts/probe-publisher-templates.py @@ -16,6 +16,7 @@ from pathlib import Path, PurePosixPath ROOT = Path(__file__).resolve().parent.parent CASES = [ ("arxiv", "preprint", None, "template.tex"), + ("plos-one", "journal-single-column", "plos", "plos_latex_template.tex"), ("springer-nature", "journal", "springer-journal", "sn-article-template/sn-article.tex"), ("elsevier-cas-sc", "journal-single-column", "elsevier-cas", "els-cas-templates/cas-sc-sample.tex"), ("elsevier-cas-dc", "journal-two-columns", "elsevier-cas", "els-cas-templates/cas-dc-sample.tex"), diff --git a/scripts/publisher-template-matrix.json b/scripts/publisher-template-matrix.json index 7bdfef6..53da74d 100644 --- a/scripts/publisher-template-matrix.json +++ b/scripts/publisher-template-matrix.json @@ -1,4 +1,8 @@ { + "plos": [ + "ea3a8a0fdbac77f95de47639541b09ef1583e059ace6783367490af9fa0b9a60", + "https://journals.plos.org/plosone/s/file?id=1457%2FPLOS_latex_template.zip" + ], "springer-journal": [ "812e76dcaa9c28dc1bff1fb6065d51729b67d4ea140552a05088317414a3ecae", "https://cms-resources.apps.public.k8s.springernature.io/springer-cms/rest/v1/content/18782940/data/v12"