Flutter Engine
The Flutter Engine
Static Public Member Functions | Static Public Attributes | List of all members
SkFontPriv Class Reference

#include <SkFontPriv.h>

Static Public Member Functions

static SkMatrix MakeTextMatrix (SkScalar size, SkScalar scaleX, SkScalar skewX)
 
static SkMatrix MakeTextMatrix (const SkFont &font)
 
static void ScaleFontMetrics (SkFontMetrics *, SkScalar)
 
static SkRect GetFontBounds (const SkFont &)
 
static SkScalar ApproximateTransformedTextSize (const SkFont &font, const SkMatrix &matrix, const SkPoint &textLocation)
 
static bool IsFinite (const SkFont &font)
 
static int CountTextElements (const void *text, size_t byteLength, SkTextEncoding)
 
static void GlyphsToUnichars (const SkFont &, const uint16_t glyphs[], int count, SkUnichar[])
 
static void Flatten (const SkFont &, SkWriteBuffer &buffer)
 
static bool Unflatten (SkFont *, SkReadBuffer &buffer)
 
static uint8_t Flags (const SkFont &font)
 

Static Public Attributes

static constexpr int kCanonicalTextSizeForPaths = 64
 

Detailed Description

Definition at line 20 of file SkFontPriv.h.

Member Function Documentation

◆ ApproximateTransformedTextSize()

SkScalar SkFontPriv::ApproximateTransformedTextSize ( const SkFont font,
const SkMatrix matrix,
const SkPoint textLocation 
)
static

Return the approximate largest dimension of typical text when transformed by the matrix.

Parameters
matrixused to transform size
textLocationlocation of the text prior to matrix transformation. Used if the matrix has perspective.
Returns
typical largest dimension

Definition at line 366 of file SkFont.cpp.

367 {
368 if (!matrix.hasPerspective()) {
369 return font.getSize() * matrix.getMaxScale();
370 } else {
371 // approximate the scale since we can't get it directly from the matrix
372 SkScalar maxScaleSq = SkMatrixPriv::DifferentialAreaScale(matrix, textLocation);
373 if (SkIsFinite(maxScaleSq) && !SkScalarNearlyZero(maxScaleSq)) {
374 return font.getSize() * SkScalarSqrt(maxScaleSq);
375 } else {
376 return -font.getSize();
377 }
378 }
379}
static bool SkIsFinite(T x, Pack... values)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
static SkScalar DifferentialAreaScale(const SkMatrix &m, const SkPoint &p)
Definition: SkMatrix.cpp:1786
float SkScalar
Definition: extension.cpp:12
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
font
Font Metadata and Metrics.

◆ CountTextElements()

int SkFontPriv::CountTextElements ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding 
)
static

Definition at line 381 of file SkFont.cpp.

381 {
382 switch (encoding) {
384 return SkUTF::CountUTF8(reinterpret_cast<const char*>(text), byteLength);
386 return SkUTF::CountUTF16(reinterpret_cast<const uint16_t*>(text), byteLength);
388 return byteLength >> 2;
390 return byteLength >> 1;
391 }
392 SkASSERT(false);
393 return 0;
394}
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kUTF8
uses bytes to represent UTF-8 or ASCII
@ kUTF16
uses two byte words to represent most of Unicode
@ kUTF32
uses four byte words to represent all of Unicode
@ kGlyphID
uses two byte words to represent glyph indices
std::u16string text
SK_SPI int CountUTF16(const uint16_t *utf16, size_t byteLength)
Definition: SkUTF.cpp:70
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
Definition: SkUTF.cpp:47

◆ Flags()

static uint8_t SkFontPriv::Flags ( const SkFont font)
inlinestatic

Definition at line 90 of file SkFontPriv.h.

90{ return font.fFlags; }

◆ Flatten()

void SkFontPriv::Flatten ( const SkFont font,
SkWriteBuffer buffer 
)
static

Definition at line 48 of file SkFont_serial.cpp.

