2013-03-08 09:09:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "gm/gm.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkAnnotation.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
namespace {
|
2013-03-08 09:09:10 +00:00
|
|
|
|
|
|
|
/** Draws two rectangles. In output formats that support internal links (PDF),
|
|
|
|
* clicking the one labeled "Link to A" should take you to the one labeled
|
|
|
|
* "Target A". Note that you'll need to zoom your PDF viewer in a fair bit in
|
|
|
|
* order for the scrolling to not be blocked by the edge of the document.
|
|
|
|
*/
|
2019-07-18 15:51:19 +00:00
|
|
|
class InternalLinksGM : public skiagm::GM {
|
|
|
|
void onOnceBeforeDraw() override { this->setBGColor(0xFFDDDDDD); }
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
SkString onShortName() override { return SkString("internal_links"); }
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
SkISize onISize() override { return {700, 500}; }
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> name(SkData::MakeWithCString("target-a"));
|
2013-03-08 09:09:10 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Draw an arbitrary rectangle at a given location and label it with some
|
|
|
|
* text. */
|
|
|
|
void drawLabeledRect(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
SkRect rect = SkRect::MakeXYWH(x, y,
|
|
|
|
SkIntToScalar(50), SkIntToScalar(20));
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 25);
|
2013-03-08 09:09:10 +00:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
2019-01-07 16:01:57 +00:00
|
|
|
canvas->drawString(text, x, y, font, paint);
|
2013-03-08 09:09:10 +00:00
|
|
|
}
|
|
|
|
};
|
2019-07-18 15:51:19 +00:00
|
|
|
} // namespace
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new InternalLinksGM; )
|