gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10252: Finish main font parsing sep


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10252: Finish main font parsing separation.
Date: Sat, 08 Nov 2008 23:24:43 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10252
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2008-11-08 23:24:43 +0100
message:
  Finish main font parsing separation.
added:
  libcore/swf/DefineFontNameTag.h
modified:
  libcore/Font.cpp
  libcore/Font.h
  libcore/impl.cpp
  libcore/swf/DefineFontTag.cpp
  libcore/swf/DefineFontTag.h
  libcore/swf/tag_loaders.cpp
  libcore/swf/tag_loaders.h
    ------------------------------------------------------------
    revno: 10244.1.8
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sat 2008-11-08 23:02:22 +0100
    message:
      Move all font parsing out of the Font class.
    added:
      libcore/swf/DefineFontNameTag.h
    modified:
      libcore/Font.cpp
      libcore/Font.h
      libcore/impl.cpp
      libcore/swf/DefineFontTag.cpp
      libcore/swf/DefineFontTag.h
      libcore/swf/tag_loaders.cpp
      libcore/swf/tag_loaders.h
=== modified file 'libcore/Font.cpp'
--- a/libcore/Font.cpp  2008-11-08 18:45:25 +0000
+++ b/libcore/Font.cpp  2008-11-08 22:02:22 +0000
@@ -22,13 +22,10 @@
 
 #include "smart_ptr.h" // GNASH_USE_GC
 #include "Font.h"
-#include "SWFStream.h"
 #include "log.h"
-#include "movie_definition.h"
 #include "shape_character_def.h"
-#include "swf.h"
-#include "GnashException.h"
 #include "DefineFontTag.h"
+#include "FreetypeGlyphsProvider.h"
 
 #include <utility> // for std::make_pair
 
@@ -66,14 +63,11 @@
     :
     _fontTag(ft.release()),
     _name(_fontTag->name()),
-    m_display_name(),
-    m_copyright_name(),
-    m_unicode_chars(_fontTag->unicodeChars()),
-    m_shift_jis_chars(_fontTag->shiftJISChars()),
-    m_ansi_chars(_fontTag->ansiChars()),
+    _unicodeChars(_fontTag->unicodeChars()),
+    _shiftJISChars(_fontTag->shiftJISChars()),
+    _ansiChars(_fontTag->ansiChars()),
     _italic(_fontTag->italic()),
-    _bold(_fontTag->bold()),
-    m_wide_codes(_fontTag->wideCodes())
+    _bold(_fontTag->bold())
 {
     if (_fontTag->hasCodeTable()) _embeddedCodeTable = 
_fontTag->getCodeTable();
 }
@@ -82,14 +76,11 @@
     :
     _fontTag(0),
     _name(name),
-    m_display_name(),
-    m_copyright_name(),
-    m_unicode_chars(false),
-    m_shift_jis_chars(false),
-    m_ansi_chars(true),
+    _unicodeChars(false),
+    _shiftJISChars(false),
+    _ansiChars(true),
     _italic(italic),
-    _bold(bold),
-    m_wide_codes(false)
+    _bold(bold)
 {
     assert(!_name.empty());
 }
@@ -117,55 +108,71 @@
     }
 }
 
