OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { | 295 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
296 // Load typeface form file. | 296 // Load typeface form file. |
297 // This test cannot run if there is no resource path. | 297 // This test cannot run if there is no resource path. |
298 SkString resourcePath = GetResourcePath(); | 298 SkString resourcePath = GetResourcePath(); |
299 if (resourcePath.isEmpty()) { | 299 if (resourcePath.isEmpty()) { |
300 SkDebugf("Could not run fontstream test because resourcePath not specifi
ed."); | 300 SkDebugf("Could not run fontstream test because resourcePath not specifi
ed."); |
301 return; | 301 return; |
302 } | 302 } |
303 SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc"); | 303 SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc"); |
304 SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str()); | 304 SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str(), 1); |
305 if (!typeface) { | 305 if (!typeface) { |
306 SkDebugf("Could not run fontstream test because test.ttc not found."); | 306 SkDebugf("Could not run fontstream test because test.ttc not found."); |
307 return; | 307 return; |
308 } | 308 } |
309 | 309 |
310 // Create a paint with the typeface we loaded. | 310 // Create a paint with the typeface we loaded. |
311 SkPaint paint; | 311 SkPaint paint; |
312 paint.setColor(SK_ColorGRAY); | 312 paint.setColor(SK_ColorGRAY); |
313 paint.setTextSize(SkIntToScalar(30)); | 313 paint.setTextSize(SkIntToScalar(30)); |
314 SkSafeUnref(paint.setTypeface(typeface)); | 314 SkSafeUnref(paint.setTypeface(typeface)); |
315 | 315 |
316 // Paint some text. | 316 // Paint some text. |
317 SkPictureRecorder recorder; | 317 SkPictureRecorder recorder; |
318 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); | 318 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
319 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, | 319 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, |
320 SkIntToScalar(canvasRect.height()
), | 320 SkIntToScalar(canvasRect.height()
), |
321 NULL, 0); | 321 NULL, 0); |
322 canvas->drawColor(SK_ColorWHITE); | 322 canvas->drawColor(SK_ColorWHITE); |
323 canvas->drawText("A", 1, 24, 32, paint); | 323 canvas->drawText("A!", 2, 24, 32, paint); |
324 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 324 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
325 | 325 |
326 // Serlialize picture and create its clone from stream. | 326 // Serlialize picture and create its clone from stream. |
327 SkDynamicMemoryWStream stream; | 327 SkDynamicMemoryWStream stream; |
328 picture->serialize(&stream); | 328 picture->serialize(&stream); |
329 SkAutoTUnref<SkStream> inputStream(stream.detachAsStream()); | 329 SkAutoTUnref<SkStream> inputStream(stream.detachAsStream()); |
330 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea
m.get())); | 330 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea
m.get())); |
331 | 331 |
332 // Draw both original and clone picture and compare bitmaps -- they should b
e identical. | 332 // Draw both original and clone picture and compare bitmaps -- they should b
e identical. |
333 SkBitmap origBitmap = draw_picture(*picture); | 333 SkBitmap origBitmap = draw_picture(*picture); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 488 |
489 // Deserialize picture | 489 // Deserialize picture |
490 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); | 490 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
491 SkAutoTUnref<SkPicture> readPict( | 491 SkAutoTUnref<SkPicture> readPict( |
492 SkPicture::CreateFromBuffer(reader)); | 492 SkPicture::CreateFromBuffer(reader)); |
493 REPORTER_ASSERT(reporter, readPict.get()); | 493 REPORTER_ASSERT(reporter, readPict.get()); |
494 } | 494 } |
495 | 495 |
496 TestPictureTypefaceSerialization(reporter); | 496 TestPictureTypefaceSerialization(reporter); |
497 } | 497 } |
OLD | NEW |