Prepare EPS graphics and BibTeX references for desktop previews

This commit is contained in:
gloamxun committed 2026-12-02 10:41:10 +08:00
1 parent 715ad81bcf
commit b38e39416e
8 files changed
+787 -7

No files matched your search

+47 -1
View File
@@ -25,6 +25,8 @@ use texrra_tex_core::{
use thread_usage::ThreadUsage;
use tiny_http::{Header, Method, Request, Response, Server};
mod bibliography;
mod figure_conversion;
mod library;
mod preview_socket;
#[path = "../../src/projects.rs"]
@@ -674,6 +676,7 @@ impl EditorSession {
entry,
editable,
options,
bibliography,
..
} = &mut self.editor;
if edit.sequence <= self.queue.current.load(Ordering::Acquire) {
@@ -699,6 +702,11 @@ impl EditorSession {
{
return Err("The entry file was edited twice".into());
}
if let Some(plan) = bibliography
&& let Some(contents) = plan.update(project, &updates)?
{
updates.insert(plan.output().to_owned(), Some(contents));
}
project.with_file_changes(edit.sequence, updates)
});
*project = match next {
@@ -759,6 +767,7 @@ struct EditorProject {
editable: BTreeMap<String, PathBuf>,
declared: BTreeSet<PathBuf>,
options: CompileRequest,
bibliography: Option<bibliography::Plan>,
}
fn copy_with_date(
@@ -869,6 +878,27 @@ fn prepare(
files.insert(logical, Arc::from(data));
}
}
let figures = additional.iter().filter_map(|relative| {
let input = run.join(relative);
let data = files.get(&input)?;
let converted = run.join(figure_conversion::converted_relative_path(relative, data)?);
if files.contains_key(&converted) {
return None;
}
let date = dates.get(&input).and_then(|time| time.to_system_time());
Some((converted, data.clone(), date))
}).collect::<Vec<_>>();
for (path, source, date) in figures {
match figure_conversion::convert(run, &source) {
Ok(Some(pdf)) => {
let modified = date.unwrap_or_else(SystemTime::now);
copy_with_date(&path, &pdf, Some(modified), &mut dates)?;
files.insert(path, Arc::from(pdf));
}
Ok(None) => {}
Err(error) => eprintln!("Editor EPS conversion for {}: {error}", path.display()),
}
}
let mut output = entry.with_extension("pdf");
if declared.contains(&output) || declared.contains(&output.with_extension("log")) {
let directory = run.join(".texrra-output");
@@ -884,7 +914,22 @@ fn prepare(
request = request.observe_generated_initial();
// Provision the finite, immutable resource bundle used by this trial.
// The seed uses the same native compiler and actual package bytes.
let seed = NativeCompiler::default().compile_detailed(request.clone());
let compiler = NativeCompiler::default();
let mut seed = compiler.compile_detailed(request.clone());
let mut bibliography = None;
if let Ok(initial) = &seed {
match bibliography::from_seed(&request, &initial.resources.generated_artifacts, &files) {
Ok(Some((plan, contents))) => {
let path = plan.output().to_owned();
copy_with_date(&path, &contents, Some(SystemTime::now()), &mut dates)?;
files.insert(path, contents);
bibliography = Some(plan);
seed = compiler.compile_detailed(request.clone());
}
Ok(None) => {}
Err(error) => eprintln!("Editor bibliography: {error}"),
}
}
let (inputs, trace, generated) = match &seed {
Ok(seed) => (
Some(seed.inputs.as_ref()),
@@ -969,6 +1014,7 @@ fn prepare(
editable,
declared,
options: request,
bibliography,
})
}