VTK  9.7.20260928
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
36
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
45
46VTK_ABI_NAMESPACE_BEGIN
47class vtkImageData;
48class vtkPath;
49class vtkStdString;
50class vtkTextProperty;
51VTK_ABI_NAMESPACE_END
52
53namespace vtksys
54{
55class RegularExpression;
56}
57
58VTK_ABI_NAMESPACE_BEGIN
59
60class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
61{
62public:
65
66private:
68 vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
69};
70
71class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkTextRenderer : public vtkObject
72{
73public:
118
120 void PrintSelf(ostream& os, vtkIndent indent) override;
121
132
138
145 {
150
152 };
153
155
158 vtkSetMacro(DefaultBackend, int);
159 vtkGetMacro(DefaultBackend, int);
161
163
166 virtual int DetectBackend(const vtkStdString& str);
168
172 virtual bool FreeTypeIsSupported() { return false; }
173 virtual bool MathTextIsSupported() { return false; }
174
176
184 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend = Default)
185 {
186 return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
187 }
188
189
191
196 bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
197 int backend = Default)
198 {
199 return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
200 }
201
202
204
219 int textDims[2], int dpi, int backend = Default)
220 {
221 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
222 }
223
224
226
232 int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
233 int targetHeight, int dpi, int backend = Default)
234 {
236 str, tprop, targetWidth, targetHeight, dpi, backend);
237 }
238
239
241
249 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
250 {
251 return this->StringToPathInternal(tprop, str, path, dpi, backend);
252 }
253
254
261 void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
262
264
265protected:
268
270
274 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
275 virtual bool GetMetricsInternal(
276 vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
277 virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
278 vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
280 int targetWidth, int targetHeight, int dpi, int backend) = 0;
282 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
283 virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
285
290 static void SetInstance(vtkTextRenderer* instance);
291
293
299
300 vtksys::RegularExpression* MathTextRegExp;
301 vtksys::RegularExpression* MathTextRegExp2;
302 vtksys::RegularExpression* MathTextRegExpColumn;
303
305
310
315
316private:
317 vtkTextRenderer(const vtkTextRenderer&) = delete;
318 void operator=(const vtkTextRenderer&) = delete;
319};
320
321VTK_ABI_NAMESPACE_END
322#endif // vtkTextRenderer_h
topologically and geometrically regular array of data
a simple class to control print indentation
Definition vtkIndent.h:108
concrete dataset representing a path defined by Bezier curves.
Definition vtkPath.h:45
Wrapper around std::string to keep symbols short.
represent text properties.
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 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...
static vtkTextRenderer * New()
This is a singleton pattern New.
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 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.
static vtkTextRenderer * GetInstance()
Return the singleton instance with no reference counting.
friend class vtkTextRendererCleanup
~vtkTextRenderer() override
templated base type for containers of constant size.
Definition vtkTuple.h:30
Some derived classes for the different vectors commonly used.
Definition vtkVector.h:450
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.
#define VTK_MARSHALAUTO