本文整理汇总了Python中reportlab.graphics.shapes.Group类的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Flag_Japan
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
示例2: makeSwatchSample
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
示例3: draw
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
示例4: renderUse
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
示例5: convertPolyline
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
示例6: makeSwatchSample
def makeSwatchSample(self,rowNo, x, y, width, height):
styleCount = len(self.lines)
styleIdx = rowNo % styleCount
rowColor = self.lines[styleIdx].strokeColor
if self.joinedLines:
dash = getattr(self.lines[styleIdx], 'strokeDashArray', getattr(self.lines,'strokeDashArray',None))
strokeWidth= getattr(self.lines[styleIdx], 'strokeWidth', getattr(self.lines[styleIdx], 'strokeWidth',None))
L = Line(x,y,x+width,y+height,strokeColor=rowColor,strokeLineCap=0)
if strokeWidth: L.strokeWidth = strokeWidth
if dash: L.strokeDashArray = dash
else:
L = None
if hasattr(self.lines[styleIdx], 'symbol'):
S = self.lines[styleIdx].symbol
elif hasattr(self.lines, 'symbol'):
S = self.lines.symbol
else:
S = None
if S: S = uSymbol2Symbol(S,x+width/2.,y+height/2.,rowColor)
if S and L:
g = Group()
g.add(S)
g.add(L)
return g
return S or L
示例7: makeInnerTiles
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: rotatedEnclosingRect
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
示例9: getTalkRect
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
示例10: ttf_ocr
def ttf_ocr(font, key=None):
gs = font.getGlyphSet()
keys = [key for key in gs.keys() if key.startswith("uni")] if key is None else [key]
c = []
for i, key in enumerate(keys):
if key not in gs:
logger.info("No this key: %s" % key)
c.append("")
continue
pen = ReportLabPen(gs, Path(fillColor=colors.black, strokeWidth=0.01))
g = gs[key]
g.draw(pen)
w, h = 50, 50
g = Group(pen.path)
g.translate(10, 10)
g.scale(0.02, 0.02)
d = Drawing(w, h)
d.add(g)
renderPM.drawToFile(d, png_file.name, fmt="PNG")
result = os.popen("tesseract %s stdout -l chi_sim -psm 5" % png_file.name).read().strip().decode("utf-8",
"ignore")
if len(result) != 1:
result = os.popen("tesseract %s stdout -l chi_sim -psm 8" % png_file.name).read().strip().decode("utf-8",
"ignore")
logger.info("key: %s, result: %s" % (key, result))
c.append(result)
if key is not None:
return c[0]
return c
示例11: _Flag_Spain
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
示例12: makeSwatchSample
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
示例13: makeCircularString
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
示例14: annotation
def annotation(self,xScale,yScale):
x = xScale(xv)
y = yScale(yv)
g = Group()
xA = xScale.im_self #the x axis
g.add(Line(xA._x,y,xA._x+xA._length,y,strokeColor=strokeColor,strokeWidth=strokeWidth))
yA = yScale.im_self #the y axis
g.add(Line(x,yA._y,x,yA._y+yA._length,strokeColor=strokeColor,strokeWidth=strokeWidth))
return g
示例15: _Flag_Cuba
def _Flag_Cuba(self):
s = _size
g = Group()
for i in range(5):
stripe = Rect(0, i*s/5, width=s*2, height=s/5,
fillColor = [colors.darkblue, colors.mintcream][i%2],
strokeColor = None,
strokeWidth=0)
g.add(stripe)
redwedge = Polygon(points = [ 0, 0, 4*s/5, (s/2), 0, s],
fillColor = colors.red, strokeColor = None, strokeWidth=0)
g.add(redwedge)
star = Star()
star.x = 2.5*s/10
star.y = s/2
star.size = 3*s/10
star.fillColor = colors.white
g.add(star)
box = Rect(0, 0, s*2, s,
fillColor = None,
strokeColor = colors.black,
strokeWidth=0)
g.add(box)
return g