2014-04-08 15:04:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-05-30 16:46:10 +00:00
|
|
|
#ifndef SkFont_DEFINED
|
|
|
|
#define SkFont_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2021-05-14 13:53:30 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-11-25 03:55:54 +00:00
|
|
|
class SkMatrix;
|
2014-04-08 15:04:29 +00:00
|
|
|
class SkPaint;
|
2018-11-14 16:52:54 +00:00
|
|
|
class SkPath;
|
2018-11-09 19:31:44 +00:00
|
|
|
struct SkFontMetrics;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** \class SkFont
|
|
|
|
SkFont controls options applied when drawing and measuring text.
|
|
|
|
*/
|
2018-10-30 11:58:59 +00:00
|
|
|
class SK_API SkFont {
|
2014-04-08 15:04:29 +00:00
|
|
|
public:
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Whether edge pixels draw opaque or with partial transparency.
|
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
enum class Edging {
|
2018-11-19 01:09:42 +00:00
|
|
|
kAlias, //!< no transparent pixels on glyph edges
|
|
|
|
kAntiAlias, //!< may have transparent pixels on glyph edges
|
|
|
|
kSubpixelAntiAlias, //!< glyph positioned in pixel using transparency
|
2018-11-12 18:19:37 +00:00
|
|
|
};
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Constructs SkFont with default values.
|
|
|
|
|
|
|
|
@return default initialized SkFont
|
|
|
|
*/
|
2018-10-24 17:34:11 +00:00
|
|
|
SkFont();
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Constructs SkFont with default values with SkTypeface and size in points.
|
|
|
|
|
|
|
|
@param typeface font and style used to draw and measure text
|
|
|
|
@param size typographic height of text
|
|
|
|
@return initialized SkFont
|
|
|
|
*/
|
|
|
|
SkFont(sk_sp<SkTypeface> typeface, SkScalar size);
|
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Constructs SkFont with default values with SkTypeface.
|
|
|
|
|
|
|
|
@param typeface font and style used to draw and measure text
|
|
|
|
@return initialized SkFont
|
|
|
|
*/
|
2018-12-13 15:06:02 +00:00
|
|
|
explicit SkFont(sk_sp<SkTypeface> typeface);
|
2018-12-13 13:38:22 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param typeface font and style used to draw and measure text
|
|
|
|
@param size typographic height of text
|
|
|
|
@param scaleX text horizontal scale
|
|
|
|
@param skewX additional shear on x-axis relative to y-axis
|
|
|
|
@return initialized SkFont
|
|
|
|
*/
|
|
|
|
SkFont(sk_sp<SkTypeface> typeface, SkScalar size, SkScalar scaleX, SkScalar skewX);
|
|
|
|
|
2018-11-26 15:43:14 +00:00
|
|
|
|
|
|
|
/** Compares SkFont and font, and returns true if they are equivalent.
|
|
|
|
May return false if SkTypeface has identical contents but different pointers.
|
|
|
|
|
2018-12-03 19:37:47 +00:00
|
|
|
@param font font to compare
|
2018-11-26 15:43:14 +00:00
|
|
|
@return true if SkFont pair are equivalent
|
|
|
|
*/
|
|
|
|
bool operator==(const SkFont& font) const;
|
2019-01-07 20:16:56 +00:00
|
|
|
|
|
|
|
/** Compares SkFont and font, and returns true if they are not equivalent.
|
|
|
|
May return true if SkTypeface has identical contents but different pointers.
|
|
|
|
|
|
|
|
@param font font to compare
|
|
|
|
@return true if SkFont pair are not equivalent
|
|
|
|
*/
|
2018-12-03 19:37:47 +00:00
|
|
|
bool operator!=(const SkFont& font) const { return !(*this == font); }
|
2018-11-21 20:10:08 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** If true, instructs the font manager to always hint glyphs.
|
|
|
|
Returned value is only meaningful if platform uses FreeType as the font manager.
|
|
|
|
|
|
|
|
@return true if all glyphs are hinted
|
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
bool isForceAutoHinting() const { return SkToBool(fFlags & kForceAutoHinting_PrivFlag); }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns true if font engine may return glyphs from font bitmaps instead of from outlines.
|
|
|
|
|
|
|
|
@return true if glyphs may be font bitmaps
|
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
bool isEmbeddedBitmaps() const { return SkToBool(fFlags & kEmbeddedBitmaps_PrivFlag); }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
/** Returns true if glyphs may be drawn at sub-pixel offsets.
|
2018-11-19 01:09:42 +00:00
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
@return true if glyphs may be drawn at sub-pixel offsets.
|
2018-11-19 01:09:42 +00:00
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
bool isSubpixel() const { return SkToBool(fFlags & kSubpixel_PrivFlag); }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
/** Returns true if font and glyph metrics are requested to be linearly scalable.
|
2018-11-19 01:09:42 +00:00
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
@return true if font and glyph metrics are requested to be linearly scalable.
|
2018-11-19 01:09:42 +00:00
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
bool isLinearMetrics() const { return SkToBool(fFlags & kLinearMetrics_PrivFlag); }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns true if bold is approximated by increasing the stroke width when creating glyph
|
|
|
|
bitmaps from outlines.
|
|
|
|
|
|
|
|
@return bold is approximated through stroke width
|
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
bool isEmbolden() const { return SkToBool(fFlags & kEmbolden_PrivFlag); }
|
2018-10-24 17:34:11 +00:00
|
|
|
|
2019-08-26 20:59:09 +00:00
|
|
|
/** Returns true if baselines will be snapped to pixel positions when the current transformation
|
|
|
|
matrix is axis aligned.
|
|
|
|
|
|
|
|
@return baselines may be snapped to pixels
|
|
|
|
*/
|
|
|
|
bool isBaselineSnap() const { return SkToBool(fFlags & kBaselineSnap_PrivFlag); }
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Sets whether to always hint glyphs.
|
|
|
|
If forceAutoHinting is set, instructs the font manager to always hint glyphs.
|
2018-10-29 14:09:09 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
Only affects platforms that use FreeType as the font manager.
|
|
|
|
|
|
|
|
@param forceAutoHinting setting to always hint glyphs
|
|
|
|
*/
|
|
|
|
void setForceAutoHinting(bool forceAutoHinting);
|
|
|
|
|
|
|
|
/** Requests, but does not require, to use bitmaps in fonts instead of outlines.
|
|
|
|
|
|
|
|
@param embeddedBitmaps setting to use bitmaps in fonts
|
|
|
|
*/
|
|
|
|
void setEmbeddedBitmaps(bool embeddedBitmaps);
|
|
|
|
|
|
|
|
/** Requests, but does not require, that glyphs respect sub-pixel positioning.
|
|
|
|
|
|
|
|
@param subpixel setting for sub-pixel positioning
|
|
|
|
*/
|
|
|
|
void setSubpixel(bool subpixel);
|
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
/** Requests, but does not require, linearly scalable font and glyph metrics.
|
2018-11-19 01:09:42 +00:00
|
|
|
|
2019-05-07 15:09:58 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param linearMetrics setting for linearly scalable font and glyph metrics.
|
2018-11-19 01:09:42 +00:00
|
|
|
*/
|
|
|
|
void setLinearMetrics(bool linearMetrics);
|
|
|
|
|
|
|
|
/** Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
|
|
|
|
|
|
|
|
@param embolden setting for bold approximation
|
|
|
|
*/
|
|
|
|
void setEmbolden(bool embolden);
|
|
|
|
|
2019-08-26 20:59:09 +00:00
|
|
|
/** Requests that baselines be snapped to pixels when the current transformation matrix is axis
|
|
|
|
aligned.
|
|
|
|
|
|
|
|
@param baselineSnap setting for baseline snapping to pixels
|
|
|
|
*/
|
|
|
|
void setBaselineSnap(bool baselineSnap);
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Whether edge pixels draw opaque or with partial transparency.
|
|
|
|
*/
|
2018-11-12 18:19:37 +00:00
|
|
|
Edging getEdging() const { return (Edging)fEdging; }
|
2018-10-29 14:09:09 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Requests, but does not require, that edge pixels draw opaque or with
|
|
|
|
partial transparency.
|
|
|
|
*/
|
|
|
|
void setEdging(Edging edging);
|
|
|
|
|
|
|
|
/** Sets level of glyph outline adjustment.
|
|
|
|
Does not check for valid values of hintingLevel.
|
|
|
|
*/
|
|
|
|
void setHinting(SkFontHinting hintingLevel);
|
2018-10-24 17:34:11 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Returns level of glyph outline adjustment.
|
|
|
|
*/
|
2018-11-09 21:59:13 +00:00
|
|
|
SkFontHinting getHinting() const { return (SkFontHinting)fHinting; }
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Returns a font with the same attributes of this font, but with the specified size.
|
2018-11-26 15:43:14 +00:00
|
|
|
Returns nullptr if size is less than zero, infinite, or NaN.
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
@param size typographic height of text
|
|
|
|
@return initialized SkFont
|
2014-04-08 15:04:29 +00:00
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
SkFont makeWithSize(SkScalar size) const;
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Returns SkTypeface if set, or nullptr.
|
|
|
|
Does not alter SkTypeface SkRefCnt.
|
|
|
|
|
|
|
|
@return SkTypeface if previously set, nullptr otherwise
|
|
|
|
*/
|
2019-01-22 19:45:16 +00:00
|
|
|
SkTypeface* getTypeface() const {return fTypeface.get(); }
|
|
|
|
|
|
|
|
/** Returns SkTypeface if set, or the default typeface.
|
|
|
|
Does not alter SkTypeface SkRefCnt.
|
|
|
|
|
|
|
|
@return SkTypeface if previously set or, a pointer to the default typeface if not
|
|
|
|
previously set.
|
|
|
|
*/
|
|
|
|
SkTypeface* getTypefaceOrDefault() const;
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns text size in points.
|
|
|
|
|
|
|
|
@return typographic height of text
|
|
|
|
*/
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar getSize() const { return fSize; }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns text scale on x-axis.
|
|
|
|
Default value is 1.
|
|
|
|
|
|
|
|
@return text horizontal scale
|
|
|
|
*/
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar getScaleX() const { return fScaleX; }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns text skew on x-axis.
|
|
|
|
Default value is zero.
|
|
|
|
|
|
|
|
@return additional shear on x-axis relative to y-axis
|
|
|
|
*/
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar getSkewX() const { return fSkewX; }
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Increases SkTypeface SkRefCnt by one.
|
|
|
|
|
|
|
|
@return SkTypeface if previously set, nullptr otherwise
|
|
|
|
*/
|
2018-10-22 18:24:07 +00:00
|
|
|
sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
|
|
|
|
|
2019-01-22 19:45:16 +00:00
|
|
|
/** Increases SkTypeface SkRefCnt by one.
|
|
|
|
|
|
|
|
@return SkTypeface if previously set or, a pointer to the default typeface if not
|
|
|
|
previously set.
|
|
|
|
*/
|
|
|
|
sk_sp<SkTypeface> refTypefaceOrDefault() const;
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param tf font and style used to draw text
|
|
|
|
*/
|
2018-10-24 17:34:11 +00:00
|
|
|
void setTypeface(sk_sp<SkTypeface> tf) { fTypeface = tf; }
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Sets text size in points.
|
|
|
|
Has no effect if textSize is not greater than or equal to zero.
|
|
|
|
|
|
|
|
@param textSize typographic height of text
|
|
|
|
*/
|
|
|
|
void setSize(SkScalar textSize);
|
|
|
|
|
|
|
|
/** Sets text scale on x-axis.
|
|
|
|
Default value is 1.
|
|
|
|
|
|
|
|
@param scaleX text horizontal scale
|
|
|
|
*/
|
|
|
|
void setScaleX(SkScalar scaleX);
|
|
|
|
|
|
|
|
/** Sets text skew on x-axis.
|
|
|
|
Default value is zero.
|
|
|
|
|
|
|
|
@param skewX additional shear on x-axis relative to y-axis
|
|
|
|
*/
|
|
|
|
void setSkewX(SkScalar skewX);
|
2014-05-30 16:46:10 +00:00
|
|
|
|
2018-11-02 16:08:31 +00:00
|
|
|
/** 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.
|
|
|
|
|
2019-05-07 19:38:46 +00:00
|
|
|
If encoding is SkTextEncoding::kUTF8 and text contains an invalid UTF-8 sequence,
|
2018-11-02 16:08:31 +00:00
|
|
|
zero is returned.
|
|
|
|
|
2019-01-16 15:32:54 +00:00
|
|
|
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.
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied.
|
|
|
|
The total glyph count is returned for subsequent buffer reallocation.
|
2018-11-02 16:08:31 +00:00
|
|
|
|
2018-12-03 14:45:17 +00:00
|
|
|
@param text character storage encoded with SkTextEncoding
|
2018-11-02 16:08:31 +00:00
|
|
|
@param byteLength length of character storage in bytes
|
|
|
|
@param glyphs storage for glyph indices; may be nullptr
|
|
|
|
@param maxGlyphCount storage capacity
|
|
|
|
@return number of glyphs represented by text of length byteLength
|
|
|
|
*/
|
2018-11-19 01:09:42 +00:00
|
|
|
int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
|
2016-07-25 14:18:12 +00:00
|
|
|
SkGlyphID glyphs[], int maxGlyphCount) const;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Returns glyph index for Unicode character.
|
|
|
|
|
2019-01-16 15:32:54 +00:00
|
|
|
If the character is not supported by the SkTypeface, returns 0.
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
@param uni Unicode character
|
|
|
|
@return glyph index
|
|
|
|
*/
|
2019-02-01 14:55:20 +00:00
|
|
|
SkGlyphID unicharToGlyph(SkUnichar uni) const;
|
2018-10-29 14:09:09 +00:00
|
|
|
|
2019-04-16 18:37:38 +00:00
|
|
|
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const;
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** Returns number of glyphs represented by text.
|
|
|
|
|
2019-05-07 19:38:46 +00:00
|
|
|
If encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or
|
|
|
|
SkTextEncoding::kUTF32; then each Unicode codepoint is mapped to a
|
2019-01-16 15:32:54 +00:00
|
|
|
single glyph.
|
|
|
|
|
2018-12-03 14:45:17 +00:00
|
|
|
@param text character storage encoded with SkTextEncoding
|
2018-11-19 01:09:42 +00:00
|
|
|
@param byteLength length of character storage in bytes
|
|
|
|
@return number of glyphs represented by text of length byteLength
|
|
|
|
*/
|
2018-11-14 16:52:54 +00:00
|
|
|
int countText(const void* text, size_t byteLength, SkTextEncoding encoding) const {
|
2016-07-19 14:59:22 +00:00
|
|
|
return this->textToGlyphs(text, byteLength, encoding, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** 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.
|
|
|
|
|
2018-12-03 14:45:17 +00:00
|
|
|
@param text character storage encoded with SkTextEncoding
|
2018-11-19 01:09:42 +00:00
|
|
|
@param byteLength length of character storage in bytes
|
|
|
|
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
|
|
|
@return number of glyphs represented by text of length byteLength
|
|
|
|
*/
|
|
|
|
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
2018-12-16 19:49:15 +00:00
|
|
|
SkRect* bounds = nullptr) const {
|
|
|
|
return this->measureText(text, byteLength, encoding, bounds, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Returns the advance width of text.
|
|
|
|
The advance is the normal distance to move before drawing additional text.
|
2020-11-11 15:54:50 +00:00
|
|
|
Returns the bounding box of text if bounds is not nullptr. The paint
|
|
|
|
stroke settings, mask filter, or path effect may modify the bounds.
|
2019-01-07 20:16:56 +00:00
|
|
|
|
|
|
|
@param text character storage encoded with SkTextEncoding
|
|
|
|
@param byteLength length of character storage in bytes
|
|
|
|
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
|
|
|
@param paint optional; may be nullptr
|
|
|
|
@return number of glyphs represented by text of length byteLength
|
|
|
|
*/
|
2018-12-16 19:49:15 +00:00
|
|
|
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
2019-01-07 20:16:56 +00:00
|
|
|
SkRect* bounds, const SkPaint* paint) const;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2018-11-27 17:27:15 +00:00
|
|
|
/** DEPRECATED
|
|
|
|
Retrieves the advance and bounds for each glyph in glyphs.
|
2018-11-19 01:09:42 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be measured
|
|
|
|
@param count number of glyphs
|
|
|
|
@param widths returns text advances for each glyph; may be nullptr
|
|
|
|
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
|
2018-11-27 17:27:15 +00:00
|
|
|
this->getWidthsBounds(glyphs, count, widths, bounds, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED
|
2019-03-15 19:42:55 +00:00
|
|
|
void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], std::nullptr_t) const {
|
2018-11-27 17:27:15 +00:00
|
|
|
this->getWidths(glyphs, count, widths);
|
|
|
|
}
|
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Retrieves the advance and bounds for each glyph in glyphs.
|
2018-11-27 17:27:15 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be measured
|
|
|
|
@param count number of glyphs
|
|
|
|
@param widths returns text advances for each glyph
|
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[]) const {
|
2018-11-27 17:27:15 +00:00
|
|
|
this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Retrieves the advance and bounds for each glyph in glyphs.
|
2018-11-27 17:27:15 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be measured
|
|
|
|
@param count number of glyphs
|
|
|
|
@param widths returns text advances for each glyph; may be nullptr
|
|
|
|
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
2018-12-11 13:41:11 +00:00
|
|
|
@param paint optional, specifies stroking, SkPathEffect and SkMaskFilter
|
2018-11-27 17:27:15 +00:00
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getWidthsBounds(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[],
|
2018-11-27 17:27:15 +00:00
|
|
|
const SkPaint* paint) const;
|
|
|
|
|
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Retrieves the bounds for each glyph in glyphs.
|
2018-11-27 17:27:15 +00:00
|
|
|
bounds must be an array of count entries.
|
2018-12-11 13:41:11 +00:00
|
|
|
If paint is not nullptr, its stroking, SkPathEffect, and SkMaskFilter fields are respected.
|
2018-11-27 17:27:15 +00:00
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be measured
|
|
|
|
@param count number of glyphs
|
|
|
|
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
2018-12-11 13:41:11 +00:00
|
|
|
@param paint optional, specifies stroking, SkPathEffect, and SkMaskFilter
|
2018-11-27 17:27:15 +00:00
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getBounds(const SkGlyphID glyphs[], int count, SkRect bounds[],
|
2018-11-29 17:05:25 +00:00
|
|
|
const SkPaint* paint) const {
|
2018-11-27 17:27:15 +00:00
|
|
|
this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
|
|
|
|
}
|
2018-11-12 01:37:45 +00:00
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Retrieves the positions for each glyph, beginning at the specified origin. The caller
|
2018-11-24 18:27:27 +00:00
|
|
|
must allocated at least count number of elements in the pos[] array.
|
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be positioned
|
|
|
|
@param count number of glyphs
|
|
|
|
@param pos returns glyphs positions
|
|
|
|
@param origin location of the first glyph. Defaults to {0, 0}.
|
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getPos(const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const;
|
2018-11-24 18:27:27 +00:00
|
|
|
|
2019-01-07 20:16:56 +00:00
|
|
|
/** Retrieves the x-positions for each glyph, beginning at the specified origin. The caller
|
2018-11-24 18:27:27 +00:00
|
|
|
must allocated at least count number of elements in the xpos[] array.
|
|
|
|
|
|
|
|
@param glyphs array of glyph indices to be positioned
|
|
|
|
@param count number of glyphs
|
2018-11-26 15:43:14 +00:00
|
|
|
@param xpos returns glyphs x-positions
|
2018-11-24 18:27:27 +00:00
|
|
|
@param origin x-position of the first glyph. Defaults to 0.
|
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getXPos(const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const;
|
2018-11-24 18:27:27 +00:00
|
|
|
|
2021-05-14 13:53:30 +00:00
|
|
|
/** Returns intervals [start, end] describing lines parallel to the advance that intersect
|
|
|
|
* with the glyphs.
|
|
|
|
*
|
|
|
|
* @param glyphs the glyphs to intersect
|
|
|
|
* @param count the number of glyphs and positions
|
|
|
|
* @param pos the position of each glyph
|
|
|
|
* @param top the top of the line intersecting
|
|
|
|
* @param bottom the bottom of the line intersecting
|
|
|
|
@return array of pairs of x values [start, end]. May be empty.
|
|
|
|
*/
|
|
|
|
std::vector<SkScalar> getIntercepts(const SkGlyphID glyphs[], int count, const SkPoint pos[],
|
|
|
|
SkScalar top, SkScalar bottom,
|
|
|
|
const SkPaint* = nullptr) const;
|
|
|
|
|
2020-01-27 22:43:41 +00:00
|
|
|
/** 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.
|
2018-11-19 01:09:42 +00:00
|
|
|
If glyph is described by a bitmap, returns false and ignores path parameter.
|
|
|
|
|
|
|
|
@param glyphID index of glyph
|
|
|
|
@param path pointer to existing SkPath
|
|
|
|
@return true if glyphID is described by path
|
2018-11-14 16:52:54 +00:00
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
bool getPath(SkGlyphID glyphID, SkPath* path) const;
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** Returns path corresponding to glyph array.
|
|
|
|
|
|
|
|
@param glyphIDs array of glyph indices
|
|
|
|
@param count number of glyphs
|
|
|
|
@param glyphPathProc function returning one glyph description as path
|
|
|
|
@param ctx function context
|
|
|
|
*/
|
2019-03-15 19:42:55 +00:00
|
|
|
void getPaths(const SkGlyphID glyphIDs[], int count,
|
2018-11-25 03:55:54 +00:00
|
|
|
void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
|
2018-11-14 16:52:54 +00:00
|
|
|
void* ctx) const;
|
|
|
|
|
2018-11-19 01:09:42 +00:00
|
|
|
/** 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
|
2018-11-26 15:43:14 +00:00
|
|
|
dimensions required by text scale, text skew, fake bold,
|
2018-11-19 01:09:42 +00:00
|
|
|
style stroke, and SkPathEffect.
|
|
|
|
|
|
|
|
@param metrics storage for SkFontMetrics; may be nullptr
|
|
|
|
@return recommended spacing between lines
|
|
|
|
*/
|
2018-11-09 19:31:44 +00:00
|
|
|
SkScalar getMetrics(SkFontMetrics* metrics) const;
|
2018-11-19 01:09:42 +00:00
|
|
|
|
|
|
|
/** 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().
|
|
|
|
|
|
|
|
@return recommended spacing between lines
|
|
|
|
*/
|
2018-11-09 19:31:44 +00:00
|
|
|
SkScalar getSpacing() const { return this->getMetrics(nullptr); }
|
|
|
|
|
2019-04-18 17:41:21 +00:00
|
|
|
/** Dumps fields of the font to SkDebugf. May change its output over time, so clients should
|
2018-12-16 21:01:18 +00:00
|
|
|
* not rely on this for anything specific. Used to aid in debugging.
|
|
|
|
*/
|
2018-12-16 19:49:15 +00:00
|
|
|
void dump() const;
|
|
|
|
|
2014-04-08 15:04:29 +00:00
|
|
|
private:
|
2018-11-12 18:19:37 +00:00
|
|
|
enum PrivFlags {
|
|
|
|
kForceAutoHinting_PrivFlag = 1 << 0,
|
|
|
|
kEmbeddedBitmaps_PrivFlag = 1 << 1,
|
|
|
|
kSubpixel_PrivFlag = 1 << 2,
|
|
|
|
kLinearMetrics_PrivFlag = 1 << 3,
|
|
|
|
kEmbolden_PrivFlag = 1 << 4,
|
2019-08-26 20:59:09 +00:00
|
|
|
kBaselineSnap_PrivFlag = 1 << 5,
|
2018-11-12 18:19:37 +00:00
|
|
|
};
|
|
|
|
|
2019-08-26 20:59:09 +00:00
|
|
|
static constexpr unsigned kAllFlags = kForceAutoHinting_PrivFlag
|
|
|
|
| kEmbeddedBitmaps_PrivFlag
|
|
|
|
| kSubpixel_PrivFlag
|
|
|
|
| kLinearMetrics_PrivFlag
|
|
|
|
| kEmbolden_PrivFlag
|
|
|
|
| kBaselineSnap_PrivFlag;
|
2014-04-08 15:04:29 +00:00
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fTypeface;
|
2014-04-08 15:04:29 +00:00
|
|
|
SkScalar fSize;
|
|
|
|
SkScalar fScaleX;
|
|
|
|
SkScalar fSkewX;
|
2018-10-24 17:34:11 +00:00
|
|
|
uint8_t fFlags;
|
2018-11-12 18:19:37 +00:00
|
|
|
uint8_t fEdging;
|
2018-10-24 17:34:11 +00:00
|
|
|
uint8_t fHinting;
|
2018-11-09 19:31:44 +00:00
|
|
|
|
|
|
|
SkScalar setupForAsPaths(SkPaint*);
|
2018-12-12 16:45:42 +00:00
|
|
|
bool hasSomeAntiAliasing() const;
|
2018-11-09 19:31:44 +00:00
|
|
|
|
2018-12-10 20:26:09 +00:00
|
|
|
friend class SkFontPriv;
|
2018-12-11 02:08:13 +00:00
|
|
|
friend class SkGlyphRunListPainter;
|
2019-06-06 14:50:56 +00:00
|
|
|
friend class SkStrikeSpec;
|
2014-04-08 15:04:29 +00:00
|
|
|
};
|
2014-05-30 16:46:10 +00:00
|
|
|
|
|
|
|
#endif
|