/**
  * Render the elements.
  *
  * @param ReportHtml $renderer
  * @param bool       $sub
  * @param bool       $inat
  *
  * @return string
  */
 public function render($renderer, $sub = false, $inat = true)
 {
     if (!empty($this->attrs["wt_style"])) {
         $renderer->setCurrentStyle($this->attrs["wt_style"]);
     }
     $this->text = $this->getStart() . $this->text;
     foreach ($this->elements as $element) {
         if (is_string($element) && $element == "footnotetexts") {
             $renderer->Footnotes();
         } elseif (is_string($element) && $element == "addpage") {
             $renderer->AddPage();
         } elseif ($element instanceof ReportBaseHtml) {
             $element->render($renderer, true, false);
         } else {
             $element->render($renderer);
         }
     }
     $this->text .= $this->getEnd();
     if ($sub) {
         return $this->text;
     }
     // If not called by an other attribute
     if ($inat) {
         $startX = $renderer->GetX();
         $startY = $renderer->GetY();
         $width = $renderer->getRemainingWidth();
         echo "<div style=\"position: absolute;top: ", $startY, "pt;", $renderer->alignRTL, ": ", $startX, "pt;width: ", $width, "pt;\">";
         $startY += $renderer->getCurrentStyleHeight() + 2;
         $renderer->SetY($startY);
     }
     echo $this->text;
     if ($inat) {
         echo "</div>\n";
     }
 }
 /**
  * Render elements.
  *
  * @param ReportHtml $renderer
  */
 public function render($renderer)
 {
     $renderer->clearPageHeader();
     foreach ($this->elements as $element) {
         $renderer->addPageHeader($element);
     }
 }
