mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Honor text’s fallback option for hyphenation (#2301)
This commit is contained in:
parent
ce658db2f3
commit
d709b0e247
@ -1272,7 +1272,7 @@ fn line<'a>(
|
|||||||
if hyphen || start < range.end || before.is_empty() {
|
if hyphen || start < range.end || before.is_empty() {
|
||||||
let mut reshaped = shaped.reshape(vt, &p.spans, start..range.end);
|
let mut reshaped = shaped.reshape(vt, &p.spans, start..range.end);
|
||||||
if hyphen || shy {
|
if hyphen || shy {
|
||||||
reshaped.push_hyphen(vt);
|
reshaped.push_hyphen(vt, TextElem::fallback_in(p.styles));
|
||||||
}
|
}
|
||||||
let punct = reshaped.glyphs.last();
|
let punct = reshaped.glyphs.last();
|
||||||
if let Some(punct) = punct {
|
if let Some(punct) = punct {
|
||||||
|
@ -429,12 +429,17 @@ impl<'a> ShapedText<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Push a hyphen to end of the text.
|
/// 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 world = vt.world;
|
||||||
let book = world.book();
|
let book = world.book();
|
||||||
|
let fallback_func = if fallback {
|
||||||
|
Some(|| book.select_fallback(None, self.variant, "-"))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let mut chain = families(self.styles)
|
let mut chain = families(self.styles)
|
||||||
.map(|family| book.select(family.as_str(), self.variant))
|
.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();
|
.flatten();
|
||||||
|
|
||||||
chain.find_map(|id| {
|
chain.find_map(|id| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user