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
3 // found in the LICENSE file.
7 #include "ppapi/cpp/dev/buffer_dev.h"
8 #include "ppapi/cpp/dev/printing_dev.h"
9 #include "ppapi/cpp/image_data.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/rect.h"
13 #include "ppapi/utility/completion_callback_factory.h"
17 const char pdf_data
[] = "%PDF-1.4\r"
19 "1 0 obj<</Type/FontDescriptor/FontBBox[-50 -207 1447 1000]/FontName/Verdana/Flags 32/StemV 92/CapHeight 734/XHeight 546/Ascent 1005/Descent -209/ItalicAngle 0/FontFamily(Verdana)/FontStretch/Normal/FontWeight 400>>\r"
20 "2 0 obj<</Type/Font/Subtype/TrueType/Encoding/UniCNS-UTF16-H/BaseFont/Verdana/Name/Verdana/FontDescriptor 1 0 R/FirstChar 72/LastChar 114/Widths[ 750 420 454 692 556 843 748 787 602 787 695 684 616 731 684 989 685 614 685 454 454 454 818 635 635 600 623 521 623 595 351 623 633 274 343 591 274 972 633 607 623 623 426]>>\r"
21 "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"
22 "5 0 obj<</Length 70>>stream\r"
23 "BT/N2 24 Tf 100 692 Td(Hello)Tj ET\r"
24 "BT/N2 24 Tf 200 692 Td(World)Tj ET\r"
28 "3 0 obj<</Type/Pages/Kids[ 4 0 R]/Count 1>>endobj\r"
29 "6 0 obj<</Type/Catalog/Pages 3 0 R>>endobj\r"
32 "0000000000 65535 f \r"
33 "0000000015 00000 n \r"
34 "0000000230 00000 n \r"
35 "0000000805 00000 n \r"
36 "0000000551 00000 n \r"
37 "0000000689 00000 n \r"
38 "0000000855 00000 n \r"
39 "trailer<</Size 7/Root 6 0 R>>\r"
46 class MyInstance
: public pp::Instance
, public pp::Printing_Dev
{
48 explicit MyInstance(PP_Instance instance
)
49 : pp::Instance(instance
),
50 pp::Printing_Dev(this) {
52 virtual ~MyInstance() {}
54 virtual bool Init(uint32_t argc
, const char* argn
[], const char* argv
[]) {
58 virtual uint32_t QuerySupportedPrintOutputFormats() {
59 return PP_PRINTOUTPUTFORMAT_PDF
;
62 virtual int32_t PrintBegin(const PP_PrintSettings_Dev
& print_settings
) {
66 virtual pp::Resource
PrintPages(
67 const PP_PrintPageNumberRange_Dev
* page_ranges
,
68 uint32_t page_range_count
) {
69 size_t pdf_len
= strlen(pdf_data
);
70 pp::Buffer_Dev
buffer(this, static_cast<uint32_t>(pdf_len
));
72 memcpy(buffer
.data(), pdf_data
, pdf_len
);
76 virtual void PrintEnd() {
79 virtual bool IsPrintScalingDisabled() {
84 class MyModule
: public pp::Module
{
86 MyModule() : pp::Module() {}
87 virtual ~MyModule() {}
89 // Override CreateInstance to create your customized Instance object.
90 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
91 return new MyInstance(instance
);
97 // Factory function for your specialization of the Module object.
98 Module
* CreateModule() {
99 return new MyModule();