OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "sk_tool_utils_flags.h" | 9 #include "sk_tool_utils_flags.h" |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "SkTestScalerContext.h" | 14 #include "SkTestScalerContext.h" |
| 15 #include "SkTextBlob.h" |
15 | 16 |
16 DEFINE_bool(portableFonts, false, "Use portable fonts"); | 17 DEFINE_bool(portableFonts, false, "Use portable fonts"); |
17 DEFINE_bool(resourceFonts, false, "Use resource fonts"); | 18 DEFINE_bool(resourceFonts, false, "Use resource fonts"); |
18 | 19 |
19 namespace sk_tool_utils { | 20 namespace sk_tool_utils { |
20 | 21 |
21 const char* colortype_name(SkColorType ct) { | 22 const char* colortype_name(SkColorType ct) { |
22 switch (ct) { | 23 switch (ct) { |
23 case kUnknown_SkColorType: return "Unknown"; | 24 case kUnknown_SkColorType: return "Unknown"; |
24 case kAlpha_8_SkColorType: return "Alpha_8"; | 25 case kAlpha_8_SkColorType: return "Alpha_8"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 71 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
71 } | 72 } |
72 | 73 |
73 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { | 74 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { |
74 SkPaint paint; | 75 SkPaint paint; |
75 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref(); | 76 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref(); |
76 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 77 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
77 canvas->drawPaint(paint); | 78 canvas->drawPaint(paint); |
78 } | 79 } |
79 | 80 |
| 81 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPain
t& origPaint, |
| 82 SkScalar x, SkScalar y) { |
| 83 SkPaint paint(origPaint); |
| 84 SkTDArray<uint16_t> glyphs; |
| 85 |
| 86 size_t len = strlen(text); |
| 87 glyphs.append(paint.textToGlyphs(text, len, NULL)); |
| 88 paint.textToGlyphs(text, len, glyphs.begin()); |
| 89 |
| 90 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 91 const SkTextBlobBuilder::RunBuffer& run = builder->allocRun(paint, glyphs.co
unt(), x, y, |
| 92 NULL); |
| 93 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); |
| 94 } |
| 95 |
| 96 |
80 } // namespace sk_tool_utils | 97 } // namespace sk_tool_utils |
OLD | NEW |