Commit 44e47d5fd61e2d7846ef419231e793f8ce8d6011

Werner Lemberg 2005-11-30T18:47:49

* src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: s/TT_CMAP_FLAG_OVERLAPPED/TT_CMAP_FLAG_OVERLAPPING/.

diff --git a/ChangeLog b/ChangeLog
index 8f3283e..bc7686d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
 	* docs/CHANGES: Document ftdump's `-v' option.
 	Document latest charmap code changes.
 
+	* src/sfnt/ttcmap.c, src/sfnt/ttcmap.h:
+	s/TT_CMAP_FLAG_OVERLAPPED/TT_CMAP_FLAG_OVERLAPPING/.
+
 2005-11-30  Chia-I Wu  <b90201047@ntu.edu.tw>
 
 	* src/sfnt/ttcmap.c (tt_cmap4_char_map_binary,
@@ -10,28 +13,27 @@
 
 2005-11-29  Chia-I Wu  <b90201047@ntu.edu.tw>
 
-	Major update to distinguish between unsorted and overlapped segments
-	for cmap format 4.  For overlapped but sorted segments, which is
-	previously considered unsorted, we still use binary search.
+	Major update to distinguish between unsorted and overlapping
+	segments for cmap format 4.  For overlapping but sorted segments,
+	which is previously considered unsorted, we still use binary search.
 
-	* src/sfnt/ttcmap.h (struct  TT_CMapRec_): Replace `unsorted' by
-	`flags'.
+	* src/sfnt/ttcmap.h (TT_CMapRec_): Replace `unsorted' by `flags'. 
 	(TT_CMAP_FLAG_UNSORTED, TT_CMAP_FLAG_OVERLAPPED): New macros.
 
 	* src/sfnt/ttcmap.c (OPT_CMAP4): Removed as it is always defined.
-	(struct TT_CMap4Rec_): Remove `old_charcode' and `table_length'.  
+	(TT_CMap4Rec_): Remove `old_charcode' and `table_length'.  
 	(tt_cmap4_reset): Removed.
 	(tt_cmap4_init): Updated accordingly.
 	(tt_cmap4_next): Updated accordingly.
-	Take care of overlapped segments.
+	Take care of overlapping segments.
 	(tt_cmap4_validate): Make sure the subtable is large enough.
 	Do not check glyph_ids because some fonts set the length wrongly.
-	Also, when all segments have offset 0, glyph_ids is always invalid. It
-	does not cause any problem so far only because the check misses
+	Also, when all segments have offset 0, glyph_ids is always invalid.
+	It does not cause any problem so far only because the check misses
 	equality.
-	Distinguish between unsorted and overlapped segments.
-	(tt_cmap4_char_map_linear, tt_cmap4_char_map_binary): New functions to
-	do "charcode => glyph index" by linear/binary search.
+	Distinguish between unsorted and overlapping segments.
+	(tt_cmap4_char_map_linear, tt_cmap4_char_map_binary): New functions
+	to do `charcode => glyph index' by linear/binary search.
 	(tt_cmap4_char_index, tt_cmap4_char_next): Use
 	tt_cmap4_char_map_linear and tt_cmap4_char_map_binary.
 	(tt_face_build_cmaps): Treat the return value of validator as flags
@@ -39,10 +41,10 @@
 
 2005-11-29  Chia-I Wu  <b90201047@ntu.edu.tw>
 
-	* src/sfnt/ttcmap.c (struct  TT_CMap12Rec_, tt_cmap12_init,
-	tt_cmap12_next): New struct/function for fast "next char".
-	(tt_cmap12_char_map_binary): New function to do "charcode => glyph
-	index" by binary search.
+	* src/sfnt/ttcmap.c (TT_CMap12Rec_, tt_cmap12_init, tt_cmap12_next):
+	New structures and functions for fast `next char'.
+	(tt_cmap12_char_map_binary): New function to do `charcode => glyph
+	index' by binary search.
 	(tt_cmap12_char_index, tt_cmap12_char_next): Use
 	tt_cmap12_char_map_binary.
 	(tt_face_build_cmaps): Check table and offset correctly (equality is
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index e20fd79..9deb483 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -700,10 +700,10 @@
   }
 
 
-  /* find the index of the charcode next to cmap->cur_charcode; */
-  /* caller should call tt_cmap4_set_range with proper range    */
-  /* before calling this function                               */
-  /*                                                            */
+  /* search the index of the charcode next to cmap->cur_charcode; */
+  /* caller should call tt_cmap4_set_range with proper range      */
+  /* before calling this function                                 */
+  /*                                                              */
   static void
   tt_cmap4_next( TT_CMap4  cmap )
   {
@@ -894,7 +894,7 @@
             if ( last_start > start || last_end > end )
               error |= TT_CMAP_FLAG_UNSORTED;
             else
-              error |= TT_CMAP_FLAG_OVERLAPPED;
+              error |= TT_CMAP_FLAG_OVERLAPPING;
           }
         }
 
@@ -947,7 +947,7 @@
         }
 
         last_start = start;
-        last_end = end;
+        last_end   = end;
       }
     }
 
@@ -964,7 +964,7 @@
     FT_Int     delta;
     FT_UInt    i, num_segs;
     FT_UInt32  charcode = *pcharcode;
-    FT_UInt    gindex    = 0;
+    FT_UInt    gindex   = 0;
     FT_Byte*   p;
 
 
@@ -1029,15 +1029,15 @@
 
 
   static FT_UInt
-  tt_cmap4_char_map_binary( TT_CMap     cmap,
-                            FT_UInt*    pcharcode,
-                            FT_Bool     next )
+  tt_cmap4_char_map_binary( TT_CMap   cmap,
+                            FT_UInt*  pcharcode,
+                            FT_Bool   next )
   {
     FT_UInt   num_segs2, start, end, offset;
     FT_Int    delta;
     FT_UInt   max, min, mid, num_segs;
     FT_UInt   charcode = *pcharcode;
-    FT_UInt   gindex    = 0;
+    FT_UInt   gindex   = 0;
     FT_Byte*  p;
     
 
@@ -1074,13 +1074,13 @@
         min = mid + 1;
       else
       {
-        p      += num_segs2;
-        delta   = TT_PEEK_SHORT( p );
-        p      += num_segs2;
-        offset  = TT_PEEK_USHORT( p );
+        p     += num_segs2;
+        delta  = TT_PEEK_SHORT( p );
+        p     += num_segs2;
+        offset = TT_PEEK_USHORT( p );
 
-        /* find the first segment containing `charcode' */
-        if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPED )
+        /* search the first segment containing `charcode' */
+        if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPING )
         {
           FT_UInt  i;
 
@@ -1091,7 +1091,7 @@
           if ( offset == 0xFFFFU )
             mid = max + 1;
 
-          /* find in segments before the current segment */
+          /* search in segments before the current segment */
           for ( i = max ; i > 0; i-- )
           {
             FT_UInt  prev_end;
@@ -1103,13 +1103,13 @@
             if ( charcode > prev_end )
               break;
 
-            end     = prev_end;
-            p      += 2 + num_segs2;
-            start   = TT_PEEK_USHORT( p );
-            p      += num_segs2;
-            delta   = TT_PEEK_SHORT( p );
-            p      += num_segs2;
-            offset  = TT_PEEK_USHORT( p );
+            end    = prev_end;
+            p     += 2 + num_segs2;
+            start  = TT_PEEK_USHORT( p );
+            p     += num_segs2;
+            delta  = TT_PEEK_SHORT( p );
+            p     += num_segs2;
+            offset = TT_PEEK_USHORT( p );
 
             if ( offset != 0xFFFFU )
               mid = i - 1;
@@ -1120,38 +1120,38 @@
           {
             if ( i != max )
             {
-              p       = cmap->data + 14 + max * 2;
-              end     = TT_PEEK_USHORT( p );
-              p      += 2 + num_segs2;
-              start   = TT_PEEK_USHORT( p );
-              p      += num_segs2;
-              delta   = TT_PEEK_SHORT( p );
-              p      += num_segs2;
-              offset  = TT_PEEK_USHORT( p );
+              p      = cmap->data + 14 + max * 2;
+              end    = TT_PEEK_USHORT( p );
+              p     += 2 + num_segs2;
+              start  = TT_PEEK_USHORT( p );
+              p     += num_segs2;
+              delta  = TT_PEEK_SHORT( p );
+              p     += num_segs2;
+              offset = TT_PEEK_USHORT( p );
             }
 
             mid = max;
 
-            /* find in segments after the current segment */
+            /* search in segments after the current segment */
             for ( i = max + 1; i < num_segs; i++ )
             {
               FT_UInt  next_end, next_start;
 
 
-              p           = cmap->data + 14 + i * 2;
-              next_end    = TT_PEEK_USHORT( p );
-              p          += 2 + num_segs2;
-              next_start  = TT_PEEK_USHORT( p );
+              p          = cmap->data + 14 + i * 2;
+              next_end   = TT_PEEK_USHORT( p );
+              p         += 2 + num_segs2;
+              next_start = TT_PEEK_USHORT( p );
 
               if ( charcode < next_start )
                 break;
 
-              end     = next_end;
-              start   = next_start;
-              p      += num_segs2;
-              delta   = TT_PEEK_SHORT( p );
-              p      += num_segs2;
-              offset  = TT_PEEK_USHORT( p );
+              end    = next_end;
+              start  = next_start;
+              p     += num_segs2;
+              delta  = TT_PEEK_SHORT( p );
+              p     += num_segs2;
+              offset = TT_PEEK_USHORT( p );
 
               if ( offset != 0xFFFFU )
                 mid = i;
@@ -1167,17 +1167,17 @@
             }
           }
 
-          /* end, start, delta and offset are for the i'th segment */
+          /* end, start, delta, and offset are for the i'th segment */
           if ( mid != i )
           {
-            p       = cmap->data + 14 + mid * 2;
-            end     = TT_PEEK_USHORT( p );
-            p      += 2 + num_segs2;
-            start   = TT_PEEK_USHORT( p );
-            p      += num_segs2;
-            delta   = TT_PEEK_SHORT( p );
-            p      += num_segs2;
-            offset  = TT_PEEK_USHORT( p );
+            p      = cmap->data + 14 + mid * 2;
+            end    = TT_PEEK_USHORT( p );
+            p     += 2 + num_segs2;
+            start  = TT_PEEK_USHORT( p );
+            p     += num_segs2;
+            delta  = TT_PEEK_SHORT( p );
+            p     += num_segs2;
+            offset = TT_PEEK_USHORT( p );
           }
         }
         else
@@ -1247,7 +1247,7 @@
   tt_cmap4_char_index( TT_CMap    cmap,
                        FT_UInt32  char_code )
   {
-    if ( char_code >= 0x10000U )
+    if ( char_code >= 0x10000UL )
       return 0;
 
     if ( cmap->flags & TT_CMAP_FLAG_UNSORTED )
@@ -1927,14 +1927,14 @@
 
   FT_CALLBACK_DEF( FT_Error )
   tt_cmap12_init( TT_CMap12  cmap,
-                  FT_Byte*  table )
+                  FT_Byte*   table )
   {
-    cmap->cmap.data   = table;
+    cmap->cmap.data  = table;
 
-    table            += 12;
-    cmap->num_groups  = FT_PEEK_ULONG( table );
+    table           += 12;
+    cmap->num_groups = FT_PEEK_ULONG( table );
 
-    cmap->valid       = 0;
+    cmap->valid      = 0;
 
     return SFNT_Err_Ok;
   }
@@ -1992,9 +1992,9 @@
   }
 
 
