From 2826287b1a3d6661535d631732abd122d460b9fa Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 28 Mar 2023 13:39:10 +0800 Subject: [PATCH] Correctly round lbearing values * src/sfnt.h (SFNT_ROUND_FIXED): * src/sfntfont.c (sfntfont_probe_widths): (sfntfont_measure_pcm): Round lbearing properly. --- src/sfnt.h | 5 ++--- src/sfntfont.c | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sfnt.h b/src/sfnt.h index fb8cb80bae9..30c82ad3795 100644 --- a/src/sfnt.h +++ b/src/sfnt.h @@ -1325,9 +1325,8 @@ struct sfnt_metrics_distortion -#define SFNT_CEIL_FIXED(fixed) \ - (!((fixed) & 0177777) ? (fixed) \ - : ((fixed) + 0200000) & 037777600000) +#define SFNT_CEIL_FIXED(fixed) (((fixed) + 0177777) & 037777600000) +#define SFNT_FLOOR_FIXED(fixed) ((fixed) & 037777600000) diff --git a/src/sfntfont.c b/src/sfntfont.c index 9c0910d18ed..f9965ef13f1 100644 --- a/src/sfntfont.c +++ b/src/sfntfont.c @@ -2460,7 +2460,7 @@ sfntfont_probe_widths (struct sfnt_font_info *font_info) num_characters++; /* Add the advance to total_width. */ - total_width += metrics.advance / 65536; + total_width += SFNT_CEIL_FIXED (metrics.advance) / 65536; /* Update min_width if it hasn't been set yet or is wider. */ if (font_info->font.min_width == 1 @@ -3183,7 +3183,8 @@ sfntfont_measure_pcm (struct sfnt_font_info *font, sfnt_glyph glyph, if (!outline) return 1; - pcm->lbearing = metrics.lbearing / 65536; + /* Round the left side bearing downwards. */ + pcm->lbearing = SFNT_FLOOR_FIXED (metrics.lbearing) / 65536; pcm->rbearing = SFNT_CEIL_FIXED (outline->xmax) / 65536; /* Round the advance, ascent and descent upwards. */ -- 2.39.2