Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 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/SkRefCnt.h" | 13 #include "third_party/skia/include/core/SkRefCnt.h" |
| 14 #include "third_party/skia/include/core/SkScalar.h" | 14 #include "third_party/skia/include/core/SkScalar.h" |
| 15 #include "third_party/skia/include/core/SkStream.h" | 15 #include "third_party/skia/include/core/SkStream.h" |
| 16 #include "third_party/skia/include/core/SkTypeface.h" | 16 #include "third_party/skia/include/core/SkTypeface.h" |
| 17 #include "third_party/skia/include/pdf/SkPDFDevice.h" | 17 #include "third_party/skia/include/pdf/SkPDFDevice.h" |
| 18 #include "third_party/skia/include/pdf/SkPDFDocument.h" | 18 #include "third_party/skia/include/pdf/SkPDFDocument.h" |
| 19 #include "third_party/skia/include/pdf/SkPDFFont.h" | 19 #include "third_party/skia/include/pdf/SkPDFFont.h" |
| 20 #include "third_party/skia/include/pdf/SkPDFPage.h" | 20 #include "third_party/skia/include/pdf/SkPDFPage.h" |
| 21 #include "ui/gfx/point.h" | 21 #include "ui/gfx/point.h" |
| 22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/size.h" | 23 #include "ui/gfx/size.h" |
| 24 | 24 |
| 25 namespace { | |
| 26 typedef base::hash_map<SkFontID, SkAdvancedTypefaceMetrics::FontType> | |
| 27 FontTypeMap; | |
| 28 }; | |
| 29 | |
| 30 namespace printing { | 25 namespace printing { |
| 31 | 26 |
| 32 struct PdfMetafileSkiaData { | 27 struct PdfMetafileSkiaData { |
| 33 SkRefPtr<SkPDFDevice> current_page_; | 28 SkRefPtr<SkPDFDevice> current_page_; |
| 34 SkPDFDocument pdf_doc_; | 29 SkPDFDocument pdf_doc_; |
| 35 SkDynamicMemoryWStream pdf_stream_; | 30 SkDynamicMemoryWStream pdf_stream_; |
| 36 FontTypeMap font_type_stats_; | |
| 37 }; | 31 }; |
| 38 | 32 |
| 39 PdfMetafileSkia::~PdfMetafileSkia() {} | 33 PdfMetafileSkia::~PdfMetafileSkia() {} |
| 40 | 34 |
| 41 bool PdfMetafileSkia::Init() { | 35 bool PdfMetafileSkia::Init() { |
| 42 return true; | 36 return true; |
| 43 } | 37 } |
| 44 bool PdfMetafileSkia::InitFromData(const void* src_buffer, | 38 bool PdfMetafileSkia::InitFromData(const void* src_buffer, |
| 45 uint32 src_buffer_size) { | 39 uint32 src_buffer_size) { |
| 46 return data_->pdf_stream_.write(src_buffer, src_buffer_size); | 40 return data_->pdf_stream_.write(src_buffer, src_buffer_size); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 74 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, | 68 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, |
| 75 const gfx::Rect& content_area, | 69 const gfx::Rect& content_area, |
| 76 const float& scale_factor) { | 70 const float& scale_factor) { |
| 77 NOTREACHED(); | 71 NOTREACHED(); |
| 78 return NULL; | 72 return NULL; |
| 79 } | 73 } |
| 80 | 74 |
| 81 bool PdfMetafileSkia::FinishPage() { | 75 bool PdfMetafileSkia::FinishPage() { |
| 82 DCHECK(data_->current_page_.get()); | 76 DCHECK(data_->current_page_.get()); |
| 83 | 77 |
| 84 const SkTDArray<SkPDFFont*>& font_resources = | |
| 85 data_->current_page_->getFontResources(); | |
| 86 for (int i = 0; i < font_resources.count(); i++) { | |
| 87 SkFontID key = font_resources[i]->typeface()->uniqueID(); | |
| 88 data_->font_type_stats_[key] = font_resources[i]->getType(); | |
| 89 } | |
| 90 | |
| 91 data_->pdf_doc_.appendPage(data_->current_page_); | 78 data_->pdf_doc_.appendPage(data_->current_page_); |
| 92 data_->current_page_ = NULL; | 79 data_->current_page_ = NULL; |
| 93 return true; | 80 return true; |
| 94 } | 81 } |
| 95 | 82 |
| 96 bool PdfMetafileSkia::FinishDocument() { | 83 bool PdfMetafileSkia::FinishDocument() { |
| 97 // Don't do anything if we've already set the data in InitFromData. | 84 // Don't do anything if we've already set the data in InitFromData. |
| 98 if (data_->pdf_stream_.getOffset()) | 85 if (data_->pdf_stream_.getOffset()) |
| 99 return true; | 86 return true; |
| 100 | 87 |
| 101 if (data_->current_page_.get()) | 88 if (data_->current_page_.get()) |
| 102 FinishPage(); | 89 FinishPage(); |
| 103 | 90 |
| 104 for (FontTypeMap::const_iterator it = data_->font_type_stats_.begin(); | 91 typedef base::hash_map<SkFontID, SkAdvancedTypefaceMetrics::FontType> |
| 105 it != data_->font_type_stats_.end(); | 92 FontTypeMap; |
| 93 FontTypeMap font_type_stats; | |
| 94 | |
| 95 const SkTDArray<SkPDFPage*>& pages = data_->pdf_doc_.getPages(); | |
| 96 for (int page_number = 0; page_number < pages.count(); page_number++) { | |
| 97 const SkTDArray<SkPDFFont*>& font_resources = | |
| 98 pages[page_number]->getFontResources(); | |
| 99 for (int font = 0; font < font_resources.count(); font++) { | |
| 100 SkFontID key = font_resources[font]->typeface()->uniqueID(); | |
|
Chris Guillory
2011/05/31 18:15:45
We can call UMA_HISTOGRAM_ENUMERATION here when th
vandebo (ex-Chrome)
2011/05/31 18:55:11
Good point. Done.
| |
| 101 font_type_stats[key] = font_resources[font]->getType(); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 for (FontTypeMap::const_iterator it = font_type_stats.begin(); | |
| 106 it != font_type_stats.end(); | |
| 106 it++) { | 107 it++) { |
| 107 UMA_HISTOGRAM_ENUMERATION( | 108 UMA_HISTOGRAM_ENUMERATION( |
| 108 "PrintPreview.FontType", | 109 "PrintPreview.FontType", |
| 109 it->second, | 110 it->second, |
| 110 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); | 111 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1); |
| 111 } | 112 } |
| 112 | 113 |
| 113 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); | 114 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); |
| 114 } | 115 } |
| 115 | 116 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 result = false; | 196 result = false; |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 return result; | 199 return result; |
| 199 } | 200 } |
| 200 #endif | 201 #endif |
| 201 | 202 |
| 202 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} | 203 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} |
| 203 | 204 |
| 204 } // namespace printing | 205 } // namespace printing |
| OLD | NEW |