SkTextBlob should store per-run text alignment

SkPaint::Align is only observed for kDefault_Positioning AFAICT, but
part of the run logical font nevertheless.

BUG=skia:4567
R=mtklein@google.com,halcanary@google.com

Review URL: https://codereview.chromium.org/1447403003
This commit is contained in:
fmalita 2015-11-17 11:39:32 -08:00 committed by Commit bot
parent 5af4e0bc8f
commit 32d6b87616
2 changed files with 95 additions and 0 deletions

View File

@ -21,6 +21,7 @@ public:
, fScaleX(paint.getTextScaleX())
, fTypeface(SkSafeRef(paint.getTypeface()))
, fSkewX(paint.getTextSkewX())
, fAlign(paint.getTextAlign())
, fHinting(paint.getHinting())
, fFlags(paint.getFlags() & kFlagsMask) { }
@ -30,6 +31,7 @@ public:
paint->setTextSize(fSize);
paint->setTextScaleX(fScaleX);
paint->setTextSkewX(fSkewX);
paint->setTextAlign(static_cast<SkPaint::Align>(fAlign));
paint->setHinting(static_cast<SkPaint::Hinting>(fHinting));
paint->setFlags((paint->getFlags() & ~kFlagsMask) | fFlags);
@ -40,6 +42,7 @@ public:
&& fSize == other.fSize
&& fScaleX == other.fScaleX
&& fSkewX == other.fSkewX
&& fAlign == other.fAlign
&& fHinting == other.fHinting
&& fFlags == other.fFlags;
}
@ -73,6 +76,8 @@ private:
SkAutoTUnref<SkTypeface> fTypeface;
SkScalar fSkewX;
static_assert(SkPaint::kAlignCount < 4, "insufficient_align_bits");
uint32_t fAlign : 2;
static_assert(SkPaint::kFull_Hinting < 4, "insufficient_hinting_bits");
uint32_t fHinting : 2;
static_assert((kFlagsMask & 0xffff) == kFlagsMask, "insufficient_flags_bits");

View File

