Flutter Engine
The Flutter Engine
skbug_5321.cpp
Go to the documentation of this file.
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"
10#include "include/core/SkFont.h"
16
17#include <string.h>
18
19// https://bugs.skia.org/5321
20// two strings should draw the same. PDF did not.
21DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
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 int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8);
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);
40 for (int 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}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
double x
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
SkScalar w
DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128)
Definition: skbug_5321.cpp:21