add EmptyTypeface class, to gracefully handle when there are no fonts avail.
git-svn-id: http://skia.googlecode.com/svn/trunk@553 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index 22256fa..0b6f88e 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -278,6 +278,23 @@
///////////////////////////////////////////////////////////////////////////////
+/* This subclass is just a place holder for when we have no fonts available.
+ It exists so that our globals (e.g. gFamilyHead) that expect *something*
+ will not be null.
+ */
+class EmptyTypeface : public FamilyTypeface {
+public:
+ EmptyTypeface() : INHERITED(SkTypeface::kNormal, true, NULL) {}
+
+ // overrides
+ virtual SkStream* openStream() { return NULL; }
+ virtual void closeStream(SkStream*) {}
+ virtual const char* getUniqueString() const { return NULL; }
+
+private:
+ typedef FamilyTypeface INHERITED;
+};
+
class StreamTypeface : public FamilyTypeface {
public:
StreamTypeface(Style style, bool sysFont, FamilyRec* family,
@@ -383,8 +400,9 @@
return;
}
- SkOSFile::Iter iter(SK_FONT_FILE_PREFIX, ".ttf");
- SkString name;
+ SkOSFile::Iter iter(SK_FONT_FILE_PREFIX, ".ttf");
+ SkString name;
+ int count = 0;
while (iter.next(&name, false)) {
SkString filename;
@@ -418,6 +436,11 @@
if (NULL == family) {
add_name(realname.c_str(), tf->getFamily());
}
+ count += 1;
+ }
+
+ if (0 == count) {
+ SkNEW(EmptyTypeface);
}
// do this after all fonts are loaded. This is our default font, and it