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

Side by Side Diff: gm/fontmgr.cpp

Issue 492763003: Lookup glyphs based on character code and language tag. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: addressing comments Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | 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"
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;
37
38 if (NULL == typeface) {
39 return x;
40 }
41
42 // repeat the process, but this time use the family name of the typeface
43 // from the first pass. This emulates the behavior in Blink where it
44 // it expects to get the same glyph when following this pattern.
45 SkString familyName;
46 typeface->getFamilyName(&familyName);
47 SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), type face->style());
48 SkSafeUnref(paint.setTypeface(typefaceCopy));
49 return drawString(canvas, ch, x, y, paint) + 20;
50 }
51
27 class FontMgrGM : public skiagm::GM { 52 class FontMgrGM : public skiagm::GM {
28 public: 53 public:
29 FontMgrGM(SkFontMgr* fontMgr = NULL) { 54 FontMgrGM(SkFontMgr* fontMgr = NULL) {
30 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); 55 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
31 56
32 fName.set("fontmgr_iter"); 57 fName.set("fontmgr_iter");
33 if (fontMgr) { 58 if (fontMgr) {
34 fName.append("_factory"); 59 fName.append("_factory");
35 fFM.reset(fontMgr); 60 fFM.reset(fontMgr);
36 } else { 61 } else {
37 fFM.reset(SkFontMgr::RefDefault()); 62 fFM.reset(SkFontMgr::RefDefault());
38 } 63 }
39 } 64 }
40 65
41 protected: 66 protected:
42 virtual SkString onShortName() { 67 virtual SkString onShortName() {
43 return fName; 68 return fName;
44 } 69 }
45 70
46 virtual SkISize onISize() { 71 virtual SkISize onISize() {
47 return SkISize::Make(640, 1024); 72 return SkISize::Make(1536, 768);
48 } 73 }
49 74
50 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 75 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
51 SkScalar y = 20; 76 SkScalar y = 20;
52 SkPaint paint; 77 SkPaint paint;
53 paint.setAntiAlias(true); 78 paint.setAntiAlias(true);
54 paint.setLCDRenderText(true); 79 paint.setLCDRenderText(true);
55 paint.setSubpixelText(true); 80 paint.setSubpixelText(true);
56 paint.setTextSize(17); 81 paint.setTextSize(17);
57 82
(...skipping 10 matching lines...) Expand all
68 93
69 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 94 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
70 for (int j = 0; j < set->count(); ++j) { 95 for (int j = 0; j < set->count(); ++j) {
71 SkString sname; 96 SkString sname;
72 SkFontStyle fs; 97 SkFontStyle fs;
73 set->getStyle(j, &fs, &sname); 98 set->getStyle(j, &fs, &sname);
74 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.isItali c()); 99 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.isItali c());
75 100
76 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); 101 SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
77 x = drawString(canvas, sname, x, y, paint) + 20; 102 x = drawString(canvas, sname, x, y, paint) + 20;
103
104 // check to see that we get different glyphs in japanese and chi nese
105 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str() , "zh", fs);
106 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str() , "ja", fs);
107 // check that emoji characters are found
108 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str( ), NULL, fs);
78 } 109 }
79 y += 24; 110 y += 24;
80 } 111 }
81 } 112 }
82 113
83 virtual uint32_t onGetFlags() const SK_OVERRIDE { 114 virtual uint32_t onGetFlags() const SK_OVERRIDE {
84 // fontdescriptors (and therefore serialization) don't yet understand 115 // fontdescriptors (and therefore serialization) don't yet understand
85 // these new styles, so skip tests that exercise that for now. 116 // these new styles, so skip tests that exercise that for now.
86 117
87 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu lar, 12MB for Bold), 118 // 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
190 }; 221 };
191 222
192 ////////////////////////////////////////////////////////////////////////////// 223 //////////////////////////////////////////////////////////////////////////////
193 224
194 DEF_GM( return SkNEW(FontMgrGM); ) 225 DEF_GM( return SkNEW(FontMgrGM); )
195 DEF_GM( return SkNEW(FontMgrMatchGM); ) 226 DEF_GM( return SkNEW(FontMgrMatchGM); )
196 227
197 #ifdef SK_BUILD_FOR_WIN 228 #ifdef SK_BUILD_FOR_WIN
198 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) 229 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); )
199 #endif 230 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698