Deliver direct SVG drafts before native PDF export

This commit is contained in:
gloamxun committed 2026-12-02 04:19:06 +08:00
1 parent 37a42c82c8
commit a72768bdb3
3 files changed
+127 -57

No files matched your search

+27 -7
View File
@@ -2836,13 +2836,24 @@ fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts(
artifacts: [Vec<u8>; 3],
update: Mutex<Option<PreviewUpdate>>,
action: Action,
early: bool,
exported: Mutex<bool>,
}
impl CompileObserver for WatchDraft {
fn stage(&self, _: u64, _: CompileStage) -> Result<(), String> {
fn stage(&self, _: u64, stage: CompileStage) -> Result<(), String> {
if stage == CompileStage::Exported {
*self.exported.lock().unwrap() = true;
}
Ok(())
}
fn preview_before_export(&self) -> bool {
self.early
}
fn draft_ready(&self, draft: DraftPreview<'_>) -> Result<(), String> {
assert_eq!(*self.exported.lock().unwrap(), !self.early);
assert!(self.update.lock().unwrap().is_none());
assert!(Arc::ptr_eq(
&self.previous,
&self.compiler.latest().unwrap()
@@ -2904,12 +2915,15 @@ fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts(
)
.unwrap();
let mut request = request.with_project(changed);
let mut cancelled = None;
for action in [
Action::Supersede,
let mut cancelled: Option<PreviewUpdate> = None;
for (action, early) in [
(Action::Supersede, false),
(Action::Supersede, true),
#[cfg(unix)]
Action::Conflict,
Action::Publish,
(Action::Conflict, false),
#[cfg(unix)]
(Action::Conflict, true),
(Action::Publish, true),
] {
let observer = Arc::new(WatchDraft {
compiler: compiler.clone(),
@@ -2918,6 +2932,8 @@ fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts(
artifacts: artifacts.clone(),
update: Mutex::new(None),
action,
early,
exported: Mutex::new(false),
});
request.observer = Some(observer.clone());
let result = compiler.compile_detailed(request.clone());
@@ -2926,7 +2942,8 @@ fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts(
let failure = result.err().unwrap();
if matches!(action, Action::Supersede) {
assert!(matches!(failure.error, CompileError::Cancelled));
assert_eq!(failure.phase, AttemptPhase::ReadyToPublish);
let phase = if early { AttemptPhase::Export } else { AttemptPhase::ReadyToPublish };
assert_eq!(failure.phase, phase);
} else {
assert!(failure.error.to_string().contains("aliases"), "{failure:?}");
assert_eq!(failure.phase, AttemptPhase::Publishing);
@@ -2937,6 +2954,9 @@ fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts(
["job.pdf", "job.log", "state.dat"].map(|name| fs::read(p.join(name)).unwrap()),
artifacts,
);
if let Some(previous_draft) = &cancelled {
assert_eq!(update.pages, previous_draft.pages);
}
cancelled = Some(update);
} else {
let document = result.unwrap();