add 1 more font routine for getting geometry - useful. you'll need to

update imlib2 too to get evas to compile & work - it uses this routine


SVN revision: 3087
This commit is contained in:
Carsten Haitzler 2000-08-10 22:11:40 +00:00
parent 6afed42c4a
commit 1896e7b45e
5 changed files with 127 additions and 2 deletions

View File

@ -10,3 +10,4 @@ Takis <takis@lumumba.luc.ac.be>
Dan Maas <dmaas@dcine.com>
pla@cland.ru
boris (Chris Ross) <chris@darkrock.co.uk>
Martin Grimm <grimm.martin@gmx.de>

View File

@ -206,6 +206,7 @@ void imlib_add_path_to_font_path(const char *path);
void imlib_remove_path_from_font_path(const char *path);
char **imlib_list_font_path(int *number_return);
int imlib_text_get_index_and_location(const char *text, int x, int y, int *char_x_return, int *char_y_return, int *char_width_return, int *char_height_return);
void imlib_text_get_location_at_index(const char *text, int index, int *char_x_return, int *char_y_return, int *char_width_return, int *char_height_return);
char **imlib_list_fonts(int *number_return);
void imlib_free_font_list(char **font_list, int number);
int imlib_get_font_cache_size(void);

View File

@ -1654,8 +1654,16 @@ imlib_text_get_index_and_location(const char *text, int x, int y,
switch(ctxt_direction)
{
case IMLIB_TEXT_TO_RIGHT:
return __imlib_char_pos(fn, text, x, y, char_x_return, char_y_return,
char_width_return, char_height_return);
cp = __imlib_char_pos(fn, text, x, y, &cx, &cy, &cw, &ch);
if (char_x_return)
*char_x_return = cx;
if (char_y_return)
*char_y_return = cy;
if (char_width_return)
*char_width_return = cw;
if (char_height_return)
*char_height_return = ch;
return cp;
break;
case IMLIB_TEXT_TO_LEFT:
__imlib_calc_size(fn, &w, &h, text);
@ -1711,6 +1719,80 @@ imlib_text_get_index_and_location(const char *text, int x, int y,
return -1;
}
void
imlib_text_get_location_at_index(const char *text, int index,
int *char_x_return, int *char_y_return,
int *char_width_return,
int *char_height_return)
{
ImlibFont *fn;
int cx, cy, cw, ch, w, h;
CHECK_PARAM_POINTER("imlib_text_get_index_and_location", "font", ctxt_font);
CHECK_PARAM_POINTER("imlib_text_get_index_and_location", "text", text);
fn = (ImlibFont *)ctxt_font;
switch(ctxt_direction)
{
case IMLIB_TEXT_TO_RIGHT:
__imlib_char_geom(fn, text, index, &cx, &cy, &cw, &ch);
if (char_x_return)
*char_x_return = cx;
if (char_y_return)
*char_y_return = cy;
if (char_width_return)
*char_width_return = cw;
if (char_height_return)
*char_height_return = ch;
return;
break;
case IMLIB_TEXT_TO_LEFT:
__imlib_calc_size(fn, &w, &h, text);
__imlib_char_geom(fn, text, index, &cx, &cy, &cw, &ch);
cx = 1 + w - cx - cw;
if (char_x_return)
*char_x_return = cx;
if (char_y_return)
*char_y_return = cy;
if (char_width_return)
*char_width_return = cw;
if (char_height_return)
*char_height_return = ch;
return;
break;
case IMLIB_TEXT_TO_DOWN:
__imlib_calc_size(fn, &w, &h, text);
__imlib_char_geom(fn, text, index, &cx, &cy, &cw, &ch);
if (char_x_return)
*char_x_return = cy;
if (char_y_return)
*char_y_return = cx;
if (char_width_return)
*char_width_return = ch;
if (char_height_return)
*char_height_return = cw;
return;
break;
case IMLIB_TEXT_TO_UP:
__imlib_calc_size(fn, &w, &h, text);
__imlib_char_geom(fn, text, index, &cx, &cy, &cw, &ch);
cy = 1 + h - cy - ch;
if (char_x_return)
*char_x_return = cy;
if (char_y_return)
*char_y_return = cx;
if (char_width_return)
*char_width_return = ch;
if (char_height_return)
*char_height_return = cw;
return;
break;
default:
return;
break;
}
return -1;
}
char **
imlib_list_fonts(int *number_return)
{

View File

@ -754,6 +754,45 @@ __imlib_char_pos(ImlibFont *fn, const char *text, int x, int y,
return -1;
}
void
__imlib_char_geom(ImlibFont *fn, const char *text, int num,
int *cx, int *cy, int *cw, int *ch)
{
int i, px, ppx;
TT_Glyph_Metrics gmetrics;
if (cy)
*cy = 0;
if (ch)
*ch = fn->ascent + fn->descent;
ppx = 0;
px = 0;
for (i = 0; text[i]; i++)
{
unsigned char j;
j = text[i];
if (!TT_VALID(fn->glyphs[j]))
continue;
TT_Get_Glyph_Metrics(fn->glyphs[j], &gmetrics);
ppx = px;
if (i == 0)
px += ((-gmetrics.bearingX) / 64);
if (text[i + 1] == 0)
px += (gmetrics.bbox.xMax / 64);
else
px += gmetrics.advance / 64;
if (i == num)
{
if (cx)
*cx = ppx;
if (cw)
*cw = px - ppx;
return;
}
}
}
char **
__imlib_list_fonts(int *num_ret)
{

View File

@ -40,6 +40,8 @@ void __imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx,
int *nextx, int *nexty, ImlibOp op);
int __imlib_char_pos(ImlibFont *fn, const char *text, int x, int y,
int *cx, int *cy, int *cw, int *ch);
void __imlib_char_geom(ImlibFont *fn, const char *text, int num,
int *cx, int *cy, int *cw, int *ch);
char **__imlib_list_fonts(int *num_ret);
void __imlib_free_font_list(char **list, int num);
int __imlib_get_cached_font_size(void);