Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
getpostextpath.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
11#include "include/core/SkFont.h"
14#include "include/core/SkPath.h"
20#include "src/base/SkRandom.h"
21#include "src/core/SkFontPriv.h"
22#include "tools/ToolUtils.h"
24
25#include <string.h>
26
27using namespace skia_private;
28
29static void strokePath(SkCanvas* canvas, const SkPath& path) {
31 paint.setAntiAlias(true);
32 paint.setColor(SK_ColorRED);
34 canvas->drawPath(path, paint);
35}
36DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780) {
37 // explicitly add spaces, to test a prev. bug
38 const char* text = "Ham bur ge fons";
39 size_t len = strlen(text);
40 SkPath path;
41
43 font.setSize(48);
44
46 paint.setAntiAlias(true);
47
48 canvas->translate(SkIntToScalar(10), SkIntToScalar(64));
49
50 canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, 0, 0, font, paint);
51 ToolUtils::get_text_path(font, text, len, SkTextEncoding::kUTF8, &path, nullptr);
52 strokePath(canvas, path);
53 path.reset();
54
56 const int count = atg.count();
59 font.getWidths(atg.glyphs(), count, &widths[0]);
60
61 SkRandom rand;
64 for (int i = 0; i < count; ++i) {
65 pos[i].set(x, y + rand.nextSScalar1() * 24);
66 x += widths[i];
67 }
68
69 canvas->translate(0, SkIntToScalar(64));
70
71 canvas->drawTextBlob(SkTextBlob::MakeFromPosText(text, len, &pos[0], font), 0, 0, paint);
73 strokePath(canvas, path);
74}
int count
SkPoint pos
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition SkScalar.h:57
const SkScalar widths[]
int count() const
Definition SkFontPriv.h:110
const uint16_t * glyphs() const
Definition SkFontPriv.h:111
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkScalar nextSScalar1()
Definition SkRandom.h:113
static sk_sp< SkTextBlob > MakeFromPosText(const void *text, size_t byteLength, const SkPoint pos[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
const Paint & paint
float SkScalar
Definition extension.cpp:12
static void strokePath(SkCanvas *canvas, const SkPath &path)
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
std::u16string text
double y
double x
SkFont DefaultPortableFont()
void get_text_path(const SkFont &font, const void *text, size_t length, SkTextEncoding encoding, SkPath *dst, const SkPoint pos[])
void set(float x, float y)