diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-17 19:44:10 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-17 19:44:10 +0100 |
commit | 1fbe17eeddefb87bf8e819be7792ae7a6482d8f8 (patch) | |
tree | 00c7866c293634db8a970a3d5be6f816e7c620ac /src/layout | |
parent | a316ae2406bd4d0f1006cdcb572a06b772b10237 (diff) | |
download | chawan-1fbe17eeddefb87bf8e819be7792ae7a6482d8f8.tar.gz |
Fix division by zero in table layout
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/engine.nim | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 479e8f3a..fbee9f6f 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -998,17 +998,19 @@ proc buildTable(box: TableBoxBuilder, parent: BlockBox): BlockBox = let dw = (table.compwidth - ctx.maxwidth) var weight: float64 var avail = ctx.calcUnspecifiedColIndices(dw, weight) - let unit = float64(dw) / weight - for i in countdown(avail.high, 0): - let j = avail[i] - let x = int(unit * ctx.cols[j].weight) - ctx.cols[j].width += x - reflow[j] = true + if weight != 0: + let unit = float64(dw) / weight + for i in countdown(avail.high, 0): + let j = avail[i] + let x = int(unit * ctx.cols[j].weight) + ctx.cols[j].width += x + reflow[j] = true elif table.compwidth < ctx.maxwidth: var dw = (ctx.maxwidth - table.compwidth) var weight: float64 var avail = ctx.calcUnspecifiedColIndices(dw, weight) while avail.len > 0 and dw != 0: + if weight == 0: break # zero weight; nothing to distribute # divide delta width by sum of sqrt(width) for all elem in avail let unit = float64(dw) / weight dw = 0 |