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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 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/image.cc ('k') | printing/print_destination_win.cc » ('j') | 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/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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/numerics/safe_conversions.h"
11 #include "base/posix/eintr_wrapper.h" 12 #include "base/posix/eintr_wrapper.h"
12 #include "base/safe_numerics.h"
13 #include "skia/ext/refptr.h" 13 #include "skia/ext/refptr.h"
14 #include "skia/ext/vector_platform_device_skia.h" 14 #include "skia/ext/vector_platform_device_skia.h"
15 #include "third_party/skia/include/core/SkData.h" 15 #include "third_party/skia/include/core/SkData.h"
16 #include "third_party/skia/include/core/SkRefCnt.h" 16 #include "third_party/skia/include/core/SkRefCnt.h"
17 #include "third_party/skia/include/core/SkScalar.h" 17 #include "third_party/skia/include/core/SkScalar.h"
18 #include "third_party/skia/include/core/SkStream.h" 18 #include "third_party/skia/include/core/SkStream.h"
19 #include "third_party/skia/include/core/SkTypeface.h" 19 #include "third_party/skia/include/core/SkTypeface.h"
20 #include "third_party/skia/include/pdf/SkPDFDevice.h" 20 #include "third_party/skia/include/pdf/SkPDFDevice.h"
21 #include "third_party/skia/include/pdf/SkPDFDocument.h" 21 #include "third_party/skia/include/pdf/SkPDFDocument.h"
22 #include "ui/gfx/point.h" 22 #include "ui/gfx/point.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 UMA_HISTOGRAM_ENUMERATION( 105 UMA_HISTOGRAM_ENUMERATION(
106 "PrintPreview.FontType", type, 106 "PrintPreview.FontType", type,
107 SkAdvancedTypefaceMetrics::kOther_Font + 2); 107 SkAdvancedTypefaceMetrics::kOther_Font + 2);
108 } 108 }
109 } 109 }
110 110
111 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); 111 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_);
112 } 112 }
113 113
114 uint32 PdfMetafileSkia::GetDataSize() const { 114 uint32 PdfMetafileSkia::GetDataSize() const {
115 return base::checked_numeric_cast<uint32>(data_->pdf_stream_.getOffset()); 115 return base::checked_cast<uint32>(data_->pdf_stream_.getOffset());
116 } 116 }
117 117
118 bool PdfMetafileSkia::GetData(void* dst_buffer, 118 bool PdfMetafileSkia::GetData(void* dst_buffer,
119 uint32 dst_buffer_size) const { 119 uint32 dst_buffer_size) const {
120 if (dst_buffer_size < GetDataSize()) 120 if (dst_buffer_size < GetDataSize())
121 return false; 121 return false;
122 122
123 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); 123 SkAutoDataUnref data(data_->pdf_stream_.copyToData());
124 memcpy(dst_buffer, data->bytes(), dst_buffer_size); 124 memcpy(dst_buffer, data->bytes(), dst_buffer_size);
125 return true; 125 return true;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 if (!pdf_doc.emitPDF(&pdf_stream)) 235 if (!pdf_doc.emitPDF(&pdf_stream))
236 return NULL; 236 return NULL;
237 237
238 SkAutoDataUnref data(pdf_stream.copyToData()); 238 SkAutoDataUnref data(pdf_stream.copyToData());
239 if (data->size() == 0) 239 if (data->size() == 0)
240 return NULL; 240 return NULL;
241 241
242 PdfMetafileSkia* metafile = new PdfMetafileSkia; 242 PdfMetafileSkia* metafile = new PdfMetafileSkia;
243 metafile->InitFromData(data->bytes(), 243 metafile->InitFromData(data->bytes(),
244 base::checked_numeric_cast<uint32>(data->size())); 244 base::checked_cast<uint32>(data->size()));
245 return metafile; 245 return metafile;
246 } 246 }
247 247
248 } // namespace printing 248 } // namespace printing
OLDNEW
« no previous file with comments | « printing/image.cc ('k') | printing/print_destination_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698