Skip to content

Commit

Permalink
Revert[4] "hide nested hinting enum"
Browse files Browse the repository at this point in the history
This reverts commit 8e12cc6.

Bug: skia:
Change-Id: Ice5e3480adad75ab77d97f7366495015f36b15a6
Reviewed-on: https://skia-review.googlesource.com/c/169520
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
  • Loading branch information
reed-at-google authored and Skia Commit-Bot committed Nov 8, 2018
1 parent 7d8f82b commit 9edbf42
Show file tree
Hide file tree
Showing 30 changed files with 114 additions and 106 deletions.
4 changes: 2 additions & 2 deletions fuzz/FuzzCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@ static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) {
paint->setEmbeddedBitmapText(make_fuzz_t<bool>(fuzz));
paint->setAutohinted( make_fuzz_t<bool>(fuzz));
paint->setFakeBoldText( make_fuzz_t<bool>(fuzz));
paint->setHinting( make_fuzz_t_range<SkPaint::Hinting>(fuzz, 0,
SkPaint::kFull_Hinting));
paint->setHinting( make_fuzz_t_range<SkFontHinting>(fuzz, 0,
kFull_SkFontHinting));
}

static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/FuzzDrawFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void init_paint(Fuzz* fuzz, SkPaint* p) {
p->setFilterQuality(static_cast<SkFilterQuality>(tmp_u8));

fuzz->nextRange(&tmp_u8, 0, (int)SkPaint::kFull_Hinting);
p->setHinting(static_cast<SkPaint::Hinting>(tmp_u8));
p->setHinting(static_cast<SkFontHinting>(tmp_u8));

fuzz->nextRange(&tmp_u8, 0, (int)SkPaint::kLast_Cap);
p->setStrokeCap(static_cast<SkPaint::Cap>(tmp_u8));
Expand Down
2 changes: 1 addition & 1 deletion gm/fontscaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FontScalerGM : public GM {
paint.setLCDRenderText(true);
//With freetype the default (normal hinting) can be really ugly.
//Most distros now set slight (vertical hinting only) in any event.
paint.setHinting(SkPaint::kSlight_Hinting);
paint.setHinting(kSlight_SkFontHinting);

const char* text = "Hamburgefons ooo mmm";
const size_t textLen = strlen(text);
Expand Down
12 changes: 7 additions & 5 deletions gm/typeface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,
// Odd sizes have embedded bitmaps.
constexpr SkScalar textSizes[] = { 9, 10, 11, 12, 13, 14, 15, 16 };

constexpr SkPaint::Hinting hintingTypes[] = { SkPaint::kNo_Hinting,
SkPaint::kSlight_Hinting,
SkPaint::kNormal_Hinting,
SkPaint::kFull_Hinting };
constexpr SkFontHinting hintingTypes[] = {
kNo_SkFontHinting,
kSlight_SkFontHinting,
kNormal_SkFontHinting,
kFull_SkFontHinting
};

struct SubpixelType {
bool requested;
Expand Down Expand Up @@ -228,7 +230,7 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,

SkScalar dy = SkScalarCeilToScalar(paint.getFontMetrics(nullptr));
y += dy;
for (const SkPaint::Hinting& hinting : hintingTypes) {
for (const SkFontHinting& hinting : hintingTypes) {
paint.setHinting(hinting);

for (const bool& rotateABit : rotateABitTypes) {
Expand Down
4 changes: 4 additions & 0 deletions gn/flutter_defines.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ flutter_defines = [
"SK_DISABLE_AAA",
"SK_DISABLE_DAA",

# API staging
"SK_SUPPORT_LEGACY_NONCLASS_HINTINGENUM",
"SK_SUPPORT_LEGACY_NESTED_HINTINGENUM",

# Flutter doesn't deserialize anything.
"SK_DISABLE_READBUFFER",
"SK_DISABLE_EFFECT_DESERIALIZATION",
Expand Down
7 changes: 6 additions & 1 deletion include/core/SkFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ class SK_API SkFont {
void DEPRECATED_setAntiAlias(bool);
void DEPRECATED_setLCDRender(bool);

void setHinting(SkFontHinting);

#ifdef SK_SUPPORT_LEGACY_NESTED_HINTINGENUM
Hinting getHinting() const { return (Hinting)fHinting; }
void setHinting(SkFontHinting hinting);
void setHinting(Hinting hinting) {
this->setHinting((SkFontHinting)hinting);
}
#else
SkFontHinting getHinting() const { return (SkFontHinting)fHinting; }
#endif

/**
* Return a font with the same attributes of this font, but with the specified size.
Expand Down
24 changes: 9 additions & 15 deletions include/core/SkPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ class SK_API SkPaint {
kFull_Hinting = 3, //!< modifies glyph outlines for maximum constrast
};

/** Returns level of glyph outline adjustment.
@return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
*/
Hinting getHinting() const {
return static_cast<Hinting>(fBitfields.fHinting);
}

/** Sets level of glyph outline adjustment.
Does not check for valid values of hintingLevel.
Expand All @@ -214,14 +206,16 @@ class SK_API SkPaint {
*/
void setHinting(SkFontHinting hintingLevel);

/** Sets level of glyph outline adjustment.
Does not check for valid values of hintingLevel.
@param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
*/
void setHinting(Hinting hintingLevel) {
this->setHinting((SkFontHinting)hintingLevel);
#ifdef SK_SUPPORT_LEGACY_NESTED_HINTINGENUM
Hinting getHinting() const { return (Hinting)fBitfields.fHinting; }
void setHinting(Hinting h) {
this->setHinting((SkFontHinting)h);
}
#else
/** Returns level of glyph outline adjustment.
*/
SkFontHinting getHinting() const { return (SkFontHinting)fBitfields.fHinting; }
#endif

/** \enum SkPaint::Flags
The bit values stored in Flags.
Expand Down
2 changes: 1 addition & 1 deletion modules/skottie/src/SkottieAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ sk_sp<SkTextBlob> TextAdapter::makeBlob() const {
SkPaint font;
font.setTypeface(fText.fTypeface);
font.setTextSize(fText.fTextSize);
font.setHinting(SkPaint::kNo_Hinting);
font.setHinting(kNo_SkFontHinting);
font.setSubpixelText(true);
font.setAntiAlias(true);
font.setTextEncoding(SkPaint::kUTF8_TextEncoding);
Expand Down
4 changes: 2 additions & 2 deletions modules/sksg/include/SkSGText.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Text final : public GeometryNode {
SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX )
SG_ATTRIBUTE(SkewX , SkScalar , fSkewX )
SG_ATTRIBUTE(Align , SkTextUtils::Align , fAlign )
SG_ATTRIBUTE(Hinting , SkPaint::Hinting , fHinting )
SG_ATTRIBUTE(Hinting , SkFontHinting , fHinting )

// TODO: add shaping functionality.

Expand All @@ -62,7 +62,7 @@ class Text final : public GeometryNode {
SkScalar fScaleX = 1;
SkScalar fSkewX = 0;
SkTextUtils::Align fAlign = SkTextUtils::kLeft_Align;
SkPaint::Hinting fHinting = SkPaintDefaults_Hinting;
SkFontHinting fHinting = SkPaintDefaults_Hinting;

sk_sp<SkTextBlob> fBlob; // cached text blob

Expand Down
2 changes: 2 additions & 0 deletions public.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ def base_defines(os_conditions):
"SK_DISABLE_LOWP_RASTER_PIPELINE",
# JPEG is in codec_limited
"SK_HAS_JPEG_LIBRARY",
"SK_SUPPORT_LEGACY_NONCLASS_HINTINGENUM",
"SK_SUPPORT_LEGACY_NESTED_HINTINGENUM",
] + skia_select(
os_conditions,
[
Expand Down
4 changes: 2 additions & 2 deletions samplecode/SampleFilterFuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ static SkBlendMode make_xfermode() {
return static_cast<SkBlendMode>(R((int)SkBlendMode::kLastMode+1));
}

static SkPaint::Hinting make_paint_hinting() {
return static_cast<SkPaint::Hinting>(R(SkPaint::kFull_Hinting+1));
static SkFontHinting make_paint_hinting() {
return static_cast<SkFontHinting>(R(static_cast<unsigned>(kFull_SkFontHinting)+1));
}

static SkPaint::Style make_paint_style() {
Expand Down
8 changes: 4 additions & 4 deletions src/core/SkFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define kDefault_Size 12
#define kDefault_Flags 0
#define kDefault_Hinting SkFont::kNormal_Hinting
#define kDefault_Hinting kNormal_SkFontHinting

static inline SkScalar valid_size(SkScalar size) {
return SkTMax<SkScalar>(0, size);
Expand All @@ -26,7 +26,7 @@ SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar
, fScaleX(scaleX)
, fSkewX(skewX)
, fFlags(flags & kAllFlags)
, fHinting(kDefault_Hinting)
, fHinting(static_cast<unsigned>(kDefault_Hinting))
{}

SkFont::SkFont() : SkFont(nullptr, kDefault_Size, 1, 0, kDefault_Flags)
Expand Down Expand Up @@ -167,7 +167,7 @@ void SkFont::LEGACY_applyToPaint(SkPaint* paint) const {
paint->setAntiAlias(SkToBool(fFlags & kDEPRECATED_Antialias_Flag));
paint->setLCDRenderText(SkToBool(fFlags & kDEPRECATED_LCDRender_Flag));

paint->setHinting((SkPaint::Hinting)this->getHinting());
paint->setHinting((SkFontHinting)this->getHinting());
}

SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) {
Expand Down Expand Up @@ -197,6 +197,6 @@ SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) {

SkFont font(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(),
paint.getTextSkewX(), flags);
font.setHinting((Hinting)paint.getHinting());
font.setHinting((SkFontHinting)paint.getHinting());
return font;
}
9 changes: 5 additions & 4 deletions src/core/SkPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SkPaint::SkPaint() {
fBitfields.fJoinType = kDefault_Join;
fBitfields.fStyle = kFill_Style;
fBitfields.fTextEncoding = kUTF8_TextEncoding;
fBitfields.fHinting = SkPaintDefaults_Hinting;
fBitfields.fHinting = static_cast<unsigned>(SkPaintDefaults_Hinting);
}

SkPaint::SkPaint(const SkPaint& src)
Expand Down Expand Up @@ -394,7 +394,8 @@ static inline int BPF_Mask(int bits) {
return (1 << bits) - 1;
}

static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned filter, unsigned flatFlags) {
static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned filter,
unsigned flatFlags) {
ASSERT_FITS_IN(flags, kFlags_BPF);
ASSERT_FITS_IN(hint, kHint_BPF);
ASSERT_FITS_IN(filter, kFilter_BPF);
Expand All @@ -409,7 +410,7 @@ static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned filter,

static FlatFlags unpack_paint_flags(SkPaint* paint, uint32_t packed) {
paint->setFlags(packed >> 16);
paint->setHinting((SkPaint::Hinting)((packed >> 14) & BPF_Mask(kHint_BPF)));
paint->setHinting((SkFontHinting)((packed >> 14) & BPF_Mask(kHint_BPF)));
paint->setFilterQuality((SkFilterQuality)((packed >> 10) & BPF_Mask(kFilter_BPF)));
return (FlatFlags)(packed & kFlatFlagMask);
}
Expand Down Expand Up @@ -441,7 +442,7 @@ void SkPaintPriv::Flatten(const SkPaint& paint, SkWriteBuffer& buffer) {
buffer.writeScalar(paint.getStrokeMiter());
buffer.writeColor4f(paint.getColor4f());

buffer.writeUInt(pack_paint_flags(paint.getFlags(), paint.getHinting(),
buffer.writeUInt(pack_paint_flags(paint.getFlags(), static_cast<unsigned>(paint.getHinting()),
paint.getFilterQuality(), flatFlags));
buffer.writeUInt(pack_4(paint.getStrokeCap(), paint.getStrokeJoin(),
(paint.getStyle() << 4) | paint.getTextEncoding(),
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkPaintDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#endif

#ifndef SkPaintDefaults_Hinting
#define SkPaintDefaults_Hinting SkPaint::kNormal_Hinting
#define SkPaintDefaults_Hinting kNormal_SkFontHinting
#endif

#ifndef SkPaintDefaults_MiterLimit
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkPaint_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ SkScalar SkPaint::setupForAsPaths() {
flags |= SkPaint::kSubpixelText_Flag;

this->setFlags(flags);
this->setHinting(SkPaint::kNo_Hinting);
this->setHinting(kNo_SkFontHinting);
this->setStyle(SkPaint::kFill_Style);
this->setPathEffect(nullptr);

Expand Down
4 changes: 2 additions & 2 deletions src/core/SkTextBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SkRunFont::SkRunFont(const SkPaint& paint)
, fScaleX(paint.getTextScaleX())
, fTypeface(SkPaintPriv::RefTypefaceOrDefault(paint))
, fSkewX(paint.getTextSkewX())
, fHinting(paint.getHinting())
, fHinting(static_cast<unsigned>(paint.getHinting()))
, fFlags(paint.getFlags() & kFlagsMask) { }

void SkRunFont::applyToPaint(SkPaint* paint) const {
Expand All @@ -36,7 +36,7 @@ void SkRunFont::applyToPaint(SkPaint* paint) const {
paint->setTextSize(fSize);
paint->setTextScaleX(fScaleX);
paint->setTextSkewX(fSkewX);
paint->setHinting(static_cast<SkPaint::Hinting>(fHinting));
paint->setHinting(static_cast<SkFontHinting>(fHinting));

paint->setFlags((paint->getFlags() & ~kFlagsMask) | fFlags);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkTextBlobPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SkRunFont : SkNoncopyable {
sk_sp<SkTypeface> fTypeface;
SkScalar fSkewX;

static_assert(SkPaint::kFull_Hinting < 4, "insufficient_hinting_bits");
static_assert(static_cast<unsigned>(kFull_SkFontHinting) < 4, "insufficient_hinting_bits");
uint32_t fHinting : 2;
static_assert((kFlagsMask & 0xffff) == kFlagsMask, "insufficient_flags_bits");
uint32_t fFlags : 16;
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/text/GrTextContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void GrTextContext::InitDistanceFieldPaint(GrTextBlob* blob,
skPaint->setAntiAlias(true);
skPaint->setLCDRenderText(false);
skPaint->setAutohinted(false);
skPaint->setHinting(SkPaint::kNormal_Hinting);
skPaint->setHinting(kNormal_SkFontHinting);
skPaint->setSubpixelText(true);

skPaint->setMaskFilter(GrSDFMaskFilter::Make());
Expand Down
2 changes: 1 addition & 1 deletion src/pdf/SkPDFDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
SkPaint paint(srcPaint);
remove_color_filter(&paint);
replace_srcmode_on_opaque_paint(&paint);
paint.setHinting(SkPaint::kNo_Hinting);
paint.setHinting(kNo_SkFontHinting);
if (!paint.getTypeface()) {
paint.setTypeface(SkTypeface::MakeDefault());
}
Expand Down
4 changes: 2 additions & 2 deletions src/pdf/SkPDFFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

SkExclusiveStrikePtr SkPDFFont::MakeVectorCache(SkTypeface* face, int* size) {
SkPaint tmpPaint;
tmpPaint.setHinting(SkPaint::kNo_Hinting);
tmpPaint.setHinting(kNo_SkFontHinting);
tmpPaint.setTypeface(sk_ref_sp(face));
int unitsPerEm = face->getUnitsPerEm();
if (unitsPerEm <= 0) {
Expand Down Expand Up @@ -154,7 +154,7 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface,

if (0 == metrics->fStemV || 0 == metrics->fCapHeight) {
SkPaint tmpPaint;
tmpPaint.setHinting(SkPaint::kNo_Hinting);
tmpPaint.setHinting(kNo_SkFontHinting);
tmpPaint.setTypeface(sk_ref_sp(typeface));
tmpPaint.setTextSize(1000); // glyph coordinate system
if (0 == metrics->fStemV) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/SkLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ static int lpaint_setTypeface(lua_State* L) {
}

static int lpaint_getHinting(lua_State* L) {
SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getHinting());
SkLua(L).pushU32((unsigned)get_obj<SkPaint>(L, 1)->getHinting());
return 1;
}

Expand Down
22 changes: 11 additions & 11 deletions tests/FontHostTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,18 @@ static void test_advances(skiatest::Reporter* reporter) {
};

static const struct {
SkPaint::Hinting hinting;
unsigned flags;
SkFontHinting hinting;
unsigned flags;
} settings[] = {
{ SkPaint::kNo_Hinting, 0 },
{ SkPaint::kNo_Hinting, SkPaint::kLinearText_Flag },
{ SkPaint::kNo_Hinting, SkPaint::kSubpixelText_Flag },
{ SkPaint::kSlight_Hinting, 0 },
{ SkPaint::kSlight_Hinting, SkPaint::kLinearText_Flag },
{ SkPaint::kSlight_Hinting, SkPaint::kSubpixelText_Flag },
{ SkPaint::kNormal_Hinting, 0 },
{ SkPaint::kNormal_Hinting, SkPaint::kLinearText_Flag },
{ SkPaint::kNormal_Hinting, SkPaint::kSubpixelText_Flag },
{ 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 },
};

static const struct {
Expand Down
Loading

0 comments on commit 9edbf42

Please sign in to comment.