aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2010-05-07 13:00:14 -0700
committerAndroid Code Review <code-review@android.com>2010-05-07 13:00:14 -0700
commit67682636faf9a799d6cfe22d07fa5042e57c6a92 (patch)
tree564bded7eae6e3a1af3d03ce34aacf7e4ebd6dfd
parent27e941fc7a0994ec5ef2d5b8586cd6fd36e7268d (diff)
parent19ca923e9120da2c5a2e66044a88022065d3c122 (diff)
downloadskia-67682636faf9a799d6cfe22d07fa5042e57c6a92.tar.gz
Merge "Improved error handling when font loading fails."
-rw-r--r--src/ports/SkFontHost_FreeType.cpp15
-rw-r--r--src/ports/SkFontHost_android.cpp16
2 files changed, 17 insertions, 14 deletions
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index c7e310e4ce..a4c51954c0 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -940,11 +940,11 @@ SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {
/* Export this so that other parts of our FonttHost port can make use of our
ability to extract the name+style from a stream, using FreeType's api.
*/
-SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name) {
+bool find_name_and_style(SkStream* stream, SkString* name, SkTypeface::Style* style) {
FT_Library library;
if (FT_Init_FreeType(&library)) {
name->set(NULL);
- return SkTypeface::kNormal;
+ return false;
}
FT_Open_Args args;
@@ -972,20 +972,21 @@ SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name) {
if (FT_Open_Face(library, &args, 0, &face)) {
FT_Done_FreeType(library);
name->set(NULL);
- return SkTypeface::kNormal;
+ return false;
}
name->set(face->family_name);
- int style = SkTypeface::kNormal;
+ int tempStyle = SkTypeface::kNormal;
if (face->style_flags & FT_STYLE_FLAG_BOLD) {
- style |= SkTypeface::kBold;
+ tempStyle |= SkTypeface::kBold;
}
if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
- style |= SkTypeface::kItalic;
+ tempStyle |= SkTypeface::kItalic;
}
+ *style = (SkTypeface::Style)tempStyle;
FT_Done_Face(face);
FT_Done_FreeType(library);
- return (SkTypeface::Style)style;
+ return true;
}
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp
index 6aa7a0b41f..2dd087ac81 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -31,7 +31,7 @@
#define SK_FONT_FILE_PREFIX "/fonts/"
#endif
-SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name);
+bool find_name_and_style(SkStream* stream, SkString* name, SkTypeface::Style* style);
static void GetFullPathForSysFonts(SkString* full, const char name[]) {
full->set(getenv("ANDROID_ROOT"));
@@ -363,14 +363,12 @@ static bool get_name_and_style(const char path[], SkString* name,
SkMMAPStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_style(&stream, name);
- return true;
+ return find_name_and_style(&stream, name, style);
}
else {
SkFILEStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_style(&stream, name);
- return true;
+ return find_name_and_style(&stream, name, style);
}
}
@@ -643,9 +641,13 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
}
SkString name;
- SkTypeface::Style style = find_name_and_style(stream, &name);
+ SkTypeface::Style style;
- return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream));
+ if (find_name_and_style(stream, &name, &style)) {
+ return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream));
+ } else {
+ return NULL;
+ }
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {