mirror of
https://github.com/typst/typst
synced 2025-07-18 10:02:54 +08:00
Support setting fonts repeatedly with different covers
(#6604)
This commit is contained in:
parent
cdbf60e883
commit
ea5272bb2b
@ -719,6 +719,10 @@ fn glyphs_width(glyphs: &[ShapedGlyph]) -> Abs {
|
||||
struct ShapingContext<'a, 'v> {
|
||||
engine: &'a Engine<'v>,
|
||||
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>,
|
||||
styles: StyleChain<'a>,
|
||||
size: Abs,
|
||||
@ -777,7 +781,10 @@ fn shape_segment<'a>(
|
||||
return;
|
||||
};
|
||||
|
||||
ctx.used.push(font.clone());
|
||||
// This font has been exhausted and will not be used again.
|
||||
if covers.is_none() {
|
||||
ctx.used.push(font.clone());
|
||||
}
|
||||
|
||||
// Fill the buffer with our text.
|
||||
let mut buffer = UnicodeBuffer::new();
|
||||
|
BIN
tests/ref/text-font-covers-repeat.png
Normal file
BIN
tests/ref/text-font-covers-repeat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 467 B |
BIN
tests/ref/text-font-covers-riffle.png
Normal file
BIN
tests/ref/text-font-covers-riffle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -135,6 +135,34 @@ I
|
||||
|
||||
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 ---
|
||||
// Error: 17-59 coverage regex may only use dot, letters, and character classes
|
||||
// Hint: 17-59 the regex is applied to each letter individually
|
||||
|
Loading…
x
Reference in New Issue
Block a user