shithub: freetype+ttf2subf

Download patch

ref: 8bfffb4c5c7387f3d2b2da0918640a9169ab4ca5
parent: 633a729d384e751031332ba2aab8221b51e29dd4
author: Werner Lemberg <[email protected]>
date: Sat Feb 21 04:52:29 EST 2015

[pfr] Signedness fixes.

* src/pfr/pfrdrivr.c, src/pfr/pfrgload.c, src/pfr/pfrload.c,
src/pfr/pfrload.h, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c,
src/pfr/pfrtypes.h: Apply.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-02-21  Werner Lemberg  <[email protected]>
 
+	[pfr] Signedness fixes.
+
+	* src/pfr/pfrdrivr.c, src/pfr/pfrgload.c, src/pfr/pfrload.c,
+	src/pfr/pfrload.h, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c,
+	src/pfr/pfrtypes.h: Apply.
+
+2015-02-21  Werner Lemberg  <[email protected]>
+
 	[cff] Minor signedness fixes related to last commit.
 
 	* src/cff/cf2ft.c, src/cff/cf2intrp.c, src/cff/cffgload.c: Apply.
--- a/src/pfr/pfrdrivr.c
+++ b/src/pfr/pfrdrivr.c
@@ -43,12 +43,14 @@
     if ( phys->outline_resolution != phys->metrics_resolution )
     {
       if ( avector->x != 0 )
-        avector->x = FT_MulDiv( avector->x, phys->outline_resolution,
-                                            phys->metrics_resolution );
+        avector->x = FT_MulDiv( avector->x,
+                                (FT_Long)phys->outline_resolution,
+                                (FT_Long)phys->metrics_resolution );
 
       if ( avector->y != 0 )
-        avector->y = FT_MulDiv( avector->x, phys->outline_resolution,
-                                            phys->metrics_resolution );
+        avector->y = FT_MulDiv( avector->x,
+                                (FT_Long)phys->outline_resolution,
+                                (FT_Long)phys->metrics_resolution );
     }
 
     return FT_Err_Ok;
@@ -118,10 +120,10 @@
     if ( size )
     {
       x_scale = FT_DivFix( size->metrics.x_ppem << 6,
-                           phys->metrics_resolution );
+                           (FT_Long)phys->metrics_resolution );
 
       y_scale = FT_DivFix( size->metrics.y_ppem << 6,
-                           phys->metrics_resolution );
+                           (FT_Long)phys->metrics_resolution );
     }
 
     if ( ametrics_x_scale )
