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

Side by Side Diff: gm/typeface.cpp

Issue 1256903002: make fontscalar gammatext lcdtext typeface verttext2 gm portable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove useless gm; fix nit Created 5 years, 5 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 | « gm/lcdtext.cpp ('k') | gm/verttext2.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 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 "SkString.h" 10 #include "SkString.h"
11 #include "SkTypeface.h" 11 #include "SkTypeface.h"
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14 static const char* gFaces[] = {
15 "Times Roman",
16 "Hiragino Maru Gothic Pro",
17 "Papyrus",
18 "Helvetica",
19 "Courier New"
20 };
21
22 class TypefaceGM : public skiagm::GM {
23 public:
24 TypefaceGM()
25 : fFaces(NULL) {
26 }
27
28 virtual ~TypefaceGM() {
29 if (fFaces) {
30 for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
31 SkSafeUnref(fFaces[i]);
32 }
33 delete [] fFaces;
34 }
35 }
36
37 protected:
38 void onOnceBeforeDraw() override {
39 fFaces = new SkTypeface*[SK_ARRAY_COUNT(gFaces)];
40 for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
41 fFaces[i] = sk_tool_utils::create_portable_typeface(gFaces[i], SkTyp eface::kNormal);
42 }
43 }
44
45 SkString onShortName() override {
46 return SkString("typeface");
47 }
48
49 SkISize onISize() override {
50 return SkISize::Make(640, 480);
51 }
52
53 void onDraw(SkCanvas* canvas) override {
54 SkString text("Typefaces are fun!");
55 SkScalar y = 0;
56
57 SkPaint paint;
58 paint.setAntiAlias(true);
59 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFaces); i++) {
60 this->drawWithFace(text, i, y, paint, canvas);
61 }
62 // Now go backwards
63 for (int i = SK_ARRAY_COUNT(gFaces) - 1; i >= 0; i--) {
64 this->drawWithFace(text, i, y, paint, canvas);
65 }
66 }
67
68 private:
69 void drawWithFace(const SkString& text, int i, SkScalar& y, SkPaint& paint,
70 SkCanvas* canvas) {
71 paint.setTypeface(fFaces[i]);
72 y += paint.getFontMetrics(NULL);
73 canvas->drawText(text.c_str(), text.size(), 0, y, paint);
74 }
75
76 SkTypeface** fFaces;
77
78 typedef skiagm::GM INHERITED;
79 };
80
81 ///////////////////////////////////////////////////////////////////////////////
82
83 static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[], 14 static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[],
84 int count, SkScalar x, SkScalar y, SkPoint pos[]) { 15 int count, SkScalar x, SkScalar y, SkPoint pos[]) {
85 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()); 16 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding());
86 17
87 SkAutoSTMalloc<128, SkScalar> widthStorage(count); 18 SkAutoSTMalloc<128, SkScalar> widthStorage(count);
88 SkScalar* widths = widthStorage.get(); 19 SkScalar* widths = widthStorage.get();
89 paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths); 20 paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths);
90 21
91 for (int i = 0; i < count; ++i) { 22 for (int i = 0; i < count; ++i) {
92 pos[i].set(x, y); 23 pos[i].set(x, y);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 101
171 virtual ~TypefaceStylesGM() { 102 virtual ~TypefaceStylesGM() {
172 for (int i = 0; i < gFaceStylesCount; i++) { 103 for (int i = 0; i < gFaceStylesCount; i++) {
173 SkSafeUnref(fFaces[i]); 104 SkSafeUnref(fFaces[i]);
174 } 105 }
175 } 106 }
176 107
177 protected: 108 protected:
178 void onOnceBeforeDraw() override { 109 void onOnceBeforeDraw() override {
179 for (int i = 0; i < gFaceStylesCount; i++) { 110 for (int i = 0; i < gFaceStylesCount; i++) {
180 fFaces[i] = sk_tool_utils::create_portable_typeface(gFaceStyles[i].f Name, 111 fFaces[i] = SkTypeface::CreateFromName(
181 gFaceStyles[i].fStyle); 112 sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFa ceStyles[i].fStyle);
182 } 113 }
183 } 114 }
184 115
185 SkString onShortName() override { 116 SkString onShortName() override {
186 SkString name("typefacestyles"); 117 SkString name("typefacestyles");
187 if (fApplyKerning) { 118 if (fApplyKerning) {
188 name.append("_kerning"); 119 name.append("_kerning");
189 } 120 }
121 name.append(sk_tool_utils::major_platform_os_name());
190 return name; 122 return name;
191 } 123 }
192 124
193 SkISize onISize() override { 125 SkISize onISize() override {
194 return SkISize::Make(640, 480); 126 return SkISize::Make(640, 480);
195 } 127 }
196 128
197 void onDraw(SkCanvas* canvas) override { 129 void onDraw(SkCanvas* canvas) override {
198 SkPaint paint; 130 SkPaint paint;
199 paint.setAntiAlias(true); 131 paint.setAntiAlias(true);
(...skipping 20 matching lines...) Expand all
220 y += dy; 152 y += dy;
221 } 153 }
222 } 154 }
223 155
224 private: 156 private:
225 typedef skiagm::GM INHERITED; 157 typedef skiagm::GM INHERITED;
226 }; 158 };
227 159
228 /////////////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////////////
229 161
230 DEF_GM( return new TypefaceGM; )
231 DEF_GM( return new TypefaceStylesGM(false); ) 162 DEF_GM( return new TypefaceStylesGM(false); )
232 DEF_GM( return new TypefaceStylesGM(true); ) 163 DEF_GM( return new TypefaceStylesGM(true); )
OLDNEW
« no previous file with comments | « gm/lcdtext.cpp ('k') | gm/verttext2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698