From 2f41910aa01fd1897eb3e35b13891baabdd2efb5 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 24 Apr 2005 15:29:50 +0000 Subject: [PATCH] Added support for DrawArc and Blit to GNOME print. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33868 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/gnome/gprint.cpp | 67 ++++++++++++++++++++++++++++++++++++++- src/gtk1/gnome/gprint.cpp | 67 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/src/gtk/gnome/gprint.cpp b/src/gtk/gnome/gprint.cpp index 3b9abeaa32..abb1c7db73 100644 --- a/src/gtk/gnome/gprint.cpp +++ b/src/gtk/gnome/gprint.cpp @@ -37,6 +37,7 @@ #include #include +static const double RAD2DEG = 180.0 / M_PI; #include "wx/html/forcelnk.h" FORCE_LINK_ME(gnome_print) @@ -878,6 +879,58 @@ void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) { + double dx = x1 - xc; + double dy = y1 - yc; + double radius = sqrt((double)(dx*dx+dy*dy)); + double alpha1, alpha2; + if (x1 == x2 && y1 == y2) + { + alpha1 = 0.0; + alpha2 = 360.0; + } + else + if (radius == 0.0) + { + alpha1 = alpha2 = 0.0; + } + else + { + alpha1 = (x1 - xc == 0) ? + (y1 - yc < 0) ? 90.0 : -90.0 : + -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; + alpha2 = (x2 - xc == 0) ? + (y2 - yc < 0) ? 90.0 : -90.0 : + -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; + + while (alpha1 <= 0) alpha1 += 360; + while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between + while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree + while (alpha2 > 360) alpha2 -= 360; + } + + if (m_brush.GetStyle() != wxTRANSPARENT) + { + SetBrush( m_brush ); + gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); + gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); + + gs_lgp->gnome_print_fill( m_gpc ); + } + + if (m_pen.GetStyle() != wxTRANSPARENT) + { + SetPen (m_pen); + gs_lgp->gnome_print_newpath( m_gpc ); + gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); + gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); + gs_lgp->gnome_print_closepath( m_gpc ); + + gs_lgp->gnome_print_stroke( m_gpc ); + } + + CalcBoundingBox (x1, y1); + CalcBoundingBox (x2, y2); + CalcBoundingBox (xc, yc); } void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) @@ -1221,7 +1274,19 @@ bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) { - return false; + wxCHECK_MSG( source, false, wxT("invalid source dc") ); + + // blit into a bitmap + wxBitmap bitmap( width, height ); + wxMemoryDC memDC; + memDC.SelectObject(bitmap); + memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ + memDC.SelectObject(wxNullBitmap); + + // draw bitmap. scaling and positioning is done there + DrawBitmap( bitmap, xdest, ydest ); + + return true; } void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) diff --git a/src/gtk1/gnome/gprint.cpp b/src/gtk1/gnome/gprint.cpp index 3b9abeaa32..abb1c7db73 100644 --- a/src/gtk1/gnome/gprint.cpp +++ b/src/gtk1/gnome/gprint.cpp @@ -37,6 +37,7 @@ #include #include +static const double RAD2DEG = 180.0 / M_PI; #include "wx/html/forcelnk.h" FORCE_LINK_ME(gnome_print) @@ -878,6 +879,58 @@ void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) { + double dx = x1 - xc; + double dy = y1 - yc; + double radius = sqrt((double)(dx*dx+dy*dy)); + double alpha1, alpha2; + if (x1 == x2 && y1 == y2) + { + alpha1 = 0.0; + alpha2 = 360.0; + } + else + if (radius == 0.0) + { + alpha1 = alpha2 = 0.0; + } + else + { + alpha1 = (x1 - xc == 0) ? + (y1 - yc < 0) ? 90.0 : -90.0 : + -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; + alpha2 = (x2 - xc == 0) ? + (y2 - yc < 0) ? 90.0 : -90.0 : + -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; + + while (alpha1 <= 0) alpha1 += 360; + while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between + while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree + while (alpha2 > 360) alpha2 -= 360; + } + + if (m_brush.GetStyle() != wxTRANSPARENT) + { + SetBrush( m_brush ); + gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); + gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); + + gs_lgp->gnome_print_fill( m_gpc ); + } + + if (m_pen.GetStyle() != wxTRANSPARENT) + { + SetPen (m_pen); + gs_lgp->gnome_print_newpath( m_gpc ); + gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); + gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); + gs_lgp->gnome_print_closepath( m_gpc ); + + gs_lgp->gnome_print_stroke( m_gpc ); + } + + CalcBoundingBox (x1, y1); + CalcBoundingBox (x2, y2); + CalcBoundingBox (xc, yc); } void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) @@ -1221,7 +1274,19 @@ bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) { - return false; + wxCHECK_MSG( source, false, wxT("invalid source dc") ); + + // blit into a bitmap + wxBitmap bitmap( width, height ); + wxMemoryDC memDC; + memDC.SelectObject(bitmap); + memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ + memDC.SelectObject(wxNullBitmap); + + // draw bitmap. scaling and positioning is done there + DrawBitmap( bitmap, xdest, ydest ); + + return true; } void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) -- 2.45.2