Honor e-TeX split shrink masks on native vertical lists
This commit is contained in:
1 parent
69efe0b895
commit
34325317d2
11 files changed
+187
-28
No files matched your search
@@ -447,15 +447,24 @@ impl Executor {
|
||||
let BoxContent::Vertical(nodes) = original.content else {
|
||||
unreachable!()
|
||||
};
|
||||
let mut nodes = Arc::unwrap_or_clone(nodes);
|
||||
let cut = super::super::vertical_break::find_break(
|
||||
&nodes,
|
||||
&mut nodes,
|
||||
i64::from(height),
|
||||
max_depth,
|
||||
&self.state,
|
||||
&mut self.reads,
|
||||
&mut self.steps,
|
||||
self.limits.steps,
|
||||
|| {
|
||||
super::super::vertical_break::log_ignored_shrink(
|
||||
files,
|
||||
&mut self.diagnostic_bytes,
|
||||
self.limits.tokens,
|
||||
)
|
||||
},
|
||||
)
|
||||
.map_err(|e| self.error(e, span))?;
|
||||
let mut nodes = Arc::unwrap_or_clone(nodes);
|
||||
let tail = nodes.split_off(cut.index);
|
||||
self.collect_split_marks(&nodes)?;
|
||||
let save = self.read_parameter(Parameter::Savingvdiscards).width() > 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::super::boxes::{self, PackSpec, VerticalBuilder};
|
||||
use super::super::page_builder::PageObservation;
|
||||
use super::*;
|
||||
use crate::native_font::{JobVirtualFonts, NativeFont, VirtualGlyphs};
|
||||
use std::collections::BTreeSet;
|
||||
@@ -95,15 +96,29 @@ impl Executor {
|
||||
}
|
||||
loop {
|
||||
self.read_parameter(Parameter::Tracingpages);
|
||||
let mut trace = Vec::new();
|
||||
let mut observations = Vec::new();
|
||||
let next = self.native_page.as_mut().unwrap().advance(
|
||||
&mut self.state,
|
||||
&mut self.reads,
|
||||
&mut self.steps,
|
||||
self.limits.steps,
|
||||
&mut trace,
|
||||
&mut observations,
|
||||
);
|
||||
for trace in trace {
|
||||
for observation in observations {
|
||||
let trace = match observation {
|
||||
PageObservation::Trace(trace) => trace,
|
||||
PageObservation::IgnoredSplitShrink(count) => {
|
||||
for _ in 0..count {
|
||||
super::super::vertical_break::log_ignored_shrink(
|
||||
files,
|
||||
&mut self.diagnostic_bytes,
|
||||
self.limits.tokens,
|
||||
)
|
||||
.map_err(|e| self.error(e, self.current))?;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let destination = if self.read_parameter(Parameter::Tracingonline).width() > 0 {
|
||||
WriteDestination::TerminalAndLog
|
||||
} else {
|
||||
|
||||
@@ -16,9 +16,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 95;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 61] = [
|
||||
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, SCHEMA,
|
||||
const SCHEMA: u32 = 96;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 62] = [
|
||||
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, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::page_builder::PageObservation;
|
||||
use super::*;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@@ -71,14 +72,14 @@ impl PageInsertions {
|
||||
|
||||
pub fn record_front(
|
||||
&mut self,
|
||||
node: &NativeInsertion,
|
||||
node: &mut NativeInsertion,
|
||||
at: usize,
|
||||
dims: &mut [i64; 8],
|
||||
state: &State,
|
||||
reads: &mut BTreeSet<Dependency>,
|
||||
steps: &mut usize,
|
||||
limit: usize,
|
||||
trace: &mut Vec<PageTrace>,
|
||||
observations: &mut Vec<PageObservation>,
|
||||
) -> Result<(), String> {
|
||||
let index = u16::from(node.class);
|
||||
let placement = Placement {
|
||||
@@ -141,20 +142,36 @@ impl PageInsertions {
|
||||
space / factor * 1000
|
||||
}
|
||||
.min(max - entry.size);
|
||||
let split =
|
||||
super::vertical_break::find_break(&node.nodes, target, node.split_depth, steps, limit)?;
|
||||
let mut ignored_shrinks = 0;
|
||||
let split = super::vertical_break::find_break(
|
||||
&mut node.nodes,
|
||||
target,
|
||||
node.split_depth,
|
||||
state,
|
||||
reads,
|
||||
steps,
|
||||
limit,
|
||||
|| {
|
||||
ignored_shrinks += 1;
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
if ignored_shrinks != 0 {
|
||||
observations.push(PageObservation::IgnoredSplitShrink(ignored_shrinks));
|
||||
}
|
||||
let split = split?;
|
||||
let penalty = match node.nodes.get(split.index) {
|
||||
None => -10000,
|
||||
Some(NativeVerticalNode::Penalty(p)) => *p,
|
||||
_ => 0,
|
||||
};
|
||||
if state.parameter(Parameter::Tracingpages).width() > 0 {
|
||||
trace.push(PageTrace::InsertionSplit {
|
||||
observations.push(PageObservation::Trace(PageTrace::InsertionSplit {
|
||||
class: node.class,
|
||||
target,
|
||||
natural_size: split.natural_size,
|
||||
penalty,
|
||||
});
|
||||
}));
|
||||
}
|
||||
entry.size += split.natural_size;
|
||||
dims[0] -= scale(split.natural_size, factor);
|
||||
|
||||
@@ -77,6 +77,11 @@ impl PageTrace {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(super) enum PageObservation {
|
||||
Trace(PageTrace),
|
||||
IgnoredSplitShrink(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct PageTraceReport {
|
||||
pub trace: PageTrace,
|
||||
@@ -139,7 +144,7 @@ impl NativePageState {
|
||||
self.best = None;
|
||||
self.least = AWFUL;
|
||||
}
|
||||
fn freeze_specs(&mut self, state: &State, trace: &mut Vec<PageTrace>) {
|
||||
fn freeze_specs(&mut self, state: &State, observations: &mut Vec<PageObservation>) {
|
||||
if self.specs_frozen {
|
||||
return;
|
||||
}
|
||||
@@ -151,10 +156,10 @@ impl NativePageState {
|
||||
self.best = None;
|
||||
self.insertions.penalties = 0;
|
||||
if state.parameter(Parameter::Tracingpages).width() > 0 {
|
||||
trace.push(PageTrace::Freeze {
|
||||
observations.push(PageObservation::Trace(PageTrace::Freeze {
|
||||
goal: self.dimensions[0],
|
||||
max_depth: self.max_depth,
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +181,7 @@ impl NativePageState {
|
||||
reads: &mut BTreeSet<Dependency>,
|
||||
steps: &mut usize,
|
||||
limit: usize,
|
||||
trace: &mut Vec<PageTrace>,
|
||||
observations: &mut Vec<PageObservation>,
|
||||
) -> Result<Option<PageBreak>, String> {
|
||||
if !self.requested || self.output_active {
|
||||
return Ok(None);
|
||||
@@ -223,7 +228,7 @@ impl NativePageState {
|
||||
}
|
||||
if !self.started && dimensions.is_some() {
|
||||
self.started = true;
|
||||
self.freeze_specs(state, trace);
|
||||
self.freeze_specs(state, observations);
|
||||
let mut skip = state.parameter(Parameter::Topskip).glue();
|
||||
skip.canonical_zero = false;
|
||||
skip.width = i32::try_from((i64::from(skip.width) - dimensions.unwrap().1).max(0))
|
||||
@@ -295,13 +300,13 @@ impl NativePageState {
|
||||
100000
|
||||
};
|
||||
if state.parameter(Parameter::Tracingpages).width() > 0 {
|
||||
trace.push(PageTrace::Break {
|
||||
observations.push(PageObservation::Trace(PageTrace::Break {
|
||||
dimensions: self.dimensions,
|
||||
badness: bad,
|
||||
penalty: p,
|
||||
cost,
|
||||
best: cost <= self.least,
|
||||
});
|
||||
}));
|
||||
}
|
||||
if cost <= self.least {
|
||||
self.least = cost;
|
||||
@@ -340,9 +345,9 @@ impl NativePageState {
|
||||
return Ok(Some(result));
|
||||
}
|
||||
}
|
||||
let n = self.contributions.pop_front().unwrap();
|
||||
if let NativeVerticalNode::Insertion(insertion) = &n {
|
||||
self.freeze_specs(state, trace);
|
||||
let mut n = self.contributions.pop_front().unwrap();
|
||||
if let NativeVerticalNode::Insertion(insertion) = &mut n {
|
||||
self.freeze_specs(state, observations);
|
||||
self.insertions.record_front(
|
||||
insertion,
|
||||
self.nodes.len(),
|
||||
@@ -351,7 +356,7 @@ impl NativePageState {
|
||||
reads,
|
||||
steps,
|
||||
limit,
|
||||
trace,
|
||||
observations,
|
||||
)?;
|
||||
}
|
||||
if let Some((_, height, depth)) = dimensions {
|
||||
|
||||
@@ -143,6 +143,7 @@ pub enum Parameter {
|
||||
Pdfdraftmode,
|
||||
Pdfsuppressptexinfo,
|
||||
Pdfptexuseunderscore,
|
||||
Ignoreprimitiveerror,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ParameterValue {
|
||||
@@ -296,6 +297,7 @@ impl Parameter {
|
||||
Self::Floatingpenalty,
|
||||
Self::Holdinginserts,
|
||||
Self::Savingvdiscards,
|
||||
Self::Ignoreprimitiveerror,
|
||||
Self::Linepenalty,
|
||||
Self::Hyphenpenalty,
|
||||
Self::Exhyphenpenalty,
|
||||
|
||||
@@ -1287,6 +1287,7 @@ impl Default for State {
|
||||
| Parameter::Tracingnesting
|
||||
| Parameter::Tracingassigns
|
||||
| Parameter::Savingvdiscards
|
||||
| Parameter::Ignoreprimitiveerror
|
||||
| Parameter::TeXXeTstate
|
||||
) || Parameter::XETEX.contains(p) {
|
||||
continue;
|
||||
@@ -1538,6 +1539,7 @@ impl State {
|
||||
Parameter::Tracingnesting,
|
||||
Parameter::Tracingassigns,
|
||||
Parameter::Savingvdiscards,
|
||||
Parameter::Ignoreprimitiveerror,
|
||||
] {
|
||||
self.commands.insert(
|
||||
CommandName::Control(parameter.name()),
|
||||
|
||||
@@ -3,6 +3,19 @@ use super::*;
|
||||
|
||||
const AWFUL: i64 = 1_073_741_823;
|
||||
|
||||
pub(super) fn log_ignored_shrink(
|
||||
files: &mut impl SourceProvider,
|
||||
diagnostic_bytes: &mut usize,
|
||||
limit: usize,
|
||||
) -> Result<(), String> {
|
||||
const TEXT: &str = "\nignored: Infinite glue shrinkage found in box being split";
|
||||
*diagnostic_bytes = diagnostic_bytes.saturating_add(TEXT.len());
|
||||
if *diagnostic_bytes > limit {
|
||||
return Err("native diagnostic output limit exceeded".into());
|
||||
}
|
||||
files.observe_diagnostic(WriteDestination::Log, TEXT)
|
||||
}
|
||||
|
||||
fn step(steps: &mut usize, limit: usize) -> Result<(), String> {
|
||||
*steps = steps.saturating_add(1);
|
||||
if *steps > limit {
|
||||
@@ -17,11 +30,14 @@ pub(super) struct VerticalBreak {
|
||||
}
|
||||
|
||||
pub(super) fn find_break(
|
||||
nodes: &[NativeVerticalNode],
|
||||
nodes: &mut [NativeVerticalNode],
|
||||
height: i64,
|
||||
max_depth: i32,
|
||||
state: &State,
|
||||
reads: &mut BTreeSet<Dependency>,
|
||||
steps: &mut usize,
|
||||
limit: usize,
|
||||
mut ignored_shrink: impl FnMut() -> Result<(), String>,
|
||||
) -> Result<VerticalBreak, String> {
|
||||
let (mut total, mut depth) = (0i64, 0i64);
|
||||
let (mut stretch, mut shrink) = ([0i64; 4], 0i64);
|
||||
@@ -105,14 +121,19 @@ pub(super) fn find_break(
|
||||
return Ok(best);
|
||||
}
|
||||
}
|
||||
match node {
|
||||
match nodes.get_mut(i) {
|
||||
Some(
|
||||
NativeVerticalNode::Glue(g)
|
||||
| NativeVerticalNode::NamedGlue(g, _)
|
||||
| NativeVerticalNode::Leaders(LeaderGlue { glue: g, .. }),
|
||||
) => {
|
||||
if g.shrink.order != 0 && g.shrink.amount != 0 {
|
||||
return Err("infinite glue shrinkage found in native box being split".into());
|
||||
reads.insert(Dependency::Parameter(Parameter::Ignoreprimitiveerror));
|
||||
if state.parameter(Parameter::Ignoreprimitiveerror).width() & 1 == 0 {
|
||||
return Err("infinite glue shrinkage found in native box being split".into());
|
||||
}
|
||||
ignored_shrink()?;
|
||||
g.shrink.order = 0;
|
||||
}
|
||||
stretch[g.stretch.order as usize] += i64::from(g.stretch.amount);
|
||||
shrink += i64::from(g.shrink.amount);
|
||||
|
||||
@@ -204,6 +204,44 @@ fn local_trace_switches_channels_and_disabled_diagnostics_preserve_actual_pages(
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
#[test]
|
||||
fn ignored_insertion_shrink_is_log_only_and_follows_page_observation_order() {
|
||||
let s = r"\catcode123=1 \catcode125=2
|
||||
\tracingpages=1 \tracingonline=1 \ignoreprimitiveerror=1
|
||||
\vsize=60pt \topskip=0pt \maxdepth=0pt
|
||||
\splittopskip=0pt \splitmaxdepth=0pt
|
||||
\count1=1000 \dimen1=25pt \skip1=0pt
|
||||
\output={\shipout\vbox{\unvbox255\ifvoid1\else\box1\fi}}
|
||||
\hrule height4pt width8pt
|
||||
\insert1{\hrule height8pt width8pt \vskip2pt minus1fil
|
||||
\hrule height8pt width8pt \vskip4pt minus2fill
|
||||
\hrule height8pt width8pt}
|
||||
\penalty-10000 \end";
|
||||
let mut host = Host::default();
|
||||
native(s, &mut host).unwrap();
|
||||
let records: Vec<_> = host
|
||||
.lines
|
||||
.iter()
|
||||
.map(|(destination, text)| (*destination, text.trim()))
|
||||
.filter(|(_, text)| {
|
||||
text.starts_with("%% goal height=")
|
||||
|| text.starts_with("ignored:")
|
||||
|| text.starts_with("% split")
|
||||
})
|
||||
.collect();
|
||||
const IGNORED: &str = "ignored: Infinite glue shrinkage found in box being split";
|
||||
assert_eq!(
|
||||
records,
|
||||
[
|
||||
(WriteDestination::TerminalAndLog, "%% goal height=60.0, max depth=0.0"),
|
||||
(WriteDestination::Log, IGNORED),
|
||||
(WriteDestination::Log, IGNORED),
|
||||
(WriteDestination::TerminalAndLog, "% split1 to 25.0,18.0 p=0"),
|
||||
(WriteDestination::TerminalAndLog, "%% goal height=60.0, max depth=0.0"),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_diagnostic_sink_failures_and_capacity_errors_do_not_become_success() {
|
||||
let s = format!(r"{HEADER}\vsize=20pt\tracingpages=1\copy0\vskip2pt\copy0\end");
|
||||
|
||||
@@ -162,6 +162,26 @@ fn legal_breaks_costs_ties_and_forced_stops_match_actual_initex() {
|
||||
compare(&cases);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignored_split_shrink_changes_only_glue_visited_by_vertical_break() {
|
||||
let cases = [
|
||||
format!(
|
||||
r"\ignoreprimitiveerror=3\splittopskip=0pt\splitmaxdepth=0pt\setbox1=\vbox{{\hrule width8pt height8pt\marks3{{FIRST}}\vskip2pt minus1fil\hrule width8pt height8pt\leaders\hrule width4pt height1pt\vskip4pt minus2fill\marks3{{LAST}}\hrule width8pt height8pt}}\setbox0=\vsplit1 to29pt{}",
|
||||
observe(r"MASK:\the\ignoreprimitiveerror/\splitfirstmarks3/\splitbotmarks3")
|
||||
),
|
||||
r"\ignoreprimitiveerror=1\setbox1=\vbox{\baselineskip=12pt minus1fil\hbox{A}\hbox{B}}\setbox0=\vsplit1 to18pt".into(),
|
||||
r"\ignoreprimitiveerror=2\splittopskip=0pt\setbox1=\vbox{\hrule width8pt height8pt\penalty-10000\hrule width8pt height8pt\vskip4pt minus2fill\hrule width8pt height8pt}\setbox0=\vsplit1 to8pt".into(),
|
||||
];
|
||||
let execution = compare(&cases);
|
||||
assert!(execution
|
||||
.reads
|
||||
.contains(&Dependency::Parameter(Parameter::Ignoreprimitiveerror)));
|
||||
assert_eq!(
|
||||
execution.state.parameter(Parameter::Ignoreprimitiveerror).width(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split_marks_are_global_expanded_tokens_per_class_and_clear_on_void() {
|
||||
let mut cases = Vec::new();
|
||||
@@ -282,6 +302,7 @@ fn invalid_split_modes_classes_glue_and_real_capacity_fail_explicitly() {
|
||||
r"\marks32768{A}",
|
||||
r"\message{\splitfirstmarks32768}",
|
||||
r"\setbox1=\vbox{\hbox{A}\vskip0pt minus1fil\hbox{B}}\setbox0=\vsplit1 to100pt",
|
||||
r"\ignoreprimitiveerror=2\setbox1=\vbox{\hbox{A}\vskip0pt minus1fil\hbox{B}}\setbox0=\vsplit1 to100pt",
|
||||
r"\setbox1=\vbox{\hbox{A}}$a^\vsplit1 to5pt$",
|
||||
r"\hbox{\discretionary{\mark{A}}{}{}}",
|
||||
r"\hbox{\discretionary{}{\marks1{B}}{}}",
|
||||
|
||||
@@ -819,6 +819,35 @@ letterspace-fresh.log 和 device-pdftex-spaced-moved.log。
|
||||
[原版字距虚拟字体构造](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16400-L16492)
|
||||
[原版格式所写字体字段](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L30627-L30696)
|
||||
|
||||
### e-TeX 拆盒的无限收缩胶水
|
||||
|
||||
原样 LaTeX 的页面标记提取会在组内设置 \ignoreprimitiveerror 的
|
||||
最低位,再调用 \vsplit。e-TeX 的 vert_break 在实际扫描到非零
|
||||
无限收缩胶水时,继续按原数值计入收缩量,并将当前节点的收缩阶
|
||||
改为有限。普通、带参数名和带 leader 的胶水走同一转换。保留
|
||||
同一份盒的副本、胶水的其余字段和强制断点之后未访问的节点。
|
||||
实际发生转换时读取该参数并计入增量依赖。最低位未启用时,
|
||||
严格作业与参考的 halt-on-error 模式一样报告错误。常规页面胶水
|
||||
和插入 skip 的错误路径仍由各自的消费者处理。
|
||||
|
||||
显式拆盒和分页拆分插入共用 vert_break。警告进入实际作业日志,
|
||||
占用诊断输出额度。开启 tracingpages 和 tracingonline 时,日志
|
||||
内的顺序与 pdfTeX 对照一致,先出现页目标,再是两条拆盒警告,
|
||||
随后是插入拆分页迹。终端保留分页追踪。显式拆盒样例及双 profile
|
||||
的插入样例共六页,144 DPI 灰度像素逐页与各自参考一致。
|
||||
|
||||
四页会话从子文件更改屏蔽位。最低位关闭的作业失败,保留已发布
|
||||
预览及 aux。恢复屏蔽位触发重算,页面保持不变。后续修改收缩
|
||||
量及写出内容时复用 80 步,只更新第 2 页。恢复和后续编辑的
|
||||
PDF、页面、SVG、来源映射和 aux 均与独立全量编译一致。
|
||||
|
||||
schema96 保存新参数及绑定,既有镜像可继续加载其原有命令状态。
|
||||
19 项定向回归通过,覆盖拆盒、插入、分页追踪及格式重载。
|
||||
定向回执 target/p3-etex-split-shrink/focused-receipt.json 的 SHA-256
|
||||
为 0a7951f1bfe8f3d4f2d3dedac4ab2898e07d429e6421cfdd8651a74e72a38434。
|
||||
先前分页日志的顺序差异和修正后的对照保存在 traced-insertion。
|
||||
原样 xelatex.ini 的 schema96 初始化及页面标记对照继续在同目录记录。
|
||||
|
||||
### 数量扫描消费空格别名
|
||||
|
||||
六页原样 xeCJK 样稿第 1 页的下划线片段之间多出约 10.49 bp,
|
||||
|
||||
Reference in new issue
Block a user