blob: 44f9d593589b3bb7cd8ddc816bb69fc644d36311 [file] [log] [blame]
epoger@google.comb58772f2013-03-08 09:09:10 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
epoger@google.comb58772f2013-03-08 09:09:10 +00007
Ben Wagner7fde8e12019-05-01 17:28:53 -04008#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/core/SkAnnotation.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkData.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkFont.h"
14#include "include/core/SkPaint.h"
15#include "include/core/SkPoint.h"
16#include "include/core/SkRect.h"
17#include "include/core/SkRefCnt.h"
18#include "include/core/SkScalar.h"
19#include "include/core/SkSize.h"
20#include "include/core/SkString.h"
21#include "include/core/SkTypeface.h"
22#include "tools/ToolUtils.h"
epoger@google.comb58772f2013-03-08 09:09:10 +000023
24namespace skiagm {
25
26/** Draws two rectangles. In output formats that support internal links (PDF),
27 * clicking the one labeled "Link to A" should take you to the one labeled
28 * "Target A". Note that you'll need to zoom your PDF viewer in a fair bit in
29 * order for the scrolling to not be blocked by the edge of the document.
30 */
31class InternalLinksGM : public GM {
32public:
33 InternalLinksGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040034 this->setBGColor(0xFFDDDDDD);
epoger@google.comb58772f2013-03-08 09:09:10 +000035 }
36
37protected:
38 virtual SkString onShortName() {
39 return SkString("internal_links");
40 }
41
42 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070043 return SkISize::Make(700, 500);
epoger@google.comb58772f2013-03-08 09:09:10 +000044 }
45
46 virtual void onDraw(SkCanvas* canvas) {
bungeman38d909e2016-08-02 14:40:46 -070047 sk_sp<SkData> name(SkData::MakeWithCString("target-a"));
epoger@google.comb58772f2013-03-08 09:09:10 +000048
49 canvas->save();
50 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
51 drawLabeledRect(canvas, "Link to A", 0, 0);
52 SkRect rect = SkRect::MakeXYWH(0, 0, SkIntToScalar(50), SkIntToScalar(20));
53 SkAnnotateLinkToDestination(canvas, rect, name.get());
54 canvas->restore();
55
56 canvas->save();
57 canvas->translate(SkIntToScalar(200), SkIntToScalar(200));
58 SkPoint point = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(50));
59 drawLabeledRect(canvas, "Target A", point.x(), point.y());
60 SkAnnotateNamedDestination(canvas, point, name.get());
61 canvas->restore();
62 }
63
epoger@google.comb58772f2013-03-08 09:09:10 +000064private:
65 /** Draw an arbitrary rectangle at a given location and label it with some
66 * text. */
67 void drawLabeledRect(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y) {
68 SkPaint paint;
69 paint.setColor(SK_ColorBLUE);
70 SkRect rect = SkRect::MakeXYWH(x, y,
71 SkIntToScalar(50), SkIntToScalar(20));
72 canvas->drawRect(rect, paint);
73
Mike Kleinea3f0142019-03-20 11:12:10 -050074 SkFont font(ToolUtils::create_portable_typeface(), 25);
epoger@google.comb58772f2013-03-08 09:09:10 +000075 paint.setColor(SK_ColorBLACK);
Mike Reed1af9b482019-01-07 11:01:57 -050076 canvas->drawString(text, x, y, font, paint);
epoger@google.comb58772f2013-03-08 09:09:10 +000077 }
78
79 typedef GM INHERITED;
80};
81
82//////////////////////////////////////////////////////////////////////////////
83
Hal Canarye964c182019-01-23 10:22:01 -050084DEF_GM( return new InternalLinksGM; )
epoger@google.comb58772f2013-03-08 09:09:10 +000085
86}