From e689213f281104fbadaf93f902a29438db6958d0 Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 22 Nov 2006 05:09:27 +0000 Subject: [PATCH] *** empty log message *** --- gtkdraw.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ imtest2.c | 30 ++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 gtkdraw.c create mode 100644 imtest2.c diff --git a/gtkdraw.c b/gtkdraw.c new file mode 100644 index 0000000..987e015 --- /dev/null +++ b/gtkdraw.c @@ -0,0 +1,155 @@ +#include +#include +#include +#include +#include + +gint +delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) +{ + return FALSE; +} + +void +destroy (GtkWidget *widget, gpointer data) +{ + gtk_main_quit (); +} + +int +main (int argc, char **argv) +{ + MSymbol lang; + MText *mt; + GdkPixmap *gdk_pixmap; + GtkWidget *window, *box, *text, *label; + + char title[256]; + int len; + + gtk_init (&argc, &argv); + + if (argc < 2) + { + fprintf (stderr, "Usage: gtk-m17n LANGUAGE\n"); + exit (1); + } + + M17N_INIT (); + lang = msymbol (argv[1]); + mt = mlanguage_text (lang); + if (! mt) + { + fprintf (stderr, "No native name for the language \"%s\".\n", argv[1]); + exit (1); + } + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + box = gtk_vbox_new (FALSE, 0); + text = gtk_drawing_area_new (); + label = gtk_label_new (title); + gtk_box_pack_start (GTK_BOX (box), text, TRUE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC (delete_event), NULL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (destroy), NULL); + + /* Draw on TEXT widget by m17n-lib. */ + { + Display *display; + Pixmap Pixmap; + MFrame *frame; + MPlist *param = mplist (); + MFace *face = mface (); + MFontset *fontset = mfontset ("generic"); + MDrawMetric metric; + + gdk_pixmap = gdk_pixmap_new (window->window, + + mface_put_prop (face, Msize, (void *) -600); + mface_put_prop (face, Mfontset, fontset); + if (argc > 2) + mface_put_prop (face, Mfamily, msymbol (argv[2])); + mplist_add (param, Mdevice, + mplist_add (param, Mface, face); + frame = mframe (param); + m17n_object_unref (face); + m17n_object_unref (param); + + if (! frame) + { + fprintf (stderr, "Frame creation failed. Perhaps no GD library.\n"); + exit (1); + } + } + + { + MDrawControl control; + + memset (&control, 0, sizeof (control)); + control.anti_alias = 1; + mdraw_text_extents (frame, mt, 0, mtext_len (mt), &control, + &metric, NULL, NULL); + + image = gdImageCreateTrueColor (metric.width, metric.height); + bg_color = gdImageColorAllocate (image, 255, 255, 255); + gdImageFilledRectangle (image, 0, 0, metric.width - 1, metric.height - 1, + bg_color); + + mdraw_text_with_control (frame, (MDrawWindow) image, + - metric.x, - metric.y, + mt, 0, mtext_len (mt), &control); + } + + m17n_object_unref (frame); + + + + + gtk_label_set_attributes (GTK_LABEL (label), attr_list); + + len = mconv_encode_buffer (msymbol ("utf-8"), mt, + (unsigned char *) title, 256); + title[len] = '\0'; + + M17N_FINI (); + + { + GdkPixbuf *pixbuf; + GtkWidget *window, *box, *text, *label; + int n_channels, rowstride; + guchar *pixels, *p; + int x, y; + PangoAttrList *attr_list = pango_attr_list_new (); + PangoAttribute *attr = pango_attr_size_new (60 * PANGO_SCALE); + + pango_attr_list_insert (attr_list, attr); + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, + metric.width, metric.height); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + pixels = gdk_pixbuf_get_pixels (pixbuf); + + for (y = 0; y < metric.height; y++) + for (x = 0; x < metric.width; x++) + { + int cid = gdImageGetPixel (image, x, y); + p = pixels + y * rowstride + x * n_channels; + + p[0] = gdImageRed (image, cid); + p[1] = gdImageGreen (image, cid); + p[2] = gdImageBlue (image, cid); + } + gdImageDestroy (image); + + gtk_widget_show (text); + gtk_widget_show (label); + gtk_widget_show (box); + gtk_widget_show (window); + gtk_main (); + } + exit (0); +} diff --git a/imtest2.c b/imtest2.c new file mode 100644 index 0000000..e9c6079 --- /dev/null +++ b/imtest2.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int +main () +{ + MInputMethod *im; + MInputContext *ic; + char buf[256]; + int i; + + for (i = 0; i < 2; i++) + { + M17N_INIT (); + im = minput_open_im (Mt, msymbol ("unicode"), NULL); + ic = minput_create_ic (im, NULL); + while (fgets (buf, 256, stdin)) + { + if (buf[strlen (buf) - 1] == '\n') + buf[strlen (buf) - 1] = '\0'; + minput_filter (ic, msymbol (buf), NULL); + } + minput_destroy_ic (ic); + minput_close_im (im); + M17N_FINI (); + } + exit (0); +} -- 1.7.10.4