revert changes to FontHostStreamTest
NoTry: true
Change-Id: Ida87530c1be26498508db25b6db3209612ace01a
Reviewed-on: https://skia-review.googlesource.com/c/182453
Reviewed-by: Hal Canary <[email protected]>
Commit-Queue: Hal Canary <[email protected]>
diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp
index c6cbbcf..343a68c 100644
--- a/tests/FontHostStreamTest.cpp
+++ b/tests/FontHostStreamTest.cpp
@@ -20,14 +20,41 @@
#include "SkTypes.h"
#include "Test.h"
-/** Checks that all is the same. */
-static bool compare(const SkBitmap& ref, const SkBitmap& test) {
- if (ref.dimensions() != test.dimensions()) {
- return false;
- }
+static const SkColor bgColor = SK_ColorWHITE;
+
+static void create(SkBitmap* bm, SkIRect bound) {
+ bm->allocN32Pixels(bound.width(), bound.height());
+}
+
+static void drawBG(SkCanvas* canvas) {
+ canvas->drawColor(bgColor);
+}
+
+/** Assumes that the ref draw was completely inside ref canvas --
+ implies that everything outside is "bgColor".
+ Checks that all overlap is the same and that all non-overlap on the
+ ref is "bgColor".
+ */
+static bool compare(const SkBitmap& ref, const SkIRect& iref,
+ const SkBitmap& test, const SkIRect& itest)
+{
+ const int xOff = itest.fLeft - iref.fLeft;
+ const int yOff = itest.fTop - iref.fTop;
+
for (int y = 0; y < test.height(); ++y) {
for (int x = 0; x < test.width(); ++x) {
- if (test.getColor(x, y) != ref.getColor(x, y)) {
+ SkColor testColor = test.getColor(x, y);
+ int refX = x + xOff;
+ int refY = y + yOff;
+ SkColor refColor;
+ if (refX >= 0 && refX < ref.width() &&
+ refY >= 0 && refY < ref.height())
+ {
+ refColor = ref.getColor(refX, refY);
+ } else {
+ refColor = bgColor;
+ }
+ if (refColor != testColor) {
return false;
}
}
@@ -35,47 +62,52 @@
return true;
}
-static void draw(SkBitmap* bitmap, const SkFont& font) {
- SkPaint paint;
- paint.setColor(SK_ColorGRAY);
- SkASSERT(bitmap);
- bitmap->allocN32Pixels(64, 64);
- SkCanvas canvas(*bitmap);
- canvas.drawColor(SK_ColorWHITE);
- canvas.drawString("A", 24, 32, font, paint);
-}
-
DEF_TEST(FontHostStream, reporter) {
- sk_sp<SkTypeface> typeface = SkTypeface::MakeFromName("Georgia", SkFontStyle());
- if (!typeface) {
- typeface = SkTypeface::MakeDefault();
+ {
+ SkPaint paint;
+ paint.setColor(SK_ColorGRAY);
+
+ SkFont font(SkTypeface::MakeFromName("Georgia", SkFontStyle()), 30);
+
+ SkIRect origRect = SkIRect::MakeWH(64, 64);
+ SkBitmap origBitmap;
+ create(&origBitmap, origRect);
+ SkCanvas origCanvas(origBitmap);
+
+ SkIRect streamRect = SkIRect::MakeWH(64, 64);
+ SkBitmap streamBitmap;
+ create(&streamBitmap, streamRect);
+ SkCanvas streamCanvas(streamBitmap);
+
+ SkPoint point = SkPoint::Make(24, 32);
+
+ // Test: origTypeface and streamTypeface from orig data draw the same
+ drawBG(&origCanvas);
+ origCanvas.drawSimpleText("A", 1, kUTF8_SkTextEncoding, point.fX, point.fY, font, paint);
+
+ sk_sp<SkTypeface> typeface = SkPaintPriv::RefTypefaceOrDefault(paint);
+ int ttcIndex;
+ std::unique_ptr<SkStreamAsset> fontData(typeface->openStream(&ttcIndex));
+ if (!fontData) {
+ // We're using a SkTypeface that can't give us a stream.
+ // This happens with portable or system fonts. End the test now.
+ return;
+ }
+
+ sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(std::move(fontData)));
+
+ SkFontDescriptor desc;
+ bool isLocalStream = false;
+ streamTypeface->getFontDescriptor(&desc, &isLocalStream);
+ REPORTER_ASSERT(reporter, isLocalStream);
+
+ paint.setTypeface(streamTypeface);
+ drawBG(&streamCanvas);
+ streamCanvas.drawSimpleText("A", 1, kUTF8_SkTextEncoding, point.fX, point.fY, font, paint);
+
+ REPORTER_ASSERT(reporter,
+ compare(origBitmap, origRect, streamBitmap, streamRect));
}
- SkFont font(typeface, 30);
- SkBitmap origBitmap, streamBitmap;
-
- // Test: origTypeface and streamTypeface from orig data draw the same
- draw(&origBitmap, font);
-
- int ttcIndex;
- std::unique_ptr<SkStreamAsset> fontData(typeface->openStream(&ttcIndex));
- if (!fontData) {
- // We're using a SkTypeface that can't give us a stream.
- // This happens with portable or system fonts. End the test now.
- return;
- }
-
- sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(std::move(fontData)));
-
- SkFontDescriptor desc;
- bool isLocalStream = false;
- streamTypeface->getFontDescriptor(&desc, &isLocalStream);
- REPORTER_ASSERT(reporter, isLocalStream);
-
- SkFont streamFont(streamTypeface);
- draw(&streamBitmap, streamFont);
-
- REPORTER_ASSERT(reporter, compare(origBitmap, streamBitmap));
-
//Make sure the typeface is deleted and removed.
SkGraphics::PurgeFontCache();
}