Support native PDF font dictionaries and running link controls

This commit is contained in:
gloamxun committed 2026-11-21 02:46:57 +08:00
1 parent 60d7411dfe
commit b647bd8dcd
19 files changed
+180 -13

No files matched your search

@@ -44,6 +44,31 @@ impl Executor {
}
Ok(())
}
pub(super) fn pdf_font_settings(
&mut self,
primitive: Primitive,
files: &mut impl SourceProvider,
) -> Result<(), Error> {
if self.read_parameter(Parameter::Pdfoutput).width() <= 0 {
return self.fail("native PDF font settings are unavailable in DVI mode");
}
let font = self.font_identifier(files)?;
if font == FontId::NULL {
return self.fail("invalid PDF font identifier");
}
match primitive {
Primitive::Pdffontattr => {
let tokens = self.scan_expanded_group(files)?;
let attributes = self.pdf_token_bytes(&tokens)?;
self.state.fonts.pdf_settings.entry(font).or_default().attributes = attributes;
}
Primitive::Pdfnobuiltintounicode => {
self.state.fonts.pdf_settings.entry(font).or_default().omit_builtin_unicode = true;
}
_ => unreachable!(),
}
Ok(())
}
pub(super) fn pdf_page_data(
&mut self,
files: &mut impl SourceProvider,
@@ -548,6 +548,8 @@ impl Executor {
Hbox | Vbox | Vtop | Box | Copy | Setbox | Wd | Ht | Dp | Lastbox | Raise
| Lower | Vsplit | Mark | Marks | Vadjust | Insert | Shipout | Openout
| Closeout | Write | Pdfcolorstack | Pdfsave | Pdfsetmatrix | Pdfrestore | Pdfcatalog | Pdfoutline
| Pdfglyphtounicode | Pdffontattr | Pdfnobuiltintounicode
| Pdfrunninglinkoff | Pdfrunninglinkon
| Ignorespaces | Unskip | Unkern | Unpenalty => {
return Ok(false);
}
@@ -353,7 +353,7 @@ impl Executor {
return self.fail("\\pdfendlink used without \\pdfstartlink");
}
LinkNode::End => link_depth -= 1,
LinkNode::Destination { .. } => {}
LinkNode::Running(_) | LinkNode::Destination { .. } => {}
}
} else {
self.output_node(output, files)?;
@@ -111,7 +111,10 @@ impl Executor {
if self.native_page.is_none() || self.read_parameter(Parameter::Pdfoutput).width() <= 0 {
return self.fail("PDF link operation not allowed in DVI mode");
}
if command != Primitive::Pdfdest && self.paragraph.is_none() && self.math.is_empty() {
if matches!(command, Primitive::Pdfstartlink | Primitive::Pdfendlink)
&& self.paragraph.is_none()
&& self.math.is_empty()
{
return self.fail(if command == Primitive::Pdfstartlink {
"\\pdfstartlink cannot be used in vertical mode"
} else {
@@ -167,6 +170,9 @@ impl Executor {
})
}
Primitive::Pdfendlink => LinkNode::End,
Primitive::Pdfrunninglinkoff | Primitive::Pdfrunninglinkon => {
LinkNode::Running(command == Primitive::Pdfrunninglinkon)
}
Primitive::Pdfdest => {
let destination = if self.keyword("name", files)? {
DestinationId::Name(self.scan_pdf_tokens(files)?)
@@ -248,7 +254,7 @@ impl Executor {
Some(PdfGraphics::Literal { .. }) => {}
None => failure = Some(self.error("missing PDF transform at link shipout", self.current)),
},
BoxPaint::RowStart(row) => {
BoxPaint::RowStart(row) if self.pdf_running_links => {
for link in active.iter_mut().filter(|link| {
link.level == row.level && link.layout.width.is_none()
}) {
@@ -292,6 +298,7 @@ impl Executor {
}
link.end_segment(&mut output, x, margin);
}
LinkNode::Running(enabled) => self.pdf_running_links = *enabled,
LinkNode::Destination { destination, view } => {
let destination = match destination {
DestinationId::Name(tokens) => DestinationId::Name(self.token_list_text(tokens)),