-
-// Read the font name, display and legal, from a DefineFontName tag.
-void Font::read_font_name(SWFStream& in, SWF::tag_type tag,
-    movie_definition& /*m*/) 
-{
-    assert(tag == SWF::DEFINEFONTNAME);
-    in.read_string(m_display_name);
-    in.read_string(m_copyright_name);
-}
-
-// TODO: move libcore/swf
-// Read additional information about this font, from a
-// DefineFontInfo tag.  The caller has already read the tag
-// type and font id.
-void   Font::read_font_info(SWFStream& in, SWF::tag_type tag,
-        movie_definition& /*m*/)
-{
-    assert(tag == SWF::DEFINEFONTINFO || tag == SWF::DEFINEFONTINFO2); 
-
-    if ( tag == SWF::DEFINEFONTINFO2 )
-    {
-        // See: SWFalexref/SWFalexref.html#tag_definefont2
-        LOG_ONCE(log_unimpl(_("DefineFontInfo2 partially implemented")));
-    }
-
-    // Can a DefineFontInfo or DefineFontInfo2 tag possibly be called on
-    // a device-only font? Otherwise the font won't exist.
-    assert(_fontTag.get());
-
-    in.read_string_with_length(_name);
-
-    in.ensureBytes(1);
-    int        flags = in.read_u8();
-    // highest two bits are reserved.
-    m_unicode_chars   = flags & (1 << 5); //???
-    m_shift_jis_chars = flags & (1 << 4);
-    m_ansi_chars      = flags & (1 << 3);
-    _italic       = flags & (1 << 2);
-    _bold         = flags & (1 << 1);
-    m_wide_codes      = flags & (1 << 0);
-
-    std::auto_ptr<CodeTable> table(new CodeTable);
-    SWF::DefineFontTag::readCodeTable(in, *table, m_wide_codes,
-            _fontTag->glyphTable().size());
-
+void
+Font::addFontNameInfo(const FontNameInfo& fontName)
+{
+    if (!_displayName.empty() || !_copyrightName.empty())
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+            log_swferror(_("Attempt to set font display or copyright name"
+                    "again. This should mean there is more than one "
+                    "DefineFontName tag referring to the same Font. Don't "
+                    "know what to do in this case, so ignoring."));
+        );
+        return;
+    }
+
+    _displayName = fontName.displayName;
+    _copyrightName = fontName.copyrightName;
+}
+
+
+Font::GlyphInfoRecords::size_type
+Font::glyphCount() const
+{
+        assert(_fontTag);
+        return _fontTag->glyphTable().size();
+}
+
+
+void
+Font::setFlags(boost::uint8_t flags)
+{
+    _shiftJISChars = flags & (1 << 6);
+    _unicodeChars = flags & (1 << 5);
+    _ansiChars = flags & (1 << 4);
+    _italic = flags & (1 << 1);
+    _bold = flags & (1 << 0);
+}
+
+
+void
+Font::setCodeTable(std::auto_ptr<CodeTable> table)
+{
+    if (_embeddedCodeTable)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+            log_swferror(_("Attempt to add an embedded glyph CodeTable to "
+                    "a font that already has one. This should mean there "
+                    "are several DefineFontInfo tags, or a DefineFontInfo "
+                    "tag refers to a font created by DefineFone2 or "
+                    "DefineFont3. Don't know what should happen in this "
+                    "case, so ignoring."));
+        );
+        return;
+    }
     _embeddedCodeTable.reset(table.release());
 }
 
