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);
}
}
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);
}
}
-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);
}
}
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;