Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Unified Diff: src/core/SkDraw.cpp

Issue 925343003: use common impl for drawTextOnPath (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move includes to the top Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkDraw.cpp
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 03b331108dc27226d5c761e303f4ba3bcc7d89ce..f40c1bbcb0ea94f3a402b7f51e2a98a07bf3d36e 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1866,135 +1866,6 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
///////////////////////////////////////////////////////////////////////////////
-#include "SkPathMeasure.h"
-
-static void morphpoints(SkPoint dst[], const SkPoint src[], int count,
- SkPathMeasure& meas, const SkMatrix& matrix) {
- SkMatrix::MapXYProc proc = matrix.getMapXYProc();
-
- for (int i = 0; i < count; i++) {
- SkPoint pos;
- SkVector tangent;
-
- proc(matrix, src[i].fX, src[i].fY, &pos);
- SkScalar sx = pos.fX;
- SkScalar sy = pos.fY;
-
- if (!meas.getPosTan(sx, &pos, &tangent)) {
- // set to 0 if the measure failed, so that we just set dst == pos
- tangent.set(0, 0);
- }
-
- /* This is the old way (that explains our approach but is way too slow
- SkMatrix matrix;
- SkPoint pt;
-
- pt.set(sx, sy);
- matrix.setSinCos(tangent.fY, tangent.fX);
- matrix.preTranslate(-sx, 0);
- matrix.postTranslate(pos.fX, pos.fY);
- matrix.mapPoints(&dst[i], &pt, 1);
- */
- dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy),
- pos.fY + SkScalarMul(tangent.fX, sy));
- }
-}
-
-/* TODO
-
- Need differentially more subdivisions when the follow-path is curvy. Not sure how to
- determine that, but we need it. I guess a cheap answer is let the caller tell us,
- but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out.
-*/
-static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas,
- const SkMatrix& matrix) {
- SkPath::Iter iter(src, false);
- SkPoint srcP[4], dstP[3];
- SkPath::Verb verb;
-
- while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) {
- switch (verb) {
- case SkPath::kMove_Verb:
- morphpoints(dstP, srcP, 1, meas, matrix);
- dst->moveTo(dstP[0]);
- break;
- case SkPath::kLine_Verb:
- // turn lines into quads to look bendy
- srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX);
- srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY);
- morphpoints(dstP, srcP, 2, meas, matrix);
- dst->quadTo(dstP[0], dstP[1]);
- break;
- case SkPath::kQuad_Verb:
- morphpoints(dstP, &srcP[1], 2, meas, matrix);
- dst->quadTo(dstP[0], dstP[1]);
- break;
- case SkPath::kCubic_Verb:
- morphpoints(dstP, &srcP[1], 3, meas, matrix);
- dst->cubicTo(dstP[0], dstP[1], dstP[2]);
- break;
- case SkPath::kClose_Verb:
- dst->close();
- break;
- default:
- SkDEBUGFAIL("unknown verb");
- break;
- }
- }
-}
-
-void SkDraw::drawTextOnPath(const char text[], size_t byteLength,
- const SkPath& follow, const SkMatrix* matrix,
- const SkPaint& paint) const {
- SkASSERT(byteLength == 0 || text != NULL);
-
- // nothing to draw
- if (text == NULL || byteLength == 0 || fRC->isEmpty()) {
- return;
- }
-
- SkTextToPathIter iter(text, byteLength, paint, true);
- SkPathMeasure meas(follow, false);
- SkScalar hOffset = 0;
-
- // need to measure first
- if (paint.getTextAlign() != SkPaint::kLeft_Align) {
- SkScalar pathLen = meas.getLength();
- if (paint.getTextAlign() == SkPaint::kCenter_Align) {
- pathLen = SkScalarHalf(pathLen);
- }
- hOffset += pathLen;
- }
-
- const SkPath* iterPath;
- SkScalar xpos;
- SkMatrix scaledMatrix;
- SkScalar scale = iter.getPathScale();
-
- scaledMatrix.setScale(scale, scale);
-
- while (iter.next(&iterPath, &xpos)) {
- if (iterPath) {
- SkPath tmp;
- SkMatrix m(scaledMatrix);
-
- tmp.setIsVolatile(true);
- m.postTranslate(xpos + hOffset, 0);
- if (matrix) {
- m.postConcat(*matrix);
- }
- morphpath(&tmp, *iterPath, meas, m);
- if (fDevice) {
- fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true);
- } else {
- this->drawPath(tmp, iter.getPaint(), NULL, true);
- }
- }
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&,
SkBlitter*);
« src/core/SkDevice.cpp ('K') | « src/core/SkDevice.cpp ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698