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.
|
|
|
|
*/
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2013-03-08 09:09:10 +00:00
|
|
|
|
|
|
|
#include "SkAnnotation.h"
|
|
|
|
#include "SkData.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
class InternalLinksGM : public GM {
|
|
|
|
public:
|
|
|
|
InternalLinksGM() {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2013-03-08 09:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("internal_links");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(700, 500);
|
2013-03-08 09:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** 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);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2013-03-08 09:09:10 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(25));
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(text, x, y, paint);
|
2013-03-08 09:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
static GM* MyFactory(void*) { return new InternalLinksGM; }
|
2013-03-08 09:09:10 +00:00
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|