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 #include "vtkTuple.h" // For metrics struct
51 #include "vtkVector.h" // For metrics struct
52 
53 class vtkImageData;
54 class vtkPath;
55 class vtkStdString;
56 class vtkUnicodeString;
57 class vtkTextProperty;
58 
59 namespace vtksys {
60 class RegularExpression;
61 }
62 
64 {
65 public:
68 
69 private:
70  vtkTextRendererCleanup(const vtkTextRendererCleanup& other); // no copy constructor
71  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs); // no copy assignment
72 };
73 
75 {
76 public:
77  struct Metrics
78  {
80 
82  : BoundingBox(0),
83  TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0)
84  {
85  }
87 
93 
95 
101  };
103 
105  virtual void PrintSelf(ostream &os, vtkIndent indent);
106 
114  static vtkTextRenderer *New();
115 
118  static vtkTextRenderer* GetInstance();
119 
121 
125  enum Backend
126  {
127  Default = -1,
128  Detect = 0,
132 
133  UserBackend = 16
134  };
135 
137 
138  vtkSetMacro(DefaultBackend, int)
139  vtkGetMacro(DefaultBackend, int)
141 
143 
144  virtual int DetectBackend(const vtkStdString &str);
145  virtual int DetectBackend(const vtkUnicodeString &str);
147 
149 
150  bool FreeTypeIsSupported() { return HasFreeType; }
151  bool MathTextIsSupported() { return HasMathText; }
153 
155 
161  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
162  int bbox[4], int dpi = 120, int backend = Default)
163  {
164  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
165  }
167  int bbox[4], int dpi = 120, int backend = Default)
168  {
169  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
170  }
172 
173 
175 
179  bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
180  Metrics &metrics, int dpi = 120, int backend = Default)
181  {
182  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
183  }
184  bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
185  Metrics &metrics, int dpi = 120, int backend = Default)
186  {
187  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
188  }
190 
192 
205  bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
206  vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
207  int backend = Default)
208  {
209  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
210  }
212  vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
213  int backend = Default)
214  {
215  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
216  }
218 
220 
227  int targetWidth, int targetHeight, int dpi = 120,
228  int backend = Default)
229  {
230  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
231  targetHeight, dpi, backend);
232  }
234  int targetWidth, int targetHeight, int dpi = 120,
235  int backend = Default)
236  {
237  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
238  targetHeight, dpi, backend);
239  }
241 
243 
248  bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
249  vtkPath *path, int backend = Default)
250  {
251  return this->StringToPathInternal(tprop, str, path, backend);
252  }
254  vtkPath *path, int backend = Default)
255  {
256  return this->StringToPathInternal(tprop, str, path, backend);
257  }
259 
261 
266  {
267  this->SetScaleToPowerOfTwoInternal(scale);
268  }
270 
272 
273 protected:
274  vtkTextRenderer();
275  ~vtkTextRenderer();
276 
278 
279  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
280  const vtkStdString &str,
281  int bbox[4], int dpi, int backend) = 0;
282  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
283  const vtkUnicodeString &str,
284  int bbox[4], int dpi, int backend) = 0;
285  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
286  const vtkStdString &str,
287  Metrics &metrics, int dpi, int backend) = 0;
288  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
289  const vtkUnicodeString &str,
290  Metrics &metrics, int dpi, int backend) = 0;
291  virtual bool RenderStringInternal(vtkTextProperty *tprop,
292  const vtkStdString &str,
293  vtkImageData *data, int textDims[2],
294  int dpi, int backend) = 0;
295  virtual bool RenderStringInternal(vtkTextProperty *tprop,
296  const vtkUnicodeString &str,
297  vtkImageData *data, int textDims[2],
298  int dpi, int backend) = 0;
299  virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
300  vtkTextProperty *tprop,
301  int targetWidth, int targetHeight,
302  int dpi, int backend) = 0;
303  virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
304  vtkTextProperty *tprop,
305  int targetWidth, int targetHeight,
306  int dpi, int backend) = 0;
307  virtual bool StringToPathInternal(vtkTextProperty *tprop,
308  const vtkStdString &str, vtkPath *path,
309  int backend) = 0;
310  virtual bool StringToPathInternal(vtkTextProperty *tprop,
311  const vtkUnicodeString &str, vtkPath *path,
312  int backend) = 0;
313  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
315 
318  static void SetInstance(vtkTextRenderer *instance);
319 
321 
325 
326  vtksys::RegularExpression *MathTextRegExp;
327  vtksys::RegularExpression *MathTextRegExp2;
328 
330 
331  virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
332  virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
334 
336 
341 
344 
345 private:
346  vtkTextRenderer(const vtkTextRenderer &); // Not implemented.
347  void operator=(const vtkTextRenderer &); // Not implemented.
348 };
349 
350 #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:632
vtksys::RegularExpression * MathTextRegExp2
void SetScaleToPowerOfTwo(bool scale)
vtkTuple< int, 4 > BoundingBox
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.
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str, Metrics &metrics, int dpi=120, int backend=Default)
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 GetMetrics(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi=120, int backend=Default)
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