コード例 #1
0
 public function format(Nodes\Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     list($x, $y) = $node->getFirstPoint()->toArray();
     $boundary->reset();
     $boundary->setNext($x, $y);
 }
コード例 #2
0
ファイル: Table.php プロジェクト: zhangxiaoliu/PHPPdf
 private function setColumnMarginIfNecessary(Node $node, $marginType)
 {
     $margin = $node->getAttribute($marginType);
     $columnNumber = $node->getNumberOfColumn();
     if (!isset($this->marginsOfColumns[$marginType][$columnNumber]) || $margin > $this->marginsOfColumns[$marginType][$columnNumber]) {
         $this->marginsOfColumns[$marginType][$columnNumber] = $margin;
     }
 }
コード例 #3
0
 private function getVerticalTranslation(Node $node, $minYCoord, $verticalAlign)
 {
     $difference = $minYCoord - ($node->getDiagonalPoint()->getY() + $node->getPaddingBottom());
     if ($verticalAlign == Node::VERTICAL_ALIGN_MIDDLE) {
         $difference /= 2;
     }
     return $difference;
 }
コード例 #4
0
 private function getMaxXCoord(Node $node)
 {
     for ($parent = $node->getParent(); $parent && !$parent->getWidth(); $parent = $parent->getParent()) {
     }
     if (!$node->getWidth() && $parent && $parent->getWidth()) {
         $node = $parent;
     }
     return $node->getFirstPoint()->getX() + $node->getWidth() - $node->getPaddingRight();
 }
コード例 #5
0
 public function format(Node $node, Document $document)
 {
     $node->convertRelativeWidthsOfColumns();
     $node->reduceColumnsWidthsByMargins();
     $columnsWidths = $node->getWidthsOfColumns();
     $columnsMarginsLeft = $node->getMarginsLeftOfColumns();
     $columnsMarginsRight = $node->getMarginsRightOfColumns();
     $numberOfColumns = $node->getNumberOfColumns();
     $totalColumnsWidth = array_sum($columnsWidths);
     $tableWidth = $node->getWidth();
     $enlargeColumnWidth = $numberOfColumns ? ($tableWidth - $totalColumnsWidth) / count($columnsWidths) : 0;
     foreach ($columnsWidths as $index => $width) {
         $columnsWidths[$index] += $enlargeColumnWidth;
     }
     foreach ($node->getChildren() as $row) {
         foreach ($row->getChildren() as $cell) {
             $column = $cell->getNumberOfColumn();
             $colspan = $cell->getColspan();
             $newWidth = 0;
             for ($i = 0; $i < $colspan; $i++) {
                 $newWidth += $columnsWidths[$column + $i];
             }
             $horizontalPaddings = $cell->getPaddingLeft() + $cell->getPaddingRight();
             $cell->setWidth($newWidth - $horizontalPaddings);
             $cell->setMarginLeft($columnsMarginsLeft[$column]);
             $cell->setMarginRight($columnsMarginsRight[$column + $colspan - 1]);
         }
     }
 }
コード例 #6
0
ファイル: BagContainer.php プロジェクト: zhangxiaoliu/PHPPdf
 public function apply(Node $node)
 {
     $attributes = $this->getAll();
     foreach ($attributes as $name => $value) {
         if (is_array($value)) {
             $node->mergeComplexAttributes($name, $value);
         } else {
             $node->setAttribute($name, $value);
         }
     }
 }
コード例 #7
0
ファイル: ListFormatter.php プロジェクト: zhangxiaoliu/PHPPdf
 public function format(Node $node, Document $document)
 {
     $position = $node->getAttribute('list-position');
     $node->assignEnumerationStrategyFromFactory();
     if ($position === BasicList::LIST_POSITION_INSIDE) {
         $widthOfEnumerationChar = $node->getEnumerationStrategy()->getWidthOfTheBiggestPosibleEnumerationElement($document, $node);
         foreach ($node->getChildren() as $child) {
             $marginLeft = $widthOfEnumerationChar + $child->getMarginLeft();
             $child->setAttribute('margin-left', $marginLeft);
         }
     }
 }
