2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2009 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 __EXPORT__ extern const FontOps FontOps_ift;
44 Esnprintf(s, sizeof(s), "%s/ttfonts", Mode.theme.path);
45 imlib_add_path_to_font_path(s);
46 Esnprintf(s, sizeof(s), "%s/fonts", EDirRoot());
47 imlib_add_path_to_font_path(s);
52 Efont_load(const char *file, int size)
54 static char ttfont_path_set = 0;
64 Esnprintf(s, sizeof(s), "%s/%d", file, size);
65 f = imlib_load_font(s);
73 imlib_context_set_font(f);
78 Efont_extents(EFont * f, const char *text, int len __UNUSED__,
79 int *width, int *height, int *ascent)
83 imlib_context_set_font(f);
84 imlib_get_text_advance(text, width, &h);
85 asc = imlib_get_font_ascent();
86 dsc = imlib_get_font_descent();
92 EFont_draw_string(EImage * im, EFont * f, int x, int y,
93 int r, int g, int b, const char *text)
95 imlib_context_set_image(im);
96 imlib_context_set_color(r, g, b, 255);
97 imlib_context_set_font(f);
98 imlib_text_draw(x, y - imlib_get_maximum_font_ascent(), text);
108 _ift_Load(TextState * ts, const char *name __UNUSED__)
115 ss = strchr(ts->fontname, '/');
118 len = ss - ts->fontname;
122 memcpy(s, ts->fontname, len);
124 font = Efont_load(s, atoi(ss + 1));
128 fdc = EMALLOC(FontCtxIft, 1);
134 ts->type = FONT_TYPE_IFT;
135 ts->ops = &FontOps_ift;
140 _ift_Unload(TextState * ts)
142 FontCtxIft *fdc = (FontCtxIft *) ts->fdc;
144 Efont_free(fdc->font);
148 _ift_TextSize(TextState * ts, const char *text, int len,
149 int *width, int *height, int *ascent)
151 FontCtxIft *fdc = (FontCtxIft *) ts->fdc;
153 Efont_extents(fdc->font, text, len, width, height, ascent);
157 _ift_TextDraw(TextState * ts, int x, int y, const char *text,
160 FontCtxIft *fdc = (FontCtxIft *) ts->fdc;
162 EFont_draw_string(fdc->im, fdc->font, x, y, fdc->r, fdc->g, fdc->b, text);
166 _ift_FdcInit(TextState * ts __UNUSED__, Win win __UNUSED__,
167 Drawable draw __UNUSED__)
173 _ift_FdcSetDrawable(TextState * ts, unsigned long draw)
175 FontCtxIft *fdc = (FontCtxIft *) ts->fdc;
177 fdc->im = (EImage *) draw;
181 _ift_FdcSetColor(TextState * ts __UNUSED__, EColor * ec)
183 FontCtxIft *fdc = (FontCtxIft *) ts->fdc;
185 GET_COLOR(ec, fdc->r, fdc->g, fdc->b);
188 const FontOps FontOps_ift = {
189 _ift_Load, _ift_Unload, _ift_TextSize, TextstateTextFit, _ift_TextDraw,
190 _ift_FdcInit, NULL, _ift_FdcSetDrawable, _ift_FdcSetColor
199 main(int argc, char **argv)
207 disp = XOpenDisplay(NULL);
209 imlib_context_set_display(disp);
210 imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
211 imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
214 win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 640, 480, 0,
216 XMapWindow(disp, win);
219 gcv.subwindow_mode = IncludeInferiors;
220 gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
223 for (i = 3; i < argc; i++)
225 XSetForeground(disp, gc, (rand() << 16 | rand()) & 0xffffff);
226 f = Efont_load(argv[i], atoi(argv[1]));
228 EFont_draw_string(win, gc, 20, atoi(argv[1]) * (i - 2),
230 DefaultVisual(disp, DefaultScreen(disp)),
231 DefaultColormap(disp, DefaultScreen(disp)));
241 #endif /* FONT_TYPE_IFT */