gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10684: Implement and test TextSnaps


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10684: Implement and test TextSnapshot more.
Date: Tue, 10 Mar 2009 13:53:48 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10684
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2009-03-10 13:53:48 +0100
message:
  Implement and test TextSnapshot more.
modified:
  libcore/Font.cpp
  libcore/Font.h
  libcore/MovieClip.cpp
  libcore/RGBA.h
  libcore/TextField.cpp
  libcore/asobj/TextSnapshot_as.cpp
  libcore/asobj/TextSnapshot_as.h
  libcore/swf/DefineFontTag.cpp
  libcore/swf/TextRecord.cpp
  libcore/swf/TextRecord.h
  testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10681.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 07:23:07 +0100
    message:
      Log once.
    modified:
      libcore/MovieClip.cpp
    ------------------------------------------------------------
    revno: 10681.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 07:31:07 +0100
    message:
      Log language code number.
    modified:
      libcore/swf/DefineFontTag.cpp
    ------------------------------------------------------------
    revno: 10681.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 08:09:35 +0100
    message:
      Test getTextRunInfo.
    modified:
      libcore/asobj/TextSnapshot_as.cpp
      testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10681.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 08:18:57 +0100
    message:
      More tests.
    modified:
      testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10681.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 08:44:14 +0100
    message:
      Stub getTextRunInfo() function.
    modified:
      libcore/asobj/TextSnapshot_as.cpp
      libcore/asobj/TextSnapshot_as.h
    ------------------------------------------------------------
    revno: 10681.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 09:50:13 +0100
    message:
      Rename Font::get_name() to Font::name(). Add toRGBA() to rgba class.
      
      TextRecords with no color field also have zero, not full alpha (tested 
only in
      TextSnapshotTest.c, so there may be exceptions).
      
      Implement some of getTextRunInfo().
    modified:
      libcore/Font.h
      libcore/RGBA.h
      libcore/TextField.cpp
      libcore/asobj/TextSnapshot_as.cpp
      libcore/asobj/TextSnapshot_as.h
      libcore/swf/TextRecord.cpp
      libcore/swf/TextRecord.h
    ------------------------------------------------------------
    revno: 10681.1.7
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 10:06:31 +0100
    message:
      Add more getTextRunInfo() items.
    modified:
      libcore/asobj/TextSnapshot_as.cpp
    ------------------------------------------------------------
    revno: 10681.1.8
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 11:37:59 +0100
    message:
      More tests.
    modified:
      testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10681.1.9
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 12:44:46 +0100
    message:
      Rename Font functions and clean up code formatting.
      
      Correct matrix members of getTextRunInfo() objects.
      
      Add more tests.
    modified:
      libcore/Font.cpp
      libcore/Font.h
      libcore/TextField.cpp
      libcore/asobj/TextSnapshot_as.cpp
      testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10681.1.10
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-03-10 13:22:29 +0100
    message:
      Add more tests showing that the selection is in fact stored in the 
TextFields,
      not the TextSnapshot, and reset on construction of a snapshot.
    modified:
      libcore/asobj/TextSnapshot_as.cpp
      testsuite/misc-ming.all/TextSnapshotTest.c
=== modified file 'libcore/Font.cpp'
--- a/libcore/Font.cpp  2009-03-05 10:58:01 +0000
+++ b/libcore/Font.cpp  2009-03-10 11:44:46 +0000
@@ -117,15 +117,12 @@
     const GlyphInfoRecords& lookup = (embedded && _fontTag) ? 
             _fontTag->glyphTable() : _deviceGlyphTable;
 
-    if (index >= 0 && (size_t)index < lookup.size())
-    {
+    if (index >= 0 && (size_t)index < lookup.size()) {
         return lookup[index].glyph.get();
     }
-    else
-    {
-        // TODO: should we log an error here ?
-        return NULL;
-    }
+
+    // TODO: should we log an error here ?
+    return 0;
 }
 
 void
@@ -212,96 +209,82 @@
 
     int glyph_index = -1;
     CodeTable::const_iterator it = ctable.find(code);
