Export native TeX shipouts as binary DVI

This commit is contained in:
gloamxun committed 2026-11-28 09:05:18 +08:00
1 parent 34325317d2
commit d9edc6c6e7
10 files changed
+459 -14

No files matched your search

+27 -1
View File
@@ -244,6 +244,8 @@ pub struct CompiledDocument {
pub export_diagnostics: Vec<String>,
/// Immutable bytes stay associated with this revision after another publish.
pub pdf: Option<Arc<[u8]>>,
/// The same revision’s bytes when TeX selected the DVI device.
pub dvi: Option<Arc<[u8]>>,
pub output: Option<ResourceVersion>,
preview: PreviewState,
}
@@ -1095,7 +1097,6 @@ impl CompileJob {
notify(&request, revision, CompileStage::Executed, &cancellation)?;
evidence.phase = AttemptPhase::Layout;
let e = &execution.execution;
let draft_mode = request.target == Target::Shipouts && e.state.pdf_draft_mode();
let (mut pages, paper_width, paper_height, origin) = if request.target
== Target::Shipouts
{
@@ -1119,6 +1120,17 @@ impl CompileJob {
},
)
};
let dvi_mode = request.target == Target::Shipouts
&& pages.first().is_some_and(|page| page.pdf.is_none());
if dvi_mode
&& output.extension().is_some_and(|extension| extension.eq_ignore_ascii_case("pdf"))
{
return Err(CompileError::Host(
"DVI mode requires a DVI output path, for example output.dvi".into(),
));
}
let draft_mode =
request.target == Target::Shipouts && !dvi_mode && e.state.pdf_draft_mode();
if let Some(path) = &request.layout_manifest {
let source_map = self.compiler.session.source_map(&execution, &pages)?;
files.write_layout_manifest(path, e, &pages, &source_map)?;
@@ -1147,6 +1159,12 @@ impl CompileJob {
reported?;
preview
}
Err(_) if dvi_mode => {
// A DVI driver resolves the requested outlines later.
// Unavailable preview fonts do not prevent DVI output.
reported?;
PreviewFonts::default()
}
Err(error) => {
if let Err(report) = reported {
evidence.gaps.push(report.to_string());
@@ -1174,10 +1192,16 @@ impl CompileJob {
} else {
None
};
let mut dvi = None;
let (pdf, export_diagnostics) = if pages.is_empty() {
(None, Vec::new())
} else if draft_mode {
(None, vec![r"\pdfdraftmode enabled, not changing output pdf".into()])
} else if dvi_mode {
let encoded = e.dvi_output(&cancellation);
check(&cancellation)?;
dvi = encoded?;
(None, Vec::new())
} else if request.target == Target::Shipouts {
let mut options = e.state.pdf_final_options();
options.xdv_glyph_names = xdv_glyph_names.as_ref();
@@ -1219,6 +1243,7 @@ impl CompileJob {
let inputs = files.input_snapshot();
let prepared = pdf
.as_ref()
.or(dvi.as_ref())
.map(|bytes| {
if checkpoints.is_some() {
PreparedOutput::write_for_draft(&output, bytes)
@@ -1260,6 +1285,7 @@ impl CompileJob {
host_runtime: files.runtime_observations(),
export_diagnostics,
pdf: pdf.map(Arc::from),
dvi: dvi.map(Arc::from),
output: receipt,
preview,
});