-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpWord\Style\Font; | ||
|
||
define('USE_AUTOLOADER', true); | ||
|
||
include_once 'Sample_Header.php'; | ||
|
||
// New Word Document | ||
echo date('H:i:s') , ' Create new PhpWord object' , EOL; | ||
|
||
$languageEnGb = new PhpOffice\PhpWord\Style\Language(PhpOffice\PhpWord\Style\Language::EN_GB); | ||
|
||
$phpWord = new PhpOffice\PhpWord\PhpWord(); | ||
$phpWord->getSettings()->setThemeFontLang($languageEnGb); | ||
|
||
$fontStyleName = 'rStyle'; | ||
$phpWord->addFontStyle($fontStyleName, ['bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true]); | ||
|
||
$paragraphStyleName = 'pStyle'; | ||
$phpWord->addParagraphStyle($paragraphStyleName, ['alignment' => PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100]); | ||
|
||
$phpWord->addTitleStyle(1, ['bold' => true], ['spaceAfter' => 240]); | ||
|
||
// New portrait section | ||
$section = $phpWord->addSection(); | ||
|
||
// Simple text | ||
$section->addTitle('Welcome to PhpWord', 1); | ||
$section->addText('Hello World!'); | ||
|
||
// $pStyle = new Font(); | ||
// $pStyle->setLang() | ||
$section->addText('Ce texte-ci est en français.', ['lang' => PhpOffice\PhpWord\Style\Language::FR_BE]); | ||
|
||
// Two text break | ||
$section->addTextBreak(2); | ||
|
||
// Define styles | ||
$section->addText('I am styled by a font style definition.', $fontStyleName); | ||
$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName); | ||
$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName); | ||
|
||
$section->addTextBreak(); | ||
|
||
// Inline font style | ||
$fontStyle['name'] = 'Times New Roman'; | ||
$fontStyle['size'] = 20; | ||
|
||
$textrun = $section->addTextRun(); | ||
$textrun->addText('I am inline styled ', $fontStyle); | ||
$textrun->addText('with '); | ||
$textrun->addText('color', ['color' => '996699']); | ||
$textrun->addText(', '); | ||
$textrun->addText('bold', ['bold' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('italic', ['italic' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('underline', ['underline' => 'dash']); | ||
$textrun->addText(', '); | ||
$textrun->addText('strikethrough', ['strikethrough' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('doubleStrikethrough', ['doubleStrikethrough' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('superScript', ['superScript' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('subScript', ['subScript' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('smallCaps', ['smallCaps' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('allCaps', ['allCaps' => true]); | ||
$textrun->addText(', '); | ||
$textrun->addText('fgColor', ['fgColor' => 'yellow']); | ||
$textrun->addText(', '); | ||
$textrun->addText('scale', ['scale' => 200]); | ||
$textrun->addText(', '); | ||
$textrun->addText('spacing', ['spacing' => 120]); | ||
$textrun->addText(', '); | ||
$textrun->addText('kerning', ['kerning' => 10]); | ||
$textrun->addText('. '); | ||
|
||
// Link | ||
$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); | ||
$section->addTextBreak(); | ||
|
||
// Image | ||
$section->addImage(__DIR__ . '/resources/_earth.jpg', ['width' => 18, 'height' => 18]); | ||
|
||
// Save file | ||
echo write($phpWord, basename(__FILE__, '.php'), $writers); | ||
if (!CLI) { | ||
include_once 'Sample_Footer.php'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPWord - A pure PHP library for reading and writing | ||
* word processing documents. | ||
* | ||
* PHPWord is free software distributed under the terms of the GNU Lesser | ||
* General Public License version 3 as published by the Free Software Foundation. | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. For the full list of | ||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. | ||
* | ||
* @see https://github.com/PHPOffice/PHPWord | ||
* | ||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpWord; | ||
|
||
class Autoloader | ||
{ | ||
/** @const string */ | ||
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\'; | ||
|
||
public static function register(): void | ||
{ | ||
spl_autoload_register([new self(), 'autoload']); | ||
} | ||
|
||
public static function autoload(string $class): void | ||
{ | ||
$prefixLength = strlen(self::NAMESPACE_PREFIX); | ||
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) { | ||
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength)); | ||
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php'); | ||
if (!$file) { | ||
return; | ||
} | ||
if (file_exists($file)) { | ||
/** @noinspection PhpIncludeInspection Dynamic includes */ | ||
require_once $file; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPWord - A pure PHP library for reading and writing | ||
* word processing documents. | ||
* | ||
* PHPWord is free software distributed under the terms of the GNU Lesser | ||
* General Public License version 3 as published by the Free Software Foundation. | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. For the full list of | ||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. | ||
* | ||
* @see https://github.com/PHPOffice/PHPWord | ||
* | ||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 | ||
*/ | ||
|
||
namespace PhpOffice\PhpWordTests; | ||
|
||
use PhpOffice\PhpWord\Autoloader; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test class for PhpOffice\PhpWord\Autoloader. | ||
*/ | ||
class AutoloaderTest extends TestCase | ||
{ | ||
public function testRegister(): void | ||
{ | ||
Autoloader::register(); | ||
$splFunctions = spl_autoload_functions(); | ||
if ($splFunctions === false) { | ||
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.4)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.3)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.2)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.0)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.1)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.2)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.3)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.4)
Check failure on line 33 in tests/PhpWordTests/AutoloaderTest.php GitHub Actions / PHP Static Analysis (8.1)
|
||
$splFunctions = []; | ||
} | ||
|
||
self::assertContains( | ||
['PhpOffice\\PhpWord\\Autoloader', 'autoload'], | ||
$splFunctions | ||
); | ||
} | ||
|
||
public function testAutoload(): void | ||
{ | ||
$declared = get_declared_classes(); | ||
$declaredCount = count($declared); | ||
Autoloader::autoload('Foo'); | ||
self::assertCount( | ||
$declaredCount, | ||
get_declared_classes(), | ||
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' . | ||
'classes outside of the PhpOffice\\PhpWord namespace' | ||
); | ||
} | ||
} |