0

Connect the right metafiles for print preview on Linux and Windows.

+ Remove the NativeMetafileFactory since we can't just use preview flag.
+ Update each Metafile constructor site to use PreviewMetafile or NativeMetafileImpl.
+ Fix misc. problems blocking pdf generation on Windows.
+ Rename the metafile interface.

BUG=NONE
TEST=NONE

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81161 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
vandebo@chromium.org
2011-04-11 21:54:06 +00:00
parent 03e204f307
commit 7d748990b3
43 changed files with 302 additions and 410 deletions

@ -17,6 +17,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "printing/metafile.h"
#include "printing/print_settings_initializer_gtk.h"
// static
@ -85,7 +86,7 @@ void PrintDialogGtk::ShowDialog(
gtk_widget_show(dialog_);
}
void PrintDialogGtk::PrintDocument(const NativeMetafile* metafile,
void PrintDialogGtk::PrintDocument(const printing::Metafile* metafile,
const string16& document_name) {
// This runs on the print worker thread, does not block the UI thread.
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
@ -164,7 +165,7 @@ void PrintDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
}
}
void PrintDialogGtk::SaveDocumentToDisk(const NativeMetafile* metafile,
void PrintDialogGtk::SaveDocumentToDisk(const printing::Metafile* metafile,
const string16& document_name) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));

