活huó字zì
一个简单的中日韩文字排印引擎,为游戏富文本特别设计。A simple typography engine for CJK languages, especially designed for game rich-text.
总览
活字是 AVG.js 的模块之一,为剧情游戏文字排版设计,兼顾中西混排和纯西文排版。
排版规则
- 方块字优先
- 横排且纵横对齐
- 避首尾
- 行末最多悬挂两个标点(共占 1em 宽)
- 行末标点超过两个的,避行首规则失效
- 在前两条规则的基础上,行末标点自第一个需避行尾的标点前断开,进入下一行
- 行内标点挤压:除破折号等不可挤压的标点外,所有标点均会两两合并为一个em宽度
- 遇非方块字(英文字母、数字等),按照西文排版方式进行排版。
- 非方块字两端以补不定长空格的方式凑齐 em 的整数倍宽度,以保证后续内容纵横对齐。
演示
https://icemic.github.io/huozi.js/
使用
npm install huozi
; const canvas = document;const context = canvas; const textSequence = '需要排版的文字内容'; const layoutSequence = ; context;contextstrokeStyle = '#999'; for const char of layoutSequence contextfont = `px sans-serif`; contexttextBaseline = 'hanging'; context; context;
输入格式:
character: String // 单个字符 fontSize: Number // 该字符的字号
输出格式:
character: String fontSize: Number x: Number // 绝对坐标 y: Number // 绝对坐标 width: Number // 字符宽度 height: Number // 字符高度
参数详解:
参与项目
欢迎任何 Issue 和 Pull Request!
许可
Copyright 2017-present Icemic Jia
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.