Beispiel #3
0
 /**
  * HTML line renderer
  *
  * @param ReportHtml $renderer
  */
 public function render($renderer)
 {
     if ($this->x1 == '.') {
         $this->x1 = $renderer->getX();
     }
     if ($this->y1 == '.') {
         $this->y1 = $renderer->getY();
     }
     if ($this->x2 == '.') {
         $this->x2 = $renderer->getRemainingWidth();
     }
     if ($this->y2 == '.') {
         $this->y2 = $renderer->getY();
     }
     // Vertical line
     if ($this->x1 == $this->x2) {
         echo "<div style=\"position:absolute;overflow:hidden;border-", $renderer->alignRTL, ":solid black 1pt;", $renderer->alignRTL, ":", $this->x1, "pt;top:", $this->y1 + 1, "pt;width:1pt;height:", $this->y2 - $this->y1, "pt;\"> </div>\n";
     }
     // Horizontal line
     if ($this->y1 == $this->y2) {
         echo "<div style=\"position:absolute;overflow:hidden;border-top:solid black 1pt;", $renderer->alignRTL, ":", $this->x1, "pt;top:", $this->y1 + 1, "pt;width:", $this->x2 - $this->x1, "pt;height:1pt;\"> </div>\n";
     }
     // Keep max Y updated
     // One or the other will be higher... lasy mans way...
     $renderer->addMaxY($this->y1);
     $renderer->addMaxY($this->y2);
 }
 /**
  * Render the elements.
  *
  * @param ReportHtml $renderer
  */
 public function render($renderer)
 {
     // checkFootnote
     $newelements = array();
     $lastelement = array();
     $footnote_element = array();
     // Element counter
     $cE = count($this->elements);
     //-- collapse duplicate elements
     for ($i = 0; $i < $cE; $i++) {
         $element = $this->elements[$i];
         if (is_object($element)) {
             if ($element instanceof ReportBaseText) {
                 if (!empty($footnote_element)) {
                     ksort($footnote_element);
                     foreach ($footnote_element as $links) {
                         $newelements[] = $links;
                     }
                     $footnote_element = array();
                 }
                 if (empty($lastelement)) {
                     $lastelement = $element;
                 } else {
                     // Checking if the Text has the same style
                     if ($element->getStyleName() == $lastelement->getStyleName()) {
                         $lastelement->addText(str_replace("\n", "<br>", $element->getValue()));
                     } elseif (!empty($lastelement)) {
                         $newelements[] = $lastelement;
                         $lastelement = $element;
                     }
                 }
             } elseif ($element instanceof ReportBaseFootnote) {
                 // Check if the Footnote has been set with it’s link number
                 $renderer->checkFootnote($element);
                 // Save first the last element if any
                 if (!empty($lastelement)) {
                     $newelements[] = $lastelement;
                     $lastelement = array();
                 }
                 // Save the Footnote with it’s link number as key for sorting later
                 $footnote_element[$element->num] = $element;
             } elseif (!$element instanceof ReportBaseFootnote || trim($element->getValue()) != "") {
                 if (!empty($footnote_element)) {
                     ksort($footnote_element);
                     foreach ($footnote_element as $links) {
                         $newelements[] = $links;
                     }
                     $footnote_element = array();
                 }
                 if (!empty($lastelement)) {
                     $newelements[] = $lastelement;
                     $lastelement = array();
                 }
                 $newelements[] = $element;
             }
         } else {
             if (!empty($lastelement)) {
                 $newelements[] = $lastelement;
                 $lastelement = array();
             }
             if (!empty($footnote_element)) {
                 ksort($footnote_element);
                 foreach ($footnote_element as $links) {
                     $newelements[] = $links;
                 }
                 $footnote_element = array();
             }
             $newelements[] = $element;
         }
     }
     if (!empty($lastelement)) {
         $newelements[] = $lastelement;
     }
     if (!empty($footnote_element)) {
         ksort($footnote_element);
         foreach ($footnote_element as $links) {
             $newelements[] = $links;
         }
     }
     $this->elements = $newelements;
     unset($footnote_element, $lastelement, $links, $newelements);
     $cP = 0;
     // Class Padding
     // Used with line breaks and cell height calculation within this box only
     $renderer->largestFontHeight = 0;
     // Current position
     if ($this->left == ".") {
         $cX = $renderer->GetX();
     } else {
         $cX = $this->left;
         $renderer->SetX($cX);
     }
     // Current position (top)
     if ($this->top == ".") {
         $this->top = $renderer->GetY();
     } else {
         $renderer->SetY($this->top);
     }
     // Check the width if set to page wide OR set by xml to larger then page wide
     if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) {
         $this->width = $renderer->getRemainingWidth();
     }
     // Setup the CellPadding
     if ($this->padding) {
         $cP = $renderer->cPadding;
     }
     // For padding, we have to use less wrap width
     $cW = $this->width - $cP * 2;
     //-- calculate the text box height
     // Number of lines, will be converted to height
     $cHT = 0;
     // Element height (exept text)
     $eH = 0;
     // Footnote height (in points)
     $fH = 0;
     $w = 0;
     //-- $lw is an array
     // 0 => last line width
     // 1 => 1 if text was wrapped, 0 if text did not wrap
     // 2 => number of LF
     $lw = array();
     // Element counter
     $cE = count($this->elements);
     for ($i = 0; $i < $cE; $i++) {
         if (is_object($this->elements[$i])) {
             $ew = $this->elements[$i]->setWrapWidth($cW - $w - 2, $cW);
             if ($ew == $cW) {
                 $w = 0;
             }
             $lw = $this->elements[$i]->getWidth($renderer);
             // Text is already gets the # LF
             $cHT += $lw[2];
             if ($lw[1] == 1) {
                 $w = $lw[0];
             } elseif ($lw[1] == 2) {
                 $w = 0;
             } else {
                 $w += $lw[0];
             }
             if ($w > $cW) {
                 $w = $lw[0];
             }
             // For anything else but text (images), get the height
             $eH += $this->elements[$i]->getHeight($renderer);
         } else {
             $fH += abs($renderer->getFootnotesHeight($cW));
         }
     }
     // Add up what’s the final height
     $cH = $this->height;
     // If any element exist
     if ($cE > 0) {
         // Check if this is text or some other element, like images
         if ($eH == 0) {
             // Number of LF but at least one line
             $cHT = ($cHT + 1) * $renderer->cellHeightRatio;
             // Calculate the cell hight with the largest font size used
             $cHT = $cHT * $renderer->largestFontHeight;
             if ($cH < $cHT) {
                 $cH = $cHT;
             }
         } else {
             if ($cH < $eH) {
                 $cH = $eH;
             }
             // Add Footnote height to the rest of the height
             $cH += $fH;
         }
     }
     unset($lw, $cHT, $fH, $w);
     // Finaly, check the last cells height
     if ($cH < $renderer->lastCellHeight) {
         $cH = $renderer->lastCellHeight;
     }
     // Update max Y incase of a pagebreak
     // We don't want to over write any images or other stuff
     $renderer->addMaxY($this->top + $cH);
     // Start to print HTML
     echo "<div style=\"position:absolute;top:", $this->top, "pt;";
     // LTR (left) or RTL (right)
     echo $renderer->alignRTL, ":", $cX, "pt;";
     // Background color
     if ($this->fill) {
         if (!empty($this->bgcolor)) {
             echo " background-color:", $this->bgcolor, ";";
         }
     }
     // Print padding only when it’s set
     if ($this->padding) {
         // Use Cell around padding to support RTL also
         echo "padding:", $cP, "pt;";
     }
     // Border setup
     if ($this->border) {
         echo " border:solid black 1pt;";
         echo "width:", $this->width - 1 - $cP * 2, "pt;height:", $cH - 1, "pt;";
     } else {
         echo "width:", $this->width - $cP * 2, "pt;height:", $cH, "pt;";
     }
     echo "\">";
     // Do a little "margin" trick before print
     // to get the correct current position => "."
     $cXT = $renderer->GetX();
     $cYT = $renderer->GetY();
     $renderer->SetXY(0, 0);
     // Print the text elements
     foreach ($this->elements as $element) {
         if (is_object($element)) {
             $element->render($renderer, $cX, false);
         } elseif (is_string($element) && $element == "footnotetexts") {
             $renderer->Footnotes();
         } elseif (is_string($element) && $element == "addpage") {
             $renderer->AddPage();
         }
     }
     echo "</div>\n";
     // Reset "margins"
     $renderer->SetXY($cXT, $cYT);
     // This will be mostly used to trick the multiple images last height
     if ($this->reseth) {
         $cH = 0;
     }
     // New line and some clean up
     if (!$this->newline) {
         $renderer->SetXY($cX + $this->width, $this->top);
         $renderer->lastCellHeight = $cH;
     } else {
         $renderer->SetXY(0, $this->top + $cH + $cP * 2);
         $renderer->lastCellHeight = 0;
     }
 }
