Measure external font expansion at paragraph break margins
This commit is contained in:
1 parent
91b3e6a8fe
commit
1e4c113b27
6 files changed
+242
-91
No files matched your search
@@ -572,14 +572,16 @@ fn metrics(nodes: &[TextNode], left: Glue, right: Glue) -> (i64, [i64; 4], i64)
|
||||
fn break_lines(
|
||||
nodes: &[TextNode],
|
||||
projected: &[BreakNode],
|
||||
margins: Option<&protrusion::Search>,
|
||||
mut margins: Option<&mut protrusion::Search>,
|
||||
expansion: Option<&expansion::Search>,
|
||||
state: &mut State,
|
||||
files: &mut impl SourceProvider,
|
||||
p: &BTreeMap<Parameter, ParameterValue>,
|
||||
shape: &[ParagraphShapeLine],
|
||||
pass: u8,
|
||||
work: &mut usize,
|
||||
previous_lines: usize,
|
||||
trace: &mut super::paragraph_trace::Tracer<'_>,
|
||||
trace: &mut super::paragraph_trace::Tracer,
|
||||
) -> Result<Option<Vec<(Break, i32)>>, String> {
|
||||
let get = |q| p[&q].width() as i64;
|
||||
let left = p[&Parameter::Leftskip].glue();
|
||||
@@ -753,17 +755,26 @@ fn break_lines(
|
||||
if target < 0 && shape.is_empty() {
|
||||
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
|
||||
// fill stops the right search at the terminal breakpoint.
|
||||
let right_visible = !final_break
|
||||
|| p[&Parameter::Parfillskip].glue().canonical_zero;
|
||||
margins.width(a.start, b.end, a.post_break, b.pre_break, right_visible)
|
||||
});
|
||||
let shortfall = target - natural + hanging;
|
||||
let delta = expansion.map_or(shortfall, |expansion| {
|
||||
expansion.residual(shortfall, a.start, b.end, a.post_break, b.pre_break)
|
||||
});
|
||||
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);
|
||||
if shortfall != 0 && expansion.is_some() {
|
||||
margin_variation = margins.variation(edges, state, files)?;
|
||||
}
|
||||
}
|
||||
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 bad = if delta >= 0 {
|
||||
if infinite {
|
||||
@@ -816,7 +827,7 @@ fn break_lines(
|
||||
get(Parameter::Doublehyphendemerits)
|
||||
});
|
||||
}
|
||||
trace.material(nodes, b.end)?;
|
||||
trace.material(state, nodes, b.end)?;
|
||||
trace.push(ParagraphTrace::Feasible {
|
||||
position: b.end,
|
||||
kind: if final_break {
|
||||
@@ -1091,7 +1102,7 @@ pub(super) fn finish(
|
||||
.iter()
|
||||
.map(|p| (*p, state.parameter(*p)))
|
||||
.collect();
|
||||
let shape = state.paragraph_shape();
|
||||
let shape = state.paragraph_shape().to_vec();
|
||||
for n in &b.nodes {
|
||||
if let TextNode::Glue(g)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
@@ -1138,7 +1149,8 @@ pub(super) fn finish(
|
||||
&b.nodes,
|
||||
¶meters,
|
||||
state,
|
||||
shape,
|
||||
files,
|
||||
&shape,
|
||||
pass,
|
||||
&mut work,
|
||||
b.previous_lines,
|
||||
|
||||
Reference in new issue
Block a user