2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies of the Software, its documentation and marketing & publicity
13 * materials, and acknowledgment shall be given in the documentation, materials
14 * and software packages that this Software was used.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 ImlibSetFgColorFromGC(Display * dpy, GC gc, Colormap cm)
36 XGetGCValues(dpy, gc, GCForeground, &xgcv);
37 xclr.pixel = xgcv.foreground;
38 XQueryColor(dpy, cm, &xclr);
39 EGetColor(&xclr, &r, &g, &b);
40 imlib_context_set_color(r, g, b, 255);
44 EFont_draw_string(Display * dpy, Drawable win, GC gc, int x, int y,
45 const char *text, Efont * f, Visual * vis __UNUSED__,
49 int w, h, ascent, descent, max_asc;
51 Efont_extents(f, text, &ascent, &descent, &w, &max_asc, NULL, NULL, NULL);
54 imlib_context_set_drawable(win);
55 im = imlib_create_image_from_drawable(0, x, y - ascent, w, h, 0);
56 imlib_context_set_image(im);
58 imlib_context_set_font(f->face);
59 ImlibSetFgColorFromGC(dpy, gc, cm);
60 imlib_text_draw(0, ascent - max_asc, text);
61 imlib_render_image_on_drawable(x, y - ascent);
72 imlib_context_set_font(f->face);
79 Efont_load(const char *file, int size)
81 static char fp_set = 0;
88 imlib_add_path_to_font_path(docdir);
89 sprintf(s, "%s/../ttfonts", docdir);
90 imlib_add_path_to_font_path(s);
91 sprintf(s, "%s/fonts", ENLIGHTENMENT_ROOT);
92 imlib_add_path_to_font_path(s);
96 Esnprintf(s, sizeof(s), "%s/%d", file, size);
97 ff = imlib_load_font(s);
101 f = EMALLOC(Efont, 1);
108 Efont_extents(Efont * f, const char *text, int *font_ascent_return,
109 int *font_descent_return, int *width_return,
110 int *max_ascent_return, int *max_descent_return,
111 int *lbearing_return __UNUSED__, int *rbearing_return __UNUSED__)
118 imlib_context_set_font(f->face);
119 imlib_get_text_advance(text, &w, &h);
122 if (font_ascent_return)
123 *font_ascent_return = imlib_get_font_ascent();
124 if (font_descent_return)
125 *font_descent_return = imlib_get_font_descent();
126 if (max_ascent_return)
127 *max_ascent_return = imlib_get_maximum_font_ascent();
128 if (max_descent_return)
129 *max_descent_return = imlib_get_maximum_font_descent();
139 main(int argc, char **argv)
147 disp = XOpenDisplay(NULL);
149 imlib_context_set_display(disp);
150 imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
151 imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
154 win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
156 XMapWindow(disp, win);
159 gcv.subwindow_mode = IncludeInferiors;
160 gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
163 for (i = 3; i < argc; i++)
165 XSetForeground(disp, gc, rand() << 16 | rand());
166 f = Efont_load(argv[i], atoi(argv[1]));
168 EFont_draw_string(disp, win, gc, 20,
169 atoi(argv[1]) * (i - 2), argv[2], f,
170 DefaultVisual(disp, DefaultScreen(disp)),
171 DefaultColormap(disp, DefaultScreen(disp)));