Beispiel #5
0
 /**
  * Image renderer
  *
  * @param ReportHtml $renderer
  */
 public function render($renderer)
 {
     global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
     // Get the current positions
     if ($this->x == ".") {
         $this->x = $renderer->getX();
     }
     if ($this->y == ".") {
         //-- first check for a collision with the last picture
         if (isset($lastpicbottom)) {
             if ($renderer->pageNo() == $lastpicpage && $lastpicbottom >= $renderer->getY() && $this->x >= $lastpicleft && $this->x <= $lastpicright) {
                 $renderer->setY($lastpicbottom + $renderer->cPadding * 2);
             }
         }
         $this->y = $renderer->getY();
     }
     // Image alignment
     switch ($this->align) {
         case "L":
             echo "<div style=\"position:absolute;top:", $this->y, "pt;left:0pt;width:", $renderer->getRemainingWidth(), "pt;text-align:left;\">\n";
             echo "<img src=\"", $this->file, "\" style=\"width:", $this->width, "pt;height:", $this->height, "pt;\" alt=\"\">\n</div>\n";
             break;
         case "C":
             echo "<div style=\"position:absolute;top:", $this->y, "pt;left:0pt;width:", $renderer->getRemainingWidth(), "pt;text-align:center;\">\n";
             echo "<img src=\"", $this->file, "\" style=\"width:", $this->width, "pt;height:", $this->height, "pt;\" alt=\"\">\n</div>\n";
             break;
         case "R":
             echo "<div style=\"position:absolute;top:", $this->y, "pt;left:0pt;width:", $renderer->getRemainingWidth(), "pt;text-align:right;\">\n";
             echo "<img src=\"", $this->file, "\" style=\"width:", $this->width, "pt;height:", $this->height, "pt;\" alt=\"\">\n</div>\n";
             break;
         default:
             echo "<img src=\"", $this->file, "\" style=\"position:absolute;", $renderer->alignRTL, ":", $this->x, "pt;top:", $this->y, "pt;width:", $this->width, "pt;height:", $this->height, "pt;\" alt=\"\">\n";
     }
     $lastpicpage = $renderer->pageNo();
     $lastpicleft = $this->x;
     $lastpicright = $this->x + $this->width;
     $lastpicbottom = $this->y + $this->height;
     // Setup for the next line
     if ($this->line == "N") {
         $renderer->setY($lastpicbottom);
     }
     // Keep max Y updated
     $renderer->addMaxY($lastpicbottom);
 }
 /**
  * Get the width of text
  * Breaks up a text into lines if needed
  *
  * @param ReportHtml $html
  *
  * @return array
  */
 public function getWidth($html)
 {
     // Setup the style name
     $html->setCurrentStyle("footnotenum");
     // Check for the largest font size in the box
     $fsize = $html->getCurrentStyleHeight();
     if ($fsize > $html->largestFontHeight) {
         $html->largestFontHeight = $fsize;
     }
     // Returns the Object if already numbered else false
     if (empty($this->num)) {
         $html->checkFootnote($this);
     }
     // Get the line width for the text in points + a little margin
     $lw = $html->GetStringWidth($this->numText);
     // Line Feed counter - Number of lines in the text
     $lfct = $html->countLines($this->numText);
     // If there is still remaining wrap width...
     if ($this->wrapWidthRemaining > 0) {
         // Check with line counter too!
         if ($lw >= $this->wrapWidthRemaining || $lfct > 1) {
             $newtext = "";
             $wrapWidthRemaining = $this->wrapWidthRemaining;
             $lines = explode("\n", $this->numText);
             // Go throught the text line by line
             foreach ($lines as $line) {
                 // Line width in points + a little margin
                 $lw = $html->GetStringWidth($line);
                 // If the line has to be wraped
                 if ($lw > $wrapWidthRemaining) {
                     $words = explode(" ", $line);
                     $addspace = count($words);
                     $lw = 0;
                     foreach ($words as $word) {
                         $addspace--;
                         $lw += $html->GetStringWidth($word . " ");
                         if ($lw <= $wrapWidthRemaining) {
                             $newtext .= $word;
                             if ($addspace != 0) {
                                 $newtext .= " ";
                             }
                         } else {
                             $lw = $html->GetStringWidth($word . " ");
                             $newtext .= "\n{$word}";
                             if ($addspace != 0) {
                                 $newtext .= " ";
                             }
                             // Reset the wrap width to the cell width
                             $wrapWidthRemaining = $this->wrapWidthCell;
                         }
                     }
                 } else {
                     $newtext .= $line;
                 }
                 // Check the Line Feed counter
                 if ($lfct > 1) {
                     // Add a new line feed as long as it’s not the last line
                     $newtext .= "\n";
                     // Reset the line width
                     $lw = 0;
                     // Reset the wrap width to the cell width
                     $wrapWidthRemaining = $this->wrapWidthCell;
                 }
                 $lfct--;
             }
             $this->numText = $newtext;
             $lfct = substr_count($this->numText, "\n");
             return array($lw, 1, $lfct);
         }
     }
     $l = 0;
     $lfct = substr_count($this->numText, "\n");
     if ($lfct > 0) {
         $l = 2;
     }
     return array($lw, $l, $lfct);
 }
