├── JiZhi-bitmap-8.bdf ├── LICENSE ├── README.md ├── generate.py ├── generate_pillow.py ├── guanzhi.ttf ├── requirements.txt ├── test1.png ├── test2.png ├── test3.png └── 观致 8×8 像素字体.ttf /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Angelic47 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FontChinese7x7 2 | 3 | 上古神器 III : 7x7像素点阵中文字体 4 | 5 | 想要在低分辨率屏幕上显示中文, 却发现中文字体实在是太大? 6 | 7 | 找了全网发现字体库最小也只有12x12? 8 | 9 | 甚至是好不容易找到了一个8x8字体, 结果发现字体收费且明确说明不得以任何形式嵌入到软件当中? 10 | 11 | 那就让这个项目来解决你的问题! 12 | 13 | # 这是什么? 14 | 15 | 这个项目提供了一个叫“观致”的字体, 该字体存在于早期年代的点阵屏当中, 现已非常罕见. 16 | 17 | 该字体内置了7x7的中文点阵字体, 能够让中文字体在7x7下依然有着良好的可读性. 18 | 19 | 其他内容不需要多说想必大家也都知道了. 20 | 21 | 例如可以拿来作为报错信息: 22 | 23 | ![7x7报错测试](test1.png) 24 | 25 | 又例如可以拿来作为提示信息: 26 | 27 | ![7x7提示测试](test2.png) 28 | 29 | 更甚至是可以拿来做RPG游戏的相关文本内容: 30 | 31 | ![7x7游戏内容测试](test3.png) 32 | 33 | # 安装 34 | 35 | 安装`观致 8×8 像素字体.ttf`文件,或者`JiZhi-bitmap-8.bdf`文件(Windows 可能不支持 bdf 文件)即可直接使用。 36 | 37 | # 关于“观致”字体版权 38 | 39 | 这是一款非常老的字体, 预估已经有15-20多岁的年龄了. 40 | 41 | 因为这个字体实在是太老, 互联网上与该字体相关的页面均在2005-2010年左右, 几乎全部404, 具体的版权信息难以知晓. 42 | 43 | 但根据字体文件中的属性信息, 该字体版权方为“北京中易中标电子信息技术有限公司(Beijing Zhongyi Electronic Co., Ltd.)”, 并宣称“这是日文字体Misaki基础上补充的”. 44 | 45 | 经过查证后甚至发现原版的Misaki字体竟是一款开源字体. 46 | 47 | 本人已无渠道追溯这款“观致”字体文件的原始出处, 因此处于学习和研究的目的, 将该字体文件公开在了这里, 目的是避免这个字体消失在互联网上. 48 | 49 | 若该项目存在字体侵权, 希望版权方能够主动联系我, 我会在第一时间内将该项目撤下. 50 | 51 | # 特殊提示 52 | 53 | 项目中的脚本使用了Python27+Windows GDI对字体进行7x7取模. 54 | 55 | ~~因为Windows10下微软对GDI有抗锯齿, 且本人并不知道如何关掉这个功能, 因此该脚本并不能完美兼容Windows10及以上版本操作系统.~~ 56 | 57 | ~~建议使用Windows7虚拟机来运行该脚本以达到最好的取模效果.~~ 58 | 59 | ~~当然, 如果你知道如何解决这个问题, 那么非常欢迎提出一个Pull Requests!~~ 60 | 61 | 这里感谢 [@Dreagonmon](https://github.com/Dreagonmon) 提供了一个使用Pillow的取模脚本generate_pillow.py, 能够在Windows10上正常取模而不受到GDI的抗锯齿干扰. 62 | 63 | 也要感谢 [@LXYan2333](https://github.com/LXYan2333) 重新将该字体文件矢量化成了像素风格, 文件名为JiZhi-bitmap-8.bdf, 方便大家直接使用. 64 | 65 | # 项目版权 66 | 67 | 除字体文件版权无法知晓外, 代码均为MIT License. 68 | 69 | 原字体文件的作者依旧保留对该字体文件的版权. 70 | -------------------------------------------------------------------------------- /generate.py: -------------------------------------------------------------------------------- 1 | #coding: utf-8 2 | 3 | import ctypes 4 | import struct 5 | import win32con 6 | import win32gui 7 | import win32ui 8 | 9 | from PIL import Image 10 | 11 | 12 | def RGB(r, g, b): 13 | return r | (g << 8) | (b << 16) 14 | 15 | def native_bmp_to_pil(hdc, bitmap_handle, width, height): 16 | bmpheader = struct.pack("LHHHH", struct.calcsize("LHHHH"), 17 | width, height, 1, 24) #w,h, planes=1, bitcount) 18 | c_bmpheader = ctypes.c_buffer(bmpheader) 19 | 20 | #3 bytes per pixel, pad lines to 4 bytes 21 | c_bits = ctypes.c_buffer(" " * (height * ((width*3 + 3) & -4))) 22 | 23 | res = ctypes.windll.gdi32.GetDIBits( 24 | hdc, bitmap_handle, 0, height, 25 | c_bits, c_bmpheader, 26 | win32con.DIB_RGB_COLORS) 27 | if not res: 28 | raise IOError("native_bmp_to_pil failed: GetDIBits") 29 | 30 | im = Image.frombuffer( 31 | "RGB", (width, height), c_bits, 32 | "raw", "BGR", (width*3 + 3) & -4, -1) 33 | return im 34 | 35 | 36 | class Win32Font: 37 | def __init__(self, name, height, weight=win32con.FW_NORMAL, 38 | italic=False, underline=False): 39 | self.font = win32ui.CreateFont({ 40 | 'name': name, 'height': height, 41 | 'weight': weight, 'italic': italic, 'underline': underline}) 42 | 43 | #create a compatible DC we can use to draw: 44 | self.desktopHwnd = win32gui.GetDesktopWindow() 45 | self.desktopDC = win32gui.GetWindowDC(self.desktopHwnd) 46 | self.mfcDC = win32ui.CreateDCFromHandle(self.desktopDC) 47 | self.drawDC = self.mfcDC.CreateCompatibleDC() 48 | 49 | #initialize it 50 | self.drawDC.SelectObject(self.font) 51 | 52 | def renderText(self, text): 53 | text = text.encode('gb2312') 54 | """render text to a PIL image using the windows API.""" 55 | self.drawDC.SetTextColor(RGB(0,0,0)) 56 | 57 | #create the compatible bitmap: 58 | w,h = self.drawDC.GetTextExtent(text) 59 | 60 | saveBitMap = win32ui.CreateBitmap() 61 | saveBitMap.CreateCompatibleBitmap(self.mfcDC, w, h) 62 | self.drawDC.SelectObject(saveBitMap) 63 | 64 | #draw it 65 | self.drawDC.DrawText(text, (0, 0, w, h), win32con.DT_LEFT) 66 | 67 | #convert to PIL image 68 | im = native_bmp_to_pil(self.drawDC.GetSafeHdc(), saveBitMap.GetHandle(), w, h) 69 | 70 | #clean-up 71 | win32gui.DeleteObject(saveBitMap.GetHandle()) 72 | 73 | return im 74 | 75 | def __del__(self): 76 | self.mfcDC.DeleteDC() 77 | self.drawDC.DeleteDC() 78 | win32gui.ReleaseDC(self.desktopHwnd, self.desktopDC) 79 | win32gui.DeleteObject(self.font.GetSafeHandle()) 80 | 81 | def __del__(self): 82 | win32gui.DeleteObject(self.font.GetSafeHandle()) 83 | 84 | f = Win32Font("JiZhi", 8) 85 | im = f.renderText("兔兔伯爵, 出击! - 向敌人扔出一个兔兔伯爵玩偶, 并在10秒后爆炸, 对周围的敌人造成火焰伤害.".decode("utf-8")) 86 | im.save("hope.png") 87 | -------------------------------------------------------------------------------- /generate_pillow.py: -------------------------------------------------------------------------------- 1 | #coding: utf-8 2 | 3 | from PIL import Image, ImageDraw, ImageFont 4 | from typing import Tuple 5 | 6 | class PILFont(): 7 | def __init__(self, font_path: str, font_size: int) -> None: 8 | self.__font = ImageFont.FreeTypeFont(font_path, font_size) 9 | 10 | def render_text(self, text: str, offset: Tuple[int, int] = (0, 0)) -> Image: 11 | ''' 绘制文本图片 12 | > text: 待绘制文本 13 | > offset: 偏移量 14 | ''' 15 | __left, __top, right, bottom = self.__font.getbbox(text) 16 | img = Image.new("1", (right, bottom), color=255) 17 | img_draw = ImageDraw.Draw(img) 18 | img_draw.text(offset, text, fill=0, font=self.__font, spacing=0) 19 | return img 20 | 21 | f = PILFont("guanzhi.ttf", 8) 22 | # 渲染文本 23 | im = f.render_text("兔兔伯爵, 出击! - 向敌人扔出一个兔兔伯爵玩偶, 并在10秒后爆炸, 对周围的敌人造成火焰伤害.") 24 | im.save("hope.png") 25 | # 渲染单个文字,可用于生成字体 26 | # im = f.render_text("龙", (0, -1)) 27 | # im.show() 28 | -------------------------------------------------------------------------------- /guanzhi.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Angelic47/FontChinese7x7/e1371d15349fe1cb4ed2c8e1472ea8187fa72843/guanzhi.ttf -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pillow~=8.2.0 2 | -------------------------------------------------------------------------------- /test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Angelic47/FontChinese7x7/e1371d15349fe1cb4ed2c8e1472ea8187fa72843/test1.png -------------------------------------------------------------------------------- /test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Angelic47/FontChinese7x7/e1371d15349fe1cb4ed2c8e1472ea8187fa72843/test2.png -------------------------------------------------------------------------------- /test3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Angelic47/FontChinese7x7/e1371d15349fe1cb4ed2c8e1472ea8187fa72843/test3.png -------------------------------------------------------------------------------- /观致 8×8 像素字体.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Angelic47/FontChinese7x7/e1371d15349fe1cb4ed2c8e1472ea8187fa72843/观致 8×8 像素字体.ttf --------------------------------------------------------------------------------