| 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::Size& content_size, |
| 41 const float& scale_factor) { | 41 const gfx::Point& content_origin, 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_origin.x()), |
| 47 SkIntToScalar(content_origin.y())); | 47 SkIntToScalar(content_origin.y())); |
| 48 transform.preScale(SkFloatToScalar(scale_factor), | 48 transform.preScale(SkFloatToScalar(scale_factor), |
| 49 SkFloatToScalar(scale_factor)); | 49 SkFloatToScalar(scale_factor)); |
| 50 | 50 |
| 51 SkRefPtr<SkPDFDevice> pdf_device = |
| 52 new SkPDFDevice(SkSize::Make( |
| 53 SkIntToScalar(page_size.width()), |
| 54 SkIntToScalar(page_size.height())), |
| 55 SkSize::Make( |
| 56 SkIntToScalar(content_size.width()), |
| 57 SkIntToScalar(content_size.height())), transform); |
| 58 pdf_device->unref(); // SkRefPtr and new both took a reference. |
| 51 skia::VectorPlatformDeviceSkia* device = | 59 skia::VectorPlatformDeviceSkia* device = |
| 52 new skia::VectorPlatformDeviceSkia(page_size.width(), page_size.height(), | 60 new skia::VectorPlatformDeviceSkia(pdf_device.get(), transform); |
| 53 transform); | |
| 54 data_->current_page_ = device->PdfDevice(); | 61 data_->current_page_ = device->PdfDevice(); |
| 55 return device; | 62 return device; |
| 56 } | 63 } |
| 57 | 64 |
| 58 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, | 65 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, |
| 59 const gfx::Point& content_origin, | 66 const gfx::Point& content_origin, |
| 60 const float& scale_factor) { | 67 const float& scale_factor) { |
| 61 NOTREACHED(); | 68 NOTREACHED(); |
| 62 return NULL; | 69 return NULL; |
| 63 } | 70 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 result = false; | 169 result = false; |
| 163 } | 170 } |
| 164 } | 171 } |
| 165 return result; | 172 return result; |
| 166 } | 173 } |
| 167 #endif | 174 #endif |
| 168 | 175 |
| 169 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} | 176 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} |
| 170 | 177 |
| 171 } // namespace printing | 178 } // namespace printing |
| OLD | NEW |