From 29abb82198868908ece4600284fa8b7d3ed73f3b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 8 Apr 2016 10:28:47 -0700 Subject: Update minikin/sample code to use new GetTable We changed the signature of the MinikinFont::GetTable method. This patch updates the sample code, and fixes the build. Change-Id: I1977be868bf7636986fc802915f3dd54c418a73a --- sample/MinikinSkia.cpp | 22 +++++++++++++--------- sample/MinikinSkia.h | 3 +-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sample/MinikinSkia.cpp b/sample/MinikinSkia.cpp index feda8ad..c4971bb 100644 --- a/sample/MinikinSkia.cpp +++ b/sample/MinikinSkia.cpp @@ -47,16 +47,20 @@ void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id, bounds->mBottom = skBounds.fBottom; } -bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { - if (buf == NULL) { - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - return tableSize != 0; - } else { - const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf); - *size = actualSize; - return actualSize != 0; +const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { + // we don't have a buffer to the font data, copy to own buffer + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + if (tableSize == 0) { + return nullptr; } + void* buf = malloc(tableSize); + if (buf == nullptr) { + return nullptr; + } + mTypeface->getTableData(tag, 0, tableSize, buf); + *destroy = free; + return buf; } SkTypeface *MinikinFontSkia::GetSkTypeface() { diff --git a/sample/MinikinSkia.h b/sample/MinikinSkia.h index 25ac1b0..e1d7bf6 100644 --- a/sample/MinikinSkia.h +++ b/sample/MinikinSkia.h @@ -12,8 +12,7 @@ public: void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - // If buf is NULL, just update size - bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); int32_t GetUniqueId() const; -- cgit v1.2.3