00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00033 #ifndef __vtkFreeTypeUtilities_h
00034 #define __vtkFreeTypeUtilities_h
00035
00036 #define VTK_FTFC_CACHE_CAPACITY 150
00037
00038 #include "vtkObject.h"
00039
00040 class vtkImageData;
00041 class vtkTextProperty;
00042
00043
00044
00045 #include "ft2build.h"
00046 #include FT_FREETYPE_H
00047 #include FT_CACHE_H
00048 #include FT_CACHE_IMAGE_H
00049 #include FT_CACHE_CHARMAP_H
00050
00051
00052
00053 class FTFont;
00054
00055
00056
00057
00058 class VTK_RENDERING_EXPORT vtkFreeTypeUtilitiesCleanup
00059 {
00060 public:
00061 vtkFreeTypeUtilitiesCleanup();
00062 ~vtkFreeTypeUtilitiesCleanup();
00063 };
00064
00065
00066
00067
00068 class VTK_RENDERING_EXPORT vtkFreeTypeUtilities : public vtkObject
00069 {
00070 public:
00071 vtkTypeRevisionMacro(vtkFreeTypeUtilities, vtkObject);
00072 void PrintSelf(ostream& os, vtkIndent indent);
00073
00080 static vtkFreeTypeUtilities *New();
00081
00083 static vtkFreeTypeUtilities* GetInstance();
00084
00087 static void SetInstance(vtkFreeTypeUtilities *instance);
00088
00090 FT_Library* GetLibrary();
00091
00093
00096 vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX);
00097 vtkGetMacro(MaximumNumberOfFaces, unsigned int);
00098 vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX);
00099 vtkGetMacro(MaximumNumberOfSizes, unsigned int);
00100 vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX);
00101 vtkGetMacro(MaximumNumberOfBytes, unsigned long);
00103
00105
00106 FTC_Manager* GetCacheManager();
00107 FTC_ImageCache* GetImageCache();
00108 FTC_CMapCache* GetCMapCache();
00110
00115 int GetSize(vtkTextProperty *tprop, FT_Size *size);
00116
00121 int GetFace(vtkTextProperty *tprop, FT_Face *face);
00122
00125 int GetGlyphIndex(vtkTextProperty *tprop, char c, FT_UInt *gindex);
00126
00128
00138 enum
00139 {
00140 GLYPH_REQUEST_DEFAULT = 0,
00141 GLYPH_REQUEST_BITMAP = 1,
00142 GLYPH_REQUEST_OUTLINE = 2
00143 };
00144
00145 int GetGlyph(vtkTextProperty *tprop,
00146 char c,
00147 FT_Glyph *glyph,
00148 int request = GLYPH_REQUEST_DEFAULT);
00150
00152
00161 int GetBoundingBox(vtkTextProperty *tprop, const char *str, int bbox[4]);
00162 int IsBoundingBoxValid(int bbox[4]);
00164
00166
00171 int RenderString(vtkTextProperty *tprop,
00172 const char *str,
00173 int x, int y,
00174 vtkImageData *data);
00176
00178
00186 void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id);
00187 void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop);
00189
00191
00192 int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size);
00193 int GetFace(unsigned long tprop_cache_id, FT_Face *face);
00194 int GetGlyphIndex(unsigned long tprop_cache_id, char c, FT_UInt *gindex);
00195 int GetGlyph(unsigned long tprop_cache_id,
00196 int font_size,
00197 FT_UInt gindex,
00198 FT_Glyph *glyph,
00199 int request = GLYPH_REQUEST_DEFAULT);
00201
00202
00203
00204
00205 struct Entry
00206 {
00207 vtkTextProperty *TextProperty;
00208 FTFont *Font;
00209 float LargestAscender;
00210 float LargestDescender;
00211 };
00212
00213 vtkFreeTypeUtilities::Entry* GetFont(vtkTextProperty *tprop,
00214 double override_color[3] = NULL);
00215
00216 protected:
00217 vtkFreeTypeUtilities();
00218 virtual ~vtkFreeTypeUtilities();
00219
00220 private:
00221 vtkFreeTypeUtilities(const vtkFreeTypeUtilities&);
00222 void operator=(const vtkFreeTypeUtilities&);
00223
00224
00225
00226 static vtkFreeTypeUtilities* Instance;
00227 static vtkFreeTypeUtilitiesCleanup Cleanup;
00228
00229
00230
00231 FTC_Manager *CacheManager;
00232 FTC_ImageCache *ImageCache;
00233 FTC_CMapCache *CMapCache;
00234
00235 unsigned int MaximumNumberOfFaces;
00236 unsigned int MaximumNumberOfSizes;
00237 unsigned long MaximumNumberOfBytes;
00238
00239 void InitializeCacheManager();
00240 void ReleaseCacheManager();
00241
00242
00243
00244 void PrintEntry(int i, char *msg = 0);
00245 void ReleaseEntry(int i);
00246
00247 void InitializeCache();
00248 void ReleaseCache();
00249
00250 Entry *Entries[VTK_FTFC_CACHE_CAPACITY];
00251 int NumberOfEntries;
00252 };
00253
00254 #endif