Deliver direct SVG drafts before native PDF export
This commit is contained in:
1 parent
37a42c82c8
commit
a72768bdb3
3 files changed
+127
-57
No files matched your search
+83
-35
@@ -140,9 +140,15 @@ pub trait CompileObserver: Send + Sync {
|
||||
_timings: SuffixKernelTimings,
|
||||
) {}
|
||||
|
||||
/// Called for a completed native draft before its staged files are synced
|
||||
/// and installed. The caller can display these pages provisionally. The
|
||||
/// compile result determines whether this revision actually published.
|
||||
/// Allow an SVG-only draft before export when the resolved pages do
|
||||
/// not need the exported PDF to render.
|
||||
fn preview_before_export(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Called once per compile attempt for a draft before publication. Observers
|
||||
/// can receive SVG-only drafts before PDF export. The compile result
|
||||
/// determines whether this revision actually published.
|
||||
fn draft_ready(&self, _draft: DraftPreview<'_>) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -150,27 +156,32 @@ pub trait CompileObserver: Send + Sync {
|
||||
|
||||
/// The same revision's native preview, available before artifact publication.
|
||||
pub struct DraftPreview<'a> {
|
||||
document: &'a CompiledDocument,
|
||||
revision: u64,
|
||||
pages: &'a [DisplayList],
|
||||
preview: &'a PreviewState,
|
||||
pdf: Option<&'a Arc<[u8]>>,
|
||||
steps: usize,
|
||||
work: &'a EntryCheckpointWork,
|
||||
cancellation: &'a Cancellation,
|
||||
}
|
||||
|
||||
impl DraftPreview<'_> {
|
||||
pub fn preview_since(&self, visible_revision: Option<u64>) -> Result<PreviewUpdate, String> {
|
||||
self.document.preview.render(
|
||||
self.document.revision(),
|
||||
&self.document.pages,
|
||||
self.document.pdf.as_ref(),
|
||||
self.preview.render(
|
||||
self.revision,
|
||||
self.pages,
|
||||
self.pdf,
|
||||
visible_revision,
|
||||
|| check(self.cancellation).map_err(|error| error.to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn execution_steps(&self) -> usize {
|
||||
self.document.execution.execution.steps
|
||||
self.steps
|
||||
}
|
||||
|
||||
pub fn entry_checkpoint_work(&self) -> &EntryCheckpointWork {
|
||||
&self.document.entry_checkpoint_work
|
||||
self.work
|
||||
}
|
||||
}
|
||||
fn notify(
|
||||
@@ -309,6 +320,10 @@ pub enum FormatPreparation {
|
||||
Reused,
|
||||
}
|
||||
impl CompiledDocument {
|
||||
fn preview_base(&self) -> (u64, &[DisplayList], &PreviewState) {
|
||||
(self.revision(), &self.pages, &self.preview)
|
||||
}
|
||||
|
||||
pub fn revision(&self) -> u64 {
|
||||
self.execution.revision
|
||||
}
|
||||
@@ -973,8 +988,8 @@ fn prepare_checked(
|
||||
check(cancellation)?;
|
||||
Ok((path, source, executor, output, format_preparation))
|
||||
})();
|
||||
evidence.world(&world);
|
||||
let (path, source, executor, output, format_preparation) = prepared?;
|
||||
let (path, source, executor, output, format_preparation) =
|
||||
prepared.inspect_err(|_| evidence.world(&world))?;
|
||||
let files = Files::new_with_terminal(
|
||||
&path,
|
||||
&output,
|
||||
@@ -1291,7 +1306,7 @@ impl CompileJob {
|
||||
files.write_layout_manifest(path, e, &pages, &source_map)?;
|
||||
}
|
||||
evidence.phase = AttemptPhase::Fonts;
|
||||
let preview_fonts = if draft_mode {
|
||||
let mut preview_fonts = if draft_mode {
|
||||
PreviewFonts::default()
|
||||
} else {
|
||||
let mut forms = pages.first_mut().map(|first| std::mem::take(&mut first.forms))
|
||||
@@ -1353,6 +1368,37 @@ impl CompileJob {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Direct SVG uses the resolved, final page lists. PDF-dependent
|
||||
// pages need the exported bytes and use the later draft boundary.
|
||||
let draft_observer = checkpoints.and(request.observer.as_ref());
|
||||
let early_preview = if let Some(observer) = draft_observer.filter(|observer| {
|
||||
observer.preview_before_export() && request.target == Target::Shipouts
|
||||
&& !dvi_mode && !draft_mode && !pages.is_empty()
|
||||
&& !pages.iter().any(DisplayList::has_embedded_pdf)
|
||||
}) {
|
||||
let previous = self.compiler.latest();
|
||||
let preview = PreviewState::new(
|
||||
&pages,
|
||||
previous.as_deref().map(CompiledDocument::preview_base),
|
||||
false,
|
||||
std::mem::take(&mut preview_fonts),
|
||||
);
|
||||
check(&cancellation)?;
|
||||
let observed = observer.draft_ready(DraftPreview {
|
||||
revision,
|
||||
pages: &pages,
|
||||
preview: &preview,
|
||||
pdf: None,
|
||||
steps: e.steps,
|
||||
work: &entry_checkpoint_work,
|
||||
cancellation: &cancellation,
|
||||
});
|
||||
check(&cancellation)?;
|
||||
observed?;
|
||||
Some(preview)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut dvi = None;
|
||||
let (pdf, export_diagnostics) = if pages.is_empty() {
|
||||
(None, Vec::new())
|
||||
@@ -1415,25 +1461,22 @@ impl CompileJob {
|
||||
})
|
||||
.transpose()?;
|
||||
let receipt = prepared.as_ref().map(|p| p.version(&output)).transpose()?;
|
||||
let previous = self.compiler.latest();
|
||||
// Identical PDF output allows direct reuse. When it differs,
|
||||
// PDF previews validate the new page and its reachable objects.
|
||||
let pdf_unchanged = pdf.is_some() && pages.iter().any(DisplayList::has_embedded_pdf)
|
||||
&& previous
|
||||
.as_deref()
|
||||
.is_some_and(|document| document.pdf.as_deref() == pdf.as_deref());
|
||||
let preview = PreviewState::new(
|
||||
&pages,
|
||||
previous.as_deref().map(|document| {
|
||||
(
|
||||
document.revision(),
|
||||
document.pages.as_slice(),
|
||||
&document.preview,
|
||||
)
|
||||
}),
|
||||
pdf_unchanged,
|
||||
preview_fonts,
|
||||
);
|
||||
let preview_sent_before_export = early_preview.is_some();
|
||||
let preview = early_preview.unwrap_or_else(|| {
|
||||
let previous = self.compiler.latest();
|
||||
// Identical PDF output allows direct reuse. When it differs,
|
||||
// PDF previews validate the new page and its reachable objects.
|
||||
let pdf_unchanged = pdf.is_some() && pages.iter().any(DisplayList::has_embedded_pdf)
|
||||
&& previous
|
||||
.as_deref()
|
||||
.is_some_and(|document| document.pdf.as_deref() == pdf.as_deref());
|
||||
PreviewState::new(
|
||||
&pages,
|
||||
previous.as_deref().map(CompiledDocument::preview_base),
|
||||
pdf_unchanged,
|
||||
preview_fonts,
|
||||
)
|
||||
});
|
||||
let result = Arc::new(CompiledDocument {
|
||||
format_preparation,
|
||||
entry_checkpoint_work,
|
||||
@@ -1461,11 +1504,16 @@ impl CompileJob {
|
||||
CompileStage::ReadyToPublish,
|
||||
&cancellation,
|
||||
)?;
|
||||
if checkpoints.is_some()
|
||||
&& let Some(observer) = &request.observer
|
||||
if !preview_sent_before_export
|
||||
&& let Some(observer) = draft_observer
|
||||
{
|
||||
let observed = observer.draft_ready(DraftPreview {
|
||||
document: &result,
|
||||
revision,
|
||||
pages: &result.pages,
|
||||
preview: &result.preview,
|
||||
pdf: result.pdf.as_ref(),
|
||||
steps: result.execution.execution.steps,
|
||||
work: &result.entry_checkpoint_work,
|
||||
cancellation: &cancellation,
|
||||
});
|
||||
check(&cancellation)?;
|
||||
|
||||
Reference in new issue
Block a user