OLD | NEW |
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 "SkMD5.h" |
8 #include "SkMilestone.h" | 9 #include "SkMilestone.h" |
9 #include "SkPDFMetadata.h" | 10 #include "SkPDFMetadata.h" |
10 #include "SkPDFTypes.h" | 11 #include "SkPDFTypes.h" |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #ifdef SK_PDF_GENERATE_PDFA | |
14 #include "SkMD5.h" | |
15 #endif | |
16 | |
17 static SkString pdf_date(const SkTime::DateTime& dt) { | 14 static SkString pdf_date(const SkTime::DateTime& dt) { |
18 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes); | 15 int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes); |
19 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; | 16 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; |
20 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; | 17 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; |
21 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; | 18 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; |
22 return SkStringPrintf( | 19 return SkStringPrintf( |
23 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'", | 20 "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'", |
24 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth), | 21 static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth), |
25 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour), | 22 static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour), |
26 static_cast<unsigned>(dt.fMinute), | 23 static_cast<unsigned>(dt.fMinute), |
(...skipping 18 matching lines...) Expand all Loading... |
45 dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE)); | 42 dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE)); |
46 if (fCreation) { | 43 if (fCreation) { |
47 dict->insertString("CreationDate", pdf_date(*fCreation.get())); | 44 dict->insertString("CreationDate", pdf_date(*fCreation.get())); |
48 } | 45 } |
49 if (fModified) { | 46 if (fModified) { |
50 dict->insertString("ModDate", pdf_date(*fModified.get())); | 47 dict->insertString("ModDate", pdf_date(*fModified.get())); |
51 } | 48 } |
52 return dict.release(); | 49 return dict.release(); |
53 } | 50 } |
54 | 51 |
55 #ifdef SK_PDF_GENERATE_PDFA | |
56 SkPDFMetadata::UUID SkPDFMetadata::uuid() const { | 52 SkPDFMetadata::UUID SkPDFMetadata::uuid() const { |
57 // The main requirement is for the UUID to be unique; the exact | 53 // The main requirement is for the UUID to be unique; the exact |
58 // format of the data that will be hashed is not important. | 54 // format of the data that will be hashed is not important. |
59 SkMD5 md5; | 55 SkMD5 md5; |
60 const char uuidNamespace[] = "org.skia.pdf\n"; | 56 const char uuidNamespace[] = "org.skia.pdf\n"; |
61 md5.write(uuidNamespace, strlen(uuidNamespace)); | 57 md5.write(uuidNamespace, strlen(uuidNamespace)); |
62 double msec = SkTime::GetMSecs(); | 58 double msec = SkTime::GetMSecs(); |
63 md5.write(&msec, sizeof(msec)); | 59 md5.write(&msec, sizeof(msec)); |
64 SkTime::DateTime dateTime; | 60 SkTime::DateTime dateTime; |
65 SkTime::GetDateTime(&dateTime); | 61 SkTime::GetDateTime(&dateTime); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 SkASSERT(0 == count_xml_escape_size(documentID)); | 339 SkASSERT(0 == count_xml_escape_size(documentID)); |
344 SkString instanceID = uuid_to_string(instance); | 340 SkString instanceID = uuid_to_string(instance); |
345 SkASSERT(0 == count_xml_escape_size(instanceID)); | 341 SkASSERT(0 == count_xml_escape_size(instanceID)); |
346 return new PDFXMLObject(sk_string_printf( | 342 return new PDFXMLObject(sk_string_printf( |
347 templateString, modificationDate.c_str(), creationDate.c_str(), | 343 templateString, modificationDate.c_str(), creationDate.c_str(), |
348 creator.c_str(), title.c_str(), | 344 creator.c_str(), title.c_str(), |
349 subject.c_str(), author.c_str(), keywords1.c_str(), | 345 subject.c_str(), author.c_str(), keywords1.c_str(), |
350 documentID.c_str(), instanceID.c_str(), keywords2.c_str())); | 346 documentID.c_str(), instanceID.c_str(), keywords2.c_str())); |
351 } | 347 } |
352 | 348 |
353 #endif // SK_PDF_GENERATE_PDFA | |
354 | |
355 #undef SKPDF_STRING | 349 #undef SKPDF_STRING |
356 #undef SKPDF_STRING_IMPL | 350 #undef SKPDF_STRING_IMPL |
357 | 351 |
OLD | NEW |