From 6e24cd3e28c19c3d87fbabfa146c6049b67a2e01 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Sat, 27 Oct 2018 14:39:00 +0000 Subject: [PATCH] Reland "hide setTextAlign" This reverts commit f10ea2108809e8c098184d9ff0daf5ba23917da4. Reason for revert: flag added for google3 Original change's description: > Revert "hide setTextAlign" > > This reverts commit 43c718302e446d5fcd2b3dbc5a7ade779297f756. > > 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 > > Reviewed-by: Ben Wagner > > 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 > Commit-Queue: Brian Osman TBR=djsollen@google.com,bungeman@google.com,herb@google.com,brianosman@google.com,fmalita@chromium.org,reed@google.com Change-Id: I0f224cd560cea12ddac3cd48d244f85ccd943086 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:8493 Reviewed-on: https://skia-review.googlesource.com/c/165681 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- fuzz/FuzzCanvas.cpp | 2 ++ include/core/SkPaint.h | 2 ++ src/core/SkFont.cpp | 8 +++++- src/core/SkGlyphRun.cpp | 2 ++ src/core/SkPaint.cpp | 11 +++++++- src/core/SkPaint_text.cpp | 2 ++ src/core/SkTextBlob.cpp | 6 +++++ src/core/SkTextToPathIter.h | 9 ++++++- src/gpu/ops/GrAAConvexTessellator.cpp | 2 ++ src/pdf/SkPDFDevice.cpp | 5 ++-- src/svg/SkSVGDevice.cpp | 5 ++++ src/utils/SkLua.cpp | 37 --------------------------- tests/PaintTest.cpp | 8 +----- tests/TextBlobTest.cpp | 6 +++++ tools/debugger/SkDrawCommand.cpp | 4 +++ tools/fonts/create_test_font.cpp | 1 - 16 files changed, 59 insertions(+), 51 deletions(-) diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index 9aa2de62cd..2bf4edb3d7 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -891,7 +891,9 @@ static void fuzz_paint_text(Fuzz* fuzz, SkPaint* paint) { paint->setDevKernText( make_fuzz_t(fuzz)); paint->setHinting( make_fuzz_t_range(fuzz, 0, SkPaint::kFull_Hinting)); +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN paint->setTextAlign( make_fuzz_t_range(fuzz, 0, 2)); +#endif } static void fuzz_paint_text_encoding(Fuzz* fuzz, SkPaint* paint) { diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index e79f9fe29c..f33604c9a0 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -872,6 +872,7 @@ public: */ static constexpr int kAlignCount = 3; +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN /** Returns SkPaint::Align. Returns kLeft_Align if SkPaint::Align has not been set. @@ -885,6 +886,7 @@ public: @param align text placement relative to position */ void setTextAlign(Align align); +#endif /** Returns text size in points. diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp index a29b51a4d2..ad932fe5bb 100644 --- a/src/core/SkFont.cpp +++ b/src/core/SkFont.cpp @@ -164,7 +164,9 @@ 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) { @@ -193,7 +195,11 @@ SkFont SkFont::LEGACY_ExtractFromPaint(const SkPaint& paint) { } SkFont font(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(), - paint.getTextSkewX(), flags, (int)paint.getTextAlign()); + paint.getTextSkewX(), flags +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN + , (int)paint.getTextAlign() +#endif + ); font.setHinting((Hinting)paint.getHinting()); return font; } diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index 1dece555dd..c0d40df5a0 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -387,6 +387,7 @@ 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) { @@ -396,6 +397,7 @@ void SkGlyphRunBuilder::simplifyDrawText( pt -= len; } } +#endif this->makeGlyphRun( paint, diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 0a6f9e2248..83fcf0222b 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -309,6 +309,7 @@ void SkPaint::setStrokeJoin(Join jt) { /////////////////////////////////////////////////////////////////////////////// +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN void SkPaint::setTextAlign(Align align) { if ((unsigned)align < kAlignCount) { fBitfields.fTextAlign = SkToU8(align); @@ -318,6 +319,7 @@ void SkPaint::setTextAlign(Align align) { #endif } } +#endif void SkPaint::setTextSize(SkScalar ts) { if (ts >= 0) { @@ -422,7 +424,9 @@ 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); } @@ -454,7 +458,12 @@ 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(), paint.getTextAlign(), + buffer.writeUInt(pack_paint_flags(paint.getFlags(), paint.getHinting(), +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN + paint.getTextAlign(), +#else + SkPaint::kLeft_Align, +#endif paint.getFilterQuality(), flatFlags)); buffer.writeUInt(pack_4(paint.getStrokeCap(), paint.getStrokeJoin(), (paint.getStyle() << 4) | paint.getTextEncoding(), diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp index 25f20b310c..89a606838f 100644 --- a/src/core/SkPaint_text.cpp +++ b/src/core/SkPaint_text.cpp @@ -811,6 +811,7 @@ 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; @@ -819,6 +820,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length, } xOffset = -width; } +#endif fXPos = xOffset; fPrevAdvance = 0; diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index b758c15150..221568e59a 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -27,7 +27,11 @@ 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) { } @@ -37,7 +41,9 @@ void SkRunFont::applyToPaint(SkPaint* paint) const { paint->setTextSize(fSize); paint->setTextScaleX(fScaleX); paint->setTextSkewX(fSkewX); +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN paint->setTextAlign(static_cast(fAlign)); +#endif paint->setHinting(static_cast(fHinting)); paint->setFlags((paint->getFlags() & ~kFlagsMask) | fFlags); diff --git a/src/core/SkTextToPathIter.h b/src/core/SkTextToPathIter.h index 103b96c8c6..c387c70fd3 100644 --- a/src/core/SkTextToPathIter.h +++ b/src/core/SkTextToPathIter.h @@ -54,7 +54,10 @@ 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) - , fTextType(textType) { +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN + , fTextType(textType) +#endif + { fBoundsBase[0] = bounds[0]; fBoundsBase[1] = bounds[1]; this->setPosition(x, y); @@ -67,6 +70,7 @@ 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; @@ -77,6 +81,7 @@ public: } xOffset = width; } +#endif for (int i = 0; i < (int) SK_ARRAY_COUNT(fBounds); ++i) { SkScalar bound = fBoundsBase[i] - y; @@ -90,7 +95,9 @@ public: private: SkScalar fBounds[2]; SkScalar fBoundsBase[2]; +#ifdef SK_SUPPORT_LEGACY_SETTEXTALIGN TextType fTextType; +#endif }; #endif diff --git a/src/gpu/ops/GrAAConvexTessellator.cpp b/src/gpu/ops/GrAAConvexTessellator.cpp index 3c82c6f460..1071dd011e 100644 --- a/src/gpu/ops/GrAAConvexTessellator.cpp +++ b/src/gpu/ops/GrAAConvexTessellator.cpp @@ -1089,7 +1089,9 @@ 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); } diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 20bbcdd411..bdde1ec791 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1034,7 +1034,6 @@ 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); @@ -1053,7 +1052,9 @@ 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); @@ -1092,7 +1093,6 @@ 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,7 +1138,6 @@ 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); diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index f85b9a92a0..902dd28c6c 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -71,6 +71,7 @@ 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) @@ -79,10 +80,12 @@ 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()); @@ -604,9 +607,11 @@ 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 familySet; diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 83008e45d8..c5cdf62040 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -846,41 +846,6 @@ 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(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(L, 1)->setTextAlign(gAlignRec[i].fAlign); - break; - } - } - } - return 0; -} - static int lpaint_getStroke(lua_State* L) { lua_pushboolean(L, SkPaint::kStroke_Style == get_obj(L, 1)->getStyle()); return 1; @@ -1081,8 +1046,6 @@ 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 }, diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index 10be8f9913..fa1340c58c 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -214,11 +214,6 @@ 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, @@ -250,7 +245,6 @@ 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) @@ -267,7 +261,7 @@ DEF_TEST(Paint_flattening, reporter) { SkPaintPriv::Unflatten(&paint2, reader); REPORTER_ASSERT(reporter, paint2 == paint); - }}}}}}} + }}}}}} #undef FOR_SETUP } diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 6438c59b96..3c29f8dc8f 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -185,7 +185,9 @@ 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); @@ -202,7 +204,9 @@ 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()); @@ -229,7 +233,9 @@ 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()); diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 022abbc762..8551526b76 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -968,6 +968,7 @@ 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) { @@ -984,6 +985,7 @@ 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) { @@ -1069,7 +1071,9 @@ 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); diff --git a/tools/fonts/create_test_font.cpp b/tools/fonts/create_test_font.cpp index 6994847254..6e9f082769 100644 --- a/tools/fonts/create_test_font.cpp +++ b/tools/fonts/create_test_font.cpp @@ -198,7 +198,6 @@ static void output_font(sk_sp 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));