From 10d6748b5681858056f6bc3acfbf7808a3ad3a57 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Mon, 27 Feb 2006 14:03:27 +0000 Subject: [PATCH] evas lets you choose font hinting - in theory. :) SVN revision: 20823 --- legacy/evas/src/lib/Evas.h | 11 ++++ .../src/lib/engines/common/evas_font_draw.c | 8 ++- .../src/lib/engines/common/evas_font_load.c | 62 ++++++++++++++++--- legacy/evas/src/lib/imaging/evas_imaging.c | 32 ++++++++++ legacy/evas/src/lib/include/evas_common.h | 11 ++++ 5 files changed, 114 insertions(+), 10 deletions(-) diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h index 97042faf0b..4f0ed343e0 100644 --- a/legacy/evas/src/lib/Evas.h +++ b/legacy/evas/src/lib/Evas.h @@ -54,6 +54,13 @@ typedef enum _Evas_Button_Flags EVAS_BUTTON_TRIPLE_CLICK = (1 << 1) /**< This mouse button press was the 3rd press of a triple click */ } Evas_Button_Flags; /**< Flags for Mouse Button events */ +typedef enum _Evas_Font_Hinting_Flags +{ + EVAS_FONT_HINTING_NONE, + EVAS_FONT_HINTING_AUTO, + EVAS_FONT_HINTING_BYTECODE +} Evas_Font_Hinting_Flags; /**< Flags for Font Hinting */ + typedef struct _Evas_List Evas_List; /**< A generic linked list node handle */ typedef struct _Evas_Rectangle Evas_Rectangle; /**< A generic rectangle handle */ typedef struct _Evas_Smart_Class Evas_Smart_Class; /**< A smart object base class */ @@ -712,6 +719,10 @@ tile_mode); EAPI void evas_imaging_image_cache_set (int bytes); EAPI int evas_imaging_image_cache_get (void); + EAPI void evas_imaging_font_hinting_set (Evas_Font_Hinting_Flags hinting); + EAPI Evas_Font_Hinting_Flags evas_imaging_font_hinting_get (void); + EAPI Evas_Bool evas_imaging_font_hinting_can_hint (Evas_Font_Hinting_Flags hinting); + EAPI Evas_Imaging_Font *evas_imaging_font_load (const char *file, const char *key, int size); EAPI void evas_imaging_font_free (Evas_Imaging_Font *fn); EAPI int evas_imaging_font_ascent_get (Evas_Imaging_Font *fn); diff --git a/legacy/evas/src/lib/engines/common/evas_font_draw.c b/legacy/evas/src/lib/engines/common/evas_font_draw.c index 6a79ece0ae..25500d4537 100644 --- a/legacy/evas/src/lib/engines/common/evas_font_draw.c +++ b/legacy/evas/src/lib/engines/common/evas_font_draw.c @@ -6,6 +6,7 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt index) RGBA_Font_Glyph *fg; char key[6]; FT_Error error; + FT_Int32 lflags; key[0] = ((index ) & 0x7f) + 1; key[1] = ((index >> 7 ) & 0x7f) + 1; @@ -18,8 +19,11 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt index) if (fg) return fg; // error = FT_Load_Glyph(fi->src->ft.face, index, FT_LOAD_NO_BITMAP); - error = FT_Load_Glyph(fi->src->ft.face, index, - FT_LOAD_RENDER); + lflags = FT_LOAD_RENDER; + if (fi->hinting == FONT_NO_HINT) lflags |= FT_LOAD_NO_HINTING; + else if (fi->hinting == FONT_AUTO_HINT) lflags |= FT_LOAD_FORCE_AUTOHINT; + else if (fi->hinting == FONT_BYTECODE_HINT) lflags |= FT_LOAD_NO_AUTOHINT; + error = FT_Load_Glyph(fi->src->ft.face, index, lflags); if (error) return NULL; fg = malloc(sizeof(struct _RGBA_Font_Glyph)); diff --git a/legacy/evas/src/lib/engines/common/evas_font_load.c b/legacy/evas/src/lib/engines/common/evas_font_load.c index 375321fc13..8829584505 100644 --- a/legacy/evas/src/lib/engines/common/evas_font_load.c +++ b/legacy/evas/src/lib/engines/common/evas_font_load.c @@ -232,11 +232,13 @@ evas_common_font_memory_load(const char *name, int size, const void *data, int d if (!fi) return NULL; fn = calloc(1, sizeof(RGBA_Font)); if (!fn) - { - free(fi); - return NULL; - } + { + free(fi); + return NULL; + } fn->fonts = evas_list_append(fn->fonts, fi); + fn->hinting = FONT_BYTECODE_HINT; + fi->hinting = fn->hinting; return fn; } @@ -250,11 +252,13 @@ evas_common_font_load(const char *name, int size) if (!fi) return NULL; fn = calloc(1, sizeof(RGBA_Font)); if (!fn) - { - free(fi); - return NULL; - } + { + free(fi); + return NULL; + } fn->fonts = evas_list_append(fn->fonts, fi); + fn->hinting = FONT_BYTECODE_HINT; + fi->hinting = fn->hinting; return fn; } @@ -271,6 +275,7 @@ evas_common_font_add(RGBA_Font *fn, const char *name, int size) fn->fonts = evas_list_append(fn->fonts, fi); return fn; } + fi->hinting = fn->hinting; return NULL; } @@ -287,6 +292,7 @@ evas_common_font_memory_add(RGBA_Font *fn, const char *name, int size, const voi fn->fonts = evas_list_append(fn->fonts, fi); return fn; } + fi->hinting = fn->hinting; return NULL; } @@ -313,6 +319,46 @@ evas_common_font_free(RGBA_Font *fn) free(fn); } +void +evas_common_font_hinting_set(RGBA_Font *fn, Font_Hint_Flags hinting) +{ + Evas_List *l; + + if (!fn) + return; + fn->hinting = hinting; + for (l = fn->fonts; l; l = l->next) + { + RGBA_Font_Int *fi; + + fi = l->data; + fi->hinting = fn->hinting; + } +} + +Evas_Bool +evas_common_hinting_available(Font_Hint_Flags hinting) +{ + if (hinting == FONT_NO_HINT) return 1; + else if (hinting == FONT_AUTO_HINT) + { +#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING + return 1; +#else + return 0; +#endif + } + else if (hinting == FONT_BYTECODE_HINT) + { +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + return 1; +#else + return 0; +#endif + } + return 0; +} + static Evas_Bool font_modify_cache_cb(Evas_Hash *hash, const char *key, void *data, void *fdata) { diff --git a/legacy/evas/src/lib/imaging/evas_imaging.c b/legacy/evas/src/lib/imaging/evas_imaging.c index d85a86d230..999b82ff30 100644 --- a/legacy/evas/src/lib/imaging/evas_imaging.c +++ b/legacy/evas/src/lib/imaging/evas_imaging.c @@ -63,11 +63,38 @@ evas_imaging_image_cache_get(void) return evas_common_image_get_cache(); } +static Evas_Font_Hinting_Flags _evas_hinting = EVAS_FONT_HINTING_BYTECODE; + +EAPI void +evas_imaging_font_hinting_set(Evas_Font_Hinting_Flags hinting) +{ + _evas_hinting = hinting; +} + +EAPI Evas_Font_Hinting_Flags +evas_imaging_font_hinting_get(void) +{ + return _evas_hinting; +} + +EAPI Evas_Bool +evas_imaging_font_hinting_can_hint(Evas_Font_Hinting_Flags hinting) +{ + Font_Hint_Flags h; + + h = FONT_BYTECODE_HINT; + if (hinting == EVAS_FONT_HINTING_NONE) h = FONT_NO_HINT; + else if (hinting == EVAS_FONT_HINTING_AUTO) h = FONT_AUTO_HINT; + else if (hinting == EVAS_FONT_HINTING_BYTECODE) h = FONT_BYTECODE_HINT; + return evas_common_hinting_available(h); +} + EAPI Evas_Imaging_Font * evas_imaging_font_load(const char *file, const char *key, int size) { Evas_Imaging_Font *fn; RGBA_Font *font; + Font_Hint_Flags h; evas_common_cpu_init(); evas_common_font_init(); @@ -109,6 +136,11 @@ evas_imaging_font_load(const char *file, const char *key, int size) { font = evas_common_font_load((char *)file, size); } + h = FONT_BYTECODE_HINT; + if (_evas_hinting == EVAS_FONT_HINTING_NONE) h = FONT_NO_HINT; + else if (_evas_hinting == EVAS_FONT_HINTING_AUTO) h = FONT_AUTO_HINT; + else if (_evas_hinting == EVAS_FONT_HINTING_BYTECODE) h = FONT_BYTECODE_HINT; + if (font) evas_common_font_hinting_set(font, h); fn = calloc(1, sizeof(RGBA_Font)); if (!fn) return NULL; fn->font = font; diff --git a/legacy/evas/src/lib/include/evas_common.h b/legacy/evas/src/lib/include/evas_common.h index 6308265d4d..d9aa6ad3b0 100644 --- a/legacy/evas/src/lib/include/evas_common.h +++ b/legacy/evas/src/lib/include/evas_common.h @@ -166,6 +166,13 @@ typedef enum _CPU_Features CPU_FEATURE_VIS2 = (1 << 5) } CPU_Features; +typedef enum _Font_Hint_Flags +{ + FONT_NO_HINT, + FONT_AUTO_HINT, + FONT_BYTECODE_HINT +} Font_Hint_Flags; + /*****************************************************************************/ struct _Evas_Object_List @@ -299,6 +306,7 @@ struct _RGBA_Polygon_Point struct _RGBA_Font { Evas_List *fonts; + Font_Hint_Flags hinting; }; struct _RGBA_Font_Int @@ -317,6 +325,7 @@ struct _RGBA_Font_Int Evas_Hash *glyphs; int usage; + Font_Hint_Flags hinting; int references; }; @@ -864,6 +873,8 @@ RGBA_Font *evas_common_font_add (RGBA_Font *fn, const char * RGBA_Font *evas_common_font_memory_add (RGBA_Font *fn, const char *name, int size, const void *data, int data_size); RGBA_Font_Int *evas_common_font_int_load_init (RGBA_Font_Int *fn); void evas_common_font_free (RGBA_Font *fn); +void evas_common_font_hinting_set (RGBA_Font *fn, Font_Hint_Flags hinting); +Evas_Bool evas_common_hinting_available (Font_Hint_Flags hinting); void evas_common_font_int_modify_cache_by(RGBA_Font_Int *fi, int dir); int evas_common_font_cache_get (void); void evas_common_font_cache_set (int size);