(txt, sz, font_path="./doc/fonts/simfang.ttf")
| 83 | |
| 84 | |
| 85 | def create_font(txt, sz, font_path="./doc/fonts/simfang.ttf"): |
| 86 | font_size = int(sz[1] * 0.99) |
| 87 | font = ImageFont.truetype(font_path, font_size, encoding="utf-8") |
| 88 | length = font.getlength(txt) |
| 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 str_count(s): |