From 17d028f9444eebc0eafef1e4edaaf258665bb093 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 3 Feb 2014 13:58:25 +0000 Subject: [PATCH] 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. --- src/lib/evas/canvas/evas_font_dir.c | 28 ++++++++++++++++++++++++++++ src/lib/evas/common/evas_font.h | 1 + src/lib/evas/common/evas_font_main.c | 16 ++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/lib/evas/canvas/evas_font_dir.c b/src/lib/evas/canvas/evas_font_dir.c index f29e31f..393f954 100644 --- a/src/lib/evas/canvas/evas_font_dir.c +++ b/src/lib/evas/canvas/evas_font_dir.c @@ -10,6 +10,7 @@ #ifdef HAVE_FONTCONFIG #include +#include #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 diff --git a/src/lib/evas/common/evas_font.h b/src/lib/evas/common/evas_font.h index 2b78ed9..dff165a 100644 --- a/src/lib/evas/common/evas_font.h +++ b/src/lib/evas/common/evas_font.h @@ -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); diff --git a/src/lib/evas/common/evas_font_main.c b/src/lib/evas/common/evas_font_main.c index 064007f..97961d0 100644 --- a/src/lib/evas/common/evas_font_main.c +++ b/src/lib/evas/common/evas_font_main.c @@ -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) { -- 2.7.4