From: Ben Pfaff Date: Sun, 13 Apr 2025 16:08:06 +0000 (-0700) Subject: most basic Pager works now X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfe45ed571d8621cb6a788f7a470c9b1b9f2dcb9;p=pspp most basic Pager works now --- diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index 1d649d113e..cf98272c6e 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -1452,9 +1452,7 @@ impl PivotTable { /// /// - Otherwise, the iterator will just visit `self.current_layer`. pub fn layers(&self, print: bool) -> Box> + '_> { - dbg!(self.look.print_all_layers); if print && self.look.print_all_layers { - dbg!(); Box::new(self.axis_values(Axis3::Z)) } else { Box::new(once(SmallVec::from_slice(&self.current_layer))) diff --git a/rust/pspp/src/output/render.rs b/rust/pspp/src/output/render.rs index 18cdff5e88..db2689c524 100644 --- a/rust/pspp/src/output/render.rs +++ b/rust/pspp/src/output/render.rs @@ -200,6 +200,7 @@ impl<'a> DrawCell<'a> { /// The horizontal cells rendered are the leftmost `h[X]`, then `r[X]`. /// The vertical cells rendered are the topmost `h[Y]`, then `r[Y]`. /// `n[i]` is the sum of `h[i]` and `r[i].len()`. +#[derive(Debug)] struct Page { table: Arc, @@ -435,22 +436,18 @@ impl Page { } // Distribute widths of spanned columns. - dbg!(&unspanned_columns); let mut columns = unspanned_columns.clone(); for cell in table.cells().filter(|cell| cell.col_span() > 1) { let rect = cell.rect(); let w = device.measure_cell_width(&DrawCell::new(cell.inner(), &table)); for ext in [Min, Max] { - dbg!(&cell, ext, w[ext]); distribute_spanned_width( w[ext], - dbg!(&unspanned_columns[ext][rect[X].clone()]), - dbg!(&mut columns[ext][rect[X].clone()]), - dbg!(&rules[X][rect[X].start..rect[X].end + 1]), + &unspanned_columns[ext][rect[X].clone()], + &mut columns[ext][rect[X].clone()], + &rules[X][rect[X].start..rect[X].end + 1], ); - dbg!(&mut columns[ext][rect[X].clone()]); - eprintln!(); } } if min_width > 0 { @@ -463,7 +460,6 @@ impl Page { ); } } - dbg!(&columns); // In pathological cases, spans can cause the minimum width of a column // to exceed the maximum width. This bollixes our interpolation @@ -608,7 +604,8 @@ impl Page { /// Returns the width of rule `z` along `axis`. fn rule_width(&self, axis: Axis2, z: usize) -> usize { - self.axis_width(axis, rule_ofs(z + 1)..rule_ofs(z + 1)) + let ofs = rule_ofs(z); + self.axis_width(axis, ofs..ofs + 1) } /// Returns the width of rule `z` along `axis`, counting in reverse order. @@ -1025,7 +1022,7 @@ impl Selection { /// Maps a contiguous range of cells from a page to the underlying table along /// the horizontal or vertical dimension. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] struct Map { /// First ordinate in the page. p0: usize, @@ -1093,7 +1090,6 @@ fn distribute_spanned_width( + rules .get(1..n) .map_or(0, |rules| rules.iter().copied().sum::()); - dbg!(total_unspanned, width); if total_unspanned >= width { return; } @@ -1163,6 +1159,7 @@ fn measure_rule(device: &dyn Device, table: &Table, a: Axis2, z: usize) -> usize .unwrap_or(0) } +#[derive(Debug)] struct Break { page: Arc, @@ -1246,8 +1243,8 @@ impl Break { return None; } - self.find_breakpoint(device, size) - .map(|(z, pixel)| match pixel { + self.find_breakpoint(device, size).map(|(z, pixel)| { + let page = match pixel { 0 => self.page.select(self.axis, self.z..z, self.pixel, 0), pixel => self.page.select( self.axis, @@ -1255,7 +1252,11 @@ impl Break { pixel, self.page.cell_width(self.axis, z) - pixel, ), - }) + }; + self.z = z; + self.pixel = pixel; + page + }) } fn break_cell(&self, device: &dyn Device, z: usize, overflow: usize) -> usize { @@ -1446,9 +1447,8 @@ impl Pager { } } - /// True if there's content left to rnder. + /// True if there's content left to render. pub fn has_next(&mut self, device: &dyn Device) -> bool { - return !self.pages.is_empty(); while self .y_break .as_mut() @@ -1471,7 +1471,7 @@ impl Pager { } } } - false + true } /// Draws a chunk of content to fit in a space that has vertical size @@ -1482,20 +1482,13 @@ impl Pager { pub fn draw_next(&mut self, device: &mut dyn Device, mut space: usize) -> usize { use Axis2::*; - let page = self.pages.pop().unwrap(); - page.draw(device, Coord2::new(0, 0)); - return page.total_size(Y); - if self.scale != 1.0 { device.scale(self.scale); space = (space as f64 / self.scale) as usize; } let mut ofs = Coord2::new(0, 0); - let mut n_pages = None; - while self.has_next(device) && n_pages == Some(self.pages.len()) { - n_pages = Some(self.pages.len()); - + while self.has_next(device) { let Some(page) = self .y_break .as_mut() diff --git a/rust/pspp/src/output/text.rs b/rust/pspp/src/output/text.rs index a47a95b288..bd3455fed7 100644 --- a/rust/pspp/src/output/text.rs +++ b/rust/pspp/src/output/text.rs @@ -319,8 +319,11 @@ impl TextRenderer { } let mut pager = Pager::new(self, table, Some(layer_indexes.as_slice())); + dbg!(); while pager.has_next(self) { + dbg!(); pager.draw_next(self, usize::MAX); + dbg!(); output.append(&mut self.lines); } }