@ -13,7 +13,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/browser_thread.h"
#include "printing/native_metafile.h"
#include "printing/print_dialog_gtk_interface.h"
#include "printing/printing_context_cairo.h"
#include "ui/base/gtk/gtk_signal.h"
@ -22,7 +21,10 @@ namespace base {
class WaitableEvent;
}
using printing::NativeMetafile;
namespace printing {
class Metafile;
}
using printing::PrintingContextCairo;
// Needs to be freed on the UI thread to clean up its GTK members variables.
@ -38,7 +40,7 @@ class PrintDialogGtk
// printing::PrintDialogGtkInterface implementation.
virtual void ShowDialog(
PrintingContextCairo::PrintSettingsCallback* callback);
virtual void PrintDocument(const NativeMetafile* metafile,
virtual void PrintDocument(const printing::Metafile* metafile,
const string16& document_name);
virtual void AddRefToDialog();
virtual void ReleaseDialog();
@ -54,7 +56,7 @@ class PrintDialogGtk
CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int);
// Saves data in |metafile| to disk for document named |document_name|.
void SaveDocumentToDisk(const NativeMetafile* metafile,
void SaveDocumentToDisk(const printing::Metafile* metafile,
const string16& document_name);
// Prints document named |document_name|.

@ -19,8 +19,8 @@
#include "content/common/notification_details.h"
#include "content/common/notification_source.h"
#include "grit/generated_resources.h"
#include "printing/native_metafile.h"
#include "printing/native_metafile_factory.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "printing/printed_document.h"
#include "ui/base/l10n/l10n_util.h"
@ -146,11 +146,9 @@ void PrintViewManager::OnDidPrintPage(
}
}
scoped_ptr<NativeMetafile> metafile;
scoped_ptr<Metafile> metafile(new NativeMetafile);
if (metafile_must_be_valid) {
metafile.reset(NativeMetafileFactory::CreateFromData(shared_buf.memory(),
params.data_size));
if (!metafile.get()) {
if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
NOTREACHED() << "Invalid metafile header";
tab_contents()->Stop();
return;

@ -18,8 +18,8 @@
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "printing/backend/print_backend.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "printing/print_job_constants.h"
namespace {
@ -121,7 +121,7 @@ class EnumeratePrintersTaskProxy
class PrintToPdfTask : public Task {
public:
// Takes ownership of |metafile|.
PrintToPdfTask(printing::NativeMetafile* metafile, const FilePath& path)
PrintToPdfTask(printing::Metafile* metafile, const FilePath& path)
: metafile_(metafile), path_(path) {
}
@ -134,7 +134,7 @@ class PrintToPdfTask : public Task {
private:
// The metafile holding the PDF data.
scoped_ptr<printing::NativeMetafile> metafile_;
scoped_ptr<printing::Metafile> metafile_;
// The absolute path where the file will be saved.
FilePath path_;
@ -262,21 +262,15 @@ void PrintPreviewHandler::SelectFile() {
void PrintPreviewHandler::FileSelected(const FilePath& path,
int index, void* params) {
#if defined(OS_POSIX)
PrintPreviewUIHTMLSource::PrintPreviewData data;
PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_);
pp_ui->html_source()->GetPrintPreviewData(&data);
DCHECK(data.first != NULL);
DCHECK(data.second > 0);
printing::NativeMetafile* metafile =
printing::NativeMetafileFactory::CreateFromData(data.first->memory(),
data.second);
metafile->FinishDocument();
printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
metafile->InitFromData(data.first->memory(), data.second);
PrintToPdfTask* task = new PrintToPdfTask(metafile, path);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task);
#else
NOTIMPLEMENTED();
#endif
}

@ -18,11 +18,6 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/rect.h"
#if defined(OS_WIN)
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#endif
// Tests that serialize/deserialize correctly understand each other
TEST(IPCMessageTest, Serialize) {
const char* serialize_cases[] = {

@ -8,8 +8,7 @@
#include "base/shared_memory.h"
#include "chrome/common/print_messages.h"
#include "ipc/ipc_message_utils.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile_impl.h"
#include "printing/units.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -137,11 +136,9 @@ void MockPrinter::PrintPage(const PrintHostMsg_DidPrintPage_Params& params) {
base::SharedMemory metafile_data(params.metafile_data_handle, true);
#endif
metafile_data.Map(params.data_size);
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::CreateFromData(metafile_data.memory(),
params.data_size));
CHECK(metafile.get());
printing::Image image(*metafile);
printing::NativeMetafile metafile;
metafile.InitFromData(metafile_data.memory(), params.data_size);
printing::Image image(metafile);
MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(),
params.data_size,
image);

@ -15,6 +15,7 @@
#include "content/common/view_messages.h"
#include "content/renderer/render_view.h"
#include "grit/generated_resources.h"
#include "printing/metafile.h"
#include "printing/units.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@ -636,7 +637,7 @@ void PrintWebViewHelper::RenderPagesForPreview(WebKit::WebFrame* frame,
#if defined(OS_POSIX)
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
printing::NativeMetafile* metafile,
printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemoryHandle mem_handle;

@ -11,7 +11,7 @@
#include "base/time.h"
#include "content/renderer/render_view_observer.h"
#include "content/renderer/render_view_observer_tracker.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
#include "ui/gfx/size.h"
@ -152,7 +152,7 @@ class PrintWebViewHelper : public RenderViewObserver ,
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebKit::WebFrame* frame,
printing::NativeMetafile* metafile,
printing::Metafile* metafile,
scoped_ptr<skia::VectorCanvas>* canvas);
#else
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
@ -177,25 +177,25 @@ class PrintWebViewHelper : public RenderViewObserver ,
#if defined(OS_WIN)
void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
int page_number, WebKit::WebFrame* frame,
scoped_ptr<printing::NativeMetafile>* metafile);
scoped_ptr<printing::Metafile>* metafile);
#elif defined(OS_MACOSX)
void RenderPage(const gfx::Size& page_size, const gfx::Point& content_origin,
const float& scale_factor, int page_number,
WebKit::WebFrame* frame, printing::NativeMetafile* metafile);
WebKit::WebFrame* frame, printing::Metafile* metafile);
#elif defined(OS_POSIX)
bool RenderPages(const PrintMsg_PrintPages_Params& params,
WebKit::WebFrame* frame,
WebKit::WebNode* node,
bool send_expected_page_count,
int* page_count,
printing::NativeMetafile* metafile);
printing::Metafile* metafile);
#endif // defined(OS_WIN)
// Helper methods -----------------------------------------------------------
bool CopyAndPrint(WebKit::WebFrame* web_frame);
bool CopyMetafileDataToSharedMem(printing::NativeMetafile* metafile,
bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle);
static void GetPageSizeAndMarginsInPoints(

@ -9,9 +9,9 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/common/print_messages.h"
#include "content/common/view_messages.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile_skia_wrapper.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "printing/metafile_skia_wrapper.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "ui/gfx/point.h"
@ -26,17 +26,16 @@ using WebKit::WebNode;
void PrintWebViewHelper::CreatePreviewDocument(
const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame,
WebKit::WebNode* node) {
// We only can use PDF in the renderer because Cairo needs to create a
// temporary file for a PostScript surface.
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
int page_count = 0;
printing::PreviewMetafile metafile;
if (!metafile.Init())
return;
if (!RenderPages(params, frame, node, false, &page_count, metafile.get()))
if (!RenderPages(params, frame, node, false, &page_count, &metafile))
return;
// Get the size of the resulting metafile.
uint32 buf_size = metafile->GetDataSize();
uint32 buf_size = metafile.GetDataSize();
DCHECK_GT(buf_size, 0u);
PrintHostMsg_DidPreviewDocument_Params preview_params;
@ -44,7 +43,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
preview_params.expected_pages_count = page_count;
preview_params.data_size = buf_size;
if (!CopyMetafileDataToSharedMem(metafile.get(),
if (!CopyMetafileDataToSharedMem(&metafile,
&(preview_params.metafile_data_handle))) {
preview_params.expected_pages_count = 0;
preview_params.data_size = 0;
@ -55,10 +54,6 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
WebFrame* frame,
WebNode* node) {
// We only can use PDF in the renderer because Cairo needs to create a
// temporary file for a PostScript surface.
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
int page_count = 0;
bool send_expected_page_count =
#if defined(OS_CHROMEOS)
@ -67,13 +62,17 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
true;
#endif // defined(OS_CHROMEOS)
printing::NativeMetafile metafile;
if (!metafile.Init())
return;
if (!RenderPages(params, frame, node, send_expected_page_count, &page_count,
metafile.get())) {
&metafile)) {
return;
}
// Get the size of the resulting metafile.
uint32 buf_size = metafile->GetDataSize();
uint32 buf_size = metafile.GetDataSize();
DCHECK_GT(buf_size, 0u);
#if defined(OS_CHROMEOS)
@ -85,7 +84,7 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
&sequence_number))) {
return;
}
if (!metafile->SaveToFD(fd))
if (!metafile.SaveToFD(fd))
return;
// Tell the browser we've finished writing the file.
@ -112,7 +111,7 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
NOTREACHED() << "Map failed";
return;
}
metafile->GetData(shared_buf.memory(), buf_size);
metafile.GetData(shared_buf.memory(), buf_size);
printed_page_params.data_size = buf_size;
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(),
&(printed_page_params.metafile_data_handle));
@ -149,7 +148,7 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
WebKit::WebNode* node,
bool send_expected_page_count,
int* page_count,
printing::NativeMetafile* metafile) {
printing::Metafile* metafile) {
PrintMsg_Print_Params printParams = params.params;
scoped_ptr<skia::VectorCanvas> canvas;
@ -197,7 +196,7 @@ void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame,
printing::NativeMetafile* metafile,
printing::Metafile* metafile,
scoped_ptr<skia::VectorCanvas>* canvas) {
double content_width_in_points;
double content_height_in_points;
@ -228,8 +227,7 @@ void PrintWebViewHelper::PrintPageInternal(
return;
canvas->reset(new skia::VectorCanvas(device));
printing::NativeMetafileSkiaWrapper::SetMetafileOnCanvas(canvas->get(),
metafile);
printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas->get(), metafile);
frame->printPage(params.page_number, canvas->get());
// TODO(myhuang): We should handle transformation for paper margins.

@ -7,10 +7,9 @@
#import <AppKit/AppKit.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/common/print_messages.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
using WebKit::WebFrame;
@ -19,9 +18,8 @@ void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame) {
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
if(!metafile.get())
printing::NativeMetafile metafile;
if (!metafile.Init())
return;
float scale_factor = frame->getPrintPageShrink(params.page_number);
@ -30,11 +28,11 @@ void PrintWebViewHelper::PrintPageInternal(
// Render page for printing.
gfx::Point origin(0.0f, 0.0f);
RenderPage(params.params.printable_size, origin, scale_factor, page_number,
frame, metafile.get());
metafile->FinishDocument();
frame, &metafile);
metafile.FinishDocument();
PrintHostMsg_DidPrintPage_Params page_params;
page_params.data_size = metafile->GetDataSize();
page_params.data_size = metafile.GetDataSize();
page_params.page_number = page_number;
page_params.document_cookie = params.params.document_cookie;
page_params.actual_shrink = scale_factor;
@ -45,7 +43,7 @@ void PrintWebViewHelper::PrintPageInternal(
params.params.printable_size.height());
// Ask the browser to create the shared memory for us.
if (!CopyMetafileDataToSharedMem(metafile.get(),
if (!CopyMetafileDataToSharedMem(&metafile,
&(page_params.metafile_data_handle))) {
page_params.data_size = 0;
}
@ -66,9 +64,8 @@ void PrintWebViewHelper::CreatePreviewDocument(
if (!page_count)
return;
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
if(!metafile.get())
printing::PreviewMetafile metafile;
if (!metafile.Init())
return;
float scale_factor = frame->getPrintPageShrink(0);
@ -76,26 +73,26 @@ void PrintWebViewHelper::CreatePreviewDocument(
if (params.pages.empty()) {
for (int i = 0; i < page_count; ++i) {
RenderPage(printParams.page_size, origin, scale_factor, i, frame,
metafile.get());
&metafile);
}
} else {
for (size_t i = 0; i < params.pages.size(); ++i) {
if (params.pages[i] >= page_count)
break;
RenderPage(printParams.page_size, origin, scale_factor,
static_cast<int>(params.pages[i]), frame, metafile.get());
static_cast<int>(params.pages[i]), frame, &metafile);
}
}
metafile->FinishDocument();
metafile.FinishDocument();
PrintHostMsg_DidPreviewDocument_Params preview_params;
preview_params.data_size = metafile->GetDataSize();
preview_params.data_size = metafile.GetDataSize();
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = page_count;
// Ask the browser to create the shared memory for us.
if (!CopyMetafileDataToSharedMem(metafile.get(),
&(preview_params.metafile_data_handle))) {
if (!CopyMetafileDataToSharedMem(&metafile,
&(preview_params.metafile_data_handle))) {
preview_params.data_size = 0;
preview_params.expected_pages_count = 0;
}
@ -105,7 +102,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::RenderPage(
const gfx::Size& page_size, const gfx::Point& content_origin,
const float& scale_factor, int page_number, WebFrame* frame,
printing::NativeMetafile* metafile) {
printing::Metafile* metafile) {
bool success = metafile->StartPage(page_size, content_origin, scale_factor);
DCHECK(success);

@ -6,9 +6,10 @@
#include "base/logging.h"
#include "base/process_util.h"
#include "base/scoped_ptr.h"
#include "chrome/common/print_messages.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "printing/units.h"
#include "skia/ext/vector_canvas.h"
#include "skia/ext/vector_platform_device_emf_win.h"
@ -72,8 +73,8 @@ void PrintWebViewHelper::PrintPageInternal(
WebFrame* frame) {
// Generate a memory-based metafile. It will use the current screen's DPI.
// Each metafile contains a single page.
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
scoped_ptr<printing::Metafile> metafile(new printing::NativeMetafile);
metafile->Init();
DCHECK(metafile->context());
skia::PlatformDevice::InitializeDC(metafile->context());
@ -131,38 +132,28 @@ void PrintWebViewHelper::CreatePreviewDocument(
if (!page_count)
return;
// NOTE: This is an enhanced-format metafile(EMF) which has an appearance of
// single page metafile. For print preview, we need a metafile with multiple
// pages.
// TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia
// PDF backend" work is completed for windows, make changes to replace this
// EMF with PDF metafile.
// http://code.google.com/p/chromium/issues/detail?id=62889
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
DCHECK(metafile->context());
skia::PlatformDevice::InitializeDC(metafile->context());
scoped_ptr<printing::Metafile> metafile(new printing::PreviewMetafile);
metafile->Init();
// Calculate the dpi adjustment.
float shrink = static_cast<float>(params.params.desired_dpi /
params.params.dpi);
float shrink = static_cast<float>(print_params.desired_dpi /
print_params.dpi);
if (params.pages.empty()) {
for (int i = 0; i < page_count; ++i) {
float scale_factor = shrink;
RenderPage(params.params, &scale_factor, i, frame, &metafile);
RenderPage(print_params, &scale_factor, i, frame, &metafile);
}
} else {
for (size_t i = 0; i < params.pages.size(); ++i) {
if (params.pages[i] >= page_count)
break;
float scale_factor = shrink;
RenderPage(params.params, &scale_factor,
RenderPage(print_params, &scale_factor,
static_cast<int>(params.pages[i]), frame, &metafile);
}
}
// Close the device context to retrieve the compiled metafile.
if (!metafile->FinishDocument())
NOTREACHED();
@ -192,9 +183,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::RenderPage(
const PrintMsg_Print_Params& params, float* scale_factor, int page_number,
WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
DCHECK(metafile->get()->context());
WebFrame* frame, scoped_ptr<printing::Metafile>* metafile) {
double content_width_in_points;
double content_height_in_points;
double margin_top_in_points;
@ -231,59 +220,63 @@ void PrintWebViewHelper::RenderPage(
bool result = (*metafile)->FinishPage();
DCHECK(result);
skia::VectorPlatformDeviceEmf* platform_device =
static_cast<skia::VectorPlatformDeviceEmf*>(device);
if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
// Currently, we handle alpha blend transparency for a single page.
// Therefore, expecting a metafile with page count 1.
DCHECK((*metafile)->GetPageCount() == 1);
if (!params.supports_alpha_blend) {
// PreviewMetafile (PDF) supports alpha blend, so we only hit this case
// for NativeMetafile.
skia::VectorPlatformDeviceEmf* platform_device =
static_cast<skia::VectorPlatformDeviceEmf*>(device);
if (platform_device->alpha_blend_used()) {
// Currently, we handle alpha blend transparency for a single page.
// Therefore, expecting a metafile with page count 1.
DCHECK_EQ(1U, (*metafile)->GetPageCount());
// Close the device context to retrieve the compiled metafile.
if (!(*metafile)->FinishDocument())
NOTREACHED();
// Close the device context to retrieve the compiled metafile.
if (!(*metafile)->FinishDocument())
NOTREACHED();
scoped_ptr<printing::NativeMetafile> metafile2(
printing::NativeMetafileFactory::Create());
// Page used alpha blend, but printer doesn't support it. Rewrite the
// metafile and flatten out the transparency.
HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
if (!bitmap_dc)
NOTREACHED() << "Bitmap DC creation failed";
SetGraphicsMode(bitmap_dc, GM_ADVANCED);
void* bits = NULL;
BITMAPINFO hdr;
gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
HBITMAP hbitmap = CreateDIBSection(
bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
if (!hbitmap)
NOTREACHED() << "Raster bitmap creation for printing failed";
// Page used alpha blend, but printer doesn't support it. Rewrite the
// metafile and flatten out the transparency.
HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
if (!bitmap_dc)
NOTREACHED() << "Bitmap DC creation failed";
SetGraphicsMode(bitmap_dc, GM_ADVANCED);
void* bits = NULL;
BITMAPINFO hdr;
gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
HBITMAP hbitmap = CreateDIBSection(
bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
if (!hbitmap)
NOTREACHED() << "Raster bitmap creation for printing failed";
HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
RECT rect = {0, 0, width, height };
HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
FillRect(bitmap_dc, &rect, whiteBrush);
HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
RECT rect = {0, 0, width, height };
HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
FillRect(bitmap_dc, &rect, whiteBrush);
HDC hdc = metafile2->context();
DCHECK(hdc);
skia::PlatformDevice::InitializeDC(hdc);
scoped_ptr<printing::Metafile> metafile2(new printing::NativeMetafile);
metafile2->Init();
HDC hdc = metafile2->context();
DCHECK(hdc);
skia::PlatformDevice::InitializeDC(hdc);
RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
// Process the old metafile, placing all non-AlphaBlend calls into the
// new metafile, and copying the results of all the AlphaBlend calls
// from the bitmap DC.
EnumEnhMetaFile(hdc,
(*metafile)->emf(),
EnhMetaFileProc,
&bitmap_dc,
&metafile_bounds);
RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
// Process the old metafile, placing all non-AlphaBlend calls into the
// new metafile, and copying the results of all the AlphaBlend calls
// from the bitmap DC.
EnumEnhMetaFile(hdc,
(*metafile)->emf(),
EnhMetaFileProc,
&bitmap_dc,
&metafile_bounds);
SelectObject(bitmap_dc, old_bitmap);
metafile->reset(metafile2.release());
SelectObject(bitmap_dc, old_bitmap);
metafile->reset(metafile2.release());
}
}
}
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
printing::NativeMetafile* metafile,
printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemory shared_buf;

@ -23,9 +23,7 @@
#include "webkit/glue/webcursor.h"
#if defined(OS_WIN)
#include "base/memory/scoped_ptr.h"
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile_impl.h"
#endif // defined(OS_WIN)
using WebKit::WebBindings;
@ -271,27 +269,26 @@ void WebPluginDelegateStub::OnDidPaint() {
void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory,
uint32* size) {
#if defined(OS_WIN)
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
if (!metafile->Init()) {
printing::NativeMetafile metafile;
if (!metafile.Init()) {
NOTREACHED();
return;
}
HDC hdc = metafile->context();
HDC hdc = metafile.context();
skia::PlatformDevice::InitializeDC(hdc);
delegate_->Print(hdc);
if (!metafile->FinishDocument()) {
if (!metafile.FinishDocument()) {
NOTREACHED();
return;
}
*size = metafile->GetDataSize();
*size = metafile.GetDataSize();
DCHECK(*size);
base::SharedMemory shared_buf;
CreateSharedBuffer(*size, &shared_buf, shared_memory);
// Retrieve a copy of the data.
bool success = metafile->GetData(shared_buf.memory(), *size);
bool success = metafile.GetData(shared_buf.memory(), *size);
DCHECK(success);
#else
// TODO(port): plugin printing.

@ -17,7 +17,6 @@
#include "content/common/view_messages.h"
#include "net/base/net_errors.h"
#include "printing/image.h"
#include "printing/native_metafile.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"

@ -54,8 +54,7 @@
#endif
#if defined(OS_WIN)
#include "printing/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/metafile_impl.h"
#endif
using WebKit::WebBindings;
@ -923,14 +922,13 @@ void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) {
}
#if defined(OS_WIN)
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
if (!metafile->InitFromData(memory.memory(), size)) {
printing::NativeMetafile metafile;
if (!metafile.InitFromData(memory.memory(), size)) {
NOTREACHED();
return;
}
// Playback the buffer.
metafile->Playback(context, NULL);
metafile.Playback(context, NULL);
#else
// TODO(port): plugin printing.
NOTIMPLEMENTED();

@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
class FilePath;
@ -23,7 +23,7 @@ class Size;
namespace printing {
// Simple wrapper class that manage an EMF data stream and its virtual HDC.
class Emf : public NativeMetafile {
class Emf : public Metafile {
public:
class Record;
class Enumerator;
@ -41,7 +41,7 @@ class Emf : public NativeMetafile {
// Initializes the Emf with the data in |metafile_path|.
virtual bool InitFromFile(const FilePath& metafile_path);
// NativeMetafile methods.
// Metafile methods.
virtual bool Init();
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

@ -6,9 +6,9 @@
#include "base/file_util.h"
#include "base/md5.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_number_conversions.h"
#include "printing/native_metafile_factory.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/codec/png_codec.h"
@ -34,7 +34,7 @@ Image::Image(const FilePath& path)
}
}
Image::Image(const NativeMetafile& metafile)
Image::Image(const Metafile& metafile)
: row_length_(0),
ignore_alpha_(true) {
LoadMetafile(metafile);
@ -146,12 +146,10 @@ bool Image::LoadPng(const std::string& compressed) {
bool Image::LoadMetafile(const std::string& data) {
DCHECK(!data.empty());
scoped_ptr<NativeMetafile> metafile(
printing::NativeMetafileFactory::CreateFromData(data.data(),
data.size()));
if(!metafile.get())
printing::NativeMetafile metafile;
if (!metafile.InitFromData(data.data(), data.size()))
return false;
return LoadMetafile(*metafile);
return LoadMetafile(metafile);
}
} // namespace printing

@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -10,13 +10,14 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "printing/native_metafile.h"
#include "ui/gfx/size.h"
class FilePath;
namespace printing {
class Metafile;
// Lightweight raw-bitmap management. The image, once initialized, is immutable.
// The main purpose is testing image contents.
class Image {
@ -28,7 +29,7 @@ class Image {
// Creates the image from the metafile. Deduces bounds based on bounds in
// metafile. If loading fails size().IsEmpty() will be true.
explicit Image(const NativeMetafile& metafile);
explicit Image(const Metafile& metafile);
// Copy constructor.
explicit Image(const Image& image);
@ -73,7 +74,7 @@ class Image {
bool LoadMetafile(const std::string& data);
bool LoadMetafile(const NativeMetafile& metafile);
bool LoadMetafile(const Metafile& metafile);
// Pixel dimensions of the image.
gfx::Size size_;

@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -8,7 +8,7 @@
namespace printing {
bool Image::LoadMetafile(const NativeMetafile& metafile) {
bool Image::LoadMetafile(const Metafile& metafile) {
NOTIMPLEMENTED();
return false;
}

@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -7,11 +7,12 @@
#include <ApplicationServices/ApplicationServices.h>
#include "base/mac/scoped_cftyperef.h"
#include "printing/metafile.h"
#include "ui/gfx/rect.h"
namespace printing {
bool Image::LoadMetafile(const NativeMetafile& metafile) {
bool Image::LoadMetafile(const Metafile& metafile) {
// 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));

@ -1,9 +1,10 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/image.h"
#include "printing/metafile.h"
#include "skia/ext/platform_device.h"
#include "ui/gfx/gdi_util.h" // EMF support
#include "ui/gfx/rect.h"
@ -44,7 +45,7 @@ class DisableFontSmoothing {
namespace printing {
bool Image::LoadMetafile(const NativeMetafile& metafile) {
bool Image::LoadMetafile(const Metafile& metafile) {
gfx::Rect rect(metafile.GetPageBounds(1));
DisableFontSmoothing disable_in_this_scope;

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_NATIVE_METAFILE_H_
#define PRINTING_NATIVE_METAFILE_H_
#ifndef PRINTING_METAFILE_H_
#define PRINTING_METAFILE_H_
#include "base/basictypes.h"
#include "build/build_config.h"
@ -11,7 +11,6 @@
#if defined(OS_WIN)
#include <windows.h>
#include <vector>
#elif defined(OS_MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#include <CoreFoundation/CoreFoundation.h>
@ -40,9 +39,9 @@ namespace printing {
// This class creates a graphics context that renders into a data stream
// (usually PDF or EMF).
class NativeMetafile {
class Metafile {
public:
virtual ~NativeMetafile() {}
virtual ~Metafile() {}
// Initializes a fresh new metafile for rendering. Returns false on failure.
// Note: It should only be called from within the renderer process to allocate
@ -149,4 +148,4 @@ class NativeMetafile {
} // namespace printing
#endif // PRINTING_NATIVE_METAFILE_H_
#endif // PRINTING_METAFILE_H_

33
printing/metafile_impl.h Normal file

@ -0,0 +1,33 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_METAFILE_IMPL_H_
#define PRINTING_METAFILE_IMPL_H_
#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"
#include "printing/pdf_metafile_skia.h"
#endif
namespace printing {
#if defined(OS_WIN)
typedef Emf NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
#elif defined(OS_MACOSX)
typedef PdfMetafileCg NativeMetafile;
typedef PdfMetafileCg PreviewMetafile;
#elif defined(OS_POSIX)
typedef PdfMetafileCairo NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
#endif
} // namespace printing
#endif // PRINTING_METAFILE_IMPL_H_

@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "base/logging.h"
#include "printing/native_metafile_skia_wrapper.h"
#include "printing/metafile_skia_wrapper.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkMetaData.h"
@ -12,7 +12,7 @@ namespace printing {
namespace {
static const char* kNativeMetafileKey = "CrNativeMetafile";
static const char* kMetafileKey = "CrMetafile";
SkMetaData& getMetaData(SkCanvas* canvas) {
DCHECK(canvas != NULL);
@ -24,31 +24,29 @@ SkMetaData& getMetaData(SkCanvas* canvas) {
} // namespace
// static
void NativeMetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas,
NativeMetafile* metafile) {
NativeMetafileSkiaWrapper* wrapper = NULL;
void MetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas,
Metafile* metafile) {
MetafileSkiaWrapper* wrapper = NULL;
if (metafile)
wrapper = new NativeMetafileSkiaWrapper(metafile);
wrapper = new MetafileSkiaWrapper(metafile);
SkMetaData& meta = getMetaData(canvas);
meta.setRefCnt(kNativeMetafileKey, wrapper);
meta.setRefCnt(kMetafileKey, wrapper);
SkSafeUnref(wrapper);
}
// static
NativeMetafile* NativeMetafileSkiaWrapper::GetMetafileFromCanvas(
SkCanvas* canvas) {
Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(SkCanvas* canvas) {
SkMetaData& meta = getMetaData(canvas);
SkRefCnt* value;
if (!meta.findRefCnt(kNativeMetafileKey, &value) || !value)
if (!meta.findRefCnt(kMetafileKey, &value) || !value)
return NULL;
return static_cast<NativeMetafileSkiaWrapper*>(value)->metafile_;
return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
}
NativeMetafileSkiaWrapper::NativeMetafileSkiaWrapper(NativeMetafile* metafile)
MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile)
: metafile_(metafile) {
}

@ -0,0 +1,34 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_METAFILE_SKIA_WRAPPER_H_
#define PRINTING_METAFILE_SKIA_WRAPPER_H_
#include "third_party/skia/include/core/SkRefCnt.h"
class SkCanvas;
namespace printing {
class Metafile;
// A wrapper class with static methods to set and retrieve a Metafile
// on an SkCanvas. The ownership of the metafile is not affected and it
// is the caller's responsibility to ensure that the metafile remains valid
// as long as the canvas.
class MetafileSkiaWrapper : public SkRefCnt {
public:
static void SetMetafileOnCanvas(SkCanvas* canvas, Metafile* metafile);
static Metafile* GetMetafileFromCanvas(SkCanvas* canvas);
private:
explicit MetafileSkiaWrapper(Metafile* metafile);
Metafile* metafile_;
};
} // namespace printing
#endif // PRINTING_METAFILE_SKIA_WRAPPER_H_

@ -1,47 +0,0 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/native_metafile_factory.h"
#include "base/memory/scoped_ptr.h"
#if defined(OS_WIN)
#include "printing/emf_win.h"
#elif defined(OS_MACOSX)
#include "printing/pdf_metafile_cg_mac.h"
#elif defined(OS_POSIX)
#include "printing/pdf_metafile_cairo_linux.h"
#endif
namespace printing {
// static
NativeMetafile* NativeMetafileFactory::Create() {
scoped_ptr<NativeMetafile> metafile(CreateNewMetafile());
if (!metafile->Init())
return NULL;
return metafile.release();
}
// static
NativeMetafile* NativeMetafileFactory::CreateFromData(
const void* src_buffer, uint32 src_buffer_size) {
scoped_ptr<NativeMetafile> metafile(CreateNewMetafile());
if (!metafile->InitFromData(src_buffer, src_buffer_size))
return NULL;
return metafile.release();
}
// static
NativeMetafile* NativeMetafileFactory::CreateNewMetafile(){
#if defined(OS_WIN)
return new printing::Emf;
#elif defined(OS_MACOSX)
return new printing::PdfMetafileCg;
#elif defined(OS_POSIX)
return new printing::PdfMetafileCairo;
#endif
}
} // namespace printing

@ -1,42 +0,0 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_NATIVE_METAFILE_FACTORY_H_
#define PRINTING_NATIVE_METAFILE_FACTORY_H_
#include "base/basictypes.h"
#include "printing/native_metafile.h"
namespace printing {
// Various printing contexts will be supported in the future (cairo, skia, emf).
// So this class returns the appropriate context depending on the platform and
// user preferences.
// (Note: For the moment there is only one option per platform.)
class NativeMetafileFactory {
public:
// This method returns a pointer to the appropriate NativeMetafile object
// according to the platform. The metafile is already initialized by invoking
// Init() on it. NULL is returned if Init() fails.
static printing::NativeMetafile* Create();
// This method returns a pointer to the appropriate NativeMetafile object
// according to the platform. The metafile is already initialized by invoking
// InitFromData(src_buffer,_buffer_size) on it. NULL is returned if
// InitiFromData() fails.
static printing::NativeMetafile* CreateFromData(const void* src_buffer,
uint32 src_buffer_size);
private:
NativeMetafileFactory();
// Retrieves a new uninitialized metafile.
static NativeMetafile* CreateNewMetafile();
DISALLOW_COPY_AND_ASSIGN(NativeMetafileFactory);
};
} // namespace printing
#endif // PRINTING_NATIVE_METAFILE_FACTORY_H_

@ -1,34 +0,0 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_
#define PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_
#include "third_party/skia/include/core/SkRefCnt.h"
class SkCanvas;
namespace printing {
class NativeMetafile;
// A wrapper class with static methods to set and retrieve a NativeMetafile
// on an SkCanvas. The ownership of the metafile is not affected and it
// is the caller's responsibility to ensure that the metafile remains valid
// as long as the canvas.
class NativeMetafileSkiaWrapper : public SkRefCnt {
public:
static void SetMetafileOnCanvas(SkCanvas* canvas, NativeMetafile* metafile);
static NativeMetafile* GetMetafileFromCanvas(SkCanvas* canvas);
private:
explicit NativeMetafileSkiaWrapper(NativeMetafile* metafile);
NativeMetafile* metafile_;
};
} // namespace printing
#endif // PRINTING_NATIVE_METAFILE_SKIA_WRAPPER_H_

@ -9,7 +9,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
namespace gfx {
class Point;
@ -23,11 +23,12 @@ namespace printing {
// This class uses Cairo graphics library to generate PDF stream and stores
// rendering results in a string buffer.
class PdfMetafileCairo : public NativeMetafile {
class PdfMetafileCairo : public Metafile {
public:
PdfMetafileCairo();
virtual ~PdfMetafileCairo();
// NativeMetafile methods.
// Metafile methods.
virtual bool Init();
// Calling InitFromData() sets the data for this metafile and masks data
@ -58,13 +59,7 @@ class PdfMetafileCairo : public NativeMetafile {
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS)
protected:
PdfMetafileCairo();
private:
friend class NativeMetafileFactory;
FRIEND_TEST_ALL_PREFIXES(PdfMetafileCairoTest, Pdf);
// Cleans up all resources.
void CleanUpAll();

@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
class FilePath;
@ -24,12 +24,12 @@ class Point;
namespace printing {
// This class creates a graphics context that renders into a PDF data stream.
class PdfMetafileCg : public NativeMetafile {
class PdfMetafileCg : public Metafile {
public:
PdfMetafileCg();
virtual ~PdfMetafileCg();
// NativeMetafile methods.
// Metafile methods.
virtual bool Init();
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
@ -64,13 +64,7 @@ class PdfMetafileCg : public NativeMetafile {
bool center_horizontally,
bool center_vertically) const;
protected:
PdfMetafileCg();
private:
friend class NativeMetafileFactory;
FRIEND_TEST_ALL_PREFIXES(PdfMetafileCgTest, Pdf);
// Returns a CGPDFDocumentRef version of pdf_data_.
CGPDFDocumentRef GetPDFDocument() const;

@ -9,7 +9,7 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "build/build_config.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#if defined(OS_WIN)
#include <windows.h>
@ -20,11 +20,12 @@ namespace printing {
struct PdfMetafileSkiaData;
// This class uses Skia graphics library to generate a PDF document.
class PdfMetafileSkia : public NativeMetafile {
class PdfMetafileSkia : public Metafile {
public:
PdfMetafileSkia();
virtual ~PdfMetafileSkia();
// NativeMetafile interface
// Metafile methods.
virtual bool Init();
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
@ -55,15 +56,9 @@ class PdfMetafileSkia : public NativeMetafile {
#endif // if defined(OS_WIN)
#if defined(OS_CHROMEOS)
virtual bool SaveToFD(const base::FileDescriptor& fd) const = 0;
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS)
protected:
PdfMetafileSkia();
private:
friend class NativeMetafileFactory;
scoped_ptr<PdfMetafileSkiaData> data_;
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);

@ -10,6 +10,8 @@
namespace printing {
class Metafile;
// An interface for GTK printing dialogs. Classes that live outside of
// printing/ can implement this interface and get threading requirements
// correct without exposing those requirements to printing/.
@ -22,7 +24,7 @@ class PrintDialogGtkInterface {
// Prints the document named |document_name| contained in |metafile|.
// Called from the print worker thread. Once called, the
// PrintDialogGtkInterface instance should not be reused.
virtual void PrintDocument(const NativeMetafile* metafile,
virtual void PrintDocument(const Metafile* metafile,
const string16& document_name) = 0;
// Same as AddRef/Release, but with different names since

@ -64,7 +64,7 @@ PrintedDocument::~PrintedDocument() {
}
void PrintedDocument::SetPage(int page_number,
NativeMetafile* metafile,
Metafile* metafile,
double shrink,
const gfx::Size& paper_size,
const gfx::Rect& page_rect,
@ -125,7 +125,7 @@ bool PrintedDocument::IsComplete() const {
PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt());
if (itr == mutable_.pages_.end() || !itr->second.get())
return false;
if (metafile_must_be_valid && !itr->second->native_metafile())
if (metafile_must_be_valid && !itr->second->metafile())
return false;
}
return true;
@ -151,7 +151,7 @@ uint32 PrintedDocument::MemoryUsage() const {
}
uint32 total = 0;
for (size_t i = 0; i < pages_copy.size(); ++i) {
total += pages_copy[i]->native_metafile()->GetDataSize();
total += pages_copy[i]->metafile()->GetDataSize();
}
return total;
}
@ -263,11 +263,11 @@ void PrintedDocument::DebugDump(const PrintedPage& page) {
filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number()));
#if defined(OS_WIN)
filename += ASCIIToUTF16("_.emf");
page.native_metafile()->SaveTo(
page.metafile()->SaveTo(
g_debug_dump_info.Get().debug_dump_path.Append(filename));
#else // OS_WIN
filename += ASCIIToUTF16("_.pdf");
page.native_metafile()->SaveTo(
page.metafile()->SaveTo(
g_debug_dump_info.Get().debug_dump_path.Append(UTF16ToUTF8(filename)));
#endif // OS_WIN
}

@ -24,7 +24,7 @@ class Font;
namespace printing {
class NativeMetafile;
class Metafile;
class PrintedPage;
class PrintedPagesSource;
class PrintingContext;
@ -45,7 +45,7 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
// Sets a page's data. 0-based. Takes metafile ownership.
// Note: locks for a short amount of time.
void SetPage(int page_number, NativeMetafile* metafile, double shrink,
void SetPage(int page_number, Metafile* metafile, double shrink,
const gfx::Size& paper_size, const gfx::Rect& page_rect,
bool has_visible_overlays);

@ -28,7 +28,7 @@ void PrintedDocument::RenderPrintedPage(
base::AutoLock lock(lock_);
if (page.page_number() - 1 == mutable_.first_page) {
reinterpret_cast<PrintingContextCairo*>(context)->PrintDocument(
page.native_metafile());
page.metafile());
}
}
#endif // !defined(OS_CHROMEOS)

@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -30,8 +30,8 @@ void PrintedDocument::RenderPrintedPage(
gfx::Rect content_area;
page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area);
const printing::NativeMetafile* metafile = page.native_metafile();
// Each NativeMetafile is a one-page PDF, and pages use 1-based indexing.
const printing::Metafile* metafile = page.metafile();
// Each Metafile is a one-page PDF, and pages use 1-based indexing.
const int page_number = 1;
metafile->RenderPage(page_number, context, content_area.ToCGRect(),
false, false, false, false);

@ -114,7 +114,7 @@ void PrintedDocument::RenderPrintedPage(
content_area.y() - page_setup.printable_area().y(),
mutable_.shrink_factor);
if (!page.native_metafile()->SafePlayback(context)) {
if (!page.metafile()->SafePlayback(context)) {
NOTREACHED();
}

@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -7,12 +7,12 @@
namespace printing {
PrintedPage::PrintedPage(int page_number,
NativeMetafile* native_metafile,
Metafile* metafile,
const gfx::Size& page_size,
const gfx::Rect& page_content_rect,
bool has_visible_overlays)
: page_number_(page_number),
native_metafile_(native_metafile),
metafile_(metafile),
page_size_(page_size),
page_content_rect_(page_content_rect),
has_visible_overlays_(has_visible_overlays) {
@ -21,8 +21,8 @@ PrintedPage::PrintedPage(int page_number,
PrintedPage::~PrintedPage() {
}
const NativeMetafile* PrintedPage::native_metafile() const {
return native_metafile_.get();
const Metafile* PrintedPage::metafile() const {
return metafile_.get();
}
void PrintedPage::GetCenteredPageContentRect(

@ -7,7 +7,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "printing/native_metafile.h"
#include "printing/metafile.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
@ -22,14 +22,14 @@ namespace printing {
class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
public:
PrintedPage(int page_number,
NativeMetafile* native_metafile,
Metafile* metafile,
const gfx::Size& page_size,
const gfx::Rect& page_content_rect,
bool has_visible_overlays);
// Getters
int page_number() const { return page_number_; }
const NativeMetafile* native_metafile() const;
const Metafile* metafile() const;
const gfx::Size& page_size() const { return page_size_; }
const gfx::Rect& page_content_rect() const { return page_content_rect_; }
bool has_visible_overlays() const { return has_visible_overlays_; }
@ -48,7 +48,7 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
const int page_number_;
// Actual paint data.
const scoped_ptr<NativeMetafile> native_metafile_;
const scoped_ptr<Metafile> metafile_;
// The physical page size. To support multiple page formats inside on print
// job.

@ -36,9 +36,8 @@
'image_mac.cc',
'image_win.cc',
'image.h',
'native_metafile_factory.cc',
'native_metafile_factory.h',
'native_metafile.h',
'metafile.h',
'metafile_impl.h',
'page_number.cc',
'page_number.h',
'page_overlays.cc',
@ -100,8 +99,8 @@
}],
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'sources': [
'native_metafile_skia_wrapper.cc',
'native_metafile_skia_wrapper.h',
'metafile_skia_wrapper.cc',
'metafile_skia_wrapper.h',
],
'dependencies': [
# For FT_Init_FreeType and friends.

@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/values.h"
#include "printing/metafile.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_gtk.h"
#include "printing/units.h"
@ -62,7 +63,7 @@ void PrintingContextCairo::SetCreatePrintDialogFunction(
create_dialog_func_ = create_dialog_func;
}
void PrintingContextCairo::PrintDocument(const NativeMetafile* metafile) {
void PrintingContextCairo::PrintDocument(const Metafile* metafile) {
DCHECK(print_dialog_);
DCHECK(metafile);
print_dialog_->PrintDocument(metafile, document_name_);

@ -9,12 +9,9 @@
#include "printing/printing_context.h"
#if !defined(OS_CHROMEOS)
#include "printing/native_metafile.h"
#endif
namespace printing {
class Metafile;
class PrintDialogGtkInterface;
class PrintingContextCairo : public PrintingContext {
@ -29,7 +26,7 @@ class PrintingContextCairo : public PrintingContext {
PrintingContextCairo* context));
// Prints the document contained in |metafile|.
void PrintDocument(const NativeMetafile* metafile);
void PrintDocument(const Metafile* metafile);
#endif
// PrintingContext implementation.

@ -31,8 +31,8 @@ class VectorPlatformDeviceSkiaFactory : public SkDeviceFactory {
class VectorPlatformDeviceSkia : public PlatformDevice {
public:
VectorPlatformDeviceSkia(int width, int height,
SkPDFDevice::OriginTransform flip);
SK_API VectorPlatformDeviceSkia(int width, int height,
SkPDFDevice::OriginTransform flip);
~VectorPlatformDeviceSkia();
@ -91,7 +91,7 @@ class VectorPlatformDeviceSkia : public PlatformDevice {
// Our own methods.
// This needs to be called before anything is drawn.
void setInitialTransform(int xOffset, int yOffset, float scale_factor);
SK_API void setInitialTransform(int xOffset, int yOffset, float scale_factor);
private:
SkRefPtr<SkPDFDevice> pdf_device_;

@ -59,18 +59,15 @@
#include "webkit/plugins/ppapi/var.h"
#include "webkit/plugins/sad_plugin.h"
#if defined(OS_POSIX)
#include "printing/native_metafile.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "printing/native_metafile_factory.h"
#include "printing/metafile_impl.h"
#endif
#if defined(OS_LINUX)
#include "printing/native_metafile_skia_wrapper.h"
#include "printing/metafile.h"
#include "printing/metafile_skia_wrapper.h"
#endif
#if defined(OS_WIN)
@ -1202,18 +1199,18 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
bool ret = false;
#if defined(OS_LINUX)
// On Linux we just set the final bits in the native metafile.
printing::NativeMetafile* metafile =
printing::NativeMetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
// On Linux we just set the final bits in the native metafile
// (NativeMetafile and PreviewMetafile must have compatible formats,
// i.e. both PDF for this to work).
printing::Metafile* metafile =
printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
DCHECK(metafile != NULL);
if (metafile)
ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
#elif defined(OS_MACOSX)
printing::NativeMetafile metafile;
// Create a PDF metafile and render from there into the passed in context.
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::CreateFromData(buffer->mapped_buffer(),
buffer->size()));
if (metafile.get() != NULL) {
if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) {
// Flip the transform.
CGContextSaveGState(canvas);
CGContextTranslateCTM(canvas, 0,
@ -1225,7 +1222,7 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
page_rect.size.width = current_print_settings_.printable_area.size.width;
page_rect.size.height = current_print_settings_.printable_area.size.height;
ret = metafile->RenderPage(1, canvas, page_rect, true, false, true, true);
ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true);
CGContextRestoreGState(canvas);
}
#elif defined(OS_WIN)