summaryrefslogtreecommitdiff
path: root/content/handlers/html
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-12-16 14:07:15 +0000
committerMichael Drake <mdrake.unique@gmail.com>2022-12-16 14:18:46 +0000
commitdbd7f5bcd8a6500c7236bbe67e4a38c48a613b20 (patch)
treeb02e3a1bee38bbb952a2ead319a4e13e779db066 /content/handlers/html
parent71765dd1e8dc968f15ce359f7e604585aa428f90 (diff)
downloadnetsurf-dbd7f5bcd8a6500c7236bbe67e4a38c48a613b20.tar.gz
netsurf-dbd7f5bcd8a6500c7236bbe67e4a38c48a613b20.tar.bz2
html: layout: flex: grow: Avoid rounding error accumulation
Diffstat (limited to 'content/handlers/html')
-rw-r--r--content/handlers/html/layout_flex.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index ac0b88827..3a0fa4aa0 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -629,8 +629,10 @@ static inline void layout_flex__distribute_free_main(
size_t item_count = line->first + line->count;
if (grow) {
+ css_fixed remainder = 0;
for (size_t i = line->first; i < item_count; i++) {
struct flex_item_data *item = &ctx->item.data[i];
+ css_fixed result;
css_fixed ratio;
if (item->freeze) {
@@ -638,11 +640,12 @@ static inline void layout_flex__distribute_free_main(
}
ratio = FDIV(item->grow, unfrozen_factor_sum);
+ result = FMUL(INTTOFIX(remaining_free_main), ratio) +
+ remainder;
item->target_main_size = item->base_size +
- FIXTOINT(FMUL(
- INTTOFIX(remaining_free_main),
- ratio));
+ FIXTOINT(result);
+ remainder = FIXFRAC(result);
}
} else {
css_fixed scaled_shrink_factor_sum = 0;