Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: gm/annotated_text.cpp

Issue 1159273003: Add GM that tests clipping annotations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-06-04 (Thursday) 10:11:04 EDT Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/annotated_text.cpp
diff --git a/gm/annotated_text.cpp b/gm/annotated_text.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ab7e8161268948975b72f0977fb4f9471567e6c1
--- /dev/null
+++ b/gm/annotated_text.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkAnnotation.h"
+#include "SkData.h"
+#include "gm.h"
+
+static void draw_url_annotated_text_with_box(
+ SkCanvas* canvas, const void* text,
+ SkScalar x, SkScalar y, const SkPaint& paint, const char* url) {
+ size_t byteLength = strlen(static_cast<const char*>(text));
+ SkRect bounds;
+ (void)paint.measureText(text, byteLength, &bounds);
+ bounds.offset(x, y);
+ SkAutoTUnref<SkData> urlData(SkData::NewWithCString(url));
+ SkAnnotateRectWithURL(canvas, bounds, urlData);
+ SkPaint shade;
+ shade.setColor(0x80346180);
+ canvas->drawRect(bounds, shade);
+ canvas->drawText(text, byteLength, x, y, paint);
+}
+
+DEF_SIMPLE_GM(annotated_text, canvas, 512, 512) {
+ SkAutoCanvasRestore autoCanvasRestore(canvas, true);
+ canvas->clear(SK_ColorWHITE);
+ canvas->clipRect(SkRect::MakeXYWH(64, 64, 384, 384));
+ canvas->clear(0xFFEEEEEE);
+ SkPaint p;
+ p.setTextSize(40);
+ const char text[] = "Click this link!";
+ const char url[] = "https://www.google.com/";
+ draw_url_annotated_text_with_box(canvas, text, 200.0f, 80.0f, p, url);
+ SkAutoCanvasRestore autoCanvasRestore2(canvas, true);
+ canvas->rotate(90);
+ draw_url_annotated_text_with_box(canvas, text, 150.0f, -55.0f, p, url);
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698