Flutter Engine
The Flutter Engine
internal_links.cpp
Go to the documentation of this file.
1/*
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 */
7
8#include "gm/gm.h"
12#include "include/core/SkData.h"
13#include "include/core/SkFont.h"
16#include "include/core/SkRect.h"
19#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
24
25namespace {
26
27/** Draws two rectangles. In output formats that support internal links (PDF),
28 * clicking the one labeled "Link to A" should take you to the one labeled
29 * "Target A". Note that you'll need to zoom your PDF viewer in a fair bit in
30 * order for the scrolling to not be blocked by the edge of the document.
31 */
32class InternalLinksGM : public skiagm::GM {
33 void onOnceBeforeDraw() override { this->setBGColor(0xFFDDDDDD); }
34
35 SkString getName() const override { return SkString("internal_links"); }
36
37 SkISize getISize() override { return {700, 500}; }
38
39 void onDraw(SkCanvas* canvas) override {
41
42 canvas->save();
43 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
44 drawLabeledRect(canvas, "Link to A", 0, 0);
47 canvas->restore();
48
49 canvas->save();
50 canvas->translate(SkIntToScalar(200), SkIntToScalar(200));
52 drawLabeledRect(canvas, "Target A", point.x(), point.y());
53 SkAnnotateNamedDestination(canvas, point, name.get());
54 canvas->restore();
55 }
56
57 /** Draw an arbitrary rectangle at a given location and label it with some
58 * text. */
59 void drawLabeledRect(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y) {
61 paint.setColor(SK_ColorBLUE);
64 canvas->drawRect(rect, paint);
65
67 paint.setColor(SK_ColorBLACK);
68 canvas->drawString(text, x, y, font, paint);
69 }
70};
71} // namespace
72
73DEF_GM( return new InternalLinksGM; )
SK_API void SkAnnotateNamedDestination(SkCanvas *, const SkPoint &, SkData *)
SK_API void SkAnnotateLinkToDestination(SkCanvas *, const SkRect &, SkData *)
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition: SkData.cpp:195
Definition: SkFont.h:35
Definition: gm.h:110
virtual SkISize getISize()=0
virtual void onOnceBeforeDraw()
Definition: gm.cpp:167
void setBGColor(SkColor)
Definition: gm.cpp:159
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
Definition: gm.cpp:139
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
std::u16string text
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
sk_sp< SkTypeface > DefaultPortableTypeface()
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
font
Font Metadata and Metrics.
Definition: SkSize.h:16
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659