Author: mordante
Date: Thu Aug 28 19:24:14 2008
New Revision: 29058

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29058&view=rev
Log:
Create a font when creating the ttext object.

This gives a small perfomance increasement and also makes some helper
code obsolete.

Modified:
    trunk/src/text.cpp
    trunk/src/text.hpp

Modified: trunk/src/text.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.cpp?rev=29058&r1=29057&r2=29058&view=diff
==============================================================================
--- trunk/src/text.cpp (original)
+++ trunk/src/text.cpp Thu Aug 28 19:24:14 2008
@@ -64,6 +64,7 @@
        context_(pango_cairo_font_map_create_context((
                
reinterpret_cast<PangoCairoFontMap*>(pango_cairo_font_map_get_default())))),
        layout_(pango_layout_new(context_)),
+       font_(pango_font_description_new()),
        rect_(),
        surface_(),
        text_(),
@@ -82,6 +83,9 @@
        // With 72 dpi the sizes are the same as with SDL_TTF so hardcoded.
        pango_cairo_context_set_resolution(context_, 72.0);
 
+       pango_font_description_set_family(font_, get_fonts().c_str());
+       pango_layout_set_font_description(layout_, font_);
+
        pango_layout_set_ellipsize(layout_, ellipse_mode_);
 }
 
@@ -92,6 +96,9 @@
        }
        if(layout_) {
                g_object_unref(layout_);
+       }
+       if(font_) {
+               pango_font_description_free(font_); 
        }
        if(surface_buffer_) {
                surface_.assign(NULL);
@@ -247,6 +254,8 @@
 ttext& ttext::set_font_size(const unsigned font_size)
 {
        if(font_size != font_size_) {
+               pango_font_description_set_size(font_, font_size * PANGO_SCALE);
+               pango_layout_set_font_description(layout_, font_);
                font_size_ = font_size;
                calculation_dirty_ = true;
                surface_dirty_ = true;
@@ -318,51 +327,11 @@
        return *this;
 }
 
-namespace {
-
-/** Small helper class to make sure the font object is destroyed properly. */
-class tfont
-{
-       tfont(const tfont&);
-       tfont& operator=(const tfont&);
-public:
-       tfont(const std::string& name, const unsigned size, const unsigned 
style) :
-               font_(pango_font_description_new())
-       {
-               pango_font_description_set_family(font_, name.c_str());
-               pango_font_description_set_size(font_, size * PANGO_SCALE);
-
-               if(style != ttext::STYLE_NORMAL) {
-                       if(style & ttext::STYLE_ITALIC) {
-                               pango_font_description_set_style(font_, 
PANGO_STYLE_ITALIC);
-                       }
-                       if(style & ttext::STYLE_BOLD) {
-                               pango_font_description_set_weight(font_, 
PANGO_WEIGHT_BOLD);
-                       }
-                       if(style & ttext::STYLE_UNDERLINE) {
-                               assert(false); // Not implemented yet
-                       }
-               }
-       }
-
-       ~tfont() { pango_font_description_free(font_); }
-
-       PangoFontDescription* get() { return font_; }
-
-private:
-       PangoFontDescription *font_;
-};
-
-} // namespace
-
 void ttext::recalculate(const bool force) const
 {
        if(calculation_dirty_ || force) {
                calculation_dirty_ = false;
                surface_dirty_ = true;
-
-               tfont font(get_fonts(), font_size_, font_style_);
-               pango_layout_set_font_description(layout_, font.get());
 
                pango_layout_get_pixel_extents(layout_, NULL, &rect_);
        }

Modified: trunk/src/text.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.hpp?rev=29058&r1=29057&r2=29058&view=diff
==============================================================================
--- trunk/src/text.hpp (original)
+++ trunk/src/text.hpp Thu Aug 28 19:24:14 2008
@@ -162,6 +162,7 @@
        /***** ***** ***** *****  Pango variables ***** ***** ***** *****/
        PangoContext* context_;
        PangoLayout* layout_;
+       PangoFontDescription* font_;
        mutable PangoRectangle rect_;
 
        /** The surface to render upon used as a cache. */


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to