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 __FTSize__ 27 #define __FTSize__ 28 29 30 #include <ft2build.h> 31 #include FT_FREETYPE_H 32 33 #include "FTGL/ftgl.h" 34 35 36 37 /** 38 * FTSize class provides an abstraction layer for the Freetype Size. 39 * 40 * @see "Freetype 2 Documentation" 41 * 42 */ 43 class FTSize 44 { 45 public: 46 /** 47 * Default Constructor 48 */ 49 FTSize(); 50 51 /** 52 * Destructor 53 */ 54 virtual ~FTSize(); 55 56 /** 57 * Sets the char size for the current face. 58 * 59 * This doesn't guarantee that the size was set correctly. Clients 60 * should check errors. If an error does occur the size object isn't modified. 61 * 62 * @param face Parent face for this size object 63 * @param point_size the face size in points (1/72 inch) 64 * @param x_resolution the horizontal resolution of the target device. 65 * @param y_resolution the vertical resolution of the target device. 66 * @return <code>true</code> if the size has been set. Clients should check Error() for more information if this function returns false() 67 */ 68 bool CharSize(FT_Face* face, unsigned int point_size, 69 unsigned int x_resolution, unsigned int y_resolution); 70 71 /** 72 * get the char size for the current face. 73 * 74 * @return The char size in points 75 */ 76 unsigned int CharSize() const; 77 78 /** 79 * Gets the global ascender height for the face in pixels. 80 * 81 * @return Ascender height 82 */ 83 float Ascender() const; 84 85 /** 86 * Gets the global descender height for the face in pixels. 87 * 88 * @return Ascender height 89 */ 90 float Descender() const; 91 92 /** 93 * Gets the global face height for the face. 94 * 95 * If the face is scalable this returns the height of the global 96 * bounding box which ensures that any glyph will be less than or 97 * equal to this height. If the font isn't scalable there is no 98 * guarantee that glyphs will not be taller than this value. 99 * 100 * @return height in pixels. 101 */ 102 float Height() const; 103 104 /** 105 * Gets the global face width for the face. 106 * 107 * If the face is scalable this returns the width of the global 108 * bounding box which ensures that any glyph will be less than or 109 * equal to this width. If the font isn't scalable this value is 110 * the max_advance for the face. 111 * 112 * @return width in pixels. 113 */ 114 float Width() const; 115 116 /** 117 * Gets the underline position for the face. 118 * 119 * @return underline position in pixels 120 */ 121 float Underline() const; 122 123 /** 124 * Queries for errors. 125 * 126 * @return The current error code. 127 */ Error()128 FT_Error Error() const { return err; } 129 130 private: 131 /** 132 * The current Freetype face that this FTSize object relates to. 133 */ 134 FT_Face* ftFace; 135 136 /** 137 * The Freetype size. 138 */ 139 FT_Size ftSize; 140 141 /** 142 * The size in points. 143 */ 144 unsigned int size; 145 146 /** 147 * The horizontal resolution. 148 */ 149 unsigned int xResolution; 150 151 /** 152 * The vertical resolution. 153 */ 154 unsigned int yResolution; 155 156 /** 157 * Current error code. Zero means no error. 158 */ 159 FT_Error err; 160 161 }; 162 163 #endif // __FTSize__ 164 165