diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-23 14:41:42 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-23 14:41:42 +0000 |
commit | 5b31b0f1eaca0cdc3aa5697e8efa1baf68b0774e (patch) | |
tree | 39d0a3ec1254f17add0d42758d519fed1ee81a5e /src/ports | |
parent | 3f0260d0f7692f28057cfcf7121829285e972e28 (diff) |
add fixed-width attribute to typeface
(patch from russellbrenner)
git-svn-id: http://skia.googlecode.com/svn/trunk@837 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkFontHost_FreeType.cpp | 10 | ||||
-rw-r--r-- | src/ports/SkFontHost_android.cpp | 35 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 7f1e377260..c1720cccca 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -518,13 +518,13 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { InitFreetype(); FT_Done_FreeType(gFTLibrary); } - + if (!gLCDSupport && rec->isLCD()) { // If the runtime Freetype library doesn't support LCD mode, we disable // it here. rec->fMaskFormat = SkMask::kA8_Format; } - + SkPaint::Hinting h = rec->getHinting(); if (SkPaint::kFull_Hinting == h && !rec->isLCD()) { // collapse full->normal hinting if we're not doing LCD @@ -1244,7 +1244,8 @@ 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) { +SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name, + bool* isFixedWidth) { FT_Library library; if (FT_Init_FreeType(&library)) { name->set(NULL); @@ -1288,6 +1289,9 @@ SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name) { if (face->style_flags & FT_STYLE_FLAG_ITALIC) { style |= SkTypeface::kItalic; } + if (isFixedWidth) { + *isFixedWidth = FT_IS_FIXED_WIDTH(face); + } FT_Done_Face(face); FT_Done_FreeType(library); diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index 73672a7372..2c31dacd97 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -31,7 +31,8 @@ #define SK_FONT_FILE_PREFIX "/fonts/" #endif -SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name); +SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name, + bool* isFixedWidth); static void GetFullPathForSysFonts(SkString* full, const char name[]) { full->set(getenv("ANDROID_ROOT")); @@ -235,8 +236,9 @@ static void remove_from_names(FamilyRec* emptyFamily) class FamilyTypeface : public SkTypeface { public: - FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember) - : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1) { + FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember, + bool isFixedWidth) + : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) { fIsSysFont = sysFont; SkAutoMutexAcquire ac(gFamilyMutex); @@ -280,8 +282,8 @@ private: class StreamTypeface : public FamilyTypeface { public: StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember, - SkStream* stream) - : INHERITED(style, sysFont, familyMember) { + SkStream* stream, bool isFixedWidth) + : INHERITED(style, sysFont, familyMember, isFixedWidth) { SkASSERT(stream); stream->ref(); fStream = stream; @@ -311,8 +313,8 @@ private: class FileTypeface : public FamilyTypeface { public: FileTypeface(Style style, bool sysFont, SkTypeface* familyMember, - const char path[]) - : INHERITED(style, sysFont, familyMember) { + const char path[], bool isFixedWidth) + : INHERITED(style, sysFont, familyMember, isFixedWidth) { SkString fullpath; if (sysFont) { @@ -359,19 +361,20 @@ private: /////////////////////////////////////////////////////////////////////////////// static bool get_name_and_style(const char path[], SkString* name, - SkTypeface::Style* style, bool isExpected) { + SkTypeface::Style* style, + bool* isFixedWidth, bool isExpected) { SkString fullpath; GetFullPathForSysFonts(&fullpath, path); SkMMAPStream stream(fullpath.c_str()); if (stream.getLength() > 0) { - *style = find_name_and_style(&stream, name); + *style = find_name_and_attributes(&stream, name, isFixedWidth); return true; } else { SkFILEStream stream(fullpath.c_str()); if (stream.getLength() > 0) { - *style = find_name_and_style(&stream, name); + *style = find_name_and_attributes(&stream, name, isFixedWidth); return true; } } @@ -461,12 +464,14 @@ static void load_system_fonts() { firstInFamily = NULL; } + bool isFixedWidth; SkString name; SkTypeface::Style style; // we expect all the fonts, except the "fallback" fonts bool isExpected = (rec[i].fNames != gFBNames); - if (!get_name_and_style(rec[i].fFileName, &name, &style, isExpected)) { + if (!get_name_and_style(rec[i].fFileName, &name, &style, + &isFixedWidth, isExpected)) { continue; } @@ -474,7 +479,8 @@ static void load_system_fonts() { (style, true, // system-font (cannot delete) firstInFamily, // what family to join - rec[i].fFileName) // filename + rec[i].fFileName, + isFixedWidth) // filename ); if (rec[i].fNames != NULL) { @@ -655,10 +661,11 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { return NULL; } + bool isFixedWidth; SkString name; - SkTypeface::Style style = find_name_and_style(stream, &name); + SkTypeface::Style style = find_name_and_attributes(stream, &name, &isFixedWidth); - return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream)); + return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth)); } SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |