From 8c662a7d6ef5bba316970d9db9a142e2f0de2197 Mon Sep 17 00:00:00 2001 From: Dominic Mazzoni Date: Wed, 17 Jun 2020 16:46:03 -0700 Subject: [PATCH] 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 Commit-Queue: Ben Wagner --- include/docs/SkPDFDocument.h | 4 -- src/pdf/SkPDFTag.cpp | 23 +++------ tests/PDFTaggedTableTest.cpp | 1 - tests/PDFTaggedTest.cpp | 97 +++++++++++++++++------------------- 4 files changed, 53 insertions(+), 72 deletions(-) diff --git a/include/docs/SkPDFDocument.h b/include/docs/SkPDFDocument.h index d0b2c8813b..0fe9ffafbd 100644 --- a/include/docs/SkPDFDocument.h +++ b/include/docs/SkPDFDocument.h @@ -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; }; diff --git a/src/pdf/SkPDFTag.cpp b/src/pdf/SkPDFTag.cpp index 2effdc16a0..faef307541 100644 --- a/src/pdf/SkPDFTag.cpp +++ b/src/pdf/SkPDFTag.cpp @@ -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(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(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(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); diff --git a/tests/PDFTaggedTableTest.cpp b/tests/PDFTaggedTableTest.cpp index 4afa5bbbfc..4e26f14fca 100644 --- a/tests/PDFTaggedTableTest.cpp +++ b/tests/PDFTaggedTableTest.cpp @@ -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); diff --git a/tests/PDFTaggedTest.cpp b/tests/PDFTaggedTest.cpp index fa1c896cdb..385e6275b6 100644 --- a/tests/PDFTaggedTest.cpp +++ b/tests/PDFTaggedTest.cpp @@ -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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + li1->fNodeId = 7; + li1->fType = SkPDF::DocumentStructureType::kLI; + l->fChildVector.push_back(std::move(li1)); + + auto lm2 = std::make_unique(); + lm2->fNodeId = 8; + lm2->fType = SkPDF::DocumentStructureType::kLbl; + l->fChildVector.push_back(std::move(lm2)); + auto li2 = std::make_unique(); + 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(); + 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(); + 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 document = SkPDF::MakeDocument( &outputStream, metadata);