| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/metafile.h" | 5 #include "printing/metafile.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 | 11 |
| 12 namespace printing { | 12 namespace printing { |
| 13 | 13 |
| 14 MetafilePlayer::MetafilePlayer() { | 14 MetafilePlayer::MetafilePlayer() { |
| 15 } | 15 } |
| 16 | 16 |
| 17 MetafilePlayer::~MetafilePlayer() { | 17 MetafilePlayer::~MetafilePlayer() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 Metafile::Metafile() { | 20 Metafile::Metafile() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 Metafile::~Metafile() { | 23 Metafile::~Metafile() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 skia::RefPtr<skia::VectorCanvas> Metafile::GetVectorCanvasForNewPage( |
| 27 const gfx::Size& page_size, const gfx::Rect& content_area, |
| 28 const float& scale_factor) { |
| 29 SkBaseDevice* device = |
| 30 this->StartPageForVectorCanvas(page_size, content_area, scale_factor); |
| 31 if (!device) return skia::RefPtr<skia::VectorCanvas>(/*NULL*/); |
| 32 return skia::AdoptRef(new skia::VectorCanvas(device)); |
| 33 } |
| 34 |
| 26 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const { | 35 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const { |
| 27 buffer->resize(GetDataSize()); | 36 buffer->resize(GetDataSize()); |
| 28 if (buffer->empty()) | 37 if (buffer->empty()) |
| 29 return false; | 38 return false; |
| 30 return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size())); | 39 return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size())); |
| 31 } | 40 } |
| 32 | 41 |
| 33 bool Metafile::SaveTo(base::File* file) const { | 42 bool Metafile::SaveTo(base::File* file) const { |
| 34 if (!file->IsValid()) | 43 if (!file->IsValid()) |
| 35 return false; | 44 return false; |
| 36 | 45 |
| 37 std::vector<char> buffer; | 46 std::vector<char> buffer; |
| 38 if (!GetDataAsVector(&buffer)) | 47 if (!GetDataAsVector(&buffer)) |
| 39 return false; | 48 return false; |
| 40 | 49 |
| 41 int size = base::checked_cast<int>(buffer.size()); | 50 int size = base::checked_cast<int>(buffer.size()); |
| 42 if (file->WriteAtCurrentPos(&buffer[0], size) != size) { | 51 if (file->WriteAtCurrentPos(&buffer[0], size) != size) { |
| 43 DLOG(ERROR) << "Failed to save file."; | 52 DLOG(ERROR) << "Failed to save file."; |
| 44 return false; | 53 return false; |
| 45 } | 54 } |
| 46 return true; | 55 return true; |
| 47 } | 56 } |
| 48 | 57 |
| 49 } // namespace printing | 58 } // namespace printing |
| OLD | NEW |