【问题标题】:Right to Left paragraph writing with node-canvas, Cairo based implementation使用节点画布从右到左的段落写作,基于开罗的实现
【发布时间】:2016-03-29 15:11:48
【问题描述】:

我正在尝试在我的 node.js 服务器上生成包含从右到左文本的图像。

我目前正在使用节点画布(基于“Cairo”),但如果其他库可以解决问题,请提供建议。

要明确:

  1. 我需要支持才能编写从右到左的文本
  2. 实际字体与此问题无关,也与字体方向无关。 E.G:我不介意在我的软件中倒写单词,只要它们会在图像中从右到左显示即可。 (例如不支持希伯来语,如果我写“תודה”这个词,它将改为“התוד”。这个我可以处理,问题是段落方向。)

【问题讨论】:

  • 我对 node.js 一无所知,但 Pango 将是适合这项工作的库
  • 您好,您解决了这个问题吗?
  • @user2951807 在我的 Ubuntu 服务器中,不需要做任何事情,node-canvas 使用我使用的希伯来字体按预期工作,但是在我的本地开发机器(Macbook Pro)上,字母是倒着写的。因为我不想再在这个问题上浪费时间了,所以我只是在用 node-canvas 绘制它们之前反转了包含希伯来字母的字符串
  • 我希望它不会是答案 :( 猜想我也需要扭转它。谢谢!
  • @user2951807 我添加了一个智能反向的答案,以方便您

标签: node.js image-processing cairo node-canvas


【解决方案1】:

这里有一个解决问题的方法:

smartReverse: function(str) {                     // Reverse a string considering english letters and and numbers.
    return str                                    // by taking it and
        .split(/\s+/)                            // splitting it into words
        .reverse()                               // and reversing the word order
        .map(function(word) {
            // and then changing each word
            return (/^[0-9\.]+$/.test(word) || /^[a-zA-Z0-9?><;,{}[\]\-_+=!@#$%\^&*|']+$/.test(word)) ?     // if it's a number or an english word
                word :                              // into itself
                word.split("").reverse().join("");                  // or otherwise into its reverse
        })
        .join(" ")                                  // put it back together
        ;
}

【讨论】:

  • 感谢您的尝试,但这还不够。该功能非常基本,当 str 与 rtl 词和 ltr 词在同一个句子甚至括号或换行符中混合时没有帮助。我们需要的解决方案是一个可以获得 textarea 输出的解决方案,它可以是任何东西,包括数学公式的并在需要时完美地反转它。
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 2015-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多