Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
SkFont Class Reference

#include <SkFont.h>

Public Types

enum class  Edging { kAlias , kAntiAlias , kSubpixelAntiAlias }
 
using sk_is_trivially_relocatable = std::true_type
 

Public Member Functions

 SkFont ()
 
 SkFont (sk_sp< SkTypeface > typeface, SkScalar size)
 
 SkFont (sk_sp< SkTypeface > typeface)
 
 SkFont (sk_sp< SkTypeface > typeface, SkScalar size, SkScalar scaleX, SkScalar skewX)
 
bool operator== (const SkFont &font) const
 
bool operator!= (const SkFont &font) const
 
bool isForceAutoHinting () const
 
bool isEmbeddedBitmaps () const
 
bool isSubpixel () const
 
bool isLinearMetrics () const
 
bool isEmbolden () const
 
bool isBaselineSnap () const
 
void setForceAutoHinting (bool forceAutoHinting)
 
void setEmbeddedBitmaps (bool embeddedBitmaps)
 
void setSubpixel (bool subpixel)
 
void setLinearMetrics (bool linearMetrics)
 
void setEmbolden (bool embolden)
 
void setBaselineSnap (bool baselineSnap)
 
Edging getEdging () const
 
void setEdging (Edging edging)
 
void setHinting (SkFontHinting hintingLevel)
 
SkFontHinting getHinting () const
 
SkFont makeWithSize (SkScalar size) const
 
SkTypefacegetTypeface () const
 
SkScalar getSize () const
 
SkScalar getScaleX () const
 
SkScalar getSkewX () const
 
sk_sp< SkTypefacerefTypeface () const
 
void setTypeface (sk_sp< SkTypeface > tf)
 
void setSize (SkScalar textSize)
 
void setScaleX (SkScalar scaleX)
 
void setSkewX (SkScalar skewX)
 
