diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-07-09 17:07:25 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-07-09 17:07:25 +0000 |
commit | cf7d2330339e54897ec1dd852bfead6ba023eb96 (patch) | |
tree | 3d39c60f1148086f8f51202b61600f372834d702 | |
parent | 40aa32f1329e0d3fe4993c5955b94a24aedea836 (diff) | |
parent | 587834ca76aa80c2bf950396aa2e1edd0869f589 (diff) | |
download | pango-cf7d2330339e54897ec1dd852bfead6ba023eb96.tar.gz |
Merge branch 'win32-cmap-free' into 'master'
pangowin32: Clear cmap on finalize
See merge request GNOME/pango!318
-rw-r--r-- | pango/pangowin32-fontmap.c | 4 | ||||
-rw-r--r-- | pango/pangowin32-private.h | 4 | ||||
-rw-r--r-- | pango/pangowin32.c | 59 |
3 files changed, 65 insertions, 2 deletions
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 4cf2df3a..379bf813 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -678,7 +678,7 @@ create_standard_family (PangoWin32FontMap *win32fontmap, new_face->has_cmap = old_face->has_cmap; new_face->cmap_format = old_face->cmap_format; - new_face->cmap = old_face->cmap; + new_face->cmap = _pango_win32_copy_cmap (old_face->cmap, old_face->cmap_format); new_face->cached_fonts = NULL; @@ -1761,7 +1761,7 @@ pango_win32_face_finalize (GObject *object) g_free (win32face->face_name); - //g_free (win32face->cmap); // Err, cmap does not have lifecycle management currently :( + g_free (win32face->cmap); g_slist_free (win32face->cached_fonts); // g_slist_free_full (win32face->cached_fonts, g_object_unref); // This doesn't work. diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h index 1c9c1c09..3884c776 100644 --- a/pango/pangowin32-private.h +++ b/pango/pangowin32-private.h @@ -275,6 +275,10 @@ HFONT _pango_win32_font_get_hfont (PangoFont *font); _PANGO_EXTERN HDC _pango_win32_get_display_dc (void); +_PANGO_EXTERN +gpointer _pango_win32_copy_cmap (gpointer cmap, + guint16 cmap_format); + extern gboolean _pango_win32_debug; #endif /* __PANGOWIN32_PRIVATE_H__ */ diff --git a/pango/pangowin32.c b/pango/pangowin32.c index c8a5b46c..2d22e1d1 100644 --- a/pango/pangowin32.c +++ b/pango/pangowin32.c @@ -1275,3 +1275,62 @@ pango_win32_font_create_hb_font (PangoFont *font) return hb_font; } + +gpointer +_pango_win32_copy_cmap (gpointer cmap, guint16 cmap_format) +{ + if (!cmap) + return NULL; + + if (cmap_format == 12) + { + struct format_12_cmap *new_table; + struct format_12_cmap *old_table; + guint32 *tbl, *tbl_end; + + old_table = (struct format_12_cmap *) cmap; + + new_table = g_malloc (old_table->length); + memcpy (old_table, new_table, sizeof (struct format_12_cmap)); + + tbl_end = (guint32 *) ((char *) new_table + new_table->length); + tbl = new_table->groups; + + while (tbl < tbl_end) + { + *tbl = GUINT32_FROM_BE (*tbl); + tbl++; + } + + return new_table; + } + else if (cmap_format == 4) + { + struct format_4_cmap *new_table; + struct format_4_cmap *old_table; + guint16 *tbl, *tbl_end; + + old_table = (struct format_4_cmap *) cmap; + + new_table = g_malloc (old_table->length); + memcpy (old_table, new_table, sizeof (struct format_4_cmap)); + + tbl_end = (guint16 *)((char *) new_table + new_table->length); + tbl = &new_table->reserved; + + while (tbl < tbl_end) + { + *tbl = GUINT16_FROM_BE (*tbl); + tbl++; + } + + return new_table; + } + else + { + /* got non-null cmap but unknown format, it shouldn't happen */ + g_assert_not_reached (); + } + + return NULL; +} |