VTK  9.2.20230207
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 
49 #ifndef vtkTextRenderer_h
50 #define vtkTextRenderer_h
51 
52 #include "vtkObject.h"
53 #include "vtkRenderingCoreModule.h" // For export macro
54 #include "vtkTuple.h" // For metrics struct
55 #include "vtkVector.h" // For metrics struct
56 
57 VTK_ABI_NAMESPACE_BEGIN
58 class vtkImageData;
59 class vtkPath;
60 class vtkStdString;
61 class vtkTextProperty;
62 VTK_ABI_NAMESPACE_END
63 
64 namespace vtksys
65 {
66 class RegularExpression;
67 }
68 
69 VTK_ABI_NAMESPACE_BEGIN
70 
71 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
72 {
73 public:
76 
77 private:
78  vtkTextRendererCleanup(const vtkTextRendererCleanup& other) = delete;
79  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
80 };
81 
82 class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
83 {
84 public:
85  struct Metrics
86  {
91  : BoundingBox(0)
92  , TopLeft(0)
93  , TopRight(0)
94  , BottomLeft(0)
95  , BottomRight(0)
96  , Ascent(0)
97  , Descent(0)
98  {
99  }
100 
107 
109 
118 
128  };
129 
130  vtkTypeMacro(vtkTextRenderer, vtkObject);
131  void PrintSelf(ostream& os, vtkIndent indent) override;
132 
142  static vtkTextRenderer* New();
143 
149 
155  enum Backend
156  {
157  Default = -1,
158  Detect = 0,
161 
162  UserBackend = 16
163  };
164 
166 
169  vtkSetMacro(DefaultBackend, int);
170  vtkGetMacro(DefaultBackend, int);
172 
174 
177  virtual int DetectBackend(const vtkStdString& str);
179 
183  virtual bool FreeTypeIsSupported() { return false; }
184  virtual bool MathTextIsSupported() { return false; }
185 
187 
195  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend = Default)
196  {
197  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
198  }
200 
202 
207  bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
208  int backend = Default)
209  {
210  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
211  }
213 
215 
230  int textDims[2], int dpi, int backend = Default)
231  {
232  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
233  }
235 
237 
243  int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
244  int targetHeight, int dpi, int backend = Default)
245  {
246  return this->GetConstrainedFontSizeInternal(
247  str, tprop, targetWidth, targetHeight, dpi, backend);
248  }
250 
252 
260  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
261  {
262  return this->StringToPathInternal(tprop, str, path, dpi, backend);
263  }
265 
272  void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
273 
275 
276 protected:
278  ~vtkTextRenderer() override;
279 
281 
285  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
286  virtual bool GetMetricsInternal(
287  vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
288  virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
289  vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
291  int targetWidth, int targetHeight, int dpi, int backend) = 0;
292  virtual bool StringToPathInternal(
293  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
294  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
296 
301  static void SetInstance(vtkTextRenderer* instance);
302 
304 
310 
311  vtksys::RegularExpression* MathTextRegExp;
312  vtksys::RegularExpression* MathTextRegExp2;
313  vtksys::RegularExpression* MathTextRegExpColumn;
314 
316 
321 
326 
327 private:
328  vtkTextRenderer(const vtkTextRenderer&) = delete;
329  void operator=(const vtkTextRenderer&) = delete;
330 };
331 
332 VTK_ABI_NAMESPACE_END
333 #endif // vtkTextRenderer_h
topologically and geometrically regular array of data
Definition: vtkImageData.h:164
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:37
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:110
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
Virtual methods for concrete implementations of the public methods.
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()
static vtkTextRenderer * GetInstance()
Return the singleton instance with no reference counting.
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 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...
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...
static vtkTextRenderer * New()
This is a singleton pattern New.
static vtkTextRendererCleanup Cleanup
The singleton instance and the singleton cleanup instance.
vtksys::RegularExpression * MathTextRegExpColumn
void SetScaleToPowerOfTwo(bool scale)
Set to true if the graphics implementation requires texture image dimensions to be a power of two.
virtual void SetScaleToPowerOfTwoInternal(bool scale)=0
Virtual methods for concrete implementations of the public methods.
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
Virtual methods for concrete implementations of the public methods.
Backend
Available backends.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool FreeTypeIsSupported()
Test for availability of various backends.
virtual bool GetMetricsInternal(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi, int backend)=0
Virtual methods for concrete implementations of the public methods.
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 methods for concrete implementations of the public methods.
virtual void CleanUpFreeTypeEscapes(vtkStdString &str)
Replace all instances of "\$" with "$".
virtual int DetectBackend(const vtkStdString &str)
Determine the appropriate back end needed to render the given string.
~vtkTextRenderer() override
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:482
@ scale
Definition: vtkX3D.h:241
@ data
Definition: vtkX3D.h:327
vtkVector2i BottomRight
The corners of the rendered text (or background, if applicable), in pixels.
vtkVector2i Descent
Vectors representing the rotated ascent and descent of the text.
vtkVector2i Ascent
Vectors representing the rotated ascent and descent of the text.
Metrics()
Construct a Metrics object with all members initialized to 0.
vtkVector2i TopRight
The corners of the rendered text (or background, if applicable), in pixels.
vtkVector2i BottomLeft
The corners of the rendered text (or background, if applicable), in pixels.
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.