diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 07:54:18 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 07:54:18 +0000 |
commit | 3890cfff20f5407c0f5e7526cb5b8941d00901fa (patch) | |
tree | e59430650a82399d8c47ac90d5ecf0c71fc3b571 /ppapi/examples | |
parent | 5d199d726c8b6ea5aa125c44b0c790672a2922c0 (diff) | |
download | chromium_src-3890cfff20f5407c0f5e7526cb5b8941d00901fa.zip chromium_src-3890cfff20f5407c0f5e7526cb5b8941d00901fa.tar.gz chromium_src-3890cfff20f5407c0f5e7526cb5b8941d00901fa.tar.bz2 |
Adds a printing proxy and example. This adds a printing example.
Review URL: http://codereview.chromium.org/9455083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples')
-rw-r--r-- | ppapi/examples/printing/README.txt | 5 | ||||
-rw-r--r-- | ppapi/examples/printing/printing.cc | 87 |
2 files changed, 92 insertions, 0 deletions
diff --git a/ppapi/examples/printing/README.txt b/ppapi/examples/printing/README.txt new file mode 100644 index 0000000..7350043 --- /dev/null +++ b/ppapi/examples/printing/README.txt @@ -0,0 +1,5 @@ +To test this you need to run this plugin as "full frame." So you have to +associate the plugin with a MIME type your server returns. + +One cheesy way to do this is to register as "application/x-shockwave-flash", +disable flash in about:plugins, and navigate to any .swf on the internet. diff --git a/ppapi/examples/printing/printing.cc b/ppapi/examples/printing/printing.cc new file mode 100644 index 0000000..657a109 --- /dev/null +++ b/ppapi/examples/printing/printing.cc @@ -0,0 +1,87 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/dev/printing_dev.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/utility/completion_callback_factory.h" + +namespace { + +void FillRect(pp::ImageData* image, int left, int top, int width, int height, + uint32_t color) { + for (int y = std::max(0, top); + y < std::min(image->size().height(), top + height); + y++) { + for (int x = std::max(0, left); + x < std::min(image->size().width(), left + width); + x++) + *image->GetAddr32(pp::Point(x, y)) = color; + } +} + +} // namespace + +class MyInstance : public pp::Instance, public pp::Printing_Dev { + public: + explicit MyInstance(PP_Instance instance) + : pp::Instance(instance), + pp::Printing_Dev(this) { + } + virtual ~MyInstance() {} + + virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { + return true; + } + + virtual uint32_t QuerySupportedPrintOutputFormats() { + return PP_PRINTOUTPUTFORMAT_RASTER; + } + + virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { + return 1; + } + + virtual pp::Resource PrintPages( + const PP_PrintPageNumberRange_Dev* page_ranges, + uint32_t page_range_count) { + pp::Size size(100, 100); + pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); + FillRect(&image, 0, 0, size.width(), size.height(), 0xFFFFFFFF); + + FillRect(&image, 0, 0, 10, 10, 0xFF000000); + FillRect(&image, size.width() - 11, size.height() - 11, 10, 10, 0xFF000000); + return image; + } + + virtual void PrintEnd() { + } + + virtual bool IsPrintScalingDisabled() { + return true; + } +}; + +class MyModule : public pp::Module { + public: + MyModule() : pp::Module() {} + virtual ~MyModule() {} + + // Override CreateInstance to create your customized Instance object. + virtual pp::Instance* CreateInstance(PP_Instance instance) { + return new MyInstance(instance); + } +}; + +namespace pp { + +// Factory function for your specialization of the Module object. +Module* CreateModule() { + return new MyModule(); +} + +} // namespace pp + |