diff options
author | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-06 00:05:13 +0000 |
---|---|---|
committer | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-06 00:05:13 +0000 |
commit | 1cad898916c9e4a21429b5325c834a51fa6f361e (patch) | |
tree | 721346bc48447def4cf0601331f3209fa586e3be /gm/internal_links.cpp | |
parent | ee38c08b0769fbe06887b50469dc97b8ebc6d868 (diff) |
PDF: add support for named destinations
Imported from https://codereview.appspot.com/7374052/ on behalf of dml@google.com
Review URL: https://codereview.chromium.org/12466008
git-svn-id: http://skia.googlecode.com/svn/trunk@8000 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/internal_links.cpp')
-rw-r--r-- | gm/internal_links.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/gm/internal_links.cpp b/gm/internal_links.cpp new file mode 100644 index 0000000000..f9846e4c67 --- /dev/null +++ b/gm/internal_links.cpp @@ -0,0 +1,77 @@ + +/* + * 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" + +#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() { + this->setBGColor(0xFFDDDDDD); + } + +protected: + virtual SkString onShortName() { + return SkString("internal_links"); + } + + virtual SkISize onISize() { + return make_isize(700, 500); + } + + 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(); + } + +private: + /** Draw an arbitrary rectangle at a given location and label it with some + * text. */ + void drawLabeledRect(SkCanvas* canvas, const char* text, int x, int y) { + SkPaint paint; + paint.setColor(SK_ColorBLUE); + SkRect rect = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), + SkIntToScalar(50), SkIntToScalar(20)); + canvas->drawRect(rect, paint); + + paint.setAntiAlias(true); + paint.setTextSize(SkIntToScalar(25)); + paint.setColor(SK_ColorBLACK); + canvas->drawText(text, strlen(text), x, y, paint); + } + + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return SkNEW(InternalLinksGM); } +static GMRegistry reg(MyFactory); + +} |