From 99c2f6e1e1a973e2898b400f57e9e1eceb9754a6 Mon Sep 17 00:00:00 2001 From: Vladimir Gamalyan Date: Sat, 4 Dec 2021 22:14:01 +0300 Subject: [PATCH] Remove manual calculation bounding box, revert to use one from font metrics --- src/freeType/FtFont.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/freeType/FtFont.h b/src/freeType/FtFont.h index de6db4d..37a5857 100644 --- a/src/freeType/FtFont.h +++ b/src/freeType/FtFont.h @@ -69,6 +69,8 @@ class Font /* Get the scalable font metrics for this font */ const auto scale = face->size->metrics.y_scale; + yMin = FT_FLOOR(FT_MulFix(face->bbox.yMin, scale)); + yMax = FT_CEIL(FT_MulFix(face->bbox.yMax, scale)); height = FT_CEIL(FT_MulFix(face->height, scale)); } else @@ -90,6 +92,8 @@ class Font * non-scalable fonts must be determined differently * or sometimes cannot be determined. * */ + yMin = 0; + yMax = face->available_sizes[ptsize].height; height = face->available_sizes[ptsize].height; } @@ -110,24 +114,7 @@ class Font glyph_italics = 0.207f; glyph_italics *= height; - { - std::int32_t yMin = 0; - FT_UInt gindex; - FT_ULong charcode = FT_Get_First_Char(face, &gindex); - yMax = 0; - while (gindex) - { - GlyphMetrics glyphMetrics = renderGlyph(nullptr, 0, 0, 0, 0, charcode, 0); - if (yMax < glyphMetrics.horiBearingY) - yMax = glyphMetrics.horiBearingY; - std::int32_t bottom = glyphMetrics.horiBearingY - glyphMetrics.height; - if (bottom < yMin) - yMin = bottom; - charcode = FT_Get_Next_Char(face, charcode, &gindex); - } - - totalHeight = yMax - yMin; - } + totalHeight = yMax - yMin; } ~Font() @@ -294,6 +281,7 @@ class Font FT_Face face = nullptr; int height; int yMax; + int yMin; int totalHeight = 0; /* For non-scalable formats, we must remember which font index size */