Skip to content

Commit

Permalink
SkPaint::Align is dead
Browse files Browse the repository at this point in the history
Bug: skia:8493
Change-Id: I272de164a4cfc630972294152d3fb10e1d4bd702
Reviewed-on: https://skia-review.googlesource.com/c/167944
Reviewed-by: Ben Wagner <[email protected]>
Commit-Queue: Mike Reed <[email protected]>
  • Loading branch information
reed-at-google authored and Skia Commit-Bot committed Nov 2, 2018
1 parent 2904121 commit 1edff30
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 211 deletions.
3 changes: 0 additions & 3 deletions fuzz/FuzzCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,6 @@ static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) {
paint->setDevKernText( make_fuzz_t<bool>(fuzz));
paint->setHinting( make_fuzz_t_range<SkPaint::Hinting>(fuzz, 0,
SkPaint::kFull_Hinting));
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
paint->setTextAlign( make_fuzz_t_range<SkPaint::Align>(fuzz, 0, 2));
#endif
}

static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) {
Expand Down
4 changes: 1 addition & 3 deletions include/core/SkFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class SK_API SkFont {

SkFont();
SkFont(sk_sp<SkTypeface>, SkScalar size, uint32_t flags);
SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, uint32_t flags,
int align = 0);
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); }
Expand Down Expand Up @@ -147,7 +146,6 @@ class SK_API SkFont {
SkScalar fScaleX;
SkScalar fSkewX;
uint8_t fFlags;
uint8_t fAlign;
uint8_t fHinting;
};

Expand Down
59 changes: 7 additions & 52 deletions include/core/SkPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,50 +846,6 @@ class SK_API SkPaint {
*/
void setLooper(sk_sp<SkDrawLooper> drawLooper);

#ifdef SK_SUPPORT_LEGACY_PAINTALIGNENUM
/** \enum SkPaint::Align
Align adjusts the text relative to the text position.
Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
SkCanvas::drawPosTextH, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
and SkCanvas::drawString;
as well as calls that place text glyphs like getTextWidths() and getTextPath().
The text position is set by the font.
Typically, for horizontal text, the position is to the left side of the glyph on the
base line.
Align adjusts the glyph position to center it or move it to abut the position
using the metrics returned by the font.
Align defaults to kLeft_Align.
*/
enum Align {
kLeft_Align, //!< positions glyph by computed font offset
kCenter_Align, //!< centers line of glyphs by its width or height
kRight_Align, //!< moves lines of glyphs by its width or height
};
#endif

/** May be used to verify that align is a legal value.
*/
static constexpr int kAlignCount = 3;

#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
/** Returns SkPaint::Align.
Returns kLeft_Align if SkPaint::Align has not been set.
@return text placement relative to position
*/
Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }

/** Sets SkPaint::Align to align.
Has no effect if align is an invalid value.
@param align text placement relative to position
*/
void setTextAlign(Align align);
#endif

