VTK
vtkFreeTypeUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFreeTypeUtilities.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef vtkFreeTypeUtilities_h
29 #define vtkFreeTypeUtilities_h
30 
31 #define VTK_FTFC_CACHE_CAPACITY 150
32 
33 #include "vtkRenderingFreeTypeModule.h" // For export macro
34 #include "vtkObject.h"
35 
36 class vtkImageData;
37 class vtkTextProperty;
38 class vtkTextActor;
39 class vtkViewport;
40 
41 // FreeType
42 
43 #include <FTGL.h>
44 
45 #include "vtk_freetype.h" //since ft2build.h could be in the path
46 #include FT_FREETYPE_H
47 #include FT_GLYPH_H
48 
49 #if (FREETYPE_MAJOR >2 ||(FREETYPE_MAJOR == 2 && ( FREETYPE_MINOR > 1 || (FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 9))))
50 # include FT_CACHE_H
51 // This flag will be used to check if Caching support is to be compiled.
52 # define VTK_FREETYPE_CACHING_SUPPORTED
53 #endif
54 
55 #ifdef FTGL_USE_NAMESPACE
56 namespace ftgl
57 {
58 #endif
59 class FTFont;
60 #ifdef FTGL_USE_NAMESPACE
61 }
62 #endif
63 
64 //----------------------------------------------------------------------------
65 // Singleton cleanup
66 
68 {
69 public:
72 };
73 
74 //----------------------------------------------------------------------------
75 // Singleton font cache
76 
78 {
79 public:
81  void PrintSelf(ostream& os, vtkIndent indent);
82 
89  static vtkFreeTypeUtilities *New();
90 
92  static vtkFreeTypeUtilities* GetInstance();
93 
96  static void SetInstance(vtkFreeTypeUtilities *instance);
97 
99  FT_Library* GetLibrary();
100 
102 
105  vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX);
106  vtkGetMacro(MaximumNumberOfFaces, unsigned int);
107  vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX);
108  vtkGetMacro(MaximumNumberOfSizes, unsigned int);
109  vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX);
110  vtkGetMacro(MaximumNumberOfBytes, unsigned long);
112 
118  int GetSize(vtkTextProperty *tprop, FT_Size *size);
119 
125  int GetFace(vtkTextProperty *tprop, FT_Face *face);
126 
130  int GetGlyphIndex(vtkTextProperty *tprop, FT_UInt32 c, FT_UInt *gindex);
131 
132  //BTX
134 
145  enum
146  {
147  GLYPH_REQUEST_DEFAULT = 0,
148  GLYPH_REQUEST_BITMAP = 1,
149  GLYPH_REQUEST_OUTLINE = 2
150  };
151  //ETX
152  int GetGlyph(vtkTextProperty *tprop,
153  FT_UInt32 c,
154  FT_Glyph *glyph,
155  int request = GLYPH_REQUEST_DEFAULT);
157 
159 
168  int GetBoundingBox(vtkTextProperty *tprop, const char *str, int bbox[4]);
169  int IsBoundingBoxValid(int bbox[4]);
171 
173 
175  int RenderString(vtkTextProperty *tprop,
176  const char *str,
177  vtkImageData *data);
179 
181 
189  void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id);
190  void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop);
192 
194 
196  int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size);
197  int GetFace(unsigned long tprop_cache_id, FT_Face *face);
198  int GetGlyphIndex(unsigned long tprop_cache_id, FT_UInt32 c,
199  FT_UInt *gindex);
200  int GetGlyph(unsigned long tprop_cache_id,
201  int font_size,
202  FT_UInt gindex,
203  FT_Glyph *glyph,
204  int request = GLYPH_REQUEST_DEFAULT);
206 
208 
213  void GetWidthHeightDescender(const char *str,
214  vtkTextProperty *tprop,
215  int *width,
216  int *height,
217  float *descender);
219 
221 
223  void PrepareImageData(vtkImageData *data,
224  vtkTextProperty *tprop,
225  const char *str,
226  int *x, int *y);
228 
230 
232  int GetConstrainedFontSize(const char *str, vtkTextProperty *tprop,
233  double orientation, int targetWidth,
234  int targetHeight);
236 
238 
239  void JustifyLine(const char *str, vtkTextProperty *tprop,
240  int totalWidth, int *x, int *y);
242 
243  // Old Code
244  // Cache entry
245 
246  struct Entry
247  {
249 #ifdef FTGL_USE_NAMESPACE
250  ftgl::FTFont *Font;
251 #else
252  FTFont *Font;
253 #endif
256  };
257 
259  double override_color[3] = NULL);
260 
261 protected:
262  //Internal helper method called by RenderString
263  int PopulateImageData(vtkTextProperty *tprop, const char *str,
264  int x, int y, vtkImageData *data, int use_shadow_color);
266  virtual ~vtkFreeTypeUtilities();
267 
268 private:
269  vtkFreeTypeUtilities(const vtkFreeTypeUtilities&); // Not implemented.
270  void operator=(const vtkFreeTypeUtilities&); // Not implemented.
271 
272  // The singleton instance and the singleton cleanup instance
273 
274  static vtkFreeTypeUtilities* Instance;
275  static vtkFreeTypeUtilitiesCleanup Cleanup;
276 
277  // The cache manager, image cache and charmap cache
278 
279 #ifdef VTK_FREETYPE_CACHING_SUPPORTED
280  FTC_Manager *CacheManager;
281  FTC_ImageCache *ImageCache;
282  FTC_CMapCache *CMapCache;
283 
285 
286  FTC_Manager* GetCacheManager();
287  FTC_ImageCache* GetImageCache();
288  FTC_CMapCache* GetCMapCache();
289 #endif
290 
291 
292  unsigned int MaximumNumberOfFaces;
293  unsigned int MaximumNumberOfSizes;
294  unsigned long MaximumNumberOfBytes;
295 
296  void InitializeCacheManager();
297  void ReleaseCacheManager();
298 
299  // Old Code
300 
301  void PrintEntry(int i, char *msg = 0);
302  void ReleaseEntry(int i);
303 
304  void InitializeCache();
305  void ReleaseCache();
306 
307  Entry *Entries[VTK_FTFC_CACHE_CAPACITY];
308  int NumberOfEntries;
309 };
310 
311 #endif
312 // VTK-HeaderTest-Exclude: vtkFreeTypeUtilities.h
abstract base class for most VTK objects
Definition: vtkObject.h:61
abstract specification for Viewports
Definition: vtkViewport.h:46
#define VTK_UNSIGNED_LONG_MAX
Definition: vtkType.h:138
#define VTKRENDERINGFREETYPE_EXPORT
An actor that displays text. Scaled or unscaled.
Definition: vtkTextActor.h:54
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
#define VTK_FTFC_CACHE_CAPACITY
#define VTK_UNSIGNED_INT_MAX
Definition: vtkType.h:134
represent text properties.
FreeType library support.
static vtkObject * New()