diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 18:03:51 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 18:03:51 +0000 |
commit | 1c0d89daeb89cb344f5852720ff4ea6edad8aad3 (patch) | |
tree | 14451754940535e9d86a0f60e374a4760176a143 /skia/ext/SkFontHost_fontconfig.cpp | |
parent | 897bd8cbf71370ec7a57446bc27e858336682632 (diff) | |
download | chromium_src-1c0d89daeb89cb344f5852720ff4ea6edad8aad3.zip chromium_src-1c0d89daeb89cb344f5852720ff4ea6edad8aad3.tar.gz chromium_src-1c0d89daeb89cb344f5852720ff4ea6edad8aad3.tar.bz2 |
Make SkFontHost_fontconfig support TTC font files.
In addition to this change, third_party/skia/src/port/SkFontHost_Freetype.cpp
needs a couple of lines changed.
The Skia part is at http://codereview.appspot.com/1847046/show
BUG=50389
TEST=Install ttf-wqy-microhei package on Ubuntu and go to http://i18nl10n.com/chrome/ttc2.html. Latin letters in the 1st line should be monospaced while they're proportional in the second line.
Review URL: http://codereview.chromium.org/2870073
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/SkFontHost_fontconfig.cpp')
-rw-r--r-- | skia/ext/SkFontHost_fontconfig.cpp | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/skia/ext/SkFontHost_fontconfig.cpp b/skia/ext/SkFontHost_fontconfig.cpp index 97d300b..68a3820 100644 --- a/skia/ext/SkFontHost_fontconfig.cpp +++ b/skia/ext/SkFontHost_fontconfig.cpp @@ -67,9 +67,11 @@ static unsigned global_next_remote_font_id; // This is the maximum size of the font cache. static const unsigned kFontCacheMemoryBudget = 2 * 1024 * 1024; // 2MB -// UniqueIds are encoded as (fileid << 8) | style +// UniqueIds are encoded as (filefaceid << 8) | style +// For system fonts, filefaceid = (fileid << 4) | face_index. +// For remote fonts, filefaceid = fileid. -static unsigned UniqueIdToFileId(unsigned uniqueid) +static unsigned UniqueIdToFileFaceId(unsigned uniqueid) { return uniqueid >> 8; } @@ -79,18 +81,18 @@ static SkTypeface::Style UniqueIdToStyle(unsigned uniqueid) return static_cast<SkTypeface::Style>(uniqueid & 0xff); } -static unsigned FileIdAndStyleToUniqueId(unsigned fileid, - SkTypeface::Style style) +static unsigned FileFaceIdAndStyleToUniqueId(unsigned filefaceid, + SkTypeface::Style style) { SkASSERT((style & 0xff) == style); - return (fileid << 8) | static_cast<int>(style); + return (filefaceid << 8) | static_cast<int>(style); } static const unsigned kRemoteFontMask = 0x00800000u; -static bool IsRemoteFont(unsigned fileid) +static bool IsRemoteFont(unsigned filefaceid) { - return fileid & kRemoteFontMask; + return filefaceid & kRemoteFontMask; } class FontConfigTypeface : public SkTypeface { @@ -102,7 +104,7 @@ public: ~FontConfigTypeface() { const uint32_t id = uniqueID(); - if (IsRemoteFont(UniqueIdToFileId(id))) { + if (IsRemoteFont(UniqueIdToFileFaceId(id))) { SkAutoMutexAcquire ac(global_remote_font_map_lock); std::map<uint32_t, std::pair<uint8_t*, size_t> >::iterator iter = global_remote_fonts.find(id); @@ -125,9 +127,9 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, if (familyFace) { // Given the fileid we can ask fontconfig for the familyname of the // font. - const unsigned fileid = UniqueIdToFileId(familyFace->uniqueID()); - if (!GetFcImpl()->Match( - &resolved_family_name, NULL, true /* fileid valid */, fileid, "", + const unsigned filefaceid = UniqueIdToFileFaceId(familyFace->uniqueID()); + if (!GetFcImpl()->Match(&resolved_family_name, NULL, + true /* filefaceid valid */, filefaceid, "", NULL, 0, NULL, NULL)) { return NULL; } @@ -137,8 +139,9 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, bool bold = style & SkTypeface::kBold; bool italic = style & SkTypeface::kItalic; - unsigned fileid; - if (!GetFcImpl()->Match(NULL, &fileid, false, -1, /* no fileid */ + unsigned filefaceid; + if (!GetFcImpl()->Match(NULL, &filefaceid, + false, -1, /* no filefaceid */ resolved_family_name, data, bytelength, &bold, &italic)) { return NULL; @@ -147,7 +150,8 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, (bold ? SkTypeface::kBold : 0) | (italic ? SkTypeface::kItalic : 0)); - const unsigned id = FileIdAndStyleToUniqueId(fileid, resulting_style); + const unsigned id = FileFaceIdAndStyleToUniqueId(filefaceid, + resulting_style); SkTypeface* typeface = SkNEW_ARGS(FontConfigTypeface, (resulting_style, id)); { @@ -180,7 +184,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) unsigned id = 0; { SkAutoMutexAcquire ac(global_remote_font_map_lock); - id = FileIdAndStyleToUniqueId( + id = FileFaceIdAndStyleToUniqueId( global_next_remote_font_id | kRemoteFontMask, style); if (++global_next_remote_font_id >= kRemoteFontMask) @@ -206,7 +210,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) // static bool SkFontHost::ValidFontID(SkFontID uniqueID) { - if (IsRemoteFont(UniqueIdToFileId(uniqueID))) { + if (IsRemoteFont(UniqueIdToFileFaceId(uniqueID))) { // remote font SkAutoMutexAcquire ac(global_remote_font_map_lock); return global_remote_fonts.find(uniqueID) != global_remote_fonts.end(); @@ -301,9 +305,9 @@ class SkFileDescriptorStream : public SkStream { // static SkStream* SkFontHost::OpenStream(uint32_t id) { - const unsigned fileid = UniqueIdToFileId(id); + const unsigned filefaceid = UniqueIdToFileFaceId(id); - if (IsRemoteFont(fileid)) { + if (IsRemoteFont(filefaceid)) { // remote font SkAutoMutexAcquire ac(global_remote_font_map_lock); std::map<uint32_t, std::pair<uint8_t*, size_t> >::const_iterator iter @@ -315,7 +319,7 @@ SkStream* SkFontHost::OpenStream(uint32_t id) } // system font - const int fd = GetFcImpl()->Open(fileid); + const int fd = GetFcImpl()->Open(filefaceid); if (fd < 0) return NULL; @@ -329,3 +333,28 @@ size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) else return 0; // nothing to do } + +// static +size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, + int32_t* index) { + const unsigned filefaceid = UniqueIdToFileFaceId(fontID); + + if (IsRemoteFont(filefaceid)) + return 0; + + if (index) { + *index = filefaceid & 0xfu; + // 1 is a bogus return value. + // We had better change the signature of this function in Skia + // to return bool to indicate success/failure and have another + // out param for fileName length. + if (!path) + return 1; + } + + if (path) + SkASSERT(!"SkFontHost::GetFileName does not support the font path " + "retrieval."); + + return 0; +} |