Get rid of deprecated API to add children to PDF tag nodes.

fChildren/fChildCount was replaced with fChildVector and Chromium
migrated to the new API a while back, it's now safe to remove the
older interface.

Bug: chromium:607777
Change-Id: I7311d3b51f1b71209dcc024ae51637536d560619
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297260
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Dominic Mazzoni 2020-06-17 16:46:03 -07:00 committed by Skia Commit-Bot
parent a85e4bf009
commit 8c662a7d6e
4 changed files with 53 additions and 72 deletions

View File

@ -120,10 +120,6 @@ struct StructureElementNode {
SkString fAlt;
SkString fLang;
// Deprecated. Use fChildVector instead.
StructureElementNode* fChildren = nullptr;
size_t fChildCount = 0;
// Deprecated. Use fTypeString instead.
DocumentStructureType fType = DocumentStructureType::kNonStruct;
};

View File

@ -210,23 +210,12 @@ void SkPDFTagTree::Copy(SkPDF::StructureElementNode& node,
dst->fAlt = node.fAlt;
dst->fLang = node.fLang;
// Temporarily support both raw fChildren and fChildVector.
if (node.fChildren) {
size_t childCount = node.fChildCount;
SkPDFTagNode* children = arena->makeArray<SkPDFTagNode>(childCount);
dst->fChildCount = childCount;
dst->fChildren = children;
for (size_t i = 0; i < childCount; ++i) {
Copy(node.fChildren[i], &children[i], arena, nodeMap);
}
} else {
size_t childCount = node.fChildVector.size();
SkPDFTagNode* children = arena->makeArray<SkPDFTagNode>(childCount);
dst->fChildCount = childCount;
dst->fChildren = children;
for (size_t i = 0; i < childCount; ++i) {
Copy(*node.fChildVector[i], &children[i], arena, nodeMap);
}
size_t childCount = node.fChildVector.size();
SkPDFTagNode* children = arena->makeArray<SkPDFTagNode>(childCount);
dst->fChildCount = childCount;
dst->fChildren = children;
for (size_t i = 0; i < childCount; ++i) {
Copy(*node.fChildVector[i], &children[i], arena, nodeMap);
}
dst->fAttributes = std::move(node.fAttributes.fAttrs);

View File

@ -91,7 +91,6 @@ DEF_TEST(SkPDF_tagged_table, r) {
cell->fAttributes.appendStringArray(
"Table", "Headers", headers);
}
cell->fChildCount = 0;
if (cellIndex == 13) {
cell->fAttributes.appendInt("Table", "RowSpan", 2);

View File

@ -35,72 +35,69 @@ DEF_TEST(SkPDF_tagged_doc, r) {
metadata.fModified = now;
// The document tag.
PDFTag root;
root.fNodeId = 1;
root.fType = SkPDF::DocumentStructureType::kDocument;
root.fChildCount = 6;
PDFTag rootChildren[6];
root.fChildren = rootChildren;
auto root = std::make_unique<PDFTag>();
root->fNodeId = 1;
root->fType = SkPDF::DocumentStructureType::kDocument;
// Heading.
PDFTag& h1 = rootChildren[0];
h1.fNodeId = 2;
h1.fType = SkPDF::DocumentStructureType::kH1;
h1.fChildCount = 0;
auto h1 = std::make_unique<PDFTag>();
h1->fNodeId = 2;
h1->fType = SkPDF::DocumentStructureType::kH1;
root->fChildVector.push_back(std::move(h1));
// Initial paragraph.
PDFTag& p = rootChildren[1];
p.fNodeId = 3;
p.fType = SkPDF::DocumentStructureType::kP;
p.fChildCount = 0;
auto p = std::make_unique<PDFTag>();
p->fNodeId = 3;
p->fType = SkPDF::DocumentStructureType::kP;
root->fChildVector.push_back(std::move(p));
// Hidden div. This is never referenced by marked content
// so it should not appear in the resulting PDF.
PDFTag& div = rootChildren[2];
div.fNodeId = 4;
div.fType = SkPDF::DocumentStructureType::kDiv;
div.fChildCount = 0;
auto div = std::make_unique<PDFTag>();
div->fNodeId = 4;
div->fType = SkPDF::DocumentStructureType::kDiv;
root->fChildVector.push_back(std::move(div));
// A bulleted list of two items.
PDFTag& l = rootChildren[3];
l.fNodeId = 5;
l.fType = SkPDF::DocumentStructureType::kL;
l.fChildCount = 4;
PDFTag listChildren[4];
l.fChildren = listChildren;
auto l = std::make_unique<PDFTag>();
l->fNodeId = 5;
l->fType = SkPDF::DocumentStructureType::kL;
PDFTag& lm1 = listChildren[0];
lm1.fNodeId = 6;
lm1.fType = SkPDF::DocumentStructureType::kLbl;
lm1.fChildCount = 0;
PDFTag& li1 = listChildren[1];
li1.fNodeId = 7;
li1.fType = SkPDF::DocumentStructureType::kLI;
li1.fChildCount = 0;
auto lm1 = std::make_unique<PDFTag>();
lm1->fNodeId = 6;
lm1->fType = SkPDF::DocumentStructureType::kLbl;
l->fChildVector.push_back(std::move(lm1));
PDFTag& lm2 = listChildren[2];
lm2.fNodeId = 8;
lm2.fType = SkPDF::DocumentStructureType::kLbl;
lm2.fChildCount = 0;
PDFTag& li2 = listChildren[3];
li2.fNodeId = 9;
li2.fType = SkPDF::DocumentStructureType::kLI;
li2.fChildCount = 0;
auto li1 = std::make_unique<PDFTag>();
li1->fNodeId = 7;
li1->fType = SkPDF::DocumentStructureType::kLI;
l->fChildVector.push_back(std::move(li1));
auto lm2 = std::make_unique<PDFTag>();
lm2->fNodeId = 8;
lm2->fType = SkPDF::DocumentStructureType::kLbl;
l->fChildVector.push_back(std::move(lm2));
auto li2 = std::make_unique<PDFTag>();
li2->fNodeId = 9;
li2->fType = SkPDF::DocumentStructureType::kLI;
l->fChildVector.push_back(std::move(li2));
root->fChildVector.push_back(std::move(l));
// Paragraph spanning two pages.
PDFTag& p2 = rootChildren[4];
p2.fNodeId = 10;
p2.fType = SkPDF::DocumentStructureType::kP;
p2.fChildCount = 0;
auto p2 = std::make_unique<PDFTag>();
p2->fNodeId = 10;
p2->fType = SkPDF::DocumentStructureType::kP;
root->fChildVector.push_back(std::move(p2));
// Image with alt text.
PDFTag& img = rootChildren[5];
img.fNodeId = 11;
img.fType = SkPDF::DocumentStructureType::kFigure;
img.fAlt = "Red box";
img.fChildCount = 0;
auto img = std::make_unique<PDFTag>();
img->fNodeId = 11;
img->fType = SkPDF::DocumentStructureType::kFigure;
img->fAlt = "Red box";
root->fChildVector.push_back(std::move(img));
metadata.fStructureElementTreeRoot = &root;
metadata.fStructureElementTreeRoot = root.get();
sk_sp<SkDocument> document = SkPDF::MakeDocument(
&outputStream, metadata);