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

Side by Side Diff: pdf/pdf.cc

Issue 2541843005: Revert "Printing: Load the source PDF only once." (Closed)
Patch Set: Created 4 years 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(void* pdf_handle, 85 bool RenderPDFPageToDC(const void* pdf_buffer,
86 int buffer_size,
86 int page_number, 87 int page_number,
87 HDC dc, 88 HDC dc,
88 int dpi, 89 int dpi,
89 int bounds_origin_x, 90 int bounds_origin_x,
90 int bounds_origin_y, 91 int bounds_origin_y,
91 int bounds_width, 92 int bounds_width,
92 int bounds_height, 93 int bounds_height,
93 bool fit_to_bounds, 94 bool fit_to_bounds,
94 bool stretch_to_bounds, 95 bool stretch_to_bounds,
95 bool keep_aspect_ratio, 96 bool keep_aspect_ratio,
96 bool center_in_bounds, 97 bool center_in_bounds,
97 bool autorotate) { 98 bool autorotate) {
98 if (!g_sdk_initialized_via_pepper) { 99 if (!g_sdk_initialized_via_pepper) {
99 if (!InitializeSDK()) { 100 if (!InitializeSDK()) {
100 return false; 101 return false;
101 } 102 }
102 } 103 }
103 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 104 PDFEngineExports* engine_exports = PDFEngineExports::Get();
104 PDFEngineExports::RenderingSettings settings( 105 PDFEngineExports::RenderingSettings settings(
105 dpi, dpi, 106 dpi, dpi,
106 pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height), 107 pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
107 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, 108 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
108 autorotate); 109 autorotate);
109 bool ret = 110 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size,
110 engine_exports->RenderPDFPageToDC(pdf_handle, page_number, settings, dc); 111 page_number, settings, dc);
111 if (!g_sdk_initialized_via_pepper) 112 if (!g_sdk_initialized_via_pepper)
112 ShutdownSDK(); 113 ShutdownSDK();
113 114
114 return ret; 115 return ret;
115 } 116 }
116 117
117 void SetPDFEnsureTypefaceCharactersAccessible( 118 void SetPDFEnsureTypefaceCharactersAccessible(
118 PDFEnsureTypefaceCharactersAccessible func) { 119 PDFEnsureTypefaceCharactersAccessible func) {
119 PDFEngineExports::Get()->SetPDFEnsureTypefaceCharactersAccessible(func); 120 PDFEngineExports::Get()->SetPDFEnsureTypefaceCharactersAccessible(func);
120 } 121 }
121 122
122 void SetPDFUseGDIPrinting(bool enable) { 123 void SetPDFUseGDIPrinting(bool enable) {
123 PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable); 124 PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable);
124 } 125 }
125 #endif // defined(OS_WIN) 126 #endif // defined(OS_WIN)
126 127
127 bool GetPDFDocInfo(const void* pdf_buffer, 128 bool GetPDFDocInfo(const void* pdf_buffer,
128 int buffer_size, 129 int buffer_size,
129 int* page_count, 130 int* page_count,
130 double* max_page_width, 131 double* max_page_width) {
131 void** pdf_handle) {
132 if (!g_sdk_initialized_via_pepper) { 132 if (!g_sdk_initialized_via_pepper) {
133 if (!InitializeSDK()) 133 if (!InitializeSDK())
134 return false; 134 return false;
135 } 135 }
136 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 136 PDFEngineExports* engine_exports = PDFEngineExports::Get();
137 bool ret = engine_exports->GetPDFDocInfo(pdf_buffer, buffer_size, page_count, 137 bool ret = engine_exports->GetPDFDocInfo(pdf_buffer, buffer_size, page_count,
138 max_page_width, pdf_handle); 138 max_page_width);
139 if (!g_sdk_initialized_via_pepper) 139 if (!g_sdk_initialized_via_pepper)
140 ShutdownSDK(); 140 ShutdownSDK();
141 141
142 return ret; 142 return ret;
143 } 143 }
144 144
145 void ReleasePDFHandle(void* pdf_handle) { 145 bool GetPDFPageSizeByIndex(const void* pdf_buffer,
146 if (!g_sdk_initialized_via_pepper) { 146 int pdf_buffer_size,
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, 147 int page_number,
158 double* width, 148 double* width,
159 double* height) { 149 double* height) {
160 if (!g_sdk_initialized_via_pepper) { 150 if (!g_sdk_initialized_via_pepper) {
161 if (!InitializeSDK()) 151 if (!chrome_pdf::InitializeSDK())
162 return false; 152 return false;
163 } 153 }
164 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 154 chrome_pdf::PDFEngineExports* engine_exports =
165 bool ret = engine_exports->GetPDFPageSizeByIndex(pdf_handle, page_number, 155 chrome_pdf::PDFEngineExports::Get();
166 width, height); 156 bool ret = engine_exports->GetPDFPageSizeByIndex(pdf_buffer, pdf_buffer_size,
157 page_number, width, height);
167 if (!g_sdk_initialized_via_pepper) 158 if (!g_sdk_initialized_via_pepper)
168 ShutdownSDK(); 159 chrome_pdf::ShutdownSDK();
169 return ret; 160 return ret;
170 } 161 }
171 162
172 bool RenderPDFPageToBitmap(void* pdf_handle, 163 bool RenderPDFPageToBitmap(const void* pdf_buffer,
164 int pdf_buffer_size,
173 int page_number, 165 int page_number,
174 void* bitmap_buffer, 166 void* bitmap_buffer,
175 int bitmap_width, 167 int bitmap_width,
176 int bitmap_height, 168 int bitmap_height,
177 int dpi, 169 int dpi,
178 bool autorotate) { 170 bool autorotate) {
179 if (!g_sdk_initialized_via_pepper) { 171 if (!g_sdk_initialized_via_pepper) {
180 if (!InitializeSDK()) 172 if (!InitializeSDK())
181 return false; 173 return false;
182 } 174 }
183 PDFEngineExports* engine_exports = PDFEngineExports::Get(); 175 PDFEngineExports* engine_exports = PDFEngineExports::Get();
184 PDFEngineExports::RenderingSettings settings( 176 PDFEngineExports::RenderingSettings settings(
185 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, 177 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true,
186 autorotate); 178 autorotate);
187 bool ret = engine_exports->RenderPDFPageToBitmap(pdf_handle, page_number, 179 bool ret = engine_exports->RenderPDFPageToBitmap(
188 settings, bitmap_buffer); 180 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer);
189 if (!g_sdk_initialized_via_pepper) 181 if (!g_sdk_initialized_via_pepper)
190 ShutdownSDK(); 182 ShutdownSDK();
191 183
192 return ret; 184 return ret;
193 } 185 }
194 186
195 } // namespace chrome_pdf 187 } // 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