Skip to content

Commit

Permalink
Merge pull request #107 from PgBiel/full-rowspan-sizing
Browse files Browse the repository at this point in the history
Fix height of rows with no drawn cells being ignored
  • Loading branch information
PgBiel authored Dec 31, 2023
2 parents f287e5c + 5cf33fa commit 19dd507
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/common.typ
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
int(0 <= x) - int(x < 0)
}

// Polyfill for array sum (.sum() is Typst 0.3.0+).
#let array-sum(arr, zero: 0) = {
arr.fold(zero, (a, x) => a + x)
}

// get the types of things so we can compare with them
// (0.2.0-0.7.0: they're strings; 0.8.0+: they're proper types)
#let _array-type = type(())
Expand Down
6 changes: 1 addition & 5 deletions src/renderer/old.typ
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,10 @@
let first-y = none
let rightmost-x = none

let row-heights = 0pt
let row-heights = array-sum(rows.slice(start-y, end-y + 1), zero: 0pt)

let first-row = true
for row in group-rows {
if row.len() > 0 {
let first-cell = row.at(0)
row-heights += rows.at(first-cell.cell.y)
}
for cell-box in row {
let x = cell-box.cell.x
let y = cell-box.cell.y
Expand Down
46 changes: 46 additions & 0 deletions tablex-test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,49 @@ Combining em and pt (with a stroke object):
vlinex(expand: -(2% + 2pt + 2em)),
)
)

*Full-width rowspans displayed with the wrong height (Issue \#105)*

#tablex(
columns: (auto, auto, auto, auto),
colspanx(4, rowspanx(3)[ONE]),
[TWO], [THREE], [FOUR], [FIVE],
)

#block(breakable: false)[
a

#tablex(
columns: 3,
colspanx(3, rowspanx(2)[a])
)

b
]

*More overlapping rowspans (Issue \#82)*

#tablex(
auto-lines: false,
stroke: 1pt,
columns: (auto,auto,auto,auto),
align:center,
//hlinex(),
//vlinex(), vlinex(), vlinex(),vlinex(),
[Name], [He],[Rack],[Beschreibung],
hlinex(),
cellx(rowspan:2,align:center)["mt01"], cellx(fill: rgb("#b9edffff"), align: left,rowspan:2)[42],
cellx(rowspan:2,align:center)["WAT"],
//hlinex(),
cellx(rowspan:2,align:center)["Löschgasflasche"],
cellx(rowspan:2,align:center)["mt2"], cellx(fill: rgb("#b9edffff"), align: left,rowspan:2)[41],
cellx(rowspan:2,align:center)["WAT"],"test",
(""),"","","","",
cellx(rowspan:2,align:center)["mt3"], cellx(fill: rgb("#b9edffff"), align: left,rowspan:2)[40],
cellx(rowspan:2,align:center)["WAT"],"test",
"","","","","",
cellx(rowspan:2,align:center)["mt3"], cellx(fill: rgb("#b9edffff"), align: left,rowspan:2)[40],
cellx(rowspan:2,align:center)["WAT"],"test",
"","","","","",

)

0 comments on commit 19dd507

Please sign in to comment.