Beispiel #7
0
 /**
  * HTML Cell renderer
  *
  * @param ReportHtml $renderer
  */
 public function render($renderer)
 {
     if (strpos($this->text, "{{:ptp:}}") !== false) {
         return;
     }
     $temptext = str_replace("#PAGENUM#", $renderer->pageNo(), $this->text);
     // underline «title» part of Source item
     $temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext);
     // Setup the style name
     if ($renderer->getCurrentStyle() != $this->styleName) {
         $renderer->setCurrentStyle($this->styleName);
     }
     // If (Future-feature-enable/disable cell padding)
     $cP = $renderer->cPadding;
     // Adjust the positions
     if ($this->left == ".") {
         $this->left = $renderer->getX();
     } else {
         $renderer->setX($this->left);
     }
     if ($this->top == ".") {
         $this->top = $renderer->getY();
     } else {
         $renderer->setY($this->top);
     }
     // Start collecting the HTML code
     echo "<div class=\"", $this->styleName, "\" style=\"position:absolute;top:", $this->top, "pt;";
     // Use Cell around padding to support RTL also
     echo "padding:", $cP, "pt;";
     // LTR (left) or RTL (right)
     echo $renderer->alignRTL, ":", $this->left, "pt;";
     // Background color
     if (!empty($this->bgcolor)) {
         echo "background-color:", $this->bgcolor, ";";
     }
     // Border setup
     $bpixX = 0;
     $bpixY = 0;
     if (!empty($this->border)) {
         // Border all around
         if ($this->border == 1) {
             echo " border:solid ";
             if (!empty($this->bocolor)) {
                 echo $this->bocolor;
             } else {
                 echo "black";
             }
             echo " 1pt;";
             $bpixX = 1;
             $bpixY = 1;
         } else {
             if (stripos($this->border, "T") !== false) {
                 echo " border-top:solid ";
                 if (!empty($this->bocolor)) {
                     echo $this->bocolor;
                 } else {
                     echo "black";
                 }
                 echo " 1pt;";
                 $bpixY = 1;
             }
             if (stripos($this->border, "B") !== false) {
                 echo " border-bottom:solid ";
                 if (!empty($this->bocolor)) {
                     echo $this->bocolor;
                 } else {
                     echo "black";
                 }
                 echo " 1pt;";
                 $bpixY = 1;
             }
             if (stripos($this->border, "R") !== false) {
                 echo " border-right:solid ";
                 if (!empty($this->bocolor)) {
                     echo $this->bocolor;
                 } else {
                     echo "black";
                 }
                 echo " 1pt;";
                 $bpixX = 1;
             }
             if (stripos($this->border, "L") !== false) {
                 echo " border-left:solid ";
                 if (!empty($this->bocolor)) {
                     echo $this->bocolor;
                 } else {
                     echo "black";
                 }
                 echo " 1pt;";
                 $bpixX = 1;
             }
         }
     }
     // Check the width if set to page wide OR set by xml to larger then page wide
     if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) {
         $this->width = $renderer->getRemainingWidth();
     }
     // We have to calculate a different width for the padding, counting on both side
     $cW = $this->width - $cP * 2;
     // If there is any text
     if (!empty($temptext)) {
         // Wrap the text
         $temptext = $renderer->textWrap($temptext, $cW);
         $tmph = $renderer->getTextCellHeight($temptext);
         // Add some cell padding
         $this->height += $cP;
         if ($tmph > $this->height) {
             $this->height = $tmph;
         }
     }
     // Check the last cell height and ajust with the current cell height
     if ($renderer->lastCellHeight > $this->height) {
         $this->height = $renderer->lastCellHeight;
     }
     echo " width:", $cW - $bpixX, "pt;height:", $this->height - $bpixY, "pt;";
     // Text alignment
     switch ($this->align) {
         case "C":
             echo " text-align:center;";
             break;
         case "L":
             echo " text-align:left;";
             break;
         case "R":
             echo " text-align:right;";
             break;
     }
     // Print the collected HTML code
     echo "\">";
     // Print URL
     if (!empty($this->url)) {
         echo "<a href=\"", $this->url, "\">";
     }
     // Print any text if exists
     if (!empty($temptext)) {
         $renderer->write($temptext, $this->tcolor, false);
     }
     if (!empty($this->url)) {
         echo "</a>";
     }
     // Finish the cell printing and start to clean up
     echo "</div>\n";
     // Where to place the next position
     // -> Next to this cell in the same line
     if ($this->newline == 0) {
         $renderer->setXy($this->left + $this->width, $this->top);
         $renderer->lastCellHeight = $this->height;
     } elseif ($this->newline == 1) {
         $renderer->setXy(0, $renderer->getY() + $this->height + $cP * 2);
         // Reset the last cell height for the next line
         $renderer->lastCellHeight = 0;
     } elseif ($this->newline == 2) {
         $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + $cP * 2);
         // Reset the last cell height for the next line
         $renderer->lastCellHeight = 0;
     }
 }