Python compares the display effects of the same character in different fonts, and python Fonts
In the openSUSE Chinese Forum, someone asked why the "charming" word "in his input method was displayed as" female "+" Yuan 」. I suspect it is a font problem, so I wrote a script using the python-fontconfig written by my friend and Pillow (a fork of PIL) When I was idle, use all fonts on the system that contain the word "yellow" to display the text and see which fonts are faulty.
(Updated) the script is as follows:
For Google Chrome/Chromium users, Note: If the copied Code contains uninterrupted spaces (0xa0), replace them manually.
#! /Usr/bin/env python3
# Vim: fileencoding = UTF-8
From PIL import Image, ImageDraw, ImageFont
Import fontconfig
Ch = 'hangzhou'
Def get_fonts ():
Ret = []
For f in fontconfig. query ():
F = fontconfig. FcFont (f)
If f. has_char (ch ):
Ret. append (f. file, f. bestname ))
Return ret
W, h = 800,200 00
Image = Image. new ('rgb ', (w, h), 'white ')
Draw = ImageDraw. Draw (image)
Pos = 0
W = 0
Strs = ch
For fontfile, fontname in get_fonts ():
Font = ImageFont. truetype (fontfile, 24)
S = '% s: % s' % (fontname, strs)
Font_width, font_height = font. getsize (s)
W = max (font_width, w ))
Draw. text (10, pos), s, font = font, fill = 'black ')
Pos + = font_height
H = pos
Image = image. crop (0, 0, w + 10, h ))
Image.save('fonts.png ')
Search for the body, and then paste it to the fonts.png file in the current directory. The process of searching for fonts takes a long time and you have to wait patiently. The final result is as follows:
Here I am, wenquanyi micron black, founder Wei Bei ref, and a Droid Sans Fallback font in which the "symbol" is incorrect. (I have three font files named "Droid Sans Fallback"...)>