From 7386e649238a459860319563e8bb47b46a1c26bd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 20 Jul 2022 17:51:59 +0100 Subject: [PATCH] Attempt to work-around wxWidgets bug with Serbian & Russian locales. Fixes https://gitlab.com/kicad/code/kicad/issues/12002 Fixes https://gitlab.com/kicad/code/kicad/issues/11963 --- common/gal/color4d.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index 09b04f8929..14a166e4b8 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -277,7 +277,32 @@ std::ostream &operator<<( std::ostream &aStream, COLOR4D const &aColor ) void to_json( nlohmann::json& aJson, const COLOR4D& aColor ) { - aJson = nlohmann::json( aColor.ToWxString( wxC2S_CSS_SYNTAX ).ToStdString() ); + wxColour c = aColor.ToColour(); + wxString str; + + const int red = c.Red(); + const int green = c.Green(); + const int blue = c.Blue(); + const int alpha = c.Alpha(); + + if ( alpha == wxALPHA_OPAQUE ) + { + str.Printf( wxT( "rgb(%d, %d, %d)" ), red, green, blue ); + } + else // use rgba() form + { + wxString a = wxString::FromCDouble( alpha / 255.0, 3); + + // The wxC2S_CSS_SYNTAX is particularly sensitive to ','s (as it uses them for value + // delimiters), and wxWidgets is known to be buggy in this respect when dealing with + // Serbian and Russian locales (at least), so we enforce an extra level of safety. + a.Replace( wxT( "," ), wxT( "." ) ); + + str.Printf( wxT( "rgba(%d, %d, %d, %s)" ), red, green, blue, a ); + } + + aJson = nlohmann::json( str.ToStdString() ); + }