-    if ( it != ctable.end() )
-    {
+    if (it != ctable.end()) {
         glyph_index = it->second;
         return glyph_index;
     }
 
     // Try adding an os font, if possible
-    if ( ! embedded )
-    {
+    if (!embedded) {
         glyph_index = const_cast<Font*>(this)->add_os_glyph(code);
     }
     return glyph_index;
 }
 
-float Font::get_advance(int glyph_index, bool embedded) const
+float
+Font::get_advance(int glyph_index, bool embedded) const
 {
     // What to do if embedded is true and this is a
     // device-only font?
     const GlyphInfoRecords& lookup = (embedded && _fontTag) ? 
             _fontTag->glyphTable() : _deviceGlyphTable;
 
-    if (glyph_index < 0)
-    {
+    if (glyph_index < 0) {
         // Default advance.
         return 512.0f;
     }
 
-    if (static_cast<size_t>(glyph_index) < lookup.size())
-    {
-        assert(glyph_index >= 0);
-        return lookup[glyph_index].advance;
-    }
-    else
-    {
-        // Bad glyph index.  Due to bad data file?
-        abort();
-        return 0;
-    }
+    assert(static_cast<size_t>(glyph_index) < lookup.size());
+    assert(glyph_index >= 0);
+    
+    return lookup[glyph_index].advance;
 }
 
 
 // Return the adjustment in advance between the given two
 // characters.  Normally this will be 0; i.e. the 
-float  Font::get_kerning_adjustment(int last_code, int code) const
+float
+Font::get_kerning_adjustment(int last_code, int code) const
 {
     kerning_pair       k;
     k.m_char0 = last_code;
     k.m_char1 = code;
     kernings_table::const_iterator it = m_kerning_pairs.find(k);
-    if ( it != m_kerning_pairs.end() )
-    {
+    if (it != m_kerning_pairs.end()) {
         float adjustment = it->second;
         return adjustment;
     }
     return 0;
 }
 
-unsigned short int Font::unitsPerEM(bool embed) const
+unsigned short int
+Font::unitsPerEM(bool embed) const
 {
     // the EM square is 1024 x 1024 for DefineFont up to 2
     // and 20 as much for DefineFont3 up
-    if (embed)
-    {
+    if (embed) {
         // If this is not an embedded font, what should we do
         // here?
         if ( _fontTag && _fontTag->subpixelFont() ) return 1024 * 20;
         else return 1024;
     }
-    else
-    {
-        if ( ! _ftProvider.get() )
-        {
-            if ( ! initDeviceFontProvider() )
-            {
-                log_error("Device font provider was not initialized, "
-                        "can't get unitsPerEM");
-                return 0; // can't query it..
-            }
+    
+    if (!_ftProvider.get()) {
+        if (!initDeviceFontProvider()) {
+            log_error("Device font provider was not initialized, "
+                    "can't get unitsPerEM");
+            return 0; // can't query it..
         }
-        return _ftProvider->unitsPerEM();
     }
+
+    return _ftProvider->unitsPerEM();
 }
 
 int
 Font::add_os_glyph(boost::uint16_t code)
 {
-    if ( ! _ftProvider.get() )
-    {
-        if ( ! initDeviceFontProvider() )
-        {
+    if (!_ftProvider.get()) {
+        if (!initDeviceFontProvider()) {
             log_error("Device font provider was not initialized, can't "
                     "get unitsPerEM");
             return -1; // can't provide it...
@@ -316,8 +299,7 @@
     boost::intrusive_ptr<shape_character_def> sh = 
         _ftProvider->getGlyph(code, advance);
 
-    if ( ! sh )
-    {
+    if (!sh) {
         log_error("Could not create shape "
                 "glyph for character code %u (%c) with "
                 "device font %s (%p)", code, code, _name,
@@ -341,16 +323,14 @@
 bool
 Font::initDeviceFontProvider() const
 {
-    if ( _name.empty() )
-    {
+    if (_name.empty()) {
         log_error("No name associated with this font, can't use device "
                 "fonts (should I use a default one?)");
         return false;
     }
 
     _ftProvider = FreetypeGlyphsProvider::createFace(_name, _bold, _italic);
-    if ( ! _ftProvider.get() )
-    {
+    if (!_ftProvider.get()) {
         log_error("Could not create a freetype face %s", _name);
         return false;
     }
@@ -365,13 +345,19 @@
 
 // TODO: what about device fonts?
 float
-Font::get_leading() const {
+Font::leading() const {
     return _fontTag ? _fontTag->leading() : 0.0f;
 }
 
 // TODO: what about device fonts?
 float
-Font::get_descent() const {
+Font::ascent() const {
+    return _fontTag ? _fontTag->ascent() : 0.0f;
+}
+    
+// TODO: what about device fonts?
+float
+Font::descent() const {
     return _fontTag ? _fontTag->descent() : 0.0f;
 }
     
@@ -392,8 +378,7 @@
 {
        // Mark device glyphs (textured and vector)
        for (GlyphInfoRecords::const_iterator i = _deviceGlyphTable.begin(),
-            e=_deviceGlyphTable.end(); i != e; ++i)
-       {
+            e=_deviceGlyphTable.end(); i != e; ++i) {
                i->markReachableResources();
        }
 

=== modified file 'libcore/Font.h'
--- a/libcore/Font.h    2009-03-05 10:58:01 +0000
+++ b/libcore/Font.h    2009-03-10 11:44:46 +0000
@@ -134,7 +134,7 @@
        shape_character_def* get_glyph(int glyph_index, bool embedded) const;
 
        /// Get name of this font. 
-       const std::string& get_name() const { return _name; }
+       const std::string& name() const { return _name; }
 
        /// Return the glyph index for a given character code
        //
@@ -187,10 +187,13 @@
        unsigned short int unitsPerEM(bool embedded) const;
 
     // TODO: what about device fonts?
-       float get_leading() const;
+    float ascent() const;
+        
+    // TODO: what about device fonts?
+       float leading() const;
  
     // TODO: what about device fonts?
-    float get_descent() const;
+    float descent() const;
         
        bool is_subpixel_font() const;
 
@@ -308,11 +311,6 @@
        /// Code to index table for device glyphs
        CodeTable _deviceCodeTable; 
 
-       // Layout stuff.
-       float m_ascent;
-       float m_descent;
-       float m_leading;
-
        typedef std::map<kerning_pair, float> kernings_table;
        kernings_table m_kerning_pairs;
 

=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp     2009-03-09 13:18:53 +0000
+++ b/libcore/MovieClip.cpp     2009-03-10 06:23:07 +0000
@@ -3102,7 +3102,7 @@
     boost::intrusive_ptr<MovieClip> movieclip =
         ensureType<MovieClip>(fn.this_ptr);
     UNUSED(movieclip);
-    log_unimpl(_("MovieClip.forceSmoothing()"));
+    LOG_ONCE(log_unimpl(_("MovieClip.forceSmoothing()")));
     return as_value();
 }
 
@@ -3113,7 +3113,7 @@
     boost::intrusive_ptr<MovieClip> movieclip =
         ensureType<MovieClip>(fn.this_ptr);
     UNUSED(movieclip);
-    log_unimpl(_("MovieClip.opaqueBackground()"));
+    LOG_ONCE(log_unimpl(_("MovieClip.opaqueBackground()")));
     return as_value();
 }
 
@@ -3124,7 +3124,7 @@
     boost::intrusive_ptr<MovieClip> movieclip =
         ensureType<MovieClip>(fn.this_ptr);
     UNUSED(movieclip);
-    log_unimpl(_("MovieClip.scale9Grid()"));
+    LOG_ONCE(log_unimpl(_("MovieClip.scale9Grid()")));
     return as_value();
 }
 
@@ -3135,7 +3135,7 @@
     boost::intrusive_ptr<MovieClip> movieclip =
         ensureType<MovieClip>(fn.this_ptr);
     UNUSED(movieclip);
-    log_unimpl(_("MovieClip.scrollRect()"));
+    LOG_ONCE(log_unimpl(_("MovieClip.scrollRect()")));
     return as_value();
 }
 
@@ -3146,7 +3146,7 @@
     boost::intrusive_ptr<MovieClip> movieclip =
         ensureType<MovieClip>(fn.this_ptr);
     UNUSED(movieclip);
-    log_unimpl(_("MovieClip.tabIndex()"));
+    LOG_ONCE(log_unimpl(_("MovieClip.tabIndex()")));
     return as_value();
 }
 

=== modified file 'libcore/RGBA.h'
--- a/libcore/RGBA.h    2009-01-05 09:32:03 +0000
+++ b/libcore/RGBA.h    2009-03-10 08:50:13 +0000
@@ -72,6 +72,11 @@
                        return (m_r<<16) + (m_g<<8) + m_b;
                }
 
+        boost::uint32_t toRGBA() const
+        {
+            return toRGB() + (m_a << 24);
+        }
+
                /// Initialize from input stream.
                //
                ///

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2009-02-26 18:48:57 +0000
+++ b/libcore/TextField.cpp     2009-03-10 11:44:46 +0000
@@ -891,7 +891,7 @@
           log_error(_("TextField: missing glyph for space char (needed "
                   "for TAB). Make sure character shapes for font "
                   "%s are being exported into your SWF file."),
-                rec.getFont()->get_name());
+                rec.getFont()->name());
         );
     }
     else
@@ -953,8 +953,8 @@
 
     boost::uint16_t fontHeight = getFontHeight();
     float scale = fontHeight / (float)_font->unitsPerEM(_embedFonts); 
-    float fontDescent = _font->get_descent() * scale; 
-    float fontLeading = _font->get_leading() * scale;
+    float fontDescent = _font->descent() * scale; 
+    float fontLeading = _font->leading() * scale;
     boost::uint16_t leftMargin = getLeftMargin();
     boost::uint16_t rightMargin = getRightMargin();
     boost::uint16_t indent = getIndent();
@@ -1130,14 +1130,14 @@
                                     "glyph for char %d. Make sure character "
                                     "shapes for font %s are being exported "
                                     "into your SWF file"),
-                                    code, _font->get_name());
+                                    code, _font->name());
                             }
                             else
                             {
                                 log_swferror(_("TextField: missing device "
                                     "glyph for char %d. Maybe you don't have "
                                     "font '%s' installed in your system."),
-                                    code, _font->get_name());
+                                    code, _font->name());
                             }
                         }
 
@@ -2372,7 +2372,7 @@
     const Font* font = text->getFont();
     if (font)
     {
-        tf->fontSet(font->get_name());
+        tf->fontSet(font->name());
         tf->italicedSet(font->isItalic());
         tf->boldSet(font->isBold());
     }

=== modified file 'libcore/asobj/TextSnapshot_as.cpp'
--- a/libcore/asobj/TextSnapshot_as.cpp 2009-03-09 18:23:02 +0000
+++ b/libcore/asobj/TextSnapshot_as.cpp 2009-03-10 12:22:29 +0000
@@ -33,6 +33,8 @@
 #include "MovieClip.h"
 #include "Font.h"
 #include "swf/TextRecord.h"
+#include "Array_as.h"
+#include "RGBA.h"
 
 #include <boost/algorithm/string/compare.hpp>
 #include <boost/dynamic_bitset.hpp>
@@ -137,7 +139,7 @@
 }
 
 bool
-TextSnapshot_as::getSelected(size_t start, size_t end)
+TextSnapshot_as::getSelected(size_t start, size_t end) const
 {
     start = std::min(start, _selected.size());
     end = std::min(end, _selected.size());
@@ -155,22 +157,92 @@
 }
 
 void
+TextSnapshot_as::getTextRunInfo(size_t start, size_t end, Array_as& ri) const
+{
+    std::string::size_type pos = 0;
+
+    std::string::size_type len = end - start;
+
+    for (TextFields::const_iterator field = _textFields.begin(),
+            e = _textFields.end(); field != e; ++field) {
+
+        const Records& rec = field->second;
+        const SWFMatrix& mat = field->first->getMatrix();
+
+        for (Records::const_iterator j = rec.begin(), end = rec.end();
+                j != end; ++j) {
+        
+            const SWF::TextRecord* tr = *j;
+            assert(tr);
+
+            const SWF::TextRecord::Glyphs& glyphs = tr->glyphs();
+            const SWF::TextRecord::Glyphs::size_type numGlyphs = glyphs.size();
+
+            if (pos + numGlyphs < start) {
+                pos += numGlyphs;
+                continue;
+            }
+
+            const Font* font = tr->getFont();
+            assert(font);
+
+            double x = tr->xOffset();
+            for (SWF::TextRecord::Glyphs::const_iterator k = glyphs.begin(),
+                    e = glyphs.end(); k != e; ++k) {
+                
+                if (pos < start) {
+                    x += k->advance;
+                    ++pos;
+                    continue;
+                }
+                
+                as_object* el = new as_object;
+
+                el->init_member("indexInRun", pos);
+                el->init_member("selected", _selected.test(pos));
+                el->init_member("font", font->name());
+                el->init_member("color", tr->color().toRGBA());
+                el->init_member("height", TWIPS_TO_PIXELS(tr->textHeight()));
+
+                const double factor = 65536.0;
+                el->init_member("matrix_a", mat.sx / factor);
+                el->init_member("matrix_b", mat.shx / factor);
+                el->init_member("matrix_c", mat.shy / factor);
+                el->init_member("matrix_d", mat.sy / factor);
+
+                const double xpos = TWIPS_TO_PIXELS(mat.tx + x);
+                const double ypos = TWIPS_TO_PIXELS(mat.ty + tr->yOffset());
+                el->init_member("matrix_tx", xpos);
+                el->init_member("matrix_ty", ypos);
+
+                ri.push(el);
+
+                ++pos;
+                x += k->advance;
+                if (pos - start > len) return;
+            }
+        }
+    }
+    
+}
+
+void
 TextSnapshot_as::makeString(std::string& to, bool newline,
         std::string::size_type start, std::string::size_type len) const
 {
 
     std::string::size_type pos = 0;
 
-    for (TextFields::const_iterator it = _textFields.begin(),
-            e = _textFields.end(); it != e; ++it)
+    for (TextFields::const_iterator field = _textFields.begin(),
+            e = _textFields.end(); field != e; ++field)
     {
         // When newlines are requested, insert one after each individual
         // text field is processed.
         if (newline && pos > start) to += '\n';
 
-        const Records& rec = it->second;
+        const Records& records = field->second;
 
-        for (Records::const_iterator j = rec.begin(), end = rec.end();
+        for (Records::const_iterator j = records.begin(), end = records.end();
                 j != end; ++j) {
         
             const SWF::TextRecord* tr = *j;
@@ -190,16 +262,20 @@
             for (SWF::TextRecord::Glyphs::const_iterator k = glyphs.begin(),
                     e = glyphs.end(); k != e; ++k) {
                 
-                if (pos++ < start) continue;
+                if (pos < start) {
+                    ++pos;
+                    continue;
+                }
                 
                 to += font->codeTableLookup(k->index, true);
-                if (pos - start >= len) return;
+                ++pos;
+                if (pos - start == len) return;
             }
         }
     }
 }
 
-const std::string
+std::string
 TextSnapshot_as::getText(boost::int32_t start, boost::int32_t end, bool nl)
     const
 {
@@ -317,9 +393,26 @@
        return o.get();
 }
 
-as_value textsnapshot_getTextRunInfo(const fn_call& /*fn*/) {
-    log_unimpl (__FUNCTION__);
-    return as_value();
+as_value
+textsnapshot_getTextRunInfo(const fn_call& fn)
+{
+    boost::intrusive_ptr<TextSnapshot_as> ts =
+        ensureType<TextSnapshot_as>(fn.this_ptr);
+    
+    if (!ts->valid()) return as_value();
+
+    if (fn.nargs != 2) {
+        return as_value();
+    }
+
+    size_t start = std::max(0, fn.arg(0).to_int());
+    size_t end = std::max<int>(start + 1, fn.arg(1).to_int());
+
+    Array_as* ri = new Array_as;
+
+    ts->getTextRunInfo(start, end, *ri);
+    
+    return as_value(ri);
 }
 
 as_value

=== modified file 'libcore/asobj/TextSnapshot_as.h'
--- a/libcore/asobj/TextSnapshot_as.h   2009-03-09 17:52:50 +0000
+++ b/libcore/asobj/TextSnapshot_as.h   2009-03-10 08:50:13 +0000
@@ -26,6 +26,7 @@
 // Forward declarations.
 namespace gnash {
     class generic_character;
+    class Array_as;
     namespace SWF {
         class TextRecord;
     }
@@ -52,26 +53,26 @@
     ///                 AS return values.
     TextSnapshot_as(const MovieClip* mc);
 
-    const std::string getText(boost::int32_t start, boost::int32_t end,
+    static void init(as_object& global);
+
+    std::string getText(boost::int32_t start, boost::int32_t end,
             bool nl) const;
 
     boost::int32_t findText(boost::int32_t start, const std::string& text,
             bool ignoreCase) const;
 
-    static void init(as_object& global);
-
-    static void construct(const std::string& snapshot);
-
     bool valid() const { return _valid; }
 
     size_t getCount() const { return _count; }
 
     void setSelected(size_t start, size_t end, bool selected);
     
-    bool getSelected(size_t start, size_t end);
+    bool getSelected(size_t start, size_t end) const;
 
     std::string getSelectedText(bool newlines) const;
 
+    void getTextRunInfo(size_t start, size_t end, Array_as& ri) const;
+
 protected:
 
     void markReachableResources() const;
@@ -88,13 +89,13 @@
     //
     /// This should be deducible from another member, but since there seems
     /// to be no point in storing the MovieClip this bool will do instead.
-    bool _valid;
+    const bool _valid;
 
     /// The number of characters
     //
     /// There is no need to store this, but it is quicker than counting
     /// afresh every time.
-    size_t _count;
+    const size_t _count;
 
     /// Characters in the text run are selected individually.
     //

=== modified file 'libcore/swf/DefineFontTag.cpp'
--- a/libcore/swf/DefineFontTag.cpp     2009-01-22 20:10:39 +0000
+++ b/libcore/swf/DefineFontTag.cpp     2009-03-10 06:31:07 +0000
@@ -204,7 +204,8 @@
     // Next is language code, always 0 for SWF5 or previous
     int languageCode = in.read_u8();
     if (languageCode) {
-        LOG_ONCE(log_unimpl("LanguageCode in DefineFont (2 or 3)"));
+        LOG_ONCE(log_unimpl("LanguageCode (%d) in DefineFont tag",
+                    languageCode));
     }
 
     in.read_string_with_length(_name);

=== modified file 'libcore/swf/TextRecord.cpp'
--- a/libcore/swf/TextRecord.cpp        2009-02-08 09:46:26 +0000
+++ b/libcore/swf/TextRecord.cpp        2009-03-10 08:50:13 +0000
@@ -86,7 +86,7 @@
         IF_VERBOSE_PARSE(
             log_parse(_("  hasColor"));
         );
-    } 
+    }
 
     if (_hasXOffset)
     {

=== modified file 'libcore/swf/TextRecord.h'
--- a/libcore/swf/TextRecord.h  2009-01-22 20:10:39 +0000
+++ b/libcore/swf/TextRecord.h  2009-03-10 08:50:13 +0000
@@ -51,7 +51,7 @@
 
     TextRecord()
         :
-        _color(0, 0, 0, 255),
+        _color(0, 0, 0, 0),
         _textHeight(0),
         _hasXOffset(false),
         _hasYOffset(false),

=== modified file 'testsuite/misc-ming.all/TextSnapshotTest.c'
--- a/testsuite/misc-ming.all/TextSnapshotTest.c        2009-03-09 17:52:50 
+0000
+++ b/testsuite/misc-ming.all/TextSnapshotTest.c        2009-03-10 12:22:29 
+0000
@@ -181,19 +181,109 @@
   check_equals(mo, "ts.getSelected(28)", "undefined");
   check_equals(mo, "ts.getSelected(20)", "undefined");
 
-  // Check that selected text is not a property of the text itself.
+  // Selected text is stored in the textfield and reset when a new
+  // snapshot is taken.
   add_actions(mo, "ts2 = new TextSnapshot(this);");
+  xcheck_equals(mo, "ts.getSelectedText(false)", "''");
   check_equals(mo, "ts2.getCount()", "64");
   check_equals(mo, "ts2.getSelectedText()", "''");
   add_actions(mo, "ts2 = this.getTextSnapshot();");
   check_equals(mo, "ts2.getCount()", "64");
   check_equals(mo, "ts2.getSelectedText()", "''");
 
-  add_actions(mo, "ts2.setSelected(3, 10);");
+  add_actions(mo, "ts2.setSelected(3, 10, true);");
+  check_equals(mo, "ts2.getSelectedText(false).length", "7");
+  xcheck_equals(mo, "ts.getSelectedText(false).length", "7");
 
   add_actions(mo, "ts.setSelectedColor(0xffff00);");
   add_actions(mo, "ts2.setSelectedColor(0x0000ff);");
 
+  xcheck_equals(mo, "ts.getSelectedText(false)", "'st text'");
+  add_actions(mo, "ri = ts.getTextRunInfo(4, 10);");
+  check_equals(mo, "typeof(ri)", "'object'");
+  check(mo, "ri instanceof Array");
+  check_equals(mo, "ri.length", "7");
+
+  add_actions(mo, "el = ri[1];");
+  check_equals(mo, "typeof(el)", "'object'");
+  check(mo, "!el.hasOwnProperty('indexInRun')");
+  check_equals(mo, "el.indexInRun", "5");
+  check_equals(mo, "el.selected", "true");
+  check_equals(mo, "el.font", "'Bitstream Vera Sans'");
+  check_equals(mo, "el.color", "0");
+  check_equals(mo, "el.height", "12");
+  check_equals(mo, "el.matrix_a", "1");
+  check_equals(mo, "el.matrix_b", "0");
+  check_equals(mo, "el.matrix_c", "0");
+  check_equals(mo, "el.matrix_d", "1");
+  check_equals(mo, "el.matrix_tx", "25.95");
+  check_equals(mo, "el.matrix_ty", "200");
+  xcheck_equals(mo, "el.corner0x", "25.95");
+  xcheck_equals(mo, "el.corner0y", "202.8");
+  xcheck_equals(mo, "el.corner1x", "29.75");
+  xcheck_equals(mo, "el.corner1y", "202.8");
+  xcheck_equals(mo, "el.corner2x", "29.75");
+  xcheck_equals(mo, "el.corner2y", "188.85");
+  xcheck_equals(mo, "el.corner3x", "25.95");
+  xcheck_equals(mo, "el.corner3y", "188.85");
+
+  // Check properties individually
+  check_equals(mo, "ri[2].height", "12");
+  check_equals(mo, "ri[3].height", "12");
+  check_equals(mo, "ri[4].height", "12");
+  check_equals(mo, "ri[5].height", "12");
+  check_equals(mo, "ri[6].height", "12");
+
+  check_equals(mo, "ri[2].selected", "true");
+  check_equals(mo, "ri[3].selected", "true");
+  check_equals(mo, "ri[4].selected", "true");
+  check_equals(mo, "ri[5].selected", "true");
+  xcheck_equals(mo, "ri[6].selected", "false");
+
+  check_equals(mo, "ri[2].matrix_tx", "29.75");
+  check_equals(mo, "ri[2].matrix_ty", "200");
+  check_equals(mo, "ri[3].matrix_tx", "34.4");
+  check_equals(mo, "ri[3].matrix_ty", "200");
+  check_equals(mo, "ri[4].matrix_tx", "41.75");
+  check_equals(mo, "ri[4].matrix_ty", "200");
+
+  xcheck_equals(mo, "ri[2].corner0x", "29.75");
+  xcheck_equals(mo, "ri[2].corner0y", "202.8");
+  xcheck_equals(mo, "ri[3].corner0x", "34.4");
+  xcheck_equals(mo, "ri[3].corner0y", "202.8");
+  xcheck_equals(mo, "ri[4].corner0x", "41.75");
+  xcheck_equals(mo, "ri[4].corner0y", "202.8");
+  
+  xcheck_equals(mo, "ri[2].corner2y", "188.85");
+  xcheck_equals(mo, "ri[3].corner2y", "188.85");
+  xcheck_equals(mo, "ri[4].corner2y", "188.85");
+
+  add_actions(mo, "ts.setSelected(0, 10, true);");
+  add_actions(mo, "ts.setSelected(15, 20, false);");
+  xcheck_equals(mo, "ts2.getSelectedText().length", "10");
+
+  add_actions(mo, "ri2 = ts.getTextRunInfo(0, 100);");
+
+  check_equals(mo, "ri2[0].selected", "true");
+  check_equals(mo, "ri2[1].selected", "true");
+  check_equals(mo, "ri2[2].selected", "true");
+  check_equals(mo, "ri2[3].selected", "true");
+  check_equals(mo, "ri2[4].selected", "true");
+  check_equals(mo, "ri2[5].selected", "true");
+  check_equals(mo, "ri2[6].selected", "true");
+  check_equals(mo, "ri2[15].selected", "false");
+  check_equals(mo, "ri2[16].selected", "false");
+  check_equals(mo, "ri2[17].selected", "false");
+  check_equals(mo, "ri2[18].selected", "false");
+
+  xcheck_equals(mo, "ri2[50].corner2y", "388.85");
+  xcheck_equals(mo, "ri2[50].corner2x", "154.55");
+  xcheck_equals(mo, "ri2[51].corner2y", "388.85");
+  xcheck_equals(mo, "ri2[51].corner2x", "161.9");
+
+  check_equals(mo, "ri2[50].matrix_tx", "149.6");
+  check_equals(mo, "ri2[51].matrix_tx", "154.5");
+
   add_actions(mo, "ts = this.getTextSnapshot();");
   check_equals(mo, "typeof(ts)", "'object'");
   add_actions(mo, "backup = TextSnapshot;");


reply via email to

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