note 59620 added to function.imagettfbbox
| From: | Nashev at osu1 dot php dot net | Date: | Sun, 11 Dec 2005 13:38:59 +0000 |
| Subject: | note 59620 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99953@lists.php.net to get a copy of this message | ||
see http://php.rinet.ru/manual/ru/function.imagettftext.php#57416
function ByteCount($s) {
$has_mbstring = extension_loaded('mbstring')
||@dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX);
$has_mb_shadow = (int) ini_get('mbstring.func_overload');
if ($has_mbstring && ($has_mb_shadow & 2) ) {
$size = mb_strlen($s,'latin1');
} else {
$size = strlen($s);
}
return $size;
}
function foxy_utf8_to_nce($s) {
$utf = "$s";
$max_count = 5; // flag-bits in $max_mark ( 1111 1000 == 5 times 1)
$max_mark = 248; // marker for a (theoretical ;-)) 5-byte-char and mask for a 4-byte-char;
$html = '';
$ByteCount = ByteCount($utf);
for($str_pos = 0; $str_pos < $ByteCount; $str_pos++) {
$old_chr = $utf{$str_pos};
$old_val = ord($old_chr);
$new_val = 0;
$utf8_marker = 0;
// skip non-utf-8-chars
if ($old_val > 127) {
$mark = $max_mark;
for ($byte_ctr = $max_count; $byte_ctr > 2; $byte_ctr--) {
// actual byte is utf-8-marker?
if (($old_val & $mark) == (($mark << 1) & 255)) {
$utf8_marker = $byte_ctr - 1;
break;
}
$mark = ($mark << 1) & 255;
}
}
// marker found: collect following bytes
if ($utf8_marker > 1 and isset($utf{$str_pos + 1})) {
$str_off = 0;
$new_val = $old_val & (127 >> $utf8_marker);
for($byte_ctr = $utf8_marker; $byte_ctr > 1; $byte_ctr--) {
// check if following chars are UTF8 additional data blocks
// UTF8 and ord() > 127
if( (ord($utf{$str_pos + 1}) & 192) == 128 ) {
$new_val = $new_val << 6;
$str_off++;
// no need for Addition, bitwise OR is sufficient
// 63: more UTF8-bytes; 0011 1111
$new_val = $new_val | ( ord( $utf{$str_pos + $str_off} ) & 63 );
}
// no UTF8, but ord() > 127
// nevertheless convert first char to NCE
else {
$new_val = $old_val;
}
}
// build NCE-Code
$html .= '&#'.$new_val.';';
// Skip additional UTF-8-Bytes
$str_pos = $str_pos + $str_off;
} else {
$html .= chr($old_val);
//$new_val = $old_val;
}
}
return $html;
}
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59620
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59620&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59620&report=yes
Search -- http://master.php.net/manage/user-notes.php