Apply e-TeX line penalty arrays to native pagination
This commit is contained in:
1 parent
09cd19594c
commit
c094d9a81d
12 files changed
+243
-24
No files matched your search
@@ -2356,6 +2356,7 @@ impl Executor {
|
|||||||
p @ (Primitive::Wd | Primitive::Ht | Primitive::Dp | Primitive::Prevdepth),
|
p @ (Primitive::Wd | Primitive::Ht | Primitive::Dp | Primitive::Prevdepth),
|
||||||
) => self.dimension_value(p, files),
|
) => self.dimension_value(p, files),
|
||||||
Meaning::Primitive(Primitive::Parshape) => Ok(self.read_paragraph_shape().len() as i32),
|
Meaning::Primitive(Primitive::Parshape) => Ok(self.read_paragraph_shape().len() as i32),
|
||||||
|
Meaning::Primitive(Primitive::LinePenalties(kind)) => self.line_penalty_value(kind, files),
|
||||||
Meaning::Primitive(Primitive::Prevgraf) => {
|
Meaning::Primitive(Primitive::Prevgraf) => {
|
||||||
if self.writing {
|
if self.writing {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
@@ -3336,6 +3337,7 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
Primitive::Etexversion => "eTeXversion".into(),
|
Primitive::Etexversion => "eTeXversion".into(),
|
||||||
Primitive::Etexrevision => "eTeXrevision".into(),
|
Primitive::Etexrevision => "eTeXrevision".into(),
|
||||||
|
Primitive::LinePenalties(kind) => kind.name().into(),
|
||||||
Primitive::Uchar => "Uchar".into(),
|
Primitive::Uchar => "Uchar".into(),
|
||||||
Primitive::Ucharcat => "Ucharcat".into(),
|
Primitive::Ucharcat => "Ucharcat".into(),
|
||||||
Primitive::Umathcode => "Umathcode".into(),
|
Primitive::Umathcode => "Umathcode".into(),
|
||||||
@@ -4514,6 +4516,7 @@ impl Executor {
|
|||||||
self.scan_math_code_assignment(p, global, files)?;
|
self.scan_math_code_assignment(p, global, files)?;
|
||||||
}
|
}
|
||||||
Some(Parshape) => self.scan_paragraph_shape(global, files)?,
|
Some(Parshape) => self.scan_paragraph_shape(global, files)?,
|
||||||
|
Some(LinePenalties(kind)) => self.scan_line_penalties(kind, global, files)?,
|
||||||
Some(Setbox) => {
|
Some(Setbox) => {
|
||||||
if !allow_setbox {
|
if !allow_setbox {
|
||||||
return self.fail("improper native setbox in an assignment prefix");
|
return self.fail("improper native setbox in an assignment prefix");
|
||||||
|
|||||||
@@ -432,6 +432,7 @@ impl Executor {
|
|||||||
| Spacefactor
|
| Spacefactor
|
||||||
| Setbox
|
| Setbox
|
||||||
| Parshape
|
| Parshape
|
||||||
|
| LinePenalties(_)
|
||||||
| Wd
|
| Wd
|
||||||
| Ht
|
| Ht
|
||||||
| Dp
|
| Dp
|
||||||
|
|||||||
@@ -885,7 +885,7 @@ impl Executor {
|
|||||||
| Day | Month | Year | BeginGroup | EndGroup | Relax | Message | Errmessage
|
| Day | Month | Year | BeginGroup | EndGroup | Relax | Message | Errmessage
|
||||||
| Endinput | Showbox | Show | Showthe | Showlists | Showifs | Showgroups
|
| Endinput | Showbox | Show | Showthe | Showlists | Showifs | Showgroups
|
||||||
| Discretionary | DiscretionaryHyphen
|
| Discretionary | DiscretionaryHyphen
|
||||||
| Parshape | Partokenname => {
|
| Parshape | LinePenalties(_) | Partokenname => {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
_ if self.execute_output_extension(*p, token, files)? => {}
|
_ if self.execute_output_extension(*p, token, files)? => {}
|
||||||
|
|||||||
@@ -244,6 +244,56 @@ impl Executor {
|
|||||||
self.assign_paragraph_shape(shape, global, files)
|
self.assign_paragraph_shape(shape, global, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn read_line_penalties(&mut self, kind: LinePenaltyKind) -> &[i32] {
|
||||||
|
self.reads.insert(Dependency::LinePenalties(kind));
|
||||||
|
self.state.line_penalties(kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assign_line_penalties(
|
||||||
|
&mut self,
|
||||||
|
kind: LinePenaltyKind,
|
||||||
|
values: Vec<i32>,
|
||||||
|
global: bool,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let equivalent = values.is_empty() && self.state.line_penalties(kind).is_empty();
|
||||||
|
self.assign_equivalence(Key::LinePenalties(kind), global, equivalent, files, |state| {
|
||||||
|
state.assign_line_penalties(kind, values, global);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn scan_line_penalties(
|
||||||
|
&mut self,
|
||||||
|
kind: LinePenaltyKind,
|
||||||
|
global: bool,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
self.optional_equals(files)?;
|
||||||
|
let count = self.integer(files)?.max(0) as usize;
|
||||||
|
if count > self.limits.tokens {
|
||||||
|
return self.fail("native line penalty array capacity exceeded");
|
||||||
|
}
|
||||||
|
let mut values = Vec::new();
|
||||||
|
for _ in 0..count {
|
||||||
|
values.push(self.integer(files)?);
|
||||||
|
}
|
||||||
|
self.assign_line_penalties(kind, values, global, files)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn line_penalty_value(
|
||||||
|
&mut self,
|
||||||
|
kind: LinePenaltyKind,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<i32, Error> {
|
||||||
|
let index = self.integer(files)?;
|
||||||
|
let values = self.read_line_penalties(kind);
|
||||||
|
Ok(match index {
|
||||||
|
..0 => 0,
|
||||||
|
0 => values.len() as i32,
|
||||||
|
_ => super::super::paragraph::line_penalty_at(values, index as usize).unwrap_or(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn paragraph_shape_dimension(
|
pub(super) fn paragraph_shape_dimension(
|
||||||
&mut self,
|
&mut self,
|
||||||
primitive: Primitive,
|
primitive: Primitive,
|
||||||
@@ -493,6 +543,11 @@ impl Executor {
|
|||||||
self.reads.insert(Dependency::Parameter(*p));
|
self.reads.insert(Dependency::Parameter(*p));
|
||||||
}
|
}
|
||||||
self.reads.insert(Dependency::ParagraphShape);
|
self.reads.insert(Dependency::ParagraphShape);
|
||||||
|
self.reads.extend([
|
||||||
|
Dependency::LinePenalties(LinePenaltyKind::Interline),
|
||||||
|
Dependency::LinePenalties(LinePenaltyKind::Club),
|
||||||
|
Dependency::LinePenalties(LinePenaltyKind::for_widow_parameter(final_widow)),
|
||||||
|
]);
|
||||||
self.reads.insert(Dependency::Hyphenation);
|
self.reads.insert(Dependency::Hyphenation);
|
||||||
for n in &b.nodes {
|
for n in &b.nodes {
|
||||||
let text = match n {
|
let text = match n {
|
||||||
@@ -636,6 +691,9 @@ impl Executor {
|
|||||||
if !self.read_paragraph_shape().is_empty() {
|
if !self.read_paragraph_shape().is_empty() {
|
||||||
self.assign_paragraph_shape(Vec::new(), false, files)?;
|
self.assign_paragraph_shape(Vec::new(), false, files)?;
|
||||||
}
|
}
|
||||||
|
if !self.read_line_penalties(LinePenaltyKind::Interline).is_empty() {
|
||||||
|
self.assign_line_penalties(LinePenaltyKind::Interline, Vec::new(), false, files)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub(super) fn horizontal_command(
|
pub(super) fn horizontal_command(
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ impl Executor {
|
|||||||
| Primitive::Gluestretchorder
|
| Primitive::Gluestretchorder
|
||||||
| Primitive::Glueshrinkorder
|
| Primitive::Glueshrinkorder
|
||||||
| Primitive::Parshape
|
| Primitive::Parshape
|
||||||
|
| Primitive::LinePenalties(_)
|
||||||
| Primitive::Prevgraf
|
| Primitive::Prevgraf
|
||||||
| Primitive::Spacefactor
|
| Primitive::Spacefactor
|
||||||
| Primitive::Hyphenchar
|
| Primitive::Hyphenchar
|
||||||
|
|||||||
@@ -199,6 +199,15 @@ impl Executor {
|
|||||||
"parshape".into(),
|
"parshape".into(),
|
||||||
self.read_paragraph_shape().len().to_string(),
|
self.read_paragraph_shape().len().to_string(),
|
||||||
),
|
),
|
||||||
|
Key::LinePenalties(kind) => {
|
||||||
|
let values = self.read_line_penalties(*kind);
|
||||||
|
let text = match values {
|
||||||
|
[] => "0".to_owned(),
|
||||||
|
[first] => format!("1 {first}"),
|
||||||
|
[first, ..] => format!("{} {first}{escape}ETC.", values.len()),
|
||||||
|
};
|
||||||
|
(kind.name().into(), text)
|
||||||
|
}
|
||||||
Key::Font => {
|
Key::Font => {
|
||||||
self.reads.insert(Dependency::FontResources);
|
self.reads.insert(Dependency::FontResources);
|
||||||
let font = self.font_token_name(self.state.text_font());
|
let font = self.font_token_name(self.state.text_font());
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ use std::{
|
|||||||
sync::{Arc, Mutex, OnceLock, Weak},
|
sync::{Arc, Mutex, OnceLock, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCHEMA: u32 = 99;
|
const SCHEMA: u32 = 100;
|
||||||
const COMPATIBLE_SCHEMAS: [u32; 65] = [
|
const COMPATIBLE_SCHEMAS: [u32; 66] = [
|
||||||
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, SCHEMA,
|
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, SCHEMA,
|
||||||
];
|
];
|
||||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
@@ -214,6 +214,9 @@ impl FormatImage {
|
|||||||
if image.schema < 99 {
|
if image.schema < 99 {
|
||||||
image.state.restore_legacy_etex_parameter(Parameter::Savinghyphcodes);
|
image.state.restore_legacy_etex_parameter(Parameter::Savinghyphcodes);
|
||||||
}
|
}
|
||||||
|
if image.schema < 100 {
|
||||||
|
image.state.install_line_penalty_primitives();
|
||||||
|
}
|
||||||
let pdf_objects = image.state.pdf_objects.as_deref();
|
let pdf_objects = image.state.pdf_objects.as_deref();
|
||||||
let mut numbered_images = 0;
|
let mut numbered_images = 0;
|
||||||
for (index, saved) in image.pdf_images.iter().enumerate() {
|
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ pub use rule::NativeRule;
|
|||||||
pub use session::{
|
pub use session::{
|
||||||
NativeSession, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceVersion,
|
NativeSession, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceVersion,
|
||||||
};
|
};
|
||||||
pub use state::{CommandName, Macro, Meaning, Primitive, Profile, Replacement, State};
|
pub use state::{CommandName, LinePenaltyKind, Macro, Meaning, Primitive, Profile, Replacement, State};
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
|
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
|
||||||
@@ -487,6 +487,7 @@ pub enum Dependency {
|
|||||||
FontResources,
|
FontResources,
|
||||||
ParagraphMode,
|
ParagraphMode,
|
||||||
ParagraphShape,
|
ParagraphShape,
|
||||||
|
LinePenalties(LinePenaltyKind),
|
||||||
PreviousParagraphLines,
|
PreviousParagraphLines,
|
||||||
Hyphenation,
|
Hyphenation,
|
||||||
BoxRegister(u16),
|
BoxRegister(u16),
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ pub(super) struct ParagraphShapeLine {
|
|||||||
pub width: i32,
|
pub width: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A one-based index, extended by the final element of a nonempty array.
|
||||||
|
pub(super) fn line_penalty_at(values: &[i32], index: usize) -> Option<i32> {
|
||||||
|
values.get(index.min(values.len()).wrapping_sub(1)).copied()
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn shaped_line(shape: &[ParagraphShapeLine], line: usize) -> Option<ParagraphShapeLine> {
|
pub(super) fn shaped_line(shape: &[ParagraphShapeLine], line: usize) -> Option<ParagraphShapeLine> {
|
||||||
shape.get(line).or_else(|| shape.last()).copied()
|
shape.get(line).or_else(|| shape.last()).copied()
|
||||||
}
|
}
|
||||||
@@ -1524,6 +1529,7 @@ pub(super) fn finish(
|
|||||||
let mut pre_display_size = -1073741823;
|
let mut pre_display_size = -1073741823;
|
||||||
let directions = super::direction::has_directions(&b.nodes);
|
let directions = super::direction::has_directions(&b.nodes);
|
||||||
let mut direction_stack = Vec::new();
|
let mut direction_stack = Vec::new();
|
||||||
|
let widow_kind = LinePenaltyKind::for_widow_parameter(final_widow);
|
||||||
for (i, (point, bad)) in path.iter().enumerate() {
|
for (i, (point, bad)) in path.iter().enumerate() {
|
||||||
let mut material = line_material(
|
let mut material = line_material(
|
||||||
&b.nodes,
|
&b.nodes,
|
||||||
@@ -1580,25 +1586,23 @@ pub(super) fn finish(
|
|||||||
let disc_break = i + 1 < path.len() && point.hyphen;
|
let disc_break = i + 1 < path.len() && point.hyphen;
|
||||||
discretionary_breaks.push(disc_break);
|
discretionary_breaks.push(disc_break);
|
||||||
if i + 1 < path.len() {
|
if i + 1 < path.len() {
|
||||||
// TeX post_line_break: all applicable terms add, including both
|
// The base array uses prevgraf, including lines before a display.
|
||||||
// club and widow for a two-line paragraph. Never penalize the end.
|
// Club counts from this segment's start and widow from its end.
|
||||||
let get = |p| parameters[&p].width() as i64;
|
let from_start = i + 1;
|
||||||
let penalty = get(Parameter::Interlinepenalty)
|
let from_end = path.len() - from_start;
|
||||||
+ if i == 0 {
|
let term = |kind, index, fallback, applies| {
|
||||||
get(Parameter::Clubpenalty)
|
line_penalty_at(state.line_penalties(kind), index)
|
||||||
} else {
|
.map(i64::from)
|
||||||
0
|
.unwrap_or_else(|| if applies { i64::from(parameters[&fallback].width()) } else { 0 })
|
||||||
}
|
};
|
||||||
+ if i + 2 == path.len() {
|
let penalty = term(
|
||||||
get(final_widow)
|
LinePenaltyKind::Interline,
|
||||||
} else {
|
b.previous_lines + from_start,
|
||||||
0
|
Parameter::Interlinepenalty,
|
||||||
}
|
true,
|
||||||
+ if disc_break {
|
) + term(LinePenaltyKind::Club, from_start, Parameter::Clubpenalty, from_start == 1)
|
||||||
get(Parameter::Brokenpenalty)
|
+ term(widow_kind, from_end, final_widow, from_end == 1)
|
||||||
} else {
|
+ if disc_break { i64::from(parameters[&Parameter::Brokenpenalty].width()) } else { 0 };
|
||||||
0
|
|
||||||
};
|
|
||||||
interline_penalties
|
interline_penalties
|
||||||
.push(i32::try_from(penalty).map_err(|_| "native interline penalty sum overflow")?);
|
.push(i32::try_from(penalty).map_err(|_| "native interline penalty sum overflow")?);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ pub enum Primitive {
|
|||||||
Parshapelength,
|
Parshapelength,
|
||||||
Parshapeindent,
|
Parshapeindent,
|
||||||
Parshapedimen,
|
Parshapedimen,
|
||||||
|
LinePenalties(LinePenaltyKind),
|
||||||
Spacefactor,
|
Spacefactor,
|
||||||
Setbox,
|
Setbox,
|
||||||
Box,
|
Box,
|
||||||
@@ -598,6 +599,38 @@ pub enum Meaning {
|
|||||||
UnicodeMathCharGiven(super::MathCode),
|
UnicodeMathCharGiven(super::MathCode),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The four indexed e-TeX penalties used between typeset paragraph lines.
|
||||||
|
#[derive(
|
||||||
|
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
|
||||||
|
)]
|
||||||
|
pub enum LinePenaltyKind {
|
||||||
|
Interline,
|
||||||
|
Club,
|
||||||
|
Widow,
|
||||||
|
DisplayWidow,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LinePenaltyKind {
|
||||||
|
const ALL: [Self; 4] = [Self::Interline, Self::Club, Self::Widow, Self::DisplayWidow];
|
||||||
|
|
||||||
|
pub(super) fn name(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Interline => "interlinepenalties",
|
||||||
|
Self::Club => "clubpenalties",
|
||||||
|
Self::Widow => "widowpenalties",
|
||||||
|
Self::DisplayWidow => "displaywidowpenalties",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn for_widow_parameter(parameter: Parameter) -> Self {
|
||||||
|
match parameter {
|
||||||
|
Parameter::Widowpenalty => Self::Widow,
|
||||||
|
Parameter::Displaywidowpenalty => Self::DisplayWidow,
|
||||||
|
_ => unreachable!("paragraph has a widow penalty parameter"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Explicit bootstrap language selection. EtexBootstrap implements the native
|
/// Explicit bootstrap language selection. EtexBootstrap implements the native
|
||||||
/// extended macro/integer language below; it does not claim full e-TeX mode,
|
/// extended macro/integer language below; it does not claim full e-TeX mode,
|
||||||
/// marks, glue/dimension expression or format-image conformance.
|
/// marks, glue/dimension expression or format-image conformance.
|
||||||
@@ -628,6 +661,7 @@ pub(super) enum Key {
|
|||||||
Parameter(Parameter),
|
Parameter(Parameter),
|
||||||
Font,
|
Font,
|
||||||
ParagraphShape,
|
ParagraphShape,
|
||||||
|
LinePenalties(LinePenaltyKind),
|
||||||
Spacefactor,
|
Spacefactor,
|
||||||
Box(u16),
|
Box(u16),
|
||||||
Mathcode(u32),
|
Mathcode(u32),
|
||||||
@@ -651,6 +685,7 @@ pub(super) enum Saved {
|
|||||||
Register(Option<RegisterValue>),
|
Register(Option<RegisterValue>),
|
||||||
Parameter(Option<ParameterValue>),
|
Parameter(Option<ParameterValue>),
|
||||||
ParagraphShape(std::sync::Arc<[super::paragraph::ParagraphShapeLine]>),
|
ParagraphShape(std::sync::Arc<[super::paragraph::ParagraphShapeLine]>),
|
||||||
|
LinePenalties(Option<std::sync::Arc<[i32]>>),
|
||||||
Font(FontId),
|
Font(FontId),
|
||||||
Box(Option<NativeBox>),
|
Box(Option<NativeBox>),
|
||||||
Mathcode(Option<super::MathCode>),
|
Mathcode(Option<super::MathCode>),
|
||||||
@@ -772,6 +807,8 @@ pub struct State {
|
|||||||
registers: BTreeMap<Register, RegisterValue>,
|
registers: BTreeMap<Register, RegisterValue>,
|
||||||
parameters: BTreeMap<Parameter, ParameterValue>,
|
parameters: BTreeMap<Parameter, ParameterValue>,
|
||||||
paragraph_shape: std::sync::Arc<[super::paragraph::ParagraphShapeLine]>,
|
paragraph_shape: std::sync::Arc<[super::paragraph::ParagraphShapeLine]>,
|
||||||
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
|
line_penalties: BTreeMap<LinePenaltyKind, std::sync::Arc<[i32]>>,
|
||||||
pub(super) text_font: FontId,
|
pub(super) text_font: FontId,
|
||||||
pub(super) fonts: super::FontCatalog,
|
pub(super) fonts: super::FontCatalog,
|
||||||
boxes: BTreeMap<u16, NativeBox>,
|
boxes: BTreeMap<u16, NativeBox>,
|
||||||
@@ -993,6 +1030,7 @@ impl Default for State {
|
|||||||
registers: BTreeMap::new(),
|
registers: BTreeMap::new(),
|
||||||
parameters: BTreeMap::new(),
|
parameters: BTreeMap::new(),
|
||||||
paragraph_shape: std::sync::Arc::default(),
|
paragraph_shape: std::sync::Arc::default(),
|
||||||
|
line_penalties: BTreeMap::new(),
|
||||||
text_font: FontId::NULL,
|
text_font: FontId::NULL,
|
||||||
fonts: super::FontCatalog::default(),
|
fonts: super::FontCatalog::default(),
|
||||||
boxes: BTreeMap::new(),
|
boxes: BTreeMap::new(),
|
||||||
@@ -1452,6 +1490,24 @@ impl State {
|
|||||||
self.parameters.insert(p, value);
|
self.parameters.insert(p, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(super) fn line_penalties(&self, kind: LinePenaltyKind) -> &[i32] {
|
||||||
|
self.line_penalties.get(&kind).map_or(&[], |values| values.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn assign_line_penalties(
|
||||||
|
&mut self,
|
||||||
|
kind: LinePenaltyKind,
|
||||||
|
values: Vec<i32>,
|
||||||
|
global: bool,
|
||||||
|
) {
|
||||||
|
self.save(Key::LinePenalties(kind), global);
|
||||||
|
if values.is_empty() {
|
||||||
|
self.line_penalties.remove(&kind);
|
||||||
|
} else {
|
||||||
|
self.line_penalties.insert(kind, values.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn paragraph_shape(&self) -> &[super::paragraph::ParagraphShapeLine] {
|
pub(super) fn paragraph_shape(&self) -> &[super::paragraph::ParagraphShapeLine] {
|
||||||
&self.paragraph_shape
|
&self.paragraph_shape
|
||||||
}
|
}
|
||||||
@@ -1533,6 +1589,7 @@ impl State {
|
|||||||
pub fn with_etex(mut self) -> Self {
|
pub fn with_etex(mut self) -> Self {
|
||||||
use Primitive::*;
|
use Primitive::*;
|
||||||
self.profile = Profile::EtexBootstrap;
|
self.profile = Profile::EtexBootstrap;
|
||||||
|
self.install_line_penalty_primitives();
|
||||||
let hook = TokenParameter::Everyeof;
|
let hook = TokenParameter::Everyeof;
|
||||||
self.commands.insert(
|
self.commands.insert(
|
||||||
CommandName::Control(hook.name()),
|
CommandName::Control(hook.name()),
|
||||||
@@ -1798,6 +1855,16 @@ impl State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn install_line_penalty_primitives(&mut self) {
|
||||||
|
if self.profile == Profile::EtexBootstrap {
|
||||||
|
for kind in LinePenaltyKind::ALL {
|
||||||
|
self.commands
|
||||||
|
.entry(CommandName::Control(kind.name().into()))
|
||||||
|
.or_insert(Meaning::Primitive(Primitive::LinePenalties(kind)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn restore_legacy_etex_parameter(&mut self, parameter: Parameter) {
|
pub(super) fn restore_legacy_etex_parameter(&mut self, parameter: Parameter) {
|
||||||
if self.profile == Profile::EtexBootstrap {
|
if self.profile == Profile::EtexBootstrap {
|
||||||
self.commands
|
self.commands
|
||||||
@@ -2353,6 +2420,14 @@ impl State {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(Key::ParagraphShape, Saved::ParagraphShape(shape)) => self.paragraph_shape = shape,
|
(Key::ParagraphShape, Saved::ParagraphShape(shape)) => self.paragraph_shape = shape,
|
||||||
|
(Key::LinePenalties(kind), Saved::LinePenalties(values)) => match values {
|
||||||
|
Some(values) => {
|
||||||
|
self.line_penalties.insert(kind, values);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
self.line_penalties.remove(&kind);
|
||||||
|
}
|
||||||
|
},
|
||||||
(Key::Mathcode(c), Saved::Mathcode(v)) => {
|
(Key::Mathcode(c), Saved::Mathcode(v)) => {
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
self.mathcodes.insert(c, v);
|
self.mathcodes.insert(c, v);
|
||||||
@@ -2448,6 +2523,7 @@ impl State {
|
|||||||
Key::Register(register) => Saved::Register(self.registers.get(register).copied()),
|
Key::Register(register) => Saved::Register(self.registers.get(register).copied()),
|
||||||
Key::Parameter(p) => Saved::Parameter(self.parameters.get(p).copied()),
|
Key::Parameter(p) => Saved::Parameter(self.parameters.get(p).copied()),
|
||||||
Key::ParagraphShape => Saved::ParagraphShape(self.paragraph_shape.clone()),
|
Key::ParagraphShape => Saved::ParagraphShape(self.paragraph_shape.clone()),
|
||||||
|
Key::LinePenalties(kind) => Saved::LinePenalties(self.line_penalties.get(kind).cloned()),
|
||||||
Key::Font => Saved::Font(self.text_font),
|
Key::Font => Saved::Font(self.text_font),
|
||||||
Key::Box(n) => Saved::Box(self.boxes.get(n).cloned()),
|
Key::Box(n) => Saved::Box(self.boxes.get(n).cloned()),
|
||||||
Key::Mathcode(c) => Saved::Mathcode(self.mathcodes.get(c).copied()),
|
Key::Mathcode(c) => Saved::Mathcode(self.mathcodes.get(c).copied()),
|
||||||
|
|||||||
@@ -128,6 +128,43 @@ fn last_line_fit_reuses_the_selected_fill_only_for_the_same_parameter() {
|
|||||||
assert_eq!((work.solved_passes, work.reused_passes), (2, 1));
|
assert_eq!((work.solved_passes, work.reused_passes), (2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn etex_penalty_arrays_index_actual_lines_across_display_and_reset_at_par() {
|
||||||
|
let execution = run(
|
||||||
|
r"\catcode36=3
|
||||||
|
\font\symbols=cmsy10 \textfont2=\symbols \scriptfont2=\symbols \scriptscriptfont2=\symbols
|
||||||
|
\font\extensions=cmex10 \textfont3=\extensions \scriptfont3=\extensions \scriptscriptfont3=\extensions
|
||||||
|
\pretolerance=10000 \tolerance=10000
|
||||||
|
\interlinepenalty=7
|
||||||
|
\clubpenalties=2 3 5
|
||||||
|
\widowpenalties=3 31 41 51
|
||||||
|
\displaywidowpenalties=3 80 90 100
|
||||||
|
\let\w=\widowpenalties
|
||||||
|
{\w=2 92 93 \message{LOCAL:\the\w0/\the\w9}}
|
||||||
|
\message{VALUES:\the\w-1/\the\w0/\the\w2/\the\numexpr\w20+1\relax}
|
||||||
|
\def\br{\hfil\penalty-10000\relax}
|
||||||
|
\setbox0=\vbox{\interlinepenalties=10 1 2 3 4 5 6 7 8 9 10
|
||||||
|
\noindent AA\br BB\br CC$$\hbox{DD}$$EE\br FF\br GG\par
|
||||||
|
\message{RESET:\the\interlinepenalties0/\the\clubpenalties0/\the\w0}
|
||||||
|
\noindent AA\br BB\par}",
|
||||||
|
);
|
||||||
|
let built = paragraphs(&execution);
|
||||||
|
assert_eq!(built.len(), 3);
|
||||||
|
assert_eq!(built[0].interline_penalties, [94, 87]);
|
||||||
|
assert_eq!(built[1].previous_lines, 6);
|
||||||
|
assert_eq!(built[1].interline_penalties, [51, 44]);
|
||||||
|
assert_eq!(built[2].interline_penalties, [41]);
|
||||||
|
let messages: Vec<_> = execution
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.filter_map(|event| match event {
|
||||||
|
Event::Message { text, .. } => Some(text.as_str()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
assert_eq!(messages, ["LOCAL:2/93", "VALUES:0/3/41/52", "RESET:0/2/3"]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn native_parameters_have_scopes_and_par_end_timing() {
|
fn native_parameters_have_scopes_and_par_end_timing() {
|
||||||
let e = run(
|
let e = run(
|
||||||
|
|||||||
@@ -18,6 +18,32 @@
|
|||||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||||
|
|
||||||
|
## 2026-11-28 e-TeX 的逐行分页罚值
|
||||||
|
|
||||||
|
原生两种 e-TeX 模式均执行 `\interlinepenalties`、`\clubpenalties`、
|
||||||
|
`\widowpenalties` 和 `\displaywidowpenalties`。数组支持分组、全局赋值、
|
||||||
|
`\let` 别名和整数查询。索引 0 查询长度,负索引返回 0,超出长度使用末项。
|
||||||
|
排版使用累计行号、离段首或段尾的行数及显示公式上下文。未设置的数组沿用
|
||||||
|
对应标量,断字项计入 `\brokenpenalty`。段落复位只清除逐行数组。
|
||||||
|
[e-TeX 上游的段落罚值](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/etexdir/etex.ch#L1979-L2009)
|
||||||
|
|
||||||
|
pdfTeX 和 XeTeX 各五页包含 43 个原始罚值节点及 26 个词框,节点值、
|
||||||
|
盒嵌套深度、词框和 144 DPI 灰度像素逐项一致。覆盖标量回退、数组末项
|
||||||
|
延用、显示前后、断字以及 `\vsplit`。两种模式的实际页面构建器都在
|
||||||
|
第三行断页,两页内容、输出罚值和光栅与相应参考一致。
|
||||||
|
|
||||||
|
schema100 保存四个数组和别名。两种真实参考格式与原生镜像的重载查询及
|
||||||
|
出页光栅一致。schema99 重载补齐缺失的原语,保留已有的同名用户宏。
|
||||||
|
原样 `pdflatex.ini` 和 `xelatex.ini` 均生成并重载 schema100,实际
|
||||||
|
LaTeX3 四个别名完成赋值和查询,各生成一页 article。
|
||||||
|
|
||||||
|
三页项目两轮分别修改并恢复子文件的拆盒断点,各复用 1,102 步及一次
|
||||||
|
段落断行搜索,只更新第二页。PDF、页面、SVG、辅助文件和来源映射
|
||||||
|
逐轮与独立全量一致。发布构建及八项段落定向测试通过。
|
||||||
|
|
||||||
|
证据保存在 `target/p2-etex-penalty-arrays`,`receipt.json` 的 SHA-256 为
|
||||||
|
`56eddd1378623b7b69a1d57e8c652c8f709595d3e838f0979b85b7a7d1610112`。
|
||||||
|
|
||||||
## 2026-11-28 资源查找失效后继续验证更早的检查点
|
## 2026-11-28 资源查找失效后继续验证更早的检查点
|
||||||
|
|
||||||
按已执行步数从后向前验证检查点。主文件前缀、已读资源及生成文件初态
|
按已执行步数从后向前验证检查点。主文件前缀、已读资源及生成文件初态
|
||||||
|
|||||||
Reference in new issue
Block a user