VTK
vtkTextRenderer.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTextRenderer.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 =========================================================================*/
15 
45 #ifndef __vtkTextRenderer_h
46 #define __vtkTextRenderer_h
47 
48 #include "vtkRenderingCoreModule.h" // For export macro
49 #include "vtkObject.h"
50 
51 class vtkImageData;
52 class vtkPath;
53 class vtkStdString;
54 class vtkUnicodeString;
55 class vtkTextProperty;
56 
57 namespace vtksys {
58 class RegularExpression;
59 }
60 
62 {
63 public:
66 
67 private:
68  vtkTextRendererCleanup(const vtkTextRendererCleanup& other); // no copy constructor
69  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs); // no copy assignment
70 };
71 
73 {
74 public:
76  virtual void PrintSelf(ostream &os, vtkIndent indent);
77 
85  static vtkTextRenderer *New();
86 
89  static vtkTextRenderer* GetInstance();
90 
92 
96  enum Backend
97  {
98  Default = -1,
99  Detect = 0,
103 
104  UserBackend = 16
105  };
106 
108 
109  vtkSetMacro(DefaultBackend, int)
110  vtkGetMacro(DefaultBackend, int)
112 
114 
115  virtual int DetectBackend(const vtkStdString &str);
116  virtual int DetectBackend(const vtkUnicodeString &str);
118 
120 
121  bool FreeTypeIsSupported() { return HasFreeType; }
122  bool MathTextIsSupported() { return HasMathText; }
124 
126 
134  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
135  int bbox[4], int dpi = 120, int backend = Default)
136  {
137  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
138  }
140  int bbox[4], int dpi = 120, int backend = Default)
141  {
142  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
143  }
145 
147 
158  bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
159  vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
160  int backend = Default)
161  {
162  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
163  }
165  vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
166  int backend = Default)
167  {
168  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
169  }
171 
173 
180  int targetWidth, int targetHeight, int dpi = 120,
181  int backend = Default)
182  {
183  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
184  targetHeight, dpi, backend);
185  }
187  int targetWidth, int targetHeight, int dpi = 120,
188  int backend = Default)
189  {
190  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
191  targetHeight, dpi, backend);
192  }
194 
196 
199  bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
200  vtkPath *path, int backend = Default)
201  {
202  return this->StringToPathInternal(tprop, str, path, backend);
203  }
205  vtkPath *path, int backend = Default)
206  {
207  return this->StringToPathInternal(tprop, str, path, backend);
208  }
210 
212 
217  {
218  this->SetScaleToPowerOfTwoInternal(scale);
219  }
221 
223 
224 protected:
225  vtkTextRenderer();
226  ~vtkTextRenderer();
227 
229 
230  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
231  const vtkStdString &str,
232  int bbox[4], int dpi, int backend) = 0;
233  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
234  const vtkUnicodeString &str,
235  int bbox[4], int dpi, int backend) = 0;
236  virtual bool RenderStringInternal(vtkTextProperty *tprop,
237  const vtkStdString &str,
238  vtkImageData *data, int textDims[2],
239  int dpi, int backend) = 0;
240  virtual bool RenderStringInternal(vtkTextProperty *tprop,
241  const vtkUnicodeString &str,
242  vtkImageData *data, int textDims[2],
243  int dpi, int backend) = 0;
244  virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
245  vtkTextProperty *tprop,
246  int targetWidth, int targetHeight,
247  int dpi, int backend) = 0;
248  virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
249  vtkTextProperty *tprop,
250  int targetWidth, int targetHeight,
251  int dpi, int backend) = 0;
252  virtual bool StringToPathInternal(vtkTextProperty *tprop,
253  const vtkStdString &str, vtkPath *path,
254  int backend) = 0;
255  virtual bool StringToPathInternal(vtkTextProperty *tprop,
256  const vtkUnicodeString &str, vtkPath *path,
257  int backend) = 0;
258  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
260 
263  static void SetInstance(vtkTextRenderer *instance);
264 
266 
270 
271  vtksys::RegularExpression *MathTextRegExp;
272  vtksys::RegularExpression *MathTextRegExp2;
273 
275 
276  virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
277  virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
279 
281 
286 
289 
290 private:
291  vtkTextRenderer(const vtkTextRenderer &); // Not implemented.
292  void operator=(const vtkTextRenderer &); // Not implemented.
293 };
294 
295 #endif //__vtkTextRenderer_h
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
abstract base class for most VTK objects
Definition: vtkObject.h:61
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:34
GLenum GLenum GLenum GLenum GLenum scale
Definition: vtkgl.h:15942
bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str, int bbox[4], int dpi=120, int backend=Default)
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
static vtkTextRendererCleanup Cleanup
bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str, vtkPath *path, int backend=Default)
bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkPath *path, int backend=Default)
bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkImageData *data, int textDims[2]=NULL, int dpi=120, int backend=Default)
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
vtksys::RegularExpression * MathTextRegExp2
void SetScaleToPowerOfTwo(bool scale)
a simple class to control print indentation
Definition: vtkIndent.h:38
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi=120, int backend=Default)
GLsizei const GLchar ** path
Definition: vtkgl.h:13835
represent text properties.
int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi=120, int backend=Default)
bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str, int bbox[4], int dpi=120, int backend=Default)
bool MathTextIsSupported()
bool RenderString(vtkTextProperty *tprop, const vtkStdString &str, vtkImageData *data, int textDims[2]=NULL, int dpi=120, int backend=Default)
Interface for generating images and path data from string data, using multiple backends.
#define VTKRENDERINGCORE_EXPORT
vtksys::RegularExpression * MathTextRegExp
String class that stores Unicode text.
static vtkTextRenderer * Instance
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69