Debian Codegraph @

gm/skbug_5321.cpp

raw
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 #include "tools/fonts/FontToolUtils.h"
16
17 #include <string.h>
18
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) {
22 SkFont font = ToolUtils::DefaultPortableFont();
23 font.setEdging(SkFont::Edging::kAlias);
24 font.setSize(30);
25
26 const char text[] = "x\314\200y"; // utf8(u"x\u0300y")
27 SkScalar x = 20, y = 45;
28
29 size_t byteLength = strlen(text);
30 canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint());
31
32 y += font.getMetrics(nullptr);
33 size_t glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8);
34 SkTextBlobBuilder builder;
35
36 auto rec = builder.allocRunPosH(font, glyph_count, y);
37 font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, {rec.glyphs, glyph_count});
38
39 font.getWidths({rec.glyphs, glyph_count}, {rec.pos, glyph_count});
40 for (size_t i = 0; i < glyph_count; ++i) {
41 SkScalar w = rec.pos[i];
42 rec.pos[i] = x;
43 x += w;
44 }
45
46 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint());
47 }