[pdf] Add AttributeList::appendTextString
Bug: 467952961
Change-Id: I3e6605e2d805606e45b9b079fe42c8c89fddd9cb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1123456
Auto-Submit: Ben Wagner <bungeman@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
diff --git a/include/docs/SkPDFDocument.h b/include/docs/SkPDFDocument.h
index 474fb53..c7ec7f0 100644
--- a/include/docs/SkPDFDocument.h
+++ b/include/docs/SkPDFDocument.h
@@ -41,6 +41,7 @@
void appendInt(const char* owner, const char* name, int value);
void appendFloat(const char* owner, const char* name, float value);
void appendName(const char* owner, const char* attrName, const char* value);
+ void appendTextString(const char* owner, const char* attrName, const char* value);
void appendFloatArray(const char* owner,
const char* name,
const std::vector<float>& value);
diff --git a/src/pdf/SkPDFTag.cpp b/src/pdf/SkPDFTag.cpp
index fc4ace0..6ffb99a 100644
--- a/src/pdf/SkPDFTag.cpp
+++ b/src/pdf/SkPDFTag.cpp
@@ -157,6 +157,16 @@
fAttrs->appendObject(std::move(attrDict));
}
+void SkPDF::AttributeList::appendTextString(const char* owner, const char* name, const char* value){
+ if (!fAttrs) {
+ fAttrs = SkPDFMakeArray();
+ }
+ std::unique_ptr<SkPDFDict> attrDict = SkPDFMakeDict();
+ attrDict->insertName("O", owner);
+ attrDict->insertTextString(name, value);
+ fAttrs->appendObject(std::move(attrDict));
+}
+
void SkPDF::AttributeList::appendFloatArray(const char* owner, const char* name,
const std::vector<float>& value) {
if (!fAttrs) {
diff --git a/tests/PDFTaggedTableTest.cpp b/tests/PDFTaggedTableTest.cpp
index 348a577..d885242 100644
--- a/tests/PDFTaggedTableTest.cpp
+++ b/tests/PDFTaggedTableTest.cpp
@@ -81,6 +81,7 @@
table->fTypeString = "Table";
auto& rows = table->fChildVector;
table->fAttributes.appendFloatArray("Layout", "BBox", {72, 72, 360, 360});
+ table->fAttributes.appendTextString("Table", "Summary", "Fuel efficiency");
for (int rowIndex = 0; rowIndex < kRowCount; rowIndex++) {
auto row = std::make_unique<PDFTag>();