Chromium Code Reviews| 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 #include "SkTypes.h" | 7 #include "SkTypes.h" |
| 8 | 8 |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 create(&streamBitmap, streamRect, SkBitmap::kARGB_8888_Config); | 84 create(&streamBitmap, streamRect, SkBitmap::kARGB_8888_Config); |
| 85 SkCanvas streamCanvas(streamBitmap); | 85 SkCanvas streamCanvas(streamBitmap); |
| 86 | 86 |
| 87 SkPoint point = SkPoint::Make(24, 32); | 87 SkPoint point = SkPoint::Make(24, 32); |
| 88 | 88 |
| 89 // Test: origTypeface and streamTypeface from orig data draw the same | 89 // Test: origTypeface and streamTypeface from orig data draw the same |
| 90 drawBG(&origCanvas); | 90 drawBG(&origCanvas); |
| 91 origCanvas.drawText("A", 1, point.fX, point.fY, paint); | 91 origCanvas.drawText("A", 1, point.fX, point.fY, paint); |
| 92 | 92 |
| 93 SkTypeface* origTypeface = paint.getTypeface(); | 93 SkTypeface* origTypeface = paint.getTypeface(); |
| 94 const SkFontID typefaceID = SkTypeface::UniqueID(origTypeface); | 94 SkAutoTUnref<SkTypeface> aur; |
| 95 SkStream* fontData = SkFontHost::OpenStream(typefaceID); | 95 if (NULL == origTypeface) { |
| 96 origTypeface = aur.reset(SkTypeface::RefDefault()); | |
|
bungeman-skia
2013/03/14 03:47:34
I see that you checked in https://code.google.com/
reed1
2013/03/14 14:22:42
I'm not sure which pattern I like better yet, so I
| |
| 97 } | |
| 98 | |
| 99 int ttcIndex; | |
| 100 SkStream* fontData = origTypeface->openStream(&ttcIndex); | |
| 96 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData); | 101 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData); |
| 97 SkSafeUnref(paint.setTypeface(streamTypeface)); | 102 SkSafeUnref(paint.setTypeface(streamTypeface)); |
| 98 drawBG(&streamCanvas); | 103 drawBG(&streamCanvas); |
| 99 streamCanvas.drawPosText("A", 1, &point, paint); | 104 streamCanvas.drawPosText("A", 1, &point, paint); |
| 100 | 105 |
| 101 REPORTER_ASSERT(reporter, | 106 REPORTER_ASSERT(reporter, |
| 102 compare(origBitmap, origRect, streamBitmap, streamRect)) ; | 107 compare(origBitmap, origRect, streamBitmap, streamRect)) ; |
| 103 } | 108 } |
| 104 //Make sure the typeface is deleted and removed. | 109 //Make sure the typeface is deleted and removed. |
| 105 SkGraphics::PurgeFontCache(); | 110 SkGraphics::PurgeFontCache(); |
| 106 } | 111 } |
| 107 | 112 |
| 108 #include "TestClassDef.h" | 113 #include "TestClassDef.h" |
| 109 DEFINE_TESTCLASS("FontHost::CreateTypefaceFromStream", FontHostStreamTestClass, test_fontHostStream) | 114 DEFINE_TESTCLASS("FontHost::CreateTypefaceFromStream", FontHostStreamTestClass, test_fontHostStream) |
| OLD | NEW |