From: handa Date: Wed, 4 Aug 2004 12:54:37 +0000 (+0000) Subject: (bidi, reversed): New variables. X-Git-Tag: REL-0-9-1~26 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c520d894ae36e30eec1140c970c10986d25507d;p=m17n%2Flibotf.git (bidi, reversed): New variables. (update_seq_area): Call OTF_drive_gdef. If reversed is nonzero, reorder glyphs properly. Create pixmap if necessary. Handle OTF_XAdvance and OTF_XAdvDevice. (BidiProc): New function. (create_widgets): Setup bidi. --- diff --git a/example/otfview.c b/example/otfview.c index 662d0b8..9fa625f 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -69,7 +69,7 @@ XtAppContext context; | | idxl[0] ... idxl[15] | | | +--------------------------------------+ | | +--- render_area (form) ---------------+ | - | | clear del | | + | | clear del bidi | | | | +--- raw (box) --------------------+ | | | | | raw_label raw_image | | | | | +----------------------------------+ | | @@ -84,7 +84,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 render_area, clear, del, raw, seq; +Widget render_area, clear, del, bidi, raw, seq; Widget raw_label, raw_image, seq_label, seq_image; unsigned long foreground, background; @@ -134,6 +134,7 @@ struct { int charmap_index; +int reversed; unsigned glyph_width, glyph_height; int glyph_x, glyph_y; int glyph_index; @@ -300,6 +301,7 @@ update_seq_area () 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]; + OTF_drive_gdef (otf, &gstring); XFillRectangle (display, seq_pixmap, gc, 0, 0, render_width, render_height); if (otf) @@ -327,12 +329,39 @@ update_seq_area () } prev = NULL; + if (reversed) + { + OTF_Glyph temp; + + for (prev = gstring.glyphs, g = gstring.glyphs + gstring.used - 1; + prev < g; prev++, g--) + temp = *prev, *prev = *g, *g = temp; + for (g = gstring.glyphs; g < gstring.glyphs + gstring.used; g++) + if (g->GlyphClass == 3) + { + OTF_Glyph *g0; + prev = g++; + while (g < gstring.glyphs + gstring.used && g->GlyphClass == 3) + g++; + for (g0 = g; prev < g0; prev++, g0--) + temp = *prev, *prev = *g, *g = temp; + } + } + + for (i = 0, x = glyph_x, prev = NULL, g = gstring.glyphs; i < gstring.used; i++, prev = g++) { BitmapRec *bmp = bitmap + gstring.glyphs[i].glyph_id; int xoff = 0, yoff = 0; + int advance = bmp->advance; + if (! bmp->pixmap) + { + create_pixmap (gstring.glyphs[i].glyph_id); + if (! bmp->pixmap) + continue; + } switch (g->positioning_type) { case 0: @@ -350,6 +379,10 @@ update_seq_area () yoff = g->f.f1.value->YPlacement * pixel_size / unitsPerEm; if (format & OTF_YPlaDevice) yoff += DEVICE_DELTA (g->f.f1.value->YPlaDevice, pixel_size); + if (format & OTF_XAdvance) + advance += g->f.f1.value->XAdvance * pixel_size / unitsPerEm; + if (format & OTF_XAdvDevice) + advance += DEVICE_DELTA (g->f.f1.value->XAdvDevice, pixel_size); } break; case 3: @@ -383,7 +416,7 @@ update_seq_area () 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 += prev_width = bmp->advance; + x += prev_width = advance; } XtSetArg (arg[0], XtNbitmap, seq_pixmap); XtSetValues (seq_image, arg, 1); @@ -625,6 +658,20 @@ RenderProc (Widget w, XtPointer client_data, XtPointer call_data) } void +BidiProc (Widget w, XtPointer client_data, XtPointer call_data) +{ + Arg arg[1]; + + reversed = ! reversed; + if (reversed) + XtSetArg (arg[0], XtNlabel, "L<-R"); + else + XtSetArg (arg[0], XtNlabel, "L->R"); + XtSetValues (w, arg, 1); + update_seq_area (); +} + +void FeatureProc (Widget w, XtPointer client_data, XtPointer call_data) { FeatureRec *rec = (FeatureRec *) client_data; @@ -1045,6 +1092,8 @@ create_widgets () XtAddCallback (clear, XtNcallback, RenderProc, (XtPointer) -1); del = XtCreateManagedWidget ("delete", commandWidgetClass, w, arg, 0); XtAddCallback (del, XtNcallback, RenderProc, (XtPointer) -2); + bidi = XtCreateManagedWidget ("L->R", toggleWidgetClass, w, arg, 0); + XtAddCallback (bidi, XtNcallback, BidiProc, NULL); XtSetArg (arg[4], XtNorientation, XtorientHorizontal); XtSetArg (arg[5], XtNborderWidth, 0);