X-Git-Url: http://git.chise.org/gitweb/?p=m17n%2Fm17n-test.git;a=blobdiff_plain;f=flt.c;h=884782a1e266b7ff1bf97b979bf333cabdced9e7;hp=5cf2479de07582dcd00a684c5724fffac7924ff9;hb=HEAD;hpb=1cf616637034fe2f47296758983c415b25966d17 diff --git a/flt.c b/flt.c index 5cf2479..884782a 100644 --- a/flt.c +++ b/flt.c @@ -9,34 +9,32 @@ #if defined (FLT_GUI) #include -#include #define PROGNAME "flt-gui" #elif defined (FLT_OTF) #include -#include #include #define PROGNAME "flt-otf" #elif defined (FLT_HB) #include -#include +#include #define PROGNAME "flt-hb" #else /* (defined (FLT_PANGO)) */ #include -#include #define PANGO_ENABLE_ENGINE #define PANGO_ENABLE_BACKEND -#include +#include #include -#include -#include + #endif +#include + static FT_Library ft_library; int @@ -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); }