-  /* find the index of the charcode next to cmap->cur_charcode */
-  /* cmap->cur_group should be set up properly by caller       */
-  /*                                                           */
+  /* search the index of the charcode next to cmap->cur_charcode */
+  /* cmap->cur_group should be set up properly by caller         */
+  /*                                                             */
   static void
   tt_cmap12_next( TT_CMap12  cmap )
   {
@@ -2071,10 +2071,10 @@
     while ( min < max )
     {
       mid = ( min + max ) >> 1;
-      p = cmap->data + 16 + 12 * mid;
+      p   = cmap->data + 16 + 12 * mid;
 
-      start    = TT_NEXT_ULONG( p );
-      end      = TT_NEXT_ULONG( p );
+      start = TT_NEXT_ULONG( p );
+      end   = TT_NEXT_ULONG( p );
 
       if ( char_code < start )
         max = mid;
@@ -2105,9 +2105,9 @@
           return 0;
       }
 
-      cmap12->valid = 1;
+      cmap12->valid        = 1;
       cmap12->cur_charcode = char_code;
-      cmap12->cur_group = mid;
+      cmap12->cur_group    = mid;
 
       if ( !gindex )
       {
@@ -2304,7 +2304,8 @@
               FT_CMap  ttcmap;
 
 
-              if ( !FT_CMap_New( (FT_CMap_Class)clazz, cmap, &charmap, &ttcmap ) )
+              if ( !FT_CMap_New( (FT_CMap_Class)clazz,
+                                 cmap, &charmap, &ttcmap ) )
               {
                 /* it is simpler to directly set `flags' than adding */
                 /* a parameter to FT_CMap_New                        */
diff --git a/src/sfnt/ttcmap.h b/src/sfnt/ttcmap.h
index fb03107..a10a3e2 100644
--- a/src/sfnt/ttcmap.h
+++ b/src/sfnt/ttcmap.h
@@ -28,8 +28,8 @@
 FT_BEGIN_HEADER
 
 
-#define TT_CMAP_FLAG_UNSORTED   1
-#define TT_CMAP_FLAG_OVERLAPPED 2
+#define TT_CMAP_FLAG_UNSORTED     1
+#define TT_CMAP_FLAG_OVERLAPPING  2
 
   typedef struct  TT_CMapRec_
   {