| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 79 | 80 |
| 81 uint16_t glyphs[1000]; |
| 82 SkASSERT(length <= SK_ARRAY_COUNT(glyphs)); |
| 83 int glyphCount = paint.textToGlyphs(text, length, glyphs); |
| 84 SkPaint glyphPaint = paint; |
| 85 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 86 SkTextBlobBuilder blobBuilder; |
| 87 |
| 80 #if 0 | 88 #if 0 |
| 81 canvas->drawText(text, length, x, y, paint); | 89 canvas->drawText(text, length, x, y, paint); |
| 82 #else | 90 #else |
| 83 { | 91 { |
| 84 SkPoint pts[1000]; | 92 SkPoint pts[1000]; |
| 85 SkScalar xpos = x; | 93 SkScalar xpos = x; |
| 86 SkASSERT(length <= SK_ARRAY_COUNT(pts)); | 94 SkASSERT(length <= SK_ARRAY_COUNT(pts)); |
| 87 for (size_t i = 0; i < length; i++) { | 95 for (size_t i = 0; i < length; i++) { |
| 88 pts[i].set(xpos, y), xpos += paint.getTextSize(); | 96 pts[i].set(xpos, y), xpos += paint.getTextSize(); |
| 89 } | 97 } |
| 90 canvas->drawPosText(text, length, pts, paint); | 98 canvas->drawPosText(text, length, pts, paint); |
| 99 |
| 100 SkAutoTUnref<const SkTextBlob> blob(SkTextBlob::Create( |
| 101 SkTextChunk::Create(glyphs, glyphCount, pt
s, glyphPaint))); |
| 102 canvas->drawTextBlob(blob, SkPoint::Make(0, 400), glyphPaint); |
| 103 |
| 91 } | 104 } |
| 92 #endif | 105 #endif |
| 93 | 106 |
| 94 p.setSubpixelText(true); | 107 p.setSubpixelText(true); |
| 95 x += SkIntToScalar(180); | 108 x += SkIntToScalar(180); |
| 96 canvas->drawText(text, length, x, y, p); | 109 canvas->drawText(text, length, x, y, p); |
| 97 | 110 |
| 111 { |
| 112 glyphPaint.setSubpixelText(true); |
| 113 SkAutoTUnref<const SkTextBlob> blob(SkTextBlob::Create( |
| 114 SkTextChunk::Create(glyphs, glyphCount, glyphP
aint))); |
| 115 canvas->drawTextBlob(blob, SkPoint::Make(x, y + 400), glyphPaint); |
| 116 } |
| 117 |
| 98 #ifdef SK_DEBUG | 118 #ifdef SK_DEBUG |
| 99 if (true) { | 119 if (true) { |
| 100 p.setSubpixelText(false); | 120 p.setSubpixelText(false); |
| 101 p.setLinearText(true); | 121 p.setLinearText(true); |
| 102 x += SkIntToScalar(180); | 122 x += SkIntToScalar(180); |
| 103 canvas->drawText(text, length, x, y, p); | 123 canvas->drawText(text, length, x, y, p); |
| 104 } | 124 } |
| 105 #endif | 125 #endif |
| 106 } | 126 } |
| 107 | 127 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int fHints; | 221 int fHints; |
| 202 SkScalar fClickX; | 222 SkScalar fClickX; |
| 203 | 223 |
| 204 typedef SampleView INHERITED; | 224 typedef SampleView INHERITED; |
| 205 }; | 225 }; |
| 206 | 226 |
| 207 ////////////////////////////////////////////////////////////////////////////// | 227 ////////////////////////////////////////////////////////////////////////////// |
| 208 | 228 |
| 209 static SkView* MyFactory() { return new TextSpeedView; } | 229 static SkView* MyFactory() { return new TextSpeedView; } |
| 210 static SkViewRegister reg(MyFactory); | 230 static SkViewRegister reg(MyFactory); |
| OLD | NEW |