SFML logo
  • Main Page
  • Modules
  • Classes
  • Files
  • File List

Font.hpp

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/Texture.hpp>
00036 #include <SFML/Graphics/Rect.hpp>
00037 #include <map>
00038 #include <string>
00039 #include <vector>
00040 
00041 
00042 namespace sf
00043 {
00044 class InputStream;
00045 
00050 class SFML_API Font : public Resource<Font>
00051 {
00052 public :
00053 
00060     Font();
00061 
00068     Font(const Font& copy);
00069 
00076     ~Font();
00077 
00094     bool LoadFromFile(const std::string& filename);
00095 
00113     bool LoadFromMemory(const void* data, std::size_t sizeInBytes);
00114 
00131     bool LoadFromStream(InputStream& stream);
00132 
00143     const Glyph& GetGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
00144 
00161     int GetKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
00162 
00174     int GetLineSpacing(unsigned int characterSize) const;
00175 
00188     const Texture& GetTexture(unsigned int characterSize) const;
00189 
00198     Font& operator =(const Font& right);
00199 
00212     static const Font& GetDefaultFont();
00213 
00214 private :
00215 
00220     struct Row
00221     {
00222         Row(unsigned int top, unsigned int height) : Width(0), Top(top), Height(height) {}
00223 
00224         unsigned int Width;  
00225         unsigned int Top;    
00226         unsigned int Height; 
00227     };
00228 
00230     // Types
00232     typedef std::map<Uint32, Glyph> GlyphTable; 
00233 
00238     struct Page
00239     {
00240         Page();
00241 
00242         GlyphTable       Glyphs;  
00243         sf::Texture      Texture; 
00244         unsigned int     NextRow; 
00245         std::vector<Row> Rows;    
00246     };
00247 
00252     void Cleanup();
00253 
00264     Glyph LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
00265 
00276     IntRect FindGlyphRect(Page& page, unsigned int width, unsigned int height) const;
00277 
00286     bool SetCurrentSize(unsigned int characterSize) const;
00287 
00289     // Types
00291     typedef std::map<unsigned int, Page> PageTable; 
00292 
00294     // Member data
00296     void*                      myLibrary;     
00297     void*                      myFace;        
00298     void*                      myStreamRec;   
00299     int*                       myRefCount;    
00300     mutable PageTable          myPages;       
00301     mutable std::vector<Uint8> myPixelBuffer; 
00302 };
00303 
00304 } // namespace sf
00305 
00306 
00307 #endif // SFML_FONT_HPP
00308 
00309 

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::