VTK: Rendering/Core/vtkTextRenderer.h Source File

| VTK 9.3.1

vtkTextRenderer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3
37 #ifndef vtkTextRenderer_h
38 #define vtkTextRenderer_h
39
40 #include "vtkObject.h"
41 #include "vtkRenderingCoreModule.h" // For export macro
42 #include "vtkTuple.h" // For metrics struct
43 #include "vtkVector.h" // For metrics struct
44
45 VTK_ABI_NAMESPACE_BEGIN
46 class vtkImageData;
47 class vtkPath;
48 class vtkStdString;
49 class vtkTextProperty;
50 VTK_ABI_NAMESPACE_END
51
52 namespace vtksys
53 {
54 class RegularExpression;
55 }
56
57 VTK_ABI_NAMESPACE_BEGIN
58
59 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
60 {
61 public:
62 vtkTextRendererCleanup();
63 ~vtkTextRendererCleanup();
64
65 private:
66 vtkTextRendererCleanup(const vtkTextRendererCleanup& other) = delete;
67 vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
68 };
69
70 class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
71 {
72 public:
73 struct Metrics
74 {
78 Metrics()
79 : BoundingBox(0)
80 , TopLeft(0)
81 , TopRight(0)
82 , BottomLeft(0)
83 , BottomRight(0)
84 , Ascent(0)
85 , Descent(0)
86 {
87 }
88
94 vtkTuple<int, 4> BoundingBox;
95
97
101 vtkVector2i TopLeft;
102 vtkVector2i TopRight;
103 vtkVector2i BottomLeft;
104 vtkVector2i BottomRight;
106
113 vtkVector2i Ascent;
114 vtkVector2i Descent;
116 };
117
118 vtkTypeMacro(vtkTextRenderer, vtkObject);
119 void PrintSelf(ostream& os, vtkIndent indent) override;
120
130 static vtkTextRenderer* New();
131
136 static vtkTextRenderer* GetInstance();
137
143 enum Backend
144 {
145 Default = -1,
146 Detect = 0,
147 FreeType,
148 MathText,
149
150 UserBackend = 16
151 };
152
154
157 vtkSetMacro(DefaultBackend, int);
158 vtkGetMacro(DefaultBackend, int);
160
162
165 virtual int DetectBackend(const vtkStdString& str);
167
171 virtual bool FreeTypeIsSupported() { return false; }
172 virtual bool MathTextIsSupported() { return false; }
173
175
182 bool GetBoundingBox(
183 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend = Default)
184 {
185 return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
186 }
188
190
195 bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
196 int backend = Default)
197 {
198 return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
199 }
201
203
217 bool RenderString(vtkTextProperty* tprop, const vtkStdString& str, vtkImageData* data,
218 int textDims[2], int dpi, int backend = Default)
219 {
220 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
221 }
223
225
231 int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
232 int targetHeight, int dpi, int backend = Default)
233 {
234 return this->GetConstrainedFontSizeInternal(
235 str, tprop, targetWidth, targetHeight, dpi, backend);
236 }
238
240
247 bool StringToPath(
248 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
249 {
250 return this->StringToPathInternal(tprop, str, path, dpi, backend);
251 }
253
260 void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
261
262 friend class vtkTextRendererCleanup;
263
264 protected:
265 vtkTextRenderer();
266 ~vtkTextRenderer() override;
267
269
272 virtual bool GetBoundingBoxInternal(
273 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
274 virtual bool GetMetricsInternal(
275 vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
276 virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
277 vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
278 virtual int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop,
279 int targetWidth, int targetHeight, int dpi, int backend) = 0;
280 virtual bool StringToPathInternal(
281 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
282 virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
284
289 static void SetInstance(vtkTextRenderer* instance);
290
292
295 static vtkTextRenderer* Instance;
296 static vtkTextRendererCleanup Cleanup;
298
299 vtksys::RegularExpression* MathTextRegExp;
300 vtksys::RegularExpression* MathTextRegExp2;
301 vtksys::RegularExpression* MathTextRegExpColumn;
302
304
307 virtual void CleanUpFreeTypeEscapes(vtkStdString& str);
309
313 int DefaultBackend;
314
315 private:
316 vtkTextRenderer(const vtkTextRenderer&) = delete;
317 void operator=(const vtkTextRenderer&) = delete;
318 };
319
320 VTK_ABI_NAMESPACE_END
321 #endif // vtkTextRenderer_h
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:52
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkPath
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:34
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:35
vtkTextRendererCleanup
Definition: vtkTextRenderer.h:60
vtkTextRendererCleanup::~vtkTextRendererCleanup
~vtkTextRendererCleanup()
vtkTextRendererCleanup::vtkTextRendererCleanup
vtkTextRendererCleanup()
vtkTextRenderer
Interface for generating images and path data from string data, using multiple backends.
Definition: vtkTextRenderer.h:71
vtkTextRenderer::DefaultBackend
int DefaultBackend
The backend to use when none is specified.
Definition: vtkTextRenderer.h:313
vtkTextRenderer::GetConstrainedFontSizeInternal
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.
vtkTextRenderer::StringToPath
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 ...
Definition: vtkTextRenderer.h:247
vtkTextRenderer::MathTextIsSupported
virtual bool MathTextIsSupported()
Definition: vtkTextRenderer.h:172
vtkTextRenderer::GetInstance
static vtkTextRenderer * GetInstance()
Return the singleton instance with no reference counting.
vtkTextRenderer::SetInstance
static void SetInstance(vtkTextRenderer *instance)
Set the singleton instance.
vtkTextRenderer::GetConstrainedFontSize
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...
Definition: vtkTextRenderer.h:231
vtkTextRenderer::RenderString
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...
Definition: vtkTextRenderer.h:217
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:182
vtkTextRenderer::New
static vtkTextRenderer * New()
This is a singleton pattern New.
vtkTextRenderer::Cleanup
static vtkTextRendererCleanup Cleanup
The singleton instance and the singleton cleanup instance.
Definition: vtkTextRenderer.h:296
vtkTextRenderer::MathTextRegExpColumn
vtksys::RegularExpression * MathTextRegExpColumn
Definition: vtkTextRenderer.h:301
vtkTextRenderer::SetScaleToPowerOfTwo
void SetScaleToPowerOfTwo(bool scale)
Set to true if the graphics implementation requires texture image dimensions to be a power of two.
Definition: vtkTextRenderer.h:260
vtkTextRenderer::SetScaleToPowerOfTwoInternal
virtual void SetScaleToPowerOfTwoInternal(bool scale)=0
Virtual methods for concrete implementations of the public methods.
vtkTextRenderer::Instance
static vtkTextRenderer * Instance
The singleton instance and the singleton cleanup instance.
Definition: vtkTextRenderer.h:295
vtkTextRenderer::vtkTextRenderer
vtkTextRenderer()
vtkTextRenderer::MathTextRegExp
vtksys::RegularExpression * MathTextRegExp
Definition: vtkTextRenderer.h:299
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.
vtkTextRenderer::RenderStringInternal
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.
vtkTextRenderer::Backend
Backend
Available backends.
Definition: vtkTextRenderer.h:144
vtkTextRenderer::FreeType
@ FreeType
Definition: vtkTextRenderer.h:147
vtkTextRenderer::MathText
@ MathText
Definition: vtkTextRenderer.h:148
vtkTextRenderer::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTextRenderer::FreeTypeIsSupported
virtual bool FreeTypeIsSupported()
Test for availability of various backends.
Definition: vtkTextRenderer.h:171
vtkTextRenderer::GetMetricsInternal
virtual bool GetMetricsInternal(vtkTextProperty *tprop, const vtkStdString &str, Metrics &metrics, int dpi, int backend)=0
Virtual methods for concrete implementations of the public methods.
vtkTextRenderer::MathTextRegExp2
vtksys::RegularExpression * MathTextRegExp2
Definition: vtkTextRenderer.h:300
vtkTextRenderer::GetMetrics
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.
Definition: vtkTextRenderer.h:195
vtkTextRenderer::StringToPathInternal
virtual bool StringToPathInternal(vtkTextProperty *tprop, const vtkStdString &str, vtkPath *path, int dpi, int backend)=0
Virtual methods for concrete implementations of the public methods.
vtkTextRenderer::CleanUpFreeTypeEscapes
virtual void CleanUpFreeTypeEscapes(vtkStdString &str)
Replace all instances of "\$" with "$".
vtkTextRenderer::DetectBackend
virtual int DetectBackend(const vtkStdString &str)
Determine the appropriate back end needed to render the given string.
vtkTextRenderer::~vtkTextRenderer
~vtkTextRenderer() override
vtkTuple< int, 4 >
vtkVector2i
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:450
vtkX3D::scale
@ scale
Definition: vtkX3D.h:229
vtkX3D::data
@ data
Definition: vtkX3D.h:315
vtksys
Definition: vtkVASPAnimationReader.h:23
vtkTextRenderer::Metrics
Definition: vtkTextRenderer.h:74
vtkTextRenderer::Metrics::BottomRight
vtkVector2i BottomRight
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:104
vtkTextRenderer::Metrics::Descent
vtkVector2i Descent
Vectors representing the rotated ascent and descent of the text.
Definition: vtkTextRenderer.h:114
vtkTextRenderer::Metrics::Ascent
vtkVector2i Ascent
Vectors representing the rotated ascent and descent of the text.
Definition: vtkTextRenderer.h:113
vtkTextRenderer::Metrics::Metrics
Metrics()
Construct a Metrics object with all members initialized to 0.
Definition: vtkTextRenderer.h:78
vtkTextRenderer::Metrics::TopRight
vtkVector2i TopRight
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:102
vtkTextRenderer::Metrics::BottomLeft
vtkVector2i BottomLeft
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:103
vtkTextRenderer::Metrics::TopLeft
vtkVector2i TopLeft
The corners of the rendered text (or background, if applicable), in pixels.
Definition: vtkTextRenderer.h:101
vtkTextRenderer::Metrics::BoundingBox
vtkTuple< int, 4 > BoundingBox
The axis-aligned bounding box of the rendered text and background, in pixels.
Definition: vtkTextRenderer.h:94
vtkObject.h
vtkTuple.h
vtkVector.h