gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/edit_text_character.cpp ...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/edit_text_character.cpp ...
Date: Tue, 24 Jul 2007 19:43:31 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/07/24 19:43:31

Modified files:
        .              : ChangeLog 
        server         : edit_text_character.cpp edit_text_character.h 
                         font.cpp font.h fontlib.cpp text.cpp text.h 
        server/parser  : text_character_def.cpp 

Log message:
                * server/font.{cpp,h}: Refactor class definition
                  to maintain two separate glyph information sets:
                  one for device and one for embedded glyphs. Added
                  a parameter to glyph-related accessors and mutators
                  to specify which set to use.
                * server/edit_text_character.{cpp,h}: update gnash::font
                  services call to select embedded or device fonts.
                * server/fontlib.cpp: updated calls to gnash::font so
                  to always use embedded ones (mostly caching stuff, which
                  is currently disabled)
                * server/text.{cpp,h}: add a boolean parameter to
                  display_glyph_records to specify wheter to use embedded
                  or device glyphs when fetching them from the font.
                * server/parser/text_character_def.cpp: use embedded glyphs.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3811&r2=1.3812
http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.cpp?cvsroot=gnash&r1=1.90&r2=1.91
http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.h?cvsroot=gnash&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.cpp?cvsroot=gnash&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.h?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/server/fontlib.cpp?cvsroot=gnash&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/gnash/server/text.cpp?cvsroot=gnash&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/gnash/server/text.h?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/text_character_def.cpp?cvsroot=gnash&r1=1.3&r2=1.4

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3811
retrieving revision 1.3812
diff -u -b -r1.3811 -r1.3812
--- ChangeLog   24 Jul 2007 17:41:33 -0000      1.3811
+++ ChangeLog   24 Jul 2007 19:43:29 -0000      1.3812
@@ -1,5 +1,22 @@
 2007-07-24 Sandro Santilli <address@hidden>
 
+       * server/font.{cpp,h}: Refactor class definition
+         to maintain two separate glyph information sets:
+         one for device and one for embedded glyphs. Added
+         a parameter to glyph-related accessors and mutators
+         to specify which set to use.
+       * server/edit_text_character.{cpp,h}: update gnash::font
+         services call to select embedded or device fonts.
+       * server/fontlib.cpp: updated calls to gnash::font so
+         to always use embedded ones (mostly caching stuff, which
+         is currently disabled)
+       * server/text.{cpp,h}: add a boolean parameter to
+         display_glyph_records to specify wheter to use embedded
+         or device glyphs when fetching them from the font.
+       * server/parser/text_character_def.cpp: use embedded glyphs.
+
+2007-07-24 Sandro Santilli <address@hidden>
+
        * server/parser/edit_text_character_def.h:
          initialize m_use_outlines to true (so dynamically-created
          textfields will use device fonts by default), provide

