blob: d86d332e295dff1e00eaf0d8b2d477196f6cfe1d [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"
Kevin Lubickbca43ec2023-10-30 10:11:22 -040015#include "tools/fonts/FontToolUtils.h"
halcanary39f988e2016-07-15 12:54:30 -070016
Ben Wagner7fde8e12019-05-01 17:28:53 -040017#include <string.h>
18
halcanary39f988e2016-07-15 12:54:30 -070019// https://bugs.skia.org/5321
20// two strings should draw the same. PDF did not.
21DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
Kevin Lubickbca43ec2023-10-30 10:11:22 -040022 SkFont font = ToolUtils::DefaultPortableFont();
Mike Reed088b74e2018-12-24 14:52:46 -050023 font.setEdging(SkFont::Edging::kAlias);
24 font.setSize(30);
Ben Wagner63fd7602017-10-09 15:45:33 -040025
halcanary39f988e2016-07-15 12:54:30 -070026 const char text[] = "x\314\200y"; // utf8(u"x\u0300y")
27 SkScalar x = 20, y = 45;
Ben Wagner63fd7602017-10-09 15:45:33 -040028
Mike Reed088b74e2018-12-24 14:52:46 -050029 size_t byteLength = strlen(text);
Ben Wagner51e15a62019-05-07 15:38:46 -040030 canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint());
Mike Reed088b74e2018-12-24 14:52:46 -050031
32 y += font.getMetrics(nullptr);
Ben Wagner51e15a62019-05-07 15:38:46 -040033 int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8);
Mike Reed088b74e2018-12-24 14:52:46 -050034 SkTextBlobBuilder builder;
35
36 auto rec = builder.allocRunPosH(font, glyph_count, y);
Ben Wagner51e15a62019-05-07 15:38:46 -040037 font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count);
Mike Reed088b74e2018-12-24 14:52:46 -050038
39 font.getWidths(rec.glyphs, glyph_count, rec.pos);
halcanary39f988e2016-07-15 12:54:30 -070040 for (int i = 0; i < glyph_count; ++i) {
Mike Reed088b74e2018-12-24 14:52:46 -050041 SkScalar w = rec.pos[i];
42 rec.pos[i] = x;
halcanary39f988e2016-07-15 12:54:30 -070043 x += w;
44 }
Mike Reed088b74e2018-12-24 14:52:46 -050045
46 canvas->drawTextBlob(builder.make(), 0, 0, SkPaint());
halcanary39f988e2016-07-15 12:54:30 -070047}