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 
182  VTK_LEGACY(int RenderString(vtkTextProperty *tprop,
183  const char *str,
184  int x, int y,
185  vtkImageData *data));
187 
189 
197  void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id);
198  void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop);
200 
202 
204  int GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size);
205  int GetFace(unsigned long tprop_cache_id, FT_Face *face);
206  int GetGlyphIndex(unsigned long tprop_cache_id, FT_UInt32 c,
207  FT_UInt *gindex);
208  int GetGlyph(unsigned long tprop_cache_id,
209  int font_size,
210  FT_UInt gindex,
211  FT_Glyph *glyph,
212  int request = GLYPH_REQUEST_DEFAULT);
214 
216 
221  void GetWidthHeightDescender(const char *str,
222  vtkTextProperty *tprop,
223  int *width,
224  int *height,
225  float *descender);
227 
229 
231  void PrepareImageData(vtkImageData *data,
232  vtkTextProperty *tprop,
233  const char *str,
234  int *x, int *y);
236 
238 
240  int GetConstrainedFontSize(const char *str, vtkTextProperty *tprop,
241  double orientation, int targetWidth,
242  int targetHeight);
244 
246 
247  void JustifyLine(const char *str, vtkTextProperty *tprop,
248  int totalWidth, int *x, int *y);
250 
251  // Old Code
252  // Cache entry
253 
254  struct Entry
255  {
257 #ifdef FTGL_USE_NAMESPACE
258  ftgl::FTFont *Font;
259 #else
260  FTFont *Font;
261 #endif
264  };
265 
267  double override_color[3] = NULL);
268 
269 protected:
270  //Internal helper method called by RenderString
271  int PopulateImageData(vtkTextProperty *tprop, const char *str,
272  int x, int y, vtkImageData *data, int use_shadow_color);
274  virtual ~vtkFreeTypeUtilities();
275 
276 private:
277  vtkFreeTypeUtilities(const vtkFreeTypeUtilities&); // Not implemented.
278  void operator=(const vtkFreeTypeUtilities&); // Not implemented.
279 
280  // The singleton instance and the singleton cleanup instance
281 
282  static vtkFreeTypeUtilities* Instance;
283  static vtkFreeTypeUtilitiesCleanup Cleanup;
284 
285  // The cache manager, image cache and charmap cache
286 
287 #ifdef VTK_FREETYPE_CACHING_SUPPORTED
288  FTC_Manager *CacheManager;
289  FTC_ImageCache *ImageCache;
290  FTC_CMapCache *CMapCache;
291 
293 
294  FTC_Manager* GetCacheManager();
295  FTC_ImageCache* GetImageCache();
296  FTC_CMapCache* GetCMapCache();
297 #endif
298 
299 
300  unsigned int MaximumNumberOfFaces;
301  unsigned int MaximumNumberOfSizes;
302  unsigned long MaximumNumberOfBytes;
303 
304  void InitializeCacheManager();
305  void ReleaseCacheManager();
306 
307  // Old Code
308 
309  void PrintEntry(int i, char *msg = 0);
310  void ReleaseEntry(int i);
311 
312  void InitializeCache();
313  void ReleaseCache();
314 
315  Entry *Entries[VTK_FTFC_CACHE_CAPACITY];
316  int NumberOfEntries;
317 };
318 
319 #endif
320 // VTK-HeaderTest-Exclude: vtkFreeTypeUtilities.h
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
GLsizeiptr size
Definition: vtkgl.h:11843
abstract base class for most VTK objects
Definition: vtkObject.h:61
abstract specification for Viewports
Definition: vtkViewport.h:46
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
#define VTK_UNSIGNED_LONG_MAX
Definition: vtkType.h:137
#define vtkSetClampMacro(name, type, min, max)
Definition: vtkSetGet.h:133
#define VTKRENDERINGFREETYPE_EXPORT
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
An actor that displays text. Scaled or unscaled.
Definition: vtkTextActor.h:55
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
const GLubyte * c
Definition: vtkgl.h:15720
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
#define VTK_FTFC_CACHE_CAPACITY
GLint GLint GLsizei width
Definition: vtkgl.h:11316
#define VTK_UNSIGNED_INT_MAX
Definition: vtkType.h:133
represent text properties.
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:787
FreeType library support.
static vtkObject * New()
GLenum GLuint GLint GLenum face
Definition: vtkgl.h:13568