javascript - 使用 python 或 javascript 将 Hershey 字体 .jhf 解析为 json

标签 javascript python json parsing fonts

我一直在网上寻找解决方案,但没有找到我能力范围内的解决方案。您将如何转换这些 Hershey Font .jhf 文件 emergent.unpythonic.net/software/hershey使用 python 或 javascript 转换为 JSON。创建类似的东西:

[
    {
        asciival:26,
        points:[[5,-5],[4,7,8],[6,8,7]]
    },
    {
        asciival:27,
        points:[[5,-3],[4,7,33],[6,32,7]]
    },
(…)
]

我知道有一个question here但这还不足以让我理解这个系统。

编辑1

我已经找到了描述paulbourke.net/dataformats/hershey/肖恩在评论中指出。

As an example consider the 8th symbol 8 9MWOMOV RUMUV ROQUQ
It has 9 coordinate pairs (this includes the left and right position).
The left position is 'M' - 'R' = -5
The right position is 'W' - 'R' = 5
The first coordinate is "OM" = (-3,-5)
The second coordinate is "OV" = (-3,4)
Raise the pen " R"
Move to "UM" = (3,-5)
Draw to "UV" = (3,4)
Raise the pen " R"
Move to "OQ" = (-3,-1)
Draw to "UQ" = (3,-1)
Drawing this out on a piece of paper will reveal it represents an 'H'.>

我试图理解这一点,但这些值从哪里来?
例如为什么UM是(3,-5)?

编辑2

我找到了this java class

最佳答案

坐标是连续的字符对。要将它们转换为数字,您需要从每个字符中减去字符“R”= 82 的 ascii 等效值。在您的示例中,“UM”翻译为 (3,-5),因为 U 是 ascii 代码 85。减去 82 (='R') 得到 3。M 是 ascii 代码 77,减去 82 得到 -5。

关于javascript - 使用 python 或 javascript 将 Hershey 字体 .jhf 解析为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14041784/

相关文章:

javascript - 我如何让 selenium ide 在 firefox 控制台中执行时使用 jquery 运行我的自定义 javascript?

javascript - 在每个空格后标记一个特定的单词

javascript - 当我尝试在 jQuery 中将背景图像添加到 div 时,我不断收到 404 错误

python - 从插入查询中获取数据?

python - 使用 pipe() 和 fdopen() 将数据从 Python 脚本传递到 Windows 中的 C++ 应用程序

php - 如何在 php mysql 中将搜索选项中的数据分配为 json 格式

javascript - jQuery Rain "Animated Menu Icon"onclick 不工作

c# - 开发游戏服务器的好语言?

php - PDO json_encode 不起作用,错误在哪里?

json - 如何使用使用蛇形大小写(下划线表示法)而不是驼峰大小写的喷射 json 解析 json