*** empty log message ***
authorhanda <handa>
Tue, 10 Dec 2002 13:11:07 +0000 (13:11 +0000)
committerhanda <handa>
Tue, 10 Dec 2002 13:11:07 +0000 (13:11 +0000)
example/otfdraw.c
src/otf.h
src/otfdrive.c
src/otfopen.c

index c71ee43..9f5040a 100644 (file)
@@ -95,8 +95,8 @@ main (int argc, char **argv)
   gstring.glyphs[gstring.used++].c = 0x940;
 #else
   gstring.glyphs[gstring.used++].c = 0x92A;
-  gstring.glyphs[gstring.used++].c = 0x94D;
   gstring.glyphs[gstring.used++].c = 0x930;
+  gstring.glyphs[gstring.used++].c = 0x94D;
   gstring.glyphs[gstring.used++].c = 0x924;
   gstring.glyphs[gstring.used++].c = 0x94D;
   gstring.glyphs[gstring.used++].c = 0x92F;
@@ -106,13 +106,13 @@ main (int argc, char **argv)
   otf_drive_cmap (otf, &gstring);
   otf_drive_gdef (otf, &gstring);
   otf_dump_gstring (&gstring);
-  if (otf_drive_gsub (otf, otf_tag ("deva"), 0, &gstring) < 0)
+  if (otf_drive_gsub (otf, &gstring, "deva", NULL, NULL) < 0)
     printf ("otf_gsub error\n");
   else
     printf ("RESULT of GSUB\n");
   otf_dump_gstring (&gstring);
 
-  if (otf_drive_gpos (otf, otf_tag ("deva"), 0, &gstring) < 0)
+  if (otf_drive_gpos (otf, &gstring, "deva", NULL, NULL) < 0)
     printf ("otf_gsub error\n");
   else
     printf ("RESULT of GPOS\n");
index ea3ab98..f6e556c 100644 (file)
--- a/src/otf.h
+++ b/src/otf.h
@@ -1140,8 +1140,8 @@ extern int otf_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
     string $GSTRING.  It may substitute, delete, insert glyphs in that
     array.  */
 
-extern int otf_drive_gsub (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
-                          OTF_GlyphString *gstring);
+extern int otf_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
+                          char *script, char *language, char *features);
 
 /*** (3-5) otf_drive_gpos() */
 
@@ -1154,9 +1154,8 @@ extern int otf_drive_gsub (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
     <positioning_type> and <f> of all glhphs in the glyph string
     $GSTRING.  */
 
-extern int otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
-                          OTF_GlyphString *gstring);
-
+extern int otf_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
+                          char *script, char *language, char *features);
 
 /*** (3-6) otf_drive_tables() */
 
@@ -1167,8 +1166,8 @@ extern int otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
     otf_drive_gdef(), otf_drive_gsub(), and otf_drive_gpos() in this
     order, and update the glyphs string GSTRING.  */
 
-extern int otf_drive_tables (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
-                            OTF_GlyphString *gstring);
+extern int otf_drive_tables (OTF *otf, OTF_GlyphString *gstring,
+                            char *script, char *language);
 
 
 /*** (4) APIs for error handling ***/
index 3f6d328..dedbec3 100644 (file)
@@ -71,10 +71,34 @@ get_coverage_index (OTF_Coverage *coverage, OTF_GlyphID id)
   return -1;
 }
 
+static unsigned
+get_class_def (OTF_ClassDef *class_def, OTF_GlyphID glyph_id)
+{
+  if (class_def->ClassFormat == 1)
+    {
+      int idx = (int) glyph_id - (int) class_def->f.f1.StartGlyph;
+
+      if (idx >= 0 && idx < class_def->f.f1.GlyphCount)
+       return class_def->f.f1.ClassValueArray[idx];
+    }
+  else
+    {
+      int i;
+
+      for (i = 0; i < class_def->f.f2.ClassRangeCount; i++)
+       if (glyph_id >= class_def->f.f2.ClassRangeRecord[i].Start
+           && glyph_id >= class_def->f.f2.ClassRangeRecord[i].End)
+         return class_def->f.f2.ClassRangeRecord[i].Class;
+    }
+  return 0;
+}
+
 static OTF_LangSys *
