gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libbase/ref_counted.h libbase/s...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libbase/ref_counted.h libbase/s...
Date: Thu, 10 Apr 2008 00:41:09 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/04/10 00:41:08

Modified files:
        .              : ChangeLog 
        libbase        : ref_counted.h smart_ptr.h 
        server         : edit_text_character.cpp edit_text_character.h 
        server/asobj   : Makefile.am TextFormat.cpp TextFormat.h 
        testsuite/misc-ming.all: DefineEditTextTest.c 

Log message:
        * libbase/ref_counted.h, libbase/smart_ptr.h: const-correctness.
        * server/edit_text_character.{cpp,h}: partially implement setTextFormat
          and getTextFormat; keep font by intrusive_ptr to avoid leak of
          AS-created fonts [should be optimized to leave ownership to fontlib]
        * server/asobj/Makefile.am: add FREETYPE_CFLAGS
        * server/asobj/TextFormat.{cpp,h}: implement getter-setters for font
          size and name.
        * testsuite/misc-ming.all/DefineEditTextTest.c: test
          getTextFormat()'s font and name.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6231&r2=1.6232
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/ref_counted.h?cvsroot=gnash&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/smart_ptr.h?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.cpp?cvsroot=gnash&r1=1.164&r2=1.165
http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.h?cvsroot=gnash&r1=1.72&r2=1.73
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Makefile.am?cvsroot=gnash&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/TextFormat.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/TextFormat.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/misc-ming.all/DefineEditTextTest.c?cvsroot=gnash&r1=1.29&r2=1.30

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6231
retrieving revision 1.6232
diff -u -b -r1.6231 -r1.6232
--- ChangeLog   9 Apr 2008 20:52:44 -0000       1.6231
+++ ChangeLog   10 Apr 2008 00:41:06 -0000      1.6232
@@ -1,5 +1,17 @@
 2008-04-09 Sandro Santilli <address@hidden>
 
+       * libbase/ref_counted.h, libbase/smart_ptr.h: const-correctness.
+       * server/edit_text_character.{cpp,h}: partially implement setTextFormat
+         and getTextFormat; keep font by intrusive_ptr to avoid leak of
+         AS-created fonts [should be optimized to leave ownership to fontlib]
+       * server/asobj/Makefile.am: add FREETYPE_CFLAGS
+       * server/asobj/TextFormat.{cpp,h}: implement getter-setters for font
+         size and name.
+       * testsuite/misc-ming.all/DefineEditTextTest.c: test
+         getTextFormat()'s font and name.
+
+2008-04-09 Sandro Santilli <address@hidden>
+
        * server/Makefile.am, server/textformat.{cpp,h},
          server/asobj/Global.cpp, server/asobj/Makefile.am,
          server/asobj/TextFormat.{cpp,h}:

Index: libbase/ref_counted.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/ref_counted.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- libbase/ref_counted.h       27 Mar 2008 16:12:35 -0000      1.16
+++ libbase/ref_counted.h       10 Apr 2008 00:41:07 -0000      1.17
@@ -97,7 +97,7 @@
        // If this design convinces us we'll be removing these two
        // methods and all the calls from ref-counted classes.
        //
-       void setReachable() { assert(m_ref_count > 0); }
+       void setReachable() const { assert(m_ref_count > 0); }
        bool isReachable() const { return true; }
 };
 

Index: libbase/smart_ptr.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/smart_ptr.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- libbase/smart_ptr.h 27 Mar 2008 16:12:35 -0000      1.27
+++ libbase/smart_ptr.h 10 Apr 2008 00:41:07 -0000      1.28
@@ -54,13 +54,13 @@
 #endif
 
 inline void
-intrusive_ptr_add_ref(ref_counted* o)
+intrusive_ptr_add_ref(const ref_counted* o)
 {
        o->add_ref();
 }
 
 inline void
-intrusive_ptr_release(ref_counted* o)
+intrusive_ptr_release(const ref_counted* o)
 {
        o->drop_ref();
 }
