Allow parsing all fractional sizes in wxFont descriptions
Remove the check that the size representation was the same as float and as double, which was supposed to catch various edge cases (NaNs, huge numbers etc) but actually caught plenty of perfectly valid font sizes such as 13.8 that simply lost precision when converting from double to float. Just check that the size is positive and less than FLT_MAX to avoid using values that really don't make sense as font sizes. Also add a unit test checking that using fractional font sizes in description string works as expected. Closes #18590. Closes https://github.com/wxWidgets/wxWidgets/pull/1707
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <float.h> // for FLT_MAX
|
||||
|
||||
#define TRACE_CTFONT "ctfont"
|
||||
|
||||
class WXDLLEXPORT wxFontRefData : public wxGDIRefData
|
||||
@@ -957,13 +959,13 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
token = tokenizer.GetNextToken();
|
||||
if ( !token.ToCDouble(&d) )
|
||||
return false;
|
||||
if ( d < 0 || d > FLT_MAX )
|
||||
return false;
|
||||
#ifdef __LP64__
|
||||
// CGFloat is just double in this case.
|
||||
m_ctSize = d;
|
||||
#else // !__LP64__
|
||||
m_ctSize = static_cast<CGFloat>(d);
|
||||
if ( static_cast<double>(m_ctSize) != d )
|
||||
return false;
|
||||
#endif // __LP64__/!__LP64__
|
||||
|
||||
token = tokenizer.GetNextToken();
|
||||
|
||||
Reference in New Issue
Block a user