Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 18083023: add charsToGlyphs to SkTypeface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | tests/PaintTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index ac01e5ba844baf640f58d5bd6b410203c5382476..ef51aef018a9b650aed4f27cee2c7e074c6913ed 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -42,6 +42,7 @@
#include "SkUtils.h"
#include "SkTypefaceCache.h"
#include "SkFontMgr.h"
+#include "SkUtils.h"
//#define HACK_COLORGLYPHS
@@ -461,6 +462,9 @@ protected:
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo,
const uint32_t*, uint32_t) const SK_OVERRIDE;
+ virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
+ int glyphCount) const SK_OVERRIDE;
+ virtual int onCountGlyphs() const SK_OVERRIDE;
private:
@@ -1900,6 +1904,61 @@ void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc,
*isLocalStream = false;
}
+int SkTypeface_Mac::onCharsToGlyphs(const void* chars, Encoding encoding,
+ uint16_t glyphs[], int glyphCount) const {
+ // UniChar is utf16
+ SkAutoSTMalloc<1024, UniChar> charStorage;
+ const UniChar* src;
+ switch (encoding) {
+ case kUTF8_Encoding: {
+ const char* u8 = (const char*)chars;
+ const UniChar* u16 = src = charStorage.reset(2 * glyphCount);
+ for (int i = 0; i < glyphCount; ++i) {
+ SkUnichar uni = SkUTF8_NextUnichar(&u8);
+ int n = SkUTF16_FromUnichar(uni, (uint16_t*)u16);
+ u16 += n;
+ }
+ break;
+ }
+ case kUTF16_Encoding:
+ src = (const UniChar*)chars;
+ break;
+ case kUTF32_Encoding: {
+ const SkUnichar* u32 = (const SkUnichar*)chars;
+ const UniChar* u16 = src = charStorage.reset(2 * glyphCount);
+ for (int i = 0; i < glyphCount; ++i) {
+ int n = SkUTF16_FromUnichar(u32[i], (uint16_t*)u16);
+ u16 += n;
+ }
+ break;
+ }
+ }
+
+ // Our caller may not want glyphs for output, but we need to give that
+ // storage to CT, so we can walk it looking for the first non-zero.
+ SkAutoSTMalloc<1024, uint16_t> glyphStorage;
+ uint16_t* macGlyphs = glyphs;
+ if (NULL == macGlyphs) {
+ macGlyphs = glyphStorage.reset(glyphCount);
+ }
+
+ if (CTFontGetGlyphsForCharacters(fFontRef, src, macGlyphs, glyphCount)) {
+ return glyphCount;
+ }
+ // If we got false, then we need to manually look for first failure
+ for (int i = 0; i < glyphCount; ++i) {
+ if (0 == macGlyphs[i]) {
+ return i;
+ }
+ }
+ // odd to get here, as we expected CT to have returned true up front.
+ return glyphCount;
+}
+
+int SkTypeface_Mac::onCountGlyphs() const {
+ return CTFontGetGlyphCount(fFontRef);
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#if 1
« no previous file with comments | « src/core/SkTypeface.cpp ('k') | tests/PaintTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698