Flutter Engine
The Flutter Engine
annotated_text.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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"
20
21#include <string.h>
22
24 SkCanvas* canvas, const void* text,
25 SkScalar x, SkScalar y, const SkFont& font, const char* url) {
26 size_t byteLength = strlen(static_cast<const char*>(text));
28 (void)font.measureText(text, byteLength, SkTextEncoding::kUTF8, &bounds);
29 bounds.offset(x, y);
31 SkAnnotateRectWithURL(canvas, bounds, urlData.get());
32 SkPaint shade;
33 shade.setColor(0x80346180);
34 canvas->drawRect(bounds, shade);
35 canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint());
36}
37
38DEF_SIMPLE_GM(annotated_text, canvas, 512, 512) {
39 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
40 canvas->clear(SK_ColorWHITE);
41 canvas->clipRect(SkRect::MakeXYWH(64, 64, 256, 256));
42 canvas->clear(0xFFEEEEEE);
45 font.setSize(40);
46 const char text[] = "Click this link!";
47 const char url[] = "https://www.google.com/";
48 draw_url_annotated_text_with_box(canvas, text, 200.0f, 80.0f, font, url);
49 canvas->saveLayer(nullptr, nullptr);
50 canvas->rotate(90);
51 draw_url_annotated_text_with_box(canvas, text, 150.0f, -55.0f, font, url);
52 canvas->restore();
53}
SK_API void SkAnnotateRectWithURL(SkCanvas *, const SkRect &, SkData *)
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static void draw_url_annotated_text_with_box(SkCanvas *canvas, const void *text, SkScalar x, SkScalar y, const SkFont &font, const char *url)
DEF_SIMPLE_GM(annotated_text, canvas, 512, 512)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition: SkData.cpp:195
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
void setColor(SkColor color)
Definition: SkPaint.cpp:119
T * get() const
Definition: SkRefCnt.h:303
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659