blob: e389cbc03bc8801ce816d498a36c5cbaafc4c2fa [file] [log] [blame]
halcanary39f988e2016-07-15 12:54:30 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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 Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkTextBlob.h"
halcanary39f988e2016-07-15 12:54:30 -070015
Ben Wagner7fde8e12019-05-01 17:28:53 -040016#include <string.h>
17
halcanary39f988e2016-07-15 12:54:30 -070018// https://bugs.skia.org/5321
19// two strings should draw the same. PDF did not.
20DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
Mike Reed088b74e2018-12-24 14:52:46 -050021 SkFont font;
22 font.setEdging(SkFont::Edging::kAlias);
23 font.setSize(30);
Ben Wagner63fd7602017-10-09 15:45:33 -040024
halcanary39f988e2016-07-15 12:54:30 -070025 const char text[] = "x\314\200y"; // utf8(u"x\u0300y")
26 SkScalar x = 20, y = 45;
Ben Wagner63fd7602017-10-09 15:45:33 -040027
Mike Reed088b74e2018-12-24 14:52:46 -050028 size_t byteLength = strlen(text);
Ben Wagner51e15a62019-05-07 15:38:46 -040029 canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint());
Mike Reed088b74e2018-12-24 14:52:46 -050030
31 y += font.getMetrics(nullptr);
Ben Wagner51e15a62019-05-07 15:38:46 -040032 int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8);
Mike Reed088b74e2018-12-24 14:52:46 -050033 SkTextBlobBuilder builder;
34
35 auto rec = builder.allocRunPosH(font, glyph_count, y);
Ben Wagner51e15a62019-05-07 15:38:46 -040036 font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count);
Mike Reed088b74e2018-12-24 14:52:46 -050037
38 font.getWidths(rec.glyphs, glyph_count, rec.pos);
halcanary39f988e2016-07-15 12:54:30 -070039 for (int i = 0; i < glyph_count; ++i) {
Mike Reed088b74e2018-12-24 14:52:46 -050040 SkScalar w = rec.pos[i];
41 rec.pos[i] = x;
halcanary39f988e2016-07-15 12:54:30 -070042 x += w;
43 }
Mike Reed088b74e2018-12-24 14:52:46 -050044
45 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint());
halcanary39f988e2016-07-15 12:54:30 -070046}