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 =========================================================================*/ 00028 #ifndef __vtkFreeTypeUtilities_h 00029 #define __vtkFreeTypeUtilities_h 00030 00031 #define VTK_FTFC_CACHE_CAPACITY 150 00032 00033 #include "vtkRenderingFreeTypeModule.h" // For export macro 00034 #include "vtkObject.h" 00035 00036 class vtkImageData; 00037 class vtkTextProperty; 00038 class vtkTextActor; 00039 class vtkViewport; 00040 00041 // FreeType 00042 00043 #include <FTGL.h> 00044 00045 #include "vtk_freetype.h" //since ft2build.h could be in the path 00046 #include FT_FREETYPE_H 00047 #include FT_GLYPH_H 00048 00049 #if (FREETYPE_MAJOR >2 ||(FREETYPE_MAJOR == 2 && ( FREETYPE_MINOR > 1 || (FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 9)))) 00050 # include FT_CACHE_H 00051 // This flag will be used to check if Caching support is to be compiled. 00052 # define VTK_FREETYPE_CACHING_SUPPORTED 00053 #endif 00054 00055 #ifdef FTGL_USE_NAMESPACE 00056 namespace ftgl 00057 { 00058 #endif 00059 class FTFont; 00060 #ifdef FTGL_USE_NAMESPACE 00061 } 00062 #endif 00063 00064 //---------------------------------------------------------------------------- 00065 // Singleton cleanup 00066 00067 class VTKRENDERINGFREETYPE_EXPORT vtkFreeTypeUtilitiesCleanup 00068 { 00069 public: 00070 vtkFreeTypeUtilitiesCleanup(); 00071 ~vtkFreeTypeUtilitiesCleanup(); 00072 }; 00073 00074 //---------------------------------------------------------------------------- 00075 // Singleton font cache 00076 00077 class VTKRENDERINGFREETYPE_EXPORT vtkFreeTypeUtilities : public vtkObject 00078 { 00079 public: 00080 vtkTypeMacro(vtkFreeTypeUtilities, vtkObject); 00081 void PrintSelf(ostream& os, vtkIndent indent); 00082 00089 static vtkFreeTypeUtilities *New(); 00090 00092 static vtkFreeTypeUtilities* GetInstance(); 00093 00096 static void SetInstance(vtkFreeTypeUtilities *instance); 00097 00099 FT_Library* GetLibrary(); 00100 00102 00105 vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX); 00106 vtkGetMacro(MaximumNumberOfFaces, unsigned int); 00107 vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX); 00108 vtkGetMacro(MaximumNumberOfSizes, unsigned int); 00109 vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX); 00110 vtkGetMacro(MaximumNumberOfBytes, unsigned long); 00112 00118 int GetSize(vtkTextProperty *tprop, FT_Size *size); 00119 00125 int GetFace(vtkTextProperty *tprop, FT_Face *face); 00126 00130 int GetGlyphIndex(vtkTextProperty *tprop, FT_UInt32 c, FT_UInt *gindex); 00131 00132 //BTX 00134 00145 enum 00146 { 00147 GLYPH_REQUEST_DEFAULT = 0, 00148 GLYPH_REQUEST_BITMAP = 1, 00149 GLYPH_REQUEST_OUTLINE = 2 00150 }; 00151 //ETX 00152 int GetGlyph(vtkTextProperty *tprop, 00153 FT_UInt32 c, 00154 FT_Glyph *glyph, 00155 int request = GLYPH_REQUEST_DEFAULT); 00157 00159 00168 int GetBoundingBox(vtkTextProperty *tprop, const char *str, int bbox[4]); 00169 int IsBoundingBoxValid(int bbox[4]); 00171 00173 00175 int RenderString(vtkTextProperty *tprop, 00176 const char *str, 00177 vtkImageData *data); 00179 00181 00182 VTK_LEGACY(int RenderString(vtkTextProperty *tprop, 00183 const char *str, 00184 int x, int y, 00185 vtkImageData *data)); 00187 00189 00197 void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id); 00198 void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop); 00200 00202 00204 int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size); 00205 int GetFace(unsigned long tprop_cache_id, FT_Face *face); 00206 int GetGlyphIndex(unsigned long tprop_cache_id, FT_UInt32 c, 00207 FT_UInt *gindex); 00208 int GetGlyph(unsigned long tprop_cache_id, 00209 int font_size, 00210 FT_UInt gindex, 00211 FT_Glyph *glyph, 00212 int request = GLYPH_REQUEST_DEFAULT); 00214 00216 00221 void GetWidthHeightDescender(const char *str, 00222 vtkTextProperty *tprop, 00223 int *width, 00224 int *height, 00225 float *descender); 00227 00229 00231 void PrepareImageData(vtkImageData *data, 00232 vtkTextProperty *tprop, 00233 const char *str, 00234 int *x, int *y); 00236 00238 00240 int GetConstrainedFontSize(const char *str, vtkTextProperty *tprop, 00241 double orientation, int targetWidth, 00242 int targetHeight); 00244 00246 00247 void JustifyLine(const char *str, vtkTextProperty *tprop, 00248 int totalWidth, int *x, int *y); 00250 00251 // Old Code 00252 // Cache entry 00253 00254 struct Entry 00255 { 00256 vtkTextProperty *TextProperty; 00257 #ifdef FTGL_USE_NAMESPACE 00258 ftgl::FTFont *Font; 00259 #else 00260 FTFont *Font; 00261 #endif 00262 float LargestAscender; 00263 float LargestDescender; 00264 }; 00265 00266 vtkFreeTypeUtilities::Entry* GetFont(vtkTextProperty *tprop, 00267 double override_color[3] = NULL); 00268 00269 protected: 00270 //Internal helper method called by RenderString 00271 int PopulateImageData(vtkTextProperty *tprop, const char *str, 00272 int x, int y, vtkImageData *data, int use_shadow_color); 00273 vtkFreeTypeUtilities(); 00274 virtual ~vtkFreeTypeUtilities(); 00275 00276 private: 00277 vtkFreeTypeUtilities(const vtkFreeTypeUtilities&); // Not implemented. 00278 void operator=(const vtkFreeTypeUtilities&); // Not implemented. 00279 00280 // The singleton instance and the singleton cleanup instance 00281 00282 static vtkFreeTypeUtilities* Instance; 00283 static vtkFreeTypeUtilitiesCleanup Cleanup; 00284 00285 // The cache manager, image cache and charmap cache 00286 00287 #ifdef VTK_FREETYPE_CACHING_SUPPORTED 00288 FTC_Manager *CacheManager; 00289 FTC_ImageCache *ImageCache; 00290 FTC_CMapCache *CMapCache; 00291 00293 00294 FTC_Manager* GetCacheManager(); 00295 FTC_ImageCache* GetImageCache(); 00296 FTC_CMapCache* GetCMapCache(); 00297 #endif 00298 00299 00300 unsigned int MaximumNumberOfFaces; 00301 unsigned int MaximumNumberOfSizes; 00302 unsigned long MaximumNumberOfBytes; 00303 00304 void InitializeCacheManager(); 00305 void ReleaseCacheManager(); 00306 00307 // Old Code 00308 00309 void PrintEntry(int i, char *msg = 0); 00310 void ReleaseEntry(int i); 00311 00312 void InitializeCache(); 00313 void ReleaseCache(); 00314 00315 Entry *Entries[VTK_FTFC_CACHE_CAPACITY]; 00316 int NumberOfEntries; 00317 }; 00318 00319 #endif 00320 // VTK-HeaderTest-Exclude: vtkFreeTypeUtilities.h