X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e77cba1a9c2085b15789bbdc3d38697c4670d2a7..8e6c2840b4149e356350cac7449a96323b4466ec:/src/generic/graphicc.cpp diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index f3c5a1f8d8..50965a5b99 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -290,6 +290,7 @@ class wxCairoBitmapData : public wxGraphicsObjectRefData { public: wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ); + wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ); ~wxCairoBitmapData(); virtual cairo_surface_t* GetCairoSurface() { return m_surface; } @@ -346,7 +347,7 @@ public: virtual void BeginLayer(wxDouble opacity); virtual void EndLayer(); - + virtual void StrokePath( const wxGraphicsPath& p ); virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxWINDING_RULE ); @@ -380,7 +381,7 @@ private: void Init(cairo_t *context); cairo_t* m_context; - + wxVector m_layerOpacities; wxDECLARE_NO_COPY_CLASS(wxCairoContext); @@ -1014,11 +1015,17 @@ void * wxCairoMatrixData::GetNativeMatrix() const // wxCairoBitmap implementation //----------------------------------------------------------------------------- +wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ) : + wxGraphicsObjectRefData( renderer ) +{ + m_surface = bitmap; + m_pattern = cairo_pattern_create_for_surface(m_surface); +} + wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsObjectRefData( renderer ) { wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap")); - cairo_surface_t* surface; int bw = bmp.GetWidth(); int bh = bmp.GetHeight(); wxBitmap bmpSource = bmp; // we need a non-const instance @@ -1085,12 +1092,17 @@ wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitm p.OffsetY(pixData, 1); } } + m_pattern = cairo_pattern_create_for_surface(m_surface); } wxCairoBitmapData::~wxCairoBitmapData() { - cairo_pattern_destroy(m_pattern); - cairo_surface_destroy(m_surface); + if (m_pattern) + cairo_pattern_destroy(m_pattern); + + if (m_surface) + cairo_surface_destroy(m_surface); + delete [] m_buffer; } @@ -1437,8 +1449,8 @@ void wxCairoContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y) wxCairoFontData* font_data = (wxCairoFontData*) m_font.GetRefData(); pango_layout_set_font_description( layout, font_data->GetFont()); pango_layout_set_text(layout, data, datalen); - - if (font_data->GetUnderlined()) + + if (font_data->GetUnderlined()) { PangoAttrList *attrs = pango_attr_list_new(); PangoAttribute *attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); @@ -1564,7 +1576,7 @@ bool wxCairoContext::SetAntialiasMode(wxAntialiasMode antialias) return true; m_antialias = antialias; - + cairo_antialias_t antialiasMode; switch (antialias) { @@ -1585,7 +1597,7 @@ bool wxCairoContext::SetCompositionMode(wxCompositionMode op) { if ( m_composition == op ) return true; - + m_composition = op; cairo_operator_t cop; switch (op) @@ -1649,7 +1661,7 @@ void wxCairoContext::EndLayer() cairo_pop_group_to_source(m_context); cairo_paint_with_alpha(m_context,opacity); } - + //----------------------------------------------------------------------------- // wxCairoRenderer declaration //----------------------------------------------------------------------------- @@ -1704,6 +1716,9 @@ public : // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); + // create a graphics bitmap from a native bitmap + virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ); + // create a subimage from a native image representation virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); @@ -1863,7 +1878,7 @@ wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour return wxNullGraphicsFont; } -wxGraphicsBitmap wxGraphicsRenderer::CreateBitmap( const wxBitmap& bmp ) +wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp ) { if ( bmp.Ok() ) { @@ -1875,7 +1890,24 @@ wxGraphicsBitmap wxGraphicsRenderer::CreateBitmap( const wxBitmap& bmp ) return wxNullGraphicsBitmap; } -wxGraphicsBitmap wxGraphicsRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) +wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) +{ + if ( bitmap != NULL ) + { + wxGraphicsBitmap p; + p.SetRefData(new wxCairoBitmapData( this , (cairo_surface_t*) bitmap )); + return p; + } + else + return wxNullGraphicsBitmap; +} + +wxGraphicsBitmap +wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap), + wxDouble WXUNUSED(x), + wxDouble WXUNUSED(y), + wxDouble WXUNUSED(w), + wxDouble WXUNUSED(h)) { wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented."); return wxNullGraphicsBitmap;