/** Returns text size in points.
@return typographic height of text
Expand Down Expand Up @@ -1236,7 +1192,7 @@ class SK_API SkPaint {
Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
All of the glyph paths are stored in path.
Uses x, y, and SkPaint::Align to position path.
Uses x, y, to position path.
@param text character codes or glyph indices
@param length number of bytes of text
Expand All @@ -1251,7 +1207,7 @@ class SK_API SkPaint {
Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
All of the glyph paths are stored in path.
Uses pos array and SkPaint::Align to position path.
Uses pos array to position path.
pos contains a position for each glyph.
@param text character codes or glyph indices
Expand All @@ -1268,7 +1224,7 @@ class SK_API SkPaint {
the string.
Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Uses x, y, and SkPaint::Align to position intervals.
Uses x, y to position intervals.
Pass nullptr for intervals to determine the size of the interval array.
Expand All @@ -1291,7 +1247,7 @@ class SK_API SkPaint {
the string.
Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Uses pos array and SkPaint::Align to position intervals.
Uses pos array to position intervals.
Pass nullptr for intervals to determine the size of the interval array.
Expand All @@ -1313,7 +1269,7 @@ class SK_API SkPaint {
the string.
Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Uses xpos array, constY, and SkPaint::Align to position intervals.
Uses xpos array, constY to position intervals.
Pass nullptr for intervals to determine the size of the interval array.
Expand All @@ -1336,7 +1292,7 @@ class SK_API SkPaint {
the string.
Uses SkTypeface to get the glyph paths,
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Uses run array and SkPaint::Align to position intervals.
Uses run array to position intervals.
SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
Expand Down Expand Up @@ -1475,14 +1431,13 @@ class SK_API SkPaint {
struct {
// all of these bitfields should add up to 32
unsigned fFlags : 16;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
unsigned fFilterQuality : 2;
//unsigned fFreeBits : 2;
//unsigned fFreeBits : 4;
} fBitfields;
uint32_t fBitfieldsUInt;
};
Expand Down
19 changes: 4 additions & 15 deletions src/core/SkFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ static inline SkScalar valid_size(SkScalar size) {
}

SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX,
uint32_t flags, int align)
uint32_t flags)
: fTypeface(face ? std::move(face) : SkTypeface::MakeDefault())
, fSize(valid_size(size))
, fScaleX(scaleX)
, fSkewX(skewX)
, fFlags(flags & kAllFlags)
, fAlign(SkToU8(align))
, fHinting(kDefault_Hinting)
{
SkASSERT(align >= 0 && align <= 2);
}
{}

SkFont::SkFont() : SkFont(nullptr, kDefault_Size, 1, 0, kDefault_Flags, 0)
SkFont::SkFont() : SkFont(nullptr, kDefault_Size, 1, 0, kDefault_Flags)
{}

SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, uint32_t flags)
Expand Down Expand Up @@ -171,10 +168,6 @@ void SkFont::LEGACY_applyToPaint(SkPaint* paint) const {
paint->setLCDRenderText(SkToBool(fFlags & kDEPRECATED_LCDRender_Flag));

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

#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
paint->setTextAlign((SkPaint::Align)fAlign);
#endif
}

SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) {
Expand Down Expand Up @@ -203,11 +196,7 @@ SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) {
}

SkFont font(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(),
paint.getTextSkewX(), flags
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
, (int)paint.getTextAlign()
#endif
);
paint.getTextSkewX(), flags);
font.setHinting((Hinting)paint.getHinting());
return font;
}
12 changes: 0 additions & 12 deletions src/core/SkGlyphRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,6 @@ void SkGlyphRunBuilder::simplifyDrawText(
endOfLastGlyph += fScratchAdvances[i];
}

#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
if (paint.getTextAlign() != SkPaint::kLeft_Align) {
SkVector len = endOfLastGlyph - origin;
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
len.scale(SK_ScalarHalf);
}
for (auto& pt : SkSpan<SkPoint>{positions, runSize}) {
pt -= len;
}
}
#endif

this->makeGlyphRun(
paint,
runFont,
Expand Down
13 changes: 0 additions & 13 deletions src/core/SkPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ SkPaint::SkPaint() {
fBitfields.fFlags = SkPaintDefaults_Flags;
fBitfields.fCapType = kDefault_Cap;
fBitfields.fJoinType = kDefault_Join;
fBitfields.fTextAlign = 0; // kLeft_Align
fBitfields.fStyle = kFill_Style;
fBitfields.fTextEncoding = kUTF8_TextEncoding;
fBitfields.fHinting = SkPaintDefaults_Hinting;
Expand Down Expand Up @@ -309,18 +308,6 @@ void SkPaint::setStrokeJoin(Join jt) {

///////////////////////////////////////////////////////////////////////////////

#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
void SkPaint::setTextAlign(Align align) {
if ((unsigned)align < kAlignCount) {
fBitfields.fTextAlign = SkToU8(align);
} else {
#ifdef SK_REPORT_API_RANGE_CHECK
SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align);
#endif
}
}
#endif

void SkPaint::setTextSize(SkScalar ts) {
if (ts >= 0) {
fTextSize = ts;
Expand Down
10 changes: 0 additions & 10 deletions src/core/SkPaint_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,16 +805,6 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
// now compute fXOffset if needed

SkScalar xOffset = 0;
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
int count;
SkScalar width = fPaint.measure_text(fCache.get(), text, length, &count, nullptr) * fScale;
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
}
xOffset = -width;
}
#endif
fXPos = xOffset;
fPrevAdvance = 0;

Expand Down
11 changes: 0 additions & 11 deletions src/core/SkTextBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ SkRunFont::SkRunFont(const SkPaint& paint)
, fScaleX(paint.getTextScaleX())
, fTypeface(SkPaintPriv::RefTypefaceOrDefault(paint))
, fSkewX(paint.getTextSkewX())
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
, fAlign(paint.getTextAlign())
#elif defined(SK_SUPPORT_LEGACY_PAINTALIGNENUM)
, fAlign(SkPaint::kLeft_Align)
#endif
, fHinting(paint.getHinting())
, fFlags(paint.getFlags() & kFlagsMask) { }

Expand All @@ -41,9 +36,6 @@ void SkRunFont::applyToPaint(SkPaint* paint) const {
paint->setTextSize(fSize);
paint->setTextScaleX(fScaleX);
paint->setTextSkewX(fSkewX);
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
paint->setTextAlign(static_cast<SkPaint::Align>(fAlign));
#endif
paint->setHinting(static_cast<SkPaint::Hinting>(fHinting));

paint->setFlags((paint->getFlags() & ~kFlagsMask) | fFlags);
Expand All @@ -54,9 +46,6 @@ bool SkRunFont::operator==(const SkRunFont& other) const {
&& fSize == other.fSize
&& fScaleX == other.fScaleX
&& fSkewX == other.fSkewX
#ifdef SK_SUPPORT_LEGACY_PAINTALIGNENUM
&& fAlign == other.fAlign
#endif
&& fHinting == other.fHinting
&& fFlags == other.fFlags;
}
Expand Down
7 changes: 0 additions & 7 deletions src/core/SkTextBlobPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class SkRunFont : SkNoncopyable {
sk_sp<SkTypeface> fTypeface;
SkScalar fSkewX;

#ifdef SK_SUPPORT_LEGACY_PAINTALIGNENUM
static_assert(SkPaint::kAlignCount < 4, "insufficient_align_bits");
uint32_t fAlign : 2;
#endif
static_assert(SkPaint::kFull_Hinting < 4, "insufficient_hinting_bits");
uint32_t fHinting : 2;
static_assert((kFlagsMask & 0xffff) == kFlagsMask, "insufficient_flags_bits");
Expand Down Expand Up @@ -243,9 +239,6 @@ inline SkPaint::SkPaint(const SkPaint& basePaint, const SkRunFont& runFont)
, fBitfieldsUInt{(basePaint.fBitfieldsUInt & ~SkRunFont::kFlagsMask) | runFont.fFlags} {
fBitfields.fTextEncoding = kGlyphID_TextEncoding;
fBitfields.fHinting = runFont.fHinting;
#ifdef SK_SUPPORT_LEGACY_PAINTALIGNENUM
fBitfields.fTextAlign = runFont.fAlign;
#endif
}

/**
Expand Down
22 changes: 1 addition & 21 deletions src/core/SkTextToPathIter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "SkPaint.h"
#include "SkStrikeCache.h"


class SkTextBaseIter {
protected:
SkTextBaseIter(const char text[], size_t length, const SkPaint& paint,
Expand Down Expand Up @@ -53,10 +52,7 @@ class SkTextInterceptsIter : SkTextBaseIter {

SkTextInterceptsIter(const char text[], size_t length, const SkPaint& paint,
const SkScalar bounds[2], SkScalar x, SkScalar y, TextType textType)
: SkTextBaseIter(text, length, paint, false)
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
, fTextType(textType)
#endif
: SkTextBaseIter(text, length, paint, false)
{
fBoundsBase[0] = bounds[0];
fBoundsBase[1] = bounds[1];
Expand All @@ -70,19 +66,6 @@ class SkTextInterceptsIter : SkTextBaseIter {

void setPosition(SkScalar x, SkScalar y) {
SkScalar xOffset = 0;
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
if (TextType::kPosText == fTextType
&& fPaint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
const char* text = fText;
const SkGlyph& glyph = fGlyphCacheProc(fCache.get(), &text, fStop);
SkScalar width = (&glyph.fAdvanceX)[0] * fScale;
if (fPaint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
}
xOffset = width;
}
#endif

for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) {
SkScalar bound = fBoundsBase[i] - y;
fBounds[i] = bound / fScale;
Expand All @@ -95,9 +78,6 @@ class SkTextInterceptsIter : SkTextBaseIter {
private:
SkScalar fBounds[2];
SkScalar fBoundsBase[2];
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
TextType fTextType;
#endif
};

#endif
3 changes: 0 additions & 3 deletions src/gpu/ops/GrAAConvexTessellator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,6 @@ void GrAAConvexTessellator::draw(SkCanvas* canvas) const {

SkPaint paint;
paint.setTextSize(kPointTextSize);
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
paint.setTextAlign(SkPaint::kCenter_Align);
#endif
if (this->depth(i) <= -kAntialiasingRadius) {
paint.setColor(SK_ColorWHITE);
}
Expand Down
3 changes: 0 additions & 3 deletions src/pdf/SkPDFDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,6 @@ void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset)
transparent.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
transparent.setColor(SK_ColorTRANSPARENT);
transparent.setTextSize(paint.getTextSize());
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
transparent.setTextAlign(paint.getTextAlign());
#endif
transparent.setTextScaleX(paint.getTextScaleX());
transparent.setTextSkewX(paint.getTextSkewX());
SkGlyphRun tmp(glyphRun, transparent);
Expand Down
Loading

0 comments on commit 1edff30

Please sign in to comment.