Write PDF interword spaces with actual device fonts

This commit is contained in:
gloamxun committed 2026-11-21 03:09:10 +08:00
1 parent b93d5f55da
commit 514a2d3344
24 files changed
+664 -65

No files matched your search

@@ -310,6 +310,10 @@ impl Executor {
} else {
Vec::new().into_iter()
};
use crate::pdf_device::text_spaces::{SpaceFontRequest, SpaceOperation, SpaceSettings};
let automatic_spaces_at_start = self.pdf_interword_spaces;
let mut uses_automatic_spaces = automatic_spaces_at_start;
let mut has_space_nodes = false;
let mut pdf_objects = Vec::new();
for output in outputs {
if let OutputOperation::PdfObject(number) = output.operation {
@@ -337,6 +341,17 @@ impl Executor {
&mut graphics_stack,
files,
)?);
} else if let OutputOperation::PdfTextSpace(operation) = output.operation {
self.current = output.span;
self.tick()?;
if device.pdf.is_none() {
return self.fail("cannot ship a PDF text space operation to DVI");
}
has_space_nodes = true;
if let SpaceOperation::Automatic(enabled) = operation {
self.pdf_interword_spaces = enabled;
uses_automatic_spaces |= enabled;
}
} else if let OutputOperation::PdfLink(link) = &output.operation {
use crate::pdf_device::links::LinkNode;
self.current = output.span;
@@ -380,6 +395,25 @@ impl Executor {
} else {
Default::default()
};
let pdf_text_spaces = (has_space_nodes || automatic_spaces_at_start).then(|| {
let parameters = if uses_automatic_spaces {
self.reads.insert(Dependency::FontResources);
self.state.fonts.fonts().iter().map(|font| {
let glue = font.space();
(glue.width, glue.shrink.amount)
}).collect()
} else {
Vec::new()
};
SpaceSettings {
automatic_at_start: automatic_spaces_at_start,
font: self.pdf_space_font.clone().unwrap_or_else(|| SpaceFontRequest {
name: "pdftexspace".into(),
from: self.source_name(current),
}),
parameters,
}
});
self.current = current;
self.native_page.as_mut().unwrap().dead_cycles = 0;
let before = self.statistics_before_shipout(&b, files)?;
@@ -390,6 +424,7 @@ impl Executor {
pdf_color_start,
pdf_color_steps,
pdf_graphics_steps,
pdf_text_spaces,
pdf_resource_entries,
pdf_links,
})));