Permalink
Browse files

Applied patches 7010 and 7020

git-svn-id: https://phppowerpoint.svn.codeplex.com/svn/trunk@52156 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
1 parent c377aee commit df76f08e43212bf79b672a7b18c39cbb41cec868 @maartenba maartenba committed Oct 11, 2010
View
114 Classes/PHPPowerPoint/Shape/Line.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * PHPPowerPoint
+ *
+ * Copyright (c) 2009 - 2010 PHPPowerPoint
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * @category PHPPowerPoint
+ * @package PHPPowerPoint_Shape
+ * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
+ * @version ##VERSION##, ##DATE##
+ */
+
+
+/**
+ * PHPPowerPoint_Shape_Line
+ *
+ * @category PHPPowerPoint
+ * @package PHPPowerPoint_Shape
+ * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
+ */
+class PHPPowerPoint_Shape_Line extends PHPPowerPoint_Shape implements PHPPowerPoint_IComparable
+{
+ /**
+ * Create a new PHPPowerPoint_Shape_Line instance
+ *
+ * @param int $columns Number of columns
+ */
+ public function __construct($fromX,$fromY,$toX,$toY)
+ {
+ parent::__construct();
+ $this->getBorder()->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE);
+
+ $this->setOffsetX($fromX);
+ $this->setOffsetY($fromY);
+ $this->setWidth($toX-$fromX);
+ $this->setHeight($toY-$fromY);
+
+ }
+
+ /**
+ * Get hash code
+ *
+ * @return string Hash code
+ */
+ public function getHashCode() {
+ return md5(
+ $this->getBorder()->getLineStyle()
+ . parent::getHashCode()
+ . __CLASS__
+ );
+ }
+
+ /**
+ * Hash index
+ *
+ * @var string
+ */
+ private $_hashIndex;
+
+ /**
+ * Get hash index
+ *
+ * Note that this index may vary during script execution! Only reliable moment is
+ * while doing a write of a workbook and when changes are not allowed.
+ *
+ * @return string Hash index
+ */
+ public function getHashIndex() {
+ return $this->_hashIndex;
+ }
+
+ /**
+ * Set hash index
+ *
+ * Note that this index may vary during script execution! Only reliable moment is
+ * while doing a write of a workbook and when changes are not allowed.
+ *
+ * @param string $value Hash index
+ */
+ public function setHashIndex($value) {
+ $this->_hashIndex = $value;
+ }
+
+ /**
+ * Implement PHP __clone to create a deep clone, not just a shallow copy.
+ */
+ public function __clone() {
+ $vars = get_object_vars($this);
+ foreach ($vars as $key => $value) {
+ if ($key == '_parent') continue;
+
+ if (is_object($value)) {
+ $this->$key = clone $value;
+ } else {
+ $this->$key = $value;
+ }
+ }
+ }
+}
View
17 Classes/PHPPowerPoint/Slide.php
@@ -134,6 +134,23 @@ public function createRichTextShape()
}
/**
+ * Create line shape
+ *
+ * @param int $fromX Starting point x offset
+ * @param int $fromY Starting point y offset
+ * @param int $toX Ending point x offset
+ * @param int $toY Ending point y offset
+ * @return PHPPowerPoint_Shape_Line
+ */
+ public function createLineShape($fromX, $fromY, $toX, $toY)
+ {
+ $shape = new PHPPowerPoint_Shape_Line($fromX,$fromY,$toX,$toY);
+ $this->addShape($shape);
+
+ return $shape;
+ }
+
+ /**
* Create drawing shape
*
* @return PHPPowerPoint_Shape_Drawing
View
110 Classes/PHPPowerPoint/Writer/PowerPoint2007/Slide.php
@@ -140,6 +140,10 @@ public function writeSlide(PHPPowerPoint_Slide $pSlide = null)
{
$this->_writeTable($objWriter, $shape, $shapeId);
}
+ else if ($shape instanceof PHPPowerPoint_Shape_Line)
+ {
+ $this->_writeLineShape($objWriter, $shape, $shapeId);
+ }
else if ($shape instanceof PHPPowerPoint_Shape_BaseDrawing)
{
// Picture --> $relationId
@@ -783,6 +787,112 @@ private function _writeParagraphs(PHPPowerPoint_Shared_XMLWriter $objWriter, $pa
$objWriter->endElement();
}
}
+
+ /**
+ * Write Line Shape
+ *
+ * @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer
+ * @param PHPPowerPoint_Shape_RichText $shape
+ * @param int $shapeId
+ * @throws Exception
+ */
+ private function _writeLineShape(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Shape_Line $shape = null,$shapeId)
+ {
+ // p:sp
+ $objWriter->startElement('p:cxnSp');
+
+ // p:nvSpPr
+ $objWriter->startElement('p:nvCxnSpPr');
+
+ // p:cNvPr
+ $objWriter->startElement('p:cNvPr');
+ $objWriter->writeAttribute('id', $shapeId);
+ $objWriter->writeAttribute('name', '');
+ $objWriter->endElement();
+
+ // p:cNvCxnSpPr
+ $objWriter->writeElement('p:cNvCxnSpPr', null);
+
+ // p:nvPr
+ $objWriter->writeElement('p:nvPr', null);
+
+ $objWriter->endElement();
+
+ // p:spPr
+ $objWriter->startElement('p:spPr');
+
+ // a:xfrm
+ $objWriter->startElement('a:xfrm');
+
+ if ($shape->getWidth() >= 0 && $shape->getHeight() >= 0) {
+ // a:off
+ $objWriter->startElement('a:off');
+ $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
+ $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
+ $objWriter->endElement();
+
+ // a:ext
+ $objWriter->startElement('a:ext');
+ $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
+ $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
+ $objWriter->endElement();
+ } else if ($shape->getWidth() < 0 && $shape->getHeight() < 0) {
+ // a:off
+ $objWriter->startElement('a:off');
+ $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()+$shape->getWidth()));
+ $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()+$shape->getHeight));
+ $objWriter->endElement();
+
+ // a:ext
+ $objWriter->startElement('a:ext');
+ $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getWidth()));
+ $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getHeight()));
+ $objWriter->endElement();
+ } else if ($shape->getHeight() < 0) {
+ $objWriter->writeAttribute('flipV', 1);
+
+ // a:off
+ $objWriter->startElement('a:off');
+ $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
+ $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()+$shape->getHeight));
+ $objWriter->endElement();
+
+ // a:ext
+ $objWriter->startElement('a:ext');
+ $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
+ $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getHeight()));
+ $objWriter->endElement();
+ } else if ($shape->getWidth() < 0) {
+ $objWriter->writeAttribute('flipV', 1);
+
+ // a:off
+ $objWriter->startElement('a:off');
+ $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()+$shape->getWidth()));
+ $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
+ $objWriter->endElement();
+
+ // a:ext
+ $objWriter->startElement('a:ext');
+ $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getWidth()));
+ $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
+ $objWriter->endElement();
+ }
+
+ $objWriter->endElement();
+
+ // a:prstGeom
+ $objWriter->startElement('a:prstGeom');
+ $objWriter->writeAttribute('prst', 'line');
+ $objWriter->endElement();
+
+ if ($shape->getBorder()->getLineStyle() != PHPPowerPoint_Style_Border::LINE_NONE) {
+ $this->_writeBorder($objWriter, $shape->getBorder(), '');
+ }
+
+ $objWriter->endElement();
+
+ $objWriter->endElement();
+ }
/**
* Write Borders
View
8 Tests/05templated.php
@@ -80,6 +80,14 @@
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
+
+// Create a shape (line)
+$shape = $currentSlide->createLineShape(170, 180, 770, 180);
+$shape->getBorder()->getColor()->setARGB('FFC00000');
+
+// Create a shape (line)
+$shape = $currentSlide->createLineShape(170, 580, 770, 580);
+$shape->getBorder()->getColor()->setARGB('FFC00000');
// Save PowerPoint 2007 file
echo date('H:i:s') . " Write to PowerPoint2007 format\n";
View
1 changelog.txt
@@ -33,6 +33,7 @@ To be planned:
- Feature: (MB) Work item 2804 - Use of CDATA text when writing text
- Feature: (MB) Work item 1378 - Possibility to set borders on tables and table cells
- Feature: (MB) Work item 4921 - Access to additional properties of Text Boxes
+- Feature: (MB) Applied patches 7010 and 7020
- Feature: (MBaker) Implement autoloader
- Bugfix: (MBaker) Allow solid colour fill
- Bugfix: (MB) Work item 3910 - Table width setting Office 2007

0 comments on commit df76f08

Please sign in to comment.