Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: tests/FontHostStreamTest.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | tests/FontHostTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 return true; 63 return true;
64 } 64 }
65 65
66 DEF_TEST(FontHostStream, reporter) { 66 DEF_TEST(FontHostStream, reporter) {
67 { 67 {
68 SkPaint paint; 68 SkPaint paint;
69 paint.setColor(SK_ColorGRAY); 69 paint.setColor(SK_ColorGRAY);
70 paint.setTextSize(SkIntToScalar(30)); 70 paint.setTextSize(SkIntToScalar(30));
71 71
72 SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia", 72 paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kNorma l));
73 SkTypeface::kNormal);
74 SkSafeUnref(paint.setTypeface(fTypeface));
75 73
76 SkIRect origRect = SkIRect::MakeWH(64, 64); 74 SkIRect origRect = SkIRect::MakeWH(64, 64);
77 SkBitmap origBitmap; 75 SkBitmap origBitmap;
78 create(&origBitmap, origRect); 76 create(&origBitmap, origRect);
79 SkCanvas origCanvas(origBitmap); 77 SkCanvas origCanvas(origBitmap);
80 78
81 SkIRect streamRect = SkIRect::MakeWH(64, 64); 79 SkIRect streamRect = SkIRect::MakeWH(64, 64);
82 SkBitmap streamBitmap; 80 SkBitmap streamBitmap;
83 create(&streamBitmap, streamRect); 81 create(&streamBitmap, streamRect);
84 SkCanvas streamCanvas(streamBitmap); 82 SkCanvas streamCanvas(streamBitmap);
85 83
86 SkPoint point = SkPoint::Make(24, 32); 84 SkPoint point = SkPoint::Make(24, 32);
87 85
88 // Test: origTypeface and streamTypeface from orig data draw the same 86 // Test: origTypeface and streamTypeface from orig data draw the same
89 drawBG(&origCanvas); 87 drawBG(&origCanvas);
90 origCanvas.drawText("A", 1, point.fX, point.fY, paint); 88 origCanvas.drawText("A", 1, point.fX, point.fY, paint);
91 89
92 SkTypeface* origTypeface = paint.getTypeface(); 90 sk_sp<SkTypeface> typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(pai nt.getTypeface())
93 SkAutoTUnref<SkTypeface> aur; 91 : SkTypeface::M akeDefault());
94 if (nullptr == origTypeface) {
95 aur.reset(SkTypeface::RefDefault());
96 origTypeface = aur.get();
97 }
98
99 int ttcIndex; 92 int ttcIndex;
100 SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex )); 93 SkAutoTDelete<SkStreamAsset> fontData(typeface->openStream(&ttcIndex));
101 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.relea se()); 94 sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(fontData.rel ease()));
102 95
103 SkFontDescriptor desc; 96 SkFontDescriptor desc;
104 bool isLocalStream = false; 97 bool isLocalStream = false;
105 streamTypeface->getFontDescriptor(&desc, &isLocalStream); 98 streamTypeface->getFontDescriptor(&desc, &isLocalStream);
106 REPORTER_ASSERT(reporter, isLocalStream); 99 REPORTER_ASSERT(reporter, isLocalStream);
107 100
108 SkSafeUnref(paint.setTypeface(streamTypeface)); 101 paint.setTypeface(streamTypeface);
109 drawBG(&streamCanvas); 102 drawBG(&streamCanvas);
110 streamCanvas.drawPosText("A", 1, &point, paint); 103 streamCanvas.drawPosText("A", 1, &point, paint);
111 104
112 REPORTER_ASSERT(reporter, 105 REPORTER_ASSERT(reporter,
113 compare(origBitmap, origRect, streamBitmap, streamRect)) ; 106 compare(origBitmap, origRect, streamBitmap, streamRect)) ;
114 } 107 }
115 //Make sure the typeface is deleted and removed. 108 //Make sure the typeface is deleted and removed.
116 SkGraphics::PurgeFontCache(); 109 SkGraphics::PurgeFontCache();
117 } 110 }
OLDNEW
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | tests/FontHostTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698