本文整理汇总了Python中reportlab.graphics.shapes.Group.add方法的典型用法代码示例。如果您正苦于以下问题:Python Group.add方法的具体用法?Python Group.add怎么用?Python Group.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.shapes.Group
的用法示例。
在下文中一共展示了Group.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Flag_Spain
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def _Flag_Spain(self):
s = _size
g = Group()
w = self._width = s*1.5
g.add(Rect(0, 0, width=w, height=s, fillColor = colors.red, strokeColor = None, strokeWidth=0))
g.add(Rect(0, (s/4), width=w, height=s/2, fillColor = colors.yellow, strokeColor = None, strokeWidth=0))
return g
示例2: getTalkRect
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def getTalkRect(self, startTime, duration, trackId, text):
"Return shapes for a specific talk"
g = Group()
y_bottom = self.scaleTime(startTime + duration)
y_top = self.scaleTime(startTime)
y_height = y_top - y_bottom
if trackId is None:
#spans all columns
x = self._colLeftEdges[1]
width = self.width - self._colWidths[0]
else:
#trackId is 1-based and these arrays have the margin info in column
#zero, so no need to add 1
x = self._colLeftEdges[trackId]
width = self._colWidths[trackId]
lab = Label()
lab.setText(text)
lab.setOrigin(x + 0.5*width, y_bottom+0.5*y_height)
lab.boxAnchor = 'c'
lab.width = width
lab.height = y_height
lab.fontSize = 6
r = Rect(x, y_bottom, width, y_height, fillColor=colors.cyan)
g.add(r)
g.add(lab)
#now for a label
# would expect to color-code and add text
return g
示例3: draw
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def draw(self):
s = float(self.size) #abbreviate as we will use this a lot
g = Group()
# new algorithm from markers.StarFive
R = float(self.size)/2
r = R*sin(18*(pi/180.0))/cos(36*(pi/180.0))
P = []
angle = 90
for i in xrange(5):
for radius in R, r:
theta = angle*(pi/180.0)
P.append(radius*cos(theta))
P.append(radius*sin(theta))
angle = angle + 36
# star specific bits
star = Polygon(P,
fillColor = self.fillColor,
strokeColor = self.strokeColor,
strokeWidth=s/50)
g.rotate(self.angle)
g.shift(self.x+self.dx,self.y+self.dy)
g.add(star)
return g
示例4: makeCircularString
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def makeCircularString(x, y, radius, angle, text, fontName, fontSize, inside=0, G=None,textAnchor='start'):
'''make a group with circular text in it'''
if not G: G = Group()
angle %= 360
pi180 = pi/180
phi = angle*pi180
width = stringWidth(text, fontName, fontSize)
sig = inside and -1 or 1
hsig = sig*0.5
sig90 = sig*90
if textAnchor!='start':
if textAnchor=='middle':
phi += sig*(0.5*width)/radius
elif textAnchor=='end':
phi += sig*float(width)/radius
elif textAnchor=='numeric':
phi += sig*float(numericXShift(textAnchor,text,width,fontName,fontSize,None))/radius
for letter in text:
width = stringWidth(letter, fontName, fontSize)
beta = float(width)/radius
h = Group()
h.add(String(0, 0, letter, fontName=fontName,fontSize=fontSize,textAnchor="start"))
h.translate(x+cos(phi)*radius,y+sin(phi)*radius) #translate to radius and angle
h.rotate((phi-hsig*beta)/pi180-sig90) # rotate as needed
G.add(h) #add to main group
phi -= sig*beta #increment
return G
示例5: makeSwatchSample
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def makeSwatchSample(self, rowNo, x, y, width, height):
baseStyle = self.strands
styleIdx = rowNo % len(baseStyle)
style = baseStyle[styleIdx]
strokeColor = getattr(style, 'strokeColor', getattr(baseStyle,'strokeColor',None))
fillColor = getattr(style, 'fillColor', getattr(baseStyle,'fillColor',None))
strokeDashArray = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
strokeWidth = getattr(style, 'strokeWidth', getattr(baseStyle, 'strokeWidth',0))
symbol = getattr(style, 'symbol', getattr(baseStyle, 'symbol',None))
ym = y+height/2.0
if fillColor is None and strokeColor is not None and strokeWidth>0:
bg = Line(x,ym,x+width,ym,strokeWidth=strokeWidth,strokeColor=strokeColor,
strokeDashArray=strokeDashArray)
elif fillColor is not None:
bg = Rect(x,y,width,height,strokeWidth=strokeWidth,strokeColor=strokeColor,
strokeDashArray=strokeDashArray,fillColor=fillColor)
else:
bg = None
if symbol:
symbol = uSymbol2Symbol(symbol,x+width/2.,ym,color)
if bg:
g = Group()
g.add(bg)
g.add(symbol)
return g
return symbol or bg
示例6: rotatedEnclosingRect
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def rotatedEnclosingRect(P, angle, rect):
'''
given P a sequence P of x,y coordinate pairs and an angle in degrees
find the centroid of P and the axis at angle theta through it
find the extreme points of P wrt axis parallel distance and axis
orthogonal distance. Then compute the least rectangle that will still
enclose P when rotated by angle.
The class R
'''
from math import pi, cos, sin, tan
x0, y0 = centroid(P)
theta = (angle/180.)*pi
s,c=sin(theta),cos(theta)
def parallelAxisDist(xy,s=s,c=c,x0=x0,y0=y0):
x,y = xy
return (s*(y-y0)+c*(x-x0))
def orthogonalAxisDist(xy,s=s,c=c,x0=x0,y0=y0):
x,y = xy
return (c*(y-y0)+s*(x-x0))
L = map(parallelAxisDist,P)
L.sort()
a0, a1 = L[0], L[-1]
L = map(orthogonalAxisDist,P)
L.sort()
b0, b1 = L[0], L[-1]
rect.x, rect.width = a0, a1-a0
rect.y, rect.height = b0, b1-b0
g = Group(transform=(c,s,-s,c,x0,y0))
g.add(rect)
return g
示例7: makeInnerTiles
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def makeInnerTiles(self):
# inner grid lines
group = Group()
w, h = self.width, self.height
# inner grid stripes (solid rectangles)
if self.useRects == 1:
cols = self.stripeColors
if self.orientation == 'vertical':
r = self.makeLinePosList(self.x, isX=1)
elif self.orientation == 'horizontal':
r = self.makeLinePosList(self.y, isX=0)
dist = makeDistancesList(r)
i = 0
for j in range(len(dist)):
if self.orientation == 'vertical':
x = r[j]
stripe = Rect(x, self.y, dist[j], h)
elif self.orientation == 'horizontal':
y = r[j]
stripe = Rect(self.x, y, w, dist[j])
stripe.fillColor = cols[i % len(cols)]
stripe.strokeColor = None
group.add(stripe)
i = i + 1
return group
示例8: getCaptcha
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def getCaptcha(n=5,fontName='Courier',fontSize=14,text=None,fillColor=None):
'''return n random chars in a string and in a byte string structured
as a GIF image'''
from reportlab.graphics.shapes import Drawing, Group, String, \
rotate, skewX, skewY, mmult, translate, Rect
if not text:
from random import randint, uniform
text=''.join([_allowed[randint(0,_mx)] for i in range(n)])
else:
uniform = lambda l,h: 0.5*(l+h)
n = len(text)
baseline = 0
x = 0
G0 = Group()
for c in text:
x += 1
A = translate(x,uniform(baseline-5,baseline+5))
A = mmult(A,rotate(uniform(-15,15)))
A = mmult(A,skewX(uniform(-8,8)))
A = mmult(A,skewY(uniform(-8,8)))
G = Group(transform=A)
G.add(String(0,0,c,fontname=fontName,fontSize=fontSize))
G0.add(G)
x0,y0,x1,y1 = G0.getBounds()
x = 1+x1
G0.transform=translate(2-x0,2-y0)
W = 4+x1-x0
H = 4+y1-y0
D = Drawing(W,H)
if fillColor:
from reportlab.lib.colors import toColor
D.add(Rect(0,0,W,H, fillColor = toColor(fillColor),strokeColor=None))
D.add(G0)
return text, D.asString('gif')
示例9: _Flag_Greece
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def _Flag_Greece(self):
s = _size
g = Group()
box = Rect(0, 0, s*2, s, fillColor = colors.gold,
strokeColor = colors.black, strokeWidth=0)
g.add(box)
for stripecounter in range (9,0, -1):
stripeheight = s/9.0
if not (stripecounter%2 == 0):
stripecolor = colors.deepskyblue
else:
stripecolor = colors.mintcream
blueorwhiteline = Rect(0, (s-(stripeheight*stripecounter)), width=s*2, height=stripeheight,
fillColor = stripecolor, strokeColor = None, strokeWidth=20)
g.add(blueorwhiteline)
bluebox1 = Rect(0, ((s)-stripeheight*5), width=(stripeheight*5), height=stripeheight*5,
fillColor = colors.deepskyblue, strokeColor = None, strokeWidth=0)
g.add(bluebox1)
whiteline1 = Rect(0, ((s)-stripeheight*3), width=stripeheight*5, height=stripeheight,
fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
g.add(whiteline1)
whiteline2 = Rect((stripeheight*2), ((s)-stripeheight*5), width=stripeheight, height=stripeheight*5,
fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
g.add(whiteline2)
return g
示例10: _Flag_Japan
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def _Flag_Japan(self):
s = _size
g = Group()
w = self._width = s*1.5
g.add(Rect(0,0,w,s,fillColor=colors.mintcream,strokeColor=None, strokeWidth=0))
g.add(Circle(cx=w/2,cy=s/2,r=0.3*w,fillColor=colors.red,strokeColor=None, strokeWidth=0))
return g
示例11: makeSwatchSample
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def makeSwatchSample(self,rowNo, x, y, width, height):
baseStyle = self.lines
styleIdx = rowNo % len(baseStyle)
style = baseStyle[styleIdx]
color = style.strokeColor
y = y+height/2.
if self.joinedLines:
dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None))
L = Line(x,y,x+width,y,strokeColor=color,strokeLineCap=0)
if strokeWidth: L.strokeWidth = strokeWidth
if dash: L.strokeDashArray = dash
else:
L = None
if hasattr(style, 'symbol'):
S = style.symbol
elif hasattr(baseStyle, 'symbol'):
S = baseStyle.symbol
else:
S = None
if S: S = uSymbol2Symbol(S,x+width/2.,y,color)
if S and L:
g = Group()
g.add(L)
g.add(S)
return g
return S or L
示例12: draw
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def draw(self):
self.qr.make()
g = Group()
color = self.barFillColor
border = self.barBorder
width = self.barWidth
height = self.barHeight
x = self.x
y = self.y
g.add(SRect(x, y, width, height, fillColor=None))
moduleCount = self.qr.getModuleCount()
minwh = float(min(width, height))
boxsize = minwh / (moduleCount + border * 2.0)
offsetX = (width - minwh) / 2.0
offsetY = (minwh - height) / 2.0
for r, row in enumerate(self.qr.modules):
row = map(bool, row)
c = 0
for t, tt in itertools.groupby(row):
isDark = t
count = len(list(tt))
if isDark:
x = (c + border) * boxsize
y = (r + border + 1) * boxsize
s = SRect(offsetX + x, offsetY + height - y, count * boxsize, boxsize)
g.add(s)
c += count
return g
示例13: convertPolyline
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def convertPolyline(self, node):
getAttr = node.getAttribute
points = getAttr("points")
points = points.replace(',', ' ')
points = points.split()
points = list(map(self.attrConverter.convertLength, points))
if len(points) % 2 != 0 or len(points) == 0:
# Odd number of coordinates or no coordinates, invalid polyline
return None
polyline = PolyLine(points)
self.applyStyleOnShape(polyline, node)
has_fill = self.attrConverter.findAttr(node, 'fill') not in ('', 'none')
if has_fill:
# ReportLab doesn't fill polylines, so we are creating a polygon
# polygon copy of the polyline, but without stroke.
group = Group()
polygon = Polygon(points)
self.applyStyleOnShape(polygon, node)
polygon.strokeColor = None
group.add(polygon)
group.add(polyline)
return group
return polyline
示例14: draw
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def draw(self):
fillColor = self.fillColor
strokeColor = self.strokeColor
g = Group()
bg = self.background
bd = self.border
bdw = self.borderWidth
shadow = self.shadow
x, y = self.x, self.y
if bg:
if shadow is not None and 0<=shadow<1:
shadow = Color(bg.red*shadow,bg.green*shadow,bg.blue*shadow)
self._paintLogo(g,dy=-2.5, dx=2,fillColor=shadow)
self._paintLogo(g,fillColor=fillColor,strokeColor=strokeColor)
g.skew(kx=self.skewX, ky=self.skewY)
g.shift(self._dx,self._dy)
G = Group()
G.add(g)
_w, _h = 130, 86
w, h = self.width, self.height
if bg or (bd and bdw):
G.insert(0,Rect(0,0,_w,_h,fillColor=bg,strokeColor=bd,strokeWidth=bdw))
if w!=_w or h!=_h: G.scale(w/float(_w),h/float(_h))
angle = self.angle
if self.angle:
w, h = w/2., h/2.
G.shift(-w,-h)
G.rotate(angle)
G.shift(w,h)
G.shift(x,y)
return G
示例15: renderUse
# 需要导入模块: from reportlab.graphics.shapes import Group [as 别名]
# 或者: from reportlab.graphics.shapes.Group import add [as 别名]
def renderUse(self, node, group=None, clipping=None):
if group is None:
group = Group()
xlink_href = node.attrib.get('{http://www.w3.org/1999/xlink}href')
if not xlink_href:
return
if xlink_href[1:] not in self.definitions:
# The missing definition should appear later in the file
self.waiting_use_nodes[xlink_href[1:]].append((node, group))
return group
if clipping:
group.add(clipping)
if len(node.getchildren()) == 0:
# Append a copy of the referenced node as the <use> child (if not already done)
node.append(copy.deepcopy(self.definitions[xlink_href[1:]]))
self.renderNode(node.getchildren()[-1], parent=group)
getAttr = node.getAttribute
transform = getAttr("transform")
x, y = map(getAttr, ("x", "y"))
if x or y:
transform += " translate(%s, %s)" % (x or '0', y or '0')
if transform:
self.shape_converter.applyTransformOnGroup(transform, group)
return group