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" |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 15 | #include "tools/fonts/FontToolUtils.h" |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 16 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 17 | #include <string.h> |
| 18 | |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 19 | // https://bugs.skia.org/5321 |
| 20 | // two strings should draw the same. PDF did not. |
| 21 | DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) { |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 22 | SkFont font = ToolUtils::DefaultPortableFont(); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 23 | font.setEdging(SkFont::Edging::kAlias); |
| 24 | font.setSize(30); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 25 | |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 26 | const char text[] = "x\314\200y"; // utf8(u"x\u0300y") |
| 27 | SkScalar x = 20, y = 45; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 28 | |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 29 | size_t byteLength = strlen(text); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 30 | canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint()); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 31 | |
| 32 | y += font.getMetrics(nullptr); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 33 | int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 34 | SkTextBlobBuilder builder; |
| 35 | |
| 36 | auto rec = builder.allocRunPosH(font, glyph_count, y); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 37 | font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 38 | |
| 39 | font.getWidths(rec.glyphs, glyph_count, rec.pos); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 40 | for (int i = 0; i < glyph_count; ++i) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 41 | SkScalar w = rec.pos[i]; |
| 42 | rec.pos[i] = x; |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 43 | x += w; |
| 44 | } |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 45 | |
| 46 | canvas->drawTextBlob(builder.make(), 0, 0, SkPaint()); |
halcanary | 39f988e | 2016-07-15 12:54:30 -0700 | [diff] [blame] | 47 | } |