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
46#ifndef vtkTextRenderer_h
47#define vtkTextRenderer_h
48
49#include "vtkObject.h"
50#include "vtkRenderingCoreModule.h" // For export macro
51#include "vtkTuple.h" // For metrics struct
52#include "vtkVector.h" // For metrics struct
53
54class vtkImageData;
55class vtkPath;
56class vtkStdString;
57class vtkTextProperty;
58
59namespace vtksys
60{
61class RegularExpression;
62}
63
64class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
65{
66public:
69
70private:
72 vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
73};
74
75class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
76{
77public:
78 struct Metrics
79 {
84 : BoundingBox(0)
85 , TopLeft(0)
86 , TopRight(0)
87 , BottomLeft(0)
88 , BottomRight(0)
89 , Ascent(0)
90 , Descent(0)
91 {
92 }
93
100
102
111
121 };
122
124 void PrintSelf(ostream& os, vtkIndent indent) override;
125
136
142
149 {
150 Default = -1,
151 Detect = 0,
154
155 UserBackend = 16
156 };
157
159
162 vtkSetMacro(DefaultBackend, int);
163 vtkGetMacro(DefaultBackend, int);
165
167
170 virtual int DetectBackend(const vtkStdString& 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 }
193
195
200 bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
201 int backend = Default)
202 {
203 return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
204 }
206
208
223 int textDims[2], int dpi, int backend = Default)
224 {
225 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
226 }
228
230
236 int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
237 int targetHeight, int dpi, int backend = Default)
238 {
239 return this->GetConstrainedFontSizeInternal(
240 str, tprop, targetWidth, targetHeight, dpi, backend);
241 }
243
245
253 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
254 {
255 return this->StringToPathInternal(tprop, str, path, dpi, backend);
256 }
258
265 void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
266
268
269protected:
272
274
278 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
279 virtual bool GetMetricsInternal(
280 vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
281 virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
282 vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
284 int targetWidth, int targetHeight, int dpi, int backend) = 0;
286 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
287 virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
289
294 static void SetInstance(vtkTextRenderer* instance);
295
297
303
304 vtksys::RegularExpression* MathTextRegExp;
305 vtksys::RegularExpression* MathTextRegExp2;
306 vtksys::RegularExpression* MathTextRegExpColumn;
307
309
314
319
320private:
321 vtkTextRenderer(const vtkTextRenderer&) = delete;
322 void operator=(const vtkTextRenderer&) = delete;
323};
324
325#endif // vtkTextRenderer_h
topologically and geometrically regular array of data
a simple class to control print indentation
Definition vtkIndent.h:34
abstract base class for most VTK objects
Definition vtkObject.h:57
concrete dataset representing a path defined by Bezier curves.
Definition vtkPath.h:33
Wrapper around std::string to keep symbols short.
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 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.
~vtkTextRenderer() override
templated base type for containers of constant size.
Definition vtkTuple.h:38
Some derived classes for the different vectors commonly used.
Definition vtkVector.h:419
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.