forked from 1b-agent/opencadstudio-upstream
fix(plot-style): load plot style tables written by other applications
Tables copied from other applications into the plot styles folder were listed but refused on selection, showing as "missing" with the reason lost on a console: the loader failed hard on a checksum or a text length that did not add up and on any non-UTF-8 byte — and those files carry their descriptions in Windows-1252. - decompress_ctb reads the file as it is: a checksum or length mismatch is reported and read past (a genuinely cut-off file is still an error), a zlib stream with a bad trailer is retried as raw deflate, and text that is not UTF-8 is read as Windows-1252 (pens and colours are numbers and unaffected; other code pages only show wrong characters in descriptions). - PlotStyleTable carries load_warnings; every load site reports them on the command line, so a table that needed tolerance says so. - load_named explains itself: a .stb name says named tables are not supported yet, a .ctb missing from the folder says which folder to copy it into (instead of "Unknown built-in plot style"). - The Plot dialog shows the reason under the Table row (style_error) — from a selection, from a page setup that names a table, and from the Load… picker, whose error used to be swallowed. - A table picked with Load… from outside the plot styles folder is copied into it (unless a file of that name is already there), so it is listed from then on and page setups naming it resolve after a restart. Tests: flipped checksum, text length off by one, a short payload field, Windows-1252 descriptions, a truncated stream, .stb and missing names. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
1 parent
2b38f798c0
commit
7a75d430cd
28 files changed
+339
-35
No files matched your search
+23
-4
@@ -4468,18 +4468,22 @@ impl OpenCADStudio {
|
||||
self.plot_dialog.apply_plot_styles = false;
|
||||
self.plot_dialog.show_plot_styles = false;
|
||||
self.plot_dialog.style_missing = false;
|
||||
self.plot_dialog.style_error = None;
|
||||
} else {
|
||||
match crate::io::plot_style::PlotStyleTable::load_named(&name) {
|
||||
Ok(table) => {
|
||||
self.plot_dialog.style_name = table.name.clone();
|
||||
self.plot_dialog.apply_plot_styles = true;
|
||||
self.plot_dialog.style_missing = false;
|
||||
self.plot_dialog.style_error = None;
|
||||
self.report_plot_style_warnings(&table);
|
||||
self.active_plot_style = Some(table);
|
||||
}
|
||||
Err(error) => {
|
||||
self.plot_dialog.style_name = name;
|
||||
self.plot_dialog.style_missing = true;
|
||||
self.command_line.push_error(&error);
|
||||
self.plot_dialog.style_error = Some(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4744,16 +4748,19 @@ impl OpenCADStudio {
|
||||
));
|
||||
self.plot_dialog.window = self.plot_window;
|
||||
}
|
||||
let mut style_error = None;
|
||||
if !ps.current_style_sheet.is_empty()
|
||||
&& self
|
||||
.active_plot_style
|
||||
.as_ref()
|
||||
.is_none_or(|table| !table.name.eq_ignore_ascii_case(&ps.current_style_sheet))
|
||||
{
|
||||
if let Ok(table) =
|
||||
crate::io::plot_style::PlotStyleTable::load_named(&ps.current_style_sheet)
|
||||
{
|
||||
self.active_plot_style = Some(table);
|
||||
match crate::io::plot_style::PlotStyleTable::load_named(&ps.current_style_sheet) {
|
||||
Ok(table) => {
|
||||
self.report_plot_style_warnings(&table);
|
||||
self.active_plot_style = Some(table);
|
||||
}
|
||||
Err(error) => style_error = Some(error),
|
||||
}
|
||||
}
|
||||
let active_style_name = self
|
||||
@@ -4901,6 +4908,18 @@ impl OpenCADStudio {
|
||||
d.apply_plot_styles = ps.flags.plot_plot_styles;
|
||||
d.show_plot_styles = ps.flags.show_plot_styles;
|
||||
d.style_missing = !d.style_name.is_empty() && !style_loaded;
|
||||
d.style_error = if d.style_missing { style_error } else { None };
|
||||
}
|
||||
|
||||
/// Tell the user what a plot style table's loader had to tolerate.
|
||||
pub(in crate::app) fn report_plot_style_warnings(
|
||||
&mut self,
|
||||
table: &crate::io::plot_style::PlotStyleTable,
|
||||
) {
|
||||
for warning in &table.load_warnings {
|
||||
let name = &table.name;
|
||||
self.command_line.push_warning(&format!("{name}: {warning}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy transient paper/scale choices out of the dialog without changing
|
||||
|
||||
+15
-2
@@ -8762,7 +8762,7 @@ impl OpenCADStudio {
|
||||
Message::PlotStyleLoad => {
|
||||
Task::perform(crate::io::pick_plot_style(), Message::PlotStyleLoaded)
|
||||
}
|
||||
Message::PlotStyleLoaded(Some(table)) => {
|
||||
Message::PlotStyleLoaded(Ok(Some(table))) => {
|
||||
if table.is_stb {
|
||||
self.command_line.push_error(
|
||||
crate::t!(
|
||||
@@ -8774,6 +8774,8 @@ impl OpenCADStudio {
|
||||
}
|
||||
self.plot_dialog.style_name = table.name.clone();
|
||||
self.plot_dialog.style_missing = false;
|
||||
self.plot_dialog.style_error = None;
|
||||
self.report_plot_style_warnings(&table);
|
||||
self.command_line.push_output(
|
||||
crate::tf!(
|
||||
"Plot style '{}' loaded ({} color entries).",
|
||||
@@ -8790,7 +8792,15 @@ impl OpenCADStudio {
|
||||
self.plot_dialog.plot_styles = crate::io::plot_style::available_ctb_names();
|
||||
Task::none()
|
||||
}
|
||||
Message::PlotStyleLoaded(None) => Task::none(),
|
||||
Message::PlotStyleLoaded(Ok(None)) => Task::none(),
|
||||
Message::PlotStyleLoaded(Err(error)) => {
|
||||
// The file the user pointed at could not be read: say why,
|
||||
// in the dialog as well as on the command line.
|
||||
self.command_line.push_error(&error);
|
||||
self.plot_dialog.style_missing = true;
|
||||
self.plot_dialog.style_error = Some(error);
|
||||
Task::none()
|
||||
}
|
||||
Message::PlotStyleClear => {
|
||||
self.active_plot_style = None;
|
||||
self.plot_dialog.style_name.clear();
|
||||
@@ -8817,12 +8827,15 @@ impl OpenCADStudio {
|
||||
if needs_load {
|
||||
match crate::io::plot_style::PlotStyleTable::load_named(&selected_style) {
|
||||
Ok(table) => {
|
||||
self.report_plot_style_warnings(&table);
|
||||
self.active_plot_style = Some(table);
|
||||
self.plot_dialog.style_missing = false;
|
||||
self.plot_dialog.style_error = None;
|
||||
}
|
||||
Err(error) => {
|
||||
self.plot_dialog.style_missing = true;
|
||||
self.command_line.push_error(&error);
|
||||
self.plot_dialog.style_error = Some(error);
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user