3c03c851ad
This reverts commitfd0bba81c0
. Reason for revert: PaintTest.cpp:150 failing Original change's description: > Revert "Revert "remove legacy code for text attributes on paint"" > > This reverts commitfb0e2aa8fd
. > > Bug: skia: > Change-Id: I16bf3c999233f7498a4d76dfbcfb26be725e88f5 > Reviewed-on: https://skia-review.googlesource.com/c/187261 > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Mike Reed <reed@google.com> > Auto-Submit: Mike Reed <reed@google.com> TBR=reed@google.com Change-Id: Ic52282f36841b7402a3a5466b93ef56ecdb6f51b No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/c/187306 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
94 lines
3.1 KiB
C++
94 lines
3.1 KiB
C++
/*
|
|
* 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 "SkFont.h"
|
|
#include "SkPaint.h"
|
|
#include "SkTypeface.h"
|
|
#include "Test.h"
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
|
static void test_fontmetrics(skiatest::Reporter* reporter,
|
|
const SkPaint& paint, const SkFont& font) {
|
|
SkFontMetrics fm0, fm1;
|
|
SkScalar h0 = paint.getFontMetrics(&fm0);
|
|
SkScalar h1 = font.getMetrics(&fm1);
|
|
|
|
REPORTER_ASSERT(reporter, h0 == h1);
|
|
#define CMP(field) REPORTER_ASSERT(reporter, fm0.field == fm1.field)
|
|
CMP(fFlags);
|
|
CMP(fTop);
|
|
CMP(fAscent);
|
|
CMP(fDescent);
|
|
CMP(fBottom);
|
|
CMP(fLeading);
|
|
#undef CMP
|
|
}
|
|
|
|
DEF_TEST(FontObj_test_cachedfont, reporter) {
|
|
SkPaint paint;
|
|
char txt[] = "long .text .with .lots .of.dots.";
|
|
unsigned mask = SkPaint::kAntiAlias_Flag |
|
|
SkPaint::kFakeBoldText_Flag |
|
|
SkPaint::kLinearText_Flag |
|
|
SkPaint::kSubpixelText_Flag |
|
|
SkPaint::kLCDRenderText_Flag |
|
|
SkPaint::kEmbeddedBitmapText_Flag |
|
|
SkPaint::kAutoHinting_Flag;
|
|
|
|
paint.setStrokeWidth(2);
|
|
{
|
|
for (unsigned flags = 0; flags <= 0xFFF; ++flags) {
|
|
if (flags & ~mask) {
|
|
continue;
|
|
}
|
|
paint.setFlags(flags);
|
|
for (int hint = 0; hint <= 3; ++hint) {
|
|
paint.setHinting((SkFontHinting)hint);
|
|
{
|
|
for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style}) {
|
|
paint.setStyle(style);
|
|
|
|
const SkFont font(SkFont::LEGACY_ExtractFromPaint(paint));
|
|
test_fontmetrics(reporter, paint, font);
|
|
|
|
SkRect pbounds, fbounds;
|
|
|
|
// Requesting the bounds forces a generateMetrics call.
|
|
SkScalar pwidth = paint.measureText(txt, strlen(txt), &pbounds);
|
|
SkScalar fwidth = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding,
|
|
&fbounds, &paint);
|
|
REPORTER_ASSERT(reporter, pwidth == fwidth);
|
|
REPORTER_ASSERT(reporter, pbounds == fbounds);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif // SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_PAINT_FONT_FIELDS
|
|
DEF_TEST(FontObj_test_aa_hinting, reporter) {
|
|
SkPaint paint;
|
|
|
|
for (bool aa : {false, true}) {
|
|
paint.setAntiAlias(aa);
|
|
for (int hint = 0; hint <= 3; ++hint) {
|
|
paint.setHinting((SkFontHinting)hint);
|
|
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
|
|
|
|
SkPaint p2;
|
|
font.LEGACY_applyToPaint(&p2);
|
|
REPORTER_ASSERT(reporter, paint.isAntiAlias() == p2.isAntiAlias());
|
|
REPORTER_ASSERT(reporter, paint.getHinting() == p2.getHinting());
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// need tests for SkStrSearch
|