From: Hal Canary Date: Wed, 22 Feb 2017 20:55:06 +0000 (-0500) Subject: SkPDF: stop using RasterClip for drawAnnotation() X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~55^2~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cd21683cae5c575be102f072d2718bab37eac9c;p=platform%2Fupstream%2FlibSkiaSharp.git SkPDF: stop using RasterClip for drawAnnotation() Change-Id: Idc3a4151f1b6bd3cb11b59e39ddb1458af385035 Reviewed-on: https://skia-review.googlesource.com/8891 Reviewed-by: Mike Reed Commit-Queue: Hal Canary --- diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 36c1418..dbe4c84 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 14e4db6..1fa48da 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;