aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2015-07-24 11:08:01 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-24 11:08:01 -0700
commit37213558e6d269807cde031e59b9567d0db6e471 (patch)
tree6ea9b08d1366a93e8a66693167128b9db8983e81 /gm
parent6c2c2b07ed83e1f83008fac6eb1b62670b1dbdb1 (diff)
make fontscalar gammatext lcdtext typeface verttext2 gm portable
Pass generic font names to tool util function to generate platform specific fonts and gm test output by unique name. R=bungeman@google.com Review URL: https://codereview.chromium.org/1256903002
Diffstat (limited to 'gm')
-rw-r--r--gm/fontscaler.cpp5
-rw-r--r--gm/gammatext.cpp6
-rw-r--r--gm/lcdtext.cpp5
-rw-r--r--gm/typeface.cpp75
-rw-r--r--gm/verttext2.cpp10
5 files changed, 20 insertions, 81 deletions
diff --git a/gm/fontscaler.cpp b/gm/fontscaler.cpp
index c3b2c87af2..6087478566 100644
--- a/gm/fontscaler.cpp
+++ b/gm/fontscaler.cpp
@@ -21,7 +21,9 @@ public:
protected:
SkString onShortName() override {
- return SkString("fontscaler");
+ SkString name("fontscaler");
+ name.append(sk_tool_utils::major_platform_os_name());
+ return name;
}
SkISize onISize() override {
@@ -44,7 +46,6 @@ protected:
//With freetype the default (normal hinting) can be really ugly.
//Most distros now set slight (vertical hinting only) in any event.
paint.setHinting(SkPaint::kSlight_Hinting);
- sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
const char* text = "Hamburgefons ooo mmm";
const size_t textLen = strlen(text);
diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp
index ed8c82929d..b6d4ea23f2 100644
--- a/gm/gammatext.cpp
+++ b/gm/gammatext.cpp
@@ -40,7 +40,9 @@ static bool setFont(SkPaint* paint, const char name[]) {
class GammaTextGM : public skiagm::GM {
protected:
SkString onShortName() override {
- return SkString("gammatext");
+ SkString name("gammatext");
+ name.append(sk_tool_utils::major_platform_os_name());
+ return name;
}
SkISize onISize() override {
@@ -72,7 +74,7 @@ protected:
size_t len = strlen(text);
SkPaint paint;
- setFont(&paint, "Times");
+ setFont(&paint, sk_tool_utils::platform_font_name("serif"));
paint.setTextSize(SkIntToScalar(16));
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
diff --git a/gm/lcdtext.cpp b/gm/lcdtext.cpp
index 5ea9396f06..6daec824f3 100644
--- a/gm/lcdtext.cpp
+++ b/gm/lcdtext.cpp
@@ -27,7 +27,9 @@ public:
protected:
SkString onShortName() {
- return SkString("lcdtext");
+ SkString name("lcdtext");
+ name.append(sk_tool_utils::major_platform_os_name());
+ return name;
}
SkISize onISize() { return SkISize::Make(640, 480); }
@@ -51,7 +53,6 @@ protected:
paint.setColor(SK_ColorBLACK);
paint.setDither(true);
paint.setAntiAlias(true);
- sk_tool_utils::set_portable_typeface(&paint);
paint.setSubpixelText(subpixelTextEnabled);
paint.setLCDRenderText(lcdRenderTextEnabled);
paint.setTextSize(textHeight);
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index 5ddc338449..b8f54abe37 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -11,75 +11,6 @@
#include "SkTypeface.h"
#include "SkTypes.h"
-static const char* gFaces[] = {
- "Times Roman",
- "Hiragino Maru Gothic Pro",
- "Papyrus",
- "Helvetica",
- "Courier New"
-};
-
-class TypefaceGM : public skiagm::GM {
-public:
- TypefaceGM()
- : fFaces(NULL) {
- }
-
- virtual ~TypefaceGM() {
- if (fFaces) {
- for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
- SkSafeUnref(fFaces[i]);
- }
- delete [] fFaces;
- }
- }
-
-protected:
- void onOnceBeforeDraw() override {
- fFaces = new SkTypeface*[SK_ARRAY_COUNT(gFaces)];
- for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
- fFaces[i] = sk_tool_utils::create_portable_typeface(gFaces[i], SkTypeface::kNormal);
- }
- }
-
- SkString onShortName() override {
- return SkString("typeface");
- }
-
- SkISize onISize() override {
- return SkISize::Make(640, 480);
- }
-
- void onDraw(SkCanvas* canvas) override {
- SkString text("Typefaces are fun!");
- SkScalar y = 0;
-
- SkPaint paint;
- paint.setAntiAlias(true);
- for (int i = 0; i < (int)SK_ARRAY_COUNT(gFaces); i++) {
- this->drawWithFace(text, i, y, paint, canvas);
- }
- // Now go backwards
- for (int i = SK_ARRAY_COUNT(gFaces) - 1; i >= 0; i--) {
- this->drawWithFace(text, i, y, paint, canvas);
- }
- }
-
-private:
- void drawWithFace(const SkString& text, int i, SkScalar& y, SkPaint& paint,
- SkCanvas* canvas) {
- paint.setTypeface(fFaces[i]);
- y += paint.getFontMetrics(NULL);
- canvas->drawText(text.c_str(), text.size(), 0, y, paint);
- }
-
- SkTypeface** fFaces;
-
- typedef skiagm::GM INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[],
int count, SkScalar x, SkScalar y, SkPoint pos[]) {
SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding());
@@ -177,8 +108,8 @@ public:
protected:
void onOnceBeforeDraw() override {
for (int i = 0; i < gFaceStylesCount; i++) {
- fFaces[i] = sk_tool_utils::create_portable_typeface(gFaceStyles[i].fName,
- gFaceStyles[i].fStyle);
+ fFaces[i] = SkTypeface::CreateFromName(
+ sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFaceStyles[i].fStyle);
}
}
@@ -187,6 +118,7 @@ protected:
if (fApplyKerning) {
name.append("_kerning");
}
+ name.append(sk_tool_utils::major_platform_os_name());
return name;
}
@@ -227,6 +159,5 @@ private:
///////////////////////////////////////////////////////////////////////////////
-DEF_GM( return new TypefaceGM; )
DEF_GM( return new TypefaceStylesGM(false); )
DEF_GM( return new TypefaceStylesGM(true); )
diff --git a/gm/verttext2.cpp b/gm/verttext2.cpp
index 9918049f10..3a3955ee7c 100644
--- a/gm/verttext2.cpp
+++ b/gm/verttext2.cpp
@@ -32,12 +32,16 @@ protected:
void onOnceBeforeDraw() override {
const int pointSize = 24;
textHeight = SkIntToScalar(pointSize);
- fProp = sk_tool_utils::create_portable_typeface("Helvetica", SkTypeface::kNormal);
- fMono = sk_tool_utils::create_portable_typeface("Courier New", SkTypeface::kNormal);
+ fProp = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("sans-serif"),
+ SkTypeface::kNormal);
+ fMono = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("monospace"),
+ SkTypeface::kNormal);
}
SkString onShortName() override {
- return SkString("verttext2");
+ SkString name("verttext2");
+ name.append(sk_tool_utils::major_platform_os_name());
+ return name;
}
SkISize onISize() override { return SkISize::Make(640, 480); }