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
3 // found in the LICENSE file.
5 #include "printing/image.h"
7 #include <ApplicationServices/ApplicationServices.h>
11 #include "base/mac/scoped_cftyperef.h"
12 #include "printing/metafile.h"
13 #include "ui/gfx/geometry/rect.h"
17 bool Image::LoadMetafile(const Metafile& metafile) {
18 // Load only the first page of |metafile|, just like Windows.
19 const unsigned int page_number = 1;
20 gfx::Rect rect(metafile.GetPageBounds(page_number));
21 if (rect.width() < 1 || rect.height() < 1)
25 row_length_ = size_.width() * sizeof(uint32_t);
26 size_t bytes = row_length_ * size_.height();
30 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
31 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
32 base::ScopedCFTypeRef<CGContextRef> bitmap_context(
33 CGBitmapContextCreate(&*data_.begin(),
39 kCGImageAlphaPremultipliedLast));
40 DCHECK(bitmap_context.get());
42 struct Metafile::MacRenderPageParams params;
43 params.shrink_to_fit = true;
44 metafile.RenderPage(page_number, bitmap_context, rect.ToCGRect(), params);
48 } // namespace printing