summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
Diffstat (limited to 'printing')
-rw-r--r--printing/image.cc6
-rw-r--r--printing/native_metafile_factory.cc21
-rw-r--r--printing/native_metafile_factory.h14
3 files changed, 37 insertions, 4 deletions
diff --git a/printing/image.cc b/printing/image.cc
index 2f5d7e3..87a6f7e 100644
--- a/printing/image.cc
+++ b/printing/image.cc
@@ -147,8 +147,10 @@ bool Image::LoadPng(const std::string& compressed) {
bool Image::LoadMetafile(const std::string& data) {
DCHECK(!data.empty());
scoped_ptr<NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
- metafile->InitFromData(data.data(), data.size());
+ printing::NativeMetafileFactory::CreateFromData(data.data(),
+ data.size()));
+ if(!metafile.get())
+ return false;
return LoadMetafile(*metafile);
}
diff --git a/printing/native_metafile_factory.cc b/printing/native_metafile_factory.cc
index f971452..f31994b 100644
--- a/printing/native_metafile_factory.cc
+++ b/printing/native_metafile_factory.cc
@@ -4,6 +4,8 @@
#include "printing/native_metafile_factory.h"
+#include "base/scoped_ptr.h"
+
#if defined(OS_WIN)
#include "printing/emf_win.h"
#elif defined(OS_MACOSX)
@@ -15,7 +17,24 @@
namespace printing {
// static
-printing::NativeMetafile* NativeMetafileFactory::Create() {
+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)
diff --git a/printing/native_metafile_factory.h b/printing/native_metafile_factory.h
index b13f17a..610970f 100644
--- a/printing/native_metafile_factory.h
+++ b/printing/native_metafile_factory.h
@@ -17,11 +17,23 @@ namespace printing {
class NativeMetafileFactory {
public:
// This method returns a pointer to the appropriate NativeMetafile object
- // according to the platform.
+ // 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);
};