我正在研究一种解决方案,可以自动为包含复杂脚本(UTF-8 中的高棉语)的大型文档的每个单词制作图像。我发现 Pango 和 Cairo 可以正确渲染高棉语。我不是一个程序员,所以我从 Pango 和 Cairo 的 PHP 版本开始。但我不确定如何分解字符串并自动为每个单词生成图像。单词之间没有“真正的”空格,只有 Unicode 字符 U+0200B(零宽度空格)。
有人愿意帮助我吗?
这是我目前使用的输出整个字符串的代码:
<?php
header("Content-Type: image/png");
/* Make a 300x300px image surface */
$s = new CairoImageSurface(CairoFormat::ARGB32, 300, 300);
$c = new CairoContext($s);
/* Set the background to white */
$c->setSourceRGB(1, 1, 1);
$c->paint();
/* Let's draw using black 'ink' */
$c->setSourceRGB(0, 0, 0);
/* Make a Pango layout, set the font, then set the layout size */
$l = new PangoLayout($c);
$desc = new PangoFontDescription("KhmerOS Regular 28");
$l->setFontDescription($desc);
$l->setWidth(250 * PANGO_SCALE);
/* Here is the text */
$l->setMarkup("កាលដើមដំបូងឡើយ ព្រះបានបង្កើតផ្ទៃមេឃ និងផែនដី។");
/* Draw the layout on the surface */
$l->showLayout($c);
/* Output the PNG to the browser */
$s->writeToPng("php://output");
?>