Apply native automatic kerns and protrusion at real line edges
This commit is contained in:
1 parent
f66a5a7e20
commit
1822ab2d32
22 files changed
+260
-36
No files matched your search
@@ -252,6 +252,7 @@ impl Executor {
|
||||
TextNode::Glyph { .. }
|
||||
| TextNode::Kern { .. }
|
||||
| TextNode::AccentKern(_)
|
||||
| TextNode::AutoKern(_)
|
||||
| TextNode::Box(_)
|
||||
| TextNode::Indent(_)
|
||||
| TextNode::Rule(_)
|
||||
|
||||
@@ -405,6 +405,8 @@ impl Executor {
|
||||
| Hyphenchar
|
||||
| Lpcode
|
||||
| Rpcode
|
||||
| Knbccode
|
||||
| Knaccode
|
||||
| Efcode
|
||||
| Pdffontexpand
|
||||
| Skewchar
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Executor {
|
||||
self.paragraph
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_language(language)
|
||||
.set_language(language, &self.state)
|
||||
.map_err(|e| self.error(e, self.current))?;
|
||||
self.reads
|
||||
.insert(Dependency::Parameter(Parameter::Lefthyphenmin));
|
||||
|
||||
@@ -20,7 +20,9 @@ impl Tail {
|
||||
TextNode::Glue(g)
|
||||
| TextNode::NamedGlue(g, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue: g, .. }) => Self::Glue(*g, false),
|
||||
TextNode::Kern { width, .. } | TextNode::AccentKern(width) => Self::Kern(*width),
|
||||
TextNode::Kern { width, .. } | TextNode::AccentKern(width) | TextNode::AutoKern(width) => {
|
||||
Self::Kern(*width)
|
||||
}
|
||||
TextNode::Penalty(n) => Self::Penalty(*n),
|
||||
TextNode::MarginKern { .. } => Self::Other(15),
|
||||
TextNode::Glyph { ligature, .. } => Self::Other(if *ligature { 7 } else { 0 }),
|
||||
|
||||
@@ -783,7 +783,7 @@ impl Executor {
|
||||
| Delcode | Count | Countdef | Dimen | Dimendef | Skip | Skipdef | Muskip
|
||||
| Muskipdef | Toks | Toksdef | Advance | Multiply | Divide | Read | Readline
|
||||
| Font | Fontdimen | Hyphenchar | Skewchar | Lpcode | Rpcode | Efcode | Pdffontexpand
|
||||
| Letterspacefont | Textfont | Scriptfont
|
||||
| Knbccode | Knaccode | Letterspacefont | Textfont | Scriptfont
|
||||
| Scriptscriptfont | Endlinechar | Newlinechar | Escapechar | Globaldefs | Time
|
||||
| Day | Month | Year | BeginGroup | EndGroup | Relax | Message | Errmessage
|
||||
| Endinput | Showbox | Show | Showthe | Discretionary | DiscretionaryHyphen
|
||||
|
||||
@@ -288,14 +288,22 @@ impl Executor {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn track_auto_kern_parameters(&mut self) {
|
||||
if self.state.fonts.has_auto_kern_codes() {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::Pdfprependkern));
|
||||
self.reads.insert(Dependency::Parameter(Parameter::Pdfappendkern));
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn finish_text(&mut self, right_boundary: bool) -> Result<(), Error> {
|
||||
self.track_auto_kern_parameters();
|
||||
let Some(p) = self.paragraph.as_mut() else {
|
||||
return Ok(());
|
||||
};
|
||||
let before = p.font_steps;
|
||||
p.ligature_carry = self.ligature_carry;
|
||||
p.font_step_limit = before.saturating_add(self.limits.steps.saturating_sub(self.steps));
|
||||
let result = p.finish_text(right_boundary);
|
||||
let result = p.finish_text(right_boundary, &self.state);
|
||||
self.ligature_carry = p.ligature_carry;
|
||||
self.steps = self
|
||||
.steps
|
||||
@@ -309,6 +317,7 @@ impl Executor {
|
||||
token: &Token,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
self.track_auto_kern_parameters();
|
||||
let before = self.paragraph.as_ref().map_or(0, |p| p.font_steps);
|
||||
if let Some(p) = self.paragraph.as_mut() {
|
||||
p.ligature_carry = self.ligature_carry;
|
||||
@@ -354,7 +363,7 @@ impl Executor {
|
||||
let language = HyphenationLanguage::from_state(&self.state);
|
||||
let b = self.paragraph.as_mut().unwrap();
|
||||
if b.current_language.language != language.language {
|
||||
b.set_language(language)
|
||||
b.set_language(language, &self.state)
|
||||
.map_err(|e| self.error(e, token.span))?;
|
||||
}
|
||||
for p in [
|
||||
@@ -597,14 +606,20 @@ impl Executor {
|
||||
hyphen_char = None;
|
||||
}
|
||||
}
|
||||
let mut pre_break = Vec::new();
|
||||
if let Some(c) = hyphen_char {
|
||||
let kern = FontCatalog::auto_kern_for(&self.state, font);
|
||||
let before = kern.and_then(|k| k.width(None, Some(c as u8)));
|
||||
let after = kern.and_then(|k| k.width(Some(c as u8), None));
|
||||
pre_break.extend(before.map(TextNode::AutoKern));
|
||||
pre_break.push(super::super::paragraph::hyphen_node(&self.state, font, c, origin));
|
||||
pre_break.extend(after.map(TextNode::AutoKern));
|
||||
}
|
||||
TextNode::Discretionary {
|
||||
font,
|
||||
automatic: false,
|
||||
hyphen_char,
|
||||
pre_break: hyphen_char
|
||||
.into_iter()
|
||||
.map(|c| super::super::paragraph::hyphen_node(&self.state, font, c, origin))
|
||||
.collect(),
|
||||
pre_break,
|
||||
post_break: Vec::new(),
|
||||
replacement_count: 0,
|
||||
}
|
||||
|
||||
@@ -230,6 +230,8 @@ impl Executor {
|
||||
| Primitive::Hyphenchar
|
||||
| Primitive::Lpcode
|
||||
| Primitive::Rpcode
|
||||
| Primitive::Knbccode
|
||||
| Primitive::Knaccode
|
||||
| Primitive::Efcode
|
||||
| Primitive::Skewchar
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user