blob: 00021c8e6ef7c88b00148dfb44185be912705d4d [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"
Mike Reed088b74e2018-12-24 14:52:46 -05009#include "SkTextBlob.h"
halcanary39f988e2016-07-15 12:54:30 -070010
11// https://bugs.skia.org/5321
12// two strings should draw the same. PDF did not.
13DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
Mike Reed088b74e2018-12-24 14:52:46 -050014 SkFont font;
15 font.setEdging(SkFont::Edging::kAlias);
16 font.setSize(30);
Ben Wagner63fd7602017-10-09 15:45:33 -040017
halcanary39f988e2016-07-15 12:54:30 -070018 const char text[] = "x\314\200y"; // utf8(u"x\u0300y")
19 SkScalar x = 20, y = 45;
Ben Wagner63fd7602017-10-09 15:45:33 -040020
Mike Reed088b74e2018-12-24 14:52:46 -050021 size_t byteLength = strlen(text);
22 canvas->drawSimpleText(text, byteLength, kUTF8_SkTextEncoding, x, y, font, SkPaint());
23
24 y += font.getMetrics(nullptr);
25 int glyph_count = font.countText(text, byteLength, kUTF8_SkTextEncoding);
26 SkTextBlobBuilder builder;
27
28 auto rec = builder.allocRunPosH(font, glyph_count, y);
29 font.textToGlyphs(text, byteLength, kUTF8_SkTextEncoding, rec.glyphs, glyph_count);
30
31 font.getWidths(rec.glyphs, glyph_count, rec.pos);
halcanary39f988e2016-07-15 12:54:30 -070032 for (int i = 0; i < glyph_count; ++i) {
Mike Reed088b74e2018-12-24 14:52:46 -050033 SkScalar w = rec.pos[i];
34 rec.pos[i] = x;
halcanary39f988e2016-07-15 12:54:30 -070035 x += w;
36 }
Mike Reed088b74e2018-12-24 14:52:46 -050037
38 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint());
halcanary39f988e2016-07-15 12:54:30 -070039}