OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkFontMgr.h" | 10 #include "SkFontMgr.h" |
11 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 | 13 |
| 14 #ifdef SK_BUILD_FOR_WIN |
| 15 extern SkFontMgr* SkFontMgr_New_GDI(); |
| 16 extern SkFontMgr* SkFontMgr_New_DirectWrite(); |
| 17 #endif |
| 18 |
14 // limit this just so we don't take too long to draw | 19 // limit this just so we don't take too long to draw |
15 #define MAX_FAMILIES 30 | 20 #define MAX_FAMILIES 30 |
16 | 21 |
17 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, | 22 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, |
18 SkScalar y, const SkPaint& paint) { | 23 SkScalar y, const SkPaint& paint) { |
19 canvas->drawText(text.c_str(), text.size(), x, y, paint); | 24 canvas->drawText(text.c_str(), text.size(), x, y, paint); |
20 return x + paint.measureText(text.c_str(), text.size()); | 25 return x + paint.measureText(text.c_str(), text.size()); |
21 } | 26 } |
22 | 27 |
23 class FontMgrGM : public skiagm::GM { | 28 class FontMgrGM : public skiagm::GM { |
24 public: | 29 public: |
25 FontMgrGM() { | 30 FontMgrGM(SkFontMgr* (*factory)() = NULL) { |
26 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); | 31 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
| 32 |
| 33 fName.set("fontmgr_iter"); |
| 34 if (factory) { |
| 35 fName.append("_factory"); |
| 36 fFM.reset(factory()); |
| 37 } else { |
| 38 fFM.reset(SkFontMgr::RefDefault()); |
| 39 } |
27 } | 40 } |
28 | 41 |
29 protected: | 42 protected: |
30 virtual SkString onShortName() { | 43 virtual SkString onShortName() { |
31 return SkString("fontmgr_iter"); | 44 return fName; |
32 } | 45 } |
33 | 46 |
34 virtual SkISize onISize() { | 47 virtual SkISize onISize() { |
35 return SkISize::Make(640, 1024); | 48 return SkISize::Make(640, 1024); |
36 } | 49 } |
37 | 50 |
38 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 51 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
39 SkScalar y = 20; | 52 SkScalar y = 20; |
40 SkPaint paint; | 53 SkPaint paint; |
41 paint.setAntiAlias(true); | 54 paint.setAntiAlias(true); |
42 paint.setLCDRenderText(true); | 55 paint.setLCDRenderText(true); |
43 paint.setSubpixelText(true); | 56 paint.setSubpixelText(true); |
44 paint.setTextSize(17); | 57 paint.setTextSize(17); |
45 | 58 |
46 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 59 SkFontMgr* fm = fFM; |
47 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); | 60 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); |
48 | 61 |
49 for (int i = 0; i < count; ++i) { | 62 for (int i = 0; i < count; ++i) { |
50 SkString fname; | 63 SkString fname; |
51 fm->getFamilyName(i, &fname); | 64 fm->getFamilyName(i, &fname); |
52 paint.setTypeface(NULL); | 65 paint.setTypeface(NULL); |
53 (void)drawString(canvas, fname, 20, y, paint); | 66 (void)drawString(canvas, fname, 20, y, paint); |
54 | 67 |
55 SkScalar x = 220; | 68 SkScalar x = 220; |
56 | 69 |
(...skipping 15 matching lines...) Expand all Loading... |
72 // fontdescriptors (and therefore serialization) don't yet understand | 85 // fontdescriptors (and therefore serialization) don't yet understand |
73 // these new styles, so skip tests that exercise that for now. | 86 // these new styles, so skip tests that exercise that for now. |
74 | 87 |
75 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), | 88 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), |
76 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. | 89 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. |
77 | 90 |
78 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; | 91 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; |
79 } | 92 } |
80 | 93 |
81 private: | 94 private: |
| 95 SkAutoTUnref<SkFontMgr> fFM; |
| 96 SkString fName; |
82 typedef GM INHERITED; | 97 typedef GM INHERITED; |
83 }; | 98 }; |
84 | 99 |
85 class FontMgrMatchGM : public skiagm::GM { | 100 class FontMgrMatchGM : public skiagm::GM { |
86 SkAutoTUnref<SkFontMgr> fFM; | 101 SkAutoTUnref<SkFontMgr> fFM; |
87 | 102 |
88 public: | 103 public: |
89 FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) { | 104 FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) { |
90 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); | 105 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
91 } | 106 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 189 } |
175 | 190 |
176 private: | 191 private: |
177 typedef GM INHERITED; | 192 typedef GM INHERITED; |
178 }; | 193 }; |
179 | 194 |
180 ////////////////////////////////////////////////////////////////////////////// | 195 ////////////////////////////////////////////////////////////////////////////// |
181 | 196 |
182 DEF_GM( return SkNEW(FontMgrGM); ) | 197 DEF_GM( return SkNEW(FontMgrGM); ) |
183 DEF_GM( return SkNEW(FontMgrMatchGM); ) | 198 DEF_GM( return SkNEW(FontMgrMatchGM); ) |
| 199 |
| 200 #ifdef SK_BUILD_FOR_WIN |
| 201 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite)); ) |
| 202 #endif |
OLD | NEW |