예제 #1
0
파일: html2pdf.class.php 프로젝트: rzt/lms
 /**
  * calculate the start position of the next line,  depending on the text-align
  *
  * @access protected
  * @param  integer $curr real current position in the text, if new line in the write of a text
  */
 protected function _setNewPositionForNewLine($curr = null)
 {
     // get the margins for the current line
     list($lx, $rx) = $this->_getMargins($this->pdf->getY());
     $this->pdf->setX($lx);
     $wMax = $rx - $lx;
     $this->_currentH = 0;
     // if subPart => return because align left
     if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) {
         $this->pdf->setWordSpacing(0);
         return null;
     }
     // create the sub object
     $sub = null;
     $this->_createSubHTML($sub);
     $sub->_saveMargin(0, 0, $sub->pdf->getW() - $wMax);
     $sub->_isForOneLine = true;
     $sub->_parsePos = $this->_parsePos;
     $sub->parsingHtml->code = $this->parsingHtml->code;
     // if $curr => adapt the current position of the parsing
     if ($curr !== null && $sub->parsingHtml->code[$this->_parsePos]['name'] == 'write') {
         $txt = $sub->parsingHtml->code[$this->_parsePos]['param']['txt'];
         $txt = str_replace('[[page_cu]]', $sub->pdf->getMyNumPage($this->_page), $txt);
         $sub->parsingHtml->code[$this->_parsePos]['param']['txt'] = substr($txt, $curr + 1);
     } else {
         $sub->_parsePos++;
     }
     // for each element of the parsing => load the action
     $res = null;
     for ($sub->_parsePos; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) {
         $action = $sub->parsingHtml->code[$sub->_parsePos];
         $res = $sub->_executeAction($action);
         if (!$res) {
             break;
         }
     }
     $w = $sub->_maxX;
     // max width
     $h = $sub->_maxH;
     // max height
     $e = $res === null ? $sub->_maxE : 0;
     // maxnumber of elemets on the line
     // destroy the sub HTML
     $this->_destroySubHTML($sub);
     // adapt the start of the line, depending on the text-align
     if ($this->parsingCss->value['text-align'] == 'center') {
         $this->pdf->setX(($rx + $this->pdf->getX() - $w) * 0.5 - 0.01);
     } else {
         if ($this->parsingCss->value['text-align'] == 'right') {
             $this->pdf->setX($rx - $w - 0.01);
         } else {
             $this->pdf->setX($lx);
         }
     }
     // set the height of the line
     $this->_currentH = $h;
     // if justify => set the word spacing
     if ($this->parsingCss->value['text-align'] == 'justify' && $e > 1) {
         $this->pdf->setWordSpacing(($wMax - $w) / ($e - 1));
     } else {
         $this->pdf->setWordSpacing(0);
     }
 }