Fix regression where we disable fonts with no specified name

Review URL: https://codereview.appspot.com/5675061

git-svn-id: http://skia.googlecode.com/svn/trunk@3202 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2012-02-15 21:03:45 +00:00
parent 48b481bc22
commit 4dc686d753
4 changed files with 41 additions and 44 deletions

View File

@ -1477,12 +1477,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_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 +1508,22 @@ SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name,
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 +1531,5 @@ SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name,
FT_Done_Face(face);
FT_Done_FreeType(library);
return (SkTypeface::Style)style;
return true;
}

View File

@ -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"));
@ -373,14 +373,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_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 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
}
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;

View File

@ -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 @@ static bool get_name_and_style(const char path[], SkString* name,
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 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
}
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[]) {

View File

@ -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 @@ private:
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 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
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[]) {