SkShaper::SkShaper(sk_sp<SkTypeface> tf) : fImpl(new Impl) { fImpl->fTypeface = tf ? std::move(tf) : SkTypeface::MakeDefault(); int index; std::unique_ptr<SkStreamAsset> asset(fImpl->fTypeface->openStream(&index)); size_t size = asset->getLength(); SkAutoMalloc autoMalloc(size); // TODO(halcanary): Avoid this malloc+copy. asset->read(autoMalloc.get(), size); asset = nullptr; void* ptr = autoMalloc.get(); hb_blob_t* blob = hb_blob_create((char*)autoMalloc.release(), size, HB_MEMORY_MODE_READONLY, ptr, sk_free); SkASSERT(blob); hb_blob_make_immutable(blob); struct HBFaceDel { void operator()(hb_face_t* f) { hb_face_destroy(f); } }; std::unique_ptr<hb_face_t, HBFaceDel> face(hb_face_create(blob, (unsigned)index)); hb_blob_destroy(blob); SkASSERT(face); if (!face) { return; } hb_face_set_index(face.get(), (unsigned)index); hb_face_set_upem(face.get(), fImpl->fTypeface->getUnitsPerEm()); fImpl->fHarfBuzzFont.reset(hb_font_create(face.get())); SkASSERT(fImpl->fHarfBuzzFont); hb_font_set_scale(fImpl->fHarfBuzzFont.get(), FONT_SIZE_SCALE, FONT_SIZE_SCALE); hb_ot_font_set_funcs(fImpl->fHarfBuzzFont.get()); fImpl->fBuffer.reset(hb_buffer_create()); }
hb_blob_t * hb_blob_create (const char *data, unsigned int length, hb_memory_mode_t mode, hb_destroy_func_t destroy, void *user_data) { hb_blob_t *blob; if (!length || !HB_OBJECT_DO_CREATE (hb_blob_t, blob)) { if (destroy) destroy (user_data); return &_hb_blob_nil; } hb_mutex_init (blob->lock); blob->lock_count = 0; blob->data = data; blob->length = length; blob->mode = mode; blob->destroy = destroy; blob->user_data = user_data; if (blob->mode == HB_MEMORY_MODE_DUPLICATE) { blob->mode = HB_MEMORY_MODE_READONLY; if (!hb_blob_try_writable (blob)) { hb_blob_destroy (blob); return &_hb_blob_nil; } } return blob; }
void _hb_ot_layout_destroy (hb_ot_layout_t *layout) { for (unsigned int i = 0; i < layout->gsub_lookup_count; i++) layout->gsub_accels[i].fini (); for (unsigned int i = 0; i < layout->gpos_lookup_count; i++) layout->gpos_accels[i].fini (); free (layout->gsub_accels); free (layout->gpos_accels); hb_blob_destroy (layout->gdef_blob); hb_blob_destroy (layout->gsub_blob); hb_blob_destroy (layout->gpos_blob); free (layout); }
static void * create_face (void) { hb_blob_t *blob = (hb_blob_t *) create_blob (); hb_face_t *face = hb_face_create (blob, 0); hb_blob_destroy (blob); return face; }
/** * pango_ot_info_get: * @face: a <type>FT_Face</type>. * * Returns the #PangoOTInfo structure for the given FreeType font face. * * Return value: the #PangoOTInfo for @face. This object will have * the same lifetime as @face. * * Since: 1.2 **/ PangoOTInfo * pango_ot_info_get (FT_Face face) { PangoOTInfo *info; if (G_LIKELY (face->generic.data && face->generic.finalizer == pango_ot_info_finalizer)) return face->generic.data; else { if (face->generic.finalizer) face->generic.finalizer (face); info = face->generic.data = g_object_new (PANGO_TYPE_OT_INFO, NULL); face->generic.finalizer = pango_ot_info_finalizer; info->face = face; if (face->stream->read == NULL) { hb_blob_t *blob; blob = hb_blob_create ((const char *) face->stream->base, (unsigned int) face->stream->size, HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, NULL, NULL); info->hb_face = hb_face_create_for_data (blob, face->face_index); hb_blob_destroy (blob); } else { info->hb_face = hb_face_create_for_tables (_get_table, NULL, info); } hb_face_set_unicode_funcs (info->hb_face, hb_glib_get_unicode_funcs ()); /* XXX this is such a waste if not SFNT */ if (!hb_ot_layout_has_font_glyph_classes (info->hb_face)) synthesize_class_def (info); } return info; }
static void _hb_blob_unlock_and_destroy (hb_blob_t *blob) { hb_blob_unlock (blob); hb_blob_destroy (blob); }
gfxSVGGlyphs::~gfxSVGGlyphs() { hb_blob_destroy(mSVGData); hb_blob_destroy(mCmapData); }