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
This commit is contained in:
reed@google.com 2013-03-21 20:34:27 +00:00
parent b58a639b2f
commit 6c66d2f2b6
7 changed files with 27 additions and 157 deletions

View File

@ -30,7 +30,6 @@
'../src/ports/SkPurgeableMemoryBlock_none.cpp', '../src/ports/SkPurgeableMemoryBlock_none.cpp',
'../src/ports/SkThread_win.cpp', '../src/ports/SkThread_win.cpp',
'../src/ports/SkFontHost_tables.cpp',
'../src/ports/SkMemory_malloc.cpp', '../src/ports/SkMemory_malloc.cpp',
'../src/ports/SkOSFile_stdio.cpp', '../src/ports/SkOSFile_stdio.cpp',
'../src/ports/SkTime_Unix.cpp', '../src/ports/SkTime_Unix.cpp',
@ -58,9 +57,6 @@
'../src/ports/SkFontConfigInterface_direct.cpp', '../src/ports/SkFontConfigInterface_direct.cpp',
'../src/ports/SkThread_pthread.cpp', '../src/ports/SkThread_pthread.cpp',
], ],
'sources!': [
'../src/ports/SkFontHost_tables.cpp',
],
}], }],
[ 'skia_os == "nacl"', { [ 'skia_os == "nacl"', {
'dependencies': [ 'dependencies': [

View File

@ -225,43 +225,6 @@ private:
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount); 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; friend class SkTypeface;

View File

@ -106,20 +106,20 @@ SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int SkTypeface::countTables() const { int SkTypeface::countTables() const {
return SkFontHost::CountTables(fUniqueID); return this->onGetTableTags(NULL);
} }
int SkTypeface::getTableTags(SkFontTableTag tags[]) const { int SkTypeface::getTableTags(SkFontTableTag tags[]) const {
return SkFontHost::GetTableTags(fUniqueID, tags); return this->onGetTableTags(tags);
} }
size_t SkTypeface::getTableSize(SkFontTableTag tag) const { 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, size_t SkTypeface::getTableData(SkFontTableTag tag, size_t offset, size_t length,
void* data) const { void* data) const {
return SkFontHost::GetTableData(fUniqueID, tag, offset, length, data); return this->onGetTableData(tag, offset, length, data);
} }
SkStream* SkTypeface::openStream(int* ttcIndex) const { SkStream* SkTypeface::openStream(int* ttcIndex) const {
@ -164,10 +164,25 @@ SkStream* SkTypeface::onOpenStream(int* ttcIndex) const {
return SkFontHost::OpenStream(fUniqueID); 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 { void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
desc->setStyle(this->style()); desc->setStyle(this->style());
} }
#include "SkFontStream.h"
#include "SkStream.h"
int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const {
int ttcIndex;
SkAutoTUnref<SkStream> 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<SkStream> stream(this->openStream(&ttcIndex));
return stream.get()
? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data)
: 0;
}

View File

@ -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 // DEPRECATED
SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) { SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) {
// We don't handle font fallback. // We don't handle font fallback.
@ -304,3 +279,4 @@ void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
desc->setStyle(this->style()); desc->setStyle(this->style());
desc->setFamilyName(this->getFamilyName()); desc->setFamilyName(this->getFamilyName());
} }

View File

@ -1728,31 +1728,6 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
return SkSafeRef(face); 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;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -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);
}

View File

@ -166,9 +166,9 @@ const HB_FontClass& SkHarfBuzzFont::GetFontClass() {
HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag, HB_Error SkHarfBuzzFont::GetFontTableFunc(void* voidface, const HB_Tag tag,
HB_Byte* buffer, HB_UInt* len) { HB_Byte* buffer, HB_UInt* len) {
SkHarfBuzzFont* font = reinterpret_cast<SkHarfBuzzFont*>(voidface); SkHarfBuzzFont* font = reinterpret_cast<SkHarfBuzzFont*>(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) { if (!tableSize) {
return HB_Err_Invalid_Argument; 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? // is this right, or should we just copy less than the full table?
return HB_Err_Invalid_Argument; return HB_Err_Invalid_Argument;
} }
SkFontHost::GetTableData(uniqueID, tag, 0, tableSize, buffer); typeface->getTableData(tag, 0, tableSize, buffer);
return HB_Err_Ok; return HB_Err_Ok;
} }