SkISize onISize() { return skiagm::make_isize(480, 780); }
+ static void strokePath(SkCanvas* canvas, const SkPath& path) {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(SK_ColorRED);
+ paint.setStyle(SkPaint::kStroke_Style);
+ canvas->drawPath(path, paint);
+ }
+
virtual void onDraw(SkCanvas* canvas) {
- const char* text = "Hamburgefons";
+ // explicitly add spaces, to test a prev. bug
+ const char* text = "Ham bur ge fons";
size_t len = strlen(text);
+ SkPath path;
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(48));
+
+ canvas->translate(SkIntToScalar(10), SkIntToScalar(64));
+
+ canvas->drawText(text, len, 0, 0, paint);
+ paint.getTextPath(text, len, 0, 0, &path);
+ strokePath(canvas, path);
+ path.reset();
SkAutoTArray<SkPoint> pos(len);
SkAutoTArray<SkScalar> widths(len);
x += widths[i];
}
- canvas->drawPosText(text, len, &pos[0], paint);
+ canvas->translate(0, SkIntToScalar(64));
- SkPath path;
- paint.setColor(SK_ColorRED);
- paint.setStyle(SkPaint::kStroke_Style);
+ canvas->drawPosText(text, len, &pos[0], paint);
paint.getPosTextPath(text, len, &pos[0], &path);
- canvas->drawPath(path, paint);
+ strokePath(canvas, path);
}
};
//////////////////////////////////////////////////////////////////////////////
static skiagm::GM* F(void*) { return new GetPosTextPathGM; }
-
static skiagm::GMRegistry gR(F);
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;
}
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);
+ }
}
}
}
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;
}
}
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++;
}
fText = text;
fStop = text + length;
-
+
fXYIndex = paint.isVerticalText() ? 1 : 0;
}
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;
}
///////////////////////////////////////////////////////////////////////////////
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;