summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorPgBiel <9021226+PgBiel@users.noreply.github.com>2025-02-23 08:26:14 -0300
committerGitHub <noreply@github.com>2025-02-23 11:26:14 +0000
commit240f238eee4d6dfce7e3c4cabb9315ad052ca230 (patch)
tree231771ef399964f28b267b2b0832bad274e0f5c9 /crates
parentd199546f9fe92b2d380dc337298fdca3e6fca8c8 (diff)
Fix HTML export of table with gutter (#5920)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/layout/grid/resolve.rs21
-rw-r--r--crates/typst-library/src/model/table.rs2
2 files changed, 17 insertions, 6 deletions
diff --git a/crates/typst-library/src/layout/grid/resolve.rs b/crates/typst-library/src/layout/grid/resolve.rs
index f6df57a3..762f94ed 100644
--- a/crates/typst-library/src/layout/grid/resolve.rs
+++ b/crates/typst-library/src/layout/grid/resolve.rs
@@ -1526,11 +1526,7 @@ impl<'a> CellGrid<'a> {
self.entry(x, y).map(|entry| match entry {
Entry::Cell(_) => Axes::new(x, y),
Entry::Merged { parent } => {
- let c = if self.has_gutter {
- 1 + self.cols.len() / 2
- } else {
- self.cols.len()
- };
+ let c = self.non_gutter_column_count();
let factor = if self.has_gutter { 2 } else { 1 };
Axes::new(factor * (*parent % c), factor * (*parent / c))
}
@@ -1602,6 +1598,21 @@ impl<'a> CellGrid<'a> {
cell.rowspan.get()
}
}
+
+ #[inline]
+ pub fn non_gutter_column_count(&self) -> usize {
+ if self.has_gutter {
+ // Calculation: With gutters, we have
+ // 'cols = 2 * (non-gutter cols) - 1', since there is a gutter
+ // column between each regular column. Therefore,
+ // 'floor(cols / 2)' will be equal to
+ // 'floor(non-gutter cols - 1/2) = non-gutter-cols - 1',
+ // so 'non-gutter cols = 1 + floor(cols / 2)'.
+ 1 + self.cols.len() / 2
+ } else {
+ self.cols.len()
+ }
+ }
}
/// Given a cell's requested x and y, the vector with the resolved cell
diff --git a/crates/typst-library/src/model/table.rs b/crates/typst-library/src/model/table.rs
index 82c1cc08..6f4461bd 100644
--- a/crates/typst-library/src/model/table.rs
+++ b/crates/typst-library/src/model/table.rs
@@ -282,7 +282,7 @@ fn show_cell_html(tag: HtmlTag, cell: &Cell, styles: StyleChain) -> Content {
fn show_cellgrid_html(grid: CellGrid, styles: StyleChain) -> Content {
let elem = |tag, body| HtmlElem::new(tag).with_body(Some(body)).pack();
- let mut rows: Vec<_> = grid.entries.chunks(grid.cols.len()).collect();
+ let mut rows: Vec<_> = grid.entries.chunks(grid.non_gutter_column_count()).collect();
let tr = |tag, row: &[Entry]| {
let row = row