From b153a79676efaca5618e30975862e82d2013690d Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 26 May 2005 00:32:31 +0000 Subject: [PATCH] (langsys_tag): New variable. (get_features): Check if rec->langsys and rec->features are not NULL. (update_seq_area): Delete unused var. (setup_feature_rec): Setup rec->langsys correctly. Don't allocate rec->features here. (compose_script_langsys, decompose_script_langsys): New functions. (ScriptProc): Fix handling of the arg call_data. (create_otf_script_widgets): Check all langsys. Allocate gsub.features and gpos.features here. (create_otf_widgets): Delete unused var. --- example/otfview.c | 207 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 154 insertions(+), 53 deletions(-) diff --git a/example/otfview.c b/example/otfview.c index 6d2baf8..ea150e6 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -111,7 +111,8 @@ typedef struct FeatureRec gsub, gpos; -OTF_Tag script_tag; +/* Currently selected script and langsys. */ +OTF_Tag script_tag, langsys_tag; int glyph_char[128]; @@ -238,7 +239,7 @@ get_features (OTF_FeatureList *list, FeatureRec *rec) int i, n; char *str, *p; - if (! rec->features[0].on) + if (! rec->langsys || ! rec->features || ! rec->features[0].on) return NULL; for (i = n = 0; i < rec->langsys->FeatureCount; i++) { @@ -369,7 +370,6 @@ update_seq_area () int xoff = 0, yoff = 0; int prev_width; int advance = bmp->advance; - int j; if (! bmp->pixmap) { @@ -793,34 +793,31 @@ FeatureProc (Widget w, XtPointer client_data, XtPointer call_data) void setup_feature_rec (FeatureRec *rec) { - int i; + int i, j; Arg arg[10]; rec->langsys = NULL; + if (! rec->gsub_gpos) + return; for (i = 0; i < rec->gsub_gpos->ScriptList.ScriptCount; i++) if (rec->gsub_gpos->ScriptList.Script[i].ScriptTag == script_tag) { - rec->langsys = &rec->gsub_gpos->ScriptList.Script[i].DefaultLangSys; + OTF_Script *script = rec->gsub_gpos->ScriptList.Script + i; + + if (langsys_tag) + { + for (j = 0; j < script->LangSysCount; j++) + if (script->LangSysRecord[j].LangSysTag == langsys_tag) + { + rec->langsys = script->LangSys + j; + break; + } + } + if (! rec->langsys) + rec->langsys = &rec->gsub_gpos->ScriptList.Script[i].DefaultLangSys; break; } - if (! rec->features) - { - rec->num_features = rec->langsys->FeatureCount; - rec->features = malloc ((sizeof (FeatureElement)) * rec->num_features); - memset (rec->features, 0, (sizeof (FeatureElement)) * rec->num_features); - } - else if (rec->num_features < rec->langsys->FeatureCount) - { - rec->features = realloc (rec->features, - (sizeof (FeatureElement)) - * rec->langsys->FeatureCount); - memset (rec->features + rec->num_features, 0, - (sizeof (FeatureElement)) - * (rec->langsys->FeatureCount - rec->num_features)); - rec->num_features = rec->langsys->FeatureCount; - } - if (! rec->langsys) i = 0; else @@ -854,7 +851,7 @@ setup_feature_rec (FeatureRec *rec) XtSetArg (arg[0], XtNborderColor, background); XtSetArg (arg[1], XtNsensitive, False); XtSetArg (arg[2], XtNlabel, " "); - for (; i < rec->langsys->FeatureCount; i++) + for (; i < rec->num_features; i++) { if (! rec->features[i].w) { @@ -868,11 +865,42 @@ setup_feature_rec (FeatureRec *rec) } void +compose_script_langsys (OTF_Tag script, OTF_Tag langsys, char *name) +{ + OTF_tag_name (script, name); + if (langsys) + { + name[4] = '('; + OTF_tag_name (langsys, name + 5); + name[9] = ')'; + name[10] = '\0'; + } +} + +void +decompose_script_langsys (OTF_Tag *script, OTF_Tag *langsys, char *name) +{ + *script = OTF_tag (name); + if (name[4]) + *langsys = OTF_tag (name + 5); + else + *langsys = 0; +} + +void ScriptProc (Widget w, XtPointer client_data, XtPointer call_data) { - if (script_tag == (OTF_Tag) client_data) + char *name; + OTF_Tag script, langsys; + Arg arg[1]; + + XtSetArg (arg[0], XtNlabel, &name); + XtGetValues (w, arg, 1); + decompose_script_langsys (&script, &langsys, name); + if (script_tag == script && langsys_tag == langsys) return; - script_tag = (OTF_Tag) client_data; + script_tag = script; + langsys_tag = langsys; setup_feature_rec (&gsub); setup_feature_rec (&gpos); update_seq_area (); @@ -883,9 +911,13 @@ create_otf_script_widgets (Widget prev) { Widget w; Arg arg[10]; - int n, i; - OTF_Tag *scripts; - char script_name[5]; + int n, prev_n, i, j; + struct { + OTF_Tag script; + OTF_Tag langsys; + } *script_langsys; + char name[11]; + int nfeatures; XtSetArg (arg[0], XtNborderWidth, 0); XtSetArg (arg[1], XtNleft, XawChainLeft); @@ -895,56 +927,126 @@ create_otf_script_widgets (Widget prev) XtSetArg (arg[5], XtNfromVert, prev); XtSetArg (arg[6], XtNorientation, XtorientHorizontal); prev = XtCreateManagedWidget ("Script", boxWidgetClass, render_area, arg, 7); - XtCreateManagedWidget ("script", labelWidgetClass, prev, arg, 1); + XtCreateManagedWidget ("script(langsys)", labelWidgetClass, prev, arg, 1); n = 0; if (otf->gsub) - n = otf->gsub->ScriptList.ScriptCount; + for (i = 0; i < otf->gsub->ScriptList.ScriptCount; i++) + n += otf->gsub->ScriptList.Script[i].LangSysCount + 1; if (otf->gpos) - n += otf->gpos->ScriptList.ScriptCount; - scripts = alloca (sizeof (OTF_Tag) * n); - i = 0; + for (i = 0; i < otf->gpos->ScriptList.ScriptCount; i++) + n += otf->gsub->ScriptList.Script[i].LangSysCount + 1; + script_langsys = alloca ((sizeof script_langsys[0]) * n); + n = 0; + nfeatures = 0; if (otf->gsub) - for (; i < otf->gsub->ScriptList.ScriptCount; i++) - scripts[i] = otf->gsub->ScriptList.Script[i].ScriptTag; - n = i; + for (i = 0; i < otf->gsub->ScriptList.ScriptCount; i++) + { + OTF_Tag tag = otf->gsub->ScriptList.Script[i].ScriptTag; + + script_langsys[n].script = tag; + script_langsys[n++].langsys = 0; + if (nfeatures + < otf->gsub->ScriptList.Script[i].DefaultLangSys.FeatureCount) + nfeatures + = otf->gsub->ScriptList.Script[i].DefaultLangSys.FeatureCount; + for (j = 0; j < otf->gsub->ScriptList.Script[i].LangSysCount; j++) + { + script_langsys[n].script = tag; + script_langsys[n++].langsys + = otf->gsub->ScriptList.Script[i].LangSysRecord[j].LangSysTag; + if (nfeatures + < otf->gsub->ScriptList.Script[i].LangSys[j].FeatureCount) + nfeatures + = otf->gsub->ScriptList.Script[i].LangSys[j].FeatureCount; + } + } + gsub.num_features = nfeatures; + if (nfeatures > 0) + { + gsub.num_features = nfeatures; + gsub.features = malloc ((sizeof (FeatureElement)) * nfeatures); + memset (gsub.features, 0, (sizeof (FeatureElement)) * nfeatures); + } + prev_n = n; + nfeatures = 0; if (otf->gpos) - for (; i < otf->gpos->ScriptList.ScriptCount; i++) + for (i = 0; i < otf->gpos->ScriptList.ScriptCount; i++) { OTF_Tag tag = otf->gpos->ScriptList.Script[i].ScriptTag; - int j; - - for (j = 0; j < i; j++) - if (tag == scripts[j]) + int k; + + if (nfeatures + < otf->gpos->ScriptList.Script[i].DefaultLangSys.FeatureCount) + nfeatures + = otf->gpos->ScriptList.Script[i].DefaultLangSys.FeatureCount; + for (k = 0; k < prev_n; k++) + if (tag == script_langsys[k].script) break; - if (j == i) - scripts[n++] = tag; + if (k == prev_n) + { + script_langsys[n].script = tag; + script_langsys[n++].langsys = 0; + } + for (j = 0; j < otf->gsub->ScriptList.Script[i].LangSysCount; j++) + { + int l; + + if (k < prev_n) + { + OTF_Script *script = otf->gsub->ScriptList.Script + i; + + for (l = k; l < prev_n && tag == script_langsys[l].script; l++) + if (script->LangSysRecord[j].LangSysTag + == script_langsys[l].langsys) + break; + } + else + l = prev_n; + if (l == prev_n) + { + script_langsys[n].script = tag; + script_langsys[n++].langsys = 0; + } + if (nfeatures + < otf->gpos->ScriptList.Script[i].LangSys[j].FeatureCount) + nfeatures + = otf->gpos->ScriptList.Script[i].LangSys[j].FeatureCount; + } } + if (nfeatures > 0) + { + gpos.num_features = nfeatures; + gpos.features = malloc ((sizeof (FeatureElement)) * nfeatures); + memset (gpos.features, 0, (sizeof (FeatureElement)) * nfeatures); + } + if (n == 0) return prev; - script_tag = scripts[0]; - OTF_tag_name (scripts[0], script_name); + script_tag = script_langsys[0].script; + langsys_tag = script_langsys[0].langsys; + compose_script_langsys (script_tag, langsys_tag, name); + if (n == 1) { XtSetArg (arg[0], XtNforeground, background); XtSetArg (arg[1], XtNbackground, foreground); - XtCreateManagedWidget (script_name, labelWidgetClass, prev, arg, 2); + XtCreateManagedWidget (name, labelWidgetClass, prev, arg, 2); } else { - char name[5]; - XtSetArg (arg[0], XtNstate, True); - w = XtCreateManagedWidget (script_name, toggleWidgetClass, prev, arg, 1); - XtAddCallback (w, XtNcallback, ScriptProc, (XtPointer) scripts[0]); + w = XtCreateManagedWidget (name, toggleWidgetClass, prev, arg, 1); + XtAddCallback (w, XtNcallback, ScriptProc, NULL); XtSetArg (arg[0], XtNradioGroup, w); for (i = 1; i < n; i++) { - OTF_tag_name (scripts[i], name); + compose_script_langsys (script_langsys[i].script, + script_langsys[i].langsys, name); w = XtCreateManagedWidget (name, toggleWidgetClass, prev, arg, 1); - XtAddCallback (w, XtNcallback, ScriptProc, (XtPointer) scripts[i]); + XtAddCallback (w, XtNcallback, ScriptProc, NULL); } } return prev; @@ -956,7 +1058,6 @@ create_otf_widgets (Widget prev, FeatureRec *rec) { Arg arg[10]; Widget w; - int i; XtSetArg (arg[0], XtNborderWidth, 0); XtSetArg (arg[1], XtNleft, XawChainLeft); -- 1.7.10.4