42#define kDefault_Size SkPaintDefaults_TextSize
43#define kDefault_Flags SkFont::kBaselineSnap_PrivFlag
44#define kDefault_Edging SkFont::Edging::kAntiAlias
45#define kDefault_Hinting SkPaintDefaults_Hinting
48 return std::max<SkScalar>(0, size);
52 : fTypeface(
std::move(face))
71 return fTypeface.
get() ==
b.fTypeface.get() &&
73 fScaleX ==
b.fScaleX &&
76 fEdging ==
b.fEdging &&
77 fHinting ==
b.fHinting;
86 SkDebugf(
"edging %u\n", (
unsigned)fEdging);
87 SkDebugf(
"hinting %u\n", (
unsigned)fHinting);
91 fTypeface = std::move(tf);
99static inline uint32_t
set_clear_mask(uint32_t bits,
bool cond, uint32_t mask) {
100 return cond ? bits | mask : bits & ~mask;
104 fFlags =
set_clear_mask(fFlags, predicate, kForceAutoHinting_PrivFlag);
107 fFlags =
set_clear_mask(fFlags, predicate, kEmbeddedBitmaps_PrivFlag);
113 fFlags =
set_clear_mask(fFlags, predicate, kLinearMetrics_PrivFlag);
119 fFlags =
set_clear_mask(fFlags, predicate, kBaselineSnap_PrivFlag);
141 font.setSize(newSize);
148 constexpr uint32_t flagsToIgnore = kEmbeddedBitmaps_PrivFlag |
149 kForceAutoHinting_PrivFlag;
151 fFlags = (fFlags & ~flagsToIgnore) | kSubpixel_PrivFlag;
160 paint->setPathEffect(
nullptr);
167bool SkFont::hasSomeAntiAliasing()
const {
191 const int glyphCount = atg.
count();
192 if (glyphCount == 0) {
206 *bounds =
glyphs[0]->rect();
208 for (
int i = 1; i < glyphCount; ++i) {
215 for (
auto glyph :
glyphs) {
216 width += glyph->advanceX();
220 if (strikeToSourceScale != 1) {
221 width *= strikeToSourceScale;
223 bounds->fLeft *= strikeToSourceScale;
224 bounds->fTop *= strikeToSourceScale;
225 bounds->fRight *= strikeToSourceScale;
226 bounds->fBottom *= strikeToSourceScale;
245 for (
auto glyph :
glyphs) {
252 for (
auto glyph :
glyphs) {
253 *cursor++ = glyph->advanceX() * strikeToSourceScale;
264 for (
auto glyph :
glyphs) {
266 sum += glyph->advanceVector() * strikeToSourceScale;
279 for (
auto glyph :
glyphs) {
281 loc += glyph->advanceX() * strikeToSourceScale;
286 void (*proc)(
const SkPath*,
const SkMatrix&,
void*),
void* ctx)
const {
295 for (
auto glyph :
glyphs) {
296 proc(glyph->path(), mx, ctx);
304 } pair = { path,
false };
307 Pair* pair =
static_cast<Pair*
>(ctx);
310 pair->fWasSet =
true;
321 if (
nullptr == metrics) {
325 auto cache = strikeSpec.findOrCreateStrike();
326 *metrics = cache->getFontMetrics();
328 if (strikeToSourceScale != 1) {
356 m.setScale(font.getSize() * font.getScaleX(), font.getSize());
357 m.postSkew(font.getSkewX(), 0);
362 m.mapRect(&bounds, typeface->
getBounds());
368 if (!matrix.hasPerspective()) {
369 return font.getSize() * matrix.getMaxScale();
376 return -font.getSize();
388 return byteLength >> 2;
390 return byteLength >> 1;
402 auto typeface = font.getTypeface();
403 const unsigned numGlyphsInTypeface = typeface->countGlyphs();
405 typeface->getGlyphToUnicodeMap(unichars.
get());
407 for (
int i = 0; i <
count; ++i) {
409 text[i] = (
id < numGlyphsInTypeface) ? unichars[
id] : 0xFFFD;
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool SkIsFinite(T x, Pack... values)
@ kNone
glyph outlines unchanged
@ 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
static SkScalar valid_size(SkScalar size)
static uint32_t set_clear_mask(uint32_t bits, bool cond, uint32_t mask)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
constexpr uint8_t SkToU8(S x)
const uint16_t * glyphs() const
static int CountTextElements(const void *text, size_t byteLength, SkTextEncoding)
static void ScaleFontMetrics(SkFontMetrics *, SkScalar)
static SkScalar ApproximateTransformedTextSize(const SkFont &font, const SkMatrix &matrix, const SkPoint &textLocation)
static constexpr int kCanonicalTextSizeForPaths
static void GlyphsToUnichars(const SkFont &, const uint16_t glyphs[], int count, SkUnichar[])
static SkRect GetFontBounds(const SkFont &)
void setSubpixel(bool subpixel)
void getXPos(const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin=0) const
bool getPath(SkGlyphID glyphID, SkPath *path) const
void setScaleX(SkScalar scaleX)
bool operator==(const SkFont &font) const
void setLinearMetrics(bool linearMetrics)
SkTypeface * getTypeface() const
void setTypeface(sk_sp< SkTypeface > tf)
SkScalar measureText(const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const
void setBaselineSnap(bool baselineSnap)
void getPos(const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin={0, 0}) const
void setEdging(Edging edging)
void setSize(SkScalar textSize)
void getPaths(const SkGlyphID glyphIDs[], int count, void(*glyphPathProc)(const SkPath *pathOrNull, const SkMatrix &mx, void *ctx), void *ctx) const
void setSkewX(SkScalar skewX)
void setForceAutoHinting(bool forceAutoHinting)
SkGlyphID unicharToGlyph(SkUnichar uni) const
SkScalar getMetrics(SkFontMetrics *metrics) const
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
SkFont makeWithSize(SkScalar size) const
void setHinting(SkFontHinting hintingLevel)
@ kAntiAlias
may have transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
void setEmbolden(bool embolden)
void setEmbeddedBitmaps(bool embeddedBitmaps)
void getWidthsBounds(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[], const SkPaint *paint) const
static SkScalar DifferentialAreaScale(const SkMatrix &m, const SkPoint &p)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
void mapRectScaleTranslate(SkRect *dst, const SkRect &src) const
@ kFill_Style
set to fill geometry
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
static std::tuple< SkStrikeSpec, SkScalar > MakeCanonicalized(const SkFont &font, const SkPaint *paint=nullptr)
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
static sk_sp< SkTypeface > MakeEmpty()
SkGlyphID unicharToGlyph(SkUnichar unichar) const
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
SK_SPI int CountUTF16(const uint16_t *utf16, size_t byteLength)
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
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...
void offset(float dx, float dy)