From 67b64ee70fb14cad348f56e78cb70bc47ec267e4 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 6 Dec 2019 20:40:57 +0100 Subject: [PATCH] Add support for creating Cairo pen from wxPen with non-solid colour Cairo colour patterns support only RGBA colours and therefore it is not possible to create a colour pattern from wxPen with non-RGB colour (non-solid colour). As a workaround under wxOSX for solid wxPen 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. --- src/generic/graphicc.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 4db5d78a0d..13a5cbf0e9 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -906,6 +906,25 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe switch ( info.GetStyle() ) { case wxPENSTYLE_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 ( !info.GetColour().IsSolid() ) + { +#if wxOSX_USE_COCOA + // Under wxOSX, non-solid NSColors are actually represented + // by pattern images and therefore a wxPen with non-solid + // colour and wxPENSTYLE_SOLID style can be converted + // to a stiple (a surface pattern). + + // Create a stiple bitmap from NSColor's pattern image + wxBitmap bmp(info.GetColour().OSXGetNSPatternImage()); + InitStipple(&bmp); +#else + wxFAIL_MSG( "Pen with non-solid colour is not supported." ); +#endif + } + break; case wxPENSTYLE_DOT : @@ -964,6 +983,8 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe if ( info.GetStyle() >= wxPENSTYLE_FIRST_HATCH && info.GetStyle() <= wxPENSTYLE_LAST_HATCH ) { + wxASSERT_MSG( info.GetColour().IsSolid(), + "Pen with non-solid colour is not supported." ); InitHatch(static_cast(info.GetStyle())); } break;