From d38a13dd3c8f57581ef72204847dd9ce9087ff44 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 25 Apr 2025 17:58:56 +0200 Subject: [PATCH] [autofit] Support diacritics with special vertical minima. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This code catches situations like U+1F90 ('ᾐ'), where some fonts have exactly the same vertical minimum for the lower accent as for the base glyph. * src/autofit/aflatin.c (af_find_highest_contour, af_find_lowest_contour): Handle it. --- src/autofit/aflatin.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c index 4978f9843..a7690193e 100644 --- a/src/autofit/aflatin.c +++ b/src/autofit/aflatin.c @@ -2863,6 +2863,7 @@ af_find_highest_contour( AF_GlyphHints hints ) { FT_Int highest_contour = 0; + FT_Pos highest_min_y = FT_INT_MAX; FT_Pos highest_max_y = FT_INT_MIN; FT_Int contour; @@ -2876,11 +2877,17 @@ /* highest y maximum value. */ for ( contour = 0; contour < hints->num_contours; contour++ ) { + FT_Pos current_min_y = hints->contour_y_minima[contour]; FT_Pos current_max_y = hints->contour_y_maxima[contour]; - if ( current_max_y > highest_max_y ) + /* If we have two contours with the same maximum value, take */ + /* the one that has a smaller height. */ + if ( current_max_y > highest_max_y || + ( current_max_y == highest_max_y && + current_min_y > highest_min_y ) ) { + highest_min_y = current_min_y; highest_max_y = current_max_y; highest_contour = contour; } @@ -2940,6 +2947,7 @@ { FT_Int lowest_contour = 0; FT_Pos lowest_min_y = FT_INT_MAX; + FT_Pos lowest_max_y = FT_INT_MIN; FT_Int contour; @@ -2947,11 +2955,15 @@ for ( contour = 0; contour < hints->num_contours; contour++ ) { FT_Pos current_min_y = hints->contour_y_minima[contour]; + FT_Pos current_max_y = hints->contour_y_maxima[contour]; - if ( current_min_y < lowest_min_y ) + if ( current_min_y < lowest_min_y || + ( current_min_y == lowest_min_y && + current_max_y < lowest_max_y ) ) { lowest_min_y = current_min_y; + lowest_max_y = current_max_y; lowest_contour = contour; } }