Add dirty-state tracking to hb_font_t
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 53671d7..fbb16a0 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -116,6 +116,16 @@
void *user_data;
hb_destroy_func_t destroy;
+ enum dirty_t {
+ NOTHING = 0x0000,
+ FACE = 0x0001,
+ PARENT = 0x0002,
+ FUNCS = 0x0004,
+ SCALE = 0x0008,
+ PPEM = 0x0010,
+ VARIATIONS = 0x0020,
+ } dirty;
+
struct hb_shaper_data_t shaper_data;
@@ -543,6 +553,8 @@
}
};
+HB_MARK_AS_FLAG_T (hb_font_t::dirty_t);
+
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font);
#include "hb-shaper-list.hh"
diff --git a/src/hb-font.cc b/src/hb-font.cc
index db3ffcc..cc0e6c3 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -1196,6 +1196,8 @@
NULL, /* user_data */
NULL, /* destroy */
+ hb_font_t::NOTHING, /* dirty_bits */
+
{
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
#include "hb-shaper-list.hh"
@@ -1348,6 +1350,11 @@
if (!parent)
parent = hb_font_get_empty ();
+ if (parent == font->parent)
+ return;
+
+ font->dirty |= font->PARENT;
+
hb_font_t *old = font->parent;
font->parent = hb_font_reference (parent);
@@ -1393,6 +1400,8 @@
if (font->face == face)
return;
+ font->dirty |= font->FACE;
+
hb_face_t *old = font->face;
font->face = hb_face_reference (face);
@@ -1446,6 +1455,8 @@
if (!klass)
klass = hb_font_funcs_get_empty ();
+ font->dirty |= font->FUNCS;
+
hb_font_funcs_reference (klass);
hb_font_funcs_destroy (font->klass);
font->klass = klass;
@@ -1501,6 +1512,11 @@
if (font->immutable)
return;
+ if (font->x_scale == x_scale && font->y_scale == y_scale)
+ return;
+
+ font->dirty |= font->SCALE;
+
font->x_scale = x_scale;
font->y_scale = y_scale;
}
@@ -1542,6 +1558,11 @@
if (font->immutable)
return;
+ if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
+ return;
+
+ font->dirty |= font->PPEM;
+
font->x_ppem = x_ppem;
font->y_ppem = y_ppem;
}
@@ -1574,6 +1595,15 @@
int *coords, /* 2.14 normalized */
unsigned int coords_length)
{
+ if (font->num_coords == coords_length &&
+ 0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0])))
+ {
+ free (coords);
+ return;
+ }
+
+ font->dirty |= font->VARIATIONS;
+
free (font->coords);
font->coords = coords;