| 79 | |
| 80 | |
| 81 | def create_font(txt, sz, font_path='./doc/fonts/simfang.ttf'): |
| 82 | font_size = int(sz[1] * 0.99) |
| 83 | font = ImageFont.truetype(font_path, font_size, encoding='utf-8') |
| 84 | if int(PIL.__version__.split('.')[0]) < 10: |
| 85 | length = font.getsize(txt)[0] |
| 86 | else: |
| 87 | length = font.getlength(txt) |
| 88 | |
| 89 | if length > sz[0]: |
| 90 | font_size = int(font_size * sz[0] / length) |
| 91 | font = ImageFont.truetype(font_path, font_size, encoding='utf-8') |
| 92 | return font |
| 93 | |
| 94 | |
| 95 | def draw_box_txt_fine(img_size, box, txt, font_path='./doc/fonts/simfang.ttf'): |