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
This commit is contained in:
Jeff Young 2022-07-20 17:51:59 +01:00
parent 012d861aab
commit 7386e64923
1 changed files with 26 additions and 1 deletions

View File

@ -277,7 +277,32 @@ std::ostream &operator<<( std::ostream &aStream, COLOR4D const &aColor )
void to_json( nlohmann::json& aJson, const COLOR4D& 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() );
} }