Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/cpp/dev/buffer_dev.h" | |
| 5 #include "ppapi/cpp/dev/printing_dev.h" | 6 #include "ppapi/cpp/dev/printing_dev.h" |
| 6 #include "ppapi/cpp/image_data.h" | 7 #include "ppapi/cpp/image_data.h" |
| 7 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" |
| 8 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/cpp/rect.h" | 10 #include "ppapi/cpp/rect.h" |
| 10 #include "ppapi/utility/completion_callback_factory.h" | 11 #include "ppapi/utility/completion_callback_factory.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 void FillRect(pp::ImageData* image, int left, int top, int width, int height, | 15 const char pdf_data[] = "%PDF-1.4\r" |
| 15 uint32_t color) { | 16 "% \r" |
| 16 for (int y = std::max(0, top); | 17 "1 0 obj<</Type/FontDescriptor/FontBBox[-50 -207 1447 1000]/FontName/Verdana/Fla gs 32/StemV 92/CapHeight 734/XHeight 546/Ascent 1005/Descent -209/ItalicAngle 0/ FontFamily(Verdana)/FontStretch/Normal/FontWeight 400>>\r" |
| 17 y < std::min(image->size().height(), top + height); | 18 "2 0 obj<</Type/Font/Subtype/TrueType/Encoding/UniCNS-UTF16-H/BaseFont/Verdana/N ame/Verdana/FontDescriptor 1 0 R/FirstChar 72/LastChar 114/Widths[ 750 420 454 6 92 556 843 748 787 602 787 695 684 616 731 684 989 685 614 685 454 454 454 818 6 35 635 600 623 521 623 595 351 623 633 274 343 591 274 972 633 607 623 623 426]> >\r" |
| 18 y++) { | 19 "4 0 obj<</Type/Page/Parent 3 0 R/MediaBox[0 0 612 792]/Contents 5 0 R/Resources <</ProcSet[/PDF/Text/ColorC]/Font<</N2 2 0 R>> >> >>endobj\r" |
| 19 for (int x = std::max(0, left); | 20 "5 0 obj<</Length 70>>stream\r" |
| 20 x < std::min(image->size().width(), left + width); | 21 "BT/N2 24 Tf 100 692 Td(Hello)Tj ET\r" |
| 21 x++) | 22 "BT/N2 24 Tf 200 692 Td(World)Tj ET\r" |
| 22 *image->GetAddr32(pp::Point(x, y)) = color; | 23 "\r" |
| 23 } | 24 "endstream\r" |
| 24 } | 25 "endobj\r" |
| 26 "3 0 obj<</Type/Pages/Kids[ 4 0 R]/Count 1>>endobj\r" | |
| 27 "6 0 obj<</Type/Catalog/Pages 3 0 R>>endobj\r" | |
| 28 "xref\r" | |
| 29 "0 7\r" | |
| 30 "0000000000 65535 f \r" | |
| 31 "0000000015 00000 n \r" | |
| 32 "0000000230 00000 n \r" | |
| 33 "0000000805 00000 n \r" | |
| 34 "0000000551 00000 n \r" | |
| 35 "0000000689 00000 n \r" | |
| 36 "0000000855 00000 n \r" | |
| 37 "trailer<</Size 7/Root 6 0 R>>\r" | |
| 38 "startxref\r" | |
| 39 "898\r" | |
| 40 "%%EOF"; | |
| 25 | 41 |
| 26 } // namespace | 42 } // namespace |
| 27 | 43 |
| 28 class MyInstance : public pp::Instance, public pp::Printing_Dev { | 44 class MyInstance : public pp::Instance, public pp::Printing_Dev { |
| 29 public: | 45 public: |
| 30 explicit MyInstance(PP_Instance instance) | 46 explicit MyInstance(PP_Instance instance) |
| 31 : pp::Instance(instance), | 47 : pp::Instance(instance), |
| 32 pp::Printing_Dev(this) { | 48 pp::Printing_Dev(this) { |
| 33 } | 49 } |
| 34 virtual ~MyInstance() {} | 50 virtual ~MyInstance() {} |
| 35 | 51 |
| 36 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 52 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 37 return true; | 53 return true; |
| 38 } | 54 } |
| 39 | 55 |
| 40 virtual uint32_t QuerySupportedPrintOutputFormats() { | 56 virtual uint32_t QuerySupportedPrintOutputFormats() { |
| 41 return PP_PRINTOUTPUTFORMAT_RASTER; | 57 return PP_PRINTOUTPUTFORMAT_PDF; |
| 42 } | 58 } |
| 43 | 59 |
| 44 virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { | 60 virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { |
| 45 return 1; | 61 return 1; |
| 46 } | 62 } |
| 47 | 63 |
| 48 virtual pp::Resource PrintPages( | 64 virtual pp::Resource PrintPages( |
| 49 const PP_PrintPageNumberRange_Dev* page_ranges, | 65 const PP_PrintPageNumberRange_Dev* page_ranges, |
| 50 uint32_t page_range_count) { | 66 uint32_t page_range_count) { |
| 51 pp::Size size(100, 100); | 67 int pdf_len = strlen(pdf_data); |
|
viettrungluu
2012/04/16 04:53:53
nit: size_t
| |
| 52 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); | 68 pp::Buffer_Dev buffer(this, pdf_len); |
| 53 FillRect(&image, 0, 0, size.width(), size.height(), 0xFFFFFFFF); | |
| 54 | 69 |
| 55 FillRect(&image, 0, 0, 10, 10, 0xFF000000); | 70 memcpy(buffer.data(), pdf_data, pdf_len); |
| 56 FillRect(&image, size.width() - 11, size.height() - 11, 10, 10, 0xFF000000); | 71 return buffer; |
| 57 return image; | |
| 58 } | 72 } |
| 59 | 73 |
| 60 virtual void PrintEnd() { | 74 virtual void PrintEnd() { |
| 61 } | 75 } |
| 62 | 76 |
| 63 virtual bool IsPrintScalingDisabled() { | 77 virtual bool IsPrintScalingDisabled() { |
| 64 return true; | 78 return true; |
| 65 } | 79 } |
| 66 }; | 80 }; |
| 67 | 81 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 78 | 92 |
| 79 namespace pp { | 93 namespace pp { |
| 80 | 94 |
| 81 // Factory function for your specialization of the Module object. | 95 // Factory function for your specialization of the Module object. |
| 82 Module* CreateModule() { | 96 Module* CreateModule() { |
| 83 return new MyModule(); | 97 return new MyModule(); |
| 84 } | 98 } |
| 85 | 99 |
| 86 } // namespace pp | 100 } // namespace pp |
| 87 | 101 |
| OLD | NEW |