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

Side by Side Diff: printing/image_mac.cc

Issue 2802093006: printing::Metafile: Simplify OS_MACOSX-specific code path (Closed)
Patch Set: vectoriz Created 3 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
« no previous file with comments | « no previous file | printing/metafile.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreFoundation/CoreFoundation.h>
8 #include <stddef.h> 9 #include <stddef.h>
9 #include <stdint.h> 10 #include <stdint.h>
10 11
11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
12 #include "printing/metafile.h" 13 #include "printing/metafile.h"
14 #include "printing/pdf_metafile_cg_mac.h"
13 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
14 16
15 namespace printing { 17 namespace printing {
16 18
17 bool Image::LoadMetafile(const Metafile& metafile) { 19 bool Image::LoadMetafile(const Metafile& metafile) {
18 // The printing system uses single-page metafiles (page indexes are 1-based). 20 // The printing system uses single-page metafiles (page indexes are 1-based).
19 const unsigned int page_number = 1; 21 const unsigned int page_number = 1;
20 gfx::Rect rect(metafile.GetPageBounds(page_number)); 22 gfx::Rect rect(metafile.GetPageBounds(page_number));
21 if (rect.width() < 1 || rect.height() < 1) 23 if (rect.width() < 1 || rect.height() < 1)
22 return false; 24 return false;
23 25
24 size_ = rect.size(); 26 size_ = rect.size();
25 row_length_ = size_.width() * sizeof(uint32_t); 27 row_length_ = size_.width() * sizeof(uint32_t);
26 size_t bytes = row_length_ * size_.height(); 28 size_t bytes = row_length_ * size_.height();
27 DCHECK(bytes); 29 DCHECK(bytes);
28 30
29 data_.resize(bytes); 31 data_.resize(bytes);
30 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( 32 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
31 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); 33 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
32 base::ScopedCFTypeRef<CGContextRef> bitmap_context( 34 base::ScopedCFTypeRef<CGContextRef> bitmap_context(
33 CGBitmapContextCreate(&*data_.begin(), 35 CGBitmapContextCreate(&*data_.begin(),
34 size_.width(), 36 size_.width(),
35 size_.height(), 37 size_.height(),
36 8, 38 8,
37 row_length_, 39 row_length_,
38 color_space, 40 color_space,
39 kCGImageAlphaPremultipliedLast)); 41 kCGImageAlphaPremultipliedLast));
40 DCHECK(bitmap_context.get()); 42 DCHECK(bitmap_context.get());
41 43
42 struct Metafile::MacRenderPageParams params; 44 PdfMetafileCg::RenderPageParams params;
43 params.shrink_to_fit = true; 45 params.shrink_to_fit = true;
44 metafile.RenderPage(page_number, bitmap_context, 46 CGRect cg_rect = CGRectMake(0, 0, size_.width(), size_.height());
45 CGRectMake(0, 0, size_.width(), size_.height()), params); 47 std::vector<char> buffer;
46 48 return metafile.GetDataAsVector(&buffer) &&
47 return true; 49 PdfMetafileCg::RenderPage(buffer, page_number, bitmap_context, cg_rect,
50 params);
48 } 51 }
49 52
50 } // namespace printing 53 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | printing/metafile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698