本文整理汇总了Python中Polygon.Polygon.boundingBox方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.boundingBox方法的具体用法?Python Polygon.boundingBox怎么用?Python Polygon.boundingBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.boundingBox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: text
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import boundingBox [as 别名]
def text(pos=(0,0), text="", font=None, height=1.0, align='left', spacing=0.03, rotate=0.0,
scale=1.0, xscale=1.0, yscale=1.0, thickness=None, vertical_spacing=None,
info=False):
# If info == True, the caller wants the additional info such as upper-left, etc.
# In this case we return an instance of the class text_info, with the Polygon as
# an attribute, text_info.Polygon. The main client of this extra info is the text object.
if thickness is not None:
raise AttributeError("Thickness is not allowed in a text shape.")
if scale != 1.0: xscale = yscale = scale
lines = text.split('\n')
while lines[-1] == '\n': # strip off trailing newlines
lines = lines[:-1]
if font is None:
font = "serif"
font = describe.openFont(findFont(font))
try:
fonth = glyphquery.charHeight(font)
except:
fonth = 1000
if fonth == 0: fonth = 1000
try:
desc = glyphquery.charDescent(font) # charDescent may not be present
fontheight = fonth+desc
fontscale = 1./fontheight
descent = fontscale*desc
except:
descent = -0.3*height # approximate value
fontheight = 0.7*fonth
fontscale = 1.3/fontheight
if vertical_spacing is None:
vertical_spacing = height*fontscale*glyphquery.lineHeight(font)
excludef_list = [("ITCEdscr")]
excludec_list = [("FRSCRIPT", "A"), ("jokerman", "O"),
("vivaldii", "O"), ("vivaldii", "Q"),
("vivaldii", "R")]
ptext = []
widths = []
width = 0.0
starts = []
start = 0.0
for line in range(len(lines)):
ptext.append(Polygon())
bb = 0
for newchar in lines[line]:
if newchar == " ":
try:
if a:
bx = a.boundingBox()
bba = bx[1]-bx[0]
bba = min(bba, 700)
bb += bba
except:
pass
continue
n = glyphquery.glyphName(font, newchar)
if n == ".notdef":
print("The character '"+newchar+"' is not supported in the font "+font)
continue
g = glyph.Glyph(n)
c = g.calculateContours(font)
contours = []
for contour in c:
contours.append(glyph.decomposeOutline(contour))
if len(contours[-1]) == 0: contours.pop()
for contour in contours:
pp = 0
for i in range(len(contour)-1):
if (contour[i][0] == contour[i+1][0]) and (contour[i][1] == contour[i+1][1]):
contour.pop(i)
pp += 1
if i+pp >= len(contour)-1: break
def lenctr(contour):
totlen = 0
for j in range(len(contour)-1):
totlen += (vis.vector(contour[j])-vis.vector(contour[j+1])).mag
return totlen
lc = len(contours)
if lc >= 4:
mli = 0
maxl = 0
lengths = []
for i in range(len(contours)):
totlen = lenctr(contours[i])
lengths.append((totlen,i))
if totlen > maxl:
mli = i
#.........这里部分代码省略.........