--- a/src/pfr/pfrgload.c
+++ b/src/pfr/pfrgload.c
@@ -143,7 +143,7 @@
     error = FT_GLYPHLOADER_CHECK_POINTS( loader, 1, 0 );
     if ( !error )
     {
-      FT_UInt  n = outline->n_points;
+      FT_Int  n = outline->n_points;
 
 
       outline->points[n] = *to;
@@ -693,7 +693,7 @@
       if ( format & PFR_SUBGLYPH_3BYTE_OFFSET )
       {
         PFR_CHECK( 3 );
-        subglyph->gps_offset = PFR_NEXT_LONG( p );
+        subglyph->gps_offset = PFR_NEXT_ULONG( p );
       }
       else
       {
@@ -736,7 +736,7 @@
 
     if ( size > 0 && *p & PFR_GLYPH_IS_COMPOUND )
     {
-      FT_Int          n, old_count, count;
+      FT_UInt         n, old_count, count;
       FT_GlyphLoader  loader = glyph->loader;
       FT_Outline*     base   = &loader->base.outline;
 
--- a/src/pfr/pfrload.c
+++ b/src/pfr/pfrload.c
@@ -199,7 +199,7 @@
   FT_LOCAL_DEF( FT_Error )
   pfr_log_font_count( FT_Stream  stream,
                       FT_UInt32  section_offset,
-                      FT_UInt   *acount )
+                      FT_Long   *acount )
   {
     FT_Error  error;
     FT_UInt   count;
@@ -212,7 +212,7 @@
     result = count;
 
   Exit:
-    *acount = result;
+    *acount = (FT_Long)result;
     return error;
   }
 
@@ -535,7 +535,8 @@
     item->pair_count = PFR_NEXT_BYTE( p );
     item->base_adj   = PFR_NEXT_SHORT( p );
     item->flags      = PFR_NEXT_BYTE( p );
-    item->offset     = phy_font->offset + ( p - phy_font->cursor );
+    item->offset     = phy_font->offset +
+                       (FT_Offset)( p - phy_font->cursor );
 
 #ifndef PFR_CONFIG_NO_CHECKS
     item->pair_size = 3;
@@ -864,7 +865,7 @@
 
 
       phy_font->num_chars    = count = PFR_NEXT_USHORT( p );
-      phy_font->chars_offset = offset + ( p - stream->cursor );
+      phy_font->chars_offset = offset + (FT_Offset)( p - stream->cursor );
 
       if ( FT_NEW_ARRAY( phy_font->chars, count ) )
         goto Fail;
@@ -898,7 +899,7 @@
 
         cur->advance   = ( flags & PFR_PHY_PROPORTIONAL )
                          ? PFR_NEXT_SHORT( p )
-                         : (FT_Int) phy_font->standard_advance;
+                         : phy_font->standard_advance;
 
 #if 0
         cur->ascii     = ( flags & PFR_PHY_ASCII_CODE )
--- a/src/pfr/pfrload.h
+++ b/src/pfr/pfrload.h
@@ -85,7 +85,7 @@
   FT_LOCAL( FT_Error )
   pfr_log_font_count( FT_Stream   stream,
                       FT_UInt32   log_section_offset,
-                      FT_UInt    *acount );
+                      FT_Long    *acount );
 
   /* load a pfr logical font entry */
   FT_LOCAL( FT_Error )
--- a/src/pfr/pfrobjs.c
+++ b/src/pfr/pfrobjs.c
@@ -94,7 +94,7 @@
 
     /* check face index */
     {
-      FT_UInt  num_faces;
+      FT_Long  num_faces;
 
 
       error = pfr_log_font_count( stream,
@@ -118,7 +118,7 @@
 
     /* load the face */
     error = pfr_log_font_load(
-               &face->log_font, stream, face_index,
+               &face->log_font, stream, (FT_UInt)face_index,
                face->header.log_dir_offset,
                FT_BOOL( face->header.phy_font_max_size_high != 0 ) );
     if ( error )
@@ -137,7 +137,7 @@
 
 
       pfrface->face_index = face_index;
-      pfrface->num_glyphs = phy_font->num_chars + 1;
+      pfrface->num_glyphs = (FT_Long)phy_font->num_chars + 1;
 
       pfrface->face_flags |= FT_FACE_FLAG_SCALABLE;
 
@@ -218,13 +218,13 @@
         strike = phy_font->strikes;
         for ( n = 0; n < count; n++, size++, strike++ )
         {
-          size->height = (FT_UShort)strike->y_ppm;
-          size->width  = (FT_UShort)strike->x_ppm;
-          size->size   = strike->y_ppm << 6;
-          size->x_ppem = strike->x_ppm << 6;
-          size->y_ppem = strike->y_ppm << 6;
+          size->height = (FT_Short)strike->y_ppm;
+          size->width  = (FT_Short)strike->x_ppm;
+          size->size   = (FT_Pos)( strike->y_ppm << 6 );
+          size->x_ppem = (FT_Pos)( strike->x_ppm << 6 );
+          size->y_ppem = (FT_Pos)( strike->y_ppm << 6 );
         }
-        pfrface->num_fixed_sizes = count;
+        pfrface->num_fixed_sizes = (FT_Int)count;
       }
 
       /* now compute maximum advance width */
@@ -366,7 +366,7 @@
       FT_BBox            cbox;
       FT_Glyph_Metrics*  metrics = &pfrslot->metrics;
       FT_Pos             advance;
-      FT_Int             em_metrics, em_outline;
+      FT_UInt            em_metrics, em_outline;
       FT_Bool            scaling;
 
 
@@ -390,7 +390,9 @@
       em_outline = face->phy_font.outline_resolution;
 
       if ( em_metrics != em_outline )
-        advance = FT_MulDiv( advance, em_outline, em_metrics );
+        advance = FT_MulDiv( advance,
+                             (FT_Long)em_outline,
+                             (FT_Long)em_metrics );
 
       if ( face->phy_font.flags & PFR_PHY_VERTICAL )
         metrics->vertAdvance = advance;
--- a/src/pfr/pfrsbit.c
+++ b/src/pfr/pfrsbit.c
@@ -39,9 +39,9 @@
   {
     FT_Byte*  line;      /* current line start                    */
     FT_Int    pitch;     /* line size in bytes                    */
-    FT_Int    width;     /* width in pixels/bits                  */
-    FT_Int    rows;      /* number of remaining rows to scan      */
-    FT_Int    total;     /* total number of bits to draw          */
+    FT_UInt   width;     /* width in pixels/bits                  */
+    FT_UInt   rows;      /* number of remaining rows to scan      */
+    FT_UInt   total;     /* total number of bits to draw          */
 
   } PFR_BitWriterRec, *PFR_BitWriter;
 
@@ -59,7 +59,7 @@
 
     if ( !decreasing )
     {
-      writer->line += writer->pitch * ( target->rows - 1 );
+      writer->line += writer->pitch * (FT_Int)( target->rows - 1 );
       writer->pitch = -writer->pitch;
     }
   }
@@ -70,8 +70,8 @@
                               FT_Byte*       p,
                               FT_Byte*       limit )
   {
-    FT_Int    n, reload;
-    FT_Int    left = writer->width;
+    FT_UInt   n, reload;
+    FT_UInt   left = writer->width;
     FT_Byte*  cur  = writer->line;
     FT_UInt   mask = 0x80;
     FT_UInt   val  = 0;
@@ -78,7 +78,7 @@
     FT_UInt   c    = 0;
 
 
-    n = (FT_Int)( limit - p ) * 8;
+    n = (FT_UInt)( limit - p ) * 8;
     if ( n > writer->total )
       n = writer->total;
 
@@ -110,7 +110,7 @@
         cur[0] = (FT_Byte)c;
         mask   = 0x80;
         c      = 0;
-        cur ++;
+        cur++;
       }
     }
 
