Exemple #1
0
 /**
  * Hook on page creation
  *
  * Hook called on page creation, so that certain areas might be reserved or
  * it already may render stuff on the frshly created page.
  *
  * @param ezcDocumentPdfPage $page
  * @return void
  */
 public function hookPageCreation(ezcDocumentPdfPage $page)
 {
     // Get default styles from document
     $style = $this->styles->inferenceFormattingRules($this->document);
     foreach ($style as $name => $value) {
         $this->driver->setTextFormatting($name, $value->value);
     }
     // Allocate space for footer
     if (($space = $page->testFitRectangle($page->x, $this->options->footer ? $page->y + $page->innerHeight - $this->options->height->get() : $page->y, $page->innerWidth, $this->options->height->get())) === false) {
         // If we can't allocate the designated space, exit.
         return false;
     }
     // Calculate vertical alignement
     $offset = 0;
     if ($this->options->footer) {
         $offset = $space->height - 2.1 * $this->driver->getCurrentLineHeight();
     }
     // Render document title
     if ($this->documentTitle && $this->options->showDocumentTitle) {
         // Inference these settings somehow
         $this->driver->setTextFormatting('font-weight', 'bold');
         $width = $this->driver->calculateWordWidth($this->documentTitle);
         $this->driver->drawWord($space->x + ($page->innerWidth - $width) / 2, $space->y + $offset + $this->driver->getCurrentLineHeight(), $this->documentTitle);
         $offset += 1.1 * $this->driver->getCurrentLineHeight();
     }
     // Render document author
     if ($this->documentAuthor && $this->options->showDocumentAuthor) {
         // Inference these settings somehow
         $this->driver->setTextFormatting('font-weight', 'normal');
         $this->driver->setTextFormatting('font-style', 'italic');
         $width = $this->driver->calculateWordWidth($this->documentAuthor);
         $this->driver->drawWord($space->x + ($page->innerWidth - $width) / 2, $space->y + $offset + $this->driver->getCurrentLineHeight(), $this->documentAuthor);
         $offset += 1.1 * $this->driver->getCurrentLineHeight();
     }
     // Render page number
     if ($this->options->showPageNumber) {
         $pageNumber = $page->number + $this->options->pageNumberOffset;
         $postion = $pageNumber % 2 ? $space->width - $this->driver->calculateWordWidth($pageNumber) : 0;
         $this->driver->drawWord($space->x + $postion, $space->y + ($space->height - $this->driver->getCurrentLineHeight()) / 2 + $this->driver->getCurrentLineHeight(), $pageNumber);
     }
     $page->setCovered($space);
     if (!$this->options->footer) {
         $page->y += $space->height;
     }
 }
Exemple #2
0
 /**
  * Create from user readable soze specification
  *
  * Create page from common page size abbreviations, like "A4" and page
  * orientation.
  *
  * @param int $pageNumber
  * @param mixed $size
  * @param mixed $orientation
  * @param array $margin
  * @param array $padding
  * @return ezcDocumentPdfPage
  */
 public static function createFromSpecification($pageNumber, $size, $orientation, array $margin, array $padding)
 {
     if (!isset(self::$pageSizes[$size])) {
         throw new ezcBaseValueException("page-size", $size, implode(', ', self::$pageSizes));
     }
     // Calculate border sizes, depending on assigned margin and
     // padding
     $topBorder = $margin['top'] + $padding['top'];
     $leftBorder = $margin['left'] + $padding['left'];
     $bottomBorder = $margin['bottom'] + $padding['bottom'];
     $rightBorder = $margin['right'] + $padding['right'];
     switch ($orientation) {
         case 'landscape':
             $page = new ezcDocumentPdfPage($pageNumber, $width = self::$pageSizes[$size][1] + $margin['left'] + $margin['right'], $height = self::$pageSizes[$size][0] + $margin['top'] + $margin['bottom'], $width - $leftBorder - $rightBorder, $height - $topBorder - $bottomBorder);
             break;
         case 'portrait':
             $page = new ezcDocumentPdfPage($pageNumber, $width = self::$pageSizes[$size][0] + $margin['left'] + $margin['right'], $height = self::$pageSizes[$size][1] + $margin['top'] + $margin['bottom'], $width - $leftBorder - $rightBorder, $height - $topBorder - $bottomBorder);
             break;
         default:
             throw new ezcBaseValueException("page-orientation", $orientation, 'landscape or portrait');
     }
     // Set cover boxes for areas covered by padding and margin
     $page->setCovered(new ezcDocumentPdfBoundingBox(0, 0, $width, $topBorder));
     $page->setCovered(new ezcDocumentPdfBoundingBox(0, 0, $leftBorder, $height));
     $page->setCovered(new ezcDocumentPdfBoundingBox(0, $height - $bottomBorder, $width, $bottomBorder));
     $page->setCovered(new ezcDocumentPdfBoundingBox($width - $rightBorder, 0, $rightBorder, $height));
     // Update rendering start position
     $page->x = $page->startX = $leftBorder;
     $page->y = $page->startY = $topBorder;
     return $page;
 }
