node.js - 使用 Node Canvas 从右到左编写段落,基于开罗的实现

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

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

我目前正在使用node-canvas(基于“Cairo”),但欢迎建议,以防其他库可以实现这一点。

需要明确的是:

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

最佳答案

这是解决问题的方法:

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
        ;
}

关于node.js - 使用 Node Canvas 从右到左编写段落,基于开罗的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431353/

相关文章:

javascript - npm install 超过了最大调用堆栈大小

c - 原始图像到 tiff 图像

r - 在 R 中,是否可以设置开罗窗口的标题?

javascript - 使用 Javascript 扫描 Mongo 数据库并在字符串不相同时触发事件

node.js - 开类 Node .js : do I need to load ssl certificates in the web console or in the application?

node.js - 同步文本编辑

algorithm - 旧彩色电影效果和海报效果

c# - 使用 System.Windows.Media.Imaging 合成两个位图

python - 开罗:在 x 和 y 中绘制从 0 到 1 的空间中的所有内容,并且仅在最后重新缩放到特定分辨率(可调整大小的窗口)

python - 如何使用 Cairo 将图像转换为灰度