Skip to content

Commit f93382e

Browse files
author
Mario Raspe
committed
Create fork from PHPOffice/PHPWord 0.18.2, added some special features and fixes.
1 parent aca1078 commit f93382e

File tree

17 files changed

+645
-13
lines changed

17 files changed

+645
-13
lines changed

src/PhpWord/Element/AbstractElement.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ abstract class AbstractElement
7777
*/
7878
protected $elementId;
7979

80+
/**
81+
* Element counter
82+
*
83+
* @var int
84+
*/
85+
private static $elementCounter = 1;
86+
8087
/**
8188
* Relation Id
8289
*
@@ -114,6 +121,11 @@ abstract class AbstractElement
114121
*/
115122
private $parentContainer;
116123

124+
/**
125+
* @var AbstractElement
126+
*/
127+
private $parentContainerElement;
128+
117129
/**
118130
* Has media relation flag; true for Link, Image, and Object
119131
*
@@ -254,7 +266,7 @@ public function getElementId()
254266
*/
255267
public function setElementId()
256268
{
257-
$this->elementId = substr(md5(rand()), 0, 6);
269+
$this->elementId = 'el' . self::$elementCounter++;
258270
}
259271

260272
/**
@@ -354,6 +366,8 @@ public function getParent()
354366
*/
355367
public function setParentContainer(self $container)
356368
{
369+
$this->setParentContainerElement($container);
370+
357371
$this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
358372
$this->parent = $container;
359373

@@ -375,6 +389,22 @@ public function setParentContainer(self $container)
375389
$this->setCollectionRelation();
376390
}
377391

392+
/**
393+
* @param AbstractElement $container
394+
*/
395+
public function setParentContainerElement(AbstractElement $container)
396+
{
397+
$this->parentContainerElement = $container;
398+
}
399+
400+
/**
401+
* @return string
402+
*/
403+
public function getParentContainerElement()
404+
{
405+
return $this->parentContainerElement;
406+
}
407+
378408
/**
379409
* Set relation Id for media elements (link, image, object; legacy of OOXML)
380410
*

src/PhpWord/Element/Cell.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,12 @@ public function getWidth()
7474
{
7575
return $this->width;
7676
}
77+
78+
/**
79+
* @param int $width
80+
*/
81+
public function setWidth($width = null)
82+
{
83+
$this->width = $width;
84+
}
7785
}

src/PhpWord/Element/CheckBox.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class CheckBox extends Text
3333
*/
3434
private $name;
3535

36+
/**
37+
* Checked state
38+
*
39+
* @var bool
40+
*/
41+
private $checked = false;
42+
3643
/**
3744
* Create new instance
3845
*
@@ -69,4 +76,22 @@ public function getName()
6976
{
7077
return $this->name;
7178
}
79+
80+
/**
81+
* @param bool $value
82+
* @return $this
83+
*/
84+
public function setChecked($value = true)
85+
{
86+
$this->checked = $value;
87+
return $this;
88+
}
89+
90+
/**
91+
* @return bool
92+
*/
93+
public function isChecked()
94+
{
95+
return $this->checked;
96+
}
7297
}

src/PhpWord/Element/Image.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Image extends AbstractElement
3737
const SOURCE_ARCHIVE = 'archive'; // Image in archives zip://$archive#$image
3838
const SOURCE_STRING = 'string'; // Image from string
3939

40+
/**
41+
* Image type WMF
42+
*/
43+
const IMAGETYPE_WMF = 'WMF';
44+
4045
/**
4146
* Image source
4247
*
@@ -409,6 +414,9 @@ private function checkImage()
409414
// Check image data
410415
if ($this->sourceType == self::SOURCE_ARCHIVE) {
411416
$imageData = $this->getArchiveImageSize($this->source);
417+
} elseif (strtolower(pathinfo($this->source, PATHINFO_EXTENSION)) === 'wmf') {
418+
// WMF image is dimensionless
419+
$imageData = array(null, null, self::IMAGETYPE_WMF);
412420
} elseif ($this->sourceType == self::SOURCE_STRING) {
413421
$imageData = $this->getStringImageSize($this->source);
414422
} else {
@@ -420,7 +428,7 @@ private function checkImage()
420428
list($actualWidth, $actualHeight, $imageType) = $imageData;
421429

422430
// Check image type support
423-
$supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG);
431+
$supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG, self::IMAGETYPE_WMF);
424432
if ($this->sourceType != self::SOURCE_GD && $this->sourceType != self::SOURCE_STRING) {
425433
$supportedTypes = array_merge($supportedTypes, array(IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM));
426434
}
@@ -429,7 +437,7 @@ private function checkImage()
429437
}
430438

431439
// Define image functions
432-
$this->imageType = image_type_to_mime_type($imageType);
440+
$this->imageType = $imageType === self::IMAGETYPE_WMF ? 'image/x-wmf' : image_type_to_mime_type($imageType);
433441
$this->setFunctions();
434442
$this->setProportionalSize($actualWidth, $actualHeight);
435443
}
@@ -551,6 +559,9 @@ private function setFunctions()
551559
case 'image/tiff':
552560
$this->imageExtension = 'tif';
553561
break;
562+
case 'image/x-wmf':
563+
$this->imageExtension = 'wmf';
564+
break;
554565
}
555566
}
556567

src/PhpWord/Element/Table.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class Table extends AbstractElement
4545
*/
4646
private $width = null;
4747

