VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/Core/vtkTextRenderer.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTextRenderer.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00045 #ifndef vtkTextRenderer_h
00046 #define vtkTextRenderer_h
00047 
00048 #include "vtkRenderingCoreModule.h" // For export macro
00049 #include "vtkObject.h"
00050 #include "vtkTuple.h"  // For metrics struct
00051 #include "vtkVector.h" // For metrics struct
00052 
00053 class vtkImageData;
00054 class vtkPath;
00055 class vtkStdString;
00056 class vtkUnicodeString;
00057 class vtkTextProperty;
00058 
00059 namespace vtksys {
00060 class RegularExpression;
00061 }
00062 
00063 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
00064 {
00065 public:
00066   vtkTextRendererCleanup();
00067   ~vtkTextRendererCleanup();
00068 
00069 private:
00070   vtkTextRendererCleanup(const vtkTextRendererCleanup& other); // no copy constructor
00071   vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs); // no copy assignment
00072 };
00073 
00074 class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
00075 {
00076 public:
00077   struct Metrics
00078   {
00080 
00081     Metrics()
00082       : BoundingBox(0),
00083         TopLeft(0), TopRight(0), BottomLeft(0), BottomRight(0)
00084     {
00085     }
00087 
00092     vtkTuple<int, 4> BoundingBox;
00093 
00095 
00097     vtkVector2i TopLeft;
00098     vtkVector2i TopRight;
00099     vtkVector2i BottomLeft;
00100     vtkVector2i BottomRight;
00101   };
00103 
00104   vtkTypeMacro(vtkTextRenderer, vtkObject)
00105   virtual void PrintSelf(ostream &os, vtkIndent indent);
00106 
00114   static vtkTextRenderer *New();
00115 
00118   static vtkTextRenderer* GetInstance();
00119 
00121 
00125   enum Backend
00126     {
00127     Default = -1,
00128     Detect = 0,
00129     FreeType,
00130     MathText,
00132 
00133     UserBackend = 16
00134     };
00135 
00137 
00138   vtkSetMacro(DefaultBackend, int)
00139   vtkGetMacro(DefaultBackend, int)
00141 
00143 
00144   virtual int DetectBackend(const vtkStdString &str);
00145   virtual int DetectBackend(const vtkUnicodeString &str);
00147 
00149 
00150   bool FreeTypeIsSupported() { return HasFreeType; }
00151   bool MathTextIsSupported() { return HasMathText; }
00153 
00155 
00161   bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
00162                       int bbox[4], int dpi = 120, int backend = Default)
00163   {
00164     return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
00165   }
00166   bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str,
00167                       int bbox[4], int dpi = 120, int backend = Default)
00168   {
00169     return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
00170   }
00172 
00173 
00175 
00179   bool GetMetrics(vtkTextProperty *tprop, const vtkStdString &str,
00180                   Metrics &metrics, int dpi = 120, int backend = Default)
00181   {
00182     return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
00183   }
00184   bool GetMetrics(vtkTextProperty *tprop, const vtkUnicodeString &str,
00185                   Metrics &metrics, int dpi = 120, int backend = Default)
00186   {
00187     return this->GetMetricsInternal(tprop, str, metrics, dpi, backend);
00188   }
00190 
00192 
00205   bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
00206                     vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
00207                     int backend = Default)
00208   {
00209     return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
00210   }
00211   bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str,
00212                     vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
00213                     int backend = Default)
00214   {
00215     return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
00216   }
00218 
00220 
00226   int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop,
00227                              int targetWidth, int targetHeight, int dpi = 120,
00228                              int backend = Default)
00229   {
00230     return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
00231                                                 targetHeight, dpi, backend);
00232   }
00233   int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop,
00234                              int targetWidth, int targetHeight, int dpi = 120,
00235                              int backend = Default)
00236   {
00237     return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
00238                                                 targetHeight, dpi, backend);
00239   }
00241 
00243 
00248   bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
00249                     vtkPath *path, int backend = Default)
00250   {
00251     return this->StringToPathInternal(tprop, str, path, backend);
00252   }
00253   bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str,
00254                     vtkPath *path, int backend = Default)
00255   {
00256     return this->StringToPathInternal(tprop, str, path, backend);
00257   }
00259 
00261 
00265   void SetScaleToPowerOfTwo(bool scale)
00266   {
00267     this->SetScaleToPowerOfTwoInternal(scale);
00268   }
00270 
00271   friend class vtkTextRendererCleanup;
00272 
00273 protected:
00274   vtkTextRenderer();
00275   ~vtkTextRenderer();
00276 
00278 
00279   virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
00280                                       const vtkStdString &str,
00281                                       int bbox[4], int dpi, int backend) = 0;
00282   virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
00283                                       const vtkUnicodeString &str,
00284                                       int bbox[4], int dpi, int backend) = 0;
00285   virtual bool GetMetricsInternal(vtkTextProperty *tprop,
00286                                   const vtkStdString &str,
00287                                   Metrics &metrics, int dpi, int backend) = 0;
00288   virtual bool GetMetricsInternal(vtkTextProperty *tprop,
00289                                   const vtkUnicodeString &str,
00290                                   Metrics &metrics, int dpi, int backend) = 0;
00291   virtual bool RenderStringInternal(vtkTextProperty *tprop,
00292                                     const vtkStdString &str,
00293                                     vtkImageData *data, int textDims[2],
00294                                     int dpi, int backend) = 0;
00295   virtual bool RenderStringInternal(vtkTextProperty *tprop,
00296                                     const vtkUnicodeString &str,
00297                                     vtkImageData *data, int textDims[2],
00298                                     int dpi, int backend) = 0;
00299   virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
00300                                              vtkTextProperty *tprop,
00301                                              int targetWidth, int targetHeight,
00302                                              int dpi, int backend) = 0;
00303   virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
00304                                              vtkTextProperty *tprop,
00305                                              int targetWidth, int targetHeight,
00306                                              int dpi, int backend) = 0;
00307   virtual bool StringToPathInternal(vtkTextProperty *tprop,
00308                                     const vtkStdString &str, vtkPath *path,
00309                                     int backend) = 0;
00310   virtual bool StringToPathInternal(vtkTextProperty *tprop,
00311                                     const vtkUnicodeString &str, vtkPath *path,
00312                                     int backend) = 0;
00313   virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
00315 
00318   static void SetInstance(vtkTextRenderer *instance);
00319 
00321 
00322   static vtkTextRenderer *Instance;
00323   static vtkTextRendererCleanup Cleanup;
00325 
00326   vtksys::RegularExpression *MathTextRegExp;
00327   vtksys::RegularExpression *MathTextRegExp2;
00328 
00330 
00331   virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
00332   virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
00334 
00336 
00338   bool HasFreeType;
00339   bool HasMathText;
00341 
00343   int DefaultBackend;
00344 
00345 private:
00346   vtkTextRenderer(const vtkTextRenderer &); // Not implemented.
00347   void operator=(const vtkTextRenderer &); // Not implemented.
00348 };
00349 
00350 #endif //vtkTextRenderer_h