@@ -124,8 +124,9 @@
                              FT_Byte*       p,
                              FT_Byte*       limit )
   {
-    FT_Int    n, phase, count, counts[2], reload;
-    FT_Int    left = writer->width;
+    FT_Int    phase, count, counts[2];
+    FT_UInt   n, reload;
+    FT_UInt   left = writer->width;
     FT_Byte*  cur  = writer->line;
     FT_UInt   mask = 0x80;
     FT_UInt   c    = 0;
@@ -175,7 +176,7 @@
 
       if ( --left <= 0 )
       {
-        cur[0] = (FT_Byte) c;
+        cur[0] = (FT_Byte)c;
         left   = writer->width;
         mask   = 0x80;
 
@@ -188,7 +189,7 @@
         cur[0] = (FT_Byte)c;
         mask   = 0x80;
         c      = 0;
-        cur ++;
+        cur++;
       }
 
       reload = ( --count <= 0 );
@@ -204,8 +205,9 @@
                              FT_Byte*       p,
                              FT_Byte*       limit )
   {
-    FT_Int    n, phase, count, reload;
-    FT_Int    left = writer->width;
+    FT_Int    phase, count;
+    FT_UInt   n, reload;
+    FT_UInt   left = writer->width;
     FT_Byte*  cur  = writer->line;
     FT_UInt   mask = 0x80;
     FT_UInt   c    = 0;
@@ -239,7 +241,7 @@
 
       if ( --left <= 0 )
       {
-        cur[0] = (FT_Byte) c;
+        cur[0] = (FT_Byte)c;
         c      = 0;
         mask   = 0x80;
         left   = writer->width;
@@ -252,7 +254,7 @@
         cur[0] = (FT_Byte)c;
         c      = 0;
         mask   = 0x80;
-        cur ++;
+        cur++;
       }
 
       reload = ( --count <= 0 );
@@ -355,7 +357,8 @@
   {
     FT_Error  error = FT_Err_Ok;
     FT_Byte   flags;
-    FT_Char   b;
+    FT_Char   c;
+    FT_Byte   b;
     FT_Byte*  p = *pdata;
     FT_Long   xpos, ypos, advance;
     FT_UInt   xsize, ysize;
@@ -374,9 +377,9 @@
     {
     case 0:
       PFR_CHECK( 1 );
-      b    = PFR_NEXT_INT8( p );
-      xpos = b >> 4;
-      ypos = ( (FT_Char)( b << 4 ) ) >> 4;
+      c    = PFR_NEXT_INT8( p );
+      xpos = c >> 4;
+      ypos = ( (FT_Char)( c << 4 ) ) >> 4;
       break;
 
     case 1:
@@ -609,8 +612,8 @@
       advance = character->advance;
       if ( phys->metrics_resolution != phys->outline_resolution )
         advance = FT_MulDiv( advance,
-                             phys->outline_resolution,
-                             phys->metrics_resolution );
+                             (FT_Long)phys->outline_resolution,
+                             (FT_Long)phys->metrics_resolution );
 
       glyph->root.linearHoriAdvance = advance;
 
@@ -618,7 +621,7 @@
       /* overridden in the bitmap header of certain glyphs.          */
       advance = FT_MulDiv( (FT_Fixed)size->root.metrics.x_ppem << 8,
                            character->advance,
-                           phys->metrics_resolution );
+                           (FT_Long)phys->metrics_resolution );
 
       if ( FT_STREAM_SEEK( face->header.gps_section_offset + gps_offset ) ||
            FT_FRAME_ENTER( gps_size )                                     )
@@ -632,12 +635,14 @@
                                        &advance, &format );
 
       /*
-       * XXX: on 16bit system, we return an error for huge bitmap
-       *      which causes a size truncation, because truncated
-       *      size properties makes bitmap glyph broken.
+       * XXX: on 16bit systems we return an error for huge bitmaps
+       *      that cause size truncation, because truncated
+       *      size properties make bitmap glyphs broken.
        */
