Пример #1
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));
 }
Пример #2
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;
 }
Пример #3
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;
     }
 }