aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/AnnotationTest.cpp
diff options
context:
space:
mode:
authorGravatar Bryce Thomas <bryct@amazon.com>2018-02-06 14:53:05 -0800
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-06 23:35:16 +0000
commitfd5a5081d53d16facd315cb0b5d4b9622ba22d9d (patch)
tree69081e1d7ddafa54508d2503f9994992e44c9fb4 /tests/AnnotationTest.cpp
parent5dd202dc9002ec7b42279b85ff89ba4780ad394d (diff)
Add link annotation support to SkSVGDevice.
This CL implements |SkSVGDevice::drawAnnotation|, overridden from |SKBaseDevice|. |drawAnnotation| supports annotating rectangular areas of a Skia device. Previous to this change, annotations are being used in |SkPDFDevice| to include hyperlinked rectangular areas in .pdf documents. This CL implements the SVG equivalent of this PDF feature. BUG=skia:7581 Docs-Preview: https://skia.org/?cl=104680 Change-Id: I92ae01ceb7ae10cd2010bebab2a58dcfe48ef253 Reviewed-on: https://skia-review.googlesource.com/104680 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'tests/AnnotationTest.cpp')
-rw-r--r--tests/AnnotationTest.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index cc2fd1f912..b49b80d545 100644
--- a/tests/AnnotationTest.cpp
+++ b/tests/AnnotationTest.cpp
@@ -8,7 +8,9 @@
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDocument.h"
+#include "SkSVGCanvas.h"
#include "SkStream.h"
+#include "SkXMLWriter.h"
#include "Test.h"
/** Returns true if data (may contain null characters) contains needle (null
@@ -57,8 +59,8 @@ DEF_TEST(Annotation_PdfLink, reporter) {
REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots "));
}
-DEF_TEST(Annotation_NamedDestination, reporter) {
- REQUIRE_PDF_DOCUMENT(Annotation_NamedDestination, reporter);
+DEF_TEST(Annotation_PdfDefineNamedDestination, reporter) {
+ REQUIRE_PDF_DOCUMENT(Annotation_PdfNamedDestination, reporter);
SkDynamicMemoryWStream outStream;
sk_sp<SkDocument> doc(SkDocument::MakePDF(&outStream));
SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
@@ -75,3 +77,42 @@ DEF_TEST(Annotation_NamedDestination, reporter) {
REPORTER_ASSERT(reporter,
ContainsString(rawOutput, out->size(), "/example "));
}
+
+DEF_TEST(Annotation_SvgLink, reporter) {
+ SkDynamicMemoryWStream outStream;
+ std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(&outStream));
+ SkRect bounds = SkRect::MakeIWH(400, 400);
+ std::unique_ptr<SkCanvas> canvas = SkSVGCanvas::Make(bounds, xmlWriter.get());
+
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), SkIntToScalar(288),
+ SkIntToScalar(72));
+ sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
+ SkAnnotateRectWithURL(canvas.get(), r, data.get());
+
+ canvas->flush();
+ sk_sp<SkData> out = outStream.detachAsData();
+ const char* rawOutput = (const char*)out->data();
+
+ REPORTER_ASSERT(reporter,
+ ContainsString(rawOutput, out->size(), "a xlink:href=\"http://www.gooogle.com\""));
+}
+
+DEF_TEST(Annotation_SvgLinkNamedDestination, reporter) {
+ SkDynamicMemoryWStream outStream;
+ std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(&outStream));
+ SkRect bounds = SkRect::MakeIWH(400, 400);
+ std::unique_ptr<SkCanvas> canvas = SkSVGCanvas::Make(bounds, xmlWriter.get());
+
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), SkIntToScalar(288),
+ SkIntToScalar(72));
+ sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com/#NamedDestination"));
+ SkAnnotateLinkToDestination(canvas.get(), r, data.get());
+
+ canvas->flush();
+ sk_sp<SkData> out = outStream.detachAsData();
+ const char* rawOutput = (const char*)out->data();
+
+ REPORTER_ASSERT(reporter,
+ ContainsString(rawOutput, out->size(),
+ "a xlink:href=\"http://www.gooogle.com/#NamedDestination\""));
+}