From 1cf981e24358d3b0ce5662bf94fa46ab298403ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Fri, 21 Sep 2018 11:33:41 +0200 Subject: [PATCH] Parse legacy weight in string font descriptions Preserve compatiblity font descriptions serialized using wxNativeFontInfo::ToString() in older versions of wxWidgets and load them correctly, instead of asserting. aedf89b09863ddb3c65e0f79e499f40edc208653 originally did this, then d355af34200f3658120b383bd5d16d203e121328 reversed it as "not needed". Turns out it is, for old serializations. Reverse d355af34200f3658120b383bd5d16d203e121328 and implement the same backward compatible logic in wxOSX. wxMSW uses win32-native description and doesn't need this. --- src/common/fontcmn.cpp | 4 ++-- src/osx/carbon/font.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 17034b0bc1..f5c47bd001 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -776,9 +776,9 @@ bool wxNativeFontInfo::FromString(const wxString& s) token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return false; - if ( l <= wxFONTWEIGHT_INVALID || l > wxFONTWEIGHT_MAX ) + weight = wxFont::ConvertFromLegacyWeightIfNecessary(l); + if ( weight <= wxFONTWEIGHT_INVALID || weight > wxFONTWEIGHT_MAX ) return false; - weight = static_cast(l); token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 8dc154e8a5..ffbf99904c 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -929,7 +929,7 @@ bool wxNativeFontInfo::FromString(const wxString& s) token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return false; - m_ctWeight = WXWeightToCT(l); + m_ctWeight = WXWeightToCT(wxFont::ConvertFromLegacyWeightIfNecessary(l)); token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) )