/usr/include/vtk-7.1/vtkTextRenderer.h is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkTextRenderer.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkTextRenderer
* @brief Interface for generating images and path data from
* string data, using multiple backends.
*
*
* vtkTextRenderer produces images, bounding boxes, and vtkPath
* objects that represent text. The advantage of using this class is to easily
* integrate mathematical expressions into renderings by automatically switching
* between FreeType and MathText backends. If the input string contains at least
* two "$" symbols separated by text, the MathText backend will be used. If
* the string does not meet this criteria, or if no MathText implementation is
* available, the faster FreeType rendering facilities are used. Literal $
* symbols can be used by escaping them with backslashes, "\$" (or "\\$" if the
* string is set programatically).
*
* For example, "Acceleration ($\\frac{m}{s^2}$)" will use MathText, but
* "\\$500, \\$100" will use FreeType.
*
* By default, the backend is set to Detect, which determines the backend based
* on the contents of the string. This can be changed by setting the
* DefaultBackend ivar.
*
* Note that this class is abstract -- link to the vtkRenderingFreetype module
* to get the default implementation.
*/
#ifndef vtkTextRenderer_h
#define vtkTextRenderer_h
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkObject.h"
#include "vtkTuple.h" // For metrics struct
#include "vtkVector.h" // For metrics struct
class vtkImageData;
class vtkPath;
class vtkStdString;
class vtkUnicodeString;
class vtkTextProperty;
namespace vtksys {
class RegularExpression;
}
class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
{
public:
vtkTextRendererCleanup();
~vtkTextRendererCleanup();
private:
vtkTextRendererCleanup(const vtkTextRendererCleanup& other) VTK_DELETE_FUNCTION;
vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs) VTK_DELETE_FUNCTION;
};
class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
{
public:
struct Metrics
{
/**
* Construct a Metrics object with all members initialized to 0.
*/
Metrics()
: BoundingBox(0),
TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0)
{
}
/**
* The axis-aligned bounding box of the rendered text and background, in
* pixels. The origin of the bounding box is the anchor point of the data
* when considering justification. Layout is { xMin, xMax, yMin, yMax }.
*/
vtkTuple<int, 4> BoundingBox;
//@{
/**
* The corners of the rendered text (or background, if applicable), in pixels.
* Uses the same origin as BoundingBox.
*/
vtkVector2i TopLeft;
vtkVector2i TopRight;
vtkVector2i BottomLeft;
vtkVector2i BottomRight;
};
//@}
vtkTypeMacro(vtkTextRenderer, vtkObject)
virtual void PrintSelf(ostream &os, vtkIndent indent);
/**
* This is a singleton pattern New. There will be only ONE reference
* to a vtkTextRenderer subclass object per process. Clients that
* call this method must use Delete() on the object so that reference
* counting will work. The single instance will be unreferenced when
* the program exits. You should just use the static GetInstance() method
* anyway to get the singleton. This method may return NULL if the object
* factory cannot find an override.
*/
static vtkTextRenderer *New();
/**
* Return the singleton instance with no reference counting. May return NULL
* if the object factory cannot find an override.
*/
static vtkTextRenderer* GetInstance();
/**
* Available backends. FreeType and MathText are provided in the default
* implementation of this interface. Enum values less than 16 are reserved.
* Custom overrides should define other backends starting at 16.
*/
enum Backend
{
Default = -1,
Detect = 0,
FreeType,
MathText,
UserBackend = 16
};
//@{
/**
* The backend to use when none is specified. Default: Detect
*/
vtkSetMacro(DefaultBackend, int)
vtkGetMacro(DefaultBackend, int)
//@}
//@{
/**
* Determine the appropriate back end needed to render the given string.
*/
virtual int DetectBackend(const vtkStdString &str);
virtual int DetectBackend(const vtkUnicodeString &str);
//@}
/**
* Test for availability of various backends
*/
virtual bool FreeTypeIsSupported() { return false; }
virtual bool MathTextIsSupported() { return false; }
//@{
/**
* Given a text property and a string, get the bounding box {xmin, xmax,
* ymin, ymax} of the rendered string in pixels. The origin of the bounding
* box is the anchor point described by the horizontal and vertical
* justification text property variables.
* Return true on success, false otherwise.
*/
bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
int bbox[4], int dpi, int backend = Default)
{
return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
}
bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str,
int bbox[4], int dpi, int backend = Default)
{
return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
}
//@}
//@{
/**
* Given a text property and a string, get some metrics for the rendered
* string.
* Return true on success, false otherwise.
*/
bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
Metrics &metrics, int dpi, int backend = Default)
{
return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
}
bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
Metrics &metrics, int dpi, int backend = Default)
{
return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
}
//@}
//@{
/**
* Given a text property and a string, this function initializes the
* vtkImageData *data and renders it in a vtkImageData.
* Return true on success, false otherwise. If using the overload that
* specifies "textDims", the array will be overwritten with the pixel width
* and height defining a tight bounding box around the text in the image,
* starting from the upper-right corner. This is used when rendering for a
* texture on graphics hardware that requires texture image dimensions to be
* a power of two; textDims can be used to determine the texture coordinates
* needed to cleanly fit the text on the target.
* The origin of the image's extents is aligned with the anchor point
* described by the text property's vertical and horizontal justification
* options.
*/
bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
vtkImageData *data, int textDims[2], int dpi,
int backend = Default)
{
return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
}
bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str,
vtkImageData *data, int textDims[2], int dpi,
int backend = Default)
{
return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
}
//@}
//@{
/**
* This function returns the font size (in points) and sets the size in @a
* tprop that is required to fit the string in the target rectangle. The
* computed font size will be set in @a tprop as well. If an error occurs,
* this function will return -1.
*/
int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop,
int targetWidth, int targetHeight, int dpi,
int backend = Default)
{
return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
targetHeight, dpi, backend);
}
int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop,
int targetWidth, int targetHeight, int dpi,
int backend = Default)
{
return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
targetHeight, dpi, backend);
}
//@}
//@{
/**
* Given a text property and a string, this function populates the vtkPath
* path with the outline of the rendered string. The origin of the path
* coordinates is aligned with the anchor point described by the text
* property's horizontal and vertical justification options.
* Return true on success, false otherwise.
*/
bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
vtkPath *path, int dpi, int backend = Default)
{
return this->StringToPathInternal(tprop, str, path, dpi, backend);
}
bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str,
vtkPath *path, int dpi, int backend = Default)
{
return this->StringToPathInternal(tprop, str, path, dpi, backend);
}
//@}
/**
* Set to true if the graphics implmentation requires texture image dimensions
* to be a power of two. Default is true, but this member will be set
* appropriately by vtkOpenGLRenderWindow::OpenGLInitContext when GL is
* inited.
*/
void SetScaleToPowerOfTwo(bool scale)
{
this->SetScaleToPowerOfTwoInternal(scale);
}
friend class vtkTextRendererCleanup;
protected:
vtkTextRenderer();
~vtkTextRenderer();
//@{
/**
* Virtual methods for concrete implementations of the public methods.
*/
virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
const vtkStdString &str,
int bbox[4], int dpi, int backend) = 0;
virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str,
int bbox[4], int dpi, int backend) = 0;
virtual bool GetMetricsInternal(vtkTextProperty *tprop,
const vtkStdString &str,
Metrics &metrics, int dpi, int backend) = 0;
virtual bool GetMetricsInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str,
Metrics &metrics, int dpi, int backend) = 0;
virtual bool RenderStringInternal(vtkTextProperty *tprop,
const vtkStdString &str,
vtkImageData *data, int textDims[2],
int dpi, int backend) = 0;
virtual bool RenderStringInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str,
vtkImageData *data, int textDims[2],
int dpi, int backend) = 0;
virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
vtkTextProperty *tprop,
int targetWidth, int targetHeight,
int dpi, int backend) = 0;
virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
vtkTextProperty *tprop,
int targetWidth, int targetHeight,
int dpi, int backend) = 0;
virtual bool StringToPathInternal(vtkTextProperty *tprop,
const vtkStdString &str, vtkPath *path,
int dpi, int backend) = 0;
virtual bool StringToPathInternal(vtkTextProperty *tprop,
const vtkUnicodeString &str, vtkPath *path,
int dpi, int backend) = 0;
virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
//@}
/**
* Set the singleton instance. Call Delete() on the supplied
* instance after setting it to fix the reference count.
*/
static void SetInstance(vtkTextRenderer *instance);
//@{
/**
* The singleton instance and the singleton cleanup instance.
*/
static vtkTextRenderer *Instance;
static vtkTextRendererCleanup Cleanup;
//@}
vtksys::RegularExpression *MathTextRegExp;
vtksys::RegularExpression *MathTextRegExp2;
//@{
/**
* Replace all instances of "\$" with "$".
*/
virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
//@}
/**
* The backend to use when none is specified. Default: Detect
*/
int DefaultBackend;
private:
vtkTextRenderer(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
void operator=(const vtkTextRenderer &) VTK_DELETE_FUNCTION;
};
#endif //vtkTextRenderer_h
|