(READ_UINT24): New macro.
authorhanda <handa>
Tue, 23 Dec 2008 01:06:47 +0000 (01:06 +0000)
committerhanda <handa>
Tue, 23 Dec 2008 01:06:47 +0000 (01:06 +0000)
(read_cmap_uvs_table): Argument changed.  Complete the code.
(read_cmap_table): Adjusted for the above change.  Fix typo.

src/otfopen.c

index 443b822..35ae8a3 100644 (file)
@@ -199,6 +199,15 @@ free_stream (OTF_Stream *stream)
     (stream)->pos += 2;                                                \
   } while (0)
 
+#define READ_UINT24(stream, var)                               \
+  do {                                                 \
+    STREAM_CHECK_SIZE ((stream), 3);                   \
+    (var) =  (((stream)->buf[(stream)->pos ] << 16)    \
+            | ((stream)->buf[(stream)->pos + 1] << 8)  \
+            | (stream)->buf[(stream)->pos + 2]);       \
+    (stream)->pos += 3;                                        \
+  } while (0)
+
 #define READ_ULONG(stream, var)                                \
   do {                                                 \
     STREAM_CHECK_SIZE ((stream), 4);                   \
@@ -496,17 +505,74 @@ read_name_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
 /*** (1-4) "cmap" table */
 
 static OTF_EncodingSubtable14 *
-read_cmap_uvs_table (OTF *otf, OTF_Stream *stream, int nbytes)
+read_cmap_uvs_table (OTF *otf, OTF_Stream *stream, OTF_Offset offset)
 {
   OTF_EncodingSubtable14 *sub14;
   char *errfmt = "cmap-uvs%s";
   void *errret = NULL;
-  int i;
+  unsigned nRecords;
+  unsigned i,j;
 
   OTF_MALLOC (sub14, 1, " (EncodingSubtable14)");
-  sub14->nbytes = nbytes;
-  OTF_MALLOC (sub14->data, nbytes, " (EncodingSubtable14-Data)");
-  READ_BYTES (stream, sub14->data, nbytes);
+  READ_ULONG (stream, nRecords);
+  sub14->nRecords = nRecords;
+  OTF_MALLOC (sub14->Records, nRecords, "(EncodingSubtable14-Records)");
+  for (i = 0; i < sub14->nRecords; i++) 
+    {
+      unsigned varSelector=0, defaultUVSOffset, nonDefaultUVSOffset;
+      READ_UINT24 (stream, varSelector);
+      sub14->Records[i].varSelector=varSelector;
+      READ_ULONG (stream, defaultUVSOffset);
+      sub14->Records[i].defaultUVSOffset=defaultUVSOffset;
+      READ_ULONG (stream, nonDefaultUVSOffset);
+      sub14->Records[i].nonDefaultUVSOffset=nonDefaultUVSOffset;
+    }
+  for (i = 0; i < sub14->nRecords; i++) 
+    {
+      OTF_VariationSelectorRecord *record=&sub14->Records[i];
+      unsigned defaultUVSOffset = record->defaultUVSOffset;
+      unsigned nonDefaultUVSOffset = record->nonDefaultUVSOffset;
+      if (defaultUVSOffset) 
+       {
+         unsigned numUnicodeValueRanges;
+         SEEK_STREAM (stream, offset+defaultUVSOffset);
+         READ_ULONG (stream, numUnicodeValueRanges);
+         record->numUnicodeValueRanges = numUnicodeValueRanges;
+         OTF_MALLOC (record->unicodeValueRanges, 
+                     numUnicodeValueRanges,
+                     "(EncodingSubtable14-Records-unicodeValueRanges)");
+         for (j = 0; j < numUnicodeValueRanges; j++)
+           {
+             OTF_UnicodeValueRange *unicodeValueRange 
+               = &record->unicodeValueRanges[j];
+             unsigned startUnicodeValue;
+             char additionalCount;
+             READ_UINT24 (stream, startUnicodeValue);
+             unicodeValueRange->startUnicodeValue=startUnicodeValue;
+             READ_BYTES (stream, &additionalCount, 1);
+             unicodeValueRange->additionalCount = (unsigned short) additionalCount;
+           }
+       }
+      if (nonDefaultUVSOffset) 
+       {
+         unsigned numUVSMappings;
+         SEEK_STREAM (stream, offset+nonDefaultUVSOffset);
+         READ_ULONG (stream, numUVSMappings);
+         record->numUVSMappings = numUVSMappings;
+         OTF_MALLOC (record->uvsMappings, numUVSMappings,
+                     "(EncodingSubtable14-Records-uvsMappings)");
+         for (j = 0; j < numUVSMappings; j++)
+           {
+             OTF_UVSMapping *uvsMapping = &record->uvsMappings[j];
+             unsigned unicodeValue;
+             unsigned short glyphID;
+             READ_UINT24 (stream, unicodeValue);
+             uvsMapping->unicodeValue = unicodeValue;
+             READ_USHORT (stream, glyphID);
+             uvsMapping->glyphID = glyphID;
+           }
+       }
+      }
   return sub14;
 }
 
@@ -732,8 +798,7 @@ read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
          {
            cmap->EncodingRecord[i].subtable.f.f14
              = read_cmap_uvs_table (otf, stream,
-                                    cmap->EncodingRecord[i].subtable.length
-                                    - 6);
+                                    cmap->EncodingRecord[i].offset);
            break;
          }
 
@@ -757,7 +822,7 @@ read_cmap_table (OTF *otf, OTF_TableInfo *table, enum OTF_ReaderFlag flag)
 
            for (i = 0; i < segCount; i++)
              {
-               OTF_cmapSegument *seg = sub4->segments + i;
+               OTF_cmapSegment *seg = sub4->segments + i;
                int c;
 
                if (seg->idRangeOffset == 0xFFFF)