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"
|
2019-04-30 17:44:26 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-30 17:44:26 +00:00
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
|
|
|
|
#include <string.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;
|
2019-05-07 19:38:46 +00:00
|
|
|
(void)font.measureText(text, byteLength, SkTextEncoding::kUTF8, &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);
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, 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
|
|
|
}
|