00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef SFML_FONT_HPP
00026 #define SFML_FONT_HPP
00027
00029
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
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
00291 typedef std::map<unsigned int, Page> PageTable;
00292
00294
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 }
00305
00306
00307 #endif // SFML_FONT_HPP
00308
00309