diff --git a/docs/changes.txt b/docs/changes.txt index f3b5245289..4be062302f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 75f4da2d7f..f01c8c1900 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -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. diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index 916c43a989..d7047133c3 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -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; }