diff --git a/src/hb-aat-layout-lcar-table.hh b/src/hb-aat-layout-lcar-table.hh index e57836a08..43ac74f9c 100644 --- a/src/hb-aat-layout-lcar-table.hh +++ b/src/hb-aat-layout-lcar-table.hh @@ -49,7 +49,8 @@ struct lcar unsigned int *caret_count /* IN/OUT */, hb_position_t *caret_array /* OUT */) const { - const OffsetTo* entry_offset = lookup.get_value (glyph, font->face->num_glyphs); + const OffsetTo* entry_offset = lookup.get_value (glyph, + font->face->get_num_glyphs ()); const LigCaretClassEntry& array = entry_offset ? this+*entry_offset : Null (LigCaretClassEntry); if (caret_count && *caret_count) { diff --git a/src/hb-face.cc b/src/hb-face.cc index da73433cb..3294ed4c4 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -87,8 +87,8 @@ DEFINE_NULL_INSTANCE (hb_face_t) = nullptr, /* destroy */ 0, /* index */ - 1000, /* upem */ - 0, /* num_glyphs */ + HB_ATOMIC_INT_INIT (1000), /* upem */ + HB_ATOMIC_INT_INIT (0), /* num_glyphs */ { #define HB_SHAPER_IMPLEMENT(shaper) HB_ATOMIC_PTR_INIT (HB_SHAPER_DATA_INVALID), @@ -129,7 +129,7 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, face->user_data = user_data; face->destroy = destroy; - face->num_glyphs = (unsigned int) -1; + face->num_glyphs.set_relaxed (-1); face->table.init0 (face); @@ -445,7 +445,7 @@ hb_face_set_upem (hb_face_t *face, if (hb_object_is_immutable (face)) return; - face->upem = upem; + face->upem.set_relaxed (upem); } /** @@ -480,7 +480,7 @@ hb_face_set_glyph_count (hb_face_t *face, if (hb_object_is_immutable (face)) return; - face->num_glyphs = glyph_count; + face->num_glyphs.set_relaxed (glyph_count); } /** diff --git a/src/hb-face.hh b/src/hb-face.hh index 5d22f4ada..002fb2cb7 100644 --- a/src/hb-face.hh +++ b/src/hb-face.hh @@ -49,8 +49,8 @@ struct hb_face_t hb_destroy_func_t destroy; unsigned int index; /* Face index in a collection, zero-based. */ - mutable unsigned int upem; /* Units-per-EM. */ - mutable unsigned int num_glyphs; /* Number of glyphs. */ + mutable hb_atomic_int_t upem; /* Units-per-EM. */ + mutable hb_atomic_int_t num_glyphs; /* Number of glyphs. */ struct hb_shaper_data_t shaper_data; /* Various shaper data. */ @@ -80,21 +80,25 @@ struct hb_face_t inline HB_PURE_FUNC unsigned int get_upem (void) const { - if (unlikely (!upem)) - load_upem (); - return upem; + unsigned int ret = upem.get_relaxed (); + if (unlikely (!ret)) + { + return load_upem (); + } + return ret; } inline unsigned int get_num_glyphs (void) const { - if (unlikely (num_glyphs == (unsigned int) -1)) - load_num_glyphs (); - return num_glyphs; + unsigned int ret = num_glyphs.get_relaxed (); + if (unlikely (ret == (unsigned int) -1)) + return load_num_glyphs (); + return ret; } private: - HB_INTERNAL void load_upem (void) const; - HB_INTERNAL void load_num_glyphs (void) const; + HB_INTERNAL unsigned int load_upem (void) const; + HB_INTERNAL unsigned int load_num_glyphs (void) const; }; DECLARE_NULL_INSTANCE (hb_face_t); diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 80d65022c..08dee2a0c 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -249,7 +249,7 @@ struct sbix /* Convert to font units. */ if (strike_ppem) { - double scale = font->face->upem / (double) strike_ppem; + double scale = font->face->get_upem () / (double) strike_ppem; extents->x_bearing = round (extents->x_bearing * scale); extents->y_bearing = round (extents->y_bearing * scale); extents->width = round (extents->width * scale); diff --git a/src/hb-static.cc b/src/hb-static.cc index 461b08be5..73d9528e6 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -46,21 +46,26 @@ DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x0 const unsigned char _hb_Null_AAT_Lookup[2] = {0xFF, 0xFF}; -void +unsigned int hb_face_t::load_num_glyphs (void) const { hb_sanitize_context_t c = hb_sanitize_context_t (); c.set_num_glyphs (0); /* So we don't recurse ad infinitum. */ hb_blob_t *maxp_blob = c.reference_table (this); const OT::maxp *maxp_table = maxp_blob->as (); - num_glyphs = maxp_table->get_num_glyphs (); + + unsigned int ret = maxp_table->get_num_glyphs (); + num_glyphs.set_relaxed (ret); hb_blob_destroy (maxp_blob); + return ret; } -void +unsigned int hb_face_t::load_upem (void) const { - upem = table.head->get_upem (); + unsigned int ret = table.head->get_upem (); + upem.set_relaxed (ret); + return ret; } #endif