Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Unified Diff: gm/internal_links.cpp

Issue 12533009: PDF: add support for named destinations. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: attempt_to_fix_warnings_in_internal_links.cpp Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/internal_links.cpp
===================================================================
--- gm/internal_links.cpp (revision 0)
+++ gm/internal_links.cpp (revision 0)
@@ -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, 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);
+ 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);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698