OLD | NEW |
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 | |
65 static const struct { | 30 static const struct { |
66 const char* fName; | 31 const char* fName; |
67 uint32_t fFlags; | 32 uint32_t fFlags; |
68 bool fFlushCache; | 33 bool fFlushCache; |
69 } gHints[] = { | 34 } gHints[] = { |
70 { "Linear", SkPaint::kLinearText_Flag, false }, | 35 { "Linear", SkPaint::kLinearText_Flag, false }, |
71 { "Normal", 0, true }, | 36 { "Normal", 0, true }, |
72 { "Subpixel", SkPaint::kSubpixelText_Flag, true } | 37 { "Subpixel", SkPaint::kSubpixelText_Flag, true } |
73 }; | 38 }; |
74 | 39 |
(...skipping 27 matching lines...) Expand all Loading... |
102 canvas->drawText(text, length, x, y, p); | 67 canvas->drawText(text, length, x, y, p); |
103 } | 68 } |
104 #endif | 69 #endif |
105 } | 70 } |
106 | 71 |
107 class TextSpeedView : public SampleView { | 72 class TextSpeedView : public SampleView { |
108 public: | 73 public: |
109 TextSpeedView() { | 74 TextSpeedView() { |
110 fHints = 0; | 75 fHints = 0; |
111 fClickX = 0; | 76 fClickX = 0; |
112 | |
113 test_breakText(); | |
114 } | 77 } |
115 | 78 |
116 protected: | 79 protected: |
117 // overrides from SkEventSink | 80 // overrides from SkEventSink |
118 bool onQuery(SkEvent* evt) override { | 81 bool onQuery(SkEvent* evt) override { |
119 if (SampleCode::TitleQ(*evt)) { | 82 if (SampleCode::TitleQ(*evt)) { |
120 SampleCode::TitleR(evt, "Text"); | 83 SampleCode::TitleR(evt, "Text"); |
121 return true; | 84 return true; |
122 } | 85 } |
123 return this->INHERITED::onQuery(evt); | 86 return this->INHERITED::onQuery(evt); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int fHints; | 163 int fHints; |
201 SkScalar fClickX; | 164 SkScalar fClickX; |
202 | 165 |
203 typedef SampleView INHERITED; | 166 typedef SampleView INHERITED; |
204 }; | 167 }; |
205 | 168 |
206 ////////////////////////////////////////////////////////////////////////////// | 169 ////////////////////////////////////////////////////////////////////////////// |
207 | 170 |
208 static SkView* MyFactory() { return new TextSpeedView; } | 171 static SkView* MyFactory() { return new TextSpeedView; } |
209 static SkViewRegister reg(MyFactory); | 172 static SkViewRegister reg(MyFactory); |
OLD | NEW |