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

Side by Side Diff: printing/image.cc

Issue 6826027: Connect the right metafiles for print preview on Linux and Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile problems Created 9 years, 8 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/image.h ('k') | printing/image_cairo.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/image.h" 5 #include "printing/image.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
11 #include "printing/native_metafile_factory.h" 10 #include "printing/metafile.h"
11 #include "printing/metafile_impl.h"
12 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/gfx/codec/png_codec.h" 13 #include "ui/gfx/codec/png_codec.h"
14 14
15 namespace printing { 15 namespace printing {
16 16
17 Image::Image(const FilePath& path) 17 Image::Image(const FilePath& path)
18 : row_length_(0), 18 : row_length_(0),
19 ignore_alpha_(true) { 19 ignore_alpha_(true) {
20 std::string data; 20 std::string data;
21 file_util::ReadFileToString(path, &data); 21 file_util::ReadFileToString(path, &data);
22 bool success = false; 22 bool success = false;
23 if (path.MatchesExtension(FILE_PATH_LITERAL(".png"))) { 23 if (path.MatchesExtension(FILE_PATH_LITERAL(".png"))) {
24 success = LoadPng(data); 24 success = LoadPng(data);
25 } else if (path.MatchesExtension(FILE_PATH_LITERAL(".emf"))) { 25 } else if (path.MatchesExtension(FILE_PATH_LITERAL(".emf"))) {
26 success = LoadMetafile(data); 26 success = LoadMetafile(data);
27 } else { 27 } else {
28 DCHECK(false); 28 DCHECK(false);
29 } 29 }
30 if (!success) { 30 if (!success) {
31 size_.SetSize(0, 0); 31 size_.SetSize(0, 0);
32 row_length_ = 0; 32 row_length_ = 0;
33 data_.clear(); 33 data_.clear();
34 } 34 }
35 } 35 }
36 36
37 Image::Image(const NativeMetafile& metafile) 37 Image::Image(const Metafile& metafile)
38 : row_length_(0), 38 : row_length_(0),
39 ignore_alpha_(true) { 39 ignore_alpha_(true) {
40 LoadMetafile(metafile); 40 LoadMetafile(metafile);
41 } 41 }
42 42
43 Image::Image(const Image& image) 43 Image::Image(const Image& image)
44 : size_(image.size_), 44 : size_(image.size_),
45 row_length_(image.row_length_), 45 row_length_(image.row_length_),
46 data_(image.data_), 46 data_(image.data_),
47 ignore_alpha_(image.ignore_alpha_) { 47 ignore_alpha_(image.ignore_alpha_) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 bool success = gfx::PNGCodec::Decode( 139 bool success = gfx::PNGCodec::Decode(
140 reinterpret_cast<const unsigned char*>(compressed.c_str()), 140 reinterpret_cast<const unsigned char*>(compressed.c_str()),
141 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); 141 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h);
142 size_.SetSize(w, h); 142 size_.SetSize(w, h);
143 row_length_ = size_.width() * sizeof(uint32); 143 row_length_ = size_.width() * sizeof(uint32);
144 return success; 144 return success;
145 } 145 }
146 146
147 bool Image::LoadMetafile(const std::string& data) { 147 bool Image::LoadMetafile(const std::string& data) {
148 DCHECK(!data.empty()); 148 DCHECK(!data.empty());
149 scoped_ptr<NativeMetafile> metafile( 149 printing::NativeMetafile metafile;
150 printing::NativeMetafileFactory::CreateFromData(data.data(), 150 if (!metafile.InitFromData(data.data(), data.size()))
151 data.size()));
152 if(!metafile.get())
153 return false; 151 return false;
154 return LoadMetafile(*metafile); 152 return LoadMetafile(metafile);
155 } 153 }
156 154
157 } // namespace printing 155 } // namespace printing
OLDNEW
« no previous file with comments | « printing/image.h ('k') | printing/image_cairo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698