Update minikin/sample code to use new GetTable

am: d2161cf

* commit 'd2161cf80f6f23bb977d92f79e49fba999846c79':
  Update minikin/sample code to use new GetTable

Change-Id: I5fcae79c42322dcc0533dbd3eb1a51007e089170
This commit is contained in:
Raph Levien
2016-04-08 17:55:14 +00:00
committed by android-build-merger
2 changed files with 14 additions and 11 deletions

View File

@@ -47,16 +47,20 @@ void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id,
bounds->mBottom = skBounds.fBottom; bounds->mBottom = skBounds.fBottom;
} }
bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) {
if (buf == NULL) { // we don't have a buffer to the font data, copy to own buffer
const size_t tableSize = mTypeface->getTableSize(tag); const size_t tableSize = mTypeface->getTableSize(tag);
*size = tableSize; *size = tableSize;
return tableSize != 0; if (tableSize == 0) {
} else { return nullptr;
const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf);
*size = actualSize;
return actualSize != 0;
} }
void* buf = malloc(tableSize);
if (buf == nullptr) {
return nullptr;
}
mTypeface->getTableData(tag, 0, tableSize, buf);
*destroy = free;
return buf;
} }
SkTypeface *MinikinFontSkia::GetSkTypeface() { SkTypeface *MinikinFontSkia::GetSkTypeface() {

View File

@@ -12,8 +12,7 @@ public:
void GetBounds(MinikinRect* bounds, uint32_t glyph_id, void GetBounds(MinikinRect* bounds, uint32_t glyph_id,
const MinikinPaint& paint) const; const MinikinPaint& paint) const;
// If buf is NULL, just update size const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy);
bool GetTable(uint32_t tag, uint8_t *buf, size_t *size);
int32_t GetUniqueId() const; int32_t GetUniqueId() const;