Exemple #3
0
 /**
  * Evaluate available bounding box
  *
  * Returns false, if not enough space is available on current
  * page, and a bounding box otherwise.
  *
  * @param ezcDocumentPdfPage $page
  * @param array $styles
  * @param float $width
  * @return mixed
  */
 protected function evaluateAvailableBoundingBox(ezcDocumentPdfPage $page, array $styles, $width)
 {
     // Grap the maximum available vertical space
     $space = $page->testFitRectangle($page->x, $page->y, $width, null);
     if ($space === false) {
         // Could not allocate space, required for even one line
         return false;
     }
     // Apply bounding box modifications
     $space->x += $styles['padding']->value['left'] + $styles['border']->value['left']['width'] + $styles['margin']->value['left'];
     $space->width -= $styles['padding']->value['left'] + $styles['padding']->value['right'] + $styles['border']->value['left']['width'] + $styles['border']->value['right']['width'] + $styles['margin']->value['left'] + $styles['margin']->value['right'];
     $space->y += $styles['padding']->value['top'] + $styles['border']->value['top']['width'] + $styles['margin']->value['top'];
     $space->height -= $styles['padding']->value['top'] + $styles['padding']->value['bottom'] + $styles['border']->value['top']['width'] + $styles['border']->value['bottom']['width'] + $styles['margin']->value['top'] + $styles['margin']->value['bottom'];
     return $space;
 }
Exemple #4
0
 /**
  * Create and append a new page.
  *
  * @param ezcDocumentPcssStyleInferencer $inferencer
  */
 public function appendPage(ezcDocumentPcssStyleInferencer $inferencer)
 {
     $current = $this->transactions[$this->transaction]->currentPage;
     // Check if the next page already exists
     if (isset($this->pages[$current + 1])) {
         $current = ++$this->transactions[$this->transaction]->currentPage;
         return $this->pages[$current];
     }
     $current = ++$this->transactions[$this->transaction]->currentPage;
     $styles = $inferencer->inferenceFormattingRules(new ezcDocumentPdfPage(0, 0, 0, 0, 0));
     $page = ezcDocumentPdfPage::createFromSpecification($current, $styles['page-size']->value, $styles['page-orientation']->value, $styles['margin']->value, $styles['padding']->value);
     // Store in which transaction the page has been created
     $this->pages[$current] = $page;
     $this->transactions[$this->transaction]->pageCreations[] = $current;
     // Tell driver about new page
     $this->createPage($page->width, $page->height);
     return $page;
 }
Exemple #5
0
 /**
  * Set cell box covered.
  *
  * Mark rendered space as convered on the page.
  *
  * @param ezcDocumentPdfPage $page 
  * @param ezcDocumentPdfBoundingBox $space 
  * @param array $styles 
  */
 protected function setCellCovered(ezcDocumentPdfPage $page, ezcDocumentPdfBoundingBox $space, array $styles)
 {
     // Apply bounding box modifications
     $space = clone $space;
     $space->x -= $styles['padding']->value['left'] + $styles['border']->value['left']['width'] + $styles['margin']->value['left'];
     $space->width += $styles['padding']->value['left'] + $styles['padding']->value['right'] + $styles['border']->value['left']['width'] + $styles['border']->value['right']['width'] + $styles['margin']->value['left'] + $styles['margin']->value['right'];
     $space->y -= $styles['padding']->value['top'] + $styles['border']->value['top']['width'] + $styles['margin']->value['top'];
     $space->height += $styles['padding']->value['top'] + $styles['border']->value['top']['width'] + $styles['margin']->value['top'];
     $page->setCovered($space);
     $page->y += $space->height;
 }
Exemple #6
0
 public function testUncoverArea()
 {
     $page = new ezcDocumentPdfPage(1, 100, 100);
     $page->startTransaction(1);
     $page->setCovered(new ezcDocumentPdfBoundingBox(0, 0, 50, 50));
     $id = $page->setCovered(new ezcDocumentPdfBoundingBox(0, 50, 50, 50));
     $page->setCovered(new ezcDocumentPdfBoundingBox(50, 0, 50, 50));
     $this->assertEquals(false, $page->testFitRectangle(10, 60, 30, 30));
     $page->uncover($id);
     $this->assertEquals(new ezcDocumentPdfBoundingBox(10, 60, 30, 30), $page->testFitRectangle(10, 60, 30, 30));
 }