/// 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>,
}
// 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 {
);
}
}
- dbg!(&columns);
// In pathological cases, spans can cause the minimum width of a column
// to exceed the maximum width. This bollixes our interpolation
/// 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.
/// 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,
+ rules
.get(1..n)
.map_or(0, |rules| rules.iter().copied().sum::<usize>());
- dbg!(total_unspanned, width);
if total_unspanned >= width {
return;
}
.unwrap_or(0)
}
+#[derive(Debug)]
struct Break {
page: Arc<Page>,
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,
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 {
}
}
- /// 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()
}
}
}
- false
+ true
}
/// Draws a chunk of content to fit in a space that has vertical size
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()