diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 02:08:57 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 02:08:57 +0000 |
commit | 19b9d3b580c92f4cf80854227d6d4b366bc34871 (patch) | |
tree | 2026e7414e24197ef16d6caa6f0735b8b20e3f51 | |
parent | ad9d525a9aac5e36280d1274e1b8efd6f4e58632 (diff) | |
download | chromium_src-19b9d3b580c92f4cf80854227d6d4b366bc34871.zip chromium_src-19b9d3b580c92f4cf80854227d6d4b366bc34871.tar.gz chromium_src-19b9d3b580c92f4cf80854227d6d4b366bc34871.tar.bz2 |
Make Metafile::StartPageForVectorCanvas take the page number as an argument.
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
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_mac.mm | 2 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 3 | ||||
-rw-r--r-- | printing/emf_win.cc | 3 | ||||
-rw-r--r-- | printing/emf_win.h | 4 | ||||
-rw-r--r-- | printing/metafile.h | 3 | ||||
-rw-r--r-- | printing/pdf_metafile_cairo_linux.cc | 4 | ||||
-rw-r--r-- | printing/pdf_metafile_cairo_linux.h | 4 | ||||
-rw-r--r-- | printing/pdf_metafile_cg_mac.cc | 2 | ||||
-rw-r--r-- | printing/pdf_metafile_cg_mac.h | 4 | ||||
-rw-r--r-- | printing/pdf_metafile_skia.cc | 21 | ||||
-rw-r--r-- | printing/pdf_metafile_skia.h | 10 |
12 files changed, 34 insertions, 28 deletions
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index 8c6dad9..f293e21 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -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; diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm index 3836161f..f5ded39 100644 --- a/chrome/renderer/print_web_view_helper_mac.mm +++ b/chrome/renderer/print_web_view_helper_mac.mm @@ -82,7 +82,7 @@ void PrintWebViewHelper::RenderPage( { #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; diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 4627e0d..b25cafd 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -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. diff --git a/printing/emf_win.cc b/printing/emf_win.cc index 4cb8530..920d64f 100644 --- a/printing/emf_win.cc +++ b/printing/emf_win.cc @@ -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; diff --git a/printing/emf_win.h b/printing/emf_win.h index f7e0ed5..a4584c9 100644 --- a/printing/emf_win.h +++ b/printing/emf_win.h @@ -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 diff --git a/printing/metafile.h b/printing/metafile.h index 84c0556..dbb838c 100644 --- a/printing/metafile.h +++ b/printing/metafile.h @@ -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; diff --git a/printing/pdf_metafile_cairo_linux.cc b/printing/pdf_metafile_cairo_linux.cc index af2aa5c..581b158 100644 --- a/printing/pdf_metafile_cairo_linux.cc +++ b/printing/pdf_metafile_cairo_linux.cc @@ -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; diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h index 6f07ae0..62fd814 100644 --- a/printing/pdf_metafile_cairo_linux.h +++ b/printing/pdf_metafile_cairo_linux.h @@ -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, diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc index 994f58f..6206552 100644 --- a/printing/pdf_metafile_cg_mac.cc +++ b/printing/pdf_metafile_cg_mac.cc @@ -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; diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h index 5a7f56d..488abe8 100644 --- a/printing/pdf_metafile_cg_mac.h +++ b/printing/pdf_metafile_cg_mac.h @@ -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); diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc index 1f08ad0..638fa7b 100644 --- a/printing/pdf_metafile_skia.cc +++ b/printing/pdf_metafile_skia.cc @@ -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; @@ -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; } @@ -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; @@ -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; diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h index 5d6d448..4ce5337 100644 --- a/printing/pdf_metafile_skia.h +++ b/printing/pdf_metafile_skia.h @@ -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); @@ -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); }; |