diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-11 21:54:06 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-11 21:54:06 +0000 |
commit | 7d748990b39550c77aa914ba6846885dd7352e10 (patch) | |
tree | 3777582ee9816b3488f218b594db1918e5ebe752 /printing | |
parent | 03e204f307255e8f39aeb002f94b8eb04137e7f9 (diff) | |
download | chromium_src-7d748990b39550c77aa914ba6846885dd7352e10.zip chromium_src-7d748990b39550c77aa914ba6846885dd7352e10.tar.gz chromium_src-7d748990b39550c77aa914ba6846885dd7352e10.tar.bz2 |
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
Diffstat (limited to 'printing')
27 files changed, 150 insertions, 225 deletions
diff --git a/printing/emf_win.h b/printing/emf_win.h index ecc1028..4d8302c 100644 --- a/printing/emf_win.h +++ b/printing/emf_win.h @@ -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); diff --git a/printing/image.cc b/printing/image.cc index a7ae67d..062ac89 100644 --- a/printing/image.cc +++ b/printing/image.cc @@ -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 diff --git a/printing/image.h b/printing/image.h index 5d84c8d..3bed218 100644 --- a/printing/image.h +++ b/printing/image.h @@ -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_; diff --git a/printing/image_cairo.cc b/printing/image_cairo.cc index d19d57e..694fd7d 100644 --- a/printing/image_cairo.cc +++ b/printing/image_cairo.cc @@ -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; } diff --git a/printing/image_mac.cc b/printing/image_mac.cc index b11757d..1ed9e0c 100644 --- a/printing/image_mac.cc +++ b/printing/image_mac.cc @@ -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)); diff --git a/printing/image_win.cc b/printing/image_win.cc index be089dc..c9ad1fe 100644 --- a/printing/image_win.cc +++ b/printing/image_win.cc @@ -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; diff --git a/printing/native_metafile.h b/printing/metafile.h index 8bb9651..264c8fe 100644 --- a/printing/native_metafile.h +++ b/printing/metafile.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 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_ diff --git a/printing/metafile_impl.h b/printing/metafile_impl.h new file mode 100644 index 0000000..d25481d --- /dev/null +++ b/printing/metafile_impl.h @@ -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_ diff --git a/printing/native_metafile_skia_wrapper.cc b/printing/metafile_skia_wrapper.cc index 38de9df..22b58c8 100644 --- a/printing/native_metafile_skia_wrapper.cc +++ b/printing/metafile_skia_wrapper.cc @@ -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) { } diff --git a/printing/metafile_skia_wrapper.h b/printing/metafile_skia_wrapper.h new file mode 100644 index 0000000..751179f --- /dev/null +++ b/printing/metafile_skia_wrapper.h @@ -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_ diff --git a/printing/native_metafile_factory.cc b/printing/native_metafile_factory.cc deleted file mode 100644 index 5db823e..0000000 --- a/printing/native_metafile_factory.cc +++ /dev/null @@ -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 diff --git a/printing/native_metafile_factory.h b/printing/native_metafile_factory.h deleted file mode 100644 index 610970f..0000000 --- a/printing/native_metafile_factory.h +++ /dev/null @@ -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_ diff --git a/printing/native_metafile_skia_wrapper.h b/printing/native_metafile_skia_wrapper.h deleted file mode 100644 index 7eb2887..0000000 --- a/printing/native_metafile_skia_wrapper.h +++ /dev/null @@ -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_ diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h index f3a80aa..fe00ff6 100644 --- a/printing/pdf_metafile_cairo_linux.h +++ b/printing/pdf_metafile_cairo_linux.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(); diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h index 0183246..616d448 100644 --- a/printing/pdf_metafile_cg_mac.h +++ b/printing/pdf_metafile_cg_mac.h @@ -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; diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h index 4e8a003..515c3a8 100644 --- a/printing/pdf_metafile_skia.h +++ b/printing/pdf_metafile_skia.h @@ -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); diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h index 04198da..dab0c9c 100644 --- a/printing/print_dialog_gtk_interface.h +++ b/printing/print_dialog_gtk_interface.h @@ -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 diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 07eeec6d..5a85c1a 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -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 } diff --git a/printing/printed_document.h b/printing/printed_document.h index b577f47..a53b90f 100644 --- a/printing/printed_document.h +++ b/printing/printed_document.h @@ -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); diff --git a/printing/printed_document_cairo.cc b/printing/printed_document_cairo.cc index cb9bbd0..7675b96 100644 --- a/printing/printed_document_cairo.cc +++ b/printing/printed_document_cairo.cc @@ -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) diff --git a/printing/printed_document_mac.cc b/printing/printed_document_mac.cc index 2651516..bb067c88 100644 --- a/printing/printed_document_mac.cc +++ b/printing/printed_document_mac.cc @@ -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); diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index a0719b4..cb25fdef 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -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(); } diff --git a/printing/printed_page.cc b/printing/printed_page.cc index 1661813..ac1a2d8 100644 --- a/printing/printed_page.cc +++ b/printing/printed_page.cc @@ -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( diff --git a/printing/printed_page.h b/printing/printed_page.h index 0fc9069..3771457 100644 --- a/printing/printed_page.h +++ b/printing/printed_page.h @@ -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. diff --git a/printing/printing.gyp b/printing/printing.gyp index 6e9afcb..1a39bfd 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -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. diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc index 552cfbb..6b24063 100644 --- a/printing/printing_context_cairo.cc +++ b/printing/printing_context_cairo.cc @@ -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_); diff --git a/printing/printing_context_cairo.h b/printing/printing_context_cairo.h index 3002b06..2326dea 100644 --- a/printing/printing_context_cairo.h +++ b/printing/printing_context_cairo.h @@ -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. |