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

Unified Diff: printing/common/pdf_metafile_utils.cc

Issue 2832633002: Add PDF compositor service (Closed)
Patch Set: rebase Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: printing/common/pdf_metafile_utils.cc
diff --git a/printing/common/pdf_metafile_utils.cc b/printing/common/pdf_metafile_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d868c76301de13eaef21d960ced4193c073ce92f
--- /dev/null
+++ b/printing/common/pdf_metafile_utils.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
Lei Zhang 2017/05/04 01:31:10 No (c).
Wei Li 2017/05/04 18:18:28 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "printing/common/pdf_metafile_utils.h"
+
+#include "base/time/time.h"
+#include "third_party/skia/include/core/SkTime.h"
+
+namespace {
+
+SkTime::DateTime TimeToSkTime(base::Time time) {
+ base::Time::Exploded exploded;
+ time.UTCExplode(&exploded);
+ SkTime::DateTime skdate;
+ skdate.fTimeZoneMinutes = 0;
+ skdate.fYear = exploded.year;
+ skdate.fMonth = exploded.month;
+ skdate.fDayOfWeek = exploded.day_of_week;
+ skdate.fDay = exploded.day_of_month;
+ skdate.fHour = exploded.hour;
+ skdate.fMinute = exploded.minute;
+ skdate.fSecond = exploded.second;
+ return skdate;
+}
+
+} // namespace
+
+namespace printing {
+
+sk_sp<SkDocument> MakePdfDocument(const std::string& creator,
+ SkWStream* stream) {
+ SkDocument::PDFMetadata metadata;
+ SkTime::DateTime now = TimeToSkTime(base::Time::Now());
+ metadata.fCreation.fEnabled = true;
+ metadata.fCreation.fDateTime = now;
+ metadata.fModified.fEnabled = true;
+ metadata.fModified.fDateTime = now;
+ metadata.fCreator = creator.empty()
+ ? SkString("Chromium")
+ : SkString(creator.c_str(), creator.size());
+ return SkDocument::MakePDF(stream, SK_ScalarDefaultRasterDPI, metadata,
+ nullptr, false);
+}
+
+} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698