Skip to content

Commit 15ca8f2

Browse files
committed
Merge branch 'develop' into html
2 parents 19a69e2 + e78489b commit 15ca8f2

File tree

20 files changed

+389
-133
lines changed

20 files changed

+389
-133
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.10.0 - Not yet released
66

7-
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML writer is initiated.
7+
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML support is enabled.
88

99
### Features
1010

@@ -31,11 +31,13 @@ This release marked heavy refactorings on internal code structure with the creat
3131
- Endnote: Ability to add endnotes - @ivanlanin
3232
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
3333
- ODT Writer: Basic table writing support - @ivanlanin
34+
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
3435
- HTML Writer: Basic HTML writer initiated - @ivanlanin
3536

3637
### Bugfixes
3738

3839
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
40+
- Documentation : Error in a fonction - @theBeerNut GH-195
3941

4042
### Deprecated
4143

@@ -64,6 +66,8 @@ This release marked heavy refactorings on internal code structure with the creat
6466
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
6567
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
6668
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
69+
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
70+
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
6771

6872
## 0.9.1 - 27 Mar 2014
6973

docs/general.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ name. Use the following functions:
108108

109109
.. code-block:: php
110110
111-
$properties = $phpWord->getProperties();
111+
$properties = $phpWord->getDocumentProperties();
112112
$properties->setCreator('My name');
113113
$properties->setCompany('My factory');
114114
$properties->setTitle('My title');

samples/Sample_13_Images.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@
1010
$section->addText('Local image without any styles:');
1111
$section->addImage('resources/_mars.jpg');
1212
$section->addTextBreak(2);
13-
//
13+
1414
$section->addText('Local image with styles:');
1515
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
1616
$section->addTextBreak(2);
1717

18+
// Remote image
1819
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
1920
$section->addText("Remote image from: {$source}");
2021
$section->addImage($source);
2122

