aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-04-30 17:12:58 -0400
committerGravatar bungeman <bungeman@google.com>2015-04-30 17:12:58 -0400
commit3ffa126066542590dc7430514a1174e49191b875 (patch)
treebe4f38159a515b02340ae6c24a7c253513b52177
parenta09c0461463a5976908af5232b755e1663b972bf (diff)
Move resource fonts to common location.
Move resource fonts to resources/fonts, add a destortable font for testing, and clean up how the tests create fonts from resources. R=joshualitt@google.com Review URL: https://codereview.chromium.org/1120823002
-rw-r--r--bench/TextBench.cpp8
-rw-r--r--gm/coloremoji.cpp11
-rw-r--r--gm/dcshader.cpp9
-rwxr-xr-xgm/dftext.cpp9
-rw-r--r--gm/mixedtextblobs.cpp18
-rw-r--r--gyp/ports.gyp2
-rw-r--r--resources/fonts/Distortable.ttfbin0 -> 16384 bytes
-rw-r--r--resources/fonts/Funkster.ttf (renamed from resources/Funkster.ttf)bin236808 -> 236808 bytes
-rw-r--r--resources/fonts/ReallyBigA.ttf (renamed from resources/ReallyBigA.ttf)bin14840 -> 14840 bytes
-rw-r--r--resources/fonts/test.ttc (renamed from resources/test.ttc)bin6076 -> 6076 bytes
-rw-r--r--tests/FontHostTest.cpp28
-rw-r--r--tests/SerializationTest.cpp10
-rw-r--r--tools/Resources.cpp28
-rw-r--r--tools/Resources.h4
14 files changed, 48 insertions, 79 deletions
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp
index 39484a2e04..4ee0fd3d25 100644
--- a/bench/TextBench.cpp
+++ b/bench/TextBench.cpp
@@ -66,13 +66,7 @@ public:
if (doColorEmoji) {
SkASSERT(kBW == fFQ);
- SkString filename = GetResourcePath("/Funkster.ttf");
- SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
- if (stream->isValid()) {
- fColorEmojiTypeface.reset(SkTypeface::CreateFromStream(stream.detach()));
- } else {
- SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
- }
+ fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
}
if (doPos) {
diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp
index 5a2703b4af..36897c52a8 100644
--- a/gm/coloremoji.cpp
+++ b/gm/coloremoji.cpp
@@ -54,15 +54,8 @@ protected:
const char* text;
} emojiFonts[2];
virtual void onOnceBeforeDraw() override {
- SkString filename = GetResourcePath("/Funkster.ttf");
- SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
- if (stream->isValid()) {
- fCBDT_CBLC_Typeface.reset(SkTypeface::CreateFromStream(stream.detach()));
- emojiFonts[0].typeface = fCBDT_CBLC_Typeface;
- } else {
- SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
- emojiFonts[0].typeface = NULL;
- }
+ fCBDT_CBLC_Typeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
+ emojiFonts[0].typeface = fCBDT_CBLC_Typeface;
emojiFonts[0].text = "hamburgerfons";
fSBIX_Typeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal));
diff --git a/gm/dcshader.cpp b/gm/dcshader.cpp
index 8120ff836a..6cfd00e840 100644
--- a/gm/dcshader.cpp
+++ b/gm/dcshader.cpp
@@ -219,14 +219,7 @@ protected:
struct BmpText : public Text {
void setFont(SkPaint* paint) override {
if (!fTypeface) {
- SkString filename = GetResourcePath("/Funkster.ttf");
- SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
- if (!stream->isValid()) {
- SkDebugf("Could not find Funkster.ttf, please set --resourcePath "
- "correctly.\n");
- return;
- }
- fTypeface.reset(SkTypeface::CreateFromStream(stream.detach()));
+ fTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
}
paint->setTypeface(fTypeface);
}
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
index 314ee71389..63e7cdfa5e 100755
--- a/gm/dftext.cpp
+++ b/gm/dftext.cpp
@@ -24,14 +24,7 @@ public:
protected:
void onOnceBeforeDraw() override {
- SkString filename = GetResourcePath("/Funkster.ttf");
- SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
- if (!stream->isValid()) {
- SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
- return;
- }
-
- fTypeface = SkTypeface::CreateFromStream(stream.detach());
+ fTypeface = GetResourceAsTypeface("/fonts/Funkster.ttf");
}
SkString onShortName() override {
diff --git a/gm/mixedtextblobs.cpp b/gm/mixedtextblobs.cpp
index 20b91accfd..fb1b632fb9 100644
--- a/gm/mixedtextblobs.cpp
+++ b/gm/mixedtextblobs.cpp
@@ -39,29 +39,15 @@ public:
protected:
void onOnceBeforeDraw() override {
- SkAutoTDelete<SkFILEStream> stream;
- SkString filename;
#ifndef SK_BUILD_FOR_MAC
- filename = GetResourcePath("/Funkster.ttf");
- stream.reset(new SkFILEStream(filename.c_str()));
- if (stream->isValid()) {
- fEmojiTypeface.reset(SkTypeface::CreateFromStream(stream.detach()));
- } else {
- SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
- }
+ fEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
fEmojiText = "Emoji!!!";
#else
fEmojiTypeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal));
fEmojiText = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // 💰🏡🎅
"\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80"; // 🍪🍕🚀
#endif
-
- filename = GetResourcePath("/ReallyBigA.ttf");
-
- stream.reset(new SkFILEStream(filename.c_str()));
- if (stream->isValid()) {
- fReallyBigATypeface.reset(SkTypeface::CreateFromStream(stream.detach()));
- }
+ fReallyBigATypeface.reset(GetResourceAsTypeface("/fonts/ReallyBigA.ttf"));
SkTextBlobBuilder builder;
diff --git a/gyp/ports.gyp b/gyp/ports.gyp
index 48fe89f37a..79687933e3 100644
--- a/gyp/ports.gyp
+++ b/gyp/ports.gyp
@@ -78,7 +78,7 @@
'variables': {
'embedded_font_data_identifier': 'sk_fonts',
'fonts_to_include': [
- '../resources/Funkster.ttf',
+ '../resources/fonts/Funkster.ttf',
],
},
'sources': [
diff --git a/resources/fonts/Distortable.ttf b/resources/fonts/Distortable.ttf
new file mode 100644
index 0000000000..95f30c333b
--- /dev/null
+++ b/resources/fonts/Distortable.ttf
Binary files differ
diff --git a/resources/Funkster.ttf b/resources/fonts/Funkster.ttf
index 6fc6110e0b..6fc6110e0b 100644
--- a/resources/Funkster.ttf
+++ b/resources/fonts/Funkster.ttf
Binary files differ
diff --git a/resources/ReallyBigA.ttf b/resources/fonts/ReallyBigA.ttf
index 088a560fbd..088a560fbd 100644
--- a/resources/ReallyBigA.ttf
+++ b/resources/fonts/ReallyBigA.ttf
Binary files differ
diff --git a/resources/test.ttc b/resources/fonts/test.ttc
index fb6729dce5..fb6729dce5 100644
--- a/resources/test.ttc
+++ b/resources/fonts/test.ttc
Binary files differ
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index 249fe7b1fb..ff275e2ad5 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -111,8 +111,7 @@ static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
}
}
-static void test_fontstream(skiatest::Reporter* reporter,
- SkStream* stream, int ttcIndex) {
+static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream, int ttcIndex) {
int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL);
SkAutoTArray<SkFontTableTag> array(n);
@@ -138,7 +137,13 @@ static void test_fontstream(skiatest::Reporter* reporter,
}
}
-static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream) {
+static void test_fontstream(skiatest::Reporter* reporter) {
+ SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream("/fonts/test.ttc"));
+ if (!stream) {
+ SkDebugf("Skipping FontHostTest::test_fontstream\n");
+ return;
+ }
+
int count = SkFontStream::CountTTCEntries(stream);
#ifdef DUMP_TTC_TABLES
SkDebugf("CountTTCEntries %d\n", count);
@@ -148,23 +153,6 @@ static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream) {
}
}
-static void test_fontstream(skiatest::Reporter* reporter) {
- // This test cannot run if there is no resource path.
- SkString resourcePath = GetResourcePath();
- if (resourcePath.isEmpty()) {
- SkDebugf("Could not run fontstream test because resourcePath not specified.");
- return;
- }
- SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc");
-
- SkFILEStream stream(filename.c_str());
- if (stream.isValid()) {
- test_fontstream(reporter, &stream);
- } else {
- SkDebugf("Could not run fontstream test because test.ttc not found.");
- }
-}
-
static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
if (false) { // avoid bit rot, suppress warning
SkFontID fontID = face->uniqueID();
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index f6a8a7d5fc..f7e298305f 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -317,14 +317,8 @@ static void compare_bitmaps(skiatest::Reporter* reporter,
}
static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
- // Load typeface form file.
- // This test cannot run if there is no resource path.
- SkString resourcePath = GetResourcePath();
- if (resourcePath.isEmpty()) {
- SkDebugf("Could not run fontstream test because resourcePath not specified.");
- return;
- }
- SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc");
+ // Load typeface form file to test CreateFromFile with index.
+ SkString filename = GetResourcePath("/fonts/test.ttc");
SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str(), 1);
if (!typeface) {
SkDebugf("Could not run fontstream test because test.ttc not found.");
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index 43cc21d209..4767edde5f 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -11,6 +11,8 @@
#include "SkData.h"
#include "SkImageGenerator.h"
#include "SkOSFile.h"
+#include "SkStream.h"
+#include "SkTypeface.h"
DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: images, fonts, etc.");
@@ -24,7 +26,29 @@ void SetResourcePath(const char* resource) {
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
SkString resourcePath = GetResourcePath(resource);
- SkAutoTUnref<SkData> resourceData(
- SkData::NewFromFileName(resourcePath.c_str()));
+ SkAutoTUnref<SkData> resourceData(SkData::NewFromFileName(resourcePath.c_str()));
return resourceData && SkInstallDiscardablePixelRef(resourceData, dst);
}
+
+SkStreamAsset* GetResourceAsStream(const char* resource) {
+ SkString resourcePath = GetResourcePath(resource);
+ SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
+ if (stream->isValid()) {
+ return stream.detach();
+ } else {
+ SkDebugf("Resource %s not found.\n", resource);
+ return NULL;
+ }
+}
+
+SkTypeface* GetResourceAsTypeface(const char* resource) {
+ SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource));
+ if (!stream) {
+ return NULL;
+ }
+ SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream(stream.detach()));
+ if (!typeface) {
+ SkDebugf("Resource %s not a valid font.", resource);
+ }
+ return typeface.detach();
+}
diff --git a/tools/Resources.h b/tools/Resources.h
index 99de77a8b7..c9785a574c 100644
--- a/tools/Resources.h
+++ b/tools/Resources.h
@@ -11,10 +11,14 @@
#include "SkString.h"
class SkBitmap;
+class SkStreamAsset;
+class SkTypeface;
SkString GetResourcePath(const char* resource = "");
void SetResourcePath(const char* );
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst);
+SkStreamAsset* GetResourceAsStream(const char* resource);
+SkTypeface* GetResourceAsTypeface(const char* resource);
#endif // Resources_DEFINED