def test(self): outPDF = "test_compare.pdf" pageSize = pagesizes.portrait(pagesizes.A4) canv = Canvas(outPDF, pagesize=pageSize) # common variables W, H = 5 * cm, 20 * cm kifMode = "shrink" # overflow/truncate/shrink/error # hyphenated column p = HyParagraph(testdata, sth) story = [p] frame = KeepInFrame(W, H, story, mode=kifMode) w, h = frame.wrapOn(canv, W, H) x, y = 100, 100 frame.drawOn(canv, x, y + (H - h)) canv.setLineWidth(2) canv.setStrokeColor(black) canv.circle(x, y, 10) canv.setStrokeColor(red) canv.rect(x, y, W, H) canv.setLineWidth(1) canv.setStrokeColor(blue) canv.rect(x, y + (H - h), w, h) # non-hyphenated column p = Paragraph(testdata, st) story = [p] frame = KeepInFrame(W, H, story, mode=kifMode) w, h = frame.wrapOn(canv, W, H) x, y = 300, 100 frame.drawOn(canv, x, y + (H - h)) canv.setLineWidth(2) canv.setStrokeColor(black) canv.circle(x, y, 10) canv.setStrokeColor(red) canv.rect(x, y, W, H) canv.setLineWidth(1) canv.setStrokeColor(blue) canv.rect(x, y + (H - h), w, h) canv.showPage() canv.save()
def draw(self): self.canv.saveState() XP, YP = self.xp, self.yp self.resize_images(self.text) story = self.text W, H = (self.width - self.lm - self.rm), self.yp - self.y0 - self.bm # possible modes: shrink, truncate, overflow, error frame = KeepInFrame(W, H, story, mode="shrink") w, h = frame.wrapOn(self.canv, W, H) frame.drawOn(self.canv, self.xp, self.yp - h) self.addSpace(0, -h - 5 * mm) self.canv.restoreState()