2 more text geometry rotuines......... um........ done! :)

SVN revision: 3088
This commit is contained in:
Carsten Haitzler 2000-08-10 22:12:42 +00:00
parent b6a389103c
commit c72ef1301d
5 changed files with 142 additions and 8 deletions

View File

@ -8,7 +8,7 @@ MAINTAINERCLEANFILES = Makefile.in
LIBS_X = @x_ldflags@ @x_libs@
LIBS_IMLIB2 = -lImlib2 -lttf -ldl -lm
LIBS_DB = -ledb
LIBS_GL = -lGL
LIBS_GL = -lGL -lGLU
LIBS_EXTRA = -L/usr/local/lib
CFLAGS_X = @x_cflags@

View File

@ -53,6 +53,8 @@ static char __evas_have_engine = 0;
static int __evas_font_cache_max = 512 * 1024;
static int __evas_font_cache_used = 0;
static int __evas_anti_alias = 1;
const int __evas_rend_lut[9] = { 0, 64, 128, 192, 255, 255, 255, 255, 255};
#define TT_VALID( handle ) ( ( handle ).z != NULL )
@ -96,8 +98,16 @@ __evas_gl_image_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y,
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (__evas_anti_alias)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
data = malloc(tw * th * 4);
for (ty = 0; ty < h; ty++)
@ -128,8 +138,12 @@ __evas_gl_image_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y,
if (tx < tw)
*p2 = p2[-1];
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tw, th, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data);
if (__evas_anti_alias)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, tw, th, GL_RGBA,
GL_UNSIGNED_BYTE, data);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tw, th, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data);
free(data);
}
@ -647,6 +661,11 @@ __evas_gl_image_set_borders(Evas_GL_Image *im, int left, int right,
}
}
void
__evas_gl_image_set_smooth_scaling(int on)
{
__evas_anti_alias = on;
}
@ -1413,6 +1432,92 @@ __evas_gl_text_get_size(Evas_GL_Font *fn, char *text, int *w, int *h)
__evas_gl_text_calc_size(fn, w, h, text);
}
int
__evas_gl_text_get_character_at_pos(Evas_GL_Font *fn, char *text, int x, int y, int *cx, int *cy, int *cw, int *ch)
{
int i, px, ppx;
TT_Glyph_Metrics gmetrics;
if ((y < 0) || (y > (fn->ascent + fn->descent)))
return -1;
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 ((x >= ppx) && (x < px))
{
if (cx)
*cx = ppx;
if (cw)
*cw = px - ppx;
return i;
}
}
*cw = 0;
*ch = 0;
*cx = 0;
*cy = 0;
return -1;
}
void
__evas_gl_text_get_character_pos(Evas_GL_Font *fn, 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;
}
}
*cw = 0;
*ch = 0;
*cx = 0;
*cy = 0;
}

View File

@ -9,6 +9,7 @@
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@ -138,10 +139,11 @@ void __evas_gl_image_free(Evas_GL_Image *im);
void __evas_gl_image_cache_empty(Display *disp);
void __evas_gl_image_cache_set_size(Display *disp, int size);
int __evas_gl_image_cache_get_size(Display *disp);
void __evas_gl_image_draw(Evas_GL_Image *im, Display *disp, Window w, int win_w, int win_h, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h);
int __evas_gl_image_get_width(Evas_GL_Image *im);
int __evas_gl_image_get_height(Evas_GL_Image *im);
void __evas_gl_image_set_borders(Evas_GL_Image *im, int left, int right, int top, int bottom);
void __evas_gl_image_set_smooth_scaling(int on);
void __evas_gl_image_draw(Evas_GL_Image *im, Display *disp, Window w, int win_w, int win_h, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h);
/********/
/* text */
@ -154,8 +156,10 @@ char **__evas_gl_text_font_list_paths(int *count);
void __evas_gl_text_cache_empty(Display *disp);
void __evas_gl_text_cache_set_size(Display *disp, int size);
int __evas_gl_text_cache_get_size(Display *disp);
void __evas_gl_text_draw(Evas_GL_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a);
void __evas_gl_text_get_size(Evas_GL_Font *fn, char *text, int *w, int *h);
int __evas_gl_text_get_character_at_pos(Evas_GL_Font *fn, char *text, int x, int y, int *cx, int *cy, int *cw, int *ch);
void __evas_gl_text_get_character_number(Evas_GL_Font *fn, char *text, int num, int *cx, int *cy, int *cw, int *ch);
void __evas_gl_text_draw(Evas_GL_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a);
/**************/
/* rectangles */

View File

@ -134,6 +134,11 @@ __evas_imlib_image_set_borders(Evas_Imlib_Image *im, int left, int right,
imlib_image_set_border(&bd);
}
void
__evas_imlib_image_set_smooth_scaling(int on)
{
imlib_context_set_anti_alias((char)on);
}
@ -284,6 +289,23 @@ __evas_imlib_text_get_size(Evas_Imlib_Font *fn, char *text, int *w, int *h)
imlib_get_text_size(text, w, h);
}
int
__evas_imlib_text_get_character_at_pos(Evas_Imlib_Font *fn, char *text,
int x, int y,
int *cx, int *cy, int *cw, int *ch)
{
imlib_context_set_font((Imlib_Font)fn);
return imlib_text_get_index_and_location(text, x, y, cx, cy, cw, ch);
}
void
__evas_imlib_text_get_character_number(Evas_Imlib_Font *fn, char *text,
int num,
int *cx, int *cy, int *cw, int *ch)
{
imlib_context_set_font((Imlib_Font)fn);
imlib_text_get_location_at_index(text, num, cx, cy, cw, ch);
}

View File

@ -47,6 +47,7 @@ int __evas_imlib_image_cache_get_size(Display *disp);
int __evas_imlib_image_get_width(Evas_Imlib_Image *im);
int __evas_imlib_image_get_height(Evas_Imlib_Image *im);
void __evas_imlib_image_set_borders(Evas_Imlib_Image *im, int left, int right, int top, int bottom);
void __evas_imlib_image_set_smooth_scaling(int on);
void __evas_imlib_image_draw(Evas_Imlib_Image *im, Display *disp, Window w, int win_w, int win_h, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h);
/********/
@ -60,8 +61,10 @@ char **__evas_imlib_text_font_list_paths(int *count);
void __evas_imlib_text_cache_empty(Display *disp);
void __evas_imlib_text_cache_set_size(Display *disp, int size);
int __evas_imlib_text_cache_get_size(Display *disp);
void __evas_imlib_text_draw(Evas_Imlib_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a);
void __evas_imlib_text_get_size(Evas_Imlib_Font *fn, char *text, int *w, int *h);
int __evas_imlib_text_get_character_at_pos(Evas_Imlib_Font *fn, char *text, int x, int y, int *cx, int *cy, int *cw, int *ch);
void __evas_imlib_text_get_character_number(Evas_Imlib_Font *fn, char *text, int num, int *cx, int *cy, int *cw, int *ch);
void __evas_imlib_text_draw(Evas_Imlib_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a);
/**************/
/* rectangles */