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

Side by Side Diff: gm/dftext.cpp

Issue 568843002: Fix scaling issue with distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix uninitialized variables. 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 | gm/fontscaler.cpp » ('j') | src/gpu/GrDistanceFieldTextContext.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "gm.h"
8 #include "SkTypeface.h"
9
10 namespace skiagm {
11
12 class DFTextGM : public GM {
13 public:
14 DFTextGM() {
15 this->setBGColor(0xFFFFFFFF);
16 }
17
18 virtual ~DFTextGM() {
19 }
20
21 protected:
22 virtual uint32_t onGetFlags() const SK_OVERRIDE {
23 return kSkipTiled_Flag | kGPUOnly_Flag;
bsalomon 2014/09/15 13:33:19 why the skip tile? Have you checked that it draws
jvanverth1 2014/09/15 13:43:53 I copied another GM that had it. I can remove it.
24 }
25
26 virtual SkString onShortName() {
27 return SkString("dftext");
28 }
29
30 virtual SkISize onISize() {
31 return SkISize::Make(1024, 768);
32 }
33
34 static void rotate_about(SkCanvas* canvas,
35 SkScalar degrees,
36 SkScalar px, SkScalar py) {
37 canvas->translate(px, py);
38 canvas->rotate(degrees);
39 canvas->translate(-px, -py);
40 }
41
42 virtual void onDraw(SkCanvas* canvas) {
43 SkScalar textSizes[] = { 11.0f, 11.0f*2.0f, 11.0f*5.0f, 11.0f*2.0f*5.0f };
44 SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f };
45
46 SkPaint paint;
47
48 paint.setAntiAlias(true);
49 paint.setSubpixelText(true);
50 paint.setDistanceFieldTextTEMP(true);
bsalomon 2014/09/15 13:33:19 Is the surface method of triggering DF more perman
jvanverth1 2014/09/15 13:43:53 Will do.
51
52 sk_tool_utils::set_portable_typeface(&paint, "Times New Roman", SkTypefa ce::kNormal);
53
54 const char* text = "Hamburgefons";
55 const size_t textLen = strlen(text);
56
57 // check a variety of scales
58 SkScalar x = SkIntToScalar(0);
59 SkScalar y = SkIntToScalar(78);
60 for (int i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) {
61 SkAutoCanvasRestore acr(canvas, true);
62 canvas->translate(x, y);
63 canvas->scale(scales[i], scales[i]);
64 paint.setTextSize(textSizes[i]);
65 canvas->drawText(text, textLen, 0, 0, paint);
66 y += paint.getFontMetrics(NULL)*scales[i];
67 }
68
69 // check rotation
70 for (int i = 0; i < 5; ++i) {
71 SkScalar rotX = SkIntToScalar(10);
72 SkScalar rotY = y;
73
74 SkAutoCanvasRestore acr(canvas, true);
75 canvas->translate(SkIntToScalar(10 + i * 200), -80);
76 rotate_about(canvas, SkIntToScalar(i * 5), rotX, rotY);
77 for (int ps = 6; ps <= 32; ps += 3) {
78 paint.setTextSize(SkIntToScalar(ps));
79 canvas->drawText(text, textLen, rotX, rotY, paint);
80 rotY += paint.getFontMetrics(NULL);
81 }
82 }
83
84 // check gamma-corrected blending
85 const SkColor fg[] = {
86 0xFFFFFFFF,
87 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
88 0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
89 0xFF000000,
90 };
91
92 paint.setLCDRenderText(true);
93 paint.setColor(0xFFF1F1F1);
94 SkRect r = SkRect::MakeLTRB(690, 20, 840, 230);
95 canvas->drawRect(r, paint);
96
97 x = 700;
98 y = 40;
99 paint.setTextSize(SkIntToScalar(22));
100 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
101 paint.setColor(fg[i]);
102
103 canvas->drawText(text, textLen, x, y, paint);
104 y += paint.getFontMetrics(NULL);
105 }
106
107 paint.setColor(0xFF1F1F1F);
108 r = SkRect::MakeLTRB(840, 20, 990, 230);
109 canvas->drawRect(r, paint);
110
111 x = 850;
112 y = 40;
113 paint.setTextSize(SkIntToScalar(22));
114 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
115 paint.setColor(fg[i]);
116
117 canvas->drawText(text, textLen, x, y, paint);
118 y += paint.getFontMetrics(NULL);
119 }
120
121 }
122
123 private:
124 typedef GM INHERITED;
125 };
126
127 //////////////////////////////////////////////////////////////////////////////
128
129 static GM* MyFactory(void*) { return new DFTextGM; }
130 static GMRegistry reg(MyFactory);
131
132 }
OLDNEW
« no previous file with comments | « no previous file | gm/fontscaler.cpp » ('j') | src/gpu/GrDistanceFieldTextContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698