summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-06-17 19:15:44 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-06-20 10:24:20 +0200
commit94bc20da50c5984e5c04929a7fde4c2f04e66380 (patch)
treed00fb503059826a77cf523ea419131f3e8b08a2a /src
parent94b14c929d75408958d4451253251fb3631a09bf (diff)
win32-font: Implement destroy function
Win32 font faces can be removed from the hashtable upon destruction. Based on the toy-font destruction code. See https://bugs.freedesktop.org/show_bug.cgi?id=38049
Diffstat (limited to 'src')
-rw-r--r--src/cairo-win32-font.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index f796f21b..34778886 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -149,6 +149,10 @@ static cairo_status_t
_cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font,
cairo_scaled_glyph_t *scaled_glyph);
+static void
+_cairo_win32_font_face_destroy (void *abstract_face);
+
+
#define NEARLY_ZERO(d) (fabs(d) < (1. / 65536.))
static HDC
@@ -1920,11 +1924,6 @@ struct _cairo_win32_font_face {
/* implement the platform-specific interface */
-static void
-_cairo_win32_font_face_destroy (void *abstract_face)
-{
-}
-
static cairo_bool_t
_is_scale (const cairo_matrix_t *matrix, double scale)
{
@@ -2041,6 +2040,37 @@ _cairo_win32_font_face_hash_table_unlock (void)
}
static void
+_cairo_win32_font_face_destroy (void *abstract_face)
+{
+ cairo_win32_font_face_t *font_face = abstract_face;
+ cairo_hash_table_t *hash_table;
+
+ if (font_face == NULL ||
+ CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->base.ref_count))
+ return;
+
+ hash_table = _cairo_win32_font_face_hash_table_lock ();
+ /* All created objects must have been mapped in the hash table. */
+ assert (hash_table != NULL);
+
+ if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) {
+ /* somebody recreated the font whilst we waited for the lock */
+ _cairo_win32_font_face_hash_table_unlock ();
+ return;
+ }
+
+ /* Font faces in SUCCESS status are guaranteed to be in the
+ * hashtable. Font faces in an error status are removed from the
+ * hashtable if they are found during a lookup, thus they should
+ * only be removed if they are in the hashtable. */
+ if (likely (font_face->base.status == CAIRO_STATUS_SUCCESS) ||
+ _cairo_hash_table_lookup (hash_table, &font_face->base.hash_entry) == font_face)
+ _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
+
+ _cairo_win32_font_face_hash_table_unlock ();
+}
+
+static void
_cairo_win32_font_face_init_key (cairo_win32_font_face_t *key,
LOGFONTW *logfont,
HFONT font)