@@ -68,13 +68,13 @@
 // These two should not be needed when we switch all GcResource 
 // pointers to use the gc_ptr instead of the intrusive_ptr
 
-inline void intrusive_ptr_add_ref(GcResource* ) { }
-inline void intrusive_ptr_release(GcResource* ) { }
+inline void intrusive_ptr_add_ref(const GcResource* ) { }
+inline void intrusive_ptr_release(const GcResource* ) { }
 
 #ifdef GNASH_USE_GC
 class as_object;
-inline void intrusive_ptr_add_ref(as_object* ) { }
-inline void intrusive_ptr_release(as_object* ) { }
+inline void intrusive_ptr_add_ref(const as_object* ) { }
+inline void intrusive_ptr_release(const as_object* ) { }
 #endif
 
 // The below thing won't work. We'll need a real templated class..

Index: server/edit_text_character.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/edit_text_character.cpp,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -b -r1.164 -r1.165
--- server/edit_text_character.cpp      8 Apr 2008 21:59:23 -0000       1.164
+++ server/edit_text_character.cpp      10 Apr 2008 00:41:07 -0000      1.165
@@ -39,6 +39,7 @@
 #include "array.h" // for _listeners construction
 #include "AsBroadcaster.h" // for initializing self as a broadcaster
 #include "StringPredicates.h"
+#include "TextFormat.h" // for getTextFormat/setTextFormat
 
 #include <algorithm>
 #include <string>
@@ -59,6 +60,8 @@
 //
 //#define PP_COMPATIBLE_DEVICE_FONT_HANDLING 1
 
+#define ONCE(x) { static bool warned=false; if (!warned) { warned=true; x; } }
+
 namespace gnash {
 
 // Forward declarations
@@ -117,22 +120,6 @@
 }
 
 static as_value
-textfield_setTextFormat(const fn_call& fn)
-{
-       boost::intrusive_ptr<edit_text_character> text = 
ensureType<edit_text_character>(fn.this_ptr);
-       UNUSED(text);
-
-       static bool warned = false;
-       if ( ! warned ) {
-               log_unimpl("TextField.setTextFormat()");
-               warned = true;
-       }
-
-       return as_value();
-
-}
-
-static as_value
 textfield_setNewTextFormat(const fn_call& fn)
 {
        boost::intrusive_ptr<edit_text_character> text = 
ensureType<edit_text_character>(fn.this_ptr);
@@ -193,17 +180,95 @@
 textfield_getTextFormat(const fn_call& fn)
 {
        boost::intrusive_ptr<edit_text_character> text = 
ensureType<edit_text_character>(fn.this_ptr);
-       UNUSED(text);
 
-       static bool warned = false;
-       if ( ! warned ) {
-               log_unimpl("TextField.getTextFormat()");
-               warned = true;
+       boost::intrusive_ptr<TextFormat> tf = new TextFormat();
+       tf->alignSet(text->getTextAlignment());
+       tf->sizeSet(text->getFontHeight());
+       tf->indentSet(text->getIndent());
+       tf->leadingSet(text->getLeading());
+       tf->leftMarginSet(text->getLeftMargin());
+       tf->rightMarginSet(text->getRightMargin());
+
+       const font* font = text->getFont();
+       if (font)
+       {
+               tf->fontSet(font->get_name());
+       }
+
+       // TODO: add font name, color and some more
+
+       ONCE( log_unimpl("TextField.getTextFormat() INCOMPLETE") );
+
+       return as_value(tf.get());
+}
+
+static as_value
+textfield_setTextFormat(const fn_call& fn)
+{
+       GNASH_REPORT_FUNCTION;
+
+       boost::intrusive_ptr<edit_text_character> text = 
ensureType<edit_text_character>(fn.this_ptr);
+
+       if ( ! fn.nargs )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("TextField.setTextFormat(%s) : %s", ss.str(), 
_("missing arg"))
+               );
+               return as_value();
+       }
+       else if ( fn.nargs > 2 )
+       {
+               std::stringstream ss; fn.dump_args(ss);
+               log_debug("TextField.setTextFormat(%s) : args past the first 
are unhandled by Gnash", ss.str());
        }
 
+       as_object* obj = fn.arg(0).to_object().get();
+       if ( ! obj )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("TextField.setTextFormat(%s) : %s", ss.str(), 
_("first argument is not an object"))
+               );
        return as_value();
+       }
+
+       TextFormat* tf = dynamic_cast<TextFormat*>(obj);
+       if ( ! tf )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("TextField.setTextFormat(%s) : %s", ss.str(), 
_("first argument is not a TextFormat"))
+               );
+               return as_value();
+       }
+
+       text->setAlignment(tf->align());
+       text->setFontHeight(tf->size()); // keep twips
+       text->setIndent(tf->indent());
+       text->setLeading(tf->leading());
+       text->setLeftMargin(tf->leftMargin());
+       text->setRightMargin(tf->rightMargin());
+
+       const std::string& fontName = tf->font();
+       if ( ! fontName.empty() )
+       {
+               // TODO: reuse an existing font with this name if known !
+               //       Would need cleanups in the fontlib package
+               //       for proper thread-safety
+               boost::intrusive_ptr<font> f ( new font(fontName) );
+               text->setFont( f );
+       }
+
+       // TODO: add font name, color and some more
+
+       ONCE( log_unimpl("TextField.setTextFormat() TESTING") );
+
+       return as_value();
+
 }
 
