lib/ezpdf/classes/class.pdf.php
function getTextWidth( $size, $text )
    {
        // this function should not change any of the settings, though it will need to
        // track any directives which change during calculation, so copy them at the start
        // and put them back at the end.
        $this->pushTextState( $this->currentTextState );

        if (!$this->numFonts)
        {
            $this->selectFont('./fonts/Helvetica');
        }

        // converts a number or a float to a string so it can get the width
        $text = "$text";
        // hmm, this is where it all starts to get tricky - use the font information to
        // calculate the width of each character, add them up and convert to user units
        $w = 0;
        $len = strlen( $text );
        $cf = $this->currentFont;
        for ( $i = 0; $i < $len; $i++ )
        {
            $f = 1;
            $directiveArray = $this->PRVTcheckTextDirective( $text, $i, $f );
            $directive = $directiveArray['directive'];
            if ( $directive )
            {
                if ($f)
                {
                    $this->setCurrentFont();
                    $cf = $this->currentFont;
                }
                $i = $i + $directive-1;
            }
            else
            {
                $char = ord( $text[$i] );
                if ( isset($this->fonts[$cf]['differences'][$char] ) )
                {
                    // then this character is being replaced by another
                    $name = $this->fonts[$cf]['differences'][$char];
                    if ( isset($this->fonts[$cf]['C'][$name]['WX'] ) )
                    {
                        $w += $this->fonts[$cf]['C'][$name]['WX'];
                    }
                }
                else if ( isset($this->fonts[$cf]['C'][$char]['WX'] ) )
                {
                    $w += $this->fonts[$cf]['C'][$char]['WX'];
                }
                else
                {
                    $w += 700;
                }
            }
        }

        $this->popTextState();
        $this->setCurrentFont();

        return $w*$size/1000;
    }
function getTextWidth( $size, $text )
    {
        // this function should not change any of the settings, though it will need to
        // track any directives which change during calculation, so copy them at the start
        // and put them back at the end.
        $this->pushTextState( $this->currentTextState );

        if (!$this->numFonts)
        {
            $this->selectFont('./fonts/Helvetica');
        }

        // converts a number or a float to a string so it can get the width
        $text = "$text";
        // hmm, this is where it all starts to get tricky - use the font information to
        // calculate the width of each character, add them up and convert to user units
        $w = 0;
        $len = strlen( $text );
        $cf = $this->currentFont;
        for ( $i = 0; $i < $len; $i++ )
        {
            $f = 1;
            $directiveArray = $this->PRVTcheckTextDirective( $text, $i, $f );
            $directive = $directiveArray['directive'];
            if ( $directive )
            {
                if ($f)
                {
                    $this->setCurrentFont();
                    $cf = $this->currentFont;
                }
                $i = $i + $directive-1;
            }
            else
            {
                $char = ord( $text[$i] );
                if ( isset($this->fonts[$cf]['differences'][$char] ) )
                {
                    // then this character is being replaced by another
                    $name = $this->fonts[$cf]['differences'][$char];
                    if ( isset($this->fonts[$cf]['C'][$name]['WX'] ) )
                    {
                        $w += $this->fonts[$cf]['C'][$name]['WX'];
                    }
                }
                else if ( isset($this->fonts[$cf]['C'][$char]['WX'] ) )
                {
                    $w += $this->fonts[$cf]['C'][$char]['WX'];
                }
                else
                {
                    $w += 700;
                }
            }
        }

        $this->popTextState();
        $this->setCurrentFont();

        return $w*$size/1000;
    }
function getTextWidth ( $ size , $ text ) { // this function should not change any of the settings, though it will need to // track any directives which change during calculation, so copy them at the start // and put them back at the end. $ this -> pushTextState ( $ this -> currentTextState ) ; if ( ! $ this -> numFonts ) { $ this -> selectFont ( './fonts/Helvetica' ) ; } // converts a number or a float to a string so it can get the width $ text = "$text" ; // hmm, this is where it all starts to get tricky - use the font information to // calculate the width of each character, add them up and convert to user units $ w = 0 ; $ len = strlen ( $ text ) ; $ cf = $ this -> currentFont ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ f = 1 ; $ directiveArray = $ this -> PRVTcheckTextDirective ( $ text , $ i , $ f ) ; $ directive = $ directiveArray [ 'directive' ] ; if ( $ directive ) { if ( $ f ) { $ this -> setCurrentFont ( ) ; $ cf = $ this -> currentFont ; } $ i = $ i + $ directive - 1 ; } else { $ char = ord ( $ text [ $ i ] ) ; if ( isset ( $ this -> fonts [ $ cf ] [ 'differences' ] [ $ char ] ) ) { // then this character is being replaced by another $ name = $ this -> fonts [ $ cf ] [ 'differences' ] [ $ char ] ; if ( isset ( $ this -> fonts [ $ cf ] [ 'C' ] [ $ name ] [ 'WX' ] ) ) { $ w += $ this -> fonts [ $ cf ] [ 'C' ] [ $ name ] [ 'WX' ] ; } } else if ( isset ( $ this -> fonts [ $ cf ] [ 'C' ] [ $ char ] [ 'WX' ] ) ) { $ w += $ this -> fonts [ $ cf ] [ 'C' ] [ $ char ] [ 'WX' ] ; } else { $ w += 700 ; } } } $ this -> popTextState ( ) ; $ this -> setCurrentFont ( ) ; return $ w * $ size / 1000 ; }
calculate how wide a given text string will be on a page, at a given size.
this can be called externally, but is alse used by the other class functions
calculate how wide a given text string will be on a page at a given size . this can be called externally but is alse used by the other class functions