add some of the font api to the api :)

SVN revision: 449
This commit is contained in:
Carsten Haitzler 1999-09-28 23:48:39 +00:00
parent 177ac5eff9
commit b37dfafbb9
5 changed files with 150 additions and 52 deletions

102
api.c
View File

@ -17,6 +17,8 @@
#include "ximage.h"
#include "rgbadraw.h"
#include "api.h"
#include <freetype.h>
#include "font.h"
#define CAST_IMAGE(im, image) (im) = (ImlibImage *)(image)
@ -847,6 +849,7 @@ imlib_updates_append_updates(Imlib_Updates updates,
}
u = u->next;
}
return u;
}
void
@ -953,3 +956,102 @@ imlib_image_tile(Imlib_Image image)
__imlib_TileImageHoriz(im);
__imlib_TileImageVert(im);
}
Imlib_Font
imlib_load_font(char *font_name)
{
return (Imlib_Font)__imlib_load_font(font_name);
}
void
imlib_free_font(Imlib_Font font)
{
__imlib_free_font(font);
}
void
imlib_text_draw(Imlib_Font font, Imlib_Image image, int x, int y,
Imlib_Text_Direction direction, char *text,
Imlib_Color *color, Imlib_Operation operation)
{
ImlibImage *im;
ImlibFont *fn;
CAST_IMAGE(im, image);
fn = (ImlibFont *)font;
__imlib_render_str(im, fn, x, y, text, (DATA8)color->red,
(DATA8)color->green, (DATA8)color->blue,
(DATA8)color->alpha, (char)direction,
NULL, NULL, 0, NULL, NULL,
(ImlibOp)operation);
}
void
imlib_text_draw_with_return_metrics(Imlib_Font font, Imlib_Image image, int x,
int y, Imlib_Text_Direction direction,
char *text, Imlib_Color *color,
Imlib_Operation operation,
int *width_return, int *height_return,
int *horizontal_advance_return,
int *vertical_advance_return)
{
ImlibImage *im;
ImlibFont *fn;
CAST_IMAGE(im, image);
fn = (ImlibFont *)font;
__imlib_render_str(im, fn, x, y, text, (DATA8)color->red,
(DATA8)color->green, (DATA8)color->blue,
(DATA8)color->alpha, (char)direction,
width_return, height_return, 0,
horizontal_advance_return, vertical_advance_return,
(ImlibOp)operation);
}
void
imlib_get_text_size(Imlib_Font font, Imlib_Text_Direction direction,
char *text, int *width_return, int *height_return)
{
ImlibFont *fn;
int w, h;
fn = (ImlibFont *)font;
__imlib_calc_size(fn, &w, &h, text);
switch(direction)
{
case IMLIB_TEXT_TO_RIGHT:
case IMLIB_TEXT_TO_LEFT:
if (width_return)
*width_return = w;
if (height_return)
*height_return = h;
break;
case IMLIB_TEXT_TO_DOWN:
case IMLIB_TEXT_TO_UP:
if (width_return)
*width_return = h;
if (height_return)
*height_return = w;
break;
default:
break;
}
}
void
imlib_add_path_to_font_path(char *path)
{
__imlib_add_font_path(path);
}
void
imlib_remove_path_from_font_path(char *path)
{
__imlib_del_font_path(path);
}
char **
imlib_list_font_path(int *number_return)
{
return __imlib_list_font_path(number_return);
}

44
api.h
View File