int textToGlyphs (const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
 
SkGlyphID unicharToGlyph (SkUnichar uni) const
 
void unicharsToGlyphs (const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
 
int countText (const void *text, size_t byteLength, SkTextEncoding encoding) const
 
SkScalar measureText (const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const
 
SkScalar measureText (const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds, const SkPaint *paint) const
 
void getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const
 
void getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[], std::nullptr_t) const
 
void getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[]) const
 
void getWidthsBounds (const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[], const SkPaint *paint) const
 
void getBounds (const SkGlyphID glyphs[], int count, SkRect bounds[], const SkPaint *paint) const
 
void getPos (const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin={0, 0}) const
 
void getXPos (const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin=0) const
 
std::vector< SkScalargetIntercepts (const SkGlyphID glyphs[], int count, const SkPoint pos[], SkScalar top, SkScalar bottom, const SkPaint *=nullptr) const
 
bool getPath (SkGlyphID glyphID, SkPath *path) const
 
void getPaths (const SkGlyphID glyphIDs[], int count, void(*glyphPathProc)(const SkPath *pathOrNull, const SkMatrix &mx, void *ctx), void *ctx) const
 
SkScalar getMetrics (SkFontMetrics *metrics) const
 
SkScalar getSpacing () const
 
void dump () const
 

Friends

class SkFontPriv
 
class SkGlyphRunListPainterCPU
 
class SkStrikeSpec
 
class SkRemoteGlyphCacheTest
 

Detailed Description

SkFont controls options applied when drawing and measuring text.

Definition at line 35 of file SkFont.h.

Member Typedef Documentation

◆ sk_is_trivially_relocatable

using SkFont::sk_is_trivially_relocatable = std::true_type

Definition at line 501 of file SkFont.h.

Member Enumeration Documentation

◆ Edging

enum class SkFont::Edging
strong

Whether edge pixels draw opaque or with partial transparency.

Enumerator
kAlias 

no transparent pixels on glyph edges

kAntiAlias 

may have transparent pixels on glyph edges

kSubpixelAntiAlias 

glyph positioned in pixel using transparency

Definition at line 39 of file SkFont.h.

39 {
40 kAlias, //!< no transparent pixels on glyph edges
41 kAntiAlias, //!< may have transparent pixels on glyph edges
42 kSubpixelAntiAlias, //!< glyph positioned in pixel using transparency
43 };
@ kAntiAlias
may have transparent pixels on glyph edges
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency

Constructor & Destructor Documentation

◆ SkFont() [1/4]

SkFont::SkFont ( )

Constructs SkFont with default values.

Returns
default initialized SkFont

Definition at line 68 of file SkFont.cpp.

68: SkFont(nullptr, kDefault_Size) {}
#define kDefault_Size
Definition SkFont.cpp:42
SkFont()
Definition SkFont.cpp:68

◆ SkFont() [2/4]

SkFont::SkFont ( sk_sp< SkTypeface typeface,
SkScalar  size 
)

Constructs SkFont with default values with SkTypeface and size in points.

Parameters
typefacefont and style used to draw and measure text
sizetypographic height of text
Returns
initialized SkFont

Definition at line 64 of file SkFont.cpp.

64: SkFont(std::move(face), size, 1, 0) {}

◆ SkFont() [3/4]

SkFont::SkFont ( sk_sp< SkTypeface typeface)
explicit

Constructs SkFont with default values with SkTypeface.

Parameters
typefacefont and style used to draw and measure text
Returns
initialized SkFont

Definition at line 66 of file SkFont.cpp.

66: SkFont(std::move(face), kDefault_Size, 1, 0) {}

◆ SkFont() [4/4]

SkFont::SkFont ( sk_sp< SkTypeface typeface,
SkScalar  size,
SkScalar  scaleX,
SkScalar  skewX 
)

Constructs SkFont with default values with SkTypeface and size in points, horizontal scale, and horizontal skew. Horizontal scale emulates condensed and expanded fonts. Horizontal skew emulates oblique fonts.

Parameters
typefacefont and style used to draw and measure text
sizetypographic height of text
scaleXtext horizontal scale
skewXadditional shear on x-axis relative to y-axis
Returns
initialized SkFont

Definition at line 51 of file SkFont.cpp.

52 : fTypeface(std::move(face))
53 , fSize(valid_size(size))
54 , fScaleX(scaleX)
55 , fSkewX(skewX)
56 , fFlags(kDefault_Flags)
57 , fEdging(static_cast<unsigned>(kDefault_Edging))
58 , fHinting(static_cast<unsigned>(kDefault_Hinting)) {
59 if (!fTypeface) {
60 fTypeface = SkTypeface::MakeEmpty();
61 }
62}
#define kDefault_Edging
Definition SkFont.cpp:44
static SkScalar valid_size(SkScalar size)
Definition SkFont.cpp:47
#define kDefault_Flags
Definition SkFont.cpp:43
#define kDefault_Hinting
Definition SkFont.cpp:45
static sk_sp< SkTypeface > MakeEmpty()

Member Function Documentation

◆ countText()

int SkFont::countText ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding 
) const
inline

Returns number of glyphs represented by text.

If encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or SkTextEncoding::kUTF32; then each Unicode codepoint is mapped to a single glyph.

Parameters
textcharacter storage encoded with SkTextEncoding
byteLengthlength of character storage in bytes
Returns
number of glyphs represented by text of length byteLength

Definition at line 323 of file SkFont.h.

323 {
324 return this->textToGlyphs(text, byteLength, encoding, nullptr, 0);
325 }
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
Definition SkFont.cpp:181
std::u16string text

◆ dump()

void SkFont::dump ( ) const

Dumps fields of the font to SkDebugf. May change its output over time, so clients should not rely on this for anything specific. Used to aid in debugging.

Definition at line 80 of file SkFont.cpp.

80 {
81 SkDebugf("typeface %p\n", fTypeface.get());
82 SkDebugf("size %g\n", fSize);
83 SkDebugf("skewx %g\n", fSkewX);
84 SkDebugf("scalex %g\n", fScaleX);
85 SkDebugf("flags 0x%X\n", fFlags);
86 SkDebugf("edging %u\n", (unsigned)fEdging);
87 SkDebugf("hinting %u\n", (unsigned)fHinting);
88}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
T * get() const
Definition SkRefCnt.h:303

◆ getBounds()

void SkFont::getBounds ( const SkGlyphID  glyphs[],
int  count,
SkRect  bounds[],
const SkPaint paint 
) const
inline

Retrieves the bounds for each glyph in glyphs. bounds must be an array of count entries. If paint is not nullptr, its stroking, SkPathEffect, and SkMaskFilter fields are respected.

Parameters
glyphsarray of glyph indices to be measured
countnumber of glyphs
boundsreturns bounds for each glyph relative to (0, 0); may be nullptr
paintoptional, specifies stroking, SkPathEffect, and SkMaskFilter

