Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SkFontPriv.h
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
8#ifndef SkFontPriv_DEFINED
9#define SkFontPriv_DEFINED
10
11#include "include/core/SkFont.h"
16
17class SkReadBuffer;
18class SkWriteBuffer;
19
21public:
22 /* This is the size we use when we ask for a glyph's path. We then
23 * post-transform it as we draw to match the request.
24 * This is done to try to re-use cache entries for the path.
25 *
26 * This value is somewhat arbitrary. In theory, it could be 1, since
27 * we store paths as floats. However, we get the path from the font
28 * scaler, and it may represent its paths as fixed-point (or 26.6),
29 * so we shouldn't ask for something too big (might overflow 16.16)
30 * or too small (underflow 26.6).
31 *
32 * This value could track kMaxSizeForGlyphCache, assuming the above
33 * constraints, but since we ask for unhinted paths, the two values
34 * need not match per-se.
35 */
36 inline static constexpr int kCanonicalTextSizeForPaths = 64;
37
38 /**
39 * Return a matrix that applies the paint's text values: size, scale, skew
40 */
42 SkMatrix m = SkMatrix::Scale(size * scaleX, size);
43 if (skewX) {
44 m.postSkew(skewX, 0);
45 }
46 return m;
47 }
48
50 return MakeTextMatrix(font.getSize(), font.getScaleX(), font.getSkewX());
51 }
52
54
55 /**
56 Returns the union of bounds of all glyphs.
57 Returned dimensions are computed by font manager from font data,
58 ignoring SkPaint::Hinting. Includes font metrics, but not fake bold or SkPathEffect.
59
60 If text size is large, text scale is one, and text skew is zero,
61 returns the bounds as:
62 { SkFontMetrics::fXMin, SkFontMetrics::fTop, SkFontMetrics::fXMax, SkFontMetrics::fBottom }.
63
64 @return union of bounds of all glyphs
65 */
66 static SkRect GetFontBounds(const SkFont&);
67
68 /** Return the approximate largest dimension of typical text when transformed by the matrix.
69 *
70 * @param matrix used to transform size
71 * @param textLocation location of the text prior to matrix transformation. Used if the
72 * matrix has perspective.
73 * @return typical largest dimension
74 */
76 const SkPoint& textLocation);
77
78 static bool IsFinite(const SkFont& font) {
79 return SkIsFinite(font.getSize(), font.getScaleX(), font.getSkewX());
80 }
81
82 // Returns the number of elements (characters or glyphs) in the array.
83 static int CountTextElements(const void* text, size_t byteLength, SkTextEncoding);
84
85 static void GlyphsToUnichars(const SkFont&, const uint16_t glyphs[], int count, SkUnichar[]);
86
87 static void Flatten(const SkFont&, SkWriteBuffer& buffer);
88 static bool Unflatten(SkFont*, SkReadBuffer& buffer);
89
90 static inline uint8_t Flags(const SkFont& font) { return font.fFlags; }
91};
92
94public:
95 SkAutoToGlyphs(const SkFont& font, const void* text, size_t length, SkTextEncoding encoding) {
96 if (encoding == SkTextEncoding::kGlyphID || length == 0) {
97 fGlyphs = reinterpret_cast<const uint16_t*>(text);
98 fCount = SkToInt(length >> 1);
99 } else {
100 fCount = font.countText(text, length, encoding);
101 if (fCount < 0) {
102 fCount = 0;
103 }
104 fStorage.reset(fCount);
105 font.textToGlyphs(text, length, encoding, fStorage.get(), fCount);
106 fGlyphs = fStorage.get();
107 }
108 }
109
110 int count() const { return fCount; }
111 const uint16_t* glyphs() const { return fGlyphs; }
112
113private:
115 const uint16_t* fGlyphs;
116 int fCount;
117};
118
119#endif
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
static bool SkIsFinite(T x, Pack... values)
SkTextEncoding
Definition: SkFontTypes.h:11
@ kGlyphID
uses two byte words to represent glyph indices
constexpr int SkToInt(S x)
Definition: SkTo.h:29
int32_t SkUnichar
Definition: SkTypes.h:175
int count() const
Definition: SkFontPriv.h:110
const uint16_t * glyphs() const
Definition: SkFontPriv.h:111
SkAutoToGlyphs(const SkFont &font, const void *text, size_t length, SkTextEncoding encoding)
Definition: SkFontPriv.h:95
static int CountTextElements(const void *text, size_t byteLength, SkTextEncoding)
Definition: SkFont.cpp:381
static void ScaleFontMetrics(SkFontMetrics *, SkScalar)
Definition: SkFont.cpp:336
static bool IsFinite(const SkFont &font)
Definition: SkFontPriv.h:78
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
static SkScalar ApproximateTransformedTextSize(const SkFont &font, const SkMatrix &matrix, const SkPoint &textLocation)
Definition: SkFont.cpp:366
static uint8_t Flags(const SkFont &font)
Definition: SkFontPriv.h:90
static constexpr int kCanonicalTextSizeForPaths
Definition: SkFontPriv.h:36
static SkMatrix MakeTextMatrix(const SkFont &font)
Definition: SkFontPriv.h:49
static SkMatrix MakeTextMatrix(SkScalar size, SkScalar scaleX, SkScalar skewX)
Definition: SkFontPriv.h:41
static void GlyphsToUnichars(const SkFont &, const uint16_t glyphs[], int count, SkUnichar[])
Definition: SkFont.cpp:396
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
static SkRect GetFontBounds(const SkFont &)
Definition: SkFont.cpp:354
Definition: SkFont.h:35
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
void reset(int count)
Definition: SkTemplates.h:195
float SkScalar
Definition: extension.cpp:12
size_t length
std::u16string text
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
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.