Flutter Engine
The Flutter Engine
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);
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);
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
Definition: FontMgrTest.cpp:50
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[]
Definition: StrokerTest.cpp:39
int count() const
Definition: SkFontPriv.h:110
const uint16_t * glyphs() const
Definition: SkFontPriv.h:111
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
Definition: SkFont.h:35
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
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)
Definition: SkTextBlob.cpp:803
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static void strokePath(SkCanvas *canvas, const SkPath &path)
DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780)
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[])
Definition: ToolUtils.cpp:236
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
font
Font Metadata and Metrics.
void set(float x, float y)
Definition: SkPoint_impl.h:200