2 Commits
7 changed files with 276 additions and 92 deletions

No files matched your search

@@ -612,6 +612,10 @@ impl FontCatalog {
Ok(variant) Ok(variant)
} }
pub(super) fn external_variant(&self, font: FontId, amount: i32) -> Option<FontId> {
self.external_expansion.get(&font)?.variants.get(&amount).copied()
}
pub(super) fn external_limit( pub(super) fn external_limit(
&self, &self,
font: FontId, font: FontId,
@@ -657,6 +661,10 @@ impl FontCatalog {
} }
} }
pub(super) fn has_external_expansions(&self) -> bool {
!self.external_expansion.is_empty()
}
pub(super) fn has_external_expansion(&self, font: FontId) -> bool { pub(super) fn has_external_expansion(&self, font: FontId) -> bool {
self.external_expansion.contains_key(&font) self.external_expansion.contains_key(&font)
} }
@@ -572,14 +572,16 @@ fn metrics(nodes: &[TextNode], left: Glue, right: Glue) -> (i64, [i64; 4], i64)
fn break_lines( fn break_lines(
nodes: &[TextNode], nodes: &[TextNode],
projected: &[BreakNode], projected: &[BreakNode],
margins: Option<&protrusion::Search>, mut margins: Option<&mut protrusion::Search>,
expansion: Option<&expansion::Search>, expansion: Option<&expansion::Search>,
state: &mut State,
files: &mut impl SourceProvider,
p: &BTreeMap<Parameter, ParameterValue>, p: &BTreeMap<Parameter, ParameterValue>,
shape: &[ParagraphShapeLine], shape: &[ParagraphShapeLine],
pass: u8, pass: u8,
work: &mut usize, work: &mut usize,
previous_lines: usize, previous_lines: usize,
trace: &mut super::paragraph_trace::Tracer<'_>, trace: &mut super::paragraph_trace::Tracer,
) -> Result<Option<Vec<(Break, i32)>>, String> { ) -> Result<Option<Vec<(Break, i32)>>, String> {
let get = |q| p[&q].width() as i64; let get = |q| p[&q].width() as i64;
let left = p[&Parameter::Leftskip].glue(); let left = p[&Parameter::Leftskip].glue();
@@ -753,17 +755,26 @@ fn break_lines(
if target < 0 && shape.is_empty() { if target < 0 && shape.is_empty() {
return Err("negative native paragraph measure".into()); return Err("negative native paragraph measure".into());
} }
let hanging = margins.map_or(0, |margins| { let mut shortfall = target - natural;
let mut margin_variation = expansion::Capacity::default();
if let Some(margins) = margins.as_deref_mut() {
// The active paragraph still ends in parfillskip. A nonzero // The active paragraph still ends in parfillskip. A nonzero
// fill stops the right search at the terminal breakpoint. // fill stops the right search at the terminal breakpoint.
let right_visible = !final_break let right_visible = !final_break
|| p[&Parameter::Parfillskip].glue().canonical_zero; || p[&Parameter::Parfillskip].glue().canonical_zero;
margins.width(a.start, b.end, a.post_break, b.pre_break, right_visible) let edges = margins.edges(a.start, b.end, a.post_break, b.pre_break, right_visible);
}); shortfall += i64::from(edges[0].width) + i64::from(edges[1].width);
let shortfall = target - natural + hanging; if shortfall != 0 && expansion.is_some() {
let delta = expansion.map_or(shortfall, |expansion| { margin_variation = margins.variation(edges, state, files)?;
expansion.residual(shortfall, a.start, b.end, a.post_break, b.pre_break) }
}); }
let delta = if let Some(expansion) = expansion {
expansion.residual(
shortfall, a.start, b.end, a.post_break, b.pre_break, margin_variation,
)?
} else {
shortfall
};
let infinite = stretch[1..].iter().any(|n| *n != 0); let infinite = stretch[1..].iter().any(|n| *n != 0);
let bad = if delta >= 0 { let bad = if delta >= 0 {
if infinite { if infinite {
@@ -816,7 +827,7 @@ fn break_lines(
get(Parameter::Doublehyphendemerits) get(Parameter::Doublehyphendemerits)
}); });
} }
trace.material(nodes, b.end)?; trace.material(state, nodes, b.end)?;
trace.push(ParagraphTrace::Feasible { trace.push(ParagraphTrace::Feasible {
position: b.end, position: b.end,
kind: if final_break { kind: if final_break {
@@ -1091,7 +1102,7 @@ pub(super) fn finish(
.iter() .iter()
.map(|p| (*p, state.parameter(*p))) .map(|p| (*p, state.parameter(*p)))
.collect(); .collect();
let shape = state.paragraph_shape(); let shape = state.paragraph_shape().to_vec();
for n in &b.nodes { for n in &b.nodes {
if let TextNode::Glue(g) if let TextNode::Glue(g)
| TextNode::NamedGlue(g, _) | TextNode::NamedGlue(g, _)
@@ -1138,7 +1149,8 @@ pub(super) fn finish(
&b.nodes, &b.nodes,
&parameters, &parameters,
state, state,
shape, files,
&shape,
pass, pass,
&mut work, &mut work,
b.previous_lines, b.previous_lines,
@@ -267,21 +267,24 @@ pub(super) fn candidate_widths(
pub(super) fn solve( pub(super) fn solve(
source: &[TextNode], source: &[TextNode],
parameters: &BTreeMap<Parameter, ParameterValue>, parameters: &BTreeMap<Parameter, ParameterValue>,
state: &State, state: &mut State,
files: &mut impl SourceProvider,
shape: &[ParagraphShapeLine], shape: &[ParagraphShapeLine],
pass: u8, pass: u8,
work: &mut usize, work: &mut usize,
previous_lines: usize, previous_lines: usize,
trace: &mut super::super::paragraph_trace::Tracer<'_>, trace: &mut super::super::paragraph_trace::Tracer,
cache: Option<&LineBreakCache>, cache: Option<&LineBreakCache>,
) -> Result<Path, String> { ) -> Result<Path, String> {
let nodes: Vec<_> = source.iter().map(BreakNode::project).collect(); let nodes: Vec<_> = source.iter().map(BreakNode::project).collect();
let margins = (parameters[&Parameter::Pdfprotrudechars].width() > 1)
.then(|| protrusion::Search::new(state, source));
let expansion = (parameters[&Parameter::Pdfadjustspacing].width() > 1 let expansion = (parameters[&Parameter::Pdfadjustspacing].width() > 1
&& state.fonts.has_expansion()) && state.fonts.has_expansion())
.then(|| expansion::Search::new(state, source)) .then(|| expansion::Search::new(state, source))
.transpose()?; .transpose()?;
let expand_margins = expansion.is_some() && state.fonts.has_external_expansions();
let mut margins = (parameters[&Parameter::Pdfprotrudechars].width() > 1)
.then(|| protrusion::Search::new(state, source, expand_margins))
.transpose()?;
let retained = nodes.len() let retained = nodes.len()
+ shape.len() + shape.len()
+ margins.as_ref().map_or(0, protrusion::Search::len) + margins.as_ref().map_or(0, protrusion::Search::len)
@@ -289,6 +292,9 @@ pub(super) fn solve(
let mut hash = None; let mut hash = None;
if let Some(cache) = cache if let Some(cache) = cache
&& retained <= RETAINED_NODES && retained <= RETAINED_NODES
// A pass that can assign a font has job effects. Only reuse search
// once all projected variations come from the live font table.
&& !margins.as_ref().is_some_and(protrusion::Search::needs_fonts)
&& parameters[&Parameter::Tracingparagraphs].width() <= 0 && parameters[&Parameter::Tracingparagraphs].width() <= 0
{ {
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
@@ -326,8 +332,10 @@ pub(super) fn solve(
let result = break_lines( let result = break_lines(
source, source,
&nodes, &nodes,
margins.as_ref(), margins.as_mut(),
expansion.as_ref(), expansion.as_ref(),
state,
files,
parameters, parameters,
shape, shape,
pass, pass,
@@ -5,7 +5,7 @@ use crate::{math_engine_tex::MathItem, native_font::NativeFont, pdf_device};
use std::{collections::BTreeMap, ops::AddAssign, sync::Arc}; use std::{collections::BTreeMap, ops::AddAssign, sync::Arc};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
struct Capacity { pub(super) struct Capacity {
stretch: i64, stretch: i64,
shrink: i64, shrink: i64,
} }
@@ -43,20 +43,25 @@ impl Limits {
Ok(()) Ok(())
} }
fn residual(self, shortfall: i64, capacity: Capacity) -> i64 { fn residual(self, shortfall: i64, capacity: Capacity) -> Result<i64, String> {
let (direction, limit, available) = if shortfall < 0 { let (direction, limit, available) = if shortfall < 0 {
(-1, self.shrink, capacity.shrink) (-1, self.shrink, capacity.shrink)
} else { } else {
(1, self.stretch, capacity.stretch) (1, self.stretch, capacity.stretch)
}; };
if available <= 0 || shortfall == 0 { if available <= 0 || shortfall == 0 {
return shortfall; return Ok(shortfall);
} }
if available > shortfall.abs() { if available <= shortfall.abs() {
direction * (available / i64::from(limit / self.step)) / 2 return Ok(shortfall - direction * available);
} else {
shortfall - direction * available
} }
// A nested margin glyph can contribute before an outer character
// establishes the step. pdfTeX's initial limit and step are both -1.
let steps = if self.step == 0 { 1 } else { limit / self.step };
if steps == 0 {
return Err("paragraph margin expansion has no limit in this direction".into());
}
Ok(direction * (available / i64::from(steps)) / 2)
} }
} }
@@ -211,8 +216,9 @@ impl Search {
end: usize, end: usize,
post: Option<usize>, post: Option<usize>,
pre: Option<usize>, pre: Option<usize>,
) -> i64 { mut total: Capacity,
let mut total = Capacity { ) -> Result<i64, String> {
total += Capacity {
stretch: self.prefix[end].stretch - self.prefix[start].stretch, stretch: self.prefix[end].stretch - self.prefix[start].stretch,
shrink: self.prefix[end].shrink - self.prefix[start].shrink, shrink: self.prefix[end].shrink - self.prefix[start].shrink,
}; };
@@ -244,6 +250,80 @@ fn slot_ratio(state: &State, font: &NativeFont, slot: u8, line_ratio: i32) -> i3
(magnitude + step / 2).div_euclid(step) as i32 * config.step * line_ratio.signum() (magnitude + step / 2).div_euclid(step) as i32 * config.step * line_ratio.signum()
} }
/// Variation of a candidate's protrusion at its quantized font limits.
/// pdfTeX uses the left protrusion code for this variation on both sides.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(super) enum MarginVariation {
Measured(Capacity),
Pending {
amounts: [i32; 2],
code: i32,
original: i64,
},
}
impl MarginVariation {
pub(super) fn project(state: &State, font: FontId, slot: u8) -> Result<Option<Self>, String> {
if !state.fonts.has_external_expansion(font) {
return Ok(None);
}
let face = state.fonts.glyph_font(font)?;
let amounts = [slot_ratio(state, face, slot, 1000), slot_ratio(state, face, slot, -1000)];
if amounts == [0, 0] {
return Ok(None);
}
let quad = i64::from(state.fonts.font(font)?.quad());
let code = state.fonts.protrusion_code(font, slot, false);
let original = pdf_device::magnify(quad, code);
let selected = |amount| -> Result<Option<i64>, String> {
if amount == 0 {
return Ok(Some(original));
}
let Some(variant) = state.fonts.external_variant(font, amount) else {
return Ok(None);
};
let quad = i64::from(state.fonts.font(variant)?.quad());
Ok(Some(pdf_device::magnify(quad, code)))
};
Ok(Some(match (selected(amounts[0])?, selected(amounts[1])?) {
(Some(wide), Some(narrow)) => Self::Measured(Capacity {
stretch: original - wide,
shrink: narrow - original,
}),
_ => Self::Pending { amounts, code, original },
}))
}
pub(super) fn resolve(
&mut self,
state: &mut State,
font: FontId,
files: &mut impl SourceProvider,
) -> Result<Capacity, String> {
match *self {
Self::Measured(capacity) => Ok(capacity),
Self::Pending { amounts, code, original } => {
let base = state.fonts.glyph_font(font)?.clone();
let defaults = state.font_defaults();
let mut selected = |amount| -> Result<i64, String> {
if amount == 0 {
return Ok(original);
}
let face = state.fonts.expansion_face(&base, amount, defaults, files)?;
let quad = i64::from(state.fonts.font(face.id)?.quad());
Ok(pdf_device::magnify(quad, code))
};
let capacity = Capacity {
stretch: original - selected(amounts[0])?,
shrink: selected(amounts[1])? - original,
};
*self = Self::Measured(capacity);
Ok(capacity)
}
}
}
}
#[derive(Default)] #[derive(Default)]
struct PackingFonts(BTreeMap<(FontId, i32), Arc<NativeFont>>); struct PackingFonts(BTreeMap<(FontId, i32), Arc<NativeFont>>);
@@ -298,21 +378,26 @@ pub(super) fn pack(
) -> Result<(), String> { ) -> Result<(), String> {
let (natural, stretch, _) = metrics(material, Default::default(), Default::default()); let (natural, stretch, _) = metrics(material, Default::default(), Default::default());
let shortfall = target - natural; let shortfall = target - natural;
if shortfall == 0 || (shortfall > 0 && stretch[1..].iter().any(|width| *width != 0)) {
return Ok(());
}
let mut fonts = PackingFonts::default(); let mut fonts = PackingFonts::default();
let mut capacity = sum(state, material, None)?; let mut capacity = Capacity::default();
for node in material.iter() { if state.fonts.has_external_expansions() {
let TextNode::MarginKern { width, right, font, slot } = *node else { // Measuring the actual margin assigns its extreme variants before
continue; // glue setting decides whether to perform any substitution.
}; for node in material.iter() {
for (ratio, limit) in [(1000, &mut capacity.stretch), (-1000, &mut capacity.shrink)] { let TextNode::MarginKern { width, right, font, slot } = *node else {
if let Some((expanded, _)) = fonts.external_margin(state, font, slot, right, ratio, files)? { continue;
*limit += i64::from(expanded) - i64::from(width); };
for (ratio, limit) in [(1000, &mut capacity.stretch), (-1000, &mut capacity.shrink)] {
if let Some((expanded, _)) = fonts.external_margin(state, font, slot, right, ratio, files)? {
*limit += i64::from(expanded) - i64::from(width);
}
} }
} }
} }
if shortfall == 0 || (shortfall > 0 && stretch[1..].iter().any(|width| *width != 0)) {
return Ok(());
}
capacity += sum(state, material, None)?;
let available = if shortfall < 0 { let available = if shortfall < 0 {
capacity.shrink capacity.shrink
} else { } else {
@@ -158,39 +158,60 @@ pub(super) fn margin_kern(
}) })
} }
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub(super) struct EdgeMeasure {
pub(super) width: i32,
expanding: Option<(FontId, u8)>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
struct Projected { struct Projected {
left: Option<(usize, i32)>, left: Option<(usize, EdgeMeasure)>,
right: Option<(usize, i32)>, right: Option<(usize, EdgeMeasure)>,
pre: Option<i32>, pre: Option<EdgeMeasure>,
post: Option<i32>, post: Option<EdgeMeasure>,
} }
#[derive(Debug, PartialEq, Eq, Hash)] #[derive(Debug, PartialEq, Eq, Hash)]
pub(super) struct Search(Vec<Projected>); pub(super) struct Search {
widths: Vec<Projected>,
variations: BTreeMap<(FontId, u8), expansion::MarginVariation>,
}
impl Search { impl Search {
pub(super) fn new(state: &State, nodes: &[TextNode]) -> Self { pub(super) fn new(state: &State, nodes: &[TextNode], expand: bool) -> Result<Self, String> {
let mut widths = vec![Projected::default(); nodes.len() + 1]; let mut widths = vec![Projected::default(); nodes.len() + 1];
let mut variations = BTreeMap::new();
let mut project = |edge: Edge, right| -> Result<EdgeMeasure, String> {
use std::collections::btree_map::Entry;
let width = edge.width(state, right);
let mut expanding = None;
if expand && let Edge::Glyph(font, slot) = edge {
let key = (font, slot);
match variations.entry(key) {
Entry::Occupied(_) => expanding = Some(key),
Entry::Vacant(entry) => {
if let Some(variation) = expansion::MarginVariation::project(state, font, slot)? {
entry.insert(variation);
expanding = Some(key);
}
}
}
}
Ok(EdgeMeasure { width, expanding })
};
for (i, node) in nodes.iter().enumerate() { for (i, node) in nodes.iter().enumerate() {
let edge = Edge::node(node, true); let edge = Edge::node(node, true);
widths[i + 1].right = if matches!(edge, Edge::Skip) { widths[i + 1].right = if matches!(edge, Edge::Skip) {
widths[i].right widths[i].right
} else { } else {
Some((i, edge.width(state, true))) Some((i, project(edge, true)?))
}; };
if let TextNode::Discretionary { if let TextNode::Discretionary { pre_break, post_break, .. } = node {
pre_break, widths[i].pre = pre_break.last()
post_break, .map(|node| project(Edge::character(node), true)).transpose()?;
.. widths[i].post = post_break.first()
} = node .map(|node| project(Edge::character(node), false)).transpose()?;
{
widths[i].pre = pre_break
.last()
.map(|node| Edge::character(node).width(state, true));
widths[i].post = post_break
.first()
.map(|node| Edge::character(node).width(state, false));
} }
} }
for (i, node) in nodes.iter().enumerate().rev() { for (i, node) in nodes.iter().enumerate().rev() {
@@ -198,36 +219,54 @@ impl Search {
widths[i].left = if matches!(edge, Edge::Skip) { widths[i].left = if matches!(edge, Edge::Skip) {
widths[i + 1].left widths[i + 1].left
} else { } else {
Some((i, edge.width(state, false))) Some((i, project(edge, false)?))
}; };
} }
Self(widths) Ok(Self { widths, variations })
} }
pub(super) fn len(&self) -> usize { pub(super) fn len(&self) -> usize {
self.0.len() self.widths.len() + self.variations.len()
} }
pub(super) fn width( pub(super) fn needs_fonts(&self) -> bool {
self.variations.values().any(|v| matches!(v, expansion::MarginVariation::Pending { .. }))
}
pub(super) fn edges(
&self, &self,
start: usize, start: usize,
end: usize, end: usize,
post: Option<usize>, post: Option<usize>,
pre: Option<usize>, pre: Option<usize>,
right_visible: bool, right_visible: bool,
) -> i64 { ) -> [EdgeMeasure; 2] {
let left = post.and_then(|i| self.0[i].post).or_else(|| { let left = post.and_then(|i| self.widths[i].post).or_else(|| {
self.0[start] self.widths[start].left
.left
.filter(|(i, _)| *i < end) .filter(|(i, _)| *i < end)
.map(|(_, width)| width) .map(|(_, edge)| edge)
}); });
let right = pre.and_then(|i| self.0[i].pre).or_else(|| { let right = pre.and_then(|i| self.widths[i].pre).or_else(|| {
self.0[end] self.widths[end].right
.right
.filter(|(i, _)| right_visible && *i >= start) .filter(|(i, _)| right_visible && *i >= start)
.map(|(_, width)| width) .map(|(_, edge)| edge)
}); });
i64::from(left.unwrap_or(0)) + i64::from(right.unwrap_or(0)) [left.unwrap_or_default(), right.unwrap_or_default()]
}
pub(super) fn variation(
&mut self,
edges: [EdgeMeasure; 2],
state: &mut State,
files: &mut impl SourceProvider,
) -> Result<expansion::Capacity, String> {
let mut total = expansion::Capacity::default();
for edge in edges {
if let Some(key) = edge.expanding {
total += self.variations.get_mut(&key).expect("projected margin glyph")
.resolve(state, key.0, files)?;
}
}
Ok(total)
} }
} }
@@ -110,8 +110,9 @@ pub struct ParagraphTraceReport {
pub span: Span, pub span: Span,
} }
pub(super) struct Tracer<'a> { pub(super) struct Tracer {
state: &'a State, escapechar: i32,
trailing_fill: bool,
enabled: bool, enabled: bool,
records: Vec<ParagraphTrace>, records: Vec<ParagraphTrace>,
printed: Option<usize>, printed: Option<usize>,
@@ -120,10 +121,11 @@ pub(super) struct Tracer<'a> {
bytes: usize, bytes: usize,
limit: usize, limit: usize,
} }
impl<'a> Tracer<'a> { impl Tracer {
pub fn new(state: &'a State, limit: usize) -> Self { pub fn new(state: &State, limit: usize) -> Self {
Self { Self {
state, escapechar: state.escapechar,
trailing_fill: !state.parameter(Parameter::Parfillskip).glue().canonical_zero,
enabled: state.parameter(Parameter::Tracingparagraphs).width() > 0, enabled: state.parameter(Parameter::Tracingparagraphs).width() > 0,
records: Vec::new(), records: Vec::new(),
printed: None, printed: None,
@@ -140,7 +142,7 @@ impl<'a> Tracer<'a> {
if self.enabled { if self.enabled {
self.bytes = self.bytes.saturating_add( self.bytes = self.bytes.saturating_add(
record record
.text(self.state.escapechar) .text(self.escapechar)
.map_or(0, |s| s.len() + 1), .map_or(0, |s| s.len() + 1),
); );
if self.bytes > self.limit { if self.bytes > self.limit {
@@ -159,11 +161,11 @@ impl<'a> Tracer<'a> {
announced: pass != 1 || first_was_run, announced: pass != 1 || first_was_run,
}) })
} }
fn character(&mut self, font: FontId, text: &str, out: &mut String) -> Result<(), String> { fn character(&mut self, state: &State, font: FontId, text: &str, out: &mut String) -> Result<(), String> {
if font != self.font { if font != self.font {
out.push_str(&escape( out.push_str(&escape(
self.state.escapechar, self.escapechar,
&self.state.fonts.font(font)?.identifier_text(), &state.fonts.font(font)?.identifier_text(),
)); ));
out.push(' '); out.push(' ');
self.font = font; self.font = font;
@@ -171,7 +173,7 @@ impl<'a> Tracer<'a> {
out.push_str(text); out.push_str(text);
Ok(()) Ok(())
} }
fn short(&mut self, nodes: &[TextNode], out: &mut String) -> Result<(), String> { fn short(&mut self, state: &State, nodes: &[TextNode], out: &mut String) -> Result<(), String> {
let mut i = 0; let mut i = 0;
while let Some(n) = nodes.get(i) { while let Some(n) = nodes.get(i) {
match n { match n {
@@ -183,7 +185,7 @@ impl<'a> Tracer<'a> {
.. ..
} => { } => {
let character = (*slot as char).to_string(); let character = (*slot as char).to_string();
self.character(*font, if *ligature { original } else { &character }, out)?; self.character(state, *font, if *ligature { original } else { &character }, out)?;
} }
TextNode::MathChar(b) => { TextNode::MathChar(b) => {
if let Some(g) = &b.math_geometry if let Some(g) = &b.math_geometry
@@ -191,7 +193,7 @@ impl<'a> Tracer<'a> {
&& let crate::math_engine_tex::MathItem::NativeGlyph { font, slot, .. } = && let crate::math_engine_tex::MathItem::NativeGlyph { font, slot, .. } =
&g.items[0].item &g.items[0].item
{ {
self.character(font.id, &(*slot as char).to_string(), out)?; self.character(state, font.id, &(*slot as char).to_string(), out)?;
} else { } else {
return Err( return Err(
"native math character short diagnostic structure is unavailable" "native math character short diagnostic structure is unavailable"
@@ -226,8 +228,8 @@ impl<'a> Tracer<'a> {
replacement_count, replacement_count,
.. ..
} => { } => {
self.short(pre_break, out)?; self.short(state, pre_break, out)?;
self.short(post_break, out)?; self.short(state, post_break, out)?;
i += usize::from(*replacement_count); i += usize::from(*replacement_count);
} }
TextNode::Kern { .. } | TextNode::AccentKern(_) | TextNode::Penalty(_) TextNode::Kern { .. } | TextNode::AccentKern(_) | TextNode::Penalty(_)
@@ -240,19 +242,16 @@ impl<'a> Tracer<'a> {
} }
Ok(()) Ok(())
} }
pub fn material(&mut self, nodes: &[TextNode], end: usize) -> Result<(), String> { pub fn material(&mut self, state: &State, nodes: &[TextNode], end: usize) -> Result<(), String> {
if !self.enabled || self.printed == Some(end) { if !self.enabled || self.printed == Some(end) {
return Ok(()); return Ok(());
} }
let mut text = String::new(); let mut text = String::new();
// short_display includes the breakpoint itself (not its following link). // short_display includes the breakpoint itself (not its following link).
let stop = (end + 1).min(nodes.len()); let stop = (end + 1).min(nodes.len());
self.short(&nodes[self.next_material.min(stop)..stop], &mut text)?; self.short(state, &nodes[self.next_material.min(stop)..stop], &mut text)?;
if end == nodes.len() { if end == nodes.len() && self.trailing_fill {
let g = self.state.parameter(Parameter::Parfillskip).glue(); text.push(' ');
if !g.canonical_zero {
text.push(' ');
}
} }
self.push(ParagraphTrace::Material { text })?; self.push(ParagraphTrace::Material { text })?;
self.printed = Some(end); self.printed = Some(end);
+34 -1
View File
@@ -1908,13 +1908,46 @@ TFM、字体映射和程序。已关联到伸缩的内部字体具有独立编
断行时同时打开 `\pdfadjustspacing=2` 和 `\pdfprotrudechars=2`,参考会先 断行时同时打开 `\pdfadjustspacing=2` 和 `\pdfprotrudechars=2`,参考会先
读取候选边缘字形的量化档位。系数 500 且缺少 +25 的冻结用例中,参考 读取候选边缘字形的量化档位。系数 500 且缺少 +25 的冻结用例中,参考
在断行时报错,原生仍完成段落。搜索阶段的边缘变化与资源读取待接入。 在断行时报错,上一阶段原生仍完成段落。该差异的修复见下节。
回执在 target/p3-external-font-expansion,SHA-256 为 回执在 target/p3-external-font-expansion,SHA-256 为
42902ce2f4b205bebdab857c9cecc0cb96dfb2db895c13237cfce18e9628b012(字体、列表、PDF), 42902ce2f4b205bebdab857c9cecc0cb96dfb2db895c13237cfce18e9628b012(字体、列表、PDF),
b05b12abccd87798a312967131420e00ffa675e9d5512990c24059bb106fef4a(编辑档位), b05b12abccd87798a312967131420e00ffa675e9d5512990c24059bb106fef4a(编辑档位),
dde86a91bc189ee571a26213273f407bafab8706aa912eed4d1de5a89af06f55(改动 TFM)。 dde86a91bc189ee571a26213273f407bafab8706aa912eed4d1de5a89af06f55(改动 TFM)。
### 断行候选边缘的外置预伸缩度量
边缘悬挂和字宽伸缩均用模式 2 时,从候选断点的实际左右边缘选择字体。
当短缺量非零,按字体系数和步长查找正负档位,用实际 em 差值修正该
候选行的伸缩容量。附到断点两侧的 discretionary 字形同样进入计算。
装盒测量会先处理实际边缘,即使后续胶水设定无需替换字形,所需度量
仍按原顺序读取。
[pdfTeX 的边缘度量变化](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/pdftexdir/pdftex.web#L19154-L19176)
实际分配字体的搜索轮次执行完整查找。已加载档位的变动量进入断行缓存键,
重复搜索可以复用。缺失 +25、缺失 −25、无边缘代码、零短缺量、实际边缘
遇到无限伸长胶水、discretionary 两侧等 12 份定向输入的状态和 TFM 读取
顺序均与 pdfTeX 一致。边界文件只改变 em 值即使模式 2 从两行改为一行。
四段原始盒列表、输出 PDF 的两个词框和 144 DPI 灰度图一致。相关诊断
与段落追踪共 13 项既有测试通过。
同一个实时会话中重复排版产生 2 次断行求解及 1 次复用。删除只在搜索
中使用的 +25 TFM 后,实际查找失败,已发布 PDF 保留。恢复不同版本的
TFM 并改动第二页文本,复用 1217 步,只更换第二页。PDF、SVG 和来源映射
均与相同项目快照的独立零复用全量相同。
回执在 target/p3-break-margin-expansion,SHA-256 分别为
27f17d6b437c10824edf2e2ca36f19854116d7406ebc141e45a3cf32157c1cf3(读取与绘制)和
8dd5a61fc607f5e99a5f0e6e0f4da8a4e8c814d220a57be76bf1a88ea593200a(资源缺失与恢复)。
最终构建复核缺失档位、嵌套盒边缘和实际发页。嵌套盒的原始列表一致,
有效 PDF 与该阶段的原生输出逐字节一致,回执 SHA-256 为
27f1da7caa0f7606bc0bfe47a3b4a271df3eea4598da7069f4129eda8402e919。
下一处字体表差异已复现。`\pdffontexpand ... autoexpand` 声明后,pdfTeX
拒绝为原字体新增第 8 个参数。参考只读基础 TFM,原生目前仍允许追加。
有无声明的原样对照在 next-auto-font-table,回执 SHA-256 为
6ecef22622cab83b83a11f6e2dbc33e82ba02ea38b8a70c4f791f7a0f9e18d1f。
### 原生段落边缘悬挂 ### 原生段落边缘悬挂
`\pdfprotrudechars`、`\lpcode`、`\rpcode` 接入实际字体槽和水平 `\pdfprotrudechars`、`\lpcode`、`\rpcode` 接入实际字体槽和水平