add api call to get text string advances........

SVN revision: 3447
This commit is contained in:
Carsten Haitzler 2000-09-13 15:52:53 +00:00
parent b4491f3c7c
commit 2d96eee956
4 changed files with 49 additions and 0 deletions

View File

@ -264,6 +264,9 @@ extern "C"
int *vertical_advance_return);
void imlib_get_text_size(const char *text, int *width_return,
int *height_return);
void imlib_get_text_advance(const char *text,
int *horizontal_advance_return,
int *vertical_advance_return);
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);

View File

@ -1697,6 +1697,23 @@ imlib_get_text_size(const char *text, int *width_return, int *height_return)
}
}
void imlib_get_text_advance(const char *text,
int *horizontal_advance_return,
int *vertical_advance_return)
{
ImlibFont *fn;
int w, h;
CHECK_PARAM_POINTER("imlib_get_text_advance", "font", ctxt_font);
CHECK_PARAM_POINTER("imlib_get_text_advance", "text", text);
fn = (ImlibFont *) ctxt_font;
__imlib_calc_advance(fn, &w, &h, text);
if (horizontal_advance_return)
*horizontal_advance_return = w;
if (vertical_advance_return)
*vertical_advance_return = h;
}
void
imlib_add_path_to_font_path(const char *path)
{

View File

@ -381,6 +381,33 @@ __imlib_calc_size(ImlibFont *f, int *width, int *height, const char *text)
*height = ph;
}
void
__imlib_calc_advance(ImlibFont *f, int *adv_w, int *adv_h, const char *text)
{
int i, ascent, descent, pw, ph;
TT_Glyph_Metrics gmetrics;
ascent = f->ascent;
descent = f->descent;
pw = 0;
ph = ascent + descent;
for (i = 0; text[i]; i++)
{
unsigned char j;
j = text[i];
if (!TT_VALID(f->glyphs[j]))
continue;
TT_Get_Glyph_Metrics(f->glyphs[j], &gmetrics);
if (i == 0)
pw += ((-gmetrics.bearingX) / 64);
pw += gmetrics.advance / 64;
}
*adv_w = pw;
*adv_h = ph;
}
void
__imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx, int dry, const char *text,
DATA8 r, DATA8 g, DATA8 b, DATA8 a,

View File

@ -33,6 +33,8 @@ ImlibFont *__imlib_load_font(const char *fontname);
void __imlib_free_font(ImlibFont *font);
void __imlib_calc_size(ImlibFont *f, int *width, int *height,
const char *text);
void __imlib_calc_advance(ImlibFont *f, int *adv_w, int *adv_h,
const char *text);
void __imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx,
int dry, const char *text,
DATA8 r, DATA8 g, DATA8 b, DATA8 a,