Skip to content
This repository
Browse code

Applied patches 7010 and 7020

git-svn-id: https://phppowerpoint.svn.codeplex.com/svn/trunk@52156 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
commit df76f08e43212bf79b672a7b18c39cbb41cec868 1 parent c377aee
Maarten Balliauw maartenba authored
114 Classes/PHPPowerPoint/Shape/Line.php
... ... @@ -0,0 +1,114 @@
  1 +<?php
  2 +/**
  3 + * PHPPowerPoint
  4 + *
  5 + * Copyright (c) 2009 - 2010 PHPPowerPoint
  6 + *
  7 + * This library is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public
  9 + * License as published by the Free Software Foundation; either
  10 + * version 2.1 of the License, or (at your option) any later version.
  11 + *
  12 + * This library is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with this library; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * @category PHPPowerPoint
  22 + * @package PHPPowerPoint_Shape
  23 + * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  24 + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25 + * @version ##VERSION##, ##DATE##
  26 + */
  27 +
  28 +
  29 +/**
  30 + * PHPPowerPoint_Shape_Line
  31 + *
  32 + * @category PHPPowerPoint
  33 + * @package PHPPowerPoint_Shape
  34 + * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  35 + */
  36 +class PHPPowerPoint_Shape_Line extends PHPPowerPoint_Shape implements PHPPowerPoint_IComparable
  37 +{
  38 + /**
  39 + * Create a new PHPPowerPoint_Shape_Line instance
  40 + *
  41 + * @param int $columns Number of columns
  42 + */
  43 + public function __construct($fromX,$fromY,$toX,$toY)
  44 + {
  45 + parent::__construct();
  46 + $this->getBorder()->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE);
  47 +
  48 + $this->setOffsetX($fromX);
  49 + $this->setOffsetY($fromY);
  50 + $this->setWidth($toX-$fromX);
  51 + $this->setHeight($toY-$fromY);
  52 +
  53 + }
  54 +
  55 + /**
  56 + * Get hash code
  57 + *
  58 + * @return string Hash code
  59 + */
  60 + public function getHashCode() {
  61 + return md5(
  62 + $this->getBorder()->getLineStyle()
  63 + . parent::getHashCode()
  64 + . __CLASS__
  65 + );
  66 + }
  67 +
  68 + /**
  69 + * Hash index
  70 + *
  71 + * @var string
  72 + */
  73 + private $_hashIndex;
  74 +
  75 + /**
  76 + * Get hash index
  77 + *
  78 + * Note that this index may vary during script execution! Only reliable moment is
  79 + * while doing a write of a workbook and when changes are not allowed.
  80 + *
  81 + * @return string Hash index
  82 + */
  83 + public function getHashIndex() {
  84 + return $this->_hashIndex;
  85 + }
  86 +
  87 + /**
  88 + * Set hash index
  89 + *
  90 + * Note that this index may vary during script execution! Only reliable moment is
  91 + * while doing a write of a workbook and when changes are not allowed.
  92 + *
  93 + * @param string $value Hash index
  94 + */
  95 + public function setHashIndex($value) {
  96 + $this->_hashIndex = $value;
  97 + }
  98 +
  99 + /**
  100 + * Implement PHP __clone to create a deep clone, not just a shallow copy.
  101 + */
  102 + public function __clone() {
  103 + $vars = get_object_vars($this);
  104 + foreach ($vars as $key => $value) {
  105 + if ($key == '_parent') continue;
  106 +
  107 + if (is_object($value)) {
  108 + $this->$key = clone $value;
  109 + } else {
  110 + $this->$key = $value;
  111 + }
  112 + }
  113 + }
  114 +}
