Fix scaling issue when drawing text on a path.
If the paint is stroked and the font size is small
we were incorrectly rendering the sample text.
Review URL: https://codereview.appspot.com/5844060
git-svn-id: http://skia.googlecode.com/svn/trunk@3437 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index 8c659c2..0ec37b3 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -128,8 +128,8 @@
class SkTextToPathIter {
public:
- SkTextToPathIter(const char text[], size_t length, const SkPaint&,
- bool applyStrokeAndPathEffects, bool forceLinearTextOn);
+ SkTextToPathIter(const char text[], size_t length, const SkPaint& paint,
+ bool applyStrokeAndPathEffects);
~SkTextToPathIter();
const SkPaint& getPaint() const { return fPaint; }
diff --git a/samplecode/SampleTextOnPath.cpp b/samplecode/SampleTextOnPath.cpp
index 2899e7c..91100a6 100644
--- a/samplecode/SampleTextOnPath.cpp
+++ b/samplecode/SampleTextOnPath.cpp
@@ -28,8 +28,8 @@
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFFFF0000);
- paint.setTextSize(SkFloatToScalar(0.065f));
- paint.setStrokeWidth(SkFloatToScalar(.01f));
+ paint.setTextSize(SkFloatToScalar(0.085f));
+ paint.setStrokeWidth(SkFloatToScalar(.005f));
canvas->drawPath(path, paint);
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 23a6d59..7c3b060 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1308,7 +1308,7 @@
const SkPaint& paint) const {
SkDEBUGCODE(this->validate();)
- SkTextToPathIter iter(text, byteLength, paint, true, true);
+ SkTextToPathIter iter(text, byteLength, paint, true);
SkMatrix matrix;
matrix.setScale(iter.getPathScale(), iter.getPathScale());
@@ -1955,7 +1955,7 @@
return;
}
- SkTextToPathIter iter(text, byteLength, paint, true, true);
+ SkTextToPathIter iter(text, byteLength, paint, true);
SkPathMeasure meas(follow, false);
SkScalar hOffset = 0;
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 68d7561..6a16e24 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1337,7 +1337,7 @@
return;
}
- SkTextToPathIter iter(text, length, *this, false, true);
+ SkTextToPathIter iter(text, length, *this, false);
SkMatrix matrix;
SkScalar prevXPos = 0;
@@ -2087,24 +2087,25 @@
SkTextToPathIter::SkTextToPathIter( const char text[], size_t length,
const SkPaint& paint,
- bool applyStrokeAndPathEffects,
- bool forceLinearTextOn) : fPaint(paint) {
+ bool applyStrokeAndPathEffects)
+ : fPaint(paint) {
fGlyphCacheProc = paint.getMeasureCacheProc(SkPaint::kForward_TextBufferDirection,
true);
- if (forceLinearTextOn) {
- fPaint.setLinearText(true);
- }
+ fPaint.setLinearText(true);
fPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup
if (fPaint.getPathEffect() == NULL && !has_thick_frame(fPaint)) {
applyStrokeAndPathEffects = false;
}
- // can't use our canonical size if we need to apply patheffects/strokes
- if (fPaint.isLinearText() && !applyStrokeAndPathEffects) {
+ // can't use our canonical size if we need to apply patheffects
+ if (fPaint.getPathEffect() == NULL) {
fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths));
fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths;
+ if (has_thick_frame(fPaint)) {
+ fPaint.setStrokeWidth(SkScalarDiv(fPaint.getStrokeWidth(), fScale));
+ }
} else {
fScale = SK_Scalar1;
}