| 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 "chrome/common/chrome_content_client.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 std::string user_agent = GetUserAgent(); |
| 168 info.emplace_back(SkString("Creator"), |
| 169 SkString(user_agent.c_str(), user_agent.size())); |
| 167 SkTime::DateTime now = TimeToSkTime(base::Time::Now()); | 170 SkTime::DateTime now = TimeToSkTime(base::Time::Now()); |
| 168 pdf_doc->setMetadata(info, &now, &now); | 171 pdf_doc->setMetadata(info, &now, &now); |
| 169 if (!pdf_doc->close()) | 172 if (!pdf_doc->close()) |
| 170 return false; | 173 return false; |
| 171 | 174 |
| 172 data_->pdf_data_.reset(pdf_stream.detachAsStream()); | 175 data_->pdf_data_.reset(pdf_stream.detachAsStream()); |
| 173 return true; | 176 return true; |
| 174 } | 177 } |
| 175 | 178 |
| 176 uint32_t PdfMetafileSkia::GetDataSize() const { | 179 uint32_t PdfMetafileSkia::GetDataSize() const { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 304 |
| 302 metafile->data_->pages_.push_back(page); | 305 metafile->data_->pages_.push_back(page); |
| 303 | 306 |
| 304 if (!metafile->FinishDocument()) // Generate PDF. | 307 if (!metafile->FinishDocument()) // Generate PDF. |
| 305 metafile.reset(); | 308 metafile.reset(); |
| 306 | 309 |
| 307 return metafile.Pass(); | 310 return metafile.Pass(); |
| 308 } | 311 } |
| 309 | 312 |
| 310 } // namespace printing | 313 } // namespace printing |
| OLD | NEW |