/* * Test the 3 annotation types by recording them into a picture, serializing, and then playing * them back into another canvas. */ DEF_TEST(Annotations, reporter) { SkPictureRecorder recorder; SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100)); const char* str0 = "rect-with-url"; const SkRect r0 = SkRect::MakeWH(10, 10); sk_sp<SkData> d0(SkData::MakeWithCString(str0)); SkAnnotateRectWithURL(recordingCanvas, r0, d0.get()); const char* str1 = "named-destination"; const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point sk_sp<SkData> d1(SkData::MakeWithCString(str1)); SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1.get()); const char* str2 = "link-to-destination"; const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6); sk_sp<SkData> d2(SkData::MakeWithCString(str2)); SkAnnotateLinkToDestination(recordingCanvas, r2, d2.get()); const AnnotationRec recs[] = { { r0, SkAnnotationKeys::URL_Key(), std::move(d0) }, { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) }, { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) }, }; sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); canvas.drawPicture(pict1); }
virtual void onDraw(SkCanvas* canvas) { SkAutoTUnref<SkData> name(SkData::NewWithCString("target-a")); canvas->save(); canvas->translate(SkIntToScalar(100), SkIntToScalar(100)); drawLabeledRect(canvas, "Link to A", 0, 0); SkRect rect = SkRect::MakeXYWH(0, 0, SkIntToScalar(50), SkIntToScalar(20)); SkAnnotateLinkToDestination(canvas, rect, name.get()); canvas->restore(); canvas->save(); canvas->translate(SkIntToScalar(200), SkIntToScalar(200)); SkPoint point = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(50)); drawLabeledRect(canvas, "Target A", point.x(), point.y()); SkAnnotateNamedDestination(canvas, point, name.get()); canvas->restore(); }