Add support for creating Cairo brush from wxBrush with non-solid colour

Cairo colour patterns support only RGBA colours and therefore it is not
possible to create a colour pattern from wxBrush with non-RGB colour
(non-solid colour). However under wxOSX, when we have a solid wxBrush with
non-solid colour, we can convert it to Cairo surface pattern (stiple)
because under wxOSX non-solid colour is actually represented by a pattern
image.
This commit is contained in:
Artur Wieczorek
2019-12-06 20:34:57 +01:00
parent 389944a116
commit 55478d95a5

View File

@@ -1026,9 +1026,34 @@ wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer,
InitStipple(brush.GetStipple());
break;
case wxBRUSHSTYLE_SOLID:
// Non-RGB colours, which may e.g. appear under wxOSX for wxColours
// with NSColor backend, are not supported by Cairo and have to be
// handled in a special way.
if ( !brush.GetColour().IsSolid() )
{
#if wxOSX_USE_COCOA
// Under wxOSX, non-solid NSColors are actually represented
// by pattern images and therefore a wxBrush with non-solid
// colour and wxBRUSHSTYLE_SOLID style can be converted
// to a stiple (a surface pattern).
// Create a stiple bitmap from NSColor's pattern image
wxBitmap bmp(brush.GetColour().OSXGetNSPatternImage());
InitStipple(&bmp);
#else
wxFAIL_MSG( "Brush with non-solid colour is not supported." );
#endif
}
break;
default:
if ( brush.IsHatch() )
{
wxASSERT_MSG( brush.GetColour().IsSolid(),
"Brush with non-solid colour is not supported." );
InitHatch(static_cast<wxHatchStyle>(brush.GetStyle()));
}
break;
}
}