use SkFontHinting from SkFontTypes.h
Bug: skia:2664
Change-Id: Id10cd5efe79681411ce556874fd89ca7624909f7
Reviewed-on: https://skia-review.googlesource.com/c/168267
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/include/core/SkFont.h b/include/core/SkFont.h
index a9d8cbc..70e2a28 100644
--- a/include/core/SkFont.h
+++ b/include/core/SkFont.h
@@ -8,18 +8,12 @@
#ifndef SkFont_DEFINED
#define SkFont_DEFINED
+#include "SkFontTypes.h"
#include "SkScalar.h"
#include "SkTypeface.h"
class SkPaint;
-enum SkTextEncoding {
- kUTF8_SkTextEncoding,
- kUTF16_SkTextEncoding,
- kUTF32_SkTextEncoding,
- kGlyphID_SkTextEncoding,
-};
-
class SK_API SkFont {
public:
enum Flags {
diff --git a/include/core/SkFontTypes.h b/include/core/SkFontTypes.h
index b9619ac..80e31bc 100644
--- a/include/core/SkFontTypes.h
+++ b/include/core/SkFontTypes.h
@@ -25,133 +25,4 @@
kFull_SkFontHinting = 3, //!< modifies glyph outlines for maximum constrast
};
-class SK_API SkFont {
-public:
- enum Flags {
- /**
- * Use the system's automatic hinting mechanism to hint the typeface.
- */
- kForceAutoHinting_Flag = 1 << 0,
-
- /**
- * If the typeface contains explicit bitmaps for hinting, use them.
- * If both bytecode and auto hints are also specified, attempt to use the bitmaps first;
- * if that fails (e.g. there are no bitmaps), then attempt to bytecode or autohint.
- */
- kEmbeddedBitmaps_Flag = 1 << 1,
-
- kSubpixel_Flag = 1 << 2,
- kLinearMetrics_Flag = 1 << 3,
- kEmbolden_Flag = 1 << 4,
-
- kDEPRECATED_Antialias_Flag = 1 << 5,
- kDEPRECATED_LCDRender_Flag = 1 << 6,
- };
-
- enum Hinting {
- kNo_Hinting = kNo_SkFontHinting,
- kSlight_Hinting = kSlight_SkFontHinting,
- kNormal_Hinting = kNormal_SkFontHinting,
- kFull_Hinting = kFull_SkFontHinting,
- };
-
- SkFont();
- SkFont(sk_sp<SkTypeface>, SkScalar size, uint32_t flags);
- SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, uint32_t flags);
-
- bool isForceAutoHinting() const { return SkToBool(fFlags & kForceAutoHinting_Flag); }
- bool isEmbeddedBitmaps() const { return SkToBool(fFlags & kEmbeddedBitmaps_Flag); }
- bool isSubpixel() const { return SkToBool(fFlags & kSubpixel_Flag); }
- bool isLinearMetrics() const { return SkToBool(fFlags & kLinearMetrics_Flag); }
- bool isEmbolden() const { return SkToBool(fFlags & kEmbolden_Flag); }
-
- bool DEPRECATED_isAntiAlias() const { return SkToBool(fFlags & kDEPRECATED_Antialias_Flag); }
- bool DEPRECATED_isLCDRender() const { return SkToBool(fFlags & kDEPRECATED_LCDRender_Flag); }
-
- void setForceAutoHinting(bool);
- void setEmbeddedBitmaps(bool);
- void setSubpixel(bool);
- void setLinearMetrics(bool);
- void setEmbolden(bool);
-
- void DEPRECATED_setAntiAlias(bool);
- void DEPRECATED_setLCDRender(bool);
-
- Hinting getHinting() const { return (Hinting)fHinting; }
- void setHinting(Hinting);
-
- /**
- * Return a font with the same attributes of this font, but with the specified size.
- * If size is not supported (e.g. <= 0 or non-finite) NULL will be returned.
- */
- SkFont makeWithSize(SkScalar size) const;
-
- /**
- * Return a font with the same attributes of this font, but with the flags.
- */
- SkFont makeWithFlags(uint32_t newFlags) const;
-
- SkTypeface* getTypeface() const { return fTypeface.get(); }
- SkScalar getSize() const { return fSize; }
- SkScalar getScaleX() const { return fScaleX; }
- SkScalar getSkewX() const { return fSkewX; }
- uint32_t getFlags() const { return fFlags; }
-
- sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
-
- void setTypeface(sk_sp<SkTypeface> tf) { fTypeface = tf; }
- void setSize(SkScalar);
- void setScaleX(SkScalar);
- void setSkewX(SkScalar);
- void setFlags(uint32_t);
-
- /** 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 SkTextEncoding is kUTF8_TextEncoding and text contains an invalid UTF-8 sequence,
- zero is returned.
-
- If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied
- (but the total glyph count is returned for subsequent buffer reallocation).
-
- @param text character storage encoded with SkPaint::TextEncoding
- @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
- */
- int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding,
- SkGlyphID glyphs[], int maxGlyphCount) const;
-
- uint16_t unicharToGlyph(SkUnichar uni) const {
- return fTypeface->unicharToGlyph(uni);
- }
-
- int countText(const void* text, size_t byteLength, SkTextEncoding encoding) {
- return this->textToGlyphs(text, byteLength, encoding, nullptr, 0);
- }
-
- SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) const;
-
- void LEGACY_applyToPaint(SkPaint*) const;
- static SkFont LEGACY_ExtractFromPaint(const SkPaint&);
-
-private:
- static constexpr unsigned kAllFlags = 0x07F;
-
- sk_sp<SkTypeface> fTypeface;
- SkScalar fSize;
- SkScalar fScaleX;
- SkScalar fSkewX;
- uint8_t fFlags;
- uint8_t fHinting;
-};
-
#endif
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index f56368d..9608128 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -889,10 +889,10 @@
// if linear-text is on, then we force hinting to be off (since that's sort of
// the point of linear-text.
-static SkPaint::Hinting computeHinting(const SkPaint& paint) {
- SkPaint::Hinting h = paint.getHinting();
+static SkFontHinting computeHinting(const SkPaint& paint) {
+ SkFontHinting h = (SkFontHinting)paint.getHinting();
if (paint.isLinearText()) {
- h = SkPaint::kNo_Hinting;
+ h = kNo_SkFontHinting;
}
return h;
}
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index 3cb8a76..51688b3 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -10,6 +10,7 @@
#include <memory>
+#include "SkFontTypes.h"
#include "SkGlyph.h"
#include "SkMacros.h"
#include "SkMask.h"
@@ -196,8 +197,8 @@
SkAxisAlignment computeAxisAlignmentForHText() const;
- inline SkPaint::Hinting getHinting() const;
- inline void setHinting(SkPaint::Hinting);
+ inline SkFontHinting getHinting() const;
+ inline void setHinting(SkFontHinting);
SkMask::Format getFormat() const {
return static_cast<SkMask::Format>(fMaskFormat);
@@ -438,13 +439,13 @@
///////////////////////////////////////////////////////////////////////////////
-SkPaint::Hinting SkScalerContextRec::getHinting() const {
+SkFontHinting SkScalerContextRec::getHinting() const {
unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >>
SkScalerContext::kHinting_Shift;
- return static_cast<SkPaint::Hinting>(hint);
+ return static_cast<SkFontHinting>(hint);
}
-void SkScalerContextRec::setHinting(SkPaint::Hinting hinting) {
+void SkScalerContextRec::setHinting(SkFontHinting hinting) {
fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) |
(hinting << SkScalerContext::kHinting_Shift);
}
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 7675a92..d671b56 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -724,15 +724,15 @@
unref_ft_library();
}
- SkPaint::Hinting h = rec->getHinting();
- if (SkPaint::kFull_Hinting == h && !isLCD(*rec)) {
+ SkFontHinting h = rec->getHinting();
+ if (kFull_SkFontHinting == h && !isLCD(*rec)) {
// collapse full->normal hinting if we're not doing LCD
- h = SkPaint::kNormal_Hinting;
+ h = kNormal_SkFontHinting;
}
// rotated text looks bad with hinting, so we disable it as needed
if (!isAxisAligned(*rec)) {
- h = SkPaint::kNo_Hinting;
+ h = kNo_SkFontHinting;
}
rec->setHinting(h);
@@ -847,23 +847,23 @@
if (SkMask::kBW_Format == fRec.fMaskFormat) {
// See http://code.google.com/p/chromium/issues/detail?id=43252#c24
loadFlags = FT_LOAD_TARGET_MONO;
- if (fRec.getHinting() == SkPaint::kNo_Hinting) {
+ if (fRec.getHinting() == kNo_SkFontHinting) {
loadFlags = FT_LOAD_NO_HINTING;
linearMetrics = true;
}
} else {
switch (fRec.getHinting()) {
- case SkPaint::kNo_Hinting:
+ case kNo_SkFontHinting:
loadFlags = FT_LOAD_NO_HINTING;
linearMetrics = true;
break;
- case SkPaint::kSlight_Hinting:
+ case kSlight_SkFontHinting:
loadFlags = FT_LOAD_TARGET_LIGHT; // This implies FORCE_AUTOHINT
break;
- case SkPaint::kNormal_Hinting:
+ case kNormal_SkFontHinting:
loadFlags = FT_LOAD_TARGET_NORMAL;
break;
- case SkPaint::kFull_Hinting:
+ case kFull_SkFontHinting:
loadFlags = FT_LOAD_TARGET_NORMAL;
if (isLCD(fRec)) {
if (fLCDIsVert) {
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 52d17d0..8bb78a3 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -1321,7 +1321,7 @@
CGGlyph cgGlyph = SkTo<CGGlyph>(glyph.getGlyphID());
// FIXME: lcd smoothed un-hinted rasterization unsupported.
- bool requestSmooth = fRec.getHinting() != SkPaint::kNo_Hinting;
+ bool requestSmooth = fRec.getHinting() != kNo_SkFontHinting;
// Draw the glyph
size_t cgRowBytes;
@@ -2217,7 +2217,7 @@
// The above turns off subpixel rendering, but the user requested it.
// Normal hinting will cause the A8 masks to be generated from CoreGraphics subpixel masks.
// See comments below for more details.
- rec->setHinting(SkPaint::kNormal_Hinting);
+ rec->setHinting(kNormal_SkFontHinting);
}
unsigned flagsWeDontSupport = SkScalerContext::kForceAutohinting_Flag |
@@ -2232,11 +2232,11 @@
// kNo_Hinting means avoid CoreGraphics outline dilation.
// kNormal_Hinting means CoreGraphics outline dilation is allowed.
// If there is no lcd support, hinting (dilation) cannot be supported.
- SkPaint::Hinting hinting = rec->getHinting();
- if (SkPaint::kSlight_Hinting == hinting || smoothBehavior == SmoothBehavior::none) {
- hinting = SkPaint::kNo_Hinting;
- } else if (SkPaint::kFull_Hinting == hinting) {
- hinting = SkPaint::kNormal_Hinting;
+ SkFontHinting hinting = rec->getHinting();
+ if (kSlight_SkFontHinting == hinting || smoothBehavior == SmoothBehavior::none) {
+ hinting = kNo_SkFontHinting;
+ } else if (kFull_SkFontHinting == hinting) {
+ hinting = kNormal_SkFontHinting;
}
rec->setHinting(hinting);
@@ -2263,11 +2263,11 @@
if (smoothBehavior == SmoothBehavior::subpixel) {
//CoreGraphics creates 555 masks for smoothed text anyway.
rec->fMaskFormat = SkMask::kLCD16_Format;
- rec->setHinting(SkPaint::kNormal_Hinting);
+ rec->setHinting(kNormal_SkFontHinting);
} else {
rec->fMaskFormat = SkMask::kA8_Format;
if (smoothBehavior == SmoothBehavior::some) {
- rec->setHinting(SkPaint::kNormal_Hinting);
+ rec->setHinting(kNormal_SkFontHinting);
}
}
}
@@ -2281,7 +2281,7 @@
// Unhinted A8 masks (those not derived from LCD masks) must respect SK_GAMMA_APPLY_TO_A8.
// All other masks can use regular gamma.
- if (SkMask::kA8_Format == rec->fMaskFormat && SkPaint::kNo_Hinting == hinting) {
+ if (SkMask::kA8_Format == rec->fMaskFormat && kNo_SkFontHinting == hinting) {
#ifndef SK_GAMMA_APPLY_TO_A8
// SRGBTODO: Is this correct? Do we want contrast boost?
rec->ignorePreBlend();
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 2c6b47f..d0cadbe 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -87,7 +87,7 @@
return true;
}
#endif
- return rec.getHinting() == SkPaint::kNo_Hinting || rec.getHinting() == SkPaint::kSlight_Hinting;
+ return rec.getHinting() == kNo_SkFontHinting || rec.getHinting() == kSlight_SkFontHinting;
}
static void tchar_to_skstring(const TCHAR t[], SkString* s) {
@@ -636,7 +636,7 @@
// When GDI hinting, remove the entire Y scale from sA and GsA. (Prevents 'linear' metrics.)
// When not hinting, remove only the integer Y scale from sA and GsA. (Applied by GDI.)
SkScalerContextRec::PreMatrixScale scaleConstraints =
- (fRec.getHinting() == SkPaint::kNo_Hinting || fRec.getHinting() == SkPaint::kSlight_Hinting)
+ (fRec.getHinting() == kNo_SkFontHinting || fRec.getHinting() == kSlight_SkFontHinting)
? SkScalerContextRec::kVerticalInteger_PreMatrixScale
: SkScalerContextRec::kVertical_PreMatrixScale;
SkVector scale;
@@ -1636,7 +1636,7 @@
//GDI only uses hinted outlines when axis aligned.
UINT format = GGO_NATIVE | GGO_GLYPH_INDEX;
- if (fRec.getHinting() == SkPaint::kNo_Hinting || fRec.getHinting() == SkPaint::kSlight_Hinting){
+ if (fRec.getHinting() == kNo_SkFontHinting || fRec.getHinting() == kSlight_SkFontHinting){
format |= GGO_UNHINTED;
}
SkAutoSTMalloc<BUFFERSIZE, uint8_t> glyphbuf(BUFFERSIZE);
@@ -1645,7 +1645,7 @@
return false;
}
- if (fRec.getHinting() != SkPaint::kSlight_Hinting) {
+ if (fRec.getHinting() != kSlight_SkFontHinting) {
sk_path_from_gdi_path(path, glyphbuf, total_size);
} else {
//GDI only uses hinted outlines when axis aligned.
@@ -2296,23 +2296,23 @@
SkScalerContext::kLCD_Vertical_Flag;
rec->fFlags &= ~flagsWeDontSupport;
- SkPaint::Hinting h = rec->getHinting();
+ SkFontHinting h = rec->getHinting();
switch (h) {
- case SkPaint::kNo_Hinting:
+ case kNo_SkFontHinting:
break;
- case SkPaint::kSlight_Hinting:
+ case kSlight_SkFontHinting:
// Only do slight hinting when axis aligned.
// TODO: re-enable slight hinting when FontHostTest can pass.
//if (!isAxisAligned(*rec)) {
- h = SkPaint::kNo_Hinting;
+ h = kNo_SkFontHinting;
//}
break;
- case SkPaint::kNormal_Hinting:
- case SkPaint::kFull_Hinting:
+ case kNormal_SkFontHinting:
+ case kFull_SkFontHinting:
// TODO: need to be able to distinguish subpixel positioned glyphs
// and linear metrics.
//rec->fFlags &= ~SkScalerContext::kSubpixelPositioning_Flag;
- h = SkPaint::kNormal_Hinting;
+ h = kNormal_SkFontHinting;
break;
default:
SkDEBUGFAIL("unknown hinting");
diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp
index 2747a11..fe31c50 100644
--- a/src/ports/SkScalerContext_win_dw.cpp
+++ b/src/ports/SkScalerContext_win_dw.cpp
@@ -350,7 +350,7 @@
// DirectWrite2 allows hinting to be disabled.
fGridFitMode = DWRITE_GRID_FIT_MODE_ENABLED;
- if (fRec.getHinting() == SkPaint::kNo_Hinting) {
+ if (fRec.getHinting() == kNo_SkFontHinting) {
fGridFitMode = DWRITE_GRID_FIT_MODE_DISABLED;
if (fRenderingMode != DWRITE_RENDERING_MODE_ALIASED) {
fRenderingMode = DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC;
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index cd0e755..3266ee9 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -415,10 +415,10 @@
SkScalerContext::kLCD_Vertical_Flag;
rec->fFlags &= ~flagsWeDontSupport;
- SkPaint::Hinting h = rec->getHinting();
+ SkFontHinting h = rec->getHinting();
// DirectWrite2 allows for hinting to be turned off. Force everything else to normal.
- if (h != SkPaint::kNo_Hinting || !fFactory2 || !fDWriteFontFace2) {
- h = SkPaint::kNormal_Hinting;
+ if (h != kNo_SkFontHinting || !fFactory2 || !fDWriteFontFace2) {
+ h = kNormal_SkFontHinting;
}
rec->setHinting(h);
diff --git a/tools/fonts/SkRandomScalerContext.cpp b/tools/fonts/SkRandomScalerContext.cpp
index 85e4272..076d905 100644
--- a/tools/fonts/SkRandomScalerContext.cpp
+++ b/tools/fonts/SkRandomScalerContext.cpp
@@ -160,7 +160,7 @@
void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
fProxy->filterRec(rec);
- rec->setHinting(SkPaint::kNo_Hinting);
+ rec->setHinting(kNo_SkFontHinting);
rec->fMaskFormat = SkMask::kARGB32_Format;
}
diff --git a/tools/fonts/SkTestSVGTypeface.cpp b/tools/fonts/SkTestSVGTypeface.cpp
index 1555448..b991d46 100644
--- a/tools/fonts/SkTestSVGTypeface.cpp
+++ b/tools/fonts/SkTestSVGTypeface.cpp
@@ -100,7 +100,7 @@
}
void SkTestSVGTypeface::onFilterRec(SkScalerContextRec* rec) const {
- rec->setHinting(SkPaint::kNo_Hinting);
+ rec->setHinting(kNo_SkFontHinting);
}
void SkTestSVGTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
diff --git a/tools/fonts/SkTestTypeface.cpp b/tools/fonts/SkTestTypeface.cpp
index 651473e..8838586 100644
--- a/tools/fonts/SkTestTypeface.cpp
+++ b/tools/fonts/SkTestTypeface.cpp
@@ -117,7 +117,7 @@
}
void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const {
- rec->setHinting(SkPaint::kNo_Hinting);
+ rec->setHinting(kNo_SkFontHinting);
}
void SkTestTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {