diff options
author | Bryce Thomas <bryct@amazon.com> | 2018-02-06 14:53:05 -0800 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-06 23:35:16 +0000 |
commit | fd5a5081d53d16facd315cb0b5d4b9622ba22d9d (patch) | |
tree | 69081e1d7ddafa54508d2503f9994992e44c9fb4 /src | |
parent | 5dd202dc9002ec7b42279b85ff89ba4780ad394d (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 'src')
-rw-r--r-- | src/svg/SkSVGDevice.cpp | 29 | ||||
-rw-r--r-- | src/svg/SkSVGDevice.h | 1 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index 4a1f2b750a..6bb971d764 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -7,9 +7,11 @@ #include "SkSVGDevice.h" +#include "SkAnnotationKeys.h" #include "SkBase64.h" #include "SkBitmap.h" #include "SkChecksum.h" +#include "SkClipOpPriv.h" #include "SkClipStack.h" #include "SkData.h" #include "SkDraw.h" @@ -22,7 +24,6 @@ #include "SkTypeface.h" #include "SkUtils.h" #include "SkXMLWriter.h" -#include "SkClipOpPriv.h" namespace { @@ -621,6 +622,32 @@ void SkSVGDevice::drawPaint(const SkPaint& paint) { SkIntToScalar(this->height()))); } +void SkSVGDevice::drawAnnotation(const SkRect& rect, const char key[], SkData* value) { + if (!value) { + return; + } + + if (!strcmp(SkAnnotationKeys::URL_Key(), key) || + !strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) { + this->cs().save(); + this->cs().clipRect(rect, this->ctm(), kIntersect_SkClipOp, true); + SkRect transformedRect = this->cs().bounds(this->getGlobalBounds()); + this->cs().restore(); + if (transformedRect.isEmpty()) { + return; + } + + SkString url(static_cast<const char*>(value->data()), value->size() - 1); + AutoElement a("a", fWriter); + a.addAttribute("xlink:href", url.c_str()); + { + AutoElement r("rect", fWriter); + r.addAttribute("fill-opacity", "0.0"); + r.addRectAttributes(transformedRect); + } + } +} + void SkSVGDevice::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { SkPath path; diff --git a/src/svg/SkSVGDevice.h b/src/svg/SkSVGDevice.h index 0e22910412..222e55d83c 100644 --- a/src/svg/SkSVGDevice.h +++ b/src/svg/SkSVGDevice.h @@ -19,6 +19,7 @@ public: protected: void drawPaint(const SkPaint& paint) override; + void drawAnnotation(const SkRect& rect, const char key[], SkData* value) override; void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint& paint) override; void drawRect(const SkRect& r, const SkPaint& paint) override; |