Skip to content

Commit f33d8f3

Browse files
committed
Merge branch 'develop' into issue192
2 parents 1468e7d + ee07eb7 commit f33d8f3

File tree

15 files changed

+255
-333
lines changed

15 files changed

+255
-333
lines changed

src/PhpPresentation/Reader/PowerPoint97.php

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ private function loadPicturesStream()
464464
$stream = $this->streamPictures;
465465

466466
$pos = 0;
467-
$readSuccess = true;
468467
do {
469468
$arrayRH = $this->loadRecordHeader($stream, $pos);
470469
$pos += 8;
470+
$readSuccess = false;
471471
if ($arrayRH['recVer'] == 0x00 && ($arrayRH['recType'] == 0xF007 || ($arrayRH['recType'] >= 0xF018 && $arrayRH['recType'] <= 0xF117))) {
472472
//@link : http://msdn.microsoft.com/en-us/library/dd950560(v=office.12).aspx
473473
if ($arrayRH['recType'] == 0xF007) {
@@ -481,8 +481,7 @@ private function loadPicturesStream()
481481
$this->arrayPictures[] = $arrayRecord['picture'];
482482
}
483483
}
484-
} else {
485-
$readSuccess = false;
484+
$readSuccess = true;
486485
}
487486
} while ($readSuccess === true);
488487
}
@@ -677,11 +676,11 @@ public static function getInt4d($data, $pos)
677676
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
678677
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
679678
$or24 = ord($data[$pos + 3]);
679+
680+
$ord24 = ($or24 & 127) << 24;
680681
if ($or24 >= 128) {
681682
// negative number
682683
$ord24 = -abs((256 - $or24) << 24);
683-
} else {
684-
$ord24 = ($or24 & 127) << 24;
685684
}
686685
return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $ord24;
687686
}
@@ -825,37 +824,36 @@ private function readRecordDocumentContainer($stream, $pos)
825824
$fontCollection['recLen'] -= 8;
826825
if ($fontEntityAtom['recVer'] != 0x0 || $fontEntityAtom['recInstance'] > 128 || $fontEntityAtom['recType'] != self::RT_FONTENTITYATOM) {
827826
throw new \Exception('File PowerPoint 97 in error (Location : RTDocument > RT_Environment > RT_FontCollection > RT_FontEntityAtom).');
828-
} else {
829-
$string = '';
830-
for ($inc = 0; $inc < 32; $inc++) {
831-
$char = self::getInt2d($stream, $pos);
832-
$pos += 2;
833-
$fontCollection['recLen'] -= 2;
834-
$string .= chr($char);
835-
}
836-
$this->arrayFonts[] = $string;
837-
838-
// lfCharSet (1 byte)
839-
$pos += 1;
840-
$fontCollection['recLen'] -= 1;
841-
842-
// fEmbedSubsetted (1 bit)
843-
// unused (7 bits)
844-
$pos += 1;
845-
$fontCollection['recLen'] -= 1;
846-
847-
// rasterFontType (1 bit)
848-
// deviceFontType (1 bit)
849-
// truetypeFontType (1 bit)
850-
// fNoFontSubstitution (1 bit)
851-
// reserved (4 bits)
852-
$pos += 1;
853-
$fontCollection['recLen'] -= 1;
854-
855-
// lfPitchAndFamily (1 byte)
856-
$pos += 1;
857-
$fontCollection['recLen'] -= 1;
858827
}
828+
$string = '';
829+
for ($inc = 0; $inc < 32; $inc++) {
830+
$char = self::getInt2d($stream, $pos);
831+
$pos += 2;
832+
$fontCollection['recLen'] -= 2;
833+
$string .= chr($char);
834+
}
835+
$this->arrayFonts[] = $string;
836+
837+
// lfCharSet (1 byte)
838+
$pos += 1;
839+
$fontCollection['recLen'] -= 1;
840+
841+
// fEmbedSubsetted (1 bit)
842+
// unused (7 bits)
843+
$pos += 1;
844+
$fontCollection['recLen'] -= 1;
845+
846+
// rasterFontType (1 bit)
847+
// deviceFontType (1 bit)
848+
// truetypeFontType (1 bit)
849+
// fNoFontSubstitution (1 bit)
850+
// reserved (4 bits)
851+
$pos += 1;
852+
$fontCollection['recLen'] -= 1;
853+
854+
// lfPitchAndFamily (1 byte)
855+
$pos += 1;
856+
$fontCollection['recLen'] -= 1;
859857

