1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkTextRendererStringToImage.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 
16 /**
17  * @class   vtkTextRendererStringToImage
18  * @brief   uses vtkTextRenderer to render the
19  * supplied text to an image.
20 */
21 
22 #ifndef vtkTextRendererStringToImage_h
23 #define vtkTextRendererStringToImage_h
24 
25 #include "vtkRenderingFreeTypeModule.h" // For export macro
26 #include "vtkStringToImage.h"
27 
28 class VTKRENDERINGFREETYPE_EXPORT vtkTextRendererStringToImage :
29     public vtkStringToImage
30 {
31 public:
32   vtkTypeMacro(vtkTextRendererStringToImage, vtkStringToImage);
33   void PrintSelf(ostream &os, vtkIndent indent) override;
34 
35   static vtkTextRendererStringToImage *New();
36 
37   //@{
38   /**
39    * Given a text property and a string, get the bounding box [xmin, xmax] x
40    * [ymin, ymax]. Note that this is the bounding box of the area
41    * where actual pixels will be written, given a text/pen/baseline location
42    * of (0,0).
43    * For example, if the string starts with a 'space', or depending on the
44    * orientation, you can end up with a [-20, -10] x [5, 10] bbox (the math
45    * to get the real bbox is straightforward).
46    * Return 1 on success, 0 otherwise.
47    * You can use IsBoundingBoxValid() to test if the computed bbox
48    * is valid (it may not if GetBoundingBox() failed or if the string
49    * was empty).
50    */
51   vtkVector2i GetBounds(vtkTextProperty *property,
52                                 const vtkUnicodeString& string,
53                                 int dpi) override;
54   vtkVector2i GetBounds(vtkTextProperty *property,
55                                 const vtkStdString& string,
56                                 int dpi) override;
57   //@}
58 
59   //@{
60   /**
61    * Given a text property and a string, this function initializes the
62    * vtkImageData *data and renders it in a vtkImageData. textDims, if provided,
63    * will be overwritten by the pixel width and height of the rendered string.
64    * This is useful when ScaleToPowerOfTwo is true, and the image dimensions may
65    * not match the dimensions of the rendered text.
66    */
67   int RenderString(vtkTextProperty *property,
68                            const vtkUnicodeString& string,
69                            int dpi,
70                            vtkImageData *data,
71                            int textDims[2] = nullptr) override;
72   int RenderString(vtkTextProperty *property,
73                            const vtkStdString& string,
74                            int dpi,
75                            vtkImageData *data,
76                            int textDims[2] = nullptr) override;
77   //@}
78 
79   /**
80    * Should we produce images at powers of 2, makes rendering on old OpenGL
81    * hardware easier. Default is false.
82    */
83   void SetScaleToPowerOfTwo(bool scale) override;
84 
85   /**
86    * Make a deep copy of the supplied utility class.
87    */
88   void DeepCopy(vtkTextRendererStringToImage *utility);
89 
90 protected:
91   vtkTextRendererStringToImage();
92   ~vtkTextRendererStringToImage() override;
93 
94   class Internals;
95   Internals* Implementation;
96 
97 private:
98   vtkTextRendererStringToImage(const vtkTextRendererStringToImage &) = delete;
99   void operator=(const vtkTextRendererStringToImage &) = delete;
100 };
101 
102 #endif //vtkTextRendererStringToImage_h
103