Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkFreeTypeUtilities.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkFreeTypeUtilities.h,v $
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 =========================================================================*/
00023 #ifndef __vtkFreeTypeUtilities_h
00024 #define __vtkFreeTypeUtilities_h
00025 
00026 #define VTK_FTFC_CACHE_CAPACITY 150
00027 
00028 #include "vtkObject.h"
00029 
00030 class vtkImageData;
00031 class vtkTextProperty;
00032 
00033 // FreeType
00034 
00035 #include "vtk_freetype.h"  //since ft2build.h could be in the path
00036 #include FT_FREETYPE_H
00037 #include FT_CACHE_H
00038 #include FT_CACHE_IMAGE_H
00039 #include FT_CACHE_CHARMAP_H
00040 
00041 // FTGL
00042 
00043 class FTFont;
00044 
00045 //----------------------------------------------------------------------------
00046 // Singleton cleanup
00047 
00048 class VTK_RENDERING_EXPORT vtkFreeTypeUtilitiesCleanup
00049 {
00050 public:
00051   vtkFreeTypeUtilitiesCleanup();
00052   ~vtkFreeTypeUtilitiesCleanup();
00053 };
00054 
00055 //----------------------------------------------------------------------------
00056 // Singleton font cache
00057 
00058 class VTK_RENDERING_EXPORT vtkFreeTypeUtilities : public vtkObject
00059 {
00060 public:
00061   vtkTypeRevisionMacro(vtkFreeTypeUtilities, vtkObject);
00062   void PrintSelf(ostream& os, vtkIndent indent);
00063 
00070   static vtkFreeTypeUtilities *New();
00071 
00073   static vtkFreeTypeUtilities* GetInstance();
00074 
00077   static void SetInstance(vtkFreeTypeUtilities *instance);
00078 
00080   FT_Library* GetLibrary();
00081 
00083 
00086   vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX);
00087   vtkGetMacro(MaximumNumberOfFaces, unsigned int);
00088   vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX);
00089   vtkGetMacro(MaximumNumberOfSizes, unsigned int);
00090   vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX);
00091   vtkGetMacro(MaximumNumberOfBytes, unsigned long);
00093 
00095 
00096   FTC_Manager* GetCacheManager();
00097   FTC_ImageCache* GetImageCache();
00098   FTC_CMapCache* GetCMapCache();
00100 
00105   int GetSize(vtkTextProperty *tprop, FT_Size *size);
00106 
00111   int GetFace(vtkTextProperty *tprop, FT_Face *face);
00112 
00115   int GetGlyphIndex(vtkTextProperty *tprop, char c, FT_UInt *gindex);
00116 
00118 
00128   enum 
00129   {
00130     GLYPH_REQUEST_DEFAULT = 0,
00131     GLYPH_REQUEST_BITMAP  = 1,
00132     GLYPH_REQUEST_OUTLINE = 2
00133   };
00134   //ETX
00135   int GetGlyph(vtkTextProperty *tprop, 
00136                char c, 
00137                FT_Glyph *glyph, 
00138                int request = GLYPH_REQUEST_DEFAULT);
00140 
00142 
00151   int GetBoundingBox(vtkTextProperty *tprop, const char *str, int bbox[4]);
00152   int IsBoundingBoxValid(int bbox[4]);
00154 
00156 
00161   int RenderString(vtkTextProperty *tprop, 
00162                    const char *str, 
00163                    int x, int y, 
00164                    vtkImageData *data);
00166 
00168 
00176   void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id);
00177   void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop);
00179 
00181 
00182   int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size);
00183   int GetFace(unsigned long tprop_cache_id, FT_Face *face);
00184   int GetGlyphIndex(unsigned long tprop_cache_id, char c, FT_UInt *gindex);
00185   int GetGlyph(unsigned long tprop_cache_id, 
00186                int font_size, 
00187                FT_UInt gindex, 
00188                FT_Glyph *glyph, 
00189                int request = GLYPH_REQUEST_DEFAULT);
00191 
00192   // Old Code
00193   // Cache entry
00194 
00195   struct Entry
00196   {
00197     vtkTextProperty *TextProperty;
00198     FTFont *Font;
00199     float LargestAscender;
00200     float LargestDescender;
00201   };
00202 
00203   vtkFreeTypeUtilities::Entry* GetFont(vtkTextProperty *tprop, 
00204                                        double override_color[3] = NULL);
00205 
00206 protected:
00207   vtkFreeTypeUtilities();
00208   virtual ~vtkFreeTypeUtilities();
00209 
00210 private:
00211   vtkFreeTypeUtilities(const vtkFreeTypeUtilities&);  // Not implemented.
00212   void operator=(const vtkFreeTypeUtilities&);  // Not implemented.
00213 
00214   // The singleton instance and the singleton cleanup instance
00215 
00216   static vtkFreeTypeUtilities* Instance;
00217   static vtkFreeTypeUtilitiesCleanup Cleanup;
00218 
00219   // The cache manager, image cache and charmap cache
00220 
00221   FTC_Manager *CacheManager;
00222   FTC_ImageCache *ImageCache;
00223   FTC_CMapCache  *CMapCache;
00224 
00225   unsigned int MaximumNumberOfFaces;
00226   unsigned int MaximumNumberOfSizes;
00227   unsigned long MaximumNumberOfBytes;
00228 
00229   void InitializeCacheManager();
00230   void ReleaseCacheManager();
00231 
00232   // Old Code
00233 
00234   void PrintEntry(int i, char *msg = 0);
00235   void ReleaseEntry(int i);
00236 
00237   void InitializeCache();
00238   void ReleaseCache();
00239 
00240   Entry *Entries[VTK_FTFC_CACHE_CAPACITY];
00241   int NumberOfEntries;
00242 };
00243 
00244 #endif

Generated on Mon Jan 21 23:07:34 2008 for VTK by  doxygen 1.4.3-20050530