Definition at line 412 of file SkFont.h.

413 {
414 this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
415 }
uint16_t glyphs[5]
int count
void getWidthsBounds(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[], const SkPaint *paint) const
Definition SkFont.cpp:233
const Paint & paint

◆ getEdging()

Edging SkFont::getEdging ( ) const
inline

Whether edge pixels draw opaque or with partial transparency.

Definition at line 180 of file SkFont.h.

180{ return (Edging)fEdging; }
Edging
Definition SkFont.h:39

◆ getHinting()

SkFontHinting SkFont::getHinting ( ) const
inline

Returns level of glyph outline adjustment.

Definition at line 194 of file SkFont.h.

194{ return (SkFontHinting)fHinting; }
SkFontHinting
Definition SkFontTypes.h:18

◆ getIntercepts()

std::vector< SkScalar > SkFont::getIntercepts ( const SkGlyphID  glyphs[],
int  count,
const SkPoint  pos[],
SkScalar  top,
SkScalar  bottom,
const SkPaint paintPtr = nullptr 
) const

Returns intervals [start, end] describing lines parallel to the advance that intersect with the glyphs.

Parameters
glyphsthe glyphs to intersect
countthe number of glyphs and positions
posthe position of each glyph
topthe top of the line intersecting
bottomthe bottom of the line intersecting
Returns
array of pairs of x values [start, end]. May be empty.

Definition at line 950 of file SkTextBlob.cpp.

953 {
954 if (count <= 0) {
955 return std::vector<SkScalar>();
956 }
957
958 const SkPaint paint(paintPtr ? *paintPtr : SkPaint());
959 const SkScalar bounds[] = {top, bottom};
960 const sktext::GlyphRun run(*this,
961 {positions, size_t(count)}, {glyphs, size_t(count)},
962 {nullptr, 0}, {nullptr, 0}, {nullptr, 0});
963
964 std::vector<SkScalar> result;
965 result.resize(count * 2); // worst case allocation
966 int intervalCount = 0;
967 intervalCount = get_glyph_run_intercepts(run, paint, bounds, result.data(), &intervalCount);
968 result.resize(intervalCount);
969 return result;
970}
float SkScalar
Definition extension.cpp:12
GAsyncResult * result
Optional< SkRect > bounds
Definition SkRecords.h:189
Definition run.py:1

◆ getMetrics()

SkScalar SkFont::getMetrics ( SkFontMetrics metrics) const

Returns SkFontMetrics associated with SkTypeface. The return value is the recommended spacing between lines: the sum of metrics descent, ascent, and leading. If metrics is not nullptr, SkFontMetrics is copied to metrics. Results are scaled by text size but does not take into account dimensions required by text scale, text skew, fake bold, style stroke, and SkPathEffect.

Parameters
metricsstorage for SkFontMetrics; may be nullptr
Returns
recommended spacing between lines

Definition at line 316 of file SkFont.cpp.

316 {
317
318 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(*this, nullptr);
319
320 SkFontMetrics storage;
321 if (nullptr == metrics) {
322 metrics = &storage;
323 }
324
325 auto cache = strikeSpec.findOrCreateStrike();
326 *metrics = cache->getFontMetrics();
327
328 if (strikeToSourceScale != 1) {
329 SkFontPriv::ScaleFontMetrics(metrics, strikeToSourceScale);
330 }
331 return metrics->fDescent - metrics->fAscent + metrics->fLeading;
332}
static void ScaleFontMetrics(SkFontMetrics *, SkScalar)
Definition SkFont.cpp:336
static std::tuple< SkStrikeSpec, SkScalar > MakeCanonicalized(const SkFont &font, const SkPaint *paint=nullptr)
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
SkScalar fLeading
distance to add between lines, typically positive or zero
SkScalar fAscent
distance to reserve above baseline, typically negative
SkScalar fDescent
distance to reserve below baseline, typically positive

◆ getPath()

bool SkFont::getPath ( SkGlyphID  glyphID,
SkPath path 
) const

Modifies path to be the outline of the glyph. If the glyph has an outline, modifies path to be the glyph's outline and returns true. The glyph outline may be empty. Degenerate contours in the glyph outline will be skipped. If glyph is described by a bitmap, returns false and ignores path parameter.

Parameters
glyphIDindex of glyph
pathpointer to existing SkPath
Returns
true if glyphID is described by path

Definition at line 300 of file SkFont.cpp.