48 {
49 SkASSERT(font.fFlags <= SkFont::kAllFlags);
50 SkASSERT((font.fFlags & ~kMask_For_Flags) == 0);
51 SkASSERT((font.fEdging & ~kMask_For_Edging) == 0);
52 SkASSERT((font.fHinting & ~kMask_For_Hinting) == 0);
53
54 uint32_t packed = 0;
55 packed |= font.fFlags << kShift_For_Flags;
56 packed |= font.fEdging << kShift_For_Edging;
57 packed |= font.fHinting << kShift_For_Hinting;
58
59 if (scalar_is_byte(font.fSize)) {
60 packed |= kSize_Is_Byte_Bit;
61 packed |= (int)font.fSize << kShift_for_Size;
62 }
63 if (font.fScaleX != 1) {
64 packed |= kHas_ScaleX_Bit;
65 }
66 if (font.fSkewX != 0) {
67 packed |= kHas_SkewX_Bit;
68 }
69 if (font.fTypeface) {
70 packed |= kHas_Typeface_Bit;
71 }
72
73 buffer.write32(packed);
74 if (!(packed & kSize_Is_Byte_Bit)) {
75 buffer.writeScalar(font.fSize);
76 }
77 if (packed & kHas_ScaleX_Bit) {
78 buffer.writeScalar(font.fScaleX);
79 }
80 if (packed & kHas_SkewX_Bit) {
81 buffer.writeScalar(font.fSkewX);
82 }
83 if (packed & kHas_Typeface_Bit) {
84 buffer.writeTypeface(font.fTypeface.get());
85 }
86}
static bool scalar_is_byte(SkScalar x)
@ kHas_ScaleX_Bit
@ kHas_Typeface_Bit
@ kMask_For_Hinting
@ kShift_For_Flags
@ kShift_For_Edging
@ kSize_Is_Byte_Bit
@ kHas_SkewX_Bit
@ kMask_For_Edging
@ kShift_for_Size
@ kShift_For_Hinting
@ kMask_For_Flags
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

◆ GetFontBounds()

SkRect SkFontPriv::GetFontBounds ( const SkFont font)
static

Returns the union of bounds of all glyphs. Returned dimensions are computed by font manager from font data, ignoring SkPaint::Hinting. Includes font metrics, but not fake bold or SkPathEffect.

If text size is large, text scale is one, and text skew is zero, returns the bounds as: { SkFontMetrics::fXMin, SkFontMetrics::fTop, SkFontMetrics::fXMax, SkFontMetrics::fBottom }.

Returns
union of bounds of all glyphs

Definition at line 354 of file SkFont.cpp.

354 {
355 SkMatrix m;
356 m.setScale(font.getSize() * font.getScaleX(), font.getSize());
357 m.postSkew(font.getSkewX(), 0);
358
359 SkTypeface* typeface = font.getTypeface();
360
362 m.mapRect(&bounds, typeface->getBounds());
363 return bounds;
364}
SkRect getBounds() const
Definition: SkTypeface.cpp:507
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ GlyphsToUnichars()

void SkFontPriv::GlyphsToUnichars ( const SkFont font,
const uint16_t  glyphs[],
int  count,
SkUnichar  text[] 
)
static

Definition at line 396 of file SkFont.cpp.

397 {
398 if (count <= 0) {
399 return;
400 }
401
402 auto typeface = font.getTypeface();
403 const unsigned numGlyphsInTypeface = typeface->countGlyphs();
404 AutoTArray<SkUnichar> unichars(static_cast<size_t>(numGlyphsInTypeface));
405 typeface->getGlyphToUnicodeMap(unichars.get());
406
407 for (int i = 0; i < count; ++i) {
408 unsigned id = glyphs[i];
409 text[i] = (id < numGlyphsInTypeface) ? unichars[id] : 0xFFFD;
410 }
411}
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50

◆ IsFinite()

static bool SkFontPriv::IsFinite ( const SkFont font)
inlinestatic

Definition at line 78 of file SkFontPriv.h.

78 {
79 return SkIsFinite(font.getSize(), font.getScaleX(), font.getSkewX());
80 }

◆ MakeTextMatrix() [1/2]

static SkMatrix SkFontPriv::MakeTextMatrix ( const SkFont font)
inlinestatic

Definition at line 49 of file SkFontPriv.h.

49 {
50 return MakeTextMatrix(font.getSize(), font.getScaleX(), font.getSkewX());
51 }
static SkMatrix MakeTextMatrix(SkScalar size, SkScalar scaleX, SkScalar skewX)
Definition: SkFontPriv.h:41

