Author: mordante
Date: Tue Oct  7 20:36:46 2008
New Revision: 29953

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29953&view=rev
Log:
Change font::ttext to use the deep copy policy.

This should fix the compilation problems on suncc, gcc worked with the
previous "hack", now the class can properly be copied.

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=29953&r1=29952&r2=29953&view=diff
==============================================================================
--- trunk/src/text.cpp (original)
+++ trunk/src/text.cpp Tue Oct  7 20:36:46 2008
@@ -27,6 +27,8 @@
 #include <cairo.h>
 
 namespace font {
+
+namespace internal {
 
 namespace {
 
@@ -239,6 +241,20 @@
        }
 }
 
+void ttext::clone()
+{
+       context_ = pango_cairo_font_map_create_context((
+               
reinterpret_cast<PangoCairoFontMap*>(pango_cairo_font_map_get_default())));
+       // With 72 dpi the sizes are the same as with SDL_TTF so hardcoded.
+       pango_cairo_context_set_resolution(context_, 72.0);
+
+       layout_ = pango_layout_new(context_);
+       pango_layout_set_ellipsize(layout_, ellipse_mode_);
+
+       surface_dirty_ = true;
+       surface_buffer_ = 0;
+}
+
 ttext& ttext::set_text(const std::string& text, const bool markedup) 
 {
        if(markedup != markedup_text_ || text != text_) {
@@ -477,5 +493,7 @@
        memset(surface_buffer_, 0, size);
 }
 
+} // namespace internal 
+
 } // namespace font 
 

Modified: trunk/src/text.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.hpp?rev=29953&r1=29952&r2=29953&view=diff
==============================================================================
--- trunk/src/text.hpp (original)
+++ trunk/src/text.hpp Tue Oct  7 20:36:46 2008
@@ -15,6 +15,7 @@
 #ifndef TEXT_HPP_INCLUDED
 #define TEXT_HPP_INCLUDED
 
+#include "copy_policy.hpp"
 #include "sdl_utils.hpp"
 
 #include <pango/pango.h>
@@ -32,33 +33,23 @@
 
 // add background colour and also font markup.
 
+/** 
+ * The classes in this namespace should not be used directly.
+ *
+ * Use the typedef which sets the policy instead.
+ */
+namespace internal {
 /**
- * Text class .
+ * Text class.
  *
  * This class stores the text to draw and uses pango with the cairo backend to
  * render the text. See http://pango.org for more info.
  */
-class ttext {
-       ttext& operator=(const ttext&);
+class ttext 
+{
 public:
 
        ttext();
-
-       /**
-        * Copy constructor.
-        *
-        * The class is not copyable but the compiler needs the have the 
illusion
-        * the class is copy constructable. The copy constructor is declared 
but not
-        * fully defined. We assume all compilers do a RVO [1] at the places 
where
-        * the constructor is used. If some compiler doesn't support it we'll 
get
-        * linker errors. We declare this constructor to avoid a default copy
-        * constructor which would do the wrong thing (double freeing the Pango 
data
-        * and the surface_surface buffer). If it breaks on some compiler or we 
need
-        * to copy this class a real constructor should be written.
-        *
-        * [1] http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.9
-        */
-       ttext(const ttext&);
 
        ~ttext();
 
@@ -160,6 +151,9 @@
         */
        size_t get_length() const { return length_; }
 
+       /** Helper for policies::tdeep_copy. */
+       void clone();
+
        /***** ***** ***** ***** Setters / getters ***** ***** ***** *****/
 
        ttext& set_text(const std::string& text, const bool markedup);
@@ -284,6 +278,18 @@
        void create_surface_buffer(const size_t size) const; 
 };
 
+} // namespace internal 
+
+
+/**
+ * Note the deepcopy might not be used on all compilers due to RVO [1].
+ * This means the code might be less tested, gcc does this optimization and
+ * thus I didn't test it on my platform -- Mordante.
+ *
+ * [1] http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.9
+ */
+typedef policies::tcopy_policy<internal::ttext, policies::tdeep_copy> ttext;
+
 } // namespace font 
 
 #endif


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

Reply via email to