From 73dab84ef8de2f419349aa4c8872704c7ca9122c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 16 Dec 2022 14:07:44 +0000 Subject: html: layout: flex: shrink: Avoid rounding error accumulation --- content/handlers/html/layout_flex.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'content/handlers') 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); } } } -- cgit v1.2.3