diff options
author | 2010-04-20 22:06:40 +0000 | |
---|---|---|
committer | 2010-04-20 22:06:40 +0000 | |
commit | 5f6a0762f14f73859e60f0e8339ca133d10e4d3c (patch) | |
tree | ea04605d6b956e3f1b591c754a74148ef1c68294 | |
parent | 756f6dd82da298375547cb36955be9ac8574d2dc (diff) |
Add a SkTypeface::CreateForChars() function.
This allows us to do font fallback for strange scripts.
Added empty stubs to the implementations on all platforms.
Patch-by: Evan Martin
Signed-off-by: Adam Langley
http://codereview.appspot.com/950041
git-svn-id: http://skia.googlecode.com/svn/trunk@557 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkFontHost.h | 14 | ||||
-rw-r--r-- | include/core/SkTypeface.h | 12 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 14 | ||||
-rw-r--r-- | src/ports/SkFontHost_FONTPATH.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_android.cpp | 3 | ||||
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_linux.cpp | 5 | ||||
-rwxr-xr-x | src/ports/SkFontHost_mac.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontHost_none.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_simple.cpp | 3 | ||||
-rw-r--r-- | src/ports/SkFontHost_win.cpp | 1 |
11 files changed, 44 insertions, 15 deletions
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h index ec345839ad..ca538d16c1 100644 --- a/include/core/SkFontHost.h +++ b/include/core/SkFontHost.h @@ -59,14 +59,16 @@ typedef uint32_t SkFontTableTag; class SkFontHost { public: /** Return a new, closest matching typeface given either an existing family - (specified by a typeface in that family) or by a familyName, and a - requested style. - 1) If familyFace is null, use famillyName. - 2) If famillyName is null, use familyFace. - 3) If both are null, return the default font that best matches style + (specified by a typeface in that family) or by a familyName and a + requested style, or by a set of Unicode codepoitns to cover in a given + style. + 1) If familyFace is null, use familyName. + 2) If familyName is null, use data (UTF-16 to cover). + 3) If all are null, return the default font that best matches style */ static SkTypeface* CreateTypeface(const SkTypeface* familyFace, - const char famillyName[], + const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style); /** Return a new typeface given the data buffer. If the data does not diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index bf783a3ff7..d4af700b34 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -83,6 +83,18 @@ public: */ static SkTypeface* CreateFromName(const char familyName[], Style style); + /** Return a new reference to the typeface that covers a set of Unicode + code points with the specified Style. Use this call if you want to + pick any font that covers a given string of text. + + @param data UTF-16 characters + @param bytelength length of data, in bytes + @return reference to the closest-matching typeface. Call must call + unref() when they are done. + */ + static SkTypeface* CreateForChars(const void* data, size_t bytelength, + Style s); + /** Return a new reference to the typeface that most closely matches the requested typeface and specified Style. Use this call if you want to pick a new style from the same family of the existing typeface. diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 65052c1cec..44337610c8 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -12,8 +12,9 @@ uint32_t SkTypeface::UniqueID(const SkTypeface* face) { static uint32_t gDefaultFontID; if (0 == gDefaultFontID) { - SkTypeface* defaultFace = SkFontHost::CreateTypeface(NULL, NULL, - SkTypeface::kNormal); + SkTypeface* defaultFace = + SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, + SkTypeface::kNormal); SkASSERT(defaultFace); gDefaultFontID = defaultFace->uniqueID(); defaultFace->unref(); @@ -28,11 +29,16 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { /////////////////////////////////////////////////////////////////////////////// SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { - return SkFontHost::CreateTypeface(NULL, name, style); + return SkFontHost::CreateTypeface(NULL, name, NULL, 0, style); +} + +SkTypeface* SkTypeface::CreateForChars(const void* data, size_t bytelength, + Style s) { + return SkFontHost::CreateTypeface(NULL, NULL, data, bytelength, s); } SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { - return SkFontHost::CreateTypeface(family, NULL, s); + return SkFontHost::CreateTypeface(family, NULL, NULL, NULL, s); } SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { diff --git a/src/ports/SkFontHost_FONTPATH.cpp b/src/ports/SkFontHost_FONTPATH.cpp index 211ed90f66..308adf8070 100644 --- a/src/ports/SkFontHost_FONTPATH.cpp +++ b/src/ports/SkFontHost_FONTPATH.cpp @@ -241,6 +241,7 @@ static uint32_t ptr2uint32(const void* p) SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { const FontFamilyRec* family; diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index f50e35952c..3eb755d468 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -542,7 +542,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { for (int j = i; j >= 0; --j) { if (rec[j].fNames != NULL) { return SkFontHost::CreateTypeface(NULL, - rec[j].fNames[0], (SkTypeface::Style)style); + rec[j].fNames[0], NULL, 0, (SkTypeface::Style)style); } } } @@ -555,6 +555,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { load_system_fonts(); diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index 83a75ce74d..d1da8d1589 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -219,6 +219,7 @@ static unsigned FileIdFromFilename(const char* filename) // static SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { const char* resolved_family_name = NULL; diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp index c838d8ca85..ebebd08bda 100644 --- a/src/ports/SkFontHost_linux.cpp +++ b/src/ports/SkFontHost_linux.cpp @@ -509,14 +509,14 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { // backup until we hit the fNames for (int j = i; j >= 0; --j) { if (rec[j].fNames != NULL) { - return SkFontHost::CreateTypeface(NULL, rec[j].fNames[0], + return SkFontHost::CreateTypeface(NULL, rec[j].fNames[0], NULL, 0, (SkTypeface::Style)style); } } } } } - return SkFontHost::CreateTypeface(NULL, NULL, (SkTypeface::Style)style); + return SkFontHost::CreateTypeface(NULL, NULL, NULL, 0, (SkTypeface::Style)style); #endif sk_throw(); return NULL; @@ -526,6 +526,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { load_system_fonts(); diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index a652d9d3d1..a0239e224c 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -492,7 +492,9 @@ uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) { } SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, - const char familyName[], SkTypeface::Style style) { + const char familyName[], + const void* data, size_t bytelength, + SkTypeface::Style style) { // todo: we don't know how to respect style bits if (NULL == familyName && NULL != familyFace) { familyFace->ref(); diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp index 9132c74e61..ae56ae4e14 100644 --- a/src/ports/SkFontHost_none.cpp +++ b/src/ports/SkFontHost_none.cpp @@ -17,6 +17,7 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char famillyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { SkASSERT(!"SkFontHost::FindTypeface unimplemented"); return NULL; diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp index deda04d090..9e126bccf8 100644 --- a/src/ports/SkFontHost_simple.cpp +++ b/src/ports/SkFontHost_simple.cpp @@ -507,7 +507,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { for (int j = i; j >= 0; --j) { if (rec[j].fNames != NULL) { return SkFontHost::CreateTypeface(NULL, - rec[j].fNames[0], (SkTypeface::Style)style); + rec[j].fNames[0], NULL, 0, (SkTypeface::Style)style); } } } @@ -520,6 +520,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], + const void* data, size_t bytelength, SkTypeface::Style style) { load_system_fonts(); diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 4533d3c0e4..f9ed7ad67c 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -540,6 +540,7 @@ SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) { SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const char familyName[],
+ const void* data, size_t bytelength,
SkTypeface::Style style) {
SkAutoMutexAcquire ac(gFTMutex);
|