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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 1232783007: Cleanup: Fix some misc nits in printing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.cc ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 15 matching lines...) Expand all
26 26
27 #if defined(OS_MACOSX) 27 #if defined(OS_MACOSX)
28 #include "printing/pdf_metafile_cg_mac.h" 28 #include "printing/pdf_metafile_cg_mac.h"
29 #endif 29 #endif
30 30
31 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
32 #include "base/file_descriptor_posix.h" 32 #include "base/file_descriptor_posix.h"
33 #endif 33 #endif
34 34
35 namespace { 35 namespace {
36
36 // This struct represents all the data we need to draw and redraw this 37 // This struct represents all the data we need to draw and redraw this
37 // page into a SkDocument. 38 // page into a SkDocument.
38 struct Page { 39 struct Page {
39 Page(const SkSize& page_size, const SkRect& content_area, float scale) 40 Page(const SkSize& page_size, const SkRect& content_area, float scale)
40 : page_size_(page_size), 41 : page_size_(page_size),
41 content_area_(content_area), 42 content_area_(content_area),
42 scale_factor_(scale), 43 scale_factor_(scale),
43 content_(/*NULL*/) {} 44 content_(/*NULL*/) {}
44 SkSize page_size_; 45 SkSize page_size_;
45 SkRect content_area_; 46 SkRect content_area_;
46 float scale_factor_; 47 float scale_factor_;
47 skia::RefPtr<SkPicture> content_; 48 skia::RefPtr<SkPicture> content_;
48 }; 49 };
49 } // namespace
50 50
51 static bool WriteAssetToBuffer(const SkStreamAsset* asset, 51 bool WriteAssetToBuffer(const SkStreamAsset* asset,
52 void* buffer, 52 void* buffer,
53 size_t size) { 53 size_t size) {
54 // Calling duplicate() keeps original asset state unchanged. 54 // Calling duplicate() keeps original asset state unchanged.
55 scoped_ptr<SkStreamAsset> assetCopy(asset->duplicate()); 55 scoped_ptr<SkStreamAsset> assetCopy(asset->duplicate());
56 size_t length = assetCopy->getLength(); 56 size_t length = assetCopy->getLength();
57 if (length > size) 57 if (length > size)
58 return false; 58 return false;
59 return (length == assetCopy->read(buffer, length)); 59 return (length == assetCopy->read(buffer, length));
60 } 60 }
61 61
62 } // namespace
63
62 namespace printing { 64 namespace printing {
63 65
64 struct PdfMetafileSkiaData { 66 struct PdfMetafileSkiaData {
65 SkPictureRecorder recorder_; // Current recording 67 SkPictureRecorder recorder_; // Current recording
66 68
67 std::vector<Page> pages_; 69 std::vector<Page> pages_;
68 scoped_ptr<SkStreamAsset> pdf_data_; 70 scoped_ptr<SkStreamAsset> pdf_data_;
69 71
70 #if defined(OS_MACOSX) 72 #if defined(OS_MACOSX)
71 PdfMetafileCg pdf_cg_; 73 PdfMetafileCg pdf_cg_;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 280
279 metafile->data_->pages_.push_back(page); 281 metafile->data_->pages_.push_back(page);
280 282
281 if (!metafile->FinishDocument()) // Generate PDF. 283 if (!metafile->FinishDocument()) // Generate PDF.
282 metafile.reset(); 284 metafile.reset();
283 285
284 return metafile.Pass(); 286 return metafile.Pass();
285 } 287 }
286 288
287 } // namespace printing 289 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698