https://github.com/PHPOffice/PHPWord/issues/58 - Part VIII (Autoloader).
This commit is contained in:
parent
90a118852c
commit
ab96c75b08
|
|
@ -1,6 +1,6 @@
|
||||||
# PhpWord
|
# PhpWord
|
||||||
|
|
||||||
[](https://travis-ci.org/PHPOffice/PhpWord)
|
[](https://travis-ci.org/PhpOffice/PhpWord)
|
||||||
[](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword)
|
[](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword)
|
||||||
|
|
||||||
__OpenXML - Read, Write and Create Word documents in PHP.__
|
__OpenXML - Read, Write and Create Word documents in PHP.__
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,36 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests;
|
namespace PhpWord\Tests;
|
||||||
|
|
||||||
use PHPWord_Autoloader;
|
use PhpOffice\PhpWord\Autoloader;
|
||||||
use PHPWord_Autoloader as Autoloader;
|
|
||||||
|
|
||||||
class AutoloaderTest extends \PHPUnit_Framework_TestCase
|
class AutoloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testRegister()
|
public function testRegister()
|
||||||
{
|
{
|
||||||
PHPWord_Autoloader::register();
|
Autoloader::register();
|
||||||
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
|
$this->assertContains(
|
||||||
$this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
|
array('PhpOffice\\PhpWord\\Autoloader', 'autoload'),
|
||||||
}
|
\spl_autoload_functions()
|
||||||
|
|
||||||
public function testAutoloadLegacy()
|
|
||||||
{
|
|
||||||
$this->assertNull(
|
|
||||||
PHPWord_Autoloader::load('Foo'),
|
|
||||||
'PHPWord_Autoloader::load() is trying to load classes outside of the PhpWord namespace'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
PHPWord_Autoloader::load('PhpWord'),
|
|
||||||
'PHPWord_Autoloader::load() failed to autoload the PhpWord class'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAutoload()
|
public function testAutoload()
|
||||||
{
|
{
|
||||||
$declared = get_declared_classes();
|
$declared = \get_declared_classes();
|
||||||
$declaredCount = count($declared);
|
$declaredCount = \count($declared);
|
||||||
Autoloader::autoload('Foo');
|
Autoloader::autoload('Foo');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$declaredCount,
|
$declaredCount,
|
||||||
count(get_declared_classes()),
|
\count(get_declared_classes()),
|
||||||
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
|
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes '
|
||||||
'outside of the PhpOffice\\PhpWord namespace'
|
. 'outside of the PhpOffice\\PhpWord namespace'
|
||||||
);
|
);
|
||||||
// TODO change this class to the main PhpWord class when it is namespaced
|
// TODO change this class to the main PhpWord class when it is namespaced
|
||||||
Autoloader::autoload(
|
Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException');
|
||||||
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
|
\in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', \get_declared_classes()),
|
||||||
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
|
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the '
|
||||||
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
|
. 'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests;
|
namespace PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\IOFactory;
|
use PhpOffice\PhpWord\IOFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ class MediaTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddSectionMediaElement()
|
public function testAddSectionMediaElement()
|
||||||
{
|
{
|
||||||
$section = new Section(0);
|
$section = new Section(0);
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars_noext_jpg");
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg");
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif");
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png");
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp");
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif");
|
||||||
|
|
||||||
$elements = $section->getElements();
|
$elements = $section->getElements();
|
||||||
$this->assertEquals(6, count($elements));
|
$this->assertEquals(6, count($elements));
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$dir = join(
|
$dir = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
|
||||||
);
|
);
|
||||||
$object = new Word2007;
|
$object = new Word2007;
|
||||||
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
|
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
|
||||||
|
|
@ -42,7 +42,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$dir = join(
|
$dir = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
|
||||||
);
|
);
|
||||||
$object = new Word2007;
|
$object = new Word2007;
|
||||||
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
|
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
|
||||||
|
|
@ -57,10 +57,10 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$dir = join(
|
$dir = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
|
||||||
);
|
);
|
||||||
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
|
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
|
||||||
$object = IOFactory::load($file);
|
$object = IOFactory::load($file);
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord', $object);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +74,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addImage($src);
|
$element = $oFooter->addImage($src);
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addImage($src);
|
$element = $oHeader->addImage($src);
|
||||||
|
|
@ -113,7 +113,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addWatermark($src);
|
$element = $oHeader->addWatermark($src);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
|
||||||
);
|
);
|
||||||
$oImage = new Image($src);
|
$oImage = new Image($src);
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
|
||||||
);
|
);
|
||||||
$oImage = new Image(
|
$oImage = new Image(
|
||||||
$src,
|
$src,
|
||||||
|
|
@ -43,12 +43,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testValidImageTypes()
|
public function testValidImageTypes()
|
||||||
{
|
{
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars_noext_jpg");
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg");
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif");
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png");
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp");
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,7 +57,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testImageNotFound()
|
public function testImageNotFound()
|
||||||
{
|
{
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/thisisnotarealimage");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,14 +66,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testInvalidImageTypes()
|
public function testInvalidImageTypes()
|
||||||
{
|
{
|
||||||
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx");
|
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/alexz-johnson.pcx");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStyle()
|
public function testStyle()
|
||||||
{
|
{
|
||||||
$oImage = new Image(\join(
|
$oImage = new Image(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
), array('width' => 210, 'height' => 210, 'align' => 'center'));
|
), array('width' => 210, 'height' => 210, 'align' => 'center'));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||||
|
|
@ -83,7 +83,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oImage = new Image(\join(
|
$oImage = new Image(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
));
|
));
|
||||||
|
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
|
|
@ -95,7 +95,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oImage = new Image(\join(
|
$oImage = new Image(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
));
|
));
|
||||||
|
|
||||||
$oImage->setIsWatermark(true);
|
$oImage->setIsWatermark(true);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
|
||||||
);
|
);
|
||||||
$oMemoryImage = new MemoryImage($src);
|
$oMemoryImage = new MemoryImage($src);
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'mario.gif')
|
||||||
);
|
);
|
||||||
$oMemoryImage = new MemoryImage($src);
|
$oMemoryImage = new MemoryImage($src);
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oMemoryImage = new MemoryImage($src);
|
$oMemoryImage = new MemoryImage($src);
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oMemoryImage = new MemoryImage(\join(
|
$oMemoryImage = new MemoryImage(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'duke_nukem.bmp')
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
|
||||||
|
|
@ -74,7 +74,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oMemoryImage = new MemoryImage(\join(
|
$oMemoryImage = new MemoryImage(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
), array('width' => 210, 'height' => 210, 'align' => 'center'));
|
), array('width' => 210, 'height' => 210, 'align' => 'center'));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
|
||||||
|
|
@ -84,7 +84,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oMemoryImage = new MemoryImage(\join(
|
$oMemoryImage = new MemoryImage(\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
));
|
));
|
||||||
|
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src);
|
$oObject = new Object($src);
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'xsl', 'passthrough.xsl')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src);
|
$oObject = new Object($src);
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src, array('width' => '230px'));
|
$oObject = new Object($src, array('width' => '230px'));
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src);
|
$oObject = new Object($src);
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src);
|
$oObject = new Object($src);
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oObject = new Object($src);
|
$oObject = new Object($src);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addImage($src);
|
$element = $oCell->addImage($src);
|
||||||
|
|
@ -104,7 +104,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oCell = new Cell('header', 1);
|
$oCell = new Cell('header', 1);
|
||||||
$element = $oCell->addImage($src);
|
$element = $oCell->addImage($src);
|
||||||
|
|
@ -117,7 +117,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oCell = new Cell('footer', 1);
|
$oCell = new Cell('footer', 1);
|
||||||
$element = $oCell->addImage($src);
|
$element = $oCell->addImage($src);
|
||||||
|
|
@ -163,7 +163,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$oCell = new Cell('section', 1);
|
$oCell = new Cell('section', 1);
|
||||||
$element = $oCell->addObject($src);
|
$element = $oCell->addObject($src);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$src = \join(
|
$src = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
$element = $oTextRun->addImage($src);
|
$element = $oTextRun->addImage($src);
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,11 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$objectSource = join(
|
$objectSource = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$imageSource = join(
|
$imageSource = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PhpWord.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'PhpWord.png')
|
||||||
);
|
);
|
||||||
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
|
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testFileExists()
|
public function testFileExists()
|
||||||
{
|
{
|
||||||
$dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates'));
|
$dir = join(DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates'));
|
||||||
chdir($dir);
|
chdir($dir);
|
||||||
$this->assertTrue(File::file_exists('blank.docx'));
|
$this->assertTrue(File::file_exists('blank.docx'));
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testNoFileExists()
|
public function testNoFileExists()
|
||||||
{
|
{
|
||||||
$dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates'));
|
$dir = join(DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates'));
|
||||||
chdir($dir);
|
chdir($dir);
|
||||||
$this->assertFalse(File::file_exists('404.docx'));
|
$this->assertFalse(File::file_exists('404.docx'));
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testRealpath()
|
public function testRealpath()
|
||||||
{
|
{
|
||||||
$dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates'));
|
$dir = join(DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates'));
|
||||||
chdir($dir);
|
chdir($dir);
|
||||||
$file = 'blank.docx';
|
$file = 'blank.docx';
|
||||||
$expected = $dir . DIRECTORY_SEPARATOR . $file;
|
$expected = $dir . DIRECTORY_SEPARATOR . $file;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Shared;
|
namespace PhpWord\Tests\Shared;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Shared\Font;
|
use PhpOffice\PhpWord\Shared\Font;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Style;
|
namespace PhpWord\Tests\Style;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Style;
|
namespace PhpWord\Tests\Style;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
use PhpOffice\PhpWord\Style\Tab;
|
use PhpOffice\PhpWord\Style\Tab;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Style;
|
namespace PhpWord\Tests\Style;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style\Tab;
|
use PhpOffice\PhpWord\Style\Tab;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests;
|
namespace PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Template;
|
use PhpOffice\PhpWord\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -17,7 +17,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$templateFqfn = \join(
|
$templateFqfn = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'with_table_macros.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'with_table_macros.docx')
|
||||||
);
|
);
|
||||||
|
|
||||||
$document = new Template($templateFqfn);
|
$document = new Template($templateFqfn);
|
||||||
|
|
@ -25,7 +25,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
$xslDOMDocument->load(
|
$xslDOMDocument->load(
|
||||||
\join(
|
\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'remove_tables_by_needle.xsl')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'xsl', 'remove_tables_by_needle.xsl')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
foreach (array('${employee.', '${scoreboard.') as $needle) {
|
foreach (array('${employee.', '${scoreboard.') as $needle) {
|
||||||
|
|
@ -65,7 +65,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$expectedDocumentFqfn = \join(
|
$expectedDocumentFqfn = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'without_table_macros.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'without_table_macros.docx')
|
||||||
);
|
);
|
||||||
|
|
||||||
$actualDocumentZip = new \ZipArchive();
|
$actualDocumentZip = new \ZipArchive();
|
||||||
|
|
@ -96,7 +96,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
$template = new Template(
|
$template = new Template(
|
||||||
\join(
|
\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'blank.docx')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
$xslDOMDocument->load(
|
$xslDOMDocument->load(
|
||||||
\join(
|
\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'xsl', 'passthrough.xsl')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
$template = new Template(
|
$template = new Template(
|
||||||
\join(
|
\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'corrupted_main_document_part.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'corrupted_main_document_part.docx')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
$xslDOMDocument->load(
|
$xslDOMDocument->load(
|
||||||
\join(
|
\join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'xsl', 'passthrough.xsl')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$template = \join(
|
$template = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'clone-row.docx')
|
||||||
);
|
);
|
||||||
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
|
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
|
||||||
$docName = 'clone-test-result.docx';
|
$docName = 'clone-test-result.docx';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer\ODText;
|
namespace PhpWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -27,11 +27,11 @@ class ContentTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$imageSrc = \join(
|
$imageSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PhpWord.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'PhpWord.png')
|
||||||
);
|
);
|
||||||
$objectSrc = \join(
|
$objectSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$expected = 'Expected';
|
$expected = 'Expected';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer;
|
namespace PhpWord\Tests\Writer;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Writer\ODText;
|
use PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,7 +18,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$object = new ODText(new PhpWord());
|
$object = new ODText(new PhpWord());
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord', $object->getPhpWord());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
|
||||||
|
|
||||||
$this->assertEquals('./', $object->getDiskCachingDirectory());
|
$this->assertEquals('./', $object->getDiskCachingDirectory());
|
||||||
|
|
@ -52,15 +52,15 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$imageSrc = \join(
|
$imageSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PhpWord.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'PhpWord.png')
|
||||||
);
|
);
|
||||||
$objectSrc = \join(
|
$objectSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$file = \join(
|
$file = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'temp.odt')
|
||||||
);
|
);
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
@ -129,9 +129,9 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testSetGetUseDiskCaching()
|
public function testSetGetUseDiskCaching()
|
||||||
{
|
{
|
||||||
$object = new ODText();
|
$object = new ODText();
|
||||||
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
|
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
|
||||||
$this->assertTrue($object->getUseDiskCaching());
|
$this->assertTrue($object->getUseDiskCaching());
|
||||||
$this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory());
|
$this->assertEquals(\PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -142,7 +142,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$dir = \join(
|
$dir = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, 'foo')
|
array(\PHPWORD_TESTS_BASE_DIR, 'foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$object = new ODText($phpWord);
|
$object = new ODText($phpWord);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer;
|
namespace PhpWord\Tests\Writer;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Writer\RTF;
|
use PhpOffice\PhpWord\Writer\RTF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,7 +18,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$object = new RTF(new PhpWord);
|
$object = new RTF(new PhpWord);
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord', $object->getPhpWord());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,15 +65,15 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$imageSrc = \join(
|
$imageSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PhpWord.png')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'PhpWord.png')
|
||||||
);
|
);
|
||||||
$objectSrc = \join(
|
$objectSrc = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
$file = \join(
|
$file = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'temp.rtf')
|
||||||
);
|
);
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer\Word2007;
|
namespace PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,7 +49,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
$aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120);
|
$aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120);
|
||||||
$imageSrc = join(
|
$imageSrc = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
@ -298,7 +298,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
|
\PHPWORD_TESTS_BASE_DIR . '/_files/images/earth.jpg',
|
||||||
array(
|
array(
|
||||||
'marginTop' => -1,
|
'marginTop' => -1,
|
||||||
'marginLeft' => -1,
|
'marginLeft' => -1,
|
||||||
|
|
@ -322,7 +322,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$imageSrc = join(
|
$imageSrc = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
|
||||||
);
|
);
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer\Word2007;
|
namespace PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,7 +41,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$objectSrc = join(
|
$objectSrc = join(
|
||||||
DIRECTORY_SEPARATOR,
|
DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
|
||||||
);
|
);
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer\Word2007;
|
namespace PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer\Word2007;
|
namespace PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests\Writer;
|
namespace PhpWord\Tests\Writer;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007;
|
use PhpOffice\PhpWord\Writer\Word2007;
|
||||||
use PhpWord\Tests\TestHelperDOCX;
|
use PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
$writer = new Word2007($phpWord);
|
$writer = new Word2007($phpWord);
|
||||||
$file = \join(
|
$file = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'temp.docx')
|
||||||
);
|
);
|
||||||
$writer->save($file);
|
$writer->save($file);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
|
|
@ -90,7 +90,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
foreach ($images as $source => $target) {
|
foreach ($images as $source => $target) {
|
||||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}");
|
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/{$source}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
@ -98,7 +98,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
foreach ($images as $source => $target) {
|
foreach ($images as $source => $target) {
|
||||||
$this->assertFileEquals(
|
$this->assertFileEquals(
|
||||||
PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}",
|
\PHPWORD_TESTS_BASE_DIR . "/_files/images/{$source}",
|
||||||
$mediaPath . "/section_image{$target}"
|
$mediaPath . "/section_image{$target}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
public function testSetGetUseDiskCaching()
|
public function testSetGetUseDiskCaching()
|
||||||
{
|
{
|
||||||
$object = new Word2007();
|
$object = new Word2007();
|
||||||
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
|
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
|
||||||
|
|
||||||
$this->assertTrue($object->getUseDiskCaching());
|
$this->assertTrue($object->getUseDiskCaching());
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +124,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$dir = \join(
|
$dir = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(\PHPWORD_TESTS_DIR_ROOT, 'foo')
|
array(\PHPWORD_TESTS_BASE_DIR, 'foo')
|
||||||
);
|
);
|
||||||
|
|
||||||
$object = new Word2007();
|
$object = new Word2007();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests;
|
namespace PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\DocumentProperties;
|
use PhpOffice\PhpWord\DocumentProperties;
|
||||||
use PhpOffice\PhpWord\Section;
|
use PhpOffice\PhpWord\Section;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
@ -133,7 +133,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$templateFqfn = \join(
|
$templateFqfn = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'blank.docx')
|
||||||
);
|
);
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
|
|
@ -150,7 +150,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$templateFqfn = \join(
|
$templateFqfn = \join(
|
||||||
\DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blanks.docx')
|
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'blanks.docx')
|
||||||
);
|
);
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$phpWord->loadTemplate($templateFqfn);
|
$phpWord->loadTemplate($templateFqfn);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PhpWord\Tests;
|
namespace PhpWord\Tests;
|
||||||
|
|
||||||
use PhpOffice\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\IOFactory;
|
use PhpOffice\PhpWord\IOFactory;
|
||||||
|
|
||||||
class TestHelperDOCX
|
class TestHelperDOCX
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
\date_default_timezone_set('UTC');
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
// defining base dir for tests
|
||||||
|
if (!\defined('PHPWORD_TESTS_BASE_DIR')) {
|
||||||
// Constantes
|
\define('PHPWORD_TESTS_BASE_DIR', __DIR__);
|
||||||
if (!defined('PHPWORD_TESTS_DIR_ROOT')) {
|
|
||||||
define('PHPWORD_TESTS_DIR_ROOT', __DIR__);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Includes
|
// loading classes with PSR-4 autoloader
|
||||||
require_once __DIR__ . '/../Classes/PhpWord/Autoloader.php';
|
require_once __DIR__ . '/../src/Autoloader.php';
|
||||||
PHPWord_Autoloader::Register();
|
PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
require_once __DIR__ . '/_inc/TestHelperDOCX.php';
|
require_once __DIR__ . '/_inc/TestHelperDOCX.php';
|
||||||
require_once __DIR__ . '/_inc/XmlDocument.php';
|
require_once __DIR__ . '/_inc/XmlDocument.php';
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2011 - 2014 PhpWord (https://github.com/PHPOffice/PhpWord/)
|
* @copyright Copyright (c) 2011 - 2014 PhpWord (https://github.com/PhpOffice/PhpWord/)
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
**************************************************************************************
|
**************************************************************************************
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@
|
||||||
"ext-xsl": "*"
|
"ext-xsl": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-4": {
|
||||||
"PhpWord": "Classes/"
|
"PhpOffice\\PhpWord\\": "src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,13 +9,13 @@
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
syntaxCheck="false">
|
syntaxCheck="false">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="PhpWord Unit Test Suite">
|
<testsuite name="PhpWord Test Suite">
|
||||||
<directory>./Tests/PhpWord/</directory>
|
<directory>./Tests/PhpWord/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory suffix=".php">./Classes</directory>
|
<directory suffix=".php">./src</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// Read contents
|
// Read contents
|
||||||
$name = basename(__FILE__, '.php');
|
$name = basename(__FILE__, '.php');
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// Init
|
// Init
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
|
||||||
require_once '../Classes/PhpWord.php';
|
require_once '../src/PhpWord.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Autoloader;
|
||||||
|
|
||||||
|
if (!\defined('PHPWORD_BASE_DIR')) {
|
||||||
|
\define('PHPWORD_BASE_DIR', \realpath(__DIR__) . \DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Autoloader
|
||||||
|
{
|
||||||
|
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function register()
|
||||||
|
{
|
||||||
|
\spl_autoload_register(array(new self, 'autoload'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fqClassName
|
||||||
|
*/
|
||||||
|
public static function autoload($fqClassName)
|
||||||
|
{
|
||||||
|
$namespacePrefixLength = \strlen(self::NAMESPACE_PREFIX);
|
||||||
|
$className = \substr($fqClassName, $namespacePrefixLength);
|
||||||
|
|
||||||
|
if (0 === \strncmp(self::NAMESPACE_PREFIX, $fqClassName, $namespacePrefixLength)) {
|
||||||
|
$fqFilename = \PHPWORD_BASE_DIR
|
||||||
|
. \str_replace('\\', \DIRECTORY_SEPARATOR, $className)
|
||||||
|
. '.php';
|
||||||
|
|
||||||
|
if (\file_exists($fqFilename)) {
|
||||||
|
require_once $fqFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,606 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
class DocumentProperties
|
||||||
|
{
|
||||||
|
/** Constants */
|
||||||
|
const PROPERTY_TYPE_BOOLEAN = 'b';
|
||||||
|
const PROPERTY_TYPE_INTEGER = 'i';
|
||||||
|
const PROPERTY_TYPE_FLOAT = 'f';
|
||||||
|
const PROPERTY_TYPE_DATE = 'd';
|
||||||
|
const PROPERTY_TYPE_STRING = 's';
|
||||||
|
const PROPERTY_TYPE_UNKNOWN = 'u';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creator
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_creator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LastModifiedBy
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_lastModifiedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created
|
||||||
|
*
|
||||||
|
* @var datetime
|
||||||
|
*/
|
||||||
|
private $_created;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modified
|
||||||
|
*
|
||||||
|
* @var datetime
|
||||||
|
*/
|
||||||
|
private $_modified;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subject
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keywords
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_keywords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Category
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Company
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_company;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Properties
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_customProperties = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new DocumentProperties
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_creator = '';
|
||||||
|
$this->_lastModifiedBy = $this->_creator;
|
||||||
|
$this->_created = time();
|
||||||
|
$this->_modified = time();
|
||||||
|
$this->_title = '';
|
||||||
|
$this->_subject = '';
|
||||||
|
$this->_description = '';
|
||||||
|
$this->_keywords = '';
|
||||||
|
$this->_category = '';
|
||||||
|
$this->_company = '';
|
||||||
|
$this->_manager = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Creator
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCreator()
|
||||||
|
{
|
||||||
|
return $this->_creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Creator
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setCreator($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_creator = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Last Modified By
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLastModifiedBy()
|
||||||
|
{
|
||||||
|
return $this->_lastModifiedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Last Modified By
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setLastModifiedBy($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_lastModifiedBy = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Created
|
||||||
|
*
|
||||||
|
* @return datetime
|
||||||
|
*/
|
||||||
|
public function getCreated()
|
||||||
|
{
|
||||||
|
return $this->_created;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Created
|
||||||
|
*
|
||||||
|
* @param datetime $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setCreated($pValue = null)
|
||||||
|
{
|
||||||
|
if (is_null($pValue)) {
|
||||||
|
$pValue = time();
|
||||||
|
}
|
||||||
|
$this->_created = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Modified
|
||||||
|
*
|
||||||
|
* @return datetime
|
||||||
|
*/
|
||||||
|
public function getModified()
|
||||||
|
{
|
||||||
|
return $this->_modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Modified
|
||||||
|
*
|
||||||
|
* @param datetime $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setModified($pValue = null)
|
||||||
|
{
|
||||||
|
if (is_null($pValue)) {
|
||||||
|
$pValue = time();
|
||||||
|
}
|
||||||
|
$this->_modified = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Title
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Title
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setTitle($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_title = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Description
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDescription()
|
||||||
|
{
|
||||||
|
return $this->_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Description
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setDescription($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_description = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Subject
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSubject()
|
||||||
|
{
|
||||||
|
return $this->_subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Subject
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setSubject($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_subject = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Keywords
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getKeywords()
|
||||||
|
{
|
||||||
|
return $this->_keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Keywords
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setKeywords($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_keywords = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Category
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCategory()
|
||||||
|
{
|
||||||
|
return $this->_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Category
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setCategory($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_category = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Company
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCompany()
|
||||||
|
{
|
||||||
|
return $this->_company;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Company
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setCompany($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_company = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Manager
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getManager()
|
||||||
|
{
|
||||||
|
return $this->_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Manager
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setManager($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_manager = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a List of Custom Property Names
|
||||||
|
*
|
||||||
|
* @return array of string
|
||||||
|
*/
|
||||||
|
public function getCustomProperties()
|
||||||
|
{
|
||||||
|
return array_keys($this->_customProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a Custom Property is defined
|
||||||
|
*
|
||||||
|
* @param string $propertyName
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isCustomPropertySet($propertyName)
|
||||||
|
{
|
||||||
|
return isset($this->_customProperties[$propertyName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Custom Property Value
|
||||||
|
*
|
||||||
|
* @param string $propertyName
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCustomPropertyValue($propertyName)
|
||||||
|
{
|
||||||
|
if (isset($this->_customProperties[$propertyName])) {
|
||||||
|
return $this->_customProperties[$propertyName]['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Custom Property Type
|
||||||
|
*
|
||||||
|
* @param string $propertyName
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCustomPropertyType($propertyName)
|
||||||
|
{
|
||||||
|
if (isset($this->_customProperties[$propertyName])) {
|
||||||
|
return $this->_customProperties[$propertyName]['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a Custom Property
|
||||||
|
*
|
||||||
|
* @param string $propertyName
|
||||||
|
* @param mixed $propertyValue
|
||||||
|
* @param string $propertyType
|
||||||
|
* 'i': Integer
|
||||||
|
* 'f': Floating Point
|
||||||
|
* 's': String
|
||||||
|
* 'd': Date/Time
|
||||||
|
* 'b': Boolean
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
|
||||||
|
{
|
||||||
|
if (($propertyType === null) || (!in_array($propertyType, array(
|
||||||
|
self::PROPERTY_TYPE_INTEGER,
|
||||||
|
self::PROPERTY_TYPE_FLOAT,
|
||||||
|
self::PROPERTY_TYPE_STRING,
|
||||||
|
self::PROPERTY_TYPE_DATE,
|
||||||
|
self::PROPERTY_TYPE_BOOLEAN
|
||||||
|
)))) {
|
||||||
|
if ($propertyValue === null) {
|
||||||
|
$propertyType = self::PROPERTY_TYPE_STRING;
|
||||||
|
} elseif (is_float($propertyValue)) {
|
||||||
|
$propertyType = self::PROPERTY_TYPE_FLOAT;
|
||||||
|
} elseif (is_int($propertyValue)) {
|
||||||
|
$propertyType = self::PROPERTY_TYPE_INTEGER;
|
||||||
|
} elseif (is_bool($propertyValue)) {
|
||||||
|
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
|
||||||
|
} else {
|
||||||
|
$propertyType = self::PROPERTY_TYPE_STRING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_customProperties[$propertyName] = array(
|
||||||
|
'value' => $propertyValue,
|
||||||
|
'type' => $propertyType
|
||||||
|
);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert document propery based on type
|
||||||
|
*
|
||||||
|
* @param mixed $propertyValue
|
||||||
|
* @param string $propertyType
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function convertProperty($propertyValue, $propertyType)
|
||||||
|
{
|
||||||
|
switch ($propertyType) {
|
||||||
|
case 'empty': // Empty
|
||||||
|
return '';
|
||||||
|
break;
|
||||||
|
case 'null': // Null
|
||||||
|
return null;
|
||||||
|
break;
|
||||||
|
case 'i1': // 1-Byte Signed Integer
|
||||||
|
case 'i2': // 2-Byte Signed Integer
|
||||||
|
case 'i4': // 4-Byte Signed Integer
|
||||||
|
case 'i8': // 8-Byte Signed Integer
|
||||||
|
case 'int': // Integer
|
||||||
|
return (int) $propertyValue;
|
||||||
|
break;
|
||||||
|
case 'ui1': // 1-Byte Unsigned Integer
|
||||||
|
case 'ui2': // 2-Byte Unsigned Integer
|
||||||
|
case 'ui4': // 4-Byte Unsigned Integer
|
||||||
|
case 'ui8': // 8-Byte Unsigned Integer
|
||||||
|
case 'uint': // Unsigned Integer
|
||||||
|
return abs((int) $propertyValue);
|
||||||
|
break;
|
||||||
|
case 'r4': // 4-Byte Real Number
|
||||||
|
case 'r8': // 8-Byte Real Number
|
||||||
|
case 'decimal': // Decimal
|
||||||
|
return (float) $propertyValue;
|
||||||
|
break;
|
||||||
|
case 'lpstr': // LPSTR
|
||||||
|
case 'lpwstr': // LPWSTR
|
||||||
|
case 'bstr': // Basic String
|
||||||
|
return $propertyValue;
|
||||||
|
break;
|
||||||
|
case 'date': // Date and Time
|
||||||
|
case 'filetime': // File Time
|
||||||
|
return strtotime($propertyValue);
|
||||||
|
break;
|
||||||
|
case 'bool': // Boolean
|
||||||
|
return ($propertyValue == 'true') ? true : false;
|
||||||
|
break;
|
||||||
|
case 'cy': // Currency
|
||||||
|
case 'error': // Error Status Code
|
||||||
|
case 'vector': // Vector
|
||||||
|
case 'array': // Array
|
||||||
|
case 'blob': // Binary Blob
|
||||||
|
case 'oblob': // Binary Blob Object
|
||||||
|
case 'stream': // Binary Stream
|
||||||
|
case 'ostream': // Binary Stream Object
|
||||||
|
case 'storage': // Binary Storage
|
||||||
|
case 'ostorage': // Binary Storage Object
|
||||||
|
case 'vstream': // Binary Versioned Stream
|
||||||
|
case 'clsid': // Class ID
|
||||||
|
case 'cf': // Clipboard Data
|
||||||
|
return $propertyValue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $propertyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert document property type
|
||||||
|
*
|
||||||
|
* @param string $propertyType
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function convertPropertyType($propertyType)
|
||||||
|
{
|
||||||
|
switch ($propertyType) {
|
||||||
|
case 'i1': // 1-Byte Signed Integer
|
||||||
|
case 'i2': // 2-Byte Signed Integer
|
||||||
|
case 'i4': // 4-Byte Signed Integer
|
||||||
|
case 'i8': // 8-Byte Signed Integer
|
||||||
|
case 'int': // Integer
|
||||||
|
case 'ui1': // 1-Byte Unsigned Integer
|
||||||
|
case 'ui2': // 2-Byte Unsigned Integer
|
||||||
|
case 'ui4': // 4-Byte Unsigned Integer
|
||||||
|
case 'ui8': // 8-Byte Unsigned Integer
|
||||||
|
case 'uint': // Unsigned Integer
|
||||||
|
return self::PROPERTY_TYPE_INTEGER;
|
||||||
|
break;
|
||||||
|
case 'r4': // 4-Byte Real Number
|
||||||
|
case 'r8': // 8-Byte Real Number
|
||||||
|
case 'decimal': // Decimal
|
||||||
|
return self::PROPERTY_TYPE_FLOAT;
|
||||||
|
break;
|
||||||
|
case 'empty': // Empty
|
||||||
|
case 'null': // Null
|
||||||
|
case 'lpstr': // LPSTR
|
||||||
|
case 'lpwstr': // LPWSTR
|
||||||
|
case 'bstr': // Basic String
|
||||||
|
return self::PROPERTY_TYPE_STRING;
|
||||||
|
break;
|
||||||
|
case 'date': // Date and Time
|
||||||
|
case 'filetime': // File Time
|
||||||
|
return self::PROPERTY_TYPE_DATE;
|
||||||
|
break;
|
||||||
|
case 'bool': // Boolean
|
||||||
|
return self::PROPERTY_TYPE_BOOLEAN;
|
||||||
|
break;
|
||||||
|
case 'cy': // Currency
|
||||||
|
case 'error': // Error Status Code
|
||||||
|
case 'vector': // Vector
|
||||||
|
case 'array': // Array
|
||||||
|
case 'blob': // Binary Blob
|
||||||
|
case 'oblob': // Binary Blob Object
|
||||||
|
case 'stream': // Binary Stream
|
||||||
|
case 'ostream': // Binary Stream Object
|
||||||
|
case 'storage': // Binary Storage
|
||||||
|
case 'ostorage': // Binary Storage Object
|
||||||
|
case 'vstream': // Binary Versioned Stream
|
||||||
|
case 'clsid': // Class ID
|
||||||
|
case 'cf': // Clipboard Data
|
||||||
|
return self::PROPERTY_TYPE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return self::PROPERTY_TYPE_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
namespace PhpOffice\PhpWord\Exceptions;
|
||||||
|
|
||||||
|
class Exception extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
namespace PhpOffice\PhpWord\Exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InvalidImageException
|
||||||
|
*
|
||||||
|
* Exception used for when an image is not found
|
||||||
|
*
|
||||||
|
* @package PhpWord
|
||||||
|
*/
|
||||||
|
class InvalidImageException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
namespace PhpOffice\PhpWord\Exceptions;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InvalidStyleException
|
||||||
|
*
|
||||||
|
* Exception used for when a style value is invalid
|
||||||
|
*
|
||||||
|
* @package PhpWord
|
||||||
|
*/
|
||||||
|
class InvalidStyleException extends InvalidArgumentException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
namespace PhpOffice\PhpWord\Exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UnsupportedImageTypeException
|
||||||
|
*
|
||||||
|
* Exception used for when an image type is unsupported
|
||||||
|
*
|
||||||
|
* @package PhpWord
|
||||||
|
*/
|
||||||
|
class UnsupportedImageTypeException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
class Footnote
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Footnote Elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_footnoteCollection = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Footnote Link Elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_footnoteLink = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Footnote Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @param string $linkName
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function addFootnoteElement(PhpOffice\PhpWord\Section\Footnote $footnote)
|
||||||
|
{
|
||||||
|
$refID = self::countFootnoteElements() + 2;
|
||||||
|
|
||||||
|
self::$_footnoteCollection[] = $footnote;
|
||||||
|
|
||||||
|
return $refID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote Elements
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getFootnoteElements()
|
||||||
|
{
|
||||||
|
return self::$_footnoteCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote Elements Count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countFootnoteElements()
|
||||||
|
{
|
||||||
|
return count(self::$_footnoteCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Footnote Link Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function addFootnoteLinkElement($linkSrc)
|
||||||
|
{
|
||||||
|
$rID = self::countFootnoteLinkElements() + 1;
|
||||||
|
|
||||||
|
$link = array();
|
||||||
|
$link['target'] = $linkSrc;
|
||||||
|
$link['rID'] = $rID;
|
||||||
|
$link['type'] = 'hyperlink';
|
||||||
|
|
||||||
|
self::$_footnoteLink[] = $link;
|
||||||
|
|
||||||
|
return $rID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote Link Elements
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getFootnoteLinkElements()
|
||||||
|
{
|
||||||
|
return self::$_footnoteLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote Link Elements Count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countFootnoteLinkElements()
|
||||||
|
{
|
||||||
|
return count(self::$_footnoteLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,209 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore Legacy from PHPExcel
|
||||||
|
*/
|
||||||
|
class HashTable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* HashTable elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $_items = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HashTable key map
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $_keyMap = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __construct($pSource = null)
|
||||||
|
{
|
||||||
|
if (!is_null($pSource)) {
|
||||||
|
$this->addFromSource($pSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add HashTable items from source
|
||||||
|
*
|
||||||
|
* @param PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addFromSource($pSource = null)
|
||||||
|
{
|
||||||
|
// Check if an array was passed
|
||||||
|
if ($pSource == null) {
|
||||||
|
return;
|
||||||
|
} elseif (!is_array($pSource)) {
|
||||||
|
throw new Exception('Invalid array parameter passed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pSource as $item) {
|
||||||
|
$this->add($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add HashTable item
|
||||||
|
*
|
||||||
|
* @param PhpOffice\PhpWord\IComparable $pSource Item to add
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function add(IComparable $pSource = null)
|
||||||
|
{
|
||||||
|
// Determine hashcode
|
||||||
|
$hashCode = null;
|
||||||
|
$hashIndex = $pSource->getHashIndex();
|
||||||
|
if (is_null($hashIndex)) {
|
||||||
|
$hashCode = $pSource->getHashCode();
|
||||||
|
} elseif (isset ($this->_keyMap[$hashIndex])) {
|
||||||
|
$hashCode = $this->_keyMap[$hashIndex];
|
||||||
|
} else {
|
||||||
|
$hashCode = $pSource->getHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add value
|
||||||
|
if (!isset($this->_items[$hashCode])) {
|
||||||
|
$this->_items[$hashCode] = $pSource;
|
||||||
|
$index = count($this->_items) - 1;
|
||||||
|
$this->_keyMap[$index] = $hashCode;
|
||||||
|
$pSource->setHashIndex($index);
|
||||||
|
} else {
|
||||||
|
$pSource->setHashIndex($this->_items[$hashCode]->getHashIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove HashTable item
|
||||||
|
*
|
||||||
|
* @param PhpOffice\PhpWord\IComparable $pSource Item to remove
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function remove(IComparable $pSource = null)
|
||||||
|
{
|
||||||
|
if (isset($this->_items[$pSource->getHashCode()])) {
|
||||||
|
unset($this->_items[$pSource->getHashCode()]);
|
||||||
|
|
||||||
|
$deleteKey = -1;
|
||||||
|
foreach ($this->_keyMap as $key => $value) {
|
||||||
|
if ($deleteKey >= 0) {
|
||||||
|
$this->_keyMap[$key - 1] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value == $pSource->getHashCode()) {
|
||||||
|
$deleteKey = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($this->_keyMap[count($this->_keyMap) - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear HashTable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function clear()
|
||||||
|
{
|
||||||
|
$this->_items = array();
|
||||||
|
$this->_keyMap = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function count()
|
||||||
|
{
|
||||||
|
return count($this->_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $pHashCode
|
||||||
|
* @return int Index
|
||||||
|
*/
|
||||||
|
public function getIndexForHashCode($pHashCode = '')
|
||||||
|
{
|
||||||
|
return array_search($pHashCode, $this->_keyMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $pIndex
|
||||||
|
* @return PhpOffice\PhpWord\IComparable
|
||||||
|
*/
|
||||||
|
public function getByIndex($pIndex = 0)
|
||||||
|
{
|
||||||
|
if (isset($this->_keyMap[$pIndex])) {
|
||||||
|
return $this->getByHashCode($this->_keyMap[$pIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $pHashCode
|
||||||
|
* @return PhpOffice\PhpWord\IComparable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getByHashCode($pHashCode = '')
|
||||||
|
{
|
||||||
|
if (isset($this->_items[$pHashCode])) {
|
||||||
|
return $this->_items[$pHashCode];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PhpOffice\PhpWord\IComparable[]
|
||||||
|
*/
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return $this->_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implement PHP __clone to create a deep clone, not just a shallow copy.
|
||||||
|
*/
|
||||||
|
public function __clone()
|
||||||
|
{
|
||||||
|
$vars = get_object_vars($this);
|
||||||
|
foreach ($vars as $key => $value) {
|
||||||
|
if (is_object($value)) {
|
||||||
|
$this->$key = clone $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||||
|
|
||||||
|
abstract class IOFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param PhpOffice\PhpWord $phpWord
|
||||||
|
* @param string $name
|
||||||
|
* @return PhpOffice\PhpWord\Writer\IWriter
|
||||||
|
* @throws PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public static function createWriter(PhpWord $phpWord, $name)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
||||||
|
|
||||||
|
return new $fqName($phpWord);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
throw new Exception("Could not instantiate \"{$name}\" class.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @return PhpOffice\PhpWord\Reader\IReader
|
||||||
|
* @throws PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public static function createReader($name)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
|
||||||
|
|
||||||
|
return new $fqName();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
throw new Exception("Could not instantiate \"{$name}\" class.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads PhpWord from file
|
||||||
|
*
|
||||||
|
* @param string $filename The name of the file
|
||||||
|
* @param string $readerName
|
||||||
|
* @return PhpOffice\PhpWord
|
||||||
|
*/
|
||||||
|
public static function load($filename, $readerName = 'Word2007')
|
||||||
|
{
|
||||||
|
$reader = self::createReader($readerName);
|
||||||
|
return $reader->load($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,347 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Section\MemoryImage;
|
||||||
|
|
||||||
|
class Media
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Section Media Elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_sectionMedia = array(
|
||||||
|
'images' => array(),
|
||||||
|
'embeddings' => array(),
|
||||||
|
'links' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header Media Elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_headerMedia = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Footer Media Elements
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_footerMedia = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ObjectID Counter
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private static $_objectId = 1325353440;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Section Media Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param string $type
|
||||||
|
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function addSectionMediaElement($src, $type, MemoryImage $memoryImage = null)
|
||||||
|
{
|
||||||
|
$mediaId = md5($src);
|
||||||
|
$key = ($type === 'image') ? 'images' : 'embeddings';
|
||||||
|
|
||||||
|
if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
|
||||||
|
$cImg = self::countSectionMediaElements('images');
|
||||||
|
$cObj = self::countSectionMediaElements('embeddings');
|
||||||
|
$rID = self::countSectionMediaElements() + 7;
|
||||||
|
|
||||||
|
$media = array();
|
||||||
|
|
||||||
|
$folder = null;
|
||||||
|
$file = null;
|
||||||
|
if ($type === 'image') {
|
||||||
|
$cImg++;
|
||||||
|
//Detect if it's a memory image first by php ext and second by regex
|
||||||
|
$isMemImage = false;
|
||||||
|
if (stripos(strrev($src), strrev('.php')) === 0) {
|
||||||
|
$isMemImage = true;
|
||||||
|
}
|
||||||
|
if (!$isMemImage) {
|
||||||
|
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false);
|
||||||
|
}
|
||||||
|
$extension = '';
|
||||||
|
if ($isMemImage) {
|
||||||
|
$extension = $memoryImage->getImageExtension();
|
||||||
|
$media['isMemImage'] = true;
|
||||||
|
$media['createfunction'] = $memoryImage->getImageCreateFunction();
|
||||||
|
$media['imagefunction'] = $memoryImage->getImageFunction();
|
||||||
|
} else {
|
||||||
|
$imageType = exif_imagetype($src);
|
||||||
|
if ($imageType === IMAGETYPE_JPEG) {
|
||||||
|
$extension = 'jpg';
|
||||||
|
} elseif ($imageType === IMAGETYPE_GIF) {
|
||||||
|
$extension = 'gif';
|
||||||
|
} elseif ($imageType === IMAGETYPE_PNG) {
|
||||||
|
$extension = 'png';
|
||||||
|
} elseif ($imageType === IMAGETYPE_BMP) {
|
||||||
|
$extension = 'bmp';
|
||||||
|
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
|
||||||
|
$extension = 'tif';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = 'media';
|
||||||
|
$file = $type . $cImg . '.' . strtolower($extension);
|
||||||
|
} elseif ($type === 'oleObject') {
|
||||||
|
$cObj++;
|
||||||
|
$folder = 'embedding';
|
||||||
|
$file = $type . $cObj . '.bin';
|
||||||
|
}
|
||||||
|
|
||||||
|
$media['source'] = $src;
|
||||||
|
$media['target'] = "$folder/section_$file";
|
||||||
|
$media['type'] = $type;
|
||||||
|
$media['rID'] = $rID;
|
||||||
|
|
||||||
|
self::$_sectionMedia[$key][$mediaId] = $media;
|
||||||
|
|
||||||
|
if ($type === 'oleObject') {
|
||||||
|
return array($rID, ++self::$_objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type === 'oleObject') {
|
||||||
|
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
|
||||||
|
return array($rID, ++self::$_objectId);
|
||||||
|
}
|
||||||
|
return self::$_sectionMedia[$key][$mediaId]['rID'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Section Link Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function addSectionLinkElement($linkSrc)
|
||||||
|
{
|
||||||
|
$rID = self::countSectionMediaElements() + 7;
|
||||||
|
|
||||||
|
$link = array();
|
||||||
|
$link['target'] = $linkSrc;
|
||||||
|
$link['rID'] = $rID;
|
||||||
|
$link['type'] = 'hyperlink';
|
||||||
|
|
||||||
|
self::$_sectionMedia['links'][] = $link;
|
||||||
|
|
||||||
|
return $rID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Section Media Elements
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getSectionMediaElements($key = null)
|
||||||
|
{
|
||||||
|
if (!is_null($key)) {
|
||||||
|
return self::$_sectionMedia[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrImages = self::$_sectionMedia['images'];
|
||||||
|
$arrObjects = self::$_sectionMedia['embeddings'];
|
||||||
|
$arrLinks = self::$_sectionMedia['links'];
|
||||||
|
return array_merge($arrImages, $arrObjects, $arrLinks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Section Media Elements Count
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countSectionMediaElements($key = null)
|
||||||
|
{
|
||||||
|
if (!is_null($key)) {
|
||||||
|
return count(self::$_sectionMedia[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cImages = count(self::$_sectionMedia['images']);
|
||||||
|
$cObjects = count(self::$_sectionMedia['embeddings']);
|
||||||
|
$cLinks = count(self::$_sectionMedia['links']);
|
||||||
|
return ($cImages + $cObjects + $cLinks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Header Media Element
|
||||||
|
*
|
||||||
|
* @param int $headerCount
|
||||||
|
* @param string $src
|
||||||
|
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function addHeaderMediaElement($headerCount, $src, MemoryImage $memoryImage = null)
|
||||||
|
{
|
||||||
|
$mediaId = md5($src);
|
||||||
|
$key = 'header' . $headerCount;
|
||||||
|
|
||||||
|
if (!array_key_exists($key, self::$_headerMedia)) {
|
||||||
|
self::$_headerMedia[$key] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
|
||||||
|
$cImg = self::countHeaderMediaElements($key);
|
||||||
|
$rID = $cImg + 1;
|
||||||
|
|
||||||
|
$cImg++;
|
||||||
|
$inf = pathinfo($src);
|
||||||
|
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
|
||||||
|
|
||||||
|
$media = array();
|
||||||
|
if ($isMemImage) {
|
||||||
|
$ext = $memoryImage->getImageExtension();
|
||||||
|
$media['isMemImage'] = true;
|
||||||
|
$media['createfunction'] = $memoryImage->getImageCreateFunction();
|
||||||
|
$media['imagefunction'] = $memoryImage->getImageFunction();
|
||||||
|
} else {
|
||||||
|
$ext = $inf['extension'];
|
||||||
|
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
|
||||||
|
$ext = 'jpg';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$file = 'image' . $cImg . '.' . strtolower($ext);
|
||||||
|
|
||||||
|
$media['source'] = $src;
|
||||||
|
$media['target'] = 'media/' . $key . '_' . $file;
|
||||||
|
$media['type'] = 'image';
|
||||||
|
$media['rID'] = $rID;
|
||||||
|
|
||||||
|
self::$_headerMedia[$key][$mediaId] = $media;
|
||||||
|
|
||||||
|
return $rID;
|
||||||
|
}
|
||||||
|
return self::$_headerMedia[$key][$mediaId]['rID'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Media Elements Count
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countHeaderMediaElements($key)
|
||||||
|
{
|
||||||
|
return count(self::$_headerMedia[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Media Elements
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function getHeaderMediaElements()
|
||||||
|
{
|
||||||
|
return self::$_headerMedia;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new Footer Media Element
|
||||||
|
*
|
||||||
|
* @param int $footerCount
|
||||||
|
* @param string $src
|
||||||
|
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function addFooterMediaElement($footerCount, $src, MemoryImage $memoryImage = null)
|
||||||
|
{
|
||||||
|
$mediaId = md5($src);
|
||||||
|
$key = 'footer' . $footerCount;
|
||||||
|
|
||||||
|
if (!array_key_exists($key, self::$_footerMedia)) {
|
||||||
|
self::$_footerMedia[$key] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
|
||||||
|
$cImg = self::countFooterMediaElements($key);
|
||||||
|
$rID = $cImg + 1;
|
||||||
|
|
||||||
|
$cImg++;
|
||||||
|
$inf = pathinfo($src);
|
||||||
|
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
|
||||||
|
|
||||||
|
$media = array();
|
||||||
|
if ($isMemImage) {
|
||||||
|
$ext = $memoryImage->getImageExtension();
|
||||||
|
$media['isMemImage'] = true;
|
||||||
|
$media['createfunction'] = $memoryImage->getImageCreateFunction();
|
||||||
|
$media['imagefunction'] = $memoryImage->getImageFunction();
|
||||||
|
} else {
|
||||||
|
$ext = $inf['extension'];
|
||||||
|
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
|
||||||
|
$ext = 'jpg';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$file = 'image' . $cImg . '.' . strtolower($ext);
|
||||||
|
|
||||||
|
$media['source'] = $src;
|
||||||
|
$media['target'] = 'media/' . $key . '_' . $file;
|
||||||
|
$media['type'] = 'image';
|
||||||
|
$media['rID'] = $rID;
|
||||||
|
|
||||||
|
self::$_footerMedia[$key][$mediaId] = $media;
|
||||||
|
|
||||||
|
return $rID;
|
||||||
|
}
|
||||||
|
return self::$_footerMedia[$key][$mediaId]['rID'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Media Elements Count
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countFooterMediaElements($key)
|
||||||
|
{
|
||||||
|
return count(self::$_footerMedia[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Media Elements
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function getFooterMediaElements()
|
||||||
|
{
|
||||||
|
return self::$_footerMedia;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,233 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\DocumentProperties;
|
||||||
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||||
|
use PhpOffice\PhpWord\Section;
|
||||||
|
use PhpOffice\PhpWord\Style;
|
||||||
|
use PhpOffice\PhpWord\Template;
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
if (!defined('PHPWORD_BASE_DIR')) {
|
||||||
|
define('PHPWORD_BASE_DIR', \realpath(__DIR__) . \DIRECTORY_SEPARATOR);
|
||||||
|
require \PHPWORD_BASE_DIR . 'Autoloader.php';
|
||||||
|
PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
class PhpWord
|
||||||
|
{
|
||||||
|
const DEFAULT_FONT_COLOR = '000000'; // HEX
|
||||||
|
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
|
||||||
|
const DEFAULT_FONT_NAME = 'Arial';
|
||||||
|
/**
|
||||||
|
* Default font size, in points.
|
||||||
|
*
|
||||||
|
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
|
||||||
|
* use, and the conversion will be conducted during XML writing.
|
||||||
|
*/
|
||||||
|
const DEFAULT_FONT_SIZE = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
private $_documentProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_defaultFontName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_defaultFontSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PhpOffice\PhpWord\Section[]
|
||||||
|
*/
|
||||||
|
private $_sections = array();
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_documentProperties = new DocumentProperties();
|
||||||
|
$this->_defaultFontName = self::DEFAULT_FONT_NAME;
|
||||||
|
$this->_defaultFontSize = self::DEFAULT_FONT_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PhpOffice\PhpWord\DocumentProperties
|
||||||
|
*/
|
||||||
|
public function getDocumentProperties()
|
||||||
|
{
|
||||||
|
return $this->_documentProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PhpOffice\PhpWord\DocumentProperties $documentProperties
|
||||||
|
* @return PhpOffice\PhpWord
|
||||||
|
*/
|
||||||
|
public function setDocumentProperties(DocumentProperties $documentProperties)
|
||||||
|
{
|
||||||
|
$this->_documentProperties = $documentProperties;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PhpOffice\PhpWord\Section\Settings $settings
|
||||||
|
* @return PhpOffice\PhpWord\Section
|
||||||
|
*/
|
||||||
|
public function createSection($settings = null)
|
||||||
|
{
|
||||||
|
$section = new Section(\count($this->_sections) + 1, $settings);
|
||||||
|
$this->_sections[] = $section;
|
||||||
|
|
||||||
|
return $section;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDefaultFontName()
|
||||||
|
{
|
||||||
|
return $this->_defaultFontName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fontName
|
||||||
|
*/
|
||||||
|
public function setDefaultFontName($fontName)
|
||||||
|
{
|
||||||
|
$this->_defaultFontName = $fontName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDefaultFontSize()
|
||||||
|
{
|
||||||
|
return $this->_defaultFontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $fontSize
|
||||||
|
*/
|
||||||
|
public function setDefaultFontSize($fontSize)
|
||||||
|
{
|
||||||
|
$this->_defaultFontSize = $fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default paragraph style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param array $styles Paragraph style definition
|
||||||
|
*/
|
||||||
|
public function setDefaultParagraphStyle($styles)
|
||||||
|
{
|
||||||
|
Style::setDefaultParagraphStyle($styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a paragraph style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param $styleName string
|
||||||
|
* @param $styles array
|
||||||
|
*/
|
||||||
|
public function addParagraphStyle($styleName, $styles)
|
||||||
|
{
|
||||||
|
Style::addParagraphStyle($styleName, $styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a font style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param $styleName string
|
||||||
|
* @param $styles array
|
||||||
|
*/
|
||||||
|
public function addFontStyle($styleName, $styleFont, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
Style::addFontStyle($styleName, $styleFont, $styleParagraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a table style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param $styleName string
|
||||||
|
* @param $styles array
|
||||||
|
*/
|
||||||
|
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
||||||
|
{
|
||||||
|
Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a heading style definition to styles.xml
|
||||||
|
*
|
||||||
|
* @param $titleCount int
|
||||||
|
* @param $styles array
|
||||||
|
*/
|
||||||
|
public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a hyperlink style to styles.xml
|
||||||
|
*
|
||||||
|
* @param $styleName string
|
||||||
|
* @param $styles array
|
||||||
|
*/
|
||||||
|
public function addLinkStyle($styleName, $styles)
|
||||||
|
{
|
||||||
|
Style::addLinkStyle($styleName, $styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PhpOffice\PhpWord\Section[]
|
||||||
|
*/
|
||||||
|
public function getSections()
|
||||||
|
{
|
||||||
|
return $this->_sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename Fully qualified filename.
|
||||||
|
* @return PhpOffice\PhpWord\Template
|
||||||
|
* @throws PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function loadTemplate($filename)
|
||||||
|
{
|
||||||
|
if (\file_exists($filename)) {
|
||||||
|
return new Template($filename);
|
||||||
|
} else {
|
||||||
|
throw new Exception("Template file {$filename} not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Reader;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore Abstract class
|
||||||
|
*/
|
||||||
|
abstract class AbstractReader implements IReader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Read data only?
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $readDataOnly = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool|resource
|
||||||
|
*/
|
||||||
|
protected $fileHandle = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read data only?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getReadDataOnly()
|
||||||
|
{
|
||||||
|
// return $this->readDataOnly;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set read data only
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Reader\IReader
|
||||||
|
*/
|
||||||
|
public function setReadDataOnly($pValue = true)
|
||||||
|
{
|
||||||
|
$this->readDataOnly = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open file for reading
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return resource
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected function openFile($pFilename)
|
||||||
|
{
|
||||||
|
// Check if file exists
|
||||||
|
if (!file_exists($pFilename) || !is_readable($pFilename)) {
|
||||||
|
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open file
|
||||||
|
$this->fileHandle = fopen($pFilename, 'r');
|
||||||
|
if ($this->fileHandle === false) {
|
||||||
|
throw new Exception("Could not open file " . $pFilename . " for reading.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can the current IReader read the file?
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function canRead($pFilename)
|
||||||
|
{
|
||||||
|
// Check if file exists
|
||||||
|
try {
|
||||||
|
$this->openFile($pFilename);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fclose($this->fileHandle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Reader;
|
||||||
|
|
||||||
|
interface IReader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Can the current IReader read the file?
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function canRead($pFilename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads PhpWord from file
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
*/
|
||||||
|
public function load($pFilename);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,452 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Reader;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\DocumentProperties;
|
||||||
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||||
|
use PhpOffice\PhpWord\Shared\File;
|
||||||
|
|
||||||
|
if (!defined('PHPWORD_BASE_DIR')) {
|
||||||
|
define('PHPWORD_BASE_DIR', \dirname(__FILE__) . '/../../');
|
||||||
|
require(PHPWORD_BASE_DIR . 'Autoloader.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
class Word2007 extends AbstractReader implements IReader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Can the current IReader read the file?
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return bool
|
||||||
|
* @throws PhpOffice\PhpWord\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function canRead($pFilename)
|
||||||
|
{
|
||||||
|
// Check if file exists
|
||||||
|
if (!file_exists($pFilename)) {
|
||||||
|
throw new Exception("Could not open {$pFilename} for reading! File does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = false;
|
||||||
|
// Load file
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
if ($zip->open($pFilename) === true) {
|
||||||
|
// check if it is an OOXML archive
|
||||||
|
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
|
||||||
|
if ($rels !== false) {
|
||||||
|
foreach ($rels->Relationship as $rel) {
|
||||||
|
switch ($rel["Type"]) {
|
||||||
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
|
||||||
|
if (basename($rel["Target"]) == 'document.xml') {
|
||||||
|
$return = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ZipArchive $archive
|
||||||
|
* @param string $fileName
|
||||||
|
* @param bool $removeNamespace
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFromZipArchive($archive, $fileName = '', $removeNamespace = false)
|
||||||
|
{
|
||||||
|
// Root-relative paths
|
||||||
|
if (strpos($fileName, '//') !== false) {
|
||||||
|
$fileName = substr($fileName, strpos($fileName, '//') + 1);
|
||||||
|
}
|
||||||
|
$fileName = File::realpath($fileName);
|
||||||
|
|
||||||
|
// Apache POI fixes
|
||||||
|
$contents = $archive->getFromName($fileName);
|
||||||
|
if ($contents === false) {
|
||||||
|
$contents = $archive->getFromName(substr($fileName, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove namespaces from elements and attributes name
|
||||||
|
if ($removeNamespace) {
|
||||||
|
$contents = preg_replace('~(</?|\s)w:~is', '$1', $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads PhpWord from file
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return PhpOffice\PhpWord|null
|
||||||
|
*/
|
||||||
|
public function load($pFilename)
|
||||||
|
{
|
||||||
|
// Check if file exists and can be read
|
||||||
|
if (!$this->canRead($pFilename)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialisations
|
||||||
|
$word = new PhpWord();
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$zip->open($pFilename);
|
||||||
|
|
||||||
|
// Read properties and documents
|
||||||
|
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
|
||||||
|
foreach ($rels->Relationship as $rel) {
|
||||||
|
switch ($rel["Type"]) {
|
||||||
|
// Core properties
|
||||||
|
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
|
||||||
|
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
|
||||||
|
if (is_object($xmlCore)) {
|
||||||
|
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||||
|
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
|
||||||
|
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
|
||||||
|
$docProps = $word->getDocumentProperties();
|
||||||
|
$docProps->setCreator((string)self::arrayItem($xmlCore->xpath("dc:creator")));
|
||||||
|
$docProps->setLastModifiedBy((string)self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
|
||||||
|
$docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created"))));
|
||||||
|
$docProps->setModified(strtotime(self::arrayItem($xmlCore->xpath("dcterms:modified"))));
|
||||||
|
$docProps->setTitle((string)self::arrayItem($xmlCore->xpath("dc:title")));
|
||||||
|
$docProps->setDescription((string)self::arrayItem($xmlCore->xpath("dc:description")));
|
||||||
|
$docProps->setSubject((string)self::arrayItem($xmlCore->xpath("dc:subject")));
|
||||||
|
$docProps->setKeywords((string)self::arrayItem($xmlCore->xpath("cp:keywords")));
|
||||||
|
$docProps->setCategory((string)self::arrayItem($xmlCore->xpath("cp:category")));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Extended properties
|
||||||
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
|
||||||
|
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
|
||||||
|
if (is_object($xmlCore)) {
|
||||||
|
$docProps = $word->getDocumentProperties();
|
||||||
|
if (isset($xmlCore->Company)) {
|
||||||
|
$docProps->setCompany((string)$xmlCore->Company);
|
||||||
|
}
|
||||||
|
if (isset($xmlCore->Manager)) {
|
||||||
|
$docProps->setManager((string)$xmlCore->Manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Custom properties
|
||||||
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
|
||||||
|
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
|
||||||
|
if (is_object($xmlCore)) {
|
||||||
|
$docProps = $word->getDocumentProperties();
|
||||||
|
foreach ($xmlCore as $xmlProperty) {
|
||||||
|
$cellDataOfficeAttributes = $xmlProperty->attributes();
|
||||||
|
if (isset($cellDataOfficeAttributes['name'])) {
|
||||||
|
$propertyName = (string)$cellDataOfficeAttributes['name'];
|
||||||
|
$cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
|
||||||
|
$attributeType = $cellDataOfficeChildren->getName();
|
||||||
|
$attributeValue = (string)$cellDataOfficeChildren->{$attributeType};
|
||||||
|
$attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
|
||||||
|
$attributeType = DocumentProperties::convertPropertyType($attributeType);
|
||||||
|
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Document
|
||||||
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
|
||||||
|
$dir = dirname($rel["Target"]);
|
||||||
|
$archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels";
|
||||||
|
$relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive));
|
||||||
|
$relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
|
||||||
|
$xpath = self::arrayItem(
|
||||||
|
$relsDoc->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")
|
||||||
|
);
|
||||||
|
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
|
||||||
|
if (is_object($xmlDoc)) {
|
||||||
|
$section = $word->createSection();
|
||||||
|
|
||||||
|
foreach ($xmlDoc->body->children() as $elm) {
|
||||||
|
$elmName = $elm->getName();
|
||||||
|
if ($elmName == 'p') { // Paragraph/section
|
||||||
|
// Create new section if section setting found
|
||||||
|
if ($elm->pPr->sectPr) {
|
||||||
|
$section->setSettings($this->loadSectionSettings($elm->pPr));
|
||||||
|
$section = $word->createSection();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Has w:r? It's either text or textrun
|
||||||
|
if ($elm->r) {
|
||||||
|
// w:r = 1? It's a plain paragraph
|
||||||
|
if (count($elm->r) == 1) {
|
||||||
|
$section->addText(
|
||||||
|
$elm->r->t,
|
||||||
|
$this->loadFontStyle($elm->r)
|
||||||
|
);
|
||||||
|
// w:r more than 1? It's a textrun
|
||||||
|
} else {
|
||||||
|
$textRun = $section->createTextRun();
|
||||||
|
foreach ($elm->r as $r) {
|
||||||
|
$textRun->addText(
|
||||||
|
$r->t,
|
||||||
|
$this->loadFontStyle($r)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No, it's a textbreak
|
||||||
|
} else {
|
||||||
|
$section->addTextBreak();
|
||||||
|
}
|
||||||
|
} elseif ($elmName == 'sectPr') {
|
||||||
|
// Last section setting
|
||||||
|
$section->setSettings($this->loadSectionSettings($xmlDoc->body));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read styles
|
||||||
|
$docRels = simplexml_load_string($this->getFromZipArchive($zip, "word/_rels/document.xml.rels"));
|
||||||
|
foreach ($docRels->Relationship as $rel) {
|
||||||
|
switch ($rel["Type"]) {
|
||||||
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
|
||||||
|
$xmlStyle = simplexml_load_string($this->getFromZipArchive($zip, "word/{$rel['Target']}", true));
|
||||||
|
if (is_object($xmlStyle)) {
|
||||||
|
foreach ($xmlStyle->children() as $elm) {
|
||||||
|
if ($elm->getName() != 'style') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$pStyle = null;
|
||||||
|
$fStyle = null;
|
||||||
|
$hasParagraphStyle = isset($elm->pPr);
|
||||||
|
$hasFontStyle = isset($elm->rPr);
|
||||||
|
$styleName = (string)$elm->name['val'];
|
||||||
|
if ($hasParagraphStyle) {
|
||||||
|
$pStyle = $this->loadParagraphStyle($elm);
|
||||||
|
if (!$hasFontStyle) {
|
||||||
|
$word->addParagraphStyle($styleName, $pStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($hasFontStyle) {
|
||||||
|
$fStyle = $this->loadFontStyle($elm);
|
||||||
|
$word->addFontStyle($styleName, $fStyle, $pStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
return $word;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load section settings from SimpleXMLElement
|
||||||
|
*
|
||||||
|
* @param SimpleXMLElement $elm
|
||||||
|
* @return array|string|null
|
||||||
|
*
|
||||||
|
* @todo Implement gutter
|
||||||
|
*/
|
||||||
|
private function loadSectionSettings($elm)
|
||||||
|
{
|
||||||
|
if ($xml = $elm->sectPr) {
|
||||||
|
$setting = array();
|
||||||
|
if ($xml->type) {
|
||||||
|
$setting['breakType'] = (string)$xml->type['val'];
|
||||||
|
}
|
||||||
|
if ($xml->pgSz) {
|
||||||
|
if (isset($xml->pgSz['w'])) {
|
||||||
|
$setting['pageSizeW'] = (int)$xml->pgSz['w'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgSz['h'])) {
|
||||||
|
$setting['pageSizeH'] = (int)$xml->pgSz['h'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgSz['orient'])) {
|
||||||
|
$setting['orientation'] = (string)$xml->pgSz['orient'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($xml->pgMar) {
|
||||||
|
if (isset($xml->pgMar['top'])) {
|
||||||
|
$setting['topMargin'] = (int)$xml->pgMar['top'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['left'])) {
|
||||||
|
$setting['leftMargin'] = (int)$xml->pgMar['left'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['bottom'])) {
|
||||||
|
$setting['bottomMargin'] = (int)$xml->pgMar['bottom'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['right'])) {
|
||||||
|
$setting['rightMargin'] = (int)$xml->pgMar['right'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['header'])) {
|
||||||
|
$setting['headerHeight'] = (int)$xml->pgMar['header'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['footer'])) {
|
||||||
|
$setting['footerHeight'] = (int)$xml->pgMar['footer'];
|
||||||
|
}
|
||||||
|
if (isset($xml->pgMar['gutter'])) {
|
||||||
|
// $setting['gutter'] = (int)$xml->pgMar['gutter'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($xml->cols) {
|
||||||
|
if (isset($xml->cols['num'])) {
|
||||||
|
$setting['colsNum'] = (int)$xml->cols['num'];
|
||||||
|
}
|
||||||
|
if (isset($xml->cols['space'])) {
|
||||||
|
$setting['colsSpace'] = (int)$xml->cols['space'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $setting;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load paragraph style from SimpleXMLElement
|
||||||
|
*
|
||||||
|
* @param SimpleXMLElement $elm
|
||||||
|
* @return array|string|null
|
||||||
|
*/
|
||||||
|
private function loadParagraphStyle($elm)
|
||||||
|
{
|
||||||
|
if ($xml = $elm->pPr) {
|
||||||
|
if ($xml->pStyle) {
|
||||||
|
return (string)$xml->pStyle['val'];
|
||||||
|
}
|
||||||
|
$style = array();
|
||||||
|
if ($xml->jc) {
|
||||||
|
$style['align'] = (string)$xml->jc['val'];
|
||||||
|
}
|
||||||
|
if ($xml->ind) {
|
||||||
|
if (isset($xml->ind->left)) {
|
||||||
|
$style['indent'] = (int)$xml->ind->left;
|
||||||
|
}
|
||||||
|
if (isset($xml->ind->hanging)) {
|
||||||
|
$style['hanging'] = (int)$xml->ind->hanging;
|
||||||
|
}
|
||||||
|
if (isset($xml->ind->line)) {
|
||||||
|
$style['spacing'] = (int)$xml->ind->line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($xml->spacing) {
|
||||||
|
if (isset($xml->spacing['after'])) {
|
||||||
|
$style['spaceAfter'] = (int)$xml->spacing['after'];
|
||||||
|
}
|
||||||
|
if (isset($xml->spacing['before'])) {
|
||||||
|
$style['spaceBefore'] = (int)$xml->spacing['before'];
|
||||||
|
}
|
||||||
|
if (isset($xml->spacing['line'])) {
|
||||||
|
$style['spacing'] = (int)$xml->spacing['line'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($xml->basedOn) {
|
||||||
|
$style['basedOn'] = (string)$xml->basedOn['val'];
|
||||||
|
}
|
||||||
|
if ($xml->next) {
|
||||||
|
$style['next'] = (string)$xml->next['val'];
|
||||||
|
}
|
||||||
|
if ($xml->widowControl) {
|
||||||
|
$style['widowControl'] = false;
|
||||||
|
}
|
||||||
|
if ($xml->keepNext) {
|
||||||
|
$style['keepNext'] = true;
|
||||||
|
}
|
||||||
|
if ($xml->keepLines) {
|
||||||
|
$style['keepLines'] = true;
|
||||||
|
}
|
||||||
|
if ($xml->pageBreakBefore) {
|
||||||
|
$style['pageBreakBefore'] = true;
|
||||||
|
}
|
||||||
|
return $style;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load font style from SimpleXMLElement
|
||||||
|
*
|
||||||
|
* @param SimpleXMLElement $elm
|
||||||
|
* @return array|string|null
|
||||||
|
*/
|
||||||
|
private function loadFontStyle($elm)
|
||||||
|
{
|
||||||
|
if ($xml = $elm->rPr) {
|
||||||
|
if ($xml->rStyle) {
|
||||||
|
return (string)$xml->rStyle['val'];
|
||||||
|
}
|
||||||
|
$style = array();
|
||||||
|
if ($xml->rFonts) {
|
||||||
|
$style['name'] = (string)$xml->rFonts['ascii'];
|
||||||
|
}
|
||||||
|
if ($xml->sz) {
|
||||||
|
$style['size'] = (int)$xml->sz['val'] / 2;
|
||||||
|
}
|
||||||
|
if ($xml->color) {
|
||||||
|
$style['color'] = (string)$xml->color['val'];
|
||||||
|
}
|
||||||
|
if ($xml->b) {
|
||||||
|
$style['bold'] = true;
|
||||||
|
}
|
||||||
|
if ($xml->i) {
|
||||||
|
$style['italic'] = true;
|
||||||
|
}
|
||||||
|
if ($xml->u) {
|
||||||
|
$style['underline'] = (string)$xml->u['val'];
|
||||||
|
}
|
||||||
|
if ($xml->strike) {
|
||||||
|
$style['strikethrough'] = true;
|
||||||
|
}
|
||||||
|
if ($xml->highlight) {
|
||||||
|
$style['fgColor'] = (string)$xml->highlight['val'];
|
||||||
|
}
|
||||||
|
if ($xml->vertAlign) {
|
||||||
|
if ($xml->vertAlign['val'] == 'superscript') {
|
||||||
|
$style['superScript'] = true;
|
||||||
|
} else {
|
||||||
|
$style['subScript'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $style;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $array
|
||||||
|
* @param mixed $key
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
private static function arrayItem($array, $key = 0)
|
||||||
|
{
|
||||||
|
return (isset($array[$key]) ? $array[$key] : null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,453 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||||
|
use PhpOffice\PhpWord\Section\Footer;
|
||||||
|
use PhpOffice\PhpWord\Section\Footnote;
|
||||||
|
use PhpOffice\PhpWord\Section\Image;
|
||||||
|
use PhpOffice\PhpWord\Section\Link;
|
||||||
|
use PhpOffice\PhpWord\Section\ListItem;
|
||||||
|
use PhpOffice\PhpWord\Section\MemoryImage;
|
||||||
|
use PhpOffice\PhpWord\Section\Object;
|
||||||
|
use PhpOffice\PhpWord\Section\PageBreak;
|
||||||
|
use PhpOffice\PhpWord\Section\Settings;
|
||||||
|
use PhpOffice\PhpWord\Section\Table;
|
||||||
|
use PhpOffice\PhpWord\Section\Text;
|
||||||
|
use PhpOffice\PhpWord\Section\TextBreak;
|
||||||
|
use PhpOffice\PhpWord\Section\TextRun;
|
||||||
|
use PhpOffice\PhpWord\Section\Title;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
|
class Section
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Section count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_sectionCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section settings
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Section\Settings
|
||||||
|
*/
|
||||||
|
private $_settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section Element Collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_elementCollection = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section Headers
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_headers = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section Footer
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Section\Footer
|
||||||
|
*/
|
||||||
|
private $_footer = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Section
|
||||||
|
*
|
||||||
|
* @param int $sectionCount
|
||||||
|
* @param mixed $settings
|
||||||
|
*/
|
||||||
|
public function __construct($sectionCount, $settings = null)
|
||||||
|
{
|
||||||
|
$this->_sectionCount = $sectionCount;
|
||||||
|
$this->_settings = new Settings();
|
||||||
|
$this->setSettings($settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Section Settings
|
||||||
|
*
|
||||||
|
* @param array $settings
|
||||||
|
*/
|
||||||
|
public function setSettings($settings = null)
|
||||||
|
{
|
||||||
|
if (!is_null($settings) && is_array($settings)) {
|
||||||
|
foreach ($settings as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_settings->setSettingValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Section Settings
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\Settings
|
||||||
|
*/
|
||||||
|
public function getSettings()
|
||||||
|
{
|
||||||
|
return $this->_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$text = new Text($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Link Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @param string $linkName
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Link
|
||||||
|
*/
|
||||||
|
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($linkSrc)) {
|
||||||
|
$linkSrc = utf8_encode($linkSrc);
|
||||||
|
}
|
||||||
|
if (!is_null($linkName)) {
|
||||||
|
if (!String::IsUTF8($linkName)) {
|
||||||
|
$linkName = utf8_encode($linkName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = new Link($linkSrc, $linkName, $styleFont, $styleParagraph);
|
||||||
|
$rID = Media::addSectionLinkElement($linkSrc);
|
||||||
|
$link->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $link;
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a TextBreak Element
|
||||||
|
*
|
||||||
|
* @param int $count
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PageBreak Element
|
||||||
|
*/
|
||||||
|
public function addPageBreak()
|
||||||
|
{
|
||||||
|
$this->_elementCollection[] = new PageBreak();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Table Element
|
||||||
|
*
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Table
|
||||||
|
*/
|
||||||
|
public function addTable($style = null)
|
||||||
|
{
|
||||||
|
$table = new Table('section', $this->_sectionCount, $style);
|
||||||
|
$this->_elementCollection[] = $table;
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a ListItem Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param int $depth
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleList
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\ListItem
|
||||||
|
*/
|
||||||
|
public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$listItem = new ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $listItem;
|
||||||
|
return $listItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a OLE-Object Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Object
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addObject($src, $style = null)
|
||||||
|
{
|
||||||
|
$object = new Object($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($object->getSource())) {
|
||||||
|
$inf = pathinfo($src);
|
||||||
|
$ext = $inf['extension'];
|
||||||
|
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
|
||||||
|
$ext = substr($ext, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/';
|
||||||
|
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
|
||||||
|
$iconSrc = $iconSrc . '_default.png';
|
||||||
|
} else {
|
||||||
|
$iconSrc .= '_' . $ext . '.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
|
||||||
|
$data = Media::addSectionMediaElement($src, 'oleObject');
|
||||||
|
$rID = $data[0];
|
||||||
|
$objectId = $data[1];
|
||||||
|
|
||||||
|
$object->setRelationId($rID);
|
||||||
|
$object->setObjectId($objectId);
|
||||||
|
$object->setImageRelationId($rIDimg);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $object;
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
throw new Exception('Source does not exist or unsupported object type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Image Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Image
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addImage($src, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
$rID = Media::addSectionMediaElement($src, 'image');
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
throw new Exception('Source does not exist or unsupported image type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a by PHP created Image Element
|
||||||
|
*
|
||||||
|
* @param string $link
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\MemoryImage
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addMemoryImage($link, $style = null)
|
||||||
|
{
|
||||||
|
$memoryImage = new MemoryImage($link, $style);
|
||||||
|
if (!is_null($memoryImage->getSource())) {
|
||||||
|
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
|
||||||
|
$memoryImage->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $memoryImage;
|
||||||
|
return $memoryImage;
|
||||||
|
}
|
||||||
|
throw new Exception('Unsupported image type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Table-of-Contents Element
|
||||||
|
*
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleTOC
|
||||||
|
* @return PhpOffice\PhpWord\TOC
|
||||||
|
*/
|
||||||
|
public function addTOC($styleFont = null, $styleTOC = null)
|
||||||
|
{
|
||||||
|
$toc = new TOC($styleFont, $styleTOC);
|
||||||
|
$this->_elementCollection[] = $toc;
|
||||||
|
return $toc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Title Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param int $depth
|
||||||
|
* @return PhpOffice\PhpWord\Section\Title
|
||||||
|
*/
|
||||||
|
public function addTitle($text, $depth = 1)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$styles = Style::getStyles();
|
||||||
|
if (array_key_exists('Heading_' . $depth, $styles)) {
|
||||||
|
$style = 'Heading' . $depth;
|
||||||
|
} else {
|
||||||
|
$style = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = new Title($text, $depth, $style);
|
||||||
|
|
||||||
|
$data = TOC::addTitle($text, $depth);
|
||||||
|
$anchor = $data[0];
|
||||||
|
$bookmarkId = $data[1];
|
||||||
|
|
||||||
|
$title->setAnchor($anchor);
|
||||||
|
$title->setBookmarkId($bookmarkId);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $title;
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextRun
|
||||||
|
*
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\TextRun
|
||||||
|
*/
|
||||||
|
public function createTextRun($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$textRun = new TextRun($styleParagraph);
|
||||||
|
$this->_elementCollection[] = $textRun;
|
||||||
|
return $textRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Elements
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Header
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\Header
|
||||||
|
*/
|
||||||
|
public function createHeader()
|
||||||
|
{
|
||||||
|
$header = new Header($this->_sectionCount);
|
||||||
|
$this->_headers[] = $header;
|
||||||
|
return $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Headers
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getHeaders()
|
||||||
|
{
|
||||||
|
return $this->_headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there a header for this section that is for the first page only?
|
||||||
|
*
|
||||||
|
* If any of the Header instances have a type of Header::FIRST then this method returns true.
|
||||||
|
* False otherwise.
|
||||||
|
*
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public function hasDifferentFirstPage()
|
||||||
|
{
|
||||||
|
$value = array_filter($this->_headers, function (Header &$header) {
|
||||||
|
return $header->getType() == Header::FIRST;
|
||||||
|
});
|
||||||
|
return count($value) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Footer
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footer
|
||||||
|
*/
|
||||||
|
public function createFooter()
|
||||||
|
{
|
||||||
|
$footer = new Footer($this->_sectionCount);
|
||||||
|
$this->_footer = $footer;
|
||||||
|
return $footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footer
|
||||||
|
*/
|
||||||
|
public function getFooter()
|
||||||
|
{
|
||||||
|
return $this->_footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Footnote Element
|
||||||
|
*
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footnote
|
||||||
|
*/
|
||||||
|
public function createFootnote($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$footnote = new Footnote($styleParagraph);
|
||||||
|
$refID = Footnote::addFootnoteElement($footnote);
|
||||||
|
$footnote->setReferenceId($refID);
|
||||||
|
$this->_elementCollection[] = $footnote;
|
||||||
|
return $footnote;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,217 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
|
use PhpOffice\PhpWord\Section\Footer\PreserveText;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
|
class Footer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Footer Count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_footerCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Footer Relation ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Footer Element Collection
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_elementCollection = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Footer
|
||||||
|
*/
|
||||||
|
public function __construct($sectionCount)
|
||||||
|
{
|
||||||
|
$this->_footerCount = $sectionCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$text = new Text($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add TextBreak
|
||||||
|
*
|
||||||
|
* @param int $count
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextRun
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\TextRun
|
||||||
|
*/
|
||||||
|
public function createTextRun($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$textRun = new TextRun($styleParagraph);
|
||||||
|
$this->_elementCollection[] = $textRun;
|
||||||
|
return $textRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Table Element
|
||||||
|
*
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Table
|
||||||
|
*/
|
||||||
|
public function addTable($style = null)
|
||||||
|
{
|
||||||
|
$table = new Table('footer', $this->_footerCount, $style);
|
||||||
|
$this->_elementCollection[] = $table;
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Image Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
public function addImage($src, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
$rID = Media::addFooterMediaElement($this->_footerCount, $src);
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Src does not exist or invalid image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a by PHP created Image Element
|
||||||
|
*
|
||||||
|
* @param string $link
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\MemoryImage
|
||||||
|
*/
|
||||||
|
public function addMemoryImage($link, $style = null)
|
||||||
|
{
|
||||||
|
$memoryImage = new MemoryImage($link, $style);
|
||||||
|
if (!is_null($memoryImage->getSource())) {
|
||||||
|
$rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
|
||||||
|
$memoryImage->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $memoryImage;
|
||||||
|
return $memoryImage;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Unsupported image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PreserveText Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
|
||||||
|
*/
|
||||||
|
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $ptext;
|
||||||
|
return $ptext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Relation ID
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Footer Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Footer Elements
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Count
|
||||||
|
*/
|
||||||
|
public function getFooterCount()
|
||||||
|
{
|
||||||
|
return $this->_footerCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section\Footer;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class PreserveText
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Text content
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
private $_styleFont;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $_styleParagraph;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Preserve Text Element
|
||||||
|
*
|
||||||
|
* @var string $text
|
||||||
|
* @var mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
// Set font style
|
||||||
|
if (is_array($styleFont)) {
|
||||||
|
$this->_styleFont = new Font('text');
|
||||||
|
|
||||||
|
foreach ($styleFont as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleFont->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleFont = $styleFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set paragraph style
|
||||||
|
if (is_array($styleParagraph)) {
|
||||||
|
$this->_styleParagraph = new Paragraph();
|
||||||
|
|
||||||
|
foreach ($styleParagraph as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleParagraph->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleParagraph = $styleParagraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||||
|
if (isset($matches[0])) {
|
||||||
|
$this->_text = $matches[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function getFontStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleParagraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getText()
|
||||||
|
{
|
||||||
|
return $this->_text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,151 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class Footnote
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $_styleParagraph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Footnote Reference ID
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_refId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_elementCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Footnote Element
|
||||||
|
*/
|
||||||
|
public function __construct($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$this->_elementCollection = array();
|
||||||
|
|
||||||
|
// Set paragraph style
|
||||||
|
if (is_array($styleParagraph)) {
|
||||||
|
$this->_styleParagraph = new Paragraph();
|
||||||
|
|
||||||
|
foreach ($styleParagraph as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleParagraph->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleParagraph = $styleParagraph;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @var string $text
|
||||||
|
* @var mixed $styleFont
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text = null, $styleFont = null)
|
||||||
|
{
|
||||||
|
$givenText = $text;
|
||||||
|
$text = new Text($givenText, $styleFont);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Link Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @param string $linkName
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @return PhpOffice\PhpWord\Section\Link
|
||||||
|
*/
|
||||||
|
public function addLink($linkSrc, $linkName = null, $styleFont = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
$link = new Link($linkSrc, $linkName, $styleFont);
|
||||||
|
$rID = PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
|
||||||
|
$link->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $link;
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote content
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleParagraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footnote Reference ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getReferenceId()
|
||||||
|
{
|
||||||
|
return $this->_refId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Footnote Reference ID
|
||||||
|
*
|
||||||
|
* @param int $refId
|
||||||
|
*/
|
||||||
|
public function setReferenceId($refId)
|
||||||
|
{
|
||||||
|
$this->_refId = $refId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,299 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
|
use PhpOffice\PhpWord\Section\Footer\PreserveText;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
|
class Header
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Header Count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_headerCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header Relation ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
|
||||||
|
*/
|
||||||
|
private $_type = self::AUTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even Numbered Pages Only
|
||||||
|
* @var string
|
||||||
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
|
||||||
|
*/
|
||||||
|
const EVEN = 'even';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default Header or Footer
|
||||||
|
* @var string
|
||||||
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
|
||||||
|
*/
|
||||||
|
const AUTO = 'default'; // Did not use DEFAULT because it is a PHP keyword
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First Page Only
|
||||||
|
* @var string
|
||||||
|
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
|
||||||
|
*/
|
||||||
|
const FIRST = 'first';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header Element Collection
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_elementCollection = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Header
|
||||||
|
*/
|
||||||
|
public function __construct($sectionCount)
|
||||||
|
{
|
||||||
|
$this->_headerCount = $sectionCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$text = new Text($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add TextBreak
|
||||||
|
*
|
||||||
|
* @param int $count
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextRun
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\TextRun
|
||||||
|
*/
|
||||||
|
public function createTextRun($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$textRun = new TextRun($styleParagraph);
|
||||||
|
$this->_elementCollection[] = $textRun;
|
||||||
|
return $textRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Table Element
|
||||||
|
*
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Table
|
||||||
|
*/
|
||||||
|
public function addTable($style = null)
|
||||||
|
{
|
||||||
|
$table = new Table('header', $this->_headerCount, $style);
|
||||||
|
$this->_elementCollection[] = $table;
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Image Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Image
|
||||||
|
*/
|
||||||
|
public function addImage($src, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Src does not exist or invalid image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a by PHP created Image Element
|
||||||
|
*
|
||||||
|
* @param string $link
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\MemoryImage
|
||||||
|
*/
|
||||||
|
public function addMemoryImage($link, $style = null)
|
||||||
|
{
|
||||||
|
$memoryImage = new MemoryImage($link, $style);
|
||||||
|
if (!is_null($memoryImage->getSource())) {
|
||||||
|
$rID = Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
|
||||||
|
$memoryImage->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $memoryImage;
|
||||||
|
return $memoryImage;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Unsupported image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PreserveText Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
|
||||||
|
*/
|
||||||
|
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $ptext;
|
||||||
|
return $ptext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Watermark Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Image
|
||||||
|
*/
|
||||||
|
public function addWatermark($src, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($src, $style, true);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Src does not exist or invalid image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Relation ID
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Header Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Header Elements
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Count
|
||||||
|
*/
|
||||||
|
public function getHeaderCount()
|
||||||
|
{
|
||||||
|
return $this->_headerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Type
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset back to default
|
||||||
|
*/
|
||||||
|
public function resetType()
|
||||||
|
{
|
||||||
|
return $this->_type = self::AUTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First page only header
|
||||||
|
*/
|
||||||
|
public function firstPage()
|
||||||
|
{
|
||||||
|
return $this->_type = self::FIRST;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even numbered Pages only
|
||||||
|
*/
|
||||||
|
public function evenPage()
|
||||||
|
{
|
||||||
|
return $this->_type = self::EVEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
|
||||||
|
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
|
||||||
|
|
||||||
|
class Image
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Image Src
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_src;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Relation ID
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is Watermark
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_isWatermark;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Image
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @param bool $isWatermark
|
||||||
|
* @throws InvalidImageException|UnsupportedImageTypeException
|
||||||
|
*/
|
||||||
|
public function __construct($src, $style = null, $isWatermark = false)
|
||||||
|
{
|
||||||
|
$supportedImageTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
|
||||||
|
|
||||||
|
if (!file_exists($src)) {
|
||||||
|
throw new InvalidImageException;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
|
||||||
|
throw new UnsupportedImageTypeException;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_src = $src;
|
||||||
|
$this->_isWatermark = $isWatermark;
|
||||||
|
$this->_style = new PhpOffice\PhpWord\Style\Image();
|
||||||
|
|
||||||
|
if (!is_null($style) && is_array($style)) {
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($style['wrappingStyle'])) {
|
||||||
|
$this->_style->setWrappingStyle($style['wrappingStyle']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
|
||||||
|
$imgData = getimagesize($this->_src);
|
||||||
|
$this->_style->setWidth($imgData[0]);
|
||||||
|
$this->_style->setHeight($imgData[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Relation ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Image Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Source
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Media ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMediaId()
|
||||||
|
{
|
||||||
|
return md5($this->_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get IsWatermark
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getIsWatermark()
|
||||||
|
{
|
||||||
|
return $this->_isWatermark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set IsWatermark
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
*/
|
||||||
|
public function setIsWatermark($pValue)
|
||||||
|
{
|
||||||
|
$this->_isWatermark = $pValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,174 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class Link
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Link source
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_linkSrc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_linkName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link Relation ID
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
private $_styleFont;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $_styleParagraph;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Link Element
|
||||||
|
*
|
||||||
|
* @var string $linkSrc
|
||||||
|
* @var string $linkName
|
||||||
|
* @var mixed $styleFont
|
||||||
|
* @var mixed $styleParagraph
|
||||||
|
*/
|
||||||
|
public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
$this->_linkSrc = $linkSrc;
|
||||||
|
$this->_linkName = $linkName;
|
||||||
|
|
||||||
|
// Set font style
|
||||||
|
if (is_array($styleFont)) {
|
||||||
|
$this->_styleFont = new Font('text');
|
||||||
|
|
||||||
|
foreach ($styleFont as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleFont->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleFont = $styleFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set paragraph style
|
||||||
|
if (is_array($styleParagraph)) {
|
||||||
|
$this->_styleParagraph = new Paragraph();
|
||||||
|
|
||||||
|
foreach ($styleParagraph as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleParagraph->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleParagraph = $styleParagraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Link Relation ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Link Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Link source
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLinkSrc()
|
||||||
|
{
|
||||||
|
return $this->_linkSrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Link name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLinkName()
|
||||||
|
{
|
||||||
|
return $this->_linkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function getFontStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleParagraph;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
class ListItem
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* ListItem Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\ListItem
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Textrun
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
private $_textObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ListItem Depth
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_depth;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ListItem
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param int $depth
|
||||||
|
* @param mixed $styleText
|
||||||
|
* @param mixed $styleList
|
||||||
|
*/
|
||||||
|
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
$this->_style = new PhpOffice\PhpWord\Style\ListItem();
|
||||||
|
$this->_textObject = new Text($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_depth = $depth;
|
||||||
|
|
||||||
|
if (!is_null($styleList) && is_array($styleList)) {
|
||||||
|
foreach ($styleList as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ListItem style
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ListItem TextRun
|
||||||
|
*/
|
||||||
|
public function getTextObject()
|
||||||
|
{
|
||||||
|
return $this->_textObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ListItem depth
|
||||||
|
*/
|
||||||
|
public function getDepth()
|
||||||
|
{
|
||||||
|
return $this->_depth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,233 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Image;
|
||||||
|
|
||||||
|
class MemoryImage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Image Src
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_src;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Relation ID
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_imageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Create function
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_imageCreateFunc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image function
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_imageFunc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image function
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_imageExtension;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Image
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($src, $style = null)
|
||||||
|
{
|
||||||
|
$imgData = getimagesize($src);
|
||||||
|
$this->_imageType = $imgData['mime'];
|
||||||
|
|
||||||
|
$_supportedImageTypes = array('image/jpeg', 'image/gif', 'image/png');
|
||||||
|
|
||||||
|
if (in_array($this->_imageType, $_supportedImageTypes)) {
|
||||||
|
$this->_src = $src;
|
||||||
|
$this->_style = new Image();
|
||||||
|
|
||||||
|
if (!is_null($style) && is_array($style)) {
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
|
||||||
|
$this->_style->setWidth($imgData[0]);
|
||||||
|
$this->_style->setHeight($imgData[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_setFunctions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Functions
|
||||||
|
*/
|
||||||
|
private function _setFunctions()
|
||||||
|
{
|
||||||
|
switch ($this->_imageType) {
|
||||||
|
case 'image/png':
|
||||||
|
$this->_imageCreateFunc = 'imagecreatefrompng';
|
||||||
|
$this->_imageFunc = 'imagepng';
|
||||||
|
$this->_imageExtension = 'png';
|
||||||
|
break;
|
||||||
|
case 'image/gif':
|
||||||
|
$this->_imageCreateFunc = 'imagecreatefromgif';
|
||||||
|
$this->_imageFunc = 'imagegif';
|
||||||
|
$this->_imageExtension = 'gif';
|
||||||
|
break;
|
||||||
|
case 'image/jpeg':
|
||||||
|
case 'image/jpg':
|
||||||
|
$this->_imageCreateFunc = 'imagecreatefromjpeg';
|
||||||
|
$this->_imageFunc = 'imagejpeg';
|
||||||
|
$this->_imageExtension = 'jpg';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Relation ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Image Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Source
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Media ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMediaId()
|
||||||
|
{
|
||||||
|
return md5($this->_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getImageType()
|
||||||
|
{
|
||||||
|
return $this->_imageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Create Function
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getImageCreateFunction()
|
||||||
|
{
|
||||||
|
return $this->_imageCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Function
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getImageFunction()
|
||||||
|
{
|
||||||
|
return $this->_imageFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Extension
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getImageExtension()
|
||||||
|
{
|
||||||
|
return $this->_imageExtension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,179 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Image;
|
||||||
|
|
||||||
|
class Object
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Ole-Object Src
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_src;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object Relation ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_rId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image Relation ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_rIdImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_objId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Ole-Object Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($src, $style = null)
|
||||||
|
{
|
||||||
|
$_supportedObjectTypes = array('xls', 'doc', 'ppt');
|
||||||
|
$inf = pathinfo($src);
|
||||||
|
|
||||||
|
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
|
||||||
|
$this->_src = $src;
|
||||||
|
$this->_style = new Image();
|
||||||
|
|
||||||
|
if (!is_null($style) && is_array($style)) {
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Image
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Source
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Object Relation ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Object Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rId = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Image Relation ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getImageRelationId()
|
||||||
|
{
|
||||||
|
return $this->_rIdImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Image Relation ID
|
||||||
|
*
|
||||||
|
* @param int $rId
|
||||||
|
*/
|
||||||
|
public function setImageRelationId($rId)
|
||||||
|
{
|
||||||
|
$this->_rIdImg = $rId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Object ID
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getObjectId()
|
||||||
|
{
|
||||||
|
return $this->_objId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Object ID
|
||||||
|
*
|
||||||
|
* @param int $objId
|
||||||
|
*/
|
||||||
|
public function setObjectId($objId)
|
||||||
|
{
|
||||||
|
$this->_objId = $objId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
class PageBreak
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new PageBreak Element
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,728 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Default Page Size Width
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_defaultPageSizeW = 11906;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default Page Size Height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_defaultPageSizeH = 16838;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Orientation
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_orientation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Margin Top
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginTop;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Margin Left
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginLeft;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Margin Right
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Margin Bottom
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginBottom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Size Width
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_pageSizeW;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Size Height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_pageSizeH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Top Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderTopSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Top Color
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderTopColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Left Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderLeftSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Left Color
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderLeftColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Right Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderRightSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Right Color
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderRightColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Bottom Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderBottomSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Border Bottom Color
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderBottomColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page Numbering Start
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $pageNumberingStart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $headerHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $footerHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section columns count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_colsNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section spacing between columns
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_colsSpace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section break type
|
||||||
|
*
|
||||||
|
* Options:
|
||||||
|
* - nextPage: Next page section break
|
||||||
|
* - nextColumn: Column section break
|
||||||
|
* - continuous: Continuous section break
|
||||||
|
* - evenPage: Even page section break
|
||||||
|
* - oddPage: Odd page section break
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_breakType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new Section Settings
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_orientation = null;
|
||||||
|
$this->_marginTop = 1418;
|
||||||
|
$this->_marginLeft = 1418;
|
||||||
|
$this->_marginRight = 1418;
|
||||||
|
$this->_marginBottom = 1134;
|
||||||
|
$this->_pageSizeW = $this->_defaultPageSizeW;
|
||||||
|
$this->_pageSizeH = $this->_defaultPageSizeH;
|
||||||
|
$this->_borderTopSize = null;
|
||||||
|
$this->_borderTopColor = null;
|
||||||
|
$this->_borderLeftSize = null;
|
||||||
|
$this->_borderLeftColor = null;
|
||||||
|
$this->_borderRightSize = null;
|
||||||
|
$this->_borderRightColor = null;
|
||||||
|
$this->_borderBottomSize = null;
|
||||||
|
$this->_borderBottomColor = null;
|
||||||
|
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
|
||||||
|
$this->footerHeight = 720;
|
||||||
|
$this->_colsNum = 1;
|
||||||
|
$this->_colsSpace = 720;
|
||||||
|
$this->_breakType = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Setting Value
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setSettingValue($key, $value)
|
||||||
|
{
|
||||||
|
if ($key == '_orientation' && $value == 'landscape') {
|
||||||
|
$this->setLandscape();
|
||||||
|
} elseif ($key == '_orientation' && is_null($value)) {
|
||||||
|
$this->setPortrait();
|
||||||
|
} elseif ($key == '_borderSize') {
|
||||||
|
$this->setBorderSize($value);
|
||||||
|
} elseif ($key == '_borderColor') {
|
||||||
|
$this->setBorderColor($value);
|
||||||
|
} else {
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Top
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginTop()
|
||||||
|
{
|
||||||
|
return $this->_marginTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Top
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setMarginTop($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_marginTop = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Left
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginLeft()
|
||||||
|
{
|
||||||
|
return $this->_marginLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Left
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setMarginLeft($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_marginLeft = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Right
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginRight()
|
||||||
|
{
|
||||||
|
return $this->_marginRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Right
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setMarginRight($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_marginRight = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Bottom
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginBottom()
|
||||||
|
{
|
||||||
|
return $this->_marginBottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Bottom
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setMarginBottom($pValue = '')
|
||||||
|
{
|
||||||
|
$this->_marginBottom = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Landscape Orientation
|
||||||
|
*/
|
||||||
|
public function setLandscape()
|
||||||
|
{
|
||||||
|
$this->_orientation = 'landscape';
|
||||||
|
$this->_pageSizeW = $this->_defaultPageSizeH;
|
||||||
|
$this->_pageSizeH = $this->_defaultPageSizeW;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Portrait Orientation
|
||||||
|
*/
|
||||||
|
public function setPortrait()
|
||||||
|
{
|
||||||
|
$this->_orientation = null;
|
||||||
|
$this->_pageSizeW = $this->_defaultPageSizeW;
|
||||||
|
$this->_pageSizeH = $this->_defaultPageSizeH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Page Size Width
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPageSizeW()
|
||||||
|
{
|
||||||
|
return $this->_pageSizeW;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Page Size Height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPageSizeH()
|
||||||
|
{
|
||||||
|
return $this->_pageSizeH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Page Orientation
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOrientation()
|
||||||
|
{
|
||||||
|
return $this->_orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Size
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopSize = $pValue;
|
||||||
|
$this->_borderLeftSize = $pValue;
|
||||||
|
$this->_borderRightSize = $pValue;
|
||||||
|
$this->_borderBottomSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Size
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getBorderSize()
|
||||||
|
{
|
||||||
|
$t = $this->getBorderTopSize();
|
||||||
|
$l = $this->getBorderLeftSize();
|
||||||
|
$r = $this->getBorderRightSize();
|
||||||
|
$b = $this->getBorderBottomSize();
|
||||||
|
|
||||||
|
return array($t, $l, $r, $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopColor = $pValue;
|
||||||
|
$this->_borderLeftColor = $pValue;
|
||||||
|
$this->_borderRightColor = $pValue;
|
||||||
|
$this->_borderBottomColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Color
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getBorderColor()
|
||||||
|
{
|
||||||
|
$t = $this->getBorderTopColor();
|
||||||
|
$l = $this->getBorderLeftColor();
|
||||||
|
$r = $this->getBorderRightColor();
|
||||||
|
$b = $this->getBorderBottomColor();
|
||||||
|
|
||||||
|
return array($t, $l, $r, $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Top Size
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderTopSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Top Size
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBorderTopSize()
|
||||||
|
{
|
||||||
|
return $this->_borderTopSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Top Color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderTopColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Top Color
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBorderTopColor()
|
||||||
|
{
|
||||||
|
return $this->_borderTopColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Left Size
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderLeftSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderLeftSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Left Size
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBorderLeftSize()
|
||||||
|
{
|
||||||
|
return $this->_borderLeftSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Left Color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderLeftColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderLeftColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Left Color
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBorderLeftColor()
|
||||||
|
{
|
||||||
|
return $this->_borderLeftColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Right Size
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderRightSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderRightSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Right Size
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBorderRightSize()
|
||||||
|
{
|
||||||
|
return $this->_borderRightSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Right Color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderRightColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderRightColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Right Color
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBorderRightColor()
|
||||||
|
{
|
||||||
|
return $this->_borderRightColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Bottom Size
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderBottomSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderBottomSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Bottom Size
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBorderBottomSize()
|
||||||
|
{
|
||||||
|
return $this->_borderBottomSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Border Bottom Color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBorderBottomColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderBottomColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Border Bottom Color
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBorderBottomColor()
|
||||||
|
{
|
||||||
|
return $this->_borderBottomColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null|int $pageNumberingStart
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setPageNumberingStart($pageNumberingStart = null)
|
||||||
|
{
|
||||||
|
$this->pageNumberingStart = $pageNumberingStart;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null|int
|
||||||
|
*/
|
||||||
|
public function getPageNumberingStart()
|
||||||
|
{
|
||||||
|
return $this->pageNumberingStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHeaderHeight()
|
||||||
|
{
|
||||||
|
return $this->headerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Header Height
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setHeaderHeight($pValue = '')
|
||||||
|
{
|
||||||
|
if (!is_numeric($pValue)) {
|
||||||
|
$pValue = 720;
|
||||||
|
}
|
||||||
|
$this->headerHeight = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getFooterHeight()
|
||||||
|
{
|
||||||
|
return $this->footerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Footer Height
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setFooterHeight($pValue = '')
|
||||||
|
{
|
||||||
|
if (!is_numeric($pValue)) {
|
||||||
|
$pValue = 720;
|
||||||
|
}
|
||||||
|
$this->footerHeight = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Section Columns Count
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setColsNum($pValue = '')
|
||||||
|
{
|
||||||
|
if (!is_numeric($pValue)) {
|
||||||
|
$pValue = 1;
|
||||||
|
}
|
||||||
|
$this->_colsNum = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Section Columns Count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getColsNum()
|
||||||
|
{
|
||||||
|
return $this->_colsNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Section Space Between Columns
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setColsSpace($pValue = '')
|
||||||
|
{
|
||||||
|
if (!is_numeric($pValue)) {
|
||||||
|
$pValue = 720;
|
||||||
|
}
|
||||||
|
$this->_colsSpace = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Section Space Between Columns
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getColsSpace()
|
||||||
|
{
|
||||||
|
return $this->_colsSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Break Type
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setBreakType($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_breakType = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Break Type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBreakType()
|
||||||
|
{
|
||||||
|
return $this->_breakType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Section\Table\Row;
|
||||||
|
|
||||||
|
class Table
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Table style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Table
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table rows
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_rows = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table holder
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_insideOf = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table holder count
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_pCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table width
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_width = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new table
|
||||||
|
*
|
||||||
|
* @param string $insideOf
|
||||||
|
* @param int $pCount
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($insideOf, $pCount, $style = null)
|
||||||
|
{
|
||||||
|
$this->_insideOf = $insideOf;
|
||||||
|
$this->_pCount = $pCount;
|
||||||
|
|
||||||
|
if (!is_null($style)) {
|
||||||
|
if (is_array($style)) {
|
||||||
|
$this->_style = new PhpOffice\PhpWord\Style\Table();
|
||||||
|
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_style = $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a row
|
||||||
|
*
|
||||||
|
* @param int $height
|
||||||
|
*/
|
||||||
|
public function addRow($height = null, $style = null)
|
||||||
|
{
|
||||||
|
$row = new Row($this->_insideOf, $this->_pCount, $height, $style);
|
||||||
|
$this->_rows[] = $row;
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a cell
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Table\Cell
|
||||||
|
*/
|
||||||
|
public function addCell($width = null, $style = null)
|
||||||
|
{
|
||||||
|
$i = count($this->_rows) - 1;
|
||||||
|
$cell = $this->_rows[$i]->addCell($width, $style);
|
||||||
|
return $cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all rows
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRows()
|
||||||
|
{
|
||||||
|
return $this->_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get table style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Table
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set table width
|
||||||
|
*
|
||||||
|
* @var int $width
|
||||||
|
*/
|
||||||
|
public function setWidth($width)
|
||||||
|
{
|
||||||
|
$this->_width = $width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get table width
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getWidth()
|
||||||
|
{
|
||||||
|
return $this->_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,350 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section\Table;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
|
use PhpOffice\PhpWord\Section\Footer\PreserveText;
|
||||||
|
use PhpOffice\PhpWord\Section\Image;
|
||||||
|
use PhpOffice\PhpWord\Section\Link;
|
||||||
|
use PhpOffice\PhpWord\Section\ListItem;
|
||||||
|
use PhpOffice\PhpWord\Section\MemoryImage;
|
||||||
|
use PhpOffice\PhpWord\Section\Object;
|
||||||
|
use PhpOffice\PhpWord\Section\Text;
|
||||||
|
use PhpOffice\PhpWord\Section\TextBreak;
|
||||||
|
use PhpOffice\PhpWord\Section\TextRun;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
|
class Cell
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cell Width
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_width = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cell Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Cell
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cell Element Collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_elementCollection = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table holder
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_insideOf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section/Header/Footer count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_pCount;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Table Cell
|
||||||
|
*
|
||||||
|
* @param string $insideOf
|
||||||
|
* @param int $pCount
|
||||||
|
* @param int $width
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($insideOf, $pCount, $width = null, $style = null)
|
||||||
|
{
|
||||||
|
$this->_insideOf = $insideOf;
|
||||||
|
$this->_pCount = $pCount;
|
||||||
|
$this->_width = $width;
|
||||||
|
$this->_style = new PhpOffice\PhpWord\Style\Cell();
|
||||||
|
|
||||||
|
if (!is_null($style)) {
|
||||||
|
if (is_array($style)) {
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_style = $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$text = new Text($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Link Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @param string $linkName
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Link
|
||||||
|
*/
|
||||||
|
public function addLink($linkSrc, $linkName = null, $style = null)
|
||||||
|
{
|
||||||
|
if ($this->_insideOf == 'section') {
|
||||||
|
if (!String::IsUTF8($linkSrc)) {
|
||||||
|
$linkSrc = utf8_encode($linkSrc);
|
||||||
|
}
|
||||||
|
if (!is_null($linkName)) {
|
||||||
|
if (!String::IsUTF8($linkName)) {
|
||||||
|
$linkName = utf8_encode($linkName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = new Link($linkSrc, $linkName, $style);
|
||||||
|
$rID = Media::addSectionLinkElement($linkSrc);
|
||||||
|
$link->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $link;
|
||||||
|
return $link;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Unsupported Link header / footer reference');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add TextBreak
|
||||||
|
*
|
||||||
|
* @param int $count
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a ListItem Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param int $depth
|
||||||
|
* @param mixed $styleText
|
||||||
|
* @param mixed $styleList
|
||||||
|
* @return PhpOffice\PhpWord\Section\ListItem
|
||||||
|
*/
|
||||||
|
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$listItem = new ListItem($text, $depth, $styleText, $styleList);
|
||||||
|
$this->_elementCollection[] = $listItem;
|
||||||
|
return $listItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Image Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Image
|
||||||
|
*/
|
||||||
|
public function addImage($src, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
if ($this->_insideOf == 'section') {
|
||||||
|
$rID = Media::addSectionMediaElement($src, 'image');
|
||||||
|
} elseif ($this->_insideOf == 'header') {
|
||||||
|
$rID = Media::addHeaderMediaElement($this->_pCount, $src);
|
||||||
|
} elseif ($this->_insideOf == 'footer') {
|
||||||
|
$rID = Media::addFooterMediaElement($this->_pCount, $src);
|
||||||
|
}
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Source does not exist or unsupported image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a by PHP created Image Element
|
||||||
|
*
|
||||||
|
* @param string $link
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\MemoryImage
|
||||||
|
*/
|
||||||
|
public function addMemoryImage($link, $style = null)
|
||||||
|
{
|
||||||
|
$memoryImage = new MemoryImage($link, $style);
|
||||||
|
if (!is_null($memoryImage->getSource())) {
|
||||||
|
if ($this->_insideOf == 'section') {
|
||||||
|
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
|
||||||
|
} elseif ($this->_insideOf == 'header') {
|
||||||
|
$rID = Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage);
|
||||||
|
} elseif ($this->_insideOf == 'footer') {
|
||||||
|
$rID = Media::addFooterMediaElement($this->_pCount, $link, $memoryImage);
|
||||||
|
}
|
||||||
|
$memoryImage->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $memoryImage;
|
||||||
|
return $memoryImage;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Unsupported image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a OLE-Object Element
|
||||||
|
*
|
||||||
|
* @param string $src
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Object
|
||||||
|
*/
|
||||||
|
public function addObject($src, $style = null)
|
||||||
|
{
|
||||||
|
$object = new Object($src, $style);
|
||||||
|
|
||||||
|
if (!is_null($object->getSource())) {
|
||||||
|
$inf = pathinfo($src);
|
||||||
|
$ext = $inf['extension'];
|
||||||
|
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
|
||||||
|
$ext = substr($ext, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/';
|
||||||
|
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
|
||||||
|
$iconSrc = $iconSrc . '_default.png';
|
||||||
|
} else {
|
||||||
|
$iconSrc .= '_' . $ext . '.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
|
||||||
|
$data = Media::addSectionMediaElement($src, 'oleObject');
|
||||||
|
$rID = $data[0];
|
||||||
|
$objectId = $data[1];
|
||||||
|
|
||||||
|
$object->setRelationId($rID);
|
||||||
|
$object->setObjectId($objectId);
|
||||||
|
$object->setImageRelationId($rIDimg);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $object;
|
||||||
|
return $object;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Source does not exist or unsupported object type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PreserveText Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @param mixed $styleParagraph
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
|
||||||
|
*/
|
||||||
|
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
|
||||||
|
$this->_elementCollection[] = $ptext;
|
||||||
|
return $ptext;
|
||||||
|
} else {
|
||||||
|
throw new Exception('addPreserveText only supported in footer/header.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextRun
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Section\TextRun
|
||||||
|
*/
|
||||||
|
public function createTextRun($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$textRun = new TextRun($styleParagraph);
|
||||||
|
$this->_elementCollection[] = $textRun;
|
||||||
|
return $textRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Elements
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Cell Style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Cell
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Cell width
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getWidth()
|
||||||
|
{
|
||||||
|
return $this->_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2013 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section\Table;
|
||||||
|
|
||||||
|
class Row
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Row height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_height = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Row
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row cells
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_cells = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table holder
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_insideOf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section/Header/Footer count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_pCount;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new table row
|
||||||
|
*
|
||||||
|
* @param string $insideOf
|
||||||
|
* @param int $pCount
|
||||||
|
* @param int $height
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($insideOf, $pCount, $height = null, $style = null)
|
||||||
|
{
|
||||||
|
$this->_insideOf = $insideOf;
|
||||||
|
$this->_pCount = $pCount;
|
||||||
|
$this->_height = $height;
|
||||||
|
$this->_style = new PhpOffice\PhpWord\Style\Row();
|
||||||
|
|
||||||
|
if (!is_null($style)) {
|
||||||
|
if (is_array($style)) {
|
||||||
|
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a cell
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PhpOffice\PhpWord\Section\Table\Cell
|
||||||
|
*/
|
||||||
|
public function addCell($width = null, $style = null)
|
||||||
|
{
|
||||||
|
$cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
|
||||||
|
$this->_cells[] = $cell;
|
||||||
|
return $cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cells
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCells()
|
||||||
|
{
|
||||||
|
return $this->_cells;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get row style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Row
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get row height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHeight()
|
||||||
|
{
|
||||||
|
return $this->_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class Text
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Text content
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
private $fontStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Text Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
$this->setText($text);
|
||||||
|
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
|
||||||
|
$this->setFontStyle($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Text style
|
||||||
|
*
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Font $style
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
if ($style instanceof Font) {
|
||||||
|
$this->fontStyle = $style;
|
||||||
|
$this->setParagraphStyle($paragraphStyle);
|
||||||
|
} elseif (is_array($style)) {
|
||||||
|
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||||
|
$this->fontStyle->setArrayStyle($style);
|
||||||
|
} elseif (null === $style) {
|
||||||
|
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||||
|
} else {
|
||||||
|
$this->fontStyle = $style;
|
||||||
|
$this->setParagraphStyle($paragraphStyle);
|
||||||
|
}
|
||||||
|
return $this->fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function getFontStyle()
|
||||||
|
{
|
||||||
|
return $this->fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Paragraph style
|
||||||
|
*
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $style
|
||||||
|
* @return null|PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setParagraphStyle($style = null)
|
||||||
|
{
|
||||||
|
if (is_array($style)) {
|
||||||
|
$this->paragraphStyle = new Paragraph;
|
||||||
|
$this->paragraphStyle->setArrayStyle($style);
|
||||||
|
} elseif ($style instanceof Paragraph) {
|
||||||
|
$this->paragraphStyle = $style;
|
||||||
|
} elseif (null === $style) {
|
||||||
|
$this->paragraphStyle = new Paragraph;
|
||||||
|
} else {
|
||||||
|
$this->paragraphStyle = $style;
|
||||||
|
}
|
||||||
|
return $this->paragraphStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->paragraphStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $text
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setText($text)
|
||||||
|
{
|
||||||
|
$this->text = $text;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getText()
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class TextBreak
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Pagaraph
|
||||||
|
*/
|
||||||
|
private $paragraphStyle = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
private $fontStyle = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextBreak Element
|
||||||
|
*/
|
||||||
|
public function __construct($fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
if (!is_null($paragraphStyle)) {
|
||||||
|
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
|
||||||
|
}
|
||||||
|
if (!is_null($fontStyle)) {
|
||||||
|
$this->setFontStyle($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Text style
|
||||||
|
*
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Font $style
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
if ($style instanceof Font) {
|
||||||
|
$this->fontStyle = $style;
|
||||||
|
$this->setParagraphStyle($paragraphStyle);
|
||||||
|
} elseif (is_array($style)) {
|
||||||
|
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||||
|
$this->fontStyle->setArrayStyle($style);
|
||||||
|
} else {
|
||||||
|
$this->fontStyle = $style;
|
||||||
|
$this->setParagraphStyle($paragraphStyle);
|
||||||
|
}
|
||||||
|
return $this->fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Text style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function getFontStyle()
|
||||||
|
{
|
||||||
|
return $this->fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Paragraph style
|
||||||
|
*
|
||||||
|
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $style
|
||||||
|
* @return null|PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setParagraphStyle($style = null)
|
||||||
|
{
|
||||||
|
if (is_array($style)) {
|
||||||
|
$this->paragraphStyle = new Paragraph;
|
||||||
|
$this->paragraphStyle->setArrayStyle($style);
|
||||||
|
} elseif ($style instanceof Paragraph) {
|
||||||
|
$this->paragraphStyle = $style;
|
||||||
|
} else {
|
||||||
|
$this->paragraphStyle = $style;
|
||||||
|
}
|
||||||
|
return $this->paragraphStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->paragraphStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,184 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
class TextRun
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Paragraph style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $_styleParagraph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_elementCollection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextRun Element
|
||||||
|
*/
|
||||||
|
public function __construct($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$this->_elementCollection = array();
|
||||||
|
|
||||||
|
// Set paragraph style
|
||||||
|
if (is_array($styleParagraph)) {
|
||||||
|
$this->_styleParagraph = new Paragraph();
|
||||||
|
|
||||||
|
foreach ($styleParagraph as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_styleParagraph->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->_styleParagraph = $styleParagraph;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Text Element
|
||||||
|
*
|
||||||
|
* @var string $text
|
||||||
|
* @var mixed $styleFont
|
||||||
|
* @return PhpOffice\PhpWord\Section\Text
|
||||||
|
*/
|
||||||
|
public function addText($text = null, $styleFont = null)
|
||||||
|
{
|
||||||
|
if (!String::IsUTF8($text)) {
|
||||||
|
$text = utf8_encode($text);
|
||||||
|
}
|
||||||
|
$text = new Text($text, $styleFont);
|
||||||
|
$this->_elementCollection[] = $text;
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Link Element
|
||||||
|
*
|
||||||
|
* @param string $linkSrc
|
||||||
|
* @param string $linkName
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @return PhpOffice\PhpWord\Section\Link
|
||||||
|
*/
|
||||||
|
public function addLink($linkSrc, $linkName = null, $styleFont = null)
|
||||||
|
{
|
||||||
|
$linkSrc = utf8_encode($linkSrc);
|
||||||
|
if (!is_null($linkName)) {
|
||||||
|
$linkName = utf8_encode($linkName);
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = new Link($linkSrc, $linkName, $styleFont);
|
||||||
|
$rID = Media::addSectionLinkElement($linkSrc);
|
||||||
|
$link->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $link;
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Image Element
|
||||||
|
*
|
||||||
|
* @param string $imageSrc
|
||||||
|
* @param mixed $styleFont
|
||||||
|
* @return PhpOffice\PhpWord\Section\Image
|
||||||
|
*/
|
||||||
|
public function addImage($imageSrc, $style = null)
|
||||||
|
{
|
||||||
|
$image = new Image($imageSrc, $style);
|
||||||
|
|
||||||
|
if (!is_null($image->getSource())) {
|
||||||
|
$rID = Media::addSectionMediaElement($imageSrc, 'image');
|
||||||
|
$image->setRelationId($rID);
|
||||||
|
|
||||||
|
$this->_elementCollection[] = $image;
|
||||||
|
return $image;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Source does not exist or unsupported image type.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add TextBreak
|
||||||
|
*
|
||||||
|
* @param int $count
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
|
||||||
|
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||||
|
*/
|
||||||
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Footnote Element
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @return PhpOffice\PhpWord\Section\Footnote
|
||||||
|
*/
|
||||||
|
public function createFootnote($styleParagraph = null)
|
||||||
|
{
|
||||||
|
$footnote = new PhpOffice\PhpWord\Section\Footnote($styleParagraph);
|
||||||
|
$refID = PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
|
||||||
|
$footnote->setReferenceId($refID);
|
||||||
|
$this->_elementCollection[] = $footnote;
|
||||||
|
return $footnote;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get TextRun content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->_elementCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->_styleParagraph;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Section;
|
||||||
|
|
||||||
|
class Title
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Title Text content
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title depth
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_depth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title anchor
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_anchor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title Bookmark ID
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_bookmarkId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title style
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Title Element
|
||||||
|
*
|
||||||
|
* @var string $text
|
||||||
|
* @var int $depth
|
||||||
|
*/
|
||||||
|
public function __construct($text, $depth = 1, $style = null)
|
||||||
|
{
|
||||||
|
if (!is_null($style)) {
|
||||||
|
$this->_style = $style;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_text = $text;
|
||||||
|
$this->_depth = $depth;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Anchor
|
||||||
|
*
|
||||||
|
* @var int $anchor
|
||||||
|
*/
|
||||||
|
public function setAnchor($anchor)
|
||||||
|
{
|
||||||
|
$this->_anchor = $anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Anchor
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAnchor()
|
||||||
|
{
|
||||||
|
return $this->_anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Bookmark ID
|
||||||
|
*
|
||||||
|
* @var int $bookmarkId
|
||||||
|
*/
|
||||||
|
public function setBookmarkId($bookmarkId)
|
||||||
|
{
|
||||||
|
$this->_bookmarkId = $bookmarkId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Anchor
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBookmarkId()
|
||||||
|
{
|
||||||
|
return $this->_bookmarkId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Title Text content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getText()
|
||||||
|
{
|
||||||
|
return $this->_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Title style
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Compatibility option for XMLWriter
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private static $_xmlWriterCompatibility = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the compatibility option used by the XMLWriter
|
||||||
|
*
|
||||||
|
* @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility
|
||||||
|
* @return boolean Success or failure
|
||||||
|
*/
|
||||||
|
public static function setCompatibility($compatibility)
|
||||||
|
{
|
||||||
|
if (is_bool($compatibility)) {
|
||||||
|
self::$_xmlWriterCompatibility = $compatibility;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the compatibility option used by the XMLWriter
|
||||||
|
*
|
||||||
|
* @return boolean Compatibility
|
||||||
|
*/
|
||||||
|
public static function getCompatibility()
|
||||||
|
{
|
||||||
|
return self::$_xmlWriterCompatibility;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,162 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
class Drawing
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Convert pixels to EMU
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in pixels
|
||||||
|
* @return int Value in EMU
|
||||||
|
*/
|
||||||
|
public static function pixelsToEMU($pValue = 0)
|
||||||
|
{
|
||||||
|
return round($pValue * 9525);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert EMU to pixels
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in EMU
|
||||||
|
* @return int Value in pixels
|
||||||
|
*/
|
||||||
|
public static function EMUToPixels($pValue = 0)
|
||||||
|
{
|
||||||
|
if ($pValue != 0) {
|
||||||
|
return round($pValue / 9525);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert pixels to points
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in pixels
|
||||||
|
* @return int Value in points
|
||||||
|
*/
|
||||||
|
public static function pixelsToPoints($pValue = 0)
|
||||||
|
{
|
||||||
|
return $pValue * 0.67777777;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert points width to pixels
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in points
|
||||||
|
* @return int Value in pixels
|
||||||
|
*/
|
||||||
|
public static function pointsToPixels($pValue = 0)
|
||||||
|
{
|
||||||
|
if ($pValue != 0) {
|
||||||
|
return $pValue * 1.333333333;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert degrees to angle
|
||||||
|
*
|
||||||
|
* @param int $pValue Degrees
|
||||||
|
* @return int Angle
|
||||||
|
*/
|
||||||
|
public static function degreesToAngle($pValue = 0)
|
||||||
|
{
|
||||||
|
return (int)round($pValue * 60000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert angle to degrees
|
||||||
|
*
|
||||||
|
* @param int $pValue Angle
|
||||||
|
* @return int Degrees
|
||||||
|
*/
|
||||||
|
public static function angleToDegrees($pValue = 0)
|
||||||
|
{
|
||||||
|
if ($pValue != 0) {
|
||||||
|
return round($pValue / 60000);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert pixels to centimeters
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in pixels
|
||||||
|
* @return int Value in centimeters
|
||||||
|
*/
|
||||||
|
public static function pixelsToCentimeters($pValue = 0)
|
||||||
|
{
|
||||||
|
return $pValue * 0.028;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert centimeters width to pixels
|
||||||
|
*
|
||||||
|
* @param int $pValue Value in centimeters
|
||||||
|
* @return int Value in pixels
|
||||||
|
*/
|
||||||
|
public static function centimetersToPixels($pValue = 0)
|
||||||
|
{
|
||||||
|
if ($pValue != 0) {
|
||||||
|
return $pValue / 0.028;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert HTML hexadecimal to RGB
|
||||||
|
*
|
||||||
|
* @param str $pValue HTML Color in hexadecimal
|
||||||
|
* @return array Value in RGB
|
||||||
|
*/
|
||||||
|
public static function htmlToRGB($pValue)
|
||||||
|
{
|
||||||
|
if ($pValue[0] == '#') {
|
||||||
|
$pValue = substr($pValue, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($pValue) == 6) {
|
||||||
|
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
|
||||||
|
} elseif (strlen($pValue) == 3) {
|
||||||
|
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$color_R = hexdec($color_R);
|
||||||
|
$color_G = hexdec($color_G);
|
||||||
|
$color_B = hexdec($color_B);
|
||||||
|
|
||||||
|
return array($color_R, $color_G, $color_B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
class File
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Verify if a file exists
|
||||||
|
*
|
||||||
|
* @param string $pFilename Filename
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function file_exists($pFilename)
|
||||||
|
{
|
||||||
|
// Regular file_exists
|
||||||
|
return file_exists($pFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns canonicalized absolute pathname, also for ZIP archives
|
||||||
|
*
|
||||||
|
* @param string $pFilename
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function realpath($pFilename)
|
||||||
|
{
|
||||||
|
// Returnvalue
|
||||||
|
$returnValue = '';
|
||||||
|
|
||||||
|
// Try using realpath()
|
||||||
|
$returnValue = realpath($pFilename);
|
||||||
|
|
||||||
|
// Found something?
|
||||||
|
if ($returnValue == '' || is_null($returnValue)) {
|
||||||
|
$pathArray = explode('/', $pFilename);
|
||||||
|
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
|
||||||
|
for ($i = 0; $i < count($pathArray); ++$i) {
|
||||||
|
if ($pathArray[$i] == '..' && $i > 0) {
|
||||||
|
unset($pathArray[$i]);
|
||||||
|
unset($pathArray[$i - 1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$returnValue = implode('/', $pathArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return $returnValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
class Font
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Calculate an (approximate) pixel size, based on a font points size
|
||||||
|
*
|
||||||
|
* @param int $fontSizeInPoints Font size (in points)
|
||||||
|
* @return int Font size (in pixels)
|
||||||
|
*/
|
||||||
|
public static function fontSizeToPixels($fontSizeInPoints = 12)
|
||||||
|
{
|
||||||
|
return ((16 / 12) * $fontSizeInPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate an (approximate) pixel size, based on inch size
|
||||||
|
*
|
||||||
|
* @param int $sizeInInch Font size (in inch)
|
||||||
|
* @return int Size (in pixels)
|
||||||
|
*/
|
||||||
|
public static function inchSizeToPixels($sizeInInch = 1)
|
||||||
|
{
|
||||||
|
return ($sizeInInch * 96);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate an (approximate) pixel size, based on centimeter size
|
||||||
|
*
|
||||||
|
* @param int $sizeInCm Font size (in centimeters)
|
||||||
|
* @return int Size (in pixels)
|
||||||
|
*/
|
||||||
|
public static function centimeterSizeToPixels($sizeInCm = 1)
|
||||||
|
{
|
||||||
|
return ($sizeInCm * 37.795275591);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function centimeterSizeToTwips($sizeInCm = 1)
|
||||||
|
{
|
||||||
|
return ($sizeInCm * 565.217);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function inchSizeToTwips($sizeInInch = 1)
|
||||||
|
{
|
||||||
|
return self::centimeterSizeToTwips($sizeInInch * 2.54);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function pixelSizeToTwips($sizeInPixel = 1)
|
||||||
|
{
|
||||||
|
return self::centimeterSizeToTwips($sizeInPixel / 37.795275591);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate twip based on point size, used mainly for paragraph spacing
|
||||||
|
*
|
||||||
|
* @param int|float $sizeInPoint Size in point
|
||||||
|
* @return int|float Size (in twips)
|
||||||
|
*/
|
||||||
|
public static function pointSizeToTwips($sizeInPoint = 1)
|
||||||
|
{
|
||||||
|
return ($sizeInPoint * 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
class String
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Control characters array
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
private static $_controlCharacters = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build control characters array
|
||||||
|
*/
|
||||||
|
private static function _buildControlCharacters()
|
||||||
|
{
|
||||||
|
for ($i = 0; $i <= 19; ++$i) {
|
||||||
|
if ($i != 9 && $i != 10 && $i != 13) {
|
||||||
|
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
|
||||||
|
$replace = chr($i);
|
||||||
|
self::$_controlCharacters[$find] = $replace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert from OpenXML escaped control character to PHP control character
|
||||||
|
*
|
||||||
|
* Excel 2007 team:
|
||||||
|
* ----------------
|
||||||
|
* That's correct, control characters are stored directly in the shared-strings table.
|
||||||
|
* We do encode characters that cannot be represented in XML using the following escape sequence:
|
||||||
|
* _xHHHH_ where H represents a hexadecimal character in the character's value...
|
||||||
|
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
|
||||||
|
* element or in the shared string <t> element.
|
||||||
|
*
|
||||||
|
* @param string $value Value to unescape
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function ControlCharacterOOXML2PHP($value = '')
|
||||||
|
{
|
||||||
|
if (empty(self::$_controlCharacters)) {
|
||||||
|
self::_buildControlCharacters();
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert from PHP control character to OpenXML escaped control character
|
||||||
|
*
|
||||||
|
* Excel 2007 team:
|
||||||
|
* ----------------
|
||||||
|
* That's correct, control characters are stored directly in the shared-strings table.
|
||||||
|
* We do encode characters that cannot be represented in XML using the following escape sequence:
|
||||||
|
* _xHHHH_ where H represents a hexadecimal character in the character's value...
|
||||||
|
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
|
||||||
|
* element or in the shared string <t> element.
|
||||||
|
*
|
||||||
|
* @param string $value Value to escape
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function ControlCharacterPHP2OOXML($value = '')
|
||||||
|
{
|
||||||
|
if (empty(self::$_controlCharacters)) {
|
||||||
|
self::_buildControlCharacters();
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a string contains UTF-8 data
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function IsUTF8($value = '')
|
||||||
|
{
|
||||||
|
return $value === '' || preg_match('/^./su', $value) === 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
|
if (!defined('DATE_W3C')) {
|
||||||
|
define('DATE_W3C', 'Y-m-d\TH:i:sP');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method bool startElement(string $name)
|
||||||
|
* @method bool writeAttribute(string $name, string $value)
|
||||||
|
* @method bool endElement()
|
||||||
|
*/
|
||||||
|
class XMLWriter
|
||||||
|
{
|
||||||
|
/** Temporary storage method */
|
||||||
|
const STORAGE_MEMORY = 1;
|
||||||
|
const STORAGE_DISK = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal XMLWriter
|
||||||
|
*
|
||||||
|
* @var XMLWriter
|
||||||
|
*/
|
||||||
|
private $_xmlWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Temporary filename
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_tempFileName = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new XMLWriter instance
|
||||||
|
*
|
||||||
|
* @param int $pTemporaryStorage Temporary storage location
|
||||||
|
* @param string $pTemporaryStorageFolder Temporary storage folder
|
||||||
|
*/
|
||||||
|
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
|
||||||
|
{
|
||||||
|
// Create internal XMLWriter
|
||||||
|
$this->_xmlWriter = new XMLWriter();
|
||||||
|
|
||||||
|
// Open temporary storage
|
||||||
|
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
|
||||||
|
$this->_xmlWriter->openMemory();
|
||||||
|
} else {
|
||||||
|
// Create temporary filename
|
||||||
|
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
|
||||||
|
|
||||||
|
// Open storage
|
||||||
|
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
|
||||||
|
// Fallback to memory...
|
||||||
|
$this->_xmlWriter->openMemory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set xml Compatibility
|
||||||
|
$compatibility = Settings::getCompatibility();
|
||||||
|
if ($compatibility) {
|
||||||
|
$this->_xmlWriter->setIndent(false);
|
||||||
|
$this->_xmlWriter->setIndentString('');
|
||||||
|
} else {
|
||||||
|
$this->_xmlWriter->setIndent(true);
|
||||||
|
$this->_xmlWriter->setIndentString(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
// Desctruct XMLWriter
|
||||||
|
unset($this->_xmlWriter);
|
||||||
|
|
||||||
|
// Unlink temporary files
|
||||||
|
if ($this->_tempFileName != '') {
|
||||||
|
@unlink($this->_tempFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get written data
|
||||||
|
*
|
||||||
|
* @return $data
|
||||||
|
*/
|
||||||
|
public function getData()
|
||||||
|
{
|
||||||
|
if ($this->_tempFileName == '') {
|
||||||
|
return $this->_xmlWriter->outputMemory(true);
|
||||||
|
} else {
|
||||||
|
$this->_xmlWriter->flush();
|
||||||
|
return file_get_contents($this->_tempFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catch function calls (and pass them to internal XMLWriter)
|
||||||
|
*
|
||||||
|
* @param unknown_type $function
|
||||||
|
* @param unknown_type $args
|
||||||
|
*/
|
||||||
|
public function __call($function, $args)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
@call_user_func_array(array($this->_xmlWriter, $function), $args);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// Do nothing!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback method for writeRaw, introduced in PHP 5.2
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function writeRaw($text)
|
||||||
|
{
|
||||||
|
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
|
||||||
|
return $this->_xmlWriter->writeRaw($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->text($text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Shared;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore Legacy from PHPExcel
|
||||||
|
*/
|
||||||
|
class ZipStreamWrapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Internal ZipAcrhive
|
||||||
|
*
|
||||||
|
* @var ZipAcrhive
|
||||||
|
*/
|
||||||
|
private $_archive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename in ZipAcrhive
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_fileNameInArchive = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Position in file
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_position = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data
|
||||||
|
*
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
private $_data = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register wrapper
|
||||||
|
*/
|
||||||
|
public static function register()
|
||||||
|
{
|
||||||
|
@stream_wrapper_unregister("zip");
|
||||||
|
@stream_wrapper_register("zip", __CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open stream
|
||||||
|
*/
|
||||||
|
public function stream_open($path, $mode, $options, &$opened_path)
|
||||||
|
{
|
||||||
|
// Check for mode
|
||||||
|
if ($mode{0} != 'r') {
|
||||||
|
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse URL
|
||||||
|
$url = @parse_url($path);
|
||||||
|
|
||||||
|
// Fix URL
|
||||||
|
if (!is_array($url)) {
|
||||||
|
$url['host'] = substr($path, strlen('zip://'));
|
||||||
|
$url['path'] = '';
|
||||||
|
}
|
||||||
|
if (strpos($url['host'], '#') !== false) {
|
||||||
|
if (!isset($url['fragment'])) {
|
||||||
|
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
|
||||||
|
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
|
||||||
|
unset($url['path']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$url['host'] = $url['host'] . $url['path'];
|
||||||
|
unset($url['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open archive
|
||||||
|
$this->_archive = new ZipArchive();
|
||||||
|
$this->_archive->open($url['host']);
|
||||||
|
|
||||||
|
$this->_fileNameInArchive = $url['fragment'];
|
||||||
|
$this->_position = 0;
|
||||||
|
$this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stat stream
|
||||||
|
*/
|
||||||
|
public function stream_stat()
|
||||||
|
{
|
||||||
|
return $this->_archive->statName($this->_fileNameInArchive);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read stream
|
||||||
|
*/
|
||||||
|
public function stream_read($count)
|
||||||
|
{
|
||||||
|
$ret = substr($this->_data, $this->_position, $count);
|
||||||
|
$this->_position += strlen($ret);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell stream
|
||||||
|
*/
|
||||||
|
public function stream_tell()
|
||||||
|
{
|
||||||
|
return $this->_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EOF stream
|
||||||
|
*/
|
||||||
|
public function stream_eof()
|
||||||
|
{
|
||||||
|
return $this->_position >= strlen($this->_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seek stream
|
||||||
|
*/
|
||||||
|
public function stream_seek($offset, $whence)
|
||||||
|
{
|
||||||
|
switch ($whence) {
|
||||||
|
case SEEK_SET:
|
||||||
|
if ($offset < strlen($this->_data) && $offset >= 0) {
|
||||||
|
$this->_position = $offset;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SEEK_CUR:
|
||||||
|
if ($offset >= 0) {
|
||||||
|
$this->_position += $offset;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SEEK_END:
|
||||||
|
if (strlen($this->_data) + $offset >= 0) {
|
||||||
|
$this->_position = strlen($this->_data) + $offset;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
use PhpOffice\PhpWord\Style\TableFull;
|
||||||
|
|
||||||
|
class Style
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $_styleElements = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $styleName
|
||||||
|
* @param array $styles
|
||||||
|
*/
|
||||||
|
public static function addParagraphStyle($styleName, $styles)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
$style = new Paragraph();
|
||||||
|
foreach ($styles as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$_styleElements[$styleName] = $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $styleName
|
||||||
|
* @param array $styleFont
|
||||||
|
* @param array $styleParagraph
|
||||||
|
*/
|
||||||
|
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
$font = new Font('text', $styleParagraph);
|
||||||
|
foreach ($styleFont as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$font->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
self::$_styleElements[$styleName] = $font;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $styleName
|
||||||
|
* @param array $styles
|
||||||
|
*/
|
||||||
|
public static function addLinkStyle($styleName, $styles)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
$style = new Font('link');
|
||||||
|
foreach ($styles as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$_styleElements[$styleName] = $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $styleName
|
||||||
|
* @param array $styles
|
||||||
|
*/
|
||||||
|
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
$style = new TableFull($styleTable, $styleFirstRow);
|
||||||
|
|
||||||
|
self::$_styleElements[$styleName] = $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $styleName
|
||||||
|
* @param array $styleFont
|
||||||
|
* @param array $styleParagraph
|
||||||
|
*/
|
||||||
|
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
|
||||||
|
{
|
||||||
|
$styleName = 'Heading_' . $titleCount;
|
||||||
|
if (!array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
$font = new Font('title', $styleParagraph);
|
||||||
|
foreach ($styleFont as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$font->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$_styleElements[$styleName] = $font;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $styles Paragraph style definition
|
||||||
|
*/
|
||||||
|
public static function setDefaultParagraphStyle($styles)
|
||||||
|
{
|
||||||
|
self::addParagraphStyle('Normal', $styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all styles
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font[]
|
||||||
|
*/
|
||||||
|
public static function getStyles()
|
||||||
|
{
|
||||||
|
return self::$_styleElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
|
public static function getStyle($styleName)
|
||||||
|
{
|
||||||
|
if (array_key_exists($styleName, self::$_styleElements)) {
|
||||||
|
return self::$_styleElements[$styleName];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,343 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
class Cell
|
||||||
|
{
|
||||||
|
const TEXT_DIR_BTLR = 'btLr';
|
||||||
|
const TEXT_DIR_TBRL = 'tbRl';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertical align (top, center, both, bottom)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_valign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text Direction
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_textDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background-Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_bgColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Top Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderTopSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Top Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_borderTopColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Left Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderLeftSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Left Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_borderLeftColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Right Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderRightSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Right Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_borderRightColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Bottom Size
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_borderBottomSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Bottom Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_borderBottomColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Border Default Color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_defaultBorderColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* colspan
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
private $_gridSpan = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rowspan (restart, continue)
|
||||||
|
*
|
||||||
|
* - restart: Start/restart merged region
|
||||||
|
* - continue: Continue merged region
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_vMerge = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Cell Style
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_valign = null;
|
||||||
|
$this->_textDirection = null;
|
||||||
|
$this->_bgColor = null;
|
||||||
|
$this->_borderTopSize = null;
|
||||||
|
$this->_borderTopColor = null;
|
||||||
|
$this->_borderLeftSize = null;
|
||||||
|
$this->_borderLeftColor = null;
|
||||||
|
$this->_borderRightSize = null;
|
||||||
|
$this->_borderRightColor = null;
|
||||||
|
$this->_borderBottomSize = null;
|
||||||
|
$this->_borderBottomColor = null;
|
||||||
|
$this->_defaultBorderColor = '000000';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* @var string $key
|
||||||
|
* @var mixed $value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
if ($key == '_borderSize') {
|
||||||
|
$this->setBorderSize($value);
|
||||||
|
} elseif ($key == '_borderColor') {
|
||||||
|
$this->setBorderColor($value);
|
||||||
|
} else {
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVAlign()
|
||||||
|
{
|
||||||
|
return $this->_valign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVAlign($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_valign = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTextDirection()
|
||||||
|
{
|
||||||
|
return $this->_textDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTextDirection($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_textDirection = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBgColor()
|
||||||
|
{
|
||||||
|
return $this->_bgColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBgColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_bgColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopSize = $pValue;
|
||||||
|
$this->_borderLeftSize = $pValue;
|
||||||
|
$this->_borderRightSize = $pValue;
|
||||||
|
$this->_borderBottomSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderSize()
|
||||||
|
{
|
||||||
|
$t = $this->getBorderTopSize();
|
||||||
|
$l = $this->getBorderLeftSize();
|
||||||
|
$r = $this->getBorderRightSize();
|
||||||
|
$b = $this->getBorderBottomSize();
|
||||||
|
|
||||||
|
return array($t, $l, $r, $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopColor = $pValue;
|
||||||
|
$this->_borderLeftColor = $pValue;
|
||||||
|
$this->_borderRightColor = $pValue;
|
||||||
|
$this->_borderBottomColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderColor()
|
||||||
|
{
|
||||||
|
$t = $this->getBorderTopColor();
|
||||||
|
$l = $this->getBorderLeftColor();
|
||||||
|
$r = $this->getBorderRightColor();
|
||||||
|
$b = $this->getBorderBottomColor();
|
||||||
|
|
||||||
|
return array($t, $l, $r, $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderTopSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderTopSize()
|
||||||
|
{
|
||||||
|
return $this->_borderTopSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderTopColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderTopColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderTopColor()
|
||||||
|
{
|
||||||
|
return $this->_borderTopColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderLeftSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderLeftSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderLeftSize()
|
||||||
|
{
|
||||||
|
return $this->_borderLeftSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderLeftColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderLeftColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderLeftColor()
|
||||||
|
{
|
||||||
|
return $this->_borderLeftColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderRightSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderRightSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderRightSize()
|
||||||
|
{
|
||||||
|
return $this->_borderRightSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderRightColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderRightColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderRightColor()
|
||||||
|
{
|
||||||
|
return $this->_borderRightColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setBorderBottomSize($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderBottomSize = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderBottomSize()
|
||||||
|
{
|
||||||
|
return $this->_borderBottomSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBorderBottomColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_borderBottomColor = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBorderBottomColor()
|
||||||
|
{
|
||||||
|
return $this->_borderBottomColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultBorderColor()
|
||||||
|
{
|
||||||
|
return $this->_defaultBorderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGridSpan($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_gridSpan = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGridSpan()
|
||||||
|
{
|
||||||
|
return $this->_gridSpan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVMerge($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_vMerge = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVMerge()
|
||||||
|
{
|
||||||
|
return $this->_vMerge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,544 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
|
||||||
|
|
||||||
|
class Font
|
||||||
|
{
|
||||||
|
const UNDERLINE_NONE = 'none';
|
||||||
|
const UNDERLINE_DASH = 'dash';
|
||||||
|
const UNDERLINE_DASHHEAVY = 'dashHeavy';
|
||||||
|
const UNDERLINE_DASHLONG = 'dashLong';
|
||||||
|
const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
|
||||||
|
const UNDERLINE_DOUBLE = 'dbl';
|
||||||
|
const UNDERLINE_DOTHASH = 'dotDash';
|
||||||
|
const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
|
||||||
|
const UNDERLINE_DOTDOTDASH = 'dotDotDash';
|
||||||
|
const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
|
||||||
|
const UNDERLINE_DOTTED = 'dotted';
|
||||||
|
const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
|
||||||
|
const UNDERLINE_HEAVY = 'heavy';
|
||||||
|
const UNDERLINE_SINGLE = 'single';
|
||||||
|
const UNDERLINE_WAVY = 'wavy';
|
||||||
|
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
|
||||||
|
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
|
||||||
|
const UNDERLINE_WORDS = 'words';
|
||||||
|
const FGCOLOR_YELLOW = 'yellow';
|
||||||
|
const FGCOLOR_LIGHTGREEN = 'green';
|
||||||
|
const FGCOLOR_CYAN = 'cyan';
|
||||||
|
const FGCOLOR_MAGENTA = 'magenta';
|
||||||
|
const FGCOLOR_BLUE = 'blue';
|
||||||
|
const FGCOLOR_RED = 'red';
|
||||||
|
const FGCOLOR_DARKBLUE = 'darkBlue';
|
||||||
|
const FGCOLOR_DARKCYAN = 'darkCyan';
|
||||||
|
const FGCOLOR_DARKGREEN = 'darkGreen';
|
||||||
|
const FGCOLOR_DARKMAGENTA = 'darkMagenta';
|
||||||
|
const FGCOLOR_DARKRED = 'darkRed';
|
||||||
|
const FGCOLOR_DARKYELLOW = 'darkYellow';
|
||||||
|
const FGCOLOR_DARKGRAY = 'darkGray';
|
||||||
|
const FGCOLOR_LIGHTGRAY = 'lightGray';
|
||||||
|
const FGCOLOR_BLACK = 'black';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font style type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paragraph Style
|
||||||
|
*
|
||||||
|
* @var PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
private $_paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font name
|
||||||
|
*
|
||||||
|
* @var int|float
|
||||||
|
*/
|
||||||
|
private $_name = PhpWord::DEFAULT_FONT_NAME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font size
|
||||||
|
*
|
||||||
|
* @var int|float
|
||||||
|
*/
|
||||||
|
private $_size = PhpWord::DEFAULT_FONT_SIZE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bold
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_bold = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Italics
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_italic = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Superscript
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_superScript = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscript
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_subScript = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Underline mode
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_underline = self::UNDERLINE_NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strikethrough
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_strikethrough = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font color
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_color = PhpWord::DEFAULT_FONT_COLOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Foreground/highlight
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_fgColor = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text line height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $lineHeight = 1.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font Content Type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New font style
|
||||||
|
*
|
||||||
|
* @param string $type Type of font
|
||||||
|
* @param array $paragraphStyle Paragraph styles definition
|
||||||
|
*/
|
||||||
|
public function __construct($type = 'text', $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
$this->_type = $type;
|
||||||
|
|
||||||
|
if ($paragraphStyle instanceof Paragraph) {
|
||||||
|
$this->_paragraphStyle = $paragraphStyle;
|
||||||
|
} elseif (is_array($paragraphStyle)) {
|
||||||
|
$this->_paragraphStyle = new Paragraph;
|
||||||
|
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
|
||||||
|
} else {
|
||||||
|
$this->_paragraphStyle = $paragraphStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $style
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setArrayStyle(array $style = array())
|
||||||
|
{
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if ($key === 'line-height') {
|
||||||
|
$this->setLineHeight($value);
|
||||||
|
null;
|
||||||
|
} elseif (substr($key, 0, 1) !== '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$method = 'set' . substr($key, 1);
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
$this->$method($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set font name
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setName($pValue = PhpWord::DEFAULT_FONT_NAME)
|
||||||
|
{
|
||||||
|
if (is_null($pValue) || $pValue == '') {
|
||||||
|
$pValue = PhpWord::DEFAULT_FONT_NAME;
|
||||||
|
}
|
||||||
|
$this->_name = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font size
|
||||||
|
*
|
||||||
|
* @return int|float
|
||||||
|
*/
|
||||||
|
public function getSize()
|
||||||
|
{
|
||||||
|
return $this->_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set font size
|
||||||
|
*
|
||||||
|
* @param int|float $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setSize($pValue = PhpWord::DEFAULT_FONT_SIZE)
|
||||||
|
{
|
||||||
|
if (!is_numeric($pValue)) {
|
||||||
|
$pValue = PhpWord::DEFAULT_FONT_SIZE;
|
||||||
|
}
|
||||||
|
$this->_size = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bold
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getBold()
|
||||||
|
{
|
||||||
|
return $this->_bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set bold
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setBold($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_bold = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get italics
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getItalic()
|
||||||
|
{
|
||||||
|
return $this->_italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set italics
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setItalic($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_italic = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get superscript
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getSuperScript()
|
||||||
|
{
|
||||||
|
return $this->_superScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set superscript
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setSuperScript($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_superScript = $pValue;
|
||||||
|
$this->_subScript = !$pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get superscript
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getSubScript()
|
||||||
|
{
|
||||||
|
return $this->_subScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set subscript
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setSubScript($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_subScript = $pValue;
|
||||||
|
$this->_superScript = !$pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get underline
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUnderline()
|
||||||
|
{
|
||||||
|
return $this->_underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set underline
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setUnderline($pValue = self::UNDERLINE_NONE)
|
||||||
|
{
|
||||||
|
if ($pValue == '') {
|
||||||
|
$pValue = self::UNDERLINE_NONE;
|
||||||
|
}
|
||||||
|
$this->_underline = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get strikethrough
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getStrikethrough()
|
||||||
|
{
|
||||||
|
return $this->_strikethrough;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set strikethrough
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setStrikethrough($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_strikethrough = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font color
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getColor()
|
||||||
|
{
|
||||||
|
return $this->_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set font color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setColor($pValue = PhpWord::DEFAULT_FONT_COLOR)
|
||||||
|
{
|
||||||
|
if (is_null($pValue) || $pValue == '') {
|
||||||
|
$pValue = PhpWord::DEFAULT_FONT_COLOR;
|
||||||
|
}
|
||||||
|
$this->_color = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get foreground/highlight color
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getFgColor()
|
||||||
|
{
|
||||||
|
return $this->_fgColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set foreground/highlight color
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setFgColor($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_fgColor = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get style type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStyleType()
|
||||||
|
{
|
||||||
|
return $this->_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get paragraph style
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function getParagraphStyle()
|
||||||
|
{
|
||||||
|
return $this->_paragraphStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the line height
|
||||||
|
*
|
||||||
|
* @param int|float|string $lineHeight
|
||||||
|
* @return $this
|
||||||
|
* @throws InvalidStyleException
|
||||||
|
*/
|
||||||
|
public function setLineHeight($lineHeight)
|
||||||
|
{
|
||||||
|
if (is_string($lineHeight)) {
|
||||||
|
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!is_integer($lineHeight) && !is_float($lineHeight)) || !$lineHeight) {
|
||||||
|
throw new InvalidStyleException('Line height must be a valid number');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->lineHeight = $lineHeight;
|
||||||
|
$this->getParagraphStyle()->setLineHeight($lineHeight);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int|float
|
||||||
|
*/
|
||||||
|
public function getLineHeight()
|
||||||
|
{
|
||||||
|
return $this->lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Font Content Type
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getHint()
|
||||||
|
{
|
||||||
|
return $this->_hint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Font Content Type
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Font
|
||||||
|
*/
|
||||||
|
public function setHint($pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE)
|
||||||
|
{
|
||||||
|
if (is_null($pValue) || $pValue == '') {
|
||||||
|
$pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
$this->_hint = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,175 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
class Image
|
||||||
|
{
|
||||||
|
const WRAPPING_STYLE_INLINE = 'inline';
|
||||||
|
const WRAPPING_STYLE_SQUARE = 'square';
|
||||||
|
const WRAPPING_STYLE_TIGHT = 'tight';
|
||||||
|
const WRAPPING_STYLE_BEHIND = 'behind';
|
||||||
|
const WRAPPING_STYLE_INFRONT = 'infront';
|
||||||
|
|
||||||
|
private $_width;
|
||||||
|
private $_height;
|
||||||
|
private $_align;
|
||||||
|
private $wrappingStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Margin Top
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginTop;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Margin Left
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_marginLeft;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_width = null;
|
||||||
|
$this->_height = null;
|
||||||
|
$this->_align = null;
|
||||||
|
$this->_marginTop = null;
|
||||||
|
$this->_marginLeft = null;
|
||||||
|
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth()
|
||||||
|
{
|
||||||
|
return $this->_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWidth($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_width = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeight()
|
||||||
|
{
|
||||||
|
return $this->_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHeight($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_height = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAlign()
|
||||||
|
{
|
||||||
|
return $this->_align;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAlign($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_align = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Top
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginTop()
|
||||||
|
{
|
||||||
|
return $this->_marginTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Top
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setMarginTop($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_marginTop = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Margin Left
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMarginLeft()
|
||||||
|
{
|
||||||
|
return $this->_marginLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Margin Left
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setMarginLeft($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_marginLeft = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $wrappingStyle
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setWrappingStyle($wrappingStyle)
|
||||||
|
{
|
||||||
|
switch ($wrappingStyle) {
|
||||||
|
case self::WRAPPING_STYLE_BEHIND:
|
||||||
|
case self::WRAPPING_STYLE_INFRONT:
|
||||||
|
case self::WRAPPING_STYLE_INLINE:
|
||||||
|
case self::WRAPPING_STYLE_SQUARE:
|
||||||
|
case self::WRAPPING_STYLE_TIGHT:
|
||||||
|
$this->wrappingStyle = $wrappingStyle;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidArgumentException('Wrapping style does not exists');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getWrappingStyle()
|
||||||
|
{
|
||||||
|
return $this->wrappingStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
class ListItem
|
||||||
|
{
|
||||||
|
const TYPE_NUMBER = 7;
|
||||||
|
const TYPE_NUMBER_NESTED = 8;
|
||||||
|
const TYPE_ALPHANUM = 9;
|
||||||
|
const TYPE_BULLET_FILLED = 3;
|
||||||
|
const TYPE_BULLET_EMPTY = 5;
|
||||||
|
const TYPE_SQUARE_FILLED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List Type
|
||||||
|
*/
|
||||||
|
private $_listType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ListItem Style
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_listType = self::TYPE_BULLET_FILLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set List Type
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setListType($pValue = self::TYPE_BULLET_FILLED)
|
||||||
|
{
|
||||||
|
$this->_listType = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get List Type
|
||||||
|
*/
|
||||||
|
public function getListType()
|
||||||
|
{
|
||||||
|
return $this->_listType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,508 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
|
||||||
|
|
||||||
|
class Paragraph
|
||||||
|
{
|
||||||
|
const LINE_HEIGHT = 240;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text line height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $lineHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paragraph alignment
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_align;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Space before Paragraph
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_spaceBefore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Space after Paragraph
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_spaceAfter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spacing between breaks
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_spacing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set of Custom Tab Stops
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_tabs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indent by how much
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_indent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hanging by how much
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_hanging;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent style
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_basedOn = 'Normal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Style for next paragraph
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow first/last line to display on a separate page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_widowControl = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep paragraph with next paragraph
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_keepNext = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep all lines on one page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_keepLines = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start paragraph on next page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_pageBreakBefore = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $style
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setArrayStyle(array $style = array())
|
||||||
|
{
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if ($key === 'line-height') {
|
||||||
|
null;
|
||||||
|
} elseif (substr($key, 0, 1) !== '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Style value
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
if ($key == '_indent' || $key == '_hanging') {
|
||||||
|
$value = $value * 720;
|
||||||
|
} elseif ($key == '_spacing') {
|
||||||
|
$value += 240; // because line height of 1 matches 240 twips
|
||||||
|
} elseif ($key === 'line-height') {
|
||||||
|
$this->setLineHeight($value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->$key = $value;
|
||||||
|
$method = 'set' . substr($key, 1);
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
$this->$method($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Paragraph Alignment
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAlign()
|
||||||
|
{
|
||||||
|
return $this->_align;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Paragraph Alignment
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setAlign($pValue = null)
|
||||||
|
{
|
||||||
|
if (strtolower($pValue) == 'justify') {
|
||||||
|
// justify becames both
|
||||||
|
$pValue = 'both';
|
||||||
|
}
|
||||||
|
$this->_align = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Space before Paragraph
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSpaceBefore()
|
||||||
|
{
|
||||||
|
return $this->_spaceBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Space before Paragraph
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setSpaceBefore($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_spaceBefore = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Space after Paragraph
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSpaceAfter()
|
||||||
|
{
|
||||||
|
return $this->_spaceAfter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Space after Paragraph
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setSpaceAfter($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_spaceAfter = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Spacing between breaks
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSpacing()
|
||||||
|
{
|
||||||
|
return $this->_spacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Spacing between breaks
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setSpacing($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_spacing = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get indentation
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getIndent()
|
||||||
|
{
|
||||||
|
return $this->_indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set indentation
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setIndent($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_indent = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get hanging
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHanging()
|
||||||
|
{
|
||||||
|
return $this->_hanging;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set hanging
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setHanging($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_hanging = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tabs
|
||||||
|
*
|
||||||
|
* @return PhpOffice\PhpWord\Style\Tabs
|
||||||
|
*/
|
||||||
|
public function getTabs()
|
||||||
|
{
|
||||||
|
return $this->_tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set tabs
|
||||||
|
*
|
||||||
|
* @param array $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setTabs($pValue = null)
|
||||||
|
{
|
||||||
|
if (is_array($pValue)) {
|
||||||
|
$this->_tabs = new Tabs($pValue);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parent style ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBasedOn()
|
||||||
|
{
|
||||||
|
return $this->_basedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set parent style ID
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setBasedOn($pValue = 'Normal')
|
||||||
|
{
|
||||||
|
$this->_basedOn = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get style for next paragraph
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNext()
|
||||||
|
{
|
||||||
|
return $this->_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style for next paragraph
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setNext($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_next = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get allow first/last line to display on a separate page setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getWidowControl()
|
||||||
|
{
|
||||||
|
return $this->_widowControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set keep paragraph with next paragraph setting
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setWidowControl($pValue = true)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = true;
|
||||||
|
}
|
||||||
|
$this->_widowControl = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get keep paragraph with next paragraph setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getKeepNext()
|
||||||
|
{
|
||||||
|
return $this->_keepNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set keep paragraph with next paragraph setting
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setKeepNext($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_keepNext = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get keep all lines on one page setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getKeepLines()
|
||||||
|
{
|
||||||
|
return $this->_keepLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set keep all lines on one page setting
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setKeepLines($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_keepLines = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get start paragraph on next page setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getPageBreakBefore()
|
||||||
|
{
|
||||||
|
return $this->_pageBreakBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set start paragraph on next page setting
|
||||||
|
*
|
||||||
|
* @param bool $pValue
|
||||||
|
* @return PhpOffice\PhpWord\Style\Paragraph
|
||||||
|
*/
|
||||||
|
public function setPageBreakBefore($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_pageBreakBefore = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the line height
|
||||||
|
*
|
||||||
|
* @param int|float|string $lineHeight
|
||||||
|
* @return $this
|
||||||
|
* @throws InvalidStyleException
|
||||||
|
*/
|
||||||
|
public function setLineHeight($lineHeight)
|
||||||
|
{
|
||||||
|
if (is_string($lineHeight)) {
|
||||||
|
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!is_integer($lineHeight) && !is_float($lineHeight)) || !$lineHeight) {
|
||||||
|
throw new InvalidStyleException('Line height must be a valid number');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->lineHeight = $lineHeight;
|
||||||
|
$this->setSpacing($lineHeight * self::LINE_HEIGHT);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int|float
|
||||||
|
*/
|
||||||
|
public function getLineHeight()
|
||||||
|
{
|
||||||
|
return $this->lineHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2013 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
class Row
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Repeat table row on every new page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_tblHeader = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table row cannot break across pages
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_cantSplit = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new row style
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTblHeader($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_tblHeader = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTblHeader()
|
||||||
|
{
|
||||||
|
return $this->_tblHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCantSplit($pValue = false)
|
||||||
|
{
|
||||||
|
if (!is_bool($pValue)) {
|
||||||
|
$pValue = false;
|
||||||
|
}
|
||||||
|
$this->_cantSplit = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCantSplit()
|
||||||
|
{
|
||||||
|
return $this->_cantSplit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PhpWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 PhpWord
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @category PhpWord
|
||||||
|
* @package PhpWord
|
||||||
|
* @copyright Copyright (c) 2014 PhpWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.8.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
class TOC
|
||||||
|
{
|
||||||
|
const TABLEADER_DOT = 'dot';
|
||||||
|
const TABLEADER_UNDERSCORE = 'underscore';
|
||||||
|
const TABLEADER_LINE = 'hyphen';
|
||||||
|
const TABLEADER_NONE = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tab Leader
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_tabLeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tab Position
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_tabPos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indent
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_indent;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TOC Style
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_tabPos = 9062;
|
||||||
|
$this->_tabLeader = self::TABLEADER_DOT;
|
||||||
|
$this->_indent = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Tab Position
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTabPos()
|
||||||
|
{
|
||||||
|
return $this->_tabPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Tab Position
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setTabPos($pValue)
|
||||||
|
{
|
||||||
|
$this->_tabPos = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Tab Leader
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTabLeader()
|
||||||
|
{
|
||||||
|
return $this->_tabLeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Tab Leader
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setTabLeader($pValue = self::TABLEADER_DOT)
|
||||||
|
{
|
||||||
|
$this->_tabLeader = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Indent
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getIndent()
|
||||||
|
{
|
||||||
|
return $this->_indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Indent
|
||||||
|
*
|
||||||
|
* @param string $pValue
|
||||||
|
*/
|
||||||
|
public function setIndent($pValue)
|
||||||
|
{
|
||||||
|
$this->_indent = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue