def _reset(self): mainlog.debug("frame reset") r = Frame._reset(self) self.top_of_frame = True return r
def _draw_front_frame(self, canvas, width, height): front_frame = Frame( self.border_front[Border.LEFT], self.border_front[Border.BOTTOM], width - self.border_front[Border.LEFT] - self.border_front[Border.RIGHT], height - self.border_front[Border.TOP] - self.border_front[Border.BOTTOM], leftPadding=self.TEXT_MARGIN, bottomPadding=self.TEXT_MARGIN, rightPadding=self.TEXT_MARGIN, topPadding=self.TEXT_MARGIN, ) # DEBUG # front_frame.drawBoundary(canvas) title_paragraph = self._get_title_paragraph() # Nasty hack alert! # There is no way to know how big the text will be and Frame only # supports top to bottom layout. This means we have no way of # knowing the maximum image size. # # As a hack to get around this, we have to: # 1. mock out the paragraphs drawOn method # 2. "draw" the paragraph # 3. Calculate how tall it was # 4. Reset the frame and restore the original drawOn def mock(*args, **kwargs): pass original_drawOn = title_paragraph.drawOn title_paragraph.drawOn = mock result = front_frame.add(title_paragraph, canvas) if not result: raise Exception("Failed to draw title in front frame") title_height = (front_frame.y1 + front_frame.height - front_frame._y + self.TEXT_MARGIN) title_paragraph.drawOn = original_drawOn front_frame._reset() available_height = front_frame.height - title_height - self.TEXT_MARGIN * 2 image_width, image_height = get_image_size( self.front_image_path, front_frame.width, available_height, ) elements = [] # Add spacer if image doesn't fully fill frame space = front_frame.height - (image_height + title_height) if space > 0: elements.append(Spacer(front_frame.width, space / 2)) elements.append(Image(self.front_image_path, image_width, image_height)) # Add second spacer if space > 0: elements.append(Spacer(front_frame.width, space / 2)) elements.append(title_paragraph) front_frame.addFromList(elements, canvas)