*** empty log message ***
authorhanda <handa>
Fri, 17 Oct 2003 13:06:22 +0000 (13:06 +0000)
committerhanda <handa>
Fri, 17 Oct 2003 13:06:22 +0000 (13:06 +0000)
example/otfimage.c
src/otfdrive.c

index 0a23a7a..d68411b 100644 (file)
@@ -1,9 +1,4 @@
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <libgen.h>
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
 FT_Face face;
 
-void
-dump_image (int pixel_size, int index)
+int
+dump_image (int pixel_size, int index, int code, int full)
 {
   int err = FT_Load_Glyph (face, index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
   int i,j, size;
   unsigned char *buf;
   
   if (err)
-    return;
+    return -1;
   size = face->glyph->bitmap.rows * face->glyph->bitmap.width;
   if (! size)
-    return;
+    return -1;
   buf = (unsigned char *) face->glyph->bitmap.buffer;
-  printf ("(#x%02X \"P4 %d %d ",
-         index, face->glyph->bitmap.width, face->glyph->bitmap.rows);
+  printf ("(#x%04X \"P4 %d %d ",
+         code, face->glyph->bitmap.width, face->glyph->bitmap.rows);
   for (i = 0; i < face->glyph->bitmap.rows; i++)
     for (j = 0; j < (face->glyph->bitmap.width + 7) / 8; j++)
       {
        printf("\\%o", buf[i * face->glyph->bitmap.pitch + j]);
       }
   printf ("\")\n");
+  return 0;
 }
 
 /* Format MSG by FMT and print the result to the stderr, and exit.  */
@@ -50,6 +46,9 @@ main (int argc, char **argv)
   int err;
   int i;
   int pixel_size = DEFAULT_PIXEL_SIZE;
+  FT_Uint *raw_table;
+  FT_UInt unicode_table[0x80];
+  int max_glyph_id;
 
   if (argc != 2)
     FATAL_ERROR ("%s\n", "Usage: otfimage [ X-OPTION ... ]  OTF-FILE");
@@ -71,8 +70,23 @@ main (int argc, char **argv)
       pixel_size = i;
   }
 
+  for (i = 0, max_glyph_id = 0; i < 0x10000; i++)
+    if (FT_Load_Glyph (face, i, FT_LOAD_RENDER | FT_LOAD_MONOCHROME)
+
+
+  for (i = 0x0D00; i < 0x0D80; i++)
+    {
+      unicode_table[i - 0x0D00] = FT_Get_Char_Index (face, (FT_ULong) i);
+      if (unicode_table[i - 0x0D00])
+       printf ("%04X->%04X\n", i, unicode_table[i - 0x0D00]);
+    }
+
+  for (i = 0; i < 0x80; i++)
+    if (unicode_table[i])
+      dump_image (pixel_size, unicode_table[i], 0x0D00 + i, 1);
   for (i = 0; i < 0x10000; i++)
-    dump_image (pixel_size, i);
+    dump_image (pixel_size, i, 0x0E00 + i, 0);
+  
 
   exit (0);
 }
index ffc9926..4e644d5 100644 (file)
@@ -141,7 +141,7 @@ get_langsys (OTF_ScriptList *script_list, char *script, char *language)
 }
 
 static int