-int    Font::get_glyph_index(boost::uint16_t code, bool embedded) const
+    
+void
+Font::setName(const std::string& name)
+{
+    _name = name;
+}
+
+int
+Font::get_glyph_index(boost::uint16_t code, bool embedded) const
 {
     const CodeTable& ctable = (embedded && _embeddedCodeTable) ? 
         *_embeddedCodeTable : _deviceCodeTable;

=== modified file 'libcore/Font.h'
--- a/libcore/Font.h    2008-11-08 19:14:15 +0000
+++ b/libcore/Font.h    2008-11-08 22:02:22 +0000
@@ -24,20 +24,15 @@
 #define GNASH_FONT_H
 
 #include "smart_ptr.h" // GNASH_USE_GC
-
 #include "ExportableResource.h" 
-#include "swf.h" // for tag_type definition
-#include "bitmap_info.h" // for dtor visibility by smart pointer
-#include "FreetypeGlyphsProvider.h" // for device fonts support
-#include "log.h"
 
 #include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 #include <map>
 
 namespace gnash {
-    class movie_definition;
     class shape_character_def;
-    class SWFStream;
+    class FreetypeGlyphsProvider;
     namespace SWF {
         class DefineFontTag;
     }
@@ -142,26 +137,7 @@
        ///
        shape_character_def*    get_glyph(int glyph_index, bool embedded) const;
 
-       /// \brief
-       /// Read additional information about this font, from a
-       /// DefineFontInfo or DefineFontInfo2 tag. 
-       //
-       /// The caller has already read the tag type and font id.
-       ///
-       /// @see SWF::define_font_info_loader
-       ///
-       void read_font_info(SWFStream& in, SWF::tag_type tag, movie_definition& 
m);
-
-    /// \brief
-    /// Read the name of this font, from a DEFINEFONTNAME tag.
-    //
-    /// The caller has already read the tag type and font id.
-    //
-    /// @see SWF::define_font_name_loader
-    ///
-    void read_font_name(SWFStream& in, SWF::tag_type tag, movie_definition& m);
-
-       /// Get name of this font. Warning: can be NULL.
+       /// Get name of this font. 
        const std::string& get_name() const { return _name; }
 
        /// Return the glyph index for a given character code
@@ -225,6 +201,15 @@
        bool isBold() const { return _bold; }
        bool isItalic() const { return _italic; }
 
+    /// A pair of strings describing the font.
+    //
+    /// Used by the DefineFontName tag, usefulness unclear.
+    struct FontNameInfo
+    {
+        std::string displayName;
+        std::string copyrightName;
+    };
+
     /// Glyph info structure
     struct GlyphInfo
     {
@@ -249,6 +234,32 @@
 
        typedef std::vector<GlyphInfo> GlyphInfoRecords;
 
+    /// Add display name and copyright name for an embedded font.
+    //
+    /// It's a string copy, but a decent standard library implementation
+    /// should be able to avoid actually copying. Since it's only two
+    /// strings, it doesn't seem worth the effort to avoid the copy.
+    void addFontNameInfo(const FontNameInfo& fontName);
+
+    /// Set the name of the font.
+    //
+    /// This is used by SWF::DefineFontInfoTag
+    void setName(const std::string& name);
+
+    /// Set the language and encoding flags of the font.
+    //
+    /// This is used by SWF::DefineFontInfoTag
+    void setFlags(boost::uint8_t flags);
+
+    /// Add a CodeTable to the font.
+    //
+    /// This is used by SWF::DefineFontInfoTag
+    void setCodeTable(std::auto_ptr<CodeTable> table);
+
+    /// Retrieve the number of embedded glyphs in this font.
+    //
+    GlyphInfoRecords::size_type glyphCount() const;
+
 private:
 
        /// Add a glyph from the os font into the device glyphs table
@@ -276,17 +287,14 @@
        GlyphInfoRecords _deviceGlyphTable;
 
        std::string     _name;
-    std::string m_display_name;
-    std::string m_copyright_name;
+    std::string _displayName;
+    std::string _copyrightName;
 
-       bool    m_has_layout;
-       bool    m_unicode_chars;
-       bool    m_shift_jis_chars;
-       bool    m_ansi_chars;
+       bool    _unicodeChars;
+       bool    _shiftJISChars;
+       bool    _ansiChars;
        bool    _italic;
        bool    _bold;
-       bool    m_wide_codes;
-       bool    m_subpixel_font;
 
        /// Code to index table for embedded glyphs
     //

=== modified file 'libcore/impl.cpp'
--- a/libcore/impl.cpp  2008-11-08 18:03:33 +0000
+++ b/libcore/impl.cpp  2008-11-08 22:02:22 +0000
@@ -51,6 +51,7 @@
 #include "StreamSoundBlockTag.h"
 #include "DefineButtonSoundTag.h"
 #include "DefineVideoStreamTag.h"
+#include "DefineFontNameTag.h"
 #include "VideoFrameTag.h"
 #include "swf/tag_loaders.h" // for all tag loaders..
 #include "RunInfo.h"
@@ -108,9 +109,9 @@
     register_tag_loader(SWF::DEFINEFONT, DefineFontTag::loader);
     register_tag_loader(SWF::DEFINETEXT, DefineTextTag::loader);
     register_tag_loader(SWF::DOACTION,  DoActionTag::doActionLoader);
-    register_tag_loader(SWF::DEFINEFONTINFO, define_font_info_loader);
+    register_tag_loader(SWF::DEFINEFONTINFO, DefineFontInfoTag::loader);
     // 62
-    register_tag_loader(SWF::DEFINEFONTINFO2, define_font_info_loader);
+    register_tag_loader(SWF::DEFINEFONTINFO2, DefineFontInfoTag::loader);
     register_tag_loader(SWF::DEFINESOUND, define_sound_loader);
     register_tag_loader(SWF::STARTSOUND, StartSoundTag::loader);
     // 89
@@ -218,7 +219,8 @@
     register_tag_loader(SWF::DEFINESHAPE4, define_shape_loader); // 83
     register_tag_loader(SWF::DEFINEMORPHSHAPE2, define_shape_morph_loader); // 
84
     
register_tag_loader(SWF::DEFINESCENEANDFRAMELABELDATA,define_scene_frame_label_loader);
 //86
-    register_tag_loader(SWF::DEFINEFONTNAME, define_font_name_loader); // 88
+    // 88
+    register_tag_loader(SWF::DEFINEFONTNAME, DefineFontNameTag::loader);
 
     register_tag_loader(SWF::REFLEX, reflex_loader); // 777
 }

=== added file 'libcore/swf/DefineFontNameTag.h'
--- a/libcore/swf/DefineFontNameTag.h   1970-01-01 00:00:00 +0000
+++ b/libcore/swf/DefineFontNameTag.h   2008-11-08 22:02:22 +0000
@@ -0,0 +1,71 @@
+// DefineFontNameTag.cpp: read a DefineFontName tag.
+// 
+//   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "swf.h"
+#include "SWFStream.h"
+#include "Font.h"
+#include "RunInfo.h"
+#include "movie_definition.h"
+
+#ifndef GNASH_SWF_DEFINEFONTNAMETAG_H
+#define GNASH_SWF_DEFINEFONTNAMETAG_H
+
+namespace gnash {
+namespace SWF {
+
+/// Process a DefineFontName tag.
+//
+/// This simple reads display name and copyright name, and seems
+/// to have little real point.
+class DefineFontNameTag
+{
+public:
+
+    // Set font name for a font.
+    static void loader(SWFStream& in, tag_type tag, movie_definition& m,
+            const RunInfo& /*r*/)
+    {
+        assert(tag == SWF::DEFINEFONTNAME);
+
+        in.ensureBytes(2);
+        boost::uint16_t fontID = in.read_u16();
+
+        Font* f = m.get_font(fontID);
+        if (!f)
+        {
+            IF_VERBOSE_MALFORMED_SWF(
+                log_swferror(_("define_font_name_loader: can't find "
+                        "font with id %d"), fontID);
+            );
+            return;
+        }
+
+        Font::FontNameInfo fontName;
+        in.read_string(fontName.displayName);
+        in.read_string(fontName.copyrightName);
+
+        f->addFontNameInfo(fontName);
+    }
+
+};
+
+}
+}
+
+#endif

=== modified file 'libcore/swf/DefineFontTag.cpp'
--- a/libcore/swf/DefineFontTag.cpp     2008-11-08 18:30:00 +0000
+++ b/libcore/swf/DefineFontTag.cpp     2008-11-08 22:02:22 +0000
@@ -197,7 +197,7 @@
     _unicodeChars = flags & (1 << 5);
     _ansiChars = flags & (1 << 4);
     bool wide_offsets = flags & (1 << 3);
-    _wideCodes = flags & (1 << 2);
+    bool wideCodes = flags & (1 << 2);
     _italic = flags & (1 << 1);
     _bold = flags & (1 << 0);
 
@@ -218,7 +218,7 @@
         log_parse(" m_unicode_chars = %d", _unicodeChars);
         log_parse(" m_ansi_chars = %d", _ansiChars);
         log_parse(" wide_offsets = %d", wide_offsets);
-        log_parse(" wide_codes = %d", _wideCodes);
+        log_parse(" wide_codes = %d", wideCodes);
         log_parse(" is_italic = %d", _italic);
         log_parse(" is_bold = %d", _bold);
         log_parse(" name = %s", _name);
@@ -301,7 +301,7 @@
 
     std::auto_ptr<Font::CodeTable> table(new Font::CodeTable);
 
-    readCodeTable(in, *table, _wideCodes, _glyphTable.size());
+    readCodeTable(in, *table, wideCodes, _glyphTable.size());
     _codeTable.reset(table.release());
 
     // Read layout info for the glyphs.
@@ -322,7 +322,7 @@
 
         // Bounds table.
         {
-            rect       dummy_rect;
+            rect dummy_rect;
             // TODO: shouldn't we log_unimpl here ??
             for (size_t i = 0; i < nGlyphs; i++) dummy_rect.read(in);
         }
@@ -330,7 +330,7 @@
         // Kerning pairs.
         in.ensureBytes(2);
         int    kerning_count = in.read_u16();
-        if ( _wideCodes )
+        if (wideCodes)
         {
             in.ensureBytes(6*kerning_count); // includes the adjustment 
         }
@@ -342,7 +342,7 @@
         for (int i = 0; i < kerning_count; i++)
         {
             boost::uint16_t    char0, char1;
-            if (_wideCodes)
+            if (wideCodes)
             {
                 char0 = in.read_u16();
                 char1 = in.read_u16();
@@ -371,6 +371,48 @@
     }
 }
 
+void
+DefineFontInfoTag::loader(SWFStream& in, tag_type tag, movie_definition& m,
+            const RunInfo& /*r*/)
+{
+    assert(tag == DEFINEFONTINFO || tag == DEFINEFONTINFO2); 
+
+    in.ensureBytes(2);
+    boost::uint16_t fontID = in.read_u16();
+
+    Font* f = m.get_font(fontID);
+    if (!f)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+            log_swferror(_("DefineFontInfo tag loader: "
+                   "can't find font with id %d"), fontID);
+        );
+        return;
+    }
+
+    if (tag == DEFINEFONTINFO2)
+    {
+        // See: SWFalexref/SWFalexref.html#tag_definefont2
+        LOG_ONCE(log_unimpl(_("DefineFontInfo2 partially implemented")));
+    }
+
+    std::string name;
+    in.read_string_with_length(name);
+
+    in.ensureBytes(1);
+    boost::uint8_t flags = in.read_u8();
+
+    bool wideCodes = flags & (1 << 0);
+
+    std::auto_ptr<Font::CodeTable> table(new Font::CodeTable);
+
+    DefineFontTag::readCodeTable(in, *table, wideCodes, f->glyphCount());
+
+    f->setName(name);
+    f->setFlags(flags);
+    f->setCodeTable(table);
+}
+
 
 }
 }

