]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/textmeasurecmn.cpp
fixing overrelease and out-of-bounds write, fixes #13725
[wxWidgets.git] / src / common / textmeasurecmn.cpp
index df91ca38bdceb7fd383bd9bfbc4714ef85cc662c..4db3b892fba74583cbe06b494414eb638972a237 100644 (file)
@@ -53,6 +53,13 @@ wxTextMeasureBase::wxTextMeasureBase(const wxWindow *win, const wxFont *theFont)
     m_useDCImpl = false;
 }
 
     m_useDCImpl = false;
 }
 
+wxFont wxTextMeasureBase::GetFont() const
+{
+    return m_font ? *m_font
+                  : m_win ? m_win->GetFont()
+                          : m_dc->GetFont();
+}
+
 void wxTextMeasureBase::CallGetTextExtent(const wxString& string,
                                           wxCoord *width,
                                           wxCoord *height,
 void wxTextMeasureBase::CallGetTextExtent(const wxString& string,
                                           wxCoord *width,
                                           wxCoord *height,
@@ -158,18 +165,15 @@ void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text,
         *heightOneLine = heightLine;
 }
 
         *heightOneLine = heightLine;
 }
 
-void wxTextMeasureBase::GetLargestStringExtent(const wxVector<wxString>& strings,
-                                               wxCoord *width,
-                                               wxCoord *height)
+wxSize wxTextMeasureBase::GetLargestStringExtent(size_t n,
+                                                 const wxString* strings)
 {
     MeasuringGuard guard(*this);
 
     wxCoord w, h, widthMax = 0, heightMax = 0;
 {
     MeasuringGuard guard(*this);
 
     wxCoord w, h, widthMax = 0, heightMax = 0;
-    for ( wxVector<wxString>::const_iterator i = strings.begin();
-          i != strings.end();
-          ++i )
+    for ( size_t i = 0; i < n; ++i )
     {
     {
-        CallGetTextExtent(*i, &w, &h);
+        CallGetTextExtent(strings[i], &w, &h);
 
         if ( w > widthMax )
             widthMax = w;
 
         if ( w > widthMax )
             widthMax = w;
@@ -177,10 +181,7 @@ void wxTextMeasureBase::GetLargestStringExtent(const wxVector<wxString>& strings
             heightMax = h;
     }
 
             heightMax = h;
     }
 
-    if ( width )
-        *width = widthMax;
-    if ( height )
-        *height = heightMax;
+    return wxSize(widthMax, heightMax);
 }
 
 bool wxTextMeasureBase::GetPartialTextExtents(const wxString& text,
 }
 
 bool wxTextMeasureBase::GetPartialTextExtents(const wxString& text,