Skip to content

Commit

Permalink
Printing: Standardize on Metafile::Init, removing Emf::CreateFromData…
Browse files Browse the repository at this point in the history
… in the

process and any ifdefs needed for this.

BUG=none
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61834 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jhawkins@chromium.org committed Oct 7, 2010
1 parent 368ddad commit e8980a5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/printing/print_view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void PrintViewManager::DidPrintPage(
NOTIMPLEMENTED() << " this printing code doesn't quite work yet.";
#else
scoped_ptr<NativeMetafile> metafile(new NativeMetafile());
if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) {
if (!metafile->Init(shared_buf.memory(), params.data_size)) {
NOTREACHED() << "Invalid metafile header";
owner_.Stop();
return;
Expand Down
5 changes: 0 additions & 5 deletions chrome/common/common_param_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,8 @@ void ParamTraits<printing::NativeMetafile>::Write(
bool ParamTraits<printing::NativeMetafile>::Read(
const Message* m, void** iter, param_type* p) {
std::vector<uint8> buffer;
#if defined(OS_WIN)
return ReadParam(m, iter, &buffer) &&
p->CreateFromData(&buffer.front(), static_cast<uint32>(buffer.size()));
#else // defined(OS_WIN)
return ReadParam(m, iter, &buffer) &&
p->Init(&buffer.front(), static_cast<uint32>(buffer.size()));
#endif // defined(OS_WIN)
}

void ParamTraits<printing::NativeMetafile>::Log(
Expand Down
2 changes: 1 addition & 1 deletion chrome/renderer/mock_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void MockPrinter::PrintPage(const ViewHostMsg_DidPrintPage_Params& params) {
#endif
metafile_data.Map(params.data_size);
printing::NativeMetafile metafile;
metafile.CreateFromData(metafile_data.memory(), params.data_size);
metafile.Init(metafile_data.memory(), params.data_size);
printing::Image image(metafile);
MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(),
params.data_size,
Expand Down
2 changes: 1 addition & 1 deletion chrome/renderer/webplugin_delegate_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) {

#if defined(OS_WIN)
printing::NativeMetafile metafile;
if (!metafile.CreateFromData(memory.memory(), size)) {
if (!metafile.Init(memory.memory(), size)) {
NOTREACHED();
return;
}
Expand Down
16 changes: 8 additions & 8 deletions printing/emf_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Emf::~Emf() {
DCHECK(!emf_ && !hdc_);
}

bool Emf::Init(const void* src_buffer, uint32 src_buffer_size) {
DCHECK(!emf_ && !hdc_);
emf_ = SetEnhMetaFileBits(src_buffer_size,
reinterpret_cast<const BYTE*>(src_buffer));
DCHECK(emf_);
return emf_ != NULL;
}

bool Emf::CreateDc(HDC sibling, const RECT* rect) {
DCHECK(!emf_ && !hdc_);
hdc_ = CreateEnhMetaFile(sibling, NULL, rect, NULL);
Expand All @@ -70,14 +78,6 @@ bool Emf::CreateFileBackedDc(HDC sibling, const RECT* rect,
return hdc_ != NULL;
}


bool Emf::CreateFromData(const void* buffer, uint32 size) {
DCHECK(!emf_ && !hdc_);
emf_ = SetEnhMetaFileBits(size, reinterpret_cast<const BYTE*>(buffer));
DCHECK(emf_);
return emf_ != NULL;
}

bool Emf::CreateFromFile(const FilePath& metafile_path) {
DCHECK(!emf_ && !hdc_);
emf_ = GetEnhMetaFile(metafile_path.value().c_str());
Expand Down
6 changes: 3 additions & 3 deletions printing/emf_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Emf {
Emf();
~Emf();

// Initializes the Emf with the data in |src_buffer|. Returns true on success.
bool Init(const void* src_buffer, uint32 src_buffer_size);

// Generates a virtual HDC that will record every GDI commands and compile it
// in a EMF data stream.
// hdc is used to setup the default DPI and color settings. hdc is optional.
Expand All @@ -38,9 +41,6 @@ class Emf {
// Similar to the above method but the metafile is backed by a file.
bool CreateFileBackedDc(HDC sibling, const RECT* rect, const FilePath& path);

// Load a EMF data stream. buffer contains EMF data.
bool CreateFromData(const void* buffer, uint32 size);

// Load an EMF file.
bool CreateFromFile(const FilePath& metafile_path);

Expand Down
6 changes: 3 additions & 3 deletions printing/emf_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(EmfTest, DC) {
// Playback the data.
hdc = CreateCompatibleDC(NULL);
EXPECT_TRUE(hdc);
EXPECT_TRUE(emf.CreateFromData(&data.front(), size));
EXPECT_TRUE(emf.Init(&data.front(), size));
RECT output_rect = {0, 0, 10, 10};
EXPECT_TRUE(emf.Playback(hdc, &output_rect));
EXPECT_TRUE(DeleteDC(hdc));
Expand Down Expand Up @@ -91,7 +91,7 @@ TEST_F(EmfPrintingTest, Enumerate) {
std::string emf_data;
file_util::ReadFileToString(emf_file, &emf_data);
ASSERT_TRUE(emf_data.size());
EXPECT_TRUE(emf.CreateFromData(&emf_data[0], emf_data.size()));
EXPECT_TRUE(emf.Init(&emf_data[0], emf_data.size()));

// This will print to file. The reason is that when running inside a
// unit_test, printing::PrintingContext automatically dumps its files to the
Expand Down Expand Up @@ -144,7 +144,7 @@ TEST_F(EmfPrintingTest, PageBreak) {
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = L"Test Job";
int job_id = ::StartDoc(dc.Get(), &di);
EXPECT_TRUE(emf.CreateFromData(&data.front(), size));
EXPECT_TRUE(emf.Init(&data.front(), size));
EXPECT_TRUE(emf.SafePlayback(dc.Get()));
::EndDoc(dc.Get());
// Since presumably the printer is not real, let us just delete the job from
Expand Down
2 changes: 1 addition & 1 deletion printing/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool Image::LoadMetafile(const std::string& data) {
DCHECK(!data.empty());
#if defined(OS_WIN) || defined(OS_MACOSX)
NativeMetafile metafile;
metafile.CreateFromData(data.data(), data.size());
metafile.Init(data.data(), data.size());
return LoadMetafile(metafile);
#else
NOTIMPLEMENTED();
Expand Down
5 changes: 0 additions & 5 deletions printing/pdf_metafile_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ bool PdfMetafile::Init(const void* src_buffer, uint32 src_buffer_size) {
return true;
}

bool PdfMetafile::CreateFromData(const void* src_buffer,
uint32 src_buffer_size) {
return Init(src_buffer, src_buffer_size);
}

void PdfMetafile::StartPage(double width, double height, double scale_factor) {
DCHECK(context_.get());
DCHECK(!page_is_open_);
Expand Down
2 changes: 0 additions & 2 deletions printing/pdf_metafile_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class PdfMetafile {

// Initializes a copy of metafile from PDF data. Returns true on success.
bool Init(const void* src_buffer, uint32 src_buffer_size);
// Alias for Init, for compatibility with Emf-based code.
bool CreateFromData(const void* src_buffer, uint32 src_buffer_size);

// Prepares a new pdf page with the given width and height and a scale
// factor to use for the drawing.
Expand Down

0 comments on commit e8980a5

Please sign in to comment.