Honor final pdfTeX font charset and document info omission
This commit is contained in:
1 parent
38c567623a
commit
de481fd762
8 files changed
+92
-26
No files matched your search
@@ -272,7 +272,9 @@ impl Executor {
|
||||
}
|
||||
if !self.pdf_info_tokens.is_empty() {
|
||||
let tokens = std::mem::take(&mut self.pdf_info_tokens);
|
||||
self.state.pdf_info = self.pdf_token_bytes(&tokens)?;
|
||||
if self.read_parameter(Parameter::Pdfomitinfodict).width() == 0 {
|
||||
self.state.pdf_info = self.pdf_token_bytes(&tokens)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 78;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 45] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, SCHEMA,
|
||||
const SCHEMA: u32 = 79;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 46] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -136,6 +136,9 @@ impl FormatImage {
|
||||
if image.schema < 58 {
|
||||
image.state.restore_legacy_mathcodes()?;
|
||||
}
|
||||
if image.schema < 79 {
|
||||
image.state.restore_legacy_pdf_omission_parameters();
|
||||
}
|
||||
image.schema = SCHEMA;
|
||||
Ok(image)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ pub enum Parameter {
|
||||
Pdfgentounicode,
|
||||
Pdfsuppresswarningdupmap,
|
||||
Pdfinfoomitdate,
|
||||
Pdfomitcharset,
|
||||
Pdfomitinfodict,
|
||||
Tracingcommands,
|
||||
Tracingrestores,
|
||||
Tracingassigns,
|
||||
@@ -154,6 +156,8 @@ impl Parameter {
|
||||
| Self::Pdfgentounicode
|
||||
| Self::Pdfsuppresswarningdupmap
|
||||
| Self::Pdfinfoomitdate
|
||||
| Self::Pdfomitcharset
|
||||
| Self::Pdfomitinfodict
|
||||
| Self::Pdfhorigin
|
||||
| Self::Pdfvorigin
|
||||
| Self::Pdflinkmargin
|
||||
@@ -192,6 +196,8 @@ impl Parameter {
|
||||
Self::Pdfgentounicode,
|
||||
Self::Pdfsuppresswarningdupmap,
|
||||
Self::Pdfinfoomitdate,
|
||||
Self::Pdfomitcharset,
|
||||
Self::Pdfomitinfodict,
|
||||
Self::Tracingcommands,
|
||||
Self::Tracingrestores,
|
||||
Self::Tracingassigns,
|
||||
|
||||
@@ -1676,15 +1676,26 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn restore_legacy_pdf_omission_parameters(&mut self) {
|
||||
if self.input_profile != super::InputProfile::XeTeX {
|
||||
for parameter in [Parameter::Pdfomitcharset, Parameter::Pdfomitinfodict] {
|
||||
self.commands
|
||||
.entry(CommandName::Control(parameter.name()))
|
||||
.or_insert(Meaning::Parameter(parameter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_initex(&self) -> bool {
|
||||
self.initex
|
||||
}
|
||||
/// Final font output uses the live table and parameters, not the values
|
||||
/// captured at a page's shipout. The table is global and survives a dump.
|
||||
/// Final PDF output uses the live state after the last page ships out.
|
||||
pub fn pdf_final_options(&self) -> crate::pdf_unicode::PdfFinalOptions<'_> {
|
||||
crate::pdf_unicode::PdfFinalOptions {
|
||||
compression: self.parameter(Parameter::Pdfcompresslevel).width(),
|
||||
generate_unicode: self.parameter(Parameter::Pdfgentounicode).width(),
|
||||
omit_charset: self.parameter(Parameter::Pdfomitcharset).width() != 0,
|
||||
omit_info: self.parameter(Parameter::Pdfomitinfodict).width() != 0,
|
||||
glyph_unicode: &self.glyph_unicode,
|
||||
fonts: &self.fonts,
|
||||
page_tree_attributes: &self.pdf_pages_attributes,
|
||||
|
||||
@@ -1507,7 +1507,7 @@ fn native_pdf(
|
||||
let (catalog, info) = if raw_objects.is_some() {
|
||||
(
|
||||
unicode.and_then(|options| options.catalog).map(|catalog| catalog.entries.as_slice()),
|
||||
unicode.map(|options| options.info.entries),
|
||||
unicode.filter(|options| !options.omit_info).map(|options| options.info.entries),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
@@ -2176,7 +2176,8 @@ fn write_pdf(
|
||||
type1_plans.paint(key, program, owner_paint.subset,
|
||||
|| native_type1_parameters(program, owner_paint, owner.metrics()), glyphs);
|
||||
}
|
||||
let type1_references = type1_plans.write(&mut objects, compression)?;
|
||||
let omit_charset = unicode.is_some_and(|options| options.omit_charset);
|
||||
let type1_references = type1_plans.write(&mut objects, compression, omit_charset)?;
|
||||
|
||||
let mut native_font_ids = BTreeMap::new();
|
||||
for (&id, (face, paint, used)) in &native_used {
|
||||
@@ -2936,25 +2937,30 @@ fn write_pdf(
|
||||
|
||||
if let Some(level) = final_compression {
|
||||
let device = pages[0].pdf.as_ref().expect("validated native PDF options");
|
||||
let info = match unicode {
|
||||
Some(options) => {
|
||||
let info = crate::pdf_device::PdfInfo {
|
||||
entries: remapped.as_ref().and_then(|resources| resources.info.as_deref())
|
||||
.unwrap_or(options.info.entries),
|
||||
date: options.info.date,
|
||||
};
|
||||
if device.driver == crate::pdf_device::PdfDriver::Xdv {
|
||||
crate::pdf_device::xdv_document::information_dictionary(info, diagnostics)?
|
||||
} else {
|
||||
native_information_dictionary(info)
|
||||
let info = if unicode.is_some_and(|options| options.omit_info) {
|
||||
None
|
||||
} else {
|
||||
let dictionary = match unicode {
|
||||
Some(options) => {
|
||||
let info = crate::pdf_device::PdfInfo {
|
||||
entries: remapped.as_ref().and_then(|resources| resources.info.as_deref())
|
||||
.unwrap_or(options.info.entries),
|
||||
date: options.info.date,
|
||||
};
|
||||
if device.driver == crate::pdf_device::PdfDriver::Xdv {
|
||||
crate::pdf_device::xdv_document::information_dictionary(info, diagnostics)?
|
||||
} else {
|
||||
native_information_dictionary(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => metadata_object(metadata)
|
||||
.map(String::into_bytes)
|
||||
.unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()),
|
||||
None => metadata_object(metadata)
|
||||
.map(String::into_bytes)
|
||||
.unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()),
|
||||
};
|
||||
objects.push(dictionary);
|
||||
Some(objects.len())
|
||||
};
|
||||
objects.push(info);
|
||||
return Ok(objects::serialize(&objects, Some(objects.len()), &device.file, level.max(0).min(9) as u8));
|
||||
return Ok(objects::serialize(&objects, info, &device.file, level.clamp(0, 9) as u8));
|
||||
}
|
||||
|
||||
let info_ref = match metadata_object(metadata) {
|
||||
|
||||
@@ -83,6 +83,7 @@ impl<'a> FontPlans<'a> {
|
||||
self,
|
||||
objects: &mut Vec<Vec<u8>>,
|
||||
compression: u8,
|
||||
omit_charset: bool,
|
||||
) -> Result<References<'a>, String> {
|
||||
let mut plans: Vec<_> = self.0.into_iter().collect();
|
||||
plans.sort_unstable_by(|((a, at), _), ((b, bt), _)| {
|
||||
@@ -109,7 +110,7 @@ impl<'a> FontPlans<'a> {
|
||||
objects,
|
||||
&subset.name,
|
||||
&plan.parameters,
|
||||
Some(&subset.glyphs),
|
||||
(!omit_charset).then_some(&subset.glyphs),
|
||||
&subset.program,
|
||||
lengths,
|
||||
compression,
|
||||
|
||||
@@ -129,6 +129,8 @@ pub use crate::pdf::opentype_unicode::XdvGlyphNames;
|
||||
pub struct PdfFinalOptions<'a> {
|
||||
pub compression: i32,
|
||||
pub generate_unicode: i32,
|
||||
pub(crate) omit_charset: bool,
|
||||
pub(crate) omit_info: bool,
|
||||
pub glyph_unicode: &'a GlyphUnicodeMap,
|
||||
pub fonts: &'a crate::execution::FontCatalog,
|
||||
pub page_tree_attributes: &'a [u8],
|
||||
|
||||
Reference in new issue
Block a user