]> git.tdb.fi Git - libs/gl.git/blobdiff - source/font.cpp
Default to Utf8 instead of direct mapping in Font
[libs/gl.git] / source / font.cpp
index 3b02583b401043b8e042becbc1edeb6febe9668c..60090e0148de8e3ebc587da94f04261c4b629fe6 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <GL/gl.h>
 #include "font.h"
 #include "texture2d.h"
@@ -9,19 +16,12 @@ namespace GL {
 
 Font::Font():
        tex(0),
-       own_tex(false),
        default_size(1),
        ascent(1),
        descent(0),
        varray((TEXCOORD2, VERTEX2))
 { }
 
-Font::~Font()
-{
-       if(own_tex)
-               delete tex;
-}
-
 void Font::set_texture(const Texture2D &t)
 {
        tex=&t;
@@ -47,16 +47,6 @@ void Font::add_glyph(unsigned code, float x1, float y1, float x2, float y2, floa
        create_glyph_vertices(glyph, *va_builder);
 }
 
-float Font::get_string_width(const string &str) const
-{
-       float x=0;
-
-       for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
-               x+=get_glyph_advance(static_cast<unsigned char>(*i));
-
-       return x;
-}
-
 float Font::get_string_width(const string &str, Codecs::Decoder &dec) const
 {
        float x=0;
@@ -67,16 +57,6 @@ float Font::get_string_width(const string &str, Codecs::Decoder &dec) const
        return x;
 }
 
-void Font::draw_string(const string &str) const
-{
-       prepare_render();
-
-       for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
-               draw_glyph(static_cast<unsigned char>(*i));
-
-       glPopMatrix();
-}
-
 void Font::draw_string(const string &str, Codecs::Decoder &dec) const
 {
        prepare_render();
@@ -141,13 +121,24 @@ float Font::get_glyph_advance(unsigned code) const
 
 
 Font::Loader::Loader(Font &f):
-       font(f)
+       font(f),
+       coll(0)
 {
-       add("default_size", &Font::default_size);
-       add("ascent",  &Font::ascent);
-       add("descent", &Font::descent);
-       add("texture", &Loader::texture);
-       add("glyph",   &Loader::glyph);
+       init();
+}
+
+Font::Loader::Loader(Font &f, Collection &c):
+       font(f),
+       coll(&c)
+{
+       init();
+}
+
+DataFile::Collection &Font::Loader::get_collection()
+{
+       if(!coll)
+               throw InvalidState("No collection");
+       return *coll;
 }
 
 Font::Loader::~Loader()
@@ -155,13 +146,13 @@ Font::Loader::~Loader()
        font.create_glyph_vertices();
 }
 
-void Font::Loader::texture(const string &t)
+void Font::Loader::init()
 {
-       Texture2D *tex=new Texture2D;
-       tex->parameter(GL_GENERATE_MIPMAP, 1);
-       font.tex=tex;
-       tex->image(t);
-       font.own_tex=true;
+       add("default_size", &Font::default_size);
+       add("ascent",  &Font::ascent);
+       add("descent", &Font::descent);
+       add("texture", &Font::tex);
+       add("glyph",   &Loader::glyph);
 }
 
 void Font::Loader::glyph(unsigned c)