]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix off by 1 error in wxHTML font size from points calculation.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Jun 2012 11:58:55 +0000 (11:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Jun 2012 11:58:55 +0000 (11:58 +0000)
m_FontSize is in 1..7 range, not 0..6, so add 1 to it when setting it from the
index into m_FontsSizes array.

Also update the comment explaining the valid range of m_FontsSize.

Closes #14442.

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

docs/changes.txt
include/wx/html/winpars.h
src/html/winpars.cpp

index f3b5245289a4f404ab2031c23dd18f290af4d616..4be062302f596a327f149ed8be77ca9235a986ab 100644 (file)
@@ -563,6 +563,7 @@ All (GUI):
 - Added wxDataViewListCtrl::{Set,Get}ItemData().
 - Added wxDataViewListCtrl::GetItemCount() (Kry).
 - Added support for Korean Johab and Vietnamese encodings (jank9201).
+- Fix off by 1 bug with setting font size in points in wxHTML (gevorg).
 
 GTK:
 
index 75f4da2d7fad369bd5c0da81de54394d7fc55a23..f01c8c190080776fd857f5f1212a2310405b2db0 100644 (file)
@@ -185,7 +185,7 @@ private:
             // current container. See Open/CloseContainer for details.
 
     int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing
-    int m_FontSize; /* -2 to +4,  0 is default */
+    int m_FontSize; // From 1 (smallest) to 7, default is 3.
     wxColour m_LinkColor;
     wxColour m_ActualColor;
             // basic font parameters.
index 916c43a989e9652b70b707ff60a69e24e583de86..d7047133c397e91a6538c05d4625e4209bb6693a 100644 (file)
@@ -573,11 +573,15 @@ void wxHtmlWinParser::SetFontPointSize(int pt)
         {
             if ( (pt > m_FontsSizes[n]) && (pt <= m_FontsSizes[n + 1]) )
             {
-                // In this range, find out which entry it is closest to
-                if ( (pt - m_FontsSizes[n]) < (m_FontsSizes[n + 1] - pt) )
-                    m_FontSize = n;
-                else
-                    m_FontSize = n + 1;
+                if ( (pt - m_FontsSizes[n]) >= (m_FontsSizes[n + 1] - pt) )
+                {
+                    // The actual size is closer to the next entry than to this
+                    // one, so use it.
+                    n++;
+                }
+
+                // Notice that m_FontSize starts from 1, hence +1 here.
+                m_FontSize = n + 1;
 
                 break;
             }