Read binary TeX inputs and render default ICC colors
This commit is contained in:
1 parent
e9893a5c1b
commit
52db77885d
10 files changed
+379
-19
No files matched your search
@@ -1192,6 +1192,53 @@ impl Executor {
|
||||
self.print_tokens(&value, token)?;
|
||||
}
|
||||
}
|
||||
Pdffiledump => {
|
||||
let offset = if self.keyword("offset", files)? {
|
||||
usize::try_from(self.integer(files)?)
|
||||
.map_err(|_| self.error("Bad file offset", token.span))?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let length = if self.keyword("length", files)? {
|
||||
usize::try_from(self.integer(files)?)
|
||||
.map_err(|_| self.error("Bad dump length", token.span))?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let body = self.scan_pdf_tokens(files)?;
|
||||
if length == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
if length > self.limits.tokens / 2 {
|
||||
return self.fail("native file dump token limit exceeded");
|
||||
}
|
||||
let name = self.token_list_text(&body);
|
||||
let mut name = self.decode_filename(name)?;
|
||||
if self.state.input_profile() != InputProfile::XeTeX {
|
||||
name.retain(|c| c != '"');
|
||||
}
|
||||
let from = self.source_name(token.span);
|
||||
self.reads.insert(Dependency::FileLookup {
|
||||
name: name.clone(),
|
||||
from: from.clone(),
|
||||
});
|
||||
if let Some(resource) = files.optional_tex_input(&name, &from)
|
||||
.map_err(|message| self.error(message, token.span))?
|
||||
&& let Some(tail) = resource.data.get(offset..)
|
||||
{
|
||||
const HEX: &[u8; 16] = b"0123456789ABCDEF";
|
||||
let bytes = &tail[..tail.len().min(length)];
|
||||
let mut output = std::string::String::with_capacity(bytes.len() * 2);
|
||||
for chunk in bytes.chunks(4096) {
|
||||
self.check_cancellation()?;
|
||||
for &byte in chunk {
|
||||
output.push(char::from(HEX[usize::from(byte >> 4)]));
|
||||
output.push(char::from(HEX[usize::from(byte & 15)]));
|
||||
}
|
||||
}
|
||||
self.print_tokens(&output, token)?;
|
||||
}
|
||||
}
|
||||
Pdfmdfivesum => {
|
||||
let file = self.keyword("file", files)?;
|
||||
let body = self.scan_pdf_tokens(files)?;
|
||||
|
||||
@@ -16,9 +16,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 109;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 75] = [
|
||||
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, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, SCHEMA,
|
||||
const SCHEMA: u32 = 110;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 76] = [
|
||||
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, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -241,6 +241,9 @@ impl FormatImage {
|
||||
if image.schema < 109 {
|
||||
image.state.install_nonscript_command();
|
||||
}
|
||||
if image.schema < 110 {
|
||||
image.state.install_filedump_command();
|
||||
}
|
||||
let pdf_objects = image.state.pdf_objects.as_deref();
|
||||
let mut numbered_images = 0;
|
||||
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||
|
||||
@@ -96,6 +96,7 @@ pub enum Primitive {
|
||||
Etexrevision,
|
||||
Pdffilesize,
|
||||
Pdffilemoddate,
|
||||
Pdffiledump,
|
||||
Pdfmdfivesum,
|
||||
Pdfxform,
|
||||
Pdfrefxform,
|
||||
@@ -527,6 +528,7 @@ impl Primitive {
|
||||
| Etexrevision
|
||||
| Pdffilesize
|
||||
| Pdffilemoddate
|
||||
| Pdffiledump
|
||||
| Pdfmdfivesum
|
||||
| Jobname
|
||||
| Pdfcreationdate
|
||||
@@ -954,6 +956,7 @@ const PDFTEX_ONLY_PRIMITIVES: &[(&str, Primitive)] = {
|
||||
("letterspacefont", Letterspacefont),
|
||||
("pdffilesize", Pdffilesize),
|
||||
("pdffilemoddate", Pdffilemoddate),
|
||||
("pdffiledump", Pdffiledump),
|
||||
("pdfmdfivesum", Pdfmdfivesum),
|
||||
("pdfxform", Pdfxform),
|
||||
("pdfrefxform", Pdfrefxform),
|
||||
@@ -1018,6 +1021,7 @@ const XETEX_PRIMITIVE_ALIASES: &[(&str, Primitive)] = {
|
||||
&[
|
||||
("creationdate", Pdfcreationdate),
|
||||
("filemoddate", Pdffilemoddate),
|
||||
("filedump", Pdffiledump),
|
||||
("filesize", Pdffilesize),
|
||||
("mdfivesum", Pdfmdfivesum),
|
||||
("normaldeviate", Pdfnormaldeviate),
|
||||
@@ -2045,6 +2049,15 @@ impl State {
|
||||
self.update_profile_command("pdfinsertht", Meaning::Primitive(Primitive::Pdfinsertht), enabled);
|
||||
}
|
||||
|
||||
pub(super) fn install_filedump_command(&mut self) {
|
||||
let name = if self.input_profile == super::InputProfile::XeTeX {
|
||||
"filedump"
|
||||
} else {
|
||||
"pdffiledump"
|
||||
};
|
||||
self.update_profile_command(name, Meaning::Primitive(Primitive::Pdffiledump), true);
|
||||
}
|
||||
|
||||
fn install_pdftex_primitives(&mut self) {
|
||||
let enabled = self.input_profile != super::InputProfile::XeTeX;
|
||||
for &(name, primitive) in PDFTEX_ONLY_PRIMITIVES {
|
||||
|
||||
Reference in new issue
Block a user