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

Side by Side Diff: src/ports/SkFontHost_win_dw.cpp

Issue 22859070: Implement charToGlyph on remaining ports. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Tabs and line length. Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTypes.h" 8 #include "SkTypes.h"
9 #undef GetGlyphIndices 9 #undef GetGlyphIndices
10 10
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 559 }
560 560
561 protected: 561 protected:
562 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; 562 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
563 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; 563 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
564 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 564 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
565 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 565 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
566 SkAdvancedTypefaceMetrics::PerGlyphInfo, 566 SkAdvancedTypefaceMetrics::PerGlyphInfo,
567 const uint32_t*, uint32_t) const SK_OVERRIDE; 567 const uint32_t*, uint32_t) const SK_OVERRIDE;
568 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ; 568 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
569 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
570 uint16_t glyphs[], int glyphCount) const SK_OVER RIDE;
569 virtual int onCountGlyphs() const SK_OVERRIDE; 571 virtual int onCountGlyphs() const SK_OVERRIDE;
570 virtual int onGetUPEM() const SK_OVERRIDE; 572 virtual int onGetUPEM() const SK_OVERRIDE;
571 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE; 573 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE;
572 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; 574 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
573 virtual size_t onGetTableData(SkFontTableTag, size_t offset, 575 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
574 size_t length, void* data) const SK_OVERRIDE; 576 size_t length, void* data) const SK_OVERRIDE;
575 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; 577 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE;
576 }; 578 };
577 579
578 class SkScalerContext_DW : public SkScalerContext { 580 class SkScalerContext_DW : public SkScalerContext {
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 SkSMallocWCHAR dwFamilyNameChar(dwFamilyNamesLength+1); 1126 SkSMallocWCHAR dwFamilyNameChar(dwFamilyNamesLength+1);
1125 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.get(), dwFamilyNamesLength+ 1)); 1127 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.get(), dwFamilyNamesLength+ 1));
1126 1128
1127 SkString utf8FamilyName; 1129 SkString utf8FamilyName;
1128 HRV(wchar_to_skstring(dwFamilyNameChar.get(), &utf8FamilyName)); 1130 HRV(wchar_to_skstring(dwFamilyNameChar.get(), &utf8FamilyName));
1129 1131
1130 desc->setFamilyName(utf8FamilyName.c_str()); 1132 desc->setFamilyName(utf8FamilyName.c_str());
1131 *isLocalStream = SkToBool(fDWriteFontFileLoader.get()); 1133 *isLocalStream = SkToBool(fDWriteFontFileLoader.get());
1132 } 1134 }
1133 1135
1136 static SkUnichar next_utf8(const void** chars) {
1137 return SkUTF8_NextUnichar((const char**)chars);
1138 }
1139
1140 static SkUnichar next_utf16(const void** chars) {
1141 return SkUTF16_NextUnichar((const uint16_t**)chars);
1142 }
1143
1144 static SkUnichar next_utf32(const void** chars) {
1145 const SkUnichar** uniChars = (const SkUnichar**)chars;
1146 SkUnichar uni = **uniChars;
1147 *uniChars += 1;
1148 return uni;
1149 }
1150
1151 typedef SkUnichar (*EncodingProc)(const void**);
1152
1153 static EncodingProc find_encoding_proc(SkTypeface::Encoding enc) {
1154 static const EncodingProc gProcs[] = {
1155 next_utf8, next_utf16, next_utf32
1156 };
1157 SkASSERT((size_t)enc < SK_ARRAY_COUNT(gProcs));
1158 return gProcs[enc];
1159 }
1160
1161 int DWriteFontTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
1162 uint16_t glyphs[], int glyphCount) const
1163 {
1164 if (NULL == glyphs) {
1165 EncodingProc next_ucs4_proc = find_encoding_proc(encoding);
1166 for (int i = 0; i < glyphCount; ++i) {
1167 const SkUnichar c = next_ucs4_proc(&chars);
1168 BOOL exists;
1169 fDWriteFont->HasCharacter(c, &exists);
1170 if (!exists) {
1171 return i;
1172 }
1173 }
1174 return glyphCount;
1175 }
1176
1177 switch (encoding) {
1178 case SkTypeface::kUTF8_Encoding:
1179 case SkTypeface::kUTF16_Encoding: {
1180 static const int scratchCount = 256;
1181 UINT32 scratch[scratchCount];
1182 EncodingProc next_ucs4_proc = find_encoding_proc(encoding);
1183 for (int baseGlyph = 0; baseGlyph < glyphCount; baseGlyph += scratchCoun t) {
1184 int glyphsLeft = glyphCount - baseGlyph;
1185 int limit = SkTMin(glyphsLeft, scratchCount);
1186 for (int i = 0; i < limit; ++i) {
1187 scratch[i] = next_ucs4_proc(&chars);
1188 }
1189 fDWriteFontFace->GetGlyphIndices(scratch, limit, &glyphs[baseGlyph]) ;
1190 }
1191 break;
1192 }
1193 case SkTypeface::kUTF32_Encoding:
1194 const UINT32* utf32 = reinterpret_cast<const UINT32*>(chars);
1195 fDWriteFontFace->GetGlyphIndices(utf32, glyphCount, glyphs);
1196 break;
1197 default:
1198 SK_CRASH();
1199 }
1200
1201 for (int i = 0; i < glyphCount; ++i) {
1202 if (0 == glyphs[i]) {
1203 return i;
1204 }
1205 }
1206 return glyphCount;
1207 }
1208
1134 int DWriteFontTypeface::onCountGlyphs() const { 1209 int DWriteFontTypeface::onCountGlyphs() const {
1135 return fDWriteFontFace->GetGlyphCount(); 1210 return fDWriteFontFace->GetGlyphCount();
1136 } 1211 }
1137 1212
1138 int DWriteFontTypeface::onGetUPEM() const { 1213 int DWriteFontTypeface::onGetUPEM() const {
1139 DWRITE_FONT_METRICS metrics; 1214 DWRITE_FONT_METRICS metrics;
1140 fDWriteFontFace->GetMetrics(&metrics); 1215 fDWriteFontFace->GetMetrics(&metrics);
1141 return metrics.designUnitsPerEm; 1216 return metrics.designUnitsPerEm;
1142 } 1217 }
1143 1218
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); 2005 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName.");
1931 } else { 2006 } else {
1932 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); 2007 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH);
1933 if (localeNameLen) { 2008 if (localeNameLen) {
1934 localeName = localeNameStorage; 2009 localeName = localeNameStorage;
1935 }; 2010 };
1936 } 2011 }
1937 2012
1938 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); 2013 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen));
1939 } 2014 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698