+
 static as_value
 textfield_replaceSel(const fn_call& fn)
 {
@@ -397,6 +462,12 @@
        _text(L""),
        _textDefined(def->has_text()),
        m_def(def),
+       _leading(m_def->get_leading()),
+       _alignment(def->get_alignment()),
+       _indent(def->get_indent()), 
+       _leftMargin(def->get_left_margin()), 
+       _rightMargin(def->get_right_margin()), 
+       _fontHeight(def->get_font_height()), 
        _font(0),
        m_has_focus(false),
        m_cursor(0u),
@@ -427,7 +498,7 @@
        set_member(NSV::PROP_uLISTENERS, ar);
 
        // WARNING! remember to set the font *before* setting text value!
-       set_font( m_def->get_font() );
+       setFont( m_def->get_font() );
 
        // set default text *before* calling registerTextVariable
        // (if the textvariable already exist and has a value
@@ -496,7 +567,7 @@
 {
        boost::uint16_t x = static_cast<boost::uint16_t>(m_xcursor);
        boost::uint16_t y = static_cast<boost::uint16_t>(m_ycursor);
-       boost::uint16_t h = m_def->get_font_height();
+       boost::uint16_t h = getFontHeight();
 
        boost::int16_t box[4];
        box[0] = x;
@@ -714,7 +785,7 @@
        }
        
        // shouldn't this be !can_handle_mouse_event() instead ?
-       if (m_def->get_no_select())
+       if (_selectable)
        {
                // not selectable, so don't catch mouse events!
                return NULL;
@@ -1101,7 +1172,7 @@
        assert(m_def);
 
        float width = _bounds.width(); // m_def->width()
-       float right_margin = m_def->get_right_margin();
+       float right_margin = getRightMargin();
 
        float   extra_space = (width - right_margin) - x - PADDING_TWIPS;
 
@@ -1147,12 +1218,16 @@
        return shift_right;
 }
 
-const font*
-edit_text_character::set_font(const font* newfont)
+boost::intrusive_ptr<const font>
+edit_text_character::setFont(boost::intrusive_ptr<const font> newfont)
 {
-       const font* oldfont = _font;
-       _font = newfont; // @@ should I add_ref() ?
-       return oldfont;  // @@ should I drop_ref() ?
+       if ( newfont == _font ) return _font;
+
+       boost::intrusive_ptr<const font> oldfont = _font;
+       set_invalidated();
+       _font = newfont; 
+       format_text();
+       return oldfont;  
 }
 
 void
@@ -1193,16 +1268,16 @@
                return;
        }
 
