複雑なスクリプト (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");
?>