PrintPreview: Implement GetMetafileForCurrentPage() function in PdfMetafileSkia.
This function is required for print preview pipeline sequence. BUG=none TEST=none Review URL: http://codereview.chromium.org/7274026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91269 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -51,7 +51,8 @@ bool PdfMetafileSkia::InitFromData(const void* src_buffer,
|
|||||||
SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
|
SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
|
||||||
const gfx::Size& page_size, const gfx::Rect& content_area,
|
const gfx::Size& page_size, const gfx::Rect& content_area,
|
||||||
const float& scale_factor) {
|
const float& scale_factor) {
|
||||||
DCHECK(data_->current_page_.get() == NULL);
|
DCHECK (!page_outstanding_);
|
||||||
|
page_outstanding_ = true;
|
||||||
|
|
||||||
// Adjust for the margins and apply the scale factor.
|
// Adjust for the margins and apply the scale factor.
|
||||||
SkMatrix transform;
|
SkMatrix transform;
|
||||||
@ -84,7 +85,7 @@ bool PdfMetafileSkia::FinishPage() {
|
|||||||
DCHECK(data_->current_page_.get());
|
DCHECK(data_->current_page_.get());
|
||||||
|
|
||||||
data_->pdf_doc_.appendPage(data_->current_page_);
|
data_->pdf_doc_.appendPage(data_->current_page_);
|
||||||
data_->current_page_ = NULL;
|
page_outstanding_ = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,9 +94,10 @@ bool PdfMetafileSkia::FinishDocument() {
|
|||||||
if (data_->pdf_stream_.getOffset())
|
if (data_->pdf_stream_.getOffset())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (data_->current_page_.get())
|
if (page_outstanding_)
|
||||||
FinishPage();
|
FinishPage();
|
||||||
|
|
||||||
|
data_->current_page_ = NULL;
|
||||||
base::hash_set<SkFontID> font_set;
|
base::hash_set<SkFontID> font_set;
|
||||||
|
|
||||||
const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages();
|
const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages();
|
||||||
@ -234,6 +236,25 @@ bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
|
|||||||
|
|
||||||
PdfMetafileSkia::PdfMetafileSkia()
|
PdfMetafileSkia::PdfMetafileSkia()
|
||||||
: data_(new PdfMetafileSkiaData),
|
: data_(new PdfMetafileSkiaData),
|
||||||
draft_(false) {}
|
draft_(false),
|
||||||
|
page_outstanding_(false) {}
|
||||||
|
|
||||||
|
PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
|
||||||
|
SkPDFDocument pdf_doc;
|
||||||
|
SkDynamicMemoryWStream pdf_stream;
|
||||||
|
if (!pdf_doc.appendPage(data_->current_page_))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!pdf_doc.emitPDF(&pdf_stream))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
SkAutoDataUnref data(pdf_stream.copyToData());
|
||||||
|
if (data.size() == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
PdfMetafileSkia* metafile = new printing::PdfMetafileSkia;
|
||||||
|
metafile->InitFromData(data.bytes(), data.size());
|
||||||
|
return metafile;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace printing
|
} // namespace printing
|
||||||
|
@ -68,12 +68,18 @@ class PdfMetafileSkia : public Metafile {
|
|||||||
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
|
virtual bool SaveToFD(const base::FileDescriptor& fd) const;
|
||||||
#endif // if defined(OS_CHROMEOS)
|
#endif // if defined(OS_CHROMEOS)
|
||||||
|
|
||||||
|
// Return a new metafile containing just the current page in draft mode.
|
||||||
|
PdfMetafileSkia* GetMetafileForCurrentPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scoped_ptr<PdfMetafileSkiaData> data_;
|
scoped_ptr<PdfMetafileSkiaData> data_;
|
||||||
|
|
||||||
// True when a draft version of metafile is requested.
|
// True when a draft version of metafile is requested.
|
||||||
mutable bool draft_;
|
mutable bool draft_;
|
||||||
|
|
||||||
|
// True when finish page is outstanding for current page.
|
||||||
|
bool page_outstanding_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
|
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user