00001
00032 #ifndef LL_LLFONT_H
00033 #define LL_LLFONT_H
00034
00035 #include <map>
00036
00037 #include "llmemory.h"
00038 #include "llstl.h"
00039
00040 class LLImageRaw;
00041 class LLFontManager;
00042 class LLFont;
00043
00044
00045
00046
00047
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
00071 S32 mWidth;
00072 S32 mHeight;
00073 F32 mXAdvance;
00074 F32 mYAdvance;
00075
00076
00077 BOOL mIsRendered;
00078 S32 mXBitmapOffset;
00079 S32 mYBitmapOffset;
00080 S32 mXBearing;
00081 S32 mYBearing;
00082 };
00083
00084
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
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
00113 virtual F32 getLineHeight() const;
00114 virtual F32 getAscenderHeight() const;
00115 virtual F32 getDescenderHeight() const;
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 enum
00134 {
00135 FIRST_CHAR = 32,
00136 NUM_CHARS = 127 - 32,
00137 LAST_CHAR_BASIC = 127,
00138
00139
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;
00147 protected:
00148 virtual BOOL hasGlyph(const llwchar wch) const;
00149 virtual BOOL addChar(const llwchar wch);
00150 virtual BOOL addGlyph(const llwchar wch, const U32 glyph_index);
00151 virtual BOOL addGlyphFromFont(LLFont *fontp, const llwchar wch, const U32 glyph_index);
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();
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;
00177
00178 typedef std::map<llwchar, LLFontGlyphInfo*> char_glyph_info_map_t;
00179 mutable char_glyph_info_map_t mCharGlyphInfoMap;
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;
00191 };
00192
00193 #endif // LL_FONT_