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 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) { | 181 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) { |
182 SkBitmap bm; | 182 SkBitmap bm; |
183 bm.allocN32Pixels(2 * size, 2 * size); | 183 bm.allocN32Pixels(2 * size, 2 * size); |
184 bm.eraseColor(c1); | 184 bm.eraseColor(c1); |
185 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); | 185 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); |
186 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); | 186 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); |
187 return SkShader::CreateBitmapShader( | 187 return SkShader::CreateBitmapShader( |
188 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 188 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
189 } | 189 } |
190 | 190 |
| 191 SkBitmap create_checkerboard_bitmap(int w, int h, SkColor c1, SkColor c2, int ch
eckSize) { |
| 192 SkBitmap bitmap; |
| 193 bitmap.allocN32Pixels(w, h); |
| 194 SkCanvas canvas(bitmap); |
| 195 |
| 196 sk_tool_utils::draw_checkerboard(&canvas, c1, c2, checkSize); |
| 197 return bitmap; |
| 198 } |
| 199 |
191 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { | 200 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { |
192 SkPaint paint; | 201 SkPaint paint; |
193 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref(); | 202 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref(); |
194 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 203 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
195 canvas->drawPaint(paint); | 204 canvas->drawPaint(paint); |
196 } | 205 } |
197 | 206 |
| 207 SkBitmap create_string_bitmap(int w, int h, SkColor c, int x, int y, |
| 208 int textSize, const char* str) { |
| 209 SkBitmap bitmap; |
| 210 bitmap.allocN32Pixels(w, h); |
| 211 SkCanvas canvas(bitmap); |
| 212 |
| 213 SkPaint paint; |
| 214 paint.setAntiAlias(true); |
| 215 sk_tool_utils::set_portable_typeface(&paint); |
| 216 paint.setColor(c); |
| 217 paint.setTextSize(SkIntToScalar(textSize)); |
| 218 |
| 219 canvas.clear(0x00000000); |
| 220 canvas.drawText(str, strlen(str), SkIntToScalar(x), SkIntToScalar(y), paint)
; |
| 221 |
| 222 return bitmap; |
| 223 } |
| 224 |
198 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPain
t& origPaint, | 225 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPain
t& origPaint, |
199 SkScalar x, SkScalar y) { | 226 SkScalar x, SkScalar y) { |
200 SkPaint paint(origPaint); | 227 SkPaint paint(origPaint); |
201 SkTDArray<uint16_t> glyphs; | 228 SkTDArray<uint16_t> glyphs; |
202 | 229 |
203 size_t len = strlen(text); | 230 size_t len = strlen(text); |
204 glyphs.append(paint.textToGlyphs(text, len, nullptr)); | 231 glyphs.append(paint.textToGlyphs(text, len, nullptr)); |
205 paint.textToGlyphs(text, len, glyphs.begin()); | 232 paint.textToGlyphs(text, len, glyphs.begin()); |
206 | 233 |
207 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 234 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 norm = leftUp; | 339 norm = leftUp; |
313 } | 340 } |
314 } | 341 } |
315 | 342 |
316 norm_to_rgb(bm, x, y, norm); | 343 norm_to_rgb(bm, x, y, norm); |
317 } | 344 } |
318 } | 345 } |
319 } | 346 } |
320 | 347 |
321 } // namespace sk_tool_utils | 348 } // namespace sk_tool_utils |
OLD | NEW |