300 {
301 struct Pair {
302 SkPath* fPath;
303 bool fWasSet;
304 } pair = { path, false };
305
306 this->getPaths(&glyphID, 1, [](const SkPath* orig, const SkMatrix& mx, void* ctx) {
307 Pair* pair = static_cast<Pair*>(ctx);
308 if (orig) {
309 orig->transform(mx, pair->fPath);
310 pair->fWasSet = true;
311 }
312 }, &pair);
313 return pair.fWasSet;
314}
SkPath fPath
void getPaths(const SkGlyphID glyphIDs[], int count, void(*glyphPathProc)(const SkPath *pathOrNull, const SkMatrix &mx, void *ctx), void *ctx) const
Definition SkFont.cpp:285
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
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

◆ getPaths()

void SkFont::getPaths ( const SkGlyphID  glyphIDs[],
int  count,
void(*)(const SkPath *pathOrNull, const SkMatrix &mx, void *ctx)  glyphPathProc,
void *  ctx 
) const

Returns path corresponding to glyph array.

Parameters
glyphIDsarray of glyph indices
countnumber of glyphs
glyphPathProcfunction returning one glyph description as path
ctxfunction context

Definition at line 285 of file SkFont.cpp.

286 {
287 SkFont font(*this);
288 SkScalar scale = font.setupForAsPaths(nullptr);
289 const SkMatrix mx = SkMatrix::Scale(scale, scale);
290
292 SkBulkGlyphMetricsAndPaths paths{strikeSpec};
293 SkSpan<const SkGlyph*> glyphs = paths.glyphs(SkSpan(glyphIDs, count));
294
295 for (auto glyph : glyphs) {
296 proc(glyph->path(), mx, ctx);
297 }
298}
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
font
Font Metadata and Metrics.
const Scalar scale

◆ getPos()

void SkFont::getPos ( const SkGlyphID  glyphs[],
int  count,
SkPoint  pos[],
SkPoint  origin = {0, 0} 
) const

Retrieves the positions for each glyph, beginning at the specified origin. The caller must allocated at least count number of elements in the pos[] array.

Parameters
glyphsarray of glyph indices to be positioned
countnumber of glyphs
posreturns glyphs positions
originlocation of the first glyph. Defaults to {0, 0}.

Definition at line 258 of file SkFont.cpp.

258 {
259 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(*this);
260 SkBulkGlyphMetrics metrics{strikeSpec};
261 SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
262
263 SkPoint sum = origin;
264 for (auto glyph : glyphs) {
265 *pos++ = sum;
266 sum += glyph->advanceVector() * strikeToSourceScale;
267 }
268}
SkPoint pos

◆ getScaleX()

SkScalar SkFont::getScaleX ( ) const
inline

Returns text scale on x-axis. Default value is 1.

Returns
text horizontal scale

Definition at line 224 of file SkFont.h.

224{ return fScaleX; }

◆ getSize()

SkScalar SkFont::getSize ( ) const
inline

Returns text size in points.

Returns
typographic height of text

Definition at line 217 of file SkFont.h.

217{ return fSize; }

◆ getSkewX()

SkScalar SkFont::getSkewX ( ) const
inline

Returns text skew on x-axis. Default value is zero.

Returns
additional shear on x-axis relative to y-axis

Definition at line 231 of file SkFont.h.

231{ return fSkewX; }

◆ getSpacing()

SkScalar SkFont::getSpacing ( ) const
inline

Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading. Result is scaled by text size but does not take into account dimensions required by stroking and SkPathEffect. Returns the same result as getMetrics().

Returns
recommended spacing between lines

Definition at line 494 of file SkFont.h.

494{ return this->getMetrics(nullptr); }
SkScalar getMetrics(SkFontMetrics *metrics) const
Definition SkFont.cpp:316

◆ getTypeface()

SkTypeface * SkFont::getTypeface ( ) const
inline

Does not alter SkTypeface SkRefCnt.

Returns
non-null SkTypeface

Definition at line 208 of file SkFont.h.

