mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 02:03:02 +00:00
Merge pull request #8098 from el-j/feat/save-pdf-transparency-confirmation-8097
Fix #8097: Save PDF: show flattener rasterization resolutions in Summary warning and Advanced section
This commit is contained in:
@@ -417,9 +417,13 @@ fn encode_carrying_at(
|
||||
}
|
||||
let (flat, flattened) = flatten_for(cmd, doc, set, p)?;
|
||||
vectorcraft_doc::cancel::check()?;
|
||||
if flattened {
|
||||
if let Some(o) = flattened {
|
||||
let kind = if set.standard.flattens() { set.standard.label() } else { set.compatibility.label() };
|
||||
notes.push(Note::loss(format!("transparency is flattened into opaque art and images ({kind} files have none): see the flattener preset")));
|
||||
let line_ppi = o.line_art_ppi.round() as u32;
|
||||
let grad_ppi = o.gradient_ppi.round() as u32;
|
||||
notes.push(Note::loss(format!(
|
||||
"transparency is flattened into opaque art and images ({kind} files have none) at {line_ppi} ppi line art and text, {grad_ppi} ppi gradients and meshes: see the flattener preset"
|
||||
)));
|
||||
}
|
||||
let r = super::super::rasterfx::export_pdf_with_report(flat.as_ref().unwrap_or(doc), &opts).map_err(|e| pdf_error(cmd, e))?;
|
||||
notes.extend(r.warnings.into_iter().map(Note::loss));
|
||||
@@ -438,9 +442,9 @@ pub const DEFAULT_FLATTENER: &str = "High Resolution";
|
||||
/// discarded overprints are dropped. Layers the pages leave out (non-printing ones, unless asked
|
||||
/// for) are left out of the flattening, hidden. → the document to write (`None`: `doc` as it is)
|
||||
/// and whether its transparency was flattened.
|
||||
fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Result<(Option<Document>, bool)> {
|
||||
fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Result<(Option<Document>, Option<FlattenOptions>)> {
|
||||
if !set.pdf13() {
|
||||
return Ok((None, false));
|
||||
return Ok((None, None));
|
||||
}
|
||||
let printed = if set.include_non_printing || set.create_layers { None } else { without_non_printing(&doc.layers) };
|
||||
let shown = printed.map(|layers| {
|
||||
@@ -456,8 +460,8 @@ fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Resul
|
||||
// its art: it is clipped to its regions (opaque inside them).
|
||||
o.clip_complex_regions = true;
|
||||
Ok(match flatten_document(shown.as_ref().unwrap_or(doc), &o)? {
|
||||
Some(flat) => (Some(flat), true),
|
||||
None => (shown, false),
|
||||
Some(flat) => (Some(flat), Some(o)),
|
||||
None => (shown, None),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -761,7 +761,18 @@ fn advanced(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
}
|
||||
});
|
||||
});
|
||||
if !flat {
|
||||
if flat {
|
||||
let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER);
|
||||
let preset_opts = FlattenOptions::for_export(Some(name), d.fields.get("flattener"), &app.session.prefs.flattener_presets).unwrap_or_default();
|
||||
let line_ppi = preset_opts.line_art_ppi.round() as u32;
|
||||
let grad_ppi = preset_opts.gradient_ppi.round() as u32;
|
||||
note(
|
||||
ui,
|
||||
&crate::i18n::fmt(
|
||||
tl!("Raster resolution: {line_ppi} ppi line art and text, {grad_ppi} ppi gradient and mesh"),
|
||||
&[("line_ppi", &line_ppi.to_string()), ("grad_ppi", &grad_ppi.to_string())],
|
||||
),
|
||||
);
|
||||
note(ui, tl!("PDF 1.3 files have no transparency: the preset flattens it."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,3 +607,63 @@ fn pdf_1_3_takes_a_flattener_preset_in_advanced() {
|
||||
let saved = app.session.prefs.pdf_presets.iter().find(|p| p.name == "Old").unwrap();
|
||||
assert_eq!((saved.settings.compatibility, saved.settings.flattener_preset.as_str()), (Compatibility::Pdf13, "Low Resolution"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_pdf_flattens_transparent_document_without_modal_prompt() {
|
||||
let (mut app, written, _) = app();
|
||||
// Add transparent artwork to the document
|
||||
app.run("transparency.set", json!({"opacity": 50})).unwrap();
|
||||
|
||||
app.run("ui.savePdfDialog", json!({"path": "/tmp/transparent.pdf", "compatibility": "1.3"})).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND);
|
||||
|
||||
// Clicking Save PDF goes ahead without stopping at a confirmation prompt
|
||||
super::super::confirm(&mut app).unwrap();
|
||||
assert!(app.ui.dialog.is_none(), "Save PDF closes without a modal prompt");
|
||||
assert_eq!(written.borrow().len(), 1);
|
||||
assert!(written.borrow()[0].1.starts_with(b"%PDF-1.3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summary_warnings_include_flattener_resolutions_when_flattening_transparency() {
|
||||
let (mut app, _, _) = app();
|
||||
app.run("transparency.set", json!({"opacity": 50})).unwrap();
|
||||
|
||||
app.run("ui.savePdfDialog", json!({"path": "/tmp/out.pdf", "compatibility": "1.3"})).unwrap();
|
||||
let p = params(app.ui.dialog.as_ref().unwrap());
|
||||
let v = summary_of(&mut app, &egui::Context::default(), &p).unwrap();
|
||||
let warnings = v["warnings"].as_array().unwrap();
|
||||
assert!(
|
||||
warnings.iter().any(|w| {
|
||||
let s = w.as_str().unwrap();
|
||||
s.contains("transparency is flattened into opaque art and images")
|
||||
&& s.contains("at 1200 ppi line art and text, 300 ppi gradients and meshes")
|
||||
}),
|
||||
"{warnings:?}"
|
||||
);
|
||||
|
||||
// With a custom flattener override, the resolution in the warning reflects the options
|
||||
set_field(&mut app, "flattener.lineArtPpi", json!(600));
|
||||
set_field(&mut app, "flattener.gradientPpi", json!(200));
|
||||
let p2 = params(app.ui.dialog.as_ref().unwrap());
|
||||
let v2 = summary_of(&mut app, &egui::Context::default(), &p2).unwrap();
|
||||
let warnings2 = v2["warnings"].as_array().unwrap();
|
||||
assert!(
|
||||
warnings2.iter().any(|w| {
|
||||
let s = w.as_str().unwrap();
|
||||
s.contains("at 600 ppi line art and text, 200 ppi gradients and meshes")
|
||||
}),
|
||||
"{warnings2:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn advanced_section_shows_raster_resolution_note() {
|
||||
let (mut app, _, _) = app();
|
||||
app.run("ui.savePdfDialog", json!({"path": "/tmp/out.pdf", "compatibility": "1.3"})).unwrap();
|
||||
set_field(&mut app, "__section", json!("Advanced"));
|
||||
set_field(&mut app, "flattener.lineArtPpi", json!(600));
|
||||
set_field(&mut app, "flattener.gradientPpi", json!(200));
|
||||
frame(&mut app);
|
||||
assert!(app.ui.dialog.is_some());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user