(get_anchor): Delete it.
[m17n/libotf.git] / example / otfdump.c
index c589d16..f5961e5 100644 (file)
@@ -1,6 +1,6 @@
 /* otfdump.c -- Dump OpenType Layout Tables.
 
-Copyright (C) 2003, 2004
+Copyright (C) 2003, 2004, 2008
   National Institute of Advanced Industrial Science and Technology (AIST)
   Registration Number H15PRO167
 
@@ -23,10 +23,12 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <libgen.h>
 
 #include <otf.h>
 
@@ -304,10 +306,14 @@ dump_device_table (int indent, char *title, OTF_DeviceTable *table)
   indent++;
   IPRINT ("(StartSize %d) (EndSize %d) (DeltaFormat %d)",
          table->StartSize, table->EndSize, table->DeltaFormat);
-  IPRINT ("(DeltaValue");
-  for (i = 0; i < table->EndSize - table->StartSize + 1; i++)
-    printf (" %d", table->DeltaValue[i]);
-  printf ("))");
+  if (table->DeltaValue)
+    {
+      IPRINT ("(DeltaValue");
+      for (i = 0; i < table->EndSize - table->StartSize + 1; i++)
+       printf (" %d", table->DeltaValue[i]);
+      printf (")");
+    }
+  printf (")");
 }
 
 \f
@@ -709,13 +715,14 @@ dump_chain_class_set_list (int indent, OTF_ChainClassSet *set, int count)
 
   IPRINT ("(ChainClassSetCount %d)", count);
   for (i = 0; i < count; i++)
-    {
-      IPRINT ("(ChainClassSet (%d)", i);
-      dump_chain_class_rule_list (indent + 1,
-                                 set[i].ChainClassRule,
-                                 set[i].ChainClassRuleCnt);
-      printf (")");
-    }
+    if (set[i].offset)
+      {
+       IPRINT ("(ChainClassSet (%d)", i);
+       dump_chain_class_rule_list (indent + 1,
+                                   set[i].ChainClassRule,
+                                   set[i].ChainClassRuleCnt);
+       printf (")");
+      }
 }
 
 
@@ -865,8 +872,7 @@ dump_lookup_subtable_gsub (int indent, int index, unsigned type,
              subtable->u.extension1.ExtensionOffset);
       dump_lookup_subtable_gsub (indent, index, 
                                 subtable->u.extension1.ExtensionLookupType,
-                                (subtable
-                                 + subtable->u.extension1.ExtensionOffset));
+                                subtable->u.extension1.ExtensionSubtable);
       break;
 
     case 8:
@@ -995,7 +1001,38 @@ dump_lookup_subtable_gpos (int indent, int index, unsigned type,
     case 5:
       if (subtable->Format == 1)
        {
-         printf (" not-yet-supported");
+         OTF_GPOS_MarkLig1 *mark_lig1 = &subtable->u.mark_lig1;
+         int i, j, k;
+
+         free (dump_coverage (indent, "Mark", &subtable->Coverage));
+         free (dump_coverage (indent, "Ligature",
+                              &mark_lig1->LigatureCoverage));
+         IPRINT ("(ClassCount %d)", mark_lig1->ClassCount);
+         dump_mark_array (indent, &mark_lig1->MarkArray);
+         IPRINT ("(LigatureArray (%d)",
+                 mark_lig1->LigatureArray.LigatureCount);
+         indent++;
+         for (i = 0; i < mark_lig1->LigatureArray.LigatureCount; i++)
+           {
+             OTF_LigatureAttach *attach
+               = mark_lig1->LigatureArray.LigatureAttach + i;
+
+             IPRINT ("(LigatureAttach (%d)", attach->ComponentCount);
+             indent++;
+             for (j = 0; j < attach->ComponentCount; j++)
+               {
+                 OTF_ComponentRecord *rec = attach->ComponentRecord + j;
+
+                 IPRINT ("(LigatureAnchor (%d)", mark_lig1->ClassCount);
+                 for (k = 0; k < mark_lig1->ClassCount; k++)
+                   if (rec->LigatureAnchor[k].AnchorFormat)
+                     dump_anchor (indent + 1, rec->LigatureAnchor + k);
+                 printf (")");
+               }
+             printf (")");
+             indent--;
+           }
+         printf (")");
        }
       else
        printf (" invalid");
@@ -1089,6 +1126,21 @@ dump_lookup_subtable_gpos (int indent, int index, unsigned type,
       else
        printf (" invalid");
       break;
+
+    case 9:
+      if (subtable->Format == 1)
+       {
+         IPRINT ("(ExtensionLookupType %d)",
+                 subtable->u.extension1.ExtensionLookupType);
+         IPRINT ("(ExtensionOffset %d)",
+                 subtable->u.extension1.ExtensionOffset);
+         dump_lookup_subtable_gpos
+           (indent, index, 
+            subtable->u.extension1.ExtensionLookupType,
+            subtable->u.extension1.ExtensionSubtable);
+       }
+      else
+       printf (" invalid");
     }
   printf (")");
 }
@@ -1309,6 +1361,75 @@ dump_cmap_table (int indent, OTF_cmap *cmap)
            printf (")");
          }
          break;
+
+       case 12:
+         {
+           OTF_EncodingSubtable12 *sub12
+             = cmap->EncodingRecord[i].subtable.f.f12;
+           int j;
+
+           for (j = 0; j < sub12->nGroups; j++)
+             {
+               IPRINT ("(Group (#x%X) (startChar #x%04X) (endChar #x%04X) (startGlyphID #x%X))",
+                       j,
+                       sub12->Groups[j].startCharCode,
+                       sub12->Groups[j].endCharCode,
+                       sub12->Groups[j].startGlyphID);
+             }
+         }
+         break;
+
+       case 14:
+         {
+           OTF_EncodingSubtable14 *sub14
+             = cmap->EncodingRecord[i].subtable.f.f14;
+           unsigned j,k;
+
+           IPRINT ("(VariationSelectorRecords %d)",sub14->nRecords);
+           for (j = 0; j < sub14->nRecords; j++)
+             {
+               OTF_VariationSelectorRecord *record = sub14->Records + j;
+               IPRINT ("(VariationSelectorRecord (varSelector #x%x)",
+                       record->varSelector);
+               indent += 1;
+               IPRINT ("(defaultUVSOffset #x%x)",
+                       record->defaultUVSOffset);
+               if (record->defaultUVSOffset) 
+                 {
+                   IPRINT ("(defaultUVS");
+                   indent += 1;
+                   for (k = 0 ; k < record->numUnicodeValueRanges; k++)
+                     {
+                       OTF_UnicodeValueRange *unicodeValueRange
+                         = &record->unicodeValueRanges[k];
+                       IPRINT("(startUnicodeValue #x%x) (additionalCount %d)",
+                              unicodeValueRange->startUnicodeValue,
+                              unicodeValueRange->additionalCount);
+                     }
+                   printf (")");
+                   indent -= 1;
+                 }
+               IPRINT ("(nonDefaultUVSOffset #x%x)",
+                       record->nonDefaultUVSOffset);
+               if (record->nonDefaultUVSOffset) 
+                 {
+                   IPRINT ("(NonDefaultUVS");
+                   indent += 1;
+                   for (k=0; k < record->numUVSMappings; k++)
+                     {
+                       OTF_UVSMapping *uvsMapping
+                         = &record->uvsMappings[k];
+                       IPRINT("(unicodeValue #x%x) (glyphID %d)",
+                              uvsMapping->unicodeValue,
+                              uvsMapping->glyphID);
+                     }
+                   printf (")");
+                   indent -= 1;
+                 }
+               printf (")");
+               indent -= 1;
+             }
+         }
        }
 
       indent -= 2;
@@ -1387,10 +1508,10 @@ main (int argc, char **argv)
 {
   OTF *otf;
 
-  if (argc != 2)
+  if (argc != 2 || !strcmp (argv[1], "-h") || !strcmp (argv[1], "--help"))
     {
-      fprintf (stderr, "Usage, dtfdump OTF-FILE");
-      exit (1);
+      fprintf (stderr, "Usage: %s OTF-FILE\n", basename (argv[0]));
+      exit (argc != 2);
     }
   
   otf = OTF_open (argv[1]);