208 {
209 SkASSERT(fTypeface);
210 return fTypeface.get();
211 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ getWidths() [1/3]

void SkFont::getWidths ( const SkGlyphID  glyphs[],
int  count,
SkScalar  widths[] 
) const
inline

Retrieves the advance and bounds for each glyph in glyphs. Both widths and bounds may be nullptr. If widths is not nullptr, widths must be an array of count entries. if bounds is not nullptr, bounds must be an array of count entries.

Parameters
glyphsarray of glyph indices to be measured
countnumber of glyphs
widthsreturns text advances for each glyph

Definition at line 384 of file SkFont.h.

384 {
385 this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
386 }
const SkScalar widths[]

◆ getWidths() [2/3]

void SkFont::getWidths ( const SkGlyphID  glyphs[],
int  count,
SkScalar  widths[],
SkRect  bounds[] 
) const
inline

DEPRECATED Retrieves the advance and bounds for each glyph in glyphs. Both widths and bounds may be nullptr. If widths is not nullptr, widths must be an array of count entries. if bounds is not nullptr, bounds must be an array of count entries.

Parameters
glyphsarray of glyph indices to be measured
countnumber of glyphs
widthsreturns text advances for each glyph; may be nullptr
boundsreturns bounds for each glyph relative to (0, 0); may be nullptr

Definition at line 366 of file SkFont.h.

366 {
367 this->getWidthsBounds(glyphs, count, widths, bounds, nullptr);
368 }

◆ getWidths() [3/3]

void SkFont::getWidths ( const SkGlyphID  glyphs[],
int  count,
SkScalar  widths[],
std::nullptr_t   
) const
inline

Definition at line 371 of file SkFont.h.

371 {
372 this->getWidths(glyphs, count, widths);
373 }
void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const
Definition SkFont.h:366

◆ getWidthsBounds()

void SkFont::getWidthsBounds ( const SkGlyphID  glyphs[],
int  count,
SkScalar  widths[],
SkRect  bounds[],
const SkPaint paint 
) const

Retrieves the advance and bounds for each glyph in glyphs. Both widths and bounds may be nullptr. If widths is not nullptr, widths must be an array of count entries. if bounds is not nullptr, bounds must be an array of count entries.

Parameters
glyphsarray of glyph indices to be measured
countnumber of glyphs
widthsreturns text advances for each glyph; may be nullptr
boundsreturns bounds for each glyph relative to (0, 0); may be nullptr
paintoptional, specifies stroking, SkPathEffect and SkMaskFilter

Definition at line 233 of file SkFont.cpp.

237 {
238 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(*this, paint);
239 SkBulkGlyphMetrics metrics{strikeSpec};
240 SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
241
242 if (bounds) {
243 SkMatrix scaleMat = SkMatrix::Scale(strikeToSourceScale, strikeToSourceScale);
244 SkRect* cursor = bounds;
245 for (auto glyph : glyphs) {
246 scaleMat.mapRectScaleTranslate(cursor++, glyph->rect());
247 }
248 }
249
250 if (widths) {
251 SkScalar* cursor = widths;
252 for (auto glyph : glyphs) {
253 *cursor++ = glyph->advanceX() * strikeToSourceScale;
254 }
255 }
256}
void mapRectScaleTranslate(SkRect *dst, const SkRect &src) const

◆ getXPos()

void SkFont::getXPos ( const SkGlyphID  glyphs[],
int  count,
SkScalar  xpos[],
SkScalar  origin = 0 
) const

Retrieves the x-positions for each glyph, beginning at the specified origin. The caller must allocated at least count number of elements in the xpos[] array.

Parameters
glyphsarray of glyph indices to be positioned
countnumber of glyphs
xposreturns glyphs x-positions
originx-position of the first glyph. Defaults to 0.

Definition at line 270 of file SkFont.cpp.

271 {
272
273 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(*this);
274 SkBulkGlyphMetrics metrics{strikeSpec};
275 SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
276
277 SkScalar loc = origin;
278 SkScalar* cursor = xpos;
279 for (auto glyph : glyphs) {
280 *cursor++ = loc;
281 loc += glyph->advanceX() * strikeToSourceScale;
282 }
283}

◆ isBaselineSnap()

bool SkFont::isBaselineSnap ( ) const
inline

Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.

Returns
baselines may be snapped to pixels

Definition at line 133 of file SkFont.h.

133{ return SkToBool(fFlags & kBaselineSnap_PrivFlag); }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ isEmbeddedBitmaps()

bool SkFont::isEmbeddedBitmaps ( ) const
inline

Returns true if font engine may return glyphs from font bitmaps instead of from outlines.

Returns
true if glyphs may be font bitmaps

Definition at line 107 of file SkFont.h.

107{ return SkToBool(fFlags & kEmbeddedBitmaps_PrivFlag); }

◆ isEmbolden()

bool SkFont::isEmbolden ( ) const
inline

Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.

Returns
bold is approximated through stroke width

Definition at line 126 of file SkFont.h.

126{ return SkToBool(fFlags & kEmbolden_PrivFlag); }

◆ isForceAutoHinting()

bool SkFont::isForceAutoHinting ( ) const
inline

If true, instructs the font manager to always hint glyphs. Returned value is only meaningful if platform uses FreeType as the font manager.

Returns
true if all glyphs are hinted

Definition at line 101 of file SkFont.h.

101{ return SkToBool(fFlags & kForceAutoHinting_PrivFlag); }

◆ isLinearMetrics()

bool SkFont::isLinearMetrics ( ) const
inline

Returns true if font and glyph metrics are requested to be linearly scalable.

Returns
true if font and glyph metrics are requested to be linearly scalable.

Definition at line 119 of file SkFont.h.

119{ return SkToBool(fFlags & kLinearMetrics_PrivFlag); }

◆ isSubpixel()

bool SkFont::isSubpixel ( ) const
inline

Returns true if glyphs may be drawn at sub-pixel offsets.

Returns
true if glyphs may be drawn at sub-pixel offsets.

Definition at line 113 of file SkFont.h.

113{ return SkToBool(fFlags & kSubpixel_PrivFlag); }

◆ makeWithSize()

SkFont SkFont::makeWithSize ( SkScalar  size) const

Returns a font with the same attributes of this font, but with the specified size. Returns nullptr if size is less than zero, infinite, or NaN.

Parameters
sizetypographic height of text
Returns
initialized SkFont

Definition at line 139 of file SkFont.cpp.

139 {
140 SkFont font = *this;
141 font.setSize(newSize);
142 return font;
143}

◆ measureText() [1/2]

SkScalar SkFont::measureText ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding,
SkRect bounds,
const SkPaint paint 
) const

