15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string.h> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/dev/buffer_dev.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/dev/printing_dev.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/image_data.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/rect.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/utility/completion_callback_factory.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char pdf_data[] = "%PDF-1.4\r" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"% \r" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"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" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"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" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"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" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"5 0 obj<</Length 70>>stream\r" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"BT/N2 24 Tf 100 692 Td(Hello)Tj ET\r" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"BT/N2 24 Tf 200 692 Td(World)Tj ET\r" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"\r" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"endstream\r" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"endobj\r" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"3 0 obj<</Type/Pages/Kids[ 4 0 R]/Count 1>>endobj\r" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"6 0 obj<</Type/Catalog/Pages 3 0 R>>endobj\r" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"xref\r" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0 7\r" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000000 65535 f \r" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000015 00000 n \r" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000230 00000 n \r" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000805 00000 n \r" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000551 00000 n \r" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000689 00000 n \r" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"0000000855 00000 n \r" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"trailer<</Size 7/Root 6 0 R>>\r" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"startxref\r" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"898\r" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"%%EOF"; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MyInstance : public pp::Instance, public pp::Printing_Dev { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit MyInstance(PP_Instance instance) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : pp::Instance(instance), 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp::Printing_Dev(this) { 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MyInstance() {} 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual uint32_t QuerySupportedPrintOutputFormats() { 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PP_PRINTOUTPUTFORMAT_PDF; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 1; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual pp::Resource PrintPages( 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const PP_PrintPageNumberRange_Dev* page_ranges, 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t page_range_count) { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t pdf_len = strlen(pdf_data); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp::Buffer_Dev buffer(this, pdf_len); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) memcpy(buffer.data(), pdf_data, pdf_len); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return buffer; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void PrintEnd() { 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsPrintScalingDisabled() { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MyModule : public pp::Module { 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MyModule() : pp::Module() {} 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MyModule() {} 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Override CreateInstance to create your customized Instance object. 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual pp::Instance* CreateInstance(PP_Instance instance) { 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new MyInstance(instance); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Factory function for your specialization of the Module object. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Module* CreateModule() { 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new MyModule(); 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace pp 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 104