Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
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
Type::kYUV Type::kRGBA() int(0.7 *637)
static const uint8_t buffer[]

◆ 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
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]
int count

◆ 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

◆ 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 ...
SkScalar fLeading
distance to add between lines, typically positive or zero
SkScalar fAvgCharWidth
average character width, zero if unknown
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
SkScalar fStrikeoutThickness
strikeout thickness
SkScalar fMaxCharWidth
maximum character width, zero if unknown
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
SkScalar fAscent
distance to reserve above baseline, typically negative
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
SkScalar fUnderlineThickness
underline thickness
SkScalar fDescent
distance to reserve below baseline, typically positive
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...

◆ 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: