| 464 | self._draw.rectangle(size, outline=color, fill=color) |
| 465 | |
| 466 | def _paint_text(self, xpos, ypos): |
| 467 | assert ImageFont is not None |
| 468 | |
| 469 | # check option to override self.text with self.human (barcode as |
| 470 | # human readable data, can be used to print own formats) |
| 471 | barcodetext = self.human if self.human != "" else self.text |
| 472 | |
| 473 | font_size = int(mm2px(pt2mm(self.font_size), self.dpi)) |
| 474 | if font_size <= 0: |
| 475 | return |
| 476 | font = ImageFont.truetype(self.font_path, font_size) |
| 477 | for subtext in barcodetext.split("\n"): |
| 478 | pos = ( |
| 479 | mm2px(xpos, self.dpi), |
| 480 | mm2px(ypos, self.dpi), |
| 481 | ) |
| 482 | self._draw.text( |
| 483 | pos, subtext, font=font, fill=self.foreground, anchor="md" |
| 484 | ) |
| 485 | ypos += pt2mm(self.font_size) / 2 + self.text_line_distance |
| 486 | |
| 487 | def _finish(self) -> T_Image: |
| 488 | return self._image |