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

Side by Side Diff: src/pdf/SkPDFMetadata.cpp

Issue 1823753002: SkPDF: record milestone version in Producer string (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: include Created 4 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 unified diff | Download patch
« no previous file with comments | « include/core/SkMilestone.h ('k') | tests/PDFMetadataAttributeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMilestone.h"
8 #include "SkPDFMetadata.h" 9 #include "SkPDFMetadata.h"
9 #include "SkPDFTypes.h" 10 #include "SkPDFTypes.h"
10 #include <utility> 11 #include <utility>
11 12
12 #ifdef SK_PDF_GENERATE_PDFA 13 #ifdef SK_PDF_GENERATE_PDFA
13 #include "SkMD5.h" 14 #include "SkMD5.h"
14 #endif 15 #endif
15 16
16 static SkString pdf_date(const SkTime::DateTime& dt) { 17 static SkString pdf_date(const SkTime::DateTime& dt) {
17 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes); 18 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes);
18 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; 19 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
19 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; 20 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60;
20 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; 21 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60;
21 return SkStringPrintf( 22 return SkStringPrintf(
22 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'", 23 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'",
23 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth), 24 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth),
24 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour), 25 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour),
25 static_cast<unsigned>(dt.fMinute), 26 static_cast<unsigned>(dt.fMinute),
26 static_cast<unsigned>(dt.fSecond), timezoneSign, timeZoneHours, 27 static_cast<unsigned>(dt.fSecond), timezoneSign, timeZoneHours,
27 timeZoneMinutes); 28 timeZoneMinutes);
28 } 29 }
29 30
31 #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X)
32 #define SKPDF_STRING_IMPL(X) #X
33
30 SkPDFObject* SkPDFMetadata::createDocumentInformationDict() const { 34 SkPDFObject* SkPDFMetadata::createDocumentInformationDict() const {
31 auto dict = sk_make_sp<SkPDFDict>(); 35 auto dict = sk_make_sp<SkPDFDict>();
32 static const char* keys[] = { 36 static const char* keys[] = {
33 "Title", "Author", "Subject", "Keywords", "Creator"}; 37 "Title", "Author", "Subject", "Keywords", "Creator"};
34 for (const char* key : keys) { 38 for (const char* key : keys) {
35 for (const SkDocument::Attribute& keyValue : fInfo) { 39 for (const SkDocument::Attribute& keyValue : fInfo) {
36 if (keyValue.fKey.equals(key)) { 40 if (keyValue.fKey.equals(key)) {
37 dict->insertString(key, keyValue.fValue); 41 dict->insertString(key, keyValue.fValue);
38 } 42 }
39 } 43 }
40 } 44 }
41 dict->insertString("Producer", "Skia/PDF"); 45 dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE));
42 if (fCreation) { 46 if (fCreation) {
43 dict->insertString("CreationDate", pdf_date(*fCreation.get())); 47 dict->insertString("CreationDate", pdf_date(*fCreation.get()));
44 } 48 }
45 if (fModified) { 49 if (fModified) {
46 dict->insertString("ModDate", pdf_date(*fModified.get())); 50 dict->insertString("ModDate", pdf_date(*fModified.get()));
47 } 51 }
48 return dict.release(); 52 return dict.release();
49 } 53 }
50 54
55 #undef SKPDF_STRING
56 #undef SKPDF_STRING_IMPL
57
51 #ifdef SK_PDF_GENERATE_PDFA 58 #ifdef SK_PDF_GENERATE_PDFA
52 SkPDFMetadata::UUID SkPDFMetadata::uuid() const { 59 SkPDFMetadata::UUID SkPDFMetadata::uuid() const {
53 // The main requirement is for the UUID to be unique; the exact 60 // The main requirement is for the UUID to be unique; the exact
54 // format of the data that will be hashed is not important. 61 // format of the data that will be hashed is not important.
55 SkMD5 md5; 62 SkMD5 md5;
56 const char uuidNamespace[] = "org.skia.pdf\n"; 63 const char uuidNamespace[] = "org.skia.pdf\n";
57 md5.write(uuidNamespace, strlen(uuidNamespace)); 64 md5.write(uuidNamespace, strlen(uuidNamespace));
58 double msec = SkTime::GetMSecs(); 65 double msec = SkTime::GetMSecs();
59 md5.write(&msec, sizeof(msec)); 66 md5.write(&msec, sizeof(msec));
60 SkTime::DateTime dateTime; 67 SkTime::DateTime dateTime;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 SkString instanceID = uuid_to_string(instance); 349 SkString instanceID = uuid_to_string(instance);
343 SkASSERT(0 == count_xml_escape_size(instanceID)); 350 SkASSERT(0 == count_xml_escape_size(instanceID));
344 return new PDFXMLObject(sk_string_printf( 351 return new PDFXMLObject(sk_string_printf(
345 templateString, modificationDate.c_str(), creationDate.c_str(), 352 templateString, modificationDate.c_str(), creationDate.c_str(),
346 metadataDate.c_str(), creator.c_str(), title.c_str(), 353 metadataDate.c_str(), creator.c_str(), title.c_str(),
347 subject.c_str(), author.c_str(), keywords1.c_str(), 354 subject.c_str(), author.c_str(), keywords1.c_str(),
348 documentID.c_str(), instanceID.c_str(), keywords2.c_str())); 355 documentID.c_str(), instanceID.c_str(), keywords2.c_str()));
349 } 356 }
350 357
351 #endif // SK_PDF_GENERATE_PDFA 358 #endif // SK_PDF_GENERATE_PDFA
OLDNEW
« no previous file with comments | « include/core/SkMilestone.h ('k') | tests/PDFMetadataAttributeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698