]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't set wxTextAttr font family to invalid value.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 2009 15:59:27 +0000 (15:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 2009 15:59:27 +0000 (15:59 +0000)
wxTextAttr::HasFontFamily() shouldn't return true if there is no valid font
family in this attribute but this could happen if it was constructed from a
font which didn't know its own family.

This fixes asserts on the startup of the text sample in wxMSW due to passing
wxFONTFAMILY_UNKNOWN to wxFont::SetFamily() when trying to use such invalid
attribute later.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/textcmn.cpp

index 6248877613b79b8ee4fb0182b3dfdefbe34eb9f5..06824dd481453cf7f0dec35d4f22d736da8e7c34 100644 (file)
@@ -333,7 +333,7 @@ wxFont wxTextAttr::GetFont() const
     if (HasFontEncoding())
         encoding = GetFontEncoding();
 
-    int fontFamily = wxFONTFAMILY_DEFAULT;
+    wxFontFamily fontFamily = wxFONTFAMILY_DEFAULT;
     if (HasFontFamily())
         fontFamily = GetFontFamily();
 
@@ -366,7 +366,16 @@ bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags)
         m_fontEncoding = font.GetEncoding();
 
     if (flags & wxTEXT_ATTR_FONT_FAMILY)
-        m_fontFamily = font.GetFamily();
+    {
+        // wxFont might not know its family, avoid setting m_fontFamily to an
+        // invalid value and rather pretend that we don't have any font family
+        // information at all in this case
+        const wxFontFamily fontFamily = font.GetFamily();
+        if ( fontFamily == wxFONTFAMILY_UNKNOWN )
+            flags &= ~wxTEXT_ATTR_FONT_FAMILY;
+        else
+            m_fontFamily = fontFamily;
+    }
 
     m_flags |= flags;