=== modified file 'libcore/swf/DefineFontTag.h'
--- a/libcore/swf/DefineFontTag.h       2008-11-08 19:14:15 +0000
+++ b/libcore/swf/DefineFontTag.h       2008-11-08 22:02:22 +0000
@@ -1,4 +1,4 @@
-// DefineFontTag.h   Read DefineFont and DefineFont2 tags
+// DefineFontTag.h   Read DefineFont and DefineFontInfo tags
 //
 //   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 // 
@@ -19,6 +19,12 @@
 
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
+/// This file handles DefineFont, DefineFontInfo, DefineFontInfo2,
+/// DefineFont2, and DefineFont3.
+//
+/// They are all handled in one file because a DefineFont2 or 3 tag
+/// contains practically the same as a DefineFont plus DefineFontInfo
+/// or DefineFontInfo2.
 
 #ifndef GNASH_SWF_DEFINEFONTTAG_H
 #define GNASH_SWF_DEFINEFONTTAG_H
@@ -80,7 +86,6 @@
     bool unicodeChars() const { return _unicodeChars; }
     bool italic() const { return _italic; }
     bool bold() const { return _bold; }
-    bool wideCodes() const { return _wideCodes; }
     bool subpixelFont() const { return _subpixelFont; }
     bool leading() const { return _leading; }
     bool ascent() const { return _ascent; }
