HB_Error harfbuzzSkiaGetTable(void* voidface, const HB_Tag tag, HB_Byte* buffer, HB_UInt* len) { FontPlatformData* font = reinterpret_cast<FontPlatformData*>(voidface); const size_t tableSize = SkFontHost::GetTableSize(font->uniqueID(), tag); if (!tableSize) return HB_Err_Invalid_Argument; // If Harfbuzz specified a NULL buffer then it's asking for the size of the table. if (!buffer) { *len = tableSize; return HB_Err_Ok; } if (*len < tableSize) return HB_Err_Invalid_Argument; SkFontHost::GetTableData(font->uniqueID(), tag, 0, tableSize, buffer); return HB_Err_Ok; }
static hb_blob_t* harfbuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* userData) { FontPlatformData* font = reinterpret_cast<FontPlatformData*>(userData); const size_t tableSize = SkFontHost::GetTableSize(font->uniqueID(), tag); if (!tableSize) return 0; char* buffer = reinterpret_cast<char*>(fastMalloc(tableSize)); if (!buffer) return 0; size_t actualSize = SkFontHost::GetTableData(font->uniqueID(), tag, 0, tableSize, buffer); if (tableSize != actualSize) { fastFree(buffer); return 0; } return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_WRITABLE, buffer, fastFree); }