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

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

Issue 12676024: Force all font backends to override onGetFontDescriptor, so we can (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); 478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get()));
479 } 479 }
480 480
481 protected: 481 protected:
482 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; 482 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
483 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; 483 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
484 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 484 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
485 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 485 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
486 SkAdvancedTypefaceMetrics::PerGlyphInfo, 486 SkAdvancedTypefaceMetrics::PerGlyphInfo,
487 const uint32_t*, uint32_t) const SK_OVERRIDE; 487 const uint32_t*, uint32_t) const SK_OVERRIDE;
488 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
488 }; 489 };
489 490
490 class SkScalerContext_Windows : public SkScalerContext { 491 class SkScalerContext_Windows : public SkScalerContext {
491 public: 492 public:
492 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc); 493 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc);
493 virtual ~SkScalerContext_Windows(); 494 virtual ~SkScalerContext_Windows();
494 495
495 protected: 496 protected:
496 virtual unsigned generateGlyphCount() SK_OVERRIDE; 497 virtual unsigned generateGlyphCount() SK_OVERRIDE;
497 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 498 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE;
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 FALSE, //sideways 1040 FALSE, //sideways
1040 FALSE, //rtl 1041 FALSE, //rtl
1041 geometryToPath.get()), 1042 geometryToPath.get()),
1042 "Could not create glyph outline."); 1043 "Could not create glyph outline.");
1043 1044
1044 SkMatrix mat; 1045 SkMatrix mat;
1045 fRec.getMatrixFrom2x2(&mat); 1046 fRec.getMatrixFrom2x2(&mat);
1046 path->transform(mat); 1047 path->transform(mat);
1047 } 1048 }
1048 1049
1049 void SkFontHost::Serialize(const SkTypeface* rawFace, SkWStream* stream) { 1050 void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
1050 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>(rawF ace); 1051 bool* isLocalStream) const {
1051 SkFontDescriptor descriptor(face->style());
1052
1053 // Get the family name. 1052 // Get the family name.
1054 SkTScopedComPtr<IDWriteLocalizedStrings> dwFamilyNames; 1053 SkTScopedComPtr<IDWriteLocalizedStrings> dwFamilyNames;
1055 HRV(face->fDWriteFontFamily->GetFamilyNames(&dwFamilyNames)); 1054 HRV(fDWriteFontFamily->GetFamilyNames(&dwFamilyNames));
1056 1055
1057 UINT32 dwFamilyNamesLength; 1056 UINT32 dwFamilyNamesLength;
1058 HRV(dwFamilyNames->GetStringLength(0, &dwFamilyNamesLength)); 1057 HRV(dwFamilyNames->GetStringLength(0, &dwFamilyNamesLength));
1059 1058
1060 SkTDArray<wchar_t> dwFamilyNameChar(new wchar_t[dwFamilyNamesLength+1], dwFa milyNamesLength+1); 1059 SkTDArray<wchar_t> dwFamilyNameChar(new wchar_t[dwFamilyNamesLength+1], dwFa milyNamesLength+1);
1061 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.begin(), dwFamilyNameChar.c ount())); 1060 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.begin(), dwFamilyNameChar.c ount()));
1062 1061
1063 // Convert the family name to utf8. 1062 // Convert the family name to utf8.
1064 // Get the buffer size needed first. 1063 // Get the buffer size needed first.
1065 int str_len = WideCharToMultiByte(CP_UTF8, 0, dwFamilyNameChar.begin(), -1, 1064 int str_len = WideCharToMultiByte(CP_UTF8, 0, dwFamilyNameChar.begin(), -1,
1066 NULL, 0, NULL, NULL); 1065 NULL, 0, NULL, NULL);
1067 // Allocate a buffer (str_len already has terminating null accounted for). 1066 // Allocate a buffer (str_len already has terminating null accounted for).
1068 SkTDArray<char> utf8FamilyName(new char[str_len], str_len); 1067 SkTDArray<char> utf8FamilyName(new char[str_len], str_len);
1069 // Now actually convert the string. 1068 // Now actually convert the string.
1070 str_len = WideCharToMultiByte(CP_UTF8, 0, dwFamilyNameChar.begin(), -1, 1069 str_len = WideCharToMultiByte(CP_UTF8, 0, dwFamilyNameChar.begin(), -1,
1071 utf8FamilyName.begin(), str_len, NULL, NULL); 1070 utf8FamilyName.begin(), str_len, NULL, NULL);
1072 1071
1073 descriptor.setFamilyName(utf8FamilyName.begin()); 1072 desc->setFamilyName(utf8FamilyName.begin());
1074 //TODO: FileName and PostScriptName currently unsupported. 1073 *isLocalStream = SkToBool(fDWriteFontFileLoader.get());
1075
1076 descriptor.serialize(stream);
1077
1078 if (NULL != face->fDWriteFontFileLoader.get()) {
1079 // store the entire font in the fontData
1080 SkStream* fontStream = face->fDWriteFontFileLoader->fStream.get();
1081 const uint32_t length = fontStream->getLength();
1082
1083 stream->writePackedUInt(length);
1084 stream->writeStream(fontStream, length);
1085 } else {
1086 stream->writePackedUInt(0);
1087 }
1088 }
1089
1090 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
1091 SkFontDescriptor descriptor(stream);
1092
1093 const uint32_t customFontDataLength = stream->readPackedUInt();
1094 if (customFontDataLength > 0) {
1095 // generate a new stream to store the custom typeface
1096 SkAutoTUnref<SkMemoryStream> fontStream(SkNEW_ARGS(SkMemoryStream, (cust omFontDataLength - 1)));
1097 stream->read((void*)fontStream->getMemoryBase(), customFontDataLength - 1);
1098
1099 return CreateTypefaceFromStream(fontStream.get());
1100 }
1101
1102 return SkFontHost::CreateTypeface(NULL, descriptor.getFamilyName(), descript or.getStyle());
1103 } 1074 }
1104 1075
1105 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 1076 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
1106 IDWriteFactory* factory; 1077 IDWriteFactory* factory;
1107 HRN(get_dwrite_factory(&factory)); 1078 HRN(get_dwrite_factory(&factory));
1108 1079
1109 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; 1080 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
1110 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); 1081 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
1111 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); 1082 HRN(factory->RegisterFontFileLoader(fontFileLoader.get()));
1112 1083
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 getAdvanceData(fDWriteFontFace.get(), 1518 getAdvanceData(fDWriteFontFace.get(),
1548 glyphCount, 1519 glyphCount,
1549 glyphIDs, 1520 glyphIDs,
1550 glyphIDsCount, 1521 glyphIDsCount,
1551 getWidthAdvance)); 1522 getWidthAdvance));
1552 } 1523 }
1553 } 1524 }
1554 1525
1555 return info; 1526 return info;
1556 } 1527 }
OLDNEW
« src/ports/SkFontHost_android.cpp ('K') | « src/ports/SkFontHost_win.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698