From 28a5069f959a4276b8280a78c925448f93d7121e Mon Sep 17 00:00:00 2001 From: Wenzhuo Liu Date: Wed, 3 Jan 2024 17:41:41 +0800 Subject: [PATCH] Fix linebreak fallback tofu (#3123) --- crates/typst/src/text/font/book.rs | 4 ++-- tests/ref/bugs/2105-linebreak-tofu.png | Bin 0 -> 473 bytes tests/typ/bugs/2105-linebreak-tofu.typ | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 tests/ref/bugs/2105-linebreak-tofu.png create mode 100644 tests/typ/bugs/2105-linebreak-tofu.typ 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 0000000000000000000000000000000000000000..78f937eb2c9867d7ed4083a40e807c0514ddb897 GIT binary patch literal 473 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQZQ#pVHL*Jf5bAbX2JY5_^DsH{KPmZ z+5n-a3SDzVCavDnC)93P7+Ex7iJ|x3V82tDk5t^lMV=bCuUs1D6_?KysU7C!ax?Mc z|IFy<m|GoVAhc7bolt5rn&E&*J1||-L22zRt0*Nc0N7hT{_s?iGco69K zF0gTe+XimAhd0i-S@1tonzQY$sFhRleEq=M?4nuTPL~#?MkY^7<=w55y)OI6)rZ@- zWfN_GtNgHOoQ?7-2@_`n=js6 z;d&=HTJ-!E?V9#vOPYYm%js{|)K70zUl{!|PI}w5Q~Ieahn^*y9Xi`>)OzX^)3Ny3 z-?h4y-{*0U$g;9tv+k~`ycX`^?4&t;ucLK6Vok++Ee literal 0 HcmV?d00001 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()中文