-setup_lookup_indices (OTF_LangSys *LangSys, OTF_FeatureList *FeatureList,
+setup_lookup_indices (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
                      char *features, int *lookup_indices)
 {
   int i, j, n = 0;
@@ -160,13 +160,23 @@ setup_lookup_indices (OTF_LangSys *LangSys, OTF_FeatureList *FeatureList,
       if (*features == '*')
        {
          /* Consume all remaining features.  */
+         /* We are sure that the last LookupCount elements of
+            lookup_indices are free to be used for this work.  */
+         int *free_table = (lookup_indices + (LookupList->LookupCount
+                                              * FeatureList->FeatureCount));
+
+         for (i = 0; i < LookupList->LookupCount; i++)
+           free_table[i] = 0;
          for (i = 0; i < FeatureList->FeatureCount; i++)
            if (! feature_table[i])
              {
                feature = FeatureList->Feature + i;
                for (j = 0; j < feature->LookupCount; j++)
-                 lookup_indices[n++] = feature->LookupListIndex[j];
+                 free_table[feature->LookupListIndex[j]] = 1;
              }
+         for (i = 0; i < LookupList->LookupCount; i++)
+           if (free_table[i])
+             lookup_indices[n++] = i;
          break;
        }
 
@@ -214,17 +224,22 @@ match_ids (OTF_GlyphString *gstring, int gidx, int count, OTF_GlyphID *ids)
 static int
 match_chain_ids (OTF_GlyphString *gstring, int gidx, OTF_ChainRule *rule)
 {
-  int i, j;
+  int i = rule->BacktrackGlyphCount;
 
-  for (i = rule->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
-    if (gstring->glyphs[j].glyph_id)
-      i--;
   if (i > 0)
-    return -1;
+    {
+      int j;
 
-  i = match_ids (gstring, j, rule->BacktrackGlyphCount, rule->Backtrack);
-  if (i < 0)
-    return -1;
+      for (j = gidx - 1; j >= 0; j--)
+       if (gstring->glyphs[j].glyph_id
+           && --i == 0)
+         break;
+      if (i > 0)
+       return -1;
+      if (match_ids (gstring, j, rule->BacktrackGlyphCount, rule->Backtrack)
+         < 0)
+       return -1;
+    }
   gidx++;
   i = match_ids (gstring, gidx, rule->InputGlyphCount - 1, rule->Input);
   if (i < 0)
@@ -259,18 +274,22 @@ match_chain_classes (OTF_GlyphString *gstring, int gidx,
                     OTF_ClassDef *LookaheadClassDef,
                     OTF_ChainClassRule *rule)
 {
-  int i, j;
+  int i = rule->BacktrackGlyphCount;
 
-  for (i = rule->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
-    if (gstring->glyphs[j].glyph_id)
-      i--;
   if (i > 0)
-    return -1;
+    {
+      int j;
 
-  i = match_classes (BacktrackClassDef, gstring, j,
-                    rule->BacktrackGlyphCount, rule->Backtrack);
-  if (i < 0)
-    return -1;
+      for (j = gidx - 1; j >= 0 && i > 0; j--)
+       if (gstring->glyphs[j].glyph_id
+           && i-- == 0)
+         break;
+      if (i > 0)
+       return -1;
+      if (match_classes (BacktrackClassDef, gstring, j,
+                        rule->BacktrackGlyphCount, rule->Backtrack) < 0);
+      return -1;
+    }
   gidx++;
   i = match_classes (InputClassDef, gstring, gidx,
                     rule->InputGlyphCount - 1, rule->Input);
@@ -296,7 +315,7 @@ match_coverages (OTF_GlyphString *gstring, int gidx, int count,
 
   for (g = gbeg, i = 0; g < gend && i < count; g++)
     if (g->glyph_id
-       && get_coverage_index (coverages + i, g->glyph_id) < 0)
+       && get_coverage_index (coverages + i++, g->glyph_id) < 0)
       return -1;
   return (i < count ? -1 : g - gbeg);
 }
@@ -305,32 +324,33 @@ static int
 match_chain_coverages (OTF_GlyphString *gstring, int gidx,
                       OTF_GSUB_ChainContext3 *context3)
 {
-  int i, j;
-
-  if (gidx < context3->BacktrackGlyphCount
-      || (gidx + context3->InputGlyphCount
-         + context3->LookaheadGlyphCount) >= gstring->used)
-    return -1;
+  int i = context3->BacktrackGlyphCount;
 
-  for (i = context3->BacktrackGlyphCount, j = gidx - 1; j >= 0 && i > 0; j--)
-    if (gstring->glyphs[j].glyph_id)
-      i--;
   if (i > 0)
-    return -1;
+    {
+      int j;
 
-  i = match_coverages (gstring, j, context3->BacktrackGlyphCount,
-                      context3->Backtrack);
-  if (i < 0)
-    return -1;
+      for (j = gidx - 1; j >= 0; j--)
+       if (gstring->glyphs[j].glyph_id
+           && --i == 0)
+         break;
+      if (i > 0)
+       return -1;
+      if (match_coverages (gstring, j, context3->BacktrackGlyphCount,
+                          context3->Backtrack) < 0)
+       return -1;
+    }
   gidx++;
-  i = match_coverages (gstring, gidx, context3->InputGlyphCount - 1,
-                      context3->Input + 1);
-  if (i < 0)
-    return -1;
-  gidx += i;
-  i = match_coverages (gstring, gidx, context3->LookaheadGlyphCount,
-                      context3->LookAhead);
-  if (i < 0)
+  if (context3->InputGlyphCount > 1)
+    {
+      i = match_coverages (gstring, gidx, context3->InputGlyphCount - 1,
+                          context3->Input + 1);
+      if (i < 0)
+       return -1;
+      gidx += i;
+    }
+  if (match_coverages (gstring, gidx, context3->LookaheadGlyphCount,
+                      context3->LookAhead) < 0)
     return -1;
   return 0;
 }
@@ -523,7 +543,7 @@ lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index,
 
                  if (gidx < rule->BacktrackGlyphCount
                      || (gidx + rule->InputGlyphCount
-                         + rule->LookaheadGlyphCount) >= gstring->used)
+                         + rule->LookaheadGlyphCount) > gstring->used)
                    continue;
                  if (match_chain_ids (gstring, gidx, rule) < 0)
                    continue;
@@ -555,7 +575,7 @@ lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index,
 
                  if (gidx < rule->BacktrackGlyphCount
                      || (gidx + rule->InputGlyphCount
-                         + rule->LookaheadGlyphCount) >= gstring->used)
+                         + rule->LookaheadGlyphCount) > gstring->used)
                    continue;
                  if (match_chain_classes (gstring, gidx,
                                           &context2->BacktrackClassDef,
@@ -579,6 +599,10 @@ lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              int orig_used;
              int j;
 
+             if (gidx < context3->BacktrackGlyphCount
+                 || (gidx + context3->InputGlyphCount
+                     + context3->LookaheadGlyphCount) > gstring->used)
+               return -1;
              if (match_chain_coverages (gstring, gidx, context3) < 0)
                continue;
              orig_used = gstring->used;
@@ -865,7 +889,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
 
                  if (gidx < rule->BacktrackGlyphCount
                      || (gidx + rule->InputGlyphCount
-                         + rule->LookaheadGlyphCount) >= gstring->used)
+                         + rule->LookaheadGlyphCount) > gstring->used)
                    continue;
                  for (k = 0; k < rule->BacktrackGlyphCount; k++)
                    if (get_class_def (&context2->BacktrackClassDef,
@@ -1018,10 +1042,10 @@ OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
   /* One lookup may be used by multiple features.  */
   lookup_indices = alloca (sizeof (int)
                           * gsub->LookupList.LookupCount
-                          * gsub->FeatureList.FeatureCount);
+                          * (gsub->FeatureList.FeatureCount + 1));
   if (! lookup_indices)
     OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
-  n = setup_lookup_indices (LangSys, &gsub->FeatureList,
+  n = setup_lookup_indices (&gsub->LookupList, &gsub->FeatureList,
                            features, lookup_indices);
   if (n < 0)
     return errret;
@@ -1082,10 +1106,10 @@ OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
   /* One lookup may be used by multiple features.  */
   lookup_indices = alloca (sizeof (int)
                           * gpos->LookupList.LookupCount
-                          * gpos->FeatureList.FeatureCount);
+                          * (gpos->FeatureList.FeatureCount + 1));
   if (! lookup_indices)
     OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
-  n = setup_lookup_indices (LangSys, &gpos->FeatureList,
+  n = setup_lookup_indices (&gpos->LookupList, &gpos->FeatureList,
                            features, lookup_indices);
   if (n < 0)
     return errret;