From: handa Date: Wed, 9 Jul 2003 23:02:12 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: REL-0-9-1~103 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=fbf3fbc271085de8a73945dd0e96fc5e79380c98;p=m17n%2Flibotf.git *** empty log message *** --- diff --git a/example/otfviewx.c b/example/otfviewx.c index 121d633..039cb8c 100644 --- a/example/otfviewx.c +++ b/example/otfviewx.c @@ -26,7 +26,8 @@ XtAppContext context; /* Widget structure. +---form----------------------------+ | +--- command_area --------------+ | - | | prev next charmap ... quit| | + | | charmap ... quit| | + | | PREV prev label next NEXT | | | +-------------------------------+ | | +--- glyph_area ----------------+ | | | | | @@ -40,7 +41,7 @@ XtAppContext context; | +-------------------------------+ | +-----------------------------------+ */ Widget shell, form, command_area, glyph_area, render_area; -Widget prev, next, *charmap, quit, glyph[128], clear; +Widget PREV, prev, label, next, NEXT, *charmap, quit, glyph[128], clear; unsigned char glyph_exist[0x10000]; Pixmap pixmap[0x10000]; @@ -99,11 +100,12 @@ void update_glyph_area () { int i; + Arg arg[2]; + char buf[16]; for (i = 0; i < 128; i++) { int index = glyph_index + i; - Arg arg[2]; int num_args = 0; if (charmap_index >= 0) @@ -113,6 +115,10 @@ update_glyph_area () XtSetArg (arg[num_args], XtNlabel, "none"), num_args++; XtSetValues (glyph[i], arg, num_args); } + + sprintf (buf, " %04X ", glyph_index); + XtSetArg (arg[0], XtNlabel, buf); + XtSetValues (label, arg, 1); } void @@ -124,16 +130,18 @@ QuitProc (Widget w, XtPointer client_data, XtPointer call_data) void ChangeProc (Widget w, XtPointer client_data, XtPointer call_data) { - if ((int) client_data < 0 && glyph_index > 0) - { - glyph_index -= 128; - update_glyph_area (); - } - else if ((int) client_data > 0 && glyph_index <= 0xFF00) - { - glyph_index += 128; - update_glyph_area (); - } + int old_glyph_index = glyph_index; + + if ((int) client_data == -2 && glyph_index > 0) + glyph_index = (glyph_index - 1) & 0xF000; + else if ((int) client_data == -1 && glyph_index > 0) + glyph_index -= 0x80; + else if ((int) client_data == 1 && glyph_index < 0xFF80) + glyph_index += 0x80; + else if ((int) client_data == 2 && glyph_index < 0xF000) + glyph_index = (glyph_index + 0x1000) & 0xF000; + if (glyph_index != old_glyph_index) + update_glyph_area (); } void @@ -147,15 +155,106 @@ EncodingProc (Widget w, XtPointer client_data, XtPointer call_data) update_glyph_area (); } -static void -ExposeProc (Widget w, XEvent *event, String *str, Cardinal *num) -{ -} -static void -KeyProc (Widget w, XEvent *event, String *str, Cardinal *num) +void +create_widgets () { - fprintf (stderr, "key pressed\n"); + String PREV_action = "Shiftp: set() notify() unset()"; + String prev_action = "~Shiftp: set() notify() unset()"; + String next_action = "~Shiftn: set() notify() unset()"; + String NEXT_action = "Shiftn: set() notify() unset()"; + String quit_action = "q: set() notify() unset()"; + Arg arg[10]; + int i, j; + + form = XtCreateManagedWidget ("form", formWidgetClass, shell, NULL, 0); + XtSetArg (arg[0], XtNborderWidth, 0); + command_area = XtCreateManagedWidget ("command-area", formWidgetClass, + form, arg, 1); + XtSetArg (arg[0], XtNborderWidth, 1); + XtSetArg (arg[1], XtNfromVert, command_area); + XtSetArg (arg[2], XtNdefaultDistance, 0); + glyph_area = XtCreateManagedWidget ("glyph-area", formWidgetClass, + form, arg, 3); + XtSetArg (arg[0], XtNborderWidth, 0); + XtSetArg (arg[1], XtNfromVert, glyph_area); + render_area = XtCreateManagedWidget ("render", formWidgetClass, + form, arg, 2); + + charmap = alloca (sizeof (Widget) * (face->num_charmaps + 1)); + XtSetArg (arg[0], XtNleft, XawChainLeft); + XtSetArg (arg[1], XtNright, XawChainLeft); + XtSetArg (arg[2], XtNtop, XawChainTop); + XtSetArg (arg[3], XtNbottom, XawChainTop); + charmap[0] = XtCreateManagedWidget (charmap_rec[0].name, commandWidgetClass, + command_area, arg, 4); + XtAddCallback (charmap[0], XtNcallback, EncodingProc, (XtPointer) -1); + for (i = 1; i <= face->num_charmaps; i++) + { + XtSetArg (arg[4], XtNfromHoriz, charmap[i - 1]); + charmap[i] = XtCreateManagedWidget (charmap_rec[i].name, + commandWidgetClass, + command_area, arg, 5); + XtAddCallback (charmap[i], XtNcallback, EncodingProc, + (XtPointer) (i - 1)); + } + XtSetArg (arg[0], XtNleft, XawChainRight); + XtSetArg (arg[1], XtNright, XawChainRight); + XtSetArg (arg[4], XtNfromHoriz, charmap[i - 1]); + XtSetArg (arg[5], XtNaccelerators, XtParseAcceleratorTable (quit_action)); + quit = XtCreateManagedWidget ("quit", commandWidgetClass, + command_area, arg, 6); + XtAddCallback (quit, XtNcallback, QuitProc, NULL); + + XtSetArg (arg[4], XtNfromVert, charmap[0]); + XtSetArg (arg[5], XtNlabel, "<< (P)"); + XtSetArg (arg[6], XtNaccelerators, XtParseAcceleratorTable (PREV_action)); + PREV = XtCreateManagedWidget ("PREV", commandWidgetClass, + command_area, arg, 7); + XtAddCallback (PREV, XtNcallback, ChangeProc, (XtPointer) -2); + XtSetArg (arg[5], XtNfromHoriz, PREV); + XtSetArg (arg[6], XtNlabel, "< (p)"); + XtSetArg (arg[7], XtNaccelerators, XtParseAcceleratorTable (prev_action)); + prev = XtCreateManagedWidget ("prev", commandWidgetClass, + command_area, arg, 8); + XtAddCallback (prev, XtNcallback, ChangeProc, (XtPointer) -1); + XtSetArg (arg[5], XtNfromHoriz, prev); + XtSetArg (arg[6], XtNlabel, " 0000 "); + label = XtCreateManagedWidget ("label", labelWidgetClass, + command_area, arg, 7); + XtSetArg (arg[5], XtNfromHoriz, label); + XtSetArg (arg[6], XtNlabel, "(n) >"); + XtSetArg (arg[7], XtNaccelerators, XtParseAcceleratorTable (next_action)); + next = XtCreateManagedWidget ("next", commandWidgetClass, + command_area, arg, 8); + XtAddCallback (next, XtNcallback, ChangeProc, (XtPointer) 1); + XtSetArg (arg[5], XtNfromHoriz, next); + XtSetArg (arg[6], XtNlabel, "(N) >>"); + XtSetArg (arg[7], XtNaccelerators, XtParseAcceleratorTable (NEXT_action)); + NEXT = XtCreateManagedWidget ("NEXT", commandWidgetClass, + command_area, arg, 8); + XtAddCallback (NEXT, XtNcallback, ChangeProc, (XtPointer) 2); + + for (i = 0; i < 8; i++) + for (j = 0; j < 16; j++) + { + int k = i * 16 + j; + int num_args = 0; + + XtSetArg (arg[num_args], XtNwidth, glyph_width), num_args++; + XtSetArg (arg[num_args], XtNheight, glyph_height), num_args++; + if (j > 0) + XtSetArg (arg[num_args], XtNfromHoriz, glyph[k - 1]), num_args++; + if (i > 0) + XtSetArg (arg[num_args], XtNfromVert, glyph[k - 16]), num_args++; + glyph[k] = XtCreateManagedWidget ("glyph", commandWidgetClass, + glyph_area, arg, num_args); + } + + clear = XtCreateManagedWidget ("clear", commandWidgetClass, + render_area, NULL, 0); + + XtInstallAllAccelerators (form, form); } /* Format MSG by FMT and print the result to the stderr, and exit. */ @@ -169,14 +268,6 @@ KeyProc (Widget w, XEvent *event, String *str, Cardinal *num) int main (int argc, char **argv) { - XtActionsRec actions[] = { {"Expose", ExposeProc}, - {"Key", KeyProc} }; - String prev_action = "<: set() notify() unset()\n\ - p: set() notify() unset()\n"; - String next_action = ">: set() notify() unset()\n\ - n: set() notify() unset()\n"; - String quit_action = "q: set() notify() unset()"; - Arg arg[10]; Display *display; FT_Library library; @@ -186,7 +277,7 @@ main (int argc, char **argv) OTF_Glyph *g; int err; - int i, j; + int i; int pixel_size = DEFAULT_PIXEL_SIZE; gstring.size = gstring.used = 256; @@ -196,7 +287,6 @@ main (int argc, char **argv) shell = XtOpenApplication (&context, "OTFView", NULL, 0, &argc, argv, NULL, shellWidgetClass, NULL, 0); display = XtDisplay (shell); - XtAppAddActions (context, actions, XtNumber (actions)); if (argc != 2) FATAL_ERROR ("%s\n", "Usage: otfview [ X-OPTION ... ] OTF-FILE"); @@ -252,77 +342,12 @@ main (int argc, char **argv) for (i = 0; i < 0x10000; i++) pixmap[i] = create_pixmap (i, display); - form = XtCreateManagedWidget ("form", formWidgetClass, shell, NULL, 0); - XtSetArg (arg[0], XtNborderWidth, 0); - command_area = XtCreateManagedWidget ("command-area", formWidgetClass, - form, arg, 1); - XtSetArg (arg[0], XtNborderWidth, 1); - XtSetArg (arg[1], XtNfromVert, command_area); - XtSetArg (arg[2], XtNdefaultDistance, 0); - glyph_area = XtCreateManagedWidget ("glyph-area", formWidgetClass, - form, arg, 3); - XtSetArg (arg[0], XtNborderWidth, 0); - XtSetArg (arg[1], XtNfromVert, glyph_area); - render_area = XtCreateManagedWidget ("render", formWidgetClass, - form, arg, 2); - - charmap = alloca (sizeof (Widget) * (face->num_charmaps + 1)); - XtSetArg (arg[0], XtNleft, XawChainLeft); - XtSetArg (arg[1], XtNright, XawChainLeft); - XtSetArg (arg[2], XtNtop, XawChainTop); - XtSetArg (arg[3], XtNbottom, XawChainTop); - XtSetArg (arg[4], XtNaccelerators, XtParseAcceleratorTable (prev_action)); - prev = XtCreateManagedWidget ("prev", commandWidgetClass, - command_area, arg, 5); - XtAddCallback (prev, XtNcallback, ChangeProc, (XtPointer) -1); - XtSetArg (arg[4], XtNaccelerators, XtParseAcceleratorTable (next_action)); - XtSetArg (arg[5], XtNfromHoriz, prev); - next = XtCreateManagedWidget ("next", commandWidgetClass, - command_area, arg, 6); - XtAddCallback (next, XtNcallback, ChangeProc, (XtPointer) 1); - XtSetArg (arg[4], XtNfromHoriz, next); - charmap[0] = XtCreateManagedWidget (charmap_rec[0].name, commandWidgetClass, - command_area, arg, 5); - XtAddCallback (charmap[0], XtNcallback, EncodingProc, (XtPointer) -1); - for (i = 1; i <= face->num_charmaps; i++) - { - XtSetArg (arg[4], XtNfromHoriz, charmap[i - 1]); - charmap[i] = XtCreateManagedWidget (charmap_rec[i].name, - commandWidgetClass, - command_area, arg, 5); - XtAddCallback (charmap[i], XtNcallback, EncodingProc, - (XtPointer) (i - 1)); - } - XtSetArg (arg[4], XtNfromHoriz, charmap[i - 1]); - XtSetArg (arg[5], XtNaccelerators, XtParseAcceleratorTable (quit_action)); - quit = XtCreateManagedWidget ("quit", commandWidgetClass, - command_area, arg, 6); - XtAddCallback (quit, XtNcallback, QuitProc, NULL); - - for (i = 0; i < 8; i++) - for (j = 0; j < 16; j++) - { - int k = i * 16 + j; - int num_args = 0; - - XtSetArg (arg[num_args], XtNwidth, glyph_width), num_args++; - XtSetArg (arg[num_args], XtNheight, glyph_height), num_args++; - if (j > 0) - XtSetArg (arg[num_args], XtNfromHoriz, glyph[k - 1]), num_args++; - if (i > 0) - XtSetArg (arg[num_args], XtNfromVert, glyph[k - 16]), num_args++; - glyph[k] = XtCreateManagedWidget ("glyph", commandWidgetClass, - glyph_area, arg, num_args); - } - - clear = XtCreateManagedWidget ("clear", commandWidgetClass, - render_area, NULL, 0); + create_widgets (); glyph_index = 0; charmap_index = -1; update_glyph_area (); - XtInstallAllAccelerators (form, form); XtRealizeWidget (shell); XtAppMainLoop (context);