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/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "printing/print_settings.h" |
13 #include "skia/ext/refptr.h" | 14 #include "skia/ext/refptr.h" |
14 #include "third_party/skia/include/core/SkData.h" | 15 #include "third_party/skia/include/core/SkData.h" |
15 #include "third_party/skia/include/core/SkDocument.h" | 16 #include "third_party/skia/include/core/SkDocument.h" |
16 #include "third_party/skia/include/core/SkPictureRecorder.h" | 17 #include "third_party/skia/include/core/SkPictureRecorder.h" |
17 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
18 #include "third_party/skia/include/core/SkRefCnt.h" | 19 #include "third_party/skia/include/core/SkRefCnt.h" |
19 #include "third_party/skia/include/core/SkScalar.h" | 20 #include "third_party/skia/include/core/SkScalar.h" |
20 #include "third_party/skia/include/core/SkSize.h" | 21 #include "third_party/skia/include/core/SkSize.h" |
21 #include "third_party/skia/include/core/SkStream.h" | 22 #include "third_party/skia/include/core/SkStream.h" |
22 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 skia::AdoptRef(SkDocument::CreatePDF(&pdf_stream)); | 157 skia::AdoptRef(SkDocument::CreatePDF(&pdf_stream)); |
157 for (const auto& page : data_->pages_) { | 158 for (const auto& page : data_->pages_) { |
158 SkCanvas* canvas = pdf_doc->beginPage( | 159 SkCanvas* canvas = pdf_doc->beginPage( |
159 page.page_size_.width(), page.page_size_.height(), &page.content_area_); | 160 page.page_size_.width(), page.page_size_.height(), &page.content_area_); |
160 // No need to save/restore, since this canvas is not reused after endPage() | 161 // No need to save/restore, since this canvas is not reused after endPage() |
161 canvas->scale(page.scale_factor_, page.scale_factor_); | 162 canvas->scale(page.scale_factor_, page.scale_factor_); |
162 canvas->drawPicture(page.content_.get()); | 163 canvas->drawPicture(page.content_.get()); |
163 pdf_doc->endPage(); | 164 pdf_doc->endPage(); |
164 } | 165 } |
165 SkTArray<SkDocument::Attribute> info; | 166 SkTArray<SkDocument::Attribute> info; |
166 info.emplace_back(SkString("Creator"), SkString("Chromium")); | 167 const std::string& user_agent = GetAgent(); |
| 168 info.emplace_back(SkString("Creator"), |
| 169 user_agent.empty() |
| 170 ? SkString("Chromium") |
| 171 : SkString(user_agent.c_str(), user_agent.size())); |
167 SkTime::DateTime now = TimeToSkTime(base::Time::Now()); | 172 SkTime::DateTime now = TimeToSkTime(base::Time::Now()); |
168 pdf_doc->setMetadata(info, &now, &now); | 173 pdf_doc->setMetadata(info, &now, &now); |
169 if (!pdf_doc->close()) | 174 if (!pdf_doc->close()) |
170 return false; | 175 return false; |
171 | 176 |
172 data_->pdf_data_.reset(pdf_stream.detachAsStream()); | 177 data_->pdf_data_.reset(pdf_stream.detachAsStream()); |
173 return true; | 178 return true; |
174 } | 179 } |
175 | 180 |
176 uint32_t PdfMetafileSkia::GetDataSize() const { | 181 uint32_t PdfMetafileSkia::GetDataSize() const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 306 |
302 metafile->data_->pages_.push_back(page); | 307 metafile->data_->pages_.push_back(page); |
303 | 308 |
304 if (!metafile->FinishDocument()) // Generate PDF. | 309 if (!metafile->FinishDocument()) // Generate PDF. |
305 metafile.reset(); | 310 metafile.reset(); |
306 | 311 |
307 return metafile.Pass(); | 312 return metafile.Pass(); |
308 } | 313 } |
309 | 314 |
310 } // namespace printing | 315 } // namespace printing |
OLD | NEW |