2002-11-08 00:02:15 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
|
2004-01-15 06:58:03 -08:00
|
|
|
FT_Library evas_ft_lib = 0;
|
2004-01-12 10:12:41 -08:00
|
|
|
static int initialised = 0;
|
2002-11-08 00:02:15 -08:00
|
|
|
|
|
|
|
void
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_init(void)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2004-01-12 15:48:10 -08:00
|
|
|
initialised++;
|
|
|
|
if (initialised != 1) return;
|
2004-01-15 06:58:03 -08:00
|
|
|
error = FT_Init_FreeType(&evas_ft_lib);
|
2004-01-12 15:48:10 -08:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
initialised--;
|
|
|
|
return;
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
2004-01-12 10:12:41 -08:00
|
|
|
void
|
|
|
|
evas_common_font_shutdown(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2004-01-12 15:48:10 -08:00
|
|
|
initialised--;
|
|
|
|
if (initialised != 0) return;
|
2004-01-15 06:58:03 -08:00
|
|
|
error = FT_Done_FreeType(evas_ft_lib);
|
2004-01-12 10:12:41 -08:00
|
|
|
}
|
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_ascent_get(RGBA_Font *fn)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2004-01-26 03:09:01 -08:00
|
|
|
int val, dv;
|
2002-11-08 00:02:15 -08:00
|
|
|
int ret;
|
2005-03-20 07:57:55 -08:00
|
|
|
RGBA_Font_Int *fi;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2004-01-23 03:03:07 -08:00
|
|
|
evas_common_font_size_use(fn);
|
2005-03-20 07:57:55 -08:00
|
|
|
fi = fn->fonts->data;
|
|
|
|
val = (int)fi->src->ft.face->size->metrics.ascender;
|
2005-05-21 19:49:48 -07:00
|
|
|
dv = (fi->src->ft.orig_upem * 2048) / fi->src->ft.face->units_per_EM;
|
2005-03-20 07:57:55 -08:00
|
|
|
ret = (val * fi->src->ft.face->size->metrics.y_scale) / (dv * dv);
|
2004-01-26 03:09:01 -08:00
|
|
|
return ret;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_descent_get(RGBA_Font *fn)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2004-01-26 03:09:01 -08:00
|
|
|
int val, dv;
|
2002-11-08 00:02:15 -08:00
|
|
|
int ret;
|
2005-03-20 07:57:55 -08:00
|
|
|
RGBA_Font_Int *fi;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2004-01-22 18:14:45 -08:00
|
|
|
evas_common_font_size_use(fn);
|
2005-03-20 07:57:55 -08:00
|
|
|
fi = fn->fonts->data;
|
|
|
|
val = -(int)fi->src->ft.face->size->metrics.descender;
|
2005-05-21 19:49:48 -07:00
|
|
|
dv = (fi->src->ft.orig_upem * 2048) / fi->src->ft.face->units_per_EM;
|
2005-03-20 07:57:55 -08:00
|
|
|
ret = (val * fi->src->ft.face->size->metrics.y_scale) / (dv * dv);
|
2004-01-26 03:09:01 -08:00
|
|
|
return ret;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_max_ascent_get(RGBA_Font *fn)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2004-01-26 00:21:00 -08:00
|
|
|
int val, dv;
|
2002-11-08 00:02:15 -08:00
|
|
|
int ret;
|
2005-03-20 07:57:55 -08:00
|
|
|
RGBA_Font_Int *fi;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2004-01-22 18:14:45 -08:00
|
|
|
evas_common_font_size_use(fn);
|
2005-03-20 07:57:55 -08:00
|
|
|
fi = fn->fonts->data;
|
|
|
|
val = (int)fi->src->ft.face->bbox.yMax;
|
2005-05-21 19:49:48 -07:00
|
|
|
dv = (fi->src->ft.orig_upem * 2048) / fi->src->ft.face->units_per_EM;
|
2005-03-20 07:57:55 -08:00
|
|
|
ret = (val * fi->src->ft.face->size->metrics.y_scale) / (dv * dv);
|
2002-11-08 00:02:15 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_max_descent_get(RGBA_Font *fn)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2004-01-26 00:21:00 -08:00
|
|
|
int val, dv;
|
2002-11-08 00:02:15 -08:00
|
|
|
int ret;
|
2005-03-20 07:57:55 -08:00
|
|
|
RGBA_Font_Int *fi;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2004-01-22 18:14:45 -08:00
|
|
|
evas_common_font_size_use(fn);
|
2005-03-20 07:57:55 -08:00
|
|
|
fi = fn->fonts->data;
|
|
|
|
val = -(int)fi->src->ft.face->bbox.yMin;
|
2005-05-21 19:49:48 -07:00
|
|
|
dv = (fi->src->ft.orig_upem * 2048) / fi->src->ft.face->units_per_EM;
|
2005-03-20 07:57:55 -08:00
|
|
|
ret = (val * fi->src->ft.face->size->metrics.y_scale) / (dv * dv);
|
2002-11-08 00:02:15 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_get_line_advance(RGBA_Font *fn)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2004-01-26 03:27:59 -08:00
|
|
|
int val, dv;
|
2002-11-08 00:02:15 -08:00
|
|
|
int ret;
|
2005-03-20 07:57:55 -08:00
|
|
|
RGBA_Font_Int *fi;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2004-01-22 18:14:45 -08:00
|
|
|
evas_common_font_size_use(fn);
|
2005-03-20 07:57:55 -08:00
|
|
|
fi = fn->fonts->data;
|
|
|
|
val = (int)fi->src->ft.face->size->metrics.height;
|
2005-05-21 19:49:48 -07:00
|
|
|
dv = (fi->src->ft.orig_upem * 2048) / fi->src->ft.face->units_per_EM;
|
2005-03-20 07:57:55 -08:00
|
|
|
ret = (val * fi->src->ft.face->size->metrics.y_scale) / (dv * dv);
|
2002-11-08 00:02:15 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_font_utf8_get_next(unsigned char *buf, int *iindex)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
/* Reads UTF8 bytes from @buf, starting at *@index and returns
|
2005-05-21 19:49:48 -07:00
|
|
|
* the decoded code point at iindex offset, and advances iidnex
|
2005-02-09 08:10:56 -08:00
|
|
|
* to the next code point after this.
|
2005-05-21 19:49:48 -07:00
|
|
|
*
|
2002-11-08 00:02:15 -08:00
|
|
|
* Returns 0 to indicate an error (e.g. invalid UTF8)
|
2005-05-21 19:49:48 -07:00
|
|
|
*/
|
2005-02-23 12:32:07 -08:00
|
|
|
int index = *iindex, r;
|
2005-02-09 08:10:56 -08:00
|
|
|
unsigned char d, d2, d3, d4;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2005-02-09 08:10:56 -08:00
|
|
|
d = buf[index++];
|
2002-11-08 00:02:15 -08:00
|
|
|
if (!d)
|
|
|
|
return 0;
|
2005-05-21 19:49:48 -07:00
|
|
|
if (d < 0x80)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
*iindex = index;
|
2005-05-21 19:49:48 -07:00
|
|
|
return d;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2005-05-21 19:49:48 -07:00
|
|
|
if ((d & 0xe0) == 0xc0)
|
|
|
|
{
|
2002-11-08 00:02:15 -08:00
|
|
|
/* 2 byte */
|
2004-07-19 21:05:14 -07:00
|
|
|
if (((d2 = buf[index++]) & 0xc0) != 0x80)
|
2002-11-08 00:02:15 -08:00
|
|
|
return 0;
|
|
|
|
r = d & 0x1f; /* copy lower 5 */
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f); /* copy lower 6 */
|
|
|
|
}
|
2005-05-21 19:49:48 -07:00
|
|
|
else if ((d & 0xf0) == 0xe0)
|
|
|
|
{
|
2002-11-08 00:02:15 -08:00
|
|
|
/* 3 byte */
|
2004-07-19 21:05:14 -07:00
|
|
|
if (((d2 = buf[index++]) & 0xc0) != 0x80 ||
|
2004-07-20 04:07:06 -07:00
|
|
|
((d3 = buf[index++]) & 0xc0) != 0x80)
|
|
|
|
return 0;
|
|
|
|
r = d & 0x0f; /* copy lower 4 */
|
2002-11-08 00:02:15 -08:00
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f);
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d3 & 0x3f);
|
|
|
|
}
|
2003-06-04 23:08:43 -07:00
|
|
|
else
|
2005-05-21 19:49:48 -07:00
|
|
|
{
|
2002-11-08 00:02:15 -08:00
|
|
|
/* 4 byte */
|
2004-07-19 21:05:14 -07:00
|
|
|
if (((d2 = buf[index++]) & 0xc0) != 0x80 ||
|
|
|
|
((d3 = buf[index++]) & 0xc0) != 0x80 ||
|
|
|
|
((d4 = buf[index++]) & 0xc0) != 0x80)
|
2002-11-08 00:02:15 -08:00
|
|
|
return 0;
|
|
|
|
r = d & 0x0f; /* copy lower 4 */
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f);
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d3 & 0x3f);
|
|
|
|
r <<= 6;
|
2005-05-21 19:49:48 -07:00
|
|
|
r |= (d4 & 0x3f);
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2003-06-04 23:08:43 -07:00
|
|
|
*iindex = index;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
evas_common_font_utf8_get_prev(unsigned char *buf, int *iindex)
|
|
|
|
{
|
|
|
|
/* Reads UTF8 bytes from @buf, starting at *@index and returns
|
2005-05-21 19:49:48 -07:00
|
|
|
* the decoded code point at iindex offset, and advances iidnex
|
2005-02-09 08:10:56 -08:00
|
|
|
* to the next code point after this.
|
2005-05-21 19:49:48 -07:00
|
|
|
*
|
2003-06-04 23:08:43 -07:00
|
|
|
* Returns 0 to indicate an error (e.g. invalid UTF8)
|
2005-05-21 19:49:48 -07:00
|
|
|
*/
|
2003-06-04 23:08:43 -07:00
|
|
|
int index = *iindex, r, istart = *iindex;
|
2005-02-09 08:10:56 -08:00
|
|
|
unsigned char d, d2, d3, d4;
|
|
|
|
|
|
|
|
d = buf[index++];
|
2005-05-21 19:49:48 -07:00
|
|
|
if (d < 0x80)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2003-06-04 23:08:43 -07:00
|
|
|
r = d;
|
|
|
|
}
|
2005-05-21 19:49:48 -07:00
|
|
|
else if ((d & 0xe0) == 0xc0)
|
|
|
|
{
|
2003-06-04 23:08:43 -07:00
|
|
|
/* 2 byte */
|
|
|
|
d2 = buf[index++];
|
|
|
|
if ((d2 & 0xc0) != 0x80)
|
|
|
|
return 0;
|
|
|
|
r = d & 0x1f; /* copy lower 5 */
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f); /* copy lower 6 */
|
|
|
|
}
|
2005-05-21 19:49:48 -07:00
|
|
|
else if ((d & 0xf0) == 0xe0)
|
|
|
|
{
|
2003-06-04 23:08:43 -07:00
|
|
|
/* 3 byte */
|
|
|
|
d2 = buf[index++];
|
|
|
|
d3 = buf[index++];
|
|
|
|
if ((d2 & 0xc0) != 0x80 ||
|
|
|
|
(d3 & 0xc0) != 0x80)
|
|
|
|
return 0;
|
|
|
|
r = d & 0x0f; /* copy lower 4 */
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f);
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d3 & 0x3f);
|
|
|
|
}
|
|
|
|
else
|
2005-05-21 19:49:48 -07:00
|
|
|
{
|
2003-06-04 23:08:43 -07:00
|
|
|
/* 4 byte */
|
|
|
|
d2 = buf[index++];
|
|
|
|
d3 = buf[index++];
|
|
|
|
d4 = buf[index++];
|
|
|
|
if ((d2 & 0xc0) != 0x80 ||
|
|
|
|
(d3 & 0xc0) != 0x80 ||
|
|
|
|
(d4 & 0xc0) != 0x80)
|
|
|
|
return 0;
|
|
|
|
r = d & 0x0f; /* copy lower 4 */
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d2 & 0x3f);
|
|
|
|
r <<= 6;
|
|
|
|
r |= (d3 & 0x3f);
|
|
|
|
r <<= 6;
|
2005-05-21 19:49:48 -07:00
|
|
|
r |= (d4 & 0x3f);
|
2003-06-04 23:08:43 -07:00
|
|
|
}
|
2005-02-20 00:02:41 -08:00
|
|
|
if (istart > 0)
|
2003-06-04 23:08:43 -07:00
|
|
|
{
|
2005-02-20 00:02:41 -08:00
|
|
|
index = istart - 1;
|
|
|
|
d = buf[index];
|
|
|
|
if (!(d & 0x80))
|
|
|
|
*iindex = index;
|
|
|
|
else
|
2003-06-04 23:08:43 -07:00
|
|
|
{
|
2005-02-20 00:02:41 -08:00
|
|
|
while (index > 0)
|
2003-06-04 23:08:43 -07:00
|
|
|
{
|
2005-02-20 00:02:41 -08:00
|
|
|
index--;
|
|
|
|
d = buf[index];
|
|
|
|
if ((d & 0xc0) != 0x80)
|
|
|
|
{
|
|
|
|
*iindex = index;
|
|
|
|
return r;
|
|
|
|
}
|
2003-06-04 23:08:43 -07:00
|
|
|
}
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2005-02-20 00:02:41 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*iindex = -1;
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
return r;
|
|
|
|
}
|
2005-02-09 08:10:56 -08:00
|
|
|
|
|
|
|
int
|
|
|
|
evas_common_font_utf8_get_last(unsigned char *buf, int buflen)
|
|
|
|
{
|
|
|
|
/* jumps to the nul byte at the buffer end and decodes backwards and
|
|
|
|
* returns the offset index byte in the buffer where the last character
|
|
|
|
* in the buffer begins.
|
2005-05-21 19:49:48 -07:00
|
|
|
*
|
2005-02-09 08:10:56 -08:00
|
|
|
* Returns -1 to indicate an error
|
|
|
|
*/
|
|
|
|
int index;
|
|
|
|
unsigned char d;
|
2005-05-21 19:49:48 -07:00
|
|
|
|
2005-02-09 08:10:56 -08:00
|
|
|
if (buflen < 1) return 0;
|
|
|
|
index = buflen - 1;
|
|
|
|
d = buf[index];
|
|
|
|
if (!(d & 0x80))
|
|
|
|
return index;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (index > 0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
d = buf[index];
|
|
|
|
if ((d & 0xc0) != 0x80)
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|