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 | 14 #ifdef SK_BUILD_FOR_WIN |
15 #include "SkTypeface_win.h" | 15 #include "SkTypeface_win.h" |
16 #endif | 16 #endif |
17 | 17 |
18 // limit this just so we don't take too long to draw | 18 // limit this just so we don't take too long to draw |
19 #define MAX_FAMILIES 30 | 19 #define MAX_FAMILIES 30 |
20 | 20 |
21 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, | 21 static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, |
22 SkScalar y, const SkPaint& paint) { | 22 SkScalar y, const SkPaint& paint) { |
23 canvas->drawText(text.c_str(), text.size(), x, y, paint); | 23 canvas->drawText(text.c_str(), text.size(), x, y, paint); |
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, | |
28 SkScalar y, SkPaint& paint, SkFontMgr* fm, | |
29 const char* fontName, const char* bpc47, | |
30 const SkFontStyle& fontStyle) { | |
31 // find typeface containing the requested character and draw it | |
32 SkString ch; | |
33 ch.appendUnichar(character); | |
34 SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, bp c47, character); | |
35 SkSafeUnref(paint.setTypeface(typeface)); | |
36 x = drawString(canvas, ch, x, y, paint) + 20; | |
tomhudson
2014/08/21 20:24:41
Assuming character width << 20?
| |
37 | |
38 // repeat the process, but this time use the family name of the typeface | |
39 // from the first pass. This emulates the behavior in Blink where it | |
40 // it expects to get the same glyph when following this pattern. | |
41 SkString familyName; | |
42 typeface->getFamilyName(&familyName); | |
bungeman-skia
2014/08/26 21:15:44
'typeface' can be NULL here if 'matchFamilyStyleCh
| |
43 SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), SkTy peface::kNormal); | |
bungeman-skia
2014/08/26 21:55:35
Instead of 'SkTypeface::kNormal', you might want t
| |
44 SkSafeUnref(paint.setTypeface(typefaceCopy)); | |
45 return drawString(canvas, ch, x, y, paint) + 20; | |
46 } | |
47 | |
27 class FontMgrGM : public skiagm::GM { | 48 class FontMgrGM : public skiagm::GM { |
28 public: | 49 public: |
29 FontMgrGM(SkFontMgr* fontMgr = NULL) { | 50 FontMgrGM(SkFontMgr* fontMgr = NULL) { |
30 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); | 51 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
31 | 52 |
32 fName.set("fontmgr_iter"); | 53 fName.set("fontmgr_iter"); |
33 if (fontMgr) { | 54 if (fontMgr) { |
34 fName.append("_factory"); | 55 fName.append("_factory"); |
35 fFM.reset(fontMgr); | 56 fFM.reset(fontMgr); |
36 } else { | 57 } else { |
37 fFM.reset(SkFontMgr::RefDefault()); | 58 fFM.reset(SkFontMgr::RefDefault()); |
38 } | 59 } |
39 } | 60 } |
40 | 61 |
41 protected: | 62 protected: |
42 virtual SkString onShortName() { | 63 virtual SkString onShortName() { |
43 return fName; | 64 return fName; |
44 } | 65 } |
45 | 66 |
46 virtual SkISize onISize() { | 67 virtual SkISize onISize() { |
47 return SkISize::Make(640, 1024); | 68 return SkISize::Make(1536, 768); |
48 } | 69 } |
49 | 70 |
50 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 71 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
51 SkScalar y = 20; | 72 SkScalar y = 20; |
52 SkPaint paint; | 73 SkPaint paint; |
53 paint.setAntiAlias(true); | 74 paint.setAntiAlias(true); |
54 paint.setLCDRenderText(true); | 75 paint.setLCDRenderText(true); |
55 paint.setSubpixelText(true); | 76 paint.setSubpixelText(true); |
56 paint.setTextSize(17); | 77 paint.setTextSize(17); |
57 | 78 |
(...skipping 10 matching lines...) Expand all Loading... | |
68 | 89 |
69 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); | 90 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); |
70 for (int j = 0; j < set->count(); ++j) { | 91 for (int j = 0; j < set->count(); ++j) { |
71 SkString sname; | 92 SkString sname; |
72 SkFontStyle fs; | 93 SkFontStyle fs; |
73 set->getStyle(j, &fs, &sname); | 94 set->getStyle(j, &fs, &sname); |
74 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.isItali c()); | 95 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.isItali c()); |
75 | 96 |
76 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); | 97 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); |
77 x = drawString(canvas, sname, x, y, paint) + 20; | 98 x = drawString(canvas, sname, x, y, paint) + 20; |
99 | |
100 // check to see that we get different glyphs in japanese and chi nese | |
101 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str() , "zh", fs); | |
102 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str() , "ja", fs); | |
103 // check that emoji characters are found | |
104 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str( ), NULL, fs); | |
78 } | 105 } |
79 y += 24; | 106 y += 24; |
80 } | 107 } |
81 } | 108 } |
82 | 109 |
83 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 110 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
84 // fontdescriptors (and therefore serialization) don't yet understand | 111 // fontdescriptors (and therefore serialization) don't yet understand |
85 // these new styles, so skip tests that exercise that for now. | 112 // these new styles, so skip tests that exercise that for now. |
86 | 113 |
87 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu lar, 12MB for Bold), | 114 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu lar, 12MB for Bold), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 }; | 217 }; |
191 | 218 |
192 ////////////////////////////////////////////////////////////////////////////// | 219 ////////////////////////////////////////////////////////////////////////////// |
193 | 220 |
194 DEF_GM( return SkNEW(FontMgrGM); ) | 221 DEF_GM( return SkNEW(FontMgrGM); ) |
195 DEF_GM( return SkNEW(FontMgrMatchGM); ) | 222 DEF_GM( return SkNEW(FontMgrMatchGM); ) |
196 | 223 |
197 #ifdef SK_BUILD_FOR_WIN | 224 #ifdef SK_BUILD_FOR_WIN |
198 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) | 225 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) |
199 #endif | 226 #endif |
OLD | NEW |