Apply pdfTeX line box dimensions and restore output penalties

This commit is contained in:
gloamxun committed 2026-11-29 12:49:56 +08:00
1 parent 7f51f01bd4
commit fb557c09c6
13 files changed
+151 -14

No files matched your search

@@ -500,7 +500,7 @@ impl Default for VerticalBuilder {
fn default() -> Self {
Self {
nodes: Vec::new(),
prev_depth: -1000 * 65536,
prev_depth: super::parameters::IGNORE_DEPTH,
previous_lines: 0,
tail_path: Vec::new(),
}
@@ -526,7 +526,7 @@ impl VerticalBuilder {
pub fn append_box(&mut self, node: NativeVerticalNode, state: &State) -> Result<(), String> {
let (_, height, depth) = node.dimensions().expect("box or line");
if self.prev_depth > -1000 * 65536 {
if self.prev_depth > state.ignored_depth() {
let mut label = Parameter::Baselineskip;
let mut g = state.parameter(label).glue();
let gap = g.width as i64 - self.prev_depth as i64 - height;
@@ -542,6 +542,8 @@ impl Executor {
const XETEX_REVISION: &'static str = ".999998";
pub fn new(state: State, limits: Limits) -> Self {
let mut vertical = super::boxes::VerticalBuilder::default();
vertical.prev_depth = state.ignored_depth();
Self {
state,
limits,
@@ -594,7 +596,7 @@ impl Executor {
pdf_force_pagebox_warned: false,
input_position: None,
paragraph: None,
vertical: super::boxes::VerticalBuilder::default(),
vertical,
box_frames: Vec::new(),
box_nodes_created: 0,
material_charge: 0,
@@ -440,6 +440,7 @@ impl Executor {
if horizontal {
self.start_alignment_hlist(span);
} else {
self.vertical.prev_depth = self.read_ignored_depth();
self.normal_paragraph(files)?;
}
Ok(())
@@ -608,6 +609,8 @@ impl Executor {
.insert(Dependency::Parameter(Parameter::Lineskip));
self.reads
.insert(Dependency::Parameter(Parameter::Lineskiplimit));
self.reads
.insert(Dependency::Parameter(Parameter::Pdfignoreddimen));
let f = self.alignments.last_mut().unwrap();
self.vertical.append(&mut f.adjustments.pre);
self.vertical
@@ -717,6 +717,7 @@ impl Executor {
b.restricted = true;
self.paragraph = Some(b);
} else {
self.vertical.prev_depth = self.read_ignored_depth();
self.normal_paragraph(files)?;
}
if group == GroupKind::Insertion {
@@ -977,12 +978,18 @@ impl Executor {
}
Ok(())
}
pub(super) fn read_ignored_depth(&mut self) -> i32 {
self.reads.insert(Dependency::Parameter(Parameter::Pdfignoreddimen));
self.state.ignored_depth()
}
pub(super) fn append_vertical_box(&mut self, node: NativeVerticalNode) -> Result<(), Error> {
self.reads.insert(Dependency::VerticalState);
for p in [
Parameter::Baselineskip,
Parameter::Lineskip,
Parameter::Lineskiplimit,
Parameter::Pdfignoreddimen,
] {
self.reads.insert(Dependency::Parameter(p));
}
@@ -1016,7 +1023,7 @@ impl Executor {
return self
.fail("outer running rule requires native page packaging; specify width");
}
self.vertical.prev_depth = -1000 * 65536;
self.vertical.prev_depth = self.read_ignored_depth();
NativeVerticalNode::Rule(r)
}
_ => unreachable!(),
@@ -153,6 +153,7 @@ impl Executor {
let mut reads = BTreeSet::from([
Dependency::ParagraphMode,
Dependency::VerticalState,
Dependency::Parameter(Parameter::Pdfignoreddimen),
Dependency::PageState,
Dependency::FontResources,
Dependency::EscapeChar,
@@ -323,7 +324,7 @@ impl Executor {
render(&mut text, &mut reads, &vertical_nodes(&vertical.nodes))?;
text.push_str(auxiliary_break);
text.push_str("prevdepth ");
if vertical.prev_depth <= -1000 * 65536 {
if vertical.prev_depth <= self.state.ignored_depth() {
text.push_str("ignored");
} else {
text.push_str(&registers::print_scaled(vertical.prev_depth));
@@ -240,6 +240,7 @@ impl Executor {
math: std::mem::take(&mut self.math),
display: self.display.take(),
});
self.vertical.prev_depth = self.read_ignored_depth();
self.inputs.push(InputFrame::Tokens {
tokens: InputTokens::Many(tokens.iter().cloned().map(InputToken::from).collect()),
cursor: 0,
@@ -303,6 +304,7 @@ impl Executor {
self.display = frame.display;
let page = self.native_page.as_mut().unwrap();
page.output_active = false;
page.insertions.penalties = 0;
page.resume_contributions(nodes);
page.requested = true;
Ok(true)
@@ -16,9 +16,9 @@ use std::{
sync::{Arc, Mutex, OnceLock, Weak},
};
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 SCHEMA: u32 = 112;
const COMPATIBLE_SCHEMAS: [u32; 78] = [
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, 111, SCHEMA,
];
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
@@ -247,6 +247,9 @@ impl FormatImage {
if image.schema < 111 {
image.state.install_pdf_font_tag_commands();
}
if image.schema < 112 {
image.state.restore_legacy_pdf_parameters(&Parameter::PDF_LINE_DIMENSIONS);
}
let pdf_objects = image.state.pdf_objects.as_deref();
let mut numbered_images = 0;
for (index, saved) in image.pdf_images.iter().enumerate() {
@@ -154,7 +154,6 @@ impl NativePageState {
self.max_depth = state.parameter(Parameter::Maxdepth).width();
self.least = AWFUL;
self.best = None;
self.insertions.penalties = 0;
if state.parameter(Parameter::Tracingpages).width() > 0 {
observations.push(PageObservation::Trace(PageTrace::Freeze {
goal: self.dimensions[0],
@@ -1535,6 +1535,16 @@ pub(super) fn finish(
let directions = super::direction::has_directions(&b.nodes);
let mut direction_stack = Vec::new();
let widow_kind = LinePenaltyKind::for_widow_parameter(final_widow);
let ignored_depth = state.ignored_depth();
let pdftex = state.input_profile() != super::InputProfile::XeTeX;
let line_dimension = |p| {
let value = parameters[&p].width();
(pdftex && value != ignored_depth).then_some(i64::from(value))
};
let each_height = line_dimension(Parameter::Pdfeachlineheight);
let each_depth = line_dimension(Parameter::Pdfeachlinedepth);
let first_height = line_dimension(Parameter::Pdffirstlineheight).or(each_height);
let last_depth = line_dimension(Parameter::Pdflastlinedepth).or(each_depth);
for (i, (point, bad)) in path.iter().enumerate() {
let mut material = line_material(
&b.nodes,
@@ -1558,7 +1568,7 @@ pub(super) fn finish(
// Keep a real breakpoint marker before the synthetic line closers.
super::direction::line(&mut material, &mut direction_stack);
}
let (line, line_box, adjustments, shrinking) = pack(
let (line, mut line_box, adjustments, shrinking) = pack(
&material,
&parameters,
dimensions,
@@ -1583,6 +1593,10 @@ pub(super) fn finish(
pre_display_size =
pre_display_line_size(material, line_box.setting, line_box.shift, quad);
}
let height = if i == 0 { first_height } else { each_height };
let depth = if i + 1 == path.len() { last_depth } else { each_depth };
line_box.height = height.unwrap_or(line_box.height);
line_box.depth = depth.unwrap_or(line_box.depth);
diagnostic_lines.push(super::diagnostics::box_view(&line_box));
line_boxes.push(line_box);
line_pre_adjustments.push(adjustments.pre);
@@ -1,6 +1,8 @@
//! Owned paragraph parameter meanings and TeX INITEX defaults.
use super::{Flex, Glue, RegisterKind, RegisterValue};
pub(super) const IGNORE_DEPTH: i32 = -1000 * 65536;
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
@@ -148,6 +150,11 @@ pub enum Parameter {
Ignoreprimitiveerror,
Lastlinefit,
Savinghyphcodes,
Pdfignoreddimen,
Pdfeachlineheight,
Pdfeachlinedepth,
Pdffirstlineheight,
Pdflastlinedepth,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum ParameterValue {
@@ -155,6 +162,13 @@ pub enum ParameterValue {
Quantity(RegisterValue),
}
impl Parameter {
pub(super) const PDF_LINE_DIMENSIONS: [Self; 5] = [
Self::Pdfignoreddimen,
Self::Pdfeachlineheight,
Self::Pdfeachlinedepth,
Self::Pdffirstlineheight,
Self::Pdflastlinedepth,
];
pub(super) fn pdftex_only(self) -> bool {
matches!(
self,
@@ -191,6 +205,11 @@ impl Parameter {
| Self::Pdfprependkern
| Self::Pdfappendkern
| Self::Pdfadjustspacing
| Self::Pdfignoreddimen
| Self::Pdfeachlineheight
| Self::Pdfeachlinedepth
| Self::Pdffirstlineheight
| Self::Pdflastlinedepth
)
}
@@ -352,6 +371,11 @@ impl Parameter {
Self::XeTeXinputnormalization,
Self::Lastlinefit,
Self::Savinghyphcodes,
Self::Pdfignoreddimen,
Self::Pdfeachlineheight,
Self::Pdfeachlinedepth,
Self::Pdffirstlineheight,
Self::Pdflastlinedepth,
];
pub fn name(self) -> String {
match self {
@@ -381,6 +405,11 @@ impl Parameter {
| Self::Pdflinkmargin
| Self::Pdfdestmargin
| Self::Pdfthreadmargin
| Self::Pdfignoreddimen
| Self::Pdfeachlineheight
| Self::Pdfeachlinedepth
| Self::Pdffirstlineheight
| Self::Pdflastlinedepth
| Self::Delimitershortfall
| Self::Predisplaysize
| Self::Displaywidth
@@ -422,10 +451,10 @@ impl Parameter {
pub fn initial(self) -> ParameterValue {
if let Some(kind) = self.kind() {
ParameterValue::Quantity(if kind == RegisterKind::Dimen {
RegisterValue::Dimension(if matches!(self, Self::Pdfhorigin | Self::Pdfvorigin) {
4_736_287
} else {
0
RegisterValue::Dimension(match self {
Self::Pdfhorigin | Self::Pdfvorigin => 4_736_287,
p if Self::PDF_LINE_DIMENSIONS.contains(&p) => IGNORE_DEPTH,
_ => 0,
})
} else {
RegisterValue::Glue(Glue::default())
@@ -1645,6 +1645,14 @@ impl State {
self.assign_parameter(Parameter::Pdfoutput, ParameterValue::Integer(1), true);
self
}
pub(super) fn ignored_depth(&self) -> i32 {
if self.input_profile() == super::InputProfile::XeTeX {
super::parameters::IGNORE_DEPTH
} else {
self.parameter(Parameter::Pdfignoreddimen).width()
}
}
pub fn parameter(&self, parameter: Parameter) -> ParameterValue {
self.parameters
.get(&parameter)