From 1e7c65806f3fbde13b5d8064dc5734d98c32a284 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Mon, 21 May 2018 16:10:17 -0400 Subject: drawPosText no longer obeys paint alignment Change-Id: Iac498b54dea4aa1b203d2b9c58e15bb5f2147f82 Reviewed-on: https://skia-review.googlesource.com/129462 Commit-Queue: Herb Derby Reviewed-by: Ben Wagner --- gm/glyph_pos_align.cpp | 66 -------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 gm/glyph_pos_align.cpp (limited to 'gm') diff --git a/gm/glyph_pos_align.cpp b/gm/glyph_pos_align.cpp deleted file mode 100644 index 50bcf82742..0000000000 --- a/gm/glyph_pos_align.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014 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 "SkCanvas.h" -#include "SkGradientShader.h" - -/** - * This test exercises drawPosTextH and drawPosText with every text align. - */ -constexpr int kWidth = 480; -constexpr int kHeight = 600; -constexpr SkScalar kTextHeight = 64.0f; -constexpr int kMaxStringLength = 12; - -static void drawTestCase(SkCanvas*, const char*, SkScalar, const SkPaint&); - -DEF_SIMPLE_GM_BG(glyph_pos_align, canvas, kWidth, kHeight, SK_ColorBLACK) { - SkPaint paint; - paint.setTextSize(kTextHeight); - paint.setFakeBoldText(true); - const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; - const SkPoint pts[] = {{0, 0}, {kWidth, kHeight}}; - paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), - SkShader::kMirror_TileMode)); - paint.setTextAlign(SkPaint::kRight_Align); - drawTestCase(canvas, "Right Align", kTextHeight, paint); - - paint.setTextAlign(SkPaint::kCenter_Align); - drawTestCase(canvas, "Center Align", 4 * kTextHeight, paint); - - paint.setTextAlign(SkPaint::kLeft_Align); - drawTestCase(canvas, "Left Align", 7 * kTextHeight, paint); -} - -void drawTestCase(SkCanvas* canvas, const char* text, SkScalar y, const SkPaint& paint) { - SkScalar widths[kMaxStringLength]; - SkScalar posX[kMaxStringLength]; - SkPoint pos[kMaxStringLength]; - int length = SkToInt(strlen(text)); - SkASSERT(length <= kMaxStringLength); - - paint.getTextWidths(text, length, widths); - - float originX; - switch (paint.getTextAlign()) { - case SkPaint::kRight_Align: originX = 1; break; - case SkPaint::kCenter_Align: originX = 0.5f; break; - case SkPaint::kLeft_Align: originX = 0; break; - default: SK_ABORT("Invalid paint origin"); return; - } - - float x = kTextHeight; - for (int i = 0; i < length; ++i) { - posX[i] = x + originX * widths[i]; - pos[i].set(posX[i], i ? pos[i - 1].y() + 3 : y + kTextHeight); - x += widths[i]; - } - - canvas->drawPosTextH(text, length, posX, y, paint); - canvas->drawPosText(text, length, pos, paint); -} -- cgit v1.2.3