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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 uint32 data_size = GetDataSize(); | 279 uint32 data_size = GetDataSize(); |
280 if (dst_buffer_size > data_size) { | 280 if (dst_buffer_size > data_size) { |
281 return false; | 281 return false; |
282 } | 282 } |
283 | 283 |
284 CFDataGetBytes(pdf_data_, CFRangeMake(0, dst_buffer_size), | 284 CFDataGetBytes(pdf_data_, CFRangeMake(0, dst_buffer_size), |
285 static_cast<UInt8*>(dst_buffer)); | 285 static_cast<UInt8*>(dst_buffer)); |
286 return true; | 286 return true; |
287 } | 287 } |
288 | 288 |
289 bool PdfMetafileCg::SaveTo(const base::FilePath& file_path) const { | |
290 DCHECK(pdf_data_.get()); | |
291 DCHECK(!context_.get()); | |
292 | |
293 std::string path_string = file_path.value(); | |
294 ScopedCFTypeRef<CFURLRef> path_url(CFURLCreateFromFileSystemRepresentation( | |
295 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(path_string.c_str()), | |
296 path_string.length(), false)); | |
297 SInt32 error_code; | |
298 CFURLWriteDataAndPropertiesToResource(path_url, pdf_data_, NULL, &error_code); | |
299 return error_code == 0; | |
300 } | |
301 | |
302 CGContextRef PdfMetafileCg::context() const { | 289 CGContextRef PdfMetafileCg::context() const { |
303 return context_.get(); | 290 return context_.get(); |
304 } | 291 } |
305 | 292 |
306 CGPDFDocumentRef PdfMetafileCg::GetPDFDocument() const { | 293 CGPDFDocumentRef PdfMetafileCg::GetPDFDocument() const { |
307 // Make sure that we have data, and that it's not being modified any more. | 294 // Make sure that we have data, and that it's not being modified any more. |
308 DCHECK(pdf_data_.get()); | 295 DCHECK(pdf_data_.get()); |
309 DCHECK(!context_.get()); | 296 DCHECK(!context_.get()); |
310 | 297 |
311 if (!pdf_doc_.get()) { | 298 if (!pdf_doc_.get()) { |
312 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 299 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
313 CGDataProviderCreateWithCFData(pdf_data_)); | 300 CGDataProviderCreateWithCFData(pdf_data_)); |
314 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 301 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
315 } | 302 } |
316 return pdf_doc_.get(); | 303 return pdf_doc_.get(); |
317 } | 304 } |
318 | 305 |
319 } // namespace printing | 306 } // namespace printing |
OLD | NEW |