Index: server/edit_text_character.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/edit_text_character.cpp,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -b -r1.90 -r1.91
--- server/edit_text_character.cpp      24 Jul 2007 17:41:34 -0000      1.90
+++ server/edit_text_character.cpp      24 Jul 2007 19:43:30 -0000      1.91
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: edit_text_character.cpp,v 1.90 2007/07/24 17:41:34 strk Exp $ */
+/* $Id: edit_text_character.cpp,v 1.91 2007/07/24 19:43:30 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -389,7 +389,7 @@
        _drawBorder(m_def->has_border()),
        _borderColor(0,0,0,255),
        _textColor(m_def->get_text_color()),
-       _embedFont(m_def->getUseEmbeddedGlyphs())
+       _embedFonts(m_def->getUseEmbeddedGlyphs())
 {
        assert(parent);
        assert(m_def);
@@ -491,7 +491,7 @@
        
        
        display_glyph_records(m, this, m_text_glyph_records,
-                             m_def->get_root_def());
+                             m_def->get_root_def(), _embedFonts);
 
        if (m_has_focus)
        {
@@ -944,7 +944,7 @@
        float   leading = m_def->get_leading();
        leading += _font->get_leading() * scale;
 
-       int     last_code = -1;
+       int     last_code = -1; // only used if _embedFonts
        int     last_space_glyph = -1;
        int     last_line_start_record = 0;
 
@@ -968,8 +968,11 @@
 
                //uint16_t      code = m_text[j];
 
+               if ( _embedFonts )
+               {
                x += _font->get_kerning_adjustment(last_code, (int) code) * 
scale;
                last_code = static_cast<int>(code);
+               }
 
                // Expand the bounding-box to the lower-right corner of each 
glyph as
                // we generate it.
@@ -1060,7 +1063,7 @@
 
                if (code == 9) // tab (ASCII HT)
                {
-                       int index = _font->get_glyph_index(32); // ascii SPACE
+                       int index = _font->get_glyph_index(32, _embedFonts); // 
ascii SPACE
                        if ( index == -1 )
                        {
                                IF_VERBOSE_MALFORMED_SWF (
@@ -1075,7 +1078,7 @@
                        {
                                text_glyph_record::glyph_entry  ge;
                                ge.m_glyph_index = index;
-                               ge.m_glyph_advance = scale * 
_font->get_advance(index);
+                               ge.m_glyph_advance = scale * 
_font->get_advance(index, _embedFonts);
 
                                const int tabstop=8;
                                rec.m_glyphs.insert(rec.m_glyphs.end(), 
tabstop, ge);
@@ -1092,7 +1095,8 @@
 
                { // need a sub-scope to avoid the 'goto' in TAB handling to 
cross
                  // initialization of the 'index' variable
-               int index = _font->get_glyph_index((uint16_t) code);
+               int index = _font->get_glyph_index((uint16_t) code, 
_embedFonts);
+
                IF_VERBOSE_MALFORMED_SWF (
                    if (index == -1)
                    {
@@ -1103,22 +1107,34 @@
                            if (s_log_count < 10)
                            {
                                    s_log_count++;
-                                   log_swferror(_("%s -- missing glyph for 
char %d. "
+               
+                                       if ( _embedFonts )
+                                       {
+                                   log_swferror(_("%s -- missing embedded 
glyph for char %d. "
                                                " Make sure character shapes 
for font %s are being exported "
                                                "into your SWF file"),
                                                __PRETTY_FUNCTION__,
                                                code,
-                                               _font->get_name().c_str()
-                                   );
+                                               _font->get_name().c_str());
+                                       }
+                                       else
+                                       {
+                                   log_swferror(_("%s -- missing device glyph 
for char %d. "
+                                               " Maybe you don't have font 
'%s' installed in your system?"),
+                                               __PRETTY_FUNCTION__,
+                                               code,
+                                               _font->get_name().c_str());
+                                       }
                            }
 
                            // Drop through and use index == -1; this will 
display
                            // using the empty-box glyph
                    }
-               );
+               ); // IF_VERBOSE_MALFORMED_SWF
+
                text_glyph_record::glyph_entry  ge;
                ge.m_glyph_index = index;
-               ge.m_glyph_advance = scale * _font->get_advance(index);
+               ge.m_glyph_advance = scale * _font->get_advance(index, 
_embedFonts);
 
                rec.m_glyphs.push_back(ge);
 
@@ -1435,11 +1451,11 @@
 void
 edit_text_character::setEmbedFonts(bool use)
 {
-       if ( _embedFont != use )
+       if ( _embedFonts != use )
        {
                set_invalidated();
                format_text();
-               _embedFont=use;
+               _embedFonts=use;
        }
 }
 

Index: server/edit_text_character.h
===================================================================
RCS file: /sources/gnash/gnash/server/edit_text_character.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- server/edit_text_character.h        24 Jul 2007 17:41:34 -0000      1.41
+++ server/edit_text_character.h        24 Jul 2007 19:43:30 -0000      1.42
@@ -148,7 +148,7 @@
        /// Return true if this TextField should use embedded font glyphs,
        /// false if it should use device font glyphs
        bool getEmbedFonts() const {
-               return _embedFont;
+               return _embedFonts;
        }
 
        /// \brief
@@ -263,7 +263,7 @@
 
        rgba _textColor;
 
-       bool _embedFont;
+       bool _embedFonts;
 
 protected:
 

Index: server/font.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/font.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- server/font.cpp     24 Jul 2007 15:40:53 -0000      1.44
+++ server/font.cpp     24 Jul 2007 19:43:30 -0000      1.45
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: font.cpp,v 1.44 2007/07/24 15:40:53 strk Exp $ */
+/* $Id: font.cpp,v 1.45 2007/07/24 19:43:30 strk Exp $ */
 
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
@@ -33,6 +33,37 @@
 #include <utility> // for std::make_pair
 
 namespace gnash {
+
+GlyphInfo::GlyphInfo()
+       :
+       glyph(),
+       textureGlyph(),
+       advance(0)
+{}
+
+GlyphInfo::GlyphInfo(boost::intrusive_ptr<shape_character_def> nGlyph, float 
nAdvance)
+       :
+       glyph(nGlyph.get()),
+       textureGlyph(),
+       advance(nAdvance)
+{}
+
+GlyphInfo::GlyphInfo(const GlyphInfo& o)
+       :
+       glyph(o.glyph.get()),
+       textureGlyph(o.textureGlyph),
+       advance(o.advance)
+{}
+
+#ifdef GNASH_USE_GC
+void
+GlyphInfo::markReachableResources() const
+{
+       textureGlyph.markReachableResources();
+       if ( glyph ) glyph->setReachable();
+}
+#endif
+
        font::font()
                :
                m_texture_glyph_nominal_size(96),       // Default is not 
important; gets overridden during glyph generation
@@ -75,62 +106,65 @@
 
        font::~font()
        {
-               m_glyphs.resize(0); // there's no need for this !
+               //m_glyphs.resize(0); // there's no need for this !
        }
 
-       shape_character_def*    font::get_glyph(int index) const
+       shape_character_def*    font::get_glyph(int index, bool embedded) const
        {
-               if (index >= 0 && index < (int) m_glyphs.size())
+               const GlyphInfoVect& lookup = embedded ? _embedGlyphTable : 
_deviceGlyphTable;
+
+               if (index >= 0 && (size_t)index < lookup.size())
                {
-                       return m_glyphs[index].get();
+                       return lookup[index].glyph.get();
                }
                else
                {
+                       // TODO: should we log an error here ?
                        return NULL;
                }
        }
 
 
-       const texture_glyph&    font::get_texture_glyph(int glyph_index) const
-       // Return a pointer to a texture_glyph struct corresponding to
-       // the given glyph_index, if we have one.  
-       // Otherwise return a "dummy" texture_glyph.
+       const texture_glyph&    font::get_texture_glyph(int glyph_index, bool 
embedded) const
        {
-               if (glyph_index < 0 || glyph_index >= (int) 
m_texture_glyphs.size())
+               const GlyphInfoVect& lookup = embedded ? _embedGlyphTable : 
_deviceGlyphTable;
+
+               if (glyph_index < 0 || (size_t)glyph_index >= lookup.size())
                {
+                       // TODO: should we log an error here ?
                        static const texture_glyph      s_dummy_texture_glyph;
                        return s_dummy_texture_glyph;
                }
 
-               return m_texture_glyphs[glyph_index];
+               return lookup[glyph_index].textureGlyph;
        }
 
 
-       void    font::add_texture_glyph(int glyph_index, const texture_glyph& 
glyph)
-       // Register some texture info for the glyph at the specified
-       // index.  The texture_glyph can be used later to render the
-       // glyph.
+       void    font::add_texture_glyph(int glyph_index, const texture_glyph& 
glyph, bool embedded)
        {
-               assert(glyph_index >= 0 && glyph_index < (int) m_glyphs.size());
-               assert(m_texture_glyphs.size() == m_glyphs.size());
+               GlyphInfoVect& lookup = embedded ? _embedGlyphTable : 
_deviceGlyphTable;
+
+               assert(glyph_index >= 0 && (size_t)glyph_index < lookup.size());
                assert(glyph.is_renderable());
 
-               assert(m_texture_glyphs[glyph_index].is_renderable() == false);
+               assert(lookup[glyph_index].textureGlyph.is_renderable() == 
false);
 
-               m_texture_glyphs[glyph_index] = glyph;
+               lookup[glyph_index].textureGlyph = glyph;
        }
 
 
        void    font::wipe_texture_glyphs()
-       // Delete all our texture glyph info.
        {
-               assert(m_texture_glyphs.size() == m_glyphs.size());
 
                // Replace with default (empty) glyph info.
                texture_glyph   default_tg;
-               for (int i = 0, n = m_texture_glyphs.size(); i < n; i++)
+               for (size_t i = 0, n = _embedGlyphTable.size(); i < n; i++)
                {
-                       m_texture_glyphs[i] = default_tg;
+                       _embedGlyphTable[i].textureGlyph = default_tg;
+               }
+               for (size_t i = 0, n = _deviceGlyphTable.size(); i < n; i++)
+               {
+                       _deviceGlyphTable[i].textureGlyph = default_tg;
                }
        }
 
@@ -186,10 +220,7 @@
                        );
                }
 
