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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 7084021: Add metrics to determine what font types are being used with print preview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 | « no previous file | 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) 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"
11 #include "base/metrics/histogram.h"
10 #include "skia/ext/vector_platform_device_skia.h" 12 #include "skia/ext/vector_platform_device_skia.h"
11 #include "third_party/skia/include/core/SkRefCnt.h" 13 #include "third_party/skia/include/core/SkRefCnt.h"
12 #include "third_party/skia/include/core/SkScalar.h" 14 #include "third_party/skia/include/core/SkScalar.h"
13 #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"
14 #include "third_party/skia/include/pdf/SkPDFDevice.h" 17 #include "third_party/skia/include/pdf/SkPDFDevice.h"
15 #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"
16 #include "third_party/skia/include/pdf/SkPDFPage.h" 20 #include "third_party/skia/include/pdf/SkPDFPage.h"
17 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
18 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
19 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
20 24
25 namespace {
26 typedef base::hash_map<SkFontID, SkAdvancedTypefaceMetrics::FontType>
27 FontTypeMap;
28 };
29
21 namespace printing { 30 namespace printing {
22 31
23 struct PdfMetafileSkiaData { 32 struct PdfMetafileSkiaData {
24 SkRefPtr<SkPDFDevice> current_page_; 33 SkRefPtr<SkPDFDevice> current_page_;
25 SkPDFDocument pdf_doc_; 34 SkPDFDocument pdf_doc_;
26 SkDynamicMemoryWStream pdf_stream_; 35 SkDynamicMemoryWStream pdf_stream_;
36 FontTypeMap font_type_stats_;
27 }; 37 };
28 38
29 PdfMetafileSkia::~PdfMetafileSkia() {} 39 PdfMetafileSkia::~PdfMetafileSkia() {}
30 40
31 bool PdfMetafileSkia::Init() { 41 bool PdfMetafileSkia::Init() {
32 return true; 42 return true;
33 } 43 }
34 bool PdfMetafileSkia::InitFromData(const void* src_buffer, 44 bool PdfMetafileSkia::InitFromData(const void* src_buffer,
35 uint32 src_buffer_size) { 45 uint32 src_buffer_size) {
36 return data_->pdf_stream_.write(src_buffer, src_buffer_size); 46 return data_->pdf_stream_.write(src_buffer, src_buffer_size);
(...skipping 27 matching lines...) Expand all
64 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size, 74 bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
65 const gfx::Rect& content_area, 75 const gfx::Rect& content_area,
66 const float& scale_factor) { 76 const float& scale_factor) {
67 NOTREACHED(); 77 NOTREACHED();
68 return NULL; 78 return NULL;
69 } 79 }
70 80
71 bool PdfMetafileSkia::FinishPage() { 81 bool PdfMetafileSkia::FinishPage() {
72 DCHECK(data_->current_page_.get()); 82 DCHECK(data_->current_page_.get());
73 83
84 const SkTDArray<SkPDFFont*>& font_resources =
Chris Guillory 2011/05/29 01:50:48 Can we not put this logic into FinishDocument() so
vandebo (ex-Chrome) 2011/05/29 06:14:54 We could keep a list of pages instead of just the
Chris Guillory 2011/05/30 16:46:31 For a second I was still thinking that the documen
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
74 data_->pdf_doc_.appendPage(data_->current_page_); 91 data_->pdf_doc_.appendPage(data_->current_page_);
75 data_->current_page_ = NULL; 92 data_->current_page_ = NULL;
76 return true; 93 return true;
77 } 94 }
78 95
79 bool PdfMetafileSkia::FinishDocument() { 96 bool PdfMetafileSkia::FinishDocument() {
80 // Don't do anything if we've already set the data in InitFromData. 97 // Don't do anything if we've already set the data in InitFromData.
81 if (data_->pdf_stream_.getOffset()) 98 if (data_->pdf_stream_.getOffset())
82 return true; 99 return true;
83 100
84 if (data_->current_page_.get()) 101 if (data_->current_page_.get())
85 FinishPage(); 102 FinishPage();
103
104 for (FontTypeMap::const_iterator it = data_->font_type_stats_.begin();
105 it != data_->font_type_stats_.end();
106 it++) {
107 UMA_HISTOGRAM_ENUMERATION(
108 "PrintPreview.FontType",
109 it->second,
110 SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1);
jar (doing other things) 2011/05/29 01:49:20 There are some interesting biases you have in this
111 }
112
86 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_); 113 return data_->pdf_doc_.emitPDF(&data_->pdf_stream_);
87 } 114 }
88 115
89 uint32 PdfMetafileSkia::GetDataSize() const { 116 uint32 PdfMetafileSkia::GetDataSize() const {
90 return data_->pdf_stream_.getOffset(); 117 return data_->pdf_stream_.getOffset();
91 } 118 }
92 119
93 bool PdfMetafileSkia::GetData(void* dst_buffer, 120 bool PdfMetafileSkia::GetData(void* dst_buffer,
94 uint32 dst_buffer_size) const { 121 uint32 dst_buffer_size) const {
95 if (dst_buffer_size < GetDataSize()) 122 if (dst_buffer_size < GetDataSize())
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 result = false; 195 result = false;
169 } 196 }
170 } 197 }
171 return result; 198 return result;
172 } 199 }
173 #endif 200 #endif
174 201
175 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {} 202 PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {}
176 203
177 } // namespace printing 204 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698