]> git.tdb.fi Git - libs/gl.git/blobdiff - source/font.cpp
Support embedding textures inside font files
[libs/gl.git] / source / font.cpp
index 766f011a97dc55708b3fb11da395342facfb6a92..f82b45d8ac81fe7bb3ac30b7f70be453b2a720b7 100644 (file)
@@ -18,14 +18,25 @@ namespace GL {
 
 Font::Font():
        tex(0),
+       own_tex(false),
        default_size(1),
        ascent(1),
        descent(0)
 { }
 
+Font::~Font()
+{
+       if(own_tex)
+               delete tex;
+}
+
 void Font::set_texture(const Texture2D &t)
 {
+       if(own_tex)
+               delete tex;
+
        tex=&t;
+       own_tex=false;
 }
 
 const Texture2D &Font::get_texture() const
@@ -140,6 +151,7 @@ void Font::Loader::init()
        add("ascent",  &Font::ascent);
        add("descent", &Font::descent);
        add("texture", &Font::tex);
+       add("texture_inline", &Loader::texture_inline);
        add("glyph",   &Loader::glyph);
 }
 
@@ -151,6 +163,14 @@ void Font::Loader::glyph(unsigned c)
        font.glyphs.insert(GlyphMap::value_type(c, gl));
 }
 
+void Font::Loader::texture_inline()
+{
+       RefPtr<Texture2D> tex=new Texture2D;
+       load_sub(*tex);
+       font.tex=tex.release();
+       font.own_tex=true;
+}
+
 
 Font::Glyph::Loader::Loader(Glyph &g):
        glyph(g)