TextWidth
Calculate text width use canvas measureText() method.
Install
npm install textwidth
Example
var tw = require('textwidth');
// 使用默认字体及大小
var width = tw("Hello textwidth!!!")
// 设置字体,大小
var width = tw("Set the text font", "10px Arial")
Doc
Test
Todo
- 添加测试用例
- 完善文档
- 发布到npm
Bug
- 中文字体宽度偏差
Roadmap
- 计算高度
- 根据不同的单位(pixel, pm)计算宽度
- 允许设置字间距
其他实现方式
License
MIT