Returns the advance width of text. The advance is the normal distance to move before drawing additional text. Returns the bounding box of text if bounds is not nullptr. The paint stroke settings, mask filter, or path effect may modify the bounds.

Parameters
textcharacter storage encoded with SkTextEncoding
byteLengthlength of character storage in bytes
boundsreturns bounding box relative to (0, 0) if not nullptr
paintoptional; may be nullptr
Returns
the sum of the default advance widths

Definition at line 187 of file SkFont.cpp.

188 {
189
190 SkAutoToGlyphs atg(*this, text, length, encoding);
191 const int glyphCount = atg.count();
192 if (glyphCount == 0) {
193 if (bounds) {
194 bounds->setEmpty();
195 }
196 return 0;
197 }
198 const SkGlyphID* glyphIDs = atg.glyphs();
199
200 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(*this, paint);
201 SkBulkGlyphMetrics metrics{strikeSpec};
202 SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, glyphCount));
203
204 SkScalar width = 0;
205 if (bounds) {
206 *bounds = glyphs[0]->rect();
207 width = glyphs[0]->advanceX();
208 for (int i = 1; i < glyphCount; ++i) {
209 SkRect r = glyphs[i]->rect();
210 r.offset(width, 0);
211 bounds->join(r);
212 width += glyphs[i]->advanceX();
213 }
214 } else {
215 for (auto glyph : glyphs) {
216 width += glyph->advanceX();
217 }
218 }
219
220 if (strikeToSourceScale != 1) {
221 width *= strikeToSourceScale;
222 if (bounds) {
223 bounds->fLeft *= strikeToSourceScale;
224 bounds->fTop *= strikeToSourceScale;
225 bounds->fRight *= strikeToSourceScale;
226 bounds->fBottom *= strikeToSourceScale;
227 }
228 }
229
230 return width;
231}
uint16_t SkGlyphID
Definition SkTypes.h:179
size_t length
int32_t width
void offset(float dx, float dy)
Definition SkRect.h:1016

◆ measureText() [2/2]

SkScalar SkFont::measureText ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding,
SkRect bounds = nullptr 
) const
inline

Returns the advance width of text. The advance is the normal distance to move before drawing additional text. Returns the bounding box of text if bounds is not nullptr.

Parameters
textcharacter storage encoded with SkTextEncoding
byteLengthlength of character storage in bytes
boundsreturns bounding box relative to (0, 0) if not nullptr
Returns
the sum of the default advance widths

Definition at line 336 of file SkFont.h.