-               // TODO: use a structure to hold all of these ?
-               m_glyphs.resize(count);
-               m_texture_glyphs.resize(count);
-               m_advance_table.resize(count);
+               _embedGlyphTable.resize(count);
 
                if (m->get_create_font_shapes() == DO_LOAD_FONT_SHAPES)
                {
@@ -208,7 +239,7 @@
                                shape_character_def* s = new 
shape_character_def;
                                s->read(in, SWF::DEFINEFONT, false, m); 
 
-                               m_glyphs[i] = s;
+                               _embedGlyphTable[i].glyph = s;
                        }}
                }
        }
@@ -291,10 +322,7 @@
                        font_code_offset = in->read_u16();
                }
 
-               // TODO: use a structure to hold all of these ?
-               m_glyphs.resize(glyph_count);
-               m_texture_glyphs.resize(glyph_count);
-               m_advance_table.resize(glyph_count);
+               _embedGlyphTable.resize(glyph_count);
 
                if (m->get_create_font_shapes() == DO_LOAD_FONT_SHAPES)
                {
@@ -317,7 +345,7 @@
                                shape_character_def* s = new 
shape_character_def;
                                s->read(in, SWF::DEFINEFONT2, false, m); // .. 
or DEFINEFONT3 actually..
 
-                               m_glyphs[i] = s;
+                               _embedGlyphTable[i].glyph = s;
                        }}
 
                        unsigned long current_position = in->get_position();
