diff options
Diffstat (limited to 'printing/image.cc')
-rw-r--r-- | printing/image.cc | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/printing/image.cc b/printing/image.cc index beff637..ba52567 100644 --- a/printing/image.cc +++ b/printing/image.cc @@ -13,6 +13,9 @@ #if defined(OS_WIN) #include "app/gfx/gdi_util.h" // EMF support +#elif defined(OS_MACOSX) +#include <ApplicationServices/ApplicationServices.h> +#include "base/scoped_cftyperef.h" #endif namespace { @@ -97,7 +100,7 @@ std::string Image::checksum() const { return HexEncode(&digest, sizeof(digest)); } -bool Image::SaveToPng(const std::wstring& filename) const { +bool Image::SaveToPng(const FilePath& filepath) const { DCHECK(!data_.empty()); std::vector<unsigned char> compressed; bool success = gfx::PNGCodec::Encode(&*data_.begin(), @@ -110,7 +113,7 @@ bool Image::SaveToPng(const std::wstring& filename) const { DCHECK(success && compressed.size()); if (success) { int write_bytes = file_util::WriteFile( - filename, + filepath, reinterpret_cast<char*>(&*compressed.begin()), compressed.size()); success = (write_bytes == static_cast<int>(compressed.size())); DCHECK(success); @@ -188,7 +191,7 @@ bool Image::LoadPng(const std::string& compressed) { bool Image::LoadMetafile(const std::string& data) { DCHECK(!data.empty()); -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_MACOSX) NativeMetafile metafile; metafile.CreateFromData(data.data(), data.size()); return LoadMetafile(metafile); @@ -229,6 +232,26 @@ bool Image::LoadMetafile(const NativeMetafile& metafile) { DeleteObject(bitmap); return success; } +#elif defined(OS_MACOSX) + // The printing system uses single-page metafiles (page indexes are 1-based). + const unsigned int page_number = 1; + gfx::Rect rect(metafile.GetPageBounds(page_number)); + if (rect.width() > 0 && rect.height() > 0) { + size_ = rect.size(); + row_length_ = size_.width() * sizeof(uint32); + size_t bytes = row_length_ * size_.height(); + DCHECK(bytes); + data_.resize(bytes); + scoped_cftyperef<CGColorSpaceRef> color_space( + CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); + scoped_cftyperef<CGContextRef> bitmap_context( + CGBitmapContextCreate(&*data_.begin(), size_.width(), size_.height(), + 8, row_length_, color_space, + kCGImageAlphaPremultipliedLast)); + DCHECK(bitmap_context.get()); + metafile.RenderPage(page_number, bitmap_context, + CGRectMake(0, 0, size_.width(), size_.height())); + } #else NOTIMPLEMENTED(); #endif |