96 {
99
100 fTestDataIterator.
rewind();
102
108
109 if (!testTypeface || !ftTypeface) {
110 *errorMsg = "Unable to initialize typeface.";
112 }
113
115 font.setSize(kFontSize);
117 font.setSubpixel(
true);
119 };
120
123
124 SkFont ftFont(ftTypeface);
125 configureFont(ftFont);
126 enum class DrawPhase { Fontations, FreeType, Comparison };
127
129 for (auto phase : {DrawPhase::Fontations, DrawPhase::FreeType, DrawPhase::Comparison}) {
131
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(),
140 testString.size(),
142 true,
143 999999,
144 &textBlobBuilder);
148 };
149
150 auto roundToDevicePixels = [canvas](
SkPoint& point) {
156 bool inverseExists = ctm.
invert(&inverse);
158 if (inverseExists) {
159 point = inverse.
mapPoint(mappedRounded);
160 }
161 };
162
163 auto fontationsCoord = [yCoord, roundToDevicePixels]() {
165 roundToDevicePixels(fontationsCoord);
166 return fontationsCoord;
167 };
168
169 auto freetypeCoord = [yCoord, maxBounds, roundToDevicePixels]() {
171 2 *
kMargin + maxBounds.left() + maxBounds.width(), yCoord);
172 roundToDevicePixels(freetypeCoord);
173 return freetypeCoord;
174 };
175
176 switch (phase) {
177 case DrawPhase::Fontations: {
178 SkRect boundsFontations = shapeAndDrawToCanvas(
font, fontationsCoord());
179
181 maxBounds.join(boundsFontations);
182 break;
183 }
184 case DrawPhase::FreeType: {
185 shapeAndDrawToCanvas(ftFont, freetypeCoord());
186 break;
187 }
188 case DrawPhase::Comparison: {
189
190
191
192
193
194 SkPoint fontationsOrigin = fontationsCoord();
195 SkPoint freetypeOrigin = freetypeCoord();
196 SkRect fontationsBBox(maxBounds.makeOffset(fontationsOrigin));
197 SkRect freetypeBBox(maxBounds.makeOffset(freetypeOrigin));
198
200 ctm.
mapRect(&fontationsBBox, fontationsBBox);
201 ctm.
mapRect(&freetypeBBox, freetypeBBox);
202
203 SkIRect fontationsIBox(fontationsBBox.roundOut());
204 SkIRect freetypeIBox(freetypeBBox.roundOut());
205
206 SkISize pixelDimensions(fontationsIBox.size());
210 SkColorType::kN32_SkColorType,
212
213 SkBitmap diffBitmap, highlightDiffBitmap;
216
217
218
219
220
223 break;
224 }
225
226 SkPixmap fontationsPixmap, freetypePixmap;
227 if (!canvasPixmap.
extractSubset(&fontationsPixmap, fontationsIBox) ||
229 {
230 break;
231 }
232
233 comparePixels(fontationsPixmap, freetypePixmap,
234 &diffBitmap, &highlightDiffBitmap);
235
236
237
239 3 *
kMargin + maxBounds.width() * 2, yCoord + maxBounds.top()));
241 4 *
kMargin + maxBounds.width() * 3, yCoord + maxBounds.top()));
242
246
248 diffBitmap, comparisonCoord.
x(), comparisonCoord.
y());
250 highlightDiffBitmap, whiteCoord.
x(), whiteCoord.
y());
251 break;
252 }
253 }
254
255 yCoord +=
font.getSize() * kLangYIncrementScale;
256 }
257 }
258 }
259
261 }
constexpr SkColor SK_ColorBLACK
@ kNone
glyph outlines unchanged
SK_API sk_sp< SkTypeface > SkTypeface_Make_Fontations(std::unique_ptr< SkStreamAsset > fontData, const SkFontArguments &args)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
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
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[])
void writePixels(const SkPixmap &src, int dstX, int dstY)
const SkRect & bounds() const
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
font
Font Metadata and Metrics.
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