48+
/**
49+
* @var bool
50+
*/
51+
private $hasDifferentCellWidths = false;
52+
4853
/**
4954
* Create a new table
5055
*
@@ -171,4 +176,20 @@ public function findFirstDefinedCellWidths()
171176

172177
return $cellWidths;
173178
}
179+
180+
/**
181+
* @param bool $value
182+
*/
183+
public function setDifferentCellWidths($value = true)
184+
{
185+
$this->hasDifferentCellWidths = $value;
186+
}
187+
188+
/**
189+
* @return bool
190+
*/
191+
public function hasDifferentCellWidths()
192+
{
193+
return $this->hasDifferentCellWidths === true;
194+
}
174195
}

src/PhpWord/Style/Border.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ class Border extends AbstractStyle
106106
*/
107107
protected $borderBottomStyle;
108108

109+
/**
110+
* Borders Space in points
111+
*
112+
* @var int|float
113+
*/
114+
protected $bordersSpace = 24;
115+
116+
/**
117+
* Get borders space in points
118+
*
119+
* @return integer
120+
*/
121+
public function getBordersSpace()
122+
{
123+
return $this->bordersSpace;
124+
}
125+
126+
/**
127+
* @param int $bordersSpace
128+
*/
129+
public function setBordersSpace($bordersSpace)
130+
{
131+
$this->bordersSpace = $bordersSpace;
132+
}
133+
109134
/**
110135
* Get border size
111136
*

src/PhpWord/Style/Cell.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ class Cell extends Border
138138
*/
139139
private $unit = TblWidth::TWIP;
140140

141+
/**
142+
* @var int|float
143+
*/
144+
private $marginTopSize;
145+
146+
/**
147+
* @var int|float
148+
*/
149+
private $marginBottomSize;
150+
151+
/**
152+
* @var int|float
153+
*/
154+
private $marginLeftSize;
155+
156+
/**
157+
* @var int|float
158+
*/
159+
private $marginRightSize;
160+
141161
/**
142162
* Get vertical align.
143163
*
@@ -337,4 +357,98 @@ public function getDefaultBorderColor()
337357
{
338358
return self::DEFAULT_BORDER_COLOR;
339359
}
360+
361+
/**
362+
* @return float|int
363+
*/
364+
public function getMarginTopSize()
365+
{
366+
return $this->marginTopSize;
367+
}
368+
369+
/**
370+
* @param int|float $value
371+
* @return $this
372+
*/
373+
public function setMarginTopSize($value = null)
374+
{
375+
$this->marginTopSize = $this->setNumericVal($value, $this->marginTopSize);
376+
return $this;
377+
}
378+
379+
/**
380+
* @return float|int
381+
*/
382+
public function getMarginBottomSize()
383+
{
384+
return $this->marginBottomSize;
385+
}
386+
387+
/**
388+
* @param int|float $value
389+
* @return $this
390+
*/
391+
public function setMarginBottomSize($value = null)
392+
{
393+
$this->marginBottomSize = $this->setNumericVal($value, $this->marginBottomSize);
394+
return $this;
395+
}
396+
397+
/**
398+
* @return float|int
399+
*/
400+
public function getMarginLeftSize()
401+
{
402+
return $this->marginLeftSize;
403+
}
404+
405+
/**
406+
* @param int|float $value
407+
* @return $this
408+
*/
409+
public function setMarginLeftSize($value = null)
410+
{
411+
$this->marginLeftSize = $this->setNumericVal($value, $this->marginLeftSize);
412+
return $this;
413+
}
414+
415+
/**
416+
* @return float|int
417+
*/
418+
public function getMarginRightSize()
419+
{
420+
return $this->marginRightSize;
421+
}
422+
423+
/**
424+
* @param int|float $value
425+
* @return $this
426+
*/
427+
public function setMarginRightSize($value = null)
428+
{
429+
$this->marginRightSize = $this->setNumericVal($value, $this->marginRightSize);
430+
return $this;
431+
}
432+
433+
/**
434+
* @return array
435+
*/
436+
public function getMarginSize()
437+
{
438+
return array(
439+
$this->getMarginTopSize(),
440+
$this->getMarginLeftSize(),
441+
$this->getMarginRightSize(),
442+
$this->getMarginBottomSize()
443+
);
444+
}
445+
446+
/**
447+
* @return bool
448+
*/
449+
public function hasMargin()
450+
{
451+
$margins = $this->getMarginSize();
452+
return $margins !== array_filter($margins, 'is_null');
453+
}
340454
}

0 commit comments

Comments
 (0)