diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-07-31 16:17:01 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-07-31 16:17:01 +0000 |
commit | ac98154faa0e786444bafcd093fd4842127fbf18 (patch) | |
tree | c45d07e7b62d121cd187a8635a16a8fa683eb946 /src | |
parent | 61608aaf932708e3e8ac05097ead1bf7885ec87d (diff) |
add GetFileName api to SkFontHost
git-svn-id: http://skia.googlecode.com/svn/trunk@299 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontHost_FONTPATH.cpp | 6 | ||||
-rw-r--r-- | src/ports/SkFontHost_android.cpp | 26 | ||||
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 21 | ||||
-rw-r--r-- | src/ports/SkFontHost_linux.cpp | 6 | ||||
-rw-r--r-- | src/ports/SkFontHost_none.cpp | 6 |
5 files changed, 65 insertions, 0 deletions
diff --git a/src/ports/SkFontHost_FONTPATH.cpp b/src/ports/SkFontHost_FONTPATH.cpp index ceab395315..211ed90f66 100644 --- a/src/ports/SkFontHost_FONTPATH.cpp +++ b/src/ports/SkFontHost_FONTPATH.cpp @@ -287,6 +287,12 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) { return NULL; } +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + SkDebugf("SkFontHost::GetFileName unimplemented\n"); + return 0; +} + void SkFontHost::Serialize(const SkTypeface* tface, SkWStream* stream) { const FontFaceRec* face = &((const FontFaceRec_Typeface*)tface)->fFace; stream->write(face, sizeof(face)); diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index e6d134a583..6aa7a0b41f 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -267,6 +267,7 @@ public: virtual SkStream* openStream() = 0; virtual const char* getUniqueString() const = 0; + virtual const char* getFilePath() const = 0; private: bool fIsSysFont; @@ -297,6 +298,7 @@ public: return fStream; } virtual const char* getUniqueString() const { return NULL; } + virtual const char* getFilePath() const { return NULL; } private: SkStream* fStream; @@ -341,6 +343,9 @@ public: } return str; } + virtual const char* getFilePath() const { + return fPath.c_str(); + } private: SkString fPath; @@ -592,6 +597,27 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) { return stream; } +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + SkAutoMutexAcquire ac(gFamilyMutex); + + FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID); + const char* src = tf ? tf->getFilePath() : NULL; + + if (src) { + size_t size = strlen(src); + if (path) { + memcpy(path, src, SkMin32(size, length)); + } + if (index) { + *index = 0; // we don't have collections (yet) + } + return size; + } else { + return 0; + } +} + uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) { load_system_fonts(); diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index bf94366f5f..83a75ce74d 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -333,6 +333,27 @@ SkStream* SkFontHost::OpenStream(uint32_t id) return SkNEW_ARGS(SkFILEStream, (i->second.c_str())); } +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + SkAutoMutexAcquire ac(global_fc_map_lock); + const unsigned fileid = UniqueIdToFileId(id); + + std::map<unsigned, std::string>::const_iterator i = + global_fc_map_inverted.find(fileid); + if (i == global_fc_map_inverted.end()) { + return 0; + } + + const std::string& str = i->second; + if (path) { + memcpy(path, str.c_str(), SkMin32(str.size(), length)); + } + if (index) { // TODO: check if we're in a TTC + *index = 0; + } + return str.size(); +} + void SkFontHost::Serialize(const SkTypeface*, SkWStream*) { SkASSERT(!"SkFontHost::Serialize unimplemented"); } diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp index 743daa5bf2..8627106023 100644 --- a/src/ports/SkFontHost_linux.cpp +++ b/src/ports/SkFontHost_linux.cpp @@ -539,6 +539,12 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) { return stream; } +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + SkDebugf("SkFontHost::GetFileName unimplemented\n"); + return 0; +} + void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream) { FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID); if (NULL != tf) { diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp index 471ffd825f..2b88695289 100644 --- a/src/ports/SkFontHost_none.cpp +++ b/src/ports/SkFontHost_none.cpp @@ -44,6 +44,12 @@ SkStream* SkFontHost::OpenStream(uint32_t uniqueID) { return NULL; } +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + SkDebugf("SkFontHost::GetFileName unimplemented\n"); + return 0; +} + /////////////////////////////////////////////////////////////////////////////// void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { |