VTK
|
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 00068 class VTKRENDERINGCORE_EXPORT vtkTextRenderer: public vtkObject 00069 { 00070 public: 00071 vtkTypeMacro(vtkTextRenderer, vtkObject) 00072 virtual void PrintSelf(ostream &os, vtkIndent indent); 00073 00081 static vtkTextRenderer *New(); 00082 00085 static vtkTextRenderer* GetInstance(); 00086 00088 00092 enum Backend 00093 { 00094 Default = -1, 00095 Detect = 0, 00096 FreeType, 00097 MathText, 00099 00100 UserBackend = 16 00101 }; 00102 00104 00105 vtkSetMacro(DefaultBackend, int) 00106 vtkGetMacro(DefaultBackend, int) 00108 00110 00111 virtual int DetectBackend(const vtkStdString &str); 00112 virtual int DetectBackend(const vtkUnicodeString &str); 00114 00116 00117 bool FreeTypeIsSupported() { return HasFreeType; } 00118 bool MathTextIsSupported() { return HasMathText; } 00120 00122 00130 bool GetBoundingBox(vtkTextProperty *tprop, const vtkStdString &str, 00131 int bbox[4], int dpi = 120, int backend = Default) 00132 { 00133 return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend); 00134 } 00135 bool GetBoundingBox(vtkTextProperty *tprop, const vtkUnicodeString &str, 00136 int bbox[4], int dpi = 120, int backend = Default) 00137 { 00138 return this->GetBoundingBoxInternal(tprop, str, bbox, dpi, backend); 00139 } 00141 00143 00154 bool RenderString(vtkTextProperty *tprop, const vtkStdString &str, 00155 vtkImageData *data, int textDims[2] = NULL, int dpi = 120, 00156 int backend = Default) 00157 { 00158 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend); 00159 } 00160 bool RenderString(vtkTextProperty *tprop, const vtkUnicodeString &str, 00161 vtkImageData *data, int textDims[2] = NULL, int dpi = 120, 00162 int backend = Default) 00163 { 00164 return this->RenderStringInternal(tprop, str, data, textDims, dpi, backend); 00165 } 00167 00169 00175 int GetConstrainedFontSize(const vtkStdString &str, vtkTextProperty *tprop, 00176 int targetWidth, int targetHeight, int dpi = 120, 00177 int backend = Default) 00178 { 00179 return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth, 00180 targetHeight, dpi, backend); 00181 } 00182 int GetConstrainedFontSize(const vtkUnicodeString &str, vtkTextProperty *tprop, 00183 int targetWidth, int targetHeight, int dpi = 120, 00184 int backend = Default) 00185 { 00186 return this->GetConstrainedFontSizeInternal(str, tprop, targetWidth, 00187 targetHeight, dpi, backend); 00188 } 00190 00192 00195 bool StringToPath(vtkTextProperty *tprop, const vtkStdString &str, 00196 vtkPath *path, int backend = Default) 00197 { 00198 return this->StringToPathInternal(tprop, str, path, backend); 00199 } 00200 bool StringToPath(vtkTextProperty *tprop, const vtkUnicodeString &str, 00201 vtkPath *path, int backend = Default) 00202 { 00203 return this->StringToPathInternal(tprop, str, path, backend); 00204 } 00206 00208 00212 void SetScaleToPowerOfTwo(bool scale) 00213 { 00214 this->SetScaleToPowerOfTwoInternal(scale); 00215 } 00217 00218 friend class vtkTextRendererCleanup; 00219 00220 protected: 00221 vtkTextRenderer(); 00222 ~vtkTextRenderer(); 00223 00225 00226 virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop, 00227 const vtkStdString &str, 00228 int bbox[4], int dpi, int backend) = 0; 00229 virtual bool GetBoundingBoxInternal(vtkTextProperty *tprop, 00230 const vtkUnicodeString &str, 00231 int bbox[4], int dpi, int backend) = 0; 00232 virtual bool RenderStringInternal(vtkTextProperty *tprop, 00233 const vtkStdString &str, 00234 vtkImageData *data, int textDims[2], 00235 int dpi, int backend) = 0; 00236 virtual bool RenderStringInternal(vtkTextProperty *tprop, 00237 const vtkUnicodeString &str, 00238 vtkImageData *data, int textDims[2], 00239 int dpi, int backend) = 0; 00240 virtual int GetConstrainedFontSizeInternal(const vtkStdString &str, 00241 vtkTextProperty *tprop, 00242 int targetWidth, int targetHeight, 00243 int dpi, int backend) = 0; 00244 virtual int GetConstrainedFontSizeInternal(const vtkUnicodeString &str, 00245 vtkTextProperty *tprop, 00246 int targetWidth, int targetHeight, 00247 int dpi, int backend) = 0; 00248 virtual bool StringToPathInternal(vtkTextProperty *tprop, 00249 const vtkStdString &str, vtkPath *path, 00250 int backend) = 0; 00251 virtual bool StringToPathInternal(vtkTextProperty *tprop, 00252 const vtkUnicodeString &str, vtkPath *path, 00253 int backend) = 0; 00254 virtual void SetScaleToPowerOfTwoInternal(bool scale) = 0; 00256 00259 static void SetInstance(vtkTextRenderer *instance); 00260 00262 00263 static vtkTextRenderer *Instance; 00264 static vtkTextRendererCleanup Cleanup; 00266 00267 vtksys::RegularExpression *MathTextRegExp; 00268 vtksys::RegularExpression *MathTextRegExp2; 00269 00271 00272 virtual void CleanUpFreeTypeEscapes(vtkStdString &str); 00273 virtual void CleanUpFreeTypeEscapes(vtkUnicodeString &str); 00275 00277 00279 bool HasFreeType; 00280 bool HasMathText; 00282 00284 int DefaultBackend; 00285 00286 private: 00287 vtkTextRenderer(const vtkTextRenderer &); // Not implemented. 00288 void operator=(const vtkTextRenderer &); // Not implemented. 00289 }; 00290 00291 #endif //__vtkTextRenderer_h