-      if ( xpos > FT_INT_MAX  || xpos < FT_INT_MIN         ||
-           ysize > FT_INT_MAX || ypos + ysize > FT_INT_MAX ||
+      if ( xpos > FT_INT_MAX                  ||
+           xpos < FT_INT_MIN                  ||
+           ysize > FT_INT_MAX                 ||
+           ypos > FT_INT_MAX - (FT_Long)ysize ||
            ypos + (FT_Long)ysize < FT_INT_MIN )
       {
         FT_TRACE1(( "pfr_slot_load_bitmap:" ));
@@ -653,8 +658,8 @@
         /* Set up glyph bitmap and metrics */
 
         /* XXX: needs casts to fit FT_Bitmap.{width|rows|pitch} */
-        glyph->root.bitmap.width      = (FT_Int)xsize;
-        glyph->root.bitmap.rows       = (FT_Int)ysize;
+        glyph->root.bitmap.width      = xsize;
+        glyph->root.bitmap.rows       = ysize;
         glyph->root.bitmap.pitch      = (FT_Int)( xsize + 7 ) >> 3;
         glyph->root.bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
 
@@ -670,11 +675,11 @@
 
         /* XXX: needs casts fit FT_GlyphSlotRec.bitmap_{left|top} */
         glyph->root.bitmap_left = (FT_Int)xpos;
-        glyph->root.bitmap_top  = (FT_Int)(ypos + ysize);
+        glyph->root.bitmap_top  = (FT_Int)( ypos + (FT_Long)ysize );
 
         /* Allocate and read bitmap data */
         {
-          FT_ULong  len = glyph->root.bitmap.pitch * ysize;
+          FT_ULong  len = (FT_ULong)glyph->root.bitmap.pitch * ysize;
 
 
           error = ft_glyphslot_alloc_bitmap( &glyph->root, len );
--- a/src/pfr/pfrtypes.h
+++ b/src/pfr/pfrtypes.h
@@ -229,7 +229,7 @@
     FT_UInt            metrics_resolution;
     FT_BBox            bbox;
     FT_UInt            flags;
-    FT_UInt            standard_advance;
+    FT_Int             standard_advance;
 
     FT_Int             ascent;   /* optional, bbox.yMax if not present */
     FT_Int             descent;  /* optional, bbox.yMin if not present */
@@ -260,7 +260,7 @@
     PFR_KernItem*      kern_items_tail;
 
     /* not part of the spec, but used during load */
-    FT_Long            bct_offset;
+    FT_ULong           bct_offset;
     FT_Byte*           cursor;
 
   } PFR_PhyFontRec, *PFR_PhyFont;