Execute TECkit font mappings in native XeLaTeX jobs
This commit is contained in:
1 parent
752af43f32
commit
c548ca8e9f
12 files changed
+1098
-17
No files matched your search
@@ -568,6 +568,145 @@ fn unicode_math_code_edit_updates_the_page_that_reads_the_table() {
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_mapping_changes_recover_and_update_the_page_that_used_the_resource() {
|
||||
use std::io::Write;
|
||||
use texrra_tex_core::{execution::InputProfile, provenance::Derivation};
|
||||
|
||||
fn mapping(replacement: u32) -> Arc<[u8]> {
|
||||
// A TECkit forward table with one Unicode plane, one page, and one
|
||||
// two-character rule keyed by the ASCII hyphen.
|
||||
const PAGES: u32 = 48;
|
||||
const LOOKUP: u32 = PAGES + 256 + 512;
|
||||
const LIST: u32 = LOOKUP + 8;
|
||||
const RULE: u32 = LIST + 4;
|
||||
const END: u32 = RULE + 16;
|
||||
let mut bytes = b"qMap".to_vec();
|
||||
for word in [0x0002_0001u32, 36, 0x10000, 0x10000, 0, 1, 0, 36] {
|
||||
bytes.extend(word.to_be_bytes());
|
||||
}
|
||||
bytes.extend(b"U->U");
|
||||
for word in [0x20000, END, 0, PAGES, LOOKUP, LIST, LIST, LIST, RULE] {
|
||||
bytes.extend(word.to_be_bytes());
|
||||
}
|
||||
bytes.extend([2, 0, 0, 1]);
|
||||
bytes.extend(0xfffdu32.to_be_bytes());
|
||||
bytes.push(0);
|
||||
bytes.extend([255; 255]);
|
||||
let mut code_table = [0; 512];
|
||||
code_table[usize::from(b'-') * 2 + 1] = 1;
|
||||
bytes.extend(code_table);
|
||||
bytes.extend([0xfd, 0, 0, 0, 0xff, 1, 0, 0]);
|
||||
bytes.extend(0u32.to_be_bytes());
|
||||
bytes.extend([2, 0, 0, 1, 0x11, 0, 0, b'-', 0x11, 0, 0, b'-']);
|
||||
bytes.extend(replacement.to_be_bytes());
|
||||
|
||||
let mut compressed = b"zQmp".to_vec();
|
||||
compressed.extend((bytes.len() as u32).to_be_bytes());
|
||||
let mut encoder =
|
||||
flate2::write::ZlibEncoder::new(compressed, flate2::Compression::default());
|
||||
encoder.write_all(&bytes).unwrap();
|
||||
Arc::from(encoder.finish().unwrap())
|
||||
}
|
||||
|
||||
let p = directory("font-mapping");
|
||||
let mut request = request(&p);
|
||||
request.world = WorldConfig::new(&p);
|
||||
request.input_profile = InputProfile::XeTeX;
|
||||
let mapping_path = p.join("replace.tec");
|
||||
let padding = format!("{}\n", "\\relax ".repeat(26)).repeat(45);
|
||||
let source = format!(
|
||||
r#"\catcode123=1 \catcode125=2
|
||||
\shipout\hbox{{\vrule width7pt height8pt}}
|
||||
{padding}
|
||||
\font\mapped="[LiberationSerif-Regular.ttf]:mapping=replace;"
|
||||
\shipout\hbox{{\mapped --}}
|
||||
\shipout\hbox{{\vrule width9pt height8pt}}
|
||||
\end
|
||||
"#
|
||||
);
|
||||
let hyphens = source.find("--").unwrap();
|
||||
let project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: request.world.clone(),
|
||||
revision: 1,
|
||||
roots: [p.clone()].into(),
|
||||
files: [
|
||||
(p.join("main.tex"), Arc::from(source.into_bytes())),
|
||||
(
|
||||
p.join("LiberationSerif-Regular.ttf"),
|
||||
Arc::from(
|
||||
include_bytes!("../assets/fonts-subset/LiberationSerif-Regular.ttf").as_slice(),
|
||||
),
|
||||
),
|
||||
(mapping_path.clone(), mapping(b'A'.into())),
|
||||
]
|
||||
.into(),
|
||||
directories: Default::default(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [p.clone()].into(),
|
||||
generated: Default::default(),
|
||||
})
|
||||
.unwrap();
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let before = compiler
|
||||
.compile(request.clone().with_project(project.clone()))
|
||||
.unwrap();
|
||||
let broken = project
|
||||
.with_file_edits(
|
||||
2,
|
||||
[(mapping_path.clone(), Arc::from(b"zQmp".as_slice()))].into(),
|
||||
)
|
||||
.unwrap();
|
||||
let Err(error) = compiler.compile(request.clone().with_project(broken.clone())) else {
|
||||
panic!("a truncated font mapping must fail");
|
||||
};
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("invalid compiled TECkit font mapping")
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(p.join("job.pdf")).unwrap(),
|
||||
before.pdf.as_deref().unwrap()
|
||||
);
|
||||
|
||||
let edited = broken
|
||||
.with_file_edits(3, [(mapping_path, mapping(b'B'.into()))].into())
|
||||
.unwrap();
|
||||
let request = request.with_project(edited);
|
||||
let resumed = compiler.compile(request.clone()).unwrap();
|
||||
let full = NativeCompiler::default().compile(request).unwrap();
|
||||
assert!(resumed.entry_checkpoint_work.reused_steps > 0);
|
||||
assert_eq!(resumed.pdf, full.pdf);
|
||||
assert_ne!(resumed.pdf, before.pdf);
|
||||
assert_eq!(resumed.pages, full.pages);
|
||||
assert_eq!(resumed.source_map.pages, full.source_map.pages);
|
||||
let source = &resumed.source_map.pages[1].entries[0].source;
|
||||
assert_eq!(
|
||||
source
|
||||
.tokens
|
||||
.iter()
|
||||
.map(|token| token.span.start)
|
||||
.collect::<Vec<_>>(),
|
||||
[hyphens, hyphens + 1],
|
||||
);
|
||||
assert!(source.derivations.contains(&Derivation::FontMapping));
|
||||
let changed = resumed.preview_since(Some(before.revision())).unwrap();
|
||||
assert_eq!(
|
||||
changed
|
||||
.pages
|
||||
.iter()
|
||||
.map(|page| page.index)
|
||||
.collect::<Vec<_>>(),
|
||||
[1]
|
||||
);
|
||||
eprintln!(
|
||||
"TECkit edit reused {} steps",
|
||||
resumed.entry_checkpoint_work.reused_steps
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkpoint_keeps_late_special_tokens_until_the_updated_page_is_shipped() {
|
||||
let p = directory("late-special");
|
||||
|
||||
Reference in new issue
Block a user