-       float scale = m_def->get_font_height() / 1024.0f;       // the EM 
square is 1024 x 1024
+       boost::uint16_t fontHeight = getFontHeight();
+       float scale = fontHeight / 1024.0f;     // the EM square is 1024 x 1024
        float fontDescent = _font->get_descent() * scale;
        float fontLeading = _font->get_leading() * scale;
-       boost::uint16_t fontHeight = m_def->get_font_height();
-       boost::uint16_t leftMargin = m_def->get_left_margin();
-       boost::uint16_t rightMargin = m_def->get_right_margin();
-       boost::uint16_t indent = m_def->get_indent();
+       boost::uint16_t leftMargin = getLeftMargin();
+       boost::uint16_t rightMargin = getRightMargin();
+       boost::uint16_t indent = getIndent();
 
        text_glyph_record       rec;    // one to work on
-       rec.m_style.setFont(_font);
+       rec.m_style.setFont(_font.get());
        rec.m_style.m_color = getTextColor(); 
        rec.m_style.m_x_offset = PADDING_TWIPS + std::max(0, leftMargin + 
indent); 
        rec.m_style.m_y_offset = PADDING_TWIPS + fontHeight
@@ -1218,7 +1293,7 @@
        // Start the bbox at the upper-left corner of the first glyph.
        reset_bounding_box(x, y - fontDescent + fontHeight); 
 
-       float   leading = m_def->get_leading();
+       float leading = getLeading();
        leading += fontLeading * scale;
 
        int     last_code = -1; // only used if _embedFonts
@@ -1267,7 +1342,7 @@
 
                        // Start a new record on the next line.
                        rec.m_glyphs.resize(0);
-                       rec.m_style.setFont(_font); 
+                       rec.m_style.setFont(_font.get()); 
                        rec.m_style.m_color = getTextColor();
                        rec.m_style.m_x_offset = x;
                        rec.m_style.m_y_offset = y;
@@ -1469,17 +1544,17 @@
                                        // Close out this stretch of glyphs.
                                        m_text_glyph_records.push_back(rec);
                                        float   previous_x = x;
-                                       x = m_def->get_left_margin() + 
PADDING_TWIPS;
-                                       y += m_def->get_font_height() + leading;
+                                       x = getLeftMargin() + PADDING_TWIPS;
+                                       y += getFontHeight() + leading;
 
 
                                        // Start a new record on the next line.
                                        rec.m_glyphs.resize(0);
-                                       rec.m_style.setFont(_font);
+                                       rec.m_style.setFont(_font.get());
                                        rec.m_style.m_color = getTextColor();
                                        rec.m_style.m_x_offset = x;
                                        rec.m_style.m_y_offset = y;
-                                       rec.m_style.m_text_height = 
m_def->get_font_height();
+                                       rec.m_style.m_text_height = 
getFontHeight();
                                        rec.m_style.m_has_x_offset = true;
                                        rec.m_style.m_has_y_offset = true;
                                        
@@ -1696,7 +1771,6 @@
        {
                _variable_name = newname;
                _text_variable_registered = false;
-               //setTextValue(m_def->get_default_text());
 #ifdef DEBUG_DYNTEXT_VARIABLES
                log_debug("Calling updateText after change of variable name");
 #endif
@@ -1754,8 +1828,6 @@
        point lp(x, y);
        wm.transform_by_inverse(lp);
        return _bounds.contains(lp.x, lp.y);
-       //const rect& def_bounds = m_def->get_bounds();
-       //return def_bounds.point_test(lp.x, lp.y);
 }
 
 bool
@@ -1885,6 +1957,72 @@
   return cf;
 }
 
