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;
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");
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() */
<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() */
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 ***/
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++)
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,
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++)
{
}
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
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++)
{
}
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;
}