Fix outline with CJK text (#5187)

This commit is contained in:
Laurenz 2024-10-12 14:01:34 +02:00 committed by GitHub
parent 61d461f080
commit 8b6f7298e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 17 deletions

View File

@ -10,7 +10,9 @@ use crate::foundations::{
NativeElement, Packed, Show, ShowSet, Smart, StyleChain, Styles,
};
use crate::introspection::{Counter, CounterKey, Locatable};
use crate::layout::{BoxElem, Em, Fr, HElem, HideElem, Length, Rel, RepeatElem, Spacing};
use crate::layout::{
BoxElem, Dir, Em, Fr, HElem, HideElem, Length, Rel, RepeatElem, Spacing,
};
use crate::model::{
Destination, HeadingElem, NumberingPattern, ParElem, ParbreakElem, Refable,
};
@ -499,12 +501,27 @@ impl Show for Packed<OutlineEntry> {
}
};
// The body text remains overridable.
crate::text::isolate(
self.body().clone().linked(Destination::Location(location)),
styles,
&mut seq,
);
// Isolate the entry body in RTL because the page number is typically
// LTR. I'm not sure whether LTR should conceptually also be isolated,
// but in any case we don't do it for now because the text shaping
// pipeline does tend to choke a bit on default ignorables (in
// particular the CJK-Latin spacing).
//
// See also:
// - https://github.com/typst/typst/issues/4476
// - https://github.com/typst/typst/issues/5176
let rtl = TextElem::dir_in(styles) == Dir::RTL;
if rtl {
// "Right-to-Left Embedding"
seq.push(TextElem::packed("\u{202B}"));
}
seq.push(self.body().clone().linked(Destination::Location(location)));
if rtl {
// "Pop Directional Formatting"
seq.push(TextElem::packed("\u{202C}"));
}
// Add filler symbols between the section name and page number.
if let Some(filler) = self.fill() {

View File

@ -1284,16 +1284,6 @@ pub(crate) fn is_default_ignorable(c: char) -> bool {
DEFAULT_IGNORABLE_DATA.as_borrowed().contains(c)
}
/// Pushes `text` wrapped in LRE/RLE + PDF to `out`.
pub(crate) fn isolate(text: Content, styles: StyleChain, out: &mut Vec<Content>) {
out.push(TextElem::packed(match TextElem::dir_in(styles) {
Dir::RTL => "\u{202B}",
_ => "\u{202A}",
}));
out.push(text);
out.push(TextElem::packed("\u{202C}"));
}
/// Checks for font families that are not available.
fn check_font_list(engine: &mut Engine, list: &Spanned<FontList>) {
let book = engine.world.book();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -171,3 +171,12 @@ A
= הוקוס Pocus
= זוהי כותרת שתורגמה על ידי מחשב
--- issue-5176-cjk-title ---
#set text(font: "Noto Serif CJK SC")
#show heading: none
#outline(title: none)
= 测
= 很