X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffont.cpp;h=2cab462c04e9eaef76b27066d327cebb15a93396;hb=48420e9e3f950cfe1e3ced8f8ea92d89671ae8c4;hp=956acb462324dddb2603442981ef476f98be6d1f;hpb=b2851c18f6361fed2203e0aced4a5d671ad28630;p=libs%2Fgl.git diff --git a/source/font.cpp b/source/font.cpp index 956acb46..2cab462c 100644 --- a/source/font.cpp +++ b/source/font.cpp @@ -16,12 +16,18 @@ Font::Font(): varray((TEXCOORD2, VERTEX2)) { } +Font::~Font() +{ + if(own_tex) + delete tex; +} + void Font::set_texture(const Texture2D &t) { tex=&t; } -void Font::add_glyph(wchar_t code, float x1, float y1, float x2, float y2, float w, float h, float ox, float oy, float adv) +void Font::add_glyph(unsigned code, float x1, float y1, float x2, float y2, float w, float h, float ox, float oy, float adv) { Glyph glyph; glyph.code=code; @@ -51,12 +57,12 @@ float Font::get_string_width(const string &str) const return x; } -float Font::get_string_width(const wstring &str) const +float Font::get_string_width(const string &str, Codecs::Decoder &dec) const { float x=0; - for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i) - x+=get_glyph_advance(*i); + for(string::const_iterator i=str.begin(); i!=str.end();) + x+=get_glyph_advance(dec.decode_char(str, i)); return x; } @@ -71,22 +77,16 @@ void Font::draw_string(const string &str) const glPopMatrix(); } -void Font::draw_string(const wstring &str) const +void Font::draw_string(const string &str, Codecs::Decoder &dec) const { prepare_render(); - for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i) - draw_glyph(*i); + for(string::const_iterator i=str.begin(); i!=str.end();) + draw_glyph(dec.decode_char(str, i)); glPopMatrix(); } -Font::~Font() -{ - if(own_tex) - delete tex; -} - void Font::create_glyph_vertices() { varray.clear(); @@ -119,7 +119,7 @@ void Font::prepare_render() const glPushMatrix(); } -void Font::draw_glyph(wchar_t code) const +void Font::draw_glyph(unsigned code) const { GlyphMap::const_iterator i=glyphs.find(code); if(i==glyphs.end()) @@ -130,7 +130,7 @@ void Font::draw_glyph(wchar_t code) const glTranslatef(i->second.advance, 0, 0); } -float Font::get_glyph_advance(wchar_t code) const +float Font::get_glyph_advance(unsigned code) const { GlyphMap::const_iterator i=glyphs.find(code); if(i==glyphs.end())