SVGFileDC DrawEllipticArc is buggy

ABC <[email protected]> Tue, 19 Mar 2019 17:00:57 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
DrawEllipticArc is wrong with SVGFileDC:

- Lines are drawn to arc ends.
From 
https://wxpython.org/Phoenix/docs/html/wx.DC.html#wx.DC.DrawEllipticArc :
"Notice that unlike DrawArc 
<https://wxpython.org/Phoenix/docs/html/wx.DC.html#wx.DC.DrawArc> , this 
function does not draw the lines to the arc ends, even when using 
non-transparent brush."

- Incorrect drawing with and without fill depends on start/end angle.

- End point is 1 pixel too far.
Observe the SVG output, where some horizontal and vertical black lines are 
overlapped by the ellipses, while in the on screen drawing they are not.

Enclosed program draws to an SVG file (svg_ellipticarc.svg) and on screen.

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
svg_ellipticarc.py (text/x-python, 3.4 KB)
import wx

class DrawPanel(wx.Frame):
    def __init__(self, height_, width_):
        wx.Frame.__init__(self, None, title="Draw on Panel")
        self.Center()   # at center of display
        
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.height = height_
        self.width  = width_
        
    def draw(self, dc_):
        # hor lines
        dc_.SetPen(wx.Pen(wx.BLACK, 1, wx.SOLID))

        for y in range(0, self.height, 50):
            dc_.DrawLine(0, y, self.width, y)   # x1,y1 upto but not incl. x2,y2

        # vert lines
        dc_.SetPen(wx.Pen(wx.BLACK, 1, wx.SOLID))

        for x in range(0, self.width, 100):
            dc_.DrawLine(x, 0, x, self.height)

        # ellipses
        self.draw_4_elliptic_arcs(dc_, UL_x_ =   0, UL_y_ =   0, start_angle_ =  0, end_angle_ = 90, is_tranparent_ = True )
        self.draw_4_elliptic_arcs(dc_, UL_x_ =   0, UL_y_ = 150, start_angle_ =  0, end_angle_ = 90, is_tranparent_ = False)

        self.draw_4_elliptic_arcs(dc_, UL_x_ = 300, UL_y_ =   0, start_angle_ =  0, end_angle_ = 70, is_tranparent_ = True )
        self.draw_4_elliptic_arcs(dc_, UL_x_ = 300, UL_y_ = 150, start_angle_ =  0, end_angle_ = 70, is_tranparent_ = False)

        self.draw_4_elliptic_arcs(dc_, UL_x_ = 600, UL_y_ =   0, start_angle_ = 20, end_angle_ = 90, is_tranparent_ = True )
        self.draw_4_elliptic_arcs(dc_, UL_x_ = 600, UL_y_ = 150, start_angle_ = 20, end_angle_ = 90, is_tranparent_ = False)
    # end draw

    def draw_4_elliptic_arcs(self, dc_, UL_x_, UL_y_, start_angle_, end_angle_, is_tranparent_):
        dc_.SetPen(wx.Pen(wx.RED, 1))
        dc_.SetBrush(wx.TRANSPARENT_BRUSH if is_tranparent_ else wx.Brush(wx.RED))
        dc_.DrawEllipticArc(UL_x_, UL_y_,               # x,y upper-left corner of rectangle containing the ellipse
                            200, 100,                   # width, height of rectangle
                            start_angle_,  end_angle_)  # start, end or arch relative to 3 O'Clock rectangle position, in degrees (positive is counter-clockwise)

        dc_.SetPen(wx.Pen(wx.GREEN, 1))
        dc_.SetBrush(wx.TRANSPARENT_BRUSH if is_tranparent_ else wx.Brush(wx.GREEN))
        dc_.DrawEllipticArc(UL_x_, UL_y_,
                            200, 100,
                            start_angle_ + 90, end_angle_ + 90)

        dc_.SetPen(wx.Pen(wx.BLUE, 1))
        dc_.SetBrush(wx.TRANSPARENT_BRUSH if is_tranparent_ else wx.Brush(wx.BLUE))
        dc_.DrawEllipticArc(UL_x_, UL_y_,
                            200, 100,
                            start_angle_ + 180, end_angle_ + 180)

        dc_.SetPen(wx.Pen(wx.YELLOW, 1))
        dc_.SetBrush(wx.TRANSPARENT_BRUSH if is_tranparent_ else wx.Brush(wx.YELLOW))
        dc_.DrawEllipticArc(UL_x_, UL_y_,
                            200, 100,
                            start_angle_ + 270, end_angle_ + 270)
    # end draw_4_elliptic_arcs
        
    def OnPaint(self, event=None):
        dc = wx.PaintDC(self)
        dc.Clear()
        self.draw(dc)

        svgfile = wx.SVGFileDC('svg_ellipticarc.svg', width = self.width, height = self.height)
        self.draw(svgfile)
        svgfile.Destroy()   # to close the output file
    # end OnPaint
# end DrawPanel

# main
app   = wx.App(False)
frame_h = 251
frame_w = 801
frame = DrawPanel(frame_h, frame_w)
frame.SetClientSize((frame.width, frame.height))   # sets the size of the INSIDE of a window
frame.Show()
app.MainLoop()
svg_ellipticarc.svg (image/svg+xml, 7.4 KB) - not displayed
screen_elliptiarc.png (image/png, 10.4 KB) - not displayed