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" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkColor.h" | 12 #include "SkColor.h" |
| 13 #include "SkFontHost.h" | 13 #include "SkFontHost.h" |
| 14 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
| 15 #include "SkPaint.h" | 15 #include "SkPaint.h" |
| 16 #include "SkPoint.h" | 16 #include "SkPoint.h" |
| 17 #include "SkRect.h" | 17 #include "SkRect.h" |
| 18 #include "SkStream.h" | |
| 18 #include "SkTypeface.h" | 19 #include "SkTypeface.h" |
| 19 | 20 |
| 20 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 21 | 22 |
| 22 static const SkColor bgColor = SK_ColorWHITE; | 23 static const SkColor bgColor = SK_ColorWHITE; |
| 23 | 24 |
| 24 static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) { | 25 static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) { |
| 25 bm->setConfig(config, bound.width(), bound.height()); | 26 bm->setConfig(config, bound.width(), bound.height()); |
| 26 bm->allocPixels(); | 27 bm->allocPixels(); |
| 27 } | 28 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 // Test: origTypeface and streamTypeface from orig data draw the same | 92 // Test: origTypeface and streamTypeface from orig data draw the same |
| 92 drawBG(&origCanvas); | 93 drawBG(&origCanvas); |
| 93 origCanvas.drawText("A", 1, point.fX, point.fY, paint); | 94 origCanvas.drawText("A", 1, point.fX, point.fY, paint); |
| 94 | 95 |
| 95 SkTypeface* origTypeface = paint.getTypeface(); | 96 SkTypeface* origTypeface = paint.getTypeface(); |
| 96 SkAutoTUnref<SkTypeface> aur; | 97 SkAutoTUnref<SkTypeface> aur; |
| 97 if (NULL == origTypeface) { | 98 if (NULL == origTypeface) { |
| 98 origTypeface = aur.reset(SkTypeface::RefDefault()); | 99 origTypeface = aur.reset(SkTypeface::RefDefault()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 int ttcIndex; | 102 int ttcIndex; |
|
robertphillips
2013/11/14 14:21:41
This addresses:
80 (32 direct, 48 indirect) bytes
| |
| 102 SkStream* fontData = origTypeface->openStream(&ttcIndex); | 103 SkAutoTUnref<SkStream> fontData(origTypeface->openStream(&ttcIndex)); |
| 103 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData); | 104 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData); |
| 104 SkSafeUnref(paint.setTypeface(streamTypeface)); | 105 SkSafeUnref(paint.setTypeface(streamTypeface)); |
| 105 drawBG(&streamCanvas); | 106 drawBG(&streamCanvas); |
| 106 streamCanvas.drawPosText("A", 1, &point, paint); | 107 streamCanvas.drawPosText("A", 1, &point, paint); |
| 107 | 108 |
| 108 REPORTER_ASSERT(reporter, | 109 REPORTER_ASSERT(reporter, |
| 109 compare(origBitmap, origRect, streamBitmap, streamRect)) ; | 110 compare(origBitmap, origRect, streamBitmap, streamRect)) ; |
| 110 } | 111 } |
| 111 //Make sure the typeface is deleted and removed. | 112 //Make sure the typeface is deleted and removed. |
| 112 SkGraphics::PurgeFontCache(); | 113 SkGraphics::PurgeFontCache(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 #include "TestClassDef.h" | 116 #include "TestClassDef.h" |
| 116 DEFINE_TESTCLASS("FontHost::CreateTypefaceFromStream", FontHostStreamTestClass, test_fontHostStream) | 117 DEFINE_TESTCLASS("FontHost::CreateTypefaceFromStream", FontHostStreamTestClass, test_fontHostStream) |
| OLD | NEW |