Evas font-engine: Added support for runtime-italic/bold.

Now when setting :style=Oblique/Italic/Cursiva/Bold and etc and there's
no matching font found in the system, adjustments will be done on
runtime to support that feature.

Patch by Myoungwoon Roy Kim (roy_kim).

SVN revision: 58584
This commit is contained in:
Tom Hacohen 2011-04-12 09:05:47 +00:00
parent c443dd97fd
commit ad3b167e88
11 changed files with 184 additions and 68 deletions

View File

@ -22,3 +22,4 @@ Samsung Electronics <tbd>
Samsung SAIT <tbd> Samsung SAIT <tbd>
Sung W. Park <sungwoo@gmail.com> Sung W. Park <sungwoo@gmail.com>
Jiyoun Park <jy0703.park@samsung.com> Jiyoun Park <jy0703.park@samsung.com>
Myoungwoon Roy Kim(roy_kim) <myoungwoon.kim@samsung.com> <myoungwoon@gmail.com>

View File

@ -239,3 +239,10 @@
* Feature: Text & Textblock - Add 8 explicit shadow directions for * Feature: Text & Textblock - Add 8 explicit shadow directions for
text style effects. text style effects.
2011-04-12 Myoungwoon Roy Kim (roy_kim)
* Font-engine: Added runtime italic (actually slanting) and
emboldening. - Automatically slants/emboldens a font at runtime if
italic/bold/crusiva and etc are requested but not found in the
system.

View File

