summaryrefslogtreecommitdiff
path: root/pango/pangowin32.c
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-04-07 18:38:20 +0900
committerSeungha Yang <seungha@centricular.com>2021-04-07 20:15:25 +0900
commit587834ca76aa80c2bf950396aa2e1edd0869f589 (patch)
tree13de7a5f0533a36758d8b1c80c4f8b27314b0265 /pango/pangowin32.c
parentacea99b46dd4f6b92229089633b0a5d54498d984 (diff)
downloadpango-587834ca76aa80c2bf950396aa2e1edd0869f589.tar.gz
pangowin32: Clear cmap on finalize
Implement copy method for format_4_cmap and format_12_cmap, and free don't leak the struct.
Diffstat (limited to 'pango/pangowin32.c')
-rw-r--r--pango/pangowin32.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 12b4a36e..f8fedcb3 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -1272,3 +1272,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;
+}