Exemplo n.º 1
0
 def makeBackground(self):
     if self.background is not None:
         BG = self.background
         if isinstance(BG,Group):
             g = BG
             for bg in g.contents:
                 bg.x = self.x
                 bg.y = self.y
                 bg.width = self.width
                 bg.height = self.height
         else:
             g = Group()
             if type(BG) not in (type(()),type([])): BG=(BG,)
             for bg in BG:
                 bg.x = self.x
                 bg.y = self.y
                 bg.width = self.width
                 bg.height = self.height
                 g.add(bg)
         return g
     else:
         strokeColor,strokeWidth,fillColor=self.strokeColor, self.strokeWidth, self.fillColor
         if (strokeWidth and strokeColor) or fillColor:
             g = Group()
             _3d_dy = getattr(self,'_3d_dy',None)
             x = self.x
             y = self.y
             h = self.height
             w = self.width
             if _3d_dy is not None:
                 _3d_dx = self._3d_dx
                 if fillColor and not strokeColor:
                     from reportlab.lib.colors import Blacker
                     c = Blacker(fillColor, getattr(self,'_3d_blacken',0.7))
                 else:
                     c = strokeColor
                 if not strokeWidth: strokeWidth = 0.5
                 if fillColor or strokeColor or c:
                     bg = Polygon([x,y,x,y+h,x+_3d_dx,y+h+_3d_dy,x+w+_3d_dx,y+h+_3d_dy,x+w+_3d_dx,y+_3d_dy,x+w,y],
                         strokeColor=strokeColor or c or grey, strokeWidth=strokeWidth, fillColor=fillColor)
                     g.add(bg)
                     g.add(Line(x,y,x+_3d_dx,y+_3d_dy, strokeWidth=0.5, strokeColor=c))
                     g.add(Line(x+_3d_dx,y+_3d_dy, x+_3d_dx,y+h+_3d_dy,strokeWidth=0.5, strokeColor=c))
                     fc = Blacker(c, getattr(self,'_3d_blacken',0.8))
                     g.add(Polygon([x,y,x+_3d_dx,y+_3d_dy,x+w+_3d_dx,y+_3d_dy,x+w,y],
                         strokeColor=strokeColor or c or grey, strokeWidth=strokeWidth, fillColor=fc))
                     bg = Line(x+_3d_dx,y+_3d_dy, x+w+_3d_dx,y+_3d_dy,strokeWidth=0.5, strokeColor=c)
                 else:
                     bg = None
             else:
                 bg = Rect(x, y, w, h,
                     strokeColor=strokeColor, strokeWidth=strokeWidth, fillColor=fillColor)
             if bg: g.add(bg)
             return g
         else:
             return None
