# my_custom_fonts **Repository Path**: dailh/my_custom_fonts ## Basic Information - **Project Name**: my_custom_fonts - **Description**: Forked from https://github.com/bberppub/my_custom_fonts.git 添加了阿里巴巴普惠体分支 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: alibaba-fonts - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2025-12-08 - **Last Updated**: 2025-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # my_custom_fonts 一个用于 Frappe/ERPNext 的极简字体应用,在系统桌面自动引入自定义字体(内置阿里巴巴普惠体),统一界面显示效果。 ## 作用与原理 - 通过在系统头部注册 CSS,将 `MyCustomFont` 应用于桌面界面的常见元素(`body`、标题、按钮、表单控件等)。 - CSS 与字体文件位于应用的公共资源目录,随应用一并提供并由框架静态服务。 - 关键接入点:在 `hooks.py` 中声明 `app_include_css`,确保桌面端加载字体样式(`apps/my_custom_fonts/my_custom_fonts/hooks.py:13`)。 ## 代码结构 - 字体文件:`apps/my_custom_fonts/my_custom_fonts/public/fonts/` - 样式文件:`apps/my_custom_fonts/my_custom_fonts/public/css/my_custom_fonts.css` - 框架钩子:`apps/my_custom_fonts/my_custom_fonts/hooks.py` 其中 CSS 已包含以下字重的阿里巴巴普惠体:Thin、Light、Medium、Bold,并统一映射为 `MyCustomFont`。 ## 安装 在 Bench 根目录执行: 1. 拉取应用 - `bench get-app https://gitee.com/dailh/my_custom_fonts.git` 2. 安装到指定站点 - `bench --site <你的站点> install-app my_custom_fonts` 3. 迁移并清理缓存 - `bench --site <你的站点> migrate` - `bench --site <你的站点> clear-cache` - `bench --site <你的站点> clear-website-cache` 完成后,桌面端(Desk)界面会自动应用新字体。 ## 使用与生效验证 - 打开系统桌面,检查菜单、列表、表单等是否已使用新字体。 - 如未生效: - 确认钩子已启用:`apps/my_custom_fonts/my_custom_fonts/hooks.py:13` - 确认静态资源可访问:`/assets/my_custom_fonts/css/my_custom_fonts.css` - 重新执行站点缓存清理命令。 ## 网站端使用(可选) 默认仅为桌面端注入字体。如果需要网站端也加载同一字体,可在钩子中配置: - 在 `hooks.py` 中设置: - `web_include_css = "/assets/my_custom_fonts/css/my_custom_fonts.css"`(位置参考 `apps/my_custom_fonts/my_custom_fonts/hooks.py:17`) - 清理网站缓存: - `bench --site <你的站点> clear-website-cache` 注:如果你不希望影响网站端,请保持该项未启用。 ## 自定义与扩展 - 如需调整字重或覆盖范围,可直接编辑:`apps/my_custom_fonts/my_custom_fonts/public/css/my_custom_fonts.css` - 例如补充 Regular 字重映射: ``` @font-face { font-family: 'MyCustomFont'; src: url('/assets/my_custom_fonts/fonts/AlibabaPuHuiTi-3-55-Regular.otf') format('opentype'); font-weight: 400; font-style: normal; } ``` - 如需只在特定页面或组件生效,可在 CSS 中缩小选择器范围,而非全局覆盖。 ## 兼容性 - 适配 Frappe v15 及以上版本(应用自身 `pyproject.toml` 要求 Python ≥ 3.10)。 - 其他版本理论可用,但不同框架版本的资源打包/缓存行为可能略有差异。 ## 常见问题 - 字体未加载:检查静态路径与文件存在性(`public/fonts`、`public/css`)。 - 样式被覆盖:其他应用或主题可能定义更高优先级的字体规则,可通过提高选择器优先级或使用 `!important`(已在核心选择器中启用)。 - 网站端不生效:确认已启用 `web_include_css` 并清理网站缓存。 ## 许可证与字体授权 - 应用代码采用 MIT 许可证(见 `apps/my_custom_fonts/license.txt`)。 - 字体文件版权归原作者所有。请根据阿里巴巴普惠体的授权条款规范使用。 ## 仓库地址 - Gitee(当前维护):`https://gitee.com/dailh/my_custom_fonts` ## 致谢 - 字体来源:阿里巴巴普惠体。