Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 7549001: PrintPreview: Remove |page_number| from StartPageForVectorCanvas function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nit Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/pdf_metafile_skia.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/pdf_metafile_skia.h" 5 #include "printing/pdf_metafile_skia.h"
6 6
7 #include "base/eintr_wrapper.h" 7 #include "base/eintr_wrapper.h"
8 #include "base/file_descriptor_posix.h" 8 #include "base/file_descriptor_posix.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 bool PdfMetafileSkia::Init() { 43 bool PdfMetafileSkia::Init() {
44 return true; 44 return true;
45 } 45 }
46 bool PdfMetafileSkia::InitFromData(const void* src_buffer, 46 bool PdfMetafileSkia::InitFromData(const void* src_buffer,
47 uint32 src_buffer_size) { 47 uint32 src_buffer_size) {
48 return data_->pdf_stream_.write(src_buffer, src_buffer_size); 48 return data_->pdf_stream_.write(src_buffer, src_buffer_size);
49 } 49 }
50 50
51 SkDevice* PdfMetafileSkia::StartPageForVectorCanvas( 51 SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
52 int page_number, const gfx::Size& page_size, const gfx::Rect& content_area, 52 const gfx::Size& page_size, const gfx::Rect& content_area,
53 const float& scale_factor) { 53 const float& scale_factor) {
54 DCHECK_EQ(outstanding_page_number_, kNoOutstandingPage); 54 DCHECK(!page_outstanding_);
55 DCHECK_GE(page_number, 0); 55 page_outstanding_ = true;
56 outstanding_page_number_ = page_number;
57 56
58 // Adjust for the margins and apply the scale factor. 57 // Adjust for the margins and apply the scale factor.
59 SkMatrix transform; 58 SkMatrix transform;
60 transform.setTranslate(SkIntToScalar(content_area.x()), 59 transform.setTranslate(SkIntToScalar(content_area.x()),
61 SkIntToScalar(content_area.y())); 60 SkIntToScalar(content_area.y()));
62 transform.preScale(SkFloatToScalar(scale_factor), 61 transform.preScale(SkFloatToScalar(scale_factor),
63 SkFloatToScalar(scale_factor)); 62 SkFloatToScalar(scale_factor));
64 63
65 // TODO(ctguil): Refactor: don't create the PDF device explicitly here. 64 // TODO(ctguil): Refactor: don't create the PDF device explicitly here.
66 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height()); 65 SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height());
(...skipping 10 matching lines...) Expand all
77 76
78 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, 77 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
79 const gfx::Rect& content_area, 78 const gfx::Rect& content_area,
80 const float& scale_factor) { 79 const float& scale_factor) {
81 NOTREACHED(); 80 NOTREACHED();
82 return NULL; 81 return NULL;
83 } 82 }
84 83
85 bool PdfMetafileSkia::FinishPage() { 84 bool PdfMetafileSkia::FinishPage() {
86 DCHECK(data_->current_page_.get()); 85 DCHECK(data_->current_page_.get());
87 DCHECK_GE(outstanding_page_number_, 0);
88 86
89 data_->pdf_doc_.setPage(outstanding_page_number_ + 1, 87 data_->pdf_doc_.appendPage(data_->current_page_.get());
90 data_->current_page_.get()); 88 page_outstanding_ = false;
91 outstanding_page_number_ = kNoOutstandingPage;
92 return true; 89 return true;
93 } 90 }
94 91
95 bool PdfMetafileSkia::FinishDocument() { 92 bool PdfMetafileSkia::FinishDocument() {
96 // Don't do anything if we've already set the data in InitFromData. 93 // Don't do anything if we've already set the data in InitFromData.
97 if (data_->pdf_stream_.getOffset()) 94 if (data_->pdf_stream_.getOffset())
98 return true; 95 return true;
99 96
100 if (outstanding_page_number_ >= 0) 97 if (page_outstanding_)
101 FinishPage(); 98 FinishPage();
102 99
103 data_->current_page_ = NULL; 100 data_->current_page_ = NULL;
104 base::hash_set<SkFontID> font_set; 101 base::hash_set<SkFontID> font_set;
105 102
106 const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages(); 103 const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages();
107 for (int page_number = 0; page_number < pages.count(); page_number++) { 104 for (int page_number = 0; page_number < pages.count(); page_number++) {
108 const SkTDArray<SkPDFFont*>& font_resources = 105 const SkTDArray<SkPDFFont*>& font_resources =
109 pages[page_number]->getFontResources(); 106 pages[page_number]->getFontResources();
110 for (int font = 0; font < font_resources.count(); font++) { 107 for (int font = 0; font < font_resources.count(); font++) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 DPLOG(WARNING) << "close"; 229 DPLOG(WARNING) << "close";
233 result = false; 230 result = false;
234 } 231 }
235 } 232 }
236 return result; 233 return result;
237 } 234 }
238 #endif 235 #endif
239 236
240 PdfMetafileSkia::PdfMetafileSkia() 237 PdfMetafileSkia::PdfMetafileSkia()
241 : data_(new PdfMetafileSkiaData), 238 : data_(new PdfMetafileSkiaData),
242 outstanding_page_number_(kNoOutstandingPage) { 239 page_outstanding_(false) {
243 } 240 }
244 241
245 PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() { 242 PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
246 SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags); 243 SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags);
247 SkDynamicMemoryWStream pdf_stream; 244 SkDynamicMemoryWStream pdf_stream;
248 if (!pdf_doc.appendPage(data_->current_page_.get())) 245 if (!pdf_doc.appendPage(data_->current_page_.get()))
249 return NULL; 246 return NULL;
250 247
251 if (!pdf_doc.emitPDF(&pdf_stream)) 248 if (!pdf_doc.emitPDF(&pdf_stream))
252 return NULL; 249 return NULL;
253 250
254 SkAutoDataUnref data(pdf_stream.copyToData()); 251 SkAutoDataUnref data(pdf_stream.copyToData());
255 if (data.size() == 0) 252 if (data.size() == 0)
256 return NULL; 253 return NULL;
257 254
258 PdfMetafileSkia* metafile = new printing::PdfMetafileSkia; 255 PdfMetafileSkia* metafile = new printing::PdfMetafileSkia;
259 metafile->InitFromData(data.bytes(), data.size()); 256 metafile->InitFromData(data.bytes(), data.size());
260 return metafile; 257 return metafile;
261 } 258 }
262 259
263 } // namespace printing 260 } // namespace printing
OLDNEW
« no previous file with comments | « printing/pdf_metafile_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698