summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-06 15:25:50 +0000
committersverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-06 15:25:50 +0000
commit0e0fca32b226a29a774728b642848bfdd732f791 (patch)
tree70547f886163e2a364ed47a8d5c85765d48f0e12
parentd09e2889c21d0a420b70680291906e4a17fb8503 (diff)
downloadchromium_src-0e0fca32b226a29a774728b642848bfdd732f791.zip
chromium_src-0e0fca32b226a29a774728b642848bfdd732f791.tar.gz
chromium_src-0e0fca32b226a29a774728b642848bfdd732f791.tar.bz2
Move Emf class to the printing library. Also creates a platform agnostic NativeMetafile definition to ease platform porting.
BUG=none TEST=none (No functional change) Review URL: http://codereview.chromium.org/149181 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/printing/print_job_manager.cc1
-rw-r--r--chrome/browser/printing/print_job_worker.cc1
-rw-r--r--chrome/browser/printing/print_view_manager.cc18
-rw-r--r--chrome/browser/printing/printed_document.cc15
-rw-r--r--chrome/browser/printing/printed_document.h8
-rw-r--r--chrome/browser/printing/printed_page.cc10
-rw-r--r--chrome/browser/printing/printed_page.h11
-rw-r--r--chrome/browser/printing/printing_layout_uitest.cc16
-rw-r--r--chrome/chrome.gyp6
-rw-r--r--chrome/common/render_messages.h8
-rw-r--r--chrome/plugin/webplugin_delegate_stub.cc17
-rw-r--r--chrome/renderer/mock_printer.cc2
-rw-r--r--chrome/renderer/mock_printer_driver_win.cc6
-rw-r--r--chrome/renderer/print_web_view_helper.cc38
-rw-r--r--chrome/renderer/webplugin_delegate_proxy.cc11
-rw-r--r--printing/emf_win.cc (renamed from chrome/common/gfx/emf.cc)6
-rw-r--r--printing/emf_win.h (renamed from chrome/common/gfx/emf.h)12
-rw-r--r--printing/emf_win_unittest.cc (renamed from chrome/common/gfx/emf_unittest.cc)17
-rw-r--r--printing/native_metafile.h36
-rw-r--r--printing/printing.gyp15
20 files changed, 148 insertions, 106 deletions
diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc
index c6f4ac3..320aa21 100644
--- a/chrome/browser/printing/print_job_manager.cc
+++ b/chrome/browser/printing/print_job_manager.cc
@@ -8,7 +8,6 @@
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/printing/printed_document.h"
#include "chrome/browser/printing/printed_page.h"
-#include "chrome/common/gfx/emf.h"
#include "chrome/common/notification_service.h"
namespace printing {
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index af32da0..728ff3d 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -8,7 +8,6 @@
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/printed_document.h"
#include "chrome/browser/printing/printed_page.h"
-#include "chrome/common/gfx/emf.h"
#include "chrome/common/notification_service.h"
namespace printing {
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index d775ff5..1c56d00d 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/printing/print_view_manager.h"
#include "app/l10n_util.h"
+#include "base/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_manager.h"
@@ -13,10 +14,10 @@
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/gfx/emf.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
#include "grit/generated_resources.h"
+#include "printing/native_metafile.h"
using base::TimeDelta;
@@ -95,23 +96,24 @@ void PrintViewManager::DidPrintPage(
return;
}
- base::SharedMemory shared_buf(params.emf_data_handle, true);
+ base::SharedMemory shared_buf(params.metafile_data_handle, true);
if (!shared_buf.Map(params.data_size)) {
NOTREACHED() << "couldn't map";
owner_.Stop();
return;
}
- gfx::Emf* emf = new gfx::Emf;
- if (!emf->CreateFromData(shared_buf.memory(), params.data_size)) {
- NOTREACHED() << "Invalid EMF header";
- delete emf;
+ scoped_ptr<NativeMetafile> metafile(new NativeMetafile());
+ if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) {
+ NOTREACHED() << "Invalid metafile header";
owner_.Stop();
return;
}
// Update the rendered document. It will send notifications to the listener.
- document->SetPage(params.page_number, emf, params.actual_shrink);
+ document->SetPage(params.page_number,
+ metafile.release(),
+ params.actual_shrink);
ShouldQuitFromInnerMessageLoop();
}
@@ -301,7 +303,7 @@ void PrintViewManager::TerminatePrintJob(bool cancel) {
return;
if (cancel) {
- // We don't need the EMF data anymore because the printing is canceled.
+ // We don't need the metafile data anymore because the printing is canceled.
print_job_->Cancel();
waiting_to_print_ = false;
inside_inner_message_loop_ = false;
diff --git a/chrome/browser/printing/printed_document.cc b/chrome/browser/printing/printed_document.cc
index a366a95..ac26581 100644
--- a/chrome/browser/printing/printed_document.cc
+++ b/chrome/browser/printing/printed_document.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/printing/page_overlays.h"
#include "chrome/browser/printing/printed_pages_source.h"
#include "chrome/browser/printing/printed_page.h"
-#include "chrome/common/gfx/emf.h"
#include "printing/units.h"
#include "skia/ext/platform_device.h"
@@ -60,12 +59,14 @@ PrintedDocument::PrintedDocument(const PrintSettings& settings,
PrintedDocument::~PrintedDocument() {
}
-void PrintedDocument::SetPage(int page_number, gfx::Emf* emf, double shrink) {
+void PrintedDocument::SetPage(int page_number,
+ NativeMetafile* metafile,
+ double shrink) {
// Notice the page_number + 1, the reason is that this is the value that will
// be shown. Users dislike 0-based counting.
scoped_refptr<PrintedPage> page(
new PrintedPage(page_number + 1,
- emf, immutable_.settings_.page_setup_pixels().physical_size()));
+ metafile, immutable_.settings_.page_setup_pixels().physical_size()));
{
AutoLock lock(lock_);
mutable_.pages_[page_number] = page;
@@ -123,7 +124,7 @@ void PrintedDocument::RenderPrintedPage(const PrintedPage& page,
BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY);
DCHECK_NE(res, 0);
- if (!page.emf()->SafePlayback(context)) {
+ if (!page.native_metafile()->SafePlayback(context)) {
NOTREACHED();
}
@@ -176,7 +177,7 @@ bool PrintedDocument::IsComplete() const {
for (; page != PageNumber::npos(); ++page) {
PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt());
if (itr == mutable_.pages_.end() || !itr->second.get() ||
- !itr->second->emf())
+ !itr->second->native_metafile())
return false;
}
return true;
@@ -202,7 +203,7 @@ size_t PrintedDocument::MemoryUsage() const {
}
size_t total = 0;
for (size_t i = 0; i < pages_copy.size(); ++i) {
- total += pages_copy[i]->emf()->GetDataSize();
+ total += pages_copy[i]->native_metafile()->GetDataSize();
}
return total;
}
@@ -321,7 +322,7 @@ void PrintedDocument::DebugDump(const PrintedPage& page)
file_util::ReplaceIllegalCharacters(&filename, '_');
std::wstring path(g_debug_dump_info->debug_dump_path);
file_util::AppendToPath(&path, filename);
- page.emf()->SaveTo(path);
+ page.native_metafile()->SaveTo(path);
}
void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) {
diff --git a/chrome/browser/printing/printed_document.h b/chrome/browser/printing/printed_document.h
index 5efc415..0d1480d 100644
--- a/chrome/browser/printing/printed_document.h
+++ b/chrome/browser/printing/printed_document.h
@@ -11,12 +11,12 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/printing/print_settings.h"
+#include "printing/native_metafile.h"
#include "googleurl/src/gurl.h"
class MessageLoop;
namespace gfx {
-class Emf;
class Font;
}
@@ -40,9 +40,9 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
int cookie);
~PrintedDocument();
- // Sets a page's data. 0-based. Takes emf ownership.
+ // Sets a page's data. 0-based. Takes metafile ownership.
// Note: locks for a short amount of time.
- void SetPage(int page_number, gfx::Emf* emf, double shrink);
+ void SetPage(int page_number, NativeMetafile* metafile, double shrink);
// Retrieves a page. If the page is not available right now, it
// requests to have this page be rendered and returns false.
@@ -103,7 +103,7 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
static const std::wstring& debug_dump_path();
private:
- // Array of EMF data for each print previewed page.
+ // Array of data for each print previewed page.
typedef std::map<int, scoped_refptr<PrintedPage>> PrintedPages;
// Contains all the mutable stuff. All this stuff MUST be accessed with the
diff --git a/chrome/browser/printing/printed_page.cc b/chrome/browser/printing/printed_page.cc
index 1cb5c0d..4c44acc 100644
--- a/chrome/browser/printing/printed_page.cc
+++ b/chrome/browser/printing/printed_page.cc
@@ -4,23 +4,21 @@
#include "chrome/browser/printing/printed_page.h"
-#include "chrome/common/gfx/emf.h"
-
namespace printing {
PrintedPage::PrintedPage(int page_number,
- gfx::Emf* emf,
+ NativeMetafile* native_metafile,
const gfx::Size& page_size)
: page_number_(page_number),
- emf_(emf),
+ native_metafile_(native_metafile),
page_size_(page_size) {
}
PrintedPage::~PrintedPage() {
}
-const gfx::Emf* PrintedPage::emf() const {
- return emf_.get();
+const NativeMetafile* PrintedPage::native_metafile() const {
+ return native_metafile_.get();
}
} // namespace printing
diff --git a/chrome/browser/printing/printed_page.h b/chrome/browser/printing/printed_page.h
index 9058d72..b60c93d 100644
--- a/chrome/browser/printing/printed_page.h
+++ b/chrome/browser/printing/printed_page.h
@@ -9,10 +9,7 @@
#include "base/gfx/size.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
-
-namespace gfx {
-class Emf;
-}
+#include "printing/native_metafile.h"
namespace printing {
@@ -25,13 +22,13 @@ namespace printing {
class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
public:
PrintedPage(int page_number,
- gfx::Emf* emf,
+ NativeMetafile* native_metafile,
const gfx::Size& page_size);
~PrintedPage();
// Getters
int page_number() const { return page_number_; }
- const gfx::Emf* emf() const;
+ const NativeMetafile* native_metafile() const;
const gfx::Size& page_size() const { return page_size_; }
private:
@@ -39,7 +36,7 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
const int page_number_;
// Actual paint data.
- const scoped_ptr<gfx::Emf> emf_;
+ const scoped_ptr<NativeMetafile> native_metafile_;
// The physical page size. To support multiple page formats inside on print
// job.
diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc
index a651a0a..e9f6c27 100644
--- a/chrome/browser/printing/printing_layout_uitest.cc
+++ b/chrome/browser/printing/printing_layout_uitest.cc
@@ -11,13 +11,13 @@
#include "base/simple_thread.h"
#include "base/win_util.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/gfx/emf.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "chrome/browser/printing/printing_test.h"
#include "net/url_request/url_request_unittest.h"
+#include "printing/native_metafile.h"
namespace {
@@ -37,7 +37,7 @@ class Image {
if (LowerCaseEqualsASCII(ext, "png")) {
LoadPng(data);
} else if (LowerCaseEqualsASCII(ext, "emf")) {
- LoadEmf(data);
+ LoadMetafile(data);
} else {
EXPECT_TRUE(false);
}
@@ -149,11 +149,11 @@ class Image {
row_length_ = size_.width() * sizeof(uint32);
}
- void LoadEmf(const std::string& data) {
+ void LoadMetafile(const std::string& data) {
ASSERT_FALSE(data.empty());
- gfx::Emf emf;
- emf.CreateFromData(data.data(), data.size());
- gfx::Rect rect(emf.GetBounds());
+ printing::NativeMetafile metafile;
+ metafile.CreateFromData(data.data(), data.size());
+ gfx::Rect rect(metafile.GetBounds());
// Create a temporary HDC and bitmap to retrieve the renderered data.
HDC hdc = CreateCompatibleDC(NULL);
BITMAPV4HEADER hdr;
@@ -170,7 +170,7 @@ class Image {
EXPECT_TRUE(bitmap);
EXPECT_TRUE(SelectObject(hdc, bitmap));
skia::PlatformDevice::InitializeDC(hdc);
- EXPECT_TRUE(emf.Playback(hdc, NULL));
+ EXPECT_TRUE(metafile.Playback(hdc, NULL));
row_length_ = size_.width() * sizeof(uint32);
size_t bytes = row_length_ * size_.height();
ASSERT_TRUE(bytes);
@@ -200,7 +200,7 @@ class PrintingLayoutTest : public PrintingTest<UITest> {
public:
PrintingLayoutTest() {
emf_path_ = browser_directory_.ToWStringHack();
- file_util::AppendToPath(&emf_path_, L"emf_dumps");
+ file_util::AppendToPath(&emf_path_, L"metafile_dumps");
launch_arguments_.AppendSwitchWithValue(L"debug-print",
L'"' + emf_path_ + L'"');
show_window_ = true;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 4251678..9893313 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -302,8 +302,6 @@
'common/extensions/url_pattern.h',
'common/extensions/user_script.cc',
'common/extensions/user_script.h',
- 'common/gfx/emf.cc',
- 'common/gfx/emf.h',
'common/gfx/utils.h',
'common/net/cookie_monster_sqlite.cc',
'common/net/cookie_monster_sqlite.h',
@@ -525,7 +523,6 @@
],
}, { # else: OS != "win"
'sources!': [
- 'common/gfx/emf.cc',
'common/classfactory.cc',
],
}],
@@ -3575,7 +3572,6 @@
'common/extensions/url_pattern_unittest.cc',
'common/extensions/user_script_unittest.cc',
'common/file_descriptor_set_unittest.cc',
- 'common/gfx/emf_unittest.cc',
'common/important_file_writer_unittest.cc',
'common/ipc_message_unittest.cc',
'common/ipc_sync_channel_unittest.cc',
@@ -3758,7 +3754,6 @@
'browser/views/find_bar_win_unittest.cc',
'browser/views/keyword_editor_view_unittest.cc',
'common/chrome_plugin_unittest.cc',
- 'common/gfx/emf_unittest.cc',
'common/net/url_util_unittest.cc',
'test/browser_with_test_window_test.cc',
'test/browser_with_test_window_test.h',
@@ -4232,6 +4227,7 @@
'installer/installer.gyp:installer_util_strings',
'theme_dll',
'worker',
+ '../printing/printing.gyp:printing',
'../net/net.gyp:net_resources',
'../build/util/support/support.gyp:*',
'../third_party/cld/cld.gyp:cld',
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index cd62ed1..8cd4280 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -335,9 +335,9 @@ struct ViewMsg_PrintPages_Params {
struct ViewHostMsg_DidPrintPage_Params {
// A shared memory handle to the EMF data. This data can be quite large so a
// memory map needs to be used.
- base::SharedMemoryHandle emf_data_handle;
+ base::SharedMemoryHandle metafile_data_handle;
- // Size of the EMF data.
+ // Size of the metafile data.
unsigned data_size;
// Cookie for the document to ensure correctness.
@@ -1490,14 +1490,14 @@ template <>
struct ParamTraits<ViewHostMsg_DidPrintPage_Params> {
typedef ViewHostMsg_DidPrintPage_Params param_type;
static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.emf_data_handle);
+ WriteParam(m, p.metafile_data_handle);
WriteParam(m, p.data_size);
WriteParam(m, p.document_cookie);
WriteParam(m, p.page_number);
WriteParam(m, p.actual_shrink);
}
static bool Read(const Message* m, void** iter, param_type* p) {
- return ReadParam(m, iter, &p->emf_data_handle) &&
+ return ReadParam(m, iter, &p->metafile_data_handle) &&
ReadParam(m, iter, &p->data_size) &&
ReadParam(m, iter, &p->document_cookie) &&
ReadParam(m, iter, &p->page_number) &&
diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc
index 8cc3273..e607667 100644
--- a/chrome/plugin/webplugin_delegate_stub.cc
+++ b/chrome/plugin/webplugin_delegate_stub.cc
@@ -13,16 +13,13 @@
#include "chrome/plugin/plugin_channel.h"
#include "chrome/plugin/plugin_thread.h"
#include "chrome/plugin/webplugin_proxy.h"
+#include "printing/native_metafile.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "skia/ext/platform_device.h"
#include "webkit/glue/webcursor.h"
#include "webkit/glue/webplugin_delegate.h"
-#if defined(OS_WIN)
-#include "chrome/common/gfx/emf.h"
-#endif
-
class FinishDestructionTask : public Task {
public:
FinishDestructionTask(WebPluginDelegate* delegate, WebPlugin* webplugin)
@@ -230,26 +227,26 @@ void WebPluginDelegateStub::OnDidPaint() {
void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory,
size_t* size) {
#if defined(OS_WIN)
- gfx::Emf emf;
- if (!emf.CreateDc(NULL, NULL)) {
+ printing::NativeMetafile metafile;
+ if (!metafile.CreateDc(NULL, NULL)) {
NOTREACHED();
return;
}
- HDC hdc = emf.hdc();
+ HDC hdc = metafile.hdc();
skia::PlatformDevice::InitializeDC(hdc);
delegate_->Print(hdc);
- if (!emf.CloseDc()) {
+ if (!metafile.CloseDc()) {
NOTREACHED();
return;
}
- *size = emf.GetDataSize();
+ *size = metafile.GetDataSize();
DCHECK(*size);
base::SharedMemory shared_buf;
CreateSharedBuffer(*size, &shared_buf, shared_memory);
// Retrieve a copy of the data.
- bool success = emf.GetData(shared_buf.memory(), *size);
+ bool success = metafile.GetData(shared_buf.memory(), *size);
DCHECK(success);
#else
// TODO(port): plugin printing.
diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc
index 1b0dcc5..2454a0c 100644
--- a/chrome/renderer/mock_printer.cc
+++ b/chrome/renderer/mock_printer.cc
@@ -113,7 +113,7 @@ void MockPrinter::PrintPage(const ViewHostMsg_DidPrintPage_Params& params) {
// We duplicate the given file handle when creating a base::SharedMemory
// instance so that its destructor closes the copy.
EXPECT_GT(params.data_size, 0U);
- base::SharedMemory emf_data(params.emf_data_handle, true,
+ base::SharedMemory emf_data(params.metafile_data_handle, true,
GetCurrentProcess());
emf_data.Map(params.data_size);
MockPrinterPage* page_data = driver_.LoadSource(emf_data.memory(),
diff --git a/chrome/renderer/mock_printer_driver_win.cc b/chrome/renderer/mock_printer_driver_win.cc
index 051838b..8fefd8e 100644
--- a/chrome/renderer/mock_printer_driver_win.cc
+++ b/chrome/renderer/mock_printer_driver_win.cc
@@ -6,7 +6,7 @@
#include "base/gfx/gdi_util.h"
#include "base/logging.h"
-#include "chrome/common/gfx/emf.h"
+#include "printing/emf_win.h"
#include "chrome/renderer/mock_printer.h"
#include "skia/ext/platform_device.h"
@@ -57,7 +57,7 @@ class EmfRenderer {
}
}
- const void* Create(int width, int height, const gfx::Emf* emf) {
+ const void* Create(int width, int height, const printing::Emf* emf) {
CHECK(!dc_ && !bitmap_);
BITMAPV4HEADER header;
@@ -98,7 +98,7 @@ MockPrinterPage* MockPrinterDriverWin::LoadSource(const void* source_data,
size_t source_size) {
// This code is mostly copied from the Image::LoadEMF() function in
// "src/chrome/browser/printing/printing_layout_uitest.cc".
- gfx::Emf emf;
+ printing::Emf emf;
emf.CreateFromData(source_data, source_size);
gfx::Rect rect(emf.GetBounds());
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index d5389af..f53709e 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -10,6 +10,7 @@
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_view.h"
#include "grit/generated_resources.h"
+#include "printing/native_metafile.h"
#include "printing/units.h"
#include "webkit/api/public/WebConsoleMessage.h"
#include "webkit/api/public/WebScreenInfo.h"
@@ -19,7 +20,6 @@
#include "webkit/glue/webframe.h"
#if defined(OS_WIN)
-#include "chrome/common/gfx/emf.h"
#include "skia/ext/vector_canvas.h"
#endif
@@ -283,12 +283,11 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame) {
#if defined(OS_WIN)
- // Generate a memory-based EMF file. The EMF will use the current screen's
- // DPI.
- gfx::Emf emf;
+ // Generate a memory-based metafile. It will use the current screen's DPI.
+ printing::NativeMetafile metafile;
- emf.CreateDc(NULL, NULL);
- HDC hdc = emf.hdc();
+ metafile.CreateDc(NULL, NULL);
+ HDC hdc = metafile.hdc();
DCHECK(hdc);
skia::PlatformDevice::InitializeDC(hdc);
// Since WebKit extends the page width depending on the magical shrink
@@ -344,17 +343,17 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
}
#endif
- // Done printing. Close the device context to retrieve the compiled EMF.
- if (!emf.CloseDc()) {
- NOTREACHED() << "EMF failed";
+ // Done printing. Close the device context to retrieve the compiled metafile.
+ if (!metafile.CloseDc()) {
+ NOTREACHED() << "metafile failed";
}
- // Get the size of the compiled EMF.
- unsigned buf_size = emf.GetDataSize();
+ // Get the size of the compiled metafile.
+ unsigned buf_size = metafile.GetDataSize();
DCHECK_GT(buf_size, 128u);
ViewHostMsg_DidPrintPage_Params page_params;
page_params.data_size = 0;
- page_params.emf_data_handle = NULL;
+ page_params.metafile_data_handle = NULL;
page_params.page_number = params.page_number;
page_params.document_cookie = params.params.document_cookie;
page_params.actual_shrink = shrink;
@@ -364,12 +363,12 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
// Windows 2000/XP: When a page in a spooled file exceeds approximately 350
// MB, it can fail to print and not send an error message.
if (buf_size < 350*1024*1024) {
- // Allocate a shared memory buffer to hold the generated EMF data.
+ // Allocate a shared memory buffer to hold the generated metafile data.
if (shared_buf.Create(L"", false, false, buf_size) &&
shared_buf.Map(buf_size)) {
// Copy the bits into shared memory.
- if (emf.GetData(shared_buf.memory(), buf_size)) {
- page_params.emf_data_handle = shared_buf.handle();
+ if (metafile.GetData(shared_buf.memory(), buf_size)) {
+ page_params.metafile_data_handle = shared_buf.handle();
page_params.data_size = buf_size;
} else {
NOTREACHED() << "GetData() failed";
@@ -381,10 +380,11 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
} else {
NOTREACHED() << "Buffer too large: " << buf_size;
}
- emf.CloseEmf();
- if (Send(new ViewHostMsg_DuplicateSection(routing_id(),
- page_params.emf_data_handle,
- &page_params.emf_data_handle))) {
+ metafile.CloseEmf();
+ if (Send(new ViewHostMsg_DuplicateSection(
+ routing_id(),
+ page_params.metafile_data_handle,
+ &page_params.metafile_data_handle))) {
Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params));
}
#else // defined(OS_WIN)
diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc
index 8117acf..b98b728 100644
--- a/chrome/renderer/webplugin_delegate_proxy.cc
+++ b/chrome/renderer/webplugin_delegate_proxy.cc
@@ -29,6 +29,7 @@
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "net/base/mime_util.h"
+#include "printing/native_metafile.h"
#include "webkit/api/public/WebDragData.h"
#include "webkit/api/public/WebString.h"
#include "webkit/api/public/WebVector.h"
@@ -37,10 +38,6 @@
#include "webkit/glue/webplugin.h"
#include "webkit/glue/webview.h"
-#if defined(OS_WIN)
-#include "chrome/common/gfx/emf.h"
-#endif
-
#if defined(OS_POSIX)
#include "chrome/common/ipc_channel_posix.h"
#endif
@@ -579,13 +576,13 @@ void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) {
}
#if defined(OS_WIN)
- gfx::Emf emf;
- if (!emf.CreateFromData(memory.memory(), size)) {
+ printing::NativeMetafile metafile;
+ if (!metafile.CreateFromData(memory.memory(), size)) {
NOTREACHED();
return;
}
// Playback the buffer.
- emf.Playback(context, NULL);
+ metafile.Playback(context, NULL);
#else
// TODO(port): plugin printing.
NOTIMPLEMENTED();
diff --git a/chrome/common/gfx/emf.cc b/printing/emf_win.cc
index 17ffae9..42380443 100644
--- a/chrome/common/gfx/emf.cc
+++ b/printing/emf_win.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/gfx/emf.h"
+#include "printing/emf_win.h"
#include "base/gfx/rect.h"
#include "base/logging.h"
-namespace gfx {
+namespace printing {
Emf::Emf() : emf_(NULL), hdc_(NULL) {
}
@@ -314,4 +314,4 @@ int CALLBACK Emf::Enumerator::EnhMetaFileProc(HDC hdc,
return 1;
}
-} // namespace gfx
+} // namespace printing
diff --git a/chrome/common/gfx/emf.h b/printing/emf_win.h
index 973f1e45..7be747a 100644
--- a/chrome/common/gfx/emf.h
+++ b/printing/emf_win.h
@@ -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 CHROME_COMMON_GFX_EMF_H__
-#define CHROME_COMMON_GFX_EMF_H__
+#ifndef PRINTING_EMF_WIN_H__
+#define PRINTING_EMF_WIN_H__
#include <windows.h>
#include <vector>
@@ -11,8 +11,10 @@
#include "base/basictypes.h"
namespace gfx {
-
class Rect;
+}
+
+namespace printing {
// Simple wrapper class that manage an EMF data stream and its virtual HDC.
class Emf {
@@ -174,6 +176,6 @@ class Emf::Enumerator {
DISALLOW_EVIL_CONSTRUCTORS(Enumerator);
};
-} // namespace gfx
+} // namespace printing
-#endif // CHROME_COMMON_GFX_EMF_H__
+#endif // PRINTING_EMF_WIN_H__
diff --git a/chrome/common/gfx/emf_unittest.cc b/printing/emf_win_unittest.cc
index 4a78e9a..ab817db 100644
--- a/chrome/common/gfx/emf_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/gfx/emf.h"
+#include "printing/emf_win.h"
// For quick access.
#include <wingdi.h>
@@ -10,8 +10,6 @@
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/path_service.h"
-#include "chrome/browser/printing/win_printing_context.h"
-#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -37,7 +35,7 @@ TEST(EmfTest, DC) {
static const int EMF_HEADER_SIZE = 128;
// Simplest use case.
- gfx::Emf emf;
+ printing::Emf emf;
RECT rect = {100, 100, 200, 200};
HDC hdc = CreateCompatibleDC(NULL);
EXPECT_TRUE(hdc != NULL);
@@ -62,6 +60,10 @@ TEST(EmfTest, DC) {
EXPECT_TRUE(DeleteDC(hdc));
}
+// TODO(sverrir): Re-enable after win_printing_context has been moved here.
+/*
+#include "chrome/browser/printing/win_printing_context.h"
+#include "chrome/common/chrome_paths.h"
// Disabled if no "UnitTest printer" exist. Useful to reproduce bug 1186598.
TEST_F(EmfPrintingTest, Enumerate) {
@@ -81,7 +83,7 @@ TEST_F(EmfPrintingTest, Enumerate) {
PathService::Get(chrome::DIR_TEST_DATA, &test_file);
// Load any EMF with an image.
- gfx::Emf emf;
+ printing::Emf emf;
file_util::AppendToPath(&test_file, L"printing");
file_util::AppendToPath(&test_file, L"test4.emf");
std::string emf_data;
@@ -96,9 +98,9 @@ TEST_F(EmfPrintingTest, Enumerate) {
context.NewDocument(L"EmfTest.Enumerate");
context.NewPage();
// Process one at a time.
- gfx::Emf::Enumerator emf_enum(emf, context.context(),
+ printing::Emf::Enumerator emf_enum(emf, context.context(),
&emf.GetBounds().ToRECT());
- for (gfx::Emf::Enumerator::const_iterator itr = emf_enum.begin();
+ for (printing::Emf::Enumerator::const_iterator itr = emf_enum.begin();
itr != emf_enum.end();
++itr) {
// To help debugging.
@@ -112,3 +114,4 @@ TEST_F(EmfPrintingTest, Enumerate) {
context.PageDone();
context.DocumentDone();
}
+*/
diff --git a/printing/native_metafile.h b/printing/native_metafile.h
new file mode 100644
index 0000000..6963089
--- /dev/null
+++ b/printing/native_metafile.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2009 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_H__
+#define PRINTING_NATIVE_METAFILE_H__
+
+// Define a metafile format for the current platform. We use this platform
+// independent define so we can define interfaces in platform agnostic manner.
+// It is still an outstanding design issue whether we create classes on all
+// platforms that have the same interface as Emf or if we change Emf to support
+// multiple platforms (and rename to NativeMetafile).
+
+
+#if defined(OS_WIN)
+
+#include "printing/emf_win.h"
+
+namespace printing {
+
+typedef Emf NativeMetafile;
+
+} // namespace printing
+
+#elif defined(OS_MACOSX)
+
+// TODO(port): Printing using PDF?
+
+#elif defined(OS_LINUX)
+
+// TODO(port): Printing using PostScript?
+
+#endif
+
+
+#endif // PRINTING_NATIVE_METAFILE_H__
diff --git a/printing/printing.gyp b/printing/printing.gyp
index 1980417..899bded 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -15,12 +15,17 @@
'type': '<(library)',
'dependencies': [
'../base/base.gyp:base',
+ '../base/base.gyp:base_gfx',
+
],
'msvs_guid': '9E5416B9-B91B-4029-93F4-102C1AD5CAF4',
'include_dirs': [
'..',
],
'sources': [
+ 'emf_win.cc',
+ 'emf_win.h',
+ 'native_metafile.h',
'units.cc',
'units.h',
],
@@ -49,8 +54,18 @@
'../testing/gtest.gyp:gtestmain',
],
'sources': [
+ 'emf_win_unittest.cc',
'units_unittest.cc',
],
+ 'conditions': [
+ ['OS!="linux"', {'sources/': [['exclude', '_linux_unittest\\.cc$']]}],
+ ['OS!="mac"', {'sources/': [['exclude', '_mac_unittest\\.(cc|mm?)$']]}],
+ ['OS!="win"', {
+ 'sources/': [['exclude', '_win_unittest\\.cc$']]
+ }, { # else: OS=="win"
+ 'sources/': [['exclude', '_posix_unittest\\.cc$']]
+ }],
+ ],
},
],
}