Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: ppapi/examples/printing/printing.cc

Issue 9455083: Proxy the PPP_Printing interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/examples/printing/README.txt ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/cpp/dev/printing_dev.h"
6 #include "ppapi/cpp/image_data.h"
7 #include "ppapi/cpp/instance.h"
8 #include "ppapi/cpp/module.h"
9 #include "ppapi/cpp/rect.h"
10 #include "ppapi/utility/completion_callback_factory.h"
11
12 namespace {
13
14 void FillRect(pp::ImageData* image, int left, int top, int width, int height,
15 uint32_t color) {
16 for (int y = std::max(0, top);
17 y < std::min(image->size().height(), top + height);
18 y++) {
19 for (int x = std::max(0, left);
20 x < std::min(image->size().width(), left + width);
21 x++)
22 *image->GetAddr32(pp::Point(x, y)) = color;
23 }
24 }
25
26 } // namespace
27
28 class MyInstance : public pp::Instance, public pp::Printing_Dev {
29 public:
30 explicit MyInstance(PP_Instance instance)
31 : pp::Instance(instance),
32 pp::Printing_Dev(this) {
33 }
34 virtual ~MyInstance() {}
35
36 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
37 return true;
38 }
39
40 virtual uint32_t QuerySupportedPrintOutputFormats() {
41 return PP_PRINTOUTPUTFORMAT_RASTER;
42 }
43
44 virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) {
45 return 1;
46 }
47
48 virtual pp::Resource PrintPages(
49 const PP_PrintPageNumberRange_Dev* page_ranges,
50 uint32_t page_range_count) {
51 pp::Size size(100, 100);
52 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true);
53 FillRect(&image, 0, 0, size.width(), size.height(), 0xFFFFFFFF);
54
55 FillRect(&image, 0, 0, 10, 10, 0xFF000000);
56 FillRect(&image, size.width() - 11, size.height() - 11, 10, 10, 0xFF000000);
57 return image;
58 }
59
60 virtual void PrintEnd() {
61 }
62
63 virtual bool IsPrintScalingDisabled() {
64 return true;
65 }
66 };
67
68 class MyModule : public pp::Module {
69 public:
70 MyModule() : pp::Module() {}
71 virtual ~MyModule() {}
72
73 // Override CreateInstance to create your customized Instance object.
74 virtual pp::Instance* CreateInstance(PP_Instance instance) {
75 return new MyInstance(instance);
76 }
77 };
78
79 namespace pp {
80
81 // Factory function for your specialization of the Module object.
82 Module* CreateModule() {
83 return new MyModule();
84 }
85
86 } // namespace pp
87
OLDNEW
« no previous file with comments | « ppapi/examples/printing/README.txt ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698