Exemple #1
0
    def endDraw(self, style, tflist):
        # fill should be painted first, then the stroke, and then the marker symbols
        fill = self.getStyleAttr('fill', style)
        stroke = self.getStyleAttr('stroke', style)
        fillRule = self.getStyleAttr('fill-rule', style)

        # fill attrs
        brush = None
        rop = None
        if fill is not None and fill != 'none':
            contextFill = self.getStyleAttr('fill')
            if contextFill != fill:
                brush = wingdi.CreateSolidBrush(fill)
                brush = self.dc.SelectObject(brush)
            try:
                if stroke and stroke != 'none':
                    # keep path for stroke
                    dcid = self.dc.SaveDC()
                    if fillRule == 'nonzero':
                        self.dc.SetPolyFillMode(win32con.WINDING)
                    else:
                        self.dc.SetPolyFillMode(win32con.ALTERNATE)
                    self.dc.FillPath()
                    self.dc.RestoreDC(dcid)
                else:
                    if fillRule == 'nonzero':
                        self.dc.SetPolyFillMode(win32con.WINDING)
                    else:
                        self.dc.SetPolyFillMode(win32con.ALTERNATE)
                    self.dc.FillPath()
            except wingdi.error, arg:
                print arg, style, tflist
            if brush:
                wingdi.DeleteObject(self.dc.SelectObject(brush))
Exemple #2
0
    def _paintOnDC(self, dc):

        # clip self to ancestors and dc, in device coordinates
        ltrb = self.getClipDR(dc)
        if ltrb is None or ltrb[0] == ltrb[2] or ltrb[1] == ltrb[3]:
            return

        # clip self to parent, device coordinates
        xywh_dst = self.getDR()

        if self._active_displist:
            entry = self._active_displist._list[0]
            bgcolor = None
            if entry[0] == 'clear' and entry[1]:
                bgcolor = entry[1]
            elif not self._transparent:
                bgcolor = self._bgcolor
            if bgcolor:
                x, y, w, h = xywh_dst
                rgb = winstruct.RGB(self._bgcolor)
                dc.FillSolidRect((x, y, x + w, y + h), rgb)
            self._active_displist._render(dc, ltrb, xywh_dst, start=1)
            if self._showing:
                brush = wingdi.CreateSolidBrush((255, 0, 0))
                dc.FrameRect(ltrb, brush)
                wingdi.DeleteObject(brush)

        elif self._transparent == 0 and self._bgcolor:
            x, y, w, h = xywh_dst
            rgb = winstruct.RGB(self._bgcolor)
            dc.FillSolidRect((x, y, x + w, y + h), rgb)
Exemple #3
0
    def tkOnEndContext(self):
        # restore dc to its previous state before deleting objects
        self.dc.RestoreDC(self.tk.saveid)

        if self.tk.pen:
            wingdi.DeleteObject(self.tk.pen)

        if self.tk.brush:
            wingdi.DeleteObject(self.tk.brush)

        if self.tk.font:
            wingdi.DeleteObject(self.tk.font)

        # restore previous tk
        self.restoreTk()

        # establish tk transform
        self.dc.SetWorldTransform(self.ctm.getElements())
Exemple #4
0
    def _paintOnSurf(self, surf, wnd_dc=None, xywh_clip=None):
        if wnd_dc is None:
            wnd_dc = wingdi.GetDesktopDC()
            release_wnd_dc = 1
        else:
            release_wnd_dc = 0

        dc = wnd_dc.CreateCompatibleDC()
        oldsurf = dc.SelectObject(surf)

        ws, hs = surf.GetSize()
        xywh_dst = 0, 0, ws, hs

        if xywh_clip is None:
            ltrb = 0, 0, ws, hs
        else:
            ltrb = self.ltrb(xywh_clip)

        if self._active_displist:
            entry = self._active_displist._list[0]
            bgcolor = None
            if entry[0] == 'clear' and entry[1]:
                bgcolor = entry[1]
            elif not self._transparent:
                bgcolor = self._bgcolor
            if bgcolor:
                x, y, w, h = xywh_dst
                rgb = winstruct.RGB(self._bgcolor)
                dc.FillSolidRect((x, y, x + w, y + h), rgb)
            self._active_displist._render(dc, ltrb, xywh_dst, start=1)
            if self._showing:
                brush = wingdi.CreateSolidBrush((255, 0, 0))
                dc.FrameRect(ltrb, brush)
                wingdi.DeleteObject(brush)

        elif self._transparent == 0 and self._bgcolor:
            x, y, w, h = xywh_dst
            rgb = winstruct.RGB(self._bgcolor)
            dc.FillSolidRect((x, y, x + w, y + h), rgb)

        dc.SelectObject(oldsurf)
        dc.DeleteDC()
        if release_wnd_dc:
            wnd_dc.DeleteDC()
