aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 15:53:00 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 15:53:00 +0000
commit7b4531f64cbd85d32a77ceab1bdec8335c5a7864 (patch)
tree0f1321ec42ca779f3b49944c13ef0ace46239e58 /src/core
parent46f935002c2b25331e552520dc7b1a912e12dfdc (diff)
change SkTextToPathIter to allow continuation even when there is no path for
the current glyph. Fixes bug in getTextPath() if there are spaces in the text. Update gm to add space-characters, so images will have to be rebaselined. git-svn-id: http://skia.googlecode.com/svn/trunk@4979 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkDraw.cpp40
-rw-r--r--src/core/SkPaint.cpp33
-rw-r--r--src/core/SkTextToPathIter.h10
3 files changed, 53 insertions, 30 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 83cec4bc2e..9e8e9ef59c 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1321,13 +1321,15 @@ void SkDraw::drawText_asPaths(const char text[], size_t byteLength,
const SkPath* iterPath;
SkScalar xpos, prevXPos = 0;
- while ((iterPath = iter.next(&xpos)) != NULL) {
+ while (iter.next(&iterPath, &xpos)) {
matrix.postTranslate(xpos - prevXPos, 0);
- const SkPaint& pnt = iter.getPaint();
- if (fDevice) {
- fDevice->drawPath(*this, *iterPath, pnt, &matrix, false);
- } else {
- this->drawPath(*iterPath, pnt, &matrix, false);
+ if (iterPath) {
+ const SkPaint& pnt = iter.getPaint();
+ if (fDevice) {
+ fDevice->drawPath(*this, *iterPath, pnt, &matrix, false);
+ } else {
+ this->drawPath(*iterPath, pnt, &matrix, false);
+ }
}
prevXPos = xpos;
}
@@ -1999,19 +2001,21 @@ void SkDraw::drawTextOnPath(const char text[], size_t byteLength,
scaledMatrix.setScale(scale, scale);
- while ((iterPath = iter.next(&xpos)) != NULL) {
- SkPath tmp;
- SkMatrix m(scaledMatrix);
+ while (iter.next(&iterPath, &xpos)) {
+ if (iterPath) {
+ SkPath tmp;
+ SkMatrix m(scaledMatrix);
- 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);
+ 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);
+ }
}
}
}
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 5fd42881e4..ae5d0b2561 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1353,9 +1353,11 @@ void SkPaint::getTextPath(const void* textData, size_t length,
SkScalar xpos;
const SkPath* iterPath;
- while ((iterPath = iter.next(&xpos)) != NULL) {
+ while (iter.next(&iterPath, &xpos)) {
matrix.postTranslate(xpos - prevXPos, 0);
- path->addPath(*iterPath, matrix);
+ if (iterPath) {
+ path->addPath(*iterPath, matrix);
+ }
prevXPos = xpos;
}
}
@@ -1379,9 +1381,11 @@ void SkPaint::getPosTextPath(const void* textData, size_t length,
unsigned int i = 0;
const SkPath* iterPath;
- while ((iterPath = iter.next(NULL)) != NULL) {
+ while (iter.next(&iterPath, NULL)) {
matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY);
- path->addPath(*iterPath, matrix);
+ if (iterPath) {
+ path->addPath(*iterPath, matrix);
+ }
prevPos = pos[i];
i++;
}
@@ -2202,7 +2206,7 @@ SkTextToPathIter::SkTextToPathIter( const char text[], size_t length,
fText = text;
fStop = text + length;
-
+
fXYIndex = paint.isVerticalText() ? 1 : 0;
}
@@ -2210,21 +2214,28 @@ SkTextToPathIter::~SkTextToPathIter() {
SkGlyphCache::AttachCache(fCache);
}
-const SkPath* SkTextToPathIter::next(SkScalar* xpos) {
- while (fText < fStop) {
+bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
+ if (fText < fStop) {
const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(glyph)), fScale);
fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
if (glyph.fWidth) {
- if (xpos) {
- *xpos = fXPos;
+ if (path) {
+ *path = fCache->findPath(glyph);
+ }
+ } else {
+ if (path) {
+ *path = NULL;
}
- return fCache->findPath(glyph);
}
+ if (xpos) {
+ *xpos = fXPos;
+ }
+ return true;
}
- return NULL;
+ return false;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkTextToPathIter.h b/src/core/SkTextToPathIter.h
index 0d8c4b25a3..73f27ed039 100644
--- a/src/core/SkTextToPathIter.h
+++ b/src/core/SkTextToPathIter.h
@@ -22,7 +22,15 @@ public:
const SkPaint& getPaint() const { return fPaint; }
SkScalar getPathScale() const { return fScale; }
- const SkPath* next(SkScalar* xpos); //!< returns nil when there are no more paths
+ struct Rec {
+ const SkPath* fPath; // may be null for "whitespace" glyphs
+ SkScalar fXPos;
+ };
+
+ /**
+ * Returns false when all of the text has been consumed
+ */
+ bool next(const SkPath** path, SkScalar* xpos);
private:
SkGlyphCache* fCache;