summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWenzhuo Liu <mgt@oi-wiki.org>2024-01-03 17:41:41 +0800
committerGitHub <noreply@github.com>2024-01-03 09:41:41 +0000
commit28a5069f959a4276b8280a78c925448f93d7121e (patch)
tree1b3f358665b0ffa5a87b6b3e101c5fd92bd50508
parent155af2318e4e747770965f7d0d54f3d934b37536 (diff)
Fix linebreak fallback tofu (#3123)
-rw-r--r--crates/typst/src/text/font/book.rs4
-rw-r--r--tests/ref/bugs/2105-linebreak-tofu.pngbin0 -> 473 bytes
-rw-r--r--tests/typ/bugs/2105-linebreak-tofu.typ1
3 files changed, 3 insertions, 2 deletions
diff --git a/crates/typst/src/text/font/book.rs b/crates/typst/src/text/font/book.rs
index c875ab17..2e64533e 100644
--- a/crates/typst/src/text/font/book.rs
+++ b/crates/typst/src/text/font/book.rs
@@ -93,8 +93,8 @@ impl FontBook {
variant: FontVariant,
text: &str,
) -> Option<usize> {
- // Find the fonts that contain the text's first char ...
- let c = text.chars().next()?;
+ // Find the fonts that contain the text's first non-space char ...
+ let c = text.chars().find(|c| !c.is_whitespace())?;
let ids = self
.infos
.iter()
diff --git a/tests/ref/bugs/2105-linebreak-tofu.png b/tests/ref/bugs/2105-linebreak-tofu.png
new file mode 100644
index 00000000..78f937eb
--- /dev/null
+++ b/tests/ref/bugs/2105-linebreak-tofu.png
Binary files differ
diff --git a/tests/typ/bugs/2105-linebreak-tofu.typ b/tests/typ/bugs/2105-linebreak-tofu.typ
new file mode 100644
index 00000000..4dd5a244
--- /dev/null
+++ b/tests/typ/bugs/2105-linebreak-tofu.typ
@@ -0,0 +1 @@
+#linebreak()中文