+void
+edit_text_character::setLeading(uint16_t h)
+{
+       if ( _leading != h )
+       {
+               set_invalidated();
+               _leading = h;
+               format_text();
+       }
+}
+
+void
+edit_text_character::setAlignment(edit_text_character_def::alignment h)
+{
+       if ( _alignment != h )
+       {
+               set_invalidated();
+               _alignment = h;
+               format_text();
+       }
+}
+
+void
+edit_text_character::setIndent(boost::uint16_t h)
+{
+       if ( _indent != h )
+       {
+               set_invalidated();
+               _indent = h;
+               format_text();
+       }
+}
+
+void
+edit_text_character::setRightMargin(boost::uint16_t h)
+{
+       if ( _rightMargin != h )
+       {
+               set_invalidated();
+               _rightMargin = h;
+               format_text();
+       }
+}
+
+void
+edit_text_character::setLeftMargin(boost::uint16_t h)
+{
+       if (_leftMargin != h)
+       {
+               set_invalidated();
+               _leftMargin = h;
+               format_text();
+       }
+}
+
+void
+edit_text_character::setFontHeight(boost::uint16_t h)
+{
+       if ( _fontHeight != h )
+       {
+               set_invalidated();
+               _fontHeight = h;
+               format_text();
+       }
+}
+
 static as_value
 textfield_background_getset(const fn_call& fn)
 {
@@ -2222,7 +2360,7 @@
        // TODO: use a _textAlignment private member to reduce lookups ?
        // The member would be initialized to m_def->get_alignment and then 
update
        // when _autoSize is updated.
-       edit_text_character_def::alignment textAlignment = 
m_def->get_alignment();
+       edit_text_character_def::alignment textAlignment = getAlignment(); 
        if ( _autoSize == autoSizeCenter ) textAlignment = 
edit_text_character_def::ALIGN_CENTER;
        else if ( _autoSize == autoSizeLeft ) textAlignment = 
edit_text_character_def::ALIGN_LEFT;
        else if ( _autoSize == autoSizeRight ) textAlignment = 
edit_text_character_def::ALIGN_RIGHT;
@@ -2289,6 +2427,17 @@
        onKillFocus();
 }
 
+void
+edit_text_character::markReachableResources() const
+{
+       if ( m_def.get() ) m_def->setReachable();
+
+       if ( _font ) _font->setReachable();
+
+       // recurse to parent...
+       markCharacterReachable();
+}
+
 } // namespace gnash
 
 

Index: server/edit_text_character.h
===================================================================
RCS file: /sources/gnash/gnash/server/edit_text_character.h,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- server/edit_text_character.h        1 Apr 2008 18:51:30 -0000       1.72
+++ server/edit_text_character.h        10 Apr 2008 00:41:07 -0000      1.73
@@ -23,11 +23,12 @@
 #endif
 
 #include "character.h" // for inheritance
-#include "edit_text_character_def.h" // for inlines
+#include "edit_text_character_def.h" // for inlines and typedefs
 #include "styles.h" // for fill_style and line_style
 #include "text.h" // for text_glyph_record
 #include "Range2d.h"
 #include "rect.h" // for inlines
