PDF without annotations skips structure tree.
The SkPDFDocument::fTagTree::fRoot is set at document creation time.
This root will initially always be discardable, since no annotations
have been made. As a result it does not make sense to assert on it being
non-discardable, since it should be possible to create a PDF which just
happens to have no annotations added to it.
Change-Id: I2fe336c872805b6937f7c8ea275c0cb4d3438682
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301383
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
diff --git a/tests/PDFTaggedPruningTest.cpp b/tests/PDFTaggedPruningTest.cpp
index da13a3a..6265014 100644
--- a/tests/PDFTaggedPruningTest.cpp
+++ b/tests/PDFTaggedPruningTest.cpp
@@ -81,4 +81,62 @@
outputStream.flush();
}
+// Similar to SkPDF_tagged_pruning but never actually writes out anything annotated.
+// Ensures that nothing goes wring when there are no annotations on an annotated PDF.
+DEF_TEST(SkPDF_tagged_pruning_empty, r) {
+ REQUIRE_PDF_DOCUMENT(SkPDF_tagged, r);
+#ifdef SK_PDF_TEST_TAGS_OUTPUT_PATH
+ SkFILEWStream outputStream(SK_PDF_TEST_TAGS_OUTPUT_PATH);
+#else
+ SkDynamicMemoryWStream outputStream;
+#endif
+
+ SkSize pageSize = SkSize::Make(612, 792); // U.S. Letter
+
+ SkPDF::Metadata metadata;
+ metadata.fTitle = "Example Tagged PDF";
+ metadata.fCreator = "Skia";
+ SkTime::DateTime now;
+ SkTime::GetDateTime(&now);
+ metadata.fCreation = now;
+ metadata.fModified = now;
+
+ // The document tag.
+ auto root = std::make_unique<PDFTag>();
+ root->fNodeId = 1;
+ root->fTypeString = "Document";
+ root->fLang = "en-US";
+
+ // First paragraph.
+ auto p1 = std::make_unique<PDFTag>();
+ p1->fNodeId = 2;
+ p1->fAdditionalNodeIds = {3, 4};
+ p1->fTypeString = "P";
+ root->fChildVector.push_back(std::move(p1));
+
+ // Second paragraph.
+ auto p2 = std::make_unique<PDFTag>();
+ p2->fNodeId = 5;
+ p2->fAdditionalNodeIds = {6, 7};
+ p2->fTypeString = "P";
+ root->fChildVector.push_back(std::move(p2));
+
+ metadata.fStructureElementTreeRoot = root.get();
+ sk_sp<SkDocument> document = SkPDF::MakeDocument(
+ &outputStream, metadata);
+
+ SkPaint paint;
+ paint.setColor(SK_ColorBLACK);
+
+ SkCanvas* canvas =
+ document->beginPage(pageSize.width(),
+ pageSize.height());
+
+ canvas->drawRect(SkRect::MakeXYWH(10, 10, 100, 100), paint);
+
+ document->endPage();
+ document->close();
+ outputStream.flush();
+}
+
#endif