VTK
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 
00051 class vtkImageData;
00052 class vtkPath;
00053 class vtkStdString;
00054 class vtkUnicodeString;
00055 class vtkTextProperty;
00056 
00057 namespace vtksys {
00058 class RegularExpression;
00059 }
00060 
00061 class VTKRENDERINGCORE_EXPORT vtkTextRendererCleanup
00062 {
00063 public:
00064   vtkTextRendererCleanup();
00065   ~vtkTextRendererCleanup();
00066 
00067 private:
00068   vtkTextRendererCleanup(const vtkTextRendererCleanup& other); // no copy constructor
00069   vtkTextRendererCleanup& operator=(const vtkTextRendererCleanup& rhs); // no copy assignment
00070 };
00071 
00072 class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject
00073 {
00074 public:
00075   vtkTypeMacro(vtkTextRenderer, vtkObject)
00076   virtual void PrintSelf(ostream &os, vtkIndent indent);
00077 
00085   static vtkTextRenderer *New();
00086 
00089   static vtkTextRenderer* GetInstance();
00090 
00092 
00096   enum Backend
00097     {
00098     Default = -1,
00099     Detect = 0,
00100     FreeType,
00101     MathText,
00103 
00104     UserBackend = 16
00105     };
00106 
00108 
00109   vtkSetMacro(DefaultBackend, int)
00110   vtkGetMacro(DefaultBackend, int)
00112 
00114 
00115   virtual int DetectBackend(const vtkStdString &str);
00116   virtual int DetectBackend(const vtkUnicodeString &str);
00118 
00120 
00121   bool FreeTypeIsSupported() { return HasFreeType; }
00122   bool MathTextIsSupported() { return HasMathText; }
00124 
00126 
00134   bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str,
00135                       int bbox[4], int dpi = 120, int backend = Default)
00136   {
00137     return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
00138   }
00139   bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str,
00140                       int bbox[4], int dpi = 120, int backend = Default)
00141   {
00142     return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend);
00143   }
00145 
00147 
00158   bool RenderString(vtkTextProperty *tprop, const vtkStdString &str,
00159                     vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
00160                     int backend = Default)
00161   {
00162     return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
00163   }
00164   bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str,
00165                     vtkImageData *data, int textDims[2] = NULL, int dpi = 120,
00166                     int backend = Default)
00167   {
00168     return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend);
00169   }
00171 
00173 
00179   int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop,
00180                              int targetWidth, int targetHeight, int dpi = 120,
00181                              int backend = Default)
00182   {
00183     return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
00184                                                 targetHeight, dpi, backend);
00185   }
00186   int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop,
00187                              int targetWidth, int targetHeight, int dpi = 120,
00188                              int backend = Default)
00189   {
00190     return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth,
00191                                                 targetHeight, dpi, backend);
00192   }
00194 
00196 
00199   bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str,
00200                     vtkPath *path, int backend = Default)
00201   {
00202     return this->StringToPathInternal(tprop, str, path, backend);
00203   }
00204   bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str,
00205                     vtkPath *path, int backend = Default)
00206   {
00207     return this->StringToPathInternal(tprop, str, path, backend);
00208   }
00210 
00212 
00216   void SetScaleToPowerOfTwo(bool scale)
00217   {
00218     this->SetScaleToPowerOfTwoInternal(scale);
00219   }
00221 
00222   friend class vtkTextRendererCleanup;
00223 
00224 protected:
00225   vtkTextRenderer();
00226   ~vtkTextRenderer();
00227 
00229 
00230   virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
00231                                       const vtkStdString &str,
00232                                       int bbox[4], int dpi, int backend) = 0;
00233   virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop,
00234                                       const vtkUnicodeString &str,
00235                                       int bbox[4], int dpi, int backend) = 0;
00236   virtual bool RenderStringInternal(vtkTextProperty *tprop,
00237                                     const vtkStdString &str,
00238                                     vtkImageData *data, int textDims[2],
00239                                     int dpi, int backend) = 0;
00240   virtual bool RenderStringInternal(vtkTextProperty *tprop,
00241                                     const vtkUnicodeString &str,
00242                                     vtkImageData *data, int textDims[2],
00243                                     int dpi, int backend) = 0;
00244   virtual int GetConstrainedFontSizeInternal(const vtkStdString &str,
00245                                              vtkTextProperty *tprop,
00246                                              int targetWidth, int targetHeight,
00247                                              int dpi, int backend) = 0;
00248   virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str,
00249                                              vtkTextProperty *tprop,
00250                                              int targetWidth, int targetHeight,
00251                                              int dpi, int backend) = 0;
00252   virtual bool StringToPathInternal(vtkTextProperty *tprop,
00253                                     const vtkStdString &str, vtkPath *path,
00254                                     int backend) = 0;
00255   virtual bool StringToPathInternal(vtkTextProperty *tprop,
00256                                     const vtkUnicodeString &str, vtkPath *path,
00257                                     int backend) = 0;
00258   virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0;
00260 
00263   static void SetInstance(vtkTextRenderer *instance);
00264 
00266 
00267   static vtkTextRenderer *Instance;
00268   static vtkTextRendererCleanup Cleanup;
00270 
00271   vtksys::RegularExpression *MathTextRegExp;
00272   vtksys::RegularExpression *MathTextRegExp2;
00273 
00275 
00276   virtual void CleanUpFreeTypeEscapes(vtkStdString &str);
00277   virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str);
00279 
00281 
00283   bool HasFreeType;
00284   bool HasMathText;
00286 
00288   int DefaultBackend;
00289 
00290 private:
00291   vtkTextRenderer(const vtkTextRenderer &); // Not implemented.
00292   void operator=(const vtkTextRenderer &); // Not implemented.
00293 };
00294 
00295 #endif //__vtkTextRenderer_h