337 {
338 return this->measureText(text, byteLength, encoding, bounds, nullptr);
339 }
SkScalar measureText(const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const
Definition SkFont.h:336

◆ operator!=()

bool SkFont::operator!= ( const SkFont font) const
inline

Compares SkFont and font, and returns true if they are not equivalent. May return true if SkTypeface has identical contents but different pointers.

Parameters
fontfont to compare
Returns
true if SkFont pair are not equivalent

Definition at line 94 of file SkFont.h.

94{ return !(*this == font); }

◆ operator==()

bool SkFont::operator== ( const SkFont font) const

Compares SkFont and font, and returns true if they are equivalent. May return false if SkTypeface has identical contents but different pointers.

Parameters
fontfont to compare
Returns
true if SkFont pair are equivalent

Definition at line 70 of file SkFont.cpp.

70 {
71 return fTypeface.get() == b.fTypeface.get() &&
72 fSize == b.fSize &&
73 fScaleX == b.fScaleX &&
74 fSkewX == b.fSkewX &&
75 fFlags == b.fFlags &&
76 fEdging == b.fEdging &&
77 fHinting == b.fHinting;
78}
static bool b

◆ refTypeface()

sk_sp< SkTypeface > SkFont::refTypeface ( ) const
inline

Increases SkTypeface SkRefCnt by one.

Returns
A non-null SkTypeface.

Definition at line 237 of file SkFont.h.

237 {
238 SkASSERT(fTypeface);
239 return fTypeface;
240 }

◆ setBaselineSnap()

void SkFont::setBaselineSnap ( bool  baselineSnap)

Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.

Parameters
baselineSnapsetting for baseline snapping to pixels

Definition at line 118 of file SkFont.cpp.

118 {
119 fFlags = set_clear_mask(fFlags, predicate, kBaselineSnap_PrivFlag);
120}
static uint32_t set_clear_mask(uint32_t bits, bool cond, uint32_t mask)
Definition SkFont.cpp:99

◆ setEdging()

void SkFont::setEdging ( Edging  edging)

Requests, but does not require, that edge pixels draw opaque or with partial transparency.

Definition at line 121 of file SkFont.cpp.

121 {
122 fEdging = SkToU8(e);
123}
constexpr uint8_t SkToU8(S x)
Definition SkTo.h:22

◆ setEmbeddedBitmaps()

void SkFont::setEmbeddedBitmaps ( bool  embeddedBitmaps)

Requests, but does not require, to use bitmaps in fonts instead of outlines.

Parameters
embeddedBitmapssetting to use bitmaps in fonts

Definition at line 106 of file SkFont.cpp.

106 {
107 fFlags = set_clear_mask(fFlags, predicate, kEmbeddedBitmaps_PrivFlag);
108}

◆ setEmbolden()

void SkFont::setEmbolden ( bool  embolden)

Increases stroke width when creating glyph bitmaps to approximate a bold typeface.

Parameters
emboldensetting for bold approximation

Definition at line 115 of file SkFont.cpp.

115 {
116 fFlags = set_clear_mask(fFlags, predicate, kEmbolden_PrivFlag);
117}

◆ setForceAutoHinting()

void SkFont::setForceAutoHinting ( bool  forceAutoHinting)

Sets whether to always hint glyphs. If forceAutoHinting is set, instructs the font manager to always hint glyphs.

Only affects platforms that use FreeType as the font manager.

Parameters
forceAutoHintingsetting to always hint glyphs

Definition at line 103 of file SkFont.cpp.

103 {
104 fFlags = set_clear_mask(fFlags, predicate, kForceAutoHinting_PrivFlag);
105}

◆ setHinting()

void SkFont::setHinting ( SkFontHinting  hintingLevel)

Sets level of glyph outline adjustment. Does not check for valid values of hintingLevel.

Definition at line 125 of file SkFont.cpp.

125 {
126 fHinting = SkToU8(h);
127}
SkScalar h

◆ setLinearMetrics()

void SkFont::setLinearMetrics ( bool  linearMetrics)

Requests, but does not require, linearly scalable font and glyph metrics.

For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding. Note that some bitmap formats may not be able to scale linearly and will ignore this flag.

Parameters
linearMetricssetting for linearly scalable font and glyph metrics.

Definition at line 112 of file SkFont.cpp.

112 {
113 fFlags = set_clear_mask(fFlags, predicate, kLinearMetrics_PrivFlag);
114}

◆ setScaleX()

void SkFont::setScaleX ( SkScalar  scaleX)

Sets text scale on x-axis. Default value is 1.

Parameters
scaleXtext horizontal scale

Definition at line 132 of file SkFont.cpp.

132 {
133 fScaleX = scale;
134}

◆ setSize()

void SkFont::setSize ( SkScalar  textSize)

Sets text size in points. Has no effect if textSize is not greater than or equal to zero.

Parameters
textSizetypographic height of text

Definition at line 129 of file SkFont.cpp.

129 {
130 fSize = valid_size(size);
131}

◆ setSkewX()

void SkFont::setSkewX ( SkScalar  skewX)

Sets text skew on x-axis. Default value is zero.

Parameters
skewXadditional shear on x-axis relative to y-axis

Definition at line 135 of file SkFont.cpp.

135 {
136 fSkewX = skew;
137}

◆ setSubpixel()

void SkFont::setSubpixel ( bool  subpixel)

Requests, but does not require, that glyphs respect sub-pixel positioning.

Parameters
subpixelsetting for sub-pixel positioning

Definition at line 109 of file SkFont.cpp.

109 {
110 fFlags = set_clear_mask(fFlags, predicate, kSubpixel_PrivFlag);
111}

◆ setTypeface()

void SkFont::setTypeface ( sk_sp< SkTypeface tf)

Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface. Pass nullptr to clear SkTypeface and use an empty typeface (which draws nothing). Increments tf SkRefCnt by one.

Parameters
tffont and style used to draw text

Definition at line 90 of file SkFont.cpp.

90 {
91 fTypeface = std::move(tf);
92 if (!fTypeface) {
93 fTypeface = SkTypeface::MakeEmpty();
94 }
95}

◆ textToGlyphs()

int SkFont::textToGlyphs ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding,
SkGlyphID  glyphs[],
int  maxGlyphCount 
) const

