/kernelActividades/application/fpdf/class.multicelltag.php

https://bitbucket.org/punketo28/sistema-de-control-de-actividades-del-poa · PHP · 859 lines · 410 code · 157 blank · 292 comment · 117 complexity · d1bd4b7a9464a8cab6d131595c5ad478 MD5 · raw file

  1. <?php
  2. /**
  3. * FPDF Tag Based Multicell - FPDF class extension
  4. * Copyright (c) 2005-2010, http://www.interpid.eu
  5. *
  6. * FPDF Tag Based Multicell is licensed under the terms of the GNU Open Source GPL 3.0
  7. * license.
  8. *
  9. * Commercial use is prohibited. Visit <http://www.interpid.eu/fpdf-components>
  10. * if you need to obtain a commercial license.
  11. *
  12. * This program is free software: you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free Software
  14. * Foundation, either version 3 of the License, or any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License along with
  22. * this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
  23. *
  24. *
  25. * Version: 1.4.2
  26. * Date: 2005/12/08
  27. * Last Modification: 2008/02/24
  28. * Author: Bintintan Andrei <andy@interpid.eu>
  29. /**
  30. Modifications:
  31. 2007.01.21
  32. - added left, top, right and bottom padding to the MultiCellTag Functions
  33. 2006.09.18
  34. - added YPOS parameter to the tab for super/subscript posibility. ypos = '-1' means the relative position to the normal Y.
  35. 2006.07.30
  36. - added Paragraph Support(a sort of) - paragraphs can be specified with size='integer value' and PARAGRAPH_STRING character
  37. 2006.05.18
  38. - removed the NBLines functions
  39. - added mt_StringToLines function
  40. - modified MultiCellTag to accept as data parameter an array type like the return from mt_StringToLines function
  41. - these modifications does not affect the main class behavior, they are used for further developement and class extensions
  42. */
  43. //require_once(dirname(__FILE__).'/class.fpdf.php');
  44. //require_once(dirname(__FILE__).'/class.string_tags.php');
  45. require_once(APPPATH.'fpdf/class.fpdf.php');
  46. require_once(APPPATH.'fpdf/class.string_tags.php');
  47. if (!defined('PARAGRAPH_STRING')) define('PARAGRAPH_STRING', '~~~');
  48. /**
  49. * MultiCellTag Class
  50. * The intern functions are prefaced with mt_, not be be overwritten
  51. *
  52. * @author andy@interpid.eu
  53. * @version 1.4
  54. *
  55. */
  56. class fpdf_multicelltag extends FPDF{
  57. /**
  58. * Valid Tag Maximum Width
  59. *
  60. * @access protected
  61. * @var integer
  62. */
  63. protected $wt_TagWidthMax = 10;
  64. /**
  65. * The current active tag
  66. *
  67. * @access protected
  68. * @var string
  69. */
  70. protected $wt_Current_Tag = '';
  71. /**
  72. * Tags Font Information
  73. *
  74. * @access protected
  75. * @var struct
  76. */
  77. protected $wt_FontInfo;
  78. /**
  79. * Parsed string data info
  80. *
  81. * @access protected
  82. * @var struct
  83. */
  84. protected $wt_DataInfo;
  85. /**
  86. * Data Extra Info
  87. *
  88. * @access protected
  89. * @var struct
  90. */
  91. protected $wt_DataExtraInfo;
  92. /**
  93. * Temporary Info
  94. *
  95. * @access protected
  96. * @var struct
  97. */
  98. protected $wt_TempData;
  99. /**
  100. * Sets the Tags Maximum width
  101. *
  102. * @access public
  103. * @param numeric $iWidth - the width of the tags
  104. * @return void
  105. */
  106. public function setTagWidthMax($iWidth = 10){
  107. $this->wt_TagWidthMax = $iWidth;
  108. }
  109. /**
  110. * Resets the current class internal variables to default values
  111. *
  112. * @access protected
  113. * @param none
  114. * @return void
  115. */
  116. protected function mt_Reset_Datas(){
  117. $this->wt_Current_Tag = "";
  118. $this->wt_DataInfo = array();
  119. $this->wt_DataExtraInfo = array(
  120. "LAST_LINE_BR" => "", //CURRENT LINE BREAK TYPE
  121. "CURRENT_LINE_BR" => "", //LAST LINE BREAK TYPE
  122. "TAB_WIDTH" => 10 //The tab WIDTH IS IN mm
  123. );
  124. //if another measure unit is used ... calculate your OWN
  125. $this->wt_DataExtraInfo["TAB_WIDTH"] *= (72/25.4) / $this->k;
  126. /*
  127. $this->wt_FontInfo - do not reset, once read ... is OK!!!
  128. */
  129. }//function mt_Reset_Datas(){
  130. /**
  131. * Sets current tag to specified style
  132. *
  133. * @access public
  134. * @param string $tag - tag name
  135. * @param string $family - text font family name
  136. * @param string $style - text font style
  137. * @param numeric $size - text font size
  138. * @param array $color - text color
  139. * @return void
  140. */
  141. public function SetStyle($tag, $family, $style, $size, $color)
  142. {
  143. if ($tag == "ttags") $this->Error (">> ttags << is reserved TAG Name.");
  144. if ($tag == "") $this->Error ("Empty TAG Name.");
  145. //use case insensitive tags
  146. $tag=trim(strtoupper($tag));
  147. $this->TagStyle[$tag]['family']=trim($family);
  148. $this->TagStyle[$tag]['style']=trim($style);
  149. $this->TagStyle[$tag]['size']=trim($size);
  150. $this->TagStyle[$tag]['color']=trim($color);
  151. }//function SetStyle
  152. /**
  153. * Sets current tag to specified style
  154. * - if the tag name is not in the tag list then de "DEFAULT" tag is saved.
  155. * This includes a fist call of the function mt_SaveCurrentStyle()
  156. *
  157. * @access protected
  158. * @param string $tag - tag name
  159. * @return void
  160. */
  161. protected function mt_ApplyStyle($tag){
  162. //use case insensitive tags
  163. $tag=trim(strtoupper($tag));
  164. if ($this->wt_Current_Tag == $tag) return;
  165. if (($tag == "") || (! isset($this->TagStyle[$tag]))) $tag = "DEFAULT";
  166. $this->wt_Current_Tag = $tag;
  167. $style = & $this->TagStyle[$tag];
  168. if (isset($style)){
  169. $this->SetFont($style['family'], $style['style'], $style['size']);
  170. //this is textcolor in FPDF format
  171. if (isset($style['textcolor_fpdf'])) {
  172. $this->TextColor = $style['textcolor_fpdf'];
  173. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  174. }else
  175. {
  176. if ($style['color'] <> ""){//if we have a specified color
  177. $temp = explode(",", $style['color']);
  178. $this->SetTextColor($temp[0], $temp[1], $temp[2]);
  179. }//fi
  180. }
  181. /**/
  182. }//isset
  183. }//function mt_ApplyStyle($tag){
  184. /**
  185. * Save the current settings as a tag default style under the DEFAUTLT tag name
  186. *
  187. * @access protected
  188. * @param none
  189. * @return void
  190. */
  191. protected function mt_SaveCurrentStyle(){
  192. $this->TagStyle['DEFAULT']['family'] = $this->FontFamily;;
  193. $this->TagStyle['DEFAULT']['style'] = $this->FontStyle;
  194. $this->TagStyle['DEFAULT']['size'] = $this->FontSizePt;
  195. $this->TagStyle['DEFAULT']['textcolor_fpdf'] = $this->TextColor;
  196. $this->TagStyle['DEFAULT']['color'] = "";
  197. }//function mt_SaveCurrentStyle
  198. /**
  199. * Divides $this->wt_DataInfo and returnes a line from this variable
  200. *
  201. * @access protected
  202. * @param numeric $w - the width of the text
  203. * @return array $aLine - array() -> contains informations to draw a line
  204. */
  205. protected function mt_MakeLine($w){
  206. $aDataInfo = & $this->wt_DataInfo;
  207. $aExtraInfo = & $this->wt_DataExtraInfo;
  208. //last line break >> current line break
  209. $aExtraInfo['LAST_LINE_BR'] = $aExtraInfo['CURRENT_LINE_BR'];
  210. $aExtraInfo['CURRENT_LINE_BR'] = "";
  211. if($w==0)
  212. $w=$this->w - $this->rMargin - $this->x;
  213. $wmax = ($w - 2*$this->cMargin) * 1000;//max width
  214. $aLine = array();//this will contain the result
  215. $return_result = false;//if break and return result
  216. $reset_spaces = false;
  217. $line_width = 0;//line string width
  218. $total_chars = 0;//total characters included in the result string
  219. $space_count = 0;//numer of spaces in the result string
  220. $fw = & $this->wt_FontInfo;//font info array
  221. $last_sepch = ""; //last separator character
  222. foreach ($aDataInfo as $key => $val){
  223. $s = $val['text'];
  224. $tag = &$val['tag'];
  225. $bParagraph = false;
  226. if (($s == "\t") && ($tag == 'pparg')){
  227. $bParagraph = true;
  228. $s = "\t";//place instead a TAB
  229. }
  230. $s_lenght=strlen($s);
  231. $i = 0;//from where is the string remain
  232. $j = 0;//untill where is the string good to copy -- leave this == 1->> copy at least one character!!!
  233. $str = "";
  234. $s_width = 0; //string width
  235. $last_sep = -1; //last separator position
  236. $last_sepwidth = 0;
  237. $last_sepch_width = 0;
  238. $ante_last_sep = -1; //ante last separator position
  239. $spaces = 0;
  240. //parse the whole string
  241. while ($i < $s_lenght){
  242. $c = $s[$i];
  243. if($c == "\n"){//Explicit line break
  244. $i++; //ignore/skip this caracter
  245. $aExtraInfo['CURRENT_LINE_BR'] = "BREAK";
  246. $return_result = true;
  247. $reset_spaces = true;
  248. break;
  249. }
  250. //space
  251. if($c == " "){
  252. $space_count++;//increase the number of spaces
  253. $spaces ++;
  254. }
  255. // Font Width / Size Array
  256. if (!isset($fw[$tag]) || ($tag == "")){
  257. //if this font was not used untill now,
  258. $this->mt_ApplyStyle($tag);
  259. $fw[$tag]['w'] = $this->CurrentFont['cw'];//width
  260. $fw[$tag]['s'] = $this->FontSize;//size
  261. }
  262. $char_width = $fw[$tag]['w'][$c] * $fw[$tag]['s'];
  263. //separators
  264. if(is_int(strpos(" ,.:;",$c))){
  265. $ante_last_sep = $last_sep;
  266. $ante_last_sepch = $last_sepch;
  267. $ante_last_sepwidth = $last_sepwidth;
  268. $ante_last_sepch_width = $last_sepch_width;
  269. $last_sep = $i;//last separator position
  270. $last_sepch = $c;//last separator char
  271. $last_sepch_width = $char_width;//last separator char
  272. $last_sepwidth = $s_width;
  273. }
  274. if ($c == "\t"){//TAB
  275. $c = $s[$i] = "";
  276. $char_width = $aExtraInfo['TAB_WIDTH'] * 1000;
  277. }
  278. if ($bParagraph == true){
  279. $c = $s[$i] = "";
  280. $char_width = $this->wt_TempData['LAST_TAB_REQSIZE']*1000 - $this->wt_TempData['LAST_TAB_SIZE'];
  281. if ($char_width < 0) $char_width = 0;
  282. }
  283. $line_width += $char_width;
  284. if($line_width > $wmax){//Automatic line break
  285. $aExtraInfo['CURRENT_LINE_BR'] = "AUTO";
  286. if ($total_chars == 0) {
  287. /* This MEANS that the $w (width) is lower than a char width...
  288. Put $i and $j to 1 ... otherwise infinite while*/
  289. $i = 1;
  290. $j = 1;
  291. $return_result = true;//YES RETURN THE RESULT!!!
  292. break;
  293. }//fi
  294. if ($last_sep <> -1){
  295. //we have a separator in this tag!!!
  296. //untill now there one separator
  297. if (($last_sepch == $c) && ($last_sepch != " ") && ($ante_last_sep <> -1)){
  298. /* this is the last character and it is a separator, if it is a space the leave it...
  299. Have to jump back to the last separator... even a space
  300. */
  301. $last_sep = $ante_last_sep;
  302. $last_sepch = $ante_last_sepch;
  303. $last_sepwidth = $ante_last_sepwidth;
  304. }
  305. if ($last_sepch == " "){
  306. $j = $last_sep;//just ignore the last space (it is at end of line)
  307. $i = $last_sep + 1;
  308. if ( $spaces > 0 ) $spaces --;
  309. $s_width = $last_sepwidth;
  310. }else{
  311. $j = $last_sep + 1;
  312. $i = $last_sep + 1;
  313. $s_width = $last_sepwidth + $last_sepch_width;
  314. }
  315. }elseif(count($aLine) > 0){
  316. //we have elements in the last tag!!!!
  317. if ($last_sepch == " "){//the last tag ends with a space, have to remove it
  318. $temp = & $aLine[ count($aLine)-1 ];
  319. if ($temp['text'][strlen($temp['text'])-1] == " "){
  320. $temp['text'] = substr($temp['text'], 0, strlen($temp['text']) - 1);
  321. $temp['width'] -= $fw[ $temp['tag'] ]['w'][" "] * $fw[ $temp['tag'] ]['s'];
  322. $temp['spaces'] --;
  323. //imediat return from this function
  324. break 2;
  325. }else{
  326. #die("should not be!!!");
  327. }//fi
  328. }//fi
  329. }//fi else
  330. $return_result = true;
  331. break;
  332. }//fi - Auto line break
  333. //increase the string width ONLY when it is added!!!!
  334. $s_width += $char_width;
  335. $i++;
  336. $j = $i;
  337. $total_chars ++;
  338. }//while
  339. $str = substr($s, 0, $j);
  340. $sTmpStr = & $aDataInfo[$key]['text'];
  341. $sTmpStr = substr($sTmpStr, $i, strlen($sTmpStr));
  342. if (($sTmpStr == "") || ($sTmpStr === FALSE))//empty
  343. array_shift($aDataInfo);
  344. if ($val['text'] == $str){
  345. }
  346. if (!isset($val['href'])) $val['href']='';
  347. if (!isset($val['ypos'])) $val['ypos']=0;
  348. //we have a partial result
  349. array_push($aLine, array(
  350. 'text' => $str,
  351. 'tag' => $val['tag'],
  352. 'href' => $val['href'],
  353. 'width' => $s_width,
  354. 'spaces' => $spaces,
  355. 'ypos' => $val['ypos']
  356. ));
  357. $this->wt_TempData['LAST_TAB_SIZE'] = $s_width;
  358. $this->wt_TempData['LAST_TAB_REQSIZE'] = (isset($val['size'])) ? $val['size'] : 0;
  359. if ($return_result) break;//break this for
  360. }//foreach
  361. // Check the first and last tag -> if first and last caracters are " " space remove them!!!"
  362. if ((count($aLine) > 0) && ($aExtraInfo['LAST_LINE_BR'] == "AUTO")){
  363. //first tag
  364. $temp = & $aLine[0];
  365. if ( (strlen($temp['text']) > 0) && ($temp['text'][0] == " ")){
  366. $temp['text'] = substr($temp['text'], 1, strlen($temp['text']));
  367. $temp['width'] -= $fw[ $temp['tag'] ]['w'][" "] * $fw[ $temp['tag'] ]['s'];
  368. $temp['spaces'] --;
  369. }
  370. //last tag
  371. $temp = & $aLine[count($aLine) - 1];
  372. if ( (strlen($temp['text'])>0) && ($temp['text'][strlen($temp['text'])-1] == " ")){
  373. $temp['text'] = substr($temp['text'], 0, strlen($temp['text']) - 1);
  374. $temp['width'] -= $fw[ $temp['tag'] ]['w'][" "] * $fw[ $temp['tag'] ]['s'];
  375. $temp['spaces'] --;
  376. }
  377. }
  378. if ($reset_spaces){//this is used in case of a "Explicit Line Break"
  379. //put all spaces to 0 so in case of "J" align there is no space extension
  380. for ($k=0; $k< count($aLine); $k++) $aLine[$k]['spaces'] = 0;
  381. }//fi
  382. return $aLine;
  383. }//function mt_MakeLine
  384. /**
  385. Draws a MultiCell with TAG recognition parameters
  386. @param $w - with of the cell
  387. $h - height of the cell
  388. $pData - string or data to be printed
  389. $border - border
  390. $align - align
  391. $fill - fill
  392. $pad_left - pad left
  393. $pad_top - pad top
  394. $pad_right - pad right
  395. $pad_bottom - pad bottom
  396. $pDataIsString - true if $pData is a string
  397. - false if $pData is an array containing lines formatted with $this->mt_MakeLine($w) function
  398. (the false option is used in relation with mt_StringToLines, to avoid double formatting of a string
  399. These paramaters are the same and have the same behavior as at Multicell function
  400. @return void
  401. */
  402. /**
  403. * Draws a MultiCell with TAG recognition parameters
  404. *
  405. * @param numeric $w - with of the cell
  406. * @param numeric $h - height of the lines in the cell
  407. * @param string $pData - string or formatted data to be putted in the multicell
  408. * @param string or numeric $border
  409. * Indicates if borders must be drawn around the cell block. The value can be either a number:
  410. * 0 = no border
  411. * 1 = frame border
  412. * or a string containing some or all of the following characters (in any order):
  413. * L: left
  414. * T: top
  415. * R: right
  416. * B: bottom
  417. * @param string $align - Sets the text alignment
  418. * Possible values:
  419. * L: left
  420. * R: right
  421. * C: center
  422. * J: justified
  423. * @param numeric $fill - Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  424. * @param numeric $pad_left - Left pad
  425. * @param numeric $pad_top - Top pad
  426. * @param numeric $pad_right - Right pad
  427. * @param numeric $pad_bottom - Bottom pad
  428. * @param boolean $pDataIsString
  429. * - true if $pData is a string
  430. * - false if $pData is an array containing lines formatted with $this->mt_MakeLine($w) function
  431. * (the false option is used in relation with mt_StringToLines, to avoid double formatting of a string
  432. * @return void
  433. */
  434. 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){
  435. //save the current style settings, this will be the default in case of no style is specified
  436. $this->mt_SaveCurrentStyle();
  437. $this->mt_Reset_Datas();
  438. $utf8_decoded_here = false;
  439. //if data is string
  440. if ($pDataIsString === true) {
  441. //IF UTF8 Support is needed then
  442. if (isset($this->utf8_support) && isset($this->utf8_decoded)){
  443. if (($this->utf8_support) && (!$this->utf8_decoded)) {
  444. $pData = utf8_decode($pData);
  445. $utf8_decoded_here = true;
  446. $this->utf8_decoded = true;
  447. }
  448. }
  449. $this->mt_DivideByTags($pData);
  450. }
  451. $b = $b1 = $b2 = $b3 = '';//borders
  452. if($w==0)
  453. $w = $this->w - $this->rMargin - $this->x;
  454. /**
  455. * If the vertical padding is bigger than the width then we ignore it
  456. * In this case we put them to 0.
  457. */
  458. if ( ($pad_left+$pad_right) > $w) {
  459. $pad_left = 0;
  460. $pad_right = 0;
  461. }
  462. $w_text = $w - $pad_left - $pad_right;
  463. //save the current X position, we will have to jump back!!!!
  464. $startX = $this -> GetX();
  465. if($border)
  466. {
  467. if($border==1)
  468. {
  469. $border = 'LTRB';
  470. $b1 = 'LRT';//without the bottom
  471. $b2 = 'LR';//without the top and bottom
  472. $b3 = 'LRB';//without the top
  473. }
  474. else
  475. {
  476. $b2='';
  477. if(is_int(strpos($border,'L')))
  478. $b2.='L';
  479. if(is_int(strpos($border,'R')))
  480. $b2.='R';
  481. $b1=is_int(strpos($border,'T')) ? $b2 . 'T' : $b2;
  482. $b3=is_int(strpos($border,'B')) ? $b2 . 'B' : $b2;
  483. }
  484. //used if there is only one line
  485. $b = '';
  486. $b .= is_int(strpos($border,'L')) ? 'L' : "";
  487. $b .= is_int(strpos($border,'R')) ? 'R' : "";
  488. $b .= is_int(strpos($border,'T')) ? 'T' : "";
  489. $b .= is_int(strpos($border,'B')) ? 'B' : "";
  490. }
  491. $first_line = true;
  492. $last_line = false;
  493. if ($pDataIsString === true){
  494. $last_line = !(count($this->wt_DataInfo) > 0);
  495. }else {
  496. $last_line = !(count($pData) > 0);
  497. }
  498. while(!$last_line){
  499. if ($first_line && ($pad_top > 0)){
  500. /**
  501. * If this is the first line and there is top_padding
  502. */
  503. $this->MultiCell($w, $pad_top, '', $b1, $align, 1);
  504. $b1 = str_replace('T', '', $b1);
  505. $b = str_replace('T', '', $b);
  506. }
  507. if ($fill == 1){
  508. //fill in the cell at this point and write after the text without filling
  509. $this->Cell($w,$h,"",0,0,"",1);
  510. $this->SetX($startX);//restore the X position
  511. }
  512. if ($pDataIsString === true){
  513. //make a line
  514. $str_data = $this->mt_MakeLine($w_text);
  515. //check for last line
  516. $last_line = !(count($this->wt_DataInfo) > 0);
  517. }else {
  518. //make a line
  519. $str_data = array_shift($pData);
  520. //check for last line
  521. $last_line = !(count($pData) > 0);
  522. }
  523. if ($last_line && ($align == "J")){//do not Justify the Last Line
  524. $align = "L";
  525. }
  526. /**
  527. * Restore the X position with the corresponding padding if it exist
  528. * The Right padding is done automatically by calculating the width of the text
  529. */
  530. $this->SetX( $startX + $pad_left );
  531. $this->mt_PrintLine($w_text, $h, $str_data, $align);
  532. //see what border we draw:
  533. if($first_line && $last_line){
  534. //we have only 1 line
  535. $real_brd = $b;
  536. }elseif($first_line){
  537. $real_brd = $b1;
  538. }elseif($last_line){
  539. $real_brd = $b3;
  540. }else{
  541. $real_brd = $b2;
  542. }
  543. if ($last_line && ($pad_bottom > 0)){
  544. /**
  545. * If we have bottom padding then the border and the padding is outputted
  546. */
  547. $this->SetX($startX);//restore the X
  548. $this->Cell($w,$h,"",$b2,2);
  549. $this->SetX($startX);//restore the X
  550. $this->MultiCell($w, $pad_bottom, '', $real_brd, $align, 1);
  551. }else{
  552. //draw the border and jump to the next line
  553. $this->SetX($startX);//restore the X
  554. $this->Cell($w,$h,"",$real_brd,2);
  555. }
  556. if ($first_line) $first_line = false;
  557. }//while(! $last_line){
  558. //APPLY THE DEFAULT STYLE
  559. $this->mt_ApplyStyle("DEFAULT");
  560. $this->x=$this->lMargin;
  561. //UTF8 Support
  562. if (isset($this->utf8_support) && isset($this->utf8_decoded)){
  563. if (true == $utf8_decoded_here) $this->utf8_decoded = false;
  564. }
  565. }//function MultiCellExt
  566. /**
  567. This method divides the string into the tags and puts the result into wt_DataInfo variable.
  568. @param $pStr - string to be printed
  569. @return void
  570. */
  571. /**
  572. * This method divides the string into the tags and puts the result into wt_DataInfo variable.
  573. *
  574. * @access protected
  575. * @param string $pStr - string to be parsed
  576. * @param boolean $return - ==TRUE if the result is returned or not
  577. * @return struct or void
  578. */
  579. protected function mt_DivideByTags($pStr, $return = false){
  580. $pStr = str_replace("\t", "<ttags>\t</ttags>", $pStr);
  581. $pStr = str_replace(PARAGRAPH_STRING, "<pparg>\t</pparg>", $pStr);
  582. $pStr = str_replace("\r", "", $pStr);
  583. //initialize the string_tags class
  584. $sWork = new string_tags(5);
  585. //get the string divisions by tags
  586. $this->wt_DataInfo = $sWork->get_tags($pStr);
  587. if ($return) return $this->wt_DataInfo;
  588. }//function mt_DivideByTags($pStr){
  589. /**
  590. * This method parses the current text and return an array that contains the text information for
  591. * each line that will be drawed.
  592. *
  593. * @access protected
  594. * @param numeric $w - width of the line
  595. * @param string $pStr - String to be parsed
  596. * @return array $aStrLines - contains parsed text information.
  597. */
  598. protected function mt_StringToLines($w = 0, $pStr){
  599. //save the current style settings, this will be the default in case of no style is specified
  600. $this->mt_SaveCurrentStyle();
  601. $this->mt_Reset_Datas();
  602. $this->mt_DivideByTags($pStr);
  603. $last_line = !(count($this->wt_DataInfo) > 0);
  604. $aStrLines = array();
  605. while (!$last_line){
  606. //make a line
  607. $str_data = $this->mt_MakeLine($w);
  608. array_push($aStrLines, $str_data);
  609. //check for last line
  610. $last_line = !(count($this->wt_DataInfo) > 0);
  611. }//while(! $last_line){
  612. //APPLY THE DEFAULT STYLE
  613. $this->mt_ApplyStyle("DEFAULT");
  614. return $aStrLines;
  615. }//function mt_StringToLines
  616. /**
  617. * Draws a Tag Based formatted line returned from mt_MakeLine function into the pdf document
  618. *
  619. * @access protected
  620. * @param numeric $w - width of the text
  621. * @param numeric $h - height of a line
  622. * @param string $aTxt - text to be draw
  623. * @param string $align - align of the text
  624. * @return void
  625. */
  626. protected function mt_PrintLine($w, $h, $aTxt, $align='J'){
  627. if($w==0)
  628. $w=$this->w-$this->rMargin - $this->x;
  629. $wmax = $w; //Maximum width
  630. $total_width = 0; //the total width of all strings
  631. $total_spaces = 0; //the total number of spaces
  632. $nr = count($aTxt);//number of elements
  633. for ($i=0; $i<$nr; $i++){
  634. $total_width += ($aTxt[$i]['width']/1000);
  635. $total_spaces += $aTxt[$i]['spaces'];
  636. }
  637. //default
  638. $w_first = $this->cMargin;
  639. switch($align){
  640. case 'J':
  641. if ($total_spaces > 0)
  642. $extra_space = ($wmax - 2 * $this->cMargin - $total_width) / $total_spaces;
  643. else $extra_space = 0;
  644. break;
  645. case 'L':
  646. break;
  647. case 'C':
  648. $w_first = ($wmax - $total_width) / 2;
  649. break;
  650. case 'R':
  651. $w_first = $wmax - $total_width - $this->cMargin;;
  652. break;
  653. }
  654. // Output the first Cell
  655. if ($w_first != 0){
  656. $this->Cell($w_first, $h, "", 0, 0, "L", 0);
  657. }
  658. $last_width = $wmax - $w_first;
  659. while (list($key, $val) = each($aTxt)) {
  660. $bYPosUsed = false;
  661. //apply current tag style
  662. $this->mt_ApplyStyle($val['tag']);
  663. //If > 0 then we will move the current X Position
  664. $extra_X = 0;
  665. if ($val['ypos'] != 0){
  666. $lastY = $this->y;
  667. $this->y = $lastY - $val['ypos'];
  668. $bYPosUsed = true;
  669. }
  670. //string width
  671. $width = $this->GetStringWidth($val['text']);
  672. $width = $val['width'] / 1000;
  673. if ($width == 0) continue;// No width jump over!!!
  674. if($align=='J'){
  675. if ($val['spaces'] < 1) $temp_X = 0;
  676. else $temp_X = $extra_space;
  677. $this->ws = $temp_X;
  678. $this->_out(sprintf('%.3f Tw', $temp_X * $this->k));
  679. $extra_X = $extra_space * $val['spaces'];//increase the extra_X Space
  680. }else{
  681. $this->ws = 0;
  682. $this->_out('0 Tw');
  683. }//fi
  684. //Output the Text/Links
  685. $this->Cell($width, $h, $val['text'], 0, 0, "C", 0, $val['href']);
  686. $last_width -= $width;//last column width
  687. if ($extra_X != 0){
  688. $this -> SetX($this->GetX() + $extra_X);
  689. $last_width -= $extra_X;
  690. }//fi
  691. if ($bYPosUsed) $this->y = $lastY;
  692. }//while
  693. // Output the Last Cell
  694. if ($last_width != 0){
  695. $this->Cell($last_width, $h, "", 0, 0, "", 0);
  696. }//fi
  697. }//function mt_PrintLine
  698. }//class
  699. ?>