summaryrefslogtreecommitdiff
path: root/content/handlers
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-12-16 14:07:44 +0000
committerMichael Drake <mdrake.unique@gmail.com>2022-12-16 14:18:46 +0000
commit73dab84ef8de2f419349aa4c8872704c7ca9122c (patch)
tree19f2ab02b3e2274c7def59c8baa7a450391b705f /content/handlers
parentdbd7f5bcd8a6500c7236bbe67e4a38c48a613b20 (diff)
downloadnetsurf-73dab84ef8de2f419349aa4c8872704c7ca9122c.tar.gz
netsurf-73dab84ef8de2f419349aa4c8872704c7ca9122c.tar.bz2
html: layout: flex: shrink: Avoid rounding error accumulation
Diffstat (limited to 'content/handlers')
-rw-r--r--content/handlers/html/layout_flex.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/content/handlers/html/layout_flex.c b/content/handlers/html/layout_flex.c
index 3a0fa4aa0..7c295f14f 100644
--- a/content/handlers/html/layout_flex.c
+++ b/content/handlers/html/layout_flex.c
@@ -649,6 +649,7 @@ static inline void layout_flex__distribute_free_main(
}
} else {
css_fixed scaled_shrink_factor_sum = 0;
+ css_fixed remainder = 0;
for (size_t i = line->first; i < item_count; i++) {
struct flex_item_data *item = &ctx->item.data[i];
@@ -667,6 +668,7 @@ static inline void layout_flex__distribute_free_main(
for (size_t i = line->first; i < item_count; i++) {
struct flex_item_data *item = &ctx->item.data[i];
css_fixed scaled_shrink_factor;
+ css_fixed result;
css_fixed ratio;
if (item->freeze) {
@@ -681,12 +683,13 @@ static inline void layout_flex__distribute_free_main(
item->shrink,
INTTOFIX(item->base_size));
ratio = FDIV(scaled_shrink_factor,
- scaled_shrink_factor_sum);
+ scaled_shrink_factor_sum);
+ result = FMUL(INTTOFIX(abs(remaining_free_main)),
+ ratio) + remainder;
item->target_main_size = item->base_size -
- FIXTOINT(FMUL(
- INTTOFIX(abs(remaining_free_main)),
- ratio));
+ FIXTOINT(result);
+ remainder = FIXFRAC(result);
}
}
}