From: handa Date: Tue, 2 Nov 2004 06:15:26 +0000 (+0000) Subject: (MAX_FEATURE_COUNT): Delete this macro. X-Git-Tag: REL-0-9-5~96 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f59d74e2f786e5429ef3a1305f4259b19b17f117;p=m17n%2Flibotf.git (MAX_FEATURE_COUNT): Delete this macro. (FeatureElement): New type. (FeatureRec): New element num_features and parent. (update_seq_area): Show alternate glyphs if any. (setup_feature_rec): (Re)allocate rec->features. Create widgets. (create_otf_widgets): Don't create widgets here. --- diff --git a/example/otfview.c b/example/otfview.c index 531f549..0accf52 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -90,18 +90,21 @@ Widget render_area, clear, del, bidi, raw, seq; Widget raw_label, raw_image, seq_label, seq_image; unsigned long foreground, background; -#define MAX_FEATURE_COUNT 16 +typedef struct +{ + OTF_Tag tag; + int on; + Widget w; +} FeatureElement; typedef struct { char *label; OTF_GSUB_GPOS *gsub_gpos; OTF_LangSys *langsys; - struct { - OTF_Tag tag; - int on; - Widget w; - } features[MAX_FEATURE_COUNT]; + int num_features; + FeatureElement *features; + Widget parent; } FeatureRec; FeatureRec gsub, gpos; @@ -360,6 +363,7 @@ update_seq_area () int xoff = 0, yoff = 0; int prev_width; int advance = bmp->advance; + int j; if (! bmp->pixmap) { @@ -434,6 +438,21 @@ update_seq_area () mark = g; else base = g, base_width = advance; + + if (g->alternate_set) + for (j = 0; j < g->alternate_set->GlyphCount; j++) + { + bmp = bitmap + g->alternate_set->Alternate[j]; + if (! bmp->pixmap) + create_pixmap (g->alternate_set->Alternate[j]); + if (! bmp->pixmap) + continue; + XCopyArea (display, bmp->pixmap, seq_pixmap, gc_or, + glyph_x + bmp->x, glyph_y + bmp->y, + bmp->width, bmp->height, + x + bmp->x + xoff, glyph_y + bmp->y - yoff); + x += bmp->advance; + } } free (gstring.glyphs); @@ -786,6 +805,23 @@ setup_feature_rec (FeatureRec *rec) 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 @@ -795,12 +831,20 @@ setup_feature_rec (FeatureRec *rec) XtSetArg (arg[2], XtNinternalWidth, 4); XtSetArg (arg[3], XtNborderColor, foreground); XtSetArg (arg[4], XtNsensitive, True); - for (i = 0; i < rec->langsys->FeatureCount && i < MAX_FEATURE_COUNT; i++) + for (i = 0; i < rec->langsys->FeatureCount; i++) { OTF_Feature *feature = rec->gsub_gpos->FeatureList.Feature; int index = rec->langsys->FeatureIndex[i]; char label[5]; + if (! rec->features[i].w) + { + Widget w = XtCreateManagedWidget ("", commandWidgetClass, + rec->parent, arg, 0); + XtAddCallback (w, XtNcallback, FeatureProc, (XtPointer) rec); + rec->features[i].w = w; + } + rec->features[i].tag = feature[index].FeatureTag; rec->features[i].on = 0; OTF_tag_name (rec->features[i].tag, label); @@ -811,8 +855,17 @@ setup_feature_rec (FeatureRec *rec) XtSetArg (arg[0], XtNborderColor, background); XtSetArg (arg[1], XtNsensitive, False); XtSetArg (arg[2], XtNlabel, " "); - for (; i < MAX_FEATURE_COUNT; i++) - XtSetValues (rec->features[i].w, arg, 3); + for (; i < rec->langsys->FeatureCount; i++) + { + if (! rec->features[i].w) + { + Widget w = XtCreateManagedWidget ("", commandWidgetClass, + rec->parent, arg, 0); + XtAddCallback (w, XtNcallback, FeatureProc, (XtPointer) rec); + rec->features[i].w = w; + } + XtSetValues (rec->features[i].w, arg, 3); + } } void @@ -924,13 +977,7 @@ create_otf_widgets (Widget prev, FeatureRec *rec) w = XtCreateManagedWidget ("none", commandWidgetClass, prev, arg, 3); XtAddCallback (w, XtNcallback, FeatureProc, (XtPointer) rec); - for (i = 0; i < MAX_FEATURE_COUNT; i++) - { - w = XtCreateManagedWidget ("", commandWidgetClass, prev, arg, 0); - XtAddCallback (w, XtNcallback, FeatureProc, (XtPointer) rec); - rec->features[i].w = w; - } - + rec->parent = prev; setup_feature_rec (rec); return prev; }