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

Side by Side Diff: gm/fontmgr.cpp

Issue 13312002: add matcher to fontstyleset (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « no previous file | include/ports/SkFontMgr.h » ('j') | 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 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"
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 class FontMgrGM : public skiagm::GM { 23 class FontMgrGM : public skiagm::GM {
24 public: 24 public:
25 FontMgrGM() { 25 FontMgrGM() {
26 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); 26 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
27 } 27 }
28 28
29 protected: 29 protected:
30 virtual SkString onShortName() { 30 virtual SkString onShortName() {
31 return SkString("fontmgr"); 31 return SkString("fontmgr_iter");
32 } 32 }
33 33
34 virtual SkISize onISize() { 34 virtual SkISize onISize() {
35 return SkISize::Make(640, 1024); 35 return SkISize::Make(640, 1024);
36 } 36 }
37 37
38 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 38 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
39 SkScalar y = 20; 39 SkScalar y = 20;
40 SkPaint paint; 40 SkPaint paint;
41 paint.setAntiAlias(true); 41 paint.setAntiAlias(true);
42 paint.setLCDRenderText(true); 42 paint.setLCDRenderText(true);
43 paint.setSubpixelText(true); 43 paint.setSubpixelText(true);
44 paint.setTextSize(17); 44 paint.setTextSize(17);
45 45
46 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 46 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
47 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); 47 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES);
48 48
49 for (int i = 0; i < count; ++i) { 49 for (int i = 0; i < count; ++i) {
50 SkString fname; 50 SkString fname;
51 fm->getFamilyName(i, &fname); 51 fm->getFamilyName(i, &fname);
52 paint.setTypeface(NULL); 52 paint.setTypeface(NULL);
53 (void)drawString(canvas, fname, 20, y, paint); 53 (void)drawString(canvas, fname, 20, y, paint);
54 54
55 SkScalar x = 220; 55 SkScalar x = 220;
56
56 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 57 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
57 for (int j = 0; j < set->count(); ++j) { 58 for (int j = 0; j < set->count(); ++j) {
58 SkString sname; 59 SkString sname;
59 SkFontStyle fs; 60 SkFontStyle fs;
60 set->getStyle(j, &fs, &sname); 61 set->getStyle(j, &fs, &sname);
61 62
62 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); 63 SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
63 x = drawString(canvas, sname, x, y, paint) + 20; 64 x = drawString(canvas, sname, x, y, paint) + 20;
64 } 65 }
65 y += 24; 66 y += 24;
66 } 67 }
67 } 68 }
68 69
69 virtual uint32_t onGetFlags() const SK_OVERRIDE { 70 virtual uint32_t onGetFlags() const SK_OVERRIDE {
70 // fontdescriptors (and therefore serialization) don't yet understand 71 // fontdescriptors (and therefore serialization) don't yet understand
71 // these new styles, so skip tests that exercise that for now. 72 // these new styles, so skip tests that exercise that for now.
72 return kSkipPicture_Flag | kSkipPipe_Flag; 73 return kSkipPicture_Flag | kSkipPipe_Flag;
73 } 74 }
74 75
75 private: 76 private:
76 typedef GM INHERITED; 77 typedef GM INHERITED;
77 }; 78 };
78 79
80 class FontMgrMatchGM : public skiagm::GM {
81 SkAutoTUnref<SkFontMgr> fFM;
82
83 public:
84 FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) {
85 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
86 }
87
88 protected:
89 virtual SkString onShortName() {
90 return SkString("fontmgr_match");
91 }
92
93 virtual SkISize onISize() {
94 return SkISize::Make(640, 1024);
95 }
96
97 void iterateFamily(SkCanvas* canvas, const SkPaint& paint,
98 SkFontStyleSet* fset) {
99 SkPaint p(paint);
100 SkScalar y = 0;
101
102 for (int j = 0; j < fset->count(); ++j) {
103 SkString sname;
104 SkFontStyle fs;
105 fset->getStyle(j, &fs, &sname);
106
107 sname.appendf(" [%d %d]", fs.weight(), fs.width());
108
109 SkSafeUnref(p.setTypeface(fset->createTypeface(j)));
110 (void)drawString(canvas, sname, 0, y, p);
111 y += 24;
112 }
113 }
114
115 void exploreFamily(SkCanvas* canvas, const SkPaint& paint,
116 SkFontStyleSet* fset) {
117 SkPaint p(paint);
118 SkScalar y = 0;
119
120 for (int weight = 100; weight <= 900; weight += 200) {
121 for (int width = 1; width <= 9; width += 2) {
122 SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant);
123 SkTypeface* face = fset->matchStyle(fs);
124 if (face) {
125 SkString str;
126 str.printf("request [%d %d]", fs.weight(), fs.width());
127 p.setTypeface(face)->unref();
128 (void)drawString(canvas, str, 0, y, p);
129 y += 24;
130 }
131 }
132 }
133 }
134
135 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
136 SkPaint paint;
137 paint.setAntiAlias(true);
138 paint.setLCDRenderText(true);
139 paint.setSubpixelText(true);
140 paint.setTextSize(17);
141
142 static const char* gNames[] = {
143 "Helvetica Neue", "Arial"
144 };
145
146 SkFontStyleSet* fset = NULL;
147 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
148 fset = fFM->matchFamily(gNames[i]);
149 if (fset && fset->count() > 0) {
150 break;
151 }
152 }
153
154 if (NULL == fset) {
155 return;
156 }
157 SkAutoUnref aur(fset);
158
159 canvas->translate(20, 40);
160 this->exploreFamily(canvas, paint, fset);
161 canvas->translate(150, 0);
162 this->iterateFamily(canvas, paint, fset);
163 }
164
165 virtual uint32_t onGetFlags() const SK_OVERRIDE {
166 // fontdescriptors (and therefore serialization) don't yet understand
167 // these new styles, so skip tests that exercise that for now.
168 return kSkipPicture_Flag | kSkipPipe_Flag;
169 }
170
171 private:
172 typedef GM INHERITED;
173 };
174
79 ////////////////////////////////////////////////////////////////////////////// 175 //////////////////////////////////////////////////////////////////////////////
80 176
81 DEF_GM( return SkNEW(FontMgrGM); ) 177 DEF_GM( return SkNEW(FontMgrGM); )
178 DEF_GM( return SkNEW(FontMgrMatchGM); )
OLDNEW
« no previous file with comments | « no previous file | include/ports/SkFontMgr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698