[Vtigercrm-developers] UTF-8 display error on the vtiger 5.2.1 Dashboard diagrams - resolved

Holbok István holbok at gmail.com
Sat Feb 26 08:47:23 PST 2011


Hi All,

I found a display error on the vtiger 5.2.1. Dashboard. The UTF-8 
characters were changed into a rectangular place-holder. I opened a 
ticket for this issue: *Ticket #7028* on the track.


The reason of this display error was the internal bug of 
*ImageTTFText()* function in \Image\Canvas\GD.php file about the line #1405.

The solution was already developed:
http://hu.php.net/manual/en/function.imagettfbbox.php (post by Nashev)
http://php.rinet.ru/manual/ru/function.imagettftext.php#57416

By adding the function described below to the \Image\Canvas\GD.php file 
(to the Image_Canvas_GD Class) the problem is solved.

     #UTF8 - Character support on the charts
     function foxy_utf8_to_nce( $utf )
     {
       if($utf == '')
       {
         return($utf);
       }
       else
       {
         $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 = '';
         for($str_pos = 0; $str_pos < strlen($utf); $str_pos++)
         {
             $old_chr = $utf{$str_pos};
             $old_val = ord( $utf{$str_pos} );
             $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);
       }
     }


Changing the line #1405 - #1414 the problem is solved:

*ImageTTFText*(
                         $this->_canvas,
                         $this->_font['size'],
                         $this->_font['angle'],
                         $x,
                         $y,
                         $this->_color($color),
                         $this->_font['file'],
*//                        $line*
*Image_Canvas_GD::foxy_utf8_to_nce($line)*  //for UTF-8 support
                     );


Cheers:

Holbok István
telefon: +3670-342-0900
e-mail: holbok at gmail.com <mailto:holbok at gmail.com>

*
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110226/d1001b48/attachment-0002.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtiger_dashboard_error.png
Type: image/png
Size: 51860 bytes
Desc: not available
Url : http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110226/d1001b48/attachment-0004.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtiger_dashboard_resolved.png
Type: image/png
Size: 33332 bytes
Desc: not available
Url : http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110226/d1001b48/attachment-0005.png 


More information about the vtigercrm-developers mailing list