| 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 "SkTextBlob.h" |
| 23 #include "SkTime.h" | 24 #include "SkTime.h" |
| 24 #include "SkTypeface.h" | 25 #include "SkTypeface.h" |
| 25 #include "SkXfermode.h" | 26 #include "SkXfermode.h" |
| 26 | 27 |
| 27 #include "SkStream.h" | 28 #include "SkStream.h" |
| 28 #include "SkXMLParser.h" | 29 #include "SkXMLParser.h" |
| 29 | 30 |
| 30 static void test_breakText() { | 31 static void test_breakText() { |
| 31 SkPaint paint; | 32 SkPaint paint; |
| 32 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; | 33 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 bool fFlushCache; | 70 bool fFlushCache; |
| 70 } gHints[] = { | 71 } gHints[] = { |
| 71 { "Linear", SkPaint::kLinearText_Flag, false }, | 72 { "Linear", SkPaint::kLinearText_Flag, false }, |
| 72 { "Normal", 0, true }, | 73 { "Normal", 0, true }, |
| 73 { "Subpixel", SkPaint::kSubpixelText_Flag, true } | 74 { "Subpixel", SkPaint::kSubpixelText_Flag, true } |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
alar x, SkScalar y, | 77 static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
alar x, SkScalar y, |
| 77 const SkPaint& paint, SkScalar clickX) { | 78 const SkPaint& paint, SkScalar clickX) { |
| 78 SkPaint p(paint); | 79 SkPaint p(paint); |
| 80 SkPoint pts[1000]; |
| 81 SkASSERT(length <= SK_ARRAY_COUNT(pts)); |
| 79 | 82 |
| 80 #if 0 | 83 #if 0 |
| 81 canvas->drawText(text, length, x, y, paint); | 84 canvas->drawText(text, length, x, y, paint); |
| 82 #else | 85 #else |
| 83 { | 86 { |
| 84 SkPoint pts[1000]; | |
| 85 SkScalar xpos = x; | 87 SkScalar xpos = x; |
| 86 SkASSERT(length <= SK_ARRAY_COUNT(pts)); | |
| 87 for (size_t i = 0; i < length; i++) { | 88 for (size_t i = 0; i < length; i++) { |
| 88 pts[i].set(xpos, y), xpos += paint.getTextSize(); | 89 pts[i].set(xpos, y), xpos += paint.getTextSize(); |
| 89 } | 90 } |
| 90 canvas->drawPosText(text, length, pts, paint); | 91 canvas->drawPosText(text, length, pts, paint); |
| 91 } | 92 } |
| 92 #endif | 93 #endif |
| 93 | 94 |
| 94 p.setSubpixelText(true); | 95 p.setSubpixelText(true); |
| 95 x += SkIntToScalar(180); | 96 x += SkIntToScalar(180); |
| 96 canvas->drawText(text, length, x, y, p); | 97 canvas->drawText(text, length, x, y, p); |
| 97 | 98 |
| 98 #ifdef SK_DEBUG | 99 #ifdef SK_DEBUG |
| 99 if (true) { | 100 if (true) { |
| 100 p.setSubpixelText(false); | 101 p.setSubpixelText(false); |
| 101 p.setLinearText(true); | 102 p.setLinearText(true); |
| 102 x += SkIntToScalar(180); | 103 x += SkIntToScalar(180); |
| 103 canvas->drawText(text, length, x, y, p); | 104 canvas->drawText(text, length, x, y, p); |
| 104 } | 105 } |
| 105 #endif | 106 #endif |
| 107 |
| 108 |
| 109 uint16_t glyphs[1000]; |
| 110 SkASSERT(length <= SK_ARRAY_COUNT(glyphs)); |
| 111 int glyphCount = paint.textToGlyphs(text, length, glyphs); |
| 112 SkPaint glyphPaint = paint; |
| 113 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 114 |
| 115 SkTextBlobBuilder blobBuilder; |
| 116 SkTextBlobBuilder::RunBuilder<SkTextBlob::kFull_Positioning> posRunBuilder = |
| 117 blobBuilder.startRun<SkTextBlob::kFull_Positioning>(glyphPaint, glyp
hCount); |
| 118 for (int i = 0; i < glyphCount; ++i) { |
| 119 posRunBuilder.addGlyph(glyphs[i], pts[i].x(), pts[i].y()); |
| 120 } |
| 121 SkAutoTUnref<const SkTextBlob> posBlob(blobBuilder.build()); |
| 122 canvas->drawTextBlob(posBlob, 0, 400, glyphPaint); |
| 123 |
| 124 glyphPaint.setSubpixelText(true); |
| 125 SkTextBlobBuilder::RunBuilder<SkTextBlob::kDefault_Positioning> runBuilder = |
| 126 blobBuilder.startRun<SkTextBlob::kDefault_Positioning>(glyphPaint, g
lyphCount); |
| 127 runBuilder.addGlyphs(glyphs, glyphCount); |
| 128 SkAutoTUnref<const SkTextBlob> blob(blobBuilder.build()); |
| 129 canvas->drawTextBlob(blob, 180, 400 + y, glyphPaint); |
| 130 |
| 131 glyphPaint.setSubpixelText(false); |
| 132 glyphPaint.setLinearText(true); |
| 133 SkTextBlobBuilder::RunBuilder<SkTextBlob::kHorizontal_Positioning> hPosRunBu
ilder = |
| 134 blobBuilder.startRun<SkTextBlob::kHorizontal_Positioning>(glyphPaint
, glyphCount); |
| 135 for (int i = 0; i < glyphCount; ++i) { |
| 136 hPosRunBuilder.addGlyph(glyphs[i], pts[i].x()); |
| 137 } |
| 138 SkAutoTUnref<const SkTextBlob> hPosBlob(blobBuilder.build()); |
| 139 canvas->drawTextBlob(hPosBlob, 360, 400 + y, glyphPaint); |
| 106 } | 140 } |
| 107 | 141 |
| 108 class TextSpeedView : public SampleView { | 142 class TextSpeedView : public SampleView { |
| 109 public: | 143 public: |
| 110 TextSpeedView() { | 144 TextSpeedView() { |
| 111 fHints = 0; | 145 fHints = 0; |
| 112 fClickX = 0; | 146 fClickX = 0; |
| 113 | 147 |
| 114 test_breakText(); | 148 test_breakText(); |
| 115 } | 149 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int fHints; | 235 int fHints; |
| 202 SkScalar fClickX; | 236 SkScalar fClickX; |
| 203 | 237 |
| 204 typedef SampleView INHERITED; | 238 typedef SampleView INHERITED; |
| 205 }; | 239 }; |
| 206 | 240 |
| 207 ////////////////////////////////////////////////////////////////////////////// | 241 ////////////////////////////////////////////////////////////////////////////// |
| 208 | 242 |
| 209 static SkView* MyFactory() { return new TextSpeedView; } | 243 static SkView* MyFactory() { return new TextSpeedView; } |
| 210 static SkViewRegister reg(MyFactory); | 244 static SkViewRegister reg(MyFactory); |
| OLD | NEW |