gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11804: Fix crash when _ftProvider h


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11804: Fix crash when _ftProvider has not yet been initialized.
Date: Mon, 25 Jan 2010 15:52:37 +0100
User-agent: Bazaar (2.0.2)

------------------------------------------------------------
revno: 11804 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2010-01-25 15:52:37 +0100
message:
  Fix crash when _ftProvider has not yet been initialized.
modified:
  libcore/Font.cpp
  libcore/Font.h
=== modified file 'libcore/Font.cpp'
--- a/libcore/Font.cpp  2010-01-25 09:57:03 +0000
+++ b/libcore/Font.cpp  2010-01-25 14:28:31 +0000
@@ -261,40 +261,33 @@
         else return 1024;
     }
     
-    if (!_ftProvider.get()) {
-        if (!initDeviceFontProvider()) {
-            log_error("Device font provider was not initialized, "
+    FreetypeGlyphsProvider* ft = ftProvider();
+    if (!ft) {
+        log_error("Device font provider was not initialized, "
                     "can't get unitsPerEM");
-            return 0; 
-        }
+        return 0; 
     }
 
-    return _ftProvider->unitsPerEM();
+    return ft->unitsPerEM();
 }
 
 int
 Font::add_os_glyph(boost::uint16_t code)
 {
-    if (!_ftProvider.get()) {
-        if (!initDeviceFontProvider()) {
-            log_error("Device font provider was not initialized, can't "
-                    "get unitsPerEM");
-            return -1; // can't provide it...
-        }
-    }
+    FreetypeGlyphsProvider* ft = ftProvider();
+    if (!ft) return -1;
 
     assert(_deviceCodeTable.find(code) == _deviceCodeTable.end());
 
     float advance;
 
     // Get the vectorial glyph
-    std::auto_ptr<SWF::ShapeRecord> sh = _ftProvider->getGlyph(code, advance);
+    std::auto_ptr<SWF::ShapeRecord> sh = ft->getGlyph(code, advance);
 
     if (!sh.get()) {
         log_error("Could not create shape "
                 "glyph for DisplayObject code %u (%c) with "
-                "device font %s (%p)", code, code, _name,
-                _ftProvider.get());
+                "device font %s (%p)", code, code, _name, ft);
         return -1;
     }
 
@@ -310,42 +303,53 @@
 }
 
 bool
-Font::initDeviceFontProvider() const
-{
+Font::matches(const std::string& name, bool bold, bool italic) const
+{
+    return (_bold == bold && _italic == italic && name ==_name);
+}
+
+float
+Font::leading() const {
+    return _fontTag ? _fontTag->leading() : 0.0f;
+}
+
+FreetypeGlyphsProvider*
+Font::ftProvider() const 
+{
+    if (_ftProvider.get()) return _ftProvider.get();
+
     if (_name.empty()) {
         log_error("No name associated with this font, can't use device "
                 "fonts (should I use a default one?)");
-        return false;
+        return 0;
     }
 
     _ftProvider = FreetypeGlyphsProvider::createFace(_name, _bold, _italic);
+    
     if (!_ftProvider.get()) {
         log_error("Could not create a freetype face %s", _name);
-        return false;
+        return 0;
     }
-    return true;
-}
-
-bool
-Font::matches(const std::string& name, bool bold, bool italic) const
-{
-    return (_bold == bold && _italic == italic && name ==_name);
-}
-
-float
-Font::leading() const {
-    return _fontTag ? _fontTag->leading() : 0.0f;
-}
-
-float
-Font::ascent(bool embedded) const {
-    return (embedded && _fontTag) ? _fontTag->ascent() : _ftProvider->ascent();
-}
-
-float
-Font::descent(bool embedded) const {
-    return (embedded && _fontTag) ? _fontTag->descent() :
-                                    _ftProvider->descent();
+    
+    return _ftProvider.get();
+}
+
+float
+Font::ascent(bool embedded) const
+{
+    if (embedded && _fontTag) return _fontTag->ascent();
+    FreetypeGlyphsProvider* ft = ftProvider();
+    if (ft) return ft->ascent();
+    return 0;
+}
+
+float
+Font::descent(bool embedded) const
+{
+    if (embedded && _fontTag) return _fontTag->descent();
+    FreetypeGlyphsProvider* ft = ftProvider();
+    if (ft) return ft->descent();
+    return 0;
 }
     
 bool

=== modified file 'libcore/Font.h'
--- a/libcore/Font.h    2010-01-25 09:05:21 +0000
+++ b/libcore/Font.h    2010-01-25 14:29:49 +0000
@@ -266,9 +266,14 @@
     void setCodeTable(std::auto_ptr<CodeTable> table);
 
     /// Retrieve the number of embedded glyphs in this font.
-    //
     GlyphInfoRecords::size_type glyphCount() const;
 
+    /// Retrieve the FreetypeGlyphsProvider, initializing it if necessary.
+    //
+    /// Always use this method rather than directly accessing the _ftProvider
+    /// member to ensure that the provider is initialized. May return null.
+    FreetypeGlyphsProvider* ftProvider() const;
+
 private:
 
     /// Add a glyph from the os font into the device glyphs table
@@ -281,14 +286,6 @@
     ///
     int add_os_glyph(boost::uint16_t code);
 
-    /// Initialize the freetype rasterizer
-    //
-    /// NOTE: this is 'const' for lazy initialization.
-    ///
-    /// Return true on success, false on error
-    ///
-    bool initDeviceFontProvider() const;
-
     /// If we were constructed from a definition, this is not NULL.
     boost::scoped_ptr<SWF::DefineFontTag> _fontTag;
 
@@ -299,11 +296,11 @@
     std::string _displayName;
     std::string _copyrightName;
 
-    bool    _unicodeChars;
-    bool    _shiftJISChars;
-    bool    _ansiChars;
-    bool    _italic;
-    bool    _bold;
+    bool _unicodeChars;
+    bool _shiftJISChars;
+    bool _ansiChars;
+    bool _italic;
+    bool _bold;
 
     /// Code to index table for embedded glyphs
     //


reply via email to

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