mirror of
https://github.com/typst/typst
synced 2025-05-22 04:55:29 +08:00
Merge text and shape PDF loops 🎡
This commit is contained in:
parent
6bd1a494e0
commit
bd12d135ca
@ -129,6 +129,11 @@ impl<'a> PdfExporter<'a> {
|
||||
fn write_page(&mut self, id: Ref, page: &'a Frame) {
|
||||
let mut content = Content::new();
|
||||
|
||||
// We only write font switching actions when the used face changes. To
|
||||
// do that, we need to remember the active face.
|
||||
let mut face = FaceId::MAX;
|
||||
let mut size = Length::ZERO;
|
||||
|
||||
for (pos, element) in &page.elements {
|
||||
let x = pos.x.to_pt() as f32;
|
||||
match element {
|
||||
@ -173,18 +178,8 @@ impl<'a> PdfExporter<'a> {
|
||||
content.restore_state();
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// We only write font switching actions when the used face changes. To
|
||||
// do that, we need to remember the active face.
|
||||
let mut face = FaceId::MAX;
|
||||
let mut size = Length::ZERO;
|
||||
|
||||
Element::Text(shaped) => {
|
||||
let mut text = content.text();
|
||||
for (pos, element) in &page.elements {
|
||||
if let Element::Text(shaped) = element {
|
||||
// Check if we need to issue a font switching action.
|
||||
if shaped.face != face || shaped.font_size != size {
|
||||
face = shaped.face;
|
||||
@ -200,8 +195,7 @@ impl<'a> PdfExporter<'a> {
|
||||
text.show(&shaped.encode_glyphs_be());
|
||||
}
|
||||
}
|
||||
|
||||
drop(text);
|
||||
}
|
||||
|
||||
self.writer.stream(id, &content.finish());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user