+#include "font.h" // for visibility of font add_ref/drop_ref
 
 // Forward declarations
 namespace gnash {
@@ -330,6 +331,57 @@
        ///
        void removeTextField();
 
+       /// Set our font, return previously set one.
+       //
+       /// @param newfont
+       ///     Will be stored in an intrusive_ptr
+       ///
+       boost::intrusive_ptr<const font> setFont(boost::intrusive_ptr<const 
font> newfont);
+
+       const font* getFont() { return _font.get(); }
+
+       boost::uint16_t getFontHeight() const
+       {
+               return _fontHeight;
+       }
+
+       void setFontHeight(boost::uint16_t h);
+
+       boost::uint16_t getLeftMargin() const
+       {
+               return _leftMargin;
+       }
+
+       void setLeftMargin(boost::uint16_t h);
+
+       boost::uint16_t getRightMargin() const
+       {
+               return _rightMargin;
+       }
+
+       void setRightMargin(boost::uint16_t h);
+
+       boost::uint16_t getIndent() const
+       {
+               return _indent;
+       }
+
+       void setIndent(boost::uint16_t h);
+
+       edit_text_character_def::alignment getAlignment() const
+       {
+               return _alignment;
+       }
+
+       void setAlignment(edit_text_character_def::alignment h);
+
+       boost::uint16_t getLeading() const
+       {
+               return _leading;
+       }
+
+       void setLeading(boost::uint16_t h);
+
 private:
 
        /// Set our text to the given string.
@@ -404,12 +456,20 @@
        float align_line(edit_text_character_def::alignment align,
                        int last_line_start_record, float x);
 
-       /// Set our font, return previously set one.
-       /// This is private for now, but might eventally
-       /// be public, for setting fonts from ActionScript.
-       const font* set_font(const font* newfont);
 
-       const font* _font;
+       boost::uint16_t _leading;
+
+       edit_text_character_def::alignment _alignment;
+
+       boost::uint16_t _indent;
+
+       boost::uint16_t _leftMargin;
+
+       boost::uint16_t _rightMargin;
+
+       boost::uint16_t _fontHeight;
+
+       boost::intrusive_ptr<const font> _font;
 
        bool m_has_focus;
        size_t m_cursor;
@@ -493,20 +553,14 @@
 
 protected:
 
-#ifdef GNASH_USE_GC
        /// Mark reachable reosurces (for GC)
        //
-       /// Reachable resource is currenlty just our definition,
-       /// plus common character resources
+       /// Reachable resources are:
+       ///  - The font being used (m_font) 
+       ///  - Our definition
+       ///  - Common character resources
        ///
-       void markReachableResources() const
-       {
-               if ( m_def.get() ) m_def->setReachable();
-
-               // recurse to parent...
-               markCharacterReachable();
-       }
-#endif
+       void markReachableResources() const;
 };
 
 /// Initialize the global TextField class

Index: server/asobj/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Makefile.am,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- server/asobj/Makefile.am    9 Apr 2008 20:52:46 -0000       1.52
+++ server/asobj/Makefile.am    10 Apr 2008 00:41:08 -0000      1.53
@@ -38,6 +38,7 @@
        $(GLIB_CFLAGS) \
        $(BOOST_CFLAGS) \
        $(LIBXML_CFLAGS) \
+       $(FREETYPE2_CFLAGS) \
        $(NULL)
 
 

Index: server/asobj/TextFormat.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/TextFormat.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- server/asobj/TextFormat.cpp 9 Apr 2008 20:52:46 -0000       1.3
+++ server/asobj/TextFormat.cpp 10 Apr 2008 00:41:08 -0000      1.4
@@ -25,6 +25,7 @@
 #include "builtin_function.h" // for getter/setter properties
 #include "namedStrings.h"
 #include "VM.h"
+#include "server/types.h" // for PIXELS_TO_TWIPS
 
 #define ONCE(x) { static bool warned=false; if (!warned) { warned=true; x; } }
 
@@ -175,16 +176,38 @@
 }
 
 as_value
-TextFormat::size_getset(const fn_call& /*fn*/)
+TextFormat::size_getset(const fn_call& fn)
 {
-       ONCE( log_unimpl("TextField.size") );
+       boost::intrusive_ptr<TextFormat> ptr = 
ensureType<TextFormat>(fn.this_ptr);
+
+       if ( fn.nargs == 0 ) // getter
+       {
+               return as_value(TWIPS_TO_PIXELS(ptr->size()));
+       }
+       else // setter
+       {
+               ptr->sizeSet(PIXELS_TO_TWIPS(fn.arg(0).to_int()));
+               ONCE( log_debug("TextField.size setter TESTING") );
+
+       }
+
        return as_value();
 }
 
 as_value
-TextFormat::font_getset(const fn_call& /*fn*/)
+TextFormat::font_getset(const fn_call& fn)
 {
-       ONCE( log_unimpl("TextField.font") );
+       boost::intrusive_ptr<TextFormat> ptr = 
ensureType<TextFormat>(fn.this_ptr);
+
+       if ( fn.nargs == 0 ) // getter
+       {
+               return as_value(ptr->font());
+       }
+       else // setter
+       {
+               ptr->fontSet(fn.arg(0).to_string());
+       }
+
        return as_value();
 }
 
@@ -213,8 +236,10 @@
        o.init_readonly_property("target", &TextFormat::target_getset);
        o.init_readonly_property("url", &TextFormat::url_getset);
        o.init_readonly_property("color", &TextFormat::color_getset);