@@ -128,6 +133,19 @@
     boost::shared_ptr<const Font::CodeTable> _codeTable;
 };
 
+
+class DefineFontInfoTag
+{
+public:
+    /// Load a DefineFontInfo tag.
+    //
+    /// Adds a CodeTable and other information to a Font created by a
+    /// DefineFont tag. The information is already contained in a 
+    /// DefineFont2 or DefineFont3 tag.
+    static void loader(SWFStream& in, tag_type tag, movie_definition& m,
+            const RunInfo& r);
+};
+
 }
 }
 

=== modified file 'libcore/swf/tag_loaders.cpp'
--- a/libcore/swf/tag_loaders.cpp       2008-11-08 18:03:33 +0000
+++ b/libcore/swf/tag_loaders.cpp       2008-11-08 22:02:22 +0000
@@ -825,52 +825,6 @@
 //
 
 
-// See description in header
-void define_font_info_loader(SWFStream& in, tag_type tag, movie_definition& m,
-               const RunInfo& /*r*/)
-{
-    assert(tag == SWF::DEFINEFONTINFO || tag == SWF::DEFINEFONTINFO2);
-
-    in.ensureBytes(2);
-    boost::uint16_t font_id = in.read_u16();
-
-    Font* f = m.get_font(font_id);
-    if (f)
-    {
-        f->read_font_info(in, tag, m);
-    }
-    else
-    {
-        IF_VERBOSE_MALFORMED_SWF(
-            log_swferror(_("define_font_info_loader: "
-                   "can't find font w/ id %d"), font_id);
-        );
-    }
-}
-
-// Set font name for a font.
-void define_font_name_loader(SWFStream& in, tag_type tag, movie_definition& m,
-               const RunInfo& /*r*/)
-{
-    assert(tag == SWF::DEFINEFONTNAME);
-
-    in.ensureBytes(2);
-    boost::uint16_t font_id = in.read_u16();
-
-    Font* f = m.get_font(font_id);
-    if (f)
-    {
-        f->read_font_name(in, tag, m);
-    }
-    else
-    {
-        IF_VERBOSE_MALFORMED_SWF(
-            log_swferror(_("define_font_name_loader: "
-                           "can't find font w/ id %d"), font_id);
-        );
-    }
-}
-
 // Create and initialize a sprite, and add it to the movie.
 void
 sprite_loader(SWFStream& in, tag_type tag, movie_definition& m,

=== modified file 'libcore/swf/tag_loaders.h'
--- a/libcore/swf/tag_loaders.h 2008-11-08 17:30:07 +0000
+++ b/libcore/swf/tag_loaders.h 2008-11-08 22:02:22 +0000
@@ -74,20 +74,6 @@
 void reflex_loader(SWFStream&, tag_type, movie_definition&,
                const RunInfo&);
 
-/// SWF Tag DefineFontInfo (13 or 62) 
-//
-/// Load a DefineFontInfo or DefineFontInfo2 tag. 
-/// This adds information to an existing font.
-///
-void define_font_info_loader(SWFStream&, tag_type, movie_definition&,
-               const RunInfo&);
-
-/// SWF Tag DefineFontName (88)
-//  Load the display name and copyright string of a font.
-//  This adds to an existing font.
-void define_font_name_loader(SWFStream&, tag_type, movie_definition&,
-               const RunInfo&);
-
 void place_object_2_loader(SWFStream&, tag_type, movie_definition&,
                const RunInfo&);
 


reply via email to

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