aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-05-21 16:10:17 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-21 21:53:54 +0000
commit1e7c65806f3fbde13b5d8064dc5734d98c32a284 (patch)
treee758fae7c14f09ba185b8aaa8f8306dad5cd4905 /src
parent4bfb50b904e0e92d10145398eb3a6f8dd7868867 (diff)
drawPosText no longer obeys paint alignment
Change-Id: Iac498b54dea4aa1b203d2b9c58e15bb5f2147f82 Reviewed-on: https://skia-review.googlesource.com/129462 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkDraw.cpp8
-rw-r--r--src/core/SkFindAndPlaceGlyph.h90
-rw-r--r--src/core/SkOverdrawCanvas.cpp2
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp22
-rw-r--r--src/xps/SkXPSDevice.cpp3
5 files changed, 20 insertions, 105 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 7e526e6098..b7150f85f8 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1590,7 +1590,6 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, const SkS
paint, props, this->scalerContextFlags(), nullptr);
const char* stop = text + byteLength;
- SkTextAlignProc alignProc(paint.getTextAlign());
SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
// Now restore the original settings, so we "draw" with whatever style/stroking.
@@ -1602,10 +1601,8 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, const SkS
if (glyph.fWidth) {
const SkPath* path = cache->findPath(glyph);
if (path) {
- SkPoint tmsLoc;
- tmsProc(pos, &tmsLoc);
SkPoint loc;
- alignProc(tmsLoc, glyph, &loc);
+ tmsProc(pos, &loc);
matrix[SkMatrix::kMTransX] = loc.fX;
matrix[SkMatrix::kMTransY] = loc.fY;
@@ -1641,11 +1638,10 @@ void SkDraw::drawPosText(const char text[], size_t byteLength, const SkScalar po
SkAutoBlitterChoose blitterChooser(*this, nullptr, paint);
SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get());
DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBlitter());
- SkPaint::Align textAlignment = paint.getTextAlign();
SkFindAndPlaceGlyph::ProcessPosText(
paint.getTextEncoding(), text, byteLength,
- offset, *fMatrix, pos, scalarsPerPosition, textAlignment, cache.get(), drawOneGlyph);
+ offset, *fMatrix, pos, scalarsPerPosition, cache.get(), drawOneGlyph);
}
#if defined _WIN32
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h
index 00417152ab..69debe4d59 100644
--- a/src/core/SkFindAndPlaceGlyph.h
+++ b/src/core/SkFindAndPlaceGlyph.h
@@ -44,7 +44,6 @@ public:
static void ProcessPosText(
SkPaint::TextEncoding, const char text[], size_t byteLength,
SkPoint offset, const SkMatrix& matrix, const SkScalar pos[], int scalarsPerPosition,
- SkPaint::Align textAlignment,
SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph);
// The SubpixelAlignment function produces a suitable position for the glyph cache to
@@ -288,23 +287,6 @@ private:
const SkMatrixPriv::MapXYProc fMapProc;
};
- // TextAlignmentAdjustment handles shifting the glyph based on its width.
- static SkPoint TextAlignmentAdjustment(SkPaint::Align textAlignment, const SkGlyph& glyph) {
- switch (textAlignment) {
- case SkPaint::kLeft_Align:
- return {0.0f, 0.0f};
- case SkPaint::kCenter_Align:
- return {SkFloatToScalar(glyph.fAdvanceX) / 2,
- SkFloatToScalar(glyph.fAdvanceY) / 2};
- case SkPaint::kRight_Align:
- return {SkFloatToScalar(glyph.fAdvanceX),
- SkFloatToScalar(glyph.fAdvanceY)};
- }
- // Even though the entire enum is covered above, MVSC doesn't think so. Make it happy.
- SK_ABORT("Should never get here.");
- return {0.0f, 0.0f};
- }
-
// The "call" to SkFixedToScalar is actually a macro. It's macros all the way down.
// Needs to be a macro because you can't have a const float unless you make it constexpr.
static constexpr SkScalar kSubpixelRounding = SkFixedToScalar(SkGlyph::kSubpixelRound);
@@ -336,8 +318,7 @@ private:
// GlyphFindAndPlaceSubpixel handles finding and placing glyphs when sub-pixel positioning is
// requested. After it has found and placed the glyph it calls the templated function
// ProcessOneGlyph in order to actually perform an action.
- template<typename ProcessOneGlyph, SkPaint::Align kTextAlignment,
- SkAxisAlignment kAxisAlignment>
+ template<typename ProcessOneGlyph, SkAxisAlignment kAxisAlignment>
class GlyphFindAndPlaceSubpixel final : public GlyphFindAndPlaceInterface<ProcessOneGlyph> {
public:
explicit GlyphFindAndPlaceSubpixel(GlyphFinderInterface* glyphFinder)
@@ -346,24 +327,6 @@ private:
SkPoint findAndPositionGlyph(
const char** text, SkPoint position, ProcessOneGlyph&& processOneGlyph) override {
- if (kTextAlignment != SkPaint::kLeft_Align) {
- // Get the width of an un-sub-pixel positioned glyph for calculating the
- // alignment. This is not needed for kLeftAlign because its adjustment is
- // always {0, 0}.
- const char* tempText = *text;
- const SkGlyph &metricGlyph = fGlyphFinder->lookupGlyph(&tempText);
-
- if (metricGlyph.fWidth <= 0) {
- // Exiting early, be sure to update text pointer.
- *text = tempText;
- return position + SkPoint{SkFloatToScalar(metricGlyph.fAdvanceX),
- SkFloatToScalar(metricGlyph.fAdvanceY)};
- }
-
- // Adjust the final position by the alignment adjustment.
- position -= TextAlignmentAdjustment(kTextAlignment, metricGlyph);
- }
-
// Find the glyph.
SkIPoint lookupPosition = SubpixelAlignment(kAxisAlignment, position);
const SkGlyph& renderGlyph =
@@ -384,7 +347,7 @@ private:
// GlyphFindAndPlaceFullPixel handles finding and placing glyphs when no sub-pixel
// positioning is requested.
- template<typename ProcessOneGlyph, SkPaint::Align kTextAlignment>
+ template<typename ProcessOneGlyph>
class GlyphFindAndPlaceFullPixel final : public GlyphFindAndPlaceInterface<ProcessOneGlyph> {
public:
explicit GlyphFindAndPlaceFullPixel(GlyphFinderInterface* glyphFinder)
@@ -397,7 +360,6 @@ private:
const SkGlyph& glyph = fGlyphFinder->lookupGlyph(text);
if (glyph.fWidth > 0) {
- finalPosition -= TextAlignmentAdjustment(kTextAlignment, glyph);
processOneGlyph(glyph, finalPosition, {SK_ScalarHalf, SK_ScalarHalf});
}
return finalPosition + SkPoint{SkFloatToScalar(glyph.fAdvanceX),
@@ -408,20 +370,20 @@ private:
GlyphFinderInterface* fGlyphFinder;
};
- template <typename ProcessOneGlyph, SkPaint::Align kTextAlignment>
+ template <typename ProcessOneGlyph>
static GlyphFindAndPlaceInterface<ProcessOneGlyph>* getSubpixel(
SkArenaAlloc* arena, SkAxisAlignment axisAlignment, GlyphFinderInterface* glyphFinder)
{
switch (axisAlignment) {
case kX_SkAxisAlignment:
return arena->make<GlyphFindAndPlaceSubpixel<
- ProcessOneGlyph, kTextAlignment, kX_SkAxisAlignment>>(glyphFinder);
+ ProcessOneGlyph, kX_SkAxisAlignment>>(glyphFinder);
case kNone_SkAxisAlignment:
return arena->make<GlyphFindAndPlaceSubpixel<
- ProcessOneGlyph, kTextAlignment, kNone_SkAxisAlignment>>(glyphFinder);
+ ProcessOneGlyph, kNone_SkAxisAlignment>>(glyphFinder);
case kY_SkAxisAlignment:
return arena->make<GlyphFindAndPlaceSubpixel<
- ProcessOneGlyph, kTextAlignment, kY_SkAxisAlignment>>(glyphFinder);
+ ProcessOneGlyph, kY_SkAxisAlignment>>(glyphFinder);
}
SK_ABORT("Should never get here.");
return nullptr;
@@ -449,7 +411,6 @@ template<typename ProcessOneGlyph>
inline void SkFindAndPlaceGlyph::ProcessPosText(
SkPaint::TextEncoding textEncoding, const char text[], size_t byteLength,
SkPoint offset, const SkMatrix& matrix, const SkScalar pos[], int scalarsPerPosition,
- SkPaint::Align textAlignment,
SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph) {
SkAxisAlignment axisAlignment = cache->getScalerContext()->computeAxisAlignmentForHText();
@@ -457,7 +418,6 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
// Specialized code for handling the most common case for blink.
if (textEncoding == SkPaint::kGlyphID_TextEncoding
- && textAlignment == SkPaint::kLeft_Align
&& axisAlignment == kX_SkAxisAlignment
&& cache->isSubpixel()
&& mtype <= SkMatrix::kTranslate_Mask)
@@ -465,7 +425,7 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
GlyphIdGlyphFinder glyphFinder(cache);
using Positioner =
GlyphFindAndPlaceSubpixel <
- ProcessOneGlyph, SkPaint::kLeft_Align, kX_SkAxisAlignment>;
+ ProcessOneGlyph, kX_SkAxisAlignment>;
HorizontalPositions hPositions{pos};
ArbitraryPositions aPositions{pos};
PositionReaderInterface* positions = nullptr;
@@ -509,37 +469,9 @@ inline void SkFindAndPlaceGlyph::ProcessPosText(
GlyphFindAndPlaceInterface<ProcessOneGlyph>* findAndPosition = nullptr;
if (cache->isSubpixel()) {
- switch (textAlignment) {
- case SkPaint::kLeft_Align:
- findAndPosition = getSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>(
- &arena, axisAlignment, glyphFinder);
- break;
- case SkPaint::kCenter_Align:
- findAndPosition = getSubpixel<ProcessOneGlyph, SkPaint::kCenter_Align>(
- &arena, axisAlignment, glyphFinder);
- break;
- case SkPaint::kRight_Align:
- findAndPosition = getSubpixel<ProcessOneGlyph, SkPaint::kRight_Align>(
- &arena, axisAlignment, glyphFinder);
- break;
- }
+ findAndPosition = getSubpixel<ProcessOneGlyph>(&arena, axisAlignment, glyphFinder);
} else {
- switch (textAlignment) {
- case SkPaint::kLeft_Align:
- findAndPosition = arena.make<
- GlyphFindAndPlaceFullPixel<ProcessOneGlyph, SkPaint::kLeft_Align>>(glyphFinder);
- break;
- case SkPaint::kCenter_Align:
- findAndPosition = arena.make<
- GlyphFindAndPlaceFullPixel<ProcessOneGlyph,
- SkPaint::kCenter_Align>>(glyphFinder);
- break;
- case SkPaint::kRight_Align:
- findAndPosition = arena.make<
- GlyphFindAndPlaceFullPixel<ProcessOneGlyph,
- SkPaint::kRight_Align>>(glyphFinder);
- break;
- }
+ findAndPosition = arena.make<GlyphFindAndPlaceFullPixel<ProcessOneGlyph>>(glyphFinder);
}
const char* stop = text + byteLength;
@@ -575,10 +507,10 @@ inline void SkFindAndPlaceGlyph::ProcessText(
GlyphFindAndPlaceInterface<ProcessOneGlyph>* findAndPosition = nullptr;
if (cache->isSubpixel()) {
SkAxisAlignment axisAlignment = cache->getScalerContext()->computeAxisAlignmentForHText();
- findAndPosition = getSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>(
+ findAndPosition = getSubpixel<ProcessOneGlyph>(
&arena, axisAlignment, glyphFinder);
} else {
- using FullPixel = GlyphFindAndPlaceFullPixel<ProcessOneGlyph, SkPaint::kLeft_Align>;
+ using FullPixel = GlyphFindAndPlaceFullPixel<ProcessOneGlyph>;
findAndPosition = arena.make<FullPixel>(glyphFinder);
}
diff --git a/src/core/SkOverdrawCanvas.cpp b/src/core/SkOverdrawCanvas.cpp
index 050ddf76fb..e5bf5a6325 100644
--- a/src/core/SkOverdrawCanvas.cpp
+++ b/src/core/SkOverdrawCanvas.cpp
@@ -81,7 +81,7 @@ void SkOverdrawCanvas::drawPosTextCommon(const void* text, size_t byteLength, co
paint, &props, SkScalerContextFlags::kNone, &this->getTotalMatrix());
SkFindAndPlaceGlyph::ProcessPosText(paint.getTextEncoding(), (const char*) text, byteLength,
SkPoint::Make(0, 0), SkMatrix(), (const SkScalar*) pos, 2,
- paint.getTextAlign(), cache.get(), processBounds);
+ cache.get(), processBounds);
}
void SkOverdrawCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 1086bc4894..8c964ba35e 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -425,7 +425,7 @@ void GrAtlasTextContext::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
auto cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
SkFindAndPlaceGlyph::ProcessPosText(
paint.skPaint().getTextEncoding(), text, byteLength, offset, viewMatrix, pos,
- scalarsPerPosition, paint.skPaint().getTextAlign(), cache.get(),
+ scalarsPerPosition, cache.get(),
[&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
position += rounding;
BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph,
@@ -504,16 +504,13 @@ void GrAtlasTextContext::DrawBmpPosTextAsPaths(GrAtlasTextBlob* blob, int runInd
const char* stop = text + byteLength;
const char* lastText = text;
- SkTextAlignProc alignProc(pathPaint.getTextAlign());
SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
while (text < stop) {
const SkGlyph& glyph = glyphCacheProc(cache.get(), &text);
if (glyph.fWidth) {
- SkPoint tmsLoc;
- tmsProc(pos, &tmsLoc);
SkPoint loc;
- alignProc(tmsLoc, glyph, &loc);
+ tmsProc(pos, &loc);
if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
fallbackTextHelper.appendText(glyph, text - lastText, lastText, loc);
} else {
@@ -729,12 +726,7 @@ void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex,
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
- SkPaint leftAlignedSkPaint(skPaint);
- leftAlignedSkPaint.setTextAlign(SkPaint::kLeft_Align);
-
- GrTextUtils::Paint leftAlignedPaint(&leftAlignedSkPaint, paint.dstColorSpaceInfo());
-
- this->drawDFPosText(blob, runIndex, glyphCache, props, leftAlignedPaint, scalerContextFlags,
+ this->drawDFPosText(blob, runIndex, glyphCache, props, paint, scalerContextFlags,
viewMatrix, text, byteLength, positions.begin(), 2, offset);
}
@@ -777,9 +769,6 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
const char* stop = text + byteLength;
- SkPaint::Align align = dfPaint.getTextAlign();
- SkScalar alignMul = SkPaint::kCenter_Align == align ? SK_ScalarHalf :
- (SkPaint::kRight_Align == align ? SK_Scalar1 : 0);
while (text < stop) {
const char* lastText = text;
// the last 2 parameters are ignored
@@ -787,9 +776,8 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
if (glyph.fWidth) {
SkPoint glyphPos(offset);
- glyphPos.fX += pos[0] - SkFloatToScalar(glyph.fAdvanceX) * alignMul * textRatio;
- glyphPos.fY += (2 == scalarsPerPosition ? pos[1] : 0) -
- SkFloatToScalar(glyph.fAdvanceY) * alignMul * textRatio;
+ glyphPos.fX += pos[0];
+ glyphPos.fY += (2 == scalarsPerPosition ? pos[1] : 0);
if (glyph.fMaskFormat == SkMask::kSDF_Format) {
DfAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, glyphPos.fX,
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index 215951622c..29ee8f3eca 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -2137,8 +2137,7 @@ void SkXPSDevice::drawPosText(const void* text, size_t byteLen,
SkFindAndPlaceGlyph::ProcessPosText(
paint.getTextEncoding(), static_cast<const char*>(text), byteLen,
- offset, SkMatrix::I(), pos, scalarsPerPos, paint.getTextAlign(),
- cache.get(), processOneGlyph);
+ offset, SkMatrix::I(), pos, scalarsPerPos, cache.get(), processOneGlyph);
if (xpsGlyphs.count() == 0) {
return;