Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: gm/typeface.cpp

Issue 2350453002: GM: add test for type1 font (Closed)
Patch Set: comments from bungeman@ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | resources/fonts/Roboto2-Regular.pfa » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/typeface.cpp
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index 8303b373582ec7d1bc9b7a31116ee7fdff742141..4ed3956986aaf519ebb34a08f7c159888e35e2c1 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -154,25 +154,13 @@ private:
typedef skiagm::GM INHERITED;
};
-class TypefaceRenderingGM : public skiagm::GM {
- sk_sp<SkTypeface> fFace;
-
-protected:
- void onOnceBeforeDraw() override {
- fFace = MakeResourceAsTypeface("/fonts/hintgasp.ttf");
- }
-
- SkString onShortName() override {
- SkString name("typefacerendering");
- name.append(sk_tool_utils::major_platform_os_name());
- return name;
- }
+DEF_GM( return new TypefaceStylesGM(false); )
+DEF_GM( return new TypefaceStylesGM(true); )
- SkISize onISize() override {
- return SkISize::Make(640, 680);
- }
+////////////////////////////////////////////////////////////////////////////////
- void onDraw(SkCanvas* canvas) override {
+static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,
+ char character = 'A') {
struct AliasType {
bool antiAlias;
bool subpixelAntitalias;
@@ -226,7 +214,7 @@ protected:
constexpr bool rotateABitTypes[] = { false, true };
SkPaint paint;
- paint.setTypeface(fFace);
+ paint.setTypeface(face);
paint.setEmbeddedBitmapText(true);
SkScalar x = 0;
@@ -260,10 +248,12 @@ protected:
canvas->rotate(2, x + subpixel.offset.x(),
y + subpixel.offset.y());
}
- canvas->drawText("A", 1, x + subpixel.offset.x(),
- y + subpixel.offset.y(), paint);
+ canvas->drawText(&character, 1,
+ x + subpixel.offset.x(),
+ y + subpixel.offset.y(), paint);
- SkScalar dx = SkScalarCeilToScalar(paint.measureText("A", 1)) + 5;
+ SkScalar dx = SkScalarCeilToScalar(
+ paint.measureText(&character, 1)) + 5;
x += dx;
xMax = SkTMax(x, xMax);
}
@@ -273,14 +263,34 @@ protected:
}
xBase = xMax;
}
+}
+
+DEF_SIMPLE_GM_BG_NAME(typefacerendering, canvas, 640, 680, SK_ColorWHITE,
+ SkStringPrintf("typefacerendering%s",
+ sk_tool_utils::major_platform_os_name().c_str())) {
+ if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("/fonts/hintgasp.ttf")) {
+ draw_typeface_rendering_gm(canvas, std::move(face));
}
+}
-private:
- typedef skiagm::GM INHERITED;
-};
+// Type1 fonts don't currently work in Skia on Windows.
+#ifndef SK_BUILD_FOR_WIN
+
+DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfa, canvas, 640, 680, SK_ColorWHITE,
+ SkStringPrintf("typefacerendering_pfa%s",
+ sk_tool_utils::major_platform_os_name().c_str())) {
+ if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfa")) {
+ // This subsetted typeface doesn't have the character 'A'.
+ draw_typeface_rendering_gm(canvas, std::move(face), 'O');
+ }
+}
-///////////////////////////////////////////////////////////////////////////////
+DEF_SIMPLE_GM_BG_NAME(typefacerendering_pfb, canvas, 640, 680, SK_ColorWHITE,
+ SkStringPrintf("typefacerendering_pfb%s",
+ sk_tool_utils::major_platform_os_name().c_str())) {
+ if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfb")) {
+ draw_typeface_rendering_gm(canvas, std::move(face), 'O');
+ }
+}
-DEF_GM( return new TypefaceStylesGM(false); )
-DEF_GM( return new TypefaceStylesGM(true); )
-DEF_GM( return new TypefaceRenderingGM(); )
+#endif
« no previous file with comments | « no previous file | resources/fonts/Roboto2-Regular.pfa » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698