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
@@ -432,6 +432,7 @@ impl Executor {
|
||||
| Spacefactor
|
||||
| Setbox
|
||||
| Parshape
|
||||
| LinePenalties(_)
|
||||
| Wd
|
||||
| Ht
|
||||
| Dp
|
||||
|
||||
@@ -885,7 +885,7 @@ impl Executor {
|
||||
| Day | Month | Year | BeginGroup | EndGroup | Relax | Message | Errmessage
|
||||
| Endinput | Showbox | Show | Showthe | Showlists | Showifs | Showgroups
|
||||
| Discretionary | DiscretionaryHyphen
|
||||
| Parshape | Partokenname => {
|
||||
| Parshape | LinePenalties(_) | Partokenname => {
|
||||
return Ok(false);
|
||||
}
|
||||
_ if self.execute_output_extension(*p, token, files)? => {}
|
||||
|
||||
@@ -244,6 +244,56 @@ impl Executor {
|
||||
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(
|
||||
&mut self,
|
||||
primitive: Primitive,
|
||||
@@ -493,6 +543,11 @@ impl Executor {
|
||||
self.reads.insert(Dependency::Parameter(*p));
|
||||
}
|
||||
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);
|
||||
for n in &b.nodes {
|
||||
let text = match n {
|
||||
@@ -636,6 +691,9 @@ impl Executor {
|
||||
if !self.read_paragraph_shape().is_empty() {
|
||||
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(())
|
||||
}
|
||||
pub(super) fn horizontal_command(
|
||||
|
||||
@@ -238,6 +238,7 @@ impl Executor {
|
||||
| Primitive::Gluestretchorder
|
||||
| Primitive::Glueshrinkorder
|
||||
| Primitive::Parshape
|
||||
| Primitive::LinePenalties(_)
|
||||
| Primitive::Prevgraf
|
||||
| Primitive::Spacefactor
|
||||
| Primitive::Hyphenchar
|
||||
|
||||
@@ -199,6 +199,15 @@ impl Executor {
|
||||
"parshape".into(),
|
||||
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 => {
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
let font = self.font_token_name(self.state.text_font());
|
||||
|
||||
Reference in new issue
Block a user