Skip to content

Commit

Permalink
Add support to use Skia printing from Mac.
Browse files Browse the repository at this point in the history
Reference the CG metafile from the Skia
version, so CG can be used to pass the PDF
data to the OS X pipeline.

If Skia is enabled as the Mac rendering engine,
generate Skia PDF files instead of CG ones.

This change adds a code path that will be enabled
in the future, but does not modify any existing
code, so there is no functional change.

BUG=79463
TEST=none

Review URL: http://codereview.chromium.org/7120006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90023 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
caryclark@chromium.org committed Jun 22, 2011
1 parent fba70e6 commit b8d85bc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion printing/metafile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#if defined(OS_WIN)
#include "printing/emf_win.h"
#include "printing/pdf_metafile_skia.h"
#elif defined(OS_MACOSX)
#include "printing/pdf_metafile_cg_mac.h"
#elif defined(OS_POSIX)
#include "printing/pdf_metafile_cairo_linux.h"
#endif

#if !defined(OS_MACOSX) || defined(USE_SKIA)
#include "printing/pdf_metafile_skia.h"
#endif

Expand All @@ -21,8 +23,13 @@ namespace printing {
typedef Emf NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
#elif defined(OS_MACOSX)
#if defined(USE_SKIA)
typedef PdfMetafileSkia NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
#else
typedef PdfMetafileCg NativeMetafile;
typedef PdfMetafileCg PreviewMetafile;
#endif
#elif defined(OS_POSIX)
typedef PdfMetafileCairo NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
Expand Down
32 changes: 31 additions & 1 deletion printing/pdf_metafile_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"

#if defined(OS_MACOSX)
#include "printing/pdf_metafile_cg_mac.h"
#endif

namespace printing {

struct PdfMetafileSkiaData {
SkRefPtr<SkPDFDevice> current_page_;
SkPDFDocument pdf_doc_;
SkDynamicMemoryWStream pdf_stream_;
#if defined(OS_MACOSX)
PdfMetafileCg pdf_cg_;
#endif
};

PdfMetafileSkia::~PdfMetafileSkia() {}
Expand Down Expand Up @@ -166,7 +173,30 @@ HENHMETAFILE PdfMetafileSkia::emf() const {
NOTREACHED();
return NULL;
}
#endif // if defined(OS_WIN)
#elif defined(OS_MACOSX)
/* TODO(caryclark): The set up of PluginInstance::PrintPDFOutput may result in
rasterized output. Even if that flow uses PdfMetafileCg::RenderPage,
the drawing of the PDF into the canvas may result in a rasterized output.
PDFMetafileSkia::RenderPage should be not implemented as shown and instead
should do something like the following CL in PluginInstance::PrintPDFOutput:
http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plugin_instance.cc
*/
bool PdfMetafileSkia::RenderPage(unsigned int page_number,
CGContextRef context,
const CGRect rect,
bool shrink_to_fit,
bool stretch_to_fit,
bool center_horizontally,
bool center_vertically) const {
DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
if (data_->pdf_cg_.GetDataSize() == 0)
data_->pdf_cg_.InitFromData(data_->pdf_stream_.getStream(),
data_->pdf_stream_.getOffset());
return data_->pdf_cg_.RenderPage(page_number, context, rect, shrink_to_fit,
stretch_to_fit, center_horizontally,
center_vertically);
}
#endif

#if defined(OS_CHROMEOS)
bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
Expand Down
10 changes: 9 additions & 1 deletion printing/pdf_metafile_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ class PdfMetafileSkia : public Metafile {
virtual bool Playback(gfx::NativeDrawingContext hdc, const RECT* rect) const;
virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const;
virtual HENHMETAFILE emf() const;
#endif // if defined(OS_WIN)
#elif defined(OS_MACOSX)
virtual bool RenderPage(unsigned int page_number,
CGContextRef context,
const CGRect rect,
bool shrink_to_fit,
bool stretch_to_fit,
bool center_horizontally,
bool center_vertically) const;
#endif

#if defined(OS_CHROMEOS)
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
Expand Down

0 comments on commit b8d85bc

Please sign in to comment.