diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2014-07-28 18:37:36 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2015-04-04 16:13:40 -0700 |
commit | 7d30b3f91958a3ff45ee2b8e5de2b6186cadfb72 (patch) | |
tree | c598289612344faffb3b0225707f1c2ed2282de8 /pango/pango-context.c | |
parent | 14c11dd96e1547aaede1bb05a0243f5b0b53186e (diff) | |
download | pango-7d30b3f91958a3ff45ee2b8e5de2b6186cadfb72.tar.gz |
Deprecate module system, skip it for shaper modules
Now shaper is discovered via (previously unused!) font->find_shaper().
I'm keeping that just to allow clients override shaping. Though,
even that I'm not sure we want to keep.
Wraps shaper in PangoEngineShape structs to keep PangoAnalysis API
intact.
Deprecated pango-modules.h and some pango-engine.h. Language modules
are not moved yet.
Wired up PangoFc, PangoWin32, and PangoCoretext shapers.
Diffstat (limited to 'pango/pango-context.c')
-rw-r--r-- | pango/pango-context.c | 176 |
1 files changed, 49 insertions, 127 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c index 6f72653b..2a7dd541 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -607,34 +607,31 @@ advance_attr_iterator_to (PangoAttrIterator *iterator, typedef struct { GHashTable *hash; -} ShaperFontCache; +} FontCache; typedef struct { - PangoEngineShape *shape_engine; PangoFont *font; -} ShaperFontElement; +} FontElement; static void -shaper_font_cache_destroy (ShaperFontCache *cache) +font_cache_destroy (FontCache *cache) { g_hash_table_destroy (cache->hash); - g_slice_free (ShaperFontCache, cache); + g_slice_free (FontCache, cache); } static void -shaper_font_element_destroy (ShaperFontElement *element) +font_element_destroy (FontElement *element) { - if (element->shape_engine) - g_object_unref (element->shape_engine); if (element->font) g_object_unref (element->font); - g_slice_free (ShaperFontElement, element); + g_slice_free (FontElement, element); } -static ShaperFontCache * -get_shaper_font_cache (PangoFontset *fontset) +static FontCache * +get_font_cache (PangoFontset *fontset) { - ShaperFontCache *cache; + FontCache *cache; static GQuark cache_quark = 0; /* MT-safe */ if (G_UNLIKELY (!cache_quark)) @@ -644,14 +641,14 @@ retry: cache = g_object_get_qdata (G_OBJECT (fontset), cache_quark); if (G_UNLIKELY (!cache)) { - cache = g_slice_new (ShaperFontCache); + cache = g_slice_new (FontCache); cache->hash = g_hash_table_new_full (g_direct_hash, NULL, - NULL, (GDestroyNotify)shaper_font_element_destroy); + NULL, (GDestroyNotify)font_element_destroy); if (!g_object_replace_qdata (G_OBJECT (fontset), cache_quark, NULL, - cache, (GDestroyNotify)shaper_font_cache_destroy, + cache, (GDestroyNotify)font_cache_destroy, NULL)) { - shaper_font_cache_destroy (cache); + font_cache_destroy (cache); goto retry; } } @@ -660,17 +657,15 @@ retry: } static gboolean -shaper_font_cache_get (ShaperFontCache *cache, - gunichar wc, - PangoEngineShape **shape_engine, - PangoFont **font) +font_cache_get (FontCache *cache, + gunichar wc, + PangoFont **font) { - ShaperFontElement *element; + FontElement *element; element = g_hash_table_lookup (cache->hash, GUINT_TO_POINTER (wc)); if (element) { - *shape_engine = element->shape_engine; *font = element->font; return TRUE; @@ -680,13 +675,11 @@ shaper_font_cache_get (ShaperFontCache *cache, } static void -shaper_font_cache_insert (ShaperFontCache *cache, - gunichar wc, - PangoEngineShape *shape_engine, - PangoFont *font) +font_cache_insert (FontCache *cache, + gunichar wc, + PangoFont *font) { - ShaperFontElement *element = g_slice_new (ShaperFontElement); - element->shape_engine = shape_engine ? g_object_ref (shape_engine) : NULL; + FontElement *element = g_slice_new (FontElement); element->font = font ? g_object_ref (font) : NULL; g_hash_table_insert (cache->hash, GUINT_TO_POINTER (wc), element); @@ -763,12 +756,9 @@ struct _ItemizeState PangoEngineLang *lang_engine; PangoFontset *current_fonts; - ShaperFontCache *cache; + FontCache *cache; PangoFont *base_font; gboolean enable_fallback; - - GSList *exact_engines; - GSList *fallback_engines; }; static void @@ -995,8 +985,6 @@ itemize_state_init (ItemizeState *state, state->lang_engine = NULL; state->current_fonts = NULL; state->cache = NULL; - state->exact_engines = NULL; - state->fallback_engines = NULL; state->base_font = NULL; state->changed = EMBEDDING_CHANGED | SCRIPT_CHANGED | LANG_CHANGED | FONT_CHANGED | WIDTH_CHANGED; @@ -1167,60 +1155,34 @@ itemize_state_add_character (ItemizeState *state, state->result = g_list_prepend (state->result, state->item); } -static void -get_engines (PangoContext *context, - PangoLanguage *lang, - PangoScript script, - GSList **exact_engines, - GSList **fallback_engines) -{ - const char *engine_type = pango_font_map_get_shape_engine_type (context->font_map); - PangoMap *shaper_map = pango_find_map (lang, - g_quark_from_string (PANGO_ENGINE_TYPE_SHAPE), - g_quark_from_string (engine_type)); - pango_map_get_engines (shaper_map, script, - exact_engines, fallback_engines); -} - typedef struct { PangoLanguage *lang; gunichar wc; - GSList *engines; - PangoEngineShape *shape_engine; PangoFont *font; -} GetShaperFontInfo; +} GetFontInfo; static gboolean -get_shaper_and_font_foreach (PangoFontset *fontset, - PangoFont *font, - gpointer data) +get_font_foreach (PangoFontset *fontset, + PangoFont *font, + gpointer data) { - GetShaperFontInfo *info = data; - GSList *l; + GetFontInfo *info = data; + PangoEngineShape *engine; + PangoCoverageLevel level; if (G_UNLIKELY (!font)) return FALSE; - for (l = info->engines; l; l = l->next) + engine = pango_font_find_shaper (font, info->lang, info->wc), + level = _pango_engine_shape_covers (engine, font, info->lang, info->wc); + if (level != PANGO_COVERAGE_NONE) { - PangoEngineShape *engine = l->data; - PangoCoverageLevel level; - - level = _pango_engine_shape_covers (engine, font, - info->lang, info->wc); - if (level != PANGO_COVERAGE_NONE) - { - info->shape_engine = engine; - info->font = font; - return TRUE; - } + info->font = font; + return TRUE; } - if (!fontset && info->engines && info->engines->next == NULL) + if (!fontset) { - /* We are in no-fallback mode and there's only one engine, just - * return it. */ - info->shape_engine = (PangoEngineShape *) info->engines->data; info->font = font; return TRUE; } @@ -1259,69 +1221,33 @@ get_shaper_and_font (ItemizeState *state, PangoEngineShape **shape_engine, PangoFont **font) { - GetShaperFontInfo info; + GetFontInfo info; /* We'd need a separate cache when fallback is disabled, but since lookup * with fallback disabled is faster anyways, we just skip caching */ - if (state->enable_fallback && shaper_font_cache_get (state->cache, wc, shape_engine, font)) - return *shape_engine != NULL; - - if (!state->exact_engines && !state->fallback_engines) - get_engines (state->context, state->derived_lang, get_script (state), - &state->exact_engines, &state->fallback_engines); + if (state->enable_fallback && font_cache_get (state->cache, wc, font)) + { + *shape_engine = pango_font_find_shaper (*font, state->derived_lang, wc); + return TRUE; + } info.lang = state->derived_lang; info.wc = wc; - info.shape_engine = NULL; info.font = NULL; - info.engines = state->exact_engines; - if (info.engines) - { - if (state->enable_fallback) - pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); - else - get_shaper_and_font_foreach (NULL, get_base_font (state), &info); - - if (info.shape_engine) - { - *shape_engine = info.shape_engine; - *font = info.font; - - /* skip caching if fallback disabled (see above) */ - if (state->enable_fallback) - shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); - - return TRUE; - } - } - - info.engines = state->fallback_engines; - if (info.engines) - { - if (state->enable_fallback) - pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); - else - get_shaper_and_font_foreach (NULL, get_base_font (state), &info); - } + if (state->enable_fallback) + pango_fontset_foreach (state->current_fonts, get_font_foreach, &info); + else + get_font_foreach (NULL, get_base_font (state), &info); - *shape_engine = info.shape_engine; *font = info.font; + *shape_engine = pango_font_find_shaper (*font, state->derived_lang, wc); /* skip caching if fallback disabled (see above) */ if (state->enable_fallback) - shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); - - return *shape_engine != NULL; -} + font_cache_insert (state->cache, wc, *font); -static void -itemize_state_reset_shape_engines (ItemizeState *state) -{ - g_slist_free (state->exact_engines); - state->exact_engines = NULL; - g_slist_free (state->fallback_engines); - state->fallback_engines = NULL; + return TRUE; } static PangoLanguage * @@ -1416,9 +1342,6 @@ itemize_state_update_for_new_run (ItemizeState *state) state->lang_engine = (PangoEngineLang *)pango_map_get_engine (lang_map, state->script); } - if (state->changed & (SCRIPT_CHANGED | DERIVED_LANG_CHANGED)) - itemize_state_reset_shape_engines (state); - if (state->changed & (FONT_CHANGED | DERIVED_LANG_CHANGED) && state->current_fonts) { @@ -1433,7 +1356,7 @@ itemize_state_update_for_new_run (ItemizeState *state) state->context, state->font_desc, state->derived_lang); - state->cache = get_shaper_font_cache (state->current_fonts); + state->cache = get_font_cache (state->current_fonts); } if ((state->changed & FONT_CHANGED) && state->base_font) @@ -1554,7 +1477,6 @@ itemize_state_finish (ItemizeState *state) _pango_script_iter_fini (&state->script_iter); pango_font_description_free (state->font_desc); - itemize_state_reset_shape_engines (state); if (state->current_fonts) g_object_unref (state->current_fonts); if (state->base_font) |