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: gm/fontmgr.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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
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 13 matching lines...) Expand all
24 return x + paint.measureText(text.c_str(), text.size()); 24 return x + paint.measureText(text.c_str(), text.size());
25 } 25 }
26 26
27 static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x, 27 static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
28 SkScalar y, SkPaint& paint, SkFontMgr* fm, 28 SkScalar y, SkPaint& paint, SkFontMgr* fm,
29 const char* fontName, const char* bcp47[], int bcp 47Count, 29 const char* fontName, const char* bcp47[], int bcp 47Count,
30 const SkFontStyle& fontStyle) { 30 const SkFontStyle& fontStyle) {
31 // find typeface containing the requested character and draw it 31 // find typeface containing the requested character and draw it
32 SkString ch; 32 SkString ch;
33 ch.appendUnichar(character); 33 ch.appendUnichar(character);
34 sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle , 34 SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle,
35 bcp47, bcp47Count, character)); 35 bcp47, bcp47Count, char acter);
36 paint.setTypeface(typeface); 36 SkSafeUnref(paint.setTypeface(typeface));
37 x = drawString(canvas, ch, x, y, paint) + 20; 37 x = drawString(canvas, ch, x, y, paint) + 20;
38 38
39 if (nullptr == typeface) { 39 if (nullptr == typeface) {
40 return x; 40 return x;
41 } 41 }
42 42
43 // repeat the process, but this time use the family name of the typeface 43 // repeat the process, but this time use the family name of the typeface
44 // from the first pass. This emulates the behavior in Blink where it 44 // from the first pass. This emulates the behavior in Blink where it
45 // it expects to get the same glyph when following this pattern. 45 // it expects to get the same glyph when following this pattern.
46 SkString familyName; 46 SkString familyName;
47 typeface->getFamilyName(&familyName); 47 typeface->getFamilyName(&familyName);
48 paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_st r(), 48 SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), type face->fontStyle());
49 typeface->fontS tyle()))); 49 SkSafeUnref(paint.setTypeface(typefaceCopy));
50 return drawString(canvas, ch, x, y, paint) + 20; 50 return drawString(canvas, ch, x, y, paint) + 20;
51 } 51 }
52 52
53 static const char* zh = "zh"; 53 static const char* zh = "zh";
54 static const char* ja = "ja"; 54 static const char* ja = "ja";
55 55
56 class FontMgrGM : public skiagm::GM { 56 class FontMgrGM : public skiagm::GM {
57 public: 57 public:
58 FontMgrGM(SkFontMgr* fontMgr = nullptr) { 58 FontMgrGM(SkFontMgr* fontMgr = nullptr) {
59 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); 59 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 SkScalar x = 220; 98 SkScalar x = 220;
99 99
100 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 100 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
101 for (int j = 0; j < set->count(); ++j) { 101 for (int j = 0; j < set->count(); ++j) {
102 SkString sname; 102 SkString sname;
103 SkFontStyle fs; 103 SkFontStyle fs;
104 set->getStyle(j, &fs, &sname); 104 set->getStyle(j, &fs, &sname);
105 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant() ); 105 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant() );
106 106
107 paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); 107 SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
108 x = drawString(canvas, sname, x, y, paint) + 20; 108 x = drawString(canvas, sname, x, y, paint) + 20;
109 109
110 // check to see that we get different glyphs in japanese and chi nese 110 // check to see that we get different glyphs in japanese and chi nese
111 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_ str(), &zh, 1, fs); 111 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_ str(), &zh, 1, fs);
112 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_ str(), &ja, 1, fs); 112 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_ str(), &ja, 1, fs);
113 // check that emoji characters are found 113 // check that emoji characters are found
114 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, familyName.c _str(), nullptr,0, fs); 114 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, familyName.c _str(), nullptr,0, fs);
115 } 115 }
116 y += 24; 116 y += 24;
117 } 117 }
(...skipping 30 matching lines...) Expand all
148 SkPaint p(paint); 148 SkPaint p(paint);
149 SkScalar y = 0; 149 SkScalar y = 0;
150 150
151 for (int j = 0; j < fset->count(); ++j) { 151 for (int j = 0; j < fset->count(); ++j) {
152 SkString sname; 152 SkString sname;
153 SkFontStyle fs; 153 SkFontStyle fs;
154 fset->getStyle(j, &fs, &sname); 154 fset->getStyle(j, &fs, &sname);
155 155
156 sname.appendf(" [%d %d]", fs.weight(), fs.width()); 156 sname.appendf(" [%d %d]", fs.weight(), fs.width());
157 157
158 p.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j))); 158 SkSafeUnref(p.setTypeface(fset->createTypeface(j)));
159 (void)drawString(canvas, sname, 0, y, p); 159 (void)drawString(canvas, sname, 0, y, p);
160 y += 24; 160 y += 24;
161 } 161 }
162 } 162 }
163 163
164 void exploreFamily(SkCanvas* canvas, const SkPaint& paint, 164 void exploreFamily(SkCanvas* canvas, const SkPaint& paint,
165 SkFontStyleSet* fset) { 165 SkFontStyleSet* fset) {
166 SkPaint p(paint); 166 SkPaint p(paint);
167 SkScalar y = 0; 167 SkScalar y = 0;
168 168
169 for (int weight = 100; weight <= 900; weight += 200) { 169 for (int weight = 100; weight <= 900; weight += 200) {
170 for (int width = 1; width <= 9; width += 2) { 170 for (int width = 1; width <= 9; width += 2) {
171 SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant); 171 SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant);
172 sk_sp<SkTypeface> face(fset->matchStyle(fs)); 172 SkTypeface* face = fset->matchStyle(fs);
173 if (face) { 173 if (face) {
174 SkString str; 174 SkString str;
175 str.printf("request [%d %d]", fs.weight(), fs.width()); 175 str.printf("request [%d %d]", fs.weight(), fs.width());
176 p.setTypeface(std::move(face)); 176 p.setTypeface(face)->unref();
177 (void)drawString(canvas, str, 0, y, p); 177 (void)drawString(canvas, str, 0, y, p);
178 y += 24; 178 y += 24;
179 } 179 }
180 } 180 }
181 } 181 }
182 } 182 }
183 183
184 void onDraw(SkCanvas* canvas) override { 184 void onDraw(SkCanvas* canvas) override {
185 SkPaint paint; 185 SkPaint paint;
186 paint.setAntiAlias(true); 186 paint.setAntiAlias(true);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 int count = SkMin32(fm->countFamilies(), 32); 267 int count = SkMin32(fm->countFamilies(), 32);
268 268
269 int index = 0; 269 int index = 0;
270 SkScalar x = 0, y = 0; 270 SkScalar x = 0, y = 0;
271 271
272 canvas->translate(80, 120); 272 canvas->translate(80, 120);
273 273
274 for (int i = 0; i < count; ++i) { 274 for (int i = 0; i < count; ++i) {
275 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 275 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
276 for (int j = 0; j < set->count(); ++j) { 276 for (int j = 0; j < set->count(); ++j) {
277 paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); 277 SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
278 if (paint.getTypeface()) { 278 if (paint.getTypeface()) {
279 show_bounds(canvas, paint, x, y, boundsColors[index & 1]); 279 show_bounds(canvas, paint, x, y, boundsColors[index & 1]);
280 index += 1; 280 index += 1;
281 x += 160; 281 x += 160;
282 if (0 == (index % 6)) { 282 if (0 == (index % 6)) {
283 x = 0; 283 x = 0;
284 y += 160; 284 y += 160;
285 } 285 }
286 if (index >= 30) { 286 if (index >= 30) {
287 return; 287 return;
(...skipping 14 matching lines...) Expand all
302 302
303 DEF_GM(return new FontMgrGM;) 303 DEF_GM(return new FontMgrGM;)
304 DEF_GM(return new FontMgrMatchGM;) 304 DEF_GM(return new FontMgrMatchGM;)
305 DEF_GM(return new FontMgrBoundsGM(1.0, 0);) 305 DEF_GM(return new FontMgrBoundsGM(1.0, 0);)
306 DEF_GM(return new FontMgrBoundsGM(0.75, 0);) 306 DEF_GM(return new FontMgrBoundsGM(0.75, 0);)
307 DEF_GM(return new FontMgrBoundsGM(1.0, -0.25);) 307 DEF_GM(return new FontMgrBoundsGM(1.0, -0.25);)
308 308
309 #ifdef SK_BUILD_FOR_WIN 309 #ifdef SK_BUILD_FOR_WIN
310 DEF_GM(return new FontMgrGM(SkFontMgr_New_DirectWrite());) 310 DEF_GM(return new FontMgrGM(SkFontMgr_New_DirectWrite());)
311 #endif 311 #endif
OLDNEW
« no previous file with comments | « gm/fontcache.cpp ('k') | gm/fontscalerdistortable.cpp » ('j') | src/ports/SkFontMgr_android.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698