OLD | NEW |
---|---|
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 Loading... | |
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 SkTypeface* origTypeface = paint.getTypeface(); |
93 SkAutoTUnref<SkTypeface> aur; | 91 sk_sp<SkTypeface> defaultTypeface; |
94 if (nullptr == origTypeface) { | 92 if (nullptr == origTypeface) { |
95 aur.reset(SkTypeface::RefDefault()); | 93 defaultTypeface = SkTypeface::MakeDefault(); |
96 origTypeface = aur.get(); | 94 origTypeface = defaultTypeface.get(); |
tomhudson
2016/04/29 21:10:36
How about SkTypeface::MakeDefault().get(), and get
bungeman-skia
2016/04/29 22:03:24
Done.
| |
97 } | 95 } |
98 | 96 |
99 int ttcIndex; | 97 int ttcIndex; |
100 SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex )); | 98 SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex )); |
101 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.relea se()); | 99 auto streamTypeface = SkTypeface::MakeFromStream(fontData.release()); |
102 | 100 |
103 SkFontDescriptor desc; | 101 SkFontDescriptor desc; |
104 bool isLocalStream = false; | 102 bool isLocalStream = false; |
105 streamTypeface->getFontDescriptor(&desc, &isLocalStream); | 103 streamTypeface->getFontDescriptor(&desc, &isLocalStream); |
106 REPORTER_ASSERT(reporter, isLocalStream); | 104 REPORTER_ASSERT(reporter, isLocalStream); |
107 | 105 |
108 SkSafeUnref(paint.setTypeface(streamTypeface)); | 106 paint.setTypeface(streamTypeface); |
109 drawBG(&streamCanvas); | 107 drawBG(&streamCanvas); |
110 streamCanvas.drawPosText("A", 1, &point, paint); | 108 streamCanvas.drawPosText("A", 1, &point, paint); |
111 | 109 |
112 REPORTER_ASSERT(reporter, | 110 REPORTER_ASSERT(reporter, |
113 compare(origBitmap, origRect, streamBitmap, streamRect)) ; | 111 compare(origBitmap, origRect, streamBitmap, streamRect)) ; |
114 } | 112 } |
115 //Make sure the typeface is deleted and removed. | 113 //Make sure the typeface is deleted and removed. |
116 SkGraphics::PurgeFontCache(); | 114 SkGraphics::PurgeFontCache(); |
117 } | 115 } |
OLD | NEW |