diff options
author | 2017-04-28 15:35:12 -0400 | |
---|---|---|
committer | 2017-04-28 20:41:04 +0000 | |
commit | 2a475eae622adc1e8fa29206be1eaf862c23548e (patch) | |
tree | 6bad5dbe2ef7aad1c7e657df6bd8cfe3a752c5fd /tests | |
parent | ec138b40ba940ab0d76b5550ee2c5505629c5293 (diff) |
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/DrawTextTest.cpp | 8 | ||||
-rw-r--r-- | tests/FlattenDrawableTest.cpp | 2 | ||||
-rw-r--r-- | tests/FontHostStreamTest.cpp | 2 | ||||
-rw-r--r-- | tests/ImageFilterTest.cpp | 4 | ||||
-rw-r--r-- | tests/PDFDocumentTest.cpp | 2 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 2 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 2 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 2 |
8 files changed, 12 insertions, 12 deletions
diff --git a/tests/DrawTextTest.cpp b/tests/DrawTextTest.cpp index a98b36f321..2f8fe056eb 100644 --- a/tests/DrawTextTest.cpp +++ b/tests/DrawTextTest.cpp @@ -120,11 +120,11 @@ DEF_TEST(DrawText_weirdCoordinates, r) { SkScalar oddballs[] = { 0.0f, (float)INFINITY, (float)NAN, 34359738368.0f }; for (auto x : oddballs) { - canvas->drawText("a", 1, +x, 0.0f, SkPaint()); - canvas->drawText("a", 1, -x, 0.0f, SkPaint()); + canvas->drawString("a", +x, 0.0f, SkPaint()); + canvas->drawString("a", -x, 0.0f, SkPaint()); } for (auto y : oddballs) { - canvas->drawText("a", 1, 0.0f, +y, SkPaint()); - canvas->drawText("a", 1, 0.0f, -y, SkPaint()); + canvas->drawString("a", 0.0f, +y, SkPaint()); + canvas->drawString("a", 0.0f, -y, SkPaint()); } } diff --git a/tests/FlattenDrawableTest.cpp b/tests/FlattenDrawableTest.cpp index d8f5142867..9df8ba0b5b 100644 --- a/tests/FlattenDrawableTest.cpp +++ b/tests/FlattenDrawableTest.cpp @@ -257,7 +257,7 @@ DEF_TEST(FlattenRecordedDrawable, r) { canvas->drawPaint(paint); SkPaint textPaint; textPaint.setColor(SK_ColorBLUE); - canvas->drawText("TEXT", 4, 467.0f, 100.0f, textPaint); + canvas->drawString("TEXT", 467.0f, 100.0f, textPaint); // Draw some drawables as well sk_sp<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp index 2bb439b791..c3bc878da8 100644 --- a/tests/FontHostStreamTest.cpp +++ b/tests/FontHostStreamTest.cpp @@ -82,7 +82,7 @@ DEF_TEST(FontHostStream, reporter) { // Test: origTypeface and streamTypeface from orig data draw the same drawBG(&origCanvas); - origCanvas.drawText("A", 1, point.fX, point.fY, paint); + origCanvas.drawString("A", point.fX, point.fY, paint); sk_sp<SkTypeface> typeface(paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault()); diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 8a19a226c6..d884644893 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -738,14 +738,14 @@ DEF_TEST(ImageFilterDrawTiled, reporter) { SkScalar ypos = SkIntToScalar(height); untiledCanvas.save(); untiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); - untiledCanvas.drawText(text, strlen(text), 0, ypos, paint); + untiledCanvas.drawString(text, 0, ypos, paint); untiledCanvas.restore(); for (int y = 0; y < height; y += tileSize) { for (int x = 0; x < width; x += tileSize) { tiledCanvas.save(); tiledCanvas.clipRect(SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize))); tiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); - tiledCanvas.drawText(text, strlen(text), 0, ypos, paint); + tiledCanvas.drawString(text, 0, ypos, paint); tiledCanvas.restore(); } } diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp index b3200156c6..f01d0f97f3 100644 --- a/tests/PDFDocumentTest.cpp +++ b/tests/PDFDocumentTest.cpp @@ -161,7 +161,7 @@ DEF_TEST(SkPDF_document_skbug_4734, r) { canvas->translate(20.0f, 10.0f); canvas->rotate(30.0f); const char text[] = "HELLO"; - canvas->drawText(text, strlen(text), 0, 0, SkPaint()); + canvas->drawString(text, 0, 0, SkPaint()); } static bool contains(const uint8_t* result, size_t size, const char expectation[]) { diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index fd4bf4ef78..0dc3bfe7b6 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -850,7 +850,7 @@ static void test_typeface(skiatest::Reporter* reporter) { SkPaint paint; paint.setTypeface(SkTypeface::MakeFromName("Arial", SkFontStyle::FromOldStyle(SkTypeface::kItalic))); - canvas->drawText("Q", 1, 0, 10, paint); + canvas->drawString("Q", 0, 10, paint); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); SkDynamicMemoryWStream stream; picture->serialize(&stream); diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 10aec539fa..bb49df0528 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -438,7 +438,7 @@ static void draw_something(SkCanvas* canvas) { canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/3), paint); paint.setColor(SK_ColorBLACK); paint.setTextSize(SkIntToScalar(kBitmapSize/3)); - canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); + canvas->drawString("Picture", SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); } DEF_TEST(Serialization, reporter) { diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 58ced7ebc0..aa351edf56 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -332,7 +332,7 @@ static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr)) EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr)) - EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testPaint)) + EXPECT_COPY_ON_WRITE(drawString(testText, 0, 1, testPaint)) EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoints2, \ testPaint)) EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testPath, nullptr, \ |