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 "skia/ext/vector_platform_device_skia.h" | 10 #include "skia/ext/vector_platform_device_skia.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 bool PdfMetafileSkia::Init() { | 31 bool PdfMetafileSkia::Init() { |
32 return true; | 32 return true; |
33 } | 33 } |
34 bool PdfMetafileSkia::InitFromData(const void* src_buffer, | 34 bool PdfMetafileSkia::InitFromData(const void* src_buffer, |
35 uint32 src_buffer_size) { | 35 uint32 src_buffer_size) { |
36 return data_->pdf_stream_.write(src_buffer, src_buffer_size); | 36 return data_->pdf_stream_.write(src_buffer, src_buffer_size); |
37 } | 37 } |
38 | 38 |
39 skia::PlatformDevice* PdfMetafileSkia::StartPageForVectorCanvas( | 39 skia::PlatformDevice* PdfMetafileSkia::StartPageForVectorCanvas( |
40 const gfx::Size& page_size, const gfx::Point& content_origin, | 40 const gfx::Size& page_size, const gfx::Rect& content_area, |
41 const float& scale_factor) { | 41 const float& scale_factor) { |
42 DCHECK(data_->current_page_.get() == NULL); | 42 DCHECK(data_->current_page_.get() == NULL); |
43 | 43 |
44 // Adjust for the margins and apply the scale factor. | 44 // Adjust for the margins and apply the scale factor. |
45 SkMatrix transform; | 45 SkMatrix transform; |
46 transform.setTranslate(SkIntToScalar(content_origin.x()), | 46 transform.setTranslate(SkIntToScalar(content_area.x()), |
47 SkIntToScalar(content_origin.y())); | 47 SkIntToScalar(content_area.y())); |
48 transform.preScale(SkFloatToScalar(scale_factor), | 48 transform.preScale(SkFloatToScalar(scale_factor), |
49 SkFloatToScalar(scale_factor)); | 49 SkFloatToScalar(scale_factor)); |
50 | 50 |
51 // TODO(ctguil): Refactor: don't create the PDF device explicitly here. | |
52 SkRefPtr<SkPDFDevice> pdf_device = | |
vandebo (ex-Chrome)
2011/04/27 22:11:34
This could be quiet a bit cleaner with a few varia
Chris Guillory
2011/04/29 18:25:44
Done.
| |
53 new SkPDFDevice(SkISize::Make(page_size.width(), page_size.height()), | |
54 SkISize::Make(content_area.width(), | |
55 content_area.height()), | |
56 transform); | |
57 pdf_device->unref(); // SkRefPtr and new both took a reference. | |
51 skia::VectorPlatformDeviceSkia* device = | 58 skia::VectorPlatformDeviceSkia* device = |
52 new skia::VectorPlatformDeviceSkia(page_size.width(), page_size.height(), | 59 new skia::VectorPlatformDeviceSkia(pdf_device.get()); |
53 transform); | |
54 data_->current_page_ = device->PdfDevice(); | 60 data_->current_page_ = device->PdfDevice(); |
55 return device; | 61 return device; |
56 } | 62 } |
57 | 63 |
58 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, | 64 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, |
59 const gfx::Point& content_origin, | 65 const gfx::Rect& content_area, |
60 const float& scale_factor) { | 66 const float& scale_factor) { |
61 NOTREACHED(); | 67 NOTREACHED(); |
62 return NULL; | 68 return NULL; |
63 } | 69 } |
64 | 70 |
65 bool PdfMetafileSkia::FinishPage() { | 71 bool PdfMetafileSkia::FinishPage() { |
66 DCHECK(data_->current_page_.get()); | 72 DCHECK(data_->current_page_.get()); |
67 | 73 |
68 data_->pdf_doc_.appendPage(data_->current_page_); | 74 data_->pdf_doc_.appendPage(data_->current_page_); |
69 data_->current_page_ = NULL; | 75 data_->current_page_ = NULL; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 result = false; | 168 result = false; |
163 } | 169 } |
164 } | 170 } |
165 return result; | 171 return result; |
166 } | 172 } |
167 #endif | 173 #endif |
168 | 174 |
169 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} | 175 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} |
170 | 176 |
171 } // namespace printing | 177 } // namespace printing |
OLD | NEW |