Work around more instances of the wxWidgets color string locale bug.
Fixes https://gitlab.com/kicad/code/kicad/issues/12552
This commit is contained in:
parent
f095453d3e
commit
c0a666507c
|
@ -248,7 +248,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
|
||||||
setCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET, nc->GetWireWidth() );
|
setCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET, nc->GetWireWidth() );
|
||||||
setCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET, nc->GetBusWidth() );
|
setCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET, nc->GetBusWidth() );
|
||||||
|
|
||||||
wxString colorAsString = nc->GetSchematicColor().ToWxString( wxC2S_CSS_SYNTAX );
|
wxString colorAsString = nc->GetSchematicColor().ToCSSString();
|
||||||
m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET,
|
m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET,
|
||||||
colorAsString );
|
colorAsString );
|
||||||
|
|
||||||
|
|
|
@ -144,10 +144,33 @@ bool COLOR4D::SetFromWxString( const wxString& aColorString )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString COLOR4D::ToWxString( long flags ) const
|
wxString COLOR4D::ToCSSString() const
|
||||||
{
|
{
|
||||||
wxColour c = ToColour();
|
wxColour c = ToColour();
|
||||||
return c.GetAsString( flags );
|
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 alpha_str = 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.
|
||||||
|
alpha_str.Replace( wxT( "," ), wxT( "." ) );
|
||||||
|
|
||||||
|
str.Printf( wxT( "rgba(%d, %d, %d, %s)" ), red, green, blue, alpha_str );
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,38 +294,13 @@ const bool operator<( const COLOR4D& lhs, const COLOR4D& rhs )
|
||||||
|
|
||||||
std::ostream &operator<<( std::ostream &aStream, COLOR4D const &aColor )
|
std::ostream &operator<<( std::ostream &aStream, COLOR4D const &aColor )
|
||||||
{
|
{
|
||||||
return aStream << aColor.ToWxString( wxC2S_CSS_SYNTAX );
|
return aStream << aColor.ToCSSString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void to_json( nlohmann::json& aJson, const COLOR4D& aColor )
|
void to_json( nlohmann::json& aJson, const COLOR4D& aColor )
|
||||||
{
|
{
|
||||||
wxColour c = aColor.ToColour();
|
aJson = nlohmann::json( aColor.ToCSSString().ToStdString() );
|
||||||
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() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ COLOR_SETTINGS::COLOR_SETTINGS( const wxString& aFilename, bool aAbsolutePath )
|
||||||
// Fix LAYER_VIA_HOLES color - before version 2, this setting had no effect
|
// Fix LAYER_VIA_HOLES color - before version 2, this setting had no effect
|
||||||
nlohmann::json::json_pointer ptr( "/board/via_hole" );
|
nlohmann::json::json_pointer ptr( "/board/via_hole" );
|
||||||
|
|
||||||
( *m_internals )[ptr] = COLOR4D( 0.5, 0.4, 0, 0.8 ).ToWxString( wxC2S_CSS_SYNTAX );
|
( *m_internals )[ptr] = COLOR4D( 0.5, 0.4, 0, 0.8 ).ToCSSString();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -146,7 +146,7 @@ void GRID_CELL_COLOR_SELECTOR::Create( wxWindow* aParent, wxWindowID aId,
|
||||||
|
|
||||||
wxString GRID_CELL_COLOR_SELECTOR::GetValue() const
|
wxString GRID_CELL_COLOR_SELECTOR::GetValue() const
|
||||||
{
|
{
|
||||||
return m_value.ToWxString( wxC2S_CSS_SYNTAX );
|
return m_value.ToCSSString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -604,7 +604,7 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
|
||||||
return DEFAULT_FONT_NAME;
|
return DEFAULT_FONT_NAME;
|
||||||
|
|
||||||
case FDC_COLOR:
|
case FDC_COLOR:
|
||||||
return field.GetTextColor().ToWxString( wxC2S_CSS_SYNTAX );
|
return field.GetTextColor().ToCSSString();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// we can't assert here because wxWidgets sometimes calls this without checking
|
// we can't assert here because wxWidgets sometimes calls this without checking
|
||||||
|
|
|
@ -1898,7 +1898,7 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine )
|
||||||
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
|
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
|
||||||
{
|
{
|
||||||
m_out->Print( 0, " %s",
|
m_out->Print( 0, " %s",
|
||||||
TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
|
TO_UTF8( aLine->GetLineColor().ToCSSString() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool SetFromWxString( const wxString& aColorString );
|
bool SetFromWxString( const wxString& aColorString );
|
||||||
|
|
||||||
wxString ToWxString( long flags ) const;
|
wxString ToCSSString() const;
|
||||||
|
|
||||||
bool SetFromHexString( const wxString& aColorString );
|
bool SetFromHexString( const wxString& aColorString );
|
||||||
wxString ToHexString() const;
|
wxString ToHexString() const;
|
||||||
|
|
|
@ -104,7 +104,7 @@ wxString NET_GRID_TABLE::GetValue( int aRow, int aCol )
|
||||||
switch( aCol )
|
switch( aCol )
|
||||||
{
|
{
|
||||||
case COL_COLOR:
|
case COL_COLOR:
|
||||||
return m_nets[aRow].color.ToWxString( wxC2S_CSS_SYNTAX );
|
return m_nets[aRow].color.ToCSSString();
|
||||||
|
|
||||||
case COL_VISIBILITY:
|
case COL_VISIBILITY:
|
||||||
return m_nets[aRow].visible ? wxT( "1" ) : wxT( "0" );
|
return m_nets[aRow].visible ? wxT( "1" ) : wxT( "0" );
|
||||||
|
|
Loading…
Reference in New Issue