-       o.init_readonly_property("size", &TextFormat::size_getset);
-       o.init_readonly_property("font", &TextFormat::font_getset);
+
+       o.init_property("size", &TextFormat::size_getset, 
&TextFormat::size_getset);
+
+       o.init_property("font", &TextFormat::font_getset, 
&TextFormat::font_getset);
 }
 
 static as_object*

Index: server/asobj/TextFormat.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/TextFormat.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- server/asobj/TextFormat.h   9 Apr 2008 20:52:46 -0000       1.3
+++ server/asobj/TextFormat.h   10 Apr 2008 00:41:08 -0000      1.4
@@ -22,6 +22,7 @@
 #define __TEXTFORMAT_H__
 
 #include "as_object.h" // for inheritance of TextFormat
+#include "edit_text_character_def.h" // for edit_text_character_def::alignment 
enum
 #include <boost/cstdint.hpp> // for boost::uint32_t
 #include <string>
 
@@ -59,7 +60,7 @@
        /// \brief
        /// Return ann integer that indicates the indentation from the left
         /// margin to the first character in the paragraph
-       float indent() const { return _indent; }
+       boost::uint16_t indent() const { return _indent; }
 
        /// Return the alignment of the paragraph, represented as a string.
        //
@@ -69,41 +70,44 @@
        ///
        /// FIXME: use an enum !
        ///
-       const std::string& align() const { return _align; }
+       edit_text_character_def::alignment align() const { return _align; }
 
        /// Return the name of a font for text as a string.
        const std::string& font() const { return _font; }
 
        ///
-       float blockIndent() { return _block_indent; }
+       boost::uint16_t blockIndent() { return _block_indent; }
 
        /// Return a number that indicates the amount of leading vertical
        /// space between lines.
-       float leading()     { return _leading; }
+       boost::uint16_t leading()     { return _leading; }
 
        /// Indicates the left margin of the paragraph, in points.
-       float leftMargin()  { return _left_margin; }
+       boost::uint16_t leftMargin()  { return _left_margin; }
 
        /// Indicates the right margin of the paragraph, in points.
-       float RightMargin() { return _right_margin; }
+       boost::uint16_t rightMargin() { return _right_margin; }
 
-       /// Return a float that indicates the point size.
-       float size()        { return _point_size; }
+       /// Return a float that indicates the point size in twips.
+       boost::uint16_t size()        { return _point_size; }
 
        void underlinedSet(bool x)   { _underline = x; }
        void italicedSet(bool x)     { _italic = x; }
        void boldSet(bool x)         { _bold = x; }
        void bulletSet(bool x)       { _bullet = x; }
        void colorSet(boost::uint32_t x)      { _color = x; }
-       void indentSet(float x)      { _indent = x; }
+       void indentSet(boost::uint16_t x)      { _indent = x; }
+       void fontSet(const std::string& font) { _font=font; }
 
-       void alignSet(const std::string& x)  { _align = x; }
+       void alignSet(edit_text_character_def::alignment x)  { _align = x; }
 
-       void blockIndentSet(float x)   { _block_indent = x; }
-       void leadingSet(float x)     { _leading = x; }
-       void leftMarginSet(float x)  { _left_margin = x; }
-       void rightMarginSet(float x) { _right_margin = x; }
-       void sizeSet(float x)        { _point_size = x; }
+       void blockIndentSet(boost::uint16_t x)   { _block_indent = x; }
+       void leadingSet(boost::uint16_t x)     { _leading = x; }
+       void leftMarginSet(boost::uint16_t x)  { _left_margin = x; }
+       void rightMarginSet(boost::uint16_t x) { _right_margin = x; }
+
+       /// Set font point size in twips
+       void sizeSet(boost::uint16_t x)        { _point_size = x; }
 
        static as_value display_getset(const fn_call& fn);
        static as_value bullet_getset(const fn_call& fn);
@@ -144,14 +148,12 @@
        //
        /// If "left", the paragraph is left-aligned. If "center", the
        /// paragraph is centered. If "right", the paragraph is
