(print_anchor, print_glyph_positioning): New functions.
authorhanda <handa>
Sat, 7 Nov 2009 02:20:40 +0000 (02:20 +0000)
committerhanda <handa>
Sat, 7 Nov 2009 02:20:40 +0000 (02:20 +0000)
(lookup_gpos): Improve debug info printing.

src/otfdrive.c

index 8dc6dba..0b2ef60 100644 (file)
@@ -773,6 +773,65 @@ gstring_insert_for_gpos (OTF_GlyphString *gstring, int gidx)
   return gidx;
 }
 
+static void
+print_anchor (char *head, OTF_Anchor *anchor)
+{
+  if (anchor->AnchorFormat == 1)
+    fprintf (stderr, " %s(X:%d Y:%d)", head,
+            anchor->XCoordinate, anchor->YCoordinate);
+  else if (anchor->AnchorFormat == 2)
+    fprintf (stderr, " %s(X:%d Y:%d AP:%d)", head,
+            anchor->XCoordinate, anchor->YCoordinate,
+            anchor->f.f1.AnchorPoint);
+  else
+    fprintf (stderr, " %s(X:%d Y:%d +alpha)", head,
+            anchor->XCoordinate, anchor->YCoordinate);
+}
+
+static void
+print_glyph_positioning (OTF_Glyph *g, int type)
+{
+  if (type)
+    fprintf (stderr, " %0X=", g->glyph_id);
+  switch (g->positioning_type)
+    {
+    case 1: case 2:
+      {
+       int format = g->f.f1.format;
+
+       if (format & OTF_XPlacement)
+         fprintf (stderr, "X:%d", g->f.f1.value->XPlacement);
+       if (format & OTF_XPlaDevice)
+         fprintf (stderr, "+alpha");
+       if (format & OTF_YPlacement)
+         fprintf (stderr, "Y:%d", g->f.f1.value->YPlacement);
+       if (format & OTF_YPlaDevice)
+         fprintf (stderr, "+alpha");
+       if (format & OTF_XAdvance)
+         fprintf (stderr, "X+:%d", g->f.f1.value->XAdvance);
+       if (format & OTF_XAdvDevice)
+         fprintf (stderr, "+alpha");
+       break;
+      }
+    case 3:
+      print_anchor ("entry", g->f.f3.entry_anchor);
+      print_anchor ("exit", g->f.f3.entry_anchor);
+      break;
+    case 4:
+      print_anchor ("mark", g->f.f4.mark_anchor);
+      print_anchor ("base", g->f.f4.base_anchor);
+      break;
+    case 5:
+      print_anchor ("mark", g->f.f5.mark_anchor);
+      print_anchor ("lig", g->f.f5.ligature_anchor);
+      break;
+    case 6:
+      print_anchor ("mark1", g->f.f6.mark1_anchor);
+      print_anchor ("mark2", g->f.f6.mark2_anchor);
+      break;
+    }
+}
+
 static int
 lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
             OTF_GlyphString *gstring, int gidx, int accumulate)
@@ -787,12 +846,12 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
   int i;
 
   if (debug_flag)
-    fprintf (stderr, "[GPOS] glyph:%X lookup(%d)",
+    fprintf (stderr, "[GPOS] glyph:%04X lookup:%02d",
             g->glyph_id, lookup_list_index);
   if (IGNORED_GLYPH (g, flag))
     {
       if (debug_flag)
-       fprintf (stderr, " ignored glyph\n");
+       fprintf (stderr, " glyph ignored\n");
       return (gidx + 1);
     }
 
@@ -816,7 +875,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
        }
 
       if (debug_flag)
-       fprintf (stderr, " type(%d)", lookup_type);
+       fprintf (stderr, "/%d", lookup_type);
       if (subtable->Coverage.offset)
        {
          coverage_idx = get_coverage_index (&subtable->Coverage,
@@ -851,6 +910,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
          g->positioning_type = positioning_type;
          g->f.f1.format = format;
          g->f.f1.value = value;
+         if (debug_flag)
+           print_glyph_positioning (g, 0);
          gidx++;
          break;
 
@@ -886,6 +947,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                          g->positioning_type = lookup_type;
                          g->f.f2.format = pair1->ValueFormat1;
                          g->f.f2.value = &set->PairValueRecord[j].Value1;
+                         if (debug_flag)
+                           print_glyph_positioning (g, 1);
                        }
                      gidx = next_gidx;
                      g = nextg;
@@ -899,7 +962,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                          g->positioning_type = lookup_type;
                          g->f.f2.format = pair1->ValueFormat2;
                          g->f.f2.value = &set->PairValueRecord[j].Value2;
-                         gidx++;
+                         if (debug_flag)
+                           print_glyph_positioning (g, 2);
                        }
                      break;
                    }
