Skip to content

Commit

Permalink
Merge pull request #10 from PHPOffice/develop
Browse files Browse the repository at this point in the history
Version 0.2.5
  • Loading branch information
Progi1984 committed Mar 3, 2016
2 parents 1e93359 + fc5243e commit 0525632
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 196 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@

### Features
- Added missing features for supporting PHPWord

## 0.2.4

### Changes
- XMLWriter : Refactoring for improving performances

## 0.2.5

### Features
- Added Zip Adapters (PclZip & ZipArchive)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.2.4
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"pclzip/pclzip": "^2.8"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
58 changes: 58 additions & 0 deletions src/Common/Adapter/Zip/PclZipAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace PhpOffice\Common\Adapter\Zip;

use PclZip;

class PclZipAdapter implements ZipInterface
{
/**
* @var PclZip
*/
protected $oPclZip;

/**
* @var string
*/
protected $tmpDir;

/**
* @param $filename
* @return $this
*/
public function open($filename)
{
$this->oPclZip = new PclZip($filename);
$this->tmpDir = sys_get_temp_dir();
return $this;
}

/**
* @return $this
*/
public function close()
{
return $this;
}

/**
* @param $localname
* @param $contents
* @return $this
* @throws \Exception
*/
public function addFromString($localname, $contents)
{
$pathData = pathinfo($localname);

$hFile = fopen($this->tmpDir.'/'.$pathData['basename'], "wb");
fwrite($hFile, $contents);
fclose($hFile);

$res = $this->oPclZip->add($this->tmpDir.'/'.$pathData['basename'], PCLZIP_OPT_REMOVE_PATH, $this->tmpDir, PCLZIP_OPT_ADD_PATH, $pathData['dirname']);
if ($res == 0) {
throw new \Exception("Error zipping files : " . $this->oPclZip->errorInfo(true));
}
unlink($this->tmpDir.'/'.$pathData['basename']);
return $this;
}
}
59 changes: 59 additions & 0 deletions src/Common/Adapter/Zip/ZipArchiveAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace PhpOffice\Common\Adapter\Zip;

use ZipArchive;

class ZipArchiveAdapter implements ZipInterface
{
/**
* @var ZipArchive
*/
protected $oZipArchive;

/**
* @var string
*/
protected $filename;

/**
* @param string $filename
* @throws \Exception Could not open $this->filename for writing.
* @return mixed
*/
public function open($filename)
{
$this->filename = $filename;
$this->oZipArchive = new ZipArchive();

if ($this->oZipArchive->open($this->filename, ZipArchive::OVERWRITE) === true) {
return $this;
}
if ($this->oZipArchive->open($this->filename, ZipArchive::CREATE) === true) {
return $this;
}
throw new \Exception("Could not open $this->filename for writing.");
}

/**
* @return $this
* @throws \Exception Could not close zip file $this->filename.
*/
public function close()
{
if ($this->oZipArchive->close() === false) {
throw new \Exception("Could not close zip file $this->filename.");
}
return $this;
}

/**
* @param $localname
* @param $contents
* @return bool
*/
public function addFromString($localname, $contents)
{
return $this->oZipArchive->addFromString($localname, $contents);
}
}
10 changes: 10 additions & 0 deletions src/Common/Adapter/Zip/ZipInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace PhpOffice\Common\Adapter\Zip;

interface ZipInterface
{
public function open($filename);
public function close();
public function addFromString($localname, $contents);
}
73 changes: 34 additions & 39 deletions src/Common/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Drawing
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
* @return int
*/
public static function pixelsToEmu($pValue = 0)
{
Expand All @@ -38,22 +38,21 @@ public static function pixelsToEmu($pValue = 0)
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
* @return int
*/
public static function emuToPixels($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 9525);
} else {
if ($pValue == 0) {
return 0;
}
return round($pValue / 9525);
}

/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
* @return float
*/
public static function pixelsToPoints($pValue = 0)
{
Expand All @@ -64,37 +63,35 @@ public static function pixelsToPoints($pValue = 0)
* Convert points width to centimeters
*
* @param int $pValue Value in points
* @return int Value in centimeters
* @return float
*/
public static function pointsToCentimeters($pValue = 0)
{
if ($pValue != 0) {
return ((($pValue * 1.333333333) / self::DPI_96) * 2.54);
} else {
if ($pValue == 0) {
return 0;
}
return ((($pValue * 1.333333333) / self::DPI_96) * 2.54);
}

/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
* @return float
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue != 0) {
return $pValue * 1.333333333;
} else {
if ($pValue == 0) {
return 0;
}
return $pValue * 1.333333333;
}

/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return int Value in centimeters
* @return float
*/
public static function pixelsToCentimeters($pValue = 0)
{
Expand All @@ -106,22 +103,21 @@ public static function pixelsToCentimeters($pValue = 0)
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return int Value in pixels
* @return float
*/
public static function centimetersToPixels($pValue = 0)
{
if ($pValue != 0) {
return ($pValue / 2.54) * self::DPI_96;
} else {
if ($pValue == 0) {
return 0;
}
return ($pValue / 2.54) * self::DPI_96;
}

/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
* @return int
*/
public static function degreesToAngle($pValue = 0)
{
Expand All @@ -132,85 +128,84 @@ public static function degreesToAngle($pValue = 0)
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
* @return int
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 60000);
} else {
if ($pValue == 0) {
return 0;
}
return round($pValue / 60000);
}

/**
* Convert centimeters width to twips
*
* @param integer $pValue
* @return float
*/
public static function centimetersToTwips($pValue = 0)
{
if ($pValue != 0) {
return $pValue * 566.928;
} else {
if ($pValue == 0) {
return 0;
}
return $pValue * 566.928;
}

/**
* Convert twips width to centimeters
*
* @param integer $pValue
* @return float
*/
public static function twipsToCentimeters($pValue = 0)
{
if ($pValue != 0) {
return $pValue / 566.928;
} else {
if ($pValue == 0) {
return 0;
}
return $pValue / 566.928;
}

/**
* Convert inches width to twips
*
* @param integer $pValue
* @return float
*/
public static function inchesToTwips($pValue = 0)
{
if ($pValue != 0) {
return $pValue * 1440;
} else {
if ($pValue == 0) {
return 0;
}
return $pValue * 1440;
}

/**
* Convert twips width to inches
*
* @param integer $pValue
* @return float
*/
public static function twipsToInches($pValue = 0)
{
if ($pValue != 0) {
return $pValue / 1440;
} else {
if ($pValue == 0) {
return 0;
}
return $pValue / 1440;
}

/**
* Convert twips width to pixels
*
* @param integer $pValue
* @return float
*/
public static function twipsToPixels($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 15.873984);
} else {
if ($pValue == 0) {
return 0;
}
return round($pValue / 15.873984);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Common/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public static function controlCharacterOOXML2PHP($value = '')
/**
* Check if a string contains UTF-8 data
*
* @deprecated 0.2.4 Use `Zend\Stdlib\StringUtils::isValidUtf8` instead.
*
* @param string $value
* @return boolean
*/
Expand Down
Loading

0 comments on commit 0525632

Please sign in to comment.