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

Side by Side Diff: printing/image_mac.cc

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