Exemple #5
0
 def close(self):
     if self._hfont and Sdk:
         wingdi.DeleteObject(self._hfont)
         self._hfont = 0
Exemple #6
0
 def __del__(self):
     if self._hfont:
         wingdi.DeleteObject(self._hfont)
Exemple #7
0
    def drawText(self, text, pos, style, tflist, a=0):
        if tflist:
            tm = self.ctm.copy()
            tm.applyTfList(tflist)
            self.dc.SetWorldTransform(tm.getElements())

        font = None
        fontFamily = self.getStyleAttr('font-family', style)
        fontSize = self.getStyleAttr('font-size', style)
        if fontFamily is not None:
            contextFontFamily = self.getStyleAttr('font-family')
            contextFontSize = self.getStyleAttr('font-size')
            if contextFontFamily != fontFamily or contextFontSize != fontSize:
                fontSizeObj = self.getStyleAttrObj('font-size', style)
                dsize = fontSize  # fontSizeObj.getDeviceValue(self.ctm, 'h')
                font = wingdi.CreateFontIndirect({
                    'name':
                    fontFamily,
                    'height':
                    dsize,
                    'outprecision':
                    win32con.OUT_OUTLINE_PRECIS
                })
                self.dc.SelectObject(font)

        fill = self.getStyleAttr('fill', style)
        stroke = self.getStyleAttr('stroke', style)

        # whats the default?
        if fill is None and stroke is None:
            # text will be invisible
            # make it visible as black
            fill = 0, 0, 0
            oldcolor = self.dc.SetTextColor(fill)
            self.dc.TextOut(pos, text)
            self.dc.SetTextColor(oldcolor)

        elif fill is not None:
            oldcolor = self.dc.SetTextColor(fill)
            self.dc.TextOut(pos, text)
            self.dc.SetTextColor(oldcolor)

        pen = None
        strokeWidth = self.getStyleAttr('stroke-width', style)
        if stroke:
            # create path
            self.dc.BeginPath()
            self.dc.TextOut(pos, text)
            self.dc.EndPath()

            # stroke path
            contextStroke = self.getStyleAttr('stroke')
            contextStrokeWidth = self.getStyleAttr('stroke-width')
            if contextStroke != stroke or contextStrokeWidth != strokeWidth:
                pen = wingdi.ExtCreatePen(strokeWidth, stroke)
                pen = self.dc.SelectObject(pen)
            self.dc.StrokePath()
            if pen:
                wingdi.DeleteObject(self.dc.SelectObject(pen))

        if font:
            wingdi.DeleteObject(self.dc.SelectObject(font))
        if tflist:
            self.dc.SetWorldTransform(self.ctm.getElements())