@ -31,6 +31,7 @@ struct _Fndat
int size; int size;
void *font; void *font;
int ref; int ref;
Font_Rend_Flags wanted_rend;
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
FcFontSet *set; FcFontSet *set;
@ -230,7 +231,8 @@ evas_font_init(void)
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
static void * static void *
evas_load_fontconfig(Evas *evas, FcFontSet *set, int size) evas_load_fontconfig(Evas *evas, FcFontSet *set, int size,
Font_Rend_Flags wanted_rend)
{ {
void *font = NULL; void *font = NULL;
int i; int i;
@ -243,9 +245,9 @@ evas_load_fontconfig(Evas *evas, FcFontSet *set, int size)
FcPatternGet(set->fonts[i], FC_FILE, 0, &filename); FcPatternGet(set->fonts[i], FC_FILE, 0, &filename);
if (font) if (font)
evas->engine.func->font_add(evas->engine.data.output, font, (char *)filename.u.s, size); evas->engine.func->font_add(evas->engine.data.output, font, (char *)filename.u.s, size, wanted_rend);
else else
font = evas->engine.func->font_load(evas->engine.data.output, (char *)filename.u.s, size); font = evas->engine.func->font_load(evas->engine.data.output, (char *)filename.u.s, size, wanted_rend);
} }
return font; return font;
@ -271,6 +273,12 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
Eina_List *fonts, *l; Eina_List *fonts, *l;
Fndat *fd; Fndat *fd;
char *nm; char *nm;
Font_Rend_Flags wanted_rend = 0;
if (evas_common_text_font_style_match(name, "Italic"))
wanted_rend |= FONT_REND_ITALIC;
if (evas_common_text_font_style_match(name, "Bold"))
wanted_rend |= FONT_REND_BOLD;
if (!name) return NULL; if (!name) return NULL;
if (name[0] == 0) return NULL; if (name[0] == 0) return NULL;
@ -284,7 +292,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
if (((!source) && (!fd->source)) || if (((!source) && (!fd->source)) ||
((source) && (fd->source) && (!strcmp(source, fd->source)))) ((source) && (fd->source) && (!strcmp(source, fd->source))))
{ {
if (size == fd->size) if ((size == fd->size) && (wanted_rend = fd->wanted_rend))
{ {
fonts_cache = eina_list_promote_list(fonts_cache, l); fonts_cache = eina_list_promote_list(fonts_cache, l);
fd->ref++; fd->ref++;
@ -293,7 +301,8 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
else if (fd->set && fd->p_nm) else if (fd->set && fd->p_nm)
{ {
font = evas_load_fontconfig(evas, fd->set, size); font = evas_load_fontconfig(evas, fd->set, size,
wanted_rend);
goto on_find; goto on_find;
} }
#endif #endif
@ -308,7 +317,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
if (((!source) && (!fd->source)) || if (((!source) && (!fd->source)) ||
((source) && (fd->source) && (!strcmp(source, fd->source)))) ((source) && (fd->source) && (!strcmp(source, fd->source))))
{ {
if (size == fd->size) if ((size == fd->size) && (wanted_rend = fd->wanted_rend))
{ {
fonts_zero = eina_list_remove_list(fonts_zero, l); fonts_zero = eina_list_remove_list(fonts_zero, l);
fonts_cache = eina_list_prepend(fonts_cache, fd); fonts_cache = eina_list_prepend(fonts_cache, fd);
@ -318,13 +327,15 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG
else if (fd->set && fd->p_nm) else if (fd->set && fd->p_nm)
{ {
font = evas_load_fontconfig(evas, fd->set, size); font = evas_load_fontconfig(evas, fd->set, size,
wanted_rend);
goto on_find; goto on_find;
} }
#endif #endif
} }
} }
} }
fonts = evas_font_set_get(name); fonts = evas_font_set_get(name);
EINA_LIST_FOREACH(fonts, l, nm) /* Load each font in append */ EINA_LIST_FOREACH(fonts, l, nm) /* Load each font in append */
{ {
@ -339,7 +350,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
fake_name = evas_file_path_join(source, nm); fake_name = evas_file_path_join(source, nm);
if (fake_name) if (fake_name)
{ {
font = evas->engine.func->font_load(evas->engine.data.output, fake_name, size); font = evas->engine.func->font_load(evas->engine.data.output, fake_name, size, wanted_rend);
if (!font) /* Load from fake name failed, probably not cached */ if (!font) /* Load from fake name failed, probably not cached */
{ {
/* read original!!! */ /* read original!!! */
@ -352,7 +363,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
fdata = eet_read(ef, nm, &fsize); fdata = eet_read(ef, nm, &fsize);
if ((fdata) && (fsize > 0)) if ((fdata) && (fsize > 0))
{ {
font = evas->engine.func->font_memory_load(evas->engine.data.output, fake_name, size, fdata, fsize); font = evas->engine.func->font_memory_load(evas->engine.data.output, fake_name, size, fdata, fsize, wanted_rend);
free(fdata); free(fdata);
} }
eet_close(ef); eet_close(ef);
@ -365,7 +376,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
{ {
#endif #endif
if (evas_file_path_is_full_path((char *)nm)) /* Try filename */ if (evas_file_path_is_full_path((char *)nm)) /* Try filename */
font = evas->engine.func->font_load(evas->engine.data.output, (char *)nm, size); font = evas->engine.func->font_load(evas->engine.data.output, (char *)nm, size, wanted_rend);
else /* search font path */ else /* search font path */
{ {
Eina_List *l; Eina_List *l;
@ -378,7 +389,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
f_file = evas_font_dir_cache_find(dir, (char *)nm); f_file = evas_font_dir_cache_find(dir, (char *)nm);
if (f_file) if (f_file)
{ {
font = evas->engine.func->font_load(evas->engine.data.output, f_file, size); font = evas->engine.func->font_load(evas->engine.data.output, f_file, size, wanted_rend);
if (font) break; if (font) break;
} }
} }
@ -401,7 +412,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
if (fake_name) if (fake_name)
{ {
/* FIXME: make an engine func */ /* FIXME: make an engine func */
if (!evas->engine.func->font_add(evas->engine.data.output, font, fake_name, size)) if (!evas->engine.func->font_add(evas->engine.data.output, font, fake_name, size, wanted_rend))
{ {
/* read original!!! */ /* read original!!! */
ef = eet_open(source, EET_FILE_MODE_READ); ef = eet_open(source, EET_FILE_MODE_READ);
@ -413,7 +424,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
fdata = eet_read(ef, nm, &fsize); fdata = eet_read(ef, nm, &fsize);
if ((fdata) && (fsize > 0)) if ((fdata) && (fsize > 0))
{ {
ok = evas->engine.func->font_memory_add(evas->engine.data.output, font, fake_name, size, fdata, fsize); ok = evas->engine.func->font_memory_add(evas->engine.data.output, font, fake_name, size, fdata, fsize, wanted_rend);
free(fdata); free(fdata);
} }
eet_close(ef); eet_close(ef);
@ -428,7 +439,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
{ {
#endif #endif
if (evas_file_path_is_full_path((char *)nm)) if (evas_file_path_is_full_path((char *)nm))
evas->engine.func->font_add(evas->engine.data.output, font, (char *)nm, size); evas->engine.func->font_add(evas->engine.data.output, font, (char *)nm, size, wanted_rend);
else else
{ {
Eina_List *l; Eina_List *l;
@ -441,7 +452,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
f_file = evas_font_dir_cache_find(dir, (char *)nm); f_file = evas_font_dir_cache_find(dir, (char *)nm);
if (f_file) if (f_file)
{ {
if (evas->engine.func->font_add(evas->engine.data.output, font, f_file, size)) if (evas->engine.func->font_add(evas->engine.data.output, font, f_file, size, wanted_rend))
break; break;
} }
} }
@ -479,7 +490,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
// to FcTrue... // to FcTrue...
// ok - not a bugfix... but there is something going on somewhere that's wierd? // ok - not a bugfix... but there is something going on somewhere that's wierd?
// FcPatternReference(p_nm); /* we have to reference count the pat */ // FcPatternReference(p_nm); /* we have to reference count the pat */
font = evas_load_fontconfig(evas, set, size); font = evas_load_fontconfig(evas, set, size, wanted_rend);
} }
} }
#endif #endif
@ -492,6 +503,7 @@ evas_font_load(Evas *evas, const char *name, const char *source, int size)
if (source) fd->source = eina_stringshare_add(source); if (source) fd->source = eina_stringshare_add(source);
fd->size = size; fd->size = size;
fd->font = font; fd->font = font;
fd->wanted_rend = wanted_rend;
fd->ref = 1; fd->ref = 1;
fonts_cache = eina_list_prepend(fonts_cache, fd); fonts_cache = eina_list_prepend(fonts_cache, fd);
#ifdef HAVE_FONTCONFIG #ifdef HAVE_FONTCONFIG

View File

@ -30,27 +30,26 @@ EAPI int evas_common_font_source_load_complete (RGBA_Font_Source *
EAPI RGBA_Font_Source *evas_common_font_source_find (const char *name); EAPI RGBA_Font_Source *evas_common_font_source_find (const char *name);
EAPI void evas_common_font_source_free (RGBA_Font_Source *fs); EAPI void evas_common_font_source_free (RGBA_Font_Source *fs);
EAPI void evas_common_font_size_use (RGBA_Font *fn); EAPI void evas_common_font_size_use (RGBA_Font *fn);
EAPI RGBA_Font *evas_common_font_memory_load (const char *name, int size, const void *data, int data_size); EAPI RGBA_Font_Int *evas_common_font_int_load (const char *name, int size, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font_Int *evas_common_font_int_load (const char *name, int size);
EAPI RGBA_Font_Int *evas_common_font_int_load_init (RGBA_Font_Int *fn); EAPI RGBA_Font_Int *evas_common_font_int_load_init (RGBA_Font_Int *fn);
EAPI RGBA_Font_Int *evas_common_font_int_load_complete (RGBA_Font_Int *fi); EAPI RGBA_Font_Int *evas_common_font_int_load_complete (RGBA_Font_Int *fi);
EAPI RGBA_Font *evas_common_font_memory_load (const char *name, int size, const void *data, int data_size); EAPI RGBA_Font *evas_common_font_memory_load (const char *name, int size, const void *data, int data_size, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_load (const char *name, int size); EAPI RGBA_Font *evas_common_font_load (const char *name, int size, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_add (RGBA_Font *fn, const char *name, int size); EAPI RGBA_Font *evas_common_font_add (RGBA_Font *fn, const char *name, int size, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_memory_add (RGBA_Font *fn, const char *name, int size, const void *data, int data_size); EAPI RGBA_Font *evas_common_font_memory_add (RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Rend_Flags wanted_rend);
EAPI void evas_common_font_free (RGBA_Font *fn); EAPI void evas_common_font_free (RGBA_Font *fn);
EAPI void evas_common_font_hinting_set (RGBA_Font *fn, Font_Hint_Flags hinting); EAPI void evas_common_font_hinting_set (RGBA_Font *fn, Font_Hint_Flags hinting);
EAPI Eina_Bool evas_common_hinting_available (Font_Hint_Flags hinting); EAPI Eina_Bool evas_common_hinting_available (Font_Hint_Flags hinting);
EAPI RGBA_Font *evas_common_font_memory_hinting_load (const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting); EAPI RGBA_Font *evas_common_font_memory_hinting_load (const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_hinting_load (const char *name, int size, Font_Hint_Flags hinting); EAPI RGBA_Font *evas_common_font_hinting_load (const char *name, int size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_hinting_add (RGBA_Font *fn, const char *name, int size, Font_Hint_Flags hinting); EAPI RGBA_Font *evas_common_font_hinting_add (RGBA_Font *fn, const char *name, int size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend);
EAPI RGBA_Font *evas_common_font_memory_hinting_add (RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting); EAPI RGBA_Font *evas_common_font_memory_hinting_add (RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend);
EAPI void evas_common_font_int_modify_cache_by (RGBA_Font_Int *fi, int dir); EAPI void evas_common_font_int_modify_cache_by (RGBA_Font_Int *fi, int dir);
EAPI int evas_common_font_cache_get (void); EAPI int evas_common_font_cache_get (void);
EAPI void evas_common_font_cache_set (int size); EAPI void evas_common_font_cache_set (int size);
EAPI void evas_common_font_flush (void); EAPI void evas_common_font_flush (void);
EAPI void evas_common_font_flush_last (void); EAPI void evas_common_font_flush_last (void);
EAPI RGBA_Font_Int *evas_common_font_int_find (const char *name, int size); EAPI RGBA_Font_Int *evas_common_font_int_find (const char *name, int size, Font_Rend_Flags wanted_rend);
EAPI void evas_common_font_all_clear (void); EAPI void evas_common_font_all_clear (void);
/* query */ /* query */

View File

@ -7,9 +7,12 @@
#include "evas_font_ot.h" #include "evas_font_ot.h"
#include FT_OUTLINE_H
#define WORD_CACHE_MAXLEN 50 #define WORD_CACHE_MAXLEN 50
/* How many to cache */ /* How many to cache */
#define WORD_CACHE_NWORDS 40 #define WORD_CACHE_NWORDS 40
static int max_cached_words = WORD_CACHE_NWORDS; static int max_cached_words = WORD_CACHE_NWORDS;
struct prword struct prword
@ -201,6 +204,7 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt index)
int size; int size;
const FT_Int32 hintflags[3] = const FT_Int32 hintflags[3] =
{ FT_LOAD_NO_HINTING, FT_LOAD_FORCE_AUTOHINT, FT_LOAD_NO_AUTOHINT }; { FT_LOAD_NO_HINTING, FT_LOAD_FORCE_AUTOHINT, FT_LOAD_NO_AUTOHINT };
static FT_Matrix transform = {0x10000, 0x05000, 0x0000, 0x10000}; // about 12 degree.
evas_common_font_int_promote(fi); evas_common_font_int_promote(fi);
if (fi->fash) if (fi->fash)
@ -217,9 +221,9 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt index)
evas_common_font_int_reload(fi); evas_common_font_int_reload(fi);
FTLOCK(); FTLOCK();
// error = FT_Load_Glyph(fi->src->ft.face, index, FT_LOAD_NO_BITMAP);
error = FT_Load_Glyph(fi->src->ft.face, index, error = FT_Load_Glyph(fi->src->ft.face, index,
FT_LOAD_RENDER | hintflags[fi->hinting]); FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP |
hintflags[fi->hinting]);
FTUNLOCK(); FTUNLOCK();
if (error) if (error)
{ {
@ -228,6 +232,14 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt index)
return NULL; return NULL;
} }
/* Transform the outline of Glyph according to runtime_rend. */
if (fi->runtime_rend & FONT_REND_ITALIC)
FT_Outline_Transform(&fi->src->ft.face->glyph->outline, &transform);
/* Embolden the outline of Glyph according to rundtime_rend. */
if (fi->runtime_rend & FONT_REND_BOLD)
FT_Outline_Embolden(&fi->src->ft.face->glyph->outline,
(fi->src->ft.face->size->metrics.x_ppem * 5 * 64) / 100);
fg = malloc(sizeof(struct _RGBA_Font_Glyph)); fg = malloc(sizeof(struct _RGBA_Font_Glyph));
if (!fg) return NULL; if (!fg) return NULL;
memset(fg, 0, (sizeof(struct _RGBA_Font_Glyph))); memset(fg, 0, (sizeof(struct _RGBA_Font_Glyph)));

View File

@ -26,7 +26,12 @@ _evas_font_cache_int_cmp(const RGBA_Font_Int *k1, int k1_length __UNUSED__,
{ {
/* RGBA_Font_Source->name is a stringshare */ /* RGBA_Font_Source->name is a stringshare */
if (k1->src->name == k2->src->name) if (k1->src->name == k2->src->name)
{
if (k1->size == k2->size)
return k1->wanted_rend - k2->wanted_rend;
else
return k1->size - k2->size; return k1->size - k2->size;
}
return strcmp(k1->src->name, k2->src->name);; return strcmp(k1->src->name, k2->src->name);;
} }
@ -34,8 +39,10 @@ static int
_evas_font_cache_int_hash(const RGBA_Font_Int *key, int key_length __UNUSED__) _evas_font_cache_int_hash(const RGBA_Font_Int *key, int key_length __UNUSED__)
{ {
int hash; int hash;
unsigned int wanted_rend = key->wanted_rend;
hash = eina_hash_djb2(key->src->name, eina_stringshare_strlen(key->src->name) + 1); hash = eina_hash_djb2(key->src->name, eina_stringshare_strlen(key->src->name) + 1);
hash ^= eina_hash_int32(&key->size, sizeof (int)); hash ^= eina_hash_int32(&key->size, sizeof (int));
hash ^= eina_hash_int32(&wanted_rend, sizeof (int));
return hash; return hash;
} }
@ -304,11 +311,11 @@ _evas_common_font_int_cache_init(RGBA_Font_Int *fi)
} }
EAPI RGBA_Font_Int * EAPI RGBA_Font_Int *
evas_common_font_int_memory_load(const char *name, int size, const void *data, int data_size) evas_common_font_int_memory_load(const char *name, int size, const void *data, int data_size, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
fi = evas_common_font_int_find(name, size); fi = evas_common_font_int_find(name, size, wanted_rend);
if (fi) return fi; if (fi) return fi;
fi = calloc(1, sizeof(RGBA_Font_Int)); fi = calloc(1, sizeof(RGBA_Font_Int));
if (!fi) return NULL; if (!fi) return NULL;
@ -328,23 +335,26 @@ evas_common_font_int_memory_load(const char *name, int size, const void *data, i
} }
EAPI RGBA_Font_Int * EAPI RGBA_Font_Int *
evas_common_font_int_load(const char *name, int size) evas_common_font_int_load(const char *name, int size,
Font_Rend_Flags wanted_rend)
{ {
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
fi = evas_common_font_int_find(name, size); fi = evas_common_font_int_find(name, size, wanted_rend);
if (fi) return fi; if (fi) return fi;
fi = calloc(1, sizeof(RGBA_Font_Int)); fi = calloc(1, sizeof(RGBA_Font_Int));
if (!fi) return NULL; if (!fi) return NULL;
fi->src = evas_common_font_source_find(name); fi->src = evas_common_font_source_find(name);
if (!fi->src && evas_file_path_is_file(name)) if (!fi->src && evas_file_path_is_file(name))
fi->src = evas_common_font_source_load(name); fi->src = evas_common_font_source_load(name);
if (!fi->src) if (!fi->src)
{ {
free(fi); free(fi);
return NULL; return NULL;
} }
fi->size = size; fi->size = size;
fi->wanted_rend = wanted_rend;
_evas_common_font_int_cache_init(fi); _evas_common_font_int_cache_init(fi);
fi = evas_common_font_int_load_init(fi); fi = evas_common_font_int_load_init(fi);
// evas_common_font_int_load_complete(fi); // evas_common_font_int_load_complete(fi);
@ -431,16 +441,30 @@ evas_common_font_int_load_complete(RGBA_Font_Int *fi)
} }
else ret = val; else ret = val;
fi->max_h += ret; fi->max_h += ret;
/* If the loaded font doesn't match with wanted_rend value requested by
* textobject and textblock, Set the runtime_rend value as FONT_REND_ITALIC
* or FONT_REND_BOLD for software rendering. */
fi->runtime_rend = FONT_REND_REGULAR;
if ((fi->wanted_rend & FONT_REND_ITALIC) &&
!(fi->src->ft.face->style_flags & FT_STYLE_FLAG_ITALIC))
fi->runtime_rend |= FONT_REND_ITALIC;
if ((fi->wanted_rend & FONT_REND_BOLD) &&
!(fi->src->ft.face->style_flags & FT_STYLE_FLAG_BOLD))
fi->runtime_rend |= FONT_REND_BOLD;
return fi; return fi;
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_memory_load(const char *name, int size, const void *data, int data_size) evas_common_font_memory_load(const char *name, int size, const void *data, int data_size, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font *fn; RGBA_Font *fn;
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
fi = evas_common_font_int_memory_load(name, size, data, data_size); fi = evas_common_font_int_memory_load(name, size, data, data_size,
wanted_rend);
if (!fi) return NULL; if (!fi) return NULL;
fn = calloc(1, sizeof(RGBA_Font)); fn = calloc(1, sizeof(RGBA_Font));
if (!fn) if (!fn)
@ -479,12 +503,12 @@ evas_common_font_memory_load(const char *name, int size, const void *data, int d
// fi->fs // fi->fs
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_load(const char *name, int size) evas_common_font_load(const char *name, int size, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font *fn; RGBA_Font *fn;
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
fi = evas_common_font_int_load(name, size); fi = evas_common_font_int_load(name, size, wanted_rend);
if (!fi) return NULL; if (!fi) return NULL;
/* First font, complete load */ /* First font, complete load */
if (!fi->ft.size) if (!fi->ft.size)
@ -517,6 +541,7 @@ evas_common_font_load(const char *name, int size)
} }
return NULL; return NULL;
} }
fn->fonts = eina_list_append(fn->fonts, fi); fn->fonts = eina_list_append(fn->fonts, fi);
fn->hinting = FONT_BYTECODE_HINT; fn->hinting = FONT_BYTECODE_HINT;
fi->hinting = fn->hinting; fi->hinting = fn->hinting;
@ -537,12 +562,12 @@ evas_common_font_load(const char *name, int size)
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_add(RGBA_Font *fn, const char *name, int size) evas_common_font_add(RGBA_Font *fn, const char *name, int size, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
if (!fn) return NULL; if (!fn) return NULL;
fi = evas_common_font_int_load(name, size); fi = evas_common_font_int_load(name, size, wanted_rend);
if (fi) if (fi)
{ {
fn->fonts = eina_list_append(fn->fonts, fi); fn->fonts = eina_list_append(fn->fonts, fi);
@ -559,13 +584,13 @@ evas_common_font_add(RGBA_Font *fn, const char *name, int size)
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_memory_add(RGBA_Font *fn, const char *name, int size, const void *data, int data_size) evas_common_font_memory_add(RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font_Int *fi; RGBA_Font_Int *fi;
if (!fn) if (!fn)
return NULL; return NULL;
fi = evas_common_font_int_memory_load(name, size, data, data_size); fi = evas_common_font_int_memory_load(name, size, data, data_size, wanted_rend);
if (fi) if (fi)
{ {
fn->fonts = eina_list_append(fn->fonts, fi); fn->fonts = eina_list_append(fn->fonts, fi);
@ -672,37 +697,38 @@ evas_common_hinting_available(Font_Hint_Flags hinting)
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_memory_hinting_load(const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting) evas_common_font_memory_hinting_load(const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font *fn; RGBA_Font *fn;
fn = evas_common_font_memory_load(name, size, data, data_size); fn = evas_common_font_memory_load(name, size, data, data_size, wanted_rend);
if (fn) evas_common_font_hinting_set(fn, hinting); if (fn) evas_common_font_hinting_set(fn, hinting);
return fn; return fn;
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_hinting_load(const char *name, int size, Font_Hint_Flags hinting) evas_common_font_hinting_load(const char *name, int size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend)
{ {
RGBA_Font *fn; RGBA_Font *fn;
fn = evas_common_font_load(name, size); fn = evas_common_font_load(name, size, wanted_rend);
if (fn) evas_common_font_hinting_set(fn, hinting); if (fn) evas_common_font_hinting_set(fn, hinting);
return fn; return fn;
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_hinting_add(RGBA_Font *fn, const char *name, int size, Font_Hint_Flags hinting) evas_common_font_hinting_add(RGBA_Font *fn, const char *name, int size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend)
{ {
fn = evas_common_font_add(fn, name, size); fn = evas_common_font_add(fn, name, size, wanted_rend);
if (fn) evas_common_font_hinting_set(fn, hinting); if (fn) evas_common_font_hinting_set(fn, hinting);
return fn; return fn;
} }
EAPI RGBA_Font * EAPI RGBA_Font *
evas_common_font_memory_hinting_add(RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting) evas_common_font_memory_hinting_add(RGBA_Font *fn, const char *name, int size, const void *data, int data_size, Font_Hint_Flags hinting, Font_Rend_Flags wanted_rend)
{ {
fn = evas_common_font_memory_add(fn, name, size, data, data_size); fn = evas_common_font_memory_add(fn, name, size, data, data_size,
wanted_rend);
if (fn) evas_common_font_hinting_set(fn, hinting); if (fn) evas_common_font_hinting_set(fn, hinting);
return fn; return fn;
} }
@ -881,7 +907,8 @@ evas_common_font_flush_last(void)
} }
EAPI RGBA_Font_Int * EAPI RGBA_Font_Int *
evas_common_font_int_find(const char *name, int size) evas_common_font_int_find(const char *name, int size,
Font_Rend_Flags wanted_rend)
{ {
RGBA_Font_Int tmp_fi; RGBA_Font_Int tmp_fi;
RGBA_Font_Source tmp_fn; RGBA_Font_Source tmp_fn;
@ -890,6 +917,7 @@ evas_common_font_int_find(const char *name, int size)
tmp_fn.name = (char*) eina_stringshare_add(name); tmp_fn.name = (char*) eina_stringshare_add(name);
tmp_fi.src = &tmp_fn; tmp_fi.src = &tmp_fn;
tmp_fi.size = size; tmp_fi.size = size;
tmp_fi.wanted_rend = wanted_rend;
fi = eina_hash_find(fonts, &tmp_fi); fi = eina_hash_find(fonts, &tmp_fi);
if (fi) if (fi)
{ {

View File

@ -367,3 +367,43 @@ evas_common_text_props_content_create(void *_fn, const Eina_Unicode *text,
return EINA_TRUE; return EINA_TRUE;
} }
Eina_Bool
evas_common_text_font_style_match(const char *font_name, const char *style_name)
{
char *style_key = NULL;
if (!font_name) return EINA_FALSE;
if (!style_name) return EINA_FALSE;
style_key = strchr(font_name, ':');
if (!style_key) return EINA_FALSE;
if (strlen(style_key) > 2) style_key++;
if (strstr(style_key, "style="))
{
if (!strcmp(style_name, "Italic"))
{
if (strstr(style_key, "Italic")
|| strstr(style_key, "italic")
|| strstr(style_key, "Cursiva")
|| strstr(style_key, "cursiva"))
return EINA_TRUE;
else
return EINA_FALSE;
}
else if (!strcmp(style_name, "Bold"))
{
if (strstr(style_key, "Bold")
|| strstr(style_key, "bold")
|| strstr(style_key, "Negreta")
|| strstr(style_key, "negreta"))
return EINA_TRUE;
else
return EINA_FALSE;
}
else
return EINA_FALSE;
}
else
return EINA_FALSE;
}

View File

@ -73,4 +73,8 @@ evas_common_text_props_split(Evas_Text_Props *base, Evas_Text_Props *ext,
int cutoff); int cutoff);
EAPI void EAPI void
evas_common_text_props_merge(Evas_Text_Props *item1, const Evas_Text_Props *item2); evas_common_text_props_merge(Evas_Text_Props *item1, const Evas_Text_Props *item2);
Eina_Bool
evas_common_text_font_style_match(const char *font_name, const char *style_name);
#endif #endif

View File

@ -510,6 +510,13 @@ typedef enum _Font_Hint_Flags
FONT_BYTECODE_HINT FONT_BYTECODE_HINT
} Font_Hint_Flags; } Font_Hint_Flags;
typedef enum _Font_Rend_Flags
{
FONT_REND_REGULAR = 0,
FONT_REND_ITALIC = (1 << 0),
FONT_REND_BOLD = (1 << 1),
} Font_Rend_Flags;
/*****************************************************************************/ /*****************************************************************************/
struct _RGBA_Image_Loadopts struct _RGBA_Image_Loadopts
@ -901,6 +908,9 @@ struct _RGBA_Font_Int
} ft; } ft;
LK(ft_mutex); LK(ft_mutex);
Font_Hint_Flags hinting; Font_Hint_Flags hinting;
Font_Rend_Flags wanted_rend; /* The wanted rendering style */
Font_Rend_Flags runtime_rend; /* The rendering we need to do on runtime
in order to comply with the wanted_rend. */
unsigned char sizeok : 1; unsigned char sizeok : 1;
unsigned char inuse : 1; unsigned char inuse : 1;
}; };

View File

@ -647,10 +647,10 @@ struct _Evas_Func
void (*image_cache_set) (void *data, int bytes); void (*image_cache_set) (void *data, int bytes);
int (*image_cache_get) (void *data); int (*image_cache_get) (void *data);
void *(*font_load) (void *data, const char *name, int size); void *(*font_load) (void *data, const char *name, int size, Font_Rend_Flags wanted_rend);
void *(*font_memory_load) (void *data, char *name, int size, const void *fdata, int fdata_size); void *(*font_memory_load) (void *data, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend);
void *(*font_add) (void *data, void *font, const char *name, int size); void *(*font_add) (void *data, void *font, const char *name, int size, Font_Rend_Flags wanted_rend);
void *(*font_memory_add) (void *data, void *font, char *name, int size, const void *fdata, int fdata_size); void *(*font_memory_add) (void *data, void *font, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend);
void (*font_free) (void *data, void *font); void (*font_free) (void *data, void *font);
int (*font_ascent_get) (void *data, void *font); int (*font_ascent_get) (void *data, void *font);
int (*font_descent_get) (void *data, void *font); int (*font_descent_get) (void *data, void *font);

View File

@ -673,27 +673,30 @@ eng_image_cache_get(void *data __UNUSED__)
} }
static void * static void *
eng_font_load(void *data __UNUSED__, const char *name, int size) eng_font_load(void *data __UNUSED__, const char *name, int size,
Font_Rend_Flags wanted_rend)
{ {
return evas_common_font_load(name, size); return evas_common_font_load(name, size, wanted_rend);
} }
static void * static void *
eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size) eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
{ {
return evas_common_font_memory_load(name, size, fdata, fdata_size); return evas_common_font_memory_load(name, size, fdata, fdata_size,
wanted_rend);
} }
static void * static void *
eng_font_add(void *data __UNUSED__, void *font, const char *name, int size) eng_font_add(void *data __UNUSED__, void *font, const char *name, int size, Font_Rend_Flags wanted_rend)
{ {
return evas_common_font_add(font, name, size); return evas_common_font_add(font, name, size, wanted_rend);
} }
static void * static void *
eng_font_memory_add(void *data __UNUSED__, void *font, char *name, int size, const void *fdata, int fdata_size) eng_font_memory_add(void *data __UNUSED__, void *font, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
{ {
return evas_common_font_memory_add(font, name, size, fdata, fdata_size); return evas_common_font_memory_add(font, name, size, fdata, fdata_size,
wanted_rend);
} }
static void static void