23+
//Wrapping style
24+
$text = str_repeat('Hello World! ', 15);
25+
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
26+
foreach ($wrappingStyles as $wrappingStyle) {
27+
$section->addTextBreak(5);
28+
$section->addText('Wrapping style ' . $wrappingStyle);
29+
$section->addImage('resources/_earth.jpg', array('marginTop' => -1, 'marginLeft' => 1,
30+
'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
31+
$section->addText($text);
32+
}
33+
2234
// Save file
2335
echo write($phpWord, basename(__FILE__, '.php'), $writers);
2436
if (!CLI) {

samples/Sample_Header.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
/**
4141
* Get results
4242
*
43-
* @param array $writers
43+
* @param \PhpOffice\PhpWord\PhpWord $phpWord
4444
* @param string $filename
45+
* @param array $writers
4546
* @return string
4647
*/
4748
function write($phpWord, $filename, $writers)

src/PhpWord/Element/Image.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,18 @@ public function __construct($source, $style = null, $isWatermark = false)
131131
$this->source = $source;
132132
$this->isWatermark = $isWatermark;
133133
$this->style = $this->setStyle(new ImageStyle(), $style, true);
134-
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
135-
$this->style->setWidth($imgData[0]);
136-
$this->style->setHeight($imgData[1]);
134+
$styleWidth = $this->style->getWidth();
135+
$styleHeight = $this->style->getHeight();
136+
list($actualWidth, $actualHeight) = $imgData;
137+
if (!($styleWidth && $styleHeight)) {
138+
if ($styleWidth == null && $styleHeight == null) {
139+
$this->style->setWidth($actualWidth);
140+
$this->style->setHeight($actualHeight);
141+
} elseif ($styleWidth) {
142+
$this->style->setHeight($actualHeight * ($styleWidth / $actualWidth));
143+
} else {
144+
$this->style->setWidth($actualWidth * ($styleHeight / $actualHeight));
145+
}
137146
}
138147
$this->setImageFunctions();
139148
}

src/PhpWord/Reader/Word2007.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function readRelationships($filename)
128128
if ($zip->open($filename) === true) {
129129
for ($i = 0; $i < $zip->numFiles; $i++) {
130130
$xmlFile = $zip->getNameIndex($i);
131-
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath) {
131+
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
132132
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
133133
$this->rels[$docPart] = $this->getRels($filename, $xmlFile, 'word/');
134134
}

src/PhpWord/Shared/ZipArchive.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ public function getFromName($filename)
218218
public function getNameIndex($index)
219219
{
220220
$list = $this->zip->listContent();
221-
$listCount = count($list);
222-
if ($index <= $listCount) {
221+
if (isset($list[$index])) {
223222
return $list[$index]['filename'];
224223
} else {
225224
return false;

src/PhpWord/Style/AbstractStyle.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ protected function setBoolVal($value, $default = null)
105105
/**
106106
* Set integer value
107107
*
108-
* @param integer|null $value
108+
* @param mixed $value
109109
* @param integer|null $default
110110
* @return integer|null
111111
*/
112112
protected function setIntVal($value, $default = null)
113113
{
114-
$value = intval($value);
115114
if (!is_int($value)) {
116115
$value = $default;
117116
}
@@ -128,7 +127,6 @@ protected function setIntVal($value, $default = null)
128127
*/
129128
protected function setFloatVal($value, $default = null)
130129
{
131-
$value = floatval($value);
132130
if (!is_float($value)) {
133131
$value = $default;
134132
}

src/PhpWord/Style/ListItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public function getNumStyle()
100100

101101
/**
102102
* Set numbering style name
103+
*
104+
* @param string $value
103105
*/
104106
public function setNumStyle($value)
105107
{

src/PhpWord/Writer/Word2007/Base.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -427,25 +427,22 @@ protected function writeImage(XMLWriter $xmlWriter, Image $image, $withoutP = fa
427427
$marginTop = $style->getMarginTop();
428428
$marginLeft = $style->getMarginLeft();
429429
$wrappingStyle = $style->getWrappingStyle();
430+
$w10wrapType = null;
430431

431432
if (!$withoutP) {
432433
$xmlWriter->startElement('w:p');
433-
434434
if (!is_null($align)) {
435435
$xmlWriter->startElement('w:pPr');
436436
$xmlWriter->startElement('w:jc');
437437
$xmlWriter->writeAttribute('w:val', $align);
438-
$xmlWriter->endElement();
439-
$xmlWriter->endElement();
438+
$xmlWriter->endElement(); // w:jc
439+
$xmlWriter->endElement(); // w:pPr
440440
}
441441
}
442442
$xmlWriter->startElement('w:r');
443-
444443
$xmlWriter->startElement('w:pict');
445-
446444
$xmlWriter->startElement('v:shape');
447445
$xmlWriter->writeAttribute('type', '#_x0000_t75');
448-
449446
$imgStyle = '';
450447
if (null !== $width) {
451448
$imgStyle .= 'width:' . $width . 'px;';
@@ -459,33 +456,38 @@ protected function writeImage(XMLWriter $xmlWriter, Image $image, $withoutP = fa
459456
if (null !== $marginLeft) {
460457
$imgStyle .= 'margin-left:' . $marginLeft . 'in;';
461458
}
462-
463459
switch ($wrappingStyle) {
464460
case ImageStyle::WRAPPING_STYLE_BEHIND:
465461
$imgStyle .= 'position:absolute;z-index:-251658752;';
466462
break;
463+
case ImageStyle::WRAPPING_STYLE_INFRONT:
464+
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
465+
break;
467466
case ImageStyle::WRAPPING_STYLE_SQUARE:
468467
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
468+
$w10wrapType = 'square';
469469
break;
470470
case ImageStyle::WRAPPING_STYLE_TIGHT:
471-
$imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute';
472-
break;
473-
case ImageStyle::WRAPPING_STYLE_INFRONT:
474-
$imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
471+
$imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
472+
$w10wrapType = 'tight';
475473
break;
476474
}
477-
478475
$xmlWriter->writeAttribute('style', $imgStyle);
479476

480477
$xmlWriter->startElement('v:imagedata');
481478
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
482479
$xmlWriter->writeAttribute('o:title', '');
483-
$xmlWriter->endElement();
484-
$xmlWriter->endElement();
480+
$xmlWriter->endElement(); // v:imagedata
485481

486-
$xmlWriter->endElement();
482+
if (!is_null($w10wrapType)) {
483+
$xmlWriter->startElement('w10:wrap');
484+
$xmlWriter->writeAttribute('type', $w10wrapType);
485+
$xmlWriter->endElement(); // w10:wrap
486+
}
487487

488-
$xmlWriter->endElement();
488+
$xmlWriter->endElement(); // v:shape
489+
$xmlWriter->endElement(); // w:pict
490+
$xmlWriter->endElement(); // w:r
489491

490492
if (!$withoutP) {
491493
$xmlWriter->endElement(); // w:p

0 commit comments

Comments
 (0)