@ -18,7 +18,8 @@ typedef struct _imlib_color Imlib_Color;
typedef struct _imlib_rectangle Imlib_Rectangle;
typedef enum _imlib_operation Imlib_Operation;
typedef enum _imlib_load_error Imlib_Load_Error;
typedef enum _imlib_chanel_mask Imlib_Chanel_Mask;
typedef enum _imlib_text_direction Imlib_Text_Direction;
struct _imlib_border
{
@ -43,12 +44,12 @@ enum _imlib_operation
IMLIB_OP_RESHADE
};
enum _imlib_chanel_mask
enum _imlib_text_direction
{
IMLIB_ALPHA = 1,
IMLIB_RED = 2,
IMLIB_GREEN = 4,
IMLIB_BLUE = 8
IMLIB_TEXT_TO_RIGHT = 0,
IMLIB_TEXT_TO_LEFT = 1,
IMLIB_TEXT_TO_DOWN = 2,
IMLIB_TEXT_TO_UP = 3
};
enum _imlib_load_error
@ -257,8 +258,27 @@ void imlib_image_tile_horizontal(Imlib_Image image);
void imlib_image_tile_vertical(Imlib_Image image);
void imlib_image_tile(Imlib_Image image);
#if 0
/* text functions needed */
Imlib_Font imlib_load_font(char *font_name);
void imlib_free_font(Imlib_Font font);
void imlib_text_draw(Imlib_Font font, Imlib_Image image, int x, int y,
Imlib_Text_Direction direction, char *text,
Imlib_Color *color, Imlib_Operation operation);
void imlib_text_draw_with_return_metrics(Imlib_Font font, Imlib_Image image,
int x, int y,
Imlib_Text_Direction direction,
char *text, Imlib_Color *color,
Imlib_Operation operation,
int *width_return, int *height_return,
int *horizontal_advance_return,
int *vertical_advance_return);
void imlib_get_text_size(Imlib_Font font, Imlib_Text_Direction direction,
char *text, int *width_return, int *height_return);
void imlib_add_path_to_font_path(char *path);
void imlib_remove_path_from_font_path(char *path);
char **imlib_list_font_path(int *number_return);
#if 0
void imlib_image_copy_alpha_to_image(Imlib_Image image_source,
Imlib_Image image_destination,
int x, int y);
@ -282,17 +302,7 @@ void imlib_image_fill_rectangle_gradient(Imlib_Image image,
Imlib_Color *bottom_right_color,
Imlib_Channel_Mask mask,
Imlib_Operation operation);
/* text functions needed */
Imlib_Font imlib_load_font(char *font_name);
void imlib_font_set_tab_size(Imlib_Font font, int size);
void imlib_free_font(Imlib_Font font);
void imlib_text_draw(Imlib_font font, Imlib_Image image, int x, int y,
int width, int height, Imlib_Text_Direction direction,
char *text, Imlib_Color *color,
Imlib_Operation operation, char wrap);
void imlib_get_text_size(Imlib_font font, Imlib_Text_Direction direction,
char *text, int *width_return,
int *height_return);
Imlib_Rectangle *imlib_get_text_in_text_size_and_position(Imlib_font font,
Imlib_Text_Direction direction,
int width, int height,

29
font.c
View File

@ -79,7 +79,7 @@ __imlib_del_font_path(char *path)
}
char **
__imlib_list_font_path(char *num_ret)
__imlib_list_font_path(int *num_ret)
{
*num_ret = fpath_num;
return fpath;
@ -254,15 +254,6 @@ __imlib_load_font(char *fontname)
f->glyphs_cached_right =
(TT_Raster_Map **)malloc(f->num_glyph * sizeof(TT_Raster_Map *));
memset(f->glyphs_cached_right, 0, f->num_glyph * sizeof(TT_Raster_Map *));
f->glyphs_cached_left =
(TT_Raster_Map **)malloc(f->num_glyph * sizeof(TT_Raster_Map *));
memset(f->glyphs_cached_left, 0, f->num_glyph * sizeof(TT_Raster_Map *));
f->glyphs_cached_down =
(TT_Raster_Map **)malloc(f->num_glyph * sizeof(TT_Raster_Map *));
memset(f->glyphs_cached_down, 0, f->num_glyph * sizeof(TT_Raster_Map *));
f->glyphs_cached_up =
(TT_Raster_Map **)malloc(f->num_glyph * sizeof(TT_Raster_Map *));
memset(f->glyphs_cached_up, 0, f->num_glyph * sizeof(TT_Raster_Map *));
load_flags = TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH;
f->max_descent = 0;
@ -341,12 +332,6 @@ __imlib_free_font(ImlibFont *font)
{
if ((font->glyphs_cached_right) && (font->glyphs_cached_right[i]))
__imlib_destroy_font_raster(font->glyphs_cached_right[i]);
if ((font->glyphs_cached_left) && (font->glyphs_cached_left[i]))
__imlib_destroy_font_raster(font->glyphs_cached_left[i]);
if ((font->glyphs_cached_down) && (font->glyphs_cached_down[i]))
__imlib_destroy_font_raster(font->glyphs_cached_down[i]);
if ((font->glyphs_cached_up) && (font->glyphs_cached_up[i]))
__imlib_destroy_font_raster(font->glyphs_cached_up[i]);
if (!TT_VALID(font->glyphs[i]))
TT_Done_Glyph(font->glyphs[i]);
}
@ -355,12 +340,6 @@ __imlib_free_font(ImlibFont *font)
/* free glyph cache arrays */
if (font->glyphs_cached_right)
free(font->glyphs_cached_right);
if (font->glyphs_cached_left)
free(font->glyphs_cached_left);
if (font->glyphs_cached_down)
free(font->glyphs_cached_down);
if (font->glyphs_cached_up)
free(font->glyphs_cached_up);
/* free font struct & name */
free(font->name);
free(font);
@ -400,7 +379,7 @@ void
__imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx, int dry, char *text,
DATA8 r, DATA8 g, DATA8 b, DATA8 a,
char dir, int *retw, int *reth, int blur,
int *nextx, int *nexty)
int *nextx, int *nexty, ImlibOp op)
{
DATA32 lut[9], *p, *tmp;
TT_Glyph_Metrics metrics;
@ -619,12 +598,12 @@ __imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx, int dry, char *text,
__imlib_BlendRGBAToData(tmp, im2.w, im2.h,
im->data, im->w, im->h,
0, 0, drx, dry, im2.w, im2.h,
1, NULL, OP_COPY);
1, NULL, op);
else
__imlib_BlendRGBAToData(tmp, im2.w, im2.h,
im->data, im->w, im->h,
0, 0, drx, dry, im2.w, im2.h,
0, NULL, OP_COPY);
0, NULL, op);
free(tmp);
__imlib_destroy_font_raster(rmap);
}

