From: Robert Roebling Date: Fri, 24 Feb 2006 09:36:35 +0000 (+0000) Subject: New implementation for printing circles and epllipses. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/74ab0bfbb7a0713ed0c6830cc3b27bc6a9128194 New implementation for printing circles and epllipses. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/gnome/gprint.h b/include/wx/gtk/gnome/gprint.h index 9397e2f3af..eb5764a170 100644 --- a/include/wx/gtk/gnome/gprint.h +++ b/include/wx/gtk/gnome/gprint.h @@ -285,6 +285,8 @@ private: wxGnomePrinter *m_printer; GnomePrintContext *m_gpc; + void makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height); + private: wxCoord XDEV2LOG(wxCoord x) const { diff --git a/src/gtk/gnome/gprint.cpp b/src/gtk/gnome/gprint.cpp index c9c378e560..ab2d2db204 100644 --- a/src/gtk/gnome/gprint.cpp +++ b/src/gtk/gnome/gprint.cpp @@ -1155,30 +1155,59 @@ void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, } } +void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, + wxCoord width, wxCoord height) +{ + double r = 4 * (sqrt (2) - 1) / 3; + double halfW = 0.5 * width, + halfH = 0.5 * height, + halfWR = r * halfW, + halfHR = r * halfH; + wxCoord halfWI = (wxCoord) halfW, + halfHI = (wxCoord) halfH; + + gs_lgp->gnome_print_newpath( m_gpc ); + + // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ + gs_lgp->gnome_print_moveto( m_gpc, + XLOG2DEV(x + width), + YLOG2DEV(y + halfHI) ); + gs_lgp->gnome_print_curveto( m_gpc, + XLOG2DEV(x + width), + YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), + XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), + YLOG2DEV(y + height), + XLOG2DEV(x + halfWI), + YLOG2DEV(y + height) ); + gs_lgp->gnome_print_curveto( m_gpc, + XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), + YLOG2DEV(y + height), + XLOG2DEV(x), + YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), + XLOG2DEV(x), YLOG2DEV(y+halfHI) ); + gs_lgp->gnome_print_curveto( m_gpc, + XLOG2DEV(x), + YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), + XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), + YLOG2DEV(y), + XLOG2DEV(x+halfWI), YLOG2DEV(y) ); + gs_lgp->gnome_print_curveto( m_gpc, + XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), + YLOG2DEV(y), + XLOG2DEV(x + width), + YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), + XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); + + gs_lgp->gnome_print_closepath(m_gpc); +} + void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if (m_brush.GetStyle () != wxTRANSPARENT) { SetBrush( m_brush ); - - gs_lgp->gnome_print_newpath( m_gpc ); - gs_lgp->gnome_print_moveto( m_gpc, - XLOG2DEV(x), YLOG2DEV(y+height/2) ); - - // start with top half - gs_lgp->gnome_print_curveto( m_gpc, - XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x+width), YLOG2DEV(y), - XLOG2DEV(x+width), YLOG2DEV(y+height/2) ); - // lower half - gs_lgp->gnome_print_curveto( m_gpc, - XLOG2DEV(x+width), YLOG2DEV(y+height), - XLOG2DEV(x), YLOG2DEV(y+height), - XLOG2DEV(x), YLOG2DEV(y+height/2) ); - - gs_lgp->gnome_print_closepath( m_gpc ); + makeEllipticalPath( x, y, width, height ); gs_lgp->gnome_print_fill( m_gpc ); - CalcBoundingBox( x, y ); CalcBoundingBox( x + width, y + height ); } @@ -1186,25 +1215,8 @@ void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord if (m_pen.GetStyle () != wxTRANSPARENT) { SetPen (m_pen); - - gs_lgp->gnome_print_newpath( m_gpc ); - gs_lgp->gnome_print_moveto( m_gpc, - XLOG2DEV(x), YLOG2DEV(y+height/2) ); - - // start with top half - gs_lgp->gnome_print_curveto( m_gpc, - XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x+width), YLOG2DEV(y), - XLOG2DEV(x+width), YLOG2DEV(y+height/2) ); - // lower half - gs_lgp->gnome_print_curveto( m_gpc, - XLOG2DEV(x+width), YLOG2DEV(y+height), - XLOG2DEV(x), YLOG2DEV(y+height), - XLOG2DEV(x), YLOG2DEV(y+height/2) ); - - gs_lgp->gnome_print_closepath( m_gpc ); + makeEllipticalPath( x, y, width, height ); gs_lgp->gnome_print_stroke( m_gpc ); - CalcBoundingBox( x, y ); CalcBoundingBox( x + width, y + height ); }