◆ MakeTextMatrix() [2/2]

static SkMatrix SkFontPriv::MakeTextMatrix ( SkScalar  size,
SkScalar  scaleX,
SkScalar  skewX 
)
inlinestatic

Return a matrix that applies the paint's text values: size, scale, skew

Definition at line 41 of file SkFontPriv.h.

41 {
42 SkMatrix m = SkMatrix::Scale(size * scaleX, size);
43 if (skewX) {
44 m.postSkew(skewX, 0);
45 }
46 return m;
47 }
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
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

◆ ScaleFontMetrics()

void SkFontPriv::ScaleFontMetrics ( SkFontMetrics metrics,
SkScalar  scale 
)
static

Definition at line 336 of file SkFont.cpp.

336 {
337 metrics->fTop *= scale;
338 metrics->fAscent *= scale;
339 metrics->fDescent *= scale;
340 metrics->fBottom *= scale;
341 metrics->fLeading *= scale;
342 metrics->fAvgCharWidth *= scale;
343 metrics->fMaxCharWidth *= scale;
344 metrics->fXMin *= scale;
345 metrics->fXMax *= scale;
346 metrics->fXHeight *= scale;
347 metrics->fCapHeight *= scale;
348 metrics->fUnderlineThickness *= scale;
349 metrics->fUnderlinePosition *= scale;
350 metrics->fStrikeoutThickness *= scale;
351 metrics->fStrikeoutPosition *= scale;
352}
const Scalar scale
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
Definition: SkFontMetrics.h:53
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAvgCharWidth
average character width, zero if unknown
Definition: SkFontMetrics.h:58
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
Definition: SkFontMetrics.h:67
SkScalar fStrikeoutThickness
strikeout thickness
Definition: SkFontMetrics.h:66
SkScalar fMaxCharWidth
maximum character width, zero if unknown
Definition: SkFontMetrics.h:59
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
Definition: SkFontMetrics.h:56
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
Definition: SkFontMetrics.h:62
SkScalar fUnderlineThickness
underline thickness
Definition: SkFontMetrics.h:64
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
Definition: SkFontMetrics.h:63
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
Definition: SkFontMetrics.h:60
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
Definition: SkFontMetrics.h:65
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
Definition: SkFontMetrics.h:61

◆ Unflatten()

bool SkFontPriv::Unflatten ( SkFont font,
SkReadBuffer buffer 
)
static

Definition at line 88 of file SkFont_serial.cpp.

88 {
89 const uint32_t packed = buffer.read32();
90
91 if (packed & kSize_Is_Byte_Bit) {
92 font->fSize = (packed >> kShift_for_Size) & kMask_For_Size;
93 } else {
94 font->fSize = buffer.readScalar();
95 }
96 if (packed & kHas_ScaleX_Bit) {
97 font->fScaleX = buffer.readScalar();
98 }
99 if (packed & kHas_SkewX_Bit) {
100 font->fSkewX = buffer.readScalar();
101 }
102 if (packed & kHas_Typeface_Bit) {
103 font->setTypeface(buffer.readTypeface());
104 }
105
106 SkASSERT(SkFont::kAllFlags <= kMask_For_Flags);
107 // we & with kAllFlags, to clear out any unknown flag bits
108 font->fFlags = SkToU8((packed >> kShift_For_Flags) & SkFont::kAllFlags);
109
110 unsigned edging = (packed >> kShift_For_Edging) & kMask_For_Edging;
111 if (edging > (unsigned)SkFont::Edging::kSubpixelAntiAlias) {
112 edging = 0;
113 }
114 font->fEdging = SkToU8(edging);
115
116 unsigned hinting = (packed >> kShift_For_Hinting) & kMask_For_Hinting;
117 if (hinting > (unsigned)SkFontHinting::kFull) {
118 hinting = 0;
119 }
120 font->fHinting = SkToU8(hinting);
121
122 return buffer.isValid();
123}
@ kFull
modifies glyph outlines for maximum constrast
@ kMask_For_Size
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency

Member Data Documentation

◆ kCanonicalTextSizeForPaths

constexpr int SkFontPriv::kCanonicalTextSizeForPaths = 64
inlinestaticconstexpr

Definition at line 36 of file SkFontPriv.h.


The documentation for this class was generated from the following files: