summaryrefslogtreecommitdiffstats
path: root/printing/image.cc
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-14 20:02:27 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-14 20:02:27 +0000
commit72f966bbd75a095ef73a121e16f5713172b51d09 (patch)
tree6f7404eb02a40fa2337d59a3d5a65b2fe4368d28 /printing/image.cc
parentd5ceb91979a8f47ca1e7e22a608eeaa7db933a14 (diff)
downloadchromium_src-72f966bbd75a095ef73a121e16f5713172b51d09.zip
chromium_src-72f966bbd75a095ef73a121e16f5713172b51d09.tar.gz
chromium_src-72f966bbd75a095ef73a121e16f5713172b51d09.tar.bz2
Enable the RenderViewTest printing tests on the Mac.
Migrates some test APIs from wstring path names to FilePath objects, and fixes some gcc compilation issues, to allow the tests to build on Mac. Moves rendering logic and some other pdf logic into PdfMetafile to avoid duplication with unit test code. Switches rendering from the deprecated CGContextDrawPDFDocument to the newer (but less convenient) CGContextDrawPDFPage. Added debugging helpers to PdfMetafile: SaveTo, matching the other platform metafiles, and context retain count checking to get early warning of issues that will cause printing failure. BUG=24750 TEST=N/A Review URL: http://codereview.chromium.org/274052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/image.cc')
-rw-r--r--printing/image.cc29
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