Skip to content

Commit

Permalink
Make Metafile::StartPageForVectorCanvas take the page number as an ar…
Browse files Browse the repository at this point in the history
…gument.

This will let us add pages to a metafile out of order for print preview.
Also, make PdfMetafileSkia::GetMetafileForCurrentPage use draft mode, now that it's available.

BUG=NONE
TEST=NONE


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93763 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
vandebo@chromium.org committed Jul 23, 2011
1 parent ad9d525 commit 19b9d3b
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion chrome/renderer/print_web_view_helper_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void PrintWebViewHelper::PrintPageInternal(
content_width_in_points, content_height_in_points);

SkDevice* device = metafile->StartPageForVectorCanvas(
page_size, content_area, 1.0f);
params.page_number, page_size, content_area, 1.0f);
if (!device)
return;

Expand Down
2 changes: 1 addition & 1 deletion chrome/renderer/print_web_view_helper_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
{
#if defined(USE_SKIA)
SkDevice* device = metafile->StartPageForVectorCanvas(
page_size, content_area, scale_factor);
page_number, page_size, content_area, scale_factor);
if (!device)
return;

Expand Down
3 changes: 2 additions & 1 deletion chrome/renderer/print_web_view_helper_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void PrintWebViewHelper::RenderPage(
static_cast<int>(content_width_in_points),
static_cast<int>(content_height_in_points));
SkDevice* device = (*metafile)->StartPageForVectorCanvas(
page_size, content_area, frame->getPrintPageShrink(page_number));
page_number, page_size, content_area,
frame->getPrintPageShrink(page_number));
DCHECK(device);
// The printPage method may take a reference to the canvas we pass down, so it
// can't be a stack object.
Expand Down
3 changes: 2 additions & 1 deletion printing/emf_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const {
}

SkDevice* Emf::StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK(page_number == page_count_);
if (!StartPage(page_size, content_area, scale_factor))
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions printing/emf_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Emf : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);
// Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
// (since StartPage and EndPage do not work in a metafile DC). Only valid
// when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are
Expand Down
3 changes: 2 additions & 1 deletion printing/metafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class Metafile {

// This method calls StartPage and then returns an appropriate
// VectorPlatformDevice implementation bound to the context created by
// StartPage or NULL on error.
// StartPage or NULL on error. |page_number| is zero based.
virtual SkDevice* StartPageForVectorCanvas(
int page_number,
const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor) = 0;
Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cairo_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ bool PdfMetafileCairo::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileCairo::StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
int /*page_number*/, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor) {
if (!StartPage(page_size, content_area, scale_factor))
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cairo_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class PdfMetafileCairo : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);

virtual bool StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
Expand Down
2 changes: 1 addition & 1 deletion printing/pdf_metafile_cg_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool PdfMetafileCg::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileCg::StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
NOTIMPLEMENTED();
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cg_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PdfMetafileCg : public Metafile, public base::ThreadChecker {

// Not implemented on mac.
virtual SkDevice* StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);
virtual bool StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor);
Expand Down
21 changes: 12 additions & 9 deletions printing/pdf_metafile_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ bool PdfMetafileSkia::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
const gfx::Size& page_size, const gfx::Rect& content_area,
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK (!page_outstanding_);
page_outstanding_ = true;
DCHECK_EQ(outstanding_page_number_, kNoOutstandingPage);
DCHECK_GE(page_number, 0);
outstanding_page_number_ = page_number;

// Adjust for the margins and apply the scale factor.
SkMatrix transform;
Expand Down Expand Up @@ -83,9 +84,11 @@ bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,

bool PdfMetafileSkia::FinishPage() {
DCHECK(data_->current_page_.get());
DCHECK_GE(outstanding_page_number_, 0);

data_->pdf_doc_.appendPage(data_->current_page_.get());
page_outstanding_ = false;
data_->pdf_doc_.setPage(outstanding_page_number_ + 1,
data_->current_page_.get());
outstanding_page_number_ = kNoOutstandingPage;
return true;
}

Expand All @@ -94,7 +97,7 @@ bool PdfMetafileSkia::FinishDocument() {
if (data_->pdf_stream_.getOffset())
return true;

if (page_outstanding_)
if (outstanding_page_number_ >= 0)
FinishPage();

data_->current_page_ = NULL;
Expand Down Expand Up @@ -236,11 +239,11 @@ bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {

PdfMetafileSkia::PdfMetafileSkia()
: data_(new PdfMetafileSkiaData),
draft_(false),
page_outstanding_(false) {}
outstanding_page_number_(kNoOutstandingPage) {
}

PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
SkPDFDocument pdf_doc;
SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags);
SkDynamicMemoryWStream pdf_stream;
if (!pdf_doc.appendPage(data_->current_page_.get()))
return NULL;
Expand Down
10 changes: 5 additions & 5 deletions printing/pdf_metafile_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PdfMetafileSkia : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
int page_number,
const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor);
Expand Down Expand Up @@ -72,13 +73,12 @@ class PdfMetafileSkia : public Metafile {
PdfMetafileSkia* GetMetafileForCurrentPage();

private:
scoped_ptr<PdfMetafileSkiaData> data_;
static const int kNoOutstandingPage = -1;

// True when a draft version of metafile is requested.
mutable bool draft_;
scoped_ptr<PdfMetafileSkiaData> data_;

// True when finish page is outstanding for current page.
bool page_outstanding_;
// Page number of the outstanding page, or kNoOutstandingPage.
int outstanding_page_number_;

DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
};
Expand Down

0 comments on commit 19b9d3b

Please sign in to comment.