Converts text into glyph indices. Returns the number of glyph indices represented by text. SkTextEncoding specifies how text represents characters or glyphs. glyphs may be nullptr, to compute the glyph count.

Does not check text for valid character codes or valid glyph indices.

If byteLength equals zero, returns zero. If byteLength includes a partial character, the partial character is ignored.

If encoding is SkTextEncoding::kUTF8 and text contains an invalid UTF-8 sequence, zero is returned.

When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or SkTextEncoding::kUTF32; then each Unicode codepoint is mapped to a single glyph. This function uses the default character-to-glyph mapping from the SkTypeface and maps characters not found in the SkTypeface to zero.

If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied. The total glyph count is returned for subsequent buffer reallocation.

Parameters
textcharacter storage encoded with SkTextEncoding
byteLengthlength of character storage in bytes
glyphsstorage for glyph indices; may be nullptr
maxGlyphCountstorage capacity
Returns
number of glyphs represented by text of length byteLength

Definition at line 181 of file SkFont.cpp.

182 {
183 return this->getTypeface()->textToGlyphs(text, byteLength, encoding,
184 glyphs, maxGlyphCount);
185}
SkTypeface * getTypeface() const
Definition SkFont.h:208
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const

◆ unicharsToGlyphs()

void SkFont::unicharsToGlyphs ( const SkUnichar  uni[],
int  count,
SkGlyphID  glyphs[] 
) const

Definition at line 177 of file SkFont.cpp.

177 {
179}
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const

◆ unicharToGlyph()

SkGlyphID SkFont::unicharToGlyph ( SkUnichar  uni) const

Returns glyph index for Unicode character.

If the character is not supported by the SkTypeface, returns 0.

Parameters
uniUnicode character
Returns
glyph index

Definition at line 173 of file SkFont.cpp.

173 {
174 return this->getTypeface()->unicharToGlyph(uni);
175}
SkGlyphID unicharToGlyph(SkUnichar unichar) const

Friends And Related Symbol Documentation

◆ SkFontPriv

friend class SkFontPriv
friend

Definition at line 533 of file SkFont.h.

◆ SkGlyphRunListPainterCPU

friend class SkGlyphRunListPainterCPU
friend

Definition at line 534 of file SkFont.h.

◆ SkRemoteGlyphCacheTest

friend class SkRemoteGlyphCacheTest
friend

Definition at line 536 of file SkFont.h.

◆ SkStrikeSpec

friend class SkStrikeSpec
friend

Definition at line 535 of file SkFont.h.


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