llfont.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLFONT_H
00033 #define LL_LLFONT_H
00034 
00035 #include <map>
00036 //#include "lllocalidhashmap.h"
00037 #include "llmemory.h"
00038 #include "llstl.h"
00039 
00040 class LLImageRaw;
00041 class LLFontManager;
00042 class LLFont;
00043 
00044 // Hack.  FT_Face is just a typedef for a pointer to a struct,
00045 // but there's no simple forward declarations file for FreeType, 
00046 // and the main include file is 200K.  
00047 // We'll forward declare the struct here.  JC
00048 struct FT_FaceRec_;
00049 typedef struct FT_FaceRec_* LLFT_Face;
00050 
00051 extern LLFontManager *gFontManagerp;
00052 
00053 class LLFontManager
00054 {
00055 public:
00056         static void initClass();
00057         static void cleanupClass();
00058         
00059 public:
00060         LLFontManager();
00061         virtual ~LLFontManager();
00062 };
00063 
00064 class LLFontGlyphInfo
00065 {
00066 public:
00067         LLFontGlyphInfo(U32 index);
00068 public:
00069         U32 mGlyphIndex;
00070         // Metrics
00071         S32 mWidth;                     // In pixels
00072         S32 mHeight;            // In pixels
00073         F32 mXAdvance;          // In pixels
00074         F32 mYAdvance;          // In pixels
00075 
00076         // Information for actually rendering
00077         BOOL mIsRendered;       // We actually have rendered this glyph
00078         S32 mXBitmapOffset; // Offset to the origin in the bitmap
00079         S32 mYBitmapOffset; // Offset to the origin in the bitmap
00080         S32 mXBearing;  // Distance from baseline to left in pixels
00081         S32 mYBearing;  // Distance from baseline to top in pixels
00082 };
00083 
00084 // Used for lists of fallback fonts
00085 class LLFontList : public std::vector<LLFont*>
00086 {
00087 public:
00088         LLFontList();
00089         ~LLFontList();
00090         void addAtEnd(LLFont *font);
00091 };
00092 
00093 
00094 class LLFont
00095 {
00096 public:
00097         LLFont(LLImageRaw *imagep = NULL);
00098         virtual ~LLFont();
00099 
00100         // is_fallback should be true for fallback fonts that aren't used to render directly (Unicode backup, primarily)
00101         virtual BOOL loadFace(const std::string& filename,
00102                                                         const F32 point_size,
00103                                                         const F32 vert_dpi,
00104                                                         const F32 horz_dpi,
00105                                                         const S32 components,
00106                                                         BOOL is_fallback);
00107         void setFallbackFont(LLFontList *fontp)         { mFallbackFontp = fontp; }
00108 
00109         void setCharToGlyphMap(llwchar wch, U32 glyph_index) const;
00110         void setRawImage( LLImageRaw *imagep );
00111 
00112         // Global font metrics - in units of pixels
00113         virtual F32 getLineHeight() const;
00114         virtual F32 getAscenderHeight() const;
00115         virtual F32 getDescenderHeight() const;
00116 
00117 
00118 // For a lowercase "g":
00119 //
00120 //      ------------------------------
00121 //                           ^     ^
00122 //                                               |     |
00123 //                              xxx x    |Ascender
00124 //                 x   x     |     |
00125 //      ---------   xxxx-------------- Baseline
00126 //      ^                      x         |     |
00127 //  | descender    x     |     |
00128 //      v                       xxxx     v     |LineHeight
00129 //  -----------------------    |
00130 //                             v
00131 //      ------------------------------
00132 
00133         enum
00134         {
00135                 FIRST_CHAR = 32, 
00136                 NUM_CHARS = 127 - 32, 
00137                 LAST_CHAR_BASIC = 127,
00138 
00139                 // Need full 8-bit ascii range for spanish
00140                 NUM_CHARS_FULL = 255 - 32,
00141                 LAST_CHAR_FULL = 255
00142         };
00143 
00144         const LLFontGlyphInfo &getMetrics(const llwchar wc) const;
00145         F32 getXAdvance(const llwchar wc) const;
00146         F32 getXKerning(const llwchar char_left, const llwchar char_right) const; // Get the kerning between the two characters
00147 protected:
00148         virtual BOOL hasGlyph(const llwchar wch) const;         // Has a glyph for this character
00149         virtual BOOL addChar(const llwchar wch);                // Add a new character to the font if necessary
00150         virtual BOOL addGlyph(const llwchar wch, const U32 glyph_index);        // Add a new glyph to the existing font
00151         virtual BOOL addGlyphFromFont(LLFont *fontp, const llwchar wch, const U32 glyph_index); // Add a glyph from this font to the other (returns the glyph_index, 0 if not found)
00152 
00153         virtual LLFontGlyphInfo* getGlyphInfo(const llwchar wch) const;
00154 
00155         void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const;
00156         void renderGlyph(const U32 glyph_index);
00157 
00158         void resetBitmap();     // Reset bitmap to contain only the null glyph
00159 protected:
00160         std::string mName;
00161         F32 mAscender;                  
00162         F32 mDescender;
00163         F32 mLineHeight;
00164 
00165         S32 mNumComponents;
00166         S32 mBitmapWidth;
00167         S32 mBitmapHeight;
00168         S32 mMaxCharWidth;
00169         S32 mMaxCharHeight;
00170         S32 mCurrentOffsetX;
00171         S32 mCurrentOffsetY;
00172 
00173         LLFT_Face mFTFace;
00174 
00175         BOOL mIsFallback;
00176         LLFontList *mFallbackFontp; // A list of fallback fonts to look for glyphs in (for Unicode chars)
00177 
00178         typedef std::map<llwchar, LLFontGlyphInfo*> char_glyph_info_map_t;
00179         mutable char_glyph_info_map_t mCharGlyphInfoMap; // Information about glyph location in bitmap
00180 
00181         BOOL mValid;
00182         void setSubImageLuminanceAlpha(const U32 x,
00183                                        const U32 y,
00184                                        const U32 width,
00185                                        const U32 height,
00186                                        const U8 *data,
00187                                        S32 stride = 0);
00188 
00189 private:
00190         LLPointer<LLImageRaw> mRawImagep;       // Bitmaps of glyphs are stored here.
00191 };
00192 
00193 #endif // LL_FONT_

Generated on Fri May 16 08:32:48 2008 for SecondLife by  doxygen 1.5.5