6 #include <msp/datafile/objectloader.h>
7 #include <msp/stringcodec/utf8.h>
12 class PrimitiveBuilder;
16 Stores a set of glyphs and creates strings out of them.
21 class Loader: public DataFile::CollectionObjectLoader<Font>
24 Loader(Font &f): Loader(f, 0) { }
25 Loader(Font &f, Collection &c): Loader(f, &c) { }
27 Loader(Font &, Collection *);
30 void kerning(unsigned, unsigned, float);
31 void ligature(unsigned, unsigned, unsigned);
33 void texture_ref(const std::string &);
38 class Loader: public Msp::DataFile::ObjectLoader<Glyph>
43 void texcoords(float, float, float, float);
57 typedef std::map<unsigned, Glyph> GlyphMap;
58 typedef std::pair<unsigned, unsigned> CodePair;
59 typedef std::map<CodePair, float> KerningMap;
60 typedef std::map<CodePair, unsigned> LigatureMap;
62 const Texture2D *texture;
70 LigatureMap ligatures;
76 void set_texture(const Texture2D &);
77 const Texture2D &get_texture() const;
79 /** Adds a glyph to the font. There must not be an existing glyph with the
81 void add_glyph(const Glyph &);
82 void set_kerning(unsigned, unsigned, float);
84 /** Returns the size used to generate the font texture. This serves as a
85 hint for obtaining the best quality when rendering strings. */
86 float get_native_size() const { return native_size; }
88 float get_ascent() const { return ascent; }
89 float get_descent() const { return descent; }
90 float get_cap_height() const { return cap_height; }
91 float get_x_height() const { return x_height; }
93 /** Returns the width of a string, in multiples of the font size. Scale the
94 result according to the size used in rendering. */
95 float get_string_width(const std::string &, StringCodec::Decoder &) const;
98 float get_string_width(const std::string &str) const
100 typename C::Decoder dec;
101 return get_string_width(str, dec);
104 float get_string_width(const std::string &str) const
105 { return get_string_width<StringCodec::Utf8>(str); }
107 /** Builds the primitives for a string. Two-dimensional vertex and texture
108 coordinates are generated. Size 1.0 is used for building; set up the
109 builder's matrix before the call. The texture is not bound, to avoid
110 unnecessary bindings when creating meshes. */
111 void build_string(const std::string &, StringCodec::Decoder &, PrimitiveBuilder &) const;
114 void build_string(const std::string &str, PrimitiveBuilder &pb) const
116 typename C::Decoder dec;
117 build_string(str, dec, pb);
120 void build_string(const std::string &str, PrimitiveBuilder &pb) const
121 { return build_string<StringCodec::Utf8>(str, pb); }
124 void create_glyph_quad(const Glyph &, PrimitiveBuilder &) const;
125 float get_glyph_advance(unsigned, unsigned = 0) const;
126 unsigned get_ligature(unsigned, unsigned) const;