blob: 740c4f4b24a8cb863dadb4e074c8870f562a814e [file] [log] [blame]
halcanary39f988e2016-07-15 12:54:30 -07001/*
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.
12DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
13 SkPaint paint;
14 paint.setStyle(SkPaint::kFill_Style);
15 paint.setTextSize(30);
Ben Wagner63fd7602017-10-09 15:45:33 -040016
halcanary39f988e2016-07-15 12:54:30 -070017 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);
Ben Wagner63fd7602017-10-09 15:45:33 -040022
halcanary39f988e2016-07-15 12:54:30 -070023 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}