Implement native automatic font expansion for paragraphs
This commit is contained in:
1 parent
1dd745afcb
commit
ebbc9e2c17
24 files changed
+632
-34
No files matched your search
@@ -4,6 +4,7 @@ use crate::{HorizontalBox, Paragraph, ParagraphFont};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
mod break_cache;
|
||||
mod expansion;
|
||||
mod protrusion;
|
||||
use break_cache::BreakNode;
|
||||
pub use break_cache::{LineBreakCache, LineBreakWork};
|
||||
@@ -557,6 +558,7 @@ fn break_lines(
|
||||
nodes: &[TextNode],
|
||||
projected: &[BreakNode],
|
||||
margins: Option<&protrusion::Search>,
|
||||
expansion: Option<&expansion::Search>,
|
||||
p: &BTreeMap<Parameter, ParameterValue>,
|
||||
shape: &[ParagraphShapeLine],
|
||||
pass: u8,
|
||||
@@ -743,7 +745,10 @@ fn break_lines(
|
||||
|| p[&Parameter::Parfillskip].glue().canonical_zero;
|
||||
margins.width(a.start, b.end, a.post_break, b.pre_break, right_visible)
|
||||
});
|
||||
let delta = target - natural + hanging;
|
||||
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 infinite = stretch[1..].iter().any(|n| *n != 0);
|
||||
let bad = if delta >= 0 {
|
||||
if infinite {
|
||||
@@ -964,7 +969,10 @@ fn pack(
|
||||
p[&Parameter::Rightskip].glue(),
|
||||
Parameter::Rightskip,
|
||||
));
|
||||
let (material, adjustments) = super::marks::extract(material);
|
||||
let (mut material, adjustments) = super::marks::extract(material);
|
||||
if p[&Parameter::Pdfadjustspacing].width() > 0 && state.fonts.has_expansion() {
|
||||
expansion::pack(state, &mut material, target)?;
|
||||
}
|
||||
let shrinking = material.iter().map(width).sum::<i64>() > target;
|
||||
let mut b = super::boxes::hpack(
|
||||
material,
|
||||
|
||||
Reference in new issue
Block a user