@@ -924,6 +988,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    g->f.f2.format = pair2->ValueFormat1;
                    g->f.f2.value
                      = &pair2->Class1Record[class1].Class2Record[class2].Value1;
+                   if (debug_flag)
+                     print_glyph_positioning (g, 1);
                  }
                gidx = next_gidx;
                g = nextg;
@@ -938,7 +1004,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    g->f.f2.format = pair2->ValueFormat2;
                    g->f.f2.value
                      = &pair2->Class1Record[class1].Class2Record[class2].Value2;
-                   gidx++;
+                   if (debug_flag)
+                     print_glyph_positioning (g, 2);
                  }
              }
          }
@@ -948,16 +1015,13 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
          {
            OTF_GPOS_Cursive1 *cursive1 = &subtable->u.cursive1;
          
-           if (accumulate && g->positioning_type)
-             {
-               gidx = gstring_insert_for_gpos (gstring, gidx);
-               g = gstring->glyphs + gidx;
-             }
            g->positioning_type = lookup_type;
            g->f.f3.entry_anchor
              = &cursive1->EntryExitRecord[coverage_idx].EntryAnchor;
            g->f.f3.exit_anchor
              = &cursive1->EntryExitRecord[coverage_idx].ExitAnchor;
+           if (debug_flag)
+             print_glyph_positioning (g, 0);
            gidx++;
          }
          break;
@@ -987,15 +1051,12 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              mark_record = mark_base1->MarkArray.MarkRecord + coverage_idx;
              base_record
                = mark_base1->BaseArray.AnchorRecord + coverage_idx_base;
-             if (accumulate && g->positioning_type)
-               {
-                 gidx = gstring_insert_for_gpos (gstring, gidx);
-                 g = gstring->glyphs + gidx;
-               }
              g->f.f4.mark_anchor = &mark_record->MarkAnchor;
              g->f.f4.base_anchor
                = &base_record->Anchor[mark_record->Class];
              g->positioning_type = lookup_type;
+             if (debug_flag)
+               print_glyph_positioning (g, 0);
              gidx++;
            }
          break;
@@ -1043,14 +1104,11 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                  if (lig_anchor[mark_record->Class].AnchorFormat
                      && num_class[mark_record->Class]-- == 0)
                    {
-                     if (accumulate && g->positioning_type)
-                       {
-                         gidx = gstring_insert_for_gpos (gstring, gidx);
-                         g = gstring->glyphs + gidx;
-                       }
                      g->positioning_type = lookup_type;
                      g->f.f5.mark_anchor = &mark_record->MarkAnchor;
                      g->f.f5.ligature_anchor = lig_anchor + mark_record->Class;
+                     if (debug_flag)
+                       print_glyph_positioning (g, 0);
                      gidx++;
                      break;
                    }
@@ -1082,15 +1140,12 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              mark1_record = mark_mark1->Mark1Array.MarkRecord + coverage_idx;
              mark2_record
                = mark_mark1->Mark2Array.AnchorRecord + coverage_idx_base;
-             if (accumulate && g->positioning_type)
-               {
-                 gidx = gstring_insert_for_gpos (gstring, gidx);
-                 g = gstring->glyphs + gidx;
-               }
              g->f.f6.mark1_anchor = &mark1_record->MarkAnchor;
              g->f.f6.mark2_anchor
                = &mark2_record->Anchor[mark1_record->Class];
              g->positioning_type = lookup_type;
+             if (debug_flag)
+               print_glyph_positioning (g, 0);
              gidx++;
              break;
            }
@@ -1275,7 +1330,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
       gidx++;
     }
   else if (debug_flag)
-    fprintf (stderr, " match %d glyphs\n", gidx - orig_gidx);
+    fprintf (stderr, "\n");
   return gidx;
 }