Apply native PDF page dictionaries and viewport projection
This commit is contained in:
1 parent
a6ba70aa46
commit
d1ddf4bfeb
19 files changed
+410
-40
No files matched your search
@@ -29,6 +29,8 @@ pub struct NativeShipout {
|
||||
pub(super) pdf_text_spaces: Option<crate::pdf_device::text_spaces::SpaceSettings>,
|
||||
#[serde(default, skip_serializing_if = "pdf_resource_entries_empty")]
|
||||
pub(super) pdf_resource_entries: Arc<[u8]>,
|
||||
#[serde(default, skip_serializing_if = "pdf_resource_entries_empty")]
|
||||
pub(super) pdf_page_attributes: Arc<[u8]>,
|
||||
#[serde(default, skip_serializing_if = "crate::pdf_device::links::PageLinks::is_empty")]
|
||||
pub(super) pdf_links: crate::pdf_device::links::PageLinks,
|
||||
}
|
||||
@@ -48,6 +50,7 @@ impl NativeShipout {
|
||||
pdf_text_spaces: self.pdf_text_spaces.clone(),
|
||||
pdf_resources: crate::pdf_device::page_resources::PageResources {
|
||||
entries: self.pdf_resource_entries.clone(),
|
||||
attributes: self.pdf_page_attributes.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
use super::*;
|
||||
use crate::pdf_device::{PdfFileOptions, PdfPageData};
|
||||
impl Executor {
|
||||
pub(super) fn pdf_token_parameter_bytes(
|
||||
&mut self,
|
||||
parameter: TokenParameter,
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
self.reads.insert(Dependency::TokenParameter(parameter));
|
||||
match self.state.token_parameter(parameter).cloned() {
|
||||
Some(tokens) => self.pdf_token_bytes(&tokens),
|
||||
None => Ok(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn validate_pdf_final_state(&mut self) -> Result<(), Error> {
|
||||
if let Some(options) = self.state.pdf_file_options.clone() {
|
||||
self.reads.insert(Dependency::GlyphUnicode);
|
||||
self.read_parameter(Parameter::Pdfgentounicode);
|
||||
if self.shipped_pages != 0 {
|
||||
self.state.pdf_pages_attributes =
|
||||
self.pdf_token_parameter_bytes(TokenParameter::Pdfpagesattr)?;
|
||||
}
|
||||
self.reads.insert(Dependency::PdfFileState);
|
||||
let mode = self.read_parameter(Parameter::Pdfoutput).width();
|
||||
if self.state.output_mode_set != Some(mode) {
|
||||
|
||||
@@ -264,16 +264,13 @@ impl Executor {
|
||||
};
|
||||
self.trace_shipout(&b, files)?;
|
||||
let current = self.current;
|
||||
let pdf_resource_entries = if device.pdf.is_some() {
|
||||
let parameter = TokenParameter::Pdfpageresources;
|
||||
self.reads.insert(Dependency::TokenParameter(parameter));
|
||||
if let Some(tokens) = self.state.token_parameter(parameter).cloned() {
|
||||
self.pdf_token_bytes(&tokens)?.into()
|
||||
} else {
|
||||
Default::default()
|
||||
}
|
||||
let (pdf_resource_entries, pdf_page_attributes) = if device.pdf.is_some() {
|
||||
(
|
||||
self.pdf_token_parameter_bytes(TokenParameter::Pdfpageresources)?.into(),
|
||||
self.pdf_token_parameter_bytes(TokenParameter::Pdfpageattr)?.into(),
|
||||
)
|
||||
} else {
|
||||
Default::default()
|
||||
(Default::default(), Default::default())
|
||||
};
|
||||
let pdf_color_start = if device.pdf.is_some() {
|
||||
self.pdf_colors.start_page()
|
||||
@@ -426,6 +423,7 @@ impl Executor {
|
||||
pdf_graphics_steps,
|
||||
pdf_text_spaces,
|
||||
pdf_resource_entries,
|
||||
pdf_page_attributes,
|
||||
pdf_links,
|
||||
})));
|
||||
self.statistics_after_shipout(before, files)?;
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 42;
|
||||
const SCHEMA: u32 = 43;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 12] = [27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, SCHEMA];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ pub enum TokenParameter {
|
||||
Errhelp,
|
||||
Everycr,
|
||||
Pdfpageresources,
|
||||
Pdfpageattr,
|
||||
Pdfpagesattr,
|
||||
}
|
||||
impl TokenParameter {
|
||||
pub const ALL: &'static [Self] = &[
|
||||
@@ -30,6 +32,8 @@ impl TokenParameter {
|
||||
Self::Errhelp,
|
||||
Self::Everycr,
|
||||
Self::Pdfpageresources,
|
||||
Self::Pdfpageattr,
|
||||
Self::Pdfpagesattr,
|
||||
];
|
||||
pub fn name(self) -> String {
|
||||
format!("{self:?}").to_ascii_lowercase()
|
||||
|
||||
@@ -700,13 +700,16 @@ impl Execution {
|
||||
let empty = PdfObjects::default();
|
||||
let objects = self.state.pdf_objects.as_deref().unwrap_or(&empty);
|
||||
let mut font_affects_paint = BTreeMap::new();
|
||||
for page in pages {
|
||||
for page in pages.iter_mut() {
|
||||
let states = page.items.iter().filter_map(|item| match item {
|
||||
DisplayItem::PdfColor(program) => Some(&program.graphics_states),
|
||||
_ => None,
|
||||
}).flatten().cloned().collect();
|
||||
page.pdf_resources = PageResources::from_page(
|
||||
page.pdf_resources.entries.clone(), &states, objects,
|
||||
page.pdf_resources.entries.clone(),
|
||||
page.pdf_resources.attributes.clone(),
|
||||
&states,
|
||||
objects,
|
||||
).map_err(|message| Error::at(
|
||||
&self.sources, self.state.input_profile(), message, Span::default(),
|
||||
))?;
|
||||
@@ -737,7 +740,10 @@ impl Execution {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
crate::pdf_device::page_attributes::resolve(pages, &self.state.pdf_pages_attributes, objects)
|
||||
.map_err(|message| Error::at(
|
||||
&self.sources, self.state.input_profile(), message, Span::default(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Export the paragraphs already measured during token execution. No text
|
||||
|
||||
@@ -646,6 +646,8 @@ pub struct State {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(super) pdf_objects: Option<Box<crate::pdf_device::page_resources::PdfObjects>>,
|
||||
pub(super) pdf_info: Vec<u8>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_pages_attributes: Vec<u8>,
|
||||
pub(super) glyph_unicode: crate::pdf_unicode::GlyphUnicodeMap,
|
||||
pub(super) hyphenation: super::hyphenation::HyphenationData,
|
||||
}
|
||||
@@ -751,6 +753,7 @@ impl Default for State {
|
||||
initial_random_seed: None,
|
||||
random: None,
|
||||
pdf_info: Vec::new(),
|
||||
pdf_pages_attributes: Vec::new(),
|
||||
glyph_unicode: crate::pdf_unicode::GlyphUnicodeMap::default(),
|
||||
hyphenation: super::hyphenation::HyphenationData::default(),
|
||||
};
|
||||
@@ -1422,6 +1425,7 @@ impl State {
|
||||
self.pdf_objects = None;
|
||||
}
|
||||
self.pdf_info.clear();
|
||||
self.pdf_pages_attributes.clear();
|
||||
self.fonts.pdf_settings.clear();
|
||||
self
|
||||
}
|
||||
@@ -1436,6 +1440,7 @@ impl State {
|
||||
generate_unicode: self.parameter(Parameter::Pdfgentounicode).width(),
|
||||
glyph_unicode: &self.glyph_unicode,
|
||||
fonts: &self.fonts,
|
||||
page_tree_attributes: &self.pdf_pages_attributes,
|
||||
catalog: self.pdf_catalog.as_deref(),
|
||||
objects: self.pdf_objects.as_deref(),
|
||||
info: crate::pdf_device::PdfInfo {
|
||||
|
||||
Reference in new issue
Block a user