17 Classes/PHPPowerPoint/Slide.php
@@ -134,6 +134,23 @@ public function createRichTextShape()
134 134 }
135 135
136 136 /**
  137 + * Create line shape
  138 + *
  139 + * @param int $fromX Starting point x offset
  140 + * @param int $fromY Starting point y offset
  141 + * @param int $toX Ending point x offset
  142 + * @param int $toY Ending point y offset
  143 + * @return PHPPowerPoint_Shape_Line
  144 + */
  145 + public function createLineShape($fromX, $fromY, $toX, $toY)
  146 + {
  147 + $shape = new PHPPowerPoint_Shape_Line($fromX,$fromY,$toX,$toY);
  148 + $this->addShape($shape);
  149 +
  150 + return $shape;
  151 + }
  152 +
  153 + /**
137 154 * Create drawing shape
138 155 *
139 156 * @return PHPPowerPoint_Shape_Drawing
110 Classes/PHPPowerPoint/Writer/PowerPoint2007/Slide.php
@@ -140,6 +140,10 @@ public function writeSlide(PHPPowerPoint_Slide $pSlide = null)
140 140 {
141 141 $this->_writeTable($objWriter, $shape, $shapeId);
142 142 }
  143 + else if ($shape instanceof PHPPowerPoint_Shape_Line)
  144 + {
  145 + $this->_writeLineShape($objWriter, $shape, $shapeId);
  146 + }
143 147 else if ($shape instanceof PHPPowerPoint_Shape_BaseDrawing)
144 148 {
145 149 // Picture --> $relationId
@@ -783,6 +787,112 @@ private function _writeParagraphs(PHPPowerPoint_Shared_XMLWriter $objWriter, $pa
783 787 $objWriter->endElement();
784 788 }
785 789 }
  790 +
  791 + /**
  792 + * Write Line Shape
  793 + *
  794 + * @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer
  795 + * @param PHPPowerPoint_Shape_RichText $shape
  796 + * @param int $shapeId
  797 + * @throws Exception
  798 + */
  799 + private function _writeLineShape(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Shape_Line $shape = null,$shapeId)
  800 + {
  801 + // p:sp
  802 + $objWriter->startElement('p:cxnSp');
  803 +
  804 + // p:nvSpPr
  805 + $objWriter->startElement('p:nvCxnSpPr');
  806 +
  807 + // p:cNvPr
  808 + $objWriter->startElement('p:cNvPr');
  809 + $objWriter->writeAttribute('id', $shapeId);
  810 + $objWriter->writeAttribute('name', '');
  811 + $objWriter->endElement();
  812 +
  813 + // p:cNvCxnSpPr
  814 + $objWriter->writeElement('p:cNvCxnSpPr', null);
  815 +
  816 + // p:nvPr
  817 + $objWriter->writeElement('p:nvPr', null);
  818 +
  819 + $objWriter->endElement();
  820 +
  821 + // p:spPr
  822 + $objWriter->startElement('p:spPr');
  823 +
  824 + // a:xfrm
  825 + $objWriter->startElement('a:xfrm');
  826 +
  827 + if ($shape->getWidth() >= 0 && $shape->getHeight() >= 0) {
  828 + // a:off
  829 + $objWriter->startElement('a:off');
  830 + $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
  831 + $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
  832 + $objWriter->endElement();
  833 +
  834 + // a:ext
  835 + $objWriter->startElement('a:ext');
  836 + $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
  837 + $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
  838 + $objWriter->endElement();
  839 + } else if ($shape->getWidth() < 0 && $shape->getHeight() < 0) {
  840 + // a:off
  841 + $objWriter->startElement('a:off');
  842 + $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()+$shape->getWidth()));
  843 + $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()+$shape->getHeight));
  844 + $objWriter->endElement();
  845 +
  846 + // a:ext
  847 + $objWriter->startElement('a:ext');
  848 + $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getWidth()));
  849 + $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getHeight()));
  850 + $objWriter->endElement();
  851 + } else if ($shape->getHeight() < 0) {
  852 + $objWriter->writeAttribute('flipV', 1);
  853 +
  854 + // a:off
  855 + $objWriter->startElement('a:off');
  856 + $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
  857 + $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()+$shape->getHeight));
  858 + $objWriter->endElement();
  859 +
  860 + // a:ext
  861 + $objWriter->startElement('a:ext');
  862 + $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
  863 + $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getHeight()));
  864 + $objWriter->endElement();
  865 + } else if ($shape->getWidth() < 0) {
  866 + $objWriter->writeAttribute('flipV', 1);
  867 +
  868 + // a:off
  869 + $objWriter->startElement('a:off');
  870 + $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()+$shape->getWidth()));
  871 + $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
  872 + $objWriter->endElement();
  873 +
  874 + // a:ext
  875 + $objWriter->startElement('a:ext');
  876 + $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU(-$shape->getWidth()));
  877 + $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
  878 + $objWriter->endElement();
  879 + }
  880 +
  881 + $objWriter->endElement();
  882 +
  883 + // a:prstGeom
  884 + $objWriter->startElement('a:prstGeom');
  885 + $objWriter->writeAttribute('prst', 'line');
  886 + $objWriter->endElement();
  887 +
  888 + if ($shape->getBorder()->getLineStyle() != PHPPowerPoint_Style_Border::LINE_NONE) {
  889 + $this->_writeBorder($objWriter, $shape->getBorder(), '');
  890 + }
  891 +
  892 + $objWriter->endElement();
  893 +
  894 + $objWriter->endElement();
  895 + }
786 896
787 897 /**
788 898 * Write Borders
8 Tests/05templated.php
@@ -80,6 +80,14 @@
80 80 $textRun->getFont()->setBold(true)
81 81 ->setSize(60)
82 82 ->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
  83 +
  84 +// Create a shape (line)
  85 +$shape = $currentSlide->createLineShape(170, 180, 770, 180);
  86 +$shape->getBorder()->getColor()->setARGB('FFC00000');
  87 +
  88 +// Create a shape (line)
  89 +$shape = $currentSlide->createLineShape(170, 580, 770, 580);
  90 +$shape->getBorder()->getColor()->setARGB('FFC00000');
83 91
84 92 // Save PowerPoint 2007 file
85 93 echo date('H:i:s') . " Write to PowerPoint2007 format\n";
1  changelog.txt
@@ -33,6 +33,7 @@ To be planned:
33 33 - Feature: (MB) Work item 2804 - Use of CDATA text when writing text
34 34 - Feature: (MB) Work item 1378 - Possibility to set borders on tables and table cells
35 35 - Feature: (MB) Work item 4921 - Access to additional properties of Text Boxes
  36 +- Feature: (MB) Applied patches 7010 and 7020
36 37 - Feature: (MBaker) Implement autoloader
37 38 - Bugfix: (MBaker) Allow solid colour fill
38 39 - Bugfix: (MB) Work item 3910 - Table width setting Office 2007

0 comments on commit df76f08

Please sign in to comment.
Something went wrong with that request. Please try again.