VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkFreeTypeUtilities.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00025 #ifndef __vtkFreeTypeUtilities_h 00026 #define __vtkFreeTypeUtilities_h 00027 00028 #define VTK_FTFC_CACHE_CAPACITY 150 00029 00030 #include "vtkObject.h" 00031 00032 class vtkImageData; 00033 class vtkTextProperty; 00034 00035 // FreeType 00036 00037 #include "vtk_freetype.h" //since ft2build.h could be in the path 00038 #include FT_FREETYPE_H 00039 #include FT_GLYPH_H 00040 00041 #if (FREETYPE_MAJOR >2 ||(FREETYPE_MAJOR == 2 && ( FREETYPE_MINOR > 1 || (FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 9)))) 00042 # include FT_CACHE_H 00043 // This flag will be used to check if Caching support is to be compiled. 00044 # define VTK_FREETYPE_CACHING_SUPPORTED 00045 #endif 00046 00047 class FTFont; 00048 00049 //---------------------------------------------------------------------------- 00050 // Singleton cleanup 00051 00052 class VTK_RENDERING_EXPORT vtkFreeTypeUtilitiesCleanup 00053 { 00054 public: 00055 vtkFreeTypeUtilitiesCleanup(); 00056 ~vtkFreeTypeUtilitiesCleanup(); 00057 }; 00058 00059 //---------------------------------------------------------------------------- 00060 // Singleton font cache 00061 00062 class VTK_RENDERING_EXPORT vtkFreeTypeUtilities : public vtkObject 00063 { 00064 public: 00065 vtkTypeMacro(vtkFreeTypeUtilities, vtkObject); 00066 void PrintSelf(ostream& os, vtkIndent indent); 00067 00074 static vtkFreeTypeUtilities *New(); 00075 00077 static vtkFreeTypeUtilities* GetInstance(); 00078 00081 static void SetInstance(vtkFreeTypeUtilities *instance); 00082 00084 FT_Library* GetLibrary(); 00085 00087 00090 vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX); 00091 vtkGetMacro(MaximumNumberOfFaces, unsigned int); 00092 vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX); 00093 vtkGetMacro(MaximumNumberOfSizes, unsigned int); 00094 vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX); 00095 vtkGetMacro(MaximumNumberOfBytes, unsigned long); 00097 00098 00099 00105 int GetSize(vtkTextProperty *tprop, FT_Size *size); 00106 00112 int GetFace(vtkTextProperty *tprop, FT_Face *face); 00113 00117 int GetGlyphIndex(vtkTextProperty *tprop, char c, FT_UInt *gindex); 00118 00120 00131 enum 00132 { 00133 GLYPH_REQUEST_DEFAULT = 0, 00134 GLYPH_REQUEST_BITMAP = 1, 00135 GLYPH_REQUEST_OUTLINE = 2 00136 }; 00137 //ETX 00138 int GetGlyph(vtkTextProperty *tprop, 00139 char c, 00140 FT_Glyph *glyph, 00141 int request = GLYPH_REQUEST_DEFAULT); 00143 00145 00154 int GetBoundingBox(vtkTextProperty *tprop, const char *str, int bbox[4]); 00155 int IsBoundingBoxValid(int bbox[4]); 00157 00159 00161 int RenderString(vtkTextProperty *tprop, 00162 const char *str, 00163 vtkImageData *data); 00165 00167 00168 int RenderString(vtkTextProperty *tprop, 00169 const char *str, 00170 int x, int y, 00171 vtkImageData *data); 00173 00175 00183 void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id); 00184 void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop); 00186 00188 00190 int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size); 00191 int GetFace(unsigned long tprop_cache_id, FT_Face *face); 00192 int GetGlyphIndex(unsigned long tprop_cache_id, char c, FT_UInt *gindex); 00193 int GetGlyph(unsigned long tprop_cache_id, 00194 int font_size, 00195 FT_UInt gindex, 00196 FT_Glyph *glyph, 00197 int request = GLYPH_REQUEST_DEFAULT); 00199 00201 00206 void GetWidthHeightDescender(const char *str, 00207 vtkTextProperty *tprop, 00208 int *width, 00209 int *height, 00210 float *descender); 00212 00214 00216 void PrepareImageData(vtkImageData *data, 00217 vtkTextProperty *tprop, 00218 const char *str, 00219 int *x, int *y); 00221 00223 00225 int GetConstrainedFontSize(const char *str, vtkTextProperty *tprop, 00226 double orientation, int targetWidth, 00227 int targetHeight); 00229 00231 00232 void JustifyLine(const char *str, vtkTextProperty *tprop, 00233 int totalWidth, int *x, int *y); 00235 00236 // Old Code 00237 // Cache entry 00238 00239 struct Entry 00240 { 00241 vtkTextProperty *TextProperty; 00242 FTFont *Font; 00243 float LargestAscender; 00244 float LargestDescender; 00245 }; 00246 00247 vtkFreeTypeUtilities::Entry* GetFont(vtkTextProperty *tprop, 00248 double override_color[3] = NULL); 00249 00250 protected: 00251 //Internal helper method called by RenderString 00252 int PopulateImageData(vtkTextProperty *tprop, const char *str, 00253 int x, int y, vtkImageData *data, int use_shadow_color); 00254 vtkFreeTypeUtilities(); 00255 virtual ~vtkFreeTypeUtilities(); 00256 00257 private: 00258 vtkFreeTypeUtilities(const vtkFreeTypeUtilities&); // Not implemented. 00259 void operator=(const vtkFreeTypeUtilities&); // Not implemented. 00260 00261 // The singleton instance and the singleton cleanup instance 00262 00263 static vtkFreeTypeUtilities* Instance; 00264 static vtkFreeTypeUtilitiesCleanup Cleanup; 00265 00266 // The cache manager, image cache and charmap cache 00267 00268 #ifdef VTK_FREETYPE_CACHING_SUPPORTED 00269 FTC_Manager *CacheManager; 00270 FTC_ImageCache *ImageCache; 00271 FTC_CMapCache *CMapCache; 00272 00274 00275 FTC_Manager* GetCacheManager(); 00276 FTC_ImageCache* GetImageCache(); 00277 FTC_CMapCache* GetCMapCache(); 00279 #endif 00280 00281 unsigned int MaximumNumberOfFaces; 00282 unsigned int MaximumNumberOfSizes; 00283 unsigned long MaximumNumberOfBytes; 00284 00285 void InitializeCacheManager(); 00286 void ReleaseCacheManager(); 00287 00288 // Old Code 00289 00290 void PrintEntry(int i, char *msg = 0); 00291 void ReleaseEntry(int i); 00292 00293 void InitializeCache(); 00294 void ReleaseCache(); 00295 00296 Entry *Entries[VTK_FTFC_CACHE_CAPACITY]; 00297 int NumberOfEntries; 00298 }; 00299 00300 #endif