blob: 73fb268a1c99d95bd1efdac4fd5d841286e954a4 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/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}