Flutter Engine
The Flutter Engine
SkTextUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
9
11#include "include/core/SkFont.h"
13#include "include/core/SkPath.h"
18#include "src/core/SkFontPriv.h"
19
20using namespace skia_private;
21
22class SkPaint;
23
24void SkTextUtils::Draw(SkCanvas* canvas, const void* text, size_t size, SkTextEncoding encoding,
25 SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint,
26 Align align) {
27 if (align != kLeft_Align) {
28 SkScalar width = font.measureText(text, size, encoding);
29 if (align == kCenter_Align) {
30 width *= 0.5f;
31 }
32 x -= width;
33 }
34
35 canvas->drawTextBlob(SkTextBlob::MakeFromText(text, size, font, encoding), x, y, paint);
36}
37
38void SkTextUtils::GetPath(const void* text, size_t length, SkTextEncoding encoding,
40 SkAutoToGlyphs ag(font, text, length, encoding);
42 font.getPos(ag.glyphs(), ag.count(), pos.get(), {x, y});
43
44 struct Rec {
45 SkPath* fDst;
46 const SkPoint* fPos;
47 } rec = { path, pos.get() };
48
49 path->reset();
50 font.getPaths(ag.glyphs(), ag.count(), [](const SkPath* src, const SkMatrix& mx, void* ctx) {
51 Rec* rec = (Rec*)ctx;
52 if (src) {
53 SkMatrix m(mx);
54 m.postTranslate(rec->fPos->fX, rec->fPos->fY);
55 rec->fDst->addPath(*src, m);
56 }
57 rec->fPos += 1;
58 }, &rec);
59}
60
SkPoint pos
SkRect fDst
Definition: LatticeOp.cpp:381
SkTextEncoding
Definition: SkFontTypes.h:11
int count() const
Definition: SkFontPriv.h:110
const uint16_t * glyphs() const
Definition: SkFontPriv.h:111
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
Definition: SkPath.h:59
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.cpp:788
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
Definition: SkTextUtils.cpp:38
static void Draw(SkCanvas *, const void *text, size_t size, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, const SkPaint &, Align=kLeft_Align)
Definition: SkTextUtils.cpp:24
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
size_t length
std::u16string text
double y
double x
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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
int32_t width