VTK
vtkFreeTypeTools.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFreeTypeTools.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 =========================================================================*/
25 #ifndef __vtkFreeTypeTools_h
26 #define __vtkFreeTypeTools_h
27 
28 #include "vtkObject.h"
29 
30 class vtkImageData;
31 class vtkTextProperty;
32 class vtkStdString;
33 class vtkUnicodeString;
34 
35 // FreeType
36 #include "vtk_freetype.h" //since ft2build.h could be in the path
37 #include FT_FREETYPE_H
38 #include FT_GLYPH_H
39 #include FT_CACHE_H
40 
41 class FTFont;
42 
43 //----------------------------------------------------------------------------
44 // Singleton cleanup
46 {
47 public:
50 };
51 
52 //----------------------------------------------------------------------------
53 // Singleton font cache
55 {
56 public:
57  vtkTypeMacro(vtkFreeTypeTools, vtkObject);
58  void PrintSelf(ostream& os, vtkIndent indent);
59 
61  static vtkFreeTypeTools* GetInstance();
62 
65  static void SetInstance(vtkFreeTypeTools *instance);
66 
68  FT_Library* GetLibrary();
69 
71 
74  vtkSetClampMacro(MaximumNumberOfFaces,unsigned int,1,VTK_UNSIGNED_INT_MAX);
75  vtkGetMacro(MaximumNumberOfFaces, unsigned int);
76  vtkSetClampMacro(MaximumNumberOfSizes,unsigned int,1,VTK_UNSIGNED_INT_MAX);
77  vtkGetMacro(MaximumNumberOfSizes, unsigned int);
78  vtkSetClampMacro(MaximumNumberOfBytes,unsigned long,1,VTK_UNSIGNED_LONG_MAX);
79  vtkGetMacro(MaximumNumberOfBytes, unsigned long);
81 
83 
92  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString& str,
93  int bbox[4]);
94  bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString& str,
95  int bbox[4]);
96  bool IsBoundingBoxValid(int bbox[4]);
98 
100 
102  bool RenderString(vtkTextProperty *tprop, const vtkStdString& str,
103  vtkImageData *data);
104  bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString& str,
105  vtkImageData *data);
107 
109 
117  void MapTextPropertyToId(vtkTextProperty *tprop, unsigned long *tprop_cache_id);
118  void MapIdToTextProperty(unsigned long tprop_cache_id, vtkTextProperty *tprop);
120 
122 
126  vtkSetMacro(ScaleToPowerTwo, bool);
127  vtkGetMacro(ScaleToPowerTwo, bool);
128  vtkBooleanMacro(ScaleToPowerTwo, bool);
130 
131 protected:
133 
135  template <typename T>
136  bool CalculateBoundingBox(vtkTextProperty *tprop, const T& str, int bbox[4]);
138 
140 
142  template <typename T>
143  void PrepareImageData(vtkImageData *data,
144  vtkTextProperty *tprop,
145  const T& str,
146  int *x, int *y);
148 
150 
151  template <typename T>
152  bool PopulateImageData(vtkTextProperty *tprop, const T& str,
153  int x, int y, vtkImageData *data);
155 
160  bool GetSize(vtkTextProperty *tprop, FT_Size *size);
161 
166  bool GetFace(vtkTextProperty *tprop, FT_Face *face);
167 
170  bool GetGlyphIndex(vtkTextProperty *tprop, FT_UInt32 c, FT_UInt *gindex);
171 
173 
183  enum
184  {
185  GLYPH_REQUEST_DEFAULT = 0,
186  GLYPH_REQUEST_BITMAP = 1,
187  GLYPH_REQUEST_OUTLINE = 2
188  };
189  bool GetGlyph(vtkTextProperty *tprop,
190  FT_UInt32 c,
191  FT_Glyph *glyph,
192  int request = GLYPH_REQUEST_DEFAULT);
193  bool GetSize(unsigned long tprop_cache_id, int font_size, FT_Size *size);
194  bool GetFace(unsigned long tprop_cache_id, FT_Face *face);
195  bool GetGlyphIndex(unsigned long tprop_cache_id, FT_UInt32 c,
196  FT_UInt *gindex);
197  bool GetGlyph(unsigned long tprop_cache_id,
198  int font_size,
199  FT_UInt gindex,
200  FT_Glyph *glyph,
201  int request = GLYPH_REQUEST_DEFAULT);
203 
206 
208  virtual ~vtkFreeTypeTools();
209 
210 private:
211  vtkFreeTypeTools(const vtkFreeTypeTools&); // Not implemented.
212  void operator=(const vtkFreeTypeTools&); // Not implemented.
213 
215 
216  bool GetFace(vtkTextProperty *prop, unsigned long &prop_cache_id,
217  FT_Face &face, bool &face_has_kerning);
219 
221 
222  FT_Bitmap* GetBitmap(FT_UInt32 c, unsigned long prop_cache_id,
223  int prop_font_size, FT_UInt &gindex,
224  FT_BitmapGlyph &bitmap_glyph);
226 
227  // The singleton instance and the singleton cleanup instance
228  static vtkFreeTypeTools* Instance;
229  static vtkFreeTypeToolsCleanup Cleanup;
230 
231  // The cache manager, image cache and charmap cache
232  FTC_Manager *CacheManager;
233  FTC_ImageCache *ImageCache;
234  FTC_CMapCache *CMapCache;
235 
237 
238  FTC_Manager* GetCacheManager();
239  FTC_ImageCache* GetImageCache();
240  FTC_CMapCache* GetCMapCache();
242 
243  unsigned int MaximumNumberOfFaces;
244  unsigned int MaximumNumberOfSizes;
245  unsigned long MaximumNumberOfBytes;
246 
247  void InitializeCacheManager();
248  void ReleaseCacheManager();
249 };
250 
251 #endif
Wrapper around vtkstd::string to keep symbols short.
Definition: vtkStdString.h:45
abstract base class for most VTK objects
Definition: vtkObject.h:60
#define VTK_UNSIGNED_LONG_MAX
Definition: vtkType.h:129
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
topologically and geometrically regular array of data
Definition: vtkImageData.h:43
#define VTK_UNSIGNED_INT_MAX
Definition: vtkType.h:125
represent text properties.
#define VTK_RENDERING_EXPORT
FreeType library support.
String class that stores Unicode text.