Add separate PDF tag attribute interfaces for names and strings

In PDF files, "names" and "strings" are not the same thing, but I was
conflating them. Separate out the interfaces for adding attributes to
PDF struct tree elements so there's a way to add either a name or a string,
and similarly for arrays of names or arrays of strings.

Fix the table test to correctly use a name for the "Scope" attribute
and an array of strings for the "Headers" attribute.

Bug: chromium:607777
Change-Id: Ib30bded2bbcf96e31ba6925fb062615558dea0db
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296338
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Auto-Submit: Dominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
Dominic Mazzoni 2020-06-14 23:42:46 -07:00 committed by Skia Commit-Bot
parent 3779f448ca
commit 127c607818
3 changed files with 45 additions and 6 deletions

View File

@ -88,13 +88,17 @@ public:
// and then a value of the proper type according to the spec.
void appendInt(const char* owner, const char* name, int value);
void appendFloat(const char* owner, const char* name, float value);
void appendString(const char* owner, const char* name, const char* value);
void appendName(const char* owner, const char* attrName, const char* value);
void appendString(const char* owner, const char* attrName, const char* value);
void appendFloatArray(const char* owner,
const char* name,
const std::vector<float>& value);
void appendNameArray(const char* owner,
const char* attrName,
const std::vector<SkString>& values);
void appendStringArray(const char* owner,
const char* name,
const std::vector<SkString>& value);
const char* attrName,
const std::vector<SkString>& values);
private:
friend class ::SkPDFTagTree;

View File

@ -90,7 +90,7 @@ void SkPDF::AttributeList::appendFloat(
fAttrs->appendObject(std::move(attrDict));
}
void SkPDF::AttributeList::appendString(
void SkPDF::AttributeList::appendName(
const char* owner, const char* name, const char* value) {
if (!fAttrs)
fAttrs = SkPDFMakeArray();
@ -100,6 +100,16 @@ void SkPDF::AttributeList::appendString(
fAttrs->appendObject(std::move(attrDict));
}
void SkPDF::AttributeList::appendString(
const char* owner, const char* name, const char* value) {
if (!fAttrs)
fAttrs = SkPDFMakeArray();
std::unique_ptr<SkPDFDict> attrDict = SkPDFMakeDict();
attrDict->insertName("O", owner);
attrDict->insertString(name, value);
fAttrs->appendObject(std::move(attrDict));
}
void SkPDF::AttributeList::appendFloatArray(
const char* owner, const char* name, const std::vector<float>& value) {
if (!fAttrs)
@ -114,7 +124,7 @@ void SkPDF::AttributeList::appendFloatArray(
fAttrs->appendObject(std::move(attrDict));
}
void SkPDF::AttributeList::appendStringArray(
void SkPDF::AttributeList::appendNameArray(
const char* owner,
const char* name,
const std::vector<SkString>& value) {
@ -130,6 +140,22 @@ void SkPDF::AttributeList::appendStringArray(
fAttrs->appendObject(std::move(attrDict));
}
void SkPDF::AttributeList::appendStringArray(
const char* owner,
const char* name,
const std::vector<SkString>& value) {
if (!fAttrs)
fAttrs = SkPDFMakeArray();
std::unique_ptr<SkPDFDict> attrDict = SkPDFMakeDict();
attrDict->insertName("O", owner);
std::unique_ptr<SkPDFArray> pdfArray = SkPDFMakeArray();
for (SkString element : value) {
pdfArray->appendString(element);
}
attrDict->insertObject(name, std::move(pdfArray));
fAttrs->appendObject(std::move(attrDict));
}
struct SkPDFTagNode {
// Structure element nodes need a unique alphanumeric ID,
// and we need to be able to output them sorted in lexicographic

View File

@ -81,6 +81,15 @@ DEF_TEST(SkPDF_tagged_table, r) {
cell->fTypeString = "TH";
} else {
cell->fTypeString = "TD";
std::vector<SkString> headers;
SkString rowHeaderIdString;
rowHeaderIdString.printf("node%08d", 10 + rowIndex * kColCount);
headers.push_back(rowHeaderIdString);
SkString colHeaderIdString;
colHeaderIdString.printf("node%08d", 10 + colIndex);
headers.push_back(colHeaderIdString);
cell->fAttributes.appendStringArray(
"Table", "Headers", headers);
}
cell->fChildCount = 0;
@ -89,7 +98,7 @@ DEF_TEST(SkPDF_tagged_table, r) {
} else if (cellIndex == 14 || cellIndex == 18) {
cell->fAttributes.appendInt("Table", "ColSpan", 2);
} else if (rowIndex == 0 || colIndex == 0) {
cell->fAttributes.appendString(
cell->fAttributes.appendName(
"Table", "Scope", rowIndex == 0 ? "Column" : "Row");
}
cells.push_back(std::move(cell));