{"id":16200549,"url":"https://github.com/antonoko/chinese-font-for-playdate","last_synced_at":"2025-10-04T01:32:00.716Z","repository":{"id":228140414,"uuid":"773258575","full_name":"Antonoko/Chinese-font-for-playdate","owner":"Antonoko","description":"Create Chinese font or other font asset for Playdate","archived":false,"fork":false,"pushed_at":"2024-06-09T11:49:16.000Z","size":74648,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-12T14:45:49.192Z","etag":null,"topics":["font","playdate"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Antonoko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-17T07:00:08.000Z","updated_at":"2024-10-13T03:51:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"0944bfe4-5148-493e-a1fa-3bba02ef3888","html_url":"https://github.com/Antonoko/Chinese-font-for-playdate","commit_stats":null,"previous_names":["antonoko/chinese-font-for-playdate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antonoko%2FChinese-font-for-playdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antonoko%2FChinese-font-for-playdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antonoko%2FChinese-font-for-playdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antonoko%2FChinese-font-for-playdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antonoko","download_url":"https://codeload.github.com/Antonoko/Chinese-font-for-playdate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235208997,"owners_count":18953003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["font","playdate"],"created_at":"2024-10-10T09:31:27.679Z","updated_at":"2025-10-04T01:31:55.667Z","avatar_url":"https://github.com/Antonoko.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create Chinese font for Playdate\n\n为 Playdate 生成中文字体\n\n![screenshot](https://github.com/Antonoko/Chinese-font-for-playdate/blob/main/__asset__/screenshot.jpg)\n\n\n## 已生成字体\n一些已转换、可直接用在 Playdate 上的字体。前往 [Release](https://github.com/Antonoko/Chinese-font-for-playdate/blob/main/release) 下载。\n- [缝合像素字体 / Fusion Pixel Font](https://github.com/TakWolf/fusion-pixel-font/releases) \n    - fusion-pixel-font-8px-proportional-zh_hans\n    - fusion-pixel-font-10px-proportional-zh_hans\n    - fusion-pixel-font-12px-proportional-zh_hans\n    - fusion-pixel-font-24px-proportional-zh_hans （在 12px 字体上以两倍大小渲染）\n- [LXGW WenKai Screen / 霞鹜文楷屏幕阅读版](https://github.com/lxgw/LxgwWenKai-Screen?tab=readme-ov-file)\n    - LXGWWenKaiGBScreen-24px\n    - LXGWWenKaiGBScreen-24px-anti-aliasing （抗锯齿版本）\n- SourceHanSansCN / 思源黑体\n    - SourceHanSansCN-M-24px\n- SourceHanSerifCN / 思源宋体\n    - SourceHanSerifCN-SemiBold-30px\n- OPPOSans\n    - OPPOSans-M-24px\n- Apple\n    - PingFang-M-24px\n\n\n## 如何转换字体\n1. Clone 仓库到本地: `git clone https://github.com/Antonoko/Chinese-font-for-playdate`\n2. 安装依赖 `pip install -r requirements.txt`\n3. 准备要生成的字体文件（如.ttf），放在 `font_asset` 或其他目录下；\n4. 使用 python jupyter notebook 环境执行 `make_font.ipynb`，填写字体文件路径、生成字号等信息，Run ALL 进行生成；\n5. 执行 `rotate_font_direction.ipynb` 可以 +90°/-90°/180° 旋转字体，以适应为不同方向制作的 Playdate 程序；\n\n\u003e [!TIP]\n\u003e\n\u003e 如果你只需要显示一部分的中文文字，可以自定义 TEXT_TABLE_STR 来覆盖仅会用到的文本，以降低储存与性能开销、同时使所有文字都能正常显示。\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e 欢迎通过 issue/PR 提交你生成的新字体，我们会将它放在 release 文件夹下提供。😉（如有使用 license 也请一并附上）\n\n## 如何使用字体\n根据 [Playdate 文档](https://sdk.play.date/2.4.1/Inside%20Playdate.html#_text) 正常引入使用即可。\n\n```lua\nimport \"CoreLibs/graphics\"\nlocal gfx \u003cconst\u003e = playdate.graphics\nlocal font_12 = gfx.font.new('font/fusion-pixel-font-12px-proportional-zh_hans')\n\nfunction playdate.update()\n    gfx.setFont(font_12)\n    gfx.drawText('你好世界', 2, 2)\nend\n```\n\n## 如何渲染字体\n`playdate.graphics.drawTextInRect` 在渲染中文段落时会存在非正确换行排版的问题，此处提供一个替代函数。\n需要注意的是，由于 lua 对 Unicode 支持较差，因此需要传入的 `text_tbl` 为包含若干独立字符的 table，而非 string。\n```lua\nfunction draw_text_area(text_tbl, lineheight_factor, char_kerning, font, draw_mode, start_x, start_y, width, height)\n    -- example:\n    -- draw_text_area({\"你\",\"好\"}, 1.6, 0, gfx.font.new('font/SourceHanSansCN-M-20px'), playdate.graphics.kDrawModeCopy, 0, 0, 300, 200)\n    --\n    -- return:\n    -- char_offset: how many chars has been drawn\n\n    function _findNextSpaceIndex(tbl, index)\n        if index \u003e= #tbl then\n            return -1\n        end\n        for i = index + 1, #tbl do\n            if tbl[i] == \" \" then\n                if i \u003e 12 then  --max line break char length\n                    return -1\n                else\n                    return i\n                end\n            end\n        end\n        return -1\n    end\n\n    local char_offset = 1\n    local current_x = start_x\n    local current_y = start_y\n    gfx.setFont(font)\n    gfx.setImageDrawMode(draw_mode)\n    local max_zh_char_size = gfx.getTextSize(\"啊\") + char_kerning\n    local lineheight = max_zh_char_size * lineheight_factor\n\n    function _linebreak_offset()\n        current_x = start_x\n        current_y += lineheight\n    end\n\n    for key, char in pairs(text_tbl) do\n        if current_y \u003e height - lineheight then\n            break\n        end\n\n        if char == \"\\n\" then\n            _linebreak_offset()\n        else\n            if char == \" \" then  --word break\n                local next_space_index = _findNextSpaceIndex(text_tbl, key)\n                local word_width = 0\n                if next_space_index \u003e 1 and next_space_index \u003e key then\n                    for i = key+1, next_space_index do\n                        word_width += gfx.getTextSize(text_tbl[i]) + char_kerning\n                    end\n                    if current_x + word_width \u003e width - max_zh_char_size then\n                        _linebreak_offset()\n                    end\n                end\n            end\n            \n            gfx.drawTextAligned(char, current_x, current_y, kTextAlignment.left)\n            current_x += gfx.getTextSize(char) + char_kerning\n        end\n        \n        if current_x \u003e width - max_zh_char_size then\n            _linebreak_offset()\n        end\n\n        char_offset += 1\n    end\n\n    return char_offset\nend\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonoko%2Fchinese-font-for-playdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonoko%2Fchinese-font-for-playdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonoko%2Fchinese-font-for-playdate/lists"}