halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | |
| 10 | // https://bugs.skia.org/5321 |
| 11 | // two strings should draw the same. PDF did not. |
| 12 | DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) { |
| 13 | SkPaint paint; |
| 14 | paint.setStyle(SkPaint::kFill_Style); |
| 15 | paint.setTextSize(30); |
| 16 | |
| 17 | paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| 18 | const char text[] = "x\314\200y"; // utf8(u"x\u0300y") |
| 19 | SkScalar x = 20, y = 45; |
| 20 | size_t byteLength = strlen(text); |
| 21 | canvas->drawText(text, byteLength, x, y, paint); |
| 22 | |
| 23 | int glyph_count = paint.countText(text, byteLength); |
| 24 | SkAutoTMalloc<SkScalar> widths(glyph_count); |
| 25 | (void)paint.getTextWidths(text, byteLength, &widths[0]); |
| 26 | for (int i = 0; i < glyph_count; ++i) { |
| 27 | SkScalar w = widths[i]; |
| 28 | widths[i] = x; |
| 29 | x += w; |
| 30 | } |
| 31 | y += paint.getFontMetrics(nullptr); |
| 32 | canvas->drawPosTextH(text, byteLength, &widths[0], y, paint); |
| 33 | } |