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" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkTextBlob.h" |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 15 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 16 | #include <string.h> |
| 17 | |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 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) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 21 | SkFont font; |
| 22 | font.setEdging(SkFont::Edging::kAlias); |
| 23 | font.setSize(30); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 24 | |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 25 | const char text[] = "x\314\200y"; // utf8(u"x\u0300y") |
| 26 | SkScalar x = 20, y = 45; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 27 | |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 28 | size_t byteLength = strlen(text); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 29 | canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint()); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 30 | |
| 31 | y += font.getMetrics(nullptr); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 32 | int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 33 | SkTextBlobBuilder builder; |
| 34 | |
| 35 | auto rec = builder.allocRunPosH(font, glyph_count, y); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 36 | font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 37 | |
| 38 | font.getWidths(rec.glyphs, glyph_count, rec.pos); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 39 | for (int i = 0; i < glyph_count; ++i) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 40 | SkScalar w = rec.pos[i]; |
| 41 | rec.pos[i] = x; |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 42 | x += w; |
| 43 | } |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 44 | |
| 45 | canvas->drawTextBlob(builder.make(), 0, 0, SkPaint()); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 46 | } |