118 lines
2.5 KiB
Plaintext
118 lines
2.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"from PIL import Image, ImageDraw, ImageFont"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"font = ImageFont.truetype(\"/usr/share/fonts/wenquanyi/wqy-microhei/wqy-microhei.ttc\", 16)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"multiplier = 2 ** np.arange(7, -1, -1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQAAAAA3iMLMAAAAMklEQVR4nGNgYGBgYGCw/8PAyMDEAEN1/1iaGJkYGBiZbZmYFRh5VBglWJgiPjEwMAAAcxcFSuzLPhQAAAAASUVORK5CYII=\n",
|
|
"text/plain": [
|
|
"<PIL.Image.Image image mode=1 size=16x16 at 0x7EFFD80EEC18>"
|
|
]
|
|
},
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"img = Image.new('1', (16, 16), 0)\n",
|
|
"s = '天'\n",
|
|
"draw = ImageDraw.Draw(img)\n",
|
|
"draw.text((0, 0), s, 255, font=font)\n",
|
|
"img"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"f = open('chinese.c', 'w')\n",
|
|
"for i in range(0x4e00, 0x9fa5):\n",
|
|
" img = Image.new('1', (16, 16), 0)\n",
|
|
" s = chr(i)\n",
|
|
" draw = ImageDraw.Draw(img)\n",
|
|
" draw.text((0, -4), s, 255, font=font)\n",
|
|
" arr = np.array(img).reshape((-1, 8))\n",
|
|
" for row in arr:\n",
|
|
" f.write('%iu,' % np.sum(row * multiplier))\n",
|
|
" f.write('//%s\\n' % s)\n",
|
|
"f.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"653.15625"
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(0x9fa5-0x4e00) * 16 * 16 / 8 / 1024"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.7.1"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|