gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11978: Fixes to Font tag.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11978: Fixes to Font tag.
Date: Fri, 26 Feb 2010 13:48:39 +0100
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 11978 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2010-02-26 13:48:39 +0100
message:
  Fixes to Font tag.
modified:
  libcore/swf/DefineFontTag.cpp
  libcore/swf/DefineFontTag.h
=== modified file 'libcore/swf/DefineFontTag.cpp'
--- a/libcore/swf/DefineFontTag.cpp     2010-01-11 06:41:38 +0000
+++ b/libcore/swf/DefineFontTag.cpp     2010-02-26 08:25:24 +0000
@@ -92,9 +92,9 @@
     _italic(false),
     _bold(false),
     _wideCodes(false),
-    _ascent(0.0f),
-    _descent(0.0f),
-    _leading(0.0f)
+    _ascent(0),
+    _descent(0),
+    _leading(0)
 {
     switch (tag)
     {
@@ -221,32 +221,31 @@
     // offset table. Make sure wide offsets fit into elements
     std::vector<boost::uint32_t> offsets;
     int        font_code_offset;
-    if (wide_offsets)
-    {
+
+    if (wide_offsets) {
         // 32-bit offsets.
         in.ensureBytes(4*glyph_count + 4); 
-        for (unsigned int i = 0; i < glyph_count; i++)
+        for (size_t i = 0; i < glyph_count; ++i)
         {
-            boost::uint32_t off = in.read_u32();       
+            const boost::uint32_t off = in.read_u32(); 
 
             IF_VERBOSE_PARSE (
-            log_parse(_("Glyph %d at offset %u"), i, off);
+                log_parse(_("Glyph %d at offset %u"), i, off);
             );
 
             offsets.push_back(off);
         }
         font_code_offset = in.read_u32();
     }
-    else
-    {
+    else {
         // 16-bit offsets.
         in.ensureBytes(2*glyph_count + 2); 
-        for (unsigned int i = 0; i < glyph_count; i++)
-        {
-            boost::uint16_t off = in.read_u16();       
+        for (size_t i = 0; i < glyph_count; ++i) {
+
+            const boost::uint16_t off = in.read_u16(); 
 
             IF_VERBOSE_PARSE (
-            log_parse(_("Glyph %d at offset %u"), i, off);
+                log_parse(_("Glyph %d at offset %u"), i, off);
             );
 
             offsets.push_back(off);
@@ -257,17 +256,13 @@
     _glyphTable.resize(glyph_count);
 
     // Read the glyph shapes.
-    for (int i = 0; i < glyph_count; i++)
-    {
+    for (size_t i = 0; i < glyph_count; ++i) {
         // Seek to the start of the shape data.
         unsigned long new_pos = table_base + offsets[i];
 
         // It seems completely possible to
         // have such seeks-back, see bug #16311
-        //assert(new_pos >= in.tell());
-
-        if ( ! in.seek(new_pos) )
-        {
+        if (!in.seek(new_pos)) {
             throw ParserException(_("Glyphs offset table corrupted in "
                         "DefineFont2/3 tag"));
         }
@@ -281,7 +276,7 @@
     {
         // Bad offset!  Don't try to read any more.
         IF_VERBOSE_MALFORMED_SWF(
-        log_swferror(_("Bad offset in DefineFont2"));
+            log_swferror(_("Bad offset in DefineFont2"));
         );
         return;
     }
@@ -292,19 +287,21 @@
     _codeTable.reset(table.release());
 
     // Read layout info for the glyphs.
-    if (has_layout)
-    {
+    if (has_layout) {
         in.ensureBytes(6);
-        _ascent = static_cast<float>(in.read_s16());
-        _descent = static_cast<float>(in.read_s16());
-        _leading = static_cast<float>(in.read_s16());
+        _ascent = in.read_s16();
+        _descent = in.read_s16();
+        _leading = in.read_s16();
         
         // Advance table; i.e. how wide each DisplayObject is.
         size_t nGlyphs = _glyphTable.size();
         in.ensureBytes(nGlyphs*2);
-        for (size_t i = 0; i < nGlyphs; i++)
-        {
-            _glyphTable[i].advance = static_cast<float>(in.read_s16());
+
+        for (size_t i = 0; i < nGlyphs; i++) {
+            // This is documented to be unsigned, but then we get negative
+            // advances for subpixel fonts because the advance overflows
+            // int16_t.
+            _glyphTable[i].advance = static_cast<float>(in.read_u16());
         }
 
         // Bounds table.
@@ -316,30 +313,21 @@
 
         // Kerning pairs.
         in.ensureBytes(2);
-        int    kerning_count = in.read_u16();
-        if (wideCodes)
-        {
-            in.ensureBytes(6*kerning_count); // includes the adjustment 
-        }
-        else
-        {
-            in.ensureBytes(4*kerning_count); // includes the adjustment 
-        }
-
-        for (int i = 0; i < kerning_count; i++)
-        {
+        const boost::uint16_t kerning_count = in.read_u16();
+
+        in.ensureBytes(kerning_count * (wideCodes ? 6 : 4));
+
+        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();
             }
-            else
-            {
+            else {
                 char0 = in.read_u8();
                 char1 = in.read_u8();
             }
-            float adjustment =  static_cast<float>(in.read_s16());
+            const boost::int16_t adjustment = in.read_s16();
 
             kerning_pair k;
             k.m_char0 = char0;
@@ -347,10 +335,9 @@
 
             // Remember this adjustment; we can look it up quickly
             // later using the DisplayObject pair as the key.
-            if ( ! m_kerning_pairs.insert(std::make_pair(k, 
adjustment)).second )
-            {
+            if (!_kerningPairs.insert(std::make_pair(k, adjustment)).second) {
                 IF_VERBOSE_MALFORMED_SWF(
-                log_swferror(_("Repeated kerning pair found - ignoring"));
+                    log_swferror(_("Repeated kerning pair found - ignoring"));
                 );
             }
 

=== modified file 'libcore/swf/DefineFontTag.h'
--- a/libcore/swf/DefineFontTag.h       2010-01-11 06:41:38 +0000
+++ b/libcore/swf/DefineFontTag.h       2010-02-26 08:25:24 +0000
@@ -34,6 +34,7 @@
 #include "SWF.h"
 #include "Font.h"
 #include <vector>
+#include <boost/cstdint.hpp>
 
 // Forward declarations
 namespace gnash {
@@ -88,9 +89,28 @@
     bool italic() const { return _italic; }
     bool bold() const { return _bold; }
     bool subpixelFont() const { return _subpixelFont; }
-    bool leading() const { return _leading; }
-    bool ascent() const { return _ascent; }
-    bool descent() const { return _descent; }
+
+    /// The font leading value
+    //
+    /// This is documented to be int16_t, but may be uint16_t like advance.
+    boost::int16_t leading() const {
+        return _leading;
+    }
+
+    /// The font ascent value
+    //
+    /// This is documented to be int16_t, but may be uint16_t like advance.
+    boost::int16_t ascent() const {
+        return _ascent;
+    }
+
+    /// The font descent value
+    //
+    /// This is documented to be int16_t, but may be uint16_t like advance.
+    boost::int16_t descent() const {
+        return _descent;
+    }
+
     const std::string& name() const { return _name; }
 
     /// Read Font::CodeTable, which maps glyph indices to DisplayObject codes.
@@ -121,12 +141,13 @@
        bool _italic;
        bool _bold;
        bool _wideCodes;
-    float _ascent;
-    float _descent;
-    float _leading;
-
-       typedef std::map<kerning_pair, float> kernings_table;
-       kernings_table m_kerning_pairs;
+
+    boost::int16_t _ascent;
+    boost::int16_t _descent;
+    boost::int16_t _leading;
+
+       typedef std::map<kerning_pair, boost::int16_t> KerningTable;
+       KerningTable _kerningPairs;
 
     boost::shared_ptr<const Font::CodeTable> _codeTable;
 };


reply via email to

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