VTK  9.0.20210424
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 "vtkDeprecation.h" // for deprecation macros
47 #include "vtkObject.h"
48 #include "vtkRenderingCoreModule.h" // For export macro
49 #include "vtkTuple.h" // For metrics struct
50 #include "vtkVector.h" // For metrics struct
51 
52 class vtkImageData;
53 class vtkPath;
54 class vtkStdString;
55 class vtkUnicodeString;
56 class vtkTextProperty;
57 
58 namespace vtksys
59 {
60 class RegularExpression;
61 }
62 
63 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
64 {
65 public:
68 
69 private:
70  vtkTextRendererCleanup(const vtkTextRendererCleanup& other) = delete;
71  vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
72 };
73 
74 class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
75 {
76 public:
77  struct Metrics
78  {
83  : BoundingBox(0)
84  , TopLeft(0)
85  , TopRight(0)
86  , BottomLeft(0)
87  , BottomRight(0)
88  , Ascent(0)
89  , Descent(0)
90  {
91  }
92 
99 
101 
110 
120  };
121 
122  vtkTypeMacro(vtkTextRenderer, vtkObject);
123  void PrintSelf(ostream& os, vtkIndent indent) override;
124 
134  static vtkTextRenderer* New();
135 
141 
147  enum Backend
148  {
149  Default = -1,
150  Detect = 0,
153 
154  UserBackend = 16
155  };
156 
158 
161  vtkSetMacro(DefaultBackend, int);
162  vtkGetMacro(DefaultBackend, int);
164 
166 
169  virtual int DetectBackend(const vtkStdString& str);
170  virtual int DetectBackend(const vtkUnicodeString& str);
172 
176  virtual bool FreeTypeIsSupported() { return false; }
177  virtual bool MathTextIsSupported() { return false; }
178 
180 
188  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend = Default)
189  {
190  return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
191  }
192  VTK_DEPRECATED_IN_9_1_0("Use bool GetBoundingBox(vtkTextProperty* tprop, const vtkStdString& "
193  "str, int bbox[4], int dpi, int backend)")
194  bool GetBoundingBox(vtkTextProperty* tprop, const vtkUnicodeString& str, int bbox[4], int dpi,
195  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  }
212  VTK_DEPRECATED_IN_9_1_0("Use bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, "
213  "Metrics& metrics, int dpi, int backend)")
214  bool GetMetrics(vtkTextProperty* tprop, const vtkUnicodeString& str, Metrics& metrics, int dpi,
215  int backend = Default)
216  {
217  return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
218  }
220 
222 
236  bool RenderString(vtkTextProperty* tprop, const vtkStdString& str, vtkImageData* data,
237  int textDims[2], int dpi, int backend = Default)
238  {
239  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
240  }
241  VTK_DEPRECATED_IN_9_1_0("Use bool RenderString(vtkTextProperty* tprop, const vtkStdString& str, "
242  "vtkImageData* data, int textDims[2], int dpi, int backend)")
243  bool RenderString(vtkTextProperty* tprop, const vtkUnicodeString& str, vtkImageData* data,
244  int textDims[2], int dpi, int backend = Default)
245  {
246  return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
247  }
249 
251 
257  int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
258  int targetHeight, int dpi, int backend = Default)
259  {
260  return this->GetConstrainedFontSizeInternal(
261  str, tprop, targetWidth, targetHeight, dpi, backend);
262  }
264  "Use int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int "
265  "targetWidth, int targetHeight, int dpi, int backend)")
266  int GetConstrainedFontSize(const vtkUnicodeString& str, vtkTextProperty* tprop, int targetWidth,
267  int targetHeight, int dpi, int backend = Default)
268  {
269  return this->GetConstrainedFontSizeInternal(
270  str, tprop, targetWidth, targetHeight, dpi, backend);
271  }
273 
275 
282  bool StringToPath(
283  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
284  {
285  return this->StringToPathInternal(tprop, str, path, dpi, backend);
286  }
287  VTK_DEPRECATED_IN_9_1_0("Use bool StringToPath(vtkTextProperty* tprop, const vtkStdString& str, "
288  "vtkPath* path, int dpi, int backend)")
289  bool StringToPath(vtkTextProperty* tprop, const vtkUnicodeString& str, vtkPath* path, int dpi,
290  int backend = Default)
291  {
292  return this->StringToPathInternal(tprop, str, path, dpi, backend);
293  }
295 
302  void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
303 
304  friend class vtkTextRendererCleanup;
305 
306 protected:
308  ~vtkTextRenderer() override;
309 
311 
315  vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
316  VTK_DEPRECATED_IN_9_1_0("Use bool GetBoundingBoxInternal(vtkTextProperty* tprop, const "
317  "vtkStdString& str, int bbox[4], int dpi, int backend)")
318  virtual bool GetBoundingBoxInternal(
319  vtkTextProperty* tprop, const vtkUnicodeString& str, int bbox[4], int dpi, int backend) = 0;
320  virtual bool GetMetricsInternal(
321  vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
322  VTK_DEPRECATED_IN_9_1_0("Use bool GetMetricsInternal(vtkTextProperty* tprop, const vtkStdString& "
323  "str, Metrics& metrics, int dpi, int backend)")
324  virtual bool GetMetricsInternal(vtkTextProperty* tprop, const vtkUnicodeString& str,
325  Metrics& metrics, int dpi, int backend) = 0;
326  virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
327  vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
329  "Use bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str, vtkImageData* "
330  "data, int textDims[2], int dpi, int backend)")
331  virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkUnicodeString& str,
332  vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
333  virtual int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop,
334  int targetWidth, int targetHeight, int dpi, int backend) = 0;
336  "Use int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop, int "
337  "targetWidth, int targetHeight, int dpi, int backend)")
338  virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString& str, vtkTextProperty* tprop,
339  int targetWidth, int targetHeight, int dpi, int backend) = 0;
340  virtual bool StringToPathInternal(
341  vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
342  VTK_DEPRECATED_IN_9_1_0("Use bool StringToPathInternal(vtkTextProperty* tprop, const "
343  "vtkStdString& str, vtkPath* path, int dpi, int backend)")
344  virtual bool StringToPathInternal(
345  vtkTextProperty* tprop, const vtkUnicodeString& str, vtkPath* path, int dpi, int backend) = 0;
346  virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
348 
353  static void SetInstance(vtkTextRenderer* instance);
354 
356 
359  static vtkTextRenderer* Instance;
360  static vtkTextRendererCleanup Cleanup;
362 
363  vtksys::RegularExpression* MathTextRegExp;
364  vtksys::RegularExpression* MathTextRegExp2;
365  vtksys::RegularExpression* MathTextRegExpColumn;
366 
368 
371  virtual void CleanUpFreeTypeEscapes(vtkStdString& str);
372  VTK_DEPRECATED_IN_9_1_0("Use void CleanUpFreeTypeEscapes(vtkStdString& str)")
373  virtual void CleanUpFreeTypeEscapes(vtkUnicodeString& str);
375 
379  int DefaultBackend;
380 
381 private:
382  vtkTextRenderer(const vtkTextRenderer&) = delete;
383  void operator=(const vtkTextRenderer&) = delete;
384 };
385 
386 #endif // vtkTextRenderer_h
vtkTextRendererCleanup
Definition: vtkTextRenderer.h:64
vtkTextRenderer::~vtkTextRenderer
~vtkTextRenderer() override
vtkTextRenderer::Backend
Backend
Available backends.
Definition: vtkTextRenderer.h:148
vtkTextRenderer::DetectBackend
virtual int DetectBackend(const vtkStdString &str)
Determine the appropriate back end needed to render the given string.
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkTextRenderer::Metrics::Metrics
Metrics()
Construct a Metrics object with all members initialized to 0.
Definition: vtkTextRenderer.h:82
vtkTextRenderer::GetBoundingBoxInternal
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.
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkTextRenderer::MathTextIsSupported
virtual bool MathTextIsSupported()
Definition: vtkTextRenderer.h:177
vtkPath
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:33
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:63
vtkVector.h
VTK_DEPRECATED_IN_9_1_0
#define VTK_DEPRECATED_IN_9_1_0(reason)
Definition: vtkDeprecation.h:117
vtkTextRenderer::DetectBackend
virtual int DetectBackend(const vtkUnicodeString &str)
Determine the appropriate back end needed to render the given string.
vtkTextRenderer::Metrics::TopLeft
vtkVector2i TopLeft
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:105
vtkTextRenderer::GetBoundingBox
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...
Definition: vtkTextRenderer.h:187
vtkTextRenderer::FreeTypeIsSupported
virtual bool FreeTypeIsSupported()
Test for availability of various backends.
Definition: vtkTextRenderer.h:176
vtkTextRenderer::vtkTextRenderer
vtkTextRenderer()
vtkTextRenderer::Metrics::BottomRight
vtkVector2i BottomRight
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:108
vtkTextRenderer::MathText
@ MathText
Definition: vtkTextRenderer.h:152
vtksys
Definition: vtkVASPAnimationReader.h:32
vtkTextRenderer::VTK_DEPRECATED_IN_9_1_0
VTK_DEPRECATED_IN_9_1_0("Use bool GetBoundingBoxInternal(vtkTextProperty* tprop, const " "vtkStdString& str, int bbox[4], int dpi, int backend)") virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop
Virtual methods for concrete implementations of the public methods.
vtkTextRenderer::Metrics::Ascent
vtkVector2i Ascent
Vectors representing the rotated ascent and descent of the text.
Definition: vtkTextRenderer.h:117
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:48
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkTextRenderer::Metrics::Descent
vtkVector2i Descent
Vectors representing the rotated ascent and descent of the text.
Definition: vtkTextRenderer.h:118
vtkTextRenderer::Metrics::BoundingBox
vtkTuple< int, 4 > BoundingBox
The axis-aligned bounding box of the rendered text and background, in pixels.
Definition: vtkTextRenderer.h:98
vtkObject.h
str
const vtkUnicodeString & str
Definition: vtkVariantBoostSerialization.h:72
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:34
vtkTextRenderer::Metrics::BottomLeft
vtkVector2i BottomLeft
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:107
vtkTextRendererCleanup::vtkTextRendererCleanup
vtkTextRendererCleanup()
vtkTuple.h
vtkDeprecation.h
vtkTextRenderer::Metrics::TopRight
vtkVector2i TopRight
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:106
vtkTextRenderer
Interface for generating images and path data from string data, using multiple backends.
Definition: vtkTextRenderer.h:75
vtkTextRenderer::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTextRendererCleanup::~vtkTextRendererCleanup
~vtkTextRendererCleanup()
vtkVector2i
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:420
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
vtkTextRenderer::New
static vtkTextRenderer * New()
This is a singleton pattern New.
vtkTextRenderer::VTK_DEPRECATED_IN_9_1_0
VTK_DEPRECATED_IN_9_1_0("Use bool GetBoundingBox(vtkTextProperty* tprop, const vtkStdString& " "str, int bbox[4], int dpi, int backend)") bool GetBoundingBox(vtkTextProperty *tprop
Given a text property and a string, get the bounding box {xmin, xmax, ymin, ymax} of the rendered str...
vtkTuple< int, 4 >
vtkTextRenderer::GetInstance
static vtkTextRenderer * GetInstance()
Return the singleton instance with no reference counting.
vtkTextRenderer::Metrics
Definition: vtkTextRenderer.h:78
vtkTextRenderer::FreeType
@ FreeType
Definition: vtkTextRenderer.h:151