add fixed-width attribute to typeface
(patch from russellbrenner)



git-svn-id: http://skia.googlecode.com/svn/trunk@837 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index cea6ab1..2a4eece 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -56,7 +56,7 @@
     /** Returns true if getStyle() has the kItalic bit set.
     */
     bool isItalic() const { return (fStyle & kItalic) != 0; }
-    
+
     /** Return a 32bit value for this typeface, unique for the underlying font
         data. Will never return 0.
      */
@@ -72,11 +72,11 @@
         handling either being null (treating null as the default font)
      */
     static bool Equal(const SkTypeface* facea, const SkTypeface* faceb);
-    
+
     /** Return a new reference to the typeface that most closely matches the
         requested familyName and style. Pass null as the familyName to return
         the default font for the requested style. Will never return null
-        
+
         @param familyName  May be NULL. The name of the font family.
         @param style       The style (normal, bold, italic) of the typeface.
         @return reference to the closest-matching typeface. Call must call
@@ -100,7 +100,7 @@
         requested typeface and specified Style. Use this call if you want to
         pick a new style from the same family of the existing typeface.
         If family is NULL, this selects from the default font's family.
-        
+
         @param family  May be NULL. The name of the existing type face.
         @param s       The style (normal, bold, italic) of the type face.
         @return reference to the closest-matching typeface. Call must call
@@ -112,7 +112,7 @@
         not a valid font file, returns null.
     */
     static SkTypeface* CreateFromFile(const char path[]);
-    
+
     /** Return a new typeface given a stream. If the stream is
         not a valid font file, returns null. Ownership of the stream is
         transferred, so the caller must not reference it again.
@@ -123,7 +123,7 @@
         typeface referencing the same font when Deserialize is called.
      */
     void serialize(SkWStream*) const;
-    
+
     /** Given the data previously written by serialize(), return a new instance
         to a typeface referring to the same font. If that font is not available,
         return null. If an instance is returned, the caller is responsible for
@@ -142,13 +142,14 @@
 protected:
     /** uniqueID must be unique (please!) and non-zero
     */
-    SkTypeface(Style style, uint32_t uniqueID)
-        : fUniqueID(uniqueID), fStyle(style) {}
+    SkTypeface(Style style, uint32_t uniqueID, bool isFixedWidth = false)
+        : fUniqueID(uniqueID), fStyle(style), fIsFixedWidth(isFixedWidth) {}
 
 private:
     uint32_t    fUniqueID;
     Style       fStyle;
-    
+    bool        fIsFixedWidth;
+
     typedef SkRefCnt INHERITED;
 };
 
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 7f1e377..c1720cc 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -518,13 +518,13 @@
         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 @@
 /*  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 @@
     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 73672a7..2c31dac 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 @@
 
 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 @@
 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 @@
 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 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 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 @@
             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 @@
                                     (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 @@
         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[]) {