Honor text’s fallback option for hyphenation (#2301)

This commit is contained in:
bluebear94 2023-10-03 09:04:15 -04:00 committed by GitHub
parent ce658db2f3
commit d709b0e247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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 {

View File

@ -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| {