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 VL_INSTRUMENT_CLASS(vl::Glyph, Object)
00058
00059 private:
00060 Glyph(const Glyph& other): Object(other)
00061 {
00062 VL_DEBUG_SET_OBJECT_NAME()
00063 }
00064 void operator=(const Glyph&){}
00065
00066 public:
00067 Glyph(): mFont(NULL), mS0(0), mT0(0), mS1(0), mT1(0), mGlyphIndex(0), mTextureHandle(0), mWidth(0), mHeight(0), mLeft(0), mTop(0) {}
00068
00069 ~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 VL_INSTRUMENT_CLASS(vl::Font, Object)
00130
00131 friend class CoreText;
00132 friend class Text;
00133 friend class FontManager;
00134
00136 void operator=(const Font&) { VL_TRAP() }
00137
00139 Font(const Font& other): Object(other) { VL_TRAP() }
00140
00142 Font(FontManager* fm = NULL);
00143
00145 Font(FontManager* fm, const String& font_file, int size );
00146
00147 public:
00149 ~Font();
00150
00152 bool operator<(const Font& other) const
00153 {
00154 if (filePath() != other.filePath())
00155 return filePath() < other.filePath();
00156 else
00157 return size() < other.size();
00158 }
00159
00161 const String& filePath() const { return mFilePath; }
00162
00164 void loadFont(const String& path);
00165
00167 int size() const { return mSize; }
00168
00170 void setSize(int size);
00171
00173 Glyph* glyph(int character);
00174
00176 void setSmooth(bool smooth);
00177
00179 bool smooth() const { return mSmooth; }
00180
00182 void releaseFreeTypeData();
00183
00185 void setFontManager(FontManager* fm) { mFontManager = fm; }
00186
00188 const FontManager* fontManager() const { return mFontManager; }
00189
00191 FontManager* fontManager() { return mFontManager; }
00192
00195 bool freeTypeLoadForceAutoHint() const { return mFreeTypeLoadForceAutoHint; }
00196
00199 void setFreeTypLoadForceAutoHint(bool enable) { mFreeTypeLoadForceAutoHint = enable; }
00200
00201 protected:
00202 FontManager* mFontManager;
00203 String mFilePath;
00204 std::map< int, ref<Glyph> > mGlyphMap;
00205 FT_Face mFT_Face;
00206 std::vector<char> mMemoryFile;
00207 int mSize;
00208 float mHeight;
00209 bool mSmooth;
00210 bool mFreeTypeLoadForceAutoHint;
00211 };
00212
00213 }
00214
00215 #endif