mirror of
https://github.com/typst/typst
synced 2025-05-22 13:05: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) {
|
fn write_page(&mut self, id: Ref, page: &'a Frame) {
|
||||||
let mut content = Content::new();
|
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 {
|
for (pos, element) in &page.elements {
|
||||||
let x = pos.x.to_pt() as f32;
|
let x = pos.x.to_pt() as f32;
|
||||||
match element {
|
match element {
|
||||||
@ -173,18 +178,8 @@ impl<'a> PdfExporter<'a> {
|
|||||||
content.restore_state();
|
content.restore_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
Element::Text(shaped) => {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
let mut text = content.text();
|
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.
|
// Check if we need to issue a font switching action.
|
||||||
if shaped.face != face || shaped.font_size != size {
|
if shaped.face != face || shaped.font_size != size {
|
||||||
face = shaped.face;
|
face = shaped.face;
|
||||||
@ -200,8 +195,7 @@ impl<'a> PdfExporter<'a> {
|
|||||||
text.show(&shaped.encode_glyphs_be());
|
text.show(&shaped.encode_glyphs_be());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
drop(text);
|
|
||||||
|
|
||||||
self.writer.stream(id, &content.finish());
|
self.writer.stream(id, &content.finish());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user