On Mon, Mar 31, 2003 at 9:54:39 +0900, Tomohiro KUBOTA wrote:
>
> Unfortunately, there are no tutorials for Pango. A developer of "Xplanet"
> and I sent mails to a Pango developers (Evan Martin and Noah Levitt) to
> ask that but they think Pango is not intended to be used from applications
> directly but from upper toolkit layer.
I appreciate the compliment, but I'm not a pango developer,
I'm just a user. :)
>
> However, GTK2 is too heavy to be recommended for *all* softwares which
> displays some text.
>
There are actually good reasons to recommend gtk2 for all
software that displays text. One that springs to mind is
that the default font comes from the user's theme.
However, it's not too difficult to use pango with gdk only.
Gdk is quite lightweight.
To satisfy my own curiosity, I wrote a simple gdk program
that uses pango to draw some text. It can be compiled with
$ gcc -Wall -ansi -g `pkg-config --cflags gdk-2.0` pango-example.c `pkg-config --libs
gdk-2.0`
Noah
#define PANGO_ENABLE_BACKEND
#include <gdk/gdk.h>
#define WIDTH 200
#define MARKUP \
"<span lang=\"is\">Ég get etið gler án þess að meiða mig.</span>\n" \
"<span lang=\"ar\">أنا قادر على أكل الزجاج و هذا لا يؤلمني.</span>\n" \
"<span lang=\"hi\">मैं काँच खा सकता हूँ, मुझे उस से कोई पीडा नहीं होती.</span>\n" \
"<span lang=\"yi\">איך קען עסן גלאָז און עס טוט מיר נישט װײ</span>\n" \
"<span lang=\"zh\">我能吞下玻璃而不伤身体。</span>\n" \
"<span lang=\"ja\">私はガラスを食べられます。それは私を傷つけません。</span>\n" \
"<span lang=\"ko\">나는 유리를 먹을 수 있어요. 그래도 아프지 않아요</span>\n" \
"<span lang=\"th\">ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ</span>\n"
int
main (int argc, char **argv)
{
GMainLoop *loop;
PangoContext *context;
PangoLayout *layout;
GdkWindow *window;
GdkGC *gc;
GdkColormap *colormap;
GdkWindowAttr attr =
{
"GDK Pango Test", 0, 0, 0, WIDTH, 400, GDK_INPUT_OUTPUT, NULL, NULL,
GDK_WINDOW_TOPLEVEL, NULL, NULL, NULL, FALSE,
};
GdkColor white = { 0, 65535, 65535, 65535, };
GdkColor black = { 0, 0, 0, 0, };
gdk_init (&argc, &argv);
colormap = gdk_colormap_new (gdk_visual_get_best (), FALSE);
gdk_rgb_find_color (colormap, &white);
gdk_rgb_find_color (colormap, &black);
window = gdk_window_new (NULL, &attr, GDK_WA_TITLE);
gdk_window_set_background (window, &white);
gdk_window_show (window);
gc = gdk_gc_new (GDK_DRAWABLE (window));
gdk_gc_set_foreground (gc, &black);
gdk_gc_set_background (gc, &white);
context = gdk_pango_context_get_for_screen (gdk_screen_get_default ());
layout = pango_layout_new (context);
pango_layout_set_width (layout, WIDTH * PANGO_SCALE);
pango_layout_set_markup (layout, MARKUP, -1);
gdk_draw_layout (GDK_DRAWABLE (window), gc, 0, 0, layout);
gdk_flush ();
loop = g_main_loop_new (g_main_context_new (), FALSE);
g_main_loop_run (loop);
return 0;
}