Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef Font_INCLUDE_ONCE
00033 #define Font_INCLUDE_ONCE
00034
00035 #include <vlCore/Object.hpp>
00036 #include <vlCore/Vector4.hpp>
00037 #include <vlCore/String.hpp>
00038 #include <vlGraphics/link_config.hpp>
00039 #include <map>
00040
00041
00042 struct FT_FaceRec_;
00043 typedef struct FT_FaceRec_* FT_Face;
00044
00045 namespace vl
00046 {
00047 class Font;
00048 class FontManager;
00049
00050
00051
00055 class Glyph: public Object
00056 {
00057 private:
00058 Glyph(const Glyph& other): Object(other)
00059 {
00060 VL_DEBUG_SET_OBJECT_NAME()
00061 }
00062 void operator=(const Glyph&){}
00063
00064 public:
00065 Glyph(): mFont(NULL), mS0(0), mT0(0), mS1(0), mT1(0), mGlyphIndex(0), mTextureHandle(0), mWidth(0), mHeight(0), mLeft(0), mTop(0) {}
00066
00067 ~Glyph();
00068
00069 virtual const char* className() { return "vl::Glyph"; }
00070
00071 unsigned int textureHandle() const { return mTextureHandle; }
00072 void setTextureHandle(unsigned int handle) { mTextureHandle = handle; }
00073
00074 int width() const { return mWidth; }
00075 void setWidth(int width) { mWidth = width; }
00076
00077 int height() const { return mHeight; }
00078 void setHeight(int height) { mHeight = height; }
00079
00080 int left() const { return mLeft; }
00081 void setLeft(int left) { mLeft = left; }
00082
00083 int top() const { return mTop; }
00084 void setTop(int top) { mTop = top; }
00085
00086 float s0() const { return mS0; }
00087 void setS0(float s0) { mS0 = s0; }
00088
00089 float t0() const { return mT0; }
00090 void setT0(float t0) { mT0 = t0; }
00091
00092 float s1() const { return mS1; }
00093 void setS1(float s1) { mS1 = s1; }
00094
00095 float t1() const { return mT1; }
00096 void setT1(float t1) { mT1 = t1; }
00097
00098 const fvec2& advance() const { return mAdvance; }
00099 void setAdvance(const fvec2& advance) { mAdvance = advance; }
00100
00101 unsigned int glyphIndex() const { return mGlyphIndex; }
00102 void setGlyphIndex(unsigned int glyph_index) { mGlyphIndex = glyph_index; }
00103
00104 const Font* font() const { return mFont; }
00105 void setFont(Font* font) { mFont = font; }
00106
00107 protected:
00108 Font* mFont;
00109 fvec2 mAdvance;
00110 float mS0;
00111 float mT0;
00112 float mS1;
00113 float mT1;
00114 unsigned int mGlyphIndex;
00115 unsigned int mTextureHandle;
00116 int mWidth;
00117 int mHeight;
00118 int mLeft;
00119 int mTop;
00120 };
00121
00122
00123
00127 class VLGRAPHICS_EXPORT Font: public Object
00128 {
00129 friend class Text;
00130 friend class FontManager;
00131
00133 void operator=(const Font&) { VL_TRAP() }
00134
00136 Font(const Font& other): Object(other) { VL_TRAP() }
00137
00139 Font(FontManager* fm);
00140
00142 Font(FontManager* fm, const String& font_file, int size );
00143
00144 public:
00145 virtual const char* className() { return "vl::Font"; }
00146
00148 ~Font();
00149
00151 bool operator<(const Font& other) const
00152 {
00153 if (filePath() != other.filePath())
00154 return filePath() < other.filePath();
00155 else
00156 return size() < other.size();
00157 }
00158
00160 const String& filePath() const { return mFilePath; }
00161
00163 void loadFont(const String& path);
00164
00166 int size() const { return mSize; }
00167
00169 void setSize(int size);
00170
00172 Glyph* glyph(int character);
00173
00175 void setSmooth(bool smooth);
00176
00178 bool smooth() const { return mSmooth; }
00179
00181 void releaseFreeTypeData();
00182
00184 void setFontManager(FontManager* fm) { mFontManager = fm; }
00185
00187 const FontManager* fontManager() const { return mFontManager; }
00188
00190 FontManager* fontManager() { return mFontManager; }
00191
00194 bool freeTypeLoadForceAutoHint() const { return mFreeTypeLoadForceAutoHint; }
00195
00198 void setFreeTypLoadForceAutoHint(bool enable) { mFreeTypeLoadForceAutoHint = enable; }
00199
00200 protected:
00201 FontManager* mFontManager;
00202 String mFilePath;
00203 std::map< int, ref<Glyph> > mGlyphMap;
00204 FT_Face mFT_Face;
00205 std::vector<unsigned char> mMemoryFile;
00206 int mSize;
00207 float mHeight;
00208 bool mSmooth;
00209 bool mFreeTypeLoadForceAutoHint;
00210 };
00211
00212 }
00213
00214 #endif