halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
halcanary | 488165e | 2016-04-22 06:10:21 -0700 | [diff] [blame] | 8 | #include "SkMD5.h" |
halcanary | ffe5400 | 2016-03-29 09:09:29 -0700 | [diff] [blame] | 9 | #include "SkMilestone.h" |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 10 | #include "SkPDFMetadata.h" |
| 11 | #include "SkPDFTypes.h" |
bungeman | 221524d | 2016-01-05 14:59:40 -0800 | [diff] [blame] | 12 | #include <utility> |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 13 | |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 14 | #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) |
| 15 | #define SKPDF_STRING_IMPL(X) #X |
| 16 | #define SKPDF_PRODUCER "Skia/PDF m" SKPDF_STRING(SK_MILESTONE) |
| 17 | #define SKPDF_CUSTOM_PRODUCER_KEY "ProductionLibrary" |
| 18 | |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 19 | static SkString pdf_date(const SkTime::DateTime& dt) { |
| 20 | int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes); |
| 21 | char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; |
| 22 | int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; |
| 23 | timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; |
| 24 | return SkStringPrintf( |
| 25 | "D:%04u%02u%02u%02u%02u%02u%c%02d'%02d'", |
| 26 | static_cast<unsigned>(dt.fYear), static_cast<unsigned>(dt.fMonth), |
| 27 | static_cast<unsigned>(dt.fDay), static_cast<unsigned>(dt.fHour), |
| 28 | static_cast<unsigned>(dt.fMinute), |
| 29 | static_cast<unsigned>(dt.fSecond), timezoneSign, timeZoneHours, |
| 30 | timeZoneMinutes); |
| 31 | } |
| 32 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 33 | namespace { |
| 34 | static const struct { |
| 35 | const char* const key; |
| 36 | SkString SkDocument::PDFMetadata::*const valuePtr; |
| 37 | } gMetadataKeys[] = { |
| 38 | {"Title", &SkDocument::PDFMetadata::fTitle}, |
| 39 | {"Author", &SkDocument::PDFMetadata::fAuthor}, |
| 40 | {"Subject", &SkDocument::PDFMetadata::fSubject}, |
| 41 | {"Keywords", &SkDocument::PDFMetadata::fKeywords}, |
| 42 | {"Creator", &SkDocument::PDFMetadata::fCreator}, |
| 43 | }; |
| 44 | } // namespace |
| 45 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 46 | sk_sp<SkPDFObject> SkPDFMetadata::MakeDocumentInformationDict( |
| 47 | const SkDocument::PDFMetadata& metadata) { |
halcanary | ece8392 | 2016-03-08 08:32:12 -0800 | [diff] [blame] | 48 | auto dict = sk_make_sp<SkPDFDict>(); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 49 | for (const auto keyValuePtr : gMetadataKeys) { |
| 50 | const SkString& value = metadata.*(keyValuePtr.valuePtr); |
| 51 | if (value.size() > 0) { |
| 52 | dict->insertString(keyValuePtr.key, value); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 53 | } |
| 54 | } |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 55 | if (metadata.fProducer.isEmpty()) { |
| 56 | dict->insertString("Producer", SKPDF_PRODUCER); |
| 57 | } else { |
| 58 | dict->insertString("Producer", metadata.fProducer); |
| 59 | dict->insertString(SKPDF_CUSTOM_PRODUCER_KEY, SKPDF_PRODUCER); |
| 60 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 61 | if (metadata.fCreation.fEnabled) { |
| 62 | dict->insertString("CreationDate", |
| 63 | pdf_date(metadata.fCreation.fDateTime)); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 64 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 65 | if (metadata.fModified.fEnabled) { |
| 66 | dict->insertString("ModDate", pdf_date(metadata.fModified.fDateTime)); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 67 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 68 | return dict; |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 69 | } |
| 70 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 71 | SkPDFMetadata::UUID SkPDFMetadata::CreateUUID( |
| 72 | const SkDocument::PDFMetadata& metadata) { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 73 | // The main requirement is for the UUID to be unique; the exact |
| 74 | // format of the data that will be hashed is not important. |
| 75 | SkMD5 md5; |
| 76 | const char uuidNamespace[] = "org.skia.pdf\n"; |
| 77 | md5.write(uuidNamespace, strlen(uuidNamespace)); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 78 | double msec = SkTime::GetMSecs(); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 79 | md5.write(&msec, sizeof(msec)); |
| 80 | SkTime::DateTime dateTime; |
| 81 | SkTime::GetDateTime(&dateTime); |
| 82 | md5.write(&dateTime, sizeof(dateTime)); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 83 | if (metadata.fCreation.fEnabled) { |
| 84 | md5.write(&metadata.fCreation.fDateTime, |
| 85 | sizeof(metadata.fCreation.fDateTime)); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 86 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 87 | if (metadata.fModified.fEnabled) { |
| 88 | md5.write(&metadata.fModified.fDateTime, |
| 89 | sizeof(metadata.fModified.fDateTime)); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 90 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 91 | |
| 92 | for (const auto keyValuePtr : gMetadataKeys) { |
| 93 | md5.write(keyValuePtr.key, strlen(keyValuePtr.key)); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 94 | md5.write("\037", 1); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 95 | const SkString& value = metadata.*(keyValuePtr.valuePtr); |
| 96 | md5.write(value.c_str(), value.size()); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 97 | md5.write("\036", 1); |
| 98 | } |
| 99 | SkMD5::Digest digest; |
| 100 | md5.finish(digest); |
| 101 | // See RFC 4122, page 6-7. |
| 102 | digest.data[6] = (digest.data[6] & 0x0F) | 0x30; |
| 103 | digest.data[8] = (digest.data[6] & 0x3F) | 0x80; |
| 104 | static_assert(sizeof(digest) == sizeof(UUID), "uuid_size"); |
| 105 | SkPDFMetadata::UUID uuid; |
| 106 | memcpy(&uuid, &digest, sizeof(digest)); |
| 107 | return uuid; |
| 108 | } |
| 109 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 110 | sk_sp<SkPDFObject> SkPDFMetadata::MakePdfId(const UUID& doc, |
| 111 | const UUID& instance) { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 112 | // /ID [ <81b14aafa313db63dbd6f981e49f94f4> |
| 113 | // <81b14aafa313db63dbd6f981e49f94f4> ] |
halcanary | ece8392 | 2016-03-08 08:32:12 -0800 | [diff] [blame] | 114 | auto array = sk_make_sp<SkPDFArray>(); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 115 | static_assert(sizeof(SkPDFMetadata::UUID) == 16, "uuid_size"); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 116 | array->appendString( |
| 117 | SkString(reinterpret_cast<const char*>(&doc), sizeof(UUID))); |
| 118 | array->appendString( |
| 119 | SkString(reinterpret_cast<const char*>(&instance), sizeof(UUID))); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 120 | return array; |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | #define HEXIFY(INPUT_PTR, OUTPUT_PTR, HEX_STRING, BYTE_COUNT) \ |
| 124 | do { \ |
| 125 | for (int i = 0; i < (BYTE_COUNT); ++i) { \ |
| 126 | uint8_t value = *(INPUT_PTR)++; \ |
| 127 | *(OUTPUT_PTR)++ = (HEX_STRING)[value >> 4]; \ |
| 128 | *(OUTPUT_PTR)++ = (HEX_STRING)[value & 0xF]; \ |
| 129 | } \ |
| 130 | } while (false) |
| 131 | static SkString uuid_to_string(const SkPDFMetadata::UUID& uuid) { |
| 132 | // 8-4-4-4-12 |
| 133 | char buffer[36]; // [32 + 4] |
| 134 | static const char gHex[] = "0123456789abcdef"; |
| 135 | SkASSERT(strlen(gHex) == 16); |
| 136 | char* ptr = buffer; |
| 137 | const uint8_t* data = uuid.fData; |
| 138 | HEXIFY(data, ptr, gHex, 4); |
| 139 | *ptr++ = '-'; |
| 140 | HEXIFY(data, ptr, gHex, 2); |
| 141 | *ptr++ = '-'; |
| 142 | HEXIFY(data, ptr, gHex, 2); |
| 143 | *ptr++ = '-'; |
| 144 | HEXIFY(data, ptr, gHex, 2); |
| 145 | *ptr++ = '-'; |
| 146 | HEXIFY(data, ptr, gHex, 6); |
| 147 | SkASSERT(ptr == buffer + 36); |
| 148 | SkASSERT(data == uuid.fData + 16); |
| 149 | return SkString(buffer, 36); |
| 150 | } |
| 151 | #undef HEXIFY |
| 152 | |
| 153 | namespace { |
halcanary | 70d1554 | 2015-11-22 12:55:04 -0800 | [diff] [blame] | 154 | class PDFXMLObject final : public SkPDFObject { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 155 | public: |
bungeman | 221524d | 2016-01-05 14:59:40 -0800 | [diff] [blame] | 156 | PDFXMLObject(SkString xml) : fXML(std::move(xml)) {} |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 157 | void emitObject(SkWStream* stream, |
halcanary | 530032a | 2016-08-18 14:22:52 -0700 | [diff] [blame] | 158 | const SkPDFObjNumMap& omap) const override { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 159 | SkPDFDict dict("Metadata"); |
| 160 | dict.insertName("Subtype", "XML"); |
| 161 | dict.insertInt("Length", fXML.size()); |
halcanary | 530032a | 2016-08-18 14:22:52 -0700 | [diff] [blame] | 162 | dict.emitObject(stream, omap); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 163 | static const char streamBegin[] = " stream\n"; |
| 164 | stream->write(streamBegin, strlen(streamBegin)); |
| 165 | // Do not compress this. The standard requires that a |
| 166 | // program that does not understand PDF can grep for |
Hal Canary | 55325b7 | 2017-01-03 10:36:17 -0500 | [diff] [blame^] | 167 | // "<?xpacket" and extract the entire XML. |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 168 | stream->write(fXML.c_str(), fXML.size()); |
| 169 | static const char streamEnd[] = "\nendstream"; |
| 170 | stream->write(streamEnd, strlen(streamEnd)); |
| 171 | } |
| 172 | |
| 173 | private: |
| 174 | const SkString fXML; |
| 175 | }; |
| 176 | } // namespace |
| 177 | |
| 178 | static int count_xml_escape_size(const SkString& input) { |
| 179 | int extra = 0; |
| 180 | for (size_t i = 0; i < input.size(); ++i) { |
| 181 | if (input[i] == '&') { |
| 182 | extra += 4; // strlen("&") - strlen("&") |
| 183 | } else if (input[i] == '<') { |
| 184 | extra += 3; // strlen("<") - strlen("<") |
| 185 | } |
| 186 | } |
| 187 | return extra; |
| 188 | } |
| 189 | |
| 190 | const SkString escape_xml(const SkString& input, |
| 191 | const char* before = nullptr, |
| 192 | const char* after = nullptr) { |
| 193 | if (input.size() == 0) { |
| 194 | return input; |
| 195 | } |
| 196 | // "&" --> "&" and "<" --> "<" |
| 197 | // text is assumed to be in UTF-8 |
| 198 | // all strings are xml content, not attribute values. |
| 199 | size_t beforeLen = before ? strlen(before) : 0; |
| 200 | size_t afterLen = after ? strlen(after) : 0; |
| 201 | int extra = count_xml_escape_size(input); |
| 202 | SkString output(input.size() + extra + beforeLen + afterLen); |
| 203 | char* out = output.writable_str(); |
| 204 | if (before) { |
| 205 | strncpy(out, before, beforeLen); |
| 206 | out += beforeLen; |
| 207 | } |
| 208 | static const char kAmp[] = "&"; |
| 209 | static const char kLt[] = "<"; |
| 210 | for (size_t i = 0; i < input.size(); ++i) { |
| 211 | if (input[i] == '&') { |
| 212 | strncpy(out, kAmp, strlen(kAmp)); |
| 213 | out += strlen(kAmp); |
| 214 | } else if (input[i] == '<') { |
| 215 | strncpy(out, kLt, strlen(kLt)); |
| 216 | out += strlen(kLt); |
| 217 | } else { |
| 218 | *out++ = input[i]; |
| 219 | } |
| 220 | } |
| 221 | if (after) { |
| 222 | strncpy(out, after, afterLen); |
| 223 | out += afterLen; |
| 224 | } |
| 225 | // Validate that we haven't written outside of our string. |
| 226 | SkASSERT(out == &output.writable_str()[output.size()]); |
| 227 | *out = '\0'; |
halcanary | 78daeff | 2016-04-07 12:34:59 -0700 | [diff] [blame] | 228 | return output; |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 229 | } |
| 230 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 231 | sk_sp<SkPDFObject> SkPDFMetadata::MakeXMPObject( |
| 232 | const SkDocument::PDFMetadata& metadata, |
| 233 | const UUID& doc, |
| 234 | const UUID& instance) { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 235 | static const char templateString[] = |
| 236 | "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n" |
| 237 | "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"\n" |
| 238 | " x:xmptk=\"Adobe XMP Core 5.4-c005 78.147326, " |
| 239 | "2012/08/23-13:03:03\">\n" |
| 240 | "<rdf:RDF " |
| 241 | "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" |
| 242 | "<rdf:Description rdf:about=\"\"\n" |
| 243 | " xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"\n" |
| 244 | " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" |
| 245 | " xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\"\n" |
| 246 | " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"\n" |
| 247 | " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\">\n" |
| 248 | "<pdfaid:part>2</pdfaid:part>\n" |
| 249 | "<pdfaid:conformance>B</pdfaid:conformance>\n" |
| 250 | "%s" // ModifyDate |
| 251 | "%s" // CreateDate |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 252 | "%s" // xmp:CreatorTool |
| 253 | "<dc:format>application/pdf</dc:format>\n" |
| 254 | "%s" // dc:title |
| 255 | "%s" // dc:description |
| 256 | "%s" // author |
| 257 | "%s" // keywords |
| 258 | "<xmpMM:DocumentID>uuid:%s</xmpMM:DocumentID>\n" |
| 259 | "<xmpMM:InstanceID>uuid:%s</xmpMM:InstanceID>\n" |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 260 | "%s" // pdf:Producer |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 261 | "%s" // pdf:Keywords |
| 262 | "</rdf:Description>\n" |
| 263 | "</rdf:RDF>\n" |
| 264 | "</x:xmpmeta>\n" // Note: the standard suggests 4k of padding. |
| 265 | "<?xpacket end=\"w\"?>\n"; |
| 266 | |
| 267 | SkString creationDate; |
| 268 | SkString modificationDate; |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 269 | if (metadata.fCreation.fEnabled) { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 270 | SkString tmp; |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 271 | metadata.fCreation.fDateTime.toISO8601(&tmp); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 272 | SkASSERT(0 == count_xml_escape_size(tmp)); |
| 273 | // YYYY-mm-ddTHH:MM:SS[+|-]ZZ:ZZ; no need to escape |
halcanary | d51bdae | 2016-04-25 09:25:35 -0700 | [diff] [blame] | 274 | creationDate = SkStringPrintf("<xmp:CreateDate>%s</xmp:CreateDate>\n", |
| 275 | tmp.c_str()); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 276 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 277 | if (metadata.fModified.fEnabled) { |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 278 | SkString tmp; |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 279 | metadata.fModified.fDateTime.toISO8601(&tmp); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 280 | SkASSERT(0 == count_xml_escape_size(tmp)); |
halcanary | d51bdae | 2016-04-25 09:25:35 -0700 | [diff] [blame] | 281 | modificationDate = SkStringPrintf( |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 282 | "<xmp:ModifyDate>%s</xmp:ModifyDate>\n", tmp.c_str()); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 283 | } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 284 | SkString title = |
| 285 | escape_xml(metadata.fTitle, |
| 286 | "<dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">", |
| 287 | "</rdf:li></rdf:Alt></dc:title>\n"); |
| 288 | SkString author = |
| 289 | escape_xml(metadata.fAuthor, "<dc:creator><rdf:Bag><rdf:li>", |
| 290 | "</rdf:li></rdf:Bag></dc:creator>\n"); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 291 | // TODO: in theory, XMP can support multiple authors. Split on a delimiter? |
halcanary | 78daeff | 2016-04-07 12:34:59 -0700 | [diff] [blame] | 292 | SkString subject = escape_xml( |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 293 | metadata.fSubject, |
halcanary | 78daeff | 2016-04-07 12:34:59 -0700 | [diff] [blame] | 294 | "<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">", |
| 295 | "</rdf:li></rdf:Alt></dc:description>\n"); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 296 | SkString keywords1 = |
| 297 | escape_xml(metadata.fKeywords, "<dc:subject><rdf:Bag><rdf:li>", |
| 298 | "</rdf:li></rdf:Bag></dc:subject>\n"); |
| 299 | SkString keywords2 = escape_xml(metadata.fKeywords, "<pdf:Keywords>", |
| 300 | "</pdf:Keywords>\n"); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 301 | // TODO: in theory, keywords can be a list too. |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 302 | |
halcanary | 492d6b5 | 2016-07-07 12:28:30 -0700 | [diff] [blame] | 303 | SkString producer("<pdf:Producer>" SKPDF_PRODUCER "</pdf:Producer>\n"); |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 304 | if (!metadata.fProducer.isEmpty()) { |
| 305 | // TODO: register a developer prefix to make |
| 306 | // <skia:SKPDF_CUSTOM_PRODUCER_KEY> a real XML tag. |
| 307 | producer = escape_xml( |
| 308 | metadata.fProducer, "<pdf:Producer>", |
| 309 | "</pdf:Producer>\n<!-- <skia:" SKPDF_CUSTOM_PRODUCER_KEY ">" |
| 310 | SKPDF_PRODUCER "</skia:" SKPDF_CUSTOM_PRODUCER_KEY "> -->\n"); |
| 311 | } |
| 312 | |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 313 | SkString creator = escape_xml(metadata.fCreator, "<xmp:CreatorTool>", |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 314 | "</xmp:CreatorTool>\n"); |
| 315 | SkString documentID = uuid_to_string(doc); // no need to escape |
| 316 | SkASSERT(0 == count_xml_escape_size(documentID)); |
| 317 | SkString instanceID = uuid_to_string(instance); |
| 318 | SkASSERT(0 == count_xml_escape_size(instanceID)); |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 319 | return sk_make_sp<PDFXMLObject>(SkStringPrintf( |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 320 | templateString, modificationDate.c_str(), creationDate.c_str(), |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 321 | creator.c_str(), title.c_str(), subject.c_str(), author.c_str(), |
| 322 | keywords1.c_str(), documentID.c_str(), instanceID.c_str(), |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 323 | producer.c_str(), keywords2.c_str())); |
halcanary | 3442261 | 2015-10-12 10:11:18 -0700 | [diff] [blame] | 324 | } |
| 325 | |
halcanary | 9f4b332 | 2016-06-30 08:22:04 -0700 | [diff] [blame] | 326 | #undef SKPDF_CUSTOM_PRODUCER_KEY |
| 327 | #undef SKPDF_PRODUCER |
halcanary | 8cd4a24 | 2016-04-07 08:56:15 -0700 | [diff] [blame] | 328 | #undef SKPDF_STRING |
| 329 | #undef SKPDF_STRING_IMPL |