VTK  9.1.0
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
52class vtkImageData;
53class vtkPath;
54class vtkStdString;
56class vtkTextProperty;
57
58namespace vtksys
59{
60class RegularExpression;
61}
62
63class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
64{
65public:
68
69private:
71 vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) = delete;
72};
73
74class VTKRENDERINGCORE_EXPORT vtkTextRenderer : public vtkObject
75{
76public:
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
123 void PrintSelf(ostream& os, vtkIndent indent) override;
124
135
141
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);
197
199
204 bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi,
205 int backend = Default)
206 {
207 return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
208 }
209 VTK_DEPRECATED_IN_9_1_0("Use bool GetMetrics(vtkTextProperty* tprop, const vtkStdString& str, "
210 "Metrics& metrics, int dpi, int backend)")
211 bool GetMetrics(vtkTextProperty* tprop, const vtkUnicodeString& str, Metrics& metrics, int dpi,
212 int backend = Default);
214
216
230 bool RenderString(vtkTextProperty* tprop, const vtkStdString& str, vtkImageData* data,
231 int textDims[2], int dpi, int backend = Default)
232 {
233 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
234 }
235 VTK_DEPRECATED_IN_9_1_0("Use bool RenderString(vtkTextProperty* tprop, const vtkStdString& str, "
236 "vtkImageData* data, int textDims[2], int dpi, int backend)")
237 bool RenderString(vtkTextProperty* tprop, const vtkUnicodeString& str, vtkImageData* data,
238 int textDims[2], int dpi, int backend = Default);
240
242
248 int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int targetWidth,
249 int targetHeight, int dpi, int backend = Default)
250 {
251 return this->GetConstrainedFontSizeInternal(
252 str, tprop, targetWidth, targetHeight, dpi, backend);
253 }
255 "Use int GetConstrainedFontSize(const vtkStdString& str, vtkTextProperty* tprop, int "
256 "targetWidth, int targetHeight, int dpi, int backend)")
257 int GetConstrainedFontSize(const vtkUnicodeString& str, vtkTextProperty* tprop, int targetWidth,
258 int targetHeight, int dpi, int backend = Default);
260
262
269 bool StringToPath(
270 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend = Default)
271 {
272 return this->StringToPathInternal(tprop, str, path, dpi, backend);
273 }
274 VTK_DEPRECATED_IN_9_1_0("Use bool StringToPath(vtkTextProperty* tprop, const vtkStdString& str, "
275 "vtkPath* path, int dpi, int backend)")
276 bool StringToPath(vtkTextProperty* tprop, const vtkUnicodeString& str, vtkPath* path, int dpi,
277 int backend = Default);
279
286 void SetScaleToPowerOfTwo(bool scale) { this->SetScaleToPowerOfTwoInternal(scale); }
287
289
290protected:
293
295
299 vtkTextProperty* tprop, const vtkStdString& str, int bbox[4], int dpi, int backend) = 0;
300 VTK_DEPRECATED_IN_9_1_0("Use bool GetBoundingBoxInternal(vtkTextProperty* tprop, const "
301 "vtkStdString& str, int bbox[4], int dpi, int backend)")
302 virtual bool GetBoundingBoxInternal(
303 vtkTextProperty* tprop, const vtkUnicodeString& str, int bbox[4], int dpi, int backend) = 0;
304 virtual bool GetMetricsInternal(
305 vtkTextProperty* tprop, const vtkStdString& str, Metrics& metrics, int dpi, int backend) = 0;
306 VTK_DEPRECATED_IN_9_1_0("Use bool GetMetricsInternal(vtkTextProperty* tprop, const vtkStdString& "
307 "str, Metrics& metrics, int dpi, int backend)")
308 virtual bool GetMetricsInternal(vtkTextProperty* tprop, const vtkUnicodeString& str,
309 Metrics& metrics, int dpi, int backend) = 0;
310 virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str,
311 vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
313 "Use bool RenderStringInternal(vtkTextProperty* tprop, const vtkStdString& str, vtkImageData* "
314 "data, int textDims[2], int dpi, int backend)")
315 virtual bool RenderStringInternal(vtkTextProperty* tprop, const vtkUnicodeString& str,
316 vtkImageData* data, int textDims[2], int dpi, int backend) = 0;
317 virtual int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop,
318 int targetWidth, int targetHeight, int dpi, int backend) = 0;
320 "Use int GetConstrainedFontSizeInternal(const vtkStdString& str, vtkTextProperty* tprop, int "
321 "targetWidth, int targetHeight, int dpi, int backend)")
322 virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString& str, vtkTextProperty* tprop,
323 int targetWidth, int targetHeight, int dpi, int backend) = 0;
324 virtual bool StringToPathInternal(
325 vtkTextProperty* tprop, const vtkStdString& str, vtkPath* path, int dpi, int backend) = 0;
326 VTK_DEPRECATED_IN_9_1_0("Use bool StringToPathInternal(vtkTextProperty* tprop, const "
327 "vtkStdString& str, vtkPath* path, int dpi, int backend)")
328 virtual bool StringToPathInternal(
329 vtkTextProperty* tprop, const vtkUnicodeString& str, vtkPath* path, int dpi, int backend) = 0;
330 virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
332
337 static void SetInstance(vtkTextRenderer* instance);
338
340
343 static vtkTextRenderer* Instance;
346
347 vtksys::RegularExpression* MathTextRegExp;
348 vtksys::RegularExpression* MathTextRegExp2;
349 vtksys::RegularExpression* MathTextRegExpColumn;
350
352
355 virtual void CleanUpFreeTypeEscapes(vtkStdString& str);
356 VTK_DEPRECATED_IN_9_1_0("Use void CleanUpFreeTypeEscapes(vtkStdString& str)")
357 virtual void CleanUpFreeTypeEscapes(vtkUnicodeString& str);
359
363 int DefaultBackend;
364
365private:
366 vtkTextRenderer(const vtkTextRenderer&) = delete;
367 void operator=(const vtkTextRenderer&) = delete;
368};
369
370#endif // vtkTextRenderer_h
topologically and geometrically regular array of data
Definition: vtkImageData.h:157
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:33
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
represent text properties.
Interface for generating images and path data from string data, using multiple backends.
virtual int DetectBackend(const vtkUnicodeString &str)
Determine the appropriate back end needed to render the given string.
virtual bool MathTextIsSupported()
static vtkTextRenderer * New()
This is a singleton pattern New.
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...
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.
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 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
String class that stores Unicode text.
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:478
@ scale
Definition: vtkX3D.h:235
@ data
Definition: vtkX3D.h:321
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_DEPRECATED_IN_9_1_0(reason)