Evas font: Added support for font fallback for eet/edje fonts.

This is a long awaited feature that has been requested years ago.
Fontconfig finally added the support needed to make it happen, so here
it is.

I added a fontconfig query to look for similar fonts in case we loaded a
font from eet/edje/file(no fontconfig). This now works quite well.

Still missing: if you load a bold/italic/whatever font directly (set the file)
without putting ":weight=bold" you will not get run-time emboldenment if
only non-bold fonts are found.

This unfortunately depends on very recent fontconfig version (#ifed out
when unavailable), so only people with fontconfig >= 2.11 will enjoy
this feature.
This commit is contained in:
Tom Hacohen 2014-02-03 13:58:25 +00:00
parent 1c44890491
commit 17d028f944
3 changed files with 45 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#ifdef HAVE_FONTCONFIG
#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
#endif
#include "evas_common_private.h"
@ -783,6 +784,33 @@ evas_font_load(Evas *eo_evas, Evas_Font_Description *fdesc, const char *source,
font = _evas_load_fontconfig(font, evas->evas, set, size, wanted_rend);
}
}
else /* Add a fallback list from fontconfig according to the found font. */
{
#if FC_MAJOR >= 2 && FC_MINOR >= 11
FcResult res;
FT_Face face = evas_common_font_freetype_face_get((RGBA_Font *) font);
if (face)
{
p_nm = FcFreeTypeQueryFace(face, (FcChar8 *) "", 0, NULL);
FcConfigSubstitute(fc_config, p_nm, FcMatchPattern);
FcDefaultSubstitute(p_nm);
/* do matching */
set = FcFontSort(fc_config, p_nm, FcTrue, NULL, &res);
if (!set)
{
FcPatternDestroy(p_nm);
p_nm = NULL;
}
else
{
font = _evas_load_fontconfig(font, evas->evas, set, size, wanted_rend);
}
}
#endif
}
#endif
#ifdef HAVE_FONTCONFIG

View File

@ -21,6 +21,7 @@ EAPI int evas_common_font_instance_max_descent_get (RGBA_Font
EAPI int evas_common_font_instance_underline_position_get (RGBA_Font_Int *fi);
EAPI int evas_common_font_instance_underline_thickness_get (RGBA_Font_Int *fi);
EAPI int evas_common_font_get_line_advance (RGBA_Font *fn);
void *evas_common_font_freetype_face_get(RGBA_Font *font); /* XXX: Not EAPI on purpose. Not ment to be used in modules. */
/* draw */
typedef Eina_Bool (*Evas_Common_Font_Draw_Cb)(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, Evas_Glyph_Array *glyphs, RGBA_Gfx_Func func, int ext_x, int ext_y, int ext_w, int ext_h, int im_w, int im_h);

View File

@ -73,6 +73,22 @@ evas_common_font_font_all_unload(void)
evas_common_font_all_clear();
}
/* FIXME: This function should not be used. It's a short-cut fix that is meant
* to improve font fallback for in-theme fonts. It will break if we stop using
* freetype (unlikely) or do anything else fancy. */
void *
evas_common_font_freetype_face_get(RGBA_Font *font)
{
RGBA_Font_Int *fi = font->fonts->data;
if (!fi)
return NULL;
evas_common_font_int_reload(fi);
return fi->src->ft.face;
}
EAPI int
evas_common_font_instance_ascent_get(RGBA_Font_Int *fi)
{