2011-01-30 02:36:39 -08:00
|
|
|
#include "evas_font_ot.h"
|
|
|
|
|
|
|
|
#ifdef OT_SUPPORT
|
|
|
|
# include <hb.h>
|
|
|
|
# include <hb-ft.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "evas_common.h"
|
|
|
|
|
|
|
|
#include <Eina.h>
|
|
|
|
#include "evas_font_private.h"
|
|
|
|
|
|
|
|
#ifdef OT_SUPPORT
|
2011-01-30 02:37:29 -08:00
|
|
|
/* FIXME: doc. returns #items */
|
|
|
|
EAPI int
|
2011-02-01 04:17:52 -08:00
|
|
|
evas_common_font_ot_cluster_size_get(const Evas_Text_Props *props, size_t char_index)
|
2011-01-30 02:37:29 -08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int items;
|
|
|
|
int left_bound, right_bound;
|
2011-02-22 05:00:02 -08:00
|
|
|
size_t base_cluster;
|
|
|
|
char_index += props->start;
|
|
|
|
base_cluster = EVAS_FONT_OT_POS_GET(props->info->ot[char_index]);
|
2011-01-30 02:37:29 -08:00
|
|
|
for (i = (int) char_index ;
|
2011-02-01 04:17:52 -08:00
|
|
|
(i >= (int) props->start) &&
|
|
|
|
(EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
|
2011-01-30 02:37:29 -08:00
|
|
|
i--)
|
|
|
|
;
|
|
|
|
left_bound = i;
|
|
|
|
for (i = (int) char_index + 1;
|
2011-02-01 04:17:52 -08:00
|
|
|
(i < (int) (props->start + props->len)) &&
|
|
|
|
(EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
|
2011-01-30 02:37:29 -08:00
|
|
|
i++)
|
|
|
|
;
|
|
|
|
right_bound = i;
|
2011-02-01 04:17:52 -08:00
|
|
|
|
2011-01-30 02:37:29 -08:00
|
|
|
if (right_bound == left_bound)
|
|
|
|
{
|
|
|
|
items = 1;
|
|
|
|
}
|
|
|
|
else if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
|
|
|
|
{
|
|
|
|
if (left_bound < 0)
|
|
|
|
{
|
2011-02-13 04:57:37 -08:00
|
|
|
items = props->text_offset + props->text_len - base_cluster;
|
2011-01-30 02:37:29 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-13 04:57:37 -08:00
|
|
|
items = props->info->ot[left_bound].source_cluster - base_cluster;
|
2011-01-30 02:37:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-14 07:02:52 -08:00
|
|
|
if (right_bound >= (int) (props->text_offset + props->text_len))
|
2011-01-30 02:37:29 -08:00
|
|
|
{
|
2011-02-13 04:57:37 -08:00
|
|
|
items = props->text_offset + props->text_len - base_cluster;
|
2011-01-30 02:37:29 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-13 04:57:37 -08:00
|
|
|
items = props->info->ot[right_bound].source_cluster - base_cluster;
|
2011-01-30 02:37:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (items > 0) ? items : 1;
|
|
|
|
}
|
|
|
|
|
2011-01-30 02:37:52 -08:00
|
|
|
EAPI void
|
|
|
|
evas_common_font_ot_load_face(void *_font)
|
|
|
|
{
|
|
|
|
RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
|
2011-01-30 02:45:23 -08:00
|
|
|
/* Unload the face if by any chance it's already loaded */
|
|
|
|
evas_common_font_ot_unload_face(font);
|
2011-01-30 02:37:52 -08:00
|
|
|
font->hb.face = hb_ft_face_create(font->ft.face, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
evas_common_font_ot_unload_face(void *_font)
|
|
|
|
{
|
|
|
|
RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
|
|
|
|
if (!font->hb.face) return;
|
|
|
|
hb_face_destroy(font->hb.face);
|
|
|
|
font->hb.face = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-02 00:24:57 -08:00
|
|
|
/* Harfbuzz font functions */
|
|
|
|
static hb_font_funcs_t *_ft_font_funcs = NULL;
|
|
|
|
|
|
|
|
static hb_codepoint_t
|
|
|
|
_evas_common_font_ot_hb_get_glyph(hb_font_t *font, hb_face_t *face,
|
|
|
|
const void *user_data, hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector)
|
|
|
|
{
|
|
|
|
RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
|
|
|
|
return hb_font_funcs_get_glyph_func(_ft_font_funcs)(font, face,
|
|
|
|
fi->src->ft.face, unicode, variation_selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_evas_common_font_ot_hb_get_glyph_advance(hb_font_t *font, hb_face_t *face,
|
|
|
|
const void *user_data, hb_codepoint_t glyph,
|
|
|
|
hb_position_t *x_advance, hb_position_t *y_advance)
|
|
|
|
{
|
|
|
|
/* Use our cache*/
|
|
|
|
RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
|
|
|
|
RGBA_Font_Glyph *fg;
|
|
|
|
(void) font;
|
|
|
|
(void) face;
|
|
|
|
fg = evas_common_font_int_cache_glyph_get(fi, glyph);
|
|
|
|
if (fg)
|
|
|
|
{
|
|
|
|
*x_advance = fg->glyph->advance.x >> 10;
|
|
|
|
*y_advance = fg->glyph->advance.y >> 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_evas_common_font_ot_hb_get_glyph_extents(hb_font_t *font, hb_face_t *face,
|
|
|
|
const void *user_data, hb_codepoint_t glyph, hb_glyph_extents_t *extents)
|
|
|
|
{
|
|
|
|
RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
|
|
|
|
hb_font_funcs_get_glyph_extents_func(_ft_font_funcs)(font, face,
|
|
|
|
fi->src->ft.face, glyph, extents);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
|
|
|
_evas_common_font_ot_hb_get_contour_point(hb_font_t *font, hb_face_t *face,
|
|
|
|
const void *user_data, unsigned int point_index, hb_codepoint_t glyph,
|
|
|
|
hb_position_t *x, hb_position_t *y)
|
|
|
|
{
|
|
|
|
RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
|
|
|
|
return hb_font_funcs_get_contour_point_func(_ft_font_funcs)(font, face,
|
|
|
|
fi->src->ft.face, point_index, glyph, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_position_t
|
|
|
|
_evas_common_font_ot_hb_get_kerning(hb_font_t *font, hb_face_t *face,
|
|
|
|
const void *user_data, hb_codepoint_t first_glyph,
|
|
|
|
hb_codepoint_t second_glyph)
|
|
|
|
{
|
|
|
|
RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
|
|
|
|
int kern;
|
|
|
|
(void) font;
|
|
|
|
(void) face;
|
|
|
|
if (evas_common_font_query_kerning(fi, first_glyph, second_glyph, &kern))
|
|
|
|
return kern;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of harfbuzz font funcs */
|
|
|
|
|
|
|
|
static hb_font_funcs_t *
|
|
|
|
_evas_common_font_ot_font_funcs_get(void)
|
|
|
|
{
|
|
|
|
static hb_font_funcs_t *font_funcs = NULL;
|
|
|
|
if (!font_funcs)
|
|
|
|
{
|
|
|
|
_ft_font_funcs = hb_ft_get_font_funcs();
|
|
|
|
font_funcs = hb_font_funcs_create();
|
|
|
|
hb_font_funcs_set_glyph_func(font_funcs,
|
|
|
|
_evas_common_font_ot_hb_get_glyph);
|
|
|
|
hb_font_funcs_set_glyph_advance_func(font_funcs,
|
|
|
|
_evas_common_font_ot_hb_get_glyph_advance);
|
|
|
|
hb_font_funcs_set_glyph_extents_func(font_funcs,
|
|
|
|
_evas_common_font_ot_hb_get_glyph_extents);
|
|
|
|
hb_font_funcs_set_contour_point_func(font_funcs,
|
|
|
|
_evas_common_font_ot_hb_get_contour_point);
|
|
|
|
hb_font_funcs_set_kerning_func(font_funcs,
|
|
|
|
_evas_common_font_ot_hb_get_kerning);
|
|
|
|
}
|
|
|
|
|
|
|
|
return font_funcs;
|
|
|
|
}
|
|
|
|
|
2011-01-30 02:36:39 -08:00
|
|
|
static void
|
2011-02-02 00:24:57 -08:00
|
|
|
_evas_common_font_ot_shape(hb_buffer_t *buffer, RGBA_Font_Int *fi)
|
2011-01-30 02:36:39 -08:00
|
|
|
{
|
|
|
|
hb_font_t *hb_font;
|
|
|
|
|
2011-02-02 00:24:57 -08:00
|
|
|
hb_font = hb_ft_font_create(fi->src->ft.face, NULL);
|
|
|
|
hb_font_set_funcs(hb_font, _evas_common_font_ot_font_funcs_get(), NULL, fi);
|
2011-01-30 02:36:39 -08:00
|
|
|
|
2011-02-02 00:24:57 -08:00
|
|
|
hb_shape(hb_font, fi->src->hb.face, buffer, NULL, 0);
|
2011-01-30 02:36:39 -08:00
|
|
|
hb_font_destroy(hb_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
evas_common_font_ot_populate_text_props(void *_fn, const Eina_Unicode *text,
|
|
|
|
Evas_Text_Props *props, int len)
|
|
|
|
{
|
|
|
|
RGBA_Font *fn = (RGBA_Font *) _fn;
|
|
|
|
RGBA_Font_Int *fi;
|
|
|
|
hb_buffer_t *buffer;
|
|
|
|
hb_glyph_position_t *positions;
|
|
|
|
hb_glyph_info_t *infos;
|
|
|
|
int slen;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
fi = fn->fonts->data;
|
|
|
|
/* Load the font needed for this script */
|
2011-01-30 02:39:42 -08:00
|
|
|
{
|
|
|
|
/* Skip common chars */
|
|
|
|
const Eina_Unicode *tmp;
|
|
|
|
for (tmp = text ;
|
|
|
|
*tmp &&
|
|
|
|
evas_common_language_char_script_get(*tmp) == EVAS_SCRIPT_COMMON ;
|
|
|
|
tmp++)
|
|
|
|
;
|
|
|
|
if (!*tmp && (tmp > text)) tmp--;
|
|
|
|
evas_common_font_glyph_search(fn, &fi, *tmp);
|
|
|
|
}
|
2011-01-30 02:40:21 -08:00
|
|
|
evas_common_font_int_reload(fi);
|
|
|
|
if (fi->src->current_size != fi->size)
|
|
|
|
{
|
|
|
|
FTLOCK();
|
|
|
|
FT_Activate_Size(fi->ft.size);
|
|
|
|
FTUNLOCK();
|
|
|
|
fi->src->current_size = fi->size;
|
|
|
|
}
|
2011-01-30 02:36:39 -08:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
slen = eina_unicode_strlen(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slen = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = hb_buffer_create(slen);
|
|
|
|
hb_buffer_set_unicode_funcs(buffer, evas_common_language_unicode_funcs_get());
|
|
|
|
hb_buffer_set_language(buffer, hb_language_from_string(
|
|
|
|
evas_common_language_from_locale_get()));
|
|
|
|
hb_buffer_set_script(buffer, props->script);
|
|
|
|
hb_buffer_set_direction(buffer,
|
|
|
|
(props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
|
|
|
|
HB_DIRECTION_RTL : HB_DIRECTION_LTR);
|
|
|
|
/* FIXME: add run-time conversions if needed, which is very unlikely */
|
|
|
|
hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
|
|
|
|
|
2011-02-02 00:24:57 -08:00
|
|
|
_evas_common_font_ot_shape(buffer, fi);
|
2011-01-30 02:36:39 -08:00
|
|
|
|
2011-02-01 04:17:52 -08:00
|
|
|
props->len = hb_buffer_get_length(buffer);
|
|
|
|
props->info->ot = calloc(props->len,
|
|
|
|
sizeof(Evas_Font_OT_Info));
|
|
|
|
props->info->glyph = calloc(props->len,
|
|
|
|
sizeof(Evas_Font_Glyph_Info));
|
2011-01-30 02:36:39 -08:00
|
|
|
positions = hb_buffer_get_glyph_positions(buffer);
|
|
|
|
infos = hb_buffer_get_glyph_infos(buffer);
|
2011-02-01 04:17:52 -08:00
|
|
|
for (i = 0 ; i < props->len ; i++)
|
2011-01-30 02:36:39 -08:00
|
|
|
{
|
2011-02-01 04:17:52 -08:00
|
|
|
props->info->ot[i].source_cluster = infos[i].cluster;
|
|
|
|
props->info->ot[i].x_offset = positions[i].x_offset;
|
|
|
|
props->info->ot[i].y_offset = positions[i].y_offset;
|
|
|
|
props->info->glyph[i].index = infos[i].codepoint;
|
|
|
|
props->info->glyph[i].advance = positions[i].x_advance;
|
2011-01-30 02:36:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
hb_buffer_destroy(buffer);
|
2011-01-30 02:40:21 -08:00
|
|
|
evas_common_font_int_use_trim();
|
2011-01-30 02:36:39 -08:00
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|