Honor PDF draft mode in native execution and publication
This commit is contained in:
1 parent
af19a26c23
commit
f14669ae39
13 files changed
+206
-30
No files matched your search
@@ -270,11 +270,38 @@ impl Executor {
|
||||
.map_err(|e| self.error(e, self.current))?;
|
||||
self.events.push(Event::Message { text, span: self.current });
|
||||
}
|
||||
let options = PdfHeaderOptions { major, minor: minor as u8, object_compression };
|
||||
let draft_mode = if self.state.input_profile() == InputProfile::TeX8Bit {
|
||||
let mode = self.read_parameter(Parameter::Pdfdraftmode).width();
|
||||
if !(0..=1).contains(&mode) {
|
||||
return self.fail("\\pdfdraftmode can only be changed before anything is written to the output");
|
||||
}
|
||||
mode == 1
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if draft_mode {
|
||||
object_compression = 0;
|
||||
self.state.disable_draft_stream_compression();
|
||||
}
|
||||
let options = PdfHeaderOptions { major, minor: minor as u8, object_compression, draft_mode };
|
||||
self.state.pdf_header_options = Some(options);
|
||||
Ok(options)
|
||||
}
|
||||
|
||||
pub(super) fn prepare_pdf_draft_shipout(&mut self) -> Result<(), Error> {
|
||||
if self.state.input_profile() == InputProfile::TeX8Bit
|
||||
&& let Some(header) = self.state.pdf_header_options
|
||||
{
|
||||
if self.read_parameter(Parameter::Pdfdraftmode).width() != i32::from(header.draft_mode) {
|
||||
return self.fail("\\pdfdraftmode can only be changed before anything is written to the output");
|
||||
}
|
||||
if header.draft_mode {
|
||||
self.state.disable_draft_stream_compression();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn pdf_page_data(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
@@ -307,7 +334,9 @@ impl Executor {
|
||||
pk_resolution: pk_resolution.clamp(72, 8000) as u32,
|
||||
});
|
||||
}
|
||||
let level = self.read_parameter(Parameter::Pdfcompresslevel).width();
|
||||
let level = if header.draft_mode { 0 } else {
|
||||
self.read_parameter(Parameter::Pdfcompresslevel).width()
|
||||
};
|
||||
if level > 9 {
|
||||
return self.fail("invalid native PDF compression level");
|
||||
}
|
||||
|
||||
@@ -323,6 +323,7 @@ impl Executor {
|
||||
}
|
||||
let job_magnification = self.prepare_magnification()?;
|
||||
let magnification = if for_form { 1000 } else { job_magnification };
|
||||
self.prepare_pdf_draft_shipout()?;
|
||||
let pdf = self.pdf_page_data(files)?;
|
||||
let unicode_pages = self.state.input_profile() != InputProfile::TeX8Bit;
|
||||
// The XDV driver uses a physical sheet and origin, then applies
|
||||
|
||||
@@ -513,6 +513,9 @@ impl Executor {
|
||||
let Some(tokens) = registered.attributes.take() else {
|
||||
return Ok(());
|
||||
};
|
||||
if self.state.pdf_draft_mode() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut image = registered.image.clone();
|
||||
if image.image.has_imported_fonts() {
|
||||
let from = self.source_name(self.current);
|
||||
|
||||
@@ -14,9 +14,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 89;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 56] = [
|
||||
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, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, SCHEMA,
|
||||
const SCHEMA: u32 = 90;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 57] = [
|
||||
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, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -191,6 +191,9 @@ impl FormatImage {
|
||||
Parameter::Pdfoptionalwaysusepdfpagebox,
|
||||
]);
|
||||
}
|
||||
if image.schema < 90 {
|
||||
image.state.restore_legacy_pdf_parameters(&[Parameter::Pdfdraftmode]);
|
||||
}
|
||||
let pdf_objects = image.state.pdf_objects.as_deref();
|
||||
let mut numbered_images = 0;
|
||||
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||
|
||||
@@ -758,11 +758,13 @@ impl Execution {
|
||||
})?);
|
||||
}
|
||||
}
|
||||
self.resolve_page_graphics_resources(&mut pages)?;
|
||||
for form in &mut forms {
|
||||
let attributes = std::mem::take(&mut form.list.pdf_resources.attributes);
|
||||
self.resolve_page_graphics_resources(std::slice::from_mut(&mut form.list))?;
|
||||
form.list.pdf_resources.attributes = attributes;
|
||||
if !self.state.pdf_draft_mode() {
|
||||
self.resolve_page_graphics_resources(&mut pages)?;
|
||||
for form in &mut forms {
|
||||
let attributes = std::mem::take(&mut form.list.pdf_resources.attributes);
|
||||
self.resolve_page_graphics_resources(std::slice::from_mut(&mut form.list))?;
|
||||
form.list.pdf_resources.attributes = attributes;
|
||||
}
|
||||
}
|
||||
if let Some(first) = pages.first_mut() {
|
||||
first.forms = forms;
|
||||
|
||||
@@ -140,6 +140,7 @@ pub enum Parameter {
|
||||
XeTeXlinebreakskip,
|
||||
XeTeXlinebreakpenalty,
|
||||
XeTeXinputnormalization,
|
||||
Pdfdraftmode,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ParameterValue {
|
||||
@@ -155,6 +156,7 @@ impl Parameter {
|
||||
| Self::Pdfminorversion
|
||||
| Self::Pdfobjcompresslevel
|
||||
| Self::Pdfcompresslevel
|
||||
| Self::Pdfdraftmode
|
||||
| Self::Pdfdecimaldigits
|
||||
| Self::Pdfpkresolution
|
||||
| Self::Pdfimageresolution
|
||||
@@ -201,6 +203,7 @@ impl Parameter {
|
||||
Self::Pdfminorversion,
|
||||
Self::Pdfobjcompresslevel,
|
||||
Self::Pdfcompresslevel,
|
||||
Self::Pdfdraftmode,
|
||||
Self::Pdfdecimaldigits,
|
||||
Self::Pdfpkresolution,
|
||||
Self::Pdfimageresolution,
|
||||
|
||||
@@ -1400,6 +1400,13 @@ impl State {
|
||||
self.parameters.remove(&old);
|
||||
}
|
||||
|
||||
pub(super) fn disable_draft_stream_compression(&mut self) {
|
||||
// This is a device update to the current eqtb value. Existing save
|
||||
// entries still restore the enclosing group's compression setting.
|
||||
self.parameters
|
||||
.insert(Parameter::Pdfcompresslevel, ParameterValue::Integer(0));
|
||||
}
|
||||
|
||||
/// Explicit host selection of the PDF driver (INITEX itself defaults to
|
||||
/// pdfoutput=0). The source can still assign the real parameter.
|
||||
pub fn with_pdf_output(mut self) -> Self {
|
||||
@@ -1746,6 +1753,11 @@ impl State {
|
||||
pub fn is_initex(&self) -> bool {
|
||||
self.initex
|
||||
}
|
||||
/// Whether this job has started PDF output in TeX's draft mode.
|
||||
pub fn pdf_draft_mode(&self) -> bool {
|
||||
self.pdf_header_options.is_some_and(|options| options.draft_mode)
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
|
||||
@@ -10,6 +10,8 @@ pub(crate) struct PdfHeaderOptions {
|
||||
pub major: i32,
|
||||
pub minor: u8,
|
||||
pub object_compression: u8,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub draft_mode: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -124,7 +124,9 @@ pub fn painted_text(items: &[texrra_tex_core::HorizontalItem]) -> String {
|
||||
}),
|
||||
MathItem::Rule { .. } => {}
|
||||
MathItem::Glyph { .. } => panic!("legacy font in native test material"),
|
||||
MathItem::PdfImage(_) => panic!("PDF image in a DVI fixture"),
|
||||
MathItem::PdfImage(_) | MathItem::PdfForm(_) => {
|
||||
panic!("PDF image or Form in a DVI fixture")
|
||||
}
|
||||
MathItem::OpenType(_) => panic!("OpenType paint in a classic DVI fixture"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user