BDF (Glyph Bitmap Distribution Format) Bitmap Font File Parser (Python).
BdfParserObject = BdfParser(<FONT_FILE_PATH>)
BdfParserObject.{getCharBmpByUnicode|getCharHexByUnicode|getCharHexByUnicode|getGlyphInfo}(<UNICODE_DECIMAL>)
(see also example.py)
Import library and instantiation:
import bdfparser as bp
bpo = bp.BdfParser('example_fonts/bdf/SimSun-14.bdf')
Get binary representation string of bitmap of the character "的":
bpo.getCharBmpByUnicode(30340)
Get hex representation string of bitmap of the character "的":
bpo.getCharHexByUnicode(30340)
Get hex representation string in bytes of bitmap of the character "的":
bpo.getCharHexByUnicode(30340).hex()
Get glyph information:
bpo.getGlyphInfo(30340)
The above script returns:
{'dwx0': 14, 'bbW': 12, 'bbH': 14, 'bbXOff': 1, 'bbYOff': -2, 'bitmap': '2100\n2100\n41F0\nFA10\n8C10\n8810\n8910\nF890\n8890\n8810\n8810\n8810\nF810\n8860', 'outputW': 14, 'outputH': 15, 'shadowedOutputW': 15, 'shadowedOutputH': 16, 'glowedOutputW': 16, 'glowedOutputH': 17}
Get binary representation of bitmap of the character " ̄"
bpo.getCharBmpByUnicode(65507)
Get binary representation of bitmap of the character "©" -- "©" does not exist in some font, and does not exist in GBK, therefore it throws an error:
bpo.getCharBmpByUnicode(169)
Get the declared font name:
bpo.getFontName()
- Example .bdf fonts:
- GNU Unifont (Wikipedia article; Homepage): Unicode font (intended to support "all" common languages)
- M+ FONTS (Wikipedia article; Homepage): Japanese font
- HanWangYanKai 王漢宗自由字型顏體 (Chinese Wikipedia article; download .ttf): Traditional Chinese font
- See also some typical but non-free, fair-used Chinese fonts in another repo
- otf2bdf: OpenType to BDF Converter. Just an archive. Not written by me.
FNT Generator: Might and Magic 6 7 8 and Heroes 3 font File Generator in Python. Another project of mine
- Python code is written by me (Tom CHEN) and is released under the MIT License.
- otf2bdf: see its page.
- Example .bdf fonts:
- GNU Unifont: GNU General Public License v2, by Roman Czyborra, Paul Hardy, part of the GNU Project
- M+ FONTS: a free license, designed by Coji Morishita
- HanWangYanKai 王漢宗自由字型顏體: GNU General Public License v2, by 王漢宗
- Other fonts are proprietary, and are used non-commercially and fairly