Flutter Engine
The Flutter Engine
Functions
annotated_text.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkAnnotation.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkData.h"
#include "include/core/SkFont.h"
#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 "tools/fonts/FontToolUtils.h"
#include <string.h>

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( annotated_text  ,
canvas  ,
512  ,
512   
)

Definition at line 38 of file annotated_text.cpp.

38 {
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}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw_url_annotated_text_with_box(SkCanvas *canvas, const void *text, SkScalar x, SkScalar y, const SkFont &font, const char *url)
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
std::u16string text
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ draw_url_annotated_text_with_box()

static void draw_url_annotated_text_with_box ( SkCanvas canvas,
const void *  text,
SkScalar  x,
SkScalar  y,
const SkFont font,
const char *  url 
)
static

Definition at line 23 of file annotated_text.cpp.

25 {
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}
SK_API void SkAnnotateRectWithURL(SkCanvas *, const SkRect &, SkData *)
@ kUTF8
uses bytes to represent UTF-8 or ASCII
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
void setColor(SkColor color)
Definition: SkPaint.cpp:119
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189