Skip to content

Commit

Permalink
beef-up paint-vs-font metrics test
Browse files Browse the repository at this point in the history
Bug: skia:
Change-Id: Ie59ad9707e1fb25ae70b40f07babf37351edb102
Reviewed-on: https://skia-review.googlesource.com/c/171535
Commit-Queue: Mike Reed <[email protected]>
Reviewed-by: Herb Derby <[email protected]>
  • Loading branch information
reed-at-google authored and Skia Commit-Bot committed Nov 17, 2018
1 parent 1bfdd1a commit d017e51
Showing 1 changed file with 35 additions and 48 deletions.
83 changes: 35 additions & 48 deletions tests/FontObjTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,70 +53,57 @@ static void test_fontmetrics(skiatest::Reporter* reporter,

static void test_cachedfont(skiatest::Reporter* reporter) {
static const char* const faces[] = {
nullptr, // default font
nullptr,
"Arial", "Times", "Times New Roman", "Helvetica", "Courier",
"Courier New", "Verdana", "monospace",
};

static const struct {
SkFontHinting hinting;
unsigned flags;
} settings[] = {
{ kNo_SkFontHinting, 0 },
{ kNo_SkFontHinting, SkPaint::kLinearText_Flag },
{ kNo_SkFontHinting, SkPaint::kSubpixelText_Flag },
{ kSlight_SkFontHinting, 0 },
{ kSlight_SkFontHinting, SkPaint::kLinearText_Flag },
{ kSlight_SkFontHinting, SkPaint::kSubpixelText_Flag },
{ kNormal_SkFontHinting, 0 },
{ kNormal_SkFontHinting, SkPaint::kLinearText_Flag },
{ kNormal_SkFontHinting, SkPaint::kSubpixelText_Flag },
};

static const struct {
SkScalar fScaleX;
SkScalar fSkewX;
} gScaleRec[] = {
{ SK_Scalar1, 0 },
{ SK_Scalar1/2, 0 },
// these two exercise obliquing (skew)
{ SK_Scalar1, -SK_Scalar1/4 },
{ SK_Scalar1/2, -SK_Scalar1/4 },
};

SkPaint paint;
char txt[] = "long.text.with.lots.of.dots.";
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;

for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkFontStyle()));

for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
paint.setHinting(settings[j].hinting);
paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0);
paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Flag) != 0);

for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
paint.setTextScaleX(gScaleRec[k].fScaleX);
paint.setTextSkewX(gScaleRec[k].fSkewX);

const SkFont font(SkFont::LEGACY_ExtractFromPaint(paint));

test_cachedfont(reporter, paint, font);
test_fontmetrics(reporter, paint, font);

SkRect bounds;

// For no hinting and light hinting this should take the
// optimized generateAdvance path.
SkScalar width1 = paint.measureText(txt, strlen(txt));

// Requesting the bounds forces a generateMetrics call.
SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds);

REPORTER_ASSERT(reporter, width1 == width2);

SkScalar font_width1 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding);
REPORTER_ASSERT(reporter, width1 == font_width1);
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 (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
paint.setTextScaleX(gScaleRec[k].fScaleX);
paint.setTextSkewX(gScaleRec[k].fSkewX);

const SkFont font(SkFont::LEGACY_ExtractFromPaint(paint));

test_cachedfont(reporter, paint, font);
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);
REPORTER_ASSERT(reporter, pwidth == fwidth);
REPORTER_ASSERT(reporter, pbounds == fbounds);
}
}
}
}
Expand Down

0 comments on commit d017e51

Please sign in to comment.