| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkDocument.h" | 11 #include "SkDocument.h" |
| 12 #include "SkForceLinking.h" | 12 #include "SkForceLinking.h" |
| 13 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
| 14 #include "SkSurface.h" | 14 #include "SkSurface.h" |
| 15 #include "SkImage.h" | 15 #include "SkImage.h" |
| 16 #include "SkImageEncoder.h" |
| 16 #include "SkStream.h" | 17 #include "SkStream.h" |
| 17 #include "SkString.h" | 18 #include "SkString.h" |
| 18 | 19 |
| 19 __SK_FORCE_IMAGE_DECODER_LINKING; | 20 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 20 | 21 |
| 21 DEFINE_string2(outFile, o, "skhello", "The filename to write the image."); | 22 DEFINE_string2(outFile, o, "skhello", "The filename to write the image."); |
| 22 DEFINE_string2(text, t, "Hello", "The string to write."); | 23 DEFINE_string2(text, t, "Hello", "The string to write."); |
| 23 | 24 |
| 24 static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) { | 25 static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) { |
| 25 SkRect bounds; | 26 SkRect bounds; |
| 26 canvas->getClipBounds(&bounds); | 27 canvas->getClipBounds(&bounds); |
| 27 | 28 |
| 28 canvas->drawColor(SK_ColorWHITE); | 29 canvas->drawColor(SK_ColorWHITE); |
| 29 canvas->drawText(text, strlen(text), | 30 canvas->drawText(text, strlen(text), |
| 30 bounds.centerX(), bounds.centerY(), | 31 bounds.centerX(), bounds.centerY(), |
| 31 paint); | 32 paint); |
| 32 } | 33 } |
| 33 | 34 |
| 34 static bool do_surface(int w, int h, const char path[], const char text[], | 35 static bool do_surface(int w, int h, const char path[], const char text[], |
| 35 const SkPaint& paint) { | 36 const SkPaint& paint) { |
| 36 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(w, h)); | 37 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(w, h)); |
| 37 doDraw(surface->getCanvas(), paint, text); | 38 doDraw(surface->getCanvas(), paint, text); |
| 38 | 39 |
| 39 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 40 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 40 SkAutoDataUnref data(image->encode()); | 41 SkAutoDataUnref data(SkImageEncoder::EncodeData(*image, |
| 42 SkImageEncoder::kPNG_Type, |
| 43 SkImageEncoder::kDefaultQual
ity)); |
| 41 if (NULL == data.get()) { | 44 if (NULL == data.get()) { |
| 42 return false; | 45 return false; |
| 43 } | 46 } |
| 44 SkFILEWStream stream(path); | 47 SkFILEWStream stream(path); |
| 45 return stream.write(data->data(), data->size()); | 48 return stream.write(data->data(), data->size()); |
| 46 } | 49 } |
| 47 | 50 |
| 48 static bool do_document(int w, int h, const char path[], const char text[], | 51 static bool do_document(int w, int h, const char path[], const char text[], |
| 49 const SkPaint& paint) { | 52 const SkPaint& paint) { |
| 50 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path)); | 53 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 104 } |
| 102 } | 105 } |
| 103 return 0; | 106 return 0; |
| 104 } | 107 } |
| 105 | 108 |
| 106 #if !defined SK_BUILD_FOR_IOS | 109 #if !defined SK_BUILD_FOR_IOS |
| 107 int main(int argc, char * const argv[]) { | 110 int main(int argc, char * const argv[]) { |
| 108 return tool_main(argc, (char**) argv); | 111 return tool_main(argc, (char**) argv); |
| 109 } | 112 } |
| 110 #endif | 113 #endif |
| OLD | NEW |