コード例 #1
0
 public function enhance(Node $node, Document $document)
 {
     $color = $document->getColorFromPalette($this->getColor());
     $alpha = $node->getAlpha();
     $graphicsContext = $node->getGraphicsContext();
     $isAlphaSet = $alpha != 1 && $alpha !== null;
     $rotationNode = $node->getAncestorWithRotation();
     if ($color || $isAlphaSet || $rotationNode) {
         $graphicsContext->saveGS();
     }
     if ($rotationNode) {
         $middlePoint = $rotationNode->getMiddlePoint();
         $graphicsContext->rotate($middlePoint->getX(), $middlePoint->getY(), $rotationNode->getRotate());
     }
     if ($alpha !== null) {
         $graphicsContext->setAlpha($alpha);
     }
     if ($color) {
         $graphicsContext->setLineColor($color);
         $graphicsContext->setFillColor($color);
     }
     $this->doEnhance($graphicsContext, $node, $document);
     if ($color || $isAlphaSet || $rotationNode) {
         $graphicsContext->restoreGs();
     }
 }
コード例 #2
0
 protected function convertColor(Node $node, Document $document)
 {
     $color = $node->getAttribute('color');
     if ($color) {
         $node->setAttribute('color', $document->getColorFromPalette($color));
     }
     if ($node->hasAttribute('chart-colors')) {
         $colors = $node->getAttribute('chart-colors');
         foreach ($colors as $key => $color) {
             $colors[$key] = $document->getColorFromPalette($color);
         }
         $node->setAttribute('chart-colors', $colors);
     }
 }
コード例 #3
0
 public function format(Node $node, Document $document)
 {
     $widthsOfColumns = $node->getWidthsOfColumns();
     $tableWidth = $node->getWidthWithoutPaddings();
     $marginsLeft = $node->getMarginsLeftOfColumns();
     $marginsRight = $node->getMarginsRightOfColumns();
     $minWidthsOfColumns = $node->getMinWidthsOfColumns();
     $totalWidth = array_sum($widthsOfColumns);
     $totalMargins = array_sum($marginsLeft) + array_sum($marginsRight);
     $verticalAlignFormatter = $document->getFormatter('PHPPdf\\Core\\Formatter\\VerticalAlignFormatter');
     foreach ($node->getChildren() as $row) {
         $diffBetweenTableAndColumnsWidths = $tableWidth - $totalWidth - $totalMargins;
         $translate = 0;
         foreach ($row->getChildren() as $cell) {
             $column = $cell->getNumberOfColumn();
             $colspan = $cell->getColspan();
             $minWidth = $newWidth = 0;
             for ($i = 0; $i < $colspan; $i++) {
                 $realColumn = $column + $i;
                 $minWidth += $minWidthsOfColumns[$realColumn];
                 $newWidth += $widthsOfColumns[$realColumn];
                 if ($i > 0) {
                     $margins = $marginsRight[$realColumn] + $marginsLeft[$realColumn];
                     $minWidth += $margins;
                     $newWidth += $margins;
                 }
             }
             $diffBetweenNewAndMinWidth = $newWidth - $minWidth;
             if ($diffBetweenTableAndColumnsWidths < 0 && -$diffBetweenTableAndColumnsWidths >= $diffBetweenNewAndMinWidth) {
                 $newWidth = $minWidth;
                 $diffBetweenTableAndColumnsWidths += $diffBetweenNewAndMinWidth;
             } elseif ($diffBetweenTableAndColumnsWidths < 0) {
                 $newWidth += $diffBetweenTableAndColumnsWidths;
                 $diffBetweenTableAndColumnsWidths = 0;
             }
             $cell->convertScalarAttribute('width', $tableWidth);
             $currentWidth = $cell->getWidth();
             $diff = $newWidth - $currentWidth;
             $minWidth = $cell->getMinWidth();
             $cell->setWidth($newWidth);
             $translate += $marginsLeft[$column];
             $cell->translate($translate, 0);
             $cell->resize($diff, 0);
             $translate += $newWidth + $marginsRight[$column];
             $verticalAlignFormatter->format($cell, $document);
         }
     }
 }
コード例 #4
0
ファイル: BasicList.php プロジェクト: zhangxiaoliu/PHPPdf
 protected function beforeFormat(Document $document)
 {
     $image = $this->getAttribute('image');
     if (is_string($image)) {
         $image = $document->createImage($image);
         $this->setAttribute('image', $image);
     }
 }
