Apply XeLaTeX CMaps to document text and embedded fonts

This commit is contained in:
gloamxun committed 2026-11-28 21:40:17 +08:00
1 parent af6466cd98
commit 7d460e0fa1
20 files changed
+747 -65

No files matched your search

@@ -57,6 +57,7 @@ impl Executor {
graphics_step: usize,
capture_origin: [f64; 2],
links: &mut crate::pdf_device::links::PageLinks,
text: Option<&crate::pdf_device::xdv_document::TextEncoding>,
origin: Option<TokenOrigin>,
files: &mut impl SourceProvider,
) -> Result<Option<PdfGraphics>, Error> {
@@ -82,9 +83,9 @@ impl Executor {
} else if matches!(kind, b"docview" | b"outline" | b"pageresources" | b"names") {
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
if kind == b"docview" {
navigation.merge_catalog(operands, position, self.limits.tokens)
navigation.merge_catalog(operands, position, text.expect("catalog text state"), self.limits.tokens)
} else if kind == b"outline" {
navigation.add_outline(operands, position, (position.page, graphics_step, 1), self.limits.tokens)
navigation.add_outline(operands, position, (position.page, graphics_step, 1), text.expect("outline text state"), self.limits.tokens)
} else if kind == b"names" {
navigation.add_names(operands, position, (position.page, graphics_step, 1), self.limits.tokens)
} else {
@@ -231,9 +232,20 @@ impl Executor {
}
}
}
if let Some(operands) = body.and_then(|body| xdv_operand(body, b"tounicode")) {
let from = self.source_name(special.span);
self.reads.insert(Dependency::PdfCatalogState);
let warnings = self.xdv_text.apply(operands, &from, files);
self.check_cancellation()?;
for warning in warnings {
files.observe_diagnostic(WriteDestination::TerminalAndLog, &warning)
.map_err(|error| self.error(error, special.span))?;
}
return Ok(None);
}
if let Some(dictionary) = body.and_then(|body| xdv_operand(body, b"docinfo")) {
use crate::pdf_device::xdv_document::merge_docinfo;
let (entries, warnings) = merge_docinfo(&self.state.pdf_info, dictionary)
let (entries, warnings) = merge_docinfo(&self.state.pdf_info, dictionary, &self.xdv_text)
.map_err(|error| self.error(error, special.span))?;
if entries.len() > self.limits.tokens {
return self.fail("native PDF information payload limit exceeded");