-get_langsys (OTF_ScriptList *script_list,
-            OTF_Tag script_tag, OTF_Tag langsys_tag)
+get_langsys (OTF_ScriptList *script_list, char *script, char *language)
 {
+
+  OTF_Tag script_tag = otf_tag (script);
+  OTF_Tag langsys_tag = otf_tag (language);
   int i, j;
 
   for (i = 0; i < script_list->ScriptCount; i++)
@@ -93,28 +117,51 @@ get_langsys (OTF_ScriptList *script_list,
   return NULL;
 }
 
-static unsigned
-get_class_def (OTF_ClassDef *class_def, OTF_GlyphID glyph_id)
+static int
+get_feature_index (OTF_LangSys *LangSys, OTF_FeatureList *FeatureList,
+                  char *features, int *feature_index)
 {
-  if (class_def->ClassFormat == 1)
+  int nfeatures = 0;
+
+  if (features)
     {
-      int idx = (int) glyph_id - (int) class_def->f.f1.StartGlyph;
+      char *p0, *p1;
+      int len = strlen (features) + 1;
 
-      if (idx >= 0 && idx < class_def->f.f1.GlyphCount)
-       return class_def->f.f1.ClassValueArray[idx];
+      p0 = alloca (len);
+      for (p1 = p0; *p1; p1++)
+       if (*p1 == ':')
+         *p1 = '\0';
+      
+      while (len > 0)
+       {
+         int this_len = strlen (p0) + 1;
+         OTF_Tag tag = otf_tag (p0);
+
+         if (tag)
+           {
+             int i;
+
+             for (i = 0; i < FeatureList->FeatureCount; i++)
+               if (tag == FeatureList->Feature[i].FeatureTag)
+                 {
+                   feature_index[nfeatures++] = i;
+                   if (nfeatures == FeatureList->FeatureCount)
+                     break;
+                 }
+           }
+         p0 += this_len;
+         len -= this_len;
+       }
     }
   else
     {
-      int i;
-
-      for (i = 0; i < class_def->f.f2.ClassRangeCount; i++)
-       if (glyph_id >= class_def->f.f2.ClassRangeRecord[i].Start
-           && glyph_id >= class_def->f.f2.ClassRangeRecord[i].End)
-         return class_def->f.f2.ClassRangeRecord[i].Class;
+      for (; nfeatures < LangSys->FeatureCount; nfeatures++)
+       feature_index[nfeatures] = LangSys->FeatureIndex[nfeatures];
     }
-  return 0;
-}
 
+  return nfeatures;
+}
 
 static int
 lookup_gsub (OTF_LookupList *lookup_list, unsigned lookup_list_index,
@@ -492,66 +539,38 @@ otf_drive_gdef (OTF *otf, OTF_GlyphString *gstring)
 
 
 int
-otf_drive_gsub (OTF *otf, char *script, char *language, char *features,
-               OTF_GlyphString *gstring)
+otf_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
+               char *script, char *language, char *features)
 {
+  char *errfmt = "GSUB driving%s";
+  int errret = -1;
   OTF_GSUB *gsub;
   OTF_LangSys *LangSys;
+  int nfeatures;
+  int *feature_index;
   int i, j;
-  OTF_Tag script_tag, layngsys_tag;
 
   if (! otf->gsub
       && otf_get_table (otf, "GSUB") < 0)
     return -1;
   gsub = otf->gsub;
 
-  script_tag = otf_tag (script);
-  langsys_tag = otf_tag (language);
-  langsys = get_langsys (&gsub->ScriptList, script_tag, langsys_tag);
-  if (! langsys)
+  LangSys = get_langsys (&gsub->ScriptList, script, language);
+  if (! LangSys)
     return -1;
 
-  if (features)
-    {
-      int len = strlen (features);
-      char name[5];
-      int i = 0;
-      OTF_Tag tag;
-      
-      while (*features)
-       {
-         if (i == 4 || *features == ':')
-           {
-             name[i] = '\0';
-             tag = otf_tag (name);
-             if (tag)
-               {
-                 feature_tags[nfeatures++] = tag;
-                 if (nfeatures == langsys->FeatureCount)
-                   break;
-               }
-             i = 0;
-             if (*features == ':')
-               features++;
-           }
-         else
-           name[i++] = *features++;
-       }
-      if (i > 0
-         && (tag = otf_tag (name)))
-       feature_tags[nfeatures++] = tag;
-    }
-  else
-    {
-      for (i = 0; i < langsys->FeatureCount; i++)
-       feature_tags[nfeatures++] = 
-
+  feature_index = alloca (sizeof (int) * gsub->FeatureList.FeatureCount);
+  if (! feature_index)
+    OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
 
+  nfeatures = get_feature_index (LangSys, &gsub->FeatureList,
+                                features, feature_index);
+  if (nfeatures == 0)
+    OTF_ERROR (OTF_ERROR_GSUB_DRIVE, " no feature");
 
-  for (i = 0; i < langsys->FeatureCount; i++)
+  for (i = 0; i < nfeatures; i++)
     {
-      OTF_Feature *feature
-       = gsub->FeatureList.Feature + langsys->FeatureIndex[i];
+      OTF_Feature *feature = gsub->FeatureList.Feature + feature_index[i];
 
       for (j = 0; j < feature->LookupCount; j++)
        {
@@ -567,11 +586,15 @@ otf_drive_gsub (OTF *otf, char *script, char *language, char *features,
 }
 
 int
-otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
-         OTF_GlyphString *gstring)
+otf_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
+               char *script, char *language, char *features)
 {
+  char *errfmt = "GPOS driving%s";
+  int errret = -1;
   OTF_GPOS *gpos;
-  OTF_LangSys *langsys;
+  OTF_LangSys *LangSys;
+  int nfeatures;
+  int *feature_index;
   int i, j;
 
   if (! otf->gpos
@@ -579,14 +602,22 @@ otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
     return -1;
   gpos = otf->gpos;
 
-  langsys = get_langsys (&gpos->ScriptList, script_tag, langsys_tag);
-  if (! langsys)
+  LangSys = get_langsys (&gpos->ScriptList, script, language);
+  if (! LangSys)
     return -1;
 
-  for (i = 0; i < langsys->FeatureCount; i++)
+  feature_index = alloca (sizeof (int) * gpos->FeatureList.FeatureCount);
+  if (! feature_index)
+    OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
+
+  nfeatures = get_feature_index (LangSys, &gpos->FeatureList,
+                                features, feature_index);
+  if (nfeatures == 0)
+    OTF_ERROR (OTF_ERROR_GSUB_DRIVE, " no feature");
+
+  for (i = 0; i < nfeatures; i++)
     {
-      OTF_Feature *feature
-       = gpos->FeatureList.Feature + langsys->FeatureIndex[i];
+      OTF_Feature *feature = gpos->FeatureList.Feature + feature_index[i];
 
       for (j = 0; j < feature->LookupCount; j++)
        {
@@ -602,16 +633,16 @@ otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
 }
 
 int
-otf_drive_tables (OTF *otf, OTF_Tag script, OTF_Tag langsys,
-                 OTF_GlyphString *gstring)
+otf_drive_tables (OTF *otf, OTF_GlyphString *gstring,
+                 char *script, char *language)
 {
   if (otf_drive_cmap (otf, gstring) < 0)
     return -1;
   if (otf_drive_gdef (otf, gstring) < 0)
     return -1;
-  if (otf_drive_gsub (otf, script, langsys, gstring) < 0)
+  if (otf_drive_gsub (otf, gstring, script, language, NULL) < 0)
     return -1;
-  if (otf_drive_gpos (otf, script, langsys, gstring) < 0)
+  if (otf_drive_gpos (otf, gstring, script, language, NULL) < 0)
     return -1;
   return 0;
 }
index cef7e16..ad10f47 100644 (file)
@@ -46,7 +46,7 @@ make_stream ()
   char *errfmt = "stream creation%s";
   void *errret = NULL;
 
-  stream = malloc (sizeof (OTF_Stream));
+  stream = calloc (1, sizeof (OTF_Stream));
   if (! stream)
     OTF_ERROR (OTF_ERROR_MEMORY, "");
   return stream;