summaryrefslogtreecommitdiff
path: root/pango/pangofc-font.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-03-10 17:13:36 -0400
committerBehdad Esfahbod <behdad@behdad.org>2009-03-13 18:03:50 -0400
commit03a13541fbf3f49c21d73490570ca217f559acbb (patch)
tree98edb70be04557bb169a4cf56601d9169ecd28ff /pango/pangofc-font.c
parentc84d4e6e068d802cd0fe2b23bee4c611ae9ef89f (diff)
downloadpango-03a13541fbf3f49c21d73490570ca217f559acbb.tar.gz
[pangofc] Share cmap cache between PangoFcFont's of the same face (#567160)
Diffstat (limited to 'pango/pangofc-font.c')
-rw-r--r--pango/pangofc-font.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 9c5b9ed1..46ce282c 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -38,33 +38,15 @@ enum {
PROP_FONTMAP
};
-typedef struct _GUnicharToGlyphCacheEntry GUnicharToGlyphCacheEntry;
-
-/* An entry in the fixed-size cache for the gunichar -> glyph mapping.
- * The cache is indexed by the lower N bits of the gunichar (see
- * GLYPH_CACHE_NUM_ENTRIES). For scripts with few code points,
- * this should provide pretty much instant lookups.
- *
- * The "ch" field is zero if that cache entry is invalid.
- */
-struct _GUnicharToGlyphCacheEntry
-{
- gunichar ch;
- PangoGlyph glyph;
-};
-
typedef struct _PangoFcFontPrivate PangoFcFontPrivate;
struct _PangoFcFontPrivate
{
PangoFcDecoder *decoder;
PangoFcFontKey *key;
- GUnicharToGlyphCacheEntry *char_to_glyph_cache;
+ PangoFcCmapCache *cmap_cache;
};
-#define GLYPH_CACHE_NUM_ENTRIES 256 /* should be power of two */
-#define GLYPH_CACHE_MASK (GLYPH_CACHE_NUM_ENTRIES - 1)
-
static gboolean pango_fc_font_real_has_char (PangoFcFont *font,
gunichar wc);
static guint pango_fc_font_real_get_glyph (PangoFcFont *font,
@@ -166,7 +148,8 @@ pango_fc_font_finalize (GObject *object)
if (priv->decoder)
_pango_fc_font_set_decoder (fcfont, NULL);
- g_free (priv->char_to_glyph_cache);
+ if (priv->cmap_cache)
+ _pango_fc_cmap_cache_unref (priv->cmap_cache);
G_OBJECT_CLASS (pango_fc_font_parent_class)->finalize (object);
}
@@ -619,23 +602,25 @@ static guint
pango_fc_font_real_get_glyph (PangoFcFont *font,
gunichar wc)
{
+ PangoFcFontPrivate *priv = font->priv;
FT_Face face;
FT_UInt index;
guint idx;
- GUnicharToGlyphCacheEntry *entry;
+ PangoFcCmapCacheEntry *entry;
- PangoFcFontPrivate *priv = font->priv;
- if (G_UNLIKELY (priv->char_to_glyph_cache == NULL))
+ if (G_UNLIKELY (priv->cmap_cache == NULL))
{
- priv->char_to_glyph_cache = g_new0 (GUnicharToGlyphCacheEntry, GLYPH_CACHE_NUM_ENTRIES);
- /* Make sure all cache entries are invalid initially */
- priv->char_to_glyph_cache[0].ch = 1; /* char 1 cannot happen in bucket 0 */
+ priv->cmap_cache = _pango_fc_font_map_get_cmap_cache ((PangoFcFontMap *) font->fontmap,
+ font);
+
+ if (G_UNLIKELY (!priv->cmap_cache))
+ return 0;
}
- idx = wc & GLYPH_CACHE_MASK;
- entry = priv->char_to_glyph_cache + idx;
+ idx = wc & CMAP_CACHE_MASK;
+ entry = priv->cmap_cache->entries + idx;
if (entry->ch != wc)
{