diff --git a/engine/src/flutter/third_party/txt/src/txt/font_skia.cc b/engine/src/flutter/third_party/txt/src/txt/font_skia.cc index e0dc263929..c825b93dd1 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_skia.cc +++ b/engine/src/flutter/third_party/txt/src/txt/font_skia.cc @@ -15,6 +15,7 @@ */ #include "font_skia.h" +#include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkFont.h" #include @@ -24,21 +25,14 @@ namespace { hb_blob_t* GetTable(hb_face_t* face, hb_tag_t tag, void* context) { SkTypeface* typeface = reinterpret_cast(context); - - const size_t table_size = typeface->getTableSize(tag); - if (table_size == 0) - return nullptr; - void* buffer = malloc(table_size); - if (buffer == nullptr) - return nullptr; - - size_t actual_size = typeface->getTableData(tag, 0, table_size, buffer); - if (table_size != actual_size) { - free(buffer); + sk_sp data = typeface->copyTableData(tag); + if (!data) { return nullptr; } - return hb_blob_create(reinterpret_cast(buffer), table_size, - HB_MEMORY_MODE_WRITABLE, buffer, free); + SkData* rawData = data.release(); + return hb_blob_create(reinterpret_cast(rawData->writable_data()), + rawData->size(), HB_MEMORY_MODE_WRITABLE, rawData, + [](void* ctx) { ((SkData*)ctx)->unref(); }); } } // namespace