1 /* 2 * FTGL - OpenGL font library 3 * 4 * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 #ifndef __FTGlyphContainer__ 27 #define __FTGlyphContainer__ 28 29 #include <ft2build.h> 30 #include FT_FREETYPE_H 31 #include FT_GLYPH_H 32 33 #include "FTGL/ftgl.h" 34 35 #include "FTVector.h" 36 37 class FTFace; 38 class FTGlyph; 39 class FTCharmap; 40 41 /** 42 * FTGlyphContainer holds the post processed FTGlyph objects. 43 * 44 * @see FTGlyph 45 */ 46 class FTGlyphContainer 47 { 48 typedef FTVector<FTGlyph*> GlyphVector; 49 public: 50 /** 51 * Constructor 52 * 53 * @param face The Freetype face 54 */ 55 FTGlyphContainer(FTFace* face); 56 57 /** 58 * Destructor 59 */ 60 ~FTGlyphContainer(); 61 62 /** 63 * Sets the character map for the face. 64 * 65 * @param encoding the Freetype encoding symbol. See above. 66 * @return <code>true</code> if charmap was valid 67 * and set correctly 68 */ 69 bool CharMap(FT_Encoding encoding); 70 71 /** 72 * Get the font index of the input character. 73 * 74 * @param characterCode The character code of the requested glyph in the 75 * current encoding eg apple roman. 76 * @return The font index for the character. 77 */ 78 unsigned int FontIndex(const unsigned int characterCode) const; 79 80 /** 81 * Adds a glyph to this glyph list. 82 * 83 * @param glyph The FTGlyph to be inserted into the container 84 * @param characterCode The char code of the glyph NOT the glyph index. 85 */ 86 void Add(FTGlyph* glyph, const unsigned int characterCode); 87 88 /** 89 * Get a glyph from the glyph list 90 * 91 * @param characterCode The char code of the glyph NOT the glyph index 92 * @return An FTGlyph or <code>null</code> is it hasn't been 93 * loaded. 94 */ 95 const FTGlyph* const Glyph(const unsigned int characterCode) const; 96 97 /** 98 * Get the bounding box for a character. 99 * @param characterCode The char code of the glyph NOT the glyph index 100 */ 101 FTBBox BBox(const unsigned int characterCode) const; 102 103 /** 104 * Returns the kerned advance width for a glyph. 105 * 106 * @param characterCode glyph index of the character 107 * @param nextCharacterCode the next glyph in a string 108 * @return advance width 109 */ 110 float Advance(const unsigned int characterCode, 111 const unsigned int nextCharacterCode); 112 113 /** 114 * Renders a character 115 * @param characterCode the glyph to be Rendered 116 * @param nextCharacterCode the next glyph in the string. Used for kerning. 117 * @param penPosition the position to Render the glyph 118 * @param renderMode Render mode to display 119 * @return The distance to advance the pen position after Rendering 120 */ 121 FTPoint Render(const unsigned int characterCode, 122 const unsigned int nextCharacterCode, 123 FTPoint penPosition, int renderMode); 124 125 /** 126 * Queries the Font for errors. 127 * 128 * @return The current error code. 129 */ Error()130 FT_Error Error() const { return err; } 131 132 private: 133 /** 134 * The FTGL face 135 */ 136 FTFace* face; 137 138 /** 139 * The Character Map object associated with the current face 140 */ 141 FTCharmap* charMap; 142 143 /** 144 * A structure to hold the glyphs 145 */ 146 GlyphVector glyphs; 147 148 /** 149 * Current error code. Zero means no error. 150 */ 151 FT_Error err; 152 }; 153 154 155 #endif // __FTGlyphContainer__ 156