* Optional metadata to be passed into the PDF factory function.
*/
struct PDFMetadata {
+ /**
+ * The document’s title.
+ */
SkString fTitle;
+ /**
+ * The name of the person who created the document.
+ */
SkString fAuthor;
+ /**
+ * The subject of the document.
+ */
SkString fSubject;
+ /**
+ * Keywords associated with the document. Commas may be used
+ * to delineate keywords within the string.
+ */
SkString fKeywords;
+ /**
+ * If the document was converted to PDF from another format,
+ * the name of the conforming product that created the
+ * original document from which it was converted.
+ */
SkString fCreator;
+ /**
+ * The product that is converting this document to PDF.
+ *
+ * Leave fProducer empty to get the default, correct value.
+ */
+ SkString fProducer;
+ /**
+ * The date and time the document was created.
+ */
OptionalTimestamp fCreation;
+ /**
+ * The date and time the document was most recently modified.
+ */
OptionalTimestamp fModified;
};
#include "SkPDFTypes.h"
#include <utility>
+#define SKPDF_STRING(X) SKPDF_STRING_IMPL(X)
+#define SKPDF_STRING_IMPL(X) #X
+#define SKPDF_PRODUCER "Skia/PDF m" SKPDF_STRING(SK_MILESTONE)
+#define SKPDF_CUSTOM_PRODUCER_KEY "ProductionLibrary"
+
static SkString pdf_date(const SkTime::DateTime& dt) {
int timeZoneMinutes = SkToInt(dt.fTimeZoneMinutes);
char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-';
timeZoneMinutes);
}
-#define SKPDF_STRING(X) SKPDF_STRING_IMPL(X)
-#define SKPDF_STRING_IMPL(X) #X
-
namespace {
static const struct {
const char* const key;
dict->insertString(keyValuePtr.key, value);
}
}
- dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE));
+ if (metadata.fProducer.isEmpty()) {
+ dict->insertString("Producer", SKPDF_PRODUCER);
+ } else {
+ dict->insertString("Producer", metadata.fProducer);
+ dict->insertString(SKPDF_CUSTOM_PRODUCER_KEY, SKPDF_PRODUCER);
+ }
if (metadata.fCreation.fEnabled) {
dict->insertString("CreationDate",
pdf_date(metadata.fCreation.fDateTime));
"%s" // keywords
"<xmpMM:DocumentID>uuid:%s</xmpMM:DocumentID>\n"
"<xmpMM:InstanceID>uuid:%s</xmpMM:InstanceID>\n"
- "<pdf:Producer>Skia/PDF m" SKPDF_STRING(SK_MILESTONE) "</pdf:Producer>\n"
+ "%s" // pdf:Producer
"%s" // pdf:Keywords
"</rdf:Description>\n"
"</rdf:RDF>\n"
"</rdf:li></rdf:Bag></dc:subject>\n");
SkString keywords2 = escape_xml(metadata.fKeywords, "<pdf:Keywords>",
"</pdf:Keywords>\n");
-
// TODO: in theory, keywords can be a list too.
+
+ SkString producer("<pdf:Producer>SKPDF_PRODUCER</pdf:Producer>\n");
+ if (!metadata.fProducer.isEmpty()) {
+ // TODO: register a developer prefix to make
+ // <skia:SKPDF_CUSTOM_PRODUCER_KEY> a real XML tag.
+ producer = escape_xml(
+ metadata.fProducer, "<pdf:Producer>",
+ "</pdf:Producer>\n<!-- <skia:" SKPDF_CUSTOM_PRODUCER_KEY ">"
+ SKPDF_PRODUCER "</skia:" SKPDF_CUSTOM_PRODUCER_KEY "> -->\n");
+ }
+
SkString creator = escape_xml(metadata.fCreator, "<xmp:CreatorTool>",
"</xmp:CreatorTool>\n");
SkString documentID = uuid_to_string(doc); // no need to escape
templateString, modificationDate.c_str(), creationDate.c_str(),
creator.c_str(), title.c_str(), subject.c_str(), author.c_str(),
keywords1.c_str(), documentID.c_str(), instanceID.c_str(),
- keywords2.c_str()));
+ producer.c_str(), keywords2.c_str()));
}
+#undef SKPDF_CUSTOM_PRODUCER_KEY
+#undef SKPDF_PRODUCER
#undef SKPDF_STRING
#undef SKPDF_STRING_IMPL