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/gm.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkFont.h" 11 #include "include/core/SkFontTypes.h" 12 #include "include/core/SkPaint.h" 13 #include "include/core/SkScalar.h" 14 #include "include/core/SkTextBlob.h" 15 16 #include <string.h> 17 18 // https://bugs.skia.org/5321 19 // two strings should draw the same. PDF did not. 20 DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) { 21 SkFont font; 22 font.setEdging(SkFont::Edging::kAlias); 23 font.setSize(30); 24 25 const char text[] = "x\314\200y"; // utf8(u"x\u0300y") 26 SkScalar x = 20, y = 45; 27 28 size_t byteLength = strlen(text); 29 canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint()); 30 31 y += font.getMetrics(nullptr); 32 int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8); 33 SkTextBlobBuilder builder; 34 35 auto rec = builder.allocRunPosH(font, glyph_count, y); 36 font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count); 37 38 font.getWidths(rec.glyphs, glyph_count, rec.pos); 39 for (int i = 0; i < glyph_count; ++i) { 40 SkScalar w = rec.pos[i]; 41 rec.pos[i] = x; 42 x += w; 43 } 44 45 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint()); 46 } 47