本文整理汇总了Python中reportlab.graphics.shapes.String方法的典型用法代码示例。如果您正苦于以下问题:Python shapes.String方法的具体用法?Python shapes.String怎么用?Python shapes.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.shapes
的用法示例。
在下文中一共展示了shapes.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_human_readable
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def _add_human_readable(self,s,gAdd):
barWidth = self.barWidth
fontSize = self.fontSize
textColor = self.textColor
fontName = self.fontName
fth = fontSize*1.2
# draw the num below the line.
c = s[0]
w = stringWidth(c,fontName,fontSize)
x = self.x+barWidth*(self._lquiet-8)
y = self.y + 0.2*fth
gAdd(String(x,y,c,fontName=fontName,fontSize=fontSize,fillColor=textColor))
x = self.x + (33-9+self._lquiet)*barWidth
c = s[1:7]
gAdd(String(x,y,c,fontName=fontName,fontSize=fontSize,fillColor=textColor,textAnchor='middle'))
x += 47*barWidth
c = s[7:]
gAdd(String(x,y,c,fontName=fontName,fontSize=fontSize,fillColor=textColor,textAnchor='middle'))
示例2: demo
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def demo(self):
D = Drawing(200, 100)
name = self.availableFlagNames()
import time
name = name[int(time.time()) % len(name)]
fx = Flag()
fx.kind = name
fx.x = 0
fx.y = 0
D.add(fx)
labelFontSize = 10
D.add(String(fx.x+(fx.size/2.0),(fx.y-(1.2*labelFontSize)),
name, fillColor=colors.black, textAnchor='middle',
fontSize=labelFontSize))
labelFontSize = int(fx.size/4.0)
D.add(String(fx.x+(fx.size),(fx.y+((fx.size/2.0))),
"SAMPLE", fillColor=colors.gold, textAnchor='middle',
fontSize=labelFontSize, fontName="Helvetica-Bold"))
return D
示例3: draw
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def draw(self):
self.computeSize()
g = Group()
# time column
g.add(Rect(self.x, self.y, self._colWidths[0], self.height - self.trackRowHeight, fillColor=colors.cornsilk))
# track headers
x = self.x + self._colWidths[0]
y = self.y + self.height - self.trackRowHeight
for trk in range(self._trackCount):
wid = self._colWidths[trk+1]
r = Rect(x, y, wid, self.trackRowHeight, fillColor=colors.yellow)
s = String(x + 0.5*wid, y, 'Track %d' % trk, align='middle')
g.add(r)
g.add(s)
x = x + wid
for talk in self._talksVisible:
(title, speaker, trackId, day, start, duration) = talk
r = self.getTalkRect(start, duration, trackId, title + '\n' + speaker)
g.add(r)
return g
示例4: add_lineChart
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def add_lineChart(self, title, data, size=(PAGE_WIDTH-100, 300)):
'''
???????
:param title: ?????
:param data: ?????
'''
__chart_width, __chart_heigh = size[0], size[1]
__draw = Drawing(__chart_width, __chart_heigh)
__draw.add(String(20, __chart_heigh-10, title, fontName="chsFont",fontSize=18, fillColor=colors.black))
lc = HorizontalLineChart()
lc.x, lc.y = 25, 50
lc.width, lc.height = __chart_width-50, __chart_heigh-100
lc.data = data
lc.joinedLines = 1
lc.valueAxis.valueMin = min(data[0])
lc.valueAxis.valueMax = max(data[0])
valueRange = lc.valueAxis.valueMax - lc.valueAxis.valueMin
lc.valueAxis.valueStep = valueRange / 10.0
__draw.add(lc)
self.__content.append(__draw)
示例5: __init__
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def __init__(self, width=500, height=250, *args, **kw):
Drawing.__init__(self,width,height,*args,**kw)
self.add(HorizontalBarChart(), name='chart')
self.add(String(180,230,'Chart'), name='title')
#set any shapes, fonts, colors you want here. We'll just
#set a title font and place the chart within the drawing
self.chart.x = 60
self.chart.y = 20
self.chart.width = self.width - 70
self.chart.height = self.height - 45
self.chart.valueAxis.valueMin = 0
self.title.fontName = 'Helvetica-Bold'
self.title.fontSize = 12
self.chart.data = [[100,150,200,235]]
示例6: _getText
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def _getText(self, x=0, y=0, color=None):
return String(x,y, self._text, fontName=self._fontName, fontSize=self._fontSize, fillColor=color)
示例7: draw
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def draw(self):
dx = self.width / 16.0
dy = self.height / 16.0
g = Group()
g.add(Rect(self.x, self.y, self.width, self.height,
fillColor=None, strokeColor=colors.black))
for x in range(16):
for y in range(16):
charValue = y * 16 + x
if charValue > 32:
s = String(self.x + x * dx,
self.y + (self.height - y*dy), int2Byte(charValue))
g.add(s)
return g
示例8: __call__
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def __call__(self,legend, g, x, xt, y, width, lWidth):
from reportlab.graphics.shapes import String, Line
fontSize = self.fontSize
fontName = self.fontName
fillColor = self.fillColor
strokeColor = self.strokeColor
strokeWidth = self.strokeWidth
ascent=getFont(fontName).face.ascent/1000.
if ascent==0: ascent=0.718 # default (from helvetica)
ascent *= fontSize
leading = fontSize*1.2
yt = y+self.dy-ascent*1.3
if self.lText and fillColor:
g.add(String(xt,yt,self.lText,
fontName=fontName,
fontSize=fontSize,
fillColor=fillColor,
textAnchor = "start"))
if self.rText:
g.add(String(xt+width,yt,self.rText,
fontName=fontName,
fontSize=fontSize,
fillColor=fillColor,
textAnchor = "end"))
if strokeWidth and strokeColor:
yL = y+self.dly-leading
g.add(Line(x+self.dlx[0],yL,x+self.dlx[1]+lWidth,yL,
strokeColor=strokeColor, strokeWidth=strokeWidth,
strokeDashArray=self.strokeDashArray))
示例9: makeCircularString
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [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
示例10: annotate
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def annotate(self,x,y,text,fontName,fontSize,anchor='middle'):
self._Gadd(String(self.x+x,self.y+y,text,fontName=fontName,fontSize=fontSize,
textAnchor=anchor,fillColor=self.textColor))
示例11: demo
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def demo(self):
D = shapes.Drawing(200, 100)
s = float(self.size)
ob = self.__class__()
ob.x=50
ob.y=0
ob.draw()
D.add(ob)
D.add(shapes.String(ob.x+(s/2),(ob.y-12),
ob.__class__.__name__, fillColor=colors.black, textAnchor='middle',
fontSize=10))
return D
示例12: draw
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def draw(self):
# general widget bits
s = float(self.size) # abbreviate as we will use this a lot
g = shapes.Group()
# stop-sign specific bits
athird=s/3
outerOctagon = shapes.Polygon(points=[self.x+athird, self.y,
self.x, self.y+athird,
self.x, self.y+(athird*2),
self.x+athird, self.y+s,
self.x+(athird*2), self.y+s,
self.x+s, self.y+(athird*2),
self.x+s, self.y+athird,
self.x+(athird*2), self.y],
strokeColor = self.strokeColor,
fillColor = None,
strokeWidth=1)
g.add(outerOctagon)
innerOctagon = shapes.Polygon(points=[self.x+athird+(s/75), self.y+(s/75),
self.x+(s/75), self.y+athird+(s/75),
self.x+(s/75), self.y+(athird*2)-(s/75),
self.x+athird+(s/75), self.y+s-(s/75),
self.x+(athird*2)-(s/75), (self.y+s)-(s/75),
(self.x+s)-(s/75), self.y+(athird*2)-(s/75),
(self.x+s)-(s/75), self.y+athird+(s/75),
self.x+(athird*2)-(s/75), self.y+(s/75)],
strokeColor = None,
fillColor = self.fillColor,
strokeWidth=0)
g.add(innerOctagon)
if self.stopColor:
g.add(shapes.String(self.x+(s*0.5),self.y+(s*0.4),
'STOP', fillColor=self.stopColor, textAnchor='middle',
fontSize=s/3, fontName="Helvetica-Bold"))
return g
示例13: add_linePlotChart
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def add_linePlotChart(self, title, data, size=(PAGE_WIDTH-100, 300)):
__chart_width, __chart_heigh = size[0], size[1]
__draw = Drawing(__chart_width, __chart_heigh)
__draw.add(String(20, __chart_heigh-10, title, fontName="chsFont",fontSize=18, fillColor=colors.black))
#LinePlot????
lp = LinePlot()
lp.x, lp.y = 25, 50
lp.width, lp.height = __chart_width-50, __chart_heigh-100
lp.data = data
lp.joinedLines = 1
#X???
lp.xValueAxis.valueMin = min([x[0] for x in data[0]])
lp.xValueAxis.valueMax = max([x[0] for x in data[0]])
valueRange = lp.xValueAxis.valueMax - lp.xValueAxis.valueMin
lp.xValueAxis.valueStep = valueRange / 10.0
#Y???
yValueMin = min([x[1] for x in data[0]])
yValueMax = max([x[1] for x in data[0]])
yValueRange = yValueMax - yValueMin
if (yValueMin-yValueRange/2) > 0:
lp.yValueAxis.valueMin = yValueMin - yValueRange/2
else:
lp.yValueAxis.valueMin = yValueMin
lp.yValueAxis.valueMax = yValueMax+ 0.01 + yValueRange/3 #+1???y???????????valuseStep?0,???????y??????????
lp.yValueAxis.valueStep = (lp.yValueAxis.valueMax - lp.yValueAxis.valueMin)/10
lp.yValueAxis.visibleGrid = 1
lp.yValueAxis.gridStrokeWidth = 0.5
lp.yValueAxis.gridStrokeColor = colors.gray
__draw.add(lp)
self.__content.append(__draw)
示例14: draw_aux_label
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def draw_aux_label(self, label, width, height, obj):
"""
just fill the label with the text
"""
fontSize = 22
if width > 127:
fontSize = 40
textWidth = stringWidth(obj, self.font, fontSize)
while textWidth > (width - 10):
fontSize *= 0.5
textWidth = stringWidth(obj, self.font, fontSize)
label.add(shapes.String(width/2.0, height-(fontSize+fontSize/5.0), obj, textAnchor="middle", fontSize=fontSize))
示例15: draw_breakout_tail_label
# 需要导入模块: from reportlab.graphics import shapes [as 别名]
# 或者: from reportlab.graphics.shapes import String [as 别名]
def draw_breakout_tail_label(self, label, width, height, obj):
"""
Split the label into 4 quads, calculate the maximum size that the
main center label can be.
"""
topLeft = str(obj[0])
bottomLeft = str(obj[1])
topRight = str(obj[2])
bottomRight = str(obj[3])
middleCenter = str(obj[4])
bottomCenter = str(obj[5])
font = self.font
fillColor = colors.HexColor("#00000")
largeFontSize = 22
smallFontSize = 7
label.add(shapes.String(5, height-smallFontSize, topLeft, fontName=font, fontSize=smallFontSize, fillColor=fillColor))
label.add(shapes.String(2, 2, bottomLeft, fontName=font, fontSize=smallFontSize, fillColor=fillColor))
name_width = stringWidth(topRight, font, smallFontSize)
label.add(shapes.String(width-(name_width+2), height-smallFontSize, topRight, fontName=font, fontSize=smallFontSize, fillColor=fillColor))
name2_width = stringWidth(bottomRight, font, smallFontSize)
label.add(shapes.String(width-(name2_width+2), 2, bottomRight, fontName=font, fontSize=smallFontSize, fillColor=fillColor))
label.add(shapes.String(width/2.0, height-(largeFontSize+largeFontSize/5.0), middleCenter, textAnchor="middle", fontSize=largeFontSize, fillColor=fillColor))
label.add(shapes.String(width/2.0, 2, bottomCenter, textAnchor="middle", fontSize=smallFontSize))