From: handa Date: Mon, 29 Dec 2008 14:54:02 +0000 (+0000) Subject: (uvs_area, uvs_label): New variables. X-Git-Tag: REL-0-9-9~20 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a97ff0e6621fea8d6d1e993e042747e438934eb;p=m17n%2Flibotf.git (uvs_area, uvs_label): New variables. (sub14, uvs): New variable. (update_uvs_area): New function. (update_seq_area): Set `glyph_id' member only when no charmap is used. (update_render_area): Handle a variation selector. (UVSProc): New function. (RenderProc): Call update_uvs_area if the font is OpenType. (create_widgets): Create uvs_area widget if the font has variation selector. (main): Setup sub14. Set font in gc_set. --- diff --git a/example/otfview.c b/example/otfview.c index d8b8720..3700d9e 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -72,6 +72,9 @@ XtAppContext context; | | idxh[7] glyph[112] ... glyph[127]| | | | idxl[0] ... idxl[15] | | | +--------------------------------------+ | + | +---- uvs_area (box) (optional) -------+ | + | | uvs[?].w ... | | + | +--------------------------------------+ | | +--- render_area (form) ---------------+ | | | clear del bidi alt_subst | | | | +--- raw (box) --------------------+ | | @@ -88,6 +91,7 @@ Widget shell, frame; Widget command_area, quit, dump, *charmap; Widget navi_area, FIRST, PREV, prev, range, next, NEXT, LAST; Widget glyph_area, glyph[128], index_label[8]; +Widget uvs_area, uvs_label; Widget render_area, clear, del, bidi, alt_subst, raw, seq; Widget raw_label, raw_image, seq_label, seq_image; unsigned long foreground, background; @@ -154,6 +158,13 @@ struct { int codes[64]; } glyph_rec; +OTF_EncodingSubtable14 *sub14 = NULL; + +struct { + Widget w; + int c; +} uvs[256]; + OTF *otf; char *filename; int fontindex; @@ -242,6 +253,27 @@ update_glyph_area () XtSetValues (range, arg, 1); } +void +update_uvs_area (int c) +{ + OTF_GlyphID code[256]; + Arg arg[1]; + int i; + + OTF_get_variation_glyphs (otf, c, code); + + for (i = 0; i < 256; i++) + if (uvs[i].w) + { + if (code[i]) + XtSetArg (arg[0], XtNsensitive, True); + else + XtSetArg (arg[0], XtNsensitive, False); + XtSetValues (uvs[i].w, arg, 1); + } +} + + char * get_features (OTF_FeatureList *list, FeatureRec *rec) { @@ -313,7 +345,11 @@ update_seq_area () gstring.glyphs = malloc (sizeof (OTF_Glyph) * len); memset (gstring.glyphs, 0, sizeof (OTF_Glyph) * len); for (i = 0; i < len; i++) - gstring.glyphs[i].c = gstring.glyphs[i].glyph_id = glyph_rec.glyphs[i]; + { + gstring.glyphs[i].c = glyph_rec.codes[i]; + if (charmap_index < 0) + gstring.glyphs[i].glyph_id = glyph_rec.glyphs[i]; + } XFillRectangle (display, seq_pixmap, gc, 0, 0, render_width, render_height); XDrawLine (display, seq_pixmap, gc_set, 0, glyph_y, render_width, glyph_y); @@ -477,28 +513,50 @@ update_render_area () XFillRectangle (display, raw_pixmap, gc, 0, 0, render_width, render_height); for (i = 0, x = glyph_x; i < glyph_rec.n_glyphs; i++) { - BitmapRec *bmp = bitmap + glyph_rec.glyphs[i]; - char buf[5]; - - XCopyArea (display, bmp->pixmap, raw_pixmap, gc, - 0, 0, glyph_width, glyph_height, - (glyph_width + 4) * i + 1, 1); - XDrawRectangle (display, raw_pixmap, gc_set, - (glyph_width + 4) * i, 0, - glyph_width + 1, glyph_height + 1); - XDrawLine (display, raw_pixmap, gc_set, - (glyph_width + 4) * i + 1 + glyph_x, 1, - (glyph_width + 4) * i + 1 + glyph_x, glyph_height + 1); - XDrawLine (display, raw_pixmap, gc_set, - (glyph_width + 4) * i + 1 + glyph_x + bmp->advance, 1, - (glyph_width + 4) * i + 1 + glyph_x + bmp->advance, - glyph_height + 1); - - sprintf (buf, "%04X", glyph_rec.codes[i]); - XDrawString (display, raw_pixmap, gc_inv, - (glyph_width + 1) * i + 1 - + (glyph_width - XTextWidth (font, buf, 4)) / 2, - glyph_height + 2 + FONT_HEIGHT, buf, 4); + if (glyph_rec.glyphs[i] >= 0) + { + BitmapRec *bmp = bitmap + glyph_rec.glyphs[i]; + char buf[5]; + + XCopyArea (display, bmp->pixmap, raw_pixmap, gc, + 0, 0, glyph_width, glyph_height, + (glyph_width + 4) * i + 1, 1); + XDrawRectangle (display, raw_pixmap, gc_set, + (glyph_width + 4) * i, 0, + glyph_width + 1, glyph_height + 1); + XDrawLine (display, raw_pixmap, gc_set, + (glyph_width + 4) * i + 1 + glyph_x, 1, + (glyph_width + 4) * i + 1 + glyph_x, glyph_height + 1); + XDrawLine (display, raw_pixmap, gc_set, + (glyph_width + 4) * i + 1 + glyph_x + bmp->advance, 1, + (glyph_width + 4) * i + 1 + glyph_x + bmp->advance, + glyph_height + 1); + + sprintf (buf, "%04X", glyph_rec.codes[i]); + XDrawString (display, raw_pixmap, gc_inv, + (glyph_width + 4) * i + 1 + + (glyph_width - XTextWidth (font, buf, 4)) / 2, + glyph_height + 2 + FONT_HEIGHT, buf, 4); + } + else + { + /* Variation Selector */ + int idx = - glyph_rec.glyphs[i]; + char buf[4]; + + sprintf (buf, "%03d", idx); + XDrawRectangle (display, raw_pixmap, gc_set, + (glyph_width + 4) * i, 0, + glyph_width + 1, glyph_height + 1); + XDrawString (display, raw_pixmap, gc_set, + (glyph_width + 4) * i + 1 + + (glyph_width - XTextWidth (font, "VS", 2)) / 2, + 1 + glyph_height / 2, "VS", 2); + XDrawString (display, raw_pixmap, gc_set, + (glyph_width + 4) * i + 1 + + (glyph_width - XTextWidth (font, buf, 3)) / 2, + 1 + glyph_height / 2 + FONT_ASCENT, buf, 3); + } } XtSetArg (arg[0], XtNbitmap, raw_pixmap); XtSetValues (raw_image, arg, 1); @@ -679,6 +737,33 @@ CharmapProc (Widget w, XtPointer client_data, XtPointer call_data) } void +UVSProc (Widget w, XtPointer client_data, XtPointer call_data) +{ + unsigned idx = (unsigned) client_data; + int selector = uvs[idx].c; + OTF_VariationSelectorRecord *record; + int i; + + if (glyph_rec.n_glyphs >= 64) + return; + for (i = 0; i < sub14->nRecords; i++) + { + record = sub14->Records + i; + if (record->varSelector == selector) + break; + } + if (i < sub14->nRecords) + { + if (glyph_rec.n_glyphs > 0 + && glyph_rec.glyphs[glyph_rec.n_glyphs - 1] < 0) + glyph_rec.n_glyphs--; + glyph_rec.codes[glyph_rec.n_glyphs] = selector; + glyph_rec.glyphs[glyph_rec.n_glyphs++] = - idx - 1; + update_render_area (); + } +} + +void RenderProc (Widget w, XtPointer client_data, XtPointer call_data) { if ((int) client_data < 0) @@ -702,6 +787,8 @@ RenderProc (Widget w, XtPointer client_data, XtPointer call_data) { glyph_rec.codes[glyph_rec.n_glyphs] = glyph_index + (int) client_data; glyph_rec.glyphs[glyph_rec.n_glyphs++] = index; + if (otf) + update_uvs_area (glyph_index + (int) client_data); update_render_area (); } } @@ -1142,7 +1229,41 @@ create_widgets () XtSetArg (arg[6], XtNdefaultDistance, 0); glyph_area = XtCreateManagedWidget ("glyph-area", formWidgetClass, frame, arg, 7); + XtSetArg (arg[5], XtNfromVert, glyph_area); + if (sub14) + { + Arg arg2[3]; + + XtSetArg (arg[6], XtNorientation, XtorientHorizontal); + uvs_area = XtCreateManagedWidget ("uvs-area", boxWidgetClass, + frame, arg, 7); + XtSetArg (arg2[0], XtNborderWidth, 0); + XtSetArg (arg2[1], XtNlabel, "Variation Selector: "); + uvs_label = XtCreateManagedWidget ("uvs-label", labelWidgetClass, + uvs_area, arg2, 2); + XtSetArg (arg2[0], XtNborderWidth, 1); + for (i = 0; i < sub14->nRecords; i++) + { + OTF_VariationSelectorRecord *record = sub14->Records + i;; + unsigned selector = record->varSelector; + unsigned idx; + char lbl[4]; + + idx = (selector <= 0xFE0F ? selector - 0xFE00 + : selector - 0xE0100 + 16); + if (uvs[idx].c) + continue; + uvs[idx].c = selector; + sprintf (lbl, "%03d", idx + 1); + XtSetArg (arg2[1], XtNlabel, lbl); + XtSetArg (arg2[2], XtNsensitive, False); + uvs[idx].w = XtCreateManagedWidget ("lbl", commandWidgetClass, + uvs_area, arg2, 3); + XtAddCallback (uvs[idx].w, XtNcallback, UVSProc, (XtPointer) idx); + } + XtSetArg (arg[5], XtNfromVert, uvs_area); + } render_area = XtCreateManagedWidget ("render-area", formWidgetClass, frame, arg, 6); @@ -1443,6 +1564,12 @@ main (int argc, char **argv) || (OTF_check_table (otf, "GSUB") < 0 && OTF_check_table (otf, "GPOS") < 0)) otf = NULL; + for (i = 0; i < otf->cmap->numTables; i++) + if (otf->cmap->EncodingRecord[i].subtable.format == 14) + { + sub14 = otf->cmap->EncodingRecord[i].subtable.f.f14; + break; + } } { @@ -1481,9 +1608,11 @@ main (int argc, char **argv) XGCValues values; gc = XCreateGC (display, none_pixmap, (unsigned long) 0, NULL); + XSetFont (display, gc, font->fid); values.function = GXset; values.line_width = 1; gc_set = XCreateGC (display, none_pixmap, valuemask, &values); + XSetFont (display, gc_set, font->fid); values.function = GXor; gc_or = XCreateGC (display, none_pixmap, valuemask, &values); values.function = GXcopyInverted;