Exemple #8
0
class SVGWinGraphics(svggraphics.SVGGraphics):
    #
    #  platform toolkit interface
    #
    # called to intialize platform toolkit before rendering
    def tkStartup(self, params):
        hdc = params
        self.dc = wingdi.CreateDCFromHandle(hdc)

        # context vars
        self.tk = Tk()
        self.saveidorg = self.tk.saveid = self.dc.SaveDC()
        self._tkstack = []

        self.dc.SetGraphicsMode(win32con.GM_ADVANCED)
        self.dc.SetBkMode(win32con.TRANSPARENT)
        self.dc.SetTextAlign(win32con.TA_BASELINE)

    # called to dispose platform toolkit objects after rendering
    def tkShutdown(self):
        self.dc.SetGraphicsMode(win32con.GM_COMPATIBLE)
        self.dc.SetMapMode(win32con.MM_TEXT)
        self.dc.RestoreDC(self.tk.saveid)
        self.dc.Detach()

    # we start rendering
    def tkOnBeginRendering(self):
        self.dc.SetMapMode(win32con.MM_ISOTROPIC)
        vcx, vcy = self.dc.GetViewportExtEx()
        if vcy < 0: vcy = -vcy
        self.dc.SetWindowExtEx((vcx, vcy))
        self.dc.SetViewportExtEx((vcx, vcy))
        self.dc.SetViewportOrgEx((0, 0))

    # we finished rendering
    def tkOnEndRendering(self):
        pass

    def delRegion(self, rgn):
        rgn.DeleteObject()

    def inside(self, rgn, pt):
        return rgn.PtInRegion(pt)

    # new graphics context
    # self state reflects this new context
    def tkOnBeginContext(self):
        # push current tkctx
        self.saveTk()

        # save dc and hold its id for restore
        self.tk.saveid = self.dc.SaveDC()

        # establish tk pen
        stroke = self.getStyleAttr('stroke')
        strokeWidth = self.getStyleAttr('stroke-width')
        if stroke is not None and stroke != 'none':
            self.tk.pen = wingdi.ExtCreatePen(strokeWidth, stroke)
            self.dc.SelectObject(self.tk.pen)

        # establish tk brush
        fill = self.getStyleAttr('fill')
        if fill is not None and fill != 'none':
            self.tk.brush = wingdi.CreateSolidBrush(fill)
            self.dc.SelectObject(self.tk.brush)

        # establish tk font
        fontFamily = self.getStyleAttr('font-family')
        fontSize = self.getStyleAttr('font-size')
        if fontFamily is not None:
            self.tk.font = wingdi.CreateFontIndirect({
                'name':
                fontFamily,
                'height':
                fontSize,
                'outprecision':
                win32con.OUT_OUTLINE_PRECIS,
            })
            self.dc.SelectObject(self.tk.font)

        # establish tk transform
        self.dc.SetWorldTransform(self.ctm.getElements())

    # end of context
    # self state reflects the restored context
    def tkOnEndContext(self):
        # restore dc to its previous state before deleting objects
        self.dc.RestoreDC(self.tk.saveid)

        if self.tk.pen:
            wingdi.DeleteObject(self.tk.pen)

        if self.tk.brush:
            wingdi.DeleteObject(self.tk.brush)

        if self.tk.font:
            wingdi.DeleteObject(self.tk.font)

        # restore previous tk
        self.restoreTk()

        # establish tk transform
        self.dc.SetWorldTransform(self.ctm.getElements())

    # init toolkit objects for 'other'
    def tkInitInstance(self, other):
        other.dc = self.dc
        other.tk = self.tk
        other._tkstack = self._tkstack

    def tkClipBox(self, clipbox):
        if clipbox is not None:
            tmprev = svgtypes.TM(self.dc.GetWorldTransform())
            self.dc.SetWorldTransform(self.ctm.getElements())
            x, y, w, h = clipbox
            ltrb = x, y, x + w, y + h
            tm = svgtypes.TM(self.dc.GetWorldTransform())
            ltrb = tm.URtoDR(ltrb)
            self.dc.SetWorldTransform([1, 0, 0, 1, 0, 0])
            rgn = wingdi.CreateRectRgn(ltrb)
            self.dc.SelectClipRgn(rgn)
            rgn.DeleteObject()
            self.dc.SetWorldTransform(tmprev.getElements())

    #
    #  platform line art interface
    #
    def beginDraw(self, style, tflist):
        if tflist:
            tm = self.ctm.copy()
            tm.applyTfList(tflist)
            self.dc.SetWorldTransform(tm.getElements())

    def endDraw(self, style, tflist):
        # fill should be painted first, then the stroke, and then the marker symbols
        fill = self.getStyleAttr('fill', style)
        stroke = self.getStyleAttr('stroke', style)
        fillRule = self.getStyleAttr('fill-rule', style)

        # fill attrs
        brush = None
        rop = None
        if fill is not None and fill != 'none':
            contextFill = self.getStyleAttr('fill')
            if contextFill != fill:
                brush = wingdi.CreateSolidBrush(fill)
                brush = self.dc.SelectObject(brush)
            try:
                if stroke and stroke != 'none':
                    # keep path for stroke
                    dcid = self.dc.SaveDC()
                    if fillRule == 'nonzero':
                        self.dc.SetPolyFillMode(win32con.WINDING)
                    else:
                        self.dc.SetPolyFillMode(win32con.ALTERNATE)
                    self.dc.FillPath()
                    self.dc.RestoreDC(dcid)
                else:
                    if fillRule == 'nonzero':
                        self.dc.SetPolyFillMode(win32con.WINDING)
                    else:
                        self.dc.SetPolyFillMode(win32con.ALTERNATE)
                    self.dc.FillPath()
            except wingdi.error, arg:
                print arg, style, tflist
            if brush:
                wingdi.DeleteObject(self.dc.SelectObject(brush))

        # stroke attrs
        pen = None
        strokeWidth = self.getStyleAttr('stroke-width', style)
        if stroke is not None and stroke != 'none':
            contextStroke = self.getStyleAttr('stroke')
            contextStrokeWidth = self.getStyleAttr('stroke-width')
            strokeMiterlimit = self.getStyleAttr('stroke-miterlimit', style)
            if strokeMiterlimit:
                oldStrokeMiterlimit = self.dc.SetMiterLimit(strokeMiterlimit)
            if contextStroke != stroke or contextStrokeWidth != strokeWidth:
                pen = wingdi.ExtCreatePen(strokeWidth, stroke)
                pen = self.dc.SelectObject(pen)
            try:
                self.dc.StrokePath()
            except wingdi.error, arg:
                print arg, style, tflist
            if pen:
                wingdi.DeleteObject(self.dc.SelectObject(pen))
            if strokeMiterlimit:
                self.dc.SetMiterLimit(oldStrokeMiterlimit)