Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1048)

Side by Side Diff: printing/emf_win.cc

Issue 6695013: Cleanup NativeMetafile (win) interface and EMF class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/emf_win.h ('k') | printing/emf_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 ExtEscape(dc, escape, size, reinterpret_cast<LPCSTR>(bits), 46 ExtEscape(dc, escape, size, reinterpret_cast<LPCSTR>(bits),
47 sizeof(supported), reinterpret_cast<LPSTR>(&supported)); 47 sizeof(supported), reinterpret_cast<LPSTR>(&supported));
48 } 48 }
49 return !!supported; 49 return !!supported;
50 } 50 }
51 51
52 Emf::Emf() : emf_(NULL), hdc_(NULL) { 52 Emf::Emf() : emf_(NULL), hdc_(NULL) {
53 } 53 }
54 54
55 Emf::~Emf() { 55 Emf::~Emf() {
56 CloseEmf(); 56 DCHECK(!hdc_);
57 if (emf_)
58 DeleteEnhMetaFile(emf_);
59 }
60
61 bool Emf::InitToFile(const FilePath& metafile_path) {
57 DCHECK(!emf_ && !hdc_); 62 DCHECK(!emf_ && !hdc_);
63 hdc_ = CreateEnhMetaFile(NULL, metafile_path.value().c_str(), NULL, NULL);
64 DCHECK(hdc_);
65 return hdc_ != NULL;
66 }
67
68 bool Emf::InitFromFile(const FilePath& metafile_path) {
69 DCHECK(!emf_ && !hdc_);
70 emf_ = GetEnhMetaFile(metafile_path.value().c_str());
71 DCHECK(emf_);
72 return emf_ != NULL;
73 }
74
75 bool Emf::Init() {
76 DCHECK(!emf_ && !hdc_);
77 hdc_ = CreateEnhMetaFile(NULL, NULL, NULL, NULL);
78 DCHECK(hdc_);
79 return hdc_ != NULL;
58 } 80 }
59 81
60 bool Emf::InitFromData(const void* src_buffer, uint32 src_buffer_size) { 82 bool Emf::InitFromData(const void* src_buffer, uint32 src_buffer_size) {
61 DCHECK(!emf_ && !hdc_); 83 DCHECK(!emf_ && !hdc_);
62 emf_ = SetEnhMetaFileBits(src_buffer_size, 84 emf_ = SetEnhMetaFileBits(src_buffer_size,
63 reinterpret_cast<const BYTE*>(src_buffer)); 85 reinterpret_cast<const BYTE*>(src_buffer));
64 return emf_ != NULL; 86 return emf_ != NULL;
65 } 87 }
66 88
67 bool Emf::CreateDc(HDC sibling, const RECT* rect) {
68 DCHECK(!emf_ && !hdc_);
69 hdc_ = CreateEnhMetaFile(sibling, NULL, rect, NULL);
70 DCHECK(hdc_);
71 return hdc_ != NULL;
72 }
73
74 bool Emf::CreateFileBackedDc(HDC sibling, const RECT* rect,
75 const FilePath& path) {
76 DCHECK(!emf_ && !hdc_);
77 DCHECK(!path.empty());
78 hdc_ = CreateEnhMetaFile(sibling, path.value().c_str(), rect, NULL);
79 DCHECK(hdc_);
80 return hdc_ != NULL;
81 }
82
83 bool Emf::CreateFromFile(const FilePath& metafile_path) {
84 DCHECK(!emf_ && !hdc_);
85 emf_ = GetEnhMetaFile(metafile_path.value().c_str());
86 DCHECK(emf_);
87 return emf_ != NULL;
88 }
89
90
91 bool Emf::FinishDocument() { 89 bool Emf::FinishDocument() {
92 DCHECK(!emf_ && hdc_); 90 DCHECK(!emf_ && hdc_);
93 emf_ = CloseEnhMetaFile(hdc_); 91 emf_ = CloseEnhMetaFile(hdc_);
94 DCHECK(emf_); 92 DCHECK(emf_);
95 hdc_ = NULL; 93 hdc_ = NULL;
96 return emf_ != NULL; 94 return emf_ != NULL;
97 } 95 }
98 96
99 void Emf::CloseEmf() {
100 DCHECK(!hdc_);
101 if (emf_) {
102 DeleteEnhMetaFile(emf_);
103 emf_ = NULL;
104 }
105 }
106
107 bool Emf::Playback(HDC hdc, const RECT* rect) const { 97 bool Emf::Playback(HDC hdc, const RECT* rect) const {
108 DCHECK(emf_ && !hdc_); 98 DCHECK(emf_ && !hdc_);
109 RECT bounds; 99 RECT bounds;
110 if (!rect) { 100 if (!rect) {
111 // Get the natural bounds of the EMF buffer. 101 // Get the natural bounds of the EMF buffer.
112 bounds = GetPageBounds(1).ToRECT(); 102 bounds = GetPageBounds(1).ToRECT();
113 rect = &bounds; 103 rect = &bounds;
114 } 104 }
115 return PlayEnhMetaFile(hdc, emf_, rect) != 0; 105 return PlayEnhMetaFile(hdc, emf_, rect) != 0;
116 } 106 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } else { 474 } else {
485 DCHECK_EQ(emf.context_.handle_table, handle_table); 475 DCHECK_EQ(emf.context_.handle_table, handle_table);
486 DCHECK_EQ(emf.context_.objects_count, objects_count); 476 DCHECK_EQ(emf.context_.objects_count, objects_count);
487 DCHECK_EQ(emf.context_.hdc, hdc); 477 DCHECK_EQ(emf.context_.hdc, hdc);
488 } 478 }
489 emf.items_.push_back(Record(&emf.context_, record)); 479 emf.items_.push_back(Record(&emf.context_, record));
490 return 1; 480 return 1;
491 } 481 }
492 482
493 } // namespace printing 483 } // namespace printing
OLDNEW
« no previous file with comments | « printing/emf_win.h ('k') | printing/emf_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698