OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_skia.h" | 5 #include "printing/pdf_metafile_skia.h" |
6 | 6 |
7 #include "base/eintr_wrapper.h" | 7 #include "base/eintr_wrapper.h" |
8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 DCHECK(!page_outstanding_); | 54 DCHECK(!page_outstanding_); |
55 page_outstanding_ = true; | 55 page_outstanding_ = true; |
56 | 56 |
57 // Adjust for the margins and apply the scale factor. | 57 // Adjust for the margins and apply the scale factor. |
58 SkMatrix transform; | 58 SkMatrix transform; |
59 transform.setTranslate(SkIntToScalar(content_area.x()), | 59 transform.setTranslate(SkIntToScalar(content_area.x()), |
60 SkIntToScalar(content_area.y())); | 60 SkIntToScalar(content_area.y())); |
61 transform.preScale(SkFloatToScalar(scale_factor), | 61 transform.preScale(SkFloatToScalar(scale_factor), |
62 SkFloatToScalar(scale_factor)); | 62 SkFloatToScalar(scale_factor)); |
63 | 63 |
64 // TODO(ctguil): Refactor: don't create the PDF device explicitly here. | |
65 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height()); | 64 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height()); |
66 SkISize pdf_content_size = | 65 SkISize pdf_content_size = |
67 SkISize::Make(content_area.width(), content_area.height()); | 66 SkISize::Make(content_area.width(), content_area.height()); |
68 SkRefPtr<SkPDFDevice> pdf_device = | 67 SkRefPtr<SkPDFDevice> pdf_device = |
69 new SkPDFDevice(pdf_page_size, pdf_content_size, transform); | 68 new skia::VectorPlatformDeviceSkia(pdf_page_size, pdf_content_size, |
70 pdf_device->unref(); // SkRefPtr and new both took a reference. | 69 transform); |
71 skia::VectorPlatformDeviceSkia* device = | 70 data_->current_page_ = pdf_device; |
72 new skia::VectorPlatformDeviceSkia(pdf_device.get()); | 71 return pdf_device.get(); |
73 data_->current_page_ = device->PdfDevice(); | |
74 return device; | |
75 } | 72 } |
76 | 73 |
77 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, | 74 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, |
78 const gfx::Rect& content_area, | 75 const gfx::Rect& content_area, |
79 const float& scale_factor) { | 76 const float& scale_factor) { |
80 NOTREACHED(); | 77 NOTREACHED(); |
81 return NULL; | 78 return NULL; |
82 } | 79 } |
83 | 80 |
84 bool PdfMetafileSkia::FinishPage() { | 81 bool PdfMetafileSkia::FinishPage() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 SkAutoDataUnref data(pdf_stream.copyToData()); | 248 SkAutoDataUnref data(pdf_stream.copyToData()); |
252 if (data.size() == 0) | 249 if (data.size() == 0) |
253 return NULL; | 250 return NULL; |
254 | 251 |
255 PdfMetafileSkia* metafile = new printing::PdfMetafileSkia; | 252 PdfMetafileSkia* metafile = new printing::PdfMetafileSkia; |
256 metafile->InitFromData(data.bytes(), data.size()); | 253 metafile->InitFromData(data.bytes(), data.size()); |
257 return metafile; | 254 return metafile; |
258 } | 255 } |
259 | 256 |
260 } // namespace printing | 257 } // namespace printing |
OLD | NEW |