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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 case 3: | 63 case 3: |
64 // After rotating by 270 degrees with the axis at the origin, the page | 64 // After rotating by 270 degrees with the axis at the origin, the page |
65 // content is now "off screen". Shift it right to move it back on screen. | 65 // content is now "off screen". Shift it right to move it back on screen. |
66 CGContextTranslateCTM(context, 0, rect.size.height); | 66 CGContextTranslateCTM(context, 0, rect.size.height); |
67 // Rotates counter-clockwise by 90 degrees. | 67 // Rotates counter-clockwise by 90 degrees. |
68 CGContextRotateCTM(context, -M_PI_2); | 68 CGContextRotateCTM(context, -M_PI_2); |
69 break; | 69 break; |
70 default: | 70 default: |
71 NOTREACHED(); | 71 NOTREACHED(); |
72 break; | 72 break; |
73 }; | 73 } |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 namespace printing { | 78 namespace printing { |
79 | 79 |
80 PdfMetafileCg::PdfMetafileCg() | 80 PdfMetafileCg::PdfMetafileCg() |
81 : page_is_open_(false), | 81 : page_is_open_(false), |
82 thread_pdf_docs_owned_(false) { | 82 thread_pdf_docs_owned_(false) { |
83 if (!thread_pdf_docs.Pointer()->Get() && | 83 if (!thread_pdf_docs.Pointer()->Get() && |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 context_.reset(CGPDFContextCreate(pdf_consumer, NULL, NULL)); | 121 context_.reset(CGPDFContextCreate(pdf_consumer, NULL, NULL)); |
122 if (!context_.get()) { | 122 if (!context_.get()) { |
123 LOG(ERROR) << "Failed to create pdf context for metafile"; | 123 LOG(ERROR) << "Failed to create pdf context for metafile"; |
124 pdf_data_.reset(NULL); | 124 pdf_data_.reset(NULL); |
125 } | 125 } |
126 | 126 |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 bool PdfMetafileCg::InitFromData(const void* src_buffer, | 130 bool PdfMetafileCg::InitFromData(const void* src_buffer, |
131 uint32 src_buffer_size) { | 131 uint32_t src_buffer_size) { |
132 DCHECK(!context_.get()); | 132 DCHECK(!context_.get()); |
133 DCHECK(!pdf_data_.get()); | 133 DCHECK(!pdf_data_.get()); |
134 | 134 |
135 if (!src_buffer || src_buffer_size == 0) { | 135 if (!src_buffer || src_buffer_size == 0) { |
136 return false; | 136 return false; |
137 } | 137 } |
138 | 138 |
139 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size)); | 139 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size)); |
140 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer), | 140 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer), |
141 src_buffer_size); | 141 src_buffer_size); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 288 } |
289 if (page_number > GetPageCount()) { | 289 if (page_number > GetPageCount()) { |
290 LOG(ERROR) << "Invalid page number: " << page_number; | 290 LOG(ERROR) << "Invalid page number: " << page_number; |
291 return gfx::Rect(); | 291 return gfx::Rect(); |
292 } | 292 } |
293 CGPDFPageRef pdf_page = CGPDFDocumentGetPage(pdf_doc, page_number); | 293 CGPDFPageRef pdf_page = CGPDFDocumentGetPage(pdf_doc, page_number); |
294 CGRect page_rect = CGPDFPageGetBoxRect(pdf_page, kCGPDFMediaBox); | 294 CGRect page_rect = CGPDFPageGetBoxRect(pdf_page, kCGPDFMediaBox); |
295 return gfx::Rect(page_rect); | 295 return gfx::Rect(page_rect); |
296 } | 296 } |
297 | 297 |
298 uint32 PdfMetafileCg::GetDataSize() const { | 298 uint32_t PdfMetafileCg::GetDataSize() const { |
299 // PDF data is only valid/complete once the context is released. | 299 // PDF data is only valid/complete once the context is released. |
300 DCHECK(!context_); | 300 DCHECK(!context_); |
301 | 301 |
302 if (!pdf_data_) | 302 if (!pdf_data_) |
303 return 0; | 303 return 0; |
304 return static_cast<uint32>(CFDataGetLength(pdf_data_)); | 304 return static_cast<uint32_t>(CFDataGetLength(pdf_data_)); |
305 } | 305 } |
306 | 306 |
307 bool PdfMetafileCg::GetData(void* dst_buffer, uint32 dst_buffer_size) const { | 307 bool PdfMetafileCg::GetData(void* dst_buffer, uint32_t dst_buffer_size) const { |
308 // PDF data is only valid/complete once the context is released. | 308 // PDF data is only valid/complete once the context is released. |
309 DCHECK(!context_); | 309 DCHECK(!context_); |
310 DCHECK(pdf_data_); | 310 DCHECK(pdf_data_); |
311 DCHECK(dst_buffer); | 311 DCHECK(dst_buffer); |
312 DCHECK_GT(dst_buffer_size, 0U); | 312 DCHECK_GT(dst_buffer_size, 0U); |
313 | 313 |
314 uint32 data_size = GetDataSize(); | 314 uint32_t data_size = GetDataSize(); |
315 if (dst_buffer_size > data_size) { | 315 if (dst_buffer_size > data_size) { |
316 return false; | 316 return false; |
317 } | 317 } |
318 | 318 |
319 CFDataGetBytes(pdf_data_, CFRangeMake(0, dst_buffer_size), | 319 CFDataGetBytes(pdf_data_, CFRangeMake(0, dst_buffer_size), |
320 static_cast<UInt8*>(dst_buffer)); | 320 static_cast<UInt8*>(dst_buffer)); |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
324 CGContextRef PdfMetafileCg::context() const { | 324 CGContextRef PdfMetafileCg::context() const { |
325 return context_.get(); | 325 return context_.get(); |
326 } | 326 } |
327 | 327 |
328 CGPDFDocumentRef PdfMetafileCg::GetPDFDocument() const { | 328 CGPDFDocumentRef PdfMetafileCg::GetPDFDocument() const { |
329 // Make sure that we have data, and that it's not being modified any more. | 329 // Make sure that we have data, and that it's not being modified any more. |
330 DCHECK(pdf_data_.get()); | 330 DCHECK(pdf_data_.get()); |
331 DCHECK(!context_.get()); | 331 DCHECK(!context_.get()); |
332 | 332 |
333 if (!pdf_doc_.get()) { | 333 if (!pdf_doc_.get()) { |
334 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 334 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
335 CGDataProviderCreateWithCFData(pdf_data_)); | 335 CGDataProviderCreateWithCFData(pdf_data_)); |
336 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 336 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
337 } | 337 } |
338 return pdf_doc_.get(); | 338 return pdf_doc_.get(); |
339 } | 339 } |
340 | 340 |
341 } // namespace printing | 341 } // namespace printing |
OLD | NEW |