00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __FONTDEFINITION_H__
00021 #define __FONTDEFINITION_H__
00022
00023 #include <vrs/image/imagemanipulator.h>
00024 #include <vrs/container/array.h>
00025 #include <vrs/sharedobj.h>
00026
00027 #include <vrs/text/vrs_textprerequisites.h>
00028 #include <vrs/text/fontglyph.h>
00029 #include <vrs/text/fonttexture.h>
00030 #include <vrs/text/fontsize.h>
00031
00032 #include <vector>
00033 #include <map>
00034 #include <string>
00035
00036 struct FT_FaceRec_;
00037 typedef struct FT_FaceRec_* FT_Face;
00038 struct FT_Bitmap_;
00039 typedef struct FT_Bitmap_ FT_Bitmap;
00040 struct FT_Stroker_;
00041 typedef struct FT_StrokerRec_* FT_Stroker;
00042
00043
00045 namespace VRS
00046 {
00047 namespace TEXT
00048 {
00049 typedef std::vector< SO<FontTexture> > FontTextureVector;
00050 typedef std::map<unsigned int, SO<FontGlyph> > FontGlyphMap;
00051 typedef std::map<GlyphCharcode, SO<FontGlyph> > FontGlyphCharMap;
00052
00058 class VRS_CORE_API FontDefinition : public SharedObj
00059 {
00060 public:
00062 FontDefinition( const std::string& name, const std::string& fontfile,
00063 const std::string& style, SO<FontSize> size, unsigned int typeFlags );
00065 virtual ~FontDefinition();
00066
00068 inline const std::string& getName() const
00069 { return m_Name; };
00071 inline const std::string& getFont() const
00072 { return m_Font; };
00074 inline const std::string& getStyle() const
00075 { return m_Style; };
00077 inline const SO<FontSize> getSize() const
00078 { return m_Size; };
00080 inline float getLineHeight() const
00081 { if( m_UseMetrics != 0 ) return m_UseMetrics->getLineHeight(); else return m_LineHeight; };
00083 inline bool hasVerticalMetrics() const
00084 { return m_HasVerticalMetrics; };
00086 inline bool hasHorizontalMetrics() const
00087 { return m_HasHorizontalMetrics; };
00088
00090 inline float getAscender() const
00091 { if( m_UseMetrics != 0 ) return m_UseMetrics->getAscender(); else return m_Ascender; };
00093 inline float getDescender() const
00094 { if( m_UseMetrics != 0 ) return m_UseMetrics->getDescender(); else return m_Descender; };
00096 inline unsigned int getTextureSize() const
00097 { return m_TextureSize; };
00098
00099
00100 inline unsigned int getPixelPerEmY() const
00101 { return m_PixelPerEmY; };
00102
00103 inline unsigned int getPixelPerEmX() const
00104 { return m_PixelPerEmX; };
00105
00107 std::string toString() const;
00108
00114 void loadFontFace();
00115
00120 SO<FontDefinition> getFallBackFont() const;
00125 void setFallBackFont( SO<FontDefinition> fontdef );
00126
00131 SO<FontTexture> getFontTexture(unsigned int id) const;
00132
00133
00137 void addGlyphs( GlyphCharcode* charArray, unsigned int count );
00143 #ifdef VRS_HAS_WSTRING // Has Unicode support
00144 void addGlyphs( const std::wstring& str );
00145 #endif
00146 void addGlyphs( const std::string& str );
00153 #ifdef VRS_HAS_WSTRING // Has Unicode support
00154 void addGlyphs( const wchar_t* str, int count );
00155 #endif
00156 void addGlyphs( const char* str, int count );
00157
00161 void addGlyphs( std::vector<GlyphCharcode> charVec );
00165 void addGlyphs( SO<Array<GlyphCharcode> > charArr );
00169 void addDefaultGlyphs( );
00170
00175 bool hasGlyphForChar( GlyphCharcode cha ) const;
00176
00181 bool isGlyphForCharLoaded( GlyphCharcode cha ) const;
00187 SO<FontGlyph> getGlyphForCharcode( GlyphCharcode cha );
00188
00195 void injectFontGlyph( GlyphCharcode cha, SO<FontGlyph> fg );
00201 SO<FontGlyph> getInjectedFontGlyph( GlyphCharcode cha );
00206 void removeInjectedFontGlyph( GlyphCharcode cha );
00209 void clearInjectedFontGlyphs( );
00210
00216 SO<FontGlyph> addGlyphForChar( GlyphCharcode cha );
00217
00224 SO<FontGlyph> addGlyph( unsigned int glyph_index, GlyphCharcode cha = 0 );
00225
00230 void setOutline( float bordersize, SO<FontDefinition> useMetrics = NULL );
00231
00235 SO<FontDefinition> getUseMetrics( ) const;
00236
00238 void applyImageManipulation( SO<ImageManipulator> imageman, unsigned int times = 1 );
00239
00241 inline unsigned int getGlpyhSpacing() const
00242 { return m_GlyphSpacing; };
00244 void setGlpyhSpacing( unsigned int spacing );
00246 void setExtraGlpyhBorder( unsigned int border );
00247
00249 unsigned int getGlyphRepresentationTypes() const;
00250
00251 #ifdef PROTOTYPE
00253 void writeTexturesToPng() const;
00254 #endif
00255
00256 VRS_TYPEINFO(FontDefinition, SharedObj);
00257 VRS_SERIALIZABLE(FontDefinition);
00258 private:
00265 SO<FontGlyph> doAddGlyph( unsigned int glyph_index, GlyphCharcode cha = 0 );
00266
00274 SO<FontTexture> renderBitmap( const FT_Bitmap& bitmap, unsigned int* uv );
00275
00277 FontDefinition();
00278
00280 std::string m_Name;
00282 std::string m_Font;
00284 std::string m_Style;
00286 SO<FontSize> m_Size;
00287
00289 float m_LineHeight;
00291 float m_Ascender;
00293 float m_Descender;
00295 float m_PixelPerEmY;
00297 float m_PixelPerEmX;
00298
00300 unsigned int m_TextureSize;
00302 FT_Face m_Face;
00304 FT_Stroker m_Stroker;
00306 float m_StrokerBorder;
00307
00309 SO<ImageManipulator> m_ImageManipulator;
00311 unsigned int m_ManipulateTimes;
00312
00314 FontTextureVector m_Textures;
00316 FontGlyphMap m_Glyphs;
00318 bool m_isLoaded;
00319
00321 bool m_HasVerticalMetrics;
00323 bool m_HasHorizontalMetrics;
00324
00326 SO<FontDefinition> m_FallbackFont;
00328 SO<FontDefinition> m_UseMetrics;
00329
00331 FontGlyphCharMap m_InjectedGlyphs;
00332
00334 unsigned int m_GlyphSpacing;
00336 unsigned int m_ExtraGlyphBorder;
00337
00339 unsigned int m_GlyphRepresentationTypes;
00340 };
00341
00342 }
00343 }
00344
00345 #endif