7
font.h
View File

@ -16,9 +16,6 @@ struct _imlib_font
int num_glyph;
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached_right;
TT_Raster_Map **glyphs_cached_left;
TT_Raster_Map **glyphs_cached_down;
TT_Raster_Map **glyphs_cached_up;
int max_descent;
int max_ascent;
int descent;
@ -29,7 +26,7 @@ TT_Raster_Map *__imlib_create_font_raster(int width, int height);
void __imlib_destroy_font_raster(TT_Raster_Map * rmap);
void __imlib_add_font_path(char *path);
void __imlib_del_font_path(char *path);
char **__imlib_list_font_path(char *num_ret);
char **__imlib_list_font_path(int *num_ret);
ImlibFont *__imlib_find_cached_font(char *fontname);
ImlibFont *__imlib_load_font(char *fontname);
void __imlib_free_font(ImlibFont *font);
@ -39,6 +36,6 @@ void __imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx,
int dry, char *text,
DATA8 r, DATA8 g, DATA8 b, DATA8 a,
char dir, int *retw, int *reth, int blur,
int *nextx, int *nexty);
int *nextx, int *nexty, ImlibOp op);
#endif

20
main.c
View File

@ -197,10 +197,10 @@ int main (int argc, char **argv)
/* "ARIAL/30" "COMIC/30" "IMPACT/30" "Prole/30" "Proteron/30" */
/* "TIMES/30" "badacid/30" "bajoran/30" "bigfish/30" */
__imlib_add_font_path("./ttfonts");
imlib_add_path_to_font_path("./ttfonts");
if (fon)
{
fn = __imlib_load_font(fon);
fn = imlib_load_font(fon);
if (!fn)
fon = NULL;
}
@ -286,13 +286,23 @@ int main (int argc, char **argv)
ty = y;
for (i = 0; i < 16; i++)
{
Imlib_Color cl;
int al;
al = (15 - i) * 16;
if (al > 255)
al = 255;
__imlib_render_str(im, fn, x, ty, str,
255, 255, 255, al,
0, &retw, &reth, 0, &nx, &ny);
cl.red = 255;
cl.green = 255;
cl.blue = 255;
cl.alpha = al;
imlib_text_draw_with_return_metrics(fn, im, x, ty,
IMLIB_TEXT_TO_RIGHT,
str, &cl,
IMLIB_OP_COPY,
&retw, &reth,
&nx, &ny);
up = imlib_update_append_rect(up, px, ty + (py - y), retw, reth);
up = imlib_update_append_rect(up, x, ty, retw, reth);
ty += ny;