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

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

Issue 12593013: remove SkFontHost::CreateScalerContext (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
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 23 matching lines...) Expand all
34 34
35 #include <dwrite.h> 35 #include <dwrite.h>
36 36
37 SK_DECLARE_STATIC_MUTEX(gFTMutex); 37 SK_DECLARE_STATIC_MUTEX(gFTMutex);
38 38
39 static bool isLCD(const SkScalerContext::Rec& rec) { 39 static bool isLCD(const SkScalerContext::Rec& rec) {
40 return SkMask::kLCD16_Format == rec.fMaskFormat || 40 return SkMask::kLCD16_Format == rec.fMaskFormat ||
41 SkMask::kLCD32_Format == rec.fMaskFormat; 41 SkMask::kLCD32_Format == rec.fMaskFormat;
42 } 42 }
43 43
44 SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { 44 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo ntID) {
45 // Zero means that we don't have any fallback fonts for this fontID. 45 // Zero means that we don't have any fallback fonts for this fontID.
46 // This function is implemented on Android, but doesn't have much 46 // This function is implemented on Android, but doesn't have much
47 // meaning here. 47 // meaning here.
48 return 0; 48 return NULL;
49 } 49 }
50 50
51 /////////////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////////////
52 52
53 class DWriteOffscreen { 53 class DWriteOffscreen {
54 public: 54 public:
55 DWriteOffscreen() : fWidth(0), fHeight(0) { 55 DWriteOffscreen() : fWidth(0), fHeight(0) {
56 } 56 }
57 57
58 void init(IDWriteFontFace* fontFace, const DWRITE_MATRIX& xform, FLOAT fontS ize) { 58 void init(IDWriteFontFace* fontFace, const DWRITE_MATRIX& xform, FLOAT fontS ize) {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 470 }
471 471
472 ~DWriteFontTypeface() { 472 ~DWriteFontTypeface() {
473 if (fDWriteFontCollectionLoader.get() == NULL) return; 473 if (fDWriteFontCollectionLoader.get() == NULL) return;
474 474
475 IDWriteFactory* factory; 475 IDWriteFactory* factory;
476 HRVM(get_dwrite_factory(&factory), "Could not get factory."); 476 HRVM(get_dwrite_factory(&factory), "Could not get factory.");
477 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get())); 477 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get()));
478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); 478 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get()));
479 } 479 }
480
481 protected:
482 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
483 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
480 }; 484 };
481 485
482 class SkScalerContext_Windows : public SkScalerContext { 486 class SkScalerContext_Windows : public SkScalerContext {
483 public: 487 public:
484 SkScalerContext_Windows(const SkDescriptor* desc); 488 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc);
485 virtual ~SkScalerContext_Windows(); 489 virtual ~SkScalerContext_Windows();
486 490
487 protected: 491 protected:
488 virtual unsigned generateGlyphCount() SK_OVERRIDE; 492 virtual unsigned generateGlyphCount() SK_OVERRIDE;
489 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 493 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE;
490 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; 494 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE;
491 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; 495 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE;
492 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; 496 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE;
493 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; 497 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE;
494 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, 498 virtual void generateFontMetrics(SkPaint::FontMetrics* mX,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 HRVM(get_default_font(font), "Could not get default font."); 704 HRVM(get_default_font(font), "Could not get default font.");
701 } else { 705 } else {
702 *font = static_cast<const DWriteFontTypeface*>(face)->fDWriteFont.get(); 706 *font = static_cast<const DWriteFontTypeface*>(face)->fDWriteFont.get();
703 (*font)->AddRef(); 707 (*font)->AddRef();
704 } 708 }
705 } 709 }
706 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) { 710 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) {
707 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID)); 711 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID));
708 } 712 }
709 713
710 SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc) 714 SkScalerContext_Windows::SkScalerContext_Windows(DWriteFontTypeface* typeface,
711 : SkScalerContext(desc) 715 const SkDescriptor* desc)
716 : SkScalerContext(typeface, desc)
717 , fTypeface(SkRef(typeface))
712 , fGlyphCount(-1) { 718 , fGlyphCount(-1) {
713 SkAutoMutexAcquire ac(gFTMutex); 719 SkAutoMutexAcquire ac(gFTMutex);
714 720
715 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); 721 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]);
716 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); 722 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]);
717 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); 723 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]);
718 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]); 724 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]);
719 fXform.dx = 0; 725 fXform.dx = 0;
720 fXform.dy = 0; 726 fXform.dy = 0;
721 727
722 fTypeface.reset(GetDWriteFontByID(fRec.fFontID));
723 fTypeface.get()->ref();
724
725 fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fR ec.fTextSize)); 728 fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fR ec.fTextSize));
726 } 729 }
727 730
728 SkScalerContext_Windows::~SkScalerContext_Windows() { 731 SkScalerContext_Windows::~SkScalerContext_Windows() {
729 } 732 }
730 733
731 unsigned SkScalerContext_Windows::generateGlyphCount() { 734 unsigned SkScalerContext_Windows::generateGlyphCount() {
732 if (fGlyphCount < 0) { 735 if (fGlyphCount < 0) {
733 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount(); 736 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount();
734 } 737 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 &fontFileStream), 1158 &fontFileStream),
1156 "Could not create font file stream."); 1159 "Could not create font file stream.");
1157 1160
1158 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get())); 1161 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get()));
1159 } 1162 }
1160 1163
1161 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3 2_t* index) { 1164 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int3 2_t* index) {
1162 return 0; 1165 return 0;
1163 } 1166 }
1164 1167
1165 SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) { 1168 SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* d esc) const {
1166 return SkNEW_ARGS(SkScalerContext_Windows, (desc)); 1169 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<DWriteFontTypeface*>( this), desc));
1167 } 1170 }
1168 1171
1169 static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** f ontFamily) { 1172 static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** f ontFamily) {
1170 IDWriteFactory* factory; 1173 IDWriteFactory* factory;
1171 HR(get_dwrite_factory(&factory)); 1174 HR(get_dwrite_factory(&factory));
1172 1175
1173 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; 1176 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection;
1174 HR(factory->GetSystemFontCollection(&sysFontCollection, FALSE)); 1177 HR(factory->GetSystemFontCollection(&sysFontCollection, FALSE));
1175 1178
1176 // Get the buffer size needed first. 1179 // Get the buffer size needed first.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 hr = font->CreateFontFace(&fontFace); 1254 hr = font->CreateFontFace(&fontFace);
1252 1255
1253 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily .get()); 1256 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily .get());
1254 } 1257 }
1255 1258
1256 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 1259 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
1257 printf("SkFontHost::CreateTypefaceFromFile unimplemented"); 1260 printf("SkFontHost::CreateTypefaceFromFile unimplemented");
1258 return NULL; 1261 return NULL;
1259 } 1262 }
1260 1263
1261 void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { 1264 void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
1262 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | 1265 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag |
1263 SkScalerContext::kAutohinting_Flag | 1266 SkScalerContext::kAutohinting_Flag |
1264 SkScalerContext::kEmbeddedBitmapText_Flag | 1267 SkScalerContext::kEmbeddedBitmapText_Flag |
1265 SkScalerContext::kEmbolden_Flag | 1268 SkScalerContext::kEmbolden_Flag |
1266 SkScalerContext::kLCD_BGROrder_Flag | 1269 SkScalerContext::kLCD_BGROrder_Flag |
1267 SkScalerContext::kLCD_Vertical_Flag; 1270 SkScalerContext::kLCD_Vertical_Flag;
1268 rec->fFlags &= ~flagsWeDontSupport; 1271 rec->fFlags &= ~flagsWeDontSupport;
1269 1272
1270 SkPaint::Hinting h = rec->getHinting(); 1273 SkPaint::Hinting h = rec->getHinting();
1271 // DirectWrite does not provide for hinting hints. 1274 // DirectWrite does not provide for hinting hints.
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 getAdvanceData(typeface->fDWriteFontFace.get(), 1555 getAdvanceData(typeface->fDWriteFontFace.get(),
1553 glyphCount, 1556 glyphCount,
1554 glyphIDs, 1557 glyphIDs,
1555 glyphIDsCount, 1558 glyphIDsCount,
1556 getWidthAdvance)); 1559 getWidthAdvance));
1557 } 1560 }
1558 } 1561 }
1559 1562
1560 return info; 1563 return info;
1561 } 1564 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698