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

Side by Side Diff: pdf/pdf.cc

Issue 2508563003: Printing: Load the source PDF only once. (Closed)
Patch Set: More renaming Created 4 years, 1 month 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
« no previous file with comments | « pdf/pdf.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "pdf/pdf.h" 5 #include "pdf/pdf.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 delete pp::Module::Get(); 75 delete pp::Module::Get();
76 pp::InternalSetModuleSingleton(nullptr); 76 pp::InternalSetModuleSingleton(nullptr);
77 } 77 }
78 78
79 const void* PPP_GetInterface(const char* interface_name) { 79 const void* PPP_GetInterface(const char* interface_name) {
80 auto* module = pp::Module::Get(); 80 auto* module = pp::Module::Get();
81 return module ? module->GetPluginInterface(interface_name) : nullptr; 81 return module ? module->GetPluginInterface(interface_name) : nullptr;
82 } 82 }
83 83
84 #if defined(OS_WIN) 84 #if defined(OS_WIN)
85 bool RenderPDFPageToDC(const void* pdf_buffer, 85 bool RenderPDFPageToDC(void* pdf_handle,
86 int buffer_size,
87 int page_number, 86 int page_number,
88 HDC dc, 87 HDC dc,
89 int dpi, 88 int dpi,
90 int bounds_origin_x, 89 int bounds_origin_x,
91 int bounds_origin_y, 90 int bounds_origin_y,
92 int bounds_width, 91 int bounds_width,
93 int bounds_height, 92 int bounds_height,
94 bool fit_to_bounds, 93 bool fit_to_bounds,
95 bool stretch_to_bounds, 94 bool stretch_to_bounds,
96 bool keep_aspect_ratio, 95 bool keep_aspect_ratio,
97 bool center_in_bounds, 96 bool center_in_bounds,
98 bool autorotate) { 97 bool autorotate) {
99 if (!g_sdk_initialized_via_pepper) { 98 if (!g_sdk_initialized_via_pepper) {
100 if (!InitializeSDK()) { 99 if (!InitializeSDK()) {
101 return false; 100 return false;
102 } 101 }
103 } 102 }
104 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 103 PDFEngineExports* engine_exports = PDFEngineExports::Get();
105 PDFEngineExports::RenderingSettings settings( 104 PDFEngineExports::RenderingSettings settings(
106 dpi, dpi, 105 dpi, dpi,
107 pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height), 106 pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
108 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, 107 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
109 autorotate); 108 autorotate);
110 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, 109 bool ret =
111 page_number, settings, dc); 110 engine_exports->RenderPDFPageToDC(pdf_handle, page_number, settings, dc);
112 if (!g_sdk_initialized_via_pepper) 111 if (!g_sdk_initialized_via_pepper)
113 ShutdownSDK(); 112 ShutdownSDK();
114 113
115 return ret; 114 return ret;
116 } 115 }
117 116
118 void SetPDFEnsureTypefaceCharactersAccessible( 117 void SetPDFEnsureTypefaceCharactersAccessible(
119 PDFEnsureTypefaceCharactersAccessible func) { 118 PDFEnsureTypefaceCharactersAccessible func) {
120 PDFEngineExports::Get()->SetPDFEnsureTypefaceCharactersAccessible(func); 119 PDFEngineExports::Get()->SetPDFEnsureTypefaceCharactersAccessible(func);
121 } 120 }
122 121
123 void SetPDFUseGDIPrinting(bool enable) { 122 void SetPDFUseGDIPrinting(bool enable) {
124 PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable); 123 PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable);
125 } 124 }
126 #endif // defined(OS_WIN) 125 #endif // defined(OS_WIN)
127 126
128 bool GetPDFDocInfo(const void* pdf_buffer, 127 bool GetPDFDocInfo(const void* pdf_buffer,
129 int buffer_size, int* page_count, 128 int buffer_size,
130 double* max_page_width) { 129 int* page_count,
130 double* max_page_width,
131 void** pdf_handle) {
131 if (!g_sdk_initialized_via_pepper) { 132 if (!g_sdk_initialized_via_pepper) {
132 if (!InitializeSDK()) 133 if (!InitializeSDK())
133 return false; 134 return false;
134 } 135 }
135 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 136 PDFEngineExports* engine_exports = PDFEngineExports::Get();
136 bool ret = engine_exports->GetPDFDocInfo( 137 bool ret = engine_exports->GetPDFDocInfo(pdf_buffer, buffer_size, page_count,
137 pdf_buffer, buffer_size, page_count, max_page_width); 138 max_page_width, pdf_handle);
138 if (!g_sdk_initialized_via_pepper) 139 if (!g_sdk_initialized_via_pepper)
139 ShutdownSDK(); 140 ShutdownSDK();
140 141
141 return ret; 142 return ret;
142 } 143 }
143 144
144 bool GetPDFPageSizeByIndex(const void* pdf_buffer, 145 void ReleasePDFHandle(void* pdf_handle) {
145 int pdf_buffer_size, int page_number,
146 double* width, double* height) {
147 if (!g_sdk_initialized_via_pepper) { 146 if (!g_sdk_initialized_via_pepper) {
148 if (!chrome_pdf::InitializeSDK()) 147 if (!InitializeSDK())
148 return;
149 }
150 PDFEngineExports* engine_exports = PDFEngineExports::Get();
151 engine_exports->ReleasePDFHandle(pdf_handle);
152 if (!g_sdk_initialized_via_pepper)
153 ShutdownSDK();
154 }
155
156 bool GetPDFPageSizeByIndex(void* pdf_handle,
157 int page_number,
158 double* width,
159 double* height) {
160 if (!g_sdk_initialized_via_pepper) {
161 if (!InitializeSDK())
149 return false; 162 return false;
150 } 163 }
151 chrome_pdf::PDFEngineExports* engine_exports = 164 PDFEngineExports* engine_exports = PDFEngineExports::Get();
152 chrome_pdf::PDFEngineExports::Get(); 165 bool ret = engine_exports->GetPDFPageSizeByIndex(pdf_handle, page_number,
153 bool ret = engine_exports->GetPDFPageSizeByIndex( 166 width, height);
154 pdf_buffer, pdf_buffer_size, page_number, width, height);
155 if (!g_sdk_initialized_via_pepper) 167 if (!g_sdk_initialized_via_pepper)
156 chrome_pdf::ShutdownSDK(); 168 ShutdownSDK();
157 return ret; 169 return ret;
158 } 170 }
159 171
160 bool RenderPDFPageToBitmap(const void* pdf_buffer, 172 bool RenderPDFPageToBitmap(void* pdf_handle,
161 int pdf_buffer_size,
162 int page_number, 173 int page_number,
163 void* bitmap_buffer, 174 void* bitmap_buffer,
164 int bitmap_width, 175 int bitmap_width,
165 int bitmap_height, 176 int bitmap_height,
166 int dpi, 177 int dpi,
167 bool autorotate) { 178 bool autorotate) {
168 if (!g_sdk_initialized_via_pepper) { 179 if (!g_sdk_initialized_via_pepper) {
169 if (!InitializeSDK()) 180 if (!InitializeSDK())
170 return false; 181 return false;
171 } 182 }
172 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 183 PDFEngineExports* engine_exports = PDFEngineExports::Get();
173 PDFEngineExports::RenderingSettings settings( 184 PDFEngineExports::RenderingSettings settings(
174 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, 185 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true,
175 autorotate); 186 autorotate);
176 bool ret = engine_exports->RenderPDFPageToBitmap( 187 bool ret = engine_exports->RenderPDFPageToBitmap(pdf_handle, page_number,
177 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); 188 settings, bitmap_buffer);
178 if (!g_sdk_initialized_via_pepper) 189 if (!g_sdk_initialized_via_pepper)
179 ShutdownSDK(); 190 ShutdownSDK();
180 191
181 return ret; 192 return ret;
182 } 193 }
183 194
184 } // namespace chrome_pdf 195 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdf.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698