00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 #ifndef SFML_FONT_HPP 00026 #define SFML_FONT_HPP 00027 00029 // Headers 00031 #include <SFML/System/Resource.hpp> 00032 #include <SFML/System/Vector2.hpp> 00033 #include <SFML/System/String.hpp> 00034 #include <SFML/Graphics/Glyph.hpp> 00035 #include <SFML/Graphics/Image.hpp> 00036 #include <SFML/Graphics/Rect.hpp> 00037 #include <map> 00038 #include <string> 00039 #include <vector> 00040 00041 00042 namespace sf 00043 { 00048 class SFML_API Font : public Resource<Font> 00049 { 00050 public : 00051 00058 Font(); 00059 00066 Font(const Font& copy); 00067 00074 ~Font(); 00075 00092 bool LoadFromFile(const std::string& filename); 00093 00111 bool LoadFromMemory(const void* data, std::size_t sizeInBytes); 00112 00123 const Glyph& GetGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const; 00124 00141 int GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) const; 00142 00154 int GetLineSpacing(unsigned int characterSize) const; 00155 00168 const Image& GetImage(unsigned int characterSize) const; 00169 00178 Font& operator =(const Font& right); 00179 00192 static const Font& GetDefaultFont(); 00193 00194 private : 00195 00201 struct GlyphInfo 00202 { 00203 Glyph GlyphDesc; 00204 IntRect TextureRect; 00205 }; 00206 00211 struct Row 00212 { 00213 Row(unsigned int top, unsigned int height) : Width(0), Top(top), Height(height) {} 00214 00215 unsigned int Width; 00216 unsigned int Top; 00217 unsigned int Height; 00218 }; 00219 00221 // Types 00223 typedef std::map<Uint32, GlyphInfo> GlyphTable; 00224 00229 struct Page 00230 { 00231 Page(); 00232 00233 GlyphTable Glyphs; 00234 Image Texture; 00235 unsigned int NextRow; 00236 std::vector<Row> Rows; 00237 }; 00238 00243 void Cleanup(); 00244 00255 GlyphInfo LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const; 00256 00267 IntRect FindGlyphRect(Page& page, unsigned int width, unsigned int height) const; 00268 00277 bool SetCurrentSize(unsigned int characterSize) const; 00278 00280 // Types 00282 typedef std::map<unsigned int, Page> PageTable; 00283 00285 // Member data 00287 void* myLibrary; 00288 void* myFace; 00289 int* myRefCount; 00290 mutable PageTable myPages; 00291 mutable std::vector<Uint8> myPixelBuffer; 00292 mutable unsigned int myCurrentSize; 00293 }; 00294 00295 } // namespace sf 00296 00297 00298 #endif // SFML_FONT_HPP 00299 00300
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::