コード例 #5
0
ファイル: Node.php プロジェクト: zhangxiaoliu/PHPPdf
 private function invokeFormatter(Document $document, array $formattersNames)
 {
     foreach ($formattersNames as $formatterName) {
         $formatter = $document->getFormatter($formatterName);
         $formatter->format($this, $document);
     }
 }
コード例 #6
0
ファイル: Page.php プロジェクト: appotter/phppdf
 protected function getGraphicsContextFromSourceDocument(Document $document)
 {
     $fileOfSourcePage = $this->getAttribute('document-template');
     if ($fileOfSourcePage) {
         $engine = $document->loadEngine($fileOfSourcePage, $this->getEncoding());
         $graphicsContexts = $engine->getAttachedGraphicsContexts();
         $count = count($graphicsContexts);
         if ($count == 0) {
             return null;
         }
         $pageContext = $this->context;
         $index = ($pageContext ? $pageContext->getPageNumber() - 1 : 0) % $count;
         return $graphicsContexts[$index];
     }
     return null;
 }
コード例 #7
0
ファイル: Image.php プロジェクト: appotter/phppdf
 /**
  * @param Document $document
  *
  * @return \PHPPdf\Core\Engine\Image
  */
 protected function createImageSource(Document $document)
 {
     $src = $this->getAttribute('src');
     return is_string($src) ? $document->createImage($src) : $src;
 }
コード例 #8
0
ファイル: Border.php プロジェクト: zhangxiaoliu/PHPPdf
 private function drawCircleBorder(GraphicsContext $gc, Node $node, Document $document)
 {
     $size = $document->convertUnit($this->size);
     $gc->setLineWidth($size);
     $point = $node->getMiddlePoint();
     $translation = $node->getPositionTranslation();
     if (!$translation->isZero()) {
         $point = $point->translate($translation->getX(), $translation->getY());
     }
     $this->drawCircle($gc, $node->getAttribute('radius'), $point->getX(), $point->getY(), GraphicsContext::SHAPE_DRAW_STROKE);
 }
コード例 #9
0
ファイル: Manager.php プロジェクト: zhangxiaoliu/PHPPdf
 public function onEndParsing(Document $document, PageCollection $root)
 {
     $document->invokeTasks($this->behavioursTasks);
     $this->behavioursTasks = new DrawingTaskHeap();
 }
コード例 #10
0
ファイル: Background.php プロジェクト: zhangxiaoliu/PHPPdf
 private function drawRectangleBackground(GraphicsContext $graphicsContext, Node $node, Document $document)
 {
     if ($this->getColor() !== null) {
         $boundary = $this->getBoundary($node);
         if ($this->getRadius() !== null) {
             $firstPoint = $boundary->getPoint(3);
             $diagonalPoint = $boundary->getPoint(1);
             $this->drawRoundedBoundary($graphicsContext, $firstPoint->getX(), $firstPoint->getY(), $diagonalPoint->getX(), $diagonalPoint->getY(), GraphicsContext::SHAPE_DRAW_FILL_AND_STROKE);
         } else {
             $this->drawBoundary($graphicsContext, $boundary, GraphicsContext::SHAPE_DRAW_FILL);
         }
     }
     $image = $this->getImage();
     $image = $image ? $document->createImage($image) : null;
     if ($image !== null) {
         $positionTranslation = $node->getPositionTranslation();
         list($x, $y) = $this->getFirstPoint($node)->translate($positionTranslation->getX(), $positionTranslation->getY())->toArray();
         list($endX, $endY) = $this->getDiagonalPoint($node)->translate($positionTranslation->getX(), $positionTranslation->getY())->toArray();
         list($width, $height) = $this->getImageDimension($document, $image, $node);
         $graphicsContext->saveGS();
         $graphicsContext->clipRectangle($x, $y, $x + $this->getWidth($node), $y - $this->getHeight($node));
         $repeatX = $this->repeat & self::REPEAT_X;
         $repeatY = $this->repeat & self::REPEAT_Y;
         $currentX = $this->getXCoord($node, $width, $x, $document);
         $currentY = $y = $this->getYCoord($node, $height, $y, $document);
         do {
             $currentY = $y;
             do {
                 $graphicsContext->drawImage($image, $currentX, $currentY - $height, $currentX + $width, $currentY);
                 $currentY -= $height;
             } while ($repeatY && $currentY > $endY);
             $currentX += $width;
         } while ($repeatX && $currentX < $endX);
         $graphicsContext->restoreGS();
     }
 }