860858
$fontEmbedData1 = $this->loadRecordHeader($stream, $pos);
861859
if ($fontEmbedData1['recVer'] == 0x0 && $fontEmbedData1['recInstance'] >= 0x000 && $fontEmbedData1['recInstance'] <= 0x003 && $fontEmbedData1['recType'] == self::RT_FONTEMBEDDATABLOB) {

src/PhpPresentation/Shape/RichText.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,12 @@ public function getParagraphs()
351351
*/
352352
public function setParagraphs($paragraphs = null)
353353
{
354-
if (is_array($paragraphs)) {
355-
$this->richTextParagraphs = $paragraphs;
356-
$this->activeParagraph = count($this->richTextParagraphs) - 1;
357-
} else {
354+
if (!is_array($paragraphs)) {
358355
throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] array passed.");
359356
}
360357

358+
$this->richTextParagraphs = $paragraphs;
359+
$this->activeParagraph = count($this->richTextParagraphs) - 1;
361360
return $this;
362361
}
363362

src/PhpPresentation/Slide/Background/Image.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public function getPath()
4949
public function setPath($pValue = '', $pVerifyFile = true)
5050
{
5151
if ($pVerifyFile) {
52-
if (file_exists($pValue)) {
53-
$this->path = $pValue;
54-
55-
if ($this->width == 0 && $this->height == 0) {
56-
// Get width/height
57-
list($this->width, $this->height) = getimagesize($pValue);
58-
}
59-
} else {
52+
if (!file_exists($pValue)) {
6053
throw new \Exception("File $pValue not found!");
6154
}
55+
$this->path = $pValue;
56+
57+
if ($this->width == 0 && $this->height == 0) {
58+
// Get width/height
59+
list($this->width, $this->height) = getimagesize($pValue);
60+
}
61+
6262
} else {
6363
$this->path = $pValue;
6464
}

src/PhpPresentation/Style/Alignment.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class Alignment implements ComparableInterface
3939
const VERTICAL_TOP = 't';
4040
const VERTICAL_CENTER = 'ctr';
4141

42+
private $supportedStyles = array(
43+
self::HORIZONTAL_GENERAL,
44+
self::HORIZONTAL_LEFT,
45+
self::HORIZONTAL_RIGHT,
46+
);
47+
4248
/**
4349
* Horizontal
4450
*
@@ -58,28 +64,28 @@ class Alignment implements ComparableInterface
5864
*
5965
* @var int
6066
*/
61-
private $level;
67+
private $level = 0;
6268

6369
/**
6470
* Indent - only possible with horizontal alignment left and right
6571
*
6672
* @var int
6773
*/
68-
private $indent;
74+
private $indent = 0;
6975

7076
/**
7177
* Margin left - only possible with horizontal alignment left and right
7278
*
7379
* @var int
7480
*/
75-
private $marginLeft;
81+
private $marginLeft = 0;
7682

7783
/**
7884
* Margin right - only possible with horizontal alignment left and right
7985
*
8086
* @var int
8187
*/
82-
private $marginRight;
88+
private $marginRight = 0;
8389

8490
/**
8591
* Hash index
@@ -96,10 +102,6 @@ public function __construct()
96102
// Initialise values
97103
$this->horizontal = self::HORIZONTAL_LEFT;
98104
$this->vertical = self::VERTICAL_BASE;
99-
$this->level = 0;
100-
$this->indent = 0;
101-
$this->marginLeft = 0;
102-
$this->marginRight = 0;
103105
}
104106

105107
/**
@@ -199,10 +201,8 @@ public function getIndent()
199201
*/
200202
public function setIndent($pValue = 0)
201203
{
202-
if ($pValue > 0) {
203-
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
204-
$pValue = 0; // indent not supported
205-
}
204+
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
205+
$pValue = 0; // indent not supported
206206
}
207207

208208
$this->indent = $pValue;
@@ -228,10 +228,8 @@ public function getMarginLeft()
228228
*/
229229
public function setMarginLeft($pValue = 0)
230230
{
231-
if ($pValue > 0) {
232-
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
233-
$pValue = 0; // margin left not supported
234-
}
231+
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
232+
$pValue = 0; // margin left not supported
235233
}
236234

237235
$this->marginLeft = $pValue;
@@ -257,10 +255,8 @@ public function getMarginRight()
257255
*/
258256
public function setMarginRight($pValue = 0)
259257
{
260-
if ($pValue > 0) {
261-
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
262-
$pValue = 0; // margin left not supported
263-
}
258+
if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
259+
$pValue = 0; // margin right not supported
264260
}
265261

266262
$this->marginRight = $pValue;

src/PhpPresentation/Writer/ODPresentation.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,10 @@ public function setUseDiskCaching($pValue = false, $pDirectory = null)
165165
$this->useDiskCaching = $pValue;
166166

167167
if (!is_null($pDirectory)) {
168-
if (is_dir($pDirectory)) {
169-
$this->diskCachingDirectory = $pDirectory;
170-
} else {
168+
if (!is_dir($pDirectory)) {
171169
throw new \Exception("Directory does not exist: $pDirectory");
172170
}
171+
$this->diskCachingDirectory = $pDirectory;
173172
}
174173

175174
return $this;

0 commit comments

Comments
 (0)