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" |
(...skipping 18 matching lines...) Expand all Loading... |
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 SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, | 34 SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, |
35 bcp47, bcp47Count, char
acter); | 35 bcp47, bcp47Count, char
acter); |
36 SkSafeUnref(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 (NULL == 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 SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), type
face->style()); | 48 SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), type
face->style()); |
49 SkSafeUnref(paint.setTypeface(typefaceCopy)); | 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 = NULL) { | 58 FontMgrGM(SkFontMgr* fontMgr = nullptr) { |
59 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); | 59 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
60 | 60 |
61 fName.set("fontmgr_iter"); | 61 fName.set("fontmgr_iter"); |
62 if (fontMgr) { | 62 if (fontMgr) { |
63 fName.append("_factory"); | 63 fName.append("_factory"); |
64 fFM.reset(fontMgr); | 64 fFM.reset(fontMgr); |
65 } else { | 65 } else { |
66 fFM.reset(SkFontMgr::RefDefault()); | 66 fFM.reset(SkFontMgr::RefDefault()); |
67 } | 67 } |
68 fName.append(sk_tool_utils::platform_os_name()); | 68 fName.append(sk_tool_utils::platform_os_name()); |
(...skipping 16 matching lines...) Expand all Loading... |
85 paint.setLCDRenderText(true); | 85 paint.setLCDRenderText(true); |
86 paint.setSubpixelText(true); | 86 paint.setSubpixelText(true); |
87 paint.setTextSize(17); | 87 paint.setTextSize(17); |
88 | 88 |
89 SkFontMgr* fm = fFM; | 89 SkFontMgr* fm = fFM; |
90 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); | 90 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); |
91 | 91 |
92 for (int i = 0; i < count; ++i) { | 92 for (int i = 0; i < count; ++i) { |
93 SkString familyName; | 93 SkString familyName; |
94 fm->getFamilyName(i, &familyName); | 94 fm->getFamilyName(i, &familyName); |
95 paint.setTypeface(NULL); | 95 paint.setTypeface(nullptr); |
96 (void)drawString(canvas, familyName, 20, y, paint); | 96 (void)drawString(canvas, familyName, 20, y, paint); |
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.isItali
c()); | 105 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.isItali
c()); |
106 | 106 |
107 SkSafeUnref(paint.setTypeface(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(), NULL,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 } |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 SkAutoTUnref<SkFontMgr> fFM; | 121 SkAutoTUnref<SkFontMgr> fFM; |
122 SkString fName; | 122 SkString fName; |
123 typedef GM INHERITED; | 123 typedef GM INHERITED; |
124 }; | 124 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 "Helvetica Neue", "Arial" | 192 "Helvetica Neue", "Arial" |
193 }; | 193 }; |
194 | 194 |
195 SkAutoTUnref<SkFontStyleSet> fset; | 195 SkAutoTUnref<SkFontStyleSet> fset; |
196 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { | 196 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { |
197 fset.reset(fFM->matchFamily(gNames[i])); | 197 fset.reset(fFM->matchFamily(gNames[i])); |
198 if (fset->count() > 0) { | 198 if (fset->count() > 0) { |
199 break; | 199 break; |
200 } | 200 } |
201 } | 201 } |
202 if (NULL == fset.get()) { | 202 if (nullptr == fset.get()) { |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 canvas->translate(20, 40); | 206 canvas->translate(20, 40); |
207 this->exploreFamily(canvas, paint, fset); | 207 this->exploreFamily(canvas, paint, fset); |
208 canvas->translate(150, 0); | 208 canvas->translate(150, 0); |
209 this->iterateFamily(canvas, paint, fset); | 209 this->iterateFamily(canvas, paint, fset); |
210 } | 210 } |
211 | 211 |
212 private: | 212 private: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |