Reuse XeTeX suffixes across physical line edits
This commit is contained in:
1 parent
0b4aa49a71
commit
bf42a88dff
5 files changed
+337
-73
No files matched your search
+41
-13
@@ -15,7 +15,7 @@ use std::{
|
||||
use texrra_engine::native::*;
|
||||
use texrra_tex_core::{
|
||||
artifacts::file_version,
|
||||
execution::{Cancellation, JobTime},
|
||||
execution::{Cancellation, InputProfile, JobTime},
|
||||
resources::{FileWorld, GeneratedLookupOrigin, ResourceKind, SearchPath, WorldConfig},
|
||||
};
|
||||
const HEADER: &str = r"\catcode123=1\catcode125=2\catcode35=6\font\f=cmr10\f ";
|
||||
@@ -444,6 +444,10 @@ fn paragraph_search_reuse_keeps_current_paint_sources_writes_and_layout() {
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
fn atomic_definition(p: &Path, revision: u64, body: &str) -> ProjectDefinition {
|
||||
atomic_definition_with_source(p, revision, format!("{HEADER}{body}").into_bytes())
|
||||
}
|
||||
|
||||
fn atomic_definition_with_source(p: &Path, revision: u64, source: Vec<u8>) -> ProjectDefinition {
|
||||
let mut configuration = request(p).world;
|
||||
let map = match &configuration.paths[&ResourceKind::Map][0] {
|
||||
SearchPath::Directory { path, .. } => path.join("pdftex.map"),
|
||||
@@ -451,10 +455,7 @@ fn atomic_definition(p: &Path, revision: u64, body: &str) -> ProjectDefinition {
|
||||
};
|
||||
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let mut files = std::collections::BTreeMap::new();
|
||||
files.insert(
|
||||
p.join("main.tex"),
|
||||
Arc::from(format!("{HEADER}{body}").into_bytes()),
|
||||
);
|
||||
files.insert(p.join("main.tex"), Arc::from(source));
|
||||
for font in ["cmr10", "cmr7"] {
|
||||
for (relative, actual) in [
|
||||
(
|
||||
@@ -1919,17 +1920,36 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
|
||||
#[test]
|
||||
fn whole_line_edits_reuse_the_settled_suffix_and_relocate_provenance() {
|
||||
check_whole_line_suffix_edits("whole-line-safe-suffix", false);
|
||||
check_whole_line_suffix_edits("whole-line-safe-suffix", InputProfile::TeX8Bit, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_utf16_whole_line_edits_reuse_and_relocate_the_settled_suffix() {
|
||||
check_whole_line_suffix_edits("whole-line-utf16-suffix", InputProfile::XeTeX, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whole_line_edits_reexecute_a_delayed_input_line_read_on_the_same_source() {
|
||||
check_whole_line_suffix_edits("whole-line-delayed-inputlineno", true);
|
||||
check_whole_line_suffix_edits("whole-line-delayed-inputlineno", InputProfile::TeX8Bit, true);
|
||||
}
|
||||
|
||||
fn check_whole_line_suffix_edits(label: &str, observe_delayed_line: bool) {
|
||||
fn check_whole_line_suffix_edits(label: &str, profile: InputProfile, observe_delayed_line: bool) {
|
||||
let cwd = directory(label);
|
||||
let entry = cwd.join("main.tex");
|
||||
let encode = |source: &str| -> Vec<u8> {
|
||||
if profile == InputProfile::XeTeX {
|
||||
let physical_lines = source.replace('\n', "\r\n");
|
||||
[0xff, 0xfe]
|
||||
.into_iter()
|
||||
.chain(physical_lines.encode_utf16().flat_map(u16::to_le_bytes))
|
||||
.collect()
|
||||
} else {
|
||||
source.as_bytes().to_vec()
|
||||
}
|
||||
};
|
||||
let byte_offset = |source: &str, marker: &str| {
|
||||
encode(&source[..source.find(marker).unwrap()]).len()
|
||||
};
|
||||
let delayed = if observe_delayed_line {
|
||||
r"\write16{Suffix line \number\inputlineno}"
|
||||
} else {
|
||||
@@ -1955,14 +1975,22 @@ fn check_whole_line_suffix_edits(label: &str, observe_delayed_line: bool) {
|
||||
.unwrap()
|
||||
+ 1
|
||||
};
|
||||
let comment = "% Inserted physical line\n";
|
||||
let comment = if profile == InputProfile::XeTeX {
|
||||
// U+010A contains an LF byte in UTF-16 LE without ending the line.
|
||||
"% Inserted physical line \u{010a}\n"
|
||||
} else {
|
||||
"% Inserted physical line\n"
|
||||
};
|
||||
for (seed, edited) in [("", comment), (comment, "")] {
|
||||
// Give each direction one donor, so the deletion cannot reuse a
|
||||
// completed revision that already contained the shorter source.
|
||||
let original = body(seed);
|
||||
let project = ProjectSnapshot::new(atomic_definition(&cwd, 1, &original)).unwrap();
|
||||
let original_source = encode(&format!("{HEADER}{original}"));
|
||||
let project =
|
||||
ProjectSnapshot::new(atomic_definition_with_source(&cwd, 1, original_source)).unwrap();
|
||||
let mut input = request(&cwd).observe_generated_initial();
|
||||
input.world = project.configuration();
|
||||
input.input_profile = profile;
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let donor = session
|
||||
.compile(input.clone().with_project(project.clone()))
|
||||
@@ -1982,10 +2010,10 @@ fn check_whole_line_suffix_edits(label: &str, observe_delayed_line: bool) {
|
||||
}
|
||||
);
|
||||
let source = format!("{HEADER}{changed}");
|
||||
let prefix_read_end = source.find(r"\shipout\hbox{Cover}").unwrap();
|
||||
let glyph_offset = source.find("Suffix glyphs").unwrap();
|
||||
let prefix_read_end = byte_offset(&source, r"\shipout\hbox{Cover}");
|
||||
let glyph_offset = byte_offset(&source, "Suffix glyphs");
|
||||
let project = project
|
||||
.with_file_edits(2, [(entry.clone(), Arc::from(source.into_bytes()))].into())
|
||||
.with_file_edits(2, [(entry.clone(), Arc::from(encode(&source)))].into())
|
||||
.unwrap();
|
||||
let input = input.with_project(project);
|
||||
let updated = session.compile(input.clone()).unwrap();
|
||||
|
||||
Reference in new issue
Block a user