def event_occurred(self, event: Event) -> None: if isinstance(event, TextRenderEvent): assert isinstance(event, TextRenderEvent) space = Rectangle( event.get_baseline().x0, event.get_baseline().y0, event.get_baseline().x1, Decimal(12), ) # TODO: height self._mark_as_unavailable(space)
def event_occurred(self, event: Event): if isinstance(event, ChunkOfTextRenderEvent): assert isinstance(event, ChunkOfTextRenderEvent) self.measurands.append( { "text": event.text, "x0": float(event.get_bounding_box().x), "x1": float( event.get_bounding_box().x + event.get_bounding_box().width ), "y": float(event.get_baseline().y), "length": float(event.get_baseline().width), } )
def event_occurred(self, event: Event): if isinstance(event, TextRenderEvent): assert isinstance(event, TextRenderEvent) self.measurands.append({ "text": event.get_text(), "x0": float(event.get_baseline().x0), "x1": float(event.get_baseline().x1), "y": float(event.get_baseline().y0), "length": float(event.get_baseline().length()), })
def _event_occurred(self, event: Event) -> None: # BeginPageEvent if isinstance(event, BeginPageEvent): self.page_nr += Decimal(1) self.page = event.get_page() self._begin_page( self.page_nr, self.page.get_page_info().get_width() or self.default_page_width, self.page.get_page_info().get_height() or self.default_page_height, ) # ImageRenderEvent if isinstance(event, ImageRenderEvent): assert self.page is not None self._render_image( self.page_nr, self.page.get_page_info().get_width() or self.default_page_width, self.page.get_page_info().get_height() or self.default_page_height, event.get_x(), event.get_y(), event.get_width(), event.get_height(), event.get_image(), ) # ChunkOfTextRenderEvent if isinstance(event, ChunkOfTextRenderEvent): assert self.page is not None font_name_as_str = "Helvetica" if event.font.get_font_name(): font_name_as_str = str(event.font.get_font_name()) self._render_text( self.page_nr, self.page.get_page_info().get_width() or self.default_page_width, self.page.get_page_info().get_height() or self.default_page_height, event.get_baseline().get_x(), event.get_baseline().get_y(), event.font_color, event.font_size, font_name_as_str.replace("#20", " ").replace( ",Bold", "").replace(",bold", "").replace("Bold", "").replace( "bold", "").replace(",Italic", "").replace( ",italic", "").replace("Italic", "").replace("italic", ""), "BOLD" in font_name_as_str.upper(), "ITALIC" in font_name_as_str.upper(), event.text, )