DEF_TEST(FontHostStream, reporter) { { SkPaint paint; paint.setColor(SK_ColorGRAY); paint.setTextSize(SkIntToScalar(30)); SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia", SkTypeface::kNormal); SkSafeUnref(paint.setTypeface(fTypeface)); 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.drawText("A", 1, point.fX, point.fY, paint); SkTypeface* origTypeface = paint.getTypeface(); SkAutoTUnref<SkTypeface> aur; if (NULL == origTypeface) { origTypeface = aur.reset(SkTypeface::RefDefault()); } int ttcIndex; SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex)); SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.detach()); SkFontDescriptor desc; bool isLocalStream = false; streamTypeface->getFontDescriptor(&desc, &isLocalStream); REPORTER_ASSERT(reporter, isLocalStream); SkSafeUnref(paint.setTypeface(streamTypeface)); drawBG(&streamCanvas); streamCanvas.drawPosText("A", 1, &point, paint); REPORTER_ASSERT(reporter, compare(origBitmap, origRect, streamBitmap, streamRect)); } //Make sure the typeface is deleted and removed. SkGraphics::PurgeFontCache(); }