-       /// right-aligned.
-       ///
-       /// FIXME: use an enum !
+       /// right-aligned. If "justify", the paragraph is justified.
        ///
-       std::string _align;
+       edit_text_character_def::alignment _align;
 
        // 
-       float           _block_indent;
+       boost::uint16_t         _block_indent;
 
        /// The color of text using this text format.
        //
@@ -163,21 +165,21 @@
        std::string _font;      
 
        /// An integer that indicates the indentation from the left
-        /// margin to the first character in the paragraph
-       float           _indent;
+        /// margin to the first character in the paragraph (twips)
+       boost::uint16_t _indent;
 
        /// A number that indicates the amount of leading vertical
-       /// space between lines.
-       float           _leading;
+       /// space between lines (twips)
+       boost::uint16_t _leading;
 
-       /// Indicates the left margin of the paragraph, in points.
-       float           _left_margin;
+       /// Indicates the left margin of the paragraph, in points (twips)
+       boost::uint16_t _left_margin;
 
-       /// Indicates the right margin of the paragraph, in points.
-       float           _right_margin;
+       /// Indicates the right margin of the paragraph, in points (twips).
+       boost::uint16_t _right_margin;
 
-       /// An float that indicates the point size.
-       float           _point_size;
+       /// Point size in twips.
+       boost::uint16_t _point_size;
 
        ///
        int             _tab_stops;

Index: testsuite/misc-ming.all/DefineEditTextTest.c
===================================================================
RCS file: /sources/gnash/gnash/testsuite/misc-ming.all/DefineEditTextTest.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- testsuite/misc-ming.all/DefineEditTextTest.c        9 Apr 2008 20:34:54 
-0000       1.29
+++ testsuite/misc-ming.all/DefineEditTextTest.c        10 Apr 2008 00:41:08 
-0000      1.30
@@ -205,7 +205,7 @@
   check(mo, "!etext1.hasOwnProperty('_xscale')");
   check(mo, "!etext1.hasOwnProperty('_yscale')");
   
-  xcheck_equals(mo, "dtext1.__proto__.hasOwnProperty('text')", "true");
+  xcheck(mo, "dtext1.__proto__.hasOwnProperty('text')");
   check_equals(mo, "dtext1.__proto__.hasOwnProperty('background')", "true");
   check_equals(mo, "dtext1.__proto__.hasOwnProperty('backgroundColor')", 
"true");
   check_equals(mo, "dtext1.__proto__.hasOwnProperty('textColor')", "true");
@@ -237,9 +237,6 @@
   check_equals(mo, "typeof(dtext2._xmouse)", "'number'");
   check_equals(mo, "typeof(etext1._ymouse)", "'number'"); 
   check_equals(mo, "typeof(dtext2._ymouse)", "'number'"); 
-  // TextFormat objects are created on the fly
-  xcheck_equals(mo, "typeof(etext1.getTextFormat())", "'object'"); 
-  xcheck_equals(mo, "typeof(dtext2.getTextFormat())", "'object'"); 
   
   add_actions(mo, "dtext1.background = true;"
                   "etext1.background = true;"
@@ -254,6 +251,14 @@
                   "etext1.text += ' world';"
                   "dtext2.text += ' world';" );
 
+  // TextFormat objects are created on the fly
+  check_equals(mo, "typeof(etext1.getTextFormat())", "'object'"); 
+  check_equals(mo, "typeof(dtext2.getTextFormat())", "'object'"); 
+  check_equals(mo, "etext1.getTextFormat().size", "12"); 
+  check_equals(mo, "dtext2.getTextFormat().size", "12"); 
+  check_equals(mo, "etext1.getTextFormat().font", "'Bitstream Vera Sans'");
+  check_equals(mo, "dtext2.getTextFormat().font", "'times'"); 
+
   check_equals(mo, "dtext1.text", "'Hello world'");
   check_equals(mo, "etext1.text", "'Hello world'");
   check_equals(mo, "dtext2.text", "'Hello world'");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]