diff options
| author | bluebear94 <uruwi@protonmail.com> | 2023-10-03 09:04:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-03 15:04:15 +0200 |
| commit | d709b0e2479d780625becc2f493ce4067aa20cb3 (patch) | |
| tree | 33d05ce4bc8d77692a8a64e7af99a9443517c05a | |
| parent | ce658db2f39f8472c3525a18ed1cfead23781fbb (diff) | |
Honor text’s fallback option for hyphenation (#2301)
| -rw-r--r-- | crates/typst-library/src/layout/par.rs | 2 | ||||
| -rw-r--r-- | crates/typst-library/src/text/shaping.rs | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index 82e7e52d..e41d3547 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -1272,7 +1272,7 @@ fn line<'a>( if hyphen || start < range.end || before.is_empty() { let mut reshaped = shaped.reshape(vt, &p.spans, start..range.end); if hyphen || shy { - reshaped.push_hyphen(vt); + reshaped.push_hyphen(vt, TextElem::fallback_in(p.styles)); } let punct = reshaped.glyphs.last(); if let Some(punct) = punct { diff --git a/crates/typst-library/src/text/shaping.rs b/crates/typst-library/src/text/shaping.rs index 57501c52..73ae0779 100644 --- a/crates/typst-library/src/text/shaping.rs +++ b/crates/typst-library/src/text/shaping.rs @@ -429,12 +429,17 @@ impl<'a> ShapedText<'a> { } /// Push a hyphen to end of the text. - pub fn push_hyphen(&mut self, vt: &Vt) { + pub fn push_hyphen(&mut self, vt: &Vt, fallback: bool) { let world = vt.world; let book = world.book(); + let fallback_func = if fallback { + Some(|| book.select_fallback(None, self.variant, "-")) + } else { + None + }; let mut chain = families(self.styles) .map(|family| book.select(family.as_str(), self.variant)) - .chain(std::iter::once_with(|| book.select_fallback(None, self.variant, "-"))) + .chain(fallback_func.iter().map(|f| f())) .flatten(); chain.find_map(|id| { |
