2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-06-28 16:20:27 +00:00
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2011-06-28 16:20:27 +00:00
|
|
|
|
2014-10-01 20:59:33 +00:00
|
|
|
class LcdTextGM : public skiagm::GM {
|
2019-07-18 16:36:54 +00:00
|
|
|
static constexpr SkScalar kTextHeight = 36;
|
|
|
|
SkScalar fY = kTextHeight;
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkString onShortName() override { return SkString("lcdtext"); }
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override { return {640, 480}; }
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
fY = kTextHeight;
|
2011-06-28 16:20:27 +00:00
|
|
|
drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"),
|
|
|
|
true, true);
|
|
|
|
drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"),
|
|
|
|
true, false);
|
|
|
|
drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"),
|
|
|
|
false, true);
|
|
|
|
drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"),
|
|
|
|
false, false);
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2011-06-28 16:20:27 +00:00
|
|
|
void drawText(SkCanvas* canvas, const SkString& string,
|
|
|
|
bool subpixelTextEnabled, bool lcdRenderTextEnabled) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
paint.setDither(true);
|
2019-07-18 16:36:54 +00:00
|
|
|
SkFont font(nullptr, kTextHeight);
|
2019-01-07 21:01:22 +00:00
|
|
|
if (subpixelTextEnabled) {
|
|
|
|
font.setSubpixel(true);
|
|
|
|
}
|
|
|
|
if (lcdRenderTextEnabled) {
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
}
|
2019-07-18 16:36:54 +00:00
|
|
|
canvas->drawString(string, 0, fY, font, paint);
|
|
|
|
fY += kTextHeight;
|
2011-06-28 16:20:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-01 20:59:33 +00:00
|
|
|
/*
|
|
|
|
* Skia will automatically disable LCD requests if the total size exceeds some limit
|
|
|
|
* (hard coded in this test for now, as it is now avaiable as an API)
|
|
|
|
*
|
|
|
|
* Test this both by changing "textsize" and by changing the computed size (textsize * CTM)
|
|
|
|
*/
|
|
|
|
class LcdTextSizeGM : public skiagm::GM {
|
|
|
|
static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) {
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(sx, sy, px, py);
|
|
|
|
canvas->concat(m);
|
|
|
|
}
|
2011-06-28 16:20:27 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkString onShortName() override { return SkString("lcdtextsize"); }
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override { return {320, 120}; }
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-10-01 20:59:33 +00:00
|
|
|
const char* lcd_text = "LCD";
|
|
|
|
const char* gray_text = "GRAY";
|
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
constexpr static float kLCDTextSizeLimit = 48;
|
|
|
|
|
2014-10-01 20:59:33 +00:00
|
|
|
const struct {
|
|
|
|
SkPoint fLoc;
|
|
|
|
SkScalar fTextSize;
|
|
|
|
SkScalar fScale;
|
|
|
|
const char* fText;
|
|
|
|
} rec[] = {
|
|
|
|
{ { 10, 50 }, kLCDTextSizeLimit - 1, 1, lcd_text },
|
|
|
|
{ { 160, 50 }, kLCDTextSizeLimit + 1, 1, gray_text },
|
|
|
|
{ { 10, 100 }, kLCDTextSizeLimit / 2, 1.99f, lcd_text },
|
|
|
|
{ { 160, 100 }, kLCDTextSizeLimit / 2, 2.01f, gray_text },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
|
|
|
const SkPoint loc = rec[i].fLoc;
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
2019-01-07 21:01:22 +00:00
|
|
|
SkFont font(nullptr, rec[i].fTextSize);
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
|
2014-10-01 20:59:33 +00:00
|
|
|
ScaleAbout(canvas, rec[i].fScale, rec[i].fScale, loc.x(), loc.y());
|
2019-01-07 21:01:22 +00:00
|
|
|
canvas->drawString(rec[i].fText, loc.x(), loc.y(), font, SkPaint());
|
2014-10-01 20:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_GM( return new LcdTextGM; )
|
|
|
|
DEF_GM( return new LcdTextSizeGM; )
|