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

Side by Side Diff: tests/DrawTextTest.cpp

Issue 1438893002: Increment text pointer when the width is zero in the subpixel with center and right alignment. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add test cases for code. Created 5 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
« no previous file with comments | « src/core/SkFindAndPlaceGlyph.h ('k') | 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 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 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SkIRect drawTextRect = SkIRect::MakeWH(64, 64); 67 SkIRect drawTextRect = SkIRect::MakeWH(64, 64);
68 SkBitmap drawTextBitmap; 68 SkBitmap drawTextBitmap;
69 create(&drawTextBitmap, drawTextRect); 69 create(&drawTextBitmap, drawTextRect);
70 SkCanvas drawTextCanvas(drawTextBitmap); 70 SkCanvas drawTextCanvas(drawTextBitmap);
71 71
72 SkIRect drawPosTextRect = SkIRect::MakeWH(64, 64); 72 SkIRect drawPosTextRect = SkIRect::MakeWH(64, 64);
73 SkBitmap drawPosTextBitmap; 73 SkBitmap drawPosTextBitmap;
74 create(&drawPosTextBitmap, drawPosTextRect); 74 create(&drawPosTextBitmap, drawPosTextRect);
75 SkCanvas drawPosTextCanvas(drawPosTextBitmap); 75 SkCanvas drawPosTextCanvas(drawPosTextBitmap);
76 76
77 for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) { 77 // Two test cases "A" for the normal path through the code, and " " to check the
78 for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f)) { 78 // early return path.
79 SkPoint point = SkPoint::Make(25.0f + offsetX, 79 const char* cases[] = {"A", " "};
80 25.0f + offsetY); 80 for (auto c : cases) {
81 for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) {
82 for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f) ) {
83 SkPoint point = SkPoint::Make(25.0f + offsetX,
84 25.0f + offsetY);
81 85
82 for (int align = 0; align < SkPaint::kAlignCount; ++align) { 86 for (int align = 0; align < SkPaint::kAlignCount; ++align) {
83 paint.setTextAlign(static_cast<SkPaint::Align>(align)); 87 paint.setTextAlign(static_cast<SkPaint::Align>(align));
84 88
85 for (unsigned int flags = 0; flags < (1 << 3); ++flags) { 89 for (unsigned int flags = 0; flags < (1 << 3); ++flags) {
86 static const unsigned int antiAliasFlag = 1; 90 static const unsigned int antiAliasFlag = 1;
87 static const unsigned int subpixelFlag = 1 << 1; 91 static const unsigned int subpixelFlag = 1 << 1;
88 static const unsigned int lcdFlag = 1 << 2; 92 static const unsigned int lcdFlag = 1 << 2;
89 93
90 paint.setAntiAlias(SkToBool(flags & antiAliasFlag)); 94 paint.setAntiAlias(SkToBool(flags & antiAliasFlag));
91 paint.setSubpixelText(SkToBool(flags & subpixelFlag)); 95 paint.setSubpixelText(SkToBool(flags & subpixelFlag));
92 paint.setLCDRenderText(SkToBool(flags & lcdFlag)); 96 paint.setLCDRenderText(SkToBool(flags & lcdFlag));
93 97
94 // Test: drawText and drawPosText draw the same. 98 // Test: drawText and drawPosText draw the same.
95 drawBG(&drawTextCanvas); 99 drawBG(&drawTextCanvas);
96 drawTextCanvas.drawText("A", 1, point.fX, point.fY, paint); 100 drawTextCanvas.drawText(c, 1, point.fX, point.fY, paint) ;
97 101
98 drawBG(&drawPosTextCanvas); 102 drawBG(&drawPosTextCanvas);
99 drawPosTextCanvas.drawPosText("A", 1, &point, paint); 103 drawPosTextCanvas.drawPosText(c, 1, &point, paint);
100 104
101 REPORTER_ASSERT(reporter, 105 REPORTER_ASSERT(reporter,
102 compare(drawTextBitmap, drawTextRect, 106 compare(drawTextBitmap, drawTextRect,
103 drawPosTextBitmap, drawPosTextRect)); 107 drawPosTextBitmap, drawPosTextRe ct));
108 }
104 } 109 }
105 } 110 }
106 } 111 }
107 } 112 }
108 } 113 }
OLDNEW
« no previous file with comments | « src/core/SkFindAndPlaceGlyph.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698