diff options
author | Hal Canary <halcanary@google.com> | 2017-02-22 15:55:06 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-22 23:23:09 +0000 |
commit | 9cd21683cae5c575be102f072d2718bab37eac9c (patch) | |
tree | 515fd9267a033df299cf03e3956146a554e96804 /src | |
parent | a41c2aa338713b1f18821a90dbca46b4c61c6c66 (diff) |
SkPDF: stop using RasterClip for drawAnnotation()
Change-Id: Idc3a4151f1b6bd3cb11b59e39ddb1458af385035
Reviewed-on: https://skia-review.googlesource.com/8891
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 51 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.h | 2 |
2 files changed, 27 insertions, 26 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 36c1418d68..dbe4c84da0 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -511,12 +511,13 @@ void SkPDFDevice::cleanUp() { void SkPDFDevice::drawAnnotation(const SkDraw& d, const SkRect& rect, const char key[], SkData* value) { - if (0 == rect.width() && 0 == rect.height()) { - handlePointAnnotation({ rect.x(), rect.y() }, *d.fMatrix, key, value); + if (!value) { + return; + } + if (rect.isEmpty()) { + this->handlePointAnnotation({ rect.x(), rect.y() }, *d.fMatrix, key, value); } else { - SkPath path; - path.addRect(rect); - handlePathAnnotation(path, d, key, value); + this->handleRectAnnotation(rect, d, key, value); } } @@ -1623,10 +1624,7 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, void SkPDFDevice::handlePointAnnotation(const SkPoint& point, const SkMatrix& matrix, const char key[], SkData* value) { - if (!value) { - return; - } - + SkASSERT(value); if (!strcmp(SkAnnotationKeys::Define_Named_Dest_Key(), key)) { SkPoint transformedPoint; matrix.mapXY(point.x(), point.y(), &transformedPoint); @@ -1634,25 +1632,28 @@ void SkPDFDevice::handlePointAnnotation(const SkPoint& point, } } -void SkPDFDevice::handlePathAnnotation(const SkPath& path, +void SkPDFDevice::handleRectAnnotation(const SkRect& rect, const SkDraw& d, const char key[], SkData* value) { - if (!value) { - return; - } - - SkRasterClip clip = *d.fRC; - clip.op(path, *d.fMatrix, SkIRect::MakeWH(width(), height()), - SkRegion::kIntersect_Op, - false); - SkRect transformedRect = SkRect::Make(clip.getBounds()); - - if (!strcmp(SkAnnotationKeys::URL_Key(), key)) { - if (!transformedRect.isEmpty()) { + SkASSERT(value); + // Convert to path to handle non-90-degree rotations. + SkPath path; + path.addRect(rect); + path.transform(*d.fMatrix, &path); + SkPath clip; + (void)d.fClipStack->asPath(&clip); + SkIPoint deviceOrigin = this->getOrigin(); + clip.offset(-deviceOrigin.x(), -deviceOrigin.y()); + // Offset here to make clip and path share coordinates. + // We remove the offset in SkPDFDevice::drawDevice(). + Op(clip, path, kIntersect_SkPathOp, &path); + // PDF wants a rectangle only. + SkRect transformedRect = path.getBounds(); + + if (!transformedRect.isEmpty()) { + if (!strcmp(SkAnnotationKeys::URL_Key(), key)) { fLinkToURLs.emplace_back(transformedRect, value); - } - } else if (!strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) { - if (!transformedRect.isEmpty()) { + } else if (!strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) { fLinkToDestinations.emplace_back(transformedRect, value); } } diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index 14e4db66ec..1fa48daf60 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -290,7 +290,7 @@ private: const SkPaint& paint, bool pathIsMutable, const SkMatrix* prePathMatrix = nullptr); void handlePointAnnotation(const SkPoint&, const SkMatrix&, const char key[], SkData* value); - void handlePathAnnotation(const SkPath&, const SkDraw& d, const char key[], SkData* value); + void handleRectAnnotation(const SkRect&, const SkDraw& d, const char key[], SkData* value); typedef SkClipStackDevice INHERITED; |