diff options
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkFontHost_android.cpp | 51 | ||||
-rw-r--r-- | src/ports/SkFontHost_ascender.cpp | 2 | ||||
-rw-r--r-- | src/ports/SkFontHost_freetype_mac.cpp | 7 | ||||
-rw-r--r-- | src/ports/SkFontHost_linux.cpp | 49 | ||||
-rw-r--r-- | src/ports/SkFontHost_simple.cpp | 48 |
5 files changed, 46 insertions, 111 deletions
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index e1d6cf471e..a955b6313b 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -9,7 +9,6 @@ #include "SkFontDescriptor.h" #include "SkGraphics.h" #include "SkDescriptor.h" -#include "SkMMapStream.h" #include "SkPaint.h" #include "SkString.h" #include "SkStream.h" @@ -370,30 +369,19 @@ public: fPath.set(path); } - // overrides - virtual SkStream* openStream() { - SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str())); - - // check for failure - if (stream->getLength() <= 0) { - SkDELETE(stream); - // maybe MMAP isn't supported. try FILE - stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str())); - if (stream->getLength() <= 0) { - SkDELETE(stream); - stream = NULL; - } - } - return stream; + virtual SkStream* openStream() SK_OVERRIDE { + return SkStream::NewFromFile(fPath.c_str()); } - virtual const char* getUniqueString() const { + + virtual const char* getUniqueString() const SK_OVERRIDE { const char* str = strrchr(fPath.c_str(), '/'); if (str) { str += 1; // skip the '/' } return str; } - virtual const char* getFilePath() const { + + virtual const char* getFilePath() const SK_OVERRIDE { return fPath.c_str(); } @@ -412,21 +400,15 @@ static bool get_name_and_style(const char path[], SkString* name, SkString fullpath; GetFullPathForSysFonts(&fullpath, path); - SkMMAPStream stream(fullpath.c_str()); - if (stream.getLength() > 0) { - return find_name_and_attributes(&stream, name, style, isFixedWidth); - } - else { - SkFILEStream stream(fullpath.c_str()); - if (stream.getLength() > 0) { - return find_name_and_attributes(&stream, name, style, isFixedWidth); + SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fullpath.c_str())); + if (stream.get()) { + return find_name_and_attributes(stream, name, style, isFixedWidth); + } else { + if (isExpected) { + SkDebugf("---- failed to open <%s> as a font", fullpath.c_str()); } + return false; } - - if (isExpected) { - SkDebugf("---- failed to open <%s> as a font", fullpath.c_str()); - } - return false; } // used to record our notion of the pre-existing fonts @@ -952,11 +934,8 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { } SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { - SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); - SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); - // since we created the stream, we let go of our ref() here - stream->unref(); - return face; + SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); + return stream.get() ? SkFontHost::CreateTypefaceFromStream(stream) : NULL; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ports/SkFontHost_ascender.cpp b/src/ports/SkFontHost_ascender.cpp index d20cc825cd..51210d9642 100644 --- a/src/ports/SkFontHost_ascender.cpp +++ b/src/ports/SkFontHost_ascender.cpp @@ -21,8 +21,6 @@ ////////////////////////////////////////////////////////////////////////// -#include "SkMMapStream.h" - class SkScalerContext_Ascender : public SkScalerContext { public: SkScalerContext_Ascender(const SkDescriptor* desc); diff --git a/src/ports/SkFontHost_freetype_mac.cpp b/src/ports/SkFontHost_freetype_mac.cpp index bc197d6872..3d89bc613a 100644 --- a/src/ports/SkFontHost_freetype_mac.cpp +++ b/src/ports/SkFontHost_freetype_mac.cpp @@ -6,7 +6,6 @@ */ #include "SkFontHost.h" -#include "SkMMapStream.h" #include "SkTypefaceCache.h" #define FONT_PATH "/Library/Fonts/Skia.ttf" @@ -26,7 +25,11 @@ public: }; static FTMacTypeface* create_from_path(const char path[]) { - SkStream* stream = new SkMMAPStream(path); + SkStream* stream = SkStream::NewFromFile(path); + if (!stream) { + return NULL; + } + size_t size = stream->getLength(); SkASSERT(size); FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal, diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp index 07235c875f..25ae7effe2 100644 --- a/src/ports/SkFontHost_linux.cpp +++ b/src/ports/SkFontHost_linux.cpp @@ -10,7 +10,6 @@ #include "SkFontHost.h" #include "SkFontDescriptor.h" #include "SkDescriptor.h" -#include "SkMMapStream.h" #include "SkOSFile.h" #include "SkPaint.h" #include "SkString.h" @@ -280,8 +279,8 @@ public: EmptyTypeface() : INHERITED(SkTypeface::kNormal, true, NULL, false) {} // overrides - virtual SkStream* openStream() { return NULL; } - virtual const char* getUniqueString() const { return NULL; } + virtual SkStream* openStream() SK_OVERRIDE { return NULL; } + virtual const char* getUniqueString() SK_OVERRIDE const { return NULL; } private: typedef FamilyTypeface INHERITED; @@ -299,14 +298,12 @@ public: fStream->unref(); } - // overrides - virtual SkStream* openStream() - { + virtual SkStream* openStream() SK_OVERRIDE { // openStream returns a refed stream. fStream->ref(); return fStream; } - virtual const char* getUniqueString() const { return NULL; } + virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } private: SkStream* fStream; @@ -322,25 +319,11 @@ public: fPath.set(path); } - // overrides - virtual SkStream* openStream() - { - SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str())); - - // check for failure - if (stream->getLength() <= 0) { - SkDELETE(stream); - // maybe MMAP isn't supported. try FILE - stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str())); - if (stream->getLength() <= 0) { - SkDELETE(stream); - stream = NULL; - } - } - return stream; + virtual SkStream* openStream() SK_OVERRIDE { + return SkStream::NewFromFile(fPath.c_str()); } - virtual const char* getUniqueString() const { + virtual const char* getUniqueString() const SK_OVERRIDE { const char* str = strrchr(fPath.c_str(), '/'); if (str) { str += 1; // skip the '/' @@ -359,19 +342,13 @@ private: static bool get_name_and_style(const char path[], SkString* name, SkTypeface::Style* style, bool* isFixedWidth) { - SkMMAPStream stream(path); - if (stream.getLength() > 0) { - return find_name_and_attributes(&stream, name, style, isFixedWidth); - } - else { - SkFILEStream stream(path); - if (stream.getLength() > 0) { - return find_name_and_attributes(&stream, name, style, isFixedWidth); - } + SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); + if (stream.get()) { + return find_name_and_attributes(stream, name, style, isFixedWidth); + } else { + SkDebugf("---- failed to open <%s> as a font\n", path); + return false; } - - SkDebugf("---- failed to open <%s> as a font\n", path); - return false; } // these globals are assigned (once) by load_system_fonts() diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp index 101d5761d2..b4f6ce0f1d 100644 --- a/src/ports/SkFontHost_simple.cpp +++ b/src/ports/SkFontHost_simple.cpp @@ -9,7 +9,6 @@ #include "SkFontHost.h" #include "SkDescriptor.h" -#include "SkMMapStream.h" #include "SkPaint.h" #include "SkString.h" #include "SkStream.h" @@ -312,30 +311,18 @@ public: fPath.set(path); } - // overrides - virtual SkStream* openStream() { - SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str())); - - // check for failure - if (stream->getLength() <= 0) { - SkDELETE(stream); - // maybe MMAP isn't supported. try FILE - stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str())); - if (stream->getLength() <= 0) { - SkDELETE(stream); - stream = NULL; - } - } - return stream; + virtual SkStream* openStream() SK_OVERRIDE { + return SkStream::NewFromFile(fPath.c_str()); } - virtual const char* getUniqueString() const { + + virtual const char* getUniqueString() const SK_OVERRIDE { const char* str = strrchr(fPath.c_str(), '/'); if (str) { str += 1; // skip the '/' } return str; } - virtual const char* getFilePath() const { + virtual const char* getFilePath() const SK_OVERRIDE { return fPath.c_str(); } @@ -353,21 +340,15 @@ static bool get_name_and_style(const char path[], SkString* name, SkString fullpath; GetFullPathForSysFonts(&fullpath, path); - SkMMAPStream stream(fullpath.c_str()); - if (stream.getLength() > 0) { + SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fullpath.c_str())); + if (stream.get()) { return find_name_and_attributes(&stream, name, style, NULL); - } - else { - SkFILEStream stream(fullpath.c_str()); - if (stream.getLength() > 0) { - return find_name_and_attributes(&stream, name, style, NULL); + } else { + if (isExpected) { + SkDebugf("---- failed to open <%s> as a font\n", fullpath.c_str()); } + return false; } - - if (isExpected) { - SkDebugf("---- failed to open <%s> as a font\n", fullpath.c_str()); - } - return false; } // used to record our notion of the pre-existing fonts @@ -636,9 +617,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { } SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { - SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); - SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); - // since we created the stream, we let go of our ref() here - stream->unref(); - return face; + SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); + return stream.get() ? SkFontHost::CreateTypefaceFromStream(stream) : NULL; } |