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 
46 #ifndef vtkTextRenderer_h
47 #define vtkTextRenderer_h
48 
49 #include "vtkRenderingCoreModule.h" // For export macro
50 #include "vtkObject.h"
51 #include "vtkTuple.h" // For metrics struct
52 #include "vtkVector.h" // For metrics struct
53 
54 class vtkImageData;
55 class vtkPath;
56 class vtkStdString;
57 class vtkUnicodeString;
58 class vtkTextProperty;
59 
60 namespace vtksys {
61 class RegularExpression;
62 }
63 
64 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
65 {
66 public:
69 
70 private:
71  vtkTextRendererCleanup(const vtkTextRendererCleanup& other) VTK_DELETE_FUNCTION;
72  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) VTK_DELETE_FUNCTION;
73 };
74 
75 class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
76 {
77 public:
78  struct Metrics
79  {
84  : BoundingBox(0),
85  TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0)
86  {
87  }
88 
95 
97 
105  };
107 
108  vtkTypeMacro(vtkTextRenderer, vtkObject)
109  virtual void PrintSelf(ostream &os, vtkIndent indent);
110 
120  static vtkTextRenderer *New();
121 
126  static vtkTextRenderer* GetInstance();
127 
133  enum Backend
134  {
135  Default = -1,
136  Detect = 0,
139 
140  UserBackend = 16
141  };
142 
144 
147  vtkSetMacro(DefaultBackend, int)
148  vtkGetMacro(DefaultBackend, int)
150 
152 
155  virtual int DetectBackend(const vtkStdString &str);
156  virtual int DetectBackend(const vtkUnicodeString &str);
158 
162  virtual bool FreeTypeIsSupported() { return false; }
163  virtual bool MathTextIsSupported() { return false; }
164 
166 
173  bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
174  int bbox[4], int dpi, int backend = Default)
175  {
176  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
177  }
179  int bbox[4], int dpi, int backend = Default)
180  {
181  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
182  }
184 
185 
187 
192  bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
193  Metrics &metrics, int dpi, int backend = Default)
194  {
195  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
196  }
197  bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
198  Metrics &metrics, int dpi, int backend = Default)
199  {
200  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
201  }
203 
205 
219  bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
220  vtkImageData *data, int textDims[2], int dpi,
221  int backend = Default)
222  {
223  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
224  }
226  vtkImageData *data, int textDims[2], int dpi,
227  int backend = Default)
228  {
229  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
230  }
232 
234 
241  int targetWidth, int targetHeight, int dpi,
242  int backend = Default)
243  {
244  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
245  targetHeight, dpi, backend);
246  }
248  int targetWidth, int targetHeight, int dpi,
249  int backend = Default)
250  {
251  return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
252  targetHeight, dpi, backend);
253  }
255 
257 
264  bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
265  vtkPath *path, int dpi, int backend = Default)
266  {
267  return this->StringToPathInternal(tprop, str, path, dpi, backend);
268  }
270  vtkPath *path, int dpi, int backend = Default)
271  {
272  return this->StringToPathInternal(tprop, str, path, dpi, backend);
273  }
275 
283  {
284  this->SetScaleToPowerOfTwoInternal(scale);
285  }
286 
288 
289 protected:
292 
294 
298  const vtkStdString &str,
299  int bbox[4], int dpi, int backend) = 0;
301  const vtkUnicodeString &str,
302  int bbox[4], int dpi, int backend) = 0;
303  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
304  const vtkStdString &str,
305  Metrics &metrics, int dpi, int backend) = 0;
306  virtual bool GetMetricsInternal(vtkTextProperty *tprop,
307  const vtkUnicodeString &str,
308  Metrics &metrics, int dpi, int backend) = 0;
310  const vtkStdString &str,
311  vtkImageData *data, int textDims[2],
312  int dpi, int backend) = 0;
314  const vtkUnicodeString &str,
315  vtkImageData *data, int textDims[2],
316  int dpi, int backend) = 0;
318  vtkTextProperty *tprop,
319  int targetWidth, int targetHeight,
320  int dpi, int backend) = 0;
322  vtkTextProperty *tprop,
323  int targetWidth, int targetHeight,
324  int dpi, int backend) = 0;
326  const vtkStdString &str, vtkPath *path,
327  int dpi, int backend) = 0;
329  const vtkUnicodeString &str, vtkPath *path,
330  int dpi, int backend) = 0;
331  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
333 
338  static void SetInstance(vtkTextRenderer *instance);
339 
341 
347 
348  vtksys::RegularExpression *MathTextRegExp;
349  vtksys::RegularExpression *MathTextRegExp2;
350 
352 
358 
363 
364 private:
365  vtkTextRenderer(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
366  void operator=(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
367 };
368 
369 #endif //vtkTextRenderer_h
topologically and geometrically regular array of data
Definition: vtkImageData.h:46
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:36
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
represent text properties.
Interface for generating images and path data from string data, using multiple backends.
int DefaultBackend
The backend to use when none is specified.
virtual int GetConstrainedFontSizeInternal(const vtkStdString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend)=0
bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkImageData *data, int textDims[2], int dpi, int backend=Default)
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 ...
virtual bool MathTextIsSupported()
virtual bool GetMetricsInternal(vtkTextProperty *tprop, const vtkUnicodeString &str, Metrics &metrics, int dpi, int backend)=0
static void SetInstance(vtkTextRenderer *instance)
Set the singleton instance.
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...
bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkPath *path, int dpi, int backend=Default)
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...
virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop, const vtkUnicodeString &str, int bbox[4], int dpi, int backend)=0
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...
virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str)
static vtkTextRendererCleanup Cleanup
void SetScaleToPowerOfTwo(bool scale)
Set to true if the graphics implmentation requires texture image dimensions to be a power of two.
virtual bool StringToPathInternal(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkPath *path, int dpi, int backend)=0
virtual void SetScaleToPowerOfTwoInternal(bool scale)=0
static vtkTextRenderer * Instance
The singleton instance and the singleton cleanup instance.
vtksys::RegularExpression * MathTextRegExp
virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop, const vtkStdString &str, int bbox[4], int dpi, int backend)=0
Virtual methods for concrete implementations of the public methods.
virtual bool RenderStringInternal(vtkTextProperty *tprop, const vtkStdString &str, vtkImageData *data, int textDims[2], int dpi, int backend)=0
Backend
Available backends.
virtual bool RenderStringInternal(vtkTextProperty *tprop, const vtkUnicodeString &str, vtkImageData *data, int textDims[2], int dpi, int backend)=0
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str, Metrics &metrics, int dpi, int backend=Default)
virtual bool GetMetricsInternal(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi, int backend)=0
vtksys::RegularExpression * MathTextRegExp2
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.
virtual bool StringToPathInternal(vtkTextProperty *tprop, const vtkStdString &str, vtkPath *path, int dpi, int backend)=0
virtual void CleanUpFreeTypeEscapes(vtkStdString &str)
Replace all instances of "\$" with "$".
int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend=Default)
virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str, vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi, int backend)=0
bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str, int bbox[4], int dpi, int backend=Default)
String class that stores Unicode text.
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:328
@ scale
Definition: vtkX3D.h:229
@ data
Definition: vtkX3D.h:315
Metrics()
Construct a Metrics object with all members initialized to 0.
vtkVector2i TopLeft
The corners of the rendered text (or background, if applicable), in pixels.
vtkTuple< int, 4 > BoundingBox
The axis-aligned bounding box of the rendered text and background, in pixels.
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.