VTK  9.2.6
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 class vtkImageData;
58 class vtkPath;
59 class vtkStdString;
60 class vtkTextProperty;
61 
62 namespace vtksys
63 {
64 class RegularExpression;
65 }
66 
67 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
68 {
69 public:
72 
73 private:
74  vtkTextRendererCleanup(const vtkTextRendererCleanup& other) = delete;
75  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
76 };
77 
78 class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
79 {
80 public:
81  struct Metrics
82  {
87  : BoundingBox(0)
88  , TopLeft(0)
89  , TopRight(0)
90  , BottomLeft(0)
91  , BottomRight(0)
92  , Ascent(0)
93  , Descent(0)
94  {
95  }
96 
103 
105 
114 
124  };
125 
126  vtkTypeMacro(vtkTextRenderer, vtkObject);
127  void PrintSelf(ostream& os, vtkIndent indent) override;
128 
138  static vtkTextRenderer* New();
139 
144  static vtkTextRenderer* GetInstance();
145 
151  enum Backend
152  {
153  Default = -1,
154  Detect = 0,
157 
158  UserBackend = 16
159  };
160 
162 
165  vtkSetMacro(DefaultBackend, int);
166  vtkGetMacro(DefaultBackend, int);
168 
170 
173  virtual int DetectBackend(const vtkStdString& str);
175 
179  virtual bool FreeTypeIsSupported() { return false; }
180  virtual bool MathTextIsSupported() { return false; }
181 
183 
191  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend = Default)
192  {
193  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
194  }
196 
198 
203  bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
204  int backend = Default)
205  {
206  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
207  }
209 
211 
226  int textDims[2], int dpi, int backend = Default)
227  {
228  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
229  }
231 
233 
239  int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
240  int targetHeight, int dpi, int backend = Default)
241  {
242  return this->GetConstrainedFontSizeInternal(
243  str, tprop, targetWidth, targetHeight, dpi, backend);
244  }
246 
248 
256  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
257  {
258  return this->StringToPathInternal(tprop, str, path, dpi, backend);
259  }
261 
268  void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
269 
271 
272 protected:
273  vtkTextRenderer();
274  ~vtkTextRenderer() override;
275 
277 
280  virtual bool GetBoundingBoxInternal(
281  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
282  virtual bool GetMetricsInternal(
283  vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
284  virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
285  vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
286  virtual int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop,
287  int targetWidth, int targetHeight, int dpi, int backend) = 0;
288  virtual bool StringToPathInternal(
289  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
290  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
292 
297  static void SetInstance(vtkTextRenderer* instance);
298 
300 
306 
307  vtksys::RegularExpression* MathTextRegExp;
308  vtksys::RegularExpression* MathTextRegExp2;
309  vtksys::RegularExpression* MathTextRegExpColumn;
310 
312 
315  virtual void CleanUpFreeTypeEscapes(vtkStdString& str);
317 
322 
323 private:
324  vtkTextRenderer(const vtkTextRenderer&) = delete;
325  void operator=(const vtkTextRenderer&) = delete;
326 };
327 
328 #endif // vtkTextRenderer_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
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:62
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:35
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.
static vtkTextRendererCleanup Cleanup
The singleton instance and the singleton cleanup instance.
vtksys::RegularExpression * MathTextRegExp2
void SetScaleToPowerOfTwo(bool scale)
Set to true if the graphics implementation requires texture image dimensions to be a power of two...
int DefaultBackend
The backend to use when none is specified.
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.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual bool MathTextIsSupported()
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:421
represent text properties.
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.
vtkVector2i BottomLeft
The corners of the rendered text (or background, if applicable), in pixels.
vtksys::RegularExpression * MathTextRegExpColumn
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...
vtksys::RegularExpression * MathTextRegExp
vtkVector2i BottomRight
The corners of the rendered text (or background, if applicable), in pixels.
static vtkTextRenderer * Instance
The singleton instance and the singleton cleanup instance.