OT::Sanitizer<OT::COLR> sanitizerCOLR;
hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR));
- const OT::COLR *colr = OT::Sanitizer<OT::COLR>::lock_instance (colr_blob);
+ const OT::COLR *colr = colr_blob->lock_as<OT::COLR> ();
OT::Sanitizer<OT::CPAL> sanitizerCPAL;
hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL));
- const OT::CPAL *cpal = OT::Sanitizer<OT::CPAL>::lock_instance (cpal_blob);
+ const OT::CPAL *cpal = cpal_blob->lock_as<OT::CPAL> ();
cairo_font_face_t *cairo_face;
{
OT::Sanitizer<LE_IMAGE_DOS_HEADER> sanitizer;
hb_blob_t *font_blob = sanitizer.sanitize (blob);
- const LE_IMAGE_DOS_HEADER* dos_header =
- OT::Sanitizer<LE_IMAGE_DOS_HEADER>::lock_instance (font_blob);
+ const LE_IMAGE_DOS_HEADER* dos_header = font_blob->lock_as<LE_IMAGE_DOS_HEADER> ();
const NE_RESOURCE_TABLE &rtable = dos_header->get_os2_header ().get_resource_table ();
int shift = rtable.get_shift_value ();
// OT::Sanitizer<AAT::morx> sanitizer;
// sanitizer.set_num_glyphs (face->get_num_glyphs ());
// hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx));
-// OT::Sanitizer<AAT::morx>::lock_instance (morx_blob);
+// morx_blob->lock_as<AAT::morx> ();
// if (0)
// {
-// OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ());
+// morx_blob->lock_as<AAT::Lookup<OT::GlyphID> > ()->get_value (1, face->get_num_glyphs ());
// }
// }
HB_INTERNAL bool try_make_writable_inplace (void);
HB_INTERNAL bool try_make_writable_inplace_unix (void);
+ inline void lock (void)
+ {
+ hb_blob_make_immutable (this);
+ }
+
+ template <typename Type>
+ inline const Type* as (void) const
+ {
+ return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data);
+ }
+ template <typename Type>
+ inline const Type* lock_as (void)
+ {
+ lock ();
+ return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data);
+ }
+
public:
hb_object_header_t header;
ASSERT_POD ();
#include "hb-private.hh"
#include "hb-face-private.hh"
+#include "hb-blob-private.hh"
#include "hb-open-file-private.hh"
#include "hb-ot-head-table.hh"
#include "hb-ot-maxp-table.hh"
if (tag == HB_TAG_NONE)
return hb_blob_reference (data->blob);
- const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob);
+ const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> ();
const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag);
hb_face_t::load_upem (void) const
{
hb_blob_t *head_blob = OT::Sanitizer<OT::head>().sanitize (reference_table (HB_OT_TAG_head));
- const OT::head *head_table = OT::Sanitizer<OT::head>::lock_instance (head_blob);
+ const OT::head *head_table = head_blob->lock_as<OT::head> ();
upem = head_table->get_upem ();
hb_blob_destroy (head_blob);
}
hb_face_t::load_num_glyphs (void) const
{
hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (reference_table (HB_OT_TAG_maxp));
- const OT::maxp *maxp_table = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob);
+ const OT::maxp *maxp_table = maxp_blob->lock_as<OT::maxp> ();
num_glyphs = maxp_table->get_num_glyphs ();
hb_blob_destroy (maxp_blob);
}
hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data;
- const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob);
+ const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> ();
const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
return ot_face.get_table_tags (start_offset, table_count, table_tags);
#include "hb-private.hh"
#include "hb-debug.hh"
+#include "hb-blob-private.hh"
#include "hb-face-private.hh"
}
}
- static const Type* lock_instance (hb_blob_t *blob) {
- hb_blob_make_immutable (blob);
- const char *base = hb_blob_get_data (blob, nullptr);
- return unlikely (!base) ? &Null(Type) : CastP<Type> (base);
- }
-
inline void set_num_glyphs (unsigned int num_glyphs) { c->num_glyphs = num_glyphs; }
private:
if (unlikely (!p))
{
hb_blob_t *blob_ = OT::Sanitizer<T>().sanitize (face->reference_table (T::tableTag));
- p = const_cast<T *>(OT::Sanitizer<T>::lock_instance (blob_));
+ p = const_cast<T *>(blob_->lock_as<T> ());
if (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p))
{
hb_blob_destroy (blob_);
inline void init (hb_face_t *face)
{
this->blob = OT::Sanitizer<OT::cmap>().sanitize (face->reference_table (HB_OT_TAG_cmap));
- const OT::cmap *cmap = OT::Sanitizer<OT::cmap>::lock_instance (this->blob);
+ const OT::cmap *cmap = this->blob->lock_as<OT::cmap> ();
const OT::CmapSubtable *subtable = nullptr;
const OT::CmapSubtableFormat14 *subtable_uvs = nullptr;
cbdt = nullptr;
return; /* Not a bitmap font. */
}
- cblc = Sanitizer<CBLC>::lock_instance (cblc_blob);
- cbdt = Sanitizer<CBDT>::lock_instance (cbdt_blob);
+ cblc = cblc_blob->lock_as<CBLC> ();
+ cbdt = cbdt_blob->lock_as<CBDT> ();
}
sanitizer.set_num_glyphs (num_glyphs);
sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix));
sbix_len = hb_blob_get_length (sbix_blob);
- sbix_table = OT::Sanitizer<OT::sbix>::lock_instance (sbix_blob);
+ sbix_table = sbix_blob->lock_as<OT::sbix> ();
}
OT::Sanitizer<OT::SVG> sanitizer;
svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG));
svg_len = hb_blob_get_length (svg_blob);
- svg = OT::Sanitizer<OT::SVG>::lock_instance (svg_blob);
+ svg = svg_blob->lock_as<OT::SVG> ();
}
memset (this, 0, sizeof (accelerator_t));
hb_blob_t *head_blob = Sanitizer<head>().sanitize (face->reference_table (HB_OT_TAG_head));
- const head *head_table = Sanitizer<head>::lock_instance (head_blob);
+ const head *head_table = head_blob->lock_as<head> ();
if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0)
{
/* head table is not present, or in an unknown format. Leave num_glyphs=0, that takes care of disabling us. */
hb_blob_destroy (head_blob);
loca_blob = Sanitizer<loca>().sanitize (face->reference_table (HB_OT_TAG_loca));
- loca_table = Sanitizer<loca>::lock_instance (loca_blob);
+ loca_table = loca_blob->lock_as<loca> ();
glyf_blob = Sanitizer<glyf>().sanitize (face->reference_table (HB_OT_TAG_glyf));
- glyf_table = Sanitizer<glyf>::lock_instance (glyf_blob);
+ glyf_table = glyf_blob->lock_as<glyf> ();
num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1;
glyf_len = hb_blob_get_length (glyf_blob);
if (T::os2Tag)
{
hb_blob_t *os2_blob = Sanitizer<os2> ().sanitize (face->reference_table (T::os2Tag));
- const os2 *os2_table = Sanitizer<os2>::lock_instance (os2_blob);
+ const os2 *os2_table = os2_blob->lock_as<os2> ();
#define USE_TYPO_METRICS (1u<<7)
if (0 != (os2_table->fsSelection & USE_TYPO_METRICS))
{
}
hb_blob_t *_hea_blob = Sanitizer<H> ().sanitize (face->reference_table (H::tableTag));
- const H *_hea_table = Sanitizer<H>::lock_instance (_hea_blob);
+ const H *_hea_table = _hea_blob->lock_as<H> ();
num_advances = _hea_table->numberOfLongMetrics;
if (!got_font_extents)
{
hb_blob_destroy (blob);
blob = hb_blob_get_empty ();
}
- table = Sanitizer<hmtxvmtx>::lock_instance (blob);
+ table = blob->lock_as<hmtxvmtx> ();
var_blob = Sanitizer<HVARVVAR> ().sanitize (face->reference_table (T::variationsTag));
- var_table = Sanitizer<HVARVVAR>::lock_instance (var_blob);
+ var_table = var_blob->lock_as<HVARVVAR> ();
}
inline void fini (void)
inline void init (hb_face_t *face)
{
blob = Sanitizer<kern>().sanitize (face->reference_table (HB_OT_TAG_kern));
- table = Sanitizer<kern>::lock_instance (blob);
+ table = blob->lock_as<kern> ();
table_length = hb_blob_get_length (blob);
}
inline void fini (void)
return nullptr;
layout->gdef_blob = OT::Sanitizer<OT::GDEF>().sanitize (face->reference_table (HB_OT_TAG_GDEF));
- layout->gdef = OT::Sanitizer<OT::GDEF>::lock_instance (layout->gdef_blob);
+ layout->gdef = layout->gdef_blob->lock_as<OT::GDEF> ();
layout->gsub_blob = OT::Sanitizer<OT::GSUB>().sanitize (face->reference_table (HB_OT_TAG_GSUB));
- layout->gsub = OT::Sanitizer<OT::GSUB>::lock_instance (layout->gsub_blob);
+ layout->gsub = layout->gsub_blob->lock_as<OT::GSUB> ();
layout->gpos_blob = OT::Sanitizer<OT::GPOS>().sanitize (face->reference_table (HB_OT_TAG_GPOS));
- layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob);
+ layout->gpos = layout->gpos_blob->lock_as<OT::GPOS> ();
layout->math.init (face);
layout->fvar.init (face);
inline void init (hb_face_t *face)
{
blob = Sanitizer<post>().sanitize (face->reference_table (HB_OT_TAG_post));
- const post *table = Sanitizer<post>::lock_instance (blob);
+ const post *table = blob->lock_as<post> ();
unsigned int table_length = hb_blob_get_length (blob);
version = table->version.to_int ();
OT::Sanitizer<TableType> sanitizer;
hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag));
- const TableType *table = OT::Sanitizer<TableType>::lock_instance (source_blob);
+ const TableType *table = source_blob->lock_as<TableType> ();
hb_tag_t tag = TableType::tableTag;
hb_bool_t result = false;
Sanitizer<OpenTypeFontFile> sanitizer;
hb_blob_t *font_blob = sanitizer.sanitize (blob);
- const OpenTypeFontFile* sanitized = Sanitizer<OpenTypeFontFile>::lock_instance (font_blob);
+ const OpenTypeFontFile* sanitized = font_blob->lock_as<OpenTypeFontFile> ();
if (sanitized == &Null (OpenTypeFontFile))
{
printf ("Sanitization of the file wasn't successful. Exit");