@ -8,6 +8,7 @@
#include "SkPaint.h"
#include "SkPoint.h"
#include "SkTextBlobRunIterator.h"
#include "SkTypeface.h"
#include "Test.h"
@ -172,6 +173,91 @@ public:
}
}
// Verify that text-related properties are captured in run paints.
static void TestPaintProps(skiatest::Reporter* reporter) {
SkPaint font;
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkAutoTUnref<SkTypeface> typeface(SkTypeface::RefDefault());
// Kitchen sink font.
font.setTextSize(42);
font.setTextScaleX(4.2f);
font.setTypeface(typeface);
font.setTextSkewX(0.42f);
font.setTextAlign(SkPaint::kCenter_Align);
font.setHinting(SkPaint::kFull_Hinting);
font.setAntiAlias(true);
font.setUnderlineText(true);
font.setStrikeThruText(true);
font.setFakeBoldText(true);
font.setLinearText(true);
font.setSubpixelText(true);
font.setDevKernText(true);
font.setLCDRenderText(true);
font.setEmbeddedBitmapText(true);
font.setAutohinted(true);
font.setVerticalText(true);
font.setFlags(font.getFlags() | SkPaint::kGenA8FromLCD_Flag);
// Ensure we didn't pick default values by mistake.
SkPaint defaultPaint;
REPORTER_ASSERT(reporter, defaultPaint.getTextSize() != font.getTextSize());
REPORTER_ASSERT(reporter, defaultPaint.getTextScaleX() != font.getTextScaleX());
REPORTER_ASSERT(reporter, defaultPaint.getTypeface() != font.getTypeface());
REPORTER_ASSERT(reporter, defaultPaint.getTextSkewX() != font.getTextSkewX());
REPORTER_ASSERT(reporter, defaultPaint.getTextAlign() != font.getTextAlign());
REPORTER_ASSERT(reporter, defaultPaint.getHinting() != font.getHinting());
REPORTER_ASSERT(reporter, defaultPaint.isAntiAlias() != font.isAntiAlias());
REPORTER_ASSERT(reporter, defaultPaint.isUnderlineText() != font.isUnderlineText());
REPORTER_ASSERT(reporter, defaultPaint.isStrikeThruText() != font.isStrikeThruText());
REPORTER_ASSERT(reporter, defaultPaint.isFakeBoldText() != font.isFakeBoldText());
REPORTER_ASSERT(reporter, defaultPaint.isLinearText() != font.isLinearText());
REPORTER_ASSERT(reporter, defaultPaint.isSubpixelText() != font.isSubpixelText());
REPORTER_ASSERT(reporter, defaultPaint.isDevKernText() != font.isDevKernText());
REPORTER_ASSERT(reporter, defaultPaint.isLCDRenderText() != font.isLCDRenderText());
REPORTER_ASSERT(reporter, defaultPaint.isEmbeddedBitmapText() != font.isEmbeddedBitmapText());
REPORTER_ASSERT(reporter, defaultPaint.isAutohinted() != font.isAutohinted());
REPORTER_ASSERT(reporter, defaultPaint.isVerticalText() != font.isVerticalText());
REPORTER_ASSERT(reporter, (defaultPaint.getFlags() & SkPaint::kGenA8FromLCD_Flag) !=
(font.getFlags() & SkPaint::kGenA8FromLCD_Flag));
SkTextBlobBuilder builder;
AddRun(font, 1, SkTextBlob::kDefault_Positioning, SkPoint::Make(0, 0), builder);
AddRun(font, 1, SkTextBlob::kHorizontal_Positioning, SkPoint::Make(0, 0), builder);
AddRun(font, 1, SkTextBlob::kFull_Positioning, SkPoint::Make(0, 0), builder);
SkAutoTUnref<const SkTextBlob> blob(builder.build());
SkTextBlobRunIterator it(blob);
while (!it.done()) {
SkPaint paint;
it.applyFontToPaint(&paint);
REPORTER_ASSERT(reporter, paint.getTextSize() == font.getTextSize());
REPORTER_ASSERT(reporter, paint.getTextScaleX() == font.getTextScaleX());
REPORTER_ASSERT(reporter, paint.getTypeface() == font.getTypeface());
REPORTER_ASSERT(reporter, paint.getTextSkewX() == font.getTextSkewX());
REPORTER_ASSERT(reporter, paint.getTextAlign() == font.getTextAlign());
REPORTER_ASSERT(reporter, paint.getHinting() == font.getHinting());
REPORTER_ASSERT(reporter, paint.isAntiAlias() == font.isAntiAlias());
REPORTER_ASSERT(reporter, paint.isUnderlineText() == font.isUnderlineText());
REPORTER_ASSERT(reporter, paint.isStrikeThruText() == font.isStrikeThruText());
REPORTER_ASSERT(reporter, paint.isFakeBoldText() == font.isFakeBoldText());
REPORTER_ASSERT(reporter, paint.isLinearText() == font.isLinearText());
REPORTER_ASSERT(reporter, paint.isSubpixelText() == font.isSubpixelText());
REPORTER_ASSERT(reporter, paint.isDevKernText() == font.isDevKernText());
REPORTER_ASSERT(reporter, paint.isLCDRenderText() == font.isLCDRenderText());
REPORTER_ASSERT(reporter, paint.isEmbeddedBitmapText() == font.isEmbeddedBitmapText());
REPORTER_ASSERT(reporter, paint.isAutohinted() == font.isAutohinted());
REPORTER_ASSERT(reporter, paint.isVerticalText() == font.isVerticalText());
REPORTER_ASSERT(reporter, (paint.getFlags() & SkPaint::kGenA8FromLCD_Flag) ==
(font.getFlags() & SkPaint::kGenA8FromLCD_Flag));
it.next();
}
}
private:
struct RunDef {
unsigned count;
@ -261,3 +347,7 @@ DEF_TEST(TextBlob_builder, reporter) {
TextBlobTester::TestBuilder(reporter);
TextBlobTester::TestBounds(reporter);
}
DEF_TEST(TextBlob_paint, reporter) {
TextBlobTester::TestPaintProps(reporter);
}