示例#1
0
 /**
  * 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 = $this->createSubHTML();
     $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]->getName() == 'write') {
         $txt = $sub->parsingHtml->code[$this->_parsePos]->getParam('txt');
         $txt = str_replace('[[page_cu]]', $sub->pdf->getMyNumPage($this->_page), $txt);
         $sub->parsingHtml->code[$this->_parsePos]->setParam('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);
     } elseif ($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);
     }
 }