Revert "hide setTextAlign"
This reverts commit 43c718302e
.
Reason for revert: Google 3 roll.
Original change's description:
> hide setTextAlign
>
> Bug: skia:8493
> Change-Id: Ib3347f600300e90d5bcc47910fd75244039a016c
> Reviewed-on: https://skia-review.googlesource.com/c/164697
> Commit-Queue: Mike Reed <reed@google.com>
> Reviewed-by: Ben Wagner <bungeman@google.com>
TBR=djsollen@google.com,bungeman@google.com,herb@google.com,fmalita@chromium.org,reed@google.com
Change-Id: I877bf993e71a6e81f1322c799c533bfea6c5813f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:8493
Reviewed-on: https://skia-review.googlesource.com/c/165660
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
51baa0e4f8
commit
f10ea21088
@ -891,9 +891,7 @@ 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) {
|
||||
|
@ -872,7 +872,6 @@ public:
|
||||
*/
|
||||
static constexpr int kAlignCount = 3;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
/** Returns SkPaint::Align.
|
||||
Returns kLeft_Align if SkPaint::Align has not been set.
|
||||
|
||||
@ -886,7 +885,6 @@ public:
|
||||
@param align text placement relative to position
|
||||
*/
|
||||
void setTextAlign(Align align);
|
||||
#endif
|
||||
|
||||
/** Returns text size in points.
|
||||
|
||||
|
@ -164,9 +164,7 @@ void SkFont::LEGACY_applyToPaint(SkPaint* paint) const {
|
||||
|
||||
paint->setHinting((SkPaint::Hinting)this->getHinting());
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
paint->setTextAlign((SkPaint::Align)fAlign);
|
||||
#endif
|
||||
}
|
||||
|
||||
SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) {
|
||||
@ -195,11 +193,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, (int)paint.getTextAlign());
|
||||
font.setHinting((Hinting)paint.getHinting());
|
||||
return font;
|
||||
}
|
||||
|
@ -387,7 +387,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) {
|
||||
@ -397,7 +396,6 @@ void SkGlyphRunBuilder::simplifyDrawText(
|
||||
pt -= len;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
this->makeGlyphRun(
|
||||
paint,
|
||||
|
@ -309,7 +309,6 @@ void SkPaint::setStrokeJoin(Join jt) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
void SkPaint::setTextAlign(Align align) {
|
||||
if ((unsigned)align < kAlignCount) {
|
||||
fBitfields.fTextAlign = SkToU8(align);
|
||||
@ -319,7 +318,6 @@ void SkPaint::setTextAlign(Align align) {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkPaint::setTextSize(SkScalar ts) {
|
||||
if (ts >= 0) {
|
||||
@ -424,9 +422,7 @@ static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned align,
|
||||
static FlatFlags unpack_paint_flags(SkPaint* paint, uint32_t packed) {
|
||||
paint->setFlags(packed >> 16);
|
||||
paint->setHinting((SkPaint::Hinting)((packed >> 14) & BPF_Mask(kHint_BPF)));
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
paint->setTextAlign((SkPaint::Align)((packed >> 12) & BPF_Mask(kAlign_BPF)));
|
||||
#endif
|
||||
paint->setFilterQuality((SkFilterQuality)((packed >> 10) & BPF_Mask(kFilter_BPF)));
|
||||
return (FlatFlags)(packed & kFlatFlagMask);
|
||||
}
|
||||
@ -458,12 +454,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(),
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
paint.getTextAlign(),
|
||||
#else
|
||||
SkPaint::kLeft_Align,
|
||||
#endif
|
||||
buffer.writeUInt(pack_paint_flags(paint.getFlags(), paint.getHinting(), paint.getTextAlign(),
|
||||
paint.getFilterQuality(), flatFlags));
|
||||
buffer.writeUInt(pack_4(paint.getStrokeCap(), paint.getStrokeJoin(),
|
||||
(paint.getStyle() << 4) | paint.getTextEncoding(),
|
||||
|
@ -811,7 +811,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;
|
||||
@ -820,7 +819,6 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
|
||||
}
|
||||
xOffset = -width;
|
||||
}
|
||||
#endif
|
||||
fXPos = xOffset;
|
||||
fPrevAdvance = 0;
|
||||
|
||||
|
@ -27,11 +27,7 @@ SkRunFont::SkRunFont(const SkPaint& paint)
|
||||
, fScaleX(paint.getTextScaleX())
|
||||
, fTypeface(SkPaintPriv::RefTypefaceOrDefault(paint))
|
||||
, fSkewX(paint.getTextSkewX())
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
, fAlign(paint.getTextAlign())
|
||||
#else
|
||||
, fAlign(SkPaint::kLeft_Align)
|
||||
#endif
|
||||
, fHinting(paint.getHinting())
|
||||
, fFlags(paint.getFlags() & kFlagsMask) { }
|
||||
|
||||
@ -41,9 +37,7 @@ 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);
|
||||
|
@ -54,10 +54,7 @@ public:
|
||||
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
|
||||
{
|
||||
, fTextType(textType) {
|
||||
fBoundsBase[0] = bounds[0];
|
||||
fBoundsBase[1] = bounds[1];
|
||||
this->setPosition(x, y);
|
||||
@ -70,7 +67,6 @@ public:
|
||||
|
||||
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;
|
||||
@ -81,7 +77,6 @@ public:
|
||||
}
|
||||
xOffset = width;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) {
|
||||
SkScalar bound = fBoundsBase[i] - y;
|
||||
@ -95,9 +90,7 @@ public:
|
||||
private:
|
||||
SkScalar fBounds[2];
|
||||
SkScalar fBoundsBase[2];
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
TextType fTextType;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1089,9 +1089,7 @@ 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);
|
||||
}
|
||||
|
@ -1034,6 +1034,7 @@ static bool contains(const SkRect& r, SkPoint p) {
|
||||
void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset) {
|
||||
SkPaint paint{glyphRun.paint()};
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setTextAlign(SkPaint::kLeft_Align);
|
||||
SkPath path;
|
||||
SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
|
||||
|
||||
@ -1052,9 +1053,7 @@ 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());
|
||||
*tmp.mutablePaint() = std::move(transparent);
|
||||
@ -1093,6 +1092,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
|
||||
uint32_t glyphCount = SkToU32(glyphRun.glyphsIDs().size());
|
||||
SkPaint srcPaint{glyphRun.paint()};
|
||||
srcPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
srcPaint.setTextAlign(SkPaint::kLeft_Align);
|
||||
|
||||
if (!glyphCount || !glyphs || srcPaint.getTextSize() <= 0 || this->hasEmptyClip()) {
|
||||
return;
|
||||
@ -1138,6 +1138,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
|
||||
SkScalar textScaleY = textSize / emSize;
|
||||
SkScalar textScaleX = advanceScale + paint.getTextSkewX() * textScaleY;
|
||||
|
||||
SkASSERT(paint.getTextAlign() == SkPaint::kLeft_Align);
|
||||
SkRect clipStackBounds = this->cs().bounds(this->bounds());
|
||||
{
|
||||
ScopedContentEntry content(this, paint, true);
|
||||
|
@ -71,7 +71,6 @@ static const char* svg_join(SkPaint::Join join) {
|
||||
return join_map[join];
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
// Keep in sync with SkPaint::Align
|
||||
static const char* text_align_map[] = {
|
||||
nullptr, // kLeft_Align (default)
|
||||
@ -80,12 +79,10 @@ static const char* text_align_map[] = {
|
||||
};
|
||||
static_assert(SK_ARRAY_COUNT(text_align_map) == SkPaint::kAlignCount,
|
||||
"missing_text_align_map_entry");
|
||||
|
||||
static const char* svg_text_align(SkPaint::Align align) {
|
||||
SkASSERT(align < SK_ARRAY_COUNT(text_align_map));
|
||||
return text_align_map[align];
|
||||
}
|
||||
#endif
|
||||
|
||||
static SkString svg_transform(const SkMatrix& t) {
|
||||
SkASSERT(!t.isIdentity());
|
||||
@ -607,11 +604,9 @@ void SkSVGDevice::AutoElement::addPathAttributes(const SkPath& path) {
|
||||
void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
|
||||
this->addAttribute("font-size", paint.getTextSize());
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
if (const char* textAlign = svg_text_align(paint.getTextAlign())) {
|
||||
this->addAttribute("text-anchor", textAlign);
|
||||
}
|
||||
#endif
|
||||
|
||||
SkString familyName;
|
||||
SkTHashSet<SkString> familySet;
|
||||
|
@ -846,6 +846,41 @@ static int lpaint_getFontID(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char* fLabel;
|
||||
SkPaint::Align fAlign;
|
||||
} gAlignRec[] = {
|
||||
{ "left", SkPaint::kLeft_Align },
|
||||
{ "center", SkPaint::kCenter_Align },
|
||||
{ "right", SkPaint::kRight_Align },
|
||||
};
|
||||
|
||||
static int lpaint_getTextAlign(lua_State* L) {
|
||||
SkPaint::Align align = get_obj<SkPaint>(L, 1)->getTextAlign();
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gAlignRec); ++i) {
|
||||
if (gAlignRec[i].fAlign == align) {
|
||||
lua_pushstring(L, gAlignRec[i].fLabel);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lpaint_setTextAlign(lua_State* L) {
|
||||
if (lua_isstring(L, 2)) {
|
||||
size_t len;
|
||||
const char* label = lua_tolstring(L, 2, &len);
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gAlignRec); ++i) {
|
||||
if (!strcmp(gAlignRec[i].fLabel, label)) {
|
||||
get_obj<SkPaint>(L, 1)->setTextAlign(gAlignRec[i].fAlign);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lpaint_getStroke(lua_State* L) {
|
||||
lua_pushboolean(L, SkPaint::kStroke_Style == get_obj<SkPaint>(L, 1)->getStyle());
|
||||
return 1;
|
||||
@ -1046,6 +1081,8 @@ static const struct luaL_Reg gSkPaint_Methods[] = {
|
||||
{ "setTypeface", lpaint_setTypeface },
|
||||
{ "getHinting", lpaint_getHinting },
|
||||
{ "getFontID", lpaint_getFontID },
|
||||
{ "getTextAlign", lpaint_getTextAlign },
|
||||
{ "setTextAlign", lpaint_setTextAlign },
|
||||
{ "getStroke", lpaint_getStroke },
|
||||
{ "setStroke", lpaint_setStroke },
|
||||
{ "getStrokeCap", lpaint_getStrokeCap },
|
||||
|
@ -214,6 +214,11 @@ DEF_TEST(Paint_flattening, reporter) {
|
||||
SkPaint::kNormal_Hinting,
|
||||
SkPaint::kFull_Hinting,
|
||||
};
|
||||
const SkPaint::Align align[] = {
|
||||
SkPaint::kLeft_Align,
|
||||
SkPaint::kCenter_Align,
|
||||
SkPaint::kRight_Align
|
||||
};
|
||||
const SkPaint::Cap caps[] = {
|
||||
SkPaint::kButt_Cap,
|
||||
SkPaint::kRound_Cap,
|
||||
@ -245,6 +250,7 @@ DEF_TEST(Paint_flattening, reporter) {
|
||||
|
||||
FOR_SETUP(i, levels, setFilterQuality)
|
||||
FOR_SETUP(j, hinting, setHinting)
|
||||
FOR_SETUP(k, align, setTextAlign)
|
||||
FOR_SETUP(l, caps, setStrokeCap)
|
||||
FOR_SETUP(m, joins, setStrokeJoin)
|
||||
FOR_SETUP(n, encodings, setTextEncoding)
|
||||
@ -261,7 +267,7 @@ DEF_TEST(Paint_flattening, reporter) {
|
||||
SkPaintPriv::Unflatten(&paint2, reader);
|
||||
REPORTER_ASSERT(reporter, paint2 == paint);
|
||||
|
||||
}}}}}}
|
||||
}}}}}}}
|
||||
#undef FOR_SETUP
|
||||
|
||||
}
|
||||
|
@ -185,9 +185,7 @@ public:
|
||||
font.setTextScaleX(4.2f);
|
||||
font.setTypeface(SkTypeface::MakeDefault());
|
||||
font.setTextSkewX(0.42f);
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
font.setTextAlign(SkPaint::kCenter_Align);
|
||||
#endif
|
||||
font.setHinting(SkPaint::kFull_Hinting);
|
||||
font.setAntiAlias(true);
|
||||
font.setFakeBoldText(true);
|
||||
@ -204,9 +202,7 @@ public:
|
||||
REPORTER_ASSERT(reporter, defaultPaint.getTextScaleX() != font.getTextScaleX());
|
||||
REPORTER_ASSERT(reporter, defaultPaint.getTypeface() != font.getTypeface());
|
||||
REPORTER_ASSERT(reporter, defaultPaint.getTextSkewX() != font.getTextSkewX());
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
REPORTER_ASSERT(reporter, defaultPaint.getTextAlign() != font.getTextAlign());
|
||||
#endif
|
||||
REPORTER_ASSERT(reporter, defaultPaint.getHinting() != font.getHinting());
|
||||
REPORTER_ASSERT(reporter, defaultPaint.isAntiAlias() != font.isAntiAlias());
|
||||
REPORTER_ASSERT(reporter, defaultPaint.isFakeBoldText() != font.isFakeBoldText());
|
||||
@ -233,9 +229,7 @@ public:
|
||||
REPORTER_ASSERT(reporter, paint.getTextScaleX() == font.getTextScaleX());
|
||||
REPORTER_ASSERT(reporter, paint.getTypeface() == font.getTypeface());
|
||||
REPORTER_ASSERT(reporter, paint.getTextSkewX() == font.getTextSkewX());
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
REPORTER_ASSERT(reporter, paint.getTextAlign() == font.getTextAlign());
|
||||
#endif
|
||||
REPORTER_ASSERT(reporter, paint.getHinting() == font.getHinting());
|
||||
REPORTER_ASSERT(reporter, paint.isAntiAlias() == font.isAntiAlias());
|
||||
REPORTER_ASSERT(reporter, paint.isFakeBoldText() == font.isFakeBoldText());
|
||||
|
@ -968,7 +968,6 @@ static void apply_paint_patheffect(const SkPaint& paint, Json::Value* target,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) {
|
||||
SkPaint::Align textAlign = paint.getTextAlign();
|
||||
if (textAlign != SkPaint::kLeft_Align) {
|
||||
@ -985,7 +984,6 @@ static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void apply_paint_typeface(const SkPaint& paint, Json::Value* target,
|
||||
UrlDataManager& urlDataManager) {
|
||||
@ -1071,9 +1069,7 @@ Json::Value SkDrawCommand::MakeJsonPaint(const SkPaint& paint, UrlDataManager& u
|
||||
apply_paint_cap(paint, &result);
|
||||
apply_paint_join(paint, &result);
|
||||
apply_paint_filterquality(paint, &result);
|
||||
#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN
|
||||
apply_paint_textalign(paint, &result);
|
||||
#endif
|
||||
apply_paint_patheffect(paint, &result, urlDataManager);
|
||||
apply_paint_maskfilter(paint, &result, urlDataManager);
|
||||
apply_paint_shader(paint, &result, urlDataManager);
|
||||
|
@ -198,6 +198,7 @@ static void output_font(sk_sp<SkTypeface> face, const char* identifier, FILE* ou
|
||||
int emSize = face->getUnitsPerEm() * 2;
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextAlign(SkPaint::kLeft_Align);
|
||||
paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
|
||||
paint.setTextSize(emSize);
|
||||
paint.setTypeface(std::move(face));
|
||||
|
Loading…
Reference in New Issue
Block a user