diff --git a/crates/typst/src/text/font/book.rs b/crates/typst/src/text/font/book.rs index c875ab172..2e64533e2 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 { - // 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 000000000..78f937eb2 Binary files /dev/null and b/tests/ref/bugs/2105-linebreak-tofu.png differ diff --git a/tests/typ/bugs/2105-linebreak-tofu.typ b/tests/typ/bugs/2105-linebreak-tofu.typ new file mode 100644 index 000000000..4dd5a2441 --- /dev/null +++ b/tests/typ/bugs/2105-linebreak-tofu.typ @@ -0,0 +1 @@ +#linebreak()中文