OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "printing/pdf_metafile_cg_mac.h" | 5 #include "printing/pdf_metafile_cg_mac.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 LOG(ERROR) << "Metafile context has " << extra_retain_count | 150 LOG(ERROR) << "Metafile context has " << extra_retain_count |
151 << " extra retain(s) on Close"; | 151 << " extra retain(s) on Close"; |
152 } | 152 } |
153 } | 153 } |
154 #endif | 154 #endif |
155 CGPDFContextClose(context_.get()); | 155 CGPDFContextClose(context_.get()); |
156 context_.reset(); | 156 context_.reset(); |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
160 bool PdfMetafileCg::RenderPage(unsigned int page_number, | 160 /* TODO(caryclark): The set up of PluginInstance::PrintPDFOutput may result in |
| 161 rasterized output. Even if that flow uses PdfMetafileCg::RenderPage, |
| 162 the drawing of the PDF into the canvas may result in a rasterized output. |
| 163 PDFMetafileSkia::RenderPage should be not implemented as shown and instead |
| 164 should do something like the following CL in PluginInstance::PrintPDFOutput: |
| 165 http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plug
in_instance.cc |
| 166 */ |
| 167 bool PdfMetafileCg::RenderPage(const std::vector<char>& src_buffer, |
| 168 unsigned int page_number, |
161 CGContextRef context, | 169 CGContextRef context, |
162 const CGRect rect, | 170 const CGRect rect, |
163 const MacRenderPageParams& params) const { | 171 const PdfMetafileCg::RenderPageParams& params) { |
164 CGPDFDocumentRef pdf_doc = GetPDFDocument(); | 172 PdfMetafileCg metafile; |
| 173 if (!metafile.InitFromData(src_buffer.data(), src_buffer.size())) { |
| 174 LOG(ERROR) << "Unable to initialize PDF document from data"; |
| 175 return false; |
| 176 } |
| 177 CGPDFDocumentRef pdf_doc = metafile.GetPDFDocument(); |
165 if (!pdf_doc) { | 178 if (!pdf_doc) { |
166 LOG(ERROR) << "Unable to create PDF document from data"; | 179 LOG(ERROR) << "Unable to create PDF document from data"; |
167 return false; | 180 return false; |
168 } | 181 } |
169 CGPDFPageRef pdf_page = CGPDFDocumentGetPage(pdf_doc, page_number); | 182 CGPDFPageRef pdf_page = CGPDFDocumentGetPage(pdf_doc, page_number); |
170 CGRect source_rect = CGPDFPageGetBoxRect(pdf_page, kCGPDFCropBox); | 183 CGRect source_rect = CGPDFPageGetBoxRect(pdf_page, kCGPDFCropBox); |
171 int pdf_src_rotation = CGPDFPageGetRotationAngle(pdf_page); | 184 int pdf_src_rotation = CGPDFPageGetRotationAngle(pdf_page); |
172 float scaling_factor = 1.0; | 185 float scaling_factor = 1.0; |
173 const bool source_is_landscape = | 186 const bool source_is_landscape = |
174 (source_rect.size.width > source_rect.size.height); | 187 (source_rect.size.width > source_rect.size.height); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 305 |
293 if (!pdf_doc_.get()) { | 306 if (!pdf_doc_.get()) { |
294 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 307 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
295 CGDataProviderCreateWithCFData(pdf_data_)); | 308 CGDataProviderCreateWithCFData(pdf_data_)); |
296 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 309 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
297 } | 310 } |
298 return pdf_doc_.get(); | 311 return pdf_doc_.get(); |
299 } | 312 } |
300 | 313 |
301 } // namespace printing | 314 } // namespace printing |
OLD | NEW |