expand flag to include all text-related paint fields
Bug: skia:
Change-Id: I8453a6d607df4902cd05c5c9bc6162feda04ef9c
Reviewed-on: https://skia-review.googlesource.com/c/182969
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
diff --git a/include/core/SkFont.h b/include/core/SkFont.h
index 009174c..608290c 100644
--- a/include/core/SkFont.h
+++ b/include/core/SkFont.h
@@ -487,6 +487,7 @@
*/
SkScalar getSpacing() const { return this->getMetrics(nullptr); }
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
/** Deprecated.
*/
void LEGACY_applyToPaint(SkPaint* paint) const;
@@ -496,6 +497,7 @@
/** Deprecated.
*/
static SkFont LEGACY_ExtractFromPaint(const SkPaint& paint);
+#endif
/** Experimental.
* Dumps fields of the font to SkDebugf. May change its output over time, so clients should
diff --git a/include/core/SkFontTypes.h b/include/core/SkFontTypes.h
index bb1b03f..c7c8abd 100644
--- a/include/core/SkFontTypes.h
+++ b/include/core/SkFontTypes.h
@@ -12,6 +12,10 @@
// remove me once google3 uses IWYU
#include "SkTypeface.h"
+#ifndef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
+#define SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
+#endif
+
enum class SkTextEncoding {
kUTF8, //!< uses bytes to represent UTF-8 or ASCII
kUTF16, //!< uses two byte words to represent most of Unicode
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 72a000f..81da896 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -27,10 +27,6 @@
#include "SkMatrix.h"
#include "SkRefCnt.h"
-#ifndef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
-#define SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
-#endif
-
class GrTextBlob;
class SkAutoDescriptor;
class SkColorFilter;
@@ -212,6 +208,7 @@
enum Flags {
kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
kDither_Flag = 0x04, //!< mask for setting dither
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
kLinearText_Flag = 0x40, //!< mask for setting linear text
kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
@@ -220,6 +217,9 @@
kAutoHinting_Flag = 0x800, //!< mask for setting force hinting
// 0x1000 used to be kVertical
kAllFlags = 0xFFFF, //!< mask of all Flags
+#else
+ kAllFlags = 0x05,
+#endif
};
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
@@ -284,9 +284,7 @@
*/
void setDither(bool dither);
-#ifndef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
-private:
-#endif
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
/** Returns true if text is converted to SkPath before drawing and measuring.
Equivalent to getFlags() masked with kLinearText_Flag.
@@ -411,8 +409,6 @@
@param fakeBoldText setting for kFakeBoldText_Flag
*/
void setFakeBoldText(bool fakeBoldText);
-#ifndef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
-public:
#endif
/** Returns SkFilterQuality, the image filtering level. A lower setting
@@ -929,6 +925,7 @@
bool containsText(const void* text, size_t byteLength) const;
#endif
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
/** Converts glyphs into text if possible.
Glyph values without direct Unicode equivalents are mapped to zero.
Uses the SkTypeface, but is unaffected
@@ -941,6 +938,7 @@
@param text storage for character codes, one per glyph
*/
void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
+#endif
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
/** Deprecated; use SkFont::countText instead
diff --git a/src/core/SkBlitter_RGB565.cpp b/src/core/SkBlitter_RGB565.cpp
index 69e8a14..4f44cda 100644
--- a/src/core/SkBlitter_RGB565.cpp
+++ b/src/core/SkBlitter_RGB565.cpp
@@ -75,9 +75,6 @@
paint.getBlendMode() != SkBlendMode::kSrc) {
return false;
}
- if (paint.isLCDRenderText()) {
- return false;
- }
if (paint.isDither()) {
return false;
}
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 26e2ffa..7fc6bf3 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2545,6 +2545,7 @@
}
void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) {
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
TRACE_EVENT0("skia", TRACE_FUNC);
if (byteLength) {
sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength));
@@ -2552,6 +2553,7 @@
const SkTextEncoding encoding = paint.private_internal_getTextEncoding();
this->drawTextBlob(SkTextBlob::MakeFromText(text, byteLength, font, encoding), x, y, paint);
}
+#endif
}
void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) {
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index 956f832..bbaafa4 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -490,6 +490,7 @@
#include "SkPaint.h"
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
void SkFont::LEGACY_applyToPaint(SkPaint* paint) const {
paint->setTypeface(fTypeface);
paint->setTextSize(fSize);
@@ -551,6 +552,7 @@
}
this->setEdging(edging);
}
+#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index f613f5b..0b8b968 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -165,8 +165,7 @@
auto glyphIDs = textToGlyphIDs(font, bytes, byteLength, kUTF8_SkTextEncoding);
if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size());
- this->simplifyDrawText(SkFont::LEGACY_ExtractFromPaint(paint),
- glyphIDs, origin, fPositions);
+ this->simplifyDrawText(font, glyphIDs, origin, fPositions);
}
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 5f1add0..3baf03a 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -212,6 +212,7 @@
this->setFlags(set_clear_mask(fBitfields.fFlags, doDither, kDither_Flag));
}
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
void SkPaint::setSubpixelText(bool doSubpixel) {
this->setFlags(set_clear_mask(fBitfields.fFlags, doSubpixel, kSubpixelText_Flag));
}
@@ -235,6 +236,7 @@
void SkPaint::setFakeBoldText(bool doFakeBold) {
this->setFlags(set_clear_mask(fBitfields.fFlags, doFakeBold, kFakeBoldText_Flag));
}
+#endif
void SkPaint::setStyle(Style style) {
if ((unsigned)style < kStyleCount) {
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index 895beaa..b5c4eb3 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -78,9 +78,11 @@
}
#endif
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar textData[]) const {
SkFont::LEGACY_ExtractFromPaint(*this).glyphsToUnichars(glyphs, count, textData);
}
+#endif
///////////////////////////////////////////////////////////////////////////////
@@ -192,6 +194,7 @@
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
SkScalar SkPaint::setupForAsPaths() {
constexpr uint32_t flagsToIgnore = SkPaint::kLinearText_Flag |
@@ -240,6 +243,7 @@
SkScalar fScale;
SkTLazy<SkPaint> fLazy;
};
+#endif
static void set_bounds(const SkGlyph& g, SkRect* bounds) {
bounds->set(SkIntToScalar(g.fLeft),
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index f69c6a5..24da9b9 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -450,6 +450,7 @@
canvas->drawPoints(mode, count, pts, *paint);
}
} break;
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
case DRAW_POS_TEXT: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text(reader, paint);
@@ -519,6 +520,7 @@
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
+#endif
case DRAW_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRect rect;
@@ -570,6 +572,7 @@
canvas->private_draw_shadow_rec(path, rec);
} break;
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
case DRAW_TEXT: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text(reader, paint);
@@ -583,6 +586,7 @@
x, y, SkFont::LEGACY_ExtractFromPaint(*paint), *paint);
}
} break;
+#endif
case DRAW_TEXT_BLOB: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkTextBlob* blob = fPictureData->getTextBlob(reader);
@@ -594,6 +598,7 @@
canvas->drawTextBlob(blob, x, y, *paint);
}
} break;
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
case DRAW_TEXT_TOP_BOTTOM: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text(reader, paint);
@@ -642,6 +647,7 @@
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
+#endif
case DRAW_VERTICES_OBJECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkVertices* vertices = fPictureData->getVertices(reader);
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index 42168e8..ea510e9 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -758,9 +758,14 @@
reader.readPoint(&offset);
SkFont font;
if (reader.isVersionLT(SkReadBuffer::kSerializeFonts_Version)) {
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
SkPaint paint;
reader.readPaint(&paint);
font = SkFont::LEGACY_ExtractFromPaint(paint);
+#else
+ reader.validate(false);
+ return nullptr;
+#endif
} else {
SkFontPriv::Unflatten(&font, reader);
}
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index ee4f3b3..c636ddc 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -556,6 +556,7 @@
return 0;
}
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) {
size_t len;
const char* text = lua_tolstring(L, 2, &len);
@@ -565,6 +566,7 @@
SkFont::LEGACY_ExtractFromPaint(*get_obj<SkPaint>(L, 5)),
*get_obj<SkPaint>(L, 5));
}
+#endif
return 0;
}
@@ -1868,11 +1870,15 @@
const char* text = lua_tolstring(L, 1, nullptr);
SkRect bounds;
lua2rect(L, 2, &bounds);
- const SkPaint& paint = *get_obj<SkPaint>(L, 3);
SkShaper shaper(nullptr);
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
+ const SkPaint& paint = *get_obj<SkPaint>(L, 3);
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
+#else
+ SkFont font;
+#endif
SkTextBlobBuilderLineHandler builder;
SkPoint end = shaper.shape(&builder, font, text, strlen(text), true,
{ bounds.left(), bounds.top() }, bounds.width());
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index 2316760..c9846a6 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -248,17 +248,18 @@
static const struct {
SkFontHinting hinting;
- unsigned flags;
+ bool linear;
+ bool subpixel;
} settings[] = {
- { kNo_SkFontHinting, 0 },
- { kNo_SkFontHinting, SkPaint::kLinearText_Flag },
- { kNo_SkFontHinting, SkPaint::kSubpixelText_Flag },
- { kSlight_SkFontHinting, 0 },
- { kSlight_SkFontHinting, SkPaint::kLinearText_Flag },
- { kSlight_SkFontHinting, SkPaint::kSubpixelText_Flag },
- { kNormal_SkFontHinting, 0 },
- { kNormal_SkFontHinting, SkPaint::kLinearText_Flag },
- { kNormal_SkFontHinting, SkPaint::kSubpixelText_Flag },
+ { kNo_SkFontHinting, false, false },
+ { kNo_SkFontHinting, true, false },
+ { kNo_SkFontHinting, false, true },
+ { kSlight_SkFontHinting, false, false },
+ { kSlight_SkFontHinting, true, false },
+ { kSlight_SkFontHinting, false, true },
+ { kNormal_SkFontHinting, false, false },
+ { kNormal_SkFontHinting, true, false },
+ { kNormal_SkFontHinting, false, true },
};
static const struct {
@@ -280,8 +281,8 @@
for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
font.setHinting(settings[j].hinting);
- font.setLinearMetrics((settings[j].flags & SkPaint::kLinearText_Flag) != 0);
- font.setSubpixel((settings[j].flags & SkPaint::kSubpixelText_Flag) != 0);
+ font.setLinearMetrics(settings[j].linear);
+ font.setSubpixel(settings[j].subpixel);
for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
font.setScaleX(gScaleRec[k].fScaleX);
diff --git a/tests/FontObjTest.cpp b/tests/FontObjTest.cpp
index bf40dfd..6ddb9f3 100644
--- a/tests/FontObjTest.cpp
+++ b/tests/FontObjTest.cpp
@@ -71,6 +71,7 @@
}
#endif // SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
+#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
DEF_TEST(FontObj_test_aa_hinting, reporter) {
SkPaint paint;
@@ -87,5 +88,6 @@
}
}
}
+#endif
// need tests for SkStrSearch
diff --git a/tests/PDFTaggedTest.cpp b/tests/PDFTaggedTest.cpp
index e966f68..5815ba3 100644
--- a/tests/PDFTaggedTest.cpp
+++ b/tests/PDFTaggedTest.cpp
@@ -99,7 +99,6 @@
SkPaint paint;
paint.setColor(SK_ColorBLACK);
- paint.setSubpixelText(true);
paint.setHinting(kNo_SkFontHinting);
// First page.
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 13ed1f9..d16461a 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -515,8 +515,6 @@
SkStrikeClient client(discardableManager, false);
SkPaint paint;
paint.setAntiAlias(true);
- paint.setSubpixelText(true);
- paint.setLCDRenderText(true);
// Server.
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
diff --git a/tools/using_skia_and_harfbuzz.cpp b/tools/using_skia_and_harfbuzz.cpp
index 6f378e2..cabd7df 100644
--- a/tools/using_skia_and_harfbuzz.cpp
+++ b/tools/using_skia_and_harfbuzz.cpp
@@ -132,9 +132,9 @@
: config(conf), document(doc), pageCanvas(nullptr) {
white_paint.setColor(SK_ColorWHITE);
glyph_paint.setColor(SK_ColorBLACK);
- glyph_paint.setFlags(SkPaint::kAntiAlias_Flag |
- SkPaint::kSubpixelText_Flag);
+ glyph_paint.setAntiAlias(true);
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ font.setSubpixel(true);
font.setSize(SkDoubleToScalar(config->font_size.value));
}
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 65c87e8..0f5216d 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -439,28 +439,35 @@
fWindow->inval();
});
fCommands.addCommand('L', "Paint", "Subpixel Antialias Mode", [this]() {
- if (!(fPaintOverrides.fFlags & SkPaint::kLCDRenderText_Flag)) {
- fPaintOverrides.fFlags |= SkPaint::kLCDRenderText_Flag;
- fPaint.setLCDRenderText(false);
+ if (!fFontOverrides.fEdging) {
+ fFontOverrides.fEdging = true;
+ fFont.setEdging(SkFont::Edging::kAlias);
} else {
- if (!fPaint.isLCDRenderText()) {
- fPaint.setLCDRenderText(true);
- } else {
- fPaintOverrides.fFlags &= ~SkPaint::kLCDRenderText_Flag;
+ switch (fFont.getEdging()) {
+ case SkFont::Edging::kAlias:
+ fFont.setEdging(SkFont::Edging::kAntiAlias);
+ break;
+ case SkFont::Edging::kAntiAlias:
+ fFont.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ break;
+ case SkFont::Edging::kSubpixelAntiAlias:
+ fFont.setEdging(SkFont::Edging::kAlias);
+ fFontOverrides.fEdging = false;
+ break;
}
}
this->updateTitle();
fWindow->inval();
});
fCommands.addCommand('S', "Paint", "Subpixel Position Mode", [this]() {
- if (!(fPaintOverrides.fFlags & SkPaint::kSubpixelText_Flag)) {
- fPaintOverrides.fFlags |= SkPaint::kSubpixelText_Flag;
- fPaint.setSubpixelText(false);
+ if (!fFontOverrides.fSubpixel) {
+ fFontOverrides.fSubpixel = true;
+ fFont.setSubpixel(false);
} else {
- if (!fPaint.isSubpixelText()) {
- fPaint.setSubpixelText(true);
+ if (!fFont.isSubpixel()) {
+ fFont.setSubpixel(true);
} else {
- fPaintOverrides.fFlags &= ~SkPaint::kSubpixelText_Flag;
+ fFontOverrides.fSubpixel = false;
}
}
this->updateTitle();
@@ -702,6 +709,7 @@
paintFlag(SkPaint::kAntiAlias_Flag, &SkPaint::isAntiAlias, "Antialias", "Alias");
paintFlag(SkPaint::kDither_Flag, &SkPaint::isDither, "DITHER", "No Dither");
+#if 0
paintFlag(SkPaint::kFakeBoldText_Flag, &SkPaint::isFakeBoldText, "Fake Bold", "No Fake Bold");
paintFlag(SkPaint::kLinearText_Flag, &SkPaint::isLinearText, "Linear Text", "Non-Linear Text");
paintFlag(SkPaint::kSubpixelText_Flag, &SkPaint::isSubpixelText, "Subpixel Text", "Pixel Text");
@@ -710,6 +718,7 @@
"Bitmap Text", "No Bitmap Text");
paintFlag(SkPaint::kAutoHinting_Flag, &SkPaint::isAutohinted,
"Force Autohint", "No Force Autohint");
+#endif
if (fFontOverrides.fHinting) {
switch (fFont.getHinting()) {
diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h
index 2cff486..495c81b 100644
--- a/tools/viewer/Viewer.h
+++ b/tools/viewer/Viewer.h
@@ -45,6 +45,8 @@
bool fTextScaleX = false;
bool fTextSkewX = false;
bool fHinting = false;
+ bool fEdging = false;
+ bool fSubpixel = false;
};
struct SkPaintFields {
bool fPathEffect = false;