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

Side by Side Diff: samplecode/SampleText.cpp

Issue 1724283003: Revert of Simple cleanups related to SkFixed. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 9 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 | « include/core/SkRect.h ('k') | src/core/SkBitmapFilter.h » ('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 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkGraphics.h" 14 #include "SkGraphics.h"
15 #include "SkImageDecoder.h" 15 #include "SkImageDecoder.h"
16 #include "SkPath.h" 16 #include "SkPath.h"
17 #include "SkRandom.h" 17 #include "SkRandom.h"
18 #include "SkRegion.h" 18 #include "SkRegion.h"
19 #include "SkShader.h" 19 #include "SkShader.h"
20 #include "SkUtils.h" 20 #include "SkUtils.h"
21 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
22 #include "SkColorFilter.h" 22 #include "SkColorFilter.h"
23 #include "SkTime.h" 23 #include "SkTime.h"
24 #include "SkTypeface.h" 24 #include "SkTypeface.h"
25 #include "SkXfermode.h" 25 #include "SkXfermode.h"
26 26
27 #include "SkStream.h" 27 #include "SkStream.h"
28 #include "SkXMLParser.h" 28 #include "SkXMLParser.h"
29 29
30 static void test_breakText() {
31 SkPaint paint;
32 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj";
33 size_t length = strlen(text);
34 SkScalar width = paint.measureText(text, length);
35
36 SkScalar mm = 0;
37 SkScalar nn = 0;
38 for (SkScalar w = 0; w <= width; w += SK_Scalar1) {
39 SkScalar m;
40 size_t n = paint.breakText(text, length, w, &m);
41
42 SkASSERT(n <= length);
43 SkASSERT(m <= width);
44
45 if (n == 0) {
46 SkASSERT(m == 0);
47 } else {
48 // now assert that we're monotonic
49 if (n == nn) {
50 SkASSERT(m == mm);
51 } else {
52 SkASSERT(n > nn);
53 SkASSERT(m > mm);
54 }
55 }
56 nn = SkIntToScalar((unsigned int)n);
57 mm = m;
58 }
59
60 SkDEBUGCODE(size_t length2 =) paint.breakText(text, length, width, &mm);
61 SkASSERT(length2 == length);
62 SkASSERT(mm == width);
63 }
64
30 static const struct { 65 static const struct {
31 const char* fName; 66 const char* fName;
32 uint32_t fFlags; 67 uint32_t fFlags;
33 bool fFlushCache; 68 bool fFlushCache;
34 } gHints[] = { 69 } gHints[] = {
35 { "Linear", SkPaint::kLinearText_Flag, false }, 70 { "Linear", SkPaint::kLinearText_Flag, false },
36 { "Normal", 0, true }, 71 { "Normal", 0, true },
37 { "Subpixel", SkPaint::kSubpixelText_Flag, true } 72 { "Subpixel", SkPaint::kSubpixelText_Flag, true }
38 }; 73 };
39 74
(...skipping 27 matching lines...) Expand all
67 canvas->drawText(text, length, x, y, p); 102 canvas->drawText(text, length, x, y, p);
68 } 103 }
69 #endif 104 #endif
70 } 105 }
71 106
72 class TextSpeedView : public SampleView { 107 class TextSpeedView : public SampleView {
73 public: 108 public:
74 TextSpeedView() { 109 TextSpeedView() {
75 fHints = 0; 110 fHints = 0;
76 fClickX = 0; 111 fClickX = 0;
112
113 test_breakText();
77 } 114 }
78 115
79 protected: 116 protected:
80 // overrides from SkEventSink 117 // overrides from SkEventSink
81 bool onQuery(SkEvent* evt) override { 118 bool onQuery(SkEvent* evt) override {
82 if (SampleCode::TitleQ(*evt)) { 119 if (SampleCode::TitleQ(*evt)) {
83 SampleCode::TitleR(evt, "Text"); 120 SampleCode::TitleR(evt, "Text");
84 return true; 121 return true;
85 } 122 }
86 return this->INHERITED::onQuery(evt); 123 return this->INHERITED::onQuery(evt);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 int fHints; 200 int fHints;
164 SkScalar fClickX; 201 SkScalar fClickX;
165 202
166 typedef SampleView INHERITED; 203 typedef SampleView INHERITED;
167 }; 204 };
168 205
169 ////////////////////////////////////////////////////////////////////////////// 206 //////////////////////////////////////////////////////////////////////////////
170 207
171 static SkView* MyFactory() { return new TextSpeedView; } 208 static SkView* MyFactory() { return new TextSpeedView; }
172 static SkViewRegister reg(MyFactory); 209 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkRect.h ('k') | src/core/SkBitmapFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698