コード例 #8
0
ファイル: Bookmark.php プロジェクト: zhangxiaoliu/PHPPdf
 private function getParentBookmarkIdentifier(Node $node)
 {
     if ($this->options['parentId']) {
         return $this->options['parentId'];
     }
     for ($parent = $node->getParent(); $parent !== null; $parent = $parent->getParent()) {
         foreach ($parent->getBehaviours() as $behaviour) {
             if ($behaviour instanceof Bookmark) {
                 return $behaviour->getUniqueId();
             }
         }
     }
     return null;
 }
コード例 #9
0
 public function format(Node $node, Document $document)
 {
     $this->lastVerticalTranslation = 0;
     $nodes = $node instanceof ColumnableContainer ? array($node) : $node->getChildren();
     foreach ($nodes as $node) {
         if ($node instanceof ColumnableContainer) {
             $container = $this->moveAllChildrenToSingleContainer($node);
             $this->breakContainerIntoColumns($node, $container);
             $this->resizeColumnableContainer($node);
             $this->staticBreakYCoord = null;
             $this->stopBreaking = false;
         }
     }
 }
コード例 #10
0
 private function setDimensionsFromParent(EngineImage $sourceImage, Node $node)
 {
     $parent = $node->getParent();
     $width = $sourceImage->getOriginalWidth();
     $height = $sourceImage->getOriginalHeight();
     if ($width > $parent->getWidth() || $height > $parent->getHeight()) {
         if ($parent->getWidth() > $parent->getHeight()) {
             $height = $parent->getHeight();
             $width = null;
         } else {
             $width = $parent->getWidth();
             $height = null;
         }
     }
     return array($width, $height);
 }
コード例 #11
0
 public function format(Node $node, Document $document)
 {
     if (!$node instanceof Page) {
         throw new InvalidArgumentException('ElasticPageFormatter works only with PHPPdf\\Core\\Node\\Page class.');
     }
     $lastChild = null;
     foreach ($node->getChildren() as $child) {
         if (!$lastChild || $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() > $child->getDiagonalPoint()->getY() - $child->getMarginBottom()) {
             $lastChild = $child;
         }
     }
     $lastNodeYCoord = $lastChild ? $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() : $node->getRealHeight();
     $height = $node->getRealHeight() - $lastNodeYCoord + $node->getMarginBottom();
     $translate = $node->getRealHeight() - $height;
     $node->setPageSize($node->getRealWidth(), $height);
     foreach ($node->getChildren() as $child) {
         $child->translate(0, $translate);
     }
     $node->removeGraphicsContext();
 }
コード例 #12
0
 public function format(Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     list($x, $y) = $boundary->getFirstPoint()->toArray();
     list($parentX, $parentY) = $node->getParent()->getStartDrawingPoint();
     $lineSizes = $node->getLineSizes();
     $lineHeight = $node->getLineHeightRecursively();
     $startX = $x;
     $currentX = $x;
     $currentY = $y;
     foreach ($lineSizes as $rowNumber => $width) {
         $newX = $x + $width;
         $newY = $currentY - $lineHeight;
         if ($currentX !== $newX) {
             $boundary->setNext($newX, $currentY);
         }
         $boundary->setNext($newX, $newY);
         $currentX = $newX;
         $currentY = $newY;
         $x = $parentX + $node->getMarginLeft();
     }
     $boundary->setNext($x, $currentY);
     $currentY = $currentY + (count($lineSizes) - 1) * $lineHeight;
     $boundary->setNext($x, $currentY);
     $boundary->setNext($startX, $currentY);
     $boundary->close();
 }
コード例 #13
0
 public function format(Nodes\Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     if (!$boundary->isClosed()) {
         list($x, $y) = $boundary->getFirstPoint()->toArray();
         $attributesSnapshot = $node->getAttributesSnapshot();
         $diffWidth = $node->getWidth() - $attributesSnapshot['width'];
         $width = $node->getWidth();
         $x += $width;
         $yEnd = $y - $node->getHeight();
         $boundary->setNext($x, $y)->setNext($x, $yEnd)->setNext($x - $width, $yEnd)->close();
         if ($node->hadAutoMargins()) {
             $node->translate(-$diffWidth / 2, 0);
         }
     }
 }
