From aab66ac8e6801809c774cc2a7a8f97823eb2a47d Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 26 Dec 2025 08:21:55 -0800 Subject: [PATCH] rendering fix --- rust/pspp/src/output/pivot/output.rs | 2 +- rust/pspp/src/output/pivot/value.rs | 14 +++++- rust/pspp/src/spv/read/legacy_xml.rs | 68 +++++++++++++++++++--------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/rust/pspp/src/output/pivot/output.rs b/rust/pspp/src/output/pivot/output.rs index cf23ef768c..0eb09d7474 100644 --- a/rust/pspp/src/output/pivot/output.rs +++ b/rust/pspp/src/output/pivot/output.rs @@ -768,7 +768,7 @@ impl<'a> Headings<'a> { .get(i + 1) .map_or(table.h[Axis2::X], |(x, _heading)| *x); table.put( - CellRect::new(x0..x1, 0..h_ofs), + CellRect::new(x0..x1, 0..table.h[Axis2::Y]), CellInner::new(Area::Corner, heading.dimension.root.name.clone()), ); } diff --git a/rust/pspp/src/output/pivot/value.rs b/rust/pspp/src/output/pivot/value.rs index 1f37966f31..8aec1f9f75 100644 --- a/rust/pspp/src/output/pivot/value.rs +++ b/rust/pspp/src/output/pivot/value.rs @@ -360,16 +360,26 @@ impl Value { /// Returns this `Value` with the specified `font_style`. pub fn with_font_style(mut self, font_style: FontStyle) -> Self { - self.styling_mut().font_style = Some(font_style); + self.set_font_style(font_style); self } + /// Sets the `Value`'s font style. + pub fn set_font_style(&mut self, font_style: FontStyle) { + self.styling_mut().font_style = Some(font_style); + } + /// Returns this `Value` with the specified `cell_style`. pub fn with_cell_style(mut self, cell_style: CellStyle) -> Self { - self.styling_mut().cell_style = Some(cell_style); + self.set_cell_style(cell_style); self } + /// Sets the `Value`'s cell style. + pub fn set_cell_style(&mut self, cell_style: CellStyle) { + self.styling_mut().cell_style = Some(cell_style); + } + /// Returns this `Value` with the specified `styling`. pub fn with_styling(self, styling: Option>) -> Self { Self { styling, ..self } diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index a6c7a1be85..e0ff168b15 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -399,23 +399,23 @@ impl Visualization { dims: &mut Vec>, ) { let base_level = variables[0].1; - let (show_label, dimension_style) = if let Ok(a) = Axis2::try_from(a) + let (show_label, dim_cell, dim_font) = if let Ok(a) = Axis2::try_from(a) && let Some(axis) = axes.get(&(base_level + variables.len())) && let Some(label) = &axis.label { let mut dimension_style = AreaStyle::default_for_area(Area::Labels(a)); let style = label.style.get(&styles); - Style::decode_area( - style, - label.text_frame_style.as_ref().and_then(|r| r.get(styles)), - &mut dimension_style, - ); + let fg = style; + let bg = label.text_frame_style.as_ref().and_then(|r| r.get(styles)); ( style.is_some_and(|s| s.visible.unwrap_or(true)), - Some(dimension_style), + Style::decode_cell_style(fg, &mut dimension_style.cell_style) + .then_some(dimension_style.cell_style), + Style::decode_font_style(fg, bg, &mut dimension_style.font_style) + .then_some(dimension_style.font_style), ) } else { - (false, None) + (false, None, None) }; if let Ok(a) = Axis2::try_from(a) && let Some(axis) = axes.get(&(base_level + variables.len() - 1)) @@ -537,17 +537,16 @@ impl Visualization { cats = next_cats; } - let dimension_label = variables[0] + let mut dimension_label = variables[0] .label .as_ref() .map_or_else(|| Value::new_empty(), |label| Value::new_user_text(label)); - let dimension_label = if let Some(style) = dimension_style { - dimension_label - .with_cell_style(style.cell_style) - .with_font_style(style.font_style) - } else { - dimension_label - }; + if let Some(dim_cell) = dim_cell { + dimension_label.set_cell_style(dim_cell); + } + if let Some(dim_font) = dim_font { + dimension_label.set_font_style(dim_font); + } let dimension = Dimension::new( Group::new(dimension_label) @@ -2011,18 +2010,32 @@ impl Style { cell_style: &mut CellStyle, font_style: &mut look::FontStyle, ) { + Self::decode_font_style(fg, bg, font_style); + Self::decode_cell_style(fg, cell_style); + } + + fn decode_font_style( + fg: Option<&Style>, + bg: Option<&Style>, + font_style: &mut look::FontStyle, + ) -> bool { + let mut updated = false; if let Some(fg) = fg { if let Some(weight) = fg.font_weight { font_style.bold = weight.is_bold(); + updated = true; } if let Some(style) = fg.font_style { font_style.italic = style.is_italic(); + updated = true; } if let Some(underline) = fg.font_underline { font_style.underline = underline.is_underline(); + updated = true; } if let Some(color) = fg.color { font_style.fg = color; + updated = true; } if let Some(font_size) = &fg.font_size { if let Ok(size) = font_size @@ -2030,22 +2043,35 @@ impl Style { .parse() { font_style.size = size; + updated = true; } else { // XXX warn? } } + } + if let Some(bg) = bg + && let Some(color) = bg.color + { + font_style.bg = color; + updated = true; + } + updated + } + + fn decode_cell_style(fg: Option<&Style>, cell_style: &mut CellStyle) -> bool { + let mut updated = false; + if let Some(fg) = fg { if let Some(alignment) = fg.text_alignment { cell_style.horz_align = alignment.as_horz_align(fg.decimal_offset); + updated = true; } if let Some(label_local_vertical) = fg.label_location_vertical { cell_style.vert_align = label_local_vertical.into(); + updated = true; } + // XXX margins? } - if let Some(bg) = bg { - if let Some(color) = bg.color { - font_style.bg = color; - } - } + updated } fn decode_area(fg: Option<&Style>, bg: Option<&Style>, out: &mut AreaStyle) { -- 2.30.2