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

Side by Side Diff: gm/scaletext.cpp

Issue 41213003: Hook in rough distance field support for fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Minor fixes for GrDistanceFieldTextContext. Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/common_variables.gypi » ('j') | include/gpu/GrDistanceFieldTextContext.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
robertphillips 2013/11/05 15:30:26 Update this?
jvanverth1 2013/11/05 17:09:22 Removed -- it shouldn't have been committed.
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 #include "gm.h" 7 #include "gm.h"
8 #include "SkTypeface.h" 8 #include "SkTypeface.h"
9 9
10 namespace skiagm { 10 namespace skiagm {
11 11
robertphillips 2013/11/05 15:30:26 // raison d'etre
12 class FontScalerGM : public GM { 12 class ScaleTextGM : public GM {
13 public: 13 public:
14 FontScalerGM() { 14 ScaleTextGM() {
15 this->setBGColor(0xFFFFFFFF); 15 this->setBGColor(0xFFFFFFFF);
16 } 16 }
17 17
18 virtual ~FontScalerGM() { 18 virtual ~ScaleTextGM() {
19 } 19 }
20 20
21 protected: 21 protected:
22 virtual SkString onShortName() { 22 virtual SkString onShortName() {
23 return SkString("fontscaler"); 23 return SkString("scaletext");
24 } 24 }
25 25
26 virtual SkISize onISize() { 26 virtual SkISize onISize() {
27 return make_isize(1450, 750); 27 return make_isize(1450, 750);
28 } 28 }
29 29
30 static void rotate_about(SkCanvas* canvas, 30 static void rotate_about(SkCanvas* canvas,
31 SkScalar degrees, 31 SkScalar degrees,
32 SkScalar px, SkScalar py) { 32 SkScalar px, SkScalar py) {
33 canvas->translate(px, py); 33 canvas->translate(px, py);
34 canvas->rotate(degrees); 34 canvas->rotate(degrees);
35 canvas->translate(-px, -py); 35 canvas->translate(-px, -py);
36 } 36 }
37 37
38 virtual void onDraw(SkCanvas* canvas) { 38 virtual void onDraw(SkCanvas* canvas) {
39 SkPaint paint; 39 SkPaint paint;
40 40
41 paint.setAntiAlias(true); 41 paint.setAntiAlias(true);
42 paint.setLCDRenderText(true); 42 paint.setLCDRenderText(true);
43 //With freetype the default (normal hinting) can be really ugly. 43 //With freetype the default (normal hinting) can be really ugly.
44 //Most distros now set slight (vertical hinting only) in any event. 44 //Most distros now set slight (vertical hinting only) in any event.
45 paint.setHinting(SkPaint::kSlight_Hinting); 45 paint.setHinting(SkPaint::kSlight_Hinting);
46 SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))); 46 SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times New Roma n", SkTypeface::kNormal)));
47 47
48 const char* text = "Hamburgefons ooo mmm"; 48 const char* text = "Thamburgefons ooo mmm";
49 const size_t textLen = strlen(text); 49 const size_t textLen = strlen(text);
50 50
robertphillips 2013/11/05 15:30:26 Do we need the 'j' loop anymore?
51 for (int j = 0; j < 2; ++j) { 51 for (int j = 0; j < 1; ++j) {
robertphillips 2013/11/05 15:30:26 Remove this comment?
52 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config. 52 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
53 for (int i = 0; i < 5; ++i) { 53 for (int i = 0; i < 2; ++i) {
54 SkScalar x = SkIntToScalar(10); 54 SkScalar x = SkIntToScalar(10);
55 SkScalar y = SkIntToScalar(20); 55 SkScalar y = SkIntToScalar(20);
56 56
57 SkAutoCanvasRestore acr(canvas, true); 57 SkAutoCanvasRestore acr(canvas, true);
58 canvas->translate(SkIntToScalar(50 + i * 230), 58 canvas->translate(SkIntToScalar(50 + 4*i * 230),
59 SkIntToScalar(20)); 59 SkIntToScalar(20));
60 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); 60 rotate_about(canvas, SkIntToScalar(4*i * 5), x, y * 10);
61 61
62 { 62 {
63 SkPaint p; 63 SkPaint p;
64 p.setAntiAlias(true); 64 p.setAntiAlias(true);
65 SkRect r; 65 SkRect r;
66 r.set(x - SkIntToScalar(3), SkIntToScalar(15), 66 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
67 x - SkIntToScalar(1), SkIntToScalar(280)); 67 x - SkIntToScalar(1), SkIntToScalar(280));
68 canvas->drawRect(r, p); 68 canvas->drawRect(r, p);
69 } 69 }
70 70
robertphillips 2013/11/05 15:30:26 What is index for?
71 int index = 0; 71 int index = 0;
robertphillips 2013/11/05 15:30:26 ps seems like a bad name Should 6 & 50 be constant
72 for (int ps = 6; ps <= 22; ps++) { 72 for (int ps = 6; ps <= 50; ps += 2) {
73 paint.setTextSize(SkIntToScalar(ps)); 73 paint.setTextSize(SkIntToScalar(ps));
74 canvas->drawText(text, textLen, x, y, paint); 74 canvas->drawText(text, textLen, x, y, paint);
75 y += paint.getFontMetrics(NULL); 75 y += paint.getFontMetrics(NULL);
76 index += 1; 76 index += 1;
77 } 77 }
78 } 78 }
robertphillips 2013/11/05 15:30:26 Are the next two lines required any more?
79 canvas->translate(0, SkIntToScalar(360)); 79 canvas->translate(0, SkIntToScalar(360));
80 paint.setSubpixelText(true); 80 paint.setSubpixelText(true);
81 } 81 }
82 } 82 }
83 83
84 private: 84 private:
85 typedef GM INHERITED; 85 typedef GM INHERITED;
86 }; 86 };
87 87
88 ////////////////////////////////////////////////////////////////////////////// 88 //////////////////////////////////////////////////////////////////////////////
89 89
robertphillips 2013/11/05 15:30:26 DEF_GM?
90 static GM* MyFactory(void*) { return new FontScalerGM; } 90 static GM* MyFactory(void*) { return new ScaleTextGM; }
91 static GMRegistry reg(MyFactory); 91 static GMRegistry reg(MyFactory);
92 92
93 } 93 }
OLDNEW
« no previous file with comments | « no previous file | gyp/common_variables.gypi » ('j') | include/gpu/GrDistanceFieldTextContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698