【发布时间】:2016-05-03 13:05:35
【问题描述】:
我正在尝试为 ReportLab 编写一个 Flowable,它需要能够拆分。根据我对文档的理解,我需要定义一个函数 split(self, aW, aH) 来拆分可流动的。但是,我遇到了以下我无法解决的错误。
一个简单的Flowable:
class MPGrid (Flowable):
def __init__(self, height=1*cm, width=None):
self.height = height
self.width = None
def wrap(self, aW, aH):
self.width = aW
return (aW, self.height)
def split(self, aW, aH):
if aH >= self.height:
return [self]
else:
return [MPGrid(aH, aW), MPGrid(self.height - aH, None)]
def draw(self):
if not self.width:
from reportlab.platypus.doctemplate import LayoutError
raise LayoutError('No Width Defined')
c = self.canv
c.saveState()
c.rect(0, 0, self.width, self.height)
c.restoreState()
在文档中使用并需要拆分时,会产生以下错误:
reportlab.platypus.doctemplate.LayoutError: Splitting error(n==2) on page 4 in
<MPGrid at 0x102051c68 frame=col1>...
S[0]=<MPGrid at 0x102043ef0 frame=col1>...
这个flowable应该是固定高度的,如果对于可用高度来说太大了,就拆分消耗掉这个高度,然后在下一帧提醒固定高度。
我做错了什么导致这个不太有用的错误?
【问题讨论】: