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 #include "SkTextBlob.h" 10 11 // https://bugs.skia.org/5321 12 // two strings should draw the same. PDF did not. 13 DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) { 14 SkFont font; 15 font.setEdging(SkFont::Edging::kAlias); 16 font.setSize(30); 17 18 const char text[] = "x\314\200y"; // utf8(u"x\u0300y") 19 SkScalar x = 20, y = 45; 20 21 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); 32 for (int i = 0; i < glyph_count; ++i) { 33 SkScalar w = rec.pos[i]; 34 rec.pos[i] = x; 35 x += w; 36 } 37 38 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint()); 39 } 40