2015-06-04 14:26:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkAnnotation.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2015-06-04 14:26:54 +00:00
|
|
|
|
|
|
|
static void draw_url_annotated_text_with_box(
|
|
|
|
SkCanvas* canvas, const void* text,
|
2018-12-12 23:10:38 +00:00
|
|
|
SkScalar x, SkScalar y, const SkFont& font, const char* url) {
|
2015-06-04 14:26:54 +00:00
|
|
|
size_t byteLength = strlen(static_cast<const char*>(text));
|
|
|
|
SkRect bounds;
|
2018-12-12 23:10:38 +00:00
|
|
|
(void)font.measureText(text, byteLength, kUTF8_SkTextEncoding, &bounds);
|
2015-06-04 14:26:54 +00:00
|
|
|
bounds.offset(x, y);
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> urlData(SkData::MakeWithCString(url));
|
|
|
|
SkAnnotateRectWithURL(canvas, bounds, urlData.get());
|
2015-06-04 14:26:54 +00:00
|
|
|
SkPaint shade;
|
|
|
|
shade.setColor(0x80346180);
|
|
|
|
canvas->drawRect(bounds, shade);
|
2018-12-12 23:10:38 +00:00
|
|
|
canvas->drawSimpleText(text, byteLength, kUTF8_SkTextEncoding, x, y, font, SkPaint());
|
2015-06-04 14:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(annotated_text, canvas, 512, 512) {
|
|
|
|
SkAutoCanvasRestore autoCanvasRestore(canvas, true);
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
2015-07-18 00:23:15 +00:00
|
|
|
canvas->clipRect(SkRect::MakeXYWH(64, 64, 256, 256));
|
2015-06-04 14:26:54 +00:00
|
|
|
canvas->clear(0xFFEEEEEE);
|
2018-12-12 23:10:38 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
font.setSize(40);
|
2015-06-04 14:26:54 +00:00
|
|
|
const char text[] = "Click this link!";
|
|
|
|
const char url[] = "https://www.google.com/";
|
2018-12-12 23:10:38 +00:00
|
|
|
draw_url_annotated_text_with_box(canvas, text, 200.0f, 80.0f, font, url);
|
2015-09-18 03:38:02 +00:00
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2015-06-04 14:26:54 +00:00
|
|
|
canvas->rotate(90);
|
2018-12-12 23:10:38 +00:00
|
|
|
draw_url_annotated_text_with_box(canvas, text, 150.0f, -55.0f, font, url);
|
2015-09-18 03:38:02 +00:00
|
|
|
canvas->restore();
|
2015-06-04 14:26:54 +00:00
|
|
|
}
|