1 #include "evas_common.h"
5 evas_common_font_query_size(RGBA_Font *fn, const char *text, int *w, int *h)
22 evas_common_font_size_use(fn);
23 use_kerning = FT_HAS_KERNING(fi->src->ft.face);
25 for (chr = 0; text[chr];)
29 int chr_x, chr_y, chr_w;
32 gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
34 index = evas_common_font_glyph_search(fn, &fi, gl);
35 /* hmmm kerning means i can't sanely do my own cached metric tables! */
36 /* grrr - this means font face sharing is kinda... not an option if */
37 /* you want performance */
39 if ((use_kerning) && (prev_index) && (index) &&
40 (pface == fi->src->ft.face))
44 if (FT_Get_Kerning(fi->src->ft.face, prev_index, index,
45 ft_kerning_default, &delta) == 0)
51 pface = fi->src->ft.face;
52 fg = evas_common_font_int_cache_glyph_get(fi, index);
55 if (kern < 0) kern = 0;
56 chr_x = ((pen_x - kern) + (fg->glyph_out->left));
57 chr_y = (pen_y + (fg->glyph_out->top));
58 // chr_w = fg->glyph_out->bitmap.width;
59 chr_w = fg->glyph_out->bitmap.width + kern;
63 advw = ((fg->glyph->advance.x + (kern << 16)) >> 16);
64 if (chr_w < advw) chr_w = advw;
67 if ((!prev_index) && (chr_x < 0))
69 if ((chr_x + chr_w) > end_x)
70 end_x = chr_x + chr_w;
72 pen_x += fg->glyph->advance.x >> 16;
75 if (w) *w = end_x - start_x;
76 if (h) *h = evas_common_font_max_ascent_get(fn) + evas_common_font_max_descent_get(fn);
81 evas_common_font_query_inset(RGBA_Font *fn, const char *text)
92 if (!text[0]) return 0;
93 gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
94 if (gl == 0) return 0;
95 evas_common_font_size_use(fn);
96 index = evas_common_font_glyph_search(fn, &fi, gl);
97 fg = evas_common_font_int_cache_glyph_get(fi, index);
100 printf("fg->glyph_out->left = %i\n"
101 "fi->src->ft.face->glyph->bitmap_left = %i\n"
102 "fi->src->ft.face->glyph->metrics.horiBearingX = %i\n"
103 "fi->src->ft.face->glyph->metrics.horiBearingY = %i\n"
104 "fi->src->ft.face->glyph->metrics.horiAdvance = %i\n"
106 (int)fg->glyph_out->left,
107 (int)fi->src->ft.face->glyph->bitmap_left,
108 (int)fi->src->ft.face->glyph->metrics.horiBearingX >> 6,
109 (int)fi->src->ft.face->glyph->metrics.horiBearingY >> 6,
110 (int)fi->src->ft.face->glyph->metrics.horiAdvance >> 6
113 return fg->glyph_out->left;
118 evas_common_font_query_advance(RGBA_Font *fn, const char *text, int *h_adv, int *v_adv)
126 FT_Face pface = NULL;
128 fi = fn->fonts->data;
133 evas_common_font_size_use(fn);
134 use_kerning = FT_HAS_KERNING(fi->src->ft.face);
136 for (chr = 0; text[chr];)
140 int chr_x, chr_y, chr_w;
143 gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
145 index = evas_common_font_glyph_search(fn, &fi, gl);
146 /* hmmm kerning means i can't sanely do my own cached metric tables! */
147 /* grrr - this means font face sharing is kinda... not an option if */
148 /* you want performance */
149 if ((use_kerning) && (prev_index) && (index) &&
150 (pface == fi->src->ft.face))
154 if (FT_Get_Kerning(fi->src->ft.face, prev_index, index,
155 ft_kerning_default, &delta) == 0)
156 pen_x += delta.x >> 6;
158 pface = fi->src->ft.face;
159 fg = evas_common_font_int_cache_glyph_get(fi, index);
162 chr_x = (pen_x + (fg->glyph_out->left));
163 chr_y = (pen_y + (fg->glyph_out->top));
164 chr_w = fg->glyph_out->bitmap.width;
166 pen_x += fg->glyph->advance.x >> 16;
169 if (v_adv) *v_adv = evas_common_font_get_line_advance(fn);
170 if (h_adv) *h_adv = pen_x - start_x;
173 /* x y w h for char at char pos */
175 evas_common_font_query_char_coords(RGBA_Font *fn, const char *text, int pos, int *cx, int *cy, int *cw, int *ch)
184 FT_Face pface = NULL;
186 fi = fn->fonts->data;
190 evas_common_font_size_use(fn);
191 use_kerning = FT_HAS_KERNING(fi->src->ft.face);
194 asc = evas_common_font_max_ascent_get(fn);
195 desc = evas_common_font_max_descent_get(fn);
196 for (chr = 0; text[chr];)
201 int chr_x, chr_y, chr_w;
205 gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
207 index = evas_common_font_glyph_search(fn, &fi, gl);
209 /* hmmm kerning means i can't sanely do my own cached metric tables! */
210 /* grrr - this means font face sharing is kinda... not an option if */
211 /* you want performance */
212 if ((use_kerning) && (prev_index) && (index) &&
213 (pface == fi->src->ft.face))
217 if (FT_Get_Kerning(fi->src->ft.face, prev_index, index,
218 ft_kerning_default, &delta) == 0)
224 pface = fi->src->ft.face;
225 fg = evas_common_font_int_cache_glyph_get(fi, index);
228 if (kern < 0) kern = 0;
229 chr_x = ((pen_x - kern) + (fg->glyph_out->left));
230 chr_y = (pen_y + (fg->glyph_out->top));
231 chr_w = fg->glyph_out->bitmap.width + (kern);
236 advw = ((fg->glyph->advance.x + (kern << 16)) >> 16);
237 if (chr_w < advw) chr_w = advw;
239 if (chr_x > prev_chr_end)
241 chr_w += (chr_x - prev_chr_end);
242 chr_x = prev_chr_end;
249 if (ch) *ch = asc + desc;
252 prev_chr_end = chr_x + chr_w;
253 pen_x += fg->glyph->advance.x >> 16;
259 /* char pos of text at xy pos */
261 evas_common_font_query_text_at_pos(RGBA_Font *fn, const char *text, int x, int y, int *cx, int *cy, int *cw, int *ch)
270 FT_Face pface = NULL;
272 fi = fn->fonts->data;
276 evas_common_font_size_use(fn);
277 use_kerning = FT_HAS_KERNING(fi->src->ft.face);
280 asc = evas_common_font_max_ascent_get(fn);
281 desc = evas_common_font_max_descent_get(fn);
282 for (chr = 0; text[chr];)
287 int chr_x, chr_y, chr_w;
291 gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
293 index = evas_common_font_glyph_search(fn, &fi, gl);
295 /* hmmm kerning means i can't sanely do my own cached metric tables! */
296 /* grrr - this means font face sharing is kinda... not an option if */
297 /* you want performance */
298 if ((use_kerning) && (prev_index) && (index) &&
299 (pface == fi->src->ft.face))
303 if (FT_Get_Kerning(fi->src->ft.face, prev_index, index,
304 ft_kerning_default, &delta) == 0)
310 pface = fi->src->ft.face;
311 fg = evas_common_font_int_cache_glyph_get(fi, index);
314 if (kern < 0) kern = 0;
315 chr_x = ((pen_x - kern) + (fg->glyph_out->left));
316 chr_y = (pen_y + (fg->glyph_out->top));
317 chr_w = fg->glyph_out->bitmap.width + kern;
322 advw = ((fg->glyph->advance.x + (kern << 16)) >> 16);
323 if (chr_w < advw) chr_w = advw;
325 if (chr_x > prev_chr_end)
327 chr_w += (chr_x - prev_chr_end);
328 chr_x = prev_chr_end;
330 if ((x >= chr_x) && (x <= (chr_x + chr_w)) &&
331 (y >= -asc) && (y <= desc))
336 if (ch) *ch = asc + desc;
339 prev_chr_end = chr_x + chr_w;
340 pen_x += fg->glyph->advance.x >> 16;