Skip to content

Commit

Permalink
Added a DCHECK to validate the metafile page count while handling alp…
Browse files Browse the repository at this point in the history
…ha blend transparency.

Added a member variable |page_count_| in emf_win.h to track the pages count.

BUG=none
TEST=windows printing works after code changes.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80167 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Apr 1, 2011
1 parent 00b1a06 commit 830cf74
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions chrome/renderer/print_web_view_helper_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ void PrintWebViewHelper::RenderPage(
skia::VectorPlatformDevice* platform_device =
static_cast<skia::VectorPlatformDevice*>(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);

// Close the device context to retrieve the compiled metafile.
if (!(*metafile)->FinishDocument())
NOTREACHED();
Expand Down
3 changes: 2 additions & 1 deletion printing/emf_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool DIBFormatNativelySupported(HDC dc, uint32 escape, const BYTE* bits,
return !!supported;
}

Emf::Emf() : emf_(NULL), hdc_(NULL) {
Emf::Emf() : emf_(NULL), hdc_(NULL), page_count_(0) {
}

Emf::~Emf() {
Expand Down Expand Up @@ -421,6 +421,7 @@ bool Emf::StartPage(const gfx::Size& /*page_size*/,
DCHECK(hdc_);
if (!hdc_)
return false;
page_count_++;
PageBreakRecord record(PageBreakRecord::START_PAGE);
return !!GdiComment(hdc_, sizeof(record),
reinterpret_cast<const BYTE *>(&record));
Expand Down
5 changes: 3 additions & 2 deletions printing/emf_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class Emf : public NativeMetafile {
virtual gfx::Rect GetPageBounds(unsigned int page_number) const;

virtual unsigned int GetPageCount() const {
// TODO(dpapad): count the number of times StartPage() is called
return 1;
return page_count_;
}

virtual HDC context() const {
Expand Down Expand Up @@ -106,6 +105,8 @@ class Emf : public NativeMetafile {
// Valid when generating EMF data through a virtual HDC.
HDC hdc_;

int page_count_;

DISALLOW_COPY_AND_ASSIGN(Emf);
};

Expand Down
1 change: 1 addition & 0 deletions printing/emf_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ TEST_F(EmfPrintingTest, PageBreak) {
EXPECT_TRUE(emf.FinishPage());
--pages;
}
EXPECT_EQ(3U, emf.GetPageCount());
EXPECT_TRUE(emf.FinishDocument());
size = emf.GetDataSize();
EXPECT_TRUE(emf.GetDataAsVector(&data));
Expand Down

0 comments on commit 830cf74

Please sign in to comment.