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

Unified Diff: gm/dftext.cpp

Issue 568843002: Fix scaling issue with distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix uninitialized variables. Created 6 years, 3 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 | gm/fontscaler.cpp » ('j') | src/gpu/GrDistanceFieldTextContext.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/dftext.cpp
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
new file mode 100755
index 0000000000000000000000000000000000000000..ecc91d02425291dd09fbba4f91ed81a9ca28ed72
--- /dev/null
+++ b/gm/dftext.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "gm.h"
+#include "SkTypeface.h"
+
+namespace skiagm {
+
+class DFTextGM : public GM {
+public:
+ DFTextGM() {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+ virtual ~DFTextGM() {
+ }
+
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag | kGPUOnly_Flag;
bsalomon 2014/09/15 13:33:19 why the skip tile? Have you checked that it draws
jvanverth1 2014/09/15 13:43:53 I copied another GM that had it. I can remove it.
+ }
+
+ virtual SkString onShortName() {
+ return SkString("dftext");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(1024, 768);
+ }
+
+ static void rotate_about(SkCanvas* canvas,
+ SkScalar degrees,
+ SkScalar px, SkScalar py) {
+ canvas->translate(px, py);
+ canvas->rotate(degrees);
+ canvas->translate(-px, -py);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ SkScalar textSizes[] = { 11.0f, 11.0f*2.0f, 11.0f*5.0f, 11.0f*2.0f*5.0f };
+ SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f };
+
+ SkPaint paint;
+
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setDistanceFieldTextTEMP(true);
bsalomon 2014/09/15 13:33:19 Is the surface method of triggering DF more perman
jvanverth1 2014/09/15 13:43:53 Will do.
+
+ sk_tool_utils::set_portable_typeface(&paint, "Times New Roman", SkTypeface::kNormal);
+
+ const char* text = "Hamburgefons";
+ const size_t textLen = strlen(text);
+
+ // check a variety of scales
+ SkScalar x = SkIntToScalar(0);
+ SkScalar y = SkIntToScalar(78);
+ for (int i = 0; i < SK_ARRAY_COUNT(textSizes); ++i) {
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->translate(x, y);
+ canvas->scale(scales[i], scales[i]);
+ paint.setTextSize(textSizes[i]);
+ canvas->drawText(text, textLen, 0, 0, paint);
+ y += paint.getFontMetrics(NULL)*scales[i];
+ }
+
+ // check rotation
+ for (int i = 0; i < 5; ++i) {
+ SkScalar rotX = SkIntToScalar(10);
+ SkScalar rotY = y;
+
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->translate(SkIntToScalar(10 + i * 200), -80);
+ rotate_about(canvas, SkIntToScalar(i * 5), rotX, rotY);
+ for (int ps = 6; ps <= 32; ps += 3) {
+ paint.setTextSize(SkIntToScalar(ps));
+ canvas->drawText(text, textLen, rotX, rotY, paint);
+ rotY += paint.getFontMetrics(NULL);
+ }
+ }
+
+ // check gamma-corrected blending
+ const SkColor fg[] = {
+ 0xFFFFFFFF,
+ 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
+ 0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
+ 0xFF000000,
+ };
+
+ paint.setLCDRenderText(true);
+ paint.setColor(0xFFF1F1F1);
+ SkRect r = SkRect::MakeLTRB(690, 20, 840, 230);
+ canvas->drawRect(r, paint);
+
+ x = 700;
+ y = 40;
+ paint.setTextSize(SkIntToScalar(22));
+ for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
+ paint.setColor(fg[i]);
+
+ canvas->drawText(text, textLen, x, y, paint);
+ y += paint.getFontMetrics(NULL);
+ }
+
+ paint.setColor(0xFF1F1F1F);
+ r = SkRect::MakeLTRB(840, 20, 990, 230);
+ canvas->drawRect(r, paint);
+
+ x = 850;
+ y = 40;
+ paint.setTextSize(SkIntToScalar(22));
+ for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
+ paint.setColor(fg[i]);
+
+ canvas->drawText(text, textLen, x, y, paint);
+ y += paint.getFontMetrics(NULL);
+ }
+
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new DFTextGM; }
+static GMRegistry reg(MyFactory);
+
+}
« no previous file with comments | « no previous file | gm/fontscaler.cpp » ('j') | src/gpu/GrDistanceFieldTextContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698