示例#1
0
 /**
  * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  * @param $sa (string) The array of chars whose total length is to be computed
  * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  * @param $fontsize (float) Font size in points. The default value is the current size.
  * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  * @return mixed int total string length or array of characted widths
  * @author Nicola Asuni
  * @public
  * @since 2.4.000 (2008-03-06)
  */
 public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
 {
     // store current values
     if (!TCPDF_STATIC::empty_string($fontname)) {
         $prev_FontFamily = $this->FontFamily;
         $prev_FontStyle = $this->FontStyle;
         $prev_FontSizePt = $this->FontSizePt;
         $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
     }
     // convert UTF-8 array to Latin1 if required
     if ($this->isunicode and !$this->isUnicodeFont()) {
         $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
     }
     $w = 0;
     // total width
     $wa = array();
     // array of characters widths
     foreach ($sa as $ck => $char) {
         // character width
         $cw = $this->GetCharWidth($char, isset($sa[$ck + 1]));
         $wa[] = $cw;
         $w += $cw;
     }
     // restore previous values
     if (!TCPDF_STATIC::empty_string($fontname)) {
         $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
     }
     if ($getarray) {
         return $wa;
     }
     return $w;
 }