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 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 27 #ifndef __FTTextureFontImpl__ 28 #define __FTTextureFontImpl__ 29 30 #include "FTFontImpl.h" 31 32 #include "../FTVector.h" 33 34 class FTTextureGlyph; 35 36 class FTTextureFontImpl : public FTFontImpl 37 { 38 friend class FTTextureFont; 39 40 protected: 41 FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath); 42 43 FTTextureFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes, 44 size_t bufferSizeInBytes); 45 46 virtual ~FTTextureFontImpl(); 47 48 /** 49 * Set the char size for the current face. 50 * 51 * @param size the face size in points (1/72 inch) 52 * @param res the resolution of the target device. 53 * @return <code>true</code> if size was set correctly 54 */ 55 virtual bool FaceSize(const unsigned int size, 56 const unsigned int res = 72); 57 58 virtual FTPoint Render(const char *s, const int len, 59 FTPoint position, FTPoint spacing, 60 int renderMode); 61 62 virtual FTPoint Render(const wchar_t *s, const int len, 63 FTPoint position, FTPoint spacing, 64 int renderMode); 65 66 private: 67 /** 68 * Create an FTTextureGlyph object for the base class. 69 */ 70 FTGlyph* MakeGlyphImpl(FT_GlyphSlot ftGlyph); 71 72 /** 73 * Get the size of a block of memory required to layout the glyphs 74 * 75 * Calculates a width and height based on the glyph sizes and the 76 * number of glyphs. It over estimates. 77 */ 78 inline void CalculateTextureSize(); 79 80 /** 81 * Creates a 'blank' OpenGL texture object. 82 * 83 * The format is GL_ALPHA and the params are 84 * GL_TEXTURE_WRAP_S = GL_CLAMP 85 * GL_TEXTURE_WRAP_T = GL_CLAMP 86 * GL_TEXTURE_MAG_FILTER = GL_LINEAR 87 * GL_TEXTURE_MIN_FILTER = GL_LINEAR 88 * Note that mipmapping is NOT used 89 */ 90 inline GLuint CreateTexture(); 91 92 /** 93 * The maximum texture dimension on this OpenGL implemetation 94 */ 95 GLsizei maximumGLTextureSize; 96 97 /** 98 * The minimum texture width required to hold the glyphs 99 */ 100 GLsizei textureWidth; 101 102 /** 103 * The minimum texture height required to hold the glyphs 104 */ 105 GLsizei textureHeight; 106 107 /** 108 *An array of texture ids 109 */ 110 FTVector<GLuint> textureIDList; 111 112 /** 113 * The max height for glyphs in the current font 114 */ 115 int glyphHeight; 116 117 /** 118 * The max width for glyphs in the current font 119 */ 120 int glyphWidth; 121 122 /** 123 * A value to be added to the height and width to ensure that 124 * glyphs don't overlap in the texture 125 */ 126 unsigned int padding; 127 128 /** 129 * 130 */ 131 unsigned int numGlyphs; 132 133 /** 134 */ 135 unsigned int remGlyphs; 136 137 /** 138 */ 139 int xOffset; 140 141 /** 142 */ 143 int yOffset; 144 145 /* Internal generic Render() implementation */ 146 template <typename T> 147 inline FTPoint RenderI(const T *s, const int len, 148 FTPoint position, FTPoint spacing, int mode); 149 }; 150 151 #endif // __FTTextureFontImpl__ 152 153