29constexpr int kGmWidth = 1000;
32constexpr float kLangYIncrementScale = 1.9;
38void comparePixels(
const SkPixmap& pixmapA,
50 for (int32_t
x = 0;
x < dimensions.
fWidth;
x++) {
51 for (int32_t
y = 0;
y < dimensions.
fHeight;
y++) {
61 if (
dr != 0 ||
dg != 0 ||
db != 0) {
75 std::string fontNameFilterRegexp,
76 std::string langFilterRegexp)
77 : fTestDataIterator(fontNameFilterRegexp, langFilterRegexp)
89 fTestDataIterator.
rewind();
93 testSet.langSamples.size() * kFontSize * kLangYIncrementScale + 100);
100 fTestDataIterator.
rewind();
109 if (!testTypeface || !ftTypeface) {
110 *errorMsg =
"Unable to initialize typeface.";
115 font.setSize(kFontSize);
117 font.setSubpixel(
true);
124 SkFont ftFont(ftTypeface);
125 configureFont(ftFont);
126 enum class DrawPhase { Fontations, FreeType, Comparison };
129 for (
auto phase : {DrawPhase::Fontations, DrawPhase::FreeType, DrawPhase::Comparison}) {
132 for (
auto& langEntry :
testSet.langSamples) {
133 auto shapeAndDrawToCanvas = [canvas,
paint, langEntry](
const SkFont&
font,
135 std::string testString(langEntry.sampleShort.c_str(),
136 langEntry.sampleShort.size());
139 shaper->shape(testString.c_str(),
150 auto roundToDevicePixels = [canvas](
SkPoint& point) {
156 bool inverseExists = ctm.
invert(&inverse);
159 point = inverse.
mapPoint(mappedRounded);
163 auto fontationsCoord = [yCoord, roundToDevicePixels]() {
165 roundToDevicePixels(fontationsCoord);
166 return fontationsCoord;
169 auto freetypeCoord = [yCoord, maxBounds, roundToDevicePixels]() {
171 2 *
kMargin + maxBounds.left() + maxBounds.width(), yCoord);
172 roundToDevicePixels(freetypeCoord);
173 return freetypeCoord;
177 case DrawPhase::Fontations: {
178 SkRect boundsFontations = shapeAndDrawToCanvas(
font, fontationsCoord());
181 maxBounds.join(boundsFontations);
184 case DrawPhase::FreeType: {
185 shapeAndDrawToCanvas(ftFont, freetypeCoord());
188 case DrawPhase::Comparison: {
194 SkPoint fontationsOrigin = fontationsCoord();
195 SkPoint freetypeOrigin = freetypeCoord();
196 SkRect fontationsBBox(maxBounds.makeOffset(fontationsOrigin));
197 SkRect freetypeBBox(maxBounds.makeOffset(freetypeOrigin));
200 ctm.
mapRect(&fontationsBBox, fontationsBBox);
201 ctm.
mapRect(&freetypeBBox, freetypeBBox);
210 SkColorType::kN32_SkColorType,
213 SkBitmap diffBitmap, highlightDiffBitmap;
226 SkPixmap fontationsPixmap, freetypePixmap;
227 if (!canvasPixmap.
extractSubset(&fontationsPixmap, fontationsIBox) ||
233 comparePixels(fontationsPixmap, freetypePixmap,
234 &diffBitmap, &highlightDiffBitmap);
239 3 *
kMargin + maxBounds.width() * 2, yCoord + maxBounds.top()));
241 4 *
kMargin + maxBounds.width() * 3, yCoord + maxBounds.top()));
248 diffBitmap, comparisonCoord.
x(), comparisonCoord.
y());
250 highlightDiffBitmap, whiteCoord.
x(), whiteCoord.
y());
255 yCoord +=
font.getSize() * kLangYIncrementScale;
264 using INHERITED =
GM;
269 std::unique_ptr<SkFontArguments::VariationPosition::Coordinate[]> fCoordinates;
275 "en_Latn|es_Latn|pt_Latn|id_Latn|ru_Cyrl|fr_Latn|tr_Latn|vi_Latn|de_"
276 "Latn|it_Latn|pl_Latn|nl_Latn|uk_Cyrl|gl_Latn|ro_Latn|cs_Latn|hu_Latn|"
277 "el_Grek|se_Latn|da_Latn|bg_Latn|sk_Latn|fi_Latn|bs_Latn|ca_Latn|no_"
278 "Latn|sr_Latn|sr_Cyrl|lt_Latn|hr_Latn|sl_Latn|uz_Latn|uz_Cyrl|lv_Latn|"
279 "et_Latn|az_Latn|az_Cyrl|la_Latn|tg_Latn|tg_Cyrl|sw_Latn|mn_Cyrl|kk_"
280 "Latn|kk_Cyrl|sq_Latn|af_Latn|ha_Latn|ky_Cyrl"));
283 "Noto Sans Devanagari",
288 "ar_Arab|uz_Arab|kk_Arab|ky_Arab"));
static const ConicPts testSet[]
#define SkGetPackedB32(packed)
#define SkGetPackedR32(packed)
#define SkGetPackedG32(packed)
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
@ kNone
glyph outlines unchanged
static int32_t SkAbs32(int32_t value)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
SK_API sk_sp< SkTypeface > SkTypeface_Make_Fontations(std::unique_ptr< SkStreamAsset > fontData, const SkFontArguments &args)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
SkISize dimensions() const
uint32_t * getAddr32(int x, int y) const
bool peekPixels(SkPixmap *pixmap)
SkMatrix getLocalToDeviceAs3x3() const
SkSurfaceProps getBaseProps() const
SkImageInfo imageInfo() const
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
SkPoint mapPoint(SkPoint pt) const
bool invert(SkMatrix *inverse) const
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
SkColor getColor(int x, int y) const
SkISize dimensions() const
bool extractSubset(SkPixmap *subset, const SkIRect &area) const
static std::unique_ptr< SkShaper > Make(sk_sp< SkFontMgr > fallback=nullptr)
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
const char * c_str() const
void writePixels(const SkPixmap &src, int dstX, int dstY)
sk_sp< SkTextBlob > makeBlob()
const SkRect & bounds() const
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
bool next(TestSet *testSet)
SkISize getISize() override
SkString getName() const override
FontationsFtCompareGM(std::string testName, std::string fontNameFilterRegexp, std::string langFilterRegexp)
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
GM(SkColor backgroundColor=SK_ColorWHITE)
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
constexpr SkISize size() const
static constexpr SkISize Make(int32_t w, int32_t h)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkPoint Make(float x, float y)
constexpr float y() const
constexpr float x() const
static constexpr SkRect MakeEmpty()
void roundOut(SkIRect *dst) const