| OLD | NEW |
| 1 // Copyright (c) 2010 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/emf_win.h" | 5 #include "printing/emf_win.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ExtEscape(dc, escape, size, reinterpret_cast<LPCSTR>(bits), | 43 ExtEscape(dc, escape, size, reinterpret_cast<LPCSTR>(bits), |
| 44 sizeof(supported), reinterpret_cast<LPSTR>(&supported)); | 44 sizeof(supported), reinterpret_cast<LPSTR>(&supported)); |
| 45 } | 45 } |
| 46 return !!supported; | 46 return !!supported; |
| 47 } | 47 } |
| 48 | 48 |
| 49 Emf::Emf() : emf_(NULL), hdc_(NULL) { | 49 Emf::Emf() : emf_(NULL), hdc_(NULL) { |
| 50 } | 50 } |
| 51 | 51 |
| 52 Emf::~Emf() { | 52 Emf::~Emf() { |
| 53 CloseEmf(); | 53 DCHECK(!hdc_); |
| 54 if (emf_) |
| 55 DeleteEnhMetaFile(emf_); |
| 56 } |
| 57 |
| 58 bool Emf::Init() { |
| 54 DCHECK(!emf_ && !hdc_); | 59 DCHECK(!emf_ && !hdc_); |
| 60 hdc_ = CreateEnhMetaFile(NULL, NULL, NULL, NULL); |
| 61 DCHECK(hdc_); |
| 62 return hdc_ != NULL; |
| 55 } | 63 } |
| 56 | 64 |
| 57 bool Emf::Init(const void* src_buffer, uint32 src_buffer_size) { | 65 bool Emf::Init(const void* src_buffer, uint32 src_buffer_size) { |
| 58 DCHECK(!emf_ && !hdc_); | 66 DCHECK(!emf_ && !hdc_); |
| 59 emf_ = SetEnhMetaFileBits(src_buffer_size, | 67 emf_ = SetEnhMetaFileBits(src_buffer_size, |
| 60 reinterpret_cast<const BYTE*>(src_buffer)); | 68 reinterpret_cast<const BYTE*>(src_buffer)); |
| 61 return emf_ != NULL; | 69 return emf_ != NULL; |
| 62 } | 70 } |
| 63 | 71 |
| 64 bool Emf::CreateDc(HDC sibling, const RECT* rect) { | 72 bool Emf::Init(const FilePath& metafile_path) { |
| 65 DCHECK(!emf_ && !hdc_); | |
| 66 hdc_ = CreateEnhMetaFile(sibling, NULL, rect, NULL); | |
| 67 DCHECK(hdc_); | |
| 68 return hdc_ != NULL; | |
| 69 } | |
| 70 | |
| 71 bool Emf::CreateFileBackedDc(HDC sibling, const RECT* rect, | |
| 72 const FilePath& path) { | |
| 73 DCHECK(!emf_ && !hdc_); | |
| 74 DCHECK(!path.empty()); | |
| 75 hdc_ = CreateEnhMetaFile(sibling, path.value().c_str(), rect, NULL); | |
| 76 DCHECK(hdc_); | |
| 77 return hdc_ != NULL; | |
| 78 } | |
| 79 | |
| 80 bool Emf::CreateFromFile(const FilePath& metafile_path) { | |
| 81 DCHECK(!emf_ && !hdc_); | 73 DCHECK(!emf_ && !hdc_); |
| 82 emf_ = GetEnhMetaFile(metafile_path.value().c_str()); | 74 emf_ = GetEnhMetaFile(metafile_path.value().c_str()); |
| 83 DCHECK(emf_); | 75 DCHECK(emf_); |
| 84 return emf_ != NULL; | 76 return emf_ != NULL; |
| 85 } | 77 } |
| 86 | 78 |
| 87 | |
| 88 bool Emf::Close() { | 79 bool Emf::Close() { |
| 89 DCHECK(!emf_ && hdc_); | 80 DCHECK(!emf_ && hdc_); |
| 90 emf_ = CloseEnhMetaFile(hdc_); | 81 emf_ = CloseEnhMetaFile(hdc_); |
| 91 DCHECK(emf_); | 82 DCHECK(emf_); |
| 92 hdc_ = NULL; | 83 hdc_ = NULL; |
| 93 return emf_ != NULL; | 84 return emf_ != NULL; |
| 94 } | 85 } |
| 95 | 86 |
| 96 void Emf::CloseEmf() { | |
| 97 DCHECK(!hdc_); | |
| 98 if (emf_) { | |
| 99 DeleteEnhMetaFile(emf_); | |
| 100 emf_ = NULL; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 bool Emf::Playback(HDC hdc, const RECT* rect) const { | 87 bool Emf::Playback(HDC hdc, const RECT* rect) const { |
| 105 DCHECK(emf_ && !hdc_); | 88 DCHECK(emf_ && !hdc_); |
| 106 RECT bounds; | 89 RECT bounds; |
| 107 if (!rect) { | 90 if (!rect) { |
| 108 // Get the natural bounds of the EMF buffer. | 91 // Get the natural bounds of the EMF buffer. |
| 109 bounds = GetPageBounds(1).ToRECT(); | 92 bounds = GetPageBounds(1).ToRECT(); |
| 110 rect = &bounds; | 93 rect = &bounds; |
| 111 } | 94 } |
| 112 return PlayEnhMetaFile(hdc, emf_, rect) != 0; | 95 return PlayEnhMetaFile(hdc, emf_, rect) != 0; |
| 113 } | 96 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } else { | 450 } else { |
| 468 DCHECK_EQ(emf.context_.handle_table, handle_table); | 451 DCHECK_EQ(emf.context_.handle_table, handle_table); |
| 469 DCHECK_EQ(emf.context_.objects_count, objects_count); | 452 DCHECK_EQ(emf.context_.objects_count, objects_count); |
| 470 DCHECK_EQ(emf.context_.hdc, hdc); | 453 DCHECK_EQ(emf.context_.hdc, hdc); |
| 471 } | 454 } |
| 472 emf.items_.push_back(Record(&emf.context_, record)); | 455 emf.items_.push_back(Record(&emf.context_, record)); |
| 473 return 1; | 456 return 1; |
| 474 } | 457 } |
| 475 | 458 |
| 476 } // namespace printing | 459 } // namespace printing |
| OLD | NEW |