Source for file class.multicelltag.php

Documentation is available at class.multicelltag.php

  1. <?php
  2.  /****************************************************************************
  3.  * Software:    FPDF class extension
  4.  *              Tag Based Multicell
  5.  * Version:        1.4
  6.  * Date:        2005/12/08
  7.  * Author:        Bintintan Andrei <andy@interpid.eu>
  8.  *
  9.  * Last Modification: 2008/02/24
  10.  *
  11.  * License: Free for Non Commercial use. 
  12.  *          You may not sell or use this class in a Commercial Project without written permission from the Author. 
  13.  *
  14.  * 
  15.  * If you like my work please DONATE!!! **** paypal@interpid.eu ***** 
  16.  * 
  17.  * For more classes visit ***** www.interpid.eu ***** 
  18.  * 
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  20.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE 
  21.  * AUTHOR OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  23.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
  24.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
  25.  * SUCH DAMAGE.
  26.  * 
  27.  * PLEASE REPORT ANY BUGS TO THE AUTHOR. 
  28.  * 
  29.  * THANK YOU. 
  30.  * 
  31.  */
  32.  
  33. /**
  34. Modifications:
  35.     ... no more logs here.
  36. 2007.01.21 
  37.     - added left, top, right and bottom padding to the MultiCellTag Functions
  38. 2006.09.18  
  39.     - added YPOS parameter to the tab for super/subscript posibility. ypos = '-1' means the relative position to the normal Y. 
  40. 2006.07.30  
  41.     - added Paragraph Support(a sort of) - paragraphs can be specified with size='integer value' and PARAGRAPH_STRING character
  42. 2006.05.18
  43.     - removed the NBLines functions
  44.     - added mt_StringToLines function
  45.     - modified  MultiCellTag to accept as data parameter an array type like the return from  mt_StringToLines function
  46.     - these modifications does not affect the main class behavior, they are used for further developement and class extensions
  47. */
  48.  
  49. require_once(dirname(__FILE__).'/class.fpdf.php');
  50. require_once(dirname(__FILE__).'/class.string_tags.php');
  51.  
  52. if (!defined('PARAGRAPH_STRING')) define('PARAGRAPH_STRING''~~~');
  53.  
  54. /**
  55.  * MultiCellTag Class
  56.  * The intern functions are prefaced with mt_, not be be overwritten
  57.  * 
  58.  * @author     andy@interpid.eu
  59.  * @version 1.4
  60.  * 
  61.  */
  62. class fpdf_multicelltag extends FPDF{
  63.  
  64. /**
  65.  * Valid Tag Maximum Width
  66.  *
  67.  * @access     protected
  68.  * @var        integer 
  69.  */
  70. protected $wt_TagWidthMax = 10;
  71.     
  72. /**
  73.  * The current active tag
  74.  *
  75.  * @access    protected
  76.  * @var        string 
  77.  */
  78. protected $wt_Current_Tag = '';
  79.  
  80. /**
  81.  * Tags Font Information
  82.  *
  83.  * @access     protected
  84.  * @var        struct 
  85.  */
  86. protected $wt_FontInfo;
  87.  
  88. /**
  89.  * Parsed string data info
  90.  *
  91.  * @access     protected
  92.  * @var        struct 
  93.  */
  94. protected $wt_DataInfo;
  95.  
  96. /**
  97.  * Data Extra Info
  98.  *
  99.  * @access     protected
  100.  * @var        struct 
  101.  */
  102. protected $wt_DataExtraInfo;
  103.  
  104. /**
  105.  * Temporary Info
  106.  *
  107.  * @access     protected
  108.  * @var        struct 
  109.  */
  110. protected $wt_TempData;
  111.  
  112.  
  113. /**
  114.  * == true if a tag was more times defined.
  115.  *
  116.  * @access     protected
  117.  * @var        boolean 
  118.  */
  119. protected $wt_bDoubleTags = false;
  120.  
  121.  
  122. /**
  123.  * Sets the Tags Maximum width
  124.  * 
  125.  * @access     public
  126.  * @param     numeric $iWidth - the width of the tags
  127.  * @return     void 
  128.  */
  129. public function setTagWidthMax($iWidth 10){
  130.     $this->wt_TagWidthMax = $iWidth;
  131. }
  132.  
  133.  
  134. /**
  135.  * Resets the current class internal variables to default values
  136.  * 
  137.  * @access     protected
  138.  * @param     none 
  139.  * @return     void 
  140.  */
  141. protected function mt_Reset_Datas(){
  142.         $this->wt_Current_Tag = "";
  143.         $this->wt_DataInfo = array();
  144.         $this->wt_DataExtraInfo = array(
  145.             "LAST_LINE_BR" => "",        //CURRENT LINE BREAK TYPE
  146.             "CURRENT_LINE_BR" => "",    //LAST LINE BREAK TYPE
  147.             "TAB_WIDTH" => 10            //The tab WIDTH IS IN mm
  148.         );
  149.  
  150.         //if another measure unit is used ... calculate your OWN
  151.         $this->wt_DataExtraInfo["TAB_WIDTH"*= (72/25.4$this->k;
  152.         /*
  153.             $this->wt_FontInfo - do not reset, once read ... is OK!!!
  154.         */
  155.     }//function mt_Reset_Datas(){
  156.     
  157.     /**
  158.      * Sets current tag to specified style
  159.      *
  160.      * @access     public
  161.      * @param     string $tag - tag name
  162.      * @param    string $family - text font family name
  163.      * @param    string $style - text font style
  164.      * @param    numeric $size - text font size
  165.      * @param    array $color - text color
  166.      * @return    void 
  167.      */
  168.     public function SetStyle($tag$family$style$size$color)
  169.     {
  170.  
  171.         if ($tag == "ttags"$this->Error (">> ttags << is reserved TAG Name.");
  172.         if ($tag == ""$this->Error ("Empty TAG Name.");
  173.  
  174.         //use case insensitive tags
  175.         $tag=trim(strtoupper($tag));
  176.         
  177.         if (isset($this->TagStyle[$tag])) $this->wt_bDoubleTags = true;
  178.         
  179.         $this->TagStyle[$tag]['family']=trim($family);
  180.         $this->TagStyle[$tag]['style']=trim($style);
  181.         $this->TagStyle[$tag]['size']=trim($size);
  182.         $this->TagStyle[$tag]['color']=trim($color);
  183.     }//function SetStyle
  184.     
  185.     /**
  186.      * Sets current tag to specified style
  187.      *         - if the tag name is not in the tag list then de "DEFAULT" tag is saved.
  188.      *         This includes a fist call of the function mt_SaveCurrentStyle()
  189.      *
  190.      * @access     protected
  191.      * @param     string $tag - tag name
  192.      * @return    void 
  193.      */
  194.     protected function mt_ApplyStyle($tag){
  195.  
  196.         //use case insensitive tags
  197.         $tag=trim(strtoupper($tag));
  198.  
  199.         if ($this->wt_Current_Tag == $tagreturn;
  200.  
  201.         if (($tag == ""|| (isset($this->TagStyle[$tag]))) $tag "DEFAULT";
  202.  
  203.         $this->wt_Current_Tag = $tag;
  204.  
  205.         $style $this->TagStyle[$tag];
  206.  
  207.         if (isset($style)){
  208.             $this->SetFont($style['family']$style['style']$style['size']);
  209.             //this is textcolor in FPDF format
  210.             if (isset($style['textcolor_fpdf'])) {
  211.                 $this->TextColor $style['textcolor_fpdf'];
  212.                 $this->ColorFlag=($this->FillColor!=$this->TextColor);
  213.             }else
  214.             {
  215.                 if ($style['color'<> ""){//if we have a specified color
  216.                     $temp explode(","$style['color']);
  217.                     $this->SetTextColor($temp[0]$temp[1]$temp[2]);
  218.                 }//fi
  219.             }
  220.             /**/
  221.         }//isset
  222.     }//function mt_ApplyStyle($tag){
  223.  
  224.     /**
  225.      * Save the current settings as a tag default style under the DEFAUTLT tag name
  226.      * 
  227.      * @access     protected
  228.      * @param     none 
  229.      * @return     void 
  230.      */
  231.     protected function mt_SaveCurrentStyle(){
  232.         $this->TagStyle['DEFAULT']['family'$this->FontFamily;;
  233.         $this->TagStyle['DEFAULT']['style'$this->FontStyle;
  234.         $this->TagStyle['DEFAULT']['size'$this->FontSizePt;
  235.         $this->TagStyle['DEFAULT']['textcolor_fpdf'$this->TextColor;
  236.         $this->TagStyle['DEFAULT']['color'"";
  237.     }//function mt_SaveCurrentStyle
  238.  
  239.     
  240.     /**
  241.      * Divides $this->wt_DataInfo and returnes a line from this variable
  242.      *
  243.      * @access     protected
  244.      * @param    numeric $w - the width of the text
  245.      * @return     array $aLine - array() -> contains informations to draw a line
  246.      */
  247.     protected function mt_MakeLine($w){
  248.  
  249.         $aDataInfo $this->wt_DataInfo;
  250.         $aExtraInfo $this->wt_DataExtraInfo;
  251.  
  252.         //last line break >> current line break
  253.         $aExtraInfo['LAST_LINE_BR'$aExtraInfo['CURRENT_LINE_BR'];
  254.         $aExtraInfo['CURRENT_LINE_BR'"";
  255.  
  256.         if($w==0)
  257.             $w=$this->$this->rMargin $this->x;
  258.  
  259.         $wmax ($w 2*$this->cMargin1000;//max width
  260.  
  261.         $aLine array();//this will contain the result
  262.         $return_result false;//if break and return result
  263.         $reset_spaces false;
  264.  
  265.         $line_width 0;//line string width
  266.         $total_chars 0;//total characters included in the result string
  267.         $space_count 0;//numer of spaces in the result string
  268.         $fw $this->wt_FontInfo;//font info array
  269.  
  270.         $last_sepch ""//last separator character
  271.         
  272.         foreach ($aDataInfo as $key => $val){
  273.             
  274.             $s $val['text'];
  275.  
  276.             $tag &$val['tag'];
  277.  
  278.             $bParagraph false;            
  279.             if (($s == "\t"&& ($tag == 'pparg')){
  280.                 $bParagraph true;
  281.                 $s "\t";//place instead a TAB
  282.             }
  283.  
  284.              $s_lenght=strlen($s);
  285.  
  286.             $i 0;//from where is the string remain
  287.             $j 0;//untill where is the string good to copy -- leave this == 1->> copy at least one character!!!
  288.             $str "";
  289.             $s_width 0;    //string width
  290.             $last_sep = -1//last separator position
  291.             $last_sepwidth 0;
  292.             $last_sepch_width 0;
  293.             $ante_last_sep = -1//ante last separator position
  294.             $spaces 0;
  295.             
  296.             //parse the whole string
  297.             while ($i $s_lenght){
  298.                 $c $s[$i];
  299.  
  300.                    if($c == "\n"){//Explicit line break
  301.                        $i++//ignore/skip this caracter
  302.                     $aExtraInfo['CURRENT_LINE_BR'"BREAK";
  303.                     $return_result true;
  304.                     $reset_spaces true;
  305.                     break;
  306.                 }
  307.  
  308.                 //space
  309.                    if($c == " "){
  310.                     $space_count++;//increase the number of spaces
  311.                     $spaces ++;
  312.                 }
  313.  
  314.                 //    Font Width / Size Array
  315.                 if (!isset($fw[$tag]|| ($tag == ""|| ($this->wt_bDoubleTags)){
  316.                     //if this font was not used untill now,
  317.                     $this->mt_ApplyStyle($tag);
  318.                     $fw[$tag]['w'$this->CurrentFont['cw'];//width
  319.                     $fw[$tag]['s'$this->FontSize;//size
  320.                 }
  321.  
  322.                 $char_width $fw[$tag]['w'][$c$fw[$tag]['s'];
  323.  
  324.                 //separators
  325.                 if(is_int(strpos(" ,.:;",$c))){
  326.  
  327.                     $ante_last_sep $last_sep;
  328.                     $ante_last_sepch $last_sepch;
  329.                     $ante_last_sepwidth $last_sepwidth;
  330.                     $ante_last_sepch_width $last_sepch_width;
  331.  
  332.                     $last_sep $i;//last separator position
  333.                     $last_sepch $c;//last separator char
  334.                     $last_sepch_width $char_width;//last separator char
  335.                     $last_sepwidth $s_width;
  336.  
  337.                 }
  338.  
  339.                 if ($c == "\t"){//TAB
  340.                     $c $s[$i"";
  341.                     $char_width $aExtraInfo['TAB_WIDTH'1000;
  342.                 }
  343.  
  344.                 if ($bParagraph == true){
  345.                     $c $s[$i"";
  346.                     $char_width $this->wt_TempData['LAST_TAB_REQSIZE']*1000 $this->wt_TempData['LAST_TAB_SIZE'];
  347.                     if ($char_width 0$char_width 0;                
  348.                 }
  349.                 
  350.                 
  351.  
  352.                 $line_width += $char_width;
  353.  
  354.                 if($line_width $wmax){//Automatic line break
  355.  
  356.                     $aExtraInfo['CURRENT_LINE_BR'"AUTO";
  357.  
  358.                     if ($total_chars == 0{
  359.                         /* This MEANS that the $w (width) is lower than a char width...
  360.                             Put $i and $j to 1 ... otherwise infinite while*/
  361.                         $i 1;
  362.                         $j 1;
  363.                         $return_result true;//YES RETURN THE RESULT!!!
  364.                         break;
  365.                     }//fi
  366.  
  367.                     if ($last_sep <> -1){
  368.                         //we have a separator in this tag!!!
  369.                         //untill now there one separator
  370.                         if (($last_sepch == $c&& ($last_sepch != " "&& ($ante_last_sep <> -1)){
  371.                             /*    this is the last character and it is a separator, if it is a space the leave it...
  372.                                 Have to jump back to the last separator... even a space
  373.                             */
  374.                             $last_sep $ante_last_sep;
  375.                             $last_sepch $ante_last_sepch;
  376.                             $last_sepwidth $ante_last_sepwidth;
  377.                         }
  378.  
  379.                         if ($last_sepch == " "){
  380.                             $j $last_sep;//just ignore the last space (it is at end of line)
  381.                             $i $last_sep 1;
  382.                             if $spaces $spaces --;
  383.                             $s_width $last_sepwidth;
  384.                         }else{
  385.                             $j $last_sep 1;
  386.                             $i $last_sep 1;
  387.                             $s_width $last_sepwidth $last_sepch_width;
  388.                         }
  389.  
  390.                     }elseif(count($aLine0){
  391.                         //we have elements in the last tag!!!!
  392.                         if ($last_sepch == " "){//the last tag ends with a space, have to remove it
  393.  
  394.                             $temp $aLinecount($aLine)-];
  395.  
  396.                             if ($temp['text'][strlen($temp['text'])-1== " "){
  397.  
  398.                                 $temp['text'substr($temp['text']0strlen($temp['text']1);
  399.                                 $temp['width'-= $fw$temp['tag'] ]['w'][" "$fw$temp['tag'] ]['s'];
  400.                                 $temp['spaces'--;
  401.  
  402.                                 //imediat return from this function
  403.                                 break 2;
  404.                             }else{
  405.                                 #die("should not be!!!");
  406.                             }//fi
  407.                         }//fi
  408.                     }//fi else
  409.  
  410.                     $return_result true;
  411.                     break;
  412.                 }//fi - Auto line break
  413.  
  414.                 //increase the string width ONLY when it is added!!!!
  415.                 $s_width += $char_width;
  416.  
  417.                 $i++;
  418.                 $j $i;
  419.                 $total_chars ++;
  420.             }//while
  421.  
  422.             $str substr($s0$j);
  423.  
  424.             $sTmpStr $aDataInfo[$key]['text'];
  425.             $sTmpStr substr($sTmpStr$istrlen($sTmpStr));
  426.  
  427.             if (($sTmpStr == ""|| ($sTmpStr === FALSE))//empty
  428.                 array_shift($aDataInfo);
  429.  
  430.             if ($val['text'== $str){
  431.             }
  432.             
  433.             if (!isset($val['href'])) $val['href']='';
  434.             if (!isset($val['ypos'])) $val['ypos']=0;
  435.  
  436.             //we have a partial result
  437.             array_push($aLinearray(
  438.                 'text' => $str,
  439.                 'tag' => $val['tag'],
  440.                 'href' => $val['href'],
  441.                 'width' => $s_width,
  442.                 'spaces' => $spaces,
  443.                 'ypos' => $val['ypos']
  444.             ));
  445.             
  446.             $this->wt_TempData['LAST_TAB_SIZE'$s_width;
  447.             $this->wt_TempData['LAST_TAB_REQSIZE'(isset($val['size'])) $val['size'0;           
  448.             
  449.             if ($return_resultbreak;//break this for
  450.  
  451.         }//foreach
  452.  
  453.         // Check the first and last tag -> if first and last caracters are " " space remove them!!!"
  454.  
  455.         if ((count($aLine0&& ($aExtraInfo['LAST_LINE_BR'== "AUTO")){
  456.             //first tag
  457.             $temp $aLine[0];
  458.             if ( (strlen($temp['text']0&& ($temp['text'][0== " ")){
  459.                 $temp['text'substr($temp['text']1strlen($temp['text']));
  460.                 $temp['width'-= $fw$temp['tag'] ]['w'][" "$fw$temp['tag'] ]['s'];
  461.                 $temp['spaces'--;
  462.             }
  463.  
  464.             //last tag
  465.             $temp $aLine[count($aLine1];
  466.             if ( (strlen($temp['text'])>0&& ($temp['text'][strlen($temp['text'])-1== " ")){
  467.                 $temp['text'substr($temp['text']0strlen($temp['text']1);
  468.                 $temp['width'-= $fw$temp['tag'] ]['w'][" "$fw$temp['tag'] ]['s'];
  469.                 $temp['spaces'--;
  470.             }
  471.         }
  472.  
  473.         if ($reset_spaces){//this is used in case of a "Explicit Line Break"
  474.             //put all spaces to 0 so in case of "J" align there is no space extension
  475.             for ($k=0$kcount($aLine)$k++$aLine[$k]['spaces'0;
  476.         }//fi
  477.  
  478.         return $aLine;
  479.     }//function mt_MakeLine
  480.  
  481.  
  482.     /**
  483.      * Draws a MultiCell with TAG recognition parameters
  484.      *
  485.      * @access     protected
  486.      * @param     numeric $w - with of the cell
  487.      * @param    numeric $h - height of the lines in the cell
  488.      * @param     string $pData - string or formatted data to be putted in the multicell
  489.      * @param    string or numeric $border
  490.      *                  Indicates if borders must be drawn around the cell block. The value can be either a number:
  491.      *                          0 = no border
  492.      *                          1 = frame border
  493.      *                  or a string containing some or all of the following characters (in any order):
  494.      *                          L: left
  495.      *                          T: top
  496.      *                          R: right
  497.      *                          B: bottom
  498.      * @param    string $align - Sets the text alignment
  499.      *                  Possible values:
  500.      *                          L: left
  501.      *                          R: right
  502.      *                          C: center
  503.      *                          J: justified
  504.      * @param    numeric $fill - Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  505.      * @param     numeric $pad_left - Left pad
  506.      * @param    numeric $pad_top - Top pad
  507.      * @param    numeric $pad_right - Right pad
  508.      * @param    numeric $pad_bottom - Bottom pad
  509.      * @param    boolean $pDataIsString 
  510.      *                          - true if $pData is a string
  511.      *                         - false if $pData is an array containing lines formatted with $this->mt_MakeLine($w) function
  512.      *                              (the false option is used in relation with mt_StringToLines, to avoid double formatting of a string
  513.      * @return     void 
  514.      */
  515.     public function MultiCellTag($w$h$pData$border=0$align='J'$fill=0$pad_left=0$pad_top=0$pad_right=0$pad_bottom=0$pDataIsString true){    
  516.         
  517.         $aRecData $this->mt_StringToLines($w$pData);
  518.         $iCounter 9999/*avoid infinite loop for any reasons*/
  519.         
  520.         $doBreak false;
  521.         
  522.         do
  523.             $iLeftHeight $this->$this->bMargin $this->GetY($pad_top $pad_bottom;
  524.             $bAddNewPage false;
  525.             
  526.             //Numer of rows that have space on this page:
  527.             $iRows floor($iLeftHeight $h);
  528.             if count($aRecData$iRows){
  529.                 $aSendData array_slice($aRecData0$iRows);
  530.                 $aRecData array_slice($aRecData$iRows);
  531.                 $bAddNewPage true;
  532.             }else{
  533.                 $aSendData &$aRecData;
  534.                 $doBreak true;    
  535.             }
  536.             
  537.             $this->MultiCellTagSec($w$h$aSendData$border$align$fill$pad_left$pad_top$pad_right$pad_bottomfalse);
  538.             
  539.             if (true == $bAddNewPage){
  540.                 $this->beforeAddPage();
  541.                 $this->AddPage();
  542.                 $this->afterAddPage();
  543.             }
  544.         
  545.         }while ((($iCounter--0&& false == $doBreak) );
  546.     }//public function MultiCellTag
  547.     
  548.     
  549.     /**
  550.      * Draws a MultiCell with TAG recognition parameters
  551.      *
  552.      * @access     protected
  553.      * @param     numeric $w - with of the cell
  554.      * @param    numeric $h - height of the lines in the cell
  555.      * @param     string $pData - string or formatted data to be putted in the multicell
  556.      * @param    string or numeric $border
  557.      *                  Indicates if borders must be drawn around the cell block. The value can be either a number:
  558.      *                          0 = no border
  559.      *                          1 = frame border
  560.      *                  or a string containing some or all of the following characters (in any order):
  561.      *                          L: left
  562.      *                          T: top
  563.      *                          R: right
  564.      *                          B: bottom
  565.      * @param    string $align - Sets the text alignment
  566.      *                  Possible values:
  567.      *                          L: left
  568.      *                          R: right
  569.      *                          C: center
  570.      *                          J: justified
  571.      * @param    numeric $fill - Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  572.      * @param     numeric $pad_left - Left pad
  573.      * @param    numeric $pad_top - Top pad
  574.      * @param    numeric $pad_right - Right pad
  575.      * @param    numeric $pad_bottom - Bottom pad
  576.      * @param    boolean $pDataIsString 
  577.      *                          - true if $pData is a string
  578.      *                         - false if $pData is an array containing lines formatted with $this->mt_MakeLine($w) function
  579.      *                              (the false option is used in relation with mt_StringToLines, to avoid double formatting of a string
  580.      * @return     void 
  581.      */    
  582.     protected function MultiCellTagSec($w$h$pData$border=0$align='J'$fill=0$pad_left=0$pad_top=0$pad_right=0$pad_bottom=0$pDataIsString true){
  583.  
  584.         //save the current style settings, this will be the default in case of no style is specified
  585.         $this->mt_SaveCurrentStyle();
  586.         $this->mt_Reset_Datas();
  587.         
  588.         //if data is string
  589.         if ($pDataIsString === true$this->mt_DivideByTags($pData);
  590.  
  591.         $b $b1 $b2 $b3 '';//borders
  592.         
  593.         if($w==0)
  594.             $w $this->$this->rMargin $this->x;        
  595.         
  596.         /**
  597.          * If the vertical padding is bigger than the width then we ignore it
  598.          * In this case we put them to 0.
  599.          */
  600.         if ( ($pad_left+$pad_right$w{
  601.             $pad_left 0;
  602.             $pad_right 0;
  603.         }
  604.         
  605.         $w_text $w $pad_left $pad_right;
  606.  
  607.         //save the current X position, we will have to jump back!!!!
  608.         $startX $this -> GetX();
  609.  
  610.         if($border)
  611.         {
  612.             if($border==1)
  613.             {
  614.                 $border 'LTRB';
  615.                 $b1 'LRT';//without the bottom
  616.                 $b2 'LR';//without the top and bottom
  617.                 $b3 'LRB';//without the top
  618.             }
  619.             else
  620.             {
  621.                 $b2='';
  622.                 if(is_int(strpos($border,'L')))
  623.                     $b2.='L';
  624.                 if(is_int(strpos($border,'R')))
  625.                     $b2.='R';
  626.                 $b1=is_int(strpos($border,'T')) $b2 'T' $b2;
  627.                 $b3=is_int(strpos($border,'B')) $b2 'B' $b2;
  628.             }
  629.  
  630.             //used if there is only one line
  631.             $b '';
  632.             $b .= is_int(strpos($border,'L')) 'L' "";
  633.             $b .= is_int(strpos($border,'R')) 'R' "";
  634.             $b .= is_int(strpos($border,'T')) 'T' "";
  635.             $b .= is_int(strpos($border,'B')) 'B' "";
  636.         }
  637.  
  638.         $first_line true;
  639.         $last_line false;
  640.         
  641.         if ($pDataIsString === true){
  642.             $last_line !(count($this->wt_DataInfo0);
  643.         }else {
  644.             $last_line !(count($pData0);
  645.         }
  646.                                                                       
  647.         while(!$last_line){
  648.             
  649.             if ($first_line && ($pad_top 0)){
  650.                 /**
  651.                  * If this is the first line and there is top_padding
  652.                  */
  653.                 $this->MultiCell($w$pad_top''$b1$align1);
  654.                 $b1 str_replace('T'''$b1);
  655.                 $b str_replace('T'''$b);
  656.             }
  657.             
  658.             if ($fill == 1){
  659.                 //fill in the cell at this point and write after the text without filling
  660.                 $this->Cell($w,$h,"",0,0,"",1);
  661.                 $this->SetX($startX);//restore the X position
  662.             }
  663.  
  664.             if ($pDataIsString === true){
  665.                 //make a line
  666.                 $str_data $this->mt_MakeLine($w_text);
  667.                 //check for last line
  668.                 $last_line !(count($this->wt_DataInfo0);
  669.             }else {
  670.                 //make a line
  671.                 $str_data array_shift($pData);
  672.                 //check for last line
  673.                 $last_line !(count($pData0);
  674.             }
  675.  
  676.             if ($last_line && ($align == "J")){//do not Justify the Last Line
  677.                 $align "L";
  678.             }
  679.  
  680.             /**
  681.              * Restore the X position with the corresponding padding if it exist
  682.              * The Right padding is done automatically by calculating the width of the text
  683.              */
  684.             $this->SetX$startX $pad_left );
  685.             $this->mt_PrintLine($w_text$h$str_data$align);
  686.             
  687.             //check if there is engough space on the current page
  688.             $currentY $this->getY();
  689.             $restHeight = (int) $this->$this->tMargin $this->bMargin;
  690.             //$restHeight -= $h;
  691.             
  692.             
  693.             //echo "$currentY - $restHeight<br>";
  694.             
  695.             //$restHeight -= 
  696.             /**/
  697.             
  698.             /*
  699.             if ($currentY > $restHeight){
  700.                 //die();
  701.                 $this->AddPage();
  702.             }
  703.             */
  704.             
  705.             if ($currentY 170){
  706.                 //die();
  707.                 //$this->AddPage();
  708.                 //$last_line = true;
  709.             }
  710.             
  711.             
  712.             //see what border we draw:
  713.             if($first_line && $last_line){
  714.                 //we have only 1 line
  715.                 $real_brd $b;
  716.             }elseif($first_line){
  717.                 $real_brd $b1;
  718.             }elseif($last_line){
  719.                 $real_brd $b3;
  720.             }else{
  721.                 $real_brd $b2;
  722.             }
  723.             
  724.             if ($last_line && ($pad_bottom 0)){
  725.                 /**
  726.                  * If we have bottom padding then the border and the padding is outputted
  727.                  */
  728.                 $this->SetX($startX);//restore the X
  729.                 $this->Cell($w,$h,"",$b2,2);
  730.                 $this->SetX($startX);//restore the X
  731.                 $this->MultiCell($w$pad_bottom''$real_brd$align1);
  732.             }else{                            
  733.                 //draw the border and jump to the next line
  734.                 $this->SetX($startX);//restore the X
  735.                 $this->Cell($w,$h,"",$real_brd,2);
  736.             }
  737.             
  738.  
  739.             if ($first_line$first_line false;                                
  740.         }//while(! $last_line){
  741.  
  742.         //APPLY THE DEFAULT STYLE
  743.         $this->mt_ApplyStyle("DEFAULT");
  744.  
  745.         $this->x=$this->lMargin;
  746.     }//function MultiCellExt
  747.  
  748.  
  749.     /**
  750.         This method divides the string into the tags and puts the result into wt_DataInfo variable.
  751.         @param        $pStr - string to be printed
  752.         @return     void
  753.     */
  754.  
  755.     /**
  756.      * This method divides the string into the tags and puts the result into wt_DataInfo variable.
  757.      *
  758.      * @access     protected
  759.      * @param     string $pStr - string to be parsed
  760.      * @param    boolean $return - ==TRUE if the result is returned or not
  761.      * @return    struct or void
  762.      */
  763.     protected function mt_DivideByTags($pStr$return false){
  764.  
  765.         $pStr str_replace("\t""<ttags>\t</ttags>"$pStr);
  766.         $pStr str_replace(PARAGRAPH_STRING"<pparg>\t</pparg>"$pStr);
  767.         $pStr str_replace("\r"""$pStr);
  768.  
  769.         //initialize the string_tags class
  770.         $sWork new string_tags(5);
  771.  
  772.         //get the string divisions by tags
  773.         $this->wt_DataInfo = $sWork->get_tags($pStr);
  774.                
  775.         if ($returnreturn $this->wt_DataInfo;
  776.     }//function mt_DivideByTags($pStr){
  777.     
  778.     /**
  779.      * This method parses the current text and return an array that contains the text information for
  780.      * each line that will be drawed.
  781.      *
  782.      * @access     protected
  783.      * @param     numeric $w - width of the line
  784.      * @param    string $pStr - String to be parsed
  785.      * @return     array $aStrLines - contains parsed text information.
  786.      */
  787.     protected function mt_StringToLines($w 0$pStr){
  788.  
  789.         //save the current style settings, this will be the default in case of no style is specified
  790.         $this->mt_SaveCurrentStyle();
  791.         $this->mt_Reset_Datas();
  792.         
  793.         $this->mt_DivideByTags($pStr);
  794.              
  795.         $last_line !(count($this->wt_DataInfo0);
  796.         
  797.         $aStrLines array();
  798.  
  799.         while (!$last_line){
  800.  
  801.             //make a line
  802.             $str_data $this->mt_MakeLine($w);
  803.             array_push($aStrLines$str_data);
  804.  
  805.             //check for last line
  806.             $last_line !(count($this->wt_DataInfo0);
  807.         }//while(! $last_line){
  808.  
  809.         //APPLY THE DEFAULT STYLE
  810.         $this->mt_ApplyStyle("DEFAULT");
  811.  
  812.         return $aStrLines;
  813.     }//function mt_StringToLines    
  814.  
  815.     
  816.     /**
  817.      * Draws a Tag Based formatted line returned from mt_MakeLine function into the pdf document
  818.      *
  819.      * @access     protected
  820.      * @param     numeric $w - width of the text
  821.      * @param    numeric $h - height of a line
  822.      * @param     string $aTxt - text to be draw
  823.      * @param    string $align - align of the text
  824.      * @return    void 
  825.      */
  826.     protected function mt_PrintLine($w$h$aTxt$align='J'){
  827.  
  828.         if($w==0)
  829.             $w=$this->w-$this->rMargin $this->x;
  830.  
  831.         $wmax $w//Maximum width
  832.  
  833.         $total_width 0;    //the total width of all strings
  834.         $total_spaces 0;    //the total number of spaces
  835.  
  836.         $nr count($aTxt);//number of elements
  837.  
  838.         for ($i=0$i<$nr$i++){
  839.             $total_width += ($aTxt[$i]['width']/1000);
  840.             $total_spaces += $aTxt[$i]['spaces'];
  841.         }
  842.  
  843.         //default
  844.         $w_first $this->cMargin;
  845.  
  846.         switch($align){
  847.             case 'J':
  848.                 if ($total_spaces 0)
  849.                     $extra_space ($wmax $this->cMargin $total_width$total_spaces;
  850.                 else $extra_space 0;
  851.                 break;
  852.             case 'L':
  853.                 break;
  854.             case 'C':
  855.                 $w_first ($wmax $total_width2;
  856.                 break;
  857.             case 'R':
  858.                 $w_first $wmax $total_width $this->cMargin;;
  859.                 break;
  860.         }
  861.  
  862.         // Output the first Cell
  863.         if ($w_first != 0){
  864.             $this->Cell($w_first$h""00"L"0);
  865.         }
  866.  
  867.         $last_width $wmax $w_first;
  868.  
  869.         while (list($key$valeach($aTxt)) {
  870.             
  871.             $bYPosUsed false;
  872.                        
  873.             //apply current tag style
  874.             $this->mt_ApplyStyle($val['tag']);
  875.  
  876.             //If > 0 then we will move the current X Position
  877.             $extra_X 0;
  878.             
  879.             if ($val['ypos'!= 0){
  880.                 $lastY $this->y;
  881.                 $this->$lastY $val['ypos'];
  882.                 $bYPosUsed true;
  883.             }
  884.  
  885.             //string width
  886.             $width $this->GetStringWidth($val['text']);
  887.             $width $val['width'1000;
  888.  
  889.             if ($width == 0continue;// No width jump over!!!
  890.  
  891.             if($align=='J'){
  892.                 if ($val['spaces'1$temp_X 0;
  893.                 else $temp_X $extra_space;
  894.  
  895.                 $this->ws $temp_X;
  896.  
  897.                 $this->_out(sprintf('%.3f Tw'$temp_X $this->k));
  898.  
  899.                 $extra_X $extra_space $val['spaces'];//increase the extra_X Space
  900.  
  901.             }else{
  902.                 $this->ws 0;
  903.                 $this->_out('0 Tw');
  904.             }//fi
  905.  
  906.             //Output the Text/Links
  907.             $this->Cell($width$h$val['text']00"C"0$val['href']);
  908.  
  909.             $last_width -= $width;//last column width
  910.  
  911.             if ($extra_X != 0){
  912.                 $this -> SetX($this->GetX($extra_X);
  913.                 $last_width -= $extra_X;
  914.             }//fi
  915.             
  916.             if ($bYPosUsed$this->$lastY;
  917.             
  918.         }//while
  919.  
  920.         // Output the Last Cell
  921.         if ($last_width != 0){
  922.             $this->Cell($last_width$h""00""0);
  923.         }//fi
  924.     }//function mt_PrintLine
  925.     
  926.     
  927.     /**
  928.      * Function executed BEFORE a new page is added for further actions on the current page.
  929.      * Usually overwritted.
  930.      *
  931.      * @access     public
  932.      * @return     void 
  933.      */
  934.     public function beforeAddPage(){
  935.         /*
  936.             TODO:
  937.             place your code here */
  938.     }// function beforeAddPage
  939.  
  940.     /**
  941.      * Function executed AFTER a new page is added for pre - actions on the current page.
  942.      * Usually overwritted.
  943.      *
  944.      * @access     public
  945.      * @return     void 
  946.      */
  947.     public function afterAddPage(){
  948.         /*
  949.             TODO:
  950.             place your code here */
  951.     }// function afterAddPage
  952.  
  953.     
  954. }//class
  955.  
  956. ?>

Documentation generated on Wed, 04 Feb 2009 22:01:33 +0100 by phpDocumentor 1.4.0a2