From 3d4ab6bac14c28dcbce00dd57bb30b0bbc4937db Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 8 Aug 2018 00:09:16 -0400 Subject: [PATCH] [pcf] Massive unsigning (part 1). Unofficial specifications hesitate to use unsigned 32-bit integers. Negative values caused a lot of trouble in the past and it is safer and easier to treat some properties as unsigned. * src/pcf/pcf.h (PCF_AccelRec): Use unsigned values for `fontAscent', `fontDescent', and `maxOverlap'. * src/pcf/pcfread.c (pcf_load_font, pcf_get_accel): Updated. * src/pcf/pcfdrivr.c (PCF_Glyph_Load, PCF_Size_Select, PCF_Size_Request): Updated. --- ChangeLog | 16 +++++++++++++++- src/pcf/pcf.h | 6 +++--- src/pcf/pcfdrivr.c | 12 ++++++------ src/pcf/pcfread.c | 44 ++++++++++++++++---------------------------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9576d837..bbe07ee22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,18 @@ -2018-08-06 Alexei Podtelezhnikov +2018-08-08 Alexei Podtelezhnikov + + [pcf] Massive unsigning (part 1). + + Unofficial specifications hesitate to use unsigned 32-bit integers. + Negative values caused a lot of trouble in the past and it is safer + and easier to treat some properties as unsigned. + + * src/pcf/pcf.h (PCF_AccelRec): Use unsigned values for `fontAscent', + `fontDescent', and `maxOverlap'. + * src/pcf/pcfread.c (pcf_load_font, pcf_get_accel): Updated. + * src/pcf/pcfdrivr.c (PCF_Glyph_Load, PCF_Size_Select, + PCF_Size_Request): Updated. + +2018-08-07 Alexei Podtelezhnikov * src/pcf/pcfread.c (pcf_get_bitmaps): Unsign `offsets' and `bitmapSizes'. diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h index 3c4eb6a99..a4f6d24de 100644 --- a/src/pcf/pcf.h +++ b/src/pcf/pcf.h @@ -113,9 +113,9 @@ FT_BEGIN_HEADER FT_Byte inkInside; FT_Byte inkMetrics; FT_Byte drawDirection; - FT_Long fontAscent; - FT_Long fontDescent; - FT_Long maxOverlap; + FT_ULong fontAscent; + FT_ULong fontDescent; + FT_ULong maxOverlap; PCF_MetricRec minbounds; PCF_MetricRec maxbounds; PCF_MetricRec ink_minbounds; diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c index e2f7e7c77..90fb896a1 100644 --- a/src/pcf/pcfdrivr.c +++ b/src/pcf/pcfdrivr.c @@ -441,8 +441,8 @@ THE SOFTWARE. FT_Select_Metrics( size->face, strike_index ); - size->metrics.ascender = accel->fontAscent * 64; - size->metrics.descender = -accel->fontDescent * 64; + size->metrics.ascender = (FT_Pos)accel->fontAscent * 64; + size->metrics.descender = -(FT_Pos)accel->fontDescent * 64; size->metrics.max_advance = accel->maxbounds.characterWidth * 64; return FT_Err_Ok; @@ -470,8 +470,8 @@ THE SOFTWARE. break; case FT_SIZE_REQUEST_TYPE_REAL_DIM: - if ( height == ( face->accel.fontAscent + - face->accel.fontDescent ) ) + if ( (FT_ULong)height == ( face->accel.fontAscent + + face->accel.fontDescent ) ) error = FT_Err_Ok; break; @@ -560,8 +560,8 @@ THE SOFTWARE. slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); ft_synthesize_vertical_metrics( &slot->metrics, - ( face->accel.fontAscent + - face->accel.fontDescent ) * 64 ); + (FT_Pos)( face->accel.fontAscent + + face->accel.fontDescent ) * 64 ); if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) goto Exit; diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 14cce67b0..493c159b5 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -1139,9 +1139,9 @@ THE SOFTWARE. FT_FRAME_BYTE ( inkMetrics ), FT_FRAME_BYTE ( drawDirection ), FT_FRAME_SKIP_BYTES( 1 ), - FT_FRAME_LONG_LE ( fontAscent ), - FT_FRAME_LONG_LE ( fontDescent ), - FT_FRAME_LONG_LE ( maxOverlap ), + FT_FRAME_ULONG_LE ( fontAscent ), + FT_FRAME_ULONG_LE ( fontDescent ), + FT_FRAME_ULONG_LE ( maxOverlap ), FT_FRAME_END }; @@ -1161,9 +1161,9 @@ THE SOFTWARE. FT_FRAME_BYTE ( inkMetrics ), FT_FRAME_BYTE ( drawDirection ), FT_FRAME_SKIP_BYTES( 1 ), - FT_FRAME_LONG ( fontAscent ), - FT_FRAME_LONG ( fontDescent ), - FT_FRAME_LONG ( maxOverlap ), + FT_FRAME_ULONG ( fontAscent ), + FT_FRAME_ULONG ( fontDescent ), + FT_FRAME_ULONG ( maxOverlap ), FT_FRAME_END }; @@ -1217,7 +1217,7 @@ THE SOFTWARE. FT_TRACE5(( " noOverlap=%s, constantMetrics=%s," " terminalFont=%s, constantWidth=%s\n" " inkInside=%s, inkMetrics=%s, drawDirection=%s\n" - " fontAscent=%ld, fontDescent=%ld, maxOverlap=%ld\n", + " fontAscent=%lu, fontDescent=%lu, maxOverlap=%lu\n", accel->noOverlap ? "yes" : "no", accel->constantMetrics ? "yes" : "no", accel->terminalFont ? "yes" : "no", @@ -1229,17 +1229,17 @@ THE SOFTWARE. accel->fontDescent, accel->maxOverlap )); - /* sanity checks */ - if ( FT_ABS( accel->fontAscent ) > 0x7FFF ) + /* sanity checks so that combined height can fit short */ + if ( accel->fontAscent > 0x3FFFU ) { - accel->fontAscent = accel->fontAscent < 0 ? -0x7FFF : 0x7FFF; - FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %d\n", + accel->fontAscent = 0x3FFFU; + FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %u\n", accel->fontAscent )); } - if ( FT_ABS( accel->fontDescent ) > 0x7FFF ) + if ( accel->fontDescent > 0x3FFFU ) { - accel->fontDescent = accel->fontDescent < 0 ? -0x7FFF : 0x7FFF; - FT_TRACE0(( "pfc_get_accel: clamping font descent to value %d\n", + accel->fontDescent = 0x3FFFU; + FT_TRACE0(( "pfc_get_accel: clamping font descent to value %u\n", accel->fontDescent )); } @@ -1565,20 +1565,8 @@ THE SOFTWARE. bsize->height = face->accel.maxbounds.ascent << 6; #endif -#ifdef FT_DEBUG_LEVEL_TRACE - if ( face->accel.fontAscent + face->accel.fontDescent < 0 ) - FT_TRACE0(( "pcf_load_font: negative height\n" )); -#endif - if ( FT_ABS( face->accel.fontAscent + - face->accel.fontDescent ) > 0x7FFF ) - { - bsize->height = 0x7FFF; - FT_TRACE0(( "pcf_load_font: clamping height to value %d\n", - bsize->height )); - } - else - bsize->height = FT_ABS( (FT_Short)( face->accel.fontAscent + - face->accel.fontDescent ) ); + bsize->height = (FT_Short)( face->accel.fontAscent + + face->accel.fontDescent ); prop = pcf_find_property( face, "AVERAGE_WIDTH" ); if ( prop )