Exemplo n.º 2
0
    def checkboxAP(
        self,
        key,  #N/D/R
        value,  #Yes/Off
        buttonStyle='circle',
        shape='square',
        fillColor=None,
        borderColor=None,
        textColor=None,
        borderWidth=1,
        borderStyle='solid',
        size=20,
        dashLen=3,
    ):
        stream = [].append
        ds = size
        if shape == 'square':
            stream('q')
            streamFill = self.streamFillColor(fillColor)
            stream('1 g 1 G %(streamFill)s 0 0 %(size)s %(size)s re f')
            if borderWidth != None:
                streamStroke = self.streamStrokeColor(borderColor)
                hbw = borderWidth * 0.5
                smbw = size - borderWidth
                ds = smbw
                if borderStyle == 'underlined':
                    stream(
                        '%(streamStroke)s %(borderWidth)s w 0 %(hbw)s m %(size)s %(hbw)s l s'
                    )
                elif borderStyle in ('dashed', 'inset', 'bevelled', 'solid'):
                    if borderStyle == 'dashed':
                        dash = ' [%s ] 0 d' % fp_str(dashLen)
                    else:
                        dash = ''
                    stream(
                        '%(streamStroke)s%(dash)s %(borderWidth)s w %(hbw)s %(hbw)s %(smbw)s %(smbw)s re s'
                    )

                if borderStyle in ('bevelled', 'inset'):
                    _2bw = 2 * borderWidth
                    sm2bw = size - _2bw
                    ds = sm2bw
                    bbs0 = Blacker(fillColor, 0.5)
                    bbs1 = fillColor
                    if key != 'D':
                        bbs0, bbs1 = bbs1, bbs0
                    bbs0 = self.streamFillColor(bbs0)
                    bbs1 = self.streamFillColor(bbs1)
                    stream(
                        '%(bbs0)s %(borderWidth)s %(borderWidth)s m %(borderWidth)s %(smbw)s l %(smbw)s %(smbw)s l %(sm2bw)s %(sm2bw)s l %(_2bw)s %(sm2bw)s l %(_2bw)s %(_2bw)s l f %(bbs1)s %(smbw)s %(smbw)s m %(smbw)s %(borderWidth)s l %(borderWidth)s %(borderWidth)s l %(_2bw)s %(_2bw)s l %(sm2bw)s %(_2bw)s l %(sm2bw)s %(sm2bw)s l f'
                    )
            stream('Q')
        elif shape == 'circle':
            cas = lambda _r, **_casKwds: self.circleArcStream(
                size, _r, **_casKwds)
            r = size * 0.5
            streamFill = self.streamFillColor(fillColor)
            stream('q 1 g 1 G %(streamFill)s')
            stream(cas(r))
            stream('f')
            stream('Q')
            if borderWidth != None:
                stream('q')
                streamStroke = self.streamStrokeColor(borderColor)
                hbw = borderWidth * 0.5
                ds = size - borderWidth
                if borderStyle == 'underlined':
                    stream(
                        'q %(streamStroke)s %(borderWidth)s w 0 %(hbw)s m %(size)s %(hbw)s l s Q'
                    )
                elif borderStyle in ('dashed', 'inset', 'bevelled', 'solid'):
                    if borderStyle == 'dashed':
                        dash = ' [3 ] 0 d'
                    else:
                        dash = ''
                    stream('%(streamStroke)s%(dash)s %(borderWidth)s w')
                    stream(cas(r - hbw))
                    stream('s')
                stream('Q')
                if borderStyle in ('bevelled', 'inset'):
                    _3bwh = 3 * hbw
                    ds = size - _3bwh
                    bbs0 = Blacker(fillColor, 0.5)
                    bbs1 = Whiter(fillColor, 0.5)
                    a0 = (0, 1)
                    a1 = (2, 3)
                    if borderStyle == 'inset':
                        bbs0, bbs1 = bbs1, bbs0
                    if key != 'D':
                        bbs0, bbs1 = bbs1, bbs0
                    bbs0 = self.streamStrokeColor(bbs0)
                    bbs1 = self.streamStrokeColor(bbs1)
                    stream('q %(bbs0)s %(borderWidth)s w')
                    stream(cas(r - _3bwh, rotated=True, arcs=a0))
                    stream('S Q %(bbs1)s q')
                    stream(cas(r - _3bwh, rotated=True, arcs=a1))
                    stream('S Q')
        if value == 'Yes':
            textFillColor = self.streamFillColor(textColor)
            textStrokeColor = self.streamStrokeColor(textColor)
            stream('q %(textFillColor)s %(textStrokeColor)s')
            cbm = cbmarks[buttonStyle]
            if shape == 'circle' and buttonStyle == 'circle':
                stream(cas((max(r - (size - ds), 1)) * 0.5))
                stream('f')
            else:
                stream(cbm.scaledRender(size, size - ds))
            stream('Q')
        stream = ('\n'.join(stream.__self__) % vars()).replace(
            '  ', ' ').replace('\n\n', '\n')
        return self.makeStream(
            size,
            size,
            stream,
            Resources=PDFFromString('<< /ProcSet [/PDF] >>'),
        )
Exemplo n.º 3
0
def _getShaded(col, shd=None, shading=0.1):
    if shd is None:
        from reportlab.lib.colors import Blacker
        if col: shd = Blacker(col, 1 - shading)
    return shd