Skia
2D Graphics Library
|
SkFont controls options applied when drawing and measuring text. More...
#include <SkFont.h>
Public Types | |
enum class | Edging { kAlias , kAntiAlias , kSubpixelAntiAlias } |
Whether edge pixels draw opaque or with partial transparency. More... | |
using | sk_is_trivially_relocatable = std::true_type |
Public Member Functions | |
SkFont () | |
Constructs SkFont with default values. More... | |
SkFont (sk_sp< SkTypeface > typeface, SkScalar size) | |
Constructs SkFont with default values with SkTypeface and size in points. More... | |
SkFont (sk_sp< SkTypeface > typeface) | |
Constructs SkFont with default values with SkTypeface. More... | |
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. More... | |
bool | operator== (const SkFont &font) const |
Compares SkFont and font, and returns true if they are equivalent. More... | |
bool | operator!= (const SkFont &font) const |
Compares SkFont and font, and returns true if they are not equivalent. More... | |
bool | isForceAutoHinting () const |
If true, instructs the font manager to always hint glyphs. More... | |
bool | isEmbeddedBitmaps () const |
Returns true if font engine may return glyphs from font bitmaps instead of from outlines. More... | |
bool | isSubpixel () const |
Returns true if glyphs may be drawn at sub-pixel offsets. More... | |
bool | isLinearMetrics () const |
Returns true if font and glyph metrics are requested to be linearly scalable. More... | |
bool | isEmbolden () const |
Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines. More... | |
bool | isBaselineSnap () const |
Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned. More... | |
void | setForceAutoHinting (bool forceAutoHinting) |
Sets whether to always hint glyphs. More... | |
void | setEmbeddedBitmaps (bool embeddedBitmaps) |
Requests, but does not require, to use bitmaps in fonts instead of outlines. More... | |
void | setSubpixel (bool subpixel) |
Requests, but does not require, that glyphs respect sub-pixel positioning. More... | |
void | setLinearMetrics (bool linearMetrics) |
Requests, but does not require, linearly scalable font and glyph metrics. More... | |
void | setEmbolden (bool embolden) |
Increases stroke width when creating glyph bitmaps to approximate a bold typeface. More... | |
void | setBaselineSnap (bool baselineSnap) |
Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned. More... | |
Edging | getEdging () const |
Whether edge pixels draw opaque or with partial transparency. More... | |
void | setEdging (Edging edging) |
Requests, but does not require, that edge pixels draw opaque or with partial transparency. More... | |
void | setHinting (SkFontHinting hintingLevel) |
Sets level of glyph outline adjustment. More... | |
SkFontHinting | getHinting () const |
Returns level of glyph outline adjustment. More... | |
SkFont | makeWithSize (SkScalar size) const |
Returns a font with the same attributes of this font, but with the specified size. More... | |
SkTypeface * | getTypeface () const |
Returns SkTypeface if set, or nullptr. More... | |
SkScalar | getSize () const |
Returns text size in points. More... | |
SkScalar | getScaleX () const |
Returns text scale on x-axis. More... | |
SkScalar | getSkewX () const |
Returns text skew on x-axis. More... | |
sk_sp< SkTypeface > | refTypeface () const |
Increases SkTypeface SkRefCnt by one. More... | |
void | setTypeface (sk_sp< SkTypeface > tf) |
Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface. More... | |
void | setSize (SkScalar textSize) |
Sets text size in points. More... | |
void | setScaleX (SkScalar scaleX) |
Sets text scale on x-axis. More... | |
void | setSkewX (SkScalar skewX) |
Sets text skew on x-axis. More... | |
int | textToGlyphs (const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const |
Converts text into glyph indices. More... | |
SkGlyphID | unicharToGlyph (SkUnichar uni) const |
Returns glyph index for Unicode character. More... | |
void | unicharsToGlyphs (const SkUnichar uni[], int count, SkGlyphID glyphs[]) const |
int | countText (const void *text, size_t byteLength, SkTextEncoding encoding) const |
Returns number of glyphs represented by text. More... | |
SkScalar | measureText (const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const |
Returns the advance width of text. More... | |
SkScalar | measureText (const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds, const SkPaint *paint) const |
Returns the advance width of text. More... | |
void | getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const |
DEPRECATED Retrieves the advance and bounds for each glyph in glyphs. More... | |
void | getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[], std::nullptr_t) const |
void | getWidths (const SkGlyphID glyphs[], int count, SkScalar widths[]) const |
Retrieves the advance and bounds for each glyph in glyphs. More... | |
void | getWidthsBounds (const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[], const SkPaint *paint) const |
Retrieves the advance and bounds for each glyph in glyphs. More... | |
void | getBounds (const SkGlyphID glyphs[], int count, SkRect bounds[], const SkPaint *paint) const |
Retrieves the bounds for each glyph in glyphs. More... | |
void | getPos (const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin={0, 0}) const |
Retrieves the positions for each glyph, beginning at the specified origin. More... | |
void | getXPos (const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin=0) const |
Retrieves the x-positions for each glyph, beginning at the specified origin. More... | |
std::vector< SkScalar > | getIntercepts (const SkGlyphID glyphs[], int count, const SkPoint pos[], SkScalar top, SkScalar bottom, const SkPaint *=nullptr) const |
Returns intervals [start, end] describing lines parallel to the advance that intersect with the glyphs. More... | |
bool | getPath (SkGlyphID glyphID, SkPath *path) const |
Modifies path to be the outline of the glyph. More... | |
void | getPaths (const SkGlyphID glyphIDs[], int count, void(*glyphPathProc)(const SkPath *pathOrNull, const SkMatrix &mx, void *ctx), void *ctx) const |
Returns path corresponding to glyph array. More... | |
SkScalar | getMetrics (SkFontMetrics *metrics) const |
Returns SkFontMetrics associated with SkTypeface. More... | |
SkScalar | getSpacing () const |
Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading. More... | |
void | dump () const |
Dumps fields of the font to SkDebugf. More... | |
Friends | |
class | SkFontPriv |
class | SkGlyphRunListPainterCPU |
class | SkStrikeSpec |
class | SkRemoteGlyphCacheTest |
SkFont controls options applied when drawing and measuring text.
using SkFont::sk_is_trivially_relocatable = std::true_type |
|
strong |
SkFont::SkFont | ( | sk_sp< SkTypeface > | typeface, |
SkScalar | size | ||
) |
Constructs SkFont with default values with SkTypeface and size in points.
typeface | font and style used to draw and measure text |
size | typographic height of text |
|
explicit |
Constructs SkFont with default values with SkTypeface.
typeface | font and style used to draw and measure text |
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.
typeface | font and style used to draw and measure text |
size | typographic height of text |
scaleX | text horizontal scale |
skewX | additional shear on x-axis relative to y-axis |
|
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.
text | character storage encoded with SkTextEncoding |
byteLength | length of character storage in bytes |
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.
|
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.
glyphs | array of glyph indices to be measured |
count | number of glyphs |
bounds | returns bounds for each glyph relative to (0, 0); may be nullptr |
paint | optional, specifies stroking, SkPathEffect, and SkMaskFilter |
|
inline |
Whether edge pixels draw opaque or with partial transparency.
|
inline |
Returns level of glyph outline adjustment.
std::vector<SkScalar> SkFont::getIntercepts | ( | const SkGlyphID | glyphs[], |
int | count, | ||
const SkPoint | pos[], | ||
SkScalar | top, | ||
SkScalar | bottom, | ||
const SkPaint * | = nullptr |
||
) | const |
Returns intervals [start, end] describing lines parallel to the advance that intersect with the glyphs.
glyphs | the glyphs to intersect |
count | the number of glyphs and positions |
pos | the position of each glyph |
top | the top of the line intersecting |
bottom | the bottom of the line intersecting |
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.
metrics | storage for SkFontMetrics; may be nullptr |
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.
glyphID | index of glyph |
path | pointer to existing SkPath |
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.
glyphIDs | array of glyph indices |
count | number of glyphs |
glyphPathProc | function returning one glyph description as path |
ctx | function context |
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.
glyphs | array of glyph indices to be positioned |
count | number of glyphs |
pos | returns glyphs positions |
origin | location of the first glyph. Defaults to {0, 0}. |
|
inline |
Returns text scale on x-axis.
Default value is 1.
|
inline |
Returns text size in points.
|
inline |
Returns text skew on x-axis.
Default value is zero.
|
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().
|
inline |
Returns SkTypeface if set, or nullptr.
Does not alter SkTypeface SkRefCnt.
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.
glyphs | array of glyph indices to be measured |
count | number of glyphs |
widths | returns text advances for each glyph |
|
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.
glyphs | array of glyph indices to be measured |
count | number of glyphs |
widths | returns text advances for each glyph; may be nullptr |
bounds | returns bounds for each glyph relative to (0, 0); may be nullptr |
|
inline |
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.
glyphs | array of glyph indices to be measured |
count | number of glyphs |
widths | returns text advances for each glyph; may be nullptr |
bounds | returns bounds for each glyph relative to (0, 0); may be nullptr |
paint | optional, specifies stroking, SkPathEffect and SkMaskFilter |
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.
glyphs | array of glyph indices to be positioned |
count | number of glyphs |
xpos | returns glyphs x-positions |
origin | x-position of the first glyph. Defaults to 0. |
|
inline |
Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.
|
inline |
Returns true if font engine may return glyphs from font bitmaps instead of from outlines.
|
inline |
Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.
|
inline |
If true, instructs the font manager to always hint glyphs.
Returned value is only meaningful if platform uses FreeType as the font manager.
|
inline |
Returns true if font and glyph metrics are requested to be linearly scalable.
|
inline |
Returns true if glyphs may be drawn at sub-pixel offsets.
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.
size | typographic height of text |
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.
text | character storage encoded with SkTextEncoding |
byteLength | length of character storage in bytes |
bounds | returns bounding box relative to (0, 0) if not nullptr |
paint | optional; may be nullptr |
|
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.
text | character storage encoded with SkTextEncoding |
byteLength | length of character storage in bytes |
bounds | returns bounding box relative to (0, 0) if not nullptr |
|
inline |
Compares SkFont and font, and returns true if they are not equivalent.
May return true if SkTypeface has identical contents but different pointers.
font | font to compare |
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.
font | font to compare |
|
inline |
Increases SkTypeface SkRefCnt by one.
void SkFont::setBaselineSnap | ( | bool | baselineSnap | ) |
Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.
baselineSnap | setting for baseline snapping to pixels |
void SkFont::setEdging | ( | Edging | edging | ) |
Requests, but does not require, that edge pixels draw opaque or with partial transparency.
void SkFont::setEmbeddedBitmaps | ( | bool | embeddedBitmaps | ) |
Requests, but does not require, to use bitmaps in fonts instead of outlines.
embeddedBitmaps | setting to use bitmaps in fonts |
void SkFont::setEmbolden | ( | bool | embolden | ) |
Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
embolden | setting for bold approximation |
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.
forceAutoHinting | setting to always hint glyphs |
void SkFont::setHinting | ( | SkFontHinting | hintingLevel | ) |
Sets level of glyph outline adjustment.
Does not check for valid values of hintingLevel.
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.
linearMetrics | setting for linearly scalable font and glyph metrics. |
void SkFont::setScaleX | ( | SkScalar | scaleX | ) |
Sets text scale on x-axis.
Default value is 1.
scaleX | text horizontal scale |
void SkFont::setSize | ( | SkScalar | textSize | ) |
Sets text size in points.
Has no effect if textSize is not greater than or equal to zero.
textSize | typographic height of text |
void SkFont::setSkewX | ( | SkScalar | skewX | ) |
Sets text skew on x-axis.
Default value is zero.
skewX | additional shear on x-axis relative to y-axis |
void SkFont::setSubpixel | ( | bool | subpixel | ) |
Requests, but does not require, that glyphs respect sub-pixel positioning.
subpixel | setting for sub-pixel positioning |
|
inline |
Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
Pass nullptr to clear SkTypeface and use the default typeface. Increments tf SkRefCnt by one.
tf | font and style used to draw text |
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.
text | character storage encoded with SkTextEncoding |
byteLength | length of character storage in bytes |
glyphs | storage for glyph indices; may be nullptr |
maxGlyphCount | storage capacity |
Returns glyph index for Unicode character.
If the character is not supported by the SkTypeface, returns 0.
uni | Unicode character |
|
friend |
|
friend |
|
friend |
|
friend |