halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkTextBlob.h" |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 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) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 14 | SkFont font; |
| 15 | font.setEdging(SkFont::Edging::kAlias); |
| 16 | font.setSize(30); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 17 | |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 18 | const char text[] = "x\314\200y"; // utf8(u"x\u0300y") |
| 19 | SkScalar x = 20, y = 45; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 20 | |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 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); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 32 | for (int i = 0; i < glyph_count; ++i) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 33 | SkScalar w = rec.pos[i]; |
| 34 | rec.pos[i] = x; |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 35 | x += w; |
| 36 | } |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 37 | |
| 38 | canvas->drawTextBlob(builder.make(), 0, 0, SkPaint()); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 39 | } |