OLD | NEW |
1 // Copyright (c) 2012 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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "skia/ext/vector_platform_device_skia.h" | 12 #include "skia/ext/vector_platform_device_skia.h" |
13 #include "third_party/skia/include/core/SkData.h" | 13 #include "third_party/skia/include/core/SkData.h" |
14 #include "third_party/skia/include/core/SkRefCnt.h" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
15 #include "third_party/skia/include/core/SkScalar.h" | 15 #include "third_party/skia/include/core/SkScalar.h" |
16 #include "third_party/skia/include/core/SkStream.h" | 16 #include "third_party/skia/include/core/SkStream.h" |
17 #include "third_party/skia/include/core/SkTypeface.h" | 17 #include "third_party/skia/include/core/SkTypeface.h" |
18 #include "third_party/skia/include/pdf/SkPDFDevice.h" | 18 #include "third_party/skia/include/pdf/SkPDFDevice.h" |
19 #include "third_party/skia/include/pdf/SkPDFDocument.h" | 19 #include "third_party/skia/include/pdf/SkPDFDocument.h" |
| 20 #include "third_party/skia/include/pdf/SkPDFFont.h" |
| 21 #include "third_party/skia/include/pdf/SkPDFPage.h" |
20 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
21 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
22 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
23 | 25 |
24 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
25 #include "printing/pdf_metafile_cg_mac.h" | 27 #include "printing/pdf_metafile_cg_mac.h" |
26 #endif | 28 #endif |
27 | 29 |
28 namespace printing { | 30 namespace printing { |
29 | 31 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 bool PdfMetafileSkia::FinishDocument() { | 89 bool PdfMetafileSkia::FinishDocument() { |
88 // Don't do anything if we've already set the data in InitFromData. | 90 // Don't do anything if we've already set the data in InitFromData. |
89 if (data_->pdf_stream_.getOffset()) | 91 if (data_->pdf_stream_.getOffset()) |
90 return true; | 92 return true; |
91 | 93 |
92 if (page_outstanding_) | 94 if (page_outstanding_) |
93 FinishPage(); | 95 FinishPage(); |
94 | 96 |
95 data_->current_page_ = NULL; | 97 data_->current_page_ = NULL; |
| 98 base::hash_set<SkFontID> font_set; |
96 | 99 |
97 int font_counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]; | 100 const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages(); |
98 // Work around bug in skia for the moment. | 101 for (int page_number = 0; page_number < pages.count(); page_number++) { |
99 memset(font_counts, 0, sizeof(font_counts)); | 102 const SkTDArray<SkPDFFont*>& font_resources = |
100 data_->pdf_doc_.getCountOfFontTypes(font_counts); | 103 pages[page_number]->getFontResources(); |
101 for (int type = 0; | 104 for (int font = 0; font < font_resources.count(); font++) { |
102 type <= SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; | 105 SkFontID font_id = font_resources[font]->typeface()->uniqueID(); |
103 type++) { | 106 if (font_set.find(font_id) == font_set.end()) { |
104 for (int count = 0; count < font_counts[type]; count++) { | 107 font_set.insert(font_id); |
105 UMA_HISTOGRAM_ENUMERATION( | 108 UMA_HISTOGRAM_ENUMERATION( |
106 "PrintPreview.FontType", type, | 109 "PrintPreview.FontType", |
107 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); | 110 font_resources[font]->getType(), |
| 111 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); |
| 112 } |
108 } | 113 } |
109 } | 114 } |
110 | 115 |
111 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); | 116 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); |
112 } | 117 } |
113 | 118 |
114 uint32 PdfMetafileSkia::GetDataSize() const { | 119 uint32 PdfMetafileSkia::GetDataSize() const { |
115 return data_->pdf_stream_.getOffset(); | 120 return data_->pdf_stream_.getOffset(); |
116 } | 121 } |
117 | 122 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 SkAutoDataUnref data(pdf_stream.copyToData()); | 248 SkAutoDataUnref data(pdf_stream.copyToData()); |
244 if (data.size() == 0) | 249 if (data.size() == 0) |
245 return NULL; | 250 return NULL; |
246 | 251 |
247 PdfMetafileSkia* metafile = new PdfMetafileSkia; | 252 PdfMetafileSkia* metafile = new PdfMetafileSkia; |
248 metafile->InitFromData(data.bytes(), data.size()); | 253 metafile->InitFromData(data.bytes(), data.size()); |
249 return metafile; | 254 return metafile; |
250 } | 255 } |
251 | 256 |
252 } // namespace printing | 257 } // namespace printing |
OLD | NEW |