Handle PDF title edge cases

This commit is contained in:
Mirko Kerezovic
2026-10-23 01:01:26 +07:00
committed by bflatastic
parent d548b4ff74
commit 97c173beb9
3 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -872,7 +872,7 @@ pub fn file_stem(name: &str) -> String {
/// (the title PDF, PNG and SVG metadata carry). A title of its own stays, and native files keep
/// the stored title.
pub fn has_own_title(doc: &vectorcraft_doc::Document) -> bool {
!doc.title.strip_prefix("Untitled-").is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit()))
!doc.title.trim().is_empty() && !doc.title.strip_prefix("Untitled-").is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit()))
}
pub fn titled_for_export(doc: &vectorcraft_doc::Document, path: Option<&str>, format: &str) -> Option<vectorcraft_doc::Document> {
+2
View File
@@ -399,6 +399,8 @@ fn export_pdf(s: &mut Session, p: &Value) -> Result<Value> {
let mut q = p.clone();
if let Some(o) = q.as_object_mut() {
o.insert("_displayDocTitle".into(), json!(display_doc_title));
} else {
q = json!({ "_displayDocTitle": display_doc_title });
}
let (bytes, warnings) = encode(C, titled.as_ref().unwrap_or(&st.doc), &q)?;
write_or_return(str_param(p, "path"), &bytes, json!({ "warnings": warnings }))