@@ -353,15 +381,15 @@
                        m_leading = (float) in->read_s16();
                        
                        // Advance table; i.e. how wide each character is.
-                       for (int i = 0, n = m_advance_table.size(); i < n; i++)
+                       for (int i = 0, n = _embedGlyphTable.size(); i < n; i++)
                        {
-                               m_advance_table[i] = (float) in->read_s16();
+                               _embedGlyphTable[i].advance = (float) 
in->read_s16();
                        }
 
                        // Bounds table.
                        //m_bounds_table.resize(m_glyphs.size());       // kill
                        rect    dummy_rect;
-                       {for (int i = 0, n = m_glyphs.size(); i < n; i++)
+                       {for (size_t i = 0, n = _embedGlyphTable.size(); i < n; 
i++)
                        {
                                //m_bounds_table[i].read(in);   // kill
                                dummy_rect.read(in);
@@ -450,42 +478,40 @@
        }
 
        void    font::read_code_table(stream* in)
-       // Read the table that maps from glyph indices to character
-       // codes.
        {
                IF_VERBOSE_PARSE (
                log_parse(_("reading code table at offset %lu"), 
in->get_position());
                );
 
-               assert(m_code_table.empty());
+               assert(_embedded_code_table.empty());
 
                if (m_wide_codes)
                {
                        // Code table is made of uint16_t's.
-                       for (int i=0, n=m_glyphs.size(); i<n; ++i)
+                       for (size_t i=0, n=_embedGlyphTable.size(); i<n; ++i)
                        {
                                uint16_t code = in->read_u16();
-                               //m_code_table.add(code, i);
-                               m_code_table.insert(std::make_pair(code, i));
+                               
_embedded_code_table.insert(std::make_pair(code, i));
                        }
                }
                else
                {
                        // Code table is made of bytes.
-                       for (int i=0, n=m_glyphs.size(); i<n; ++i)
+                       for (int i=0, n=_embedGlyphTable.size(); i<n; ++i)
                        {
                                uint8_t code = in->read_u8();
-                               //m_code_table.add(code, i);
-                               m_code_table.insert(std::make_pair(code, i));
+                               
_embedded_code_table.insert(std::make_pair(code, i));
                        }
                }
        }
 
-       int     font::get_glyph_index(uint16_t code) const
+       int     font::get_glyph_index(uint16_t code, bool embedded) const
        {
+               const code_table& ctable = embedded ? _embedded_code_table : 
_device_code_table;
+
                int glyph_index = -1;
-               code_table::const_iterator it = m_code_table.find(code);
-               if ( it != m_code_table.end() )
+               code_table::const_iterator it = ctable.find(code);
+               if ( it != ctable.end() )
                {
                        glyph_index = it->second;
 #if 0
@@ -496,7 +522,7 @@
                }
 
                // Try adding an os font, of possible
-               if ( _ftProvider.get() )
+               if ( ! embedded && _ftProvider.get() )
                {
                        glyph_index = 
const_cast<font*>(this)->add_os_glyph(code);
                }
@@ -506,32 +532,20 @@
                return glyph_index;
        }
 
-       float   font::get_advance(int glyph_index) const
+       float   font::get_advance(int glyph_index, bool embedded) const
        {
-               if (glyph_index == -1)
+               const GlyphInfoVect& lookup = embedded ? _embedGlyphTable : 
_deviceGlyphTable;
+
+               if (glyph_index <= -1)
                {
                        // Default advance.
                        return 512.0f;
                }
 
-               if (m_advance_table.size() == 0)
-               {
-                       // No layout info for this font!!!
-                       static bool     s_logged = false;
-                       if (s_logged == false)
-                       {
-                               s_logged = true;
-                               IF_VERBOSE_MALFORMED_SWF(
-                               log_swferror(_("empty advance table in font 
%s"), get_name().c_str());
-                               );
-                       }
-                       return 0;
-               }
-
-               if (glyph_index < (int) m_advance_table.size())
+               if ((size_t)glyph_index < lookup.size())
                {
                        assert(glyph_index >= 0);
-                       return m_advance_table[glyph_index];
+                       return lookup[glyph_index].advance;
                }
                else
                {
@@ -607,7 +621,7 @@
        font::add_os_glyph(uint16_t code)
        {
                assert ( _ftProvider.get() );
-               assert(m_code_table.find(code) == m_code_table.end());
+               assert(_device_code_table.find(code) == 
_device_code_table.end());
 
                float advance;
 
@@ -624,19 +638,12 @@
                }
 
                // Find new glyph offset
-               int newOffset = m_texture_glyphs.size();
+               int newOffset = _deviceGlyphTable.size();
 
                // Add the new glyph id
-               m_code_table[code] = newOffset;
+               _device_code_table[code] = newOffset;
 
-               // Add advance info
-               m_advance_table.push_back(advance);
-
-               // Add dummy textured glyph
-               m_texture_glyphs.push_back(texture_glyph());
-
-               // Add vector glyph
-               m_glyphs.push_back(sh);
+               _deviceGlyphTable.push_back(GlyphInfo(sh, advance));
 
                testInvariant();
 
@@ -670,16 +677,16 @@
 void
 font::markReachableResources() const
 {
-       // Mark textured glyphs
-       for (TextureGlyphVect::const_iterator i=m_texture_glyphs.begin(), 
e=m_texture_glyphs.end(); i!=e; ++i)
+       // Mark embed glyphs (textured and vector)
+       for (GlyphInfoVect::const_iterator i=_embedGlyphTable.begin(), 
e=_embedGlyphTable.end(); i!=e; ++i)
        {
                i->markReachableResources();
        }
 
-       // Mark vector glyphs
-       for (GlyphVect::const_iterator i=m_glyphs.begin(), e=m_glyphs.end(); 
i!=e; ++i)
+       // Mark device glyphs (textured and vector)
+       for (GlyphInfoVect::const_iterator i=_deviceGlyphTable.begin(), 
e=_deviceGlyphTable.end(); i!=e; ++i)
        {
-               (*i)->setReachable();
+               i->markReachableResources();
        }
 
 }

Index: server/font.h
===================================================================
RCS file: /sources/gnash/gnash/server/font.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- server/font.h       24 Jul 2007 17:45:03 -0000      1.27
+++ server/font.h       24 Jul 2007 19:43:30 -0000      1.28
@@ -128,6 +128,29 @@
        }
 }
 
+/// Glyph info structure
+struct GlyphInfo
+{
+       // no glyph, default textured glyph, 0 advance
+       GlyphInfo();
+
+       // given glyph and advance, default textured glyph
+       GlyphInfo(boost::intrusive_ptr<shape_character_def> nGlyph, float 
nAdvance);
+
+       GlyphInfo(const GlyphInfo&);
+
+#ifdef GNASH_USE_GC
+       /// Mark any glyph and texture glyph resources as reachable
+       void markReachableResources() const;
+#endif
+
+       boost::intrusive_ptr<shape_character_def> glyph;
+
+       texture_glyph textureGlyph;
+
+       float advance;
+};
+
 /// \brief
 /// A 'font' definition as read from SWF::DefineFont,
 /// SWF::DefineFont2 or SWF::DefineFont3 tags.
@@ -148,6 +171,7 @@
 
        void testInvariant()
        {
+#if 0
                assert(m_texture_glyphs.size() == m_glyphs.size());
 #ifndef NDEBUG
                if (m_texture_glyphs.size() != m_advance_table.size())
@@ -159,28 +183,36 @@
                        abort();
                }
 #endif
+#endif
        }
 
-       /// Get number of glyphs defined for this font
+       /// Get number of embedded glyphs defined for this font
        //
-       /// NOTE: for device fonts, this method will returns whatever
-       ///       number of glyphs the cache happens to have at time of
-       ///       calls. Anyway, the cache will grow if any font user
-       ///       requests more glyphs... 
-       ///       
        /// Callers of this function are:
        ///
        ///     - fontlib, for writing cache data (known to be not working 
anyway).
        ///     - edit_text_character, for validating the font (obsoleted too).
        ///
-       int     get_glyph_count() const
+       int     getEmbedGlyphCount() const
        {
-               log_error("FIXME: font::get_glyph_count() is a deprecated 
method");
-               return m_glyphs.size();
+               return _embedGlyphTable.size();
        }
 
-       /// Get glyph by index. Return NULL if out of range
-       shape_character_def*    get_glyph(int glyph_index) const;
+       /// Get glyph by index.
+       //
+       /// @param glyph_index
+       ///     Index of the glyph. See get_glyph_index() to obtain by 
character code.
+       ///
+       /// @param embedded
+       ///     If true, queries the 'embedded' glyphs table, 
+       ///     otherwise, looks in the 'device' font table.
+       ///
+       /// @return
+       ///     The glyph outline, or NULL if out of range.
+       ///     (would be a programming error most likely)
+       ///
+       ///
+       shape_character_def*    get_glyph(int glyph_index, bool embedded) const;
 
        /// Read a DefineFont or DefineFont2 tag from an SWF stream 
        //
@@ -207,7 +239,7 @@
        /// Read our cached data from the given stream.
        void    input_cached_data(tu_file* in);
 
-       /// Delete all our texture glyph info.
+       /// Delete all our texture glyph info (both embedded and device)
        void    wipe_texture_glyphs();
 
        /// Get name of this font. Warning: can be NULL.
@@ -221,37 +253,88 @@
        /// corresponding to the given glyph_index, if we
        /// have one.  Otherwise return a "dummy" texture_glyph.
        //
+       /// @param glyph_index
+       ///     Index of the glyph. See get_glyph_index() to obtain by 
character code.
+       ///
+       /// @param embedded
+       ///     If true, queries the 'embedded' glyphs table, 
+       ///     otherwise, looks in the 'device' font table.
+       ///
        /// Note: the "dummy" texture_glyph is a default-constructed
        /// texture_glyph.
        ///
-       const texture_glyph&    get_texture_glyph(int glyph_index) const;
+       const texture_glyph& get_texture_glyph(int glyph_index, bool embedded) 
const;
 
        /// \brief
        /// Register some texture info for the glyph at the specified
        /// index.  The texture_glyph can be used later to render the
        /// glyph.
        //
+       /// @param glyph_index
+       ///     Index of the glyph. See get_glyph_index() to obtain by 
character code.
+       ///
+       /// @param glyph
+       ///     The textured glyph.
+       ///
+       /// @param embedded
+       ///     If true, queries the 'embedded' glyphs table, 
+       ///     otherwise, looks in the 'device' font table.
+       ///
        /// TODO: deprecate this, probably only used by the caching mechanism
        ///
-       void    add_texture_glyph(int glyph_index, const texture_glyph& glyph);
+       void    add_texture_glyph(int glyph_index, const texture_glyph& glyph, 
bool embedded);
 
        void    set_texture_glyph_nominal_size(int size) { 
m_texture_glyph_nominal_size = imax(1, size); }
        int     get_texture_glyph_nominal_size() const { return 
m_texture_glyph_nominal_size; }
 
-       int     get_glyph_index(uint16_t code) const;
-       float   get_advance(int glyph_index) const;
+       /// Return the glyph index for a given character code
+       //
+       /// @param code
+       ///     Character code to fetch the corresponding glyph index of.
+       ///
+       /// @param embedded
+       ///     If true, queries the 'embedded' glyphs table, 
+       ///     otherwise, looks in the 'device' font table.
+       ///
+       /// Note, when querying device fonts, glyphs are created on demand,
+       /// this never happens for embedded fonts, in which case an unexistent
+       /// glyph results in a return of -1
+       ///
+       /// @return -1 if there is no glyph for the specified code or a valid
+       ///         positive index to use in subsequent calls to other 
glyph-index-based
+       ///         methods.
+       ///
+       int     get_glyph_index(uint16_t code, bool embedded) const;
+
+       /// Return the advance value for the given glyph index
+       //
+       /// @param glyph_index
+       ///     Index of the glyph. See get_glyph_index() to obtain by 
character code.
+       ///
+       /// @param embedded
+       ///     If true, queries the 'embedded' glyphs table, 
+       ///     otherwise, looks in the 'device' font table.
+       ///
+       float   get_advance(int glyph_index, bool embedded) const;
 
        /// \brief
        /// Return the adjustment in advance between the given two
-       /// characters. 
+       /// characters (makes sense for embedded glyphs only)
        //
        /// Normally this will be 0
        ///
+       /// NOTE: don't call this method when willing to work with device
+       ///       fonts, or you'll end up mixing information from device fonts
+       ///       with information from embedded fonts.
+       ///
        float   get_kerning_adjustment(int last_code, int this_code) const;
+
        float   get_leading() const { return m_leading; }
        float   get_descent() const { return m_descent; }
 
 private:
+
+       /// Read the table that maps from glyph indices to character codes.
        void    read_code_table(stream* in);
 
        /// Read a DefineFont2 or DefineFont3 tag
@@ -260,7 +343,7 @@
        /// Read a DefineFont tag
        void readDefineFont(stream* in, movie_definition* m);
 
-       /// Add a glyph from the os font.
+       /// Add a glyph from the os font into the device glyphs table
        //
        /// It is assumed that the glyph tables do NOT contain
        /// an entry for the given code.
@@ -275,11 +358,13 @@
        /// Return true on success, false on error
        bool initDeviceFontProvider();
 
-       typedef std::vector< boost::intrusive_ptr<shape_character_def> > 
GlyphVect;
-       GlyphVect m_glyphs;
+       typedef std::vector< GlyphInfo > GlyphInfoVect;
+
+       // Embedded glyphs
+       GlyphInfoVect _embedGlyphTable;
 
-       typedef std::vector< texture_glyph > TextureGlyphVect;
-       TextureGlyphVect m_texture_glyphs;      // cached info, built by 
gnash_fontlib.
+       // Device glyphs
+       GlyphInfoVect _deviceGlyphTable;
 
        int     m_texture_glyph_nominal_size;
 
@@ -296,13 +381,18 @@
 
        // This table maps from Unicode character number to glyph index.
        typedef std::map<uint16_t, int> code_table;
-       code_table m_code_table; 
+
+       /// Code to index table for embedded glyphs
+       code_table _embedded_code_table; 
+
+       /// Code to index table for device glyphs
+       code_table _device_code_table; 
 
        // Layout stuff.
        float   m_ascent;
        float   m_descent;
        float   m_leading;
-       std::vector<float>      m_advance_table;
+       //std::vector<float>    m_advance_table;
 
        typedef std::map<kerning_pair, float> kernings_table;
        kernings_table m_kerning_pairs;

Index: server/fontlib.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/fontlib.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- server/fontlib.cpp  13 Jul 2007 16:05:08 -0000      1.32
+++ server/fontlib.cpp  24 Jul 2007 19:43:30 -0000      1.33
@@ -5,7 +5,7 @@
 
 // A module to take care of all of gnash's loaded fonts.
 
-/* $Id: fontlib.cpp,v 1.32 2007/07/13 16:05:08 strk Exp $ */
+/* $Id: fontlib.cpp,v 1.33 2007/07/24 19:43:30 strk Exp $ */
 
 #include "container.h"
 #include "tu_file.h"
@@ -231,6 +231,9 @@
 
        void    finish_current_texture(movie_definition* owner)
        {
+
+               bool embed=true; // use embedded fonts
+
                if (s_pending_glyphs.size() == 0)
                {
                        return;
@@ -297,7 +300,7 @@
                        assert(pgi->m_source_font != NULL);
 
                        pgi->m_texture_glyph.set_bitmap_info(bi.get());
-                       
pgi->m_source_font->add_texture_glyph(pgi->m_glyph_index, pgi->m_texture_glyph);
+                       
pgi->m_source_font->add_texture_glyph(pgi->m_glyph_index, pgi->m_texture_glyph, 
embed);
                        //s_pending_glyphs[i]->set_bitmap_info(bi.get());
                        }
                }
@@ -658,6 +661,8 @@
        // fonts that use the same dummy glyph for many undefined
        // characters.
        {
+               bool embed=true; // use embedded fonts
+
                const map<unsigned int, const 
rendered_glyph_info*>::const_iterator image =
                        image_hash.find(rgi.m_image_hash);
 
@@ -678,7 +683,7 @@
                                texture_glyph   identical_tg =
                                        identical_image->
                                        m_source_font->
-                                       
get_texture_glyph(identical_image->m_glyph_index);
+                                       
get_texture_glyph(identical_image->m_glyph_index, embed); 
 
                                if (identical_tg.is_renderable() == false)
                                {
@@ -720,7 +725,7 @@
                                {
                                        // This image is already packed and has 
a valid bitmap_info.
                                        // Push straight into our font.
-                                       
rgi.m_source_font->add_texture_glyph(rgi.m_glyph_index, tg);
+                                       
rgi.m_source_font->add_texture_glyph(rgi.m_glyph_index, tg, embed); // embed 
font only
                                }
                                else
                                {
@@ -904,13 +909,15 @@
        {
                assert(f);
 
+               bool embed=true; // use embedded fonts
+
                f->set_texture_glyph_nominal_size(s_glyph_nominal_size);
 
-               for (int i = 0, n = f->get_glyph_count(); i < n; i++)
+               for (int i = 0, n = f->getEmbedGlyphCount(); i < n; i++)
                {
-                       if (f->get_texture_glyph(i).is_renderable() == false)
+                       if (f->get_texture_glyph(i, embed).is_renderable() == 
false) 
                        {
-                               shape_character_def*    sh = f->get_glyph(i);
+                               shape_character_def*    sh = f->get_glyph(i, 
embed); 
                                if (sh)
                                {
                                        rect    glyph_bounds;
@@ -1014,6 +1021,8 @@
        {
                assert(out);
 
+               bool embed=true; // use embedded glyphs
+
                // skip number of bitmaps.
                int     bitmaps_used_base = owner->get_bitmap_info_count();
                int     size_pos = out->get_position();
@@ -1050,7 +1059,7 @@
                        out->write_le16(nominal_glyph_size);
 
                        // skip number of glyphs.
-                       int ng = fonts[f]->get_glyph_count();
+                       int ng = fonts[f]->getEmbedGlyphCount();
                        int ng_position = out->get_position();
                        out->write_le32(0);
                        
@@ -1059,7 +1068,7 @@
                        // save texture glyphs:
                        for (int g = 0; g < ng; g++)
                        {
-                               const texture_glyph& tg = 
fonts[f]->get_texture_glyph(g);
+                               const texture_glyph& tg = 
fonts[f]->get_texture_glyph(g, embed);
                                if (tg.is_renderable())
                                {
                                        // save glyph index.
@@ -1113,6 +1122,8 @@
        void    input_cached_data(tu_file* in, const std::vector<font*>& fonts, 
movie_definition* owner)
        // Load a stream containing previously-saved font glyph textures.
        {
+               bool embed=true; // use embedded glyphs
+
                // load number of bitmaps.
                int nb = in->read_le16();
 
@@ -1220,17 +1231,17 @@
                                tg.m_uv_origin.m_x = in->read_float32();
                                tg.m_uv_origin.m_y = in->read_float32();
 
-                               if (glyph_index < 0 || glyph_index >= 
fnt->get_glyph_count())
+                               if (glyph_index < 0 || glyph_index >= 
fnt->getEmbedGlyphCount())
                                {
                                        // Cached data doesn't match this font!
                                        log_error("invalid glyph index %d in 
cached font data, limit is %d, font is '%s'\n",
                                                  glyph_index,
-                                                 fnt->get_glyph_count(),
+                                                 fnt->getEmbedGlyphCount(),
                                                  fnt->get_name().c_str());
                                }
                                else
                                {
-                                       fnt->add_texture_glyph(glyph_index, tg);
+                                       fnt->add_texture_glyph(glyph_index, tg, 
embed);
                                }
                        }
 

Index: server/text.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/text.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- server/text.cpp     11 Jul 2007 16:52:47 -0000      1.33
+++ server/text.cpp     24 Jul 2007 19:43:30 -0000      1.34
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: text.cpp,v 1.33 2007/07/11 16:52:47 strk Exp $ */
+/* $Id: text.cpp,v 1.34 2007/07/24 19:43:30 strk Exp $ */
 
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
@@ -74,7 +74,7 @@
                character* inst,
                const std::vector<text_glyph_record>& records,
                // root_def was used to resove fonts, now done at parse time
-               movie_definition* /*root_def*/)
+               movie_definition* /*root_def*/, bool useEmbeddedGlyphs)
        {
                //GNASH_REPORT_FUNCTION;
                
@@ -181,8 +181,8 @@
                                }
                                else
                                {
-                                       const texture_glyph&    tg = 
fnt->get_texture_glyph(index);
-                                       shape_character_def*    glyph = 
fnt->get_glyph(index);
+                                       const texture_glyph&    tg = 
fnt->get_texture_glyph(index, useEmbeddedGlyphs);
+                                       shape_character_def*    glyph = 
fnt->get_glyph(index, useEmbeddedGlyphs);
 
                                        if (tg.is_renderable()
                                            && (use_glyph_textures || glyph == 
NULL))

Index: server/text.h
===================================================================
RCS file: /sources/gnash/gnash/server/text.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- server/text.h       1 Jul 2007 10:54:25 -0000       1.17
+++ server/text.h       24 Jul 2007 19:43:30 -0000      1.18
@@ -84,11 +84,16 @@
        };
 
        /// Render the given glyph records.
+       //
+       /// @param useEmbeddedGlyphs
+       ///     If true, the font will be queried for embedded glyphs.
+       ///     Otherwise, the font will be queried for device fonts.
+       ///
        void display_glyph_records(
                const matrix& this_mat,
                character* inst,
                const std::vector<text_glyph_record>& records,
-               movie_definition* root_def);
+               movie_definition* root_def, bool useEmbeddedGlyphs);
 
 } // namespace gnash
 

Index: server/parser/text_character_def.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/text_character_def.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- server/parser/text_character_def.cpp        18 Apr 2007 14:07:32 -0000      
1.3
+++ server/parser/text_character_def.cpp        24 Jul 2007 19:43:30 -0000      
1.4
@@ -148,8 +148,11 @@
 void text_character_def::display(character* inst)
 {
 //     GNASH_REPORT_FUNCTION;
+
+       bool useEmbeddedGlyphs = true;
+
        display_glyph_records(m_matrix, inst,
-               m_text_glyph_records, m_root_def);
+               m_text_glyph_records, m_root_def, useEmbeddedGlyphs); 
 }
 
 }      // end namespace gnash




reply via email to

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