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 
104  vtkTypeMacro(vtkTextRenderer, vtkObject)
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  virtual bool FreeTypeIsSupported() { return false; }
151  virtual bool MathTextIsSupported() { return false; }
153 
155 
160  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
161  int bbox[4], int dpi, int backend = Default)
162  {
163  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
164  }
166  int bbox[4], int dpi, int backend = Default)
167  {
168  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
169  }
171 
172 
174 
176  bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
177  Metrics &metrics, int dpi, int backend = Default)
178  {
179  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
180  }
181  bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
182  Metrics &metrics, int dpi, int backend = Default)
183  {
184  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
185  }
187 
189 
200  bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
201  vtkImageData *data, int textDims[2], int dpi,
202  int backend = Default)
203  {
204  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
205  }
207  vtkImageData *data, int textDims[2], int dpi,
208  int backend = Default)
209  {
210  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
211  }
213 
215 
220  int targetWidth, int targetHeight, int dpi,
221  int backend = Default)
222  {
223  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
224  targetHeight, dpi, backend);
225  }
227  int targetWidth, int targetHeight, int dpi,
228  int backend = Default)
229  {
230  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
231  targetHeight, dpi, backend);
232  }
234 
236 
241  bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
242  vtkPath *path, int dpi, int backend = Default)
243  {
244  return this->StringToPathInternal(tprop, str, path, dpi, backend);
245  }
247  vtkPath *path, int dpi, int backend = Default)
248  {
249  return this->StringToPathInternal(tprop, str, path, dpi, backend);
250  }
252 
254 
259  {
260  this->SetScaleToPowerOfTwoInternal(scale);
261  }
263 
265 
266 protected:
267  vtkTextRenderer();
268  ~vtkTextRenderer();
269 
271 
272  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
273  const vtkStdString &str,
274  int bbox[4], int dpi, int backend) = 0;
275  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
276  const vtkUnicodeString &str,
277  int bbox[4], int dpi, int backend) = 0;
278  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
279  const vtkStdString &str,
280  Metrics &metrics, int dpi, int backend) = 0;
281  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
282  const vtkUnicodeString &str,
283  Metrics &metrics, int dpi, int backend) = 0;
284  virtual bool RenderStringInternal(vtkTextProperty *tprop,
285  const vtkStdString &str,
286  vtkImageData *data, int textDims[2],
287  int dpi, int backend) = 0;
288  virtual bool RenderStringInternal(vtkTextProperty *tprop,
289  const vtkUnicodeString &str,
290  vtkImageData *data, int textDims[2],
291  int dpi, int backend) = 0;
292  virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
293  vtkTextProperty *tprop,
294  int targetWidth, int targetHeight,
295  int dpi, int backend) = 0;
296  virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
297  vtkTextProperty *tprop,
298  int targetWidth, int targetHeight,
299  int dpi, int backend) = 0;
300  virtual bool StringToPathInternal(vtkTextProperty *tprop,
301  const vtkStdString &str, vtkPath *path,
302  int dpi, int backend) = 0;
303  virtual bool StringToPathInternal(vtkTextProperty *tprop,
304  const vtkUnicodeString &str, vtkPath *path,
305  int dpi, int backend) = 0;
306  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
308 
311  static void SetInstance(vtkTextRenderer *instance);
312 
314 
318 
319  vtksys::RegularExpression *MathTextRegExp;
320  vtksys::RegularExpression *MathTextRegExp2;
321 
323 
324  virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
325  virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
327 
330 
331 private:
332  vtkTextRenderer(const vtkTextRenderer &); // Not implemented.
333  void operator=(const vtkTextRenderer &); // Not implemented.
334 };
335 
336 #endif //vtkTextRenderer_h
bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkPath *path, int dpi, int backend=Default)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str, int bbox[4], int dpi, int backend=Default)
abstract base class for most VTK objects
Definition: vtkObject.h:61
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:34
bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str, vtkPath *path, int dpi, int backend=Default)
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str, Metrics &metrics, int dpi, int backend=Default)
static vtkTextRendererCleanup Cleanup
vtksys::RegularExpression * MathTextRegExp2
void SetScaleToPowerOfTwo(bool scale)
bool RenderString(vtkTextProperty *tprop, const vtkStdString &str, vtkImageData *data, int textDims[2], int dpi, int backend=Default)
vtkTuple< int, 4 > BoundingBox
bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkImageData *data, int textDims[2], int dpi, int backend=Default)
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual bool MathTextIsSupported()
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
represent text properties.
Interface for generating images and path data from string data, using multiple backends.
bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi, int backend=Default)
int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend=Default)
#define VTKRENDERINGCORE_EXPORT
bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str, int bbox[4], int dpi, int backend=Default)
int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend=Default)
vtksys::RegularExpression * MathTextRegExp
String class that stores Unicode text.
static vtkTextRenderer * Instance