Horde_Pdf_Writer::getStringWidth PHP Method

getStringWidth() public method

Returns the length of a text string. A font must be selected.
public getStringWidth ( string $text, boolean $pt = false ) : float
$text string The text whose length is to be computed.
$pt boolean Whether the width should be returned in points or user units.
return float
    public function getStringWidth($text, $pt = false)
    {
        $text = (string) $text;
        $width = 0;
        $length = strlen($text);
        for ($i = 0; $i < $length; $i++) {
            $width += $this->_current_font['cw'][$text[$i]];
        }
        /* Adjust for word spacing. */
        $width += $this->_word_spacing * substr_count($text, ' ') * $this->_current_font['cw'][' '];
        if ($pt) {
            return $width * $this->_font_size_pt / 1000;
        } else {
            return $width * $this->_font_size / 1000;
        }
    }