Created
November 26, 2010 14:59
-
-
Save dtinth/716814 to your computer and use it in GitHub Desktop.
Utility function to fix floating tone marks when outputting as PDF.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function thai($x) { | |
$back = array( | |
"\xE0\xB9\x88" => "\xEF\x9C\x85", | |
"\xE0\xB9\x89" => "\xEF\x9C\x86", | |
"\xE0\xB9\x8A" => "\xEF\x9C\x87", | |
"\xE0\xB9\x8B" => "\xEF\x9C\x88", | |
"\xE0\xB9\x8C" => "\xEF\x9C\x89" | |
); | |
$cross = array(); | |
foreach (array("\xE0\xB8\xB4", "\xE0\xB8\xB5", "\xE0\xB8\xB6", "\xE0\xB8\xB7") as $p) { | |
for ($i = 0x85; $i <= 0x89; $i ++) { | |
$from = $p . "\xEF\x9C" . chr($i); | |
$to = $p . "\xE0\xB9" . chr($i + 3); | |
$cross[$from] = $to; | |
} | |
} | |
$x = strtr($x, $back); | |
$x = strtr($x, $cross); | |
return $x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
อัปเดทใหม่ นอกจากจะแก้เสียงวรรณยุกต์ลอยแล้ว (ไม้เอก เป็นต้น) ยังแก้เรื่องสระด้านล่างไปชนกับตัวอักษรที่ลากยาวลงมาด้านล่างด้วย เช่น ญ, ฎ เป็นต้น.
ทำสอบโดยใช้โค้ดสร้าง PDF ใดๆก็ได้แล้วแก้ไขชื่อฟอนต์เอาให้ถูกต้อง
หมายเหตุ: ไม่สามารถแก้ไขได้กับทุกฟอนต์ บางฟอนต์ที่เสียงวรรณยุกต์จม (สระจม, ไม้เอกจม เป็นต้น) จะไม่สามารถแก้ได้เลย เนื่องจากเขาทำมาไม่ครบ. ดังนั้นตรวจสอบกับฟอนต์ที่จะใช้ให้ดีก่อนใช้จริง.