コード例 #14
0
ファイル: Page.php プロジェクト: zhangxiaoliu/PHPPdf
 private function getTemplateDrawingTasksAndFormatPlaceholders(Document $document)
 {
     $this->formatConvertAttributes($document);
     $this->getHeader()->format($document);
     $this->getFooter()->format($document);
     $this->getWatermark()->format($document);
     $tasks = new DrawingTaskHeap();
     $this->getDrawingTasksFromComplexAttributes($document, $tasks);
     $this->footer->collectOrderedDrawingTasks($document, $tasks);
     $this->header->collectOrderedDrawingTasks($document, $tasks);
     $this->watermark->collectOrderedDrawingTasks($document, $tasks);
     $this->footer->removeAll();
     $this->header->removeAll();
     $this->watermark->removeAll();
     return $tasks;
 }
コード例 #15
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);
         }
     }
 }
コード例 #16
0
 public function format(Node $node, Document $document)
 {
     $originalRatio = $node->getOriginalRatio();
     $currentRatio = $node->getCurrentRatio();
     if (!$this->floatEquals($originalRatio, $currentRatio)) {
         $width = $node->getWidth();
         $height = $node->getHeight();
         if ($originalRatio > $currentRatio) {
             $height = $originalRatio ? $width / $originalRatio : 0;
             $node->setHeight($height);
         } else {
             $width = $height * $originalRatio;
             $node->setWidth($width);
         }
     }
 }
コード例 #17
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);
     }
 }
コード例 #18
0
ファイル: Paragraph.php プロジェクト: zhangxiaoliu/PHPPdf
 protected function doBreakAt($height)
 {
     $linesToMove = array();
     $numberOfLines = count($this->lines);
     foreach ($this->lines as $i => $line) {
         $lineEnd = $line->getYTranslation() + $line->getHeight();
         if ($lineEnd > $height) {
             $linesToMove[] = $line;
             unset($this->lines[$i]);
         }
     }
     if (!$linesToMove || count($linesToMove) == $numberOfLines) {
         return null;
     }
     $firstLineToMove = current($linesToMove);
     $yTranslation = $height - $firstLineToMove->getYTranslation();
     $height = $firstLineToMove->getYTranslation();
     $paragraphProduct = Node::doBreakAt($height);
     $paragraphProduct->removeAll();
     $replaceText = array();
     $textsToMove = array();
     foreach ($firstLineToMove->getParts() as $part) {
         $text = $part->getText();
         $textHeight = $text->getFirstPoint()->getY() - ($this->getFirstPoint()->getY() - $height);
         $textProduct = $text->breakAt($textHeight);
         if ($textProduct) {
             $replaceText[spl_object_hash($text)] = $textProduct;
             $paragraphProduct->add($textProduct);
             $part->setText($textProduct);
         } else {
             $replaceText[spl_object_hash($text)] = $text;
             $textsToMove[spl_object_hash($text)] = $text;
         }
     }
     foreach ($linesToMove as $line) {
         $line->setYTranslation($line->getYTranslation() - $height);
         $line->setParagraph($paragraphProduct);
         $paragraphProduct->addLine($line);
     }
     array_shift($linesToMove);
     foreach ($linesToMove as $line) {
         foreach ($line->getParts() as $part) {
             $text = $part->getText();
             $hash = spl_object_hash($text);
             if (isset($replaceText[$hash])) {
                 $part->setText($replaceText[$hash]);
             } else {
                 $textsToMove[$hash] = $text;
             }
         }
     }
     foreach ($textsToMove as $text) {
         $this->remove($text);
         $paragraphProduct->add($text);
     }
     $paragraphProduct->translate(0, $yTranslation);
     $paragraphProduct->resize(0, -$yTranslation);
     $paragraphProduct->resize(0, $yTranslation);
     return $paragraphProduct;
 }
コード例 #19
0
 protected function getTranslationAwareBoundary(Node $node, Boundary $boundary)
 {
     $positionTranslation = $node->getPositionTranslation();
     if ($positionTranslation && ($positionTranslation->getX() != 0 || $positionTranslation->getY() != 0)) {
         $boundary = clone $boundary;
         $boundary->translate($positionTranslation->getX(), $positionTranslation->getY());
     }
     return $boundary;
 }
コード例 #20
0
 public function format(Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     $verticalMargins = $node->getMarginsBottomOfCells() + $node->getMarginsTopOfCells();
     $newHeight = $node->getMaxHeightOfCells() + $verticalMargins;
     $heightDiff = $newHeight - $node->getHeight();
     $boundary->pointTranslate(2, 0, $heightDiff)->pointTranslate(3, 0, $heightDiff);
     $node->setHeight($newHeight);
     foreach ((array) $node->getChildren() as $cell) {
         $heightDiff = $node->getMaxHeightOfCells() - $cell->getHeight();
         $cell->setHeight($node->getMaxHeightOfCells());
         $cell->getBoundary()->pointTranslate(2, 0, $heightDiff)->pointTranslate(3, 0, $heightDiff);
         $cell->translate(0, $node->getMarginsTopOfCells());
     }
 }
コード例 #21
0
 private function isLineBreak(Node $node, Node $previousSibling)
 {
     return $node->getAttribute('line-break') && $previousSibling->getAttribute('line-break');
 }
コード例 #22
0
ファイル: Text.php プロジェクト: zhangxiaoliu/PHPPdf
 public function flush()
 {
     $this->lineParts = array();
     parent::flush();
 }
コード例 #23
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);
 }
コード例 #24
0
ファイル: Behaviour.php プロジェクト: zhangxiaoliu/PHPPdf
 private static function getTranslatedPointOf(Node $node, Point $point)
 {
     $translation = $node->getPositionTranslation();
     return $point->translate($translation->getX(), $translation->getY());
 }
コード例 #25
0
 private function correctXCoordWithParent(Node $node)
 {
     $parent = $node->getParent();
     if ($node->getFloat() === Node::FLOAT_LEFT) {
         $preferredXCoord = $parent->getFirstPoint()->getX() + $parent->getPaddingLeft() + $node->getMarginLeft() + $node->getPaddingLeft();
     } else {
         $preferredXCoord = $parent->getDiagonalPoint()->getX() - $node->getWidth() + $node->getPaddingLeft() - $node->getMarginRight();
     }
     return $preferredXCoord;
 }
コード例 #26
0
 public function format(Node $node, Document $document)
 {
     $parent = $node->getParent();
     if ($node->getWidth() === null && !$node->isInline() && $node->getFloat() === Node::FLOAT_NONE) {
         $parentWidth = $parent->getWidthWithoutPaddings();
         $marginLeft = $node->getMarginLeft();
         $marginRight = $node->getMarginRight();
         $node->setWidth($parentWidth - ($marginLeft + $marginRight));
         $node->setRelativeWidth('100%');
     } elseif ($node->isInline()) {
         $node->setWidth(0);
     }
     if ($node->getHeight() === null) {
         $node->setHeight(0);
     }
     $paddingLeft = $node->getPaddingLeft();
     $paddingRight = $node->getPaddingRight();
     $paddingTop = $node->getPaddingTop();
     $paddingBottom = $node->getPaddingBottom();
     $prefferedWidth = $node->getRealWidth() + $paddingLeft + $paddingRight;
     $parent = $node->getParent();
     $parentWidth = $parent ? $parent->getWidthWithoutPaddings() : null;
     if ($parent && $parentWidth < $prefferedWidth) {
         $prefferedWidth = $parentWidth;
     }
     $node->setWidth($prefferedWidth);
     $node->setHeight($node->getRealHeight() + $paddingTop + $paddingBottom);
 }
コード例 #27
0
 public function format(Node $node, Document $document)
 {
     $parent = $node->getParent();
     $boundary = $node->getBoundary();
     $boundary->setNext($parent->getFirstPoint());
 }
コード例 #28
0
 private function setBehavioursFromReader(\XMLReader $reader, Node $node)
 {
     foreach ($this->behaviourFactory->getSupportedBehaviourNames() as $name) {
         $value = $reader->getAttribute($name);
         if ($value) {
             $node->addBehaviour($this->behaviourFactory->create($name, $value));
         }
     }
 }
コード例 #29
0
ファイル: StubNode.php プロジェクト: zhangxiaoliu/PHPPdf
 public function initialize()
 {
     parent::initialize();
     $this->addAttribute('name-two');
     $this->addAttribute('name', 'value');
 }
コード例 #30
0
ファイル: Image.php プロジェクト: appotter/phppdf
 protected static function initializeType()
 {
     static::setAttributeSetters(array('ignore-error' => 'setIgnoreError'));
     static::setAttributeSetters(array('keep-ratio' => 'setKeepRatio'));
     parent::initializeType();
 }