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 
43 #ifndef vtkTextRenderer_h
44 #define vtkTextRenderer_h
45 
46 #include "vtkRenderingCoreModule.h" // For export macro
47 #include "vtkObject.h"
48 #include "vtkTuple.h" // For metrics struct
49 #include "vtkVector.h" // For metrics struct
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 
61 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
62 {
63 public:
66 
67 private:
68  vtkTextRendererCleanup(const vtkTextRendererCleanup& other) VTK_DELETE_FUNCTION;
69  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) VTK_DELETE_FUNCTION;
70 };
71 
72 class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
73 {
74 public:
75  struct Metrics
76  {
81  : BoundingBox(0),
82  TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0),
83  Ascent(0), Descent(0)
84  {
85  }
86 
93 
95 
104 
114  };
115 
116  vtkTypeMacro(vtkTextRenderer, vtkObject)
117  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
118 
128  static vtkTextRenderer *New();
129 
134  static vtkTextRenderer* GetInstance();
135 
141  enum Backend
142  {
143  Default = -1,
144  Detect = 0,
147 
148  UserBackend = 16
149  };
150 
152 
155  vtkSetMacro(DefaultBackend, int)
156  vtkGetMacro(DefaultBackend, int)
158 
160 
163  virtual int DetectBackend(const vtkStdString &str);
164  virtual int DetectBackend(const vtkUnicodeString &str);
166 
170  virtual bool FreeTypeIsSupported() { return false; }
171  virtual bool MathTextIsSupported() { return false; }
172 
174 
181  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
182  int bbox[4], int dpi, int backend = Default)
183  {
184  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
185  }
187  int bbox[4], int dpi, int backend = Default)
188  {
189  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
190  }
192 
193 
195 
200  bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
201  Metrics &metrics, int dpi, int backend = Default)
202  {
203  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
204  }
205  bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
206  Metrics &metrics, int dpi, int backend = Default)
207  {
208  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
209  }
211 
213 
227  bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
228  vtkImageData *data, int textDims[2], int dpi,
229  int backend = Default)
230  {
231  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
232  }
234  vtkImageData *data, int textDims[2], int dpi,
235  int backend = Default)
236  {
237  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
238  }
240 
242 
249  int targetWidth, int targetHeight, int dpi,
250  int backend = Default)
251  {
252  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
253  targetHeight, dpi, backend);
254  }
256  int targetWidth, int targetHeight, int dpi,
257  int backend = Default)
258  {
259  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
260  targetHeight, dpi, backend);
261  }
263 
265 
272  bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
273  vtkPath *path, int dpi, int backend = Default)
274  {
275  return this->StringToPathInternal(tprop, str, path, dpi, backend);
276  }
278  vtkPath *path, int dpi, int backend = Default)
279  {
280  return this->StringToPathInternal(tprop, str, path, dpi, backend);
281  }
283 
291  {
292  this->SetScaleToPowerOfTwoInternal(scale);
293  }
294 
296 
297 protected:
298  vtkTextRenderer();
299  ~vtkTextRenderer() VTK_OVERRIDE;
300 
302 
305  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
306  const vtkStdString &str,
307  int bbox[4], int dpi, int backend) = 0;
308  virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
309  const vtkUnicodeString &str,
310  int bbox[4], int dpi, int backend) = 0;
311  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
312  const vtkStdString &str,
313  Metrics &metrics, int dpi, int backend) = 0;
314  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
315  const vtkUnicodeString &str,
316  Metrics &metrics, int dpi, int backend) = 0;
317  virtual bool RenderStringInternal(vtkTextProperty *tprop,
318  const vtkStdString &str,
319  vtkImageData *data, int textDims[2],
320  int dpi, int backend) = 0;
321  virtual bool RenderStringInternal(vtkTextProperty *tprop,
322  const vtkUnicodeString &str,
323  vtkImageData *data, int textDims[2],
324  int dpi, int backend) = 0;
325  virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
326  vtkTextProperty *tprop,
327  int targetWidth, int targetHeight,
328  int dpi, int backend) = 0;
329  virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
330  vtkTextProperty *tprop,
331  int targetWidth, int targetHeight,
332  int dpi, int backend) = 0;
333  virtual bool StringToPathInternal(vtkTextProperty *tprop,
334  const vtkStdString &str, vtkPath *path,
335  int dpi, int backend) = 0;
336  virtual bool StringToPathInternal(vtkTextProperty *tprop,
337  const vtkUnicodeString &str, vtkPath *path,
338  int dpi, int backend) = 0;
339  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
341 
346  static void SetInstance(vtkTextRenderer *instance);
347 
349 
352  static vtkTextRenderer *Instance;
353  static vtkTextRendererCleanup Cleanup;
355 
356  vtksys::RegularExpression *MathTextRegExp;
357  vtksys::RegularExpression *MathTextRegExp2;
358 
360 
363  virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
364  virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
366 
370  int DefaultBackend;
371 
372 private:
373  vtkTextRenderer(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
374  void operator=(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
375 };
376 
377 #endif //vtkTextRenderer_h
bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkPath *path, int dpi, int backend=Default)
Given a text property and a string, this function populates the vtkPath path with the outline of the ...
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str, int bbox[4], int dpi, int backend=Default)
Given a text property and a string, get the bounding box {xmin, xmax, ymin, ymax} of the rendered str...
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:32
vtkVector2i TopRight
The corners of the rendered text (or background, if applicable), in pixels.
Backend
Available backends.
vtkVector2i Descent
Vectors representing the rotated ascent and descent of the text.
bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str, vtkPath *path, int dpi, int backend=Default)
Given a text property and a string, this function populates the vtkPath path with the outline of the ...
vtkVector2i TopLeft
The corners of the rendered text (or background, if applicable), in pixels.
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str, Metrics &metrics, int dpi, int backend=Default)
Given a text property and a string, get some metrics for the rendered string.
void SetScaleToPowerOfTwo(bool scale)
Set to true if the graphics implmentation requires texture image dimensions to be a power of two...
bool RenderString(vtkTextProperty *tprop, const vtkStdString &str, vtkImageData *data, int textDims[2], int dpi, int backend=Default)
Given a text property and a string, this function initializes the vtkImageData *data and renders it i...
vtkTuple< int, 4 > BoundingBox
The axis-aligned bounding box of the rendered text and background, in pixels.
bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkImageData *data, int textDims[2], int dpi, int backend=Default)
Given a text property and a string, this function initializes the vtkImageData *data and renders it i...
a simple class to control print indentation
Definition: vtkIndent.h:33
virtual bool MathTextIsSupported()
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:324
represent text properties.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual bool FreeTypeIsSupported()
Test for availability of various backends.
Metrics()
Construct a Metrics object with all members initialized to 0.
Interface for generating images and path data from string data, using multiple backends.
vtkVector2i Ascent
Vectors representing the rotated ascent and descent of the text.
bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi, int backend=Default)
Given a text property and a string, get some metrics for the rendered string.
int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend=Default)
This function returns the font size (in points) and sets the size in tprop that is required to fit th...
vtkVector2i BottomLeft
The corners of the rendered text (or background, if applicable), in pixels.
bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str, int bbox[4], int dpi, int backend=Default)
Given a text property and a string, get the bounding box {xmin, xmax, ymin, ymax} of the rendered str...
int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend=Default)
This function returns the font size (in points) and sets the size in tprop that is required to fit th...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkVector2i BottomRight
The corners of the rendered text (or background, if applicable), in pixels.
String class that stores Unicode text.