OLD | NEW |
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/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
| 12 #include "base/safe_numerics.h" |
12 #include "skia/ext/vector_platform_device_skia.h" | 13 #include "skia/ext/vector_platform_device_skia.h" |
13 #include "third_party/skia/include/core/SkData.h" | 14 #include "third_party/skia/include/core/SkData.h" |
14 #include "third_party/skia/include/core/SkRefCnt.h" | 15 #include "third_party/skia/include/core/SkRefCnt.h" |
15 #include "third_party/skia/include/core/SkScalar.h" | 16 #include "third_party/skia/include/core/SkScalar.h" |
16 #include "third_party/skia/include/core/SkStream.h" | 17 #include "third_party/skia/include/core/SkStream.h" |
17 #include "third_party/skia/include/core/SkTypeface.h" | 18 #include "third_party/skia/include/core/SkTypeface.h" |
18 #include "third_party/skia/include/pdf/SkPDFDevice.h" | 19 #include "third_party/skia/include/pdf/SkPDFDevice.h" |
19 #include "third_party/skia/include/pdf/SkPDFDocument.h" | 20 #include "third_party/skia/include/pdf/SkPDFDocument.h" |
20 #include "ui/gfx/point.h" | 21 #include "ui/gfx/point.h" |
21 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 UMA_HISTOGRAM_ENUMERATION( | 104 UMA_HISTOGRAM_ENUMERATION( |
104 "PrintPreview.FontType", type, | 105 "PrintPreview.FontType", type, |
105 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); | 106 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); | 110 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); |
110 } | 111 } |
111 | 112 |
112 uint32 PdfMetafileSkia::GetDataSize() const { | 113 uint32 PdfMetafileSkia::GetDataSize() const { |
113 return data_->pdf_stream_.getOffset(); | 114 return base::checked_numeric_cast<uint32>(data_->pdf_stream_.getOffset()); |
114 } | 115 } |
115 | 116 |
116 bool PdfMetafileSkia::GetData(void* dst_buffer, | 117 bool PdfMetafileSkia::GetData(void* dst_buffer, |
117 uint32 dst_buffer_size) const { | 118 uint32 dst_buffer_size) const { |
118 if (dst_buffer_size < GetDataSize()) | 119 if (dst_buffer_size < GetDataSize()) |
119 return false; | 120 return false; |
120 | 121 |
121 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); | 122 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); |
122 memcpy(dst_buffer, data->bytes(), dst_buffer_size); | 123 memcpy(dst_buffer, data->bytes(), dst_buffer_size); |
123 return true; | 124 return true; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return NULL; | 232 return NULL; |
232 | 233 |
233 if (!pdf_doc.emitPDF(&pdf_stream)) | 234 if (!pdf_doc.emitPDF(&pdf_stream)) |
234 return NULL; | 235 return NULL; |
235 | 236 |
236 SkAutoDataUnref data(pdf_stream.copyToData()); | 237 SkAutoDataUnref data(pdf_stream.copyToData()); |
237 if (data->size() == 0) | 238 if (data->size() == 0) |
238 return NULL; | 239 return NULL; |
239 | 240 |
240 PdfMetafileSkia* metafile = new PdfMetafileSkia; | 241 PdfMetafileSkia* metafile = new PdfMetafileSkia; |
241 metafile->InitFromData(data->bytes(), data->size()); | 242 metafile->InitFromData(data->bytes(), |
| 243 base::checked_numeric_cast<uint32>(data->size())); |
242 return metafile; | 244 return metafile; |
243 } | 245 } |
244 | 246 |
245 } // namespace printing | 247 } // namespace printing |
OLD | NEW |