From 6c66d2f2b6525576524308c84eb952bb4bccf664 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 21 Mar 2013 20:34:27 +0000 Subject: [PATCH] remove GetTable* APIs from SkFontHost, and rely on SkTypeface::onGetTable* default impls call SkFontStream, and rely on SkTypeface::onOpenStream Review URL: https://codereview.chromium.org/13001002 git-svn-id: http://skia.googlecode.com/svn/trunk@8310 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gyp/ports.gyp | 4 --- include/core/SkFontHost.h | 37 ------------------- src/core/SkTypeface.cpp | 29 +++++++++++---- src/ports/SkFontHost_fontconfig.cpp | 26 +------------- src/ports/SkFontHost_mac.cpp | 25 ------------- src/ports/SkFontHost_tables.cpp | 56 ----------------------------- src/ports/SkHarfBuzzFont.cpp | 7 ++-- 7 files changed, 27 insertions(+), 157 deletions(-) delete mode 100644 src/ports/SkFontHost_tables.cpp diff --git a/gyp/ports.gyp b/gyp/ports.gyp index 83c6c5173c..49b278de21 100644 --- a/gyp/ports.gyp +++ b/gyp/ports.gyp @@ -30,7 +30,6 @@ '../src/ports/SkPurgeableMemoryBlock_none.cpp', '../src/ports/SkThread_win.cpp', - '../src/ports/SkFontHost_tables.cpp', '../src/ports/SkMemory_malloc.cpp', '../src/ports/SkOSFile_stdio.cpp', '../src/ports/SkTime_Unix.cpp', @@ -58,9 +57,6 @@ '../src/ports/SkFontConfigInterface_direct.cpp', '../src/ports/SkThread_pthread.cpp', ], - 'sources!': [ - '../src/ports/SkFontHost_tables.cpp', - ], }], [ 'skia_os == "nacl"', { 'dependencies': [ diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h index 30852f22f6..3939cc4d35 100644 --- a/include/core/SkFontHost.h +++ b/include/core/SkFontHost.h @@ -225,43 +225,6 @@ private: const uint32_t* glyphIDs, uint32_t glyphIDsCount); - /** Return the number of tables in the font - */ - static int CountTables(SkFontID); - - /** Copy into tags[] (allocated by the caller) the list of table tags in - the font, and return the number. This will be the same as CountTables() - or 0 if an error occured. - */ - static int GetTableTags(SkFontID, SkFontTableTag[]); - - /** Given a table tag, return the size of its contents, or 0 if not present - */ - static size_t GetTableSize(SkFontID, SkFontTableTag); - - /** Copy the contents of a table into data (allocated by the caller). Note - that the contents of the table will be in their native endian order - (which for most truetype tables is big endian). If the table tag is - not found, or there is an error copying the data, then 0 is returned. - If this happens, it is possible that some or all of the memory pointed - to by data may have been written to, even though an error has occured. - - @param fontID the font to copy the table from - @param tag The table tag whose contents are to be copied - @param offset The offset in bytes into the table's contents where the - copy should start from. - @param length The number of bytes, starting at offset, of table data - to copy. - @param data storage address where the table contents are copied to - @return the number of bytes actually copied into data. If offset+length - exceeds the table's size, then only the bytes up to the table's - size are actually copied, and this is the value returned. If - offset > the table's size, or tag is not a valid table, - then 0 is returned. - */ - static size_t GetTableData(SkFontID fontID, SkFontTableTag tag, - size_t offset, size_t length, void* data); - /////////////////////////////////////////////////////////////////////////// friend class SkTypeface; diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 4a3dd4fe11..5632bbc6d7 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -106,20 +106,20 @@ SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( /////////////////////////////////////////////////////////////////////////////// int SkTypeface::countTables() const { - return SkFontHost::CountTables(fUniqueID); + return this->onGetTableTags(NULL); } int SkTypeface::getTableTags(SkFontTableTag tags[]) const { - return SkFontHost::GetTableTags(fUniqueID, tags); + return this->onGetTableTags(tags); } size_t SkTypeface::getTableSize(SkFontTableTag tag) const { - return SkFontHost::GetTableSize(fUniqueID, tag); + return this->onGetTableData(tag, 0, ~0U, NULL); } size_t SkTypeface::getTableData(SkFontTableTag tag, size_t offset, size_t length, void* data) const { - return SkFontHost::GetTableData(fUniqueID, tag, offset, length, data); + return this->onGetTableData(tag, offset, length, data); } SkStream* SkTypeface::openStream(int* ttcIndex) const { @@ -164,10 +164,25 @@ SkStream* SkTypeface::onOpenStream(int* ttcIndex) const { return SkFontHost::OpenStream(fUniqueID); } -int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { return 0; } -size_t SkTypeface::onGetTableData(SkFontTableTag, size_t offset, - size_t length, void* data) const { return 0; } void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { desc->setStyle(this->style()); } +#include "SkFontStream.h" +#include "SkStream.h" + +int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { + int ttcIndex; + SkAutoTUnref stream(this->openStream(&ttcIndex)); + return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0; +} + +size_t SkTypeface::onGetTableData(SkFontTableTag tag, size_t offset, + size_t length, void* data) const { + int ttcIndex; + SkAutoTUnref stream(this->openStream(&ttcIndex)); + return stream.get() + ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data) + : 0; +} + diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index ea0971018a..8cdca1e584 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -175,31 +175,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { /////////////////////////////////////////////////////////////////////////////// -// DEPRECATED -int SkFontHost::CountTables(SkFontID fontID) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableTags(NULL) : 0; -} - -// DEPRECATED -int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableTags(tags) : 0; -} - -// DEPRECATED -size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableData(tag, 0, ~0U, NULL) : 0; -} - -// DEPRECATED -size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag, - size_t offset, size_t length, void* dst) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableData(tag, offset, length, dst) : 0; -} - // DEPRECATED SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) { // We don't handle font fallback. @@ -304,3 +279,4 @@ void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { desc->setStyle(this->style()); desc->setFamilyName(this->getFamilyName()); } + diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 9bc757cb9c..8f93c0e5d3 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -1728,31 +1728,6 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo return SkSafeRef(face); } -// DEPRECATED -int SkFontHost::CountTables(SkFontID fontID) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableTags(NULL) : 0; -} - -// DEPRECATED -int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableTags(tags) : 0; -} - -// DEPRECATED -size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableData(tag, 0, ~0U, NULL) : 0; -} - -// DEPRECATED -size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag, - size_t offset, size_t length, void* dst) { - SkTypeface* face = SkTypefaceCache::FindByID(fontID); - return face ? face->onGetTableData(tag, offset, length, dst) : 0; -} - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ports/SkFontHost_tables.cpp b/src/ports/SkFontHost_tables.cpp deleted file mode 100644 index 9ddf6c0db6..0000000000 --- a/src/ports/SkFontHost_tables.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkEndian.h" -#include "SkFontHost.h" -#include "SkFontStream.h" -#include "SkStream.h" - -int SkFontHost::CountTables(SkFontID fontID) { - SkStream* stream = SkFontHost::OpenStream(fontID); - if (NULL == stream) { - return 0; - } - - SkAutoUnref au(stream); - int ttcIndex = 0; - return SkFontStream::GetTableTags(stream, ttcIndex, NULL); -} - -int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) { - SkStream* stream = SkFontHost::OpenStream(fontID); - if (NULL == stream) { - return 0; - } - - SkAutoUnref au(stream); - int ttcIndex = 0; - return SkFontStream::GetTableTags(stream, ttcIndex, tags); -} - -size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) { - SkStream* stream = SkFontHost::OpenStream(fontID); - if (NULL == stream) { - return 0; - } - - SkAutoUnref au(stream); - int ttcIndex = 0; - return SkFontStream::GetTableData(stream, ttcIndex, tag, 0, ~0U, NULL); -} - -size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag, - size_t offset, size_t length, void* data) { - SkStream* stream = SkFontHost::OpenStream(fontID); - if (NULL == stream) { - return 0; - } - - SkAutoUnref au(stream); - int ttcIndex = 0; - return SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data); -} diff --git a/src/ports/SkHarfBuzzFont.cpp b/src/ports/SkHarfBuzzFont.cpp index b5cd0f7f9e..4e6f48da0d 100644 --- a/src/ports/SkHarfBuzzFont.cpp +++ b/src/ports/SkHarfBuzzFont.cpp @@ -166,9 +166,9 @@ const HB_FontClass& SkHarfBuzzFont::GetFontClass() { HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag, HB_Byte* buffer, HB_UInt* len) { SkHarfBuzzFont* font = reinterpret_cast(voidface); - uint32_t uniqueID = SkTypeface::UniqueID(font->getTypeface()); + SkTypeface* typeface = font->getTypeface(); - const size_t tableSize = SkFontHost::GetTableSize(uniqueID, tag); + const size_t tableSize = typeface->getTableSize(tag); if (!tableSize) { return HB_Err_Invalid_Argument; } @@ -182,6 +182,7 @@ HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag, // is this right, or should we just copy less than the full table? return HB_Err_Invalid_Argument; } - SkFontHost::GetTableData(uniqueID, tag, 0, tableSize, buffer); + typeface->getTableData(tag, 0, tableSize, buffer); return HB_Err_Ok; } +