*** empty log message ***
[m17n/m17n-test.git] / flt.c
diff --git a/flt.c b/flt.c
index 23d894a..884782a 100644 (file)
--- a/flt.c
+++ b/flt.c
@@ -20,7 +20,7 @@
 #elif defined (FLT_HB)
 
 #include <m17n-flt.h>
-#include <harfbuzz.h>
+#include <hb.h>
 #define PROGNAME "flt-hb"
 
 #else  /* (defined (FLT_PANGO)) */
 #include <m17n-flt.h>
 #define PANGO_ENABLE_ENGINE
 #define PANGO_ENABLE_BACKEND
-#include <pango/pango.h>
+#include <pango/pangcairo.h>
 #include <pango/pango-ot.h>
-#include <pango/pangoft2.h>
-#include <pango/pangofc-font.h>
 
 #endif
 
@@ -303,61 +301,74 @@ encode_features (char *str, int count, unsigned *features)
   *str = '\0';
 }
 
+static OTF_GlyphString otf_gstring;
+
+static void
+setup_otf_gstring (int size)
+{
+  if (otf_gstring.size == 0)
+    {
+      otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size);
+      otf_gstring.size = size;
+    }
+  else if (otf_gstring.size < size)
+    {
+      otf_gstring.glyphs = xrealloc (otf_gstring.glyphs,
+                                    sizeof (OTF_Glyph) * size);
+      otf_gstring.size = size;
+    }
+  otf_gstring.used = size;
+  memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * size);
+}
+
 int
 drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
           MFLTGlyphString *in, int from, int to,
           MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment)
 {
-  int len = to - from;
-  int i, gidx;
   OTF *otf = ((FontInfoOTF *) font)->otf;
-  OTF_GlyphString otf_gstring;
+  int len = to - from;
+  int i, j, gidx;
   OTF_Glyph *otfg;
-  char script[4], langsys[4];
+  char script[5], *langsys = NULL;
   char *gsub_features = NULL, *gpos_features = NULL;
 
   if (len == 0)
     return from;
 
-  if (! otf)
-    goto simple_copy;
-  otf_gstring.glyphs = NULL;
-  if (OTF_get_table (otf, "head") < 0)
-    {
-      OTF_close (otf);
-      ((FontInfoOTF *) font)->otf = NULL;
-      goto simple_copy;
-    }
-
-  tag_name (script, spec->script);
-  tag_name (langsys, spec->langsys);
-
-  if (spec->gsub_count > 0)
+  OTF_tag_name (spec->script, script);
+  if (spec->langsys)
     {
-      gsub_features = alloca (6 * spec->gsub_count);
-      if (gsub_features)
-       {
-         if (OTF_check_table (otf, "GSUB") < 0)
-           gsub_features = NULL;
-         else
-           encode_features (gsub_features, spec->gsub_count, spec->gsub);
-       }
+      langsys = alloca (5);
+      OTF_tag_name (spec->langsys, langsys);
     }
-  if (spec->gpos_count)
+  for (i = 0; i < 2; i++)
     {
-      gpos_features = alloca (6 * spec->gpos_count);
-      if (gpos_features)
+      char *p;
+
+      if (spec->features[i] && spec->features[i][1] != 0xFFFFFFFF)
        {
-         if (OTF_check_table (otf, "GPOS") < 0)
-           gpos_features = NULL;
+         for (j = 0; spec->features[i][j]; j++);
+         if (i == 0)
+           p = gsub_features = alloca (6 * j);
          else
-           encode_features (gpos_features, spec->gpos_count, spec->gpos);
+           p = gpos_features = alloca (6 * j);
+         for (j = 0; spec->features[i][j]; j++)
+           {
+             if (spec->features[i][j] == 0xFFFFFFFF)
+               *p++ = '*', *p++ = ',';
+             else
+               {
+                 OTF_tag_name (spec->features[i][j], p);
+                 p[4] = ',';
+                 p += 5;
+               }
+           }
+         *--p = '\0';
        }
     }
 
-  otf_gstring.size = otf_gstring.used = len;
-  otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len);
-  memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len);
+  setup_otf_gstring (len);
   for (i = 0; i < len; i++)
     {
       otf_gstring.glyphs[i].c = in->glyphs[from + i].c;
@@ -530,6 +541,13 @@ open_font (char *fontname, char **err)
   font_info = malloc (sizeof (FontInfoOTF));
   font_info->face = face;
   font_info->otf = OTF_open_ft_face (face);
+  if (OTF_get_table (font_info->otf, "head") < 0)
+    {
+      OTF_close (font_info->otf);
+      FT_Done_Face (font_info->face);
+      free (font_info);
+      return NULL;
+    }
   return ((MFLTFont *) font_info);
 }