commit
39cf5d0b4a
|
|
@ -4,9 +4,9 @@
|
|||
.Trashes
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
composer.lock
|
||||
composer.phar
|
||||
phpunit.xml
|
||||
phpword.ini
|
||||
/.buildpath
|
||||
/.idea
|
||||
/.project
|
||||
|
|
|
|||
|
|
@ -5,12 +5,20 @@ before_commands:
|
|||
- "composer install --prefer-source --dev"
|
||||
|
||||
tools:
|
||||
php_code_sniffer:
|
||||
enabled: true
|
||||
config:
|
||||
standard: PSR2
|
||||
php_mess_detector:
|
||||
enabled: true
|
||||
config:
|
||||
ruleset: phpmd.xml.dist
|
||||
external_code_coverage:
|
||||
enabled: true
|
||||
timeout: 900
|
||||
php_code_coverage:
|
||||
enabled: false
|
||||
test_command: phpunit -c phpunit.xml.dist
|
||||
php_sim: true
|
||||
php_cpd: true
|
||||
# php_sim: # Temporarily disabled to allow focus on things other than duplicates
|
||||
# min_mass: 40
|
||||
php_pdepend: true
|
||||
php_analyzer: true
|
||||
sensiolabs_security_checker: true
|
||||
|
|
|
|||
93
.travis.yml
93
.travis.yml
|
|
@ -1,55 +1,60 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.3.3
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
- 5.3.3
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 5.3.3
|
||||
- php: 5.6
|
||||
- php: hhvm
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
|
||||
env:
|
||||
global:
|
||||
- secure: "Sq+6bVtnPsu0mWX8DWQ+9bGAjxMcGorksUiHc4YIXEJsuDfVmVlH8tTD547IeCjDAx9MxXerZ2Z4HSjxTB70VEnJPvZMHI/EZn4Ny31YLHEthdZbV5Gd1h0TGp8VOzPKGShvGrtGBX6MvMfgpK4zuieVWbSfdKeecm8ZNLMpUd4="
|
||||
|
||||
before_script:
|
||||
## Composer
|
||||
# - curl -s http://getcomposer.org/installer | php
|
||||
# - php composer.phar install --prefer-source
|
||||
- composer self-update
|
||||
- composer require dompdf/dompdf:0.6.*
|
||||
- composer install --prefer-source
|
||||
## PHP_CodeSniffer
|
||||
- pyrus install pear/PHP_CodeSniffer
|
||||
- phpenv rehash
|
||||
## PHP Copy/Paste Detector
|
||||
#- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
|
||||
## PHP Mess Detector
|
||||
#- pear config-set preferred_state beta
|
||||
#- printf "\n" | pecl install imagick
|
||||
#- pear channel-discover pear.phpmd.org
|
||||
#- pear channel-discover pear.pdepend.org
|
||||
#- pear install --alldeps phpmd/PHP_PMD
|
||||
#- phpenv rehash
|
||||
## PHPLOC
|
||||
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
|
||||
## Packages
|
||||
- sudo apt-get -qq update > /dev/null
|
||||
- sudo apt-get -qq install graphviz > /dev/null
|
||||
## Composer
|
||||
- composer self-update
|
||||
- composer install --prefer-source --dev
|
||||
## PHP Copy/Paste Detector
|
||||
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
|
||||
## PHP Mess Detector
|
||||
- pear config-set preferred_state beta
|
||||
- printf "\n" | pecl install imagick
|
||||
- pear channel-discover pear.phpmd.org
|
||||
- pear channel-discover pear.pdepend.org
|
||||
- pear install --alldeps phpmd/PHP_PMD
|
||||
- phpenv rehash
|
||||
## PHPLOC
|
||||
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
|
||||
## PHPDocumentor
|
||||
- mkdir -p build/docs
|
||||
- mkdir -p build/coverage
|
||||
|
||||
script:
|
||||
## PHP_CodeSniffer
|
||||
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
|
||||
- phpcs --standard=PSR2 -n tests/
|
||||
## PHP Copy/Paste Detector
|
||||
#- php phpcpd.phar --verbose src/
|
||||
## PHP Mess Detector
|
||||
#- phpmd src/ text unusedcode,naming,design
|
||||
## PHPLOC
|
||||
#- php phploc.phar src/
|
||||
## PHPUnit
|
||||
- phpunit -c ./ --coverage-text
|
||||
## PHP_CodeSniffer
|
||||
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
|
||||
## PHP Copy/Paste Detector
|
||||
- php phpcpd.phar src/ tests/ --verbose
|
||||
## PHP Mess Detector
|
||||
- phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
|
||||
## PHPLOC
|
||||
#- php phploc.phar src/
|
||||
## PHPUnit
|
||||
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
|
||||
## PHPDocumentor
|
||||
- vendor/bin/phpdoc.php -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
|
||||
|
||||
after_script:
|
||||
## Scrutinizer
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
|
||||
## PHPDocumentor
|
||||
- bash .travis_shell_after_success.sh
|
||||
## Scrutinizer
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "--DEBUG--"
|
||||
echo "TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG"
|
||||
echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
|
||||
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
|
||||
|
||||
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
|
||||
|
||||
echo -e "Publishing PHPDoc...\n"
|
||||
|
||||
cp -R build/docs $HOME/docs-latest
|
||||
cp -R build/coverage $HOME/coverage-latest
|
||||
|
||||
cd $HOME
|
||||
git config --global user.email "travis@travis-ci.org"
|
||||
git config --global user.name "travis-ci"
|
||||
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/PHPWord gh-pages > /dev/null
|
||||
|
||||
cd gh-pages
|
||||
echo "--DEBUG : Suppression"
|
||||
git rm -rf ./docs/$TRAVIS_BRANCH
|
||||
|
||||
echo "--DEBUG : Dossier"
|
||||
mkdir -p docs/$TRAVIS_BRANCH
|
||||
mkdir -p coverage/$TRAVIS_BRANCH
|
||||
|
||||
echo "--DEBUG : Copie"
|
||||
cp -Rf $HOME/docs-latest/* ./docs/$TRAVIS_BRANCH/
|
||||
cp -Rf $HOME/coverage-latest/* ./coverage/$TRAVIS_BRANCH/
|
||||
|
||||
echo "--DEBUG : Git"
|
||||
git add -f .
|
||||
git commit -m "PHPDocumentor (Travis Build: $TRAVIS_BUILD_NUMBER - Branch: $TRAVIS_BRANCH)"
|
||||
git push -fq origin gh-pages > /dev/null
|
||||
|
||||
echo -e "Published PHPDoc to gh-pages.\n"
|
||||
|
||||
fi
|
||||
69
CHANGELOG.md
69
CHANGELOG.md
|
|
@ -2,6 +2,73 @@
|
|||
|
||||
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
|
||||
|
||||
## 0.11.0 - 1 June 2014
|
||||
|
||||
This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four new elements were added: TextBox, ListItemRun, Field, and Line. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemented. RTF and HTML reader were initiated.
|
||||
|
||||
### Features
|
||||
|
||||
- Image: Ability to define relative and absolute positioning - @basjan GH-217
|
||||
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
|
||||
- Element: New `TextBox` element - @basjan @ivanlanin GH-228 GH-229 GH-231
|
||||
- HTML: Ability to add elements to PHPWord object via html - @basjan GH-231
|
||||
- Element: New `ListItemRun` element that can add a list item with inline formatting like a textrun - @basjan GH-235
|
||||
- Table: Ability to add table inside a cell (nested table) - @ivanlanin GH-149
|
||||
- RTF Writer: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158
|
||||
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
|
||||
- RTF Writer: Ability to add links and page breaks in RTF - @ivanlanin GH-196
|
||||
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
|
||||
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
|
||||
- ODT Writer: Enable inline font style in TextRun - @ivanlanin
|
||||
- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
|
||||
- ODT Writer: Enable section and column - @ivanlanin
|
||||
- PDF Writer: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin
|
||||
- ODT Writer: Enable title element and custom document properties - @ivanlanin
|
||||
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
|
||||
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
|
||||
- Image: Enable "image float left" - @ivanlanin GH-244
|
||||
- RTF Writer: Ability to write document properties - @ivanlanin
|
||||
- RTF Writer: Ability to write image - @ivanlanin
|
||||
- Element: New `Field` element - @basjan GH-251
|
||||
- RTF Reader: Basic RTF reader - @ivanlanin GH-72 GH-252
|
||||
- Element: New `Line` element - @basjan GH-253
|
||||
- Title: Ability to apply numbering in heading - @ivanlanin GH-193
|
||||
- HTML Reader: Basic HTML reader - @ivanlanin GH-80 GH-254
|
||||
- RTF Writer: Basic table writing - @ivanlanin GH-245
|
||||
|
||||
### Bugfixes
|
||||
|
||||
- Header: All images added to the second header were assigned to the first header - @basjan GH-222
|
||||
- Conversion: Fix conversion from cm to pixel, pixel to cm, and pixel to point - @basjan GH-233 GH-234
|
||||
- PageBreak: Page break adds new line in the beginning of the new page - @ivanlanin GH-150
|
||||
- Image: `marginLeft` and `marginTop` cannot accept float value - @ivanlanin GH-248
|
||||
- Title: Orphan `w:fldChar` caused OpenOffice to crash when opening DOCX - @ivanlanin GH-236
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Static classes `Footnotes`, `Endnotes`, and `TOC`
|
||||
- `Writer\Word2007\Part`: `Numbering::writeNumbering()`, `Settings::writeSettings()`, `WebSettings::writeWebSettings()`, `ContentTypes::writeContentTypes()`, `Styles::writeStyles()`, `Document::writeDocument()` all changed into `write()`
|
||||
- `Writer\Word2007\Part\DocProps`: Split into `Writer\Word2007\Part\DocPropsCore` and `Writer\Word2007\Part\DocPropsApp`
|
||||
- `Element\Title::getBookmarkId()` replaced by `Element\Title::getRelationId()`
|
||||
- `Writer\HTML::writeDocument`: Replaced by `Writer\HTML::getContent`
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211
|
||||
- Word2007 Writer: New `Style\Image` class - @ivanlanin
|
||||
- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206
|
||||
- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
|
||||
- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
|
||||
- Docs: Create gh-pages branch for API documentation - @Progi1984 GH-154
|
||||
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186
|
||||
- Writer: Refactor writer parts using composite pattern - @ivanlanin
|
||||
- Docs: Show code quality and test code coverage badge on README
|
||||
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
|
||||
- Shared: Unify PHP ZipArchive and PCLZip features into PhpWord ZipArchive - @ivanlanin
|
||||
- Docs: Create VERSION file - @ivanlanin
|
||||
- QA: Improve dan update requirement check in `samples` folder - @ivanlanin
|
||||
|
||||
|
||||
## 0.10.1 - 21 May 2014
|
||||
|
||||
This is a bugfix release for `php-zip` requirement in Composer.
|
||||
|
|
@ -32,7 +99,7 @@ This release marked heavy refactorings on internal code structure with the creat
|
|||
- Link: Ability to add link in header/footer - @ivanlanin GH-187
|
||||
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
|
||||
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
||||
- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
|
||||
- General: Add `Style::resetStyles()` - @ivanlanin GH-187
|
||||
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
|
||||
- Endnote: Ability to add endnotes - @ivanlanin
|
||||
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
||||
|
|
|
|||
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
PHPWord, a pure PHP library for reading and writing word processing documents.
|
||||
|
||||
Copyright (c) 2010-2014 PHPWord.
|
||||
|
||||
PHPWord is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License version 3 as published by
|
||||
the Free Software Foundation.
|
||||
|
||||
PHPWord 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 version 3 for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License version 3
|
||||
along with PHPWord. If not, see <http://www.gnu.org/licenses/>.
|
||||
345
LICENSE.md
345
LICENSE.md
|
|
@ -1,345 +0,0 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
75
README.md
75
README.md
|
|
@ -1,46 +1,50 @@
|
|||
# 
|
||||
|
||||
[](https://travis-ci.org/PHPOffice/PHPWord)
|
||||
[](https://packagist.org/packages/phpoffice/phpword)
|
||||
[](https://travis-ci.org/PHPOffice/PHPWord)
|
||||
[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
|
||||
[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
|
||||
[](https://packagist.org/packages/phpoffice/phpword)
|
||||
[](https://packagist.org/packages/phpoffice/phpword)
|
||||
[](https://packagist.org/packages/phpoffice/phpword)
|
||||
|
||||
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF.
|
||||
|
||||
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
|
||||
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
||||
|
||||
## Features
|
||||
|
||||
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
|
||||
|
||||
* Set document properties, e.g. title, subject, and creator.
|
||||
* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
|
||||
* Create header and footer for each sections
|
||||
* Set default font type, font size, and paragraph style
|
||||
* Use UTF-8 and East Asia fonts/characters
|
||||
* Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
|
||||
* Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
|
||||
* Insert titles (headers) and table of contents
|
||||
* Insert text breaks and page breaks
|
||||
* Insert and format images, either local, remote, or as page watermarks
|
||||
* Insert binary OLE Objects such as Excel or Visio
|
||||
* Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
|
||||
* Insert list items as bulleted, numbered, or multilevel
|
||||
* Insert hyperlinks
|
||||
* Insert footnotes and endnotes
|
||||
* Create document from templates
|
||||
* Use XSL 1.0 style sheets to transform main document part of OOXML template
|
||||
* ... and many more features on progress
|
||||
|
||||
__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
|
||||
- Set document properties, e.g. title, subject, and creator.
|
||||
- Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
|
||||
- Create header and footer for each sections
|
||||
- Set default font type, font size, and paragraph style
|
||||
- Use UTF-8 and East Asia fonts/characters
|
||||
- Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
|
||||
- Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
|
||||
- Insert titles (headers) and table of contents
|
||||
- Insert text breaks and page breaks
|
||||
- Insert and format images, either local, remote, or as page watermarks
|
||||
- Insert binary OLE Objects such as Excel or Visio
|
||||
- Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
|
||||
- Insert list items as bulleted, numbered, or multilevel
|
||||
- Insert hyperlinks
|
||||
- Insert footnotes and endnotes
|
||||
- Create document from templates
|
||||
- Use XSL 1.0 style sheets to transform main document part of OOXML template
|
||||
- ... and many more features on progress
|
||||
|
||||
## Requirements
|
||||
* PHP 5.3+
|
||||
* PHP [Zip](http://php.net/manual/en/book.zip.php) extension
|
||||
* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
|
||||
|
||||
### Optional PHP extensions
|
||||
* PHP [GD](http://php.net/manual/en/book.image.php) extension
|
||||
* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension
|
||||
* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension
|
||||
PHPWord requires the following:
|
||||
|
||||
- PHP 5.3+
|
||||
- [Zip extension](http://php.net/manual/en/book.zip.php)
|
||||
- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
|
||||
- [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images)
|
||||
- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write DOCX and ODT)
|
||||
- [XSL extension](http://php.net/manual/en/book.xsl.php) (optional, used to apply XSL style sheet to template )
|
||||
- [dompdf](https://github.com/dompdf/dompdf) (optional, used to write PDF)
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
@ -63,7 +67,7 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
|
|||
\PhpOffice\PhpWord\Autoloader::register();
|
||||
```
|
||||
|
||||
## Basic usage
|
||||
## Usages
|
||||
|
||||
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
|
||||
|
||||
|
|
@ -107,6 +111,11 @@ $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
|
|||
$objWriter->save('helloWorld.rtf');
|
||||
```
|
||||
|
||||
## Documentation
|
||||
## Contributing
|
||||
|
||||
__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/).
|
||||
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute:
|
||||
|
||||
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md)
|
||||
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch
|
||||
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub
|
||||
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"name": "phpoffice/phpword",
|
||||
"description": "PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP",
|
||||
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)",
|
||||
"keywords": [
|
||||
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer",
|
||||
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML",
|
||||
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument"
|
||||
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument", "PDF", "HTML"
|
||||
],
|
||||
"homepage": "http://phpoffice.github.io",
|
||||
"type": "library",
|
||||
"license": "LGPL-2.1+",
|
||||
"license": "LGPL-3.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Baker"
|
||||
|
|
@ -36,7 +36,12 @@
|
|||
"ext-xml": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"phpdocumentor/phpdocumentor":"2.*",
|
||||
"squizlabs/php_codesniffer": "1.*",
|
||||
"dompdf/dompdf":"0.6.*",
|
||||
"tecnick.com/tcpdf": "6.*",
|
||||
"mpdf/mpdf": "5.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-zip": "Used to write DOCX and ODT",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -17,7 +17,7 @@ column shows the containers while the rows lists the elements.
|
|||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 4 | Title | v | ? | ? | ? | ? | ? |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 5 | Preserve Text | ? | v | v | v\* | ? | ? |
|
||||
| 5 | Preserve Text | ? | v | v | v\* | - | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 6 | Text Break | v | v | v | v | v | v |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
|
|
@ -25,7 +25,7 @@ column shows the containers while the rows lists the elements.
|
|||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 8 | List | v | v | v | v | - | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 9 | Table | v | v | v | ? | - | - |
|
||||
| 9 | Table | v | v | v | v | - | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 10 | Image | v | v | v | v | v | v |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
|
|
@ -39,7 +39,13 @@ column shows the containers while the rows lists the elements.
|
|||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 15 | Endnote | v | - | - | v\*\* | v\*\* | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 16 | CheckBox | v | v | v | v | ? | ? |
|
||||
| 16 | CheckBox | v | v | v | v | - | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 17 | TextBox | v | v | v | v | - | - |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 18 | Field | v | v | v | v | v | v |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
| 19 | Line | v | v | v | v | v | v |
|
||||
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
|
||||
|
||||
Legend:
|
||||
|
|
@ -473,3 +479,18 @@ Checkbox elements can be added to sections or table cells by using
|
|||
- ``$text`` Text following the check box
|
||||
- ``$fontStyle`` See "Font style" section.
|
||||
- ``$paragraphStyle`` See "Paragraph style" section.
|
||||
|
||||
Textboxes
|
||||
---------
|
||||
|
||||
To be completed
|
||||
|
||||
Fields
|
||||
------
|
||||
|
||||
To be completed
|
||||
|
||||
Line
|
||||
------
|
||||
|
||||
To be completed
|
||||
|
|
|
|||
165
docs/intro.rst
165
docs/intro.rst
|
|
@ -12,18 +12,14 @@ Applications <http://en.wikipedia.org/wiki/OpenDocument>`__
|
|||
(OpenDocument or ODF), and `Rich Text
|
||||
Format <http://en.wikipedia.org/wiki/Rich_Text_Format>`__ (RTF).
|
||||
|
||||
No Windows operating system is needed for usage because the resulting
|
||||
DOCX, ODT, or RTF files can be opened by all major `word processing
|
||||
softwares <http://en.wikipedia.org/wiki/List_of_word_processors>`__.
|
||||
|
||||
PHPWord is an open source project licensed under LGPL. PHPWord is `unit
|
||||
tested <https://travis-ci.org/PHPOffice/PHPWord>`__ to make sure that
|
||||
the released versions are stable.
|
||||
|
||||
**Want to contribute?** `Fork
|
||||
us <https://github.com/PHPOffice/PHPWord/fork>`__ or
|
||||
`submit <https://github.com/PHPOffice/PHPWord/issues>`__ your bug
|
||||
reports or feature requests to us.
|
||||
PHPWord is an open source project licensed under the terms of `LGPL
|
||||
version 3 <https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER>`__.
|
||||
PHPWord is aimed to be a high quality software product by incorporating
|
||||
`continuous integration <https://travis-ci.org/PHPOffice/PHPWord>`__ and
|
||||
`unit testing <http://phpoffice.github.io/PHPWord/coverage/develop/>`__.
|
||||
You can learn more about PHPWord by reading this Developers'
|
||||
Documentation and the `API
|
||||
Documentation <http://phpoffice.github.io/PHPWord/docs/develop/>`__.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
|
@ -65,31 +61,29 @@ Writers
|
|||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
||||
+===========================+======================+========+=======+=======+========+=======+
|
||||
| **Document Properties** | Standard | ✓ | | | | |
|
||||
| **Document Properties** | Standard | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Extended | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | UserDefined | ✓ | | | | |
|
||||
| | Custom | ✓ | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Title | ✓ | | | ✓ | ✓ |
|
||||
| | Title | ✓ | ✓ | | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Link | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Preserve Text | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Page Break | ✓ | | | | |
|
||||
| | Page Break | ✓ | | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | List | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Table | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Table | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Image | ✓ | ✓ | | ✓ | |
|
||||
| | Image | ✓ | ✓ | ✓ | ✓ | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Object | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
|
|
@ -123,60 +117,75 @@ Writers
|
|||
Readers
|
||||
~~~~~~~
|
||||
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| Features | | DOCX | ODT | RTF |
|
||||
+===========================+======================+========+=======+=======+
|
||||
| **Document Properties** | Standard | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Extended | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | UserDefined | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| **Element Type** | Text | ✓ | ✓ | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Text Run | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Title | ✓ | ✓ | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Link | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Preserve Text | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Text Break | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Page Break | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | List | ✓ | ✓ | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Table | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Image | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Object | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Watermark | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Table of Contents | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Header | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Footer | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Footnote | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Endnote | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| **Graphs** | 2D basic graphs | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | 2D advanced graphs | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | 3D graphs | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| **Math** | OMML support | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | MathML support | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| **Bonus** | Encryption | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
| | Protection | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| Features | | DOCX | ODT | RTF | HTML |
|
||||
+===========================+======================+========+=======+=======+=======+
|
||||
| **Document Properties** | Standard | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Custom | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Text Run | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Title | ✓ | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Link | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Preserve Text | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Text Break | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Page Break | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | List | ✓ | ✓ | | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Table | ✓ | | | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Image | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Object | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Watermark | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Table of Contents | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Header | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Footer | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Footnote | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Endnote | ✓ | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| **Graphs** | 2D basic graphs | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | 2D advanced graphs | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | 3D graphs | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| **Math** | OMML support | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | MathML support | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| **Bonus** | Encryption | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
| | Protection | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
We welcome everyone to contribute to PHPWord. Below are some of the
|
||||
things that you can do to contribute:
|
||||
|
||||
- Read `our contributing
|
||||
guide <https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md>`__
|
||||
- `Fork us <https://github.com/PHPOffice/PHPWord/fork>`__ and `request
|
||||
a pull <https://github.com/PHPOffice/PHPWord/pulls>`__ to the
|
||||
`develop <https://github.com/PHPOffice/PHPWord/tree/develop>`__
|
||||
branch
|
||||
- Submit `bug reports or feature
|
||||
requests <https://github.com/PHPOffice/PHPWord/issues>`__ to GitHub
|
||||
- Follow `@PHPWord <https://twitter.com/PHPWord>`__ and
|
||||
`@PHPOffice <https://twitter.com/PHPOffice>`__ on Twitter
|
||||
|
|
|
|||
|
|
@ -2,3 +2,66 @@
|
|||
|
||||
Recipes
|
||||
=======
|
||||
|
||||
Create float left image
|
||||
-----------------------
|
||||
|
||||
Use absolute positioning relative to margin horizontally and to line
|
||||
vertically.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$imageStyle = array(
|
||||
'width' => 40,
|
||||
'height' => 40,
|
||||
'wrappingStyle' => 'square',
|
||||
'positioning' => 'absolute',
|
||||
'posHorizontalRel' => 'margin',
|
||||
'posVerticalRel' => 'line',
|
||||
);
|
||||
$textrun->addImage('resources/_earth.jpg', $imageStyle);
|
||||
$textrun->addText($lipsumText);
|
||||
|
||||
Download the produced file automatically
|
||||
----------------------------------------
|
||||
|
||||
Use ``php://output`` as the filename.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Hello World!');
|
||||
$file = 'HelloWorld.docx';
|
||||
header("Content-Description: File Transfer");
|
||||
header('Content-Disposition: attachment; filename="' . $file . '"');
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Expires: 0');
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||
$xmlWriter->save("php://output");
|
||||
|
||||
Create numbered headings
|
||||
------------------------
|
||||
|
||||
Define a numbering style and title styles, and match the two styles (with ``pStyle`` and ``numStyle``) like below.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$phpWord->addNumberingStyle(
|
||||
'hNum',
|
||||
array('type' => 'multilevel', 'levels' => array(
|
||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||
)
|
||||
)
|
||||
);
|
||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'hNum', 'numLevel' => 0));
|
||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'hNum', 'numLevel' => 1));
|
||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'hNum', 'numLevel' => 2));
|
||||
|
||||
$section->addTitle('Heading 1', 1);
|
||||
$section->addTitle('Heading 2', 2);
|
||||
$section->addTitle('Heading 3', 3);
|
||||
|
|
|
|||
|
|
@ -3,11 +3,21 @@
|
|||
References
|
||||
==========
|
||||
|
||||
ISO/IEC 29500, Third edition, 2012-09-01
|
||||
---------------------
|
||||
|
||||
- `Part 1: Fundamentals and Markup Language Reference
|
||||
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061750_ISO_IEC_29500-1_2012.zip>`__
|
||||
- `Part 2: Open Packaging Conventions
|
||||
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061796_ISO_IEC_29500-2_2012.zip>`__
|
||||
- `Part 3: Markup Compatibility and Extensibility
|
||||
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061797_ISO_IEC_29500-3_2012.zip>`__
|
||||
- `Part 4: Transitional Migration Features
|
||||
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061798_ISO_IEC_29500-4_2012.zip>`__
|
||||
|
||||
Formal specifications
|
||||
---------------------
|
||||
|
||||
- `Office Open XML (OOXML) (ECMA-376)
|
||||
Schema <http://www.schemacentral.com/sc/ooxml/ss.html>`__
|
||||
- `Oasis OpenDocument Standard Version
|
||||
1.2 <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html>`__
|
||||
- `Rich Text Format (RTF) Specification, version
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
|
|||
- [Table of contents](#table-of-contents)
|
||||
- [Footnotes & endnotes](#footnotes-endnotes)
|
||||
- [Checkboxes](#checkboxes)
|
||||
- [Textboxes](#textboxes)
|
||||
- [Fields](#fields)
|
||||
- [Lines](#lines)
|
||||
- [Templates](#templates)
|
||||
- [Writers & readers](#writers-readers)
|
||||
- [OOXML](#ooxml)
|
||||
|
|
@ -40,6 +43,7 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
|
|||
- [RTF](#rtf)
|
||||
- [HTML](#html)
|
||||
- [PDF](#pdf)
|
||||
- [Recipes](#recipes)
|
||||
- [Frequently asked questions](#frequently-asked-questions)
|
||||
- [References](#references)
|
||||
|
||||
|
|
@ -47,11 +51,7 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
|
|||
|
||||
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
|
||||
|
||||
No Windows operating system is needed for usage because the resulting DOCX, ODT, or RTF files can be opened by all major [word processing softwares](http://en.wikipedia.org/wiki/List_of_word_processors).
|
||||
|
||||
PHPWord is an open source project licensed under LGPL. PHPWord is [unit tested](https://travis-ci.org/PHPOffice/PHPWord) to make sure that the released versions are stable.
|
||||
|
||||
**Want to contribute?** [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
|
||||
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading this Developers' Documentation and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
||||
|
||||
## Features
|
||||
|
||||
|
|
@ -82,19 +82,18 @@ Below are the supported features for each file formats.
|
|||
|
||||
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
||||
|-------------------------|--------------------|------|-----|-----|------|-----|
|
||||
| **Document Properties** | Standard | ✓ | | | | |
|
||||
| | Extended | ✓ | | | | |
|
||||
| | UserDefined | ✓ | | | | |
|
||||
| **Document Properties** | Standard | ✓ | ✓ | ✓ | ✓ | |
|
||||
| | Custom | ✓ | ✓ | | | |
|
||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Title | ✓ | | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Title | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Preserve Text | ✓ | | | | |
|
||||
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Page Break | ✓ | | | | |
|
||||
| | Page Break | ✓ | | ✓ | | |
|
||||
| | List | ✓ | | | | |
|
||||
| | Table | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Image | ✓ | ✓ | | ✓ | |
|
||||
| | Table | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Image | ✓ | ✓ | ✓ | ✓ | |
|
||||
| | Object | ✓ | | | | |
|
||||
| | Watermark | ✓ | | | | |
|
||||
| | Table of Contents | ✓ | | | | |
|
||||
|
|
@ -112,35 +111,43 @@ Below are the supported features for each file formats.
|
|||
|
||||
### Readers
|
||||
|
||||
| Features | | DOCX | ODT | RTF |
|
||||
|-------------------------|--------------------|------|-----|-----|
|
||||
| **Document Properties** | Standard | ✓ | | |
|
||||
| | Extended | ✓ | | |
|
||||
| | UserDefined | ✓ | | |
|
||||
| **Element Type** | Text | ✓ | ✓ | |
|
||||
| | Text Run | ✓ | | |
|
||||
| | Title | ✓ | ✓ | |
|
||||
| | Link | ✓ | | |
|
||||
| | Preserve Text | ✓ | | |
|
||||
| | Text Break | ✓ | | |
|
||||
| | Page Break | ✓ | | |
|
||||
| | List | ✓ | ✓ | |
|
||||
| | Table | ✓ | | |
|
||||
| | Image | ✓ | | |
|
||||
| | Object | | | |
|
||||
| | Watermark | | | |
|
||||
| | Table of Contents | | | |
|
||||
| | Header | ✓ | | |
|
||||
| | Footer | ✓ | | |
|
||||
| | Footnote | ✓ | | |
|
||||
| | Endnote | ✓ | | |
|
||||
| **Graphs** | 2D basic graphs | | | |
|
||||
| | 2D advanced graphs | | | |
|
||||
| | 3D graphs | | | |
|
||||
| **Math** | OMML support | | | |
|
||||
| | MathML support | | | |
|
||||
| **Bonus** | Encryption | | | |
|
||||
| | Protection | | | |
|
||||
| Features | | DOCX | ODT | RTF | HTML|
|
||||
|-------------------------|--------------------|------|-----|-----|-----|
|
||||
| **Document Properties** | Standard | ✓ | | | |
|
||||
| | Custom | ✓ | | | |
|
||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Text Run | ✓ | | | |
|
||||
| | Title | ✓ | ✓ | | |
|
||||
| | Link | ✓ | | | |
|
||||
| | Preserve Text | ✓ | | | |
|
||||
| | Text Break | ✓ | | | |
|
||||
| | Page Break | ✓ | | | |
|
||||
| | List | ✓ | ✓ | | ✓ |
|
||||
| | Table | ✓ | | | ✓ |
|
||||
| | Image | ✓ | | | |
|
||||
| | Object | | | | |
|
||||
| | Watermark | | | | |
|
||||
| | Table of Contents | | | | |
|
||||
| | Header | ✓ | | | |
|
||||
| | Footer | ✓ | | | |
|
||||
| | Footnote | ✓ | | | |
|
||||
| | Endnote | ✓ | | | |
|
||||
| **Graphs** | 2D basic graphs | | | | |
|
||||
| | 2D advanced graphs | | | | |
|
||||
| | 3D graphs | | | | |
|
||||
| **Math** | OMML support | | | | |
|
||||
| | MathML support | | | | |
|
||||
| **Bonus** | Encryption | | | | |
|
||||
| | Protection | | | | |
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute:
|
||||
|
||||
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md)
|
||||
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch
|
||||
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub
|
||||
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter
|
||||
|
||||
# Installing/configuring
|
||||
|
||||
|
|
@ -443,18 +450,21 @@ Below are the matrix of element availability in each container. The column shows
|
|||
| 2 | Text Run | v | v | v | v | - | - |
|
||||
| 3 | Link | v | v | v | v | v | v |
|
||||
| 4 | Title | v | ? | ? | ? | ? | ? |
|
||||
| 5 | Preserve Text | ? | v | v | v* | ? | ? |
|
||||
| 5 | Preserve Text | ? | v | v | v* | - | - |
|
||||
| 6 | Text Break | v | v | v | v | v | v |
|
||||
| 7 | Page Break | v | - | - | - | - | - |
|
||||
| 8 | List | v | v | v | v | - | - |
|
||||
| 9 | Table | v | v | v | ? | - | - |
|
||||
| 9 | Table | v | v | v | v | - | - |
|
||||
| 10 | Image | v | v | v | v | v | v |
|
||||
| 11 | Watermark | - | v | - | - | - | - |
|
||||
| 12 | Object | v | v | v | v | v | v |
|
||||
| 13 | TOC | v | - | - | - | - | - |
|
||||
| 14 | Footnote | v | - | - | v** | v** | - |
|
||||
| 15 | Endnote | v | - | - | v** | v** | - |
|
||||
| 16 | CheckBox | v | v | v | v | ? | ? |
|
||||
| 16 | CheckBox | v | v | v | v | - | - |
|
||||
| 17 | TextBox | v | v | v | v | - | - |
|
||||
| 18 | Field | v | v | v | v | v | v |
|
||||
| 19 | Line | v | v | v | v | v | v |
|
||||
|
||||
Legend:
|
||||
|
||||
|
|
@ -487,7 +497,7 @@ $section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
|
|||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('I am bold', array('bold' => true));
|
||||
$textrun->addText('I am italic', array('italic' => true));
|
||||
$textrun->addText('I am colored, array('color' => 'AACC00'));
|
||||
$textrun->addText('I am colored', array('color' => 'AACC00'));
|
||||
```
|
||||
|
||||
Defined style examples:
|
||||
|
|
@ -828,6 +838,18 @@ $section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle])
|
|||
- `$fontStyle` See "Font style" section.
|
||||
- `$paragraphStyle` See "Paragraph style" section.
|
||||
|
||||
## Textboxes
|
||||
|
||||
To be completed.
|
||||
|
||||
## Fields
|
||||
|
||||
To be completed.
|
||||
|
||||
## Lines
|
||||
|
||||
To be completed.
|
||||
|
||||
# Templates
|
||||
|
||||
You can create a docx template with included search-patterns that can be replaced by any value you wish. Only single-line values can be replaced. To load a template file, use the `loadTemplate` method. After loading the docx template, you can use the `setValue` method to change the value of a search pattern. The search-pattern model is: `${search-pattern}`. It is not possible to add new PHPWord elements to a loaded template file.
|
||||
|
|
@ -926,6 +948,67 @@ To be completed.
|
|||
|
||||
To be completed.
|
||||
|
||||
# Recipes
|
||||
|
||||
## Create float left image
|
||||
|
||||
Use absolute positioning relative to margin horizontally and to line vertically.
|
||||
|
||||
```php
|
||||
$imageStyle = array(
|
||||
'width' => 40,
|
||||
'height' => 40
|
||||
'wrappingStyle' => 'square',
|
||||
'positioning' => 'absolute',
|
||||
'posHorizontalRel' => 'margin',
|
||||
'posVerticalRel' => 'line',
|
||||
);
|
||||
$textrun->addImage('resources/_earth.jpg', $imageStyle);
|
||||
$textrun->addText($lipsumText);
|
||||
```
|
||||
|
||||
## Download the produced file automatically
|
||||
|
||||
Use `php://output` as the filename.
|
||||
|
||||
```php
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Hello World!');
|
||||
$file = 'HelloWorld.docx';
|
||||
header("Content-Description: File Transfer");
|
||||
header('Content-Disposition: attachment; filename="' . $file . '"');
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Expires: 0');
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||
$xmlWriter->save("php://output");
|
||||
```
|
||||
|
||||
## Create numbered headings
|
||||
|
||||
Define a numbering style and title styles, and match the two styles (with `pStyle` and `numStyle`) like below.
|
||||
|
||||
```php
|
||||
$phpWord->addNumberingStyle(
|
||||
'hNum',
|
||||
array('type' => 'multilevel', 'levels' => array(
|
||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||
)
|
||||
)
|
||||
);
|
||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'hNum', 'numLevel' => 0));
|
||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'hNum', 'numLevel' => 1));
|
||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'hNum', 'numLevel' => 2));
|
||||
|
||||
$section->addTitle('Heading 1', 1);
|
||||
$section->addTitle('Heading 2', 2);
|
||||
$section->addTitle('Heading 3', 3);
|
||||
```
|
||||
|
||||
# Frequently asked questions
|
||||
|
||||
## Is this the same with PHPWord that I found in CodePlex?
|
||||
|
|
@ -938,13 +1021,18 @@ PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex can run w
|
|||
|
||||
# References
|
||||
|
||||
## ISO/IEC 29500, Third edition, 2012-09-01
|
||||
|
||||
- [Part 1: Fundamentals and Markup Language Reference](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061750_ISO_IEC_29500-1_2012.zip)
|
||||
- [Part 2: Open Packaging Conventions](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061796_ISO_IEC_29500-2_2012.zip)
|
||||
- [Part 3: Markup Compatibility and Extensibility](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061797_ISO_IEC_29500-3_2012.zip)
|
||||
- [Part 4: Transitional Migration Features](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061798_ISO_IEC_29500-4_2012.zip)
|
||||
|
||||
## Formal specifications
|
||||
|
||||
- [Office Open XML (OOXML) (ECMA-376) Schema](http://www.schemacentral.com/sc/ooxml/ss.html)
|
||||
- [Oasis OpenDocument Standard Version 1.2](http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html)
|
||||
- [Rich Text Format (RTF) Specification, version 1.9.1](http://www.microsoft.com/en-us/download/details.aspx?id=10725)
|
||||
- [Oasis OpenDocument Standard Version 1.2](http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html)
|
||||
- [Rich Text Format (RTF) Specification, version 1.9.1](http://www.microsoft.com/en-us/download/details.aspx?id=10725)
|
||||
|
||||
## Other resources
|
||||
|
||||
- [DocumentFormat.OpenXml.Wordprocessing Namespace on MSDN](http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing%28v=office.14%29.aspx)
|
||||
|
||||
- [DocumentFormat.OpenXml.Wordprocessing Namespace on MSDN](http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing%28v=office.14%29.aspx)
|
||||
|
|
|
|||
14
phpmd.xml
14
phpmd.xml
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="PHPWord mess detector ruleset"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<rule ref="rulesets/unusedcode.xml" />
|
||||
<rule ref="rulesets/design.xml" />
|
||||
<rule ref="rulesets/naming.xml/LongVariable" />
|
||||
<rule ref="rulesets/naming.xml/ShortVariable" />
|
||||
<rule ref="rulesets/naming.xml/ShortMethodName" />
|
||||
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
|
||||
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
|
||||
</ruleset>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<ruleset name="PHPWord PHP Mess Detector Rule Set"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<rule ref="rulesets/naming.xml"/>
|
||||
<rule ref="rulesets/design.xml/ExitExpression" />
|
||||
<rule ref="rulesets/design.xml/EvalExpression" />
|
||||
<rule ref="rulesets/design.xml/GotoStatement" />
|
||||
<rule ref="rulesets/design.xml/DepthOfInheritance" />
|
||||
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
|
||||
<!-- AbstractContainer needs more coupling (default: 13) -->
|
||||
<properties>
|
||||
<property name="minimum" value="20" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/design.xml/NumberOfChildren">
|
||||
<!-- AbstractStyle needs more children (default: 15) -->
|
||||
<properties>
|
||||
<property name="minimum" value="20" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/unusedcode.xml" />
|
||||
<rule ref="rulesets/controversial.xml" />
|
||||
</ruleset>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="PhpWord Test Suite">
|
||||
<directory>./tests/PhpWord/</directory>
|
||||
<directory>./tests/PhpWord</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
|
||||
<log type="coverage-clover" target="./build/logs/clover.xml" />
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
; Default config file for PHPWord
|
||||
; Copy this file into phpword.ini and use Settings::loadConfig to load
|
||||
|
||||
[General]
|
||||
|
||||
compatibility = true
|
||||
zipClass = ZipArchive
|
||||
pdfRendererName = DomPDF
|
||||
pdfRendererPath =
|
||||
|
||||
[Font]
|
||||
|
||||
defaultFontName = Arial
|
||||
defaultFontSize = 10
|
||||
|
|
@ -22,7 +22,8 @@ $section->addTextBreak(2);
|
|||
$section->addText('I am styled by a font style definition.', 'rStyle');
|
||||
$section->addText('I am styled by a paragraph style definition.', null, 'pStyle');
|
||||
$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle');
|
||||
$section->addTextBreak();
|
||||
|
||||
$section->addPageBreak();
|
||||
|
||||
// Inline font style
|
||||
$fontStyle['name'] = 'Times New Roman';
|
||||
|
|
@ -36,10 +37,11 @@ $fontStyle['color'] = 'FF0000';
|
|||
$fontStyle['fgColor'] = 'yellow';
|
||||
$fontStyle['smallCaps'] = true;
|
||||
$section->addText('I am inline styled.', $fontStyle);
|
||||
|
||||
$section->addTextBreak();
|
||||
|
||||
// Link
|
||||
$section->addLink('http://www.google.com', null, 'NLink');
|
||||
$section->addLink('http://www.google.com', 'Google');
|
||||
$section->addTextBreak();
|
||||
|
||||
// Image
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ $section = $phpWord->addSection(array(
|
|||
'colsNum' => 2,
|
||||
'colsSpace' => 1440,
|
||||
'breakType' => 'continuous'));
|
||||
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
|
||||
$section->addText('Two columns, one inch (1440 twips) spacing. ' . $filler);
|
||||
|
||||
// Normal
|
||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ for($i = 1; $i <= 8; $i++) {
|
|||
|
||||
// 3. colspan (gridSpan) and rowspan (vMerge)
|
||||
|
||||
$section->addTextBreak(1);
|
||||
$section->addPageBreak();
|
||||
$section->addText("Table with colspan and rowspan", $header);
|
||||
|
||||
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
||||
|
|
@ -84,6 +84,17 @@ $table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
|
|||
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
|
||||
$table->addCell(null, $cellRowContinue);
|
||||
|
||||
// 4. Nested table
|
||||
|
||||
$section->addTextBreak(2);
|
||||
$section->addText('Nested table in a centered and 50% width table.', $header);
|
||||
|
||||
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center'));
|
||||
$cell = $table->addRow()->addCell();
|
||||
$cell->addText('This cell contains nested table.');
|
||||
$innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell();
|
||||
$innerCell->addText('Inside nested table');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ include_once 'Sample_Header.php';
|
|||
|
||||
// Read contents
|
||||
$name = basename(__FILE__, '.php');
|
||||
$source = "resources/{$name}.docx";
|
||||
$source = __DIR__ . "/resources/{$name}.docx";
|
||||
|
||||
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ $table->addCell(4500)->addImage(
|
|||
// Add header for all other pages
|
||||
$subsequent = $section->addHeader();
|
||||
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
|
||||
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
||||
|
||||
// Add footer
|
||||
$footer = $section->addFooter();
|
||||
|
|
|
|||
|
|
@ -26,11 +26,45 @@ $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
|||
foreach ($wrappingStyles as $wrappingStyle) {
|
||||
$section->addTextBreak(5);
|
||||
$section->addText('Wrapping style ' . $wrappingStyle);
|
||||
$section->addImage('resources/_earth.jpg', array('marginTop' => -1, 'marginLeft' => 1,
|
||||
$section->addImage('resources/_earth.jpg', array('positioning' => 'relative', 'marginTop' => -1, 'marginLeft' => 1,
|
||||
'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
|
||||
$section->addText($text);
|
||||
}
|
||||
|
||||
//Absolute positioning
|
||||
$section->addTextBreak(3);
|
||||
$section->addText('Absolute positioning: see top right corner of page');
|
||||
$section->addImage(
|
||||
'resources/_mars.jpg',
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)
|
||||
)
|
||||
);
|
||||
|
||||
//Relative positioning
|
||||
$section->addTextBreak(3);
|
||||
$section->addText('Relative positioning: Horizontal position center relative to column,');
|
||||
$section->addText('Vertical position top relative to line');
|
||||
$section->addImage(
|
||||
'resources/_mars.jpg',
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
|
||||
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE
|
||||
)
|
||||
);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ $phpWord->addNumberingStyle(
|
|||
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
||||
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
||||
|
||||
|
|
@ -54,6 +54,37 @@ $section->addListItem('List Item 6', 1, 'myOwnStyle', $predefinedMultilevel, 'P-
|
|||
$section->addListItem('List Item 7', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('List with inline formatting.');
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 1');
|
||||
$listItemRun->addText(' in bold', array('bold'=>true));
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 2');
|
||||
$listItemRun->addText(' in italic', array('italic'=>true));
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 3');
|
||||
$listItemRun->addText(' underlined', array('underline'=>'dash'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Numbered heading
|
||||
|
||||
$phpWord->addNumberingStyle(
|
||||
'headingNumbering',
|
||||
array('type' => 'multilevel', 'levels' => array(
|
||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||
)
|
||||
)
|
||||
);
|
||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
|
||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
|
||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
|
||||
|
||||
$section->addTitle('Heading 1', 1);
|
||||
$section->addTitle('Heading 2', 2);
|
||||
$section->addTitle('Heading 3', 3);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ include_once 'Sample_Header.php';
|
|||
|
||||
// Read contents
|
||||
$name = basename(__FILE__, '.php');
|
||||
$source = "resources/{$name}.odt";
|
||||
$source = __DIR__ . "/resources/{$name}.odt";
|
||||
|
||||
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'ODText');
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// In section
|
||||
$textbox = $section->addTextBox(array('align' => 'center', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
||||
$textbox->addText('Text box content in section.');
|
||||
$textbox->addText('Another line.');
|
||||
$cell = $textbox->addTable()->addRow()->addCell();
|
||||
$cell->addText('Table inside textbox');
|
||||
|
||||
// Inside table
|
||||
$section->addTextBreak(2);
|
||||
$cell = $section->addTable()->addRow()->addCell(300);
|
||||
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
||||
$textbox->addText('Textbox inside table');
|
||||
|
||||
// Inside header with textrun
|
||||
$header = $section->addHeader();
|
||||
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||
$textrun = $textbox->addTextRun();
|
||||
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
|
||||
$textrun->addText('with bold text', array('bold' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addLink('http://www.google.com', 'link');
|
||||
$textrun->addText(', and image ');
|
||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||
$textrun->addText('.');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
$html = '<h1>Adding element via HTML</h1>';
|
||||
$html .= '<p>Some well formed HTML snippet needs to be used</p>';
|
||||
$html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>';
|
||||
$html .= '<p>Unordered (bulleted) list:</p>';
|
||||
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
|
||||
$html .= '<p>Ordered (numbered) list:</p>';
|
||||
$html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
|
||||
|
||||
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// Add Field elements
|
||||
// See Element/Field.php for all options
|
||||
$section->addText('Date field:');
|
||||
$section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
||||
|
||||
$section->addText('Page field:');
|
||||
$section->addField('PAGE', array('format'=>'ArabicDash'));
|
||||
|
||||
$section->addText('Number of pages field:');
|
||||
$section->addField('NUMPAGES', array('format'=>'Arabic', 'numformat'=>'0,00'), array('PreserveFormat'));
|
||||
|
||||
$textrun = $section->addTextRun(array('align' => 'center'));
|
||||
$textrun->addText('This is the date of lunar calendar ');
|
||||
$textrun->addField('DATE', array('dateformat'=>'d-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
||||
$textrun->addText(' written in a textrun.');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// Read contents
|
||||
$name = basename(__FILE__, '.php');
|
||||
$source = __DIR__ . "/resources/{$name}.rtf";
|
||||
|
||||
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'RTF');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// Add Line elements
|
||||
// See Element/Line.php for all options
|
||||
$section->addText('Horizontal Line (Inline style):');
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
||||
'positioning' => 'absolute'
|
||||
)
|
||||
);
|
||||
$section->addText('Vertical Line (Inline style):');
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
|
||||
'positioning' => 'absolute'
|
||||
)
|
||||
);
|
||||
// Two text break
|
||||
$section->addTextBreak(1);
|
||||
|
||||
$section->addText('Positioned Line (red):');
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
|
||||
'positioning' => 'absolute',
|
||||
'posHorizontalRel' => 'page',
|
||||
'posVerticalRel' => 'page',
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(10),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(8),
|
||||
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
|
||||
'color' => 'red'
|
||||
)
|
||||
);
|
||||
|
||||
$section->addText('Horizontal Formatted Line');
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
||||
'positioning' => 'absolute',
|
||||
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
|
||||
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
|
||||
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
|
||||
'weight' => 10
|
||||
)
|
||||
);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// Read contents
|
||||
$name = basename(__FILE__, '.php');
|
||||
$source = realpath(__DIR__ . "/resources/{$name}.html");
|
||||
|
||||
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'HTML');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
|
|
@ -2,23 +2,25 @@
|
|||
/**
|
||||
* Header file
|
||||
*/
|
||||
use PhpOffice\PhpWord\Autoloader;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
||||
define('EOL', CLI ? PHP_EOL : '<br />');
|
||||
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
|
||||
define('IS_INDEX', SCRIPT_FILENAME == 'index');
|
||||
|
||||
require_once '../src/PhpWord/Autoloader.php';
|
||||
\PhpOffice\PhpWord\Autoloader::register();
|
||||
require_once __DIR__ . '/../src/PhpWord/Autoloader.php';
|
||||
Autoloader::register();
|
||||
Settings::loadConfig();
|
||||
|
||||
// Set writers
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
|
||||
|
||||
// Set PDF renderer
|
||||
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF;
|
||||
$rendererLibraryPath = ''; // DomPDF library path
|
||||
|
||||
if (!\PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) {
|
||||
if (Settings::getPdfRendererPath() === null) {
|
||||
$writers['PDF'] = null;
|
||||
}
|
||||
|
||||
|
|
@ -60,9 +62,9 @@ function write($phpWord, $filename, $writers)
|
|||
foreach ($writers as $writer => $extension) {
|
||||
$result .= date('H:i:s') . " Write to {$writer} format";
|
||||
if (!is_null($extension)) {
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
||||
$xmlWriter->save("{$filename}.{$extension}");
|
||||
rename("{$filename}.{$extension}", "results/{$filename}.{$extension}");
|
||||
$xmlWriter = IOFactory::createWriter($phpWord, $writer);
|
||||
$xmlWriter->save(__DIR__ . "/{$filename}.{$extension}");
|
||||
rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}");
|
||||
} else {
|
||||
$result .= ' ... NOT DONE!';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
$requirements = array(
|
||||
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
||||
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
||||
'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')),
|
||||
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
||||
'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')),
|
||||
'xsl' => array('PHP extension XSL (optional)', extension_loaded('xsl')),
|
||||
);
|
||||
if (!CLI) {
|
||||
?>
|
||||
<div class="jumbotron">
|
||||
|
|
@ -10,21 +18,23 @@ if (!CLI) {
|
|||
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/en/develop/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
|
||||
</p>
|
||||
</div>
|
||||
<?
|
||||
$requirements = array(
|
||||
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
||||
'zip' => array('PHP extension ZipArchive', extension_loaded('zip')),
|
||||
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
||||
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
||||
);
|
||||
echo "<h3>Requirements</h3>";
|
||||
echo "<ul>";
|
||||
foreach ($requirements as $key => $value) {
|
||||
$status = $value[1] ? 'passed' : 'failed';
|
||||
echo "<li>{$value[0]} ... <span class='{$status}'>{$status}</span></li>";
|
||||
}
|
||||
echo "</ul>";
|
||||
<?php
|
||||
}
|
||||
if (!CLI) {
|
||||
echo "<h3>Requirement check:</h3>";
|
||||
echo "<ul>";
|
||||
foreach ($requirements as $key => $value) {
|
||||
list($label, $result) = $value;
|
||||
$status = $result ? 'passed' : 'failed';
|
||||
echo "<li>{$label} ... <span class='{$status}'>{$status}</span></li>";
|
||||
}
|
||||
echo "</ul>";
|
||||
include_once 'Sample_Footer.php';
|
||||
} else {
|
||||
echo 'Requirement check:' . PHP_EOL;
|
||||
foreach ($requirements as $key => $value) {
|
||||
list($label, $result) = $value;
|
||||
$status = $result ? '32m passed' : '31m failed';
|
||||
echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,21 @@
|
|||
{\rtf1
|
||||
\ansi\ansicpg1252
|
||||
\deff0
|
||||
{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 Times New Roman;}}
|
||||
{\colortbl;\red255\green0\blue0;\red14\green0\blue0}
|
||||
{\*\generator PhpWord;}
|
||||
|
||||
{\info{\title }{\subject }{\category }{\keywords }{\comment }{\author }{\operator }{\creatim \yr2014\mo05\dy27\hr23\min36\sec45}{\revtim \yr2014\mo05\dy27\hr23\min36\sec45}{\company }{\manager }}
|
||||
\deftab720\viewkind1\uc1\pard\nowidctlpar\lang1036\kerning1\fs20
|
||||
{Welcome to PhpWord}\par
|
||||
\pard\nowidctlpar{\cf0\f0 Hello World!}\par
|
||||
\par
|
||||
\par
|
||||
\pard\nowidctlpar{\cf0\f0\fs32\b\i I am styled by a font style definition.}\par
|
||||
\pard\nowidctlpar{\cf0\f0 I am styled by a paragraph style definition.}\par
|
||||
\pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par
|
||||
\pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par
|
||||
\par
|
||||
{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par
|
||||
\par
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>PHPWord</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Adding element via HTML</h1>
|
||||
<p>Some well formed HTML snippet needs to be used</p>
|
||||
<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>
|
||||
<p>Unordered (bulleted) list:</p>
|
||||
<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>
|
||||
<p>Ordered (numbered) list:</p>
|
||||
<ol><li>Item 1</li><li>Item 2</li></ol>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
|
@ -14,6 +22,7 @@ namespace PhpOffice\PhpWord;
|
|||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/** @const string */
|
||||
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
|
||||
|
||||
/**
|
||||
|
|
@ -38,6 +47,7 @@ class Autoloader
|
|||
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
|
||||
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
|
||||
if (file_exists($file)) {
|
||||
/** @noinspection PhpIncludeInspection Dynamic includes */
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Collection;
|
||||
|
||||
/**
|
||||
* Collection abstract class
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
abstract class AbstractCollection
|
||||
{
|
||||
/**
|
||||
* Items
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $items = array();
|
||||
|
||||
/**
|
||||
* Get items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item by index
|
||||
*
|
||||
* @param int $index
|
||||
* @return mixed
|
||||
*/
|
||||
public function getItem($index)
|
||||
{
|
||||
if (array_key_exists($index, $this->items)) {
|
||||
return $this->items[$index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item
|
||||
*
|
||||
* @param int $index
|
||||
* @param mixed $item
|
||||
*/
|
||||
public function setItem($index, $item)
|
||||
{
|
||||
if (array_key_exists($index, $this->items)) {
|
||||
$this->items[$index] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new item
|
||||
*
|
||||
* @param mixed $item
|
||||
* @return int
|
||||
*/
|
||||
public function addItem($item)
|
||||
{
|
||||
$index = $this->countItems() + 1;
|
||||
$this->items[$index] = $item;
|
||||
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item count
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countItems()
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Collection;
|
||||
|
||||
/**
|
||||
* Endnotes collection
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Endnotes extends AbstractCollection
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Collection;
|
||||
|
||||
/**
|
||||
* Footnotes collection
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Footnotes extends AbstractCollection
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Collection;
|
||||
|
||||
/**
|
||||
* Titles collection
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Titles extends AbstractCollection
|
||||
{
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
|
@ -14,7 +22,7 @@ namespace PhpOffice\PhpWord;
|
|||
*/
|
||||
class DocumentProperties
|
||||
{
|
||||
/** Constants */
|
||||
/** @const string Property type constants */
|
||||
const PROPERTY_TYPE_BOOLEAN = 'b';
|
||||
const PROPERTY_TYPE_INTEGER = 'i';
|
||||
const PROPERTY_TYPE_FLOAT = 'f';
|
||||
|
|
@ -408,8 +416,9 @@ class DocumentProperties
|
|||
{
|
||||
if ($this->isCustomPropertySet($propertyName)) {
|
||||
return $this->customProperties[$propertyName]['value'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -422,8 +431,9 @@ class DocumentProperties
|
|||
{
|
||||
if ($this->isCustomPropertySet($propertyName)) {
|
||||
return $this->customProperties[$propertyName]['type'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -478,49 +488,23 @@ class DocumentProperties
|
|||
*/
|
||||
public static function convertProperty($propertyValue, $propertyType)
|
||||
{
|
||||
switch ($propertyType) {
|
||||
case 'empty': // Empty
|
||||
$conversion = self::getConversion($propertyType);
|
||||
|
||||
switch ($conversion) {
|
||||
case 'empty': // Empty
|
||||
return '';
|
||||
case 'null': // Null
|
||||
case 'null': // Null
|
||||
return null;
|
||||
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 'int': // Signed integer
|
||||
return (int) $propertyValue;
|
||||
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
|
||||
case 'uint': // Unsigned integer
|
||||
return abs((int) $propertyValue);
|
||||
case 'r4': // 4-Byte Real Number
|
||||
case 'r8': // 8-Byte Real Number
|
||||
case 'decimal': // Decimal
|
||||
case 'float': // Float
|
||||
return (float) $propertyValue;
|
||||
case 'date': // Date and Time
|
||||
case 'filetime': // File Time
|
||||
case 'date': // Date
|
||||
return strtotime($propertyValue);
|
||||
case 'bool': // Boolean
|
||||
case 'bool': // Boolean
|
||||
return ($propertyValue == 'true') ? true : false;
|
||||
case 'lpstr': // LPSTR
|
||||
case 'lpwstr': // LPWSTR
|
||||
case 'bstr': // Basic String
|
||||
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;
|
||||
}
|
||||
|
||||
return $propertyValue;
|
||||
|
|
@ -559,10 +543,36 @@ class DocumentProperties
|
|||
*/
|
||||
private function setValue($value, $default)
|
||||
{
|
||||
if (is_null($value) || $value == '') {
|
||||
if ($value === null || $value == '') {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get conversion model depending on property type
|
||||
*
|
||||
* @param string $propertyType
|
||||
* @return string
|
||||
*/
|
||||
private static function getConversion($propertyType)
|
||||
{
|
||||
$conversions = array(
|
||||
'empty' => array('empty'),
|
||||
'null' => array('null'),
|
||||
'int' => array('i1', 'i2', 'i4', 'i8', 'int'),
|
||||
'uint' => array('ui1', 'ui2', 'ui4', 'ui8', 'uint'),
|
||||
'float' => array('r4', 'r8', 'decimal'),
|
||||
'bool' => array('bool'),
|
||||
'date' => array('date', 'filetime'),
|
||||
);
|
||||
foreach ($conversions as $conversion => $types) {
|
||||
if (in_array($propertyType, $types)) {
|
||||
return $conversion;
|
||||
}
|
||||
}
|
||||
|
||||
return 'string';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Endnotes;
|
||||
use PhpOffice\PhpWord\Footnotes;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\TOC as Titles;
|
||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
|
||||
/**
|
||||
* Container abstract class
|
||||
*
|
||||
* @method Text addText($text, $fStyle = null, $pStyle = null)
|
||||
* @method TextRun addTextRun($pStyle = null)
|
||||
* @method Link addLink($target, $text = null, $fStyle = null, $pStyle = null)
|
||||
* @method PreserveText addPreserveText($text, $fStyle = null, $pStyle = null)
|
||||
* @method void addTextBreak($count = 1, $fStyle = null, $pStyle = null)
|
||||
* @method ListItem addListItem($text, $depth = 0, $fStyle = null, $listStyle = null, $pStyle = null)
|
||||
* @method ListItemRun addListItemRun($depth = 0, $listStyle = null, $pStyle = null)
|
||||
* @method Table addTable($style = null)
|
||||
* @method Image addImage($source, $style = null, $isWatermark = false)
|
||||
* @method Object addObject($source, $style = null)
|
||||
* @method Footnote addFootnote($pStyle = null)
|
||||
* @method Endnote addEndnote($pStyle = null)
|
||||
* @method CheckBox addCheckBox($name, $text, $fStyle = null, $pStyle = null)
|
||||
* @method TextBox addTextBox($style = null)
|
||||
* @method Field addField($type = null, $properties = array(), $options = array())
|
||||
* @method Line addLine($lineStyle = null)
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
abstract class AbstractContainer extends AbstractElement
|
||||
|
|
@ -32,13 +52,104 @@ abstract class AbstractContainer extends AbstractElement
|
|||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Set element index and unique id, and add element into elements collection
|
||||
* Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function addElement(AbstractElement $element)
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Magic method to catch all 'addElement' variation
|
||||
*
|
||||
* This removes addText, addTextRun, etc. When adding new element, we have to
|
||||
* add the model in the class docblock with `@method`.
|
||||
*
|
||||
* Warning: This makes capitalization matters, e.g. addCheckbox or addcheckbox won't work.
|
||||
*
|
||||
* @param mixed $function
|
||||
* @param mixed $args
|
||||
* @return \PhpOffice\PhpWord\Element\AbstractElement
|
||||
*/
|
||||
public function __call($function, $args)
|
||||
{
|
||||
$elements = array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak',
|
||||
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'Footnote',
|
||||
'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line');
|
||||
$functions = array();
|
||||
for ($i = 0; $i < count($elements); $i++) {
|
||||
$functions[$i] = 'add' . $elements[$i];
|
||||
}
|
||||
|
||||
// Run valid `add` command
|
||||
if (in_array($function, $functions)) {
|
||||
$element = str_replace('add', '', $function);
|
||||
|
||||
// Special case for TextBreak
|
||||
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
|
||||
if ($element == 'TextBreak') {
|
||||
@list($count, $fontStyle, $paragraphStyle) = $args; // Suppress error
|
||||
if ($count === null) {
|
||||
$count = 1;
|
||||
}
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$this->addElement($element, $fontStyle, $paragraphStyle);
|
||||
}
|
||||
|
||||
// All other elements
|
||||
} else {
|
||||
array_unshift($args, $element); // Prepend element name to the beginning of args array
|
||||
return call_user_func_array(array($this, 'addElement'), $args);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add element
|
||||
*
|
||||
* Each element has different number of parameters passed
|
||||
*
|
||||
* @param string $elementName
|
||||
* @return \PhpOffice\PhpWord\Element\AbstractElement
|
||||
*/
|
||||
protected function addElement($elementName)
|
||||
{
|
||||
$elementClass = __NAMESPACE__ . '\\' . $elementName;
|
||||
$this->checkValidity($elementName);
|
||||
|
||||
// Get arguments
|
||||
$args = func_get_args();
|
||||
$withoutP = in_array($this->container, array('TextRun', 'Footnote', 'Endnote', 'ListItemRun', 'Field'));
|
||||
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
|
||||
$args[3] = null; // Remove paragraph style for texts in textrun
|
||||
}
|
||||
$source = '';
|
||||
if (count($args) > 1) {
|
||||
$source = $args[1];
|
||||
}
|
||||
|
||||
// Create element using reflection
|
||||
$reflection = new \ReflectionClass($elementClass);
|
||||
$elementArgs = $args;
|
||||
array_shift($elementArgs); // Shift the $elementName off the beginning of array
|
||||
|
||||
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
||||
$element = $reflection->newInstanceArgs($elementArgs);
|
||||
|
||||
// Set nested level and relation Id
|
||||
$this->setElementNestedLevel($element);
|
||||
$this->setElementRelationId($element, $elementName, $source);
|
||||
|
||||
// Set other properties and add element into collection
|
||||
$element->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$element->setElementIndex($this->countElements() + 1);
|
||||
$element->setElementId();
|
||||
$element->setPhpWord($this->phpWord);
|
||||
|
||||
$this->elements[] = $element;
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +165,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||
/**
|
||||
* Count elements
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function countElements()
|
||||
{
|
||||
|
|
@ -62,331 +173,97 @@ abstract class AbstractContainer extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Add text element
|
||||
*
|
||||
* @param string $text
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return Text
|
||||
* Set element nested level based on container; add one when it's inside a cell
|
||||
*/
|
||||
public function addText($text, $fontStyle = null, $paragraphStyle = null)
|
||||
private function setElementNestedLevel(AbstractElement $element)
|
||||
{
|
||||
$this->checkValidity('text');
|
||||
|
||||
// Reset paragraph style for footnote and textrun. They have their own
|
||||
if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) {
|
||||
$paragraphStyle = null;
|
||||
}
|
||||
|
||||
$text = String::toUTF8($text);
|
||||
$textObject = new Text($text, $fontStyle, $paragraphStyle);
|
||||
$textObject->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($textObject);
|
||||
|
||||
return $textObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add textrun element
|
||||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @return TextRun
|
||||
*/
|
||||
public function addTextRun($paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('textrun');
|
||||
|
||||
$textRun = new TextRun($paragraphStyle);
|
||||
$textRun->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($textRun);
|
||||
|
||||
return $textRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link element
|
||||
*
|
||||
* @param string $linkSrc
|
||||
* @param string $linkName
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return Link
|
||||
*/
|
||||
public function addLink($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('link');
|
||||
$elementDocPart = $this->checkElementDocPart();
|
||||
|
||||
$link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle);
|
||||
$link->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$rId = Media::addElement($elementDocPart, 'link', $linkSrc);
|
||||
$link->setRelationId($rId);
|
||||
$this->addElement($link);
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Title Element
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $depth
|
||||
* @return Title
|
||||
* @todo Enable title element in other containers
|
||||
*/
|
||||
public function addTitle($text, $depth = 1)
|
||||
{
|
||||
$this->checkValidity('title');
|
||||
|
||||
$styles = Style::getStyles();
|
||||
if (array_key_exists('Heading_' . $depth, $styles)) {
|
||||
$style = 'Heading' . $depth;
|
||||
if ($this->container == 'Cell') {
|
||||
$element->setNestedLevel($this->getNestedLevel() + 1);
|
||||
} else {
|
||||
$style = null;
|
||||
}
|
||||
$text = String::toUTF8($text);
|
||||
$title = new Title($text, $depth, $style);
|
||||
$title->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$data = Titles::addTitle($text, $depth);
|
||||
$anchor = $data[0];
|
||||
$bookmarkId = $data[1];
|
||||
$title->setAnchor($anchor);
|
||||
$title->setBookmarkId($bookmarkId);
|
||||
$this->addElement($title);
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text element
|
||||
*
|
||||
* @param string $text
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return PreserveText
|
||||
*/
|
||||
public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('preservetext');
|
||||
|
||||
$preserveText = new PreserveText(String::toUTF8($text), $fontStyle, $paragraphStyle);
|
||||
$preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($preserveText);
|
||||
|
||||
return $preserveText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break element
|
||||
*
|
||||
* @param int $count
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('textbreak');
|
||||
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$textBreak = new TextBreak($fontStyle, $paragraphStyle);
|
||||
$textBreak->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($textBreak);
|
||||
$element->setNestedLevel($this->getNestedLevel());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add listitem element
|
||||
* Set relation Id
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $depth
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $styleList
|
||||
* @param mixed $paragraphStyle
|
||||
* @return ListItem
|
||||
* @param string $elementName
|
||||
* @param string $source
|
||||
*/
|
||||
public function addListItem($text, $depth = 0, $fontStyle = null, $styleList = null, $paragraphStyle = null)
|
||||
private function setElementRelationId(AbstractElement $element, $elementName, $source)
|
||||
{
|
||||
$this->checkValidity('listitem');
|
||||
$mediaContainer = $this->getMediaContainer();
|
||||
$hasMediaRelation = in_array($elementName, array('Link', 'Image', 'Object'));
|
||||
$hasOtherRelation = in_array($elementName, array('Footnote', 'Endnote', 'Title'));
|
||||
|
||||
$listItem = new ListItem(String::toUTF8($text), $depth, $fontStyle, $styleList, $paragraphStyle);
|
||||
$listItem->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($listItem);
|
||||
|
||||
return $listItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add table element
|
||||
*
|
||||
* @param mixed $style
|
||||
* @return Table
|
||||
*/
|
||||
public function addTable($style = null)
|
||||
{
|
||||
$this->checkValidity('table');
|
||||
|
||||
$table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
|
||||
$this->addElement($table);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image element
|
||||
*
|
||||
* @param string $src
|
||||
* @param mixed $style Image style
|
||||
* @param boolean $isWatermark
|
||||
* @return Image
|
||||
*/
|
||||
public function addImage($src, $style = null, $isWatermark = false)
|
||||
{
|
||||
$this->checkValidity('image');
|
||||
$elementDocPart = $this->checkElementDocPart();
|
||||
|
||||
$image = new Image($src, $style, $isWatermark);
|
||||
$image->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$rId = Media::addElement($elementDocPart, 'image', $src, $image);
|
||||
$image->setRelationId($rId);
|
||||
$this->addElement($image);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add OLE-object element
|
||||
*
|
||||
* All exceptions should be handled by \PhpOffice\PhpWord\Element\Object
|
||||
*
|
||||
* @param string $src
|
||||
* @param mixed $style
|
||||
* @return Object
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
* @todo Enable OLE object element in header and footer
|
||||
*/
|
||||
public function addObject($src, $style = null)
|
||||
{
|
||||
$this->checkValidity('object');
|
||||
$elementDocPart = $this->checkElementDocPart();
|
||||
|
||||
$object = new Object($src, $style);
|
||||
$object->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
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);
|
||||
}
|
||||
$icon = realpath(__DIR__ . "/../resources/{$ext}.png");
|
||||
$rId = Media::addElement($elementDocPart, 'object', $src);
|
||||
$object->setRelationId($rId);
|
||||
$rIdimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
|
||||
$object->setImageRelationId($rIdimg);
|
||||
$this->addElement($object);
|
||||
|
||||
return $object;
|
||||
} else {
|
||||
throw new InvalidObjectException();
|
||||
// Set relation Id for media elements (link, image, object; legacy of OOXML)
|
||||
// Only Image that needs to be passed to Media class
|
||||
if ($hasMediaRelation) {
|
||||
/** @var \PhpOffice\PhpWord\Element\Image $element Type hint */
|
||||
$image = ($elementName == 'Image') ? $element : null;
|
||||
$rId = Media::addElement($mediaContainer, strtolower($elementName), $source, $image);
|
||||
$element->setRelationId($rId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add footnote element
|
||||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @return Footnote
|
||||
*/
|
||||
public function addFootnote($paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('footnote');
|
||||
// Set relation Id for icon of object element
|
||||
if ($elementName == 'Object') {
|
||||
/** @var \PhpOffice\PhpWord\Element\Object $element Type hint */
|
||||
$rIdIcon = Media::addElement($mediaContainer, 'image', $element->getIcon(), new Image($element->getIcon()));
|
||||
$element->setImageRelationId($rIdIcon);
|
||||
}
|
||||
|
||||
$footnote = new Footnote($paragraphStyle);
|
||||
$rId = Footnotes::addElement($footnote);
|
||||
|
||||
$footnote->setDocPart('footnote', $this->getDocPartId());
|
||||
$footnote->setRelationId($rId);
|
||||
$this->addElement($footnote);
|
||||
|
||||
return $footnote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add endnote element
|
||||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @return Endnote
|
||||
*/
|
||||
public function addEndnote($paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('endnote');
|
||||
|
||||
$endnote = new Endnote($paragraphStyle);
|
||||
$rId = Endnotes::addElement($endnote);
|
||||
|
||||
$endnote->setDocPart('endnote', $this->getDocPartId());
|
||||
$endnote->setRelationId($rId);
|
||||
$this->addElement($endnote);
|
||||
|
||||
return $endnote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a CheckBox Element
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $text
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return CheckBox
|
||||
*/
|
||||
public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->checkValidity('checkbox');
|
||||
|
||||
$checkBox = new CheckBox(String::toUTF8($name), String::toUTF8($text), $fontStyle, $paragraphStyle);
|
||||
$checkBox->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$this->addElement($checkBox);
|
||||
|
||||
return $checkBox;
|
||||
// Set relation Id for elements that will be registered in the Collection subnamespaces
|
||||
if ($hasOtherRelation && $this->phpWord instanceof PhpWord) {
|
||||
$addMethod = "add{$elementName}";
|
||||
$rId = $this->phpWord->$addMethod($element);
|
||||
$element->setRelationId($rId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a method is allowed for the current container
|
||||
*
|
||||
* @param string $method
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
private function checkValidity($method)
|
||||
{
|
||||
// Valid containers for each element
|
||||
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote');
|
||||
$allContainers = array(
|
||||
'Section', 'Header', 'Footer', 'Footnote', 'Endnote',
|
||||
'Cell', 'TextRun', 'TextBox', 'ListItemRun',
|
||||
);
|
||||
$validContainers = array(
|
||||
'text' => $allContainers,
|
||||
'link' => $allContainers,
|
||||
'textbreak' => $allContainers,
|
||||
'image' => $allContainers,
|
||||
'object' => $allContainers,
|
||||
'textrun' => array('section', 'header', 'footer', 'cell'),
|
||||
'listitem' => array('section', 'header', 'footer', 'cell'),
|
||||
'checkbox' => array('section', 'header', 'footer', 'cell'),
|
||||
'table' => array('section', 'header', 'footer'),
|
||||
'footnote' => array('section', 'textrun', 'cell'),
|
||||
'endnote' => array('section', 'textrun', 'cell'),
|
||||
'preservetext' => array('header', 'footer', 'cell'),
|
||||
'title' => array('section'),
|
||||
'Text' => $allContainers,
|
||||
'Link' => $allContainers,
|
||||
'TextBreak' => $allContainers,
|
||||
'Image' => $allContainers,
|
||||
'Object' => $allContainers,
|
||||
'Field' => $allContainers,
|
||||
'Line' => $allContainers,
|
||||
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell'),
|
||||
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
|
||||
'Footnote' => array('Section', 'TextRun', 'Cell'),
|
||||
'Endnote' => array('Section', 'TextRun', 'Cell'),
|
||||
'PreserveText' => array('Header', 'Footer', 'Cell'),
|
||||
);
|
||||
// Special condition, e.g. preservetext can only exists in cell when
|
||||
// the cell is located in header or footer
|
||||
$validSubcontainers = array(
|
||||
'preservetext' => array(array('cell'), array('header', 'footer')),
|
||||
'footnote' => array(array('cell', 'textrun'), array('section')),
|
||||
'endnote' => array(array('cell', 'textrun'), array('section')),
|
||||
'PreserveText' => array(array('Cell'), array('Header', 'Footer')),
|
||||
'Footnote' => array(array('Cell', 'TextRun'), array('Section')),
|
||||
'Endnote' => array(array('Cell', 'TextRun'), array('Section')),
|
||||
);
|
||||
|
||||
// Check if a method is valid for current container
|
||||
if (array_key_exists($method, $validContainers)) {
|
||||
if (!in_array($this->container, $validContainers[$method])) {
|
||||
throw new \BadMethodCallException();
|
||||
throw new \BadMethodCallException("Cannot add $method in $this->container.");
|
||||
}
|
||||
}
|
||||
// Check if a method is valid for current container, located in other container
|
||||
|
|
@ -396,7 +273,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||
$allowedDocParts = $rules[1];
|
||||
foreach ($containers as $container) {
|
||||
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
|
||||
throw new \BadMethodCallException();
|
||||
throw new \BadMethodCallException("Cannot add $method in $this->container.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -405,16 +282,21 @@ abstract class AbstractContainer extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Return element location in document: section, headerx, or footerx
|
||||
* Return media element (image, object, link) container name
|
||||
*
|
||||
* @return string section|headerx|footerx|footnote|endnote
|
||||
*/
|
||||
private function checkElementDocPart()
|
||||
private function getMediaContainer()
|
||||
{
|
||||
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
|
||||
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
|
||||
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
|
||||
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
|
||||
$partName = $this->container;
|
||||
if (in_array($partName, array('Cell', 'TextRun', 'TextBox', 'ListItemRun'))) {
|
||||
$partName = $this->getDocPart();
|
||||
}
|
||||
if ($partName == 'Header' || $partName == 'Footer') {
|
||||
$partName .= $this->getDocPartId();
|
||||
}
|
||||
|
||||
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
|
||||
return strtolower($partName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -422,6 +304,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||
*
|
||||
* @param string $src
|
||||
* @param mixed $style
|
||||
* @return \PhpOffice\PhpWord\Element\Image
|
||||
* @deprecated 0.9.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
|
@ -434,6 +317,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||
* Create textrun element
|
||||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Element\TextRun
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
|
@ -446,6 +330,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||
* Create footnote element
|
||||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Element\Footnote
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
|
||||
/**
|
||||
|
|
@ -19,11 +28,11 @@ use PhpOffice\PhpWord\Style;
|
|||
abstract class AbstractElement
|
||||
{
|
||||
/**
|
||||
* Container type section|header|footer|cell|textrun|footnote|endnote
|
||||
* PhpWord object
|
||||
*
|
||||
* @var string
|
||||
* @var \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
protected $container;
|
||||
protected $phpWord;
|
||||
|
||||
/**
|
||||
* Section Id
|
||||
|
|
@ -41,7 +50,7 @@ abstract class AbstractElement
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $docPart = 'section';
|
||||
protected $docPart = 'Section';
|
||||
|
||||
/**
|
||||
* Document part Id
|
||||
|
|
@ -50,21 +59,21 @@ abstract class AbstractElement
|
|||
* because the max number of header/footer in every page is 3, i.e.
|
||||
* AUTO, FIRST, and EVEN (AUTO = ODD)
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $docPartId = 1;
|
||||
|
||||
/**
|
||||
* Index of element in the elements collection (start with 1)
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $elementIndex = 1;
|
||||
|
||||
/**
|
||||
* Unique Id for element
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $elementId;
|
||||
|
||||
|
|
@ -75,10 +84,39 @@ abstract class AbstractElement
|
|||
*/
|
||||
protected $relationId;
|
||||
|
||||
/**
|
||||
* Depth of table container nested level; Primarily used for RTF writer/reader
|
||||
*
|
||||
* 0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $nestedLevel = 0;
|
||||
|
||||
/**
|
||||
* Get PhpWord
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
public function getPhpWord()
|
||||
{
|
||||
return $this->phpWord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PhpWord as reference
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
public function setPhpWord(PhpWord &$phpWord = null)
|
||||
{
|
||||
$this->phpWord = &$phpWord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get section number
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function getSectionId()
|
||||
{
|
||||
|
|
@ -89,7 +127,7 @@ abstract class AbstractElement
|
|||
* Set doc part
|
||||
*
|
||||
* @param string $docPart
|
||||
* @param integer $docPartId
|
||||
* @param int $docPartId
|
||||
*/
|
||||
public function setDocPart($docPart, $docPartId = 1)
|
||||
{
|
||||
|
|
@ -110,7 +148,7 @@ abstract class AbstractElement
|
|||
/**
|
||||
* Get doc part Id
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function getDocPartId()
|
||||
{
|
||||
|
|
@ -168,21 +206,41 @@ abstract class AbstractElement
|
|||
/**
|
||||
* Set relation Id
|
||||
*
|
||||
* @param int $rId
|
||||
* @param int $value
|
||||
*/
|
||||
public function setRelationId($rId)
|
||||
public function setRelationId($value)
|
||||
{
|
||||
$this->relationId = $rId;
|
||||
$this->relationId = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if element is located in section doc part (as opposed to header/footer)
|
||||
* Get nested level
|
||||
*
|
||||
* @return boolean
|
||||
* @return int
|
||||
*/
|
||||
public function getNestedLevel()
|
||||
{
|
||||
return $this->nestedLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set nested level
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function setNestedLevel($value)
|
||||
{
|
||||
$this->nestedLevel = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if element is located in Section doc part (as opposed to Header/Footer)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInSection()
|
||||
{
|
||||
return ($this->docPart == 'section');
|
||||
return ($this->docPart == 'Section');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -190,14 +248,13 @@ abstract class AbstractElement
|
|||
*
|
||||
* @param mixed $styleObject Style object
|
||||
* @param mixed $styleValue Style value
|
||||
* @param boolean $returnObject Always return object
|
||||
* @param bool $returnObject Always return object
|
||||
* @return mixed
|
||||
*/
|
||||
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
|
||||
{
|
||||
if (!is_null($styleValue) && is_array($styleValue)) {
|
||||
foreach ($styleValue as $key => $value) {
|
||||
$styleObject->setStyleValue($key, $value);
|
||||
}
|
||||
$styleObject->setStyleByArray($styleValue);
|
||||
$style = $styleObject;
|
||||
} else {
|
||||
$style = $returnObject ? $styleObject : $styleValue;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -16,6 +24,11 @@ use PhpOffice\PhpWord\Style\Cell as CellStyle;
|
|||
*/
|
||||
class Cell extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'Cell';
|
||||
|
||||
/**
|
||||
* Cell width
|
||||
*
|
||||
|
|
@ -28,22 +41,18 @@ class Cell extends AbstractContainer
|
|||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Cell
|
||||
*/
|
||||
private $cellStyle;
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param string $docPart section|header|footer
|
||||
* @param int $docPartId
|
||||
* @param int $width
|
||||
* @param array|\PhpOffice\PhpWord\Style\Cell $style
|
||||
*/
|
||||
public function __construct($docPart, $docPartId, $width = null, $style = null)
|
||||
public function __construct($width = null, $style = null)
|
||||
{
|
||||
$this->container = 'cell';
|
||||
$this->setDocPart($docPart, $docPartId);
|
||||
$this->width = $width;
|
||||
$this->cellStyle = $this->setStyle(new CellStyle(), $style, true);
|
||||
$this->style = $this->setStyle(new CellStyle(), $style, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +62,7 @@ class Cell extends AbstractContainer
|
|||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->cellStyle;
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
|
||||
/**
|
||||
* Check box element
|
||||
*/
|
||||
|
|
@ -44,7 +54,7 @@ class CheckBox extends Text
|
|||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->name = String::toUTF8($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -18,6 +26,11 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
|||
*/
|
||||
class Endnote extends Footnote
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'Endnote';
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
|
|
@ -25,7 +38,6 @@ class Endnote extends Footnote
|
|||
*/
|
||||
public function __construct($paragraphStyle = null)
|
||||
{
|
||||
$this->container = 'endnote';
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
/**
|
||||
* Field element
|
||||
*
|
||||
* @since 0.11.0
|
||||
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_SimpleField.html
|
||||
*/
|
||||
class Field extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* Field properties and options. Depending on type, a field can have different properties
|
||||
* and options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldsArray = array(
|
||||
'PAGE'=>array(
|
||||
'properties'=>array(
|
||||
'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
|
||||
),
|
||||
'options'=>array('PreserveFormat')
|
||||
),
|
||||
'NUMPAGES'=>array(
|
||||
'properties'=>array(
|
||||
'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
|
||||
'numformat' => array('0', '0,00', '#.##0', '#.##0,00', '€ #.##0,00(€ #.##0,00)', '0%', '0,00%')
|
||||
),
|
||||
'options'=>array('PreserveFormat')
|
||||
),
|
||||
'DATE'=>array(
|
||||
'properties'=> array(
|
||||
'dateformat' =>array('d-M-yyyy', 'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-M-yy', 'yyyy-MM-dd',
|
||||
'd-MMM-yy', 'd/M/yyyy', 'd MMM. yy', 'd/M/yy', 'MMM-yy', 'd-M-yyy H:mm', 'd-M-yyyy H:mm:ss',
|
||||
'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss')
|
||||
),
|
||||
'options'=>array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Field type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Field properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = array();
|
||||
|
||||
/**
|
||||
* Field options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* Create a new Field Element
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $properties
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($type = null, $properties = array(), $options = array())
|
||||
{
|
||||
$this->setType($type);
|
||||
$this->setProperties($properties);
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Field type
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setType($type = null)
|
||||
{
|
||||
if (isset($type)) {
|
||||
if (array_key_exists($type, $this->fieldsArray)) {
|
||||
$this->type = $type;
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Invalid type");
|
||||
}
|
||||
}
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Field type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Field properties
|
||||
*
|
||||
* @param array $properties
|
||||
* @return self
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setProperties($properties = array())
|
||||
{
|
||||
if (is_array($properties)) {
|
||||
foreach (array_keys($properties) as $propkey) {
|
||||
if (!(array_key_exists($propkey, $this->fieldsArray[$this->type]['properties']))) {
|
||||
throw new \InvalidArgumentException("Invalid property");
|
||||
}
|
||||
}
|
||||
$this->properties = array_merge($this->properties, $properties);
|
||||
}
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Field properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Field options
|
||||
*
|
||||
* @param array $options
|
||||
* @return self
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
{
|
||||
if (is_array($options)) {
|
||||
foreach (array_keys($options) as $optionkey) {
|
||||
if (!(array_key_exists($optionkey, $this->fieldsArray[$this->type]['options']))) {
|
||||
throw new \InvalidArgumentException("Invalid option");
|
||||
}
|
||||
}
|
||||
$this->options = array_merge($this->options, $options);
|
||||
}
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Field properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -14,30 +22,40 @@ namespace PhpOffice\PhpWord\Element;
|
|||
*/
|
||||
class Footer extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* Header/footer types constants
|
||||
*
|
||||
* @var string
|
||||
* @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
|
||||
*/
|
||||
const AUTO = 'default'; // default and odd pages
|
||||
const FIRST = 'first';
|
||||
const EVEN = 'even';
|
||||
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'Footer';
|
||||
|
||||
/**
|
||||
* Header type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = self::AUTO;
|
||||
protected $type = self::AUTO;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param int $sectionId
|
||||
* @param int $footerId
|
||||
* @param int $containerId
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct($sectionId, $footerId = 1, $type = self::AUTO)
|
||||
public function __construct($sectionId, $containerId = 1, $type = self::AUTO)
|
||||
{
|
||||
$this->container = 'footer';
|
||||
$this->sectionId = $sectionId;
|
||||
$this->setType($type);
|
||||
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $footerId);
|
||||
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $containerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +66,9 @@ class Footer extends AbstractContainer
|
|||
*/
|
||||
public function setType($value = self::AUTO)
|
||||
{
|
||||
if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
|
||||
$value = self::AUTO;
|
||||
}
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
|
|
@ -61,4 +82,34 @@ class Footer extends AbstractContainer
|
|||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset type to default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resetType()
|
||||
{
|
||||
return $this->type = self::AUTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* First page only header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function firstPage()
|
||||
{
|
||||
return $this->type = self::FIRST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Even numbered pages only
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function evenPage()
|
||||
{
|
||||
return $this->type = self::EVEN;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -16,6 +24,11 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
|||
*/
|
||||
class Footnote extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'Footnote';
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
|
|
@ -30,7 +43,6 @@ class Footnote extends AbstractContainer
|
|||
*/
|
||||
public function __construct($paragraphStyle = null)
|
||||
{
|
||||
$this->container = 'footnote';
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Image;
|
||||
|
||||
/**
|
||||
* Header element
|
||||
*/
|
||||
class Header extends AbstractContainer
|
||||
class Header extends Footer
|
||||
{
|
||||
/**
|
||||
* Header types constants
|
||||
*
|
||||
* @var string
|
||||
* @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
|
||||
* @var string Container type
|
||||
*/
|
||||
const AUTO = 'default'; // default and odd pages
|
||||
const FIRST = 'first';
|
||||
const EVEN = 'even';
|
||||
|
||||
/**
|
||||
* Header type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = self::AUTO;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param int $sectionId
|
||||
* @param int $headerId
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct($sectionId, $headerId = 1, $type = self::AUTO)
|
||||
{
|
||||
$this->container = 'header';
|
||||
$this->sectionId = $sectionId;
|
||||
$this->setType($type);
|
||||
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $headerId);
|
||||
}
|
||||
protected $container = 'Header';
|
||||
|
||||
/**
|
||||
* Add a Watermark Element
|
||||
|
|
@ -59,58 +38,4 @@ class Header extends AbstractContainer
|
|||
{
|
||||
return $this->addImage($src, $style, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set header type
|
||||
*
|
||||
* @param string $value
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public function setType($value = self::AUTO)
|
||||
{
|
||||
if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
|
||||
$value = self::AUTO;
|
||||
}
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get header type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset type to default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resetType()
|
||||
{
|
||||
return $this->type = self::AUTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* First page only header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function firstPage()
|
||||
{
|
||||
return $this->type = self::FIRST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Even numbered pages only
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function evenPage()
|
||||
{
|
||||
return $this->type = self::EVEN;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
||||
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +60,7 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $isWatermark;
|
||||
private $watermark;
|
||||
|
||||
/**
|
||||
* Image type
|
||||
|
|
@ -87,7 +95,7 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $isMemImage;
|
||||
private $memoryImage;
|
||||
|
||||
/**
|
||||
* Image target file name
|
||||
|
|
@ -108,14 +116,14 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @param string $source
|
||||
* @param mixed $style
|
||||
* @param boolean $isWatermark
|
||||
* @param boolean $watermark
|
||||
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
|
||||
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
||||
*/
|
||||
public function __construct($source, $style = null, $isWatermark = false)
|
||||
public function __construct($source, $style = null, $watermark = false)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->setIsWatermark($isWatermark);
|
||||
$this->setIsWatermark($watermark);
|
||||
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
||||
|
||||
$this->checkImage($source);
|
||||
|
|
@ -166,19 +174,19 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsWatermark()
|
||||
public function isWatermark()
|
||||
{
|
||||
return $this->isWatermark;
|
||||
return $this->watermark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set is watermark
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @param boolean $value
|
||||
*/
|
||||
public function setIsWatermark($pValue)
|
||||
public function setIsWatermark($value)
|
||||
{
|
||||
$this->isWatermark = $pValue;
|
||||
$this->watermark = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -226,9 +234,9 @@ class Image extends AbstractElement
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsMemImage()
|
||||
public function isMemImage()
|
||||
{
|
||||
return $this->isMemImage;
|
||||
return $this->memoryImage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -271,10 +279,83 @@ class Image extends AbstractElement
|
|||
$this->mediaIndex = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image string data
|
||||
*
|
||||
* @param bool $base64
|
||||
* @return string|null
|
||||
* @since 0.11.0
|
||||
*/
|
||||
public function getImageStringData($base64 = false)
|
||||
{
|
||||
$source = $this->source;
|
||||
$actualSource = null;
|
||||
$imageBinary = null;
|
||||
$imageData = null;
|
||||
$isTemp = false;
|
||||
|
||||
// Get actual source from archive image or other source
|
||||
// Return null if not found
|
||||
if ($this->sourceType == self::SOURCE_ARCHIVE) {
|
||||
$source = substr($source, 6);
|
||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
if ($zip->locateName($imageFilename)) {
|
||||
$isTemp = true;
|
||||
$zip->extractTo(sys_get_temp_dir(), $imageFilename);
|
||||
$actualSource = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
$actualSource = $source;
|
||||
}
|
||||
|
||||
// Can't find any case where $actualSource = null hasn't captured by
|
||||
// preceding exceptions. Please uncomment when you find the case and
|
||||
// put the case into Element\ImageTest.
|
||||
// if ($actualSource === null) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// Read image binary data and convert to hex/base64 string
|
||||
if ($this->sourceType == self::SOURCE_GD) {
|
||||
$imageResource = call_user_func($this->imageCreateFunc, $actualSource);
|
||||
ob_start();
|
||||
call_user_func($this->imageFunc, $imageResource);
|
||||
$imageBinary = ob_get_contents();
|
||||
ob_end_clean();
|
||||
} else {
|
||||
$fileHandle = fopen($actualSource, 'rb', false);
|
||||
if ($fileHandle !== false) {
|
||||
$imageBinary = fread($fileHandle, filesize($actualSource));
|
||||
fclose($fileHandle);
|
||||
}
|
||||
}
|
||||
if ($imageBinary !== null) {
|
||||
if ($base64) {
|
||||
$imageData = chunk_split(base64_encode($imageBinary));
|
||||
} else {
|
||||
$imageData = chunk_split(bin2hex($imageBinary));
|
||||
}
|
||||
}
|
||||
|
||||
// Delete temporary file if necessary
|
||||
if ($isTemp === true) {
|
||||
@unlink($actualSource);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check memory image, supported type, image functions, and proportional width/height
|
||||
*
|
||||
* @param string $source
|
||||
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
|
||||
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
||||
*/
|
||||
private function checkImage($source)
|
||||
{
|
||||
|
|
@ -314,14 +395,14 @@ class Image extends AbstractElement
|
|||
private function setSourceType($source)
|
||||
{
|
||||
if (stripos(strrev($source), strrev('.php')) === 0) {
|
||||
$this->isMemImage = true;
|
||||
$this->memoryImage = true;
|
||||
$this->sourceType = self::SOURCE_GD;
|
||||
} elseif (strpos($source, 'zip://') !== false) {
|
||||
$this->isMemImage = false;
|
||||
$this->memoryImage = false;
|
||||
$this->sourceType = self::SOURCE_ARCHIVE;
|
||||
} else {
|
||||
$this->isMemImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
|
||||
$this->sourceType = $this->isMemImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
|
||||
$this->memoryImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
|
||||
$this->sourceType = $this->memoryImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,8 +419,7 @@ class Image extends AbstractElement
|
|||
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||
$tempFilename = tempnam(sys_get_temp_dir(), 'PHPWordImage');
|
||||
|
||||
$zipClass = Settings::getZipClass();
|
||||
$zip = new $zipClass();
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
if ($zip->locateName($imageFilename)) {
|
||||
$imageContent = $zip->getFromName($imageFilename);
|
||||
|
|
@ -409,4 +489,26 @@ class Image extends AbstractElement
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is watermark
|
||||
*
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getIsWatermark()
|
||||
{
|
||||
return $this->isWatermark();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is memory image
|
||||
*
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getIsMemImage()
|
||||
{
|
||||
return $this->isMemImage();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Line as LineStyle;
|
||||
|
||||
/**
|
||||
* Line element
|
||||
*/
|
||||
class Line extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* Line style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Line
|
||||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* Create new line element
|
||||
*
|
||||
* @param mixed $style
|
||||
*/
|
||||
public function __construct($style = null)
|
||||
{
|
||||
$this->style = $this->setStyle(new LineStyle(), $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Line
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
|
|
@ -56,8 +65,8 @@ class Link extends AbstractElement
|
|||
*/
|
||||
public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->text = is_null($text) ? $target : $text;
|
||||
$this->target = String::toUTF8($target);
|
||||
$this->text = is_null($text) ? $this->target : String::toUTF8($text);
|
||||
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -17,27 +26,26 @@ use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
|||
class ListItem extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* ListItem Style
|
||||
* Element style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\ListItem
|
||||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* Textrun
|
||||
* Text object
|
||||
*
|
||||
* @var Text
|
||||
* @var \PhpOffice\PhpWord\Element\Text
|
||||
*/
|
||||
private $textObject;
|
||||
|
||||
/**
|
||||
* ListItem Depth
|
||||
* Depth
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $depth;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ListItem
|
||||
*
|
||||
|
|
@ -49,7 +57,7 @@ class ListItem extends AbstractElement
|
|||
*/
|
||||
public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->textObject = new Text($text, $fontStyle, $paragraphStyle);
|
||||
$this->textObject = new Text(String::toUTF8($text), $fontStyle, $paragraphStyle);
|
||||
$this->depth = $depth;
|
||||
|
||||
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
|
||||
|
|
@ -61,7 +69,9 @@ class ListItem extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get ListItem style
|
||||
* Get style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\ListItem
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
|
|
@ -69,7 +79,9 @@ class ListItem extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get ListItem TextRun
|
||||
* Get Text object
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Element\Text
|
||||
*/
|
||||
public function getTextObject()
|
||||
{
|
||||
|
|
@ -77,10 +89,23 @@ class ListItem extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get ListItem depth
|
||||
* Get depth
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDepth()
|
||||
{
|
||||
return $this->depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text
|
||||
*
|
||||
* @return string
|
||||
* @since 0.11.0
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->textObject->getText();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
/**
|
||||
* List item element
|
||||
*/
|
||||
class ListItemRun extends TextRun
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'ListItemRun';
|
||||
|
||||
/**
|
||||
* ListItem Style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\ListItem
|
||||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* ListItem Depth
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $depth;
|
||||
|
||||
/**
|
||||
* Create a new ListItem
|
||||
*
|
||||
* @param int $depth
|
||||
* @param array|string|null $listStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function __construct($depth = 0, $listStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->depth = $depth;
|
||||
|
||||
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
|
||||
if (!is_null($listStyle) && is_string($listStyle)) {
|
||||
$this->style = new ListItemStyle($listStyle);
|
||||
} else {
|
||||
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
|
||||
}
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ListItem style
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ListItem depth
|
||||
*/
|
||||
public function getDepth()
|
||||
{
|
||||
return $this->depth;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -30,6 +39,13 @@ class Object extends AbstractElement
|
|||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* Icon
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $icon;
|
||||
|
||||
/**
|
||||
* Image Relation ID
|
||||
*
|
||||
|
|
@ -40,35 +56,33 @@ class Object extends AbstractElement
|
|||
/**
|
||||
* Create a new Ole-Object Element
|
||||
*
|
||||
* @param string $src
|
||||
* @param string $source
|
||||
* @param mixed $style
|
||||
* @throws \PhpOffice\PhpWord\Exception\InvalidObjectException
|
||||
*/
|
||||
public function __construct($src, $style = null)
|
||||
public function __construct($source, $style = null)
|
||||
{
|
||||
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
|
||||
$inf = pathinfo($src);
|
||||
$pathInfo = pathinfo($source);
|
||||
|
||||
if (file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
|
||||
$this->source = $src;
|
||||
if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
|
||||
$ext = $pathInfo['extension'];
|
||||
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
|
||||
$ext = substr($ext, 0, -1);
|
||||
}
|
||||
|
||||
$this->source = $source;
|
||||
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
||||
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
|
||||
|
||||
return $this;
|
||||
} else {
|
||||
return false;
|
||||
throw new InvalidObjectException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Image
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Source
|
||||
* Get object source
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -78,7 +92,27 @@ class Object extends AbstractElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get Image Relation ID
|
||||
* Get object style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Image
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object icon
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon()
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image relation ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
|
|
@ -45,14 +54,15 @@ class PreserveText extends AbstractElement
|
|||
* @param string $text
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
|
||||
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$this->text = String::toUTF8($text);
|
||||
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
if (isset($matches[0])) {
|
||||
$this->text = $matches;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -35,21 +43,18 @@ class Row extends AbstractElement
|
|||
/**
|
||||
* Row cells
|
||||
*
|
||||
* @var array
|
||||
* @var \PhpOffice\PhpWord\Element\Cell[]
|
||||
*/
|
||||
private $cells = array();
|
||||
|
||||
/**
|
||||
* Create a new table row
|
||||
*
|
||||
* @param string $docPart
|
||||
* @param int $docPartId
|
||||
* @param int $height
|
||||
* @param mixed $style
|
||||
*/
|
||||
public function __construct($docPart, $docPartId, $height = null, $style = null)
|
||||
public function __construct($height = null, $style = null)
|
||||
{
|
||||
$this->setDocPart($docPart, $docPartId);
|
||||
$this->height = $height;
|
||||
$this->style = $this->setStyle(new RowStyle(), $style, true);
|
||||
}
|
||||
|
|
@ -59,18 +64,23 @@ class Row extends AbstractElement
|
|||
*
|
||||
* @param int $width
|
||||
* @param mixed $style
|
||||
* @return \PhpOffice\PhpWord\Element\Cell
|
||||
*/
|
||||
public function addCell($width = null, $style = null)
|
||||
{
|
||||
$cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style);
|
||||
$cell = new Cell($width, $style);
|
||||
$cell->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$cell->setPhpWord($this->phpWord);
|
||||
$cell->setNestedLevel($this->getNestedLevel());
|
||||
$this->cells[] = $cell;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all cells
|
||||
*
|
||||
* @return array
|
||||
* @return \PhpOffice\PhpWord\Element\Cell[]
|
||||
*/
|
||||
public function getCells()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,24 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Style\Section as SectionSettings;
|
||||
use PhpOffice\PhpWord\Element\PageBreak;
|
||||
use PhpOffice\PhpWord\Element\TOC;
|
||||
|
||||
/**
|
||||
* Section
|
||||
*/
|
||||
class Section extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'Section';
|
||||
|
||||
/**
|
||||
* Section settings
|
||||
*
|
||||
|
|
@ -48,7 +59,6 @@ class Section extends AbstractContainer
|
|||
*/
|
||||
public function __construct($sectionCount, $settings = null)
|
||||
{
|
||||
$this->container = 'section';
|
||||
$this->sectionId = $sectionCount;
|
||||
$this->setDocPart($this->container, $this->sectionId);
|
||||
$this->settings = new SectionSettings();
|
||||
|
|
@ -82,12 +92,24 @@ class Section extends AbstractContainer
|
|||
return $this->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Title Element
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $depth
|
||||
* @return \PhpOffice\PhpWord\Element\Title
|
||||
*/
|
||||
public function addTitle($text, $depth = 1)
|
||||
{
|
||||
return $this->addElement('Title', $text, $depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a PageBreak Element
|
||||
*/
|
||||
public function addPageBreak()
|
||||
{
|
||||
$this->elements[] = new PageBreak();
|
||||
return $this->addElement('PageBreak');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,9 +123,7 @@ class Section extends AbstractContainer
|
|||
*/
|
||||
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
|
||||
{
|
||||
$toc = new TOC($fontStyle, $tocStyle, $minDepth, $maxDepth);
|
||||
$this->elements[] = $toc;
|
||||
return $toc;
|
||||
return $this->addElement('TOC', $fontStyle, $tocStyle, $minDepth, $maxDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -179,14 +199,17 @@ class Section extends AbstractContainer
|
|||
*/
|
||||
private function addHeaderFooter($type = Header::AUTO, $header = true)
|
||||
{
|
||||
$containerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
|
||||
($header ? 'Header' : 'Footer');
|
||||
$collectionArray = $header ? 'headers' : 'footers';
|
||||
$containerClass = 'PhpOffice\\PhpWord\\Element\\';
|
||||
$containerClass .= ($header ? 'Header' : 'Footer');
|
||||
$collection = &$this->$collectionArray;
|
||||
|
||||
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
|
||||
$index = count($collection);
|
||||
/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
|
||||
$container = new $containerClass($this->sectionId, ++$index, $type);
|
||||
$container->setPhpWord($this->phpWord);
|
||||
|
||||
$collection[$index] = $container;
|
||||
return $container;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\TOC as Titles;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
|
||||
|
||||
|
|
@ -60,20 +68,14 @@ class TOC extends AbstractElement
|
|||
$this->TOCStyle = new TOCStyle();
|
||||
|
||||
if (!is_null($tocStyle) && is_array($tocStyle)) {
|
||||
foreach ($tocStyle as $key => $value) {
|
||||
$this->TOCStyle->setStyleValue($key, $value);
|
||||
}
|
||||
$this->TOCStyle->setStyleByArray($tocStyle);
|
||||
}
|
||||
|
||||
if (!is_null($fontStyle)) {
|
||||
if (is_array($fontStyle)) {
|
||||
$this->fontStyle = new Font();
|
||||
foreach ($fontStyle as $key => $value) {
|
||||
$this->fontStyle->setStyleValue($key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->fontStyle = $fontStyle;
|
||||
}
|
||||
if (!is_null($fontStyle) && is_array($fontStyle)) {
|
||||
$this->fontStyle = new Font();
|
||||
$this->fontStyle->setStyleByArray($fontStyle);
|
||||
} else {
|
||||
$this->fontStyle = $fontStyle;
|
||||
}
|
||||
|
||||
$this->minDepth = $minDepth;
|
||||
|
|
@ -87,16 +89,21 @@ class TOC extends AbstractElement
|
|||
*/
|
||||
public function getTitles()
|
||||
{
|
||||
$titles = Titles::getTitles();
|
||||
if (!$this->phpWord instanceof PhpWord) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$titles = $this->phpWord->getTitles()->getItems();
|
||||
foreach ($titles as $i => $title) {
|
||||
if ($this->minDepth > $title['depth']) {
|
||||
/** @var \PhpOffice\PhpWord\Element\Title $title Type hint */
|
||||
$depth = $title->getDepth();
|
||||
if ($this->minDepth > $depth) {
|
||||
unset($titles[$i]);
|
||||
}
|
||||
if (($this->maxDepth != 0) && ($this->maxDepth < $title['depth'])) {
|
||||
if (($this->maxDepth != 0) && ($this->maxDepth < $depth)) {
|
||||
unset($titles[$i]);
|
||||
}
|
||||
}
|
||||
$titles = array_merge(array(), $titles);
|
||||
|
||||
return $titles;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -26,62 +34,65 @@ class Table extends AbstractElement
|
|||
/**
|
||||
* Table rows
|
||||
*
|
||||
* @var array
|
||||
* @var \PhpOffice\PhpWord\Element\Row[]
|
||||
*/
|
||||
private $rows = array();
|
||||
|
||||
/**
|
||||
* Table width
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
private $width = null;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new table
|
||||
*
|
||||
* @param string $docPart
|
||||
* @param integer $docPartId
|
||||
* @param mixed $style
|
||||
*/
|
||||
public function __construct($docPart, $docPartId, $style = null)
|
||||
public function __construct($style = null)
|
||||
{
|
||||
$this->setDocPart($docPart, $docPartId);
|
||||
$this->style = $this->setStyle(new TableStyle(), $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a row
|
||||
*
|
||||
* @param integer $height
|
||||
* @param int $height
|
||||
* @param mixed $style
|
||||
* @return \PhpOffice\PhpWord\Element\Row
|
||||
*/
|
||||
public function addRow($height = null, $style = null)
|
||||
{
|
||||
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
|
||||
$row = new Row($height, $style);
|
||||
$row->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$row->setPhpWord($this->phpWord);
|
||||
$row->setNestedLevel($this->getNestedLevel());
|
||||
$this->rows[] = $row;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cell
|
||||
*
|
||||
* @param integer $width
|
||||
* @param int $width
|
||||
* @param mixed $style
|
||||
* @return Cell
|
||||
* @return \PhpOffice\PhpWord\Element\Cell
|
||||
*/
|
||||
public function addCell($width = null, $style = null)
|
||||
{
|
||||
$index = count($this->rows) - 1;
|
||||
$cell = $this->rows[$index]->addCell($width, $style);
|
||||
$row = $this->rows[$index];
|
||||
$cell = $row->addCell($width, $style);
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rows
|
||||
*
|
||||
* @return array
|
||||
* @return \PhpOffice\PhpWord\Element\Row[]
|
||||
*/
|
||||
public function getRows()
|
||||
{
|
||||
|
|
@ -98,30 +109,30 @@ class Table extends AbstractElement
|
|||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table width
|
||||
*
|
||||
* @param integer $width
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table width
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table width
|
||||
*
|
||||
* @param int $width
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column count
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function countColumns()
|
||||
{
|
||||
|
|
@ -129,7 +140,9 @@ class Table extends AbstractElement
|
|||
if (is_array($this->rows)) {
|
||||
$rowCount = count($this->rows);
|
||||
for ($i = 0; $i < $rowCount; $i++) {
|
||||
$cellCount = count($this->rows[$i]->getCells());
|
||||
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
|
||||
$row = $this->rows[$i];
|
||||
$cellCount = count($row->getCells());
|
||||
if ($columnCount < $cellCount) {
|
||||
$columnCount = $cellCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
|
|
@ -66,7 +75,7 @@ class Text extends AbstractElement
|
|||
$this->setParagraphStyle($paragraphStyle);
|
||||
} elseif (is_array($style)) {
|
||||
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||
$this->fontStyle->setArrayStyle($style);
|
||||
$this->fontStyle->setStyleByArray($style);
|
||||
} elseif (null === $style) {
|
||||
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||
} else {
|
||||
|
|
@ -97,7 +106,7 @@ class Text extends AbstractElement
|
|||
{
|
||||
if (is_array($style)) {
|
||||
$this->paragraphStyle = new Paragraph;
|
||||
$this->paragraphStyle->setArrayStyle($style);
|
||||
$this->paragraphStyle->setStyleByArray($style);
|
||||
} elseif ($style instanceof Paragraph) {
|
||||
$this->paragraphStyle = $style;
|
||||
} elseif (null === $style) {
|
||||
|
|
@ -127,7 +136,7 @@ class Text extends AbstractElement
|
|||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
$this->text = String::toUTF8($text);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
|
||||
|
||||
/**
|
||||
* TextBox element
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class TextBox extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'TextBox';
|
||||
|
||||
/**
|
||||
* TextBox style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\TextBox
|
||||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* Create a new textbox
|
||||
*
|
||||
* @param mixed $style
|
||||
*/
|
||||
public function __construct($style = null)
|
||||
{
|
||||
$this->style = $this->setStyle(new TextBoxStyle(), $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get textbox style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\TextBox
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -61,7 +69,7 @@ class TextBreak extends AbstractElement
|
|||
$this->setParagraphStyle($paragraphStyle);
|
||||
} elseif (is_array($style)) {
|
||||
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||
$this->fontStyle->setArrayStyle($style);
|
||||
$this->fontStyle->setStyleByArray($style);
|
||||
} else {
|
||||
$this->fontStyle = $style;
|
||||
$this->setParagraphStyle($paragraphStyle);
|
||||
|
|
@ -89,7 +97,7 @@ class TextBreak extends AbstractElement
|
|||
{
|
||||
if (is_array($style)) {
|
||||
$this->paragraphStyle = new Paragraph;
|
||||
$this->paragraphStyle->setArrayStyle($style);
|
||||
$this->paragraphStyle->setStyleByArray($style);
|
||||
} elseif ($style instanceof Paragraph) {
|
||||
$this->paragraphStyle = $style;
|
||||
} else {
|
||||
|
|
@ -107,4 +115,14 @@ class TextBreak extends AbstractElement
|
|||
{
|
||||
return $this->paragraphStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has font/paragraph style defined
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasStyle()
|
||||
{
|
||||
return !is_null($this->fontStyle) || !is_null($this->paragraphStyle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
|
@ -16,12 +24,17 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
|||
*/
|
||||
class TextRun extends AbstractContainer
|
||||
{
|
||||
/**
|
||||
* @var string Container type
|
||||
*/
|
||||
protected $container = 'TextRun';
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var string|\PhpOffice\PhpWord\Style\Paragraph
|
||||
*/
|
||||
private $paragraphStyle;
|
||||
protected $paragraphStyle;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
|
|
@ -30,7 +43,6 @@ class TextRun extends AbstractContainer
|
|||
*/
|
||||
public function __construct($paragraphStyle = null)
|
||||
{
|
||||
$this->container = 'textrun';
|
||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
|
||||
/**
|
||||
* Title element
|
||||
*/
|
||||
|
|
@ -26,89 +37,33 @@ class Title extends AbstractElement
|
|||
*
|
||||
* @var int
|
||||
*/
|
||||
private $depth;
|
||||
private $depth = 1;
|
||||
|
||||
/**
|
||||
* Title anchor
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $anchor;
|
||||
|
||||
/**
|
||||
* Title Bookmark ID
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $bookmarkId;
|
||||
|
||||
/**
|
||||
* Title style
|
||||
* Name of the heading style, e.g. 'Heading1'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $style;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Title Element
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $depth
|
||||
* @param string $style Name of the heading style, e.g. 'Heading1'
|
||||
*/
|
||||
public function __construct($text, $depth = 1, $style = null)
|
||||
public function __construct($text, $depth = 1)
|
||||
{
|
||||
if (!is_null($style)) {
|
||||
$this->style = $style;
|
||||
|
||||
$this->text = String::toUTF8($text);
|
||||
$this->depth = $depth;
|
||||
if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) {
|
||||
$this->style = 'Heading' . $this->depth;
|
||||
}
|
||||
|
||||
$this->text = $text;
|
||||
$this->depth = $depth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Anchor
|
||||
*
|
||||
* @param int $anchor
|
||||
*/
|
||||
public function setAnchor($anchor)
|
||||
{
|
||||
$this->anchor = $anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Anchor
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAnchor()
|
||||
{
|
||||
return $this->anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Bookmark ID
|
||||
*
|
||||
* @param int $bookmarkId
|
||||
*/
|
||||
public function setBookmarkId($bookmarkId)
|
||||
{
|
||||
$this->bookmarkId = $bookmarkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Anchor
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBookmarkId()
|
||||
{
|
||||
return $this->bookmarkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title Text content
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
/**
|
||||
* Endnote collection
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Endnotes
|
||||
{
|
||||
/**
|
||||
* Elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $elements = array();
|
||||
|
||||
/**
|
||||
* Add new element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Endnote $element
|
||||
* @return integer Reference ID
|
||||
*/
|
||||
public static function addElement($element)
|
||||
{
|
||||
$rId = self::countElements() + 1;
|
||||
self::$elements[$rId] = $element;
|
||||
|
||||
return $rId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element
|
||||
*
|
||||
* @param integer $index
|
||||
* @param \PhpOffice\PhpWord\Element\Endnote $element
|
||||
*/
|
||||
public static function setElement($index, $element)
|
||||
{
|
||||
if (array_key_exists($index, self::$elements)) {
|
||||
self::$elements[$index] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element by index
|
||||
*
|
||||
* @param integer $index
|
||||
* @return \PhpOffice\PhpWord\Element\Endnote
|
||||
*/
|
||||
public static function getElement($index)
|
||||
{
|
||||
if (array_key_exists($index, self::$elements)) {
|
||||
return self::$elements[$index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getElements()
|
||||
{
|
||||
return self::$elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element count
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function countElements()
|
||||
{
|
||||
return count(self::$elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset elements
|
||||
*/
|
||||
public static function resetElements()
|
||||
{
|
||||
self::$elements = array();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Exception;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Exception;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Exception;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Exception;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Exception;
|
||||
|
|
|
|||
|
|
@ -1,162 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
/**
|
||||
* Footnote collection
|
||||
*/
|
||||
class Footnotes
|
||||
{
|
||||
/**
|
||||
* Elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $elements = array();
|
||||
|
||||
/**
|
||||
* Add new element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Footnote $element
|
||||
* @return integer Reference ID
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function addElement($element)
|
||||
{
|
||||
$rId = self::countElements() + 1;
|
||||
self::$elements[$rId] = $element;
|
||||
|
||||
return $rId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element
|
||||
*
|
||||
* @param integer $index
|
||||
* @param \PhpOffice\PhpWord\Element\Footnote $element
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function setElement($index, $element)
|
||||
{
|
||||
if (array_key_exists($index, self::$elements)) {
|
||||
self::$elements[$index] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element by index
|
||||
*
|
||||
* @param integer $index
|
||||
* @return \PhpOffice\PhpWord\Element\Footnote
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function getElement($index)
|
||||
{
|
||||
if (array_key_exists($index, self::$elements)) {
|
||||
return self::$elements[$index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*
|
||||
* @return array
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function getElements()
|
||||
{
|
||||
return self::$elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element count
|
||||
*
|
||||
* @return integer
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function countElements()
|
||||
{
|
||||
return count(self::$elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset elements
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function resetElements()
|
||||
{
|
||||
self::$elements = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new footnote
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Footnote $element
|
||||
* @return integer Reference ID
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function addFootnoteElement($element)
|
||||
{
|
||||
return self::addElement($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Footnote Elements
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getFootnoteElements()
|
||||
{
|
||||
return self::getElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Footnote Elements Count
|
||||
*
|
||||
* @return integer
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function countFootnoteElements()
|
||||
{
|
||||
return self::countElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new Footnote Link Element
|
||||
*
|
||||
* @param string $linkSrc
|
||||
* @return integer Reference ID
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function addFootnoteLinkElement($linkSrc)
|
||||
{
|
||||
return Media::addElement('footnotes', 'link', $linkSrc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Footnote Link Elements
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getFootnoteLinkElements()
|
||||
{
|
||||
return Media::getElements('footnotes', 'link');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
|
@ -12,7 +20,7 @@ namespace PhpOffice\PhpWord;
|
|||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
|
||||
/**
|
||||
* IO factory
|
||||
* IO Factory
|
||||
*/
|
||||
abstract class IOFactory
|
||||
{
|
||||
|
|
@ -26,12 +34,12 @@ abstract class IOFactory
|
|||
*/
|
||||
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
||||
{
|
||||
if (!in_array($name, array('WriterInterface', 'Word2007', 'ODText', 'RTF', 'HTML', 'PDF'))) {
|
||||
$class = 'PhpOffice\\PhpWord\\Writer\\' . $name;
|
||||
if (class_exists($class) && self::isConcreteClass($class)) {
|
||||
return new $class($phpWord);
|
||||
} else {
|
||||
throw new Exception("\"{$name}\" is not a valid writer.");
|
||||
}
|
||||
|
||||
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
||||
return new $fqName($phpWord);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,12 +51,12 @@ abstract class IOFactory
|
|||
*/
|
||||
public static function createReader($name = 'Word2007')
|
||||
{
|
||||
if (!in_array($name, array('ReaderInterface', 'Word2007', 'ODText'))) {
|
||||
$class = 'PhpOffice\\PhpWord\\Reader\\' . $name;
|
||||
if (class_exists($class) && self::isConcreteClass($class)) {
|
||||
return new $class();
|
||||
} else {
|
||||
throw new Exception("\"{$name}\" is not a valid reader.");
|
||||
}
|
||||
|
||||
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
|
||||
return new $fqName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +69,20 @@ abstract class IOFactory
|
|||
public static function load($filename, $readerName = 'Word2007')
|
||||
{
|
||||
$reader = self::createReader($readerName);
|
||||
|
||||
return $reader->load($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it's a concrete class (not abstract nor interface)
|
||||
*
|
||||
* @param string $class
|
||||
* @return bool
|
||||
*/
|
||||
private static function isConcreteClass($class)
|
||||
{
|
||||
$reflection = new \ReflectionClass($class);
|
||||
|
||||
return !$reflection->isAbstract() && !$reflection->isInterface();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
|
@ -59,7 +67,7 @@ class Media
|
|||
if (is_null($image)) {
|
||||
throw new Exception('Image object not assigned.');
|
||||
}
|
||||
$isMemImage = $image->getIsMemImage();
|
||||
$isMemImage = $image->isMemImage();
|
||||
$extension = $image->getImageExtension();
|
||||
$mediaData['imageExtension'] = $extension;
|
||||
$mediaData['imageType'] = $image->getImageType();
|
||||
|
|
@ -131,37 +139,53 @@ class Media
|
|||
* Get media elements
|
||||
*
|
||||
* @param string $container section|headerx|footerx|footnote|endnote
|
||||
* @param string $mediaType image|object|link
|
||||
* @param string $type image|object|link
|
||||
* @return array
|
||||
* @since 0.10.0
|
||||
*/
|
||||
public static function getElements($container, $mediaType = null)
|
||||
public static function getElements($container, $type = null)
|
||||
{
|
||||
$mediaElements = array();
|
||||
$elements = array();
|
||||
|
||||
// If header/footer, search for headerx and footerx where x is number
|
||||
if ($container == 'header' || $container == 'footer') {
|
||||
foreach (self::$elements as $key => $val) {
|
||||
if (substr($key, 0, 6) == $container) {
|
||||
$mediaElements[$key] = $val;
|
||||
$elements[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $elements;
|
||||
} else {
|
||||
if (!array_key_exists($container, self::$elements)) {
|
||||
return $mediaElements;
|
||||
return $elements;
|
||||
}
|
||||
foreach (self::$elements[$container] as $mediaKey => $mediaData) {
|
||||
if (!is_null($mediaType)) {
|
||||
if ($mediaType == $mediaData['type']) {
|
||||
$mediaElements[$mediaKey] = $mediaData;
|
||||
}
|
||||
} else {
|
||||
$mediaElements[$mediaKey] = $mediaData;
|
||||
return self::getElementsByType($container, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements by media type
|
||||
*
|
||||
* @param string $container section|footnote|endnote
|
||||
* @param string $type image|object|link
|
||||
* @return array
|
||||
* @since 0.11.0 Splitted from `getElements` to reduce complexity
|
||||
*/
|
||||
private static function getElementsByType($container, $type = null)
|
||||
{
|
||||
$elements = array();
|
||||
|
||||
foreach (self::$elements[$container] as $key => $data) {
|
||||
if ($type !== null) {
|
||||
if ($type == $data['type']) {
|
||||
$elements[$key] = $data;
|
||||
}
|
||||
} else {
|
||||
$elements[$key] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $mediaElements;
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,36 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
use PhpOffice\PhpWord\DocumentProperties;
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Collection\Endnotes;
|
||||
use PhpOffice\PhpWord\Collection\Footnotes;
|
||||
use PhpOffice\PhpWord\Collection\Titles;
|
||||
use PhpOffice\PhpWord\Element\Section;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\Template;
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
|
||||
/**
|
||||
* PHPWord main class
|
||||
*/
|
||||
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.
|
||||
* Default font settings
|
||||
*
|
||||
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
|
||||
* use, and the conversion will be conducted during XML writing.
|
||||
* @const string|int
|
||||
* @deprecated 0.11.0 Use Settings constants
|
||||
*/
|
||||
const DEFAULT_FONT_SIZE = 10;
|
||||
const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
|
||||
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
|
||||
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
||||
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
||||
|
||||
/**
|
||||
* Document properties object
|
||||
|
|
@ -39,19 +46,6 @@ class PhpWord
|
|||
*/
|
||||
private $documentProperties;
|
||||
|
||||
/**
|
||||
* Default font name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $defaultFontName;
|
||||
|
||||
/**
|
||||
* Default font size
|
||||
* @var int
|
||||
*/
|
||||
private $defaultFontSize;
|
||||
|
||||
/**
|
||||
* Collection of sections
|
||||
*
|
||||
|
|
@ -59,14 +53,36 @@ class PhpWord
|
|||
*/
|
||||
private $sections = array();
|
||||
|
||||
/**
|
||||
* Collection of titles
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Collection\Titles
|
||||
*/
|
||||
private $titles;
|
||||
|
||||
/**
|
||||
* Collection of footnotes
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Collection\Footnotes
|
||||
*/
|
||||
private $footnotes;
|
||||
|
||||
/**
|
||||
* Collection of endnotes
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Collection\Endnotes
|
||||
*/
|
||||
private $endnotes;
|
||||
|
||||
/**
|
||||
* Create new
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->documentProperties = new DocumentProperties();
|
||||
$this->defaultFontName = self::DEFAULT_FONT_NAME;
|
||||
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
|
||||
$this->titles = new Titles();
|
||||
$this->footnotes = new Footnotes();
|
||||
$this->endnotes = new Endnotes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,6 +108,16 @@ class PhpWord
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sections
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Element\Section[]
|
||||
*/
|
||||
public function getSections()
|
||||
{
|
||||
return $this->sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new section
|
||||
*
|
||||
|
|
@ -101,11 +127,75 @@ class PhpWord
|
|||
public function addSection($settings = null)
|
||||
{
|
||||
$section = new Section(count($this->sections) + 1, $settings);
|
||||
$section->setPhpWord($this);
|
||||
$this->sections[] = $section;
|
||||
|
||||
return $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get titles
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Collection\Titles
|
||||
*/
|
||||
public function getTitles()
|
||||
{
|
||||
return $this->titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new title
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Title $title
|
||||
* @return int
|
||||
*/
|
||||
public function addTitle($title)
|
||||
{
|
||||
return $this->titles->addItem($title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get footnotes
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Collection\Footnotes
|
||||
*/
|
||||
public function getFootnotes()
|
||||
{
|
||||
return $this->footnotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new footnote
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Footnote $footnote
|
||||
* @return int
|
||||
*/
|
||||
public function addFootnote($footnote)
|
||||
{
|
||||
return $this->footnotes->addItem($footnote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get endnotes
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Collection\Endnotes
|
||||
*/
|
||||
public function getEndnotes()
|
||||
{
|
||||
return $this->endnotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new endnote
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Endnote $endnote
|
||||
* @return int
|
||||
*/
|
||||
public function addEndnote($endnote)
|
||||
{
|
||||
return $this->endnotes->addItem($endnote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default font name
|
||||
*
|
||||
|
|
@ -113,7 +203,7 @@ class PhpWord
|
|||
*/
|
||||
public function getDefaultFontName()
|
||||
{
|
||||
return $this->defaultFontName;
|
||||
return Settings::getDefaultFontName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,7 +213,7 @@ class PhpWord
|
|||
*/
|
||||
public function setDefaultFontName($fontName)
|
||||
{
|
||||
$this->defaultFontName = $fontName;
|
||||
Settings::setDefaultFontName($fontName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,7 +223,7 @@ class PhpWord
|
|||
*/
|
||||
public function getDefaultFontSize()
|
||||
{
|
||||
return $this->defaultFontSize;
|
||||
return Settings::getDefaultFontSize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,17 +233,18 @@ class PhpWord
|
|||
*/
|
||||
public function setDefaultFontSize($fontSize)
|
||||
{
|
||||
$this->defaultFontSize = $fontSize;
|
||||
Settings::setDefaultFontSize($fontSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default paragraph style definition to styles.xml
|
||||
*
|
||||
* @param array $styles Paragraph style definition
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
*/
|
||||
public function setDefaultParagraphStyle($styles)
|
||||
{
|
||||
Style::setDefaultParagraphStyle($styles);
|
||||
return Style::setDefaultParagraphStyle($styles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,10 +252,11 @@ class PhpWord
|
|||
*
|
||||
* @param string $styleName
|
||||
* @param array $styles
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
*/
|
||||
public function addParagraphStyle($styleName, $styles)
|
||||
{
|
||||
Style::addParagraphStyle($styleName, $styles);
|
||||
return Style::addParagraphStyle($styleName, $styles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,10 +265,11 @@ class PhpWord
|
|||
* @param string $styleName
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
*/
|
||||
public function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
|
||||
{
|
||||
Style::addFontStyle($styleName, $fontStyle, $paragraphStyle);
|
||||
return Style::addFontStyle($styleName, $fontStyle, $paragraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,33 +278,11 @@ class PhpWord
|
|||
* @param string $styleName
|
||||
* @param mixed $styleTable
|
||||
* @param mixed $styleFirstRow
|
||||
* @return \PhpOffice\PhpWord\Style\Table
|
||||
*/
|
||||
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
||||
{
|
||||
Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a heading style definition to styles.xml
|
||||
*
|
||||
* @param int $titleCount
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null)
|
||||
{
|
||||
Style::addTitleStyle($titleCount, $fontStyle, $paragraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a hyperlink style to styles.xml
|
||||
*
|
||||
* @param string $styleName
|
||||
* @param mixed $styles
|
||||
*/
|
||||
public function addLinkStyle($styleName, $styles)
|
||||
{
|
||||
Style::addLinkStyle($styleName, $styles);
|
||||
return Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -219,20 +290,36 @@ class PhpWord
|
|||
*
|
||||
* @param string $styleName
|
||||
* @param mixed $styles
|
||||
* @return \PhpOffice\PhpWord\Style\Numbering
|
||||
*/
|
||||
public function addNumberingStyle($styleName, $styles)
|
||||
{
|
||||
Style::addNumberingStyle($styleName, $styles);
|
||||
return Style::addNumberingStyle($styleName, $styles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sections
|
||||
* Adds a hyperlink style to styles.xml
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Element\Section[]
|
||||
* @param string $styleName
|
||||
* @param mixed $styles
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
*/
|
||||
public function getSections()
|
||||
public function addLinkStyle($styleName, $styles)
|
||||
{
|
||||
return $this->sections;
|
||||
return Style::addLinkStyle($styleName, $styles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a heading style definition to styles.xml
|
||||
*
|
||||
* @param int $depth
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
*/
|
||||
public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
|
||||
{
|
||||
return Style::addTitleStyle($depth, $fontStyle, $paragraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
|
@ -14,6 +22,7 @@ use PhpOffice\PhpWord\Exception\Exception;
|
|||
/**
|
||||
* Reader abstract class
|
||||
*
|
||||
* @since 0.8.0
|
||||
* @codeCoverageIgnore Abstract class
|
||||
*/
|
||||
abstract class AbstractReader implements ReaderInterface
|
||||
|
|
@ -30,14 +39,14 @@ abstract class AbstractReader implements ReaderInterface
|
|||
*
|
||||
* @var bool|resource
|
||||
*/
|
||||
protected $fileHandle = true;
|
||||
protected $fileHandle;
|
||||
|
||||
/**
|
||||
* Read data only?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getReadDataOnly()
|
||||
public function isReadDataOnly()
|
||||
{
|
||||
// return $this->readDataOnly;
|
||||
return true;
|
||||
|
|
@ -46,47 +55,47 @@ abstract class AbstractReader implements ReaderInterface
|
|||
/**
|
||||
* Set read data only
|
||||
*
|
||||
* @param bool $pValue
|
||||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setReadDataOnly($pValue = true)
|
||||
public function setReadDataOnly($value = true)
|
||||
{
|
||||
$this->readDataOnly = $pValue;
|
||||
$this->readDataOnly = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open file for reading
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return resource
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
*/
|
||||
protected function openFile($pFilename)
|
||||
protected function openFile($filename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename) || !is_readable($pFilename)) {
|
||||
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
if (!file_exists($filename) || !is_readable($filename)) {
|
||||
throw new Exception("Could not open " . $filename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
// Open file
|
||||
$this->fileHandle = fopen($pFilename, 'r');
|
||||
$this->fileHandle = fopen($filename, 'r');
|
||||
if ($this->fileHandle === false) {
|
||||
throw new Exception("Could not open file " . $pFilename . " for reading.");
|
||||
throw new Exception("Could not open file " . $filename . " for reading.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the current ReaderInterface read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
public function canRead($filename)
|
||||
{
|
||||
// Check if file exists
|
||||
try {
|
||||
$this->openFile($pFilename);
|
||||
$this->openFile($filename);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -96,4 +105,15 @@ abstract class AbstractReader implements ReaderInterface
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data only?
|
||||
*
|
||||
* @deprecated 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getReadDataOnly()
|
||||
{
|
||||
return $this->isReadDataOnly();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\Html as HTMLParser;
|
||||
|
||||
/**
|
||||
* HTML Reader class
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class HTML extends AbstractReader implements ReaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads PhpWord from file
|
||||
*
|
||||
* @param string $docFile
|
||||
* @throws \Exception
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
public function load($docFile)
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
|
||||
if ($this->canRead($docFile)) {
|
||||
$section = $phpWord->addSection();
|
||||
HTMLParser::addHtml($section, file_get_contents($docFile), true);
|
||||
} else {
|
||||
throw new \Exception("Cannot read {$docFile}.");
|
||||
}
|
||||
|
||||
return $phpWord;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
|
@ -32,6 +40,7 @@ class ODText extends AbstractReader implements ReaderInterface
|
|||
|
||||
$readerParts = array(
|
||||
'content.xml' => 'Content',
|
||||
'meta.xml' => 'Meta',
|
||||
);
|
||||
|
||||
foreach ($readerParts as $xmlFile => $partName) {
|
||||
|
|
@ -54,6 +63,7 @@ class ODText extends AbstractReader implements ReaderInterface
|
|||
{
|
||||
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
|
||||
if (class_exists($partClass)) {
|
||||
/** @var \PhpOffice\PhpWord\Reader\ODText\AbstractPart $part Type hint */
|
||||
$part = new $partClass($docFile, $xmlFile);
|
||||
$part->setRels($relationships);
|
||||
$part->read($phpWord);
|
||||
|
|
|
|||
|
|
@ -1,50 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\ODText;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
|
||||
|
||||
/**
|
||||
* Abstract part reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart
|
||||
abstract class AbstractPart extends Word2007AbstractPart
|
||||
{
|
||||
/**
|
||||
* Read w:r (override)
|
||||
*
|
||||
* @param mixed $parent
|
||||
* @param string $docPart
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $paragraphStyle = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:pPr (override)
|
||||
*/
|
||||
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:rPr (override)
|
||||
*/
|
||||
protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:tblPr (override)
|
||||
*/
|
||||
protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\ODText;
|
||||
|
|
@ -14,6 +22,8 @@ use PhpOffice\PhpWord\Shared\XMLReader;
|
|||
|
||||
/**
|
||||
* Content reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Content extends AbstractPart
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\ODText;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
|
||||
/**
|
||||
* Meta reader
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Meta extends AbstractPart
|
||||
{
|
||||
/**
|
||||
* Read meta.xml
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @todo Process property type
|
||||
*/
|
||||
public function read(PhpWord &$phpWord)
|
||||
{
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||
$docProps = $phpWord->getDocumentProperties();
|
||||
|
||||
$metaNode = $xmlReader->getElement('office:meta');
|
||||
|
||||
// Standard properties
|
||||
$properties = array(
|
||||
'title' => 'dc:title',
|
||||
'subject' => 'dc:subject',
|
||||
'description' => 'dc:description',
|
||||
'keywords' => 'meta:keyword',
|
||||
'creator' => 'meta:initial-creator',
|
||||
'lastModifiedBy' => 'dc:creator',
|
||||
// 'created' => 'meta:creation-date',
|
||||
// 'modified' => 'dc:date',
|
||||
);
|
||||
foreach ($properties as $property => $path) {
|
||||
$method = "set{$property}";
|
||||
$propertyNode = $xmlReader->getElement($path, $metaNode);
|
||||
if ($propertyNode !== null && method_exists($docProps, $method)) {
|
||||
$docProps->$method($propertyNode->nodeValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom properties
|
||||
$propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode);
|
||||
foreach ($propertyNodes as $propertyNode) {
|
||||
$property = $xmlReader->getAttribute('meta:name', $propertyNode);
|
||||
|
||||
// Set category, company, and manager property
|
||||
if (in_array($property, array('Category', 'Company', 'Manager'))) {
|
||||
$method = "set{$property}";
|
||||
$docProps->$method($propertyNode->nodeValue);
|
||||
|
||||
// Set other custom properties
|
||||
} else {
|
||||
$docProps->setCustomProperty($property, $propertyNode->nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Reader\RTF\Document;
|
||||
|
||||
/**
|
||||
* RTF Reader class
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class RTF extends AbstractReader implements ReaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads PhpWord from file
|
||||
*
|
||||
* @param string $docFile
|
||||
* @throws \Exception
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
public function load($docFile)
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
|
||||
if ($this->canRead($docFile)) {
|
||||
$doc = new Document();
|
||||
$doc->rtf = file_get_contents($docFile);
|
||||
$doc->read($phpWord);
|
||||
} else {
|
||||
throw new \Exception("Cannot read {$docFile}.");
|
||||
}
|
||||
|
||||
return $phpWord;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,393 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\RTF;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
|
||||
/**
|
||||
* RTF document reader
|
||||
*
|
||||
* References:
|
||||
* - How to Write an RTF Reader http://latex2rtf.sourceforge.net/rtfspec_45.html
|
||||
* - PHP rtfclass by Markus Fischer https://github.com/mfn/rtfclass
|
||||
* - JavaScript RTF-parser by LazyGyu https://github.com/lazygyu/RTF-parser
|
||||
*
|
||||
* @since 0.11.0
|
||||
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
|
||||
*/
|
||||
class Document
|
||||
{
|
||||
/** @const int */
|
||||
const PARA = 'readParagraph';
|
||||
const STYL = 'readStyle';
|
||||
const SKIP = 'readSkip';
|
||||
|
||||
/**
|
||||
* PhpWord object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
private $phpWord;
|
||||
|
||||
/**
|
||||
* Section object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Element\Section
|
||||
*/
|
||||
private $section;
|
||||
|
||||
/**
|
||||
* Textrun object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Element\TextRun
|
||||
*/
|
||||
private $textrun;
|
||||
|
||||
/**
|
||||
* RTF content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $rtf;
|
||||
|
||||
/**
|
||||
* Content length
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $length = 0;
|
||||
|
||||
/**
|
||||
* Character index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Current control word
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $control = '';
|
||||
|
||||
/**
|
||||
* Text content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $text = '';
|
||||
|
||||
/**
|
||||
* Parsing a control word flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isControl = false;
|
||||
|
||||
/**
|
||||
* First character flag: watch out for control symbols
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isFirst = false;
|
||||
|
||||
/**
|
||||
* Group groups
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $groups = array();
|
||||
|
||||
/**
|
||||
* Parser flags; not used
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $flags = array();
|
||||
|
||||
/**
|
||||
* Parse RTF content
|
||||
*
|
||||
* - Marks controlling characters `{`, `}`, and `\`
|
||||
* - Removes line endings
|
||||
* - Builds control words and control symbols
|
||||
* - Pushes every other character into the text queue
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @todo Use `fread` stream for scalability
|
||||
*/
|
||||
public function read(PhpWord &$phpWord)
|
||||
{
|
||||
$markers = array(
|
||||
123 => 'markOpening', // {
|
||||
125 => 'markClosing', // }
|
||||
92 => 'markBackslash', // \
|
||||
10 => 'markNewline', // LF
|
||||
13 => 'markNewline' // CR
|
||||
);
|
||||
|
||||
$this->phpWord = $phpWord;
|
||||
$this->section = $phpWord->addSection();
|
||||
$this->textrun = $this->section->addTextRun();
|
||||
$this->length = strlen($this->rtf);
|
||||
|
||||
$this->flags['paragraph'] = true; // Set paragraph flag from the beginning
|
||||
|
||||
// Walk each characters
|
||||
while ($this->offset < $this->length) {
|
||||
$char = $this->rtf[$this->offset];
|
||||
$ascii = ord($char);
|
||||
|
||||
if (array_key_exists($ascii, $markers)) { // Marker found: {, }, \, LF, or CR
|
||||
$markerFunction = $markers[$ascii];
|
||||
$this->$markerFunction();
|
||||
} else {
|
||||
if ($this->isControl === false) { // Non control word: Push character
|
||||
$this->pushText($char);
|
||||
} else {
|
||||
if (preg_match("/^[a-zA-Z0-9-]?$/", $char)) { // No delimiter: Buffer control
|
||||
$this->control .= $char;
|
||||
$this->isFirst = false;
|
||||
} else { // Delimiter found: Parse buffered control
|
||||
if ($this->isFirst) {
|
||||
$this->isFirst = false;
|
||||
} else {
|
||||
if ($char == ' ') { // Discard space as a control word delimiter
|
||||
$this->flushControl(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->offset++;
|
||||
}
|
||||
$this->flushText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark opening braket `{` character
|
||||
*/
|
||||
private function markOpening()
|
||||
{
|
||||
$this->flush(true);
|
||||
array_push($this->groups, $this->flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark closing braket `}` character
|
||||
*/
|
||||
private function markClosing()
|
||||
{
|
||||
$this->flush(true);
|
||||
$this->flags = array_pop($this->groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark backslash `\` character
|
||||
*/
|
||||
private function markBackslash()
|
||||
{
|
||||
if ($this->isFirst) {
|
||||
$this->setControl(false);
|
||||
$this->text .= '\\';
|
||||
} else {
|
||||
$this->flush();
|
||||
$this->setControl(true);
|
||||
$this->control = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark newline character: Flush control word because it's not possible to span multiline
|
||||
*/
|
||||
private function markNewline()
|
||||
{
|
||||
if ($this->isControl) {
|
||||
$this->flushControl(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush control word or text
|
||||
*
|
||||
* @param bool $isControl
|
||||
*/
|
||||
private function flush($isControl = false)
|
||||
{
|
||||
if ($this->isControl) {
|
||||
$this->flushControl($isControl);
|
||||
} else {
|
||||
$this->flushText();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush control word
|
||||
*
|
||||
* @param bool $isControl
|
||||
*/
|
||||
private function flushControl($isControl = false)
|
||||
{
|
||||
if (preg_match("/^([A-Za-z]+)(-?[0-9]*) ?$/", $this->control, $match) === 1) {
|
||||
list(, $control, $parameter) = $match;
|
||||
$this->parseControl($control, $parameter);
|
||||
}
|
||||
|
||||
if ($isControl === true) {
|
||||
$this->setControl(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush text in queue
|
||||
*/
|
||||
private function flushText()
|
||||
{
|
||||
if ($this->text != '') {
|
||||
if (isset($this->flags['property'])) { // Set property
|
||||
$this->flags['value'] = $this->text;
|
||||
} else { // Set text
|
||||
if ($this->flags['paragraph'] === true) {
|
||||
$this->flags['paragraph'] = false;
|
||||
$this->flags['text'] = $this->text;
|
||||
}
|
||||
}
|
||||
|
||||
// Add text if it's not flagged as skipped
|
||||
if (!isset($this->flags['skipped'])) {
|
||||
$this->readText();
|
||||
}
|
||||
|
||||
$this->text = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset control word and first char state
|
||||
*
|
||||
* @param bool $value
|
||||
*/
|
||||
private function setControl($value)
|
||||
{
|
||||
$this->isControl = $value;
|
||||
$this->isFirst = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push text into queue
|
||||
*
|
||||
* @param string $char
|
||||
*/
|
||||
private function pushText($char)
|
||||
{
|
||||
if ($char == '<') {
|
||||
$this->text .= "<";
|
||||
} elseif ($char == '>') {
|
||||
$this->text .= ">";
|
||||
} else {
|
||||
$this->text .= $char;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse control
|
||||
*
|
||||
* @param string $control
|
||||
* @param string $parameter
|
||||
*/
|
||||
private function parseControl($control, $parameter)
|
||||
{
|
||||
$controls = array(
|
||||
'par' => array(self::PARA, 'paragraph', true),
|
||||
'b' => array(self::STYL, 'font', 'bold', true),
|
||||
'i' => array(self::STYL, 'font', 'italic', true),
|
||||
'u' => array(self::STYL, 'font', 'underline', true),
|
||||
'strike' => array(self::STYL, 'font', 'strikethrough',true),
|
||||
'fs' => array(self::STYL, 'font', 'size', $parameter),
|
||||
'qc' => array(self::STYL, 'paragraph', 'align', 'center'),
|
||||
'sa' => array(self::STYL, 'paragraph', 'spaceAfter', $parameter),
|
||||
'fonttbl' => array(self::SKIP, 'fonttbl', null),
|
||||
'colortbl' => array(self::SKIP, 'colortbl', null),
|
||||
'info' => array(self::SKIP, 'info', null),
|
||||
'generator' => array(self::SKIP, 'generator', null),
|
||||
'title' => array(self::SKIP, 'title', null),
|
||||
'subject' => array(self::SKIP, 'subject', null),
|
||||
'category' => array(self::SKIP, 'category', null),
|
||||
'keywords' => array(self::SKIP, 'keywords', null),
|
||||
'comment' => array(self::SKIP, 'comment', null),
|
||||
'shppict' => array(self::SKIP, 'pic', null),
|
||||
'fldinst' => array(self::SKIP, 'link', null),
|
||||
);
|
||||
|
||||
if (array_key_exists($control, $controls)) {
|
||||
list($function) = $controls[$control];
|
||||
if (method_exists($this, $function)) {
|
||||
$directives = $controls[$control];
|
||||
array_shift($directives); // remove the function variable; we won't need it
|
||||
$this->$function($directives);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read paragraph
|
||||
*
|
||||
* @param array $directives
|
||||
*/
|
||||
private function readParagraph($directives)
|
||||
{
|
||||
list($property, $value) = $directives;
|
||||
$this->textrun = $this->section->addTextRun();
|
||||
$this->flags[$property] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read style
|
||||
*
|
||||
* @param array $directives
|
||||
*/
|
||||
private function readStyle($directives)
|
||||
{
|
||||
list($style, $property, $value) = $directives;
|
||||
$this->flags['styles'][$style][$property] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read skip
|
||||
*
|
||||
* @param array $directives
|
||||
*/
|
||||
private function readSkip($directives)
|
||||
{
|
||||
list($property) = $directives;
|
||||
$this->flags['property'] = $property;
|
||||
$this->flags['skipped'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read text
|
||||
*/
|
||||
private function readText()
|
||||
{
|
||||
$text = $this->textrun->addText($this->text);
|
||||
if (isset($this->flags['styles']['font'])) {
|
||||
$text->getFontStyle()->setStyleByArray($this->flags['styles']['font']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
||||
/**
|
||||
* Reader interface
|
||||
*
|
||||
* @since 0.8.0
|
||||
*/
|
||||
interface ReaderInterface
|
||||
{
|
||||
/**
|
||||
* Can the current ReaderInterface read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
public function canRead($pFilename);
|
||||
public function canRead($filename);
|
||||
|
||||
/**
|
||||
* Loads PhpWord from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
*/
|
||||
public function load($pFilename);
|
||||
public function load($filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||
|
||||
/**
|
||||
* Reader for Word2007
|
||||
|
|
@ -79,6 +87,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
{
|
||||
$partClass = "PhpOffice\\PhpWord\\Reader\\Word2007\\{$partName}";
|
||||
if (class_exists($partClass)) {
|
||||
/** @var \PhpOffice\PhpWord\Reader\Word2007\AbstractPart $part Type hint */
|
||||
$part = new $partClass($docFile, $xmlFile);
|
||||
$part->setRels($relationships);
|
||||
$part->read($phpWord);
|
||||
|
|
@ -101,8 +110,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
|
||||
// word/_rels/*.xml.rels
|
||||
$wordRelsPath = 'word/_rels/';
|
||||
$zipClass = Settings::getZipClass();
|
||||
$zip = new $zipClass();
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($docFile) === true) {
|
||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||
$xmlFile = $zip->getNameIndex($i);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
|
@ -14,9 +22,24 @@ use PhpOffice\PhpWord\Shared\XMLReader;
|
|||
|
||||
/**
|
||||
* Abstract part reader
|
||||
*
|
||||
* This class is inherited by ODText reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
abstract class AbstractPart
|
||||
{
|
||||
/**
|
||||
* Conversion method
|
||||
*
|
||||
* @const int
|
||||
*/
|
||||
const READ_VALUE = 'attributeValue'; // Read attribute value
|
||||
const READ_EQUAL = 'attributeEquals'; // Read `true` when attribute value equals specified value
|
||||
const READ_TRUE = 'attributeTrue'; // Read `true` when element exists
|
||||
const READ_FALSE = 'attributeFalse'; // Read `false` when element exists
|
||||
const READ_SIZE = 'attributeMultiplyByTwo'; // Read special attribute value for Font::$size
|
||||
|
||||
/**
|
||||
* Document file
|
||||
*
|
||||
|
|
@ -65,6 +88,96 @@ abstract class AbstractPart
|
|||
$this->rels = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:p
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @param mixed $parent
|
||||
* @param string $docPart
|
||||
*
|
||||
* @todo Get font style for preserve text
|
||||
*/
|
||||
protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart = 'document')
|
||||
{
|
||||
// Paragraph style
|
||||
$paragraphStyle = null;
|
||||
$headingMatches = array();
|
||||
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
||||
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
||||
if (is_array($paragraphStyle) && array_key_exists('styleName', $paragraphStyle)) {
|
||||
preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches);
|
||||
}
|
||||
}
|
||||
|
||||
// PreserveText
|
||||
if ($xmlReader->elementExists('w:r/w:instrText', $domNode)) {
|
||||
$ignoreText = false;
|
||||
$textContent = '';
|
||||
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$instrText = $xmlReader->getValue('w:instrText', $node);
|
||||
if ($xmlReader->elementExists('w:fldChar', $node)) {
|
||||
$fldCharType = $xmlReader->getAttribute('w:fldCharType', $node, 'w:fldChar');
|
||||
if ($fldCharType == 'begin') {
|
||||
$ignoreText = true;
|
||||
} elseif ($fldCharType == 'end') {
|
||||
$ignoreText = false;
|
||||
}
|
||||
}
|
||||
if (!is_null($instrText)) {
|
||||
$textContent .= '{' . $instrText . '}';
|
||||
} else {
|
||||
if ($ignoreText === false) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
$parent->addPreserveText($textContent, $fontStyle, $paragraphStyle);
|
||||
|
||||
// List item
|
||||
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
|
||||
$textContent = '';
|
||||
$numId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:numId');
|
||||
$levelId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:ilvl');
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $paragraphStyle);
|
||||
|
||||
// Heading
|
||||
} elseif (!empty($headingMatches)) {
|
||||
$textContent = '';
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
$parent->addTitle($textContent, $headingMatches[1]);
|
||||
|
||||
// Text and TextRun
|
||||
} else {
|
||||
$runCount = $xmlReader->countElements('w:r', $domNode);
|
||||
$linkCount = $xmlReader->countElements('w:hyperlink', $domNode);
|
||||
$runLinkCount = $runCount + $linkCount;
|
||||
if ($runLinkCount == 0) {
|
||||
$parent->addTextBreak(null, $paragraphStyle);
|
||||
} else {
|
||||
if ($runLinkCount > 1) {
|
||||
$textrun = $parent->addTextRun($paragraphStyle);
|
||||
$textParent = &$textrun;
|
||||
} else {
|
||||
$textParent = &$parent;
|
||||
}
|
||||
$nodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$this->readRun($xmlReader, $node, $textParent, $docPart, $paragraphStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:r
|
||||
*
|
||||
|
|
@ -128,144 +241,144 @@ abstract class AbstractPart
|
|||
}
|
||||
|
||||
/**
|
||||
* Read w:pPr
|
||||
* Read w:tbl
|
||||
*
|
||||
* @return string|array|null
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @param mixed $parent
|
||||
* @param string $docPart
|
||||
*/
|
||||
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart = 'document')
|
||||
{
|
||||
$style = null;
|
||||
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
||||
if ($xmlReader->elementExists('w:pPr/w:pStyle', $domNode)) {
|
||||
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:pStyle');
|
||||
} else {
|
||||
$style = array();
|
||||
$mapping = array(
|
||||
'w:ind' => 'indent', 'w:spacing' => 'spacing',
|
||||
'w:jc' => 'align', 'w:basedOn' => 'basedOn', 'w:next' => 'next',
|
||||
'w:widowControl' => 'widowControl', 'w:keepNext' => 'keepNext',
|
||||
'w:keepLines' => 'keepLines', 'w:pageBreakBefore' => 'pageBreakBefore',
|
||||
// Table style
|
||||
$tblStyle = null;
|
||||
if ($xmlReader->elementExists('w:tblPr', $domNode)) {
|
||||
$tblStyle = $this->readTableStyle($xmlReader, $domNode);
|
||||
}
|
||||
|
||||
/** @var \PhpOffice\PhpWord\Element\Table $table Type hint */
|
||||
$table = $parent->addTable($tblStyle);
|
||||
$tblNodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($tblNodes as $tblNode) {
|
||||
if ($tblNode->nodeName == 'w:tblGrid') { // Column
|
||||
// @todo Do something with table columns
|
||||
|
||||
} elseif ($tblNode->nodeName == 'w:tr') { // Row
|
||||
$rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight');
|
||||
$rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight');
|
||||
$rowHRule = $rowHRule == 'exact' ? true : false;
|
||||
$rowStyle = array(
|
||||
'tblHeader' => $xmlReader->elementExists('w:trPr/w:tblHeader', $tblNode),
|
||||
'cantSplit' => $xmlReader->elementExists('w:trPr/w:cantSplit', $tblNode),
|
||||
'exactHeight' => $rowHRule,
|
||||
);
|
||||
|
||||
$nodes = $xmlReader->getElements('w:pPr/*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
$property = $mapping[$node->nodeName];
|
||||
switch ($node->nodeName) {
|
||||
$row = $table->addRow($rowHeight, $rowStyle);
|
||||
$rowNodes = $xmlReader->getElements('*', $tblNode);
|
||||
foreach ($rowNodes as $rowNode) {
|
||||
if ($rowNode->nodeName == 'w:trPr') { // Row style
|
||||
// @todo Do something with row style
|
||||
|
||||
case 'w:ind':
|
||||
$style['indent'] = $xmlReader->getAttribute('w:left', $node);
|
||||
$style['hanging'] = $xmlReader->getAttribute('w:hanging', $node);
|
||||
break;
|
||||
} elseif ($rowNode->nodeName == 'w:tc') { // Cell
|
||||
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
|
||||
$cellStyle = null;
|
||||
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
|
||||
if (!is_null($cellStyleNode)) {
|
||||
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
|
||||
}
|
||||
|
||||
case 'w:spacing':
|
||||
$style['spaceAfter'] = $xmlReader->getAttribute('w:after', $node);
|
||||
$style['spaceBefore'] = $xmlReader->getAttribute('w:before', $node);
|
||||
// Commented. Need to adjust the number when return value is null
|
||||
// $style['spacing'] = $xmlReader->getAttribute('w:line', $node);
|
||||
break;
|
||||
|
||||
case 'w:keepNext':
|
||||
case 'w:keepLines':
|
||||
case 'w:pageBreakBefore':
|
||||
$style[$property] = true;
|
||||
break;
|
||||
|
||||
case 'w:widowControl':
|
||||
$style[$property] = false;
|
||||
break;
|
||||
|
||||
case 'w:jc':
|
||||
case 'w:basedOn':
|
||||
case 'w:next':
|
||||
$style[$property] = $xmlReader->getAttribute('w:val', $node);
|
||||
break;
|
||||
$cell = $row->addCell($cellWidth, $cellStyle);
|
||||
$cellNodes = $xmlReader->getElements('*', $rowNode);
|
||||
foreach ($cellNodes as $cellNode) {
|
||||
if ($cellNode->nodeName == 'w:p') { // Paragraph
|
||||
$this->readParagraph($xmlReader, $cellNode, $cell, $docPart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $style;
|
||||
/**
|
||||
* Read w:pPr
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @return array|null
|
||||
*/
|
||||
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
if (!$xmlReader->elementExists('w:pPr', $domNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$styleNode = $xmlReader->getElement('w:pPr', $domNode);
|
||||
$styleDefs = array(
|
||||
'styleName' => array(self::READ_VALUE, 'w:pStyle'),
|
||||
'align' => array(self::READ_VALUE, 'w:jc'),
|
||||
'basedOn' => array(self::READ_VALUE, 'w:basedOn'),
|
||||
'next' => array(self::READ_VALUE, 'w:next'),
|
||||
'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'),
|
||||
'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'),
|
||||
'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'),
|
||||
'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'),
|
||||
'widowControl' => array(self::READ_FALSE, 'w:widowControl'),
|
||||
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
|
||||
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
|
||||
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
|
||||
);
|
||||
|
||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:rPr
|
||||
*
|
||||
* @return string|array|null
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @return array
|
||||
*/
|
||||
protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
$style = null;
|
||||
if (is_null($domNode)) {
|
||||
return null;
|
||||
}
|
||||
// Hyperlink has an extra w:r child
|
||||
if ($domNode->nodeName == 'w:hyperlink') {
|
||||
$domNode = $xmlReader->getElement('w:r', $domNode);
|
||||
}
|
||||
if (is_null($domNode)) {
|
||||
return $style;
|
||||
}
|
||||
if ($xmlReader->elementExists('w:rPr', $domNode)) {
|
||||
if ($xmlReader->elementExists('w:rPr/w:rStyle', $domNode)) {
|
||||
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:rPr/w:rStyle');
|
||||
} else {
|
||||
$style = array();
|
||||
$mapping = array(
|
||||
'w:b' => 'bold', 'w:i' => 'italic', 'w:color' => 'color',
|
||||
'w:strike' => 'strikethrough', 'w:u' => 'underline',
|
||||
'w:highlight' => 'fgColor', 'w:sz' => 'size',
|
||||
'w:rFonts' => 'name', 'w:vertAlign' => 'superScript',
|
||||
);
|
||||
|
||||
$nodes = $xmlReader->getElements('w:rPr/*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
$property = $mapping[$node->nodeName];
|
||||
switch ($node->nodeName) {
|
||||
|
||||
case 'w:rFonts':
|
||||
$style['name'] = $xmlReader->getAttribute('w:ascii', $node);
|
||||
$style['hint'] = $xmlReader->getAttribute('w:hint', $node);
|
||||
break;
|
||||
|
||||
case 'w:b':
|
||||
case 'w:i':
|
||||
case 'w:strike':
|
||||
$style[$property] = true;
|
||||
break;
|
||||
|
||||
case 'w:u':
|
||||
case 'w:highlight':
|
||||
case 'w:color':
|
||||
$style[$property] = $xmlReader->getAttribute('w:val', $node);
|
||||
break;
|
||||
|
||||
case 'w:sz':
|
||||
$style[$property] = $xmlReader->getAttribute('w:val', $node) / 2;
|
||||
break;
|
||||
|
||||
case 'w:vertAlign':
|
||||
$style[$property] = $xmlReader->getAttribute('w:val', $node);
|
||||
if ($style[$property] == 'superscript') {
|
||||
$style['superScript'] = true;
|
||||
} else {
|
||||
$style['superScript'] = false;
|
||||
$style['subScript'] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$xmlReader->elementExists('w:rPr', $domNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $style;
|
||||
$styleNode = $xmlReader->getElement('w:rPr', $domNode);
|
||||
$styleDefs = array(
|
||||
'styleName' => array(self::READ_VALUE, 'w:rStyle'),
|
||||
'name' => array(self::READ_VALUE, 'w:rFonts', 'w:ascii'),
|
||||
'hint' => array(self::READ_VALUE, 'w:rFonts', 'w:hint'),
|
||||
'size' => array(self::READ_SIZE, 'w:sz'),
|
||||
'color' => array(self::READ_VALUE, 'w:color'),
|
||||
'underline' => array(self::READ_VALUE, 'w:u'),
|
||||
'bold' => array(self::READ_TRUE, 'w:b'),
|
||||
'italic' => array(self::READ_TRUE, 'w:i'),
|
||||
'strikethrough' => array(self::READ_TRUE, 'w:strike'),
|
||||
'doubleStrikethrough' => array(self::READ_TRUE, 'w:dstrike'),
|
||||
'smallCaps' => array(self::READ_TRUE, 'w:smallCaps'),
|
||||
'allCaps' => array(self::READ_TRUE, 'w:caps'),
|
||||
'superScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'superscript'),
|
||||
'subScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'subscript'),
|
||||
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
|
||||
);
|
||||
|
||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:tblPr
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @return string|array|null
|
||||
* @todo Capture w:tblStylePr w:type="firstRow"
|
||||
*/
|
||||
|
|
@ -279,39 +392,101 @@ abstract class AbstractPart
|
|||
if ($xmlReader->elementExists('w:tblPr/w:tblStyle', $domNode)) {
|
||||
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:tblPr/w:tblStyle');
|
||||
} else {
|
||||
$style = array();
|
||||
$mapping = array(
|
||||
'w:tblCellMar' => 'cellMargin',
|
||||
'w:tblBorders' => 'border',
|
||||
);
|
||||
$styleNode = $xmlReader->getElement('w:tblPr', $domNode);
|
||||
$styleDefs = array();
|
||||
// $styleDefs['styleName'] = array(self::READ_VALUE, 'w:tblStyle');
|
||||
foreach ($margins as $side) {
|
||||
$ucfSide = ucfirst($side);
|
||||
$styleDefs["cellMargin$ucfSide"] = array(self::READ_VALUE, "w:tblCellMar/w:$side", 'w:w');
|
||||
}
|
||||
foreach ($borders as $side) {
|
||||
$ucfSide = ucfirst($side);
|
||||
$styleDefs["border{$ucfSide}Size"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:sz');
|
||||
$styleDefs["border{$ucfSide}Color"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:color');
|
||||
}
|
||||
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $xmlReader->getElements('w:tblPr/*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
// $property = $mapping[$node->nodeName];
|
||||
switch ($node->nodeName) {
|
||||
return $style;
|
||||
}
|
||||
|
||||
case 'w:tblCellMar':
|
||||
foreach ($margins as $side) {
|
||||
$ucfSide = ucfirst($side);
|
||||
$style["cellMargin$ucfSide"] = $xmlReader->getAttribute('w:w', $node, "w:$side");
|
||||
}
|
||||
break;
|
||||
/**
|
||||
* Read w:tcPr
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @return array
|
||||
*/
|
||||
private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
$styleDefs = array(
|
||||
'valign' => array(self::READ_VALUE, 'w:vAlign'),
|
||||
'textDirection' => array(self::READ_VALUE, 'w:textDirection'),
|
||||
'gridSpan' => array(self::READ_VALUE, 'w:gridSpan'),
|
||||
'vMerge' => array(self::READ_VALUE, 'w:vMerge'),
|
||||
'bgColor' => array(self::READ_VALUE, 'w:shd/w:fill'),
|
||||
);
|
||||
|
||||
case 'w:tblBorders':
|
||||
foreach ($borders as $side) {
|
||||
$ucfSide = ucfirst($side);
|
||||
$style["border{$ucfSide}Size"] = $xmlReader->getAttribute('w:sz', $node, "w:$side");
|
||||
$style["border{$ucfSide}Color"] = $xmlReader->getAttribute('w:color', $node, "w:$side");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read style definition
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $parentNode
|
||||
* @param array $styleDefs
|
||||
* @ignoreScrutinizerPatch
|
||||
* @return array
|
||||
*/
|
||||
protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode = null, $styleDefs = array())
|
||||
{
|
||||
$styles = array();
|
||||
|
||||
foreach ($styleDefs as $styleProp => $styleVal) {
|
||||
@list($method, $element, $attribute, $expected) = $styleVal;
|
||||
|
||||
if ($xmlReader->elementExists($element, $parentNode)) {
|
||||
$node = $xmlReader->getElement($element, $parentNode);
|
||||
|
||||
// Use w:val as default if no attribute assigned
|
||||
$attribute = ($attribute === null) ? 'w:val' : $attribute;
|
||||
$attributeValue = $xmlReader->getAttribute($attribute, $node);
|
||||
|
||||
$styleValue = $this->readStyleDef($method, $attributeValue, $expected);
|
||||
if ($styleValue !== null) {
|
||||
$styles[$styleProp] = $styleValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return style definition based on conversion method
|
||||
*
|
||||
* @param string $method
|
||||
* @ignoreScrutinizerPatch
|
||||
* @param mixed $attributeValue
|
||||
* @param mixed $expected
|
||||
* @return mixed
|
||||
*/
|
||||
private function readStyleDef($method, $attributeValue, $expected)
|
||||
{
|
||||
$style = $attributeValue;
|
||||
|
||||
if ($method == self::READ_SIZE) {
|
||||
$style = $attributeValue / 2;
|
||||
} elseif ($method == self::READ_TRUE) {
|
||||
$style = true;
|
||||
} elseif ($method == self::READ_FALSE) {
|
||||
$style = false;
|
||||
} elseif ($method == self::READ_EQUAL && $attributeValue == $expected) {
|
||||
$style = true;
|
||||
}
|
||||
|
||||
return $style;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
|
||||
/**
|
||||
* Core/extended document properties reader
|
||||
*/
|
||||
class DocProps extends AbstractPart
|
||||
{
|
||||
/**
|
||||
* Property mapping
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mapping = array();
|
||||
|
||||
/**
|
||||
* Callback functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $callbacks = array();
|
||||
|
||||
/**
|
||||
* Read core/extended document properties
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
*/
|
||||
public function read(PhpWord &$phpWord)
|
||||
{
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||
|
||||
$docProps = $phpWord->getDocumentProperties();
|
||||
|
||||
$nodes = $xmlReader->getElements('*');
|
||||
if ($nodes->length > 0) {
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $this->mapping)) {
|
||||
continue;
|
||||
}
|
||||
$method = $this->mapping[$node->nodeName];
|
||||
$value = $node->nodeValue == '' ? null : $node->nodeValue;
|
||||
if (array_key_exists($node->nodeName, $this->callbacks)) {
|
||||
$value = $this->callbacks[$node->nodeName]($value);
|
||||
}
|
||||
if (method_exists($docProps, $method)) {
|
||||
$docProps->$method($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
||||
/**
|
||||
* Extended properties reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class DocPropsApp extends DocProps
|
||||
class DocPropsApp extends DocPropsCore
|
||||
{
|
||||
/**
|
||||
* Property mapping
|
||||
|
|
@ -20,4 +30,11 @@ class DocPropsApp extends DocProps
|
|||
* @var array
|
||||
*/
|
||||
protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager');
|
||||
|
||||
/**
|
||||
* Callback functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $callbacks = array();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
|
||||
/**
|
||||
* Core properties reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class DocPropsCore extends DocProps
|
||||
class DocPropsCore extends AbstractPart
|
||||
{
|
||||
/**
|
||||
* Property mapping
|
||||
|
|
@ -37,4 +50,34 @@ class DocPropsCore extends DocProps
|
|||
* @var array
|
||||
*/
|
||||
protected $callbacks = array('dcterms:created' => 'strtotime', 'dcterms:modified' => 'strtotime');
|
||||
|
||||
/**
|
||||
* Read core/extended document properties
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
*/
|
||||
public function read(PhpWord &$phpWord)
|
||||
{
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||
|
||||
$docProps = $phpWord->getDocumentProperties();
|
||||
|
||||
$nodes = $xmlReader->getElements('*');
|
||||
if ($nodes->length > 0) {
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $this->mapping)) {
|
||||
continue;
|
||||
}
|
||||
$method = $this->mapping[$node->nodeName];
|
||||
$value = $node->nodeValue == '' ? null : $node->nodeValue;
|
||||
if (array_key_exists($node->nodeName, $this->callbacks)) {
|
||||
$value = $this->callbacks[$node->nodeName]($value);
|
||||
}
|
||||
if (method_exists($docProps, $method)) {
|
||||
$docProps->$method($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
|
@ -15,6 +23,8 @@ use PhpOffice\PhpWord\Shared\XMLReader;
|
|||
|
||||
/**
|
||||
* Custom properties reader
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class DocPropsCustom extends AbstractPart
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,22 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
* 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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
use PhpOffice\PhpWord\Element\Section;
|
||||
|
||||
/**
|
||||
* Document reader
|
||||
*
|
||||
* @since 0.10.0
|
||||
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) For readWPNode
|
||||
*/
|
||||
class Document extends AbstractPart
|
||||
{
|
||||
/**
|
||||
* PhpWord object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
private $phpWord;
|
||||
|
||||
/**
|
||||
* Read document.xml
|
||||
*
|
||||
|
|
@ -24,49 +43,18 @@ class Document extends AbstractPart
|
|||
*/
|
||||
public function read(PhpWord &$phpWord)
|
||||
{
|
||||
$this->phpWord = $phpWord;
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
||||
$readMethods = array('w:p' => 'readWPNode', 'w:tbl' => 'readTable', 'w:sectPr' => 'readWSectPrNode');
|
||||
|
||||
$nodes = $xmlReader->getElements('w:body/*');
|
||||
if ($nodes->length > 0) {
|
||||
$section = $phpWord->addSection();
|
||||
$section = $this->phpWord->addSection();
|
||||
foreach ($nodes as $node) {
|
||||
switch ($node->nodeName) {
|
||||
|
||||
case 'w:p': // Paragraph
|
||||
// Page break
|
||||
// @todo <w:lastRenderedPageBreak>
|
||||
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
||||
$section->addPageBreak(); // PageBreak
|
||||
}
|
||||
|
||||
// Paragraph
|
||||
$this->readParagraph($xmlReader, $node, $section, 'document');
|
||||
// Section properties
|
||||
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
||||
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
||||
if (!is_null($settingsNode)) {
|
||||
$settings = $this->readSectionStyle($xmlReader, $settingsNode);
|
||||
$section->setSettings($settings);
|
||||
if (!is_null($settings)) {
|
||||
$this->readHeaderFooter($settings, $section);
|
||||
}
|
||||
}
|
||||
$section = $phpWord->addSection();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w:tbl': // Table
|
||||
$this->readTable($xmlReader, $node, $section, 'document');
|
||||
break;
|
||||
|
||||
case 'w:sectPr': // Last section
|
||||
$settings = $this->readSectionStyle($xmlReader, $node);
|
||||
$section->setSettings($settings);
|
||||
if (!is_null($settings)) {
|
||||
$this->readHeaderFooter($settings, $section);
|
||||
}
|
||||
break;
|
||||
if (array_key_exists($node->nodeName, $readMethods)) {
|
||||
$readMethod = $readMethods[$node->nodeName];
|
||||
$this->$readMethod($xmlReader, $node, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,14 +66,16 @@ class Document extends AbstractPart
|
|||
* @param array $settings
|
||||
* @param \PhpOffice\PhpWord\Element\Section $section
|
||||
*/
|
||||
private function readHeaderFooter($settings, &$section)
|
||||
private function readHeaderFooter($settings, Section &$section)
|
||||
{
|
||||
$readMethods = array('w:p' => 'readParagraph', 'w:tbl' => 'readTable');
|
||||
|
||||
if (is_array($settings) && array_key_exists('hf', $settings)) {
|
||||
foreach ($settings['hf'] as $rId => $hfSetting) {
|
||||
if (array_key_exists($rId, $this->rels['document'])) {
|
||||
list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]);
|
||||
$method = "add{$hfType}";
|
||||
$hfObject = $section->$method($hfSetting['type']);
|
||||
$addMethod = "add{$hfType}";
|
||||
$hfObject = $section->$addMethod($hfSetting['type']);
|
||||
|
||||
// Read header/footer content
|
||||
$xmlReader = new XMLReader();
|
||||
|
|
@ -93,160 +83,9 @@ class Document extends AbstractPart
|
|||
$nodes = $xmlReader->getElements('*');
|
||||
if ($nodes->length > 0) {
|
||||
foreach ($nodes as $node) {
|
||||
switch ($node->nodeName) {
|
||||
|
||||
case 'w:p': // Paragraph
|
||||
$this->readParagraph($xmlReader, $node, $hfObject, $docPart);
|
||||
break;
|
||||
|
||||
case 'w:tbl': // Table
|
||||
$this->readTable($xmlReader, $node, $hfObject, $docPart);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:p
|
||||
*
|
||||
* @param mixed $parent
|
||||
* @param string $docPart
|
||||
*
|
||||
* @todo Get font style for preserve text
|
||||
*/
|
||||
private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart)
|
||||
{
|
||||
// Paragraph style
|
||||
$paragraphStyle = null;
|
||||
$headingMatches = array();
|
||||
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
||||
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
||||
if (is_string($paragraphStyle)) {
|
||||
preg_match('/Heading(\d)/', $paragraphStyle, $headingMatches);
|
||||
}
|
||||
}
|
||||
|
||||
// PreserveText
|
||||
if ($xmlReader->elementExists('w:r/w:instrText', $domNode)) {
|
||||
$ignoreText = false;
|
||||
$textContent = '';
|
||||
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$instrText = $xmlReader->getValue('w:instrText', $node);
|
||||
if ($xmlReader->elementExists('w:fldChar', $node)) {
|
||||
$fldCharType = $xmlReader->getAttribute('w:fldCharType', $node, 'w:fldChar');
|
||||
if ($fldCharType == 'begin') {
|
||||
$ignoreText = true;
|
||||
} elseif ($fldCharType == 'end') {
|
||||
$ignoreText = false;
|
||||
}
|
||||
}
|
||||
if (!is_null($instrText)) {
|
||||
$textContent .= '{' . $instrText . '}';
|
||||
} else {
|
||||
if ($ignoreText === false) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
$parent->addPreserveText($textContent, $fontStyle, $paragraphStyle);
|
||||
|
||||
// List item
|
||||
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
|
||||
$textContent = '';
|
||||
$numId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:numId');
|
||||
$levelId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:ilvl');
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $paragraphStyle);
|
||||
|
||||
// Heading
|
||||
} elseif (!empty($headingMatches)) {
|
||||
$textContent = '';
|
||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||
}
|
||||
$parent->addTitle($textContent, $headingMatches[1]);
|
||||
|
||||
// Text and TextRun
|
||||
} else {
|
||||
$runCount = $xmlReader->countElements('w:r', $domNode);
|
||||
$linkCount = $xmlReader->countElements('w:hyperlink', $domNode);
|
||||
$runLinkCount = $runCount + $linkCount;
|
||||
if ($runLinkCount == 0) {
|
||||
$parent->addTextBreak(null, $paragraphStyle);
|
||||
} else {
|
||||
if ($runLinkCount > 1) {
|
||||
$textrun = $parent->addTextRun($paragraphStyle);
|
||||
$textParent = &$textrun;
|
||||
} else {
|
||||
$textParent = &$parent;
|
||||
}
|
||||
$nodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
$this->readRun($xmlReader, $node, $textParent, $docPart, $paragraphStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:tbl
|
||||
*
|
||||
* @param mixed $parent
|
||||
* @param string $docPart
|
||||
*/
|
||||
private function readTable(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart)
|
||||
{
|
||||
// Table style
|
||||
$tblStyle = null;
|
||||
if ($xmlReader->elementExists('w:tblPr', $domNode)) {
|
||||
$tblStyle = $this->readTableStyle($xmlReader, $domNode);
|
||||
}
|
||||
|
||||
$table = $parent->addTable($tblStyle);
|
||||
$tblNodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($tblNodes as $tblNode) {
|
||||
if ($tblNode->nodeName == 'w:tblGrid') { // Column
|
||||
// @todo Do something with table columns
|
||||
|
||||
} elseif ($tblNode->nodeName == 'w:tr') { // Row
|
||||
$rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight');
|
||||
$rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight');
|
||||
$rowHRule = $rowHRule == 'exact' ? true : false;
|
||||
$rowStyle = array(
|
||||
'tblHeader' => $xmlReader->elementExists('w:trPr/w:tblHeader', $tblNode),
|
||||
'cantSplit' => $xmlReader->elementExists('w:trPr/w:cantSplit', $tblNode),
|
||||
'exactHeight' => $rowHRule,
|
||||
);
|
||||
|
||||
$row = $table->addRow($rowHeight, $rowStyle);
|
||||
$rowNodes = $xmlReader->getElements('*', $tblNode);
|
||||
foreach ($rowNodes as $rowNode) {
|
||||
if ($rowNode->nodeName == 'w:trPr') { // Row style
|
||||
// @todo Do something with row style
|
||||
|
||||
} elseif ($rowNode->nodeName == 'w:tc') { // Cell
|
||||
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
|
||||
$cellStyle = null;
|
||||
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
|
||||
if (!is_null($cellStyleNode)) {
|
||||
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
|
||||
}
|
||||
|
||||
$cell = $row->addCell($cellWidth, $cellStyle);
|
||||
$cellNodes = $xmlReader->getElements('*', $rowNode);
|
||||
foreach ($cellNodes as $cellNode) {
|
||||
if ($cellNode->nodeName == 'w:p') { // Paragraph
|
||||
$this->readParagraph($xmlReader, $cellNode, $cell, $docPart);
|
||||
if (array_key_exists($node->nodeName, $readMethods)) {
|
||||
$readMethod = $readMethods[$node->nodeName];
|
||||
$this->$readMethod($xmlReader, $node, $hfObject, $docPart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -258,93 +97,86 @@ class Document extends AbstractPart
|
|||
/**
|
||||
* Read w:sectPr
|
||||
*
|
||||
* @return array|null
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $domNode
|
||||
* @ignoreScrutinizerPatch
|
||||
* @return array
|
||||
*/
|
||||
private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
{
|
||||
$ret = null;
|
||||
$mapping = array(
|
||||
'w:type' => 'breakType', 'w:pgSz' => 'pageSize',
|
||||
'w:pgMar' => 'pageMargin', 'w:cols' => 'columns',
|
||||
'w:headerReference' => 'header', 'w:footerReference' => 'footer',
|
||||
$styleDefs = array(
|
||||
'breakType' => array(self::READ_VALUE, 'w:type'),
|
||||
'pageSizeW' => array(self::READ_VALUE, 'w:pgSz', 'w:w'),
|
||||
'pageSizeH' => array(self::READ_VALUE, 'w:pgSz', 'w:h'),
|
||||
'orientation' => array(self::READ_VALUE, 'w:pgSz', 'w:orient'),
|
||||
'colsNum' => array(self::READ_VALUE, 'w:cols', 'w:num'),
|
||||
'colsSpace' => array(self::READ_VALUE, 'w:cols', 'w:space'),
|
||||
'topMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:top'),
|
||||
'leftMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:left'),
|
||||
'bottomMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'),
|
||||
'rightMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:right'),
|
||||
'headerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:header'),
|
||||
'footerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:footer'),
|
||||
'gutter' => array(self::READ_VALUE, 'w:pgMar', 'w:gutter'),
|
||||
);
|
||||
$styles = $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
|
||||
|
||||
// Header and footer
|
||||
// @todo Cleanup this part
|
||||
$nodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
$property = $mapping[$node->nodeName];
|
||||
switch ($node->nodeName) {
|
||||
|
||||
case 'w:type':
|
||||
$ret['breakType'] = $xmlReader->getAttribute('w:val', $node);
|
||||
break;
|
||||
|
||||
case 'w:pgSz':
|
||||
$ret['pageSizeW'] = $xmlReader->getAttribute('w:w', $node);
|
||||
$ret['pageSizeH'] = $xmlReader->getAttribute('w:h', $node);
|
||||
$ret['orientation'] = $xmlReader->getAttribute('w:orient', $node);
|
||||
break;
|
||||
|
||||
case 'w:pgMar':
|
||||
$ret['topMargin'] = $xmlReader->getAttribute('w:top', $node);
|
||||
$ret['leftMargin'] = $xmlReader->getAttribute('w:left', $node);
|
||||
$ret['bottomMargin'] = $xmlReader->getAttribute('w:bottom', $node);
|
||||
$ret['rightMargin'] = $xmlReader->getAttribute('w:right', $node);
|
||||
$ret['headerHeight'] = $xmlReader->getAttribute('w:header', $node);
|
||||
$ret['footerHeight'] = $xmlReader->getAttribute('w:footer', $node);
|
||||
$ret['gutter'] = $xmlReader->getAttribute('w:gutter', $node);
|
||||
break;
|
||||
|
||||
case 'w:cols':
|
||||
$ret['colsNum'] = $xmlReader->getAttribute('w:num', $node);
|
||||
$ret['colsSpace'] = $xmlReader->getAttribute('w:space', $node);
|
||||
break;
|
||||
|
||||
case 'w:headerReference':
|
||||
case 'w:footerReference':
|
||||
$id = $xmlReader->getAttribute('r:id', $node);
|
||||
$ret['hf'][$id] = array(
|
||||
'method' => $property,
|
||||
'type' => $xmlReader->getAttribute('w:type', $node),
|
||||
);
|
||||
break;
|
||||
if ($node->nodeName == 'w:headerReference' || $node->nodeName == 'w:footerReference') {
|
||||
$id = $xmlReader->getAttribute('r:id', $node);
|
||||
$styles['hf'][$id] = array(
|
||||
'method' => str_replace('w:', '', str_replace('Reference', '', $node->nodeName)),
|
||||
'type' => $xmlReader->getAttribute('w:type', $node),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:tcPr
|
||||
* Read w:p node
|
||||
*
|
||||
* @return array|null
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $node
|
||||
* @param \PhpOffice\PhpWord\Element\Section $section
|
||||
*
|
||||
* @todo <w:lastRenderedPageBreak>
|
||||
*/
|
||||
private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode)
|
||||
private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
|
||||
{
|
||||
$style = null;
|
||||
$mapping = array(
|
||||
'w:shd' => 'bgColor',
|
||||
'w:vAlign' => 'valign', 'w:textDirection' => 'textDirection',
|
||||
'w:gridSpan' => 'gridSpan', 'w:vMerge' => 'vMerge',
|
||||
);
|
||||
$nodes = $xmlReader->getElements('*', $domNode);
|
||||
foreach ($nodes as $node) {
|
||||
if (!array_key_exists($node->nodeName, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
$property = $mapping[$node->nodeName];
|
||||
switch ($node->nodeName) {
|
||||
case 'w:shd':
|
||||
$style['bgColor'] = $xmlReader->getAttribute('w:fill', $node);
|
||||
break;
|
||||
|
||||
default:
|
||||
$style[$property] = $xmlReader->getAttribute('w:val', $node);
|
||||
break;
|
||||
}
|
||||
// Page break
|
||||
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
||||
$section->addPageBreak(); // PageBreak
|
||||
}
|
||||
|
||||
return $style;
|
||||
// Paragraph
|
||||
$this->readParagraph($xmlReader, $node, $section);
|
||||
|
||||
// Section properties
|
||||
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
||||
$sectPrNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
||||
if ($sectPrNode !== null) {
|
||||
$this->readWSectPrNode($xmlReader, $sectPrNode, $section);
|
||||
}
|
||||
$section = $this->phpWord->addSection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read w:sectPr node
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
|
||||
* @param \DOMElement $node
|
||||
* @param \PhpOffice\PhpWord\Element\Section $section
|
||||
*/
|
||||
private function readWSectPrNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
|
||||
{
|
||||
$settings = $this->readSectionStyle($xmlReader, $node);
|
||||
$section->setSettings($settings);
|
||||
$this->readHeaderFooter($settings, $section);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue