add drawString helper to canvas
Many tests and examples use drawText with
a guess of how long the text is in bytes,
or a call to strlen(). Add a helper to
SkCanvas to simplify these examples.
Add another helper for SkString.
R=reed@google.com
Change-Id: I0204a31e938f065606f08ee7cd9a6b36db791ee2
Reviewed-on: https://skia-review.googlesource.com/13642
Commit-Queue: Cary Clark <caryclark@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Cary Clark <caryclark@skia.org>
diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp
index 875db26..6f6541b 100644
--- a/samplecode/SampleAAGeometry.cpp
+++ b/samplecode/SampleAAGeometry.cpp
@@ -606,8 +606,8 @@
canvas->drawLine(fBounds.fLeft - 5, fYLo, fBounds.fRight + 5, fYLo, paints.fIndicator);
SkString label;
label.printf("%0.3g", fValLo);
- canvas->drawText(label.c_str(), label.size(), fBounds.fLeft + 5, fYLo - 5, paints.fValue);
- canvas->drawText(fName.c_str(), fName.size(), fBounds.fLeft, fBounds.bottom() + 11,
+ canvas->drawString(label, fBounds.fLeft + 5, fYLo - 5, paints.fValue);
+ canvas->drawString(fName, fBounds.fLeft, fBounds.bottom() + 11,
paints.fLabel);
}
};
@@ -634,7 +634,7 @@
if (yPos < fYLo + 10) {
yPos = fYLo + 10;
}
- canvas->drawText(label.c_str(), label.size(), fBounds.fLeft + 5, yPos - 5, paints.fValue);
+ canvas->drawString(label, fBounds.fLeft + 5, yPos - 5, paints.fValue);
SkRect fill = { fBounds.fLeft, fYLo, fBounds.fRight, yPos };
canvas->drawRect(fill, paints.fFill);
}
@@ -1819,11 +1819,11 @@
SkScalar bottomOffset = this->height() - 10;
for (int index = kKeyCommandCount - 1; index >= 0; --index) {
bottomOffset -= 15;
- canvas->drawText(kKeyCommandList[index].fDescriptionL,
- strlen(kKeyCommandList[index].fDescriptionL), this->width() - 160, bottomOffset,
+ canvas->drawString(kKeyCommandList[index].fDescriptionL,
+ this->width() - 160, bottomOffset,
fLegendLeftPaint);
- canvas->drawText(kKeyCommandList[index].fDescriptionR,
- strlen(kKeyCommandList[index].fDescriptionR), this->width() - 20, bottomOffset,
+ canvas->drawString(kKeyCommandList[index].fDescriptionR,
+ this->width() - 20, bottomOffset,
fLegendRightPaint);
}
}