most basic Pager works now
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Apr 2025 16:08:06 +0000 (09:08 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Apr 2025 16:08:06 +0000 (09:08 -0700)
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/render.rs
rust/pspp/src/output/text.rs

index 1d649d113e707a6049e5e9e38068527ee656d854..cf98272c6ee125e127ca832c286e15d0eea5f60b 100644 (file)
@@ -1452,9 +1452,7 @@ impl PivotTable {
     ///
     /// - Otherwise, the iterator will just visit `self.current_layer`.
     pub fn layers(&self, print: bool) -> Box<dyn Iterator<Item = SmallVec<[usize; 4]>> + '_> {
-        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)))
index 18cdff5e88fced6e27ec3ec6d325e20206a61468..db2689c524c2f98d46483db146b62ba2f259d65f 100644 (file)
@@ -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<Table>,
 
@@ -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::<usize>());
-    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<Page>,
 
@@ -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()
index a47a95b28863132eba84628789ab557c704937af..bd3455fed7ff4991baab9f74cf9aa5d41d600e03 100644 (file)
@@ -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);
             }
         }