/Code/Angel/Libraries/FTGLES/ftgles/src/FTGL/FTGlyph.h

http://angel-engine.googlecode.com/ · C++ Header · 200 lines · 45 code · 24 blank · 131 comment · 0 complexity · e5286040b12cfe7e3a2f54e8abf63a75 MD5 · raw file

  1. /*
  2. * FTGL - OpenGL font library
  3. *
  4. * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
  5. * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
  6. * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sublicense, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  22. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #ifndef __ftgl__
  28. # include <FTGL/ftgles.h>
  29. #endif
  30. #ifndef __FTGlyph__
  31. #define __FTGlyph__
  32. #ifdef __cplusplus
  33. class FTGlyphImpl;
  34. /**
  35. * FTGlyph is the base class for FTGL glyphs.
  36. *
  37. * It provides the interface between Freetype glyphs and their openGL
  38. * renderable counterparts. This is an abstract class and derived classes
  39. * must implement the <code>Render</code> function.
  40. *
  41. * @see FTBBox
  42. * @see FTPoint
  43. */
  44. class FTGL_EXPORT FTGlyph
  45. {
  46. protected:
  47. /**
  48. * Create a glyph.
  49. *
  50. * @param glyph The Freetype glyph to be processed
  51. */
  52. FTGlyph(FT_GlyphSlot glyph);
  53. private:
  54. /**
  55. * Internal FTGL FTGlyph constructor. For private use only.
  56. *
  57. * @param pImpl Internal implementation object. Will be destroyed
  58. * upon FTGlyph deletion.
  59. */
  60. FTGlyph(FTGlyphImpl *pImpl);
  61. /* Allow our internal subclasses to access the private constructor */
  62. friend class FTBitmapGlyph;
  63. friend class FTBufferGlyph;
  64. //friend class FTExtrudeGlyph;
  65. friend class FTOutlineGlyph;
  66. friend class FTPixmapGlyph;
  67. friend class FTPolygonGlyph;
  68. friend class FTTextureGlyph;
  69. public:
  70. /**
  71. * Destructor
  72. */
  73. virtual ~FTGlyph();
  74. /**
  75. * Renders this glyph at the current pen position.
  76. *
  77. * @param pen The current pen position.
  78. * @param renderMode Render mode to display
  79. * @return The advance distance for this glyph.
  80. */
  81. virtual const FTPoint& Render(const FTPoint& pen, int renderMode) = 0;
  82. /**
  83. * Return the advance width for this glyph.
  84. *
  85. * @return advance width.
  86. */
  87. virtual float Advance() const;
  88. /**
  89. * Return the bounding box for this glyph.
  90. *
  91. * @return bounding box.
  92. */
  93. virtual const FTBBox& BBox() const;
  94. /**
  95. * Queries for errors.
  96. *
  97. * @return The current error code.
  98. */
  99. virtual FT_Error Error() const;
  100. private:
  101. /**
  102. * Internal FTGL FTGlyph implementation object. For private use only.
  103. */
  104. FTGlyphImpl *impl;
  105. };
  106. #endif //__cplusplus
  107. FTGL_BEGIN_C_DECLS
  108. /**
  109. * FTGLglyph is the base class for FTGL glyphs.
  110. *
  111. * It provides the interface between Freetype glyphs and their openGL
  112. * renderable counterparts. This is an abstract class and derived classes
  113. * must implement the ftglRenderGlyph() function.
  114. */
  115. struct _FTGLGlyph;
  116. typedef struct _FTGLglyph FTGLglyph;
  117. /**
  118. * Create a custom FTGL glyph object.
  119. * FIXME: maybe get rid of "base" and have advanceCallback etc. functions
  120. *
  121. * @param base The base FTGLglyph* to subclass.
  122. * @param data A pointer to private data that will be passed to callbacks.
  123. * @param renderCallback A rendering callback function.
  124. * @param destroyCallback A callback function to be called upon destruction.
  125. * @return An FTGLglyph* object.
  126. */
  127. FTGL_EXPORT FTGLglyph *ftglCreateCustomGlyph(FTGLglyph *base, void *data,
  128. void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
  129. int, FTGL_DOUBLE *, FTGL_DOUBLE *),
  130. void (*destroyCallback) (FTGLglyph *, void *));
  131. /**
  132. * Destroy an FTGL glyph object.
  133. *
  134. * @param glyph An FTGLglyph* object.
  135. */
  136. FTGL_EXPORT void ftglDestroyGlyph(FTGLglyph *glyph);
  137. /**
  138. * Render a glyph at the current pen position and compute the corresponding
  139. * advance.
  140. *
  141. * @param glyph An FTGLglyph* object.
  142. * @param penx The current pen's X position.
  143. * @param peny The current pen's Y position.
  144. * @param renderMode Render mode to display
  145. * @param advancex A pointer to an FTGL_DOUBLE where to write the advance's X
  146. * component.
  147. * @param advancey A pointer to an FTGL_DOUBLE where to write the advance's Y
  148. * component.
  149. */
  150. FTGL_EXPORT void ftglRenderGlyph(FTGLglyph *glyph, FTGL_DOUBLE penx,
  151. FTGL_DOUBLE peny, int renderMode,
  152. FTGL_DOUBLE *advancex, FTGL_DOUBLE *advancey);
  153. /**
  154. * Return the advance for a glyph.
  155. *
  156. * @param glyph An FTGLglyph* object.
  157. * @return The advance's X component.
  158. */
  159. FTGL_EXPORT float ftglGetGlyphAdvance(FTGLglyph *glyph);
  160. /**
  161. * Return the bounding box for a glyph.
  162. *
  163. * @param glyph An FTGLglyph* object.
  164. * @param bounds An array of 6 float values where the bounding box's lower
  165. * left near and upper right far 3D coordinates will be stored.
  166. */
  167. FTGL_EXPORT void ftglGetGlyphBBox(FTGLglyph *glyph, float bounds[6]);
  168. /**
  169. * Query a glyph for errors.
  170. *
  171. * @param glyph An FTGLglyph* object.
  172. * @return The current error code.
  173. */
  174. FTGL_EXPORT FT_Error ftglGetGlyphError(FTGLglyph* glyph);
  175. FTGL_END_C_DECLS
  176. #endif // __FTGlyph__