6 #include <msp/datafile/objectloader.h>
7 #include <msp/stringcodec/utf8.h>
8 #include "vertexarray.h"
13 class PrimitiveBuilder;
19 class Loader: public DataFile::CollectionObjectLoader<Font>
23 Loader(Font &, Collection &);
28 void kerning(unsigned, unsigned, float);
30 void texture_ref(const std::string &);
35 class Loader: public Msp::DataFile::ObjectLoader<Glyph>
40 void texcoords(float, float, float, float);
52 typedef std::map<unsigned, Glyph> GlyphMap;
53 typedef std::pair<unsigned, unsigned> KerningKey;
54 typedef std::map<KerningKey, float> KerningMap;
56 RefPtr<const Texture2D> texture;
67 void set_texture(const Texture2D &);
68 const Texture2D &get_texture() const;
69 void add_glyph(const Glyph &);
70 void set_kerning(unsigned, unsigned, float);
71 float get_native_size() const { return native_size; }
72 float get_ascent() const { return ascent; }
73 float get_descent() const { return descent; }
75 float get_string_width(const std::string &, StringCodec::Decoder &) const;
78 float get_string_width(const std::string &str) const
80 typename C::Decoder dec;
81 return get_string_width(str, dec);
84 float get_string_width(const std::string &str) const
85 { return get_string_width<StringCodec::Utf8>(str); }
87 /// Draws a string to the framebuffer with Immediate.
88 void draw_string(const std::string &, StringCodec::Decoder &, const Color & = Color()) const;
91 void draw_string(const std::string &str, const Color &color = Color()) const
93 typename C::Decoder dec;
94 draw_string(str, dec, color);
97 void draw_string(const std::string &str, const Color &color = Color()) const
98 { draw_string<StringCodec::Utf8>(str, color); }
100 /** Builds the primitives for a string. The PrimitiveBuilder should be
101 associated with a target that has at least VERTEX2 and TEXCOORD2 components.
102 The texture is not bound, to avoid unnecessary bindings when creating
104 void build_string(const std::string &, StringCodec::Decoder &, PrimitiveBuilder &) const;
107 void build_string(const std::string &str, PrimitiveBuilder &pb) const
109 typename C::Decoder dec;
110 build_string(str, dec, pb);
113 void build_string(const std::string &str, PrimitiveBuilder &pb) const
114 { return build_string<StringCodec::Utf8>(str, pb); }
117 void create_glyph_vertices(const Glyph &, VertexBuilder &) const;
118 float get_glyph_advance(unsigned, unsigned = 0) const;