| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /********************************************************************** 00002 VRS - The Virtual Rendering System 00003 Copyright (C) 2001 Computer Graphics Systems Group at the 00004 Hasso-Plattner-Institute, Potsdam, Germany. 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 This library is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 See the GNU Lesser General Public License for more details. 00013 You should have received a copy of the GNU Lesser+ General Public 00014 License along with this library; if not, write to the FreeSoftware 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA. 00016 **********************************************************************/ 00017 // $Id: font.h 6014 2007-08-09 07:51:16Z Konstantin_Baumann $ 00018 // $Date: 2007-08-09 09:51:16 +0200 (Thu, 09 Aug 2007) $ 00019 // $Revision: 6014 $ 00020 // $State$ 00021 // $Author: Konstantin_Baumann $ 00022 // 00023 // $Log$ 00024 // Revision 1.37 2006/02/07 15:28:10 bohnet 00025 // fix: Bitmap-Font problem due to wrong GL_UNPACK_ALIGNMENT 00026 // 00027 // Revision 1.36 2005/01/03 01:43:07 klimetschek 00028 // - modified win32 project layout, splitted vrs.vcproj into vrs_container, vrs_core, vrs_sg, vrs_image, vrs_opengl and vrs_io 00029 // - removed vrs.vcproj 00030 // minor things: 00031 // - added all glutexamples to vrs4glut.sln 00032 // - fixed some problems in glutexamples 00033 // - removed all project references from all VS projects (using solution wide project dependencies instead) 00034 // 00035 // Revision 1.35 2004/11/05 13:58:09 basch 00036 // Class comment changed (Doxygen style) 00037 // 00038 // Revision 1.34 2004/08/05 16:51:49 haykel 00039 // - Added static function Font::fontSupported which returns if a font is supported 00040 // in VRS (returns true if fontAvailable() returns true and the font is not in a list 00041 // of fonts known not to work in VRS) 00042 // 00043 // Revision 1.33 2004/06/21 07:25:24 baumann 00044 // performance improvement: instead of using an Array<Cache> for several PolygonSets 00045 // we use a Cache for a Composite consisting of several PolygonSets 00046 // 00047 // Revision 1.32 2004/06/06 19:02:36 kirsch 00048 // use unnamed namespace instead of private static attributes and methods 00049 // 00050 // Revision 1.31 2004/06/06 08:35:59 baumann 00051 // using std::map<std::string, std::string> instead of VRS::Dictionary<std::string, std::string> 00052 // 00053 // Revision 1.30 2004/05/27 09:49:23 schmidt 00054 // added VRS_CORE_API to Glyph classes 00055 // 00056 // Revision 1.29 2004/03/12 16:28:38 baumann 00057 // macros VRS_NAMESPACE_BEGIN/_END expanded and removed 00058 // 00059 // Revision 1.28 2004/01/29 09:16:34 baumann 00060 // added explicit cast for char -> unsigned char -> wchar_t 00061 // 00062 // Revision 1.27 2004/01/19 11:43:57 baumann 00063 // serialization mechanism improved 00064 // 00065 // Revision 1.26 2004/01/19 07:28:03 baumann 00066 // serialization mechanism improved 00067 // 00068 // Revision 1.25 2003/12/07 10:41:25 kirsch 00069 // added qualified namespace of std::string 00070 // 00071 // Revision 1.24 2003/11/07 14:19:24 kirsch 00072 // removed leading underscore from include guards 00073 // 00074 // Revision 1.23 2003/07/23 17:04:49 baumann 00075 // code cleanup (especially untabified) 00076 // 00077 // Revision 1.22 2003/06/23 09:47:42 baumann 00078 // - new compile time switch VRS_HAS_WSTRING added 00079 // - renamed macros VRS_HAVE_* to VRS_HAS_* 00080 // - removed "typedef std::string String;" 00081 // - Font uses ImageTexture2D instead of ImageTexture2DGL 00082 // 00083 // Revision 1.21 2003/06/02 20:45:09 skirsch 00084 // fixed font serialization 00085 // 00086 // Revision 1.20 2002/11/18 13:36:34 skirsch 00087 // enhanced convinience of searchFont and related methods 00088 // 00089 // Revision 1.19 2002/11/12 07:37:20 skirsch 00090 // moved linkage pragma from h to cpp 00091 // 00092 // Revision 1.18 2002/11/08 13:24:11 skirsch 00093 // added system depended searchFont 00094 // 00095 // Revision 1.17 2002/10/29 23:57:24 skirsch 00096 // introduced unicode support 00097 // 00098 // Revision 1.16 2002/09/20 06:49:12 kirsch 00099 // made texture dictionary non persistent; minor changes in getGlyph 00100 // 00101 // Revision 1.15 2002/09/19 15:43:33 kirsch 00102 // use staticarray instead of dictionary for glyphs 00103 // 00104 // Revision 1.14 2002/08/06 10:32:38 baumann 00105 // added explicit casts for double to float or int conversions 00106 // 00107 // Revision 1.13 2002/07/29 10:37:40 baumann 00108 // static attribute removed 00109 // 00110 // Revision 1.12 2002/07/17 20:52:05 baumann 00111 // name of freetype libs changed 00112 // 00113 // Revision 1.11 2002/07/17 20:23:30 baumann 00114 // renamed fretype deubg lib 00115 // 00116 // Revision 1.10 2002/07/15 19:42:59 skirsch 00117 // changed the way of painting haloe with texture fonts 00118 // 00119 // Revision 1.9 2002/07/11 04:52:40 baumann 00120 // debug and non-debug version of freetype lib swapped 00121 // 00122 // Revision 1.8 2002/07/06 10:38:18 baumann 00123 // #ifdef corrected 00124 // 00125 // Revision 1.7 2002/07/05 18:05:36 skirsch 00126 // corrected the freetype libs 00127 // 00128 // Revision 1.6 2002/06/21 05:44:19 skirsch 00129 // fixed a bug with type casting 00130 // 00131 // Revision 1.5 2002/06/19 12:41:52 skirsch 00132 // fixed a bug with empty bitmaps 00133 // 00134 // Revision 1.4 2002/06/14 08:01:51 skirsch 00135 // added outline font support 00136 // 00137 // Revision 1.3 2002/06/12 10:33:43 skirsch 00138 // changed the way the haloe is painted when using polygon fonts 00139 // 00140 // Revision 1.2 2002/06/04 09:21:08 kersting 00141 // added cached geometry glyphs 00142 // 00143 // Revision 1.1 2002/06/04 08:43:39 skirsch 00144 // removed ftgl 00145 // 00146 // Revision 1.4 2002/04/10 13:00:13 skirsch 00147 // changes due to textsimplifier 00148 // 00149 // Revision 1.3 2002/03/26 15:18:19 kersting 00150 // added createFont method an made Ctor private 00151 // 00152 // Revision 1.2 2002/03/07 08:49:49 kosta 00153 // replaced "class VRS::String" by "typedef std::string String" 00154 // 00155 // Revision 1.1 2002/03/04 12:00:20 kersting 00156 // directory structure changes 00157 // 00158 // Revision 1.11 2002/03/03 21:44:25 kosta 00159 // VRS_TYPEINFO-macro rewritten 00160 // 00161 // Revision 1.10 2002/02/19 10:34:13 kosta 00162 // undone all changes since 2002-02-15 00163 // 00164 // Revision 1.7 2002/02/12 14:58:00 kosta 00165 // copyright and logging header added 00166 // 00167 00168 #ifndef VRS_FONT_H 00169 #define VRS_FONT_H 00170 00171 #include <vrs/text/vrs_textprerequisites.h> 00172 #include <vrs/sharedobj.h> 00173 #include <vrs/container/dictionary.h> 00174 #include <vrs/container/array.h> 00175 #include <vrs/container/staticarray.h> 00176 #include <vrs/cache.h> 00177 #include <vrs/image/memoryimage.h> 00178 #include <vrs/imagetexture2d.h> 00179 00180 namespace VRS { 00181 00182 //some necessary forward declarations to avoid header dependancies from the freetype includes 00183 typedef struct FT_GlyphSlotRec_* FT_GlyphSlot; 00184 typedef struct FT_Outline_ FT_Outline; 00185 typedef struct FT_FaceRec_* FT_Face; 00186 typedef struct FT_LibraryRec_* FT_Library; 00187 00193 class VRS_CORE_API Glyph : public SharedObj { 00194 00195 public: 00196 double getGlyphAdvance() const; 00197 virtual Bounds boundingBox() const = 0; 00198 00199 VRS_TYPEINFO(Glyph, SharedObj); 00200 00201 protected: 00202 void setGlyphAdvance(double adv); 00203 00204 private: 00205 double advance_; 00206 }; 00207 00209 class VRS_CORE_API ImageGlyph : public Glyph { 00210 00211 public: 00212 ImageGlyph(FT_GlyphSlot* slot, double resolution); 00214 00215 int width() const; 00217 00218 int height() const; 00220 00221 int pitch() const; 00223 00224 MemoryImage* getAlphaImage() const; 00226 00230 ImageTexture2D* getTexture() const; 00232 00233 ImageTexture2D* getHaloedTexture(double haloeSize) const; 00235 00239 unsigned char* getBitmapImage() const; 00241 00242 Vector getLowerLeftCorner() const; 00244 00248 virtual Bounds boundingBox() const; 00249 // Returns the width and height of the glyph in pixels as bounding box, so take care 00250 // in the text shape bounding box method! 00251 00252 VRS_TYPEINFO(ImageGlyph, Glyph); 00253 00254 private: 00255 SO<MemoryImage> alphaImage_; 00256 SO<ImageTexture2D> texture_; 00257 SO<NonPersistentDictionary<double, SO<ImageTexture2D> > > haloedTextures_; 00258 unsigned char* bitmapImage_; 00259 double resolution_; 00260 Vector llc_; 00261 int width_; 00262 int height_; 00263 int pitch_; 00264 }; 00265 00267 class VRS_CORE_API GeometryGlyph : public Glyph { 00268 00269 public: 00270 GeometryGlyph(FT_GlyphSlot* sourceGlyph, double resolution); 00272 00273 SO<Shape> getPolygons() const; 00275 00276 SO<Array<SO<Array<Vector> > > > getOutline() const; 00278 00279 virtual Bounds boundingBox() const; 00280 00281 VRS_TYPEINFO(GeometryGlyph, Glyph) 00282 00283 private: 00284 //functions for the internal decomposition of the freetype bezier outlines 00285 FT_Outline* ftOutline_; 00286 double bValues_[4][4][2];//3D array storing values of the de Casteljau algorithm. 00287 double controlPointArray_[4][2];//stores the control points for the bezier curve 00288 SO<Array<Vector> > points_; 00289 int conic(const int index, const int first, const int last); 00290 int cubic(const int index, const int first, const int last); 00291 void deCasteljau(const double t, const int n); 00292 void evaluateCurve(const int n); 00293 00294 SO<Shape> polygons_; 00295 SO<Array<SO<Array<Vector> > > > outline_; 00296 00297 Bounds bbox_; 00298 bool updateBBox_; 00299 }; 00300 00313 class VRS_CORE_API Font : public SharedObj { 00314 00315 public: 00316 enum FontType { BITMAP, PIXMAP, TEXTURE, OUTLINE, POLYGON, EXTRUDE }; 00317 VRS_SERIALIZABLE_CLASS_ENUM(FontType); 00319 00320 static Font* createFont(const std::string& fontFileName, Font::FontType fType, 00321 double resolution = 50.0, const std::string& fontName = ""); 00323 00325 static Font* searchFont(const std::string& fontName, Font::FontType fType, double resolution = 50.0); 00327 00329 static std::string getFontFileNameByFontName(const std::string& fontName); 00331 00333 static bool fontAvailable(const std::string& fontName); 00335 00336 static bool fontSupported(const std::string& fontName); 00338 00339 void setFontFileName(const std::string& newFileName); 00341 const std::string& getFontFileName() const; 00343 00344 const std::string& getFontName() const; 00346 00347 void setFontType(FontType newType); 00349 FontType getFontType() const; 00351 00352 void setResolution(double newResolution); 00354 00355 double getResolution() const; 00357 00358 Glyph* getGlyph(char ch) const { return getGlyph(static_cast<wchar_t>(static_cast<unsigned char>(ch))); } 00359 Glyph* getGlyph(wchar_t ch) const; 00361 00362 double getAdvance(wchar_t from, wchar_t to) const; 00364 00365 VRS_TYPEINFO(Font, SharedObj); 00366 VRS_SERIALIZABLE(Font); 00367 00368 private: 00369 00370 void invalidate(); 00371 // clears glyphs_ and ftFace_ 00372 00373 Font(const std::string& fontFileName, FontType fType, double resolution = 1.0, 00374 const std::string& fontName = ""); 00376 00377 Font(); // for persistency 00378 void loadFace(); 00379 static FT_Library* getFTLibrary(); 00380 00381 static std::vector<std::string> notSupportedFonts_; 00383 00384 std::string fileName_; 00385 int type_; 00386 double resolution_; 00387 std::string fontName_; 00388 SO<NonPersistentDictionary<wchar_t, SO<Glyph> > > glyphs_; 00389 FT_Face* ftFace_; 00390 }; 00391 00392 } // namespace VRS 00393 00394 #endif //_VRS_FONT_H