Support setting fonts repeatedly with different covers (#6604)

This commit is contained in:
Y.D.X. 2025-07-16 16:10:21 +08:00 committed by GitHub
parent cdbf60e883
commit ea5272bb2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 1 deletions

View File

@ -719,6 +719,10 @@ fn glyphs_width(glyphs: &[ShapedGlyph]) -> Abs {
struct ShapingContext<'a, 'v> { struct ShapingContext<'a, 'v> {
engine: &'a Engine<'v>, engine: &'a Engine<'v>,
glyphs: Vec<ShapedGlyph>, glyphs: Vec<ShapedGlyph>,
/// Font families that have been used with unlimited coverage.
///
/// These font families are considered exhausted and will not be used again,
/// even if they are declared again (e.g., during fallback after normal selection).
used: Vec<Font>, used: Vec<Font>,
styles: StyleChain<'a>, styles: StyleChain<'a>,
size: Abs, size: Abs,
@ -777,7 +781,10 @@ fn shape_segment<'a>(
return; return;
}; };
// This font has been exhausted and will not be used again.
if covers.is_none() {
ctx.used.push(font.clone()); ctx.used.push(font.clone());
}
// Fill the buffer with our text. // Fill the buffer with our text.
let mut buffer = UnicodeBuffer::new(); let mut buffer = UnicodeBuffer::new();

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -135,6 +135,34 @@ I
The number 123. The number 123.
--- text-font-covers-repeat ---
// Repeatedly use the same font.
#set text(font: (
(name: "Libertinus Serif", covers: regex("[0-9]")),
"Libertinus Serif"
))
The number 123.
--- text-font-covers-riffle ---
// Repeatedly use two fonts alternately.
#set text(font: (
(name: "Noto Color Emoji", covers: regex("[🔗⛓‍💥]")),
(name: "Twitter Color Emoji", covers: regex("[^🖥️]")),
"Noto Color Emoji",
))
🔗⛓‍💥🖥️🔑
// The above should be the same as:
#{
text(font: "Noto Color Emoji", "🔗⛓‍💥🖥️")
text(font: "Twitter Color Emoji", "🔑")
}
// but not:
#text(font: "Twitter Color Emoji", "🔗⛓‍💥🖥️🔑")
--- text-font-covers-bad-1 --- --- text-font-covers-bad-1 ---
// Error: 17-59 coverage regex may only use dot, letters, and character classes // Error: 17-59 coverage regex may only use dot, letters, and character classes
// Hint: 17-59 the regex is applied to each letter individually // Hint: 17-59 the regex is applied to each letter individually