Fix regression where we disable fonts with no specified name.
bug: 6011971
Change-Id: Ic9e9088dcc2fe3c8d675f64605223e2def0a6e18
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 61efb95..94cd1b0 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -857,16 +857,6 @@
this face with other context (at different sizes).
*/
FT_Error SkScalerContext_FreeType::setupSize() {
- /* In the off-chance that a font has been removed, we want to error out
- right away, so call resolve just to be sure.
-
- TODO: perhaps we can skip this, by walking the global font cache and
- killing all of the contexts when we know that a given fontID is going
- away...
- */
- if (!SkFontHost::ValidFontID(fRec.fFontID)) {
- return (FT_Error)-1;
- }
FT_Error err = FT_Activate_Size(fFTSize);
@@ -1477,12 +1467,11 @@
/* 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_attributes(SkStream* stream, SkString* name,
- bool* isFixedWidth) {
+bool find_name_and_attributes(SkStream* stream, SkString* name,
+ SkTypeface::Style* style, bool* isFixedWidth) {
FT_Library library;
if (FT_Init_FreeType(&library)) {
- name->reset();
- return SkTypeface::kNormal;
+ return false;
}
FT_Open_Args args;
@@ -1509,18 +1498,22 @@
FT_Face face;
if (FT_Open_Face(library, &args, 0, &face)) {
FT_Done_FreeType(library);
- name->reset();
- 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;
+ }
+
+ if (name) {
+ name->set(face->family_name);
+ }
+ if (style) {
+ *style = (SkTypeface::Style) tempStyle;
}
if (isFixedWidth) {
*isFixedWidth = FT_IS_FIXED_WIDTH(face);
@@ -1528,5 +1521,5 @@
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 b07d93d..0f41818 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -32,8 +32,8 @@
#define SK_FONT_FILE_PREFIX "/fonts/"
#endif
-SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name,
- bool* isFixedWidth);
+bool find_name_and_attributes(SkStream* stream, SkString* name,
+ SkTypeface::Style* style, bool* isFixedWidth);
static void GetFullPathForSysFonts(SkString* full, const char name[]) {
full->set(getenv("ANDROID_ROOT"));
@@ -108,7 +108,7 @@
}
}
// should never get here, since the faces list should not be empty
- SkASSERT(!"faces list is empty");
+ SkDEBUGFAIL("faces list is empty");
return NULL;
}
@@ -373,14 +373,12 @@
SkMMAPStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, isFixedWidth);
}
else {
SkFILEStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, isFixedWidth);
}
}
@@ -749,10 +747,9 @@
}
bool isFixedWidth;
- SkString name;
- SkTypeface::Style style = find_name_and_attributes(stream, &name, &isFixedWidth);
+ SkTypeface::Style style;
- if (!name.isEmpty()) {
+ if (find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth));
} else {
return NULL;
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index c87b036..14684ed 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -22,8 +22,8 @@
#define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/msttcorefonts/"
#endif
-SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name,
- bool* isFixedWidth);
+bool find_name_and_attributes(SkStream* stream, SkString* name,
+ SkTypeface::Style* style, bool* isFixedWidth);
static void GetFullPathForSysFonts(SkString* full, const char name[])
{
@@ -358,14 +358,12 @@
SkTypeface::Style* style, bool* isFixedWidth) {
SkMMAPStream stream(path);
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, isFixedWidth);
}
else {
SkFILEStream stream(path);
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, isFixedWidth);
}
}
@@ -581,10 +579,12 @@
}
bool isFixedWidth;
- SkString name;
- SkTypeface::Style style = find_name_and_attributes(stream, &name, &isFixedWidth);
-
- return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth));
+ SkTypeface::Style style;
+ if (find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
+ return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth));
+ } else {
+ return NULL;
+ }
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp
index 0624d35..c0674ca 100644
--- a/src/ports/SkFontHost_simple.cpp
+++ b/src/ports/SkFontHost_simple.cpp
@@ -23,8 +23,8 @@
#define SK_FONT_FILE_PREFIX "/skimages/"
#endif
-SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name,
- bool* isFixedWidth);
+bool find_name_and_attributes(SkStream* stream, SkString* name,
+ SkTypeface::Style* style, bool* isFixedWidth);
static void GetFullPathForSysFonts(SkString* full, const char name[]) {
full->set(SK_FONT_FILE_PREFIX);
@@ -350,20 +350,17 @@
static bool get_name_and_style(const char path[], SkString* name,
SkTypeface::Style* style, bool isExpected) {
- bool isFixedWidth;
SkString fullpath;
GetFullPathForSysFonts(&fullpath, path);
SkMMAPStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, &isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, NULL);
}
else {
SkFILEStream stream(fullpath.c_str());
if (stream.getLength() > 0) {
- *style = find_name_and_attributes(&stream, name, &isFixedWidth);
- return true;
+ return find_name_and_attributes(&stream, name, style, NULL);
}
}
@@ -635,12 +632,12 @@
return NULL;
}
- bool isFixedWidth;
- SkString name;
- SkTypeface::Style style = find_name_and_attributes(stream, &name,
- &isFixedWidth);
-
- return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream));
+ SkTypeface::Style style;
+ if (find_name_and_attributes(stream, NULL, &style, NULL)) {
+ return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream));
+ } else {
+ return NULL;
+ }
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {