forked from 1b-agent/opencadstudio-upstream
app: wire web export, preview, and print flows through the plot UI
- plot dialog: the web build defaults to 'Save to PDF file...' (its only
output choice); native dropdowns and defaults are untouched.
- on_plot_dlg_commit forces to_file on wasm so a stale page setup can no
longer route the web build into the (unreachable) printer path; both
preview branches now go through preview_page_pdf, which is identical to
the old inline temp-PDF + OS-viewer flow on desktop.
- Print ribbon / PRINTALL on wasm render the PDF and open it in a tab
instead of erroring; PrintAllPdf picks a virtual path and downloads.
- pdf_plot_options maps the dialog's Quality dropdown into PdfPlotOptions.
(cherry picked from commit 892d693d2d)
This commit is contained in:
1 parent
978000d37c
commit
38f0e2b25f
4 files changed
+117
-55
No files matched your search
+48
-10
@@ -3,6 +3,8 @@
|
||||
//! quality and output options into one dialog; on commit it either sends the
|
||||
//! current layout to a system printer (with the chosen options) or writes a
|
||||
//! PDF. Styled to match the other OCS dialogs (dark pills + fields).
|
||||
//! The web build has no system printers, so PDF is the only output it
|
||||
//! offers — and its default.
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::io::paper_catalog::{self, CustomPaper, Margins, PaperSize, PaperUnits};
|
||||
@@ -599,7 +601,8 @@ impl Default for PlotDialogState {
|
||||
import_draft: None,
|
||||
page_setup_on_new_layout: false,
|
||||
printer: None,
|
||||
to_file: false,
|
||||
// Web defaults to PDF output: it has no system printers.
|
||||
to_file: cfg!(target_arch = "wasm32"),
|
||||
file_svg: false,
|
||||
paper: paper_catalog::default_paper().canonical.to_string(),
|
||||
paper_width_mm: 297.0,
|
||||
@@ -1144,6 +1147,25 @@ fn custom_paper_editor<'a>(draft: &'a CustomPaperDraft, width: Length) -> Elemen
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Entries for the output dropdown. The web build has no system printers, so
|
||||
/// PDF is the only output it offers; native lists the system default, every
|
||||
/// discovered printer, then PDF.
|
||||
fn output_choices(printers: &[String]) -> Vec<PlotChoice> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
let _ = printers;
|
||||
vec![PlotChoice::localized(OUT_PDF)]
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let mut out = vec![PlotChoice::localized(OUT_DEFAULT)];
|
||||
out.extend(printers.iter().cloned().map(PlotChoice::raw));
|
||||
out.push(PlotChoice::localized(OUT_PDF));
|
||||
out.push(PlotChoice::localized(OUT_SVG));
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view_window(
|
||||
s: &PlotDialogState,
|
||||
print_all_options: bool,
|
||||
@@ -1151,10 +1173,17 @@ pub fn view_window(
|
||||
) -> Element<'_, Message> {
|
||||
let width = sizing.width;
|
||||
let height = sizing.height;
|
||||
// The web build always outputs PDF, whatever a stored dialog state says;
|
||||
// native follows the stored choice.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let to_file = true;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let to_file = s.to_file;
|
||||
let action = if print_all_options {
|
||||
t!("Apply")
|
||||
} else if s.to_file {
|
||||
if s.file_svg {
|
||||
} else if to_file {
|
||||
// The web build writes PDF whatever a stored dialog state says.
|
||||
if s.file_svg && cfg!(not(target_arch = "wasm32")) {
|
||||
t!("Export SVG")
|
||||
} else {
|
||||
t!("Export PDF")
|
||||
@@ -1289,12 +1318,21 @@ pub fn view_window(
|
||||
},
|
||||
None => PlotChoice::localized(OUT_DEFAULT),
|
||||
};
|
||||
let mut printer_opts = vec![default_entry.clone()];
|
||||
printer_opts.extend(s.printers.iter().cloned().map(PlotChoice::raw));
|
||||
printer_opts.push(PlotChoice::localized(OUT_PDF));
|
||||
printer_opts.push(PlotChoice::localized(OUT_SVG));
|
||||
let printer_sel = if s.to_file {
|
||||
Some(PlotChoice::localized(if s.file_svg { OUT_SVG } else { OUT_PDF }))
|
||||
let mut printer_opts = output_choices(&s.printers);
|
||||
if let Some(first) = printer_opts
|
||||
.first_mut()
|
||||
.filter(|first| first.raw == OUT_DEFAULT)
|
||||
{
|
||||
*first = default_entry.clone();
|
||||
}
|
||||
let printer_sel = if to_file {
|
||||
Some(PlotChoice::localized(
|
||||
if s.file_svg && cfg!(not(target_arch = "wasm32")) {
|
||||
OUT_SVG
|
||||
} else {
|
||||
OUT_PDF
|
||||
},
|
||||
))
|
||||
} else {
|
||||
Some(match &s.printer {
|
||||
Some(printer) => PlotChoice::raw(printer.clone()),
|
||||
@@ -1373,7 +1411,7 @@ pub fn view_window(
|
||||
.spacing(8)
|
||||
.align_y(iced::Center)
|
||||
.width(Length::Fill);
|
||||
let printer_controls: Element<'_, Message> = if s.to_file {
|
||||
let printer_controls: Element<'_, Message> = if to_file {
|
||||
Space::new().height(0).into()
|
||||
} else {
|
||||
row![
|
||||
|
||||
Reference in new issue
Block a user