at path:
ROOT
/
phpoffice.tar
run:
R
W
Run
.well-known
DIR
2024-07-18 07:32:21
R
W
Run
adstesting
DIR
2026-05-07 07:41:07
R
W
Run
androidfamilylocator
DIR
2026-05-07 07:41:18
R
W
Run
axelonyticslostphonefinder
DIR
2026-05-07 07:41:02
R
W
Run
axelonyticsmobiletracker
DIR
2026-05-07 07:41:18
R
W
Run
axelonyticsparentlink
DIR
2026-05-07 07:41:07
R
W
Run
callforhelp
DIR
2026-05-07 07:40:54
R
W
Run
carmanagement
DIR
2026-05-07 07:40:52
R
W
Run
devicetrackerplus
DIR
2026-05-07 07:41:03
R
W
Run
docspot
DIR
2026-05-07 07:40:54
R
W
Run
eventhybrid
DIR
2026-05-07 07:41:03
R
W
Run
excusefinder
DIR
2026-05-07 07:41:18
R
W
Run
findlostphonerapid
DIR
2026-05-07 07:41:18
R
W
Run
findmykids
DIR
2026-05-07 07:41:02
R
W
Run
foodproducts
DIR
2026-05-07 07:41:20
R
W
Run
halalfoodscanner
DIR
2026-05-07 07:41:02
R
W
Run
home
DIR
2023-09-05 11:51:03
R
W
Run
innovagictechnologies
DIR
2026-05-07 07:41:18
R
W
Run
innovagicwebsite
DIR
2026-05-07 07:41:18
R
W
Run
khalis
DIR
2026-05-07 07:40:54
R
W
Run
lastpassmanager
DIR
2026-05-07 07:41:01
R
W
Run
lostphonerainbow
DIR
2026-05-07 07:41:03
R
W
Run
lostphonetrack
DIR
2026-05-07 07:41:02
R
W
Run
lyricstudio
DIR
2026-05-07 07:40:54
R
W
Run
muffinbreak
DIR
2026-05-07 07:41:02
R
W
Run
numanarshad
DIR
2026-05-07 07:41:18
R
W
Run
offlinephonetrack
DIR
2026-05-07 07:41:01
R
W
Run
parentalcontrol
DIR
2026-05-07 07:41:02
R
W
Run
pushnoti
DIR
2026-05-07 07:41:02
R
W
Run
pushnotification
DIR
2026-05-07 07:41:07
R
W
Run
remotemouse
DIR
2026-05-07 07:40:54
R
W
Run
scrum
DIR
2026-05-07 07:40:59
R
W
Run
scrumapp
DIR
2026-05-07 07:41:20
R
W
Run
scrumhrmanagement
DIR
2026-05-07 07:41:03
R
W
Run
scrumlive
DIR
2026-05-07 07:41:02
R
W
Run
seminarhub
DIR
2026-05-07 07:41:03
R
W
Run
seventyfivechallenges
DIR
2026-05-07 07:41:06
R
W
Run
shaheer
DIR
2026-05-07 07:41:07
R
W
Run
smartswitchphone
DIR
2026-05-07 07:41:02
R
W
Run
trackviewblue
DIR
2026-05-07 07:40:52
R
W
Run
trackviewnewapp
DIR
2026-05-07 07:41:18
R
W
Run
virtualstudygroup
DIR
2026-05-07 07:41:03
R
W
Run
vkonnect
DIR
2026-05-07 07:41:06
R
W
Run
warrantyapp
DIR
2026-05-07 07:40:52
R
W
Run
wp-admin
DIR
2026-05-07 07:41:02
R
W
Run
wp-content
DIR
2026-05-07 07:40:54
R
W
Run
wp-includes
DIR
2026-05-07 07:41:18
R
W
Run
zengo
DIR
2026-05-07 07:41:18
R
W
Run
.Archive.tar
4.5 KB
2026-05-07 12:05:59
R
W
Run
Delete
Rename
.Archive.tar.gz
656 By
2026-05-07 12:05:59
R
W
Run
Delete
Rename
.Archive.zip
1.53 KB
2026-05-07 12:04:14
R
W
Run
Delete
Rename
.Sent.zip
673 By
2026-05-07 12:04:07
R
W
Run
Delete
Rename
.Trash.tar
3 KB
2026-05-07 12:05:16
R
W
Run
Delete
Rename
.Trash.tar.gz
339 By
2026-05-07 12:05:16
R
W
Run
Delete
Rename
.Trash.zip
673 By
2026-05-07 12:05:00
R
W
Run
Delete
Rename
.bash_profile.bash_profile.tar.gz
253 By
2026-05-07 11:08:49
R
W
Run
Delete
Rename
.bash_profile.tar
2 KB
2026-05-07 11:08:49
R
W
Run
Delete
Rename
.cache.tar
2.66 MB
2026-05-07 11:07:01
R
W
Run
Delete
Rename
.cache.tar.gz
1.03 MB
2026-05-07 11:07:02
R
W
Run
Delete
Rename
.cache.zip
2.62 MB
2026-05-07 11:06:11
R
W
Run
Delete
Rename
.caldav.tar
10 KB
2026-05-07 11:06:11
R
W
Run
Delete
Rename
.caldav.tar.gz
1.17 KB
2026-05-07 11:06:11
R
W
Run
Delete
Rename
.caldav.zip
4.17 KB
2026-05-07 11:05:50
R
W
Run
Delete
Rename
.channels.zip
4.34 KB
2026-05-07 12:05:08
R
W
Run
Delete
Rename
.composer.zip
320 By
2026-05-07 11:06:59
R
W
Run
Delete
Rename
.config.zip
124.06 MB
2026-05-07 11:06:08
R
W
Run
Delete
Rename
.gnupg.zip
8.08 KB
2026-05-07 11:06:45
R
W
Run
Delete
Rename
.htaccess
2.08 KB
2026-05-06 07:15:54
R
W
Run
Delete
Rename
.htaccess.htaccess.tar.gz
961 By
2026-05-07 10:04:13
R
W
Run
Delete
Rename
.htaccess.tar
4 KB
2026-05-07 10:04:13
R
W
Run
Delete
Rename
.local.tar
2 KB
2026-05-07 12:04:52
R
W
Run
Delete
Rename
.local.tar.gz
119 By
2026-05-07 12:04:52
R
W
Run
Delete
Rename
.local.zip
195 By
2026-05-07 12:04:19
R
W
Run
Delete
Rename
.lock.lock.tar.gz
107 By
2026-05-07 12:03:30
R
W
Run
Delete
Rename
.lock.tar
1.5 KB
2026-05-07 12:03:30
R
W
Run
Delete
Rename
.php.error.log.php.error.log.tar.gz
1.62 KB
2026-05-07 12:06:08
R
W
Run
Delete
Rename
.php.error.log.tar
25 KB
2026-05-07 12:06:08
R
W
Run
Delete
Rename
.razor.tar
37 KB
2026-05-07 11:06:41
R
W
Run
Delete
Rename
.razor.tar.gz
4.75 KB
2026-05-07 11:06:41
R
W
Run
Delete
Rename
.razor.zip
32.15 KB
2026-05-07 11:05:57
R
W
Run
Delete
Rename
.scrummanager@toptrendingappstudio_com.tar
758.5 KB
2026-05-07 12:07:38
R
W
Run
Delete
Rename
.scrummanager@toptrendingappstudio_com.tar.gz
299.44 KB
2026-05-07 12:07:39
R
W
Run
Delete
Rename
.scrummanager@toptrendingappstudio_com.zip
704.09 KB
2026-05-07 12:08:06
R
W
Run
Delete
Rename
.spamassassin.zip
62.23 KB
2026-05-07 11:06:46
R
W
Run
Delete
Rename
.spamassassinboxenable.spamassassinboxenable.tar.gz
117 By
2026-05-07 12:13:18
R
W
Run
Delete
Rename
.spamassassinboxenable.tar
1.5 KB
2026-05-07 12:13:18
R
W
Run
Delete
Rename
.spamassassinenable.spamassassinenable.tar.gz
114 By
2026-05-07 11:08:47
R
W
Run
Delete
Rename
.spamassassinenable.tar
1.5 KB
2026-05-07 11:08:47
R
W
Run
Delete
Rename
.ssh.tar
6.5 KB
2026-05-07 11:06:10
R
W
Run
Delete
Rename
.ssh.tar.gz
1.93 KB
2026-05-07 11:06:10
R
W
Run
Delete
Rename
.ssh.zip
3.18 KB
2026-05-07 11:05:49
R
W
Run
Delete
Rename
.subaccounts.tar
17.5 KB
2026-05-07 11:06:41
R
W
Run
Delete
Rename
.subaccounts.tar.gz
495 By
2026-05-07 11:06:41
R
W
Run
Delete
Rename
.subaccounts.zip
16.16 KB
2026-05-07 11:06:13
R
W
Run
Delete
Rename
.user.ini.tar
2.5 KB
2026-05-07 11:08:46
R
W
Run
Delete
Rename
.user.ini.user.ini.tar.gz
463 By
2026-05-07 11:08:46
R
W
Run
Delete
Rename
.wget-hsts.tar
2 KB
2026-05-07 11:06:06
R
W
Run
Delete
Rename
.wget-hsts.wget-hsts.tar.gz
270 By
2026-05-07 11:06:06
R
W
Run
Delete
Rename
.wp-cli.tar
2 KB
2026-05-07 11:06:04
R
W
Run
Delete
Rename
.wp-cli.tar.gz
125 By
2026-05-07 11:06:04
R
W
Run
Delete
Rename
.wp-cli.zip
209 By
2026-05-07 11:05:25
R
W
Run
Delete
Rename
.wp-toolkit-identifier.tar
2.5 KB
2026-05-07 11:08:50
R
W
Run
Delete
Rename
.wp-toolkit-identifier.wp-toolkit-identifier.tar.gz
669 By
2026-05-07 11:08:50
R
W
Run
Delete
Rename
115743369141451647082_scaled_uu ju jj.jpg.jpg.tar.gz
7.56 KB
2026-05-07 12:07:15
R
W
Run
Delete
Rename
115743369141451647082_scaled_uu ju jj.jpg.tar
9.5 KB
2026-05-07 12:07:15
R
W
Run
Delete
Rename
14_1000016331.jpg.jpg.tar.gz
413.83 KB
2026-05-07 12:06:07
R
W
Run
Delete
Rename
14_1000016331.jpg.tar
454.5 KB
2026-05-07 12:06:07
R
W
Run
Delete
Rename
3_1000016296.jpg.jpg.tar.gz
514.67 KB
2026-05-07 12:06:48
R
W
Run
Delete
Rename
3_1000016296.jpg.tar
552.5 KB
2026-05-07 12:06:48
R
W
Run
Delete
Rename
66.php.php.tar.gz
679.9 KB
2026-05-07 10:03:53
R
W
Run
Delete
Rename
66.php.tar
1.18 MB
2026-05-07 10:03:53
R
W
Run
Delete
Rename
666.php.php.tar.gz
24.71 KB
2026-05-07 10:03:52
R
W
Run
Delete
Rename
666.php.tar
80.5 KB
2026-05-07 10:03:52
R
W
Run
Delete
Rename
8.php
15.05 KB
2026-05-07 07:39:38
R
W
Run
Delete
Rename
8.php.php.tar.gz
4.68 KB
2026-05-07 10:03:14
R
W
Run
Delete
Rename
8.php.tar
17 KB
2026-05-07 10:03:14
R
W
Run
Delete
Rename
a.php.php.tar.gz
242 By
2026-05-07 12:05:14
R
W
Run
Delete
Rename
a.php.tar
2 KB
2026-05-07 12:05:14
R
W
Run
Delete
Rename
access-logs.tar
63.59 MB
2026-05-07 11:08:45
R
W
Run
Delete
Rename
access-logs.tar.gz
3.1 MB
2026-05-07 11:08:47
R
W
Run
Delete
Rename
awstats.tar
1.5 GB
2026-05-07 12:13:37
R
W
Run
Delete
Rename
awstats.tar.gz
109.24 MB
2026-05-07 12:14:37
R
W
Run
Delete
Rename
bayes_toks.tar
49.5 KB
2026-05-07 12:13:29
R
W
Run
Delete
Rename
bayes_toks.tar.gz
14.93 KB
2026-05-07 12:13:29
R
W
Run
Delete
Rename
bin.tar
5.68 MB
2026-05-07 12:11:50
R
W
Run
Delete
Rename
bin.tar.gz
1.21 MB
2026-05-07 11:07:03
R
W
Run
Delete
Rename
bin.zip
5.4 MB
2026-05-07 12:10:49
R
W
Run
Delete
Rename
cache.tar
2 KB
2026-05-07 12:05:54
R
W
Run
Delete
Rename
cache.tar.gz
104 By
2026-05-07 12:05:54
R
W
Run
Delete
Rename
cacheid.tar
2 KB
2026-05-07 12:05:20
R
W
Run
Delete
Rename
cacheid.tar.gz
120 By
2026-05-07 12:05:20
R
W
Run
Delete
Rename
caches.tar
59 KB
2026-05-07 12:13:18
R
W
Run
Delete
Rename
caches.tar.gz
11.1 KB
2026-05-07 12:13:18
R
W
Run
Delete
Rename
cboden.tar
224.5 KB
2026-05-07 12:12:50
R
W
Run
Delete
Rename
cboden.tar.gz
36.15 KB
2026-05-07 12:12:50
R
W
Run
Delete
Rename
cboden.zip
177.43 KB
2026-05-07 12:11:46
R
W
Run
Delete
Rename
citycam.tar
58.72 MB
2026-05-07 12:05:19
R
W
Run
Delete
Rename
citycam.tar.gz
58.29 MB
2026-05-07 12:05:22
R
W
Run
Delete
Rename
citycam.zip
58.7 MB
2026-05-07 12:05:03
R
W
Run
Delete
Rename
composer.json.json.tar.gz
337 By
2026-05-07 11:08:32
R
W
Run
Delete
Rename
composer.json.tar
2 KB
2026-05-07 11:08:32
R
W
Run
Delete
Rename
composer.lock.lock.tar.gz
9.36 KB
2026-05-07 11:08:37
R
W
Run
Delete
Rename
composer.lock.tar
84 KB
2026-05-07 11:08:37
R
W
Run
Delete
Rename
composer.tar
5.42 MB
2026-05-07 12:12:34
R
W
Run
Delete
Rename
composer.tar.gz
543.1 KB
2026-05-07 11:08:54
R
W
Run
Delete
Rename
composer.zip
2.77 MB
2026-05-07 12:12:21
R
W
Run
Delete
Rename
deletegoogleaccount_php.php.php.tar.gz
627 By
2026-05-07 12:06:23
R
W
Run
Delete
Rename
deletegoogleaccount_php.php.tar
3 KB
2026-05-07 12:06:23
R
W
Run
Delete
Rename
doctrine.tar
15.5 KB
2026-05-07 12:12:31
R
W
Run
Delete
Rename
doctrine.tar.gz
3.64 KB
2026-05-07 12:12:31
R
W
Run
Delete
Rename
doctrine.zip
11.38 KB
2026-05-07 12:12:50
R
W
Run
Delete
Rename
dompdf.tar
9.11 MB
2026-05-07 12:12:17
R
W
Run
Delete
Rename
dompdf.tar.gz
3.63 MB
2026-05-07 12:12:17
R
W
Run
Delete
Rename
dompdf.zip
9.03 MB
2026-05-07 12:11:51
R
W
Run
Delete
Rename
dovecot-acl-list.tar
1.5 KB
2026-05-07 12:06:12
R
W
Run
Delete
Rename
dovecot-acl-list.tar.gz
113 By
2026-05-07 12:06:12
R
W
Run
Delete
Rename
dovecot.list.index.log.list.index.log.tar.gz
1.48 KB
2026-05-07 12:06:53
R
W
Run
Delete
Rename
dovecot.list.index.log.tar
9 KB
2026-05-07 12:06:53
R
W
Run
Delete
Rename
egulias.zip
268.99 KB
2026-05-07 12:12:33
R
W
Run
Delete
Rename
error_log
891 By
2026-05-07 13:38:51
R
W
Run
Delete
Rename
error_log.tar
4 KB
2026-05-07 12:12:40
R
W
Run
Delete
Rename
error_log.tar.gz
1.92 KB
2026-05-07 10:03:53
R
W
Run
Delete
Rename
etc.tar
24.04 MB
2026-05-07 11:06:41
R
W
Run
Delete
Rename
etc.tar.gz
795.71 KB
2026-05-07 11:06:42
R
W
Run
Delete
Rename
etc.zip
24.01 MB
2026-05-07 11:05:58
R
W
Run
Delete
Rename
evenement.tar
58.5 KB
2026-05-07 12:12:36
R
W
Run
Delete
Rename
evenement.tar.gz
8.91 KB
2026-05-07 12:12:36
R
W
Run
Delete
Rename
evenement.zip
43.7 KB
2026-05-07 12:12:22
R
W
Run
Delete
Rename
getData.php.php.tar.gz
504 By
2026-05-07 12:06:09
R
W
Run
Delete
Rename
getData.php.tar
2.5 KB
2026-05-07 12:06:09
R
W
Run
Delete
Rename
get_all_contests.php.3.php.3.tar.gz
730 By
2026-05-07 12:06:14
R
W
Run
Delete
Rename
get_all_contests.php.3.tar
3 KB
2026-05-07 12:06:14
R
W
Run
Delete
Rename
gpg.conf.conf.tar.gz
3.31 KB
2026-05-07 12:06:12
R
W
Run
Delete
Rename
gpg.conf.tar
9 KB
2026-05-07 12:06:12
R
W
Run
Delete
Rename
hmsc.so.so.tar.gz
1.33 MB
2026-05-07 12:06:01
R
W
Run
Delete
Rename
hmsc.so.tar
2.96 MB
2026-05-07 12:06:01
R
W
Run
Delete
Rename
icals.zip
3.18 KB
2026-05-07 12:12:34
R
W
Run
Delete
Rename
images.tar
241.5 KB
2026-05-07 12:13:18
R
W
Run
Delete
Rename
images.tar.gz
239.71 KB
2026-05-07 12:05:23
R
W
Run
Delete
Rename
index.php.php.tar.gz
2.05 KB
2026-05-07 11:08:28
R
W
Run
Delete
Rename
index.php.tar
11.5 KB
2026-05-07 11:08:28
R
W
Run
Delete
Rename
keys.tar
108.5 KB
2026-05-07 12:05:44
R
W
Run
Delete
Rename
keys.tar.gz
52.97 KB
2026-05-07 12:05:45
R
W
Run
Delete
Rename
laminas.zip
171.21 KB
2026-05-07 12:12:40
R
W
Run
Delete
Rename
logs.tar
86.31 MB
2026-05-07 11:06:12
R
W
Run
Delete
Rename
logs.tar.gz
34.76 MB
2026-05-07 11:06:14
R
W
Run
Delete
Rename
logs.zip
86.15 MB
2026-05-07 11:05:51
R
W
Run
Delete
Rename
mailbox_format.cpanel.cpanel.tar.gz
130 By
2026-05-07 12:06:14
R
W
Run
Delete
Rename
mailbox_format.cpanel.tar
2 KB
2026-05-07 12:06:14
R
W
Run
Delete
Rename
maildirsize.tar
6 KB
2026-05-07 12:06:10
R
W
Run
Delete
Rename
maildirsize.tar.gz
1.19 KB
2026-05-07 12:06:10
R
W
Run
Delete
Rename
new.tar
22.98 MB
2026-05-07 12:05:44
R
W
Run
Delete
Rename
new.tar.gz
1.37 MB
2026-05-07 12:05:45
R
W
Run
Delete
Rename
nvdata.zip
5 KB
2026-05-07 12:12:31
R
W
Run
Delete
Rename
p.php.php.tar.gz
307 By
2026-05-07 12:05:08
R
W
Run
Delete
Rename
p.php.tar
2 KB
2026-05-07 12:05:08
R
W
Run
Delete
Rename
phenx.tar
647.5 KB
2026-05-07 12:12:33
R
W
Run
Delete
Rename
phenx.tar.gz
117.8 KB
2026-05-07 12:12:33
R
W
Run
Delete
Rename
phenx.zip
590.77 KB
2026-05-07 12:12:18
R
W
Run
Delete
Rename
php-cli.tar
2 KB
2026-05-07 11:06:07
R
W
Run
Delete
Rename
php-cli.tar.gz
111 By
2026-05-07 11:06:07
R
W
Run
Delete
Rename
php-cli.zip
169 By
2026-05-07 11:05:47
R
W
Run
Delete
Rename
php.ini.swp.ini.swp.tar.gz
3.56 KB
2026-05-07 12:11:16
R
W
Run
Delete
Rename
php.ini.swp.tar
17.5 KB
2026-05-07 12:11:16
R
W
Run
Delete
Rename
php.tar
12 KB
2026-05-07 11:14:27
R
W
Run
Delete
Rename
php.tar.gz
983 By
2026-05-07 11:06:57
R
W
Run
Delete
Rename
php.zip
4.72 KB
2026-05-07 11:15:10
R
W
Run
Delete
Rename
phpoffice.tar
1.82 MB
2026-05-07 12:12:41
R
W
Run
Delete
Rename
phpoffice.tar.gz
263.76 KB
2026-05-07 12:12:41
R
W
Run
Delete
Rename
phpoffice.zip
1.62 MB
2026-05-07 12:12:38
R
W
Run
Delete
Rename
prepend.txt.tar
121.1 MB
2026-05-07 12:06:14
R
W
Run
Delete
Rename
prepend.txt.txt.tar.gz
12.71 MB
2026-05-07 12:06:21
R
W
Run
Delete
Rename
psr.zip
59.33 KB
2026-05-07 12:11:48
R
W
Run
Delete
Rename
public_ftp.zip
975.85 MB
2026-05-07 11:06:47
R
W
Run
Delete
Rename
public_html.tar
977.12 MB
2026-05-07 12:06:28
R
W
Run
Delete
Rename
public_html.tar.gz
32 KB
2026-05-07 12:06:52
R
W
Run
Delete
Rename
ralouphie.tar
8.5 KB
2026-05-07 12:12:37
R
W
Run
Delete
Rename
ralouphie.tar.gz
1.88 KB
2026-05-07 12:12:37
R
W
Run
Delete
Rename
ralouphie.zip
4.84 KB
2026-05-07 12:12:24
R
W
Run
Delete
Rename
ratchet.zip
140.66 KB
2026-05-07 12:12:21
R
W
Run
Delete
Rename
react.zip
731.88 KB
2026-05-07 12:12:22
R
W
Run
Delete
Rename
robots.txt
2.34 KB
2026-05-07 07:32:42
R
W
Run
Delete
Rename
robots.txt.tar
4 KB
2026-05-07 10:03:14
R
W
Run
Delete
Rename
robots.txt.txt.tar.gz
322 By
2026-05-07 10:03:14
R
W
Run
Delete
Rename
roundcube.tar
9.5 KB
2026-05-07 12:05:24
R
W
Run
Delete
Rename
roundcube.tar.gz
1.55 KB
2026-05-07 12:05:24
R
W
Run
Delete
Rename
saveData.php.php.tar.gz
445 By
2026-05-07 12:06:09
R
W
Run
Delete
Rename
saveData.php.tar
2.5 KB
2026-05-07 12:06:09
R
W
Run
Delete
Rename
save_admin_details.php.php.tar.gz
779 By
2026-05-07 12:06:15
R
W
Run
Delete
Rename
save_admin_details.php.tar
4 KB
2026-05-07 12:06:15
R
W
Run
Delete
Rename
scrum_toptrendingappstudio_com.php.error.log.php.error.log.tar.gz
125.37 KB
2026-05-07 12:08:05
R
W
Run
Delete
Rename
scrum_toptrendingappstudio_com.php.error.log.tar
1.9 MB
2026-05-07 12:08:04
R
W
Run
Delete
Rename
server.c302.cloudmark.com.conf.tar
2.5 KB
2026-05-07 12:13:48
R
W
Run
Delete
Rename
share.zip
183 By
2026-05-07 12:05:55
R
W
Run
Delete
Rename
ssl.zip
717.75 KB
2026-05-07 11:06:08
R
W
Run
Delete
Rename
storage.sqlite.sqlite.tar.gz
521 By
2026-05-07 12:06:07
R
W
Run
Delete
Rename
storage.sqlite.tar
17.5 KB
2026-05-07 12:06:07
R
W
Run
Delete
Rename
swiftmailer.zip
717.46 KB
2026-05-07 12:12:38
R
W
Run
Delete
Rename
symfony.zip
2.79 MB
2026-05-07 12:14:18
R
W
Run
Delete
Rename
toptrendingappst.rcube.db.1771972649.rcube.db.1771972649.tar.gz
12.34 KB
2026-05-07 12:08:05
R
W
Run
Delete
Rename
toptrendingappst.rcube.db.1771972649.tar
457.5 KB
2026-05-07 12:08:05
R
W
Run
Delete
Rename
toptrendingappst.zip
3.87 KB
2026-05-07 12:13:19
R
W
Run
Delete
Rename
userAudio_30.3gp.3gp.tar.gz
22.83 KB
2026-05-07 12:06:14
R
W
Run
Delete
Rename
userAudio_30.3gp.tar
31 KB
2026-05-07 12:06:14
R
W
Run
Delete
Rename
userAudio_99.3gp.3gp.tar.gz
612 By
2026-05-07 12:06:15
R
W
Run
Delete
Rename
userAudio_99.3gp.tar
12.5 KB
2026-05-07 12:06:15
R
W
Run
Delete
Rename
vendor.tar
2.53 MB
2026-05-07 12:12:37
R
W
Run
Delete
Rename
vendor.tar.gz
475.53 KB
2026-05-07 12:12:38
R
W
Run
Delete
Rename
vendor.zip
2.13 MB
2026-05-07 12:12:37
R
W
Run
Delete
Rename
webalizer.tar
450.43 MB
2026-05-07 12:12:19
R
W
Run
Delete
Rename
www.tar
117.38 MB
2026-05-07 11:06:08
R
W
Run
Delete
Rename
www.tar.gz
39.75 MB
2026-05-07 11:06:12
R
W
Run
Delete
Rename
www.zip
3.54 MB
2026-05-07 11:05:46
R
W
Run
Delete
Rename
error_log
up
📄
phpoffice.tar
Save
phpword/.github/workflows/ci.yml 0000664 00000015123 15177100670 0012752 0 ustar 00 name: CI on: - push - pull_request jobs: test: runs-on: ubuntu-latest strategy: matrix: php-version: - '7.2' - "7.3" - "7.4" - "8.0" name: PHP ${{ matrix.php-version }} steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Update PHPUnit version for PHP 8 id: composer-lock if: "startsWith(matrix.php-version, '8.')" run: | rm -f composer.lock echo "::set-output name=flags::--ignore-platform-reqs" composer remove phpunit/phpunit --dev --no-update --no-interaction composer require phpunit/phpunit ^8.0 --dev --no-update - name: Install dependencies run: composer update --no-progress --prefer-dist --optimize-autoloader ${{ steps.composer-lock.outputs.flags }} - name: Update code to make PHPUnit 8 compatible if: "startsWith(matrix.php-version, '8.')" run: | find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \; find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \; sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php - name: Setup problem matchers for PHP run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Configure matchers uses: mheap/phpunit-matcher-action@v1 - name: Test with PHPUnit run: ./vendor/bin/phpunit --teamcity --no-coverage -c ./ php-cs-fixer: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Code style with PHP-CS-Fixer run: ./vendor/bin/php-cs-fixer fix --dry-run --show-progress=none --using-cache=no -v --format=checkstyle | cs2pr phpcs: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: none tools: cs2pr - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Code style with PHP_CodeSniffer run: ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip --report=checkstyle | cs2pr coverage: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib coverage: xdebug - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Coverage run: | ./vendor/bin/phpunit --coverage-clover coverage-clover.xml curl -LO https://scrutinizer-ci.com/ocular.phar php ocular.phar code-coverage:upload --format=php-clover coverage-clover.xml phpword/.github/workflows/github-pages.yml 0000664 00000001374 15177100670 0014741 0 ustar 00 name: GithHub Pages on: push: tags: - '*' jobs: github-pages: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 coverage: none # remove xdebug - name: Build API documentation run: | curl -LO https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.0.0/phpDocumentor.phar php phpDocumentor.phar --directory src/ --target docs/api - name: Deploy to GithHub Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/api phpword/.github/ISSUE_TEMPLATE/how-to-use.md 0000664 00000000702 15177100670 0014310 0 ustar 00 --- name: How to Use PHPWord about: Find out how to use PHPWord labels: WontFix --- ***Please do not use the issue tracker to ask how to use PHPWord.*** Documentation is available on [Read the Docs](https://phpword.readthedocs.io/en/latest/). Sample code is in the [`/samples/` directory](https://github.com/PHPOffice/PHPWord/tree/develop/samples). Usage questions belong on [Stack Overflow](https://stackoverflow.com/questions/tagged/phpword). phpword/.github/ISSUE_TEMPLATE/feature_request.md 0000664 00000001113 15177100670 0015501 0 ustar 00 --- name: Feature request about: Suggest an idea for this project labels: Change Request --- ### Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] ### Describe the solution you'd like A clear and concise description of what you want to happen. ### Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. ### Additional context Add any other context or screenshots about the feature request here. phpword/.github/ISSUE_TEMPLATE/bug_report.md 0000664 00000001176 15177100670 0014457 0 ustar 00 --- name: Bug report about: Create a report to help improve PHPWord labels: Bug Report --- ### Describe the Bug A clear and concise description of what the bug is. ### Steps to Reproduce Please provide a code sample that reproduces the issue. ```php <?php require __DIR__ . '/vendor/autoload.php'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $section->... ``` ### Expected Behavior A clear and concise description of what you expected to happen. ### Current Behavior What is the current behavior? ### Context Please fill in your environment information: - PHP Version: - PHPWord Version: phpword/.github/support.yml 0000664 00000001072 15177100670 0012034 0 ustar 00 # Label used to mark issues as support requests supportLabel: Question # Comment to post on issues marked as support requests. Add a link # to a support page, or set to `false` to disable supportComment: > This looks like a support question. Please ask your support questions on [StackOverflow](http://stackoverflow.com/questions/tagged/phpword), or [Gitter](https://gitter.im/PHPOffice/PHPWord). Thank you for your contributions. # Whether to close issues marked as support requests close: true # Whether to lock issues marked as support requests lock: false phpword/.github/PULL_REQUEST_TEMPLATE.md 0000664 00000000624 15177100670 0013400 0 ustar 00 ### Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. Fixes # (issue) ### Checklist: - [ ] I have run `composer run-script check --timeout=0` and no errors were reported - [ ] The new code is covered by unit tests (check build/coverage for coverage report) - [ ] I have updated the documentation to describe the changes phpword/.github/dependabot.yml 0000664 00000000226 15177100670 0012425 0 ustar 00 version: 2 updates: - package-ecosystem: composer directory: "/" schedule: interval: monthly time: "11:00" open-pull-requests-limit: 10 phpword/src/PhpWord/Collection/Bookmarks.php 0000664 00000001461 15177100670 0015145 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Bookmarks collection * * @since 0.12.0 */ class Bookmarks extends AbstractCollection { } phpword/src/PhpWord/Collection/Comments.php 0000664 00000001457 15177100670 0015007 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Comments collection * * @since 0.12.0 */ class Comments extends AbstractCollection { } phpword/src/PhpWord/Collection/AbstractCollection.php 0000664 00000004133 15177100670 0016773 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Collection abstract class * * @since 0.10.0 */ abstract class AbstractCollection { /** * Items * * @var \PhpOffice\PhpWord\Element\AbstractContainer[] */ private $items = array(); /** * Get items * * @return \PhpOffice\PhpWord\Element\AbstractContainer[] */ public function getItems() { return $this->items; } /** * Get item by index * * @param int $index * @return \PhpOffice\PhpWord\Element\AbstractContainer */ public function getItem($index) { if (array_key_exists($index, $this->items)) { return $this->items[$index]; } return null; } /** * Set item. * * @param int $index * @param \PhpOffice\PhpWord\Element\AbstractContainer $item */ public function setItem($index, $item) { if (array_key_exists($index, $this->items)) { $this->items[$index] = $item; } } /** * Add new item * * @param \PhpOffice\PhpWord\Element\AbstractContainer $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); } } phpword/src/PhpWord/Collection/Charts.php 0000664 00000001453 15177100670 0014442 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Charts collection * * @since 0.12.0 */ class Charts extends AbstractCollection { } phpword/src/PhpWord/Collection/Endnotes.php 0000664 00000001457 15177100670 0015001 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Endnotes collection * * @since 0.10.0 */ class Endnotes extends AbstractCollection { } phpword/src/PhpWord/Collection/Footnotes.php 0000664 00000001461 15177100670 0015175 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Footnotes collection * * @since 0.10.0 */ class Footnotes extends AbstractCollection { } phpword/src/PhpWord/Collection/Titles.php 0000664 00000001453 15177100670 0014462 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Collection; /** * Titles collection * * @since 0.10.0 */ class Titles extends AbstractCollection { } phpword/src/PhpWord/Metadata/Protection.php 0000664 00000007723 15177100670 0014777 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Metadata; use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder; use PhpOffice\PhpWord\SimpleType\DocProtect; /** * Document protection class * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html */ class Protection { /** * Editing restriction none|readOnly|comments|trackedChanges|forms * * @var string * @see http://www.datypic.com/sc/ooxml/a-w_edit-1.html */ private $editing; /** * password * * @var string */ private $password; /** * Iterations to Run Hashing Algorithm * * @var int */ private $spinCount = 100000; /** * Cryptographic Hashing Algorithm (see constants defined in \PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder) * * @var string */ private $algorithm = PasswordEncoder::ALGORITHM_SHA_1; /** * Salt for Password Verifier * * @var string */ private $salt; /** * Create a new instance * * @param string $editing */ public function __construct($editing = null) { if ($editing != null) { $this->setEditing($editing); } } /** * Get editing protection * * @return string */ public function getEditing() { return $this->editing; } /** * Set editing protection * * @param string $editing Any value of \PhpOffice\PhpWord\SimpleType\DocProtect * @return self */ public function setEditing($editing = null) { DocProtect::validate($editing); $this->editing = $editing; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Set password * * @param string $password * @return self */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get count for hash iterations * * @return int */ public function getSpinCount() { return $this->spinCount; } /** * Set count for hash iterations * * @param int $spinCount * @return self */ public function setSpinCount($spinCount) { $this->spinCount = $spinCount; return $this; } /** * Get algorithm * * @return string */ public function getAlgorithm() { return $this->algorithm; } /** * Set algorithm * * @param string $algorithm * @return self */ public function setAlgorithm($algorithm) { $this->algorithm = $algorithm; return $this; } /** * Get salt * * @return string */ public function getSalt() { return $this->salt; } /** * Set salt. Salt HAS to be 16 characters, or an exception will be thrown. * * @param string $salt * @throws \InvalidArgumentException * @return self */ public function setSalt($salt) { if ($salt !== null && strlen($salt) !== 16) { throw new \InvalidArgumentException('salt has to be of exactly 16 bytes length'); } $this->salt = $salt; return $this; } } phpword/src/PhpWord/Metadata/Compatibility.php 0000664 00000002662 15177100670 0015457 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Metadata; /** * Compatibility setting class * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_Compat.html */ class Compatibility { /** * OOXML version * * 12 = 2007 * 14 = 2010 * 15 = 2013 * * @var int * @see http://msdn.microsoft.com/en-us/library/dd909048%28v=office.12%29.aspx */ private $ooxmlVersion = 12; /** * Get OOXML version * * @return int */ public function getOoxmlVersion() { return $this->ooxmlVersion; } /** * Set OOXML version * * @param int $value * @return self */ public function setOoxmlVersion($value) { $this->ooxmlVersion = $value; return $this; } } phpword/src/PhpWord/Metadata/Settings.php 0000664 00000024011 15177100670 0014436 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Metadata; use PhpOffice\PhpWord\ComplexType\ProofState; use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\SimpleType\Zoom; use PhpOffice\PhpWord\Style\Language; /** * Setting class * * @since 0.14.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_Settings.html */ class Settings { /** * Magnification Setting * * @see http://www.datypic.com/sc/ooxml/e-w_zoom-1.html * @var mixed either integer, in which case it treated as a percent, or one of PhpOffice\PhpWord\SimpleType\Zoom */ private $zoom = 100; /** * Mirror Page Margins * * @see http://www.datypic.com/sc/ooxml/e-w_mirrorMargins-1.html * @var bool */ private $mirrorMargins; /** * Hide spelling errors * * @var bool */ private $hideSpellingErrors = false; /** * Hide grammatical errors * * @var bool */ private $hideGrammaticalErrors = false; /** * Visibility of Annotation Types * * @var TrackChangesView */ private $revisionView; /** * Track Revisions to Document * * @var bool */ private $trackRevisions = false; /** * Do Not Use Move Syntax When Tracking Revisions * * @var bool */ private $doNotTrackMoves = false; /** * Do Not Track Formatting Revisions When Tracking Revisions * * @var bool */ private $doNotTrackFormatting = false; /** * Spelling and Grammatical Checking State * * @var \PhpOffice\PhpWord\ComplexType\ProofState */ private $proofState; /** * Document Editing Restrictions * * @var \PhpOffice\PhpWord\Metadata\Protection */ private $documentProtection; /** * Enables different header for odd and even pages. * * @var bool */ private $evenAndOddHeaders = false; /** * Theme Font Languages * * @var Language */ private $themeFontLang; /** * Automatically Recalculate Fields on Open * * @var bool */ private $updateFields = false; /** * Radix Point for Field Code Evaluation * * @var string */ private $decimalSymbol = '.'; /** * Automatically hyphenate document contents when displayed * * @var bool|null */ private $autoHyphenation; /** * Maximum number of consecutively hyphenated lines * * @var int|null */ private $consecutiveHyphenLimit; /** * The allowed amount of whitespace before hyphenation is applied * @var float|null */ private $hyphenationZone; /** * Do not hyphenate words in all capital letters * @var bool|null */ private $doNotHyphenateCaps; /** * @return Protection */ public function getDocumentProtection() { if ($this->documentProtection == null) { $this->documentProtection = new Protection(); } return $this->documentProtection; } /** * @param Protection $documentProtection */ public function setDocumentProtection($documentProtection) { $this->documentProtection = $documentProtection; } /** * @return ProofState */ public function getProofState() { if ($this->proofState == null) { $this->proofState = new ProofState(); } return $this->proofState; } /** * @param ProofState $proofState */ public function setProofState($proofState) { $this->proofState = $proofState; } /** * Are spelling errors hidden * * @return bool */ public function hasHideSpellingErrors() { return $this->hideSpellingErrors; } /** * Hide spelling errors * * @param bool $hideSpellingErrors */ public function setHideSpellingErrors($hideSpellingErrors) { $this->hideSpellingErrors = $hideSpellingErrors === null ? true : $hideSpellingErrors; } /** * Are grammatical errors hidden * * @return bool */ public function hasHideGrammaticalErrors() { return $this->hideGrammaticalErrors; } /** * Hide grammatical errors * * @param bool $hideGrammaticalErrors */ public function setHideGrammaticalErrors($hideGrammaticalErrors) { $this->hideGrammaticalErrors = $hideGrammaticalErrors === null ? true : $hideGrammaticalErrors; } /** * @return bool */ public function hasEvenAndOddHeaders() { return $this->evenAndOddHeaders; } /** * @param bool $evenAndOddHeaders */ public function setEvenAndOddHeaders($evenAndOddHeaders) { $this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders; } /** * Get the Visibility of Annotation Types * * @return \PhpOffice\PhpWord\ComplexType\TrackChangesView */ public function getRevisionView() { return $this->revisionView; } /** * Set the Visibility of Annotation Types * * @param TrackChangesView $trackChangesView */ public function setRevisionView(TrackChangesView $trackChangesView = null) { $this->revisionView = $trackChangesView; } /** * @return bool */ public function hasTrackRevisions() { return $this->trackRevisions; } /** * @param bool $trackRevisions */ public function setTrackRevisions($trackRevisions) { $this->trackRevisions = $trackRevisions === null ? true : $trackRevisions; } /** * @return bool */ public function hasDoNotTrackMoves() { return $this->doNotTrackMoves; } /** * @param bool $doNotTrackMoves */ public function setDoNotTrackMoves($doNotTrackMoves) { $this->doNotTrackMoves = $doNotTrackMoves === null ? true : $doNotTrackMoves; } /** * @return bool */ public function hasDoNotTrackFormatting() { return $this->doNotTrackFormatting; } /** * @param bool $doNotTrackFormatting */ public function setDoNotTrackFormatting($doNotTrackFormatting) { $this->doNotTrackFormatting = $doNotTrackFormatting === null ? true : $doNotTrackFormatting; } /** * @return mixed */ public function getZoom() { return $this->zoom; } /** * @param mixed $zoom */ public function setZoom($zoom) { if (is_numeric($zoom)) { // zoom is a percentage $this->zoom = $zoom; } else { Zoom::validate($zoom); $this->zoom = $zoom; } } /** * @return bool */ public function hasMirrorMargins() { return $this->mirrorMargins; } /** * @param bool $mirrorMargins */ public function setMirrorMargins($mirrorMargins) { $this->mirrorMargins = $mirrorMargins; } /** * Returns the Language * * @return Language */ public function getThemeFontLang() { return $this->themeFontLang; } /** * sets the Language for this document * * @param Language $themeFontLang */ public function setThemeFontLang($themeFontLang) { $this->themeFontLang = $themeFontLang; } /** * @return bool */ public function hasUpdateFields() { return $this->updateFields; } /** * @param bool $updateFields */ public function setUpdateFields($updateFields) { $this->updateFields = $updateFields === null ? false : $updateFields; } /** * Returns the Radix Point for Field Code Evaluation * * @return string */ public function getDecimalSymbol() { return $this->decimalSymbol; } /** * sets the Radix Point for Field Code Evaluation * * @param string $decimalSymbol */ public function setDecimalSymbol($decimalSymbol) { $this->decimalSymbol = $decimalSymbol; } /** * @return bool|null */ public function hasAutoHyphenation() { return $this->autoHyphenation; } /** * @param bool $autoHyphenation */ public function setAutoHyphenation($autoHyphenation) { $this->autoHyphenation = (bool) $autoHyphenation; } /** * @return int|null */ public function getConsecutiveHyphenLimit() { return $this->consecutiveHyphenLimit; } /** * @param int $consecutiveHyphenLimit */ public function setConsecutiveHyphenLimit($consecutiveHyphenLimit) { $this->consecutiveHyphenLimit = (int) $consecutiveHyphenLimit; } /** * @return float|null */ public function getHyphenationZone() { return $this->hyphenationZone; } /** * @param float $hyphenationZone Measurement unit is twip */ public function setHyphenationZone($hyphenationZone) { $this->hyphenationZone = $hyphenationZone; } /** * @return null|bool */ public function hasDoNotHyphenateCaps() { return $this->doNotHyphenateCaps; } /** * @param bool $doNotHyphenateCaps */ public function setDoNotHyphenateCaps($doNotHyphenateCaps) { $this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps; } } phpword/src/PhpWord/Metadata/DocInfo.php 0000664 00000027650 15177100670 0014173 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Metadata; /** * Document information */ class DocInfo { /** @const string Property type constants */ const PROPERTY_TYPE_BOOLEAN = 'b'; const PROPERTY_TYPE_INTEGER = 'i'; const PROPERTY_TYPE_FLOAT = 'f'; const PROPERTY_TYPE_DATE = 'd'; const PROPERTY_TYPE_STRING = 's'; const PROPERTY_TYPE_UNKNOWN = 'u'; /** * Creator * * @var string */ private $creator; /** * LastModifiedBy * * @var string */ private $lastModifiedBy; /** * Created * * @var int */ private $created; /** * Modified * * @var int */ private $modified; /** * Title * * @var string */ private $title; /** * Description * * @var string */ private $description; /** * Subject * * @var string */ private $subject; /** * Keywords * * @var string */ private $keywords; /** * Category * * @var string */ private $category; /** * Company * * @var string */ private $company; /** * Manager * * @var string */ private $manager; /** * Custom Properties * * @var array */ private $customProperties = array(); /** * Create new instance */ public function __construct() { $this->creator = ''; $this->lastModifiedBy = $this->creator; $this->created = time(); $this->modified = time(); $this->title = ''; $this->subject = ''; $this->description = ''; $this->keywords = ''; $this->category = ''; $this->company = ''; $this->manager = ''; } /** * Get Creator * * @return string */ public function getCreator() { return $this->creator; } /** * Set Creator * * @param string $value * @return self */ public function setCreator($value = '') { $this->creator = $this->setValue($value, ''); return $this; } /** * Get Last Modified By * * @return string */ public function getLastModifiedBy() { return $this->lastModifiedBy; } /** * Set Last Modified By * * @param string $value * @return self */ public function setLastModifiedBy($value = '') { $this->lastModifiedBy = $this->setValue($value, $this->creator); return $this; } /** * Get Created * * @return int */ public function getCreated() { return $this->created; } /** * Set Created * * @param int $value * @return self */ public function setCreated($value = null) { $this->created = $this->setValue($value, time()); return $this; } /** * Get Modified * * @return int */ public function getModified() { return $this->modified; } /** * Set Modified * * @param int $value * @return self */ public function setModified($value = null) { $this->modified = $this->setValue($value, time()); return $this; } /** * Get Title * * @return string */ public function getTitle() { return $this->title; } /** * Set Title * * @param string $value * @return self */ public function setTitle($value = '') { $this->title = $this->setValue($value, ''); return $this; } /** * Get Description * * @return string */ public function getDescription() { return $this->description; } /** * Set Description * * @param string $value * @return self */ public function setDescription($value = '') { $this->description = $this->setValue($value, ''); return $this; } /** * Get Subject * * @return string */ public function getSubject() { return $this->subject; } /** * Set Subject * * @param string $value * @return self */ public function setSubject($value = '') { $this->subject = $this->setValue($value, ''); return $this; } /** * Get Keywords * * @return string */ public function getKeywords() { return $this->keywords; } /** * Set Keywords * * @param string $value * @return self */ public function setKeywords($value = '') { $this->keywords = $this->setValue($value, ''); return $this; } /** * Get Category * * @return string */ public function getCategory() { return $this->category; } /** * Set Category * * @param string $value * @return self */ public function setCategory($value = '') { $this->category = $this->setValue($value, ''); return $this; } /** * Get Company * * @return string */ public function getCompany() { return $this->company; } /** * Set Company * * @param string $value * @return self */ public function setCompany($value = '') { $this->company = $this->setValue($value, ''); return $this; } /** * Get Manager * * @return string */ public function getManager() { return $this->manager; } /** * Set Manager * * @param string $value * @return self */ public function setManager($value = '') { $this->manager = $this->setValue($value, ''); return $this; } /** * Get a List of Custom Property Names * * @return array of string */ public function getCustomProperties() { return array_keys($this->customProperties); } /** * Check if a Custom Property is defined * * @param string $propertyName * @return bool */ public function isCustomPropertySet($propertyName) { return isset($this->customProperties[$propertyName]); } /** * Get a Custom Property Value * * @param string $propertyName * @return mixed */ public function getCustomPropertyValue($propertyName) { if ($this->isCustomPropertySet($propertyName)) { return $this->customProperties[$propertyName]['value']; } return null; } /** * Get a Custom Property Type * * @param string $propertyName * @return string */ public function getCustomPropertyType($propertyName) { if ($this->isCustomPropertySet($propertyName)) { return $this->customProperties[$propertyName]['type']; } return null; } /** * Set a Custom Property * * @param string $propertyName * @param mixed $propertyValue * @param string $propertyType * 'i': Integer * 'f': Floating Point * 's': String * 'd': Date/Time * 'b': Boolean * @return self */ public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null) { $propertyTypes = array( self::PROPERTY_TYPE_INTEGER, self::PROPERTY_TYPE_FLOAT, self::PROPERTY_TYPE_STRING, self::PROPERTY_TYPE_DATE, self::PROPERTY_TYPE_BOOLEAN, ); if (($propertyType === null) || (!in_array($propertyType, $propertyTypes))) { if ($propertyValue === null) { $propertyType = self::PROPERTY_TYPE_STRING; } elseif (is_float($propertyValue)) { $propertyType = self::PROPERTY_TYPE_FLOAT; } elseif (is_int($propertyValue)) { $propertyType = self::PROPERTY_TYPE_INTEGER; } elseif (is_bool($propertyValue)) { $propertyType = self::PROPERTY_TYPE_BOOLEAN; } elseif ($propertyValue instanceof \DateTime) { $propertyType = self::PROPERTY_TYPE_DATE; } else { $propertyType = self::PROPERTY_TYPE_STRING; } } $this->customProperties[$propertyName] = array( 'value' => $propertyValue, 'type' => $propertyType, ); return $this; } /** * Convert document property based on type * * @param string $propertyValue * @param string $propertyType * @return mixed */ public static function convertProperty($propertyValue, $propertyType) { $conversion = self::getConversion($propertyType); switch ($conversion) { case 'empty': // Empty return ''; case 'null': // Null return null; case 'int': // Signed integer return (int) $propertyValue; case 'uint': // Unsigned integer return abs((int) $propertyValue); case 'float': // Float return (float) $propertyValue; case 'date': // Date return strtotime($propertyValue); case 'bool': // Boolean return $propertyValue == 'true'; } return $propertyValue; } /** * Convert document property type * * @param string $propertyType * @return string */ public static function convertPropertyType($propertyType) { $typeGroups = array( self::PROPERTY_TYPE_INTEGER => array('i1', 'i2', 'i4', 'i8', 'int', 'ui1', 'ui2', 'ui4', 'ui8', 'uint'), self::PROPERTY_TYPE_FLOAT => array('r4', 'r8', 'decimal'), self::PROPERTY_TYPE_STRING => array('empty', 'null', 'lpstr', 'lpwstr', 'bstr'), self::PROPERTY_TYPE_DATE => array('date', 'filetime'), self::PROPERTY_TYPE_BOOLEAN => array('bool'), ); foreach ($typeGroups as $groupId => $groupMembers) { if (in_array($propertyType, $groupMembers)) { return $groupId; } } return self::PROPERTY_TYPE_UNKNOWN; } /** * Set default for null and empty value * * @param mixed $value * @param mixed $default * @return mixed */ private function setValue($value, $default) { 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'; } } phpword/src/PhpWord/SimpleType/Zoom.php 0000664 00000002205 15177100670 0014136 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Magnification Preset Values * * @since 0.14.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_Zoom.html */ final class Zoom extends AbstractEnum { //No Preset Magnification const NONE = 'none'; //Display One Full Page const FULL_PAGE = 'fullPage'; //Display Page Width const BEST_FIT = 'bestFit'; //Display Text Width const TEXT_FIT = 'textFit'; } phpword/src/PhpWord/SimpleType/LineSpacingRule.php 0000664 00000002215 15177100670 0016237 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Line Spacing Rule * * @since 0.14.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_LineSpacingRule.html */ final class LineSpacingRule extends AbstractEnum { /** * Automatically Determined Line Height */ const AUTO = 'auto'; /** * Exact Line Height */ const EXACT = 'exact'; /** * Minimum Line Height */ const AT_LEAST = 'atLeast'; } phpword/src/PhpWord/SimpleType/Jc.php 0000664 00000004531 15177100670 0013552 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Horizontal Alignment Type. * * Introduced in 1st Edition of ECMA-376. Initially it was intended to align paragraphs and tables. * Since ISO/IEC-29500:2008 the type must not be used for table alignment. * * @since 0.13.0 * * @see \PhpOffice\PhpWord\SimpleType\JcTable For table alignment modes available since ISO/IEC-29500:2008. * @see http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html */ final class Jc extends AbstractEnum { const START = 'start'; const CENTER = 'center'; const END = 'end'; const BOTH = 'both'; const MEDIUM_KASHIDA = 'mediumKashida'; const DISTRIBUTE = 'distribute'; const NUM_TAB = 'numTab'; const HIGH_KASHIDA = 'highKashida'; const LOW_KASHIDA = 'lowKashida'; const THAI_DISTRIBUTE = 'thaiDistribute'; /** * Kept for compatibility with 1st edition of ECMA-376 standard. * Microsoft Word 2007 and WPS Writer 2016 still rely on it. * * @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `START` instead. */ const LEFT = 'left'; /** * Kept for compatibility with 1st edition of ECMA-376 standard. * Microsoft Word 2007 and WPS Writer 2016 still rely on it. * * @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `END` instead. */ const RIGHT = 'right'; /** * Kept for compatibility with 1st edition of ECMA-376 standard. * Microsoft Word 2007 and WPS Writer 2016 still rely on it. * * @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `BOTH` instead. */ const JUSTIFY = 'justify'; } phpword/src/PhpWord/SimpleType/TblWidth.php 0000664 00000002176 15177100670 0014742 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Table Width Units * * @since 0.15.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_TblWidth.html */ final class TblWidth extends AbstractEnum { //No Width const NIL = 'nil'; //Automatically Determined Width const AUTO = 'auto'; //Width in Fiftieths of a Percent const PERCENT = 'pct'; //Width in Twentieths of a Point const TWIP = 'dxa'; } phpword/src/PhpWord/SimpleType/VerticalJc.php 0000664 00000002063 15177100670 0015242 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Vertical Alignment Type. * * Introduced in ISO/IEC-29500:2008. * * @see http://www.datypic.com/sc/ooxml/t-w_ST_VerticalJc.html * @since 0.17.0 */ final class VerticalJc extends AbstractEnum { const TOP = 'top'; const CENTER = 'center'; const BOTH = 'both'; const BOTTOM = 'bottom'; } phpword/src/PhpWord/SimpleType/NumberFormat.php 0000664 00000012622 15177100670 0015617 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Numbering Format. * * @since 0.14.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_NumberFormat.html. */ final class NumberFormat extends AbstractEnum { //Decimal Numbers const DECIMAL = 'decimal'; //Uppercase Roman Numerals const UPPER_ROMAN = 'upperRoman'; //Lowercase Roman Numerals const LOWER_ROMAN = 'lowerRoman'; //Uppercase Latin Alphabet const UPPER_LETTER = 'upperLetter'; //Lowercase Latin Alphabet const LOWER_LETTER = 'lowerLetter'; //Ordinal const ORDINAL = 'ordinal'; //Cardinal Text const CARDINAL_TEXT = 'cardinalText'; //Ordinal Text const ORDINAL_TEXT = 'ordinalText'; //Hexadecimal Numbering const HEX = 'hex'; //Chicago Manual of Style const CHICAGO = 'chicago'; //Ideographs const IDEOGRAPH_DIGITAL = 'ideographDigital'; //Japanese Counting System const JAPANESE_COUNTING = 'japaneseCounting'; //AIUEO Order Hiragana const AIUEO = 'aiueo'; //Iroha Ordered Katakana const IROHA = 'iroha'; //Double Byte Arabic Numerals const DECIMAL_FULL_WIDTH = 'decimalFullWidth'; //Single Byte Arabic Numerals const DECIMAL_HALF_WIDTH = 'decimalHalfWidth'; //Japanese Legal Numbering const JAPANESE_LEGAL = 'japaneseLegal'; //Japanese Digital Ten Thousand Counting System const JAPANESE_DIGITAL_TEN_THOUSAND = 'japaneseDigitalTenThousand'; //Decimal Numbers Enclosed in a Circle const DECIMAL_ENCLOSED_CIRCLE = 'decimalEnclosedCircle'; //Double Byte Arabic Numerals Alternate const DECIMAL_FULL_WIDTH2 = 'decimalFullWidth2'; //Full-Width AIUEO Order Hiragana const AIUEO_FULL_WIDTH = 'aiueoFullWidth'; //Full-Width Iroha Ordered Katakana const IROHA_FULL_WIDTH = 'irohaFullWidth'; //Initial Zero Arabic Numerals const DECIMAL_ZERO = 'decimalZero'; //Bullet const BULLET = 'bullet'; //Korean Ganada Numbering const GANADA = 'ganada'; //Korean Chosung Numbering const CHOSUNG = 'chosung'; //Decimal Numbers Followed by a Period const DECIMAL_ENCLOSED_FULL_STOP = 'decimalEnclosedFullstop'; //Decimal Numbers Enclosed in Parenthesis const DECIMAL_ENCLOSED_PAREN = 'decimalEnclosedParen'; //Decimal Numbers Enclosed in a Circle const DECIMAL_ENCLOSED_CIRCLE_CHINESE = 'decimalEnclosedCircleChinese'; //Ideographs Enclosed in a Circle const IDEOGRAPHENCLOSEDCIRCLE = 'ideographEnclosedCircle'; //Traditional Ideograph Format const IDEOGRAPH_TRADITIONAL = 'ideographTraditional'; //Zodiac Ideograph Format const IDEOGRAPH_ZODIAC = 'ideographZodiac'; //Traditional Zodiac Ideograph Format const IDEOGRAPH_ZODIAC_TRADITIONAL = 'ideographZodiacTraditional'; //Taiwanese Counting System const TAIWANESE_COUNTING = 'taiwaneseCounting'; //Traditional Legal Ideograph Format const IDEOGRAPH_LEGAL_TRADITIONAL = 'ideographLegalTraditional'; //Taiwanese Counting Thousand System const TAIWANESE_COUNTING_THOUSAND = 'taiwaneseCountingThousand'; //Taiwanese Digital Counting System const TAIWANESE_DIGITAL = 'taiwaneseDigital'; //Chinese Counting System const CHINESE_COUNTING = 'chineseCounting'; //Chinese Legal Simplified Format const CHINESE_LEGAL_SIMPLIFIED = 'chineseLegalSimplified'; //Chinese Counting Thousand System const CHINESE_COUNTING_THOUSAND = 'chineseCountingThousand'; //Korean Digital Counting System const KOREAN_DIGITAL = 'koreanDigital'; //Korean Counting System const KOREAN_COUNTING = 'koreanCounting'; //Korean Legal Numbering const KOREAN_LEGAL = 'koreanLegal'; //Korean Digital Counting System Alternate const KOREAN_DIGITAL2 = 'koreanDigital2'; //Vietnamese Numerals const VIETNAMESE_COUNTING = 'vietnameseCounting'; //Lowercase Russian Alphabet const RUSSIAN_LOWER = 'russianLower'; //Uppercase Russian Alphabet const RUSSIAN_UPPER = 'russianUpper'; //No Numbering const NONE = 'none'; //Number With Dashes const NUMBER_IN_DASH = 'numberInDash'; //Hebrew Numerals const HEBREW1 = 'hebrew1'; //Hebrew Alphabet const HEBREW2 = 'hebrew2'; //Arabic Alphabet const ARABIC_ALPHA = 'arabicAlpha'; //Arabic Abjad Numerals const ARABIC_ABJAD = 'arabicAbjad'; //Hindi Vowels const HINDI_VOWELS = 'hindiVowels'; //Hindi Consonants const HINDI_CONSONANTS = 'hindiConsonants'; //Hindi Numbers const HINDI_NUMBERS = 'hindiNumbers'; //Hindi Counting System const HINDI_COUNTING = 'hindiCounting'; //Thai Letters const THAI_LETTERS = 'thaiLetters'; //Thai Numerals const THAI_NUMBERS = 'thaiNumbers'; //Thai Counting System const THAI_COUNTING = 'thaiCounting'; } phpword/src/PhpWord/SimpleType/TextAlignment.php 0000664 00000002317 15177100670 0016001 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Magnification Preset Values * * @since 0.14.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_TextAlignment.html */ final class TextAlignment extends AbstractEnum { //Align Text at Top const TOP = 'top'; //Align Text at Center const CENTER = 'center'; //Align Text at Baseline const BASELINE = 'baseline'; //Align Text at Bottom const BOTTOM = 'bottom'; //Automatically Determine Alignment const AUTO = 'auto'; } phpword/src/PhpWord/SimpleType/Border.php 0000664 00000006115 15177100670 0014433 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Border Styles. * * @since 0.18.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_Border.html */ final class Border extends AbstractEnum { const SINGLE = 'single'; //A single line const DASH_DOT_STROKED = 'dashDotStroked'; //A line with a series of alternating thin and thick strokes const DASHED = 'dashed'; //A dashed line const DASH_SMALL_GAP = 'dashSmallGap'; //A dashed line with small gaps const DOT_DASH = 'dotDash'; //A line with alternating dots and dashes const DOT_DOT_DASH = 'dotDotDash'; //A line with a repeating dot - dot - dash sequence const DOTTED = 'dotted'; //A dotted line const DOUBLE = 'double'; //A double line const DOUBLE_WAVE = 'doubleWave'; //A double wavy line const INSET = 'inset'; //An inset set of lines const NIL = 'nil'; //No border const NONE = 'none'; //No border const OUTSET = 'outset'; //An outset set of lines const THICK = 'thick'; //A single line const THICK_THIN_LARGE_GAP = 'thickThinLargeGap'; //A thick line contained within a thin line with a large-sized intermediate gap const THICK_THIN_MEDIUM_GAP = 'thickThinMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap const THICK_THIN_SMALL_GAP = 'thickThinSmallGap'; //A thick line contained within a thin line with a small intermediate gap const THIN_THICK_LARGE_GAP = 'thinThickLargeGap'; //A thin line contained within a thick line with a large-sized intermediate gap const THIN_THICK_MEDIUM_GAP = 'thinThickMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap const THIN_THICK_SMALL_GAP = 'thinThickSmallGap'; //A thick line contained within a thin line with a small intermediate gap const THIN_THICK_THINLARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap const THIN_THICK_THIN_MEDIUM_GAP = 'thinThickThinMediumGap'; //A thin-thick-thin line with a medium gap const THIN_THICK_THIN_SMALL_GAP = 'thinThickThinSmallGap'; //A thin-thick-thin line with a small gap const THREE_D_EMBOSS = 'threeDEmboss'; //A three-staged gradient line, getting darker towards the paragraph const THREE_D_ENGRAVE = 'threeDEngrave'; //A three-staged gradient like, getting darker away from the paragraph const TRIPLE = 'triple'; //A triple line const WAVE = 'wave'; //A wavy line } phpword/src/PhpWord/SimpleType/DocProtect.php 0000664 00000002506 15177100670 0015264 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Document Protection Types * * @since 0.14.0 * * @see http://www.datypic.com/sc/ooxml/t-w_ST_DocProtect.html */ final class DocProtect extends AbstractEnum { /** * No Editing Restrictions */ const NONE = 'none'; /** * Allow No Editing */ const READ_ONLY = 'readOnly'; /** * Allow Editing of Comments */ const COMMENTS = 'comments'; /** * Allow Editing With Revision Tracking */ const TRACKED_CHANGES = 'trackedChanges'; /** * Allow Editing of Form Fields */ const FORMS = 'forms'; } phpword/src/PhpWord/SimpleType/JcTable.php 0000664 00000001723 15177100670 0014522 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\SimpleType; use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Table Alignment Type. * * Introduced in ISO/IEC-29500:2008. * * @since 0.13.0 */ final class JcTable extends AbstractEnum { const START = 'start'; const CENTER = 'center'; const END = 'end'; } phpword/src/PhpWord/Reader/ODText/AbstractPart.php 0000664 00000001646 15177100670 0016072 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\ODText; use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart; /** * Abstract part reader * * @since 0.10.0 * @codeCoverageIgnore */ abstract class AbstractPart extends Word2007AbstractPart { } phpword/src/PhpWord/Reader/ODText/Meta.php 0000664 00000005243 15177100670 0014363 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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->getDocInfo(); $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); } else { // Set other custom properties $docProps->setCustomProperty($property, $propertyNode->nodeValue); } } } } phpword/src/PhpWord/Reader/ODText/Content.php 0000664 00000012377 15177100670 0015115 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\ODText; use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLReader; /** * Content reader * * @since 0.10.0 */ class Content extends AbstractPart { /** * Read content.xml. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $trackedChanges = array(); $nodes = $xmlReader->getElements('office:body/office:text/*'); if ($nodes->length > 0) { $section = $phpWord->addSection(); foreach ($nodes as $node) { // $styleName = $xmlReader->getAttribute('text:style-name', $node); switch ($node->nodeName) { case 'text:h': // Heading $depth = $xmlReader->getAttribute('text:outline-level', $node); $section->addTitle($node->nodeValue, $depth); break; case 'text:p': // Paragraph $children = $node->childNodes; foreach ($children as $child) { switch ($child->nodeName) { case 'text:change-start': $changeId = $child->getAttribute('text:change-id'); if (isset($trackedChanges[$changeId])) { $changed = $trackedChanges[$changeId]; } break; case 'text:change-end': unset($changed); break; case 'text:change': $changeId = $child->getAttribute('text:change-id'); if (isset($trackedChanges[$changeId])) { $changed = $trackedChanges[$changeId]; } break; } } $element = $section->addText($node->nodeValue); if (isset($changed) && is_array($changed)) { $element->setTrackChange($changed['changed']); if (isset($changed['textNodes'])) { foreach ($changed['textNodes'] as $changedNode) { $element = $section->addText($changedNode->nodeValue); $element->setTrackChange($changed['changed']); } } } break; case 'text:list': // List $listItems = $xmlReader->getElements('text:list-item/text:p', $node); foreach ($listItems as $listItem) { // $listStyleName = $xmlReader->getAttribute('text:style-name', $listItem); $section->addListItem($listItem->nodeValue, 0); } break; case 'text:tracked-changes': $changedRegions = $xmlReader->getElements('text:changed-region', $node); foreach ($changedRegions as $changedRegion) { $type = ($changedRegion->firstChild->nodeName == 'text:insertion') ? TrackChange::INSERTED : TrackChange::DELETED; $creatorNode = $xmlReader->getElements('office:change-info/dc:creator', $changedRegion->firstChild); $author = $creatorNode[0]->nodeValue; $dateNode = $xmlReader->getElements('office:change-info/dc:date', $changedRegion->firstChild); $date = $dateNode[0]->nodeValue; $date = preg_replace('/\.\d+$/', '', $date); $date = \DateTime::createFromFormat('Y-m-d\TH:i:s', $date); $changed = new TrackChange($type, $author, $date); $textNodes = $xmlReader->getElements('text:deletion/text:p', $changedRegion); $trackedChanges[$changedRegion->getAttribute('text:id')] = array('changed' => $changed, 'textNodes'=> $textNodes); } break; } } } } } phpword/src/PhpWord/Reader/Word2007/AbstractPart.php 0000664 00000072415 15177100670 0016151 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType; use PhpOffice\PhpWord\Element\AbstractContainer; use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\PhpWord; 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 * * @var string */ protected $docFile; /** * XML file * * @var string */ protected $xmlFile; /** * Part relationships * * @var array */ protected $rels = array(); /** * Read part. */ abstract public function read(PhpWord $phpWord); /** * Create new instance * * @param string $docFile * @param string $xmlFile */ public function __construct($docFile, $xmlFile) { $this->docFile = $docFile; $this->xmlFile = $xmlFile; } /** * Set relationships. * * @param array $value */ public function setRels($value) { $this->rels = $value; } /** * Read w:p. * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @param \PhpOffice\PhpWord\Element\AbstractContainer $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; $headingDepth = null; if ($xmlReader->elementExists('w:pPr', $domNode)) { $paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode); $headingDepth = $this->getHeadingDepth($paragraphStyle); } // 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 ('begin' == $fldCharType) { $ignoreText = true; } elseif ('end' == $fldCharType) { $ignoreText = false; } } if (!is_null($instrText)) { $textContent .= '{' . $instrText . '}'; } else { if (false === $ignoreText) { $textContent .= $xmlReader->getValue('w:t', $node); } } } $parent->addPreserveText(htmlspecialchars($textContent, ENT_QUOTES, 'UTF-8'), $fontStyle, $paragraphStyle); } elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) { // List item $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('*', $domNode); $listItemRun = $parent->addListItemRun($levelId, "PHPWordList{$numId}", $paragraphStyle); foreach ($nodes as $node) { $this->readRun($xmlReader, $node, $listItemRun, $docPart, $paragraphStyle); } } elseif ($headingDepth !== null) { // Heading or Title $textContent = null; $nodes = $xmlReader->getElements('w:r', $domNode); if ($nodes->length === 1) { $textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8'); } else { $textContent = new TextRun($paragraphStyle); foreach ($nodes as $node) { $this->readRun($xmlReader, $node, $textContent, $docPart, $paragraphStyle); } } $parent->addTitle($textContent, $headingDepth); } else { // Text and TextRun $textRunContainers = $xmlReader->countElements('w:r|w:ins|w:del|w:hyperlink|w:smartTag', $domNode); if (0 === $textRunContainers) { $parent->addTextBreak(null, $paragraphStyle); } else { $nodes = $xmlReader->getElements('*', $domNode); $paragraph = $parent->addTextRun($paragraphStyle); foreach ($nodes as $node) { $this->readRun($xmlReader, $node, $paragraph, $docPart, $paragraphStyle); } } } } /** * Returns the depth of the Heading, returns 0 for a Title * * @param array $paragraphStyle * @return number|null */ private function getHeadingDepth(array $paragraphStyle = null) { if (is_array($paragraphStyle) && isset($paragraphStyle['styleName'])) { if ('Title' === $paragraphStyle['styleName']) { return 0; } $headingMatches = array(); preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches); if (!empty($headingMatches)) { return $headingMatches[1]; } } return null; } /** * Read w:r. * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @param \PhpOffice\PhpWord\Element\AbstractContainer $parent * @param string $docPart * @param mixed $paragraphStyle * * @todo Footnote paragraph style */ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart, $paragraphStyle = null) { if (in_array($domNode->nodeName, array('w:ins', 'w:del', 'w:smartTag', 'w:hyperlink'))) { $nodes = $xmlReader->getElements('*', $domNode); foreach ($nodes as $node) { $this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle); } } elseif ($domNode->nodeName == 'w:r') { $fontStyle = $this->readFontStyle($xmlReader, $domNode); $nodes = $xmlReader->getElements('*', $domNode); foreach ($nodes as $node) { $this->readRunChild($xmlReader, $node, $parent, $docPart, $paragraphStyle, $fontStyle); } } } /** * Parses nodes under w:r * * @param XMLReader $xmlReader * @param \DOMElement $node * @param AbstractContainer $parent * @param string $docPart * @param mixed $paragraphStyle * @param mixed $fontStyle */ protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, AbstractContainer $parent, $docPart, $paragraphStyle = null, $fontStyle = null) { $runParent = $node->parentNode->parentNode; if ($node->nodeName == 'w:footnoteReference') { // Footnote $wId = $xmlReader->getAttribute('w:id', $node); $footnote = $parent->addFootnote(); $footnote->setRelationId($wId); } elseif ($node->nodeName == 'w:endnoteReference') { // Endnote $wId = $xmlReader->getAttribute('w:id', $node); $endnote = $parent->addEndnote(); $endnote->setRelationId($wId); } elseif ($node->nodeName == 'w:pict') { // Image $rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata'); $target = $this->getMediaTarget($docPart, $rId); if (!is_null($target)) { if ('External' == $this->getTargetMode($docPart, $rId)) { $imageSource = $target; } else { $imageSource = "zip://{$this->docFile}#{$target}"; } $parent->addImage($imageSource); } } elseif ($node->nodeName == 'w:drawing') { // Office 2011 Image $xmlReader->registerNamespace('wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $xmlReader->registerNamespace('r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlReader->registerNamespace('pic', 'http://schemas.openxmlformats.org/drawingml/2006/picture'); $xmlReader->registerNamespace('a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr'); $embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip'); if ($name === null && $embedId === null) { // some Converters puts images on a different path $name = $xmlReader->getAttribute('name', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr'); $embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip'); } $target = $this->getMediaTarget($docPart, $embedId); if (!is_null($target)) { $imageSource = "zip://{$this->docFile}#{$target}"; $parent->addImage($imageSource, null, false, $name); } } elseif ($node->nodeName == 'w:object') { // Object $rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject'); // $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata'); $target = $this->getMediaTarget($docPart, $rId); if (!is_null($target)) { $textContent = "<Object: {$target}>"; $parent->addText($textContent, $fontStyle, $paragraphStyle); } } elseif ($node->nodeName == 'w:br') { $parent->addTextBreak(); } elseif ($node->nodeName == 'w:tab') { $parent->addText("\t"); } elseif ($node->nodeName == 'mc:AlternateContent') { if ($node->hasChildNodes()) { // Get fallback instead of mc:Choice to make sure it is compatible $fallbackElements = $node->getElementsByTagName('Fallback'); if ($fallbackElements->length) { $fallback = $fallbackElements->item(0); // TextRun $textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8'); $parent->addText($textContent, $fontStyle, $paragraphStyle); } } } elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') { // TextRun $textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8'); if ($runParent->nodeName == 'w:hyperlink') { $rId = $xmlReader->getAttribute('r:id', $runParent); $target = $this->getMediaTarget($docPart, $rId); if (!is_null($target)) { $parent->addLink($target, $textContent, $fontStyle, $paragraphStyle); } else { $parent->addText($textContent, $fontStyle, $paragraphStyle); } } else { /** @var AbstractElement $element */ $element = $parent->addText($textContent, $fontStyle, $paragraphStyle); if (in_array($runParent->nodeName, array('w:ins', 'w:del'))) { $type = ($runParent->nodeName == 'w:del') ? TrackChange::DELETED : TrackChange::INSERTED; $author = $runParent->getAttribute('w:author'); $date = \DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $runParent->getAttribute('w:date')); $element->setChangeInfo($type, $author, $date); } } } } /** * Read w:tbl. * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart */ protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart = 'document') { // 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 ('w:tblGrid' == $tblNode->nodeName) { // Column // @todo Do something with table columns } elseif ('w:tr' == $tblNode->nodeName) { // Row $rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight'); $rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight'); $rowHRule = $rowHRule == 'exact'; $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 ('w:trPr' == $rowNode->nodeName) { // Row style // @todo Do something with row style } elseif ('w:tc' == $rowNode->nodeName) { // 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 ('w:p' == $cellNode->nodeName) { // Paragraph $this->readParagraph($xmlReader, $cellNode, $cell, $docPart); } } } } } } } /** * 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, array('w:pStyle', 'w:name')), 'alignment' => 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'), 'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'), 'bidi' => array(self::READ_TRUE, 'w:bidi'), 'suppressAutoHyphens' => array(self::READ_TRUE, 'w:suppressAutoHyphens'), ); return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs); } /** * Read w:rPr * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @return array|null */ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode) { if (is_null($domNode)) { return null; } // Hyperlink has an extra w:r child if ('w:hyperlink' == $domNode->nodeName) { $domNode = $xmlReader->getElement('w:r', $domNode); } if (!$xmlReader->elementExists('w:rPr', $domNode)) { return null; } $styleNode = $xmlReader->getElement('w:rPr', $domNode); $styleDefs = array( 'styleName' => array(self::READ_VALUE, 'w:rStyle'), 'name' => array(self::READ_VALUE, 'w:rFonts', array('w:ascii', 'w:hAnsi', 'w:eastAsia', 'w:cs')), 'hint' => array(self::READ_VALUE, 'w:rFonts', 'w:hint'), 'size' => array(self::READ_SIZE, array('w:sz', 'w:szCs')), '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'), 'rtl' => array(self::READ_TRUE, 'w:rtl'), 'lang' => array(self::READ_VALUE, 'w:lang'), 'position' => array(self::READ_VALUE, 'w:position'), 'hidden' => array(self::READ_TRUE, 'w:vanish'), ); 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" */ protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode) { $style = null; $margins = array('top', 'left', 'bottom', 'right'); $borders = array_merge($margins, array('insideH', 'insideV')); if ($xmlReader->elementExists('w:tblPr', $domNode)) { if ($xmlReader->elementExists('w:tblPr/w:tblStyle', $domNode)) { $style = $xmlReader->getAttribute('w:val', $domNode, 'w:tblPr/w:tblStyle'); } else { $styleNode = $xmlReader->getElement('w:tblPr', $domNode); $styleDefs = array(); 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'); $styleDefs["border{$ucfSide}Style"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:val'); } $styleDefs['layout'] = array(self::READ_VALUE, 'w:tblLayout', 'w:type'); $styleDefs['bidiVisual'] = array(self::READ_TRUE, 'w:bidiVisual'); $styleDefs['cellSpacing'] = array(self::READ_VALUE, 'w:tblCellSpacing', 'w:w'); $style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs); $tablePositionNode = $xmlReader->getElement('w:tblpPr', $styleNode); if ($tablePositionNode !== null) { $style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode); } $indentNode = $xmlReader->getElement('w:tblInd', $styleNode); if ($indentNode !== null) { $style['indent'] = $this->readTableIndent($xmlReader, $indentNode); } } } return $style; } /** * Read w:tblpPr * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @return array */ private function readTablePosition(XMLReader $xmlReader, \DOMElement $domNode) { $styleDefs = array( 'leftFromText' => array(self::READ_VALUE, '.', 'w:leftFromText'), 'rightFromText' => array(self::READ_VALUE, '.', 'w:rightFromText'), 'topFromText' => array(self::READ_VALUE, '.', 'w:topFromText'), 'bottomFromText' => array(self::READ_VALUE, '.', 'w:bottomFromText'), 'vertAnchor' => array(self::READ_VALUE, '.', 'w:vertAnchor'), 'horzAnchor' => array(self::READ_VALUE, '.', 'w:horzAnchor'), 'tblpXSpec' => array(self::READ_VALUE, '.', 'w:tblpXSpec'), 'tblpX' => array(self::READ_VALUE, '.', 'w:tblpX'), 'tblpYSpec' => array(self::READ_VALUE, '.', 'w:tblpYSpec'), 'tblpY' => array(self::READ_VALUE, '.', 'w:tblpY'), ); return $this->readStyleDefs($xmlReader, $domNode, $styleDefs); } /** * Read w:tblInd * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @return TblWidthComplexType */ private function readTableIndent(XMLReader $xmlReader, \DOMElement $domNode) { $styleDefs = array( 'value' => array(self::READ_VALUE, '.', 'w:w'), 'type' => array(self::READ_VALUE, '.', 'w:type'), ); $styleDefs = $this->readStyleDefs($xmlReader, $domNode, $styleDefs); return new TblWidthComplexType((int) $styleDefs['value'], $styleDefs['type']); } /** * 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'), ); return $this->readStyleDefs($xmlReader, $domNode, $styleDefs); } /** * Returns the first child element found * * @param XMLReader $xmlReader * @param \DOMElement|null $parentNode * @param string|array|null $elements * @return string|null */ private function findPossibleElement(XMLReader $xmlReader, \DOMElement $parentNode = null, $elements = null) { if (is_array($elements)) { //if element is an array, we take the first element that exists in the XML foreach ($elements as $possibleElement) { if ($xmlReader->elementExists($possibleElement, $parentNode)) { return $possibleElement; } } } else { return $elements; } return null; } /** * Returns the first attribute found * * @param XMLReader $xmlReader * @param \DOMElement $node * @param string|array $attributes * @return string|null */ private function findPossibleAttribute(XMLReader $xmlReader, \DOMElement $node, $attributes) { //if attribute is an array, we take the first attribute that exists in the XML if (is_array($attributes)) { foreach ($attributes as $possibleAttribute) { if ($xmlReader->getAttribute($possibleAttribute, $node)) { return $possibleAttribute; } } return null; } return $attributes; } /** * 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) = array_pad($styleVal, 4, null); $element = $this->findPossibleElement($xmlReader, $parentNode, $element); if ($element === null) { continue; } if ($xmlReader->elementExists($element, $parentNode)) { $node = $xmlReader->getElement($element, $parentNode); $attribute = $this->findPossibleAttribute($xmlReader, $node, $attribute); // 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 string|null $attributeValue * @param mixed $expected * @return mixed */ private function readStyleDef($method, $attributeValue, $expected) { $style = $attributeValue; if (self::READ_SIZE == $method) { $style = $attributeValue / 2; } elseif (self::READ_TRUE == $method) { $style = $this->isOn($attributeValue); } elseif (self::READ_FALSE == $method) { $style = !$this->isOn($attributeValue); } elseif (self::READ_EQUAL == $method) { $style = $attributeValue == $expected; } return $style; } /** * Parses the value of the on/off value, null is considered true as it means the w:val attribute was not present * * @see http://www.datypic.com/sc/ooxml/t-w_ST_OnOff.html * @param string $value * @return bool */ private function isOn($value = null) { return $value === null || $value === '1' || $value === 'true' || $value === 'on'; } /** * Returns the target of image, object, or link as stored in ::readMainRels * * @param string $docPart * @param string $rId * @return string|null */ private function getMediaTarget($docPart, $rId) { $target = null; if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) { $target = $this->rels[$docPart][$rId]['target']; } return $target; } /** * Returns the target mode * * @param string $docPart * @param string $rId * @return string|null */ private function getTargetMode($docPart, $rId) { $mode = null; if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) { $mode = $this->rels[$docPart][$rId]['targetMode']; } return $mode; } } phpword/src/PhpWord/Reader/Word2007/DocPropsCustom.php 0000664 00000003610 15177100670 0016472 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; use PhpOffice\PhpWord\Metadata\DocInfo; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLReader; /** * Custom properties reader * * @since 0.11.0 */ class DocPropsCustom extends AbstractPart { /** * Read custom document properties. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $docProps = $phpWord->getDocInfo(); $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { $propertyName = $xmlReader->getAttribute('name', $node); $attributeNode = $xmlReader->getElement('*', $node); $attributeType = $attributeNode->nodeName; $attributeValue = $attributeNode->nodeValue; $attributeValue = DocInfo::convertProperty($attributeValue, $attributeType); $attributeType = DocInfo::convertPropertyType($attributeType); $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType); } } } } phpword/src/PhpWord/Reader/Word2007/DocPropsCore.php 0000664 00000005023 15177100670 0016110 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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 AbstractPart { /** * Property mapping * * @var array */ protected $mapping = array( 'dc:creator' => 'setCreator', 'dc:title' => 'setTitle', 'dc:description' => 'setDescription', 'dc:subject' => 'setSubject', 'cp:keywords' => 'setKeywords', 'cp:category' => 'setCategory', 'cp:lastModifiedBy' => 'setLastModifiedBy', 'dcterms:created' => 'setCreated', 'dcterms:modified' => 'setModified', ); /** * Callback functions * * @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->getDocInfo(); $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { if (!isset($this->mapping[$node->nodeName])) { continue; } $method = $this->mapping[$node->nodeName]; $value = $node->nodeValue == '' ? null : $node->nodeValue; if (isset($this->callbacks[$node->nodeName])) { $value = $this->callbacks[$node->nodeName]($value); } if (method_exists($docProps, $method)) { $docProps->$method($value); } } } } } phpword/src/PhpWord/Reader/Word2007/Numbering.php 0000664 00000011442 15177100670 0015476 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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; /** * Numbering reader * * @since 0.10.0 */ class Numbering extends AbstractPart { /** * Read numbering.xml. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $abstracts = array(); $numberings = array(); $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); // Abstract numbering definition $nodes = $xmlReader->getElements('w:abstractNum'); if ($nodes->length > 0) { foreach ($nodes as $node) { $abstractId = $xmlReader->getAttribute('w:abstractNumId', $node); $abstracts[$abstractId] = array('levels' => array()); $abstract = &$abstracts[$abstractId]; $subnodes = $xmlReader->getElements('*', $node); foreach ($subnodes as $subnode) { switch ($subnode->nodeName) { case 'w:multiLevelType': $abstract['type'] = $xmlReader->getAttribute('w:val', $subnode); break; case 'w:lvl': $levelId = $xmlReader->getAttribute('w:ilvl', $subnode); $abstract['levels'][$levelId] = $this->readLevel($xmlReader, $subnode, $levelId); break; } } } } // Numbering instance definition $nodes = $xmlReader->getElements('w:num'); if ($nodes->length > 0) { foreach ($nodes as $node) { $numId = $xmlReader->getAttribute('w:numId', $node); $abstractId = $xmlReader->getAttribute('w:val', $node, 'w:abstractNumId'); $numberings[$numId] = $abstracts[$abstractId]; $numberings[$numId]['numId'] = $numId; $subnodes = $xmlReader->getElements('w:lvlOverride/w:lvl', $node); foreach ($subnodes as $subnode) { $levelId = $xmlReader->getAttribute('w:ilvl', $subnode); $overrides = $this->readLevel($xmlReader, $subnode, $levelId); foreach ($overrides as $key => $value) { $numberings[$numId]['levels'][$levelId][$key] = $value; } } } } // Push to Style collection foreach ($numberings as $numId => $numbering) { $phpWord->addNumberingStyle("PHPWordList{$numId}", $numbering); } } /** * Read numbering level definition from w:abstractNum and w:num * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $subnode * @param int $levelId * @return array */ private function readLevel(XMLReader $xmlReader, \DOMElement $subnode, $levelId) { $level = array(); $level['level'] = $levelId; $level['start'] = $xmlReader->getAttribute('w:val', $subnode, 'w:start'); $level['format'] = $xmlReader->getAttribute('w:val', $subnode, 'w:numFmt'); $level['restart'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlRestart'); $level['suffix'] = $xmlReader->getAttribute('w:val', $subnode, 'w:suff'); $level['text'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlText'); $level['alignment'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlJc'); $level['tab'] = $xmlReader->getAttribute('w:pos', $subnode, 'w:pPr/w:tabs/w:tab'); $level['left'] = $xmlReader->getAttribute('w:left', $subnode, 'w:pPr/w:ind'); $level['hanging'] = $xmlReader->getAttribute('w:hanging', $subnode, 'w:pPr/w:ind'); $level['font'] = $xmlReader->getAttribute('w:ascii', $subnode, 'w:rPr/w:rFonts'); $level['hint'] = $xmlReader->getAttribute('w:hint', $subnode, 'w:rPr/w:rFonts'); foreach ($level as $key => $value) { if (is_null($value)) { unset($level[$key]); } } return $level; } } phpword/src/PhpWord/Reader/Word2007/Settings.php 0000664 00000014654 15177100670 0015360 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLReader; use PhpOffice\PhpWord\Style\Language; /** * Settings reader * * @since 0.14.0 */ class Settings extends AbstractPart { private static $booleanProperties = array( 'mirrorMargins', 'hideSpellingErrors', 'hideGrammaticalErrors', 'trackRevisions', 'doNotTrackMoves', 'doNotTrackFormatting', 'evenAndOddHeaders', 'updateFields', 'autoHyphenation', 'doNotHyphenateCaps', ); /** * Read settings.xml. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $docSettings = $phpWord->getSettings(); $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { $name = str_replace('w:', '', $node->nodeName); $value = $xmlReader->getAttribute('w:val', $node); $method = 'set' . $name; if (in_array($name, $this::$booleanProperties)) { if ($value == 'false') { $docSettings->$method(false); } else { $docSettings->$method(true); } } elseif (method_exists($this, $method)) { $this->$method($xmlReader, $phpWord, $node); } elseif (method_exists($docSettings, $method)) { $docSettings->$method($value); } } } } /** * Sets the document Language * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setThemeFontLang(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $val = $xmlReader->getAttribute('w:val', $node); $eastAsia = $xmlReader->getAttribute('w:eastAsia', $node); $bidi = $xmlReader->getAttribute('w:bidi', $node); $themeFontLang = new Language(); $themeFontLang->setLatin($val); $themeFontLang->setEastAsia($eastAsia); $themeFontLang->setBidirectional($bidi); $phpWord->getSettings()->setThemeFontLang($themeFontLang); } /** * Sets the document protection * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $documentProtection = $phpWord->getSettings()->getDocumentProtection(); $edit = $xmlReader->getAttribute('w:edit', $node); if ($edit !== null) { $documentProtection->setEditing($edit); } } /** * Sets the proof state * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setProofState(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $proofState = $phpWord->getSettings()->getProofState(); $spelling = $xmlReader->getAttribute('w:spelling', $node); $grammar = $xmlReader->getAttribute('w:grammar', $node); if ($spelling !== null) { $proofState->setSpelling($spelling); } if ($grammar !== null) { $proofState->setGrammar($grammar); } } /** * Sets the proof state * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $percent = $xmlReader->getAttribute('w:percent', $node); $val = $xmlReader->getAttribute('w:val', $node); if ($percent !== null || $val !== null) { $phpWord->getSettings()->setZoom($percent === null ? $val : $percent); } } /** * Set the Revision view * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $revisionView = new TrackChangesView(); $revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setComments($xmlReader->getAttribute('w:comments', $node)); $revisionView->setInsDel(filter_var($xmlReader->getAttribute('w:insDel', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN)); $phpWord->getSettings()->setRevisionView($revisionView); } /** * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setConsecutiveHyphenLimit(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $value = $xmlReader->getAttribute('w:val', $node); if ($value !== null) { $phpWord->getSettings()->setConsecutiveHyphenLimit($value); } } /** * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMElement $node */ protected function setHyphenationZone(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $value = $xmlReader->getAttribute('w:val', $node); if ($value !== null) { $phpWord->getSettings()->setHyphenationZone($value); } } } phpword/src/PhpWord/Reader/Word2007/DocPropsApp.php 0000664 00000002067 15177100670 0015745 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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 DocPropsCore { /** * Property mapping * * @var array */ protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager'); /** * Callback functions * * @var array */ protected $callbacks = array(); } phpword/src/PhpWord/Reader/Word2007/Document.php 0000664 00000015213 15177100670 0015326 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLReader; /** * 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. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ 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 = $this->phpWord->addSection(); foreach ($nodes as $node) { if (isset($readMethods[$node->nodeName])) { $readMethod = $readMethods[$node->nodeName]; $this->$readMethod($xmlReader, $node, $section); } } } } /** * Read header footer. * * @param array $settings * @param \PhpOffice\PhpWord\Element\Section &$section */ private function readHeaderFooter($settings, Section &$section) { $readMethods = array('w:p' => 'readParagraph', 'w:tbl' => 'readTable'); if (is_array($settings) && isset($settings['hf'])) { foreach ($settings['hf'] as $rId => $hfSetting) { if (isset($this->rels['document'][$rId])) { list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]); $addMethod = "add{$hfType}"; $hfObject = $section->$addMethod($hfSetting['type']); // Read header/footer content $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $xmlFile); $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { if (isset($readMethods[$node->nodeName])) { $readMethod = $readMethods[$node->nodeName]; $this->$readMethod($xmlReader, $node, $hfObject, $docPart); } } } } } } } /** * Read w:sectPr * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $domNode * @ignoreScrutinizerPatch * @return array */ private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode) { $styleDefs = array( 'breakType' => array(self::READ_VALUE, 'w:type'), 'vAlign' => array(self::READ_VALUE, 'w:vAlign'), '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'), 'marginTop' => array(self::READ_VALUE, 'w:pgMar', 'w:top'), 'marginLeft' => array(self::READ_VALUE, 'w:pgMar', 'w:left'), 'marginBottom' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'), 'marginRight' => 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 ($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 $styles; } /** * Read w:p node. * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $node * @param \PhpOffice\PhpWord\Element\Section &$section * * @todo <w:lastRenderedPageBreak> */ private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section) { // Page break if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') { $section->addPageBreak(); // PageBreak } // 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) { $style = $this->readSectionStyle($xmlReader, $node); $section->setStyle($style); $this->readHeaderFooter($style, $section); } } phpword/src/PhpWord/Reader/Word2007/Endnotes.php 0000664 00000001763 15177100670 0015334 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; /** * Endnotes reader * * @since 0.10.0 */ class Endnotes extends Footnotes { /** * Collection name * * @var string */ protected $collection = 'endnotes'; /** * Element name * * @var string */ protected $element = 'endnote'; } phpword/src/PhpWord/Reader/Word2007/Footnotes.php 0000664 00000006023 15177100670 0015527 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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; /** * Footnotes reader * * @since 0.10.0 */ class Footnotes extends AbstractPart { /** * Collection name footnotes|endnotes * * @var string */ protected $collection = 'footnotes'; /** * Element name footnote|endnote * * @var string */ protected $element = 'footnote'; /** * Read (footnotes|endnotes).xml. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { $id = $xmlReader->getAttribute('w:id', $node); $type = $xmlReader->getAttribute('w:type', $node); // Avoid w:type "separator" and "continuationSeparator" // Only look for <footnote> or <endnote> without w:type attribute, or with w:type = normal if ((is_null($type) || $type === 'normal')) { $element = $this->getElement($phpWord, $id); if ($element !== null) { $pNodes = $xmlReader->getElements('w:p/*', $node); foreach ($pNodes as $pNode) { $this->readRun($xmlReader, $pNode, $element, $this->collection); } $addMethod = "add{$this->element}"; $phpWord->$addMethod($element); } } } } } /** * Searches for the element with the given relationId * * @param PhpWord $phpWord * @param int $relationId * @return \PhpOffice\PhpWord\Element\AbstractContainer|null */ private function getElement(PhpWord $phpWord, $relationId) { $getMethod = "get{$this->collection}"; $collection = $phpWord->$getMethod()->getItems(); //not found by key, looping to search by relationId foreach ($collection as $collectionElement) { if ($collectionElement->getRelationId() == $relationId) { return $collectionElement; } } return null; } } phpword/src/PhpWord/Reader/Word2007/Styles.php 0000664 00000010356 15177100670 0015036 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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\Style\Language; /** * Styles reader * * @since 0.10.0 */ class Styles extends AbstractPart { /** * Read styles.xml. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function read(PhpWord $phpWord) { $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $fontDefaults = $xmlReader->getElement('w:docDefaults/w:rPrDefault'); if ($fontDefaults !== null) { $fontDefaultStyle = $this->readFontStyle($xmlReader, $fontDefaults); if (array_key_exists('name', $fontDefaultStyle)) { $phpWord->setDefaultFontName($fontDefaultStyle['name']); } if (array_key_exists('size', $fontDefaultStyle)) { $phpWord->setDefaultFontSize($fontDefaultStyle['size']); } if (array_key_exists('lang', $fontDefaultStyle)) { $phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang'])); } } $paragraphDefaults = $xmlReader->getElement('w:docDefaults/w:pPrDefault'); if ($paragraphDefaults !== null) { $paragraphDefaultStyle = $this->readParagraphStyle($xmlReader, $paragraphDefaults); if ($paragraphDefaultStyle != null) { $phpWord->setDefaultParagraphStyle($paragraphDefaultStyle); } } $nodes = $xmlReader->getElements('w:style'); if ($nodes->length > 0) { foreach ($nodes as $node) { $type = $xmlReader->getAttribute('w:type', $node); $name = $xmlReader->getAttribute('w:val', $node, 'w:name'); if (is_null($name)) { $name = $xmlReader->getAttribute('w:styleId', $node); } $headingMatches = array(); preg_match('/Heading\s*(\d)/i', $name, $headingMatches); // $default = ($xmlReader->getAttribute('w:default', $node) == 1); switch ($type) { case 'paragraph': $paragraphStyle = $this->readParagraphStyle($xmlReader, $node); $fontStyle = $this->readFontStyle($xmlReader, $node); if (!empty($headingMatches)) { $phpWord->addTitleStyle($headingMatches[1], $fontStyle, $paragraphStyle); } else { if (empty($fontStyle)) { if (is_array($paragraphStyle)) { $phpWord->addParagraphStyle($name, $paragraphStyle); } } else { $phpWord->addFontStyle($name, $fontStyle, $paragraphStyle); } } break; case 'character': $fontStyle = $this->readFontStyle($xmlReader, $node); if (!empty($fontStyle)) { $phpWord->addFontStyle($name, $fontStyle); } break; case 'table': $tStyle = $this->readTableStyle($xmlReader, $node); if (!empty($tStyle)) { $phpWord->addTableStyle($name, $tStyle); } break; } } } } } phpword/src/PhpWord/Reader/RTF/Document.php 0000664 00000024566 15177100670 0014550 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\RTF; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\SimpleType\Jc; /** * 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 (isset($markers[$ascii])) { // Marker found: {, }, \, LF, or CR $markerFunction = $markers[$ascii]; $this->$markerFunction(); } else { if (false === $this->isControl) { // 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 (1 === preg_match('/^([A-Za-z]+)(-?[0-9]*) ?$/', $this->control, $match)) { list(, $control, $parameter) = $match; $this->parseControl($control, $parameter); } if (true === $isControl) { $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 (true === $this->flags['paragraph']) { $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', 'alignment', Jc::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 (isset($controls[$control])) { 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']); } } } phpword/src/PhpWord/Reader/AbstractReader.php 0000664 00000005350 15177100670 0015213 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader; use PhpOffice\PhpWord\Exception\Exception; /** * Reader abstract class * * @since 0.8.0 * * @codeCoverageIgnore Abstract class */ abstract class AbstractReader implements ReaderInterface { /** * Read data only? * * @var bool */ protected $readDataOnly = true; /** * File pointer * * @var bool|resource */ protected $fileHandle; /** * Read data only? * * @return bool */ public function isReadDataOnly() { // return $this->readDataOnly; return true; } /** * Set read data only * * @param bool $value * @return self */ public function setReadDataOnly($value = true) { $this->readDataOnly = $value; return $this; } /** * Open file for reading * * @param string $filename * * @throws \PhpOffice\PhpWord\Exception\Exception * * @return resource */ protected function openFile($filename) { // Check if file exists 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($filename, 'r'); if ($this->fileHandle === false) { throw new Exception("Could not open file $filename for reading."); } } /** * Can the current ReaderInterface read the file? * * @param string $filename * @return bool */ public function canRead($filename) { // Check if file exists try { $this->openFile($filename); } catch (Exception $e) { return false; } if (is_resource($this->fileHandle)) { fclose($this->fileHandle); } return true; } /** * Read data only? * * @deprecated 0.10.0 * * @codeCoverageIgnore */ public function getReadDataOnly() { return $this->isReadDataOnly(); } } phpword/src/PhpWord/Reader/RTF.php 0000664 00000002621 15177100670 0012756 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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; } } phpword/src/PhpWord/Reader/Word2007.php 0000664 00000013304 15177100670 0013547 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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\XMLReader; use PhpOffice\PhpWord\Shared\ZipArchive; /** * Reader for Word2007 * * @since 0.8.0 * @todo watermark, checkbox, toc * @todo Partly done: image, object */ class Word2007 extends AbstractReader implements ReaderInterface { /** * Loads PhpWord from file * * @param string $docFile * @return \PhpOffice\PhpWord\PhpWord */ public function load($docFile) { $phpWord = new PhpWord(); $relationships = $this->readRelationships($docFile); $steps = array( array('stepPart' => 'document', 'stepItems' => array( 'styles' => 'Styles', 'numbering' => 'Numbering', )), array('stepPart' => 'main', 'stepItems' => array( 'officeDocument' => 'Document', 'core-properties' => 'DocPropsCore', 'extended-properties' => 'DocPropsApp', 'custom-properties' => 'DocPropsCustom', )), array('stepPart' => 'document', 'stepItems' => array( 'endnotes' => 'Endnotes', 'footnotes' => 'Footnotes', 'settings' => 'Settings', )), ); foreach ($steps as $step) { $stepPart = $step['stepPart']; $stepItems = $step['stepItems']; if (!isset($relationships[$stepPart])) { continue; } foreach ($relationships[$stepPart] as $relItem) { $relType = $relItem['type']; if (isset($stepItems[$relType])) { $partName = $stepItems[$relType]; $xmlFile = $relItem['target']; $this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile); } } } return $phpWord; } /** * Read document part. * * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param array $relationships * @param string $partName * @param string $docFile * @param string $xmlFile */ private function readPart(PhpWord $phpWord, $relationships, $partName, $docFile, $xmlFile) { $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); } } /** * Read all relationship files * * @param string $docFile * @return array */ private function readRelationships($docFile) { $relationships = array(); // _rels/.rels $relationships['main'] = $this->getRels($docFile, '_rels/.rels'); // word/_rels/*.xml.rels $wordRelsPath = 'word/_rels/'; $zip = new ZipArchive(); if ($zip->open($docFile) === true) { for ($i = 0; $i < $zip->numFiles; $i++) { $xmlFile = $zip->getNameIndex($i); if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') { $docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile)); $relationships[$docPart] = $this->getRels($docFile, $xmlFile, 'word/'); } } $zip->close(); } return $relationships; } /** * Get relationship array * * @param string $docFile * @param string $xmlFile * @param string $targetPrefix * @return array */ private function getRels($docFile, $xmlFile, $targetPrefix = '') { $metaPrefix = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/'; $officePrefix = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/'; $rels = array(); $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($docFile, $xmlFile); $nodes = $xmlReader->getElements('*'); foreach ($nodes as $node) { $rId = $xmlReader->getAttribute('Id', $node); $type = $xmlReader->getAttribute('Type', $node); $target = $xmlReader->getAttribute('Target', $node); $mode = $xmlReader->getAttribute('TargetMode', $node); // Remove URL prefixes from $type to make it easier to read $type = str_replace($metaPrefix, '', $type); $type = str_replace($officePrefix, '', $type); $docPart = str_replace('.xml', '', $target); // Do not add prefix to link source if ($type != 'hyperlink' && $mode != 'External') { $target = $targetPrefix . $target; } // Push to return array $rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart, 'targetMode' => $mode); } ksort($rels); return $rels; } } phpword/src/PhpWord/Reader/HTML.php 0000664 00000002634 15177100670 0013073 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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; } } phpword/src/PhpWord/Reader/MsDoc.php 0000664 00000307142 15177100670 0013336 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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\Drawing; use PhpOffice\PhpWord\Shared\OLERead; use PhpOffice\PhpWord\Style; /** * Reader for Word97 * * @since 0.10.0 */ class MsDoc extends AbstractReader implements ReaderInterface { /** * PhpWord object * * @var PhpWord */ private $phpWord; /** * WordDocument Stream * * @var */ private $dataWorkDocument; /** * 1Table Stream * * @var */ private $data1Table; /** * Data Stream * * @var */ private $dataData; /** * Object Pool Stream * * @var */ private $dataObjectPool; /** * @var \stdClass[] */ private $arrayCharacters = array(); /** * @var array */ private $arrayFib = array(); /** * @var string[] */ private $arrayFonts = array(); /** * @var string[] */ private $arrayParagraphs = array(); /** * @var \stdClass[] */ private $arraySections = array(); const VERSION_97 = '97'; const VERSION_2000 = '2000'; const VERSION_2002 = '2002'; const VERSION_2003 = '2003'; const VERSION_2007 = '2007'; const SPRA_VALUE = 10; const SPRA_VALUE_OPPOSITE = 20; const OFFICEARTBLIPEMF = 0xF01A; const OFFICEARTBLIPWMF = 0xF01B; const OFFICEARTBLIPPICT = 0xF01C; const OFFICEARTBLIPJPG = 0xF01D; const OFFICEARTBLIPPNG = 0xF01E; const OFFICEARTBLIPDIB = 0xF01F; const OFFICEARTBLIPTIFF = 0xF029; const OFFICEARTBLIPJPEG = 0xF02A; const MSOBLIPERROR = 0x00; const MSOBLIPUNKNOWN = 0x01; const MSOBLIPEMF = 0x02; const MSOBLIPWMF = 0x03; const MSOBLIPPICT = 0x04; const MSOBLIPJPEG = 0x05; const MSOBLIPPNG = 0x06; const MSOBLIPDIB = 0x07; const MSOBLIPTIFF = 0x11; const MSOBLIPCMYKJPEG = 0x12; /** * Loads PhpWord from file * * @param string $filename * @return PhpWord */ public function load($filename) { $this->phpWord = new PhpWord(); $this->loadOLE($filename); $this->readFib($this->dataWorkDocument); $this->readFibContent(); return $this->phpWord; } /** * Load an OLE Document * @param string $filename */ private function loadOLE($filename) { // OLE reader $ole = new OLERead(); $ole->read($filename); // Get WorkDocument stream $this->dataWorkDocument = $ole->getStream($ole->wrkdocument); // Get 1Table stream $this->data1Table = $ole->getStream($ole->wrk1Table); // Get Data stream $this->dataData = $ole->getStream($ole->wrkData); // Get Data stream $this->dataObjectPool = $ole->getStream($ole->wrkObjectPool); // Get Summary Information data $this->_SummaryInformation = $ole->getStream($ole->summaryInformation); // Get Document Summary Information data $this->_DocumentSummaryInformation = $ole->getStream($ole->docSummaryInfos); } private function getNumInLcb($lcb, $iSize) { return ($lcb - 4) / (4 + $iSize); } private function getArrayCP($data, $posMem, $iNum) { $arrayCP = array(); for ($inc = 0; $inc < $iNum; $inc++) { $arrayCP[$inc] = self::getInt4d($data, $posMem); $posMem += 4; } return $arrayCP; } /** * @see http://msdn.microsoft.com/en-us/library/dd949344%28v=office.12%29.aspx * @see https://igor.io/2012/09/24/binary-parsing.html * @param string $data */ private function readFib($data) { $pos = 0; //----- FibBase // wIdent $pos += 2; // nFib $pos += 2; // unused $pos += 2; // lid : Language Identifier $pos += 2; // pnNext $pos += 2; // $mem = self::getInt2d($data, $pos); // $fDot = ($mem >> 15) & 1; // $fGlsy = ($mem >> 14) & 1; // $fComplex = ($mem >> 13) & 1; // $fHasPic = ($mem >> 12) & 1; // $cQuickSaves = ($mem >> 8) & bindec('1111'); // $fEncrypted = ($mem >> 7) & 1; // $fWhichTblStm = ($mem >> 6) & 1; // $fReadOnlyRecommended = ($mem >> 5) & 1; // $fWriteReservation = ($mem >> 4) & 1; // $fExtChar = ($mem >> 3) & 1; // $fLoadOverride = ($mem >> 2) & 1; // $fFarEast = ($mem >> 1) & 1; // $fObfuscated = ($mem >> 0) & 1; $pos += 2; // nFibBack $pos += 2; // lKey $pos += 4; // envr $pos += 1; // $mem = self::getInt1d($data, $pos); // $fMac = ($mem >> 7) & 1; // $fEmptySpecial = ($mem >> 6) & 1; // $fLoadOverridePage = ($mem >> 5) & 1; // $reserved1 = ($mem >> 4) & 1; // $reserved2 = ($mem >> 3) & 1; // $fSpare0 = ($mem >> 0) & bindec('111'); $pos += 1; // reserved3 $pos += 2; // reserved4 $pos += 2; // reserved5 $pos += 4; // reserved6 $pos += 4; //----- csw $pos += 2; //----- fibRgW // reserved1 $pos += 2; // reserved2 $pos += 2; // reserved3 $pos += 2; // reserved4 $pos += 2; // reserved5 $pos += 2; // reserved6 $pos += 2; // reserved7 $pos += 2; // reserved8 $pos += 2; // reserved9 $pos += 2; // reserved10 $pos += 2; // reserved11 $pos += 2; // reserved12 $pos += 2; // reserved13 $pos += 2; // lidFE $pos += 2; //----- cslw $pos += 2; //----- fibRgLw // cbMac $pos += 4; // reserved1 $pos += 4; // reserved2 $pos += 4; $this->arrayFib['ccpText'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['ccpFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['ccpHdd'] = self::getInt4d($data, $pos); $pos += 4; // reserved3 $pos += 4; // ccpAtn $pos += 4; // ccpEdn $pos += 4; // ccpTxbx $pos += 4; // ccpHdrTxbx $pos += 4; // reserved4 $pos += 4; // reserved5 $pos += 4; // reserved6 $pos += 4; // reserved7 $pos += 4; // reserved8 $pos += 4; // reserved9 $pos += 4; // reserved10 $pos += 4; // reserved11 $pos += 4; // reserved12 $pos += 4; // reserved13 $pos += 4; // reserved14 $pos += 4; //----- cbRgFcLcb $cbRgFcLcb = self::getInt2d($data, $pos); $pos += 2; //----- fibRgFcLcbBlob switch ($cbRgFcLcb) { case 0x005D: $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_97); break; case 0x006C: $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_97); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2000); break; case 0x0088: $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_97); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2000); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2002); break; case 0x00A4: $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_97); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2000); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2002); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2003); break; case 0x00B7: $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_97); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2000); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2002); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2003); $pos = $this->readBlockFibRgFcLcb($data, $pos, self::VERSION_2007); break; } //----- cswNew $this->arrayFib['cswNew'] = self::getInt2d($data, $pos); $pos += 2; if ($this->arrayFib['cswNew'] != 0) { //@todo : fibRgCswNew } return $pos; } private function readBlockFibRgFcLcb($data, $pos, $version) { if ($version == self::VERSION_97) { $this->arrayFib['fcStshfOrig'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbStshfOrig'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcStshf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbStshf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcffndRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcffndRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcffndTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcffndTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfandRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfandRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfandTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfandTxt '] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfSed'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfSed'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcPad'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcPad'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfPhe'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfPhe'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfGlsy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfGlsy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfGlsy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfGlsy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfHdd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfHdd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBteChpx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBteChpx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBtePapx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBtePapx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfSea'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfSea'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfFfn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfFfn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldMom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldMom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldHdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldHdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldAtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldAtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldMcr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldMcr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmk'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmk'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcCmds'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbCmds'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfMcr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfMcr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPrDrvr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPrDrvr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPrEnvPort'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPrEnvPort'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPrEnvLand'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPrEnvLand'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcWss'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbWss'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcDop'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbDop'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfAssoc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfAssoc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcClx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbClx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfPgdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfPgdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAutosaveSource'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAutosaveSource'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcGrpXstAtnOwners'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbGrpXstAtnOwners'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfAtnBkmk'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfAtnBkmk'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused3'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused3'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcSpaMom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcSpaMom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcSpaHdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcSpaHdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfAtnBkf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfAtnBkf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfAtnBkl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfAtnBkl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPms'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPms'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcFormFldSttbs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbFormFldSttbs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfendRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfendRef'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfendTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfendTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused4'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused4'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcDggInfo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbDggInfo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfRMark'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfRMark'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfCaption'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfCaption'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfAutoCaption'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfAutoCaption'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfWkb'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfWkb'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfSpl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfSpl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcftxbxTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcftxbxTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfFldTxbx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfFldTxbx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfHdrtxbxTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfHdrtxbxTxt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcffldHdrTxbx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcffldHdrTxbx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcStwUser'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbStwUser'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbTtmbd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbTtmbd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcCookieData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbCookieData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdMotherOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdMotherOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdMotherOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdMotherOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdFtnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdFtnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdFtnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdFtnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdEdnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdEdnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdEdnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdEdnOldOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfIntlFld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfIntlFld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcRouteSlip'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbRouteSlip'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbSavedBy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbSavedBy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbFnm'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbFnm'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlfLst'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlfLst'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlfLfo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlfLfo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfTxbxBkd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfTxbxBkd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfTxbxHdrBkd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfTxbxHdrBkd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcDocUndoWord9'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbDocUndoWord9'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcRgbUse'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbRgbUse'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUsp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUsp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUskf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUskf'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcupcRgbUse'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcupcRgbUse'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcupcUsp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcupcUsp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbGlsyStyle'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbGlsyStyle'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlgosl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlgosl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcocx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcocx'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBteLvc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBteLvc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['dwLowDateTime'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['dwHighDateTime'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfLvcPre10'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfLvcPre10'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfAsumy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfAsumy'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfGram'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfGram'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbListNames'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbListNames'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfUssr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfUssr'] = self::getInt4d($data, $pos); $pos += 4; } if ($version == self::VERSION_2000) { $this->arrayFib['fcPlcfTch'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfTch'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcRmdThreading'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbRmdThreading'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcMid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbMid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbRgtplc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbRgtplc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcMsoEnvelope'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbMsoEnvelope'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfLad'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfLad'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcRgDofr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbRgDofr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcosl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcosl'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfCookieOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfCookieOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdMotherOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdMotherOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdMotherOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdMotherOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdFtnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdFtnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdFtnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdFtnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdEdnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdEdnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdEdnOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdEdnOld'] = self::getInt4d($data, $pos); $pos += 4; } if ($version == self::VERSION_2002) { $this->arrayFib['fcUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfPgp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfPgp'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfuim'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfuim'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlfguidUim'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlfguidUim'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAtrdExtra'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAtrdExtra'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlrsid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlrsid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfcookie'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfcookie'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklFactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcFactoidData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbFactoidData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcDocUndo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbDocUndo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklFcc'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfbkmkBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfbkmkBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfbkfBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfbkfBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfbklBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfbklBPRepairs'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPmsNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPmsNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcODSO'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbODSO'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiOldXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiOldXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiNewXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiNewXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiMixedXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiMixedXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcffactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcffactoid'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcOldXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcOldXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcNewXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcNewXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcMixedXP'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcMixedXP'] = self::getInt4d($data, $pos); $pos += 4; } if ($version == self::VERSION_2003) { $this->arrayFib['fcHplxsdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbHplxsdr'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklSdt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcCustomXForm'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbCustomXForm'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklProt'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbProtUser'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbProtUser'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiOldInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiOldInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfpmiNewInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfpmiNewInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcOld'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcOldInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcOldInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcNew'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcflvcNewInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcflvcNewInline'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAfdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAfdMother'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAfdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAfdFtn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPgdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPgdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcBkdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbBkdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAfdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAfdEdn'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcAfd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbAfd'] = self::getInt4d($data, $pos); $pos += 4; } if ($version == self::VERSION_2007) { $this->arrayFib['fcPlcfmthd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfmthd'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklMoveFrom'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklMoveTo'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused1'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused2'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused3'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused3'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcSttbfBkmkArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbSttbfBkmkArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBkfArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBkfArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcPlcfBklArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbPlcfBklArto'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcArtoData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbArtoData'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused4'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused4'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused5'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused5'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcUnused6'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbUnused6'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcOssTheme'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbOssTheme'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['fcColorSchemeMapping'] = self::getInt4d($data, $pos); $pos += 4; $this->arrayFib['lcbColorSchemeMapping'] = self::getInt4d($data, $pos); $pos += 4; } return $pos; } private function readFibContent() { // Informations about Font $this->readRecordSttbfFfn(); // Informations about page $this->readRecordPlcfSed(); // reading paragraphs //@see https://github.com/notmasteryet/CompoundFile/blob/ec118f354efebdee9102e41b5b7084fce81125b0/WordFileReader/WordDocument.cs#L86 $this->readRecordPlcfBtePapx(); // reading character formattings //@see https://github.com/notmasteryet/CompoundFile/blob/ec118f354efebdee9102e41b5b7084fce81125b0/WordFileReader/WordDocument.cs#L94 $this->readRecordPlcfBteChpx(); $this->generatePhpWord(); } /** * Section and information about them * @see : http://msdn.microsoft.com/en-us/library/dd924458%28v=office.12%29.aspx */ private function readRecordPlcfSed() { $posMem = $this->arrayFib['fcPlcfSed']; // PlcfSed // PlcfSed : aCP $aCP = array(); $aCP[0] = self::getInt4d($this->data1Table, $posMem); $posMem += 4; $aCP[1] = self::getInt4d($this->data1Table, $posMem); $posMem += 4; // PlcfSed : aSed //@see : http://msdn.microsoft.com/en-us/library/dd950194%28v=office.12%29.aspx $numSed = $this->getNumInLcb($this->arrayFib['lcbPlcfSed'], 12); $aSed = array(); for ($iInc = 0; $iInc < $numSed; ++$iInc) { // Sed : http://msdn.microsoft.com/en-us/library/dd950982%28v=office.12%29.aspx // fn $posMem += 2; // fnMpr $aSed[$iInc] = self::getInt4d($this->data1Table, $posMem); $posMem += 4; // fnMpr $posMem += 2; // fcMpr $posMem += 4; } foreach ($aSed as $offsetSed) { // Sepx : http://msdn.microsoft.com/en-us/library/dd921348%28v=office.12%29.aspx $cb = self::getInt2d($this->dataWorkDocument, $offsetSed); $offsetSed += 2; $oStylePrl = $this->readPrl($this->dataWorkDocument, $offsetSed, $cb); $offsetSed += $oStylePrl->length; $this->arraySections[] = $oStylePrl; } } /** * Specifies the fonts that are used in the document * @see : http://msdn.microsoft.com/en-us/library/dd943880%28v=office.12%29.aspx */ private function readRecordSttbfFfn() { $posMem = $this->arrayFib['fcSttbfFfn']; $cData = self::getInt2d($this->data1Table, $posMem); $posMem += 2; $cbExtra = self::getInt2d($this->data1Table, $posMem); $posMem += 2; if ($cData < 0x7FF0 && $cbExtra == 0) { for ($inc = 0; $inc < $cData; $inc++) { // len $posMem += 1; // ffid $posMem += 1; // wWeight (400 : Normal - 700 bold) $posMem += 2; // chs $posMem += 1; // ixchSzAlt $ixchSzAlt = self::getInt1d($this->data1Table, $posMem); $posMem += 1; // panose $posMem += 10; // fs $posMem += 24; // xszFfn $xszFfn = ''; do { $char = self::getInt2d($this->data1Table, $posMem); $posMem += 2; if ($char > 0) { $xszFfn .= chr($char); } } while ($char != 0); // xszAlt $xszAlt = ''; if ($ixchSzAlt > 0) { do { $char = self::getInt2d($this->data1Table, $posMem); $posMem += 2; if ($char == 0) { break; } $xszAlt .= chr($char); } while ($char != 0); } $this->arrayFonts[] = array( 'main' => $xszFfn, 'alt' => $xszAlt, ); } } } /** * Paragraph and information about them * @see http://msdn.microsoft.com/en-us/library/dd908569%28v=office.12%29.aspx */ private function readRecordPlcfBtePapx() { $posMem = $this->arrayFib['fcPlcfBtePapx']; $num = $this->getNumInLcb($this->arrayFib['lcbPlcfBtePapx'], 4); $posMem += 4 * ($num + 1); $arrAPnBtePapx = $this->getArrayCP($this->data1Table, $posMem, $num); $posMem += 4 * $num; foreach ($arrAPnBtePapx as $aPnBtePapx) { $offsetBase = $aPnBtePapx * 512; $offset = $offsetBase; $string = ''; $numRun = self::getInt1d($this->dataWorkDocument, $offset + 511); $arrayRGFC = array(); for ($inc = 0; $inc <= $numRun; $inc++) { $arrayRGFC[$inc] = self::getInt4d($this->dataWorkDocument, $offset); $offset += 4; } $arrayRGB = array(); for ($inc = 1; $inc <= $numRun; $inc++) { // @see http://msdn.microsoft.com/en-us/library/dd925804(v=office.12).aspx $arrayRGB[$inc] = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; // reserved $offset += 12; } foreach (array_keys($arrayRGFC) as $key) { if (!isset($arrayRGFC[$key + 1])) { break; } $strLen = $arrayRGFC[$key + 1] - $arrayRGFC[$key] - 1; for ($inc = 0; $inc < $strLen; $inc++) { $byte = self::getInt1d($this->dataWorkDocument, $arrayRGFC[$key] + $inc); if ($byte > 0) { $string .= chr($byte); } } } $this->arrayParagraphs[] = $string; //@todo readPrl for paragraphs /*// use $this->readPrl() foreach ($arrayRGB as $key => $rgb) { $offset = $offsetBase + ($rgb * 2); $cb = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; print_r('$cb : '.$cb.PHP_EOL); if ($cb == 0) { $cb = self::getInt1d($this->dataWorkDocument, $offset); $cb = $cb * 2; $offset += 1; print_r('$cb0 : '.$cb.PHP_EOL); } else { $cb = $cb * 2 - 1; print_r('$cbD : '.$cb.PHP_EOL); } $istd = self::getInt2d($this->dataWorkDocument, $offset); $offset += 2; $cb -= 2; print_r('$istd : '.$istd.($istd == 0 ? ' (Normal)' : '').PHP_EOL); if ($cb > 0) { do{ $sprm = self::getInt2d($this->dataWorkDocument, $offset); $offset += 2; $cb -= 2; $sprm_IsPmd = $sprm & 0x01FF; $sprm_F = ($sprm/512) & 0x0001; $sprm_Sgc = ($sprm/1024) & 0x0007; $sprm_Spra = ($sprm/8192); print_r('$sprm : 0x'.dechex($sprm).PHP_EOL); print_r('$sprm.ispmd : 0x'.dechex($sprm_IsPmd).PHP_EOL); print_r('$sprm.f : 0x'.dechex($sprm_F).PHP_EOL); print_r('$sprm.sgc : 0x'.dechex($sprm_Sgc)); switch (dechex($sprm_Sgc)) { case 0x01: print_r(' (Paragraph property)'); break; case 0x02: print_r(' (Character property)'); break; case 0x03: print_r(' (Picture property)'); break; case 0x04: print_r(' (Section property)'); break; case 0x05: print_r(' (Table property)'); break; } print_r(PHP_EOL); print_r('$sprm.spra : 0x'.dechex($sprm_Spra).PHP_EOL); switch (dechex($sprm_Spra)) { case 0x0: $operand = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; $cb -= 1; switch (dechex($operand)) { case 0x00: $operand = 'OFF'; break; case 0x01: $operand = 'ON'; break; case 0x80: $operand = 'CURRENT VALUE'; print_r(''.PHP_EOL.PHP_EOL); break; case 0x81: $operand = 'OPPOSITE OF THE CURRENT VALUE'; break; } break; case 0x1: $operand = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; $cb -= 1; print_r('$operand : 0x'.dechex($operand).PHP_EOL); break; case 0x2: case 0x4: case 0x5: $operand = self::getInt2d($this->dataWorkDocument, $offset); $offset += 2; $cb -= 2; print_r('$operand : 0x'.dechex($operand).PHP_EOL); break; case 0x3: if ($sprm_IsPmd != 0x70) { $operand = self::getInt4d($this->dataWorkDocument, $offset); $offset += 4; $cb -= 4; print_r('$operand : 0x'.dechex($operand).PHP_EOL); } break; case 0x7: $operand = self::getInt3d($this->dataWorkDocument, $offset); $offset += 3; $cb -= 3; print_r('$operand : 0x'.dechex($operand).PHP_EOL); break; default: print_r('YO YO YO : '.PHP_EOL); } // switch (dechex($sprm_Sgc)) { case 0x01: // Sprm is modifying a paragraph property. switch ($sprm_IsPmd) { case 0x0A: // sprmPIlvl print_r('sprmPIlvl : '.$operand.PHP_EOL.PHP_EOL); break; case 0x0B: // sprmPIlfo print_r('sprmPIlfo : '.$operand.PHP_EOL.PHP_EOL); break; default: print_r('$sprm_IsPmd(1) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x02: // Sprm is modifying a character property. switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(2) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x03: // Sprm is modifying a picture property. switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(3) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x04: // Sprm is modifying a section property. switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x05: // Sprm is modifying a table property. switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; default: print_r('$sprm_Sgc : '.dechex($sprm_Sgc).PHP_EOL.PHP_EOL); break; } } while ($cb > 0); } else { if ($istd > 0) { // @todo : Determining Properties of a Paragraph Style # @see http://msdn.microsoft.com/en-us/library/dd948631%28v=office.12%29.aspx } } }*/ } } /** * Character formatting properties to text in a document * @see http://msdn.microsoft.com/en-us/library/dd907108%28v=office.12%29.aspx */ private function readRecordPlcfBteChpx() { $posMem = $this->arrayFib['fcPlcfBteChpx']; $num = $this->getNumInLcb($this->arrayFib['lcbPlcfBteChpx'], 4); $aPnBteChpx = array(); for ($inc = 0; $inc <= $num; $inc++) { $aPnBteChpx[$inc] = self::getInt4d($this->data1Table, $posMem); $posMem += 4; } $pnFkpChpx = self::getInt4d($this->data1Table, $posMem); $posMem += 4; $offsetBase = $pnFkpChpx * 512; $offset = $offsetBase; // ChpxFkp // @see : http://msdn.microsoft.com/en-us/library/dd910989%28v=office.12%29.aspx $numRGFC = self::getInt1d($this->dataWorkDocument, $offset + 511); $arrayRGFC = array(); for ($inc = 0; $inc <= $numRGFC; $inc++) { $arrayRGFC[$inc] = self::getInt4d($this->dataWorkDocument, $offset); $offset += 4; } $arrayRGB = array(); for ($inc = 1; $inc <= $numRGFC; $inc++) { $arrayRGB[$inc] = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; } $start = 0; foreach ($arrayRGB as $keyRGB => $rgb) { $oStyle = new \stdClass(); $oStyle->pos_start = $start; $oStyle->pos_len = (int) ceil((($arrayRGFC[$keyRGB] - 1) - $arrayRGFC[$keyRGB - 1]) / 2); $start += $oStyle->pos_len; if ($rgb > 0) { // Chp Structure // @see : http://msdn.microsoft.com/en-us/library/dd772849%28v=office.12%29.aspx $posRGB = $offsetBase + $rgb * 2; $cb = self::getInt1d($this->dataWorkDocument, $posRGB); $posRGB += 1; $oStyle->style = $this->readPrl($this->dataWorkDocument, $posRGB, $cb); $posRGB += $oStyle->style->length; } $this->arrayCharacters[] = $oStyle; } } /** * @param $sprm * @return \stdClass */ private function readSprm($sprm) { $oSprm = new \stdClass(); $oSprm->isPmd = $sprm & 0x01FF; $oSprm->f = ($sprm / 512) & 0x0001; $oSprm->sgc = ($sprm / 1024) & 0x0007; $oSprm->spra = ($sprm / 8192); return $oSprm; } /** * @param string $data * @param int $pos * @param \stdClass $oSprm * @return array */ private function readSprmSpra($data, $pos, $oSprm) { $length = 0; $operand = null; switch (dechex($oSprm->spra)) { case 0x0: $operand = self::getInt1d($data, $pos); $length = 1; switch (dechex($operand)) { case 0x00: $operand = false; break; case 0x01: $operand = true; break; case 0x80: $operand = self::SPRA_VALUE; break; case 0x81: $operand = self::SPRA_VALUE_OPPOSITE; break; } break; case 0x1: $operand = self::getInt1d($data, $pos); $length = 1; break; case 0x2: case 0x4: case 0x5: $operand = self::getInt2d($data, $pos); $length = 2; break; case 0x3: if ($oSprm->isPmd != 0x70) { $operand = self::getInt4d($data, $pos); $length = 4; } break; case 0x7: $operand = self::getInt3d($data, $pos); $length = 3; break; default: // print_r('YO YO YO : '.PHP_EOL); } return array( 'length' => $length, 'operand' => $operand, ); } /** * @param $data int * @param $pos int * @param $cbNum int * @return \stdClass * @see http://msdn.microsoft.com/en-us/library/dd772849%28v=office.12%29.aspx */ private function readPrl($data, $pos, $cbNum) { $posStart = $pos; $oStylePrl = new \stdClass(); // Variables $sprmCPicLocation = null; $sprmCFData = null; //$sprmCFSpec = null; do { // Variables $operand = null; $sprm = self::getInt2d($data, $pos); $oSprm = $this->readSprm($sprm); $pos += 2; $cbNum -= 2; $arrayReturn = $this->readSprmSpra($data, $pos, $oSprm); $pos += $arrayReturn['length']; $cbNum -= $arrayReturn['length']; $operand = $arrayReturn['operand']; switch (dechex($oSprm->sgc)) { // Paragraph property case 0x01: break; // Character property case 0x02: if (!isset($oStylePrl->styleFont)) { $oStylePrl->styleFont = array(); } switch ($oSprm->isPmd) { // sprmCFRMarkIns case 0x01: break; // sprmCFFldVanish case 0x02: break; // sprmCPicLocation case 0x03: $sprmCPicLocation = $operand; break; // sprmCFData case 0x06: $sprmCFData = dechex($operand) != 0x00; break; // sprmCFItalic case 0x36: // By default, text is not italicized. switch ($operand) { case false: case true: $oStylePrl->styleFont['italic'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['italic'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['italic'] = true; break; } break; // sprmCIstd case 0x30: //print_r('sprmCIstd : '.dechex($operand).PHP_EOL.PHP_EOL); break; // sprmCFBold case 0x35: // By default, text is not bold. switch ($operand) { case false: case true: $oStylePrl->styleFont['bold'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['bold'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['bold'] = true; break; } break; // sprmCFStrike case 0x37: // By default, text is not struck through. switch ($operand) { case false: case true: $oStylePrl->styleFont['strikethrough'] = $operand; break; case self::SPRA_VALUE: $oStylePrl->styleFont['strikethrough'] = false; break; case self::SPRA_VALUE_OPPOSITE: $oStylePrl->styleFont['strikethrough'] = true; break; } break; // sprmCKul case 0x3E: switch (dechex($operand)) { case 0x00: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; break; case 0x01: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_SINGLE; break; case 0x02: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WORDS; break; case 0x03: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOUBLE; break; case 0x04: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTTED; break; case 0x06: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_HEAVY; break; case 0x07: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASH; break; case 0x09: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDASH; break; case 0x0A: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDOTDASH; break; case 0x0B: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVY; break; case 0x14: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTTEDHEAVY; break; case 0x17: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHHEAVY; break; case 0x19: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDASHHEAVY; break; case 0x1A: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DOTDOTDASHHEAVY; break; case 0x1B: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVYHEAVY; break; case 0x27: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHLONG; break; case 0x2B: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_WAVYDOUBLE; break; case 0x37: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_DASHLONGHEAVY; break; default: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; break; } break; // sprmCIco //@see http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx case 0x42: switch (dechex($operand)) { case 0x00: case 0x01: $oStylePrl->styleFont['color'] = '000000'; break; case 0x02: $oStylePrl->styleFont['color'] = '0000FF'; break; case 0x03: $oStylePrl->styleFont['color'] = '00FFFF'; break; case 0x04: $oStylePrl->styleFont['color'] = '00FF00'; break; case 0x05: $oStylePrl->styleFont['color'] = 'FF00FF'; break; case 0x06: $oStylePrl->styleFont['color'] = 'FF0000'; break; case 0x07: $oStylePrl->styleFont['color'] = 'FFFF00'; break; case 0x08: $oStylePrl->styleFont['color'] = 'FFFFFF'; break; case 0x09: $oStylePrl->styleFont['color'] = '000080'; break; case 0x0A: $oStylePrl->styleFont['color'] = '008080'; break; case 0x0B: $oStylePrl->styleFont['color'] = '008000'; break; case 0x0C: $oStylePrl->styleFont['color'] = '800080'; break; case 0x0D: $oStylePrl->styleFont['color'] = '800080'; break; case 0x0E: $oStylePrl->styleFont['color'] = '808000'; break; case 0x0F: $oStylePrl->styleFont['color'] = '808080'; break; case 0x10: $oStylePrl->styleFont['color'] = 'C0C0C0'; } break; // sprmCHps case 0x43: $oStylePrl->styleFont['size'] = dechex($operand / 2); break; // sprmCIss case 0x48: if (!isset($oStylePrl->styleFont['superScript'])) { $oStylePrl->styleFont['superScript'] = false; } if (!isset($oStylePrl->styleFont['subScript'])) { $oStylePrl->styleFont['subScript'] = false; } switch (dechex($operand)) { case 0x00: // Normal text break; case 0x01: $oStylePrl->styleFont['superScript'] = true; break; case 0x02: $oStylePrl->styleFont['subScript'] = true; break; } break; // sprmCRgFtc0 case 0x4F: $oStylePrl->styleFont['name'] = ''; if (isset($this->arrayFonts[$operand])) { $oStylePrl->styleFont['name'] = $this->arrayFonts[$operand]['main']; } break; // sprmCRgFtc1 case 0x50: // if the language for the text is an East Asian language break; // sprmCRgFtc2 case 0x51: // if the character falls outside the Unicode character range break; // sprmCFSpec case 0x55: //$sprmCFSpec = $operand; break; // sprmCFtcBi case 0x5E: break; // sprmCFItalicBi case 0x5D: break; // sprmCHpsBi case 0x61: break; // sprmCShd80 //@see http://msdn.microsoft.com/en-us/library/dd923447%28v=office.12%29.aspx case 0x66: // $operand = self::getInt2d($data, $pos); $pos += 2; $cbNum -= 2; // $ipat = ($operand >> 0) && bindec('111111'); // $icoBack = ($operand >> 6) && bindec('11111'); // $icoFore = ($operand >> 11) && bindec('11111'); break; // sprmCCv //@see : http://msdn.microsoft.com/en-us/library/dd952824%28v=office.12%29.aspx case 0x70: $red = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $green = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $blue = str_pad(dechex(self::getInt1d($this->dataWorkDocument, $pos)), 2, '0', STR_PAD_LEFT); $pos += 1; $pos += 1; $oStylePrl->styleFont['color'] = $red . $green . $blue; $cbNum -= 4; break; default: // print_r('@todo Character : 0x'.dechex($oSprm->isPmd)); // print_r(PHP_EOL); } break; // Picture property case 0x03: break; // Section property case 0x04: if (!isset($oStylePrl->styleSection)) { $oStylePrl->styleSection = array(); } switch ($oSprm->isPmd) { // sprmSNfcPgn case 0x0E: // numbering format used for page numbers break; // sprmSXaPage case 0x1F: $oStylePrl->styleSection['pageSizeW'] = $operand; break; // sprmSYaPage case 0x20: $oStylePrl->styleSection['pageSizeH'] = $operand; break; // sprmSDxaLeft case 0x21: $oStylePrl->styleSection['marginLeft'] = $operand; break; // sprmSDxaRight case 0x22: $oStylePrl->styleSection['marginRight'] = $operand; break; // sprmSDyaTop case 0x23: $oStylePrl->styleSection['marginTop'] = $operand; break; // sprmSDyaBottom case 0x24: $oStylePrl->styleSection['marginBottom'] = $operand; break; // sprmSFBiDi case 0x28: // RTL layout break; // sprmSDxtCharSpace case 0x30: // characpter pitch break; // sprmSDyaLinePitch case 0x31: // line height break; // sprmSClm case 0x32: // document grid mode break; // sprmSTextFlow case 0x33: // text flow break; default: // print_r('@todo Section : 0x'.dechex($oSprm->isPmd)); // print_r(PHP_EOL); } break; // Table property case 0x05: break; } } while ($cbNum > 0); if (!is_null($sprmCPicLocation)) { if (!is_null($sprmCFData) && $sprmCFData == 0x01) { // NilPICFAndBinData //@todo Read Hyperlink structure /*$lcb = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $cbHeader = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // ignored $sprmCPicLocation += 62; // depending of the element // Hyperlink => HFD // HFD > bits $sprmCPicLocation += 1; // HFD > clsid $sprmCPicLocation += 16; // HFD > hyperlink //@see : http://msdn.microsoft.com/en-us/library/dd909835%28v=office.12%29.aspx $streamVersion = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $data = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; $hlstmfAbsFromGetdataRel = ($data >> 9) & bindec('1'); $hlstmfMonikerSavedAsStr = ($data >> 8) & bindec('1'); $hlstmfHasFrameName = ($data >> 7) & bindec('1'); $hlstmfHasCreationTime = ($data >> 6) & bindec('1'); $hlstmfHasGUID = ($data >> 5) & bindec('1'); $hlstmfHasDisplayName = ($data >> 4) & bindec('1'); $hlstmfHasLocationStr = ($data >> 3) & bindec('1'); $hlstmfSiteGaveDisplayName = ($data >> 2) & bindec('1'); $hlstmfIsAbsolute = ($data >> 1) & bindec('1'); $hlstmfHasMoniker = ($data >> 0) & bindec('1'); for ($inc = 0; $inc <= 32; $inc++) { echo ($data >> $inc) & bindec('1'); } print_r('$hlstmfHasMoniker > '.$hlstmfHasMoniker.PHP_EOL); print_r('$hlstmfIsAbsolute > '.$hlstmfIsAbsolute.PHP_EOL); print_r('$hlstmfSiteGaveDisplayName > '.$hlstmfSiteGaveDisplayName.PHP_EOL); print_r('$hlstmfHasLocationStr > '.$hlstmfHasLocationStr.PHP_EOL); print_r('$hlstmfHasDisplayName > '.$hlstmfHasDisplayName.PHP_EOL); print_r('$hlstmfHasGUID > '.$hlstmfHasGUID.PHP_EOL); print_r('$hlstmfHasCreationTime > '.$hlstmfHasCreationTime.PHP_EOL); print_r('$hlstmfHasFrameName > '.$hlstmfHasFrameName.PHP_EOL); print_r('$hlstmfMonikerSavedAsStr > '.$hlstmfMonikerSavedAsStr.PHP_EOL); print_r('$hlstmfAbsFromGetdataRel > '.$hlstmfAbsFromGetdataRel.PHP_EOL); if ($streamVersion == 2) { $AAA = self::getInt4d($this->dataData, $sprmCPicLocation); echo 'AAAA : '.$AAA.PHP_EOL; if ($hlstmfHasDisplayName == 1) { echo 'displayName'.PHP_EOL; } if ($hlstmfHasFrameName == 1) { echo 'targetFrameName'.PHP_EOL; } if ($hlstmfHasMoniker == 1 || $hlstmfMonikerSavedAsStr == 1) { $sprmCPicLocation += 16; $length = self::getInt4d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 4; for ($inc = 0; $inc < ($length / 2); $inc++) { $chr = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; print_r(chr($chr)); } echo PHP_EOL; echo 'moniker : '.$length.PHP_EOL; } if ($hlstmfHasMoniker == 1 || $hlstmfMonikerSavedAsStr == 1) { echo 'oleMoniker'.PHP_EOL; } if ($hlstmfHasLocationStr == 1) { echo 'location'.PHP_EOL; } if ($hlstmfHasGUID == 1) { echo 'guid'.PHP_EOL; $sprmCPicLocation += 16; } if ($hlstmfHasCreationTime == 1) { echo 'fileTime'.PHP_EOL; $sprmCPicLocation += 4; } echo 'HYPERLINK'.PHP_EOL; }*/ } else { // Pictures //@see : http://msdn.microsoft.com/en-us/library/dd925458%28v=office.12%29.aspx //@see : http://msdn.microsoft.com/en-us/library/dd926136%28v=office.12%29.aspx // PICF : lcb $sprmCPicLocation += 4; // PICF : cbHeader $sprmCPicLocation += 2; // PICF : mfpf : mm $mfpfMm = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : mfpf : xExt $sprmCPicLocation += 2; // PICF : mfpf : yExt $sprmCPicLocation += 2; // PICF : mfpf : swHMF $sprmCPicLocation += 2; // PICF : innerHeader : grf $sprmCPicLocation += 4; // PICF : innerHeader : padding1 $sprmCPicLocation += 4; // PICF : innerHeader : mmPM $sprmCPicLocation += 2; // PICF : innerHeader : padding2 $sprmCPicLocation += 4; // PICF : picmid : dxaGoal $picmidDxaGoal = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaGoal $picmidDyaGoal = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : mx $picmidMx = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : my $picmidMy = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dxaReserved1 $picmidDxaCropLeft = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaReserved1 $picmidDxaCropTop = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dxaReserved2 $picmidDxaCropRight = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : dyaReserved2 $picmidDxaCropBottom = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; // PICF : picmid : fReserved $sprmCPicLocation += 1; // PICF : picmid : bpp $sprmCPicLocation += 1; // PICF : picmid : brcTop80 $sprmCPicLocation += 4; // PICF : picmid : brcLeft80 $sprmCPicLocation += 4; // PICF : picmid : brcBottom80 $sprmCPicLocation += 4; // PICF : picmid : brcRight80 $sprmCPicLocation += 4; // PICF : picmid : dxaReserved3 $sprmCPicLocation += 2; // PICF : picmid : dyaReserved3 $sprmCPicLocation += 2; // PICF : cProps $sprmCPicLocation += 2; if ($mfpfMm == 0x0066) { // cchPicName $cchPicName = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; // stPicName //$stPicName = ''; for ($inc = 0; $inc <= $cchPicName; $inc++) { //$chr = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; //$stPicName .= chr($chr); } } // picture (OfficeArtInlineSpContainer) // picture : shape $shapeRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 8; if ($shapeRH['recVer'] == 0xF && $shapeRH['recInstance'] == 0x000 && $shapeRH['recType'] == 0xF004) { $sprmCPicLocation += $shapeRH['recLen']; } // picture : rgfb //@see : http://msdn.microsoft.com/en-us/library/dd950560%28v=office.12%29.aspx $fileBlockRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); while ($fileBlockRH['recType'] == 0xF007 || ($fileBlockRH['recType'] >= 0xF018 && $fileBlockRH['recType'] <= 0xF117)) { $sprmCPicLocation += 8; switch ($fileBlockRH['recType']) { // OfficeArtFBSE //@see : http://msdn.microsoft.com/en-us/library/dd944923%28v=office.12%29.aspx case 0xF007: // btWin32 $sprmCPicLocation += 1; // btMacOS $sprmCPicLocation += 1; // rgbUid $sprmCPicLocation += 16; // tag $sprmCPicLocation += 2; // size $sprmCPicLocation += 4; // cRef $sprmCPicLocation += 4; // foDelay $sprmCPicLocation += 4; // unused1 $sprmCPicLocation += 1; // cbName $cbName = self::getInt1d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 1; // unused2 $sprmCPicLocation += 1; // unused3 $sprmCPicLocation += 1; // nameData if ($cbName > 0) { //$nameData = ''; for ($inc = 0; $inc <= ($cbName / 2); $inc++) { //$chr = self::getInt2d($this->dataData, $sprmCPicLocation); $sprmCPicLocation += 2; //$nameData .= chr($chr); } } // embeddedBlip //@see : http://msdn.microsoft.com/en-us/library/dd910081%28v=office.12%29.aspx $embeddedBlipRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); switch ($embeddedBlipRH['recType']) { case self::OFFICEARTBLIPJPG: case self::OFFICEARTBLIPJPEG: if (!isset($oStylePrl->image)) { $oStylePrl->image = array(); } $sprmCPicLocation += 8; // embeddedBlip : rgbUid1 $sprmCPicLocation += 16; if ($embeddedBlipRH['recInstance'] == 0x6E1) { // rgbUid2 $sprmCPicLocation += 16; } // embeddedBlip : tag $sprmCPicLocation += 1; // embeddedBlip : BLIPFileData $oStylePrl->image['data'] = substr($this->dataData, $sprmCPicLocation, $embeddedBlipRH['recLen']); $oStylePrl->image['format'] = 'jpg'; // Image Size $iCropWidth = $picmidDxaGoal - ($picmidDxaCropLeft + $picmidDxaCropRight); $iCropHeight = $picmidDyaGoal - ($picmidDxaCropTop + $picmidDxaCropBottom); if (!$iCropWidth) { $iCropWidth = 1; } if (!$iCropHeight) { $iCropHeight = 1; } $oStylePrl->image['width'] = Drawing::twipsToPixels($iCropWidth * $picmidMx / 1000); $oStylePrl->image['height'] = Drawing::twipsToPixels($iCropHeight * $picmidMy / 1000); $sprmCPicLocation += $embeddedBlipRH['recLen']; break; case self::OFFICEARTBLIPPNG: break; default: // print_r(dechex($embeddedBlipRH['recType'])); } break; } $fileBlockRH = $this->loadRecordHeader($this->dataData, $sprmCPicLocation); } } } $oStylePrl->length = $pos - $posStart; return $oStylePrl; } /** * Read a record header * @param string $stream * @param int $pos * @return array */ private function loadRecordHeader($stream, $pos) { $rec = self::getInt2d($stream, $pos); $recType = self::getInt2d($stream, $pos + 2); $recLen = self::getInt4d($stream, $pos + 4); return array( 'recVer' => ($rec >> 0) & bindec('1111'), 'recInstance' => ($rec >> 4) & bindec('111111111111'), 'recType' => $recType, 'recLen' => $recLen, ); } private function generatePhpWord() { foreach ($this->arraySections as $itmSection) { $oSection = $this->phpWord->addSection(); $oSection->setStyle($itmSection->styleSection); $sHYPERLINK = ''; foreach ($this->arrayParagraphs as $itmParagraph) { $textPara = $itmParagraph; foreach ($this->arrayCharacters as $oCharacters) { $subText = substr($textPara, $oCharacters->pos_start, $oCharacters->pos_len); $subText = str_replace(chr(13), PHP_EOL, $subText); $arrayText = explode(PHP_EOL, $subText); if (end($arrayText) == '') { array_pop($arrayText); } if (reset($arrayText) == '') { array_shift($arrayText); } // Style Character $styleFont = array(); if (isset($oCharacters->style)) { if (isset($oCharacters->style->styleFont)) { $styleFont = $oCharacters->style->styleFont; } } foreach ($arrayText as $sText) { // HyperLink if (empty($sText) && !empty($sHYPERLINK)) { $arrHYPERLINK = explode('"', $sHYPERLINK); $oSection->addLink($arrHYPERLINK[1], null); // print_r('>addHyperLink<'.$sHYPERLINK.'>'.ord($sHYPERLINK[0]).EOL); $sHYPERLINK = ''; } // TextBreak if (empty($sText)) { $oSection->addTextBreak(); $sHYPERLINK = ''; // print_r('>addTextBreak<' . EOL); } if (!empty($sText)) { if (!empty($sHYPERLINK) && ord($sText[0]) > 20) { $sHYPERLINK .= $sText; } if (empty($sHYPERLINK)) { if (ord($sText[0]) > 20) { if (strpos(trim($sText), 'HYPERLINK "') === 0) { $sHYPERLINK = $sText; } else { $oSection->addText($sText, $styleFont); // print_r('>addText<'.$sText.'>'.ord($sText[0]).EOL); } } if (ord($sText[0]) == 1) { if (isset($oCharacters->style->image)) { $fileImage = tempnam(sys_get_temp_dir(), 'PHPWord_MsDoc') . '.' . $oCharacters->style->image['format']; file_put_contents($fileImage, $oCharacters->style->image['data']); $oSection->addImage($fileImage, array('width' => $oCharacters->style->image['width'], 'height' => $oCharacters->style->image['height'])); // print_r('>addImage<'.$fileImage.'>'.EOL); } } } } } } } } } /** * Read 8-bit unsigned integer * * @param string $data * @param int $pos * @return int */ public static function getInt1d($data, $pos) { return ord($data[$pos]); } /** * Read 16-bit unsigned integer * * @param string $data * @param int $pos * @return int */ public static function getInt2d($data, $pos) { return ord($data[$pos]) | (ord($data[$pos + 1]) << 8); } /** * Read 24-bit signed integer * * @param string $data * @param int $pos * @return int */ public static function getInt3d($data, $pos) { return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16); } /** * Read 32-bit signed integer * * @param string $data * @param int $pos * @return int */ public static function getInt4d($data, $pos) { // FIX: represent numbers correctly on 64-bit system // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334 // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems $or24 = ord($data[$pos + 3]); if ($or24 >= 128) { // negative number $ord24 = -abs((256 - $or24) << 24); } else { $ord24 = ($or24 & 127) << 24; } return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $ord24; } } phpword/src/PhpWord/Reader/ReaderInterface.php 0000664 00000002073 15177100670 0015347 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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 $filename * @return bool */ public function canRead($filename); /** * Loads PhpWord from file * * @param string $filename */ public function load($filename); } phpword/src/PhpWord/Reader/ODText.php 0000664 00000005422 15177100670 0013474 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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\XMLReader; /** * Reader for ODText * * @since 0.10.0 */ class ODText extends AbstractReader implements ReaderInterface { /** * Loads PhpWord from file * * @param string $docFile * @return \PhpOffice\PhpWord\PhpWord */ public function load($docFile) { $phpWord = new PhpWord(); $relationships = $this->readRelationships($docFile); $readerParts = array( 'content.xml' => 'Content', 'meta.xml' => 'Meta', ); foreach ($readerParts as $xmlFile => $partName) { $this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile); } return $phpWord; } /** * Read document part. * * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param array $relationships * @param string $partName * @param string $docFile * @param string $xmlFile */ private function readPart(PhpWord $phpWord, $relationships, $partName, $docFile, $xmlFile) { $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); } } /** * Read all relationship files * * @param string $docFile * @return array */ private function readRelationships($docFile) { $rels = array(); $xmlFile = 'META-INF/manifest.xml'; $xmlReader = new XMLReader(); $xmlReader->getDomFromZip($docFile, $xmlFile); $nodes = $xmlReader->getElements('manifest:file-entry'); foreach ($nodes as $node) { $type = $xmlReader->getAttribute('manifest:media-type', $node); $target = $xmlReader->getAttribute('manifest:full-path', $node); $rels[] = array('type' => $type, 'target' => $target); } return $rels; } } phpword/src/PhpWord/Writer/PDF/DomPDF.php 0000664 00000003666 15177100670 0014071 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PhpWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\PDF; use Dompdf\Dompdf as DompdfLib; use PhpOffice\PhpWord\Writer\WriterInterface; /** * DomPDF writer * * @see https://github.com/dompdf/dompdf * @since 0.10.0 */ class DomPDF extends AbstractRenderer implements WriterInterface { /** * Name of renderer include file * * @var string */ protected $includeFile = null; /** * Gets the implementation of external PDF library that should be used. * * @return Dompdf implementation */ protected function createExternalWriterInstance() { return new DompdfLib(); } /** * Save PhpWord to file. * * @param string $filename Name of the file to save as */ public function save($filename = null) { $fileHandle = parent::prepareForSave($filename); // PDF settings $paperSize = 'A4'; $orientation = 'portrait'; // Create PDF $pdf = $this->createExternalWriterInstance(); $pdf->setPaper(strtolower($paperSize), $orientation); $pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent())); $pdf->render(); // Write to file fwrite($fileHandle, $pdf->output()); parent::restoreStateAfterSave($fileHandle); } } phpword/src/PhpWord/Writer/PDF/TCPDF.php 0000664 00000005160 15177100670 0013647 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PhpWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\Writer\WriterInterface; /** * TCPDF writer * * @deprecated 0.13.0 Use `DomPDF` or `MPDF` instead. * * @see http://www.tcpdf.org/ * @since 0.11.0 */ class TCPDF extends AbstractRenderer implements WriterInterface { /** * Name of renderer include file * * @var string */ protected $includeFile = 'tcpdf.php'; /** * Gets the implementation of external PDF library that should be used. * * @param string $orientation Page orientation * @param string $unit Unit measure * @param string $paperSize Paper size * * @return \TCPDF implementation */ protected function createExternalWriterInstance($orientation, $unit, $paperSize) { return new \TCPDF($orientation, $unit, $paperSize); } /** * Save PhpWord to file. * * @param string $filename Name of the file to save as */ public function save($filename = null) { $fileHandle = parent::prepareForSave($filename); // PDF settings $paperSize = 'A4'; $orientation = 'P'; // Create PDF $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize); $pdf->setFontSubsetting(false); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); $pdf->SetFont($this->getFont()); $pdf->writeHTML($this->getContent()); // Write document properties $phpWord = $this->getPhpWord(); $docProps = $phpWord->getDocInfo(); $pdf->SetTitle($docProps->getTitle()); $pdf->SetAuthor($docProps->getCreator()); $pdf->SetSubject($docProps->getSubject()); $pdf->SetKeywords($docProps->getKeywords()); $pdf->SetCreator($docProps->getCreator()); // Write to file fwrite($fileHandle, $pdf->Output($filename, 'S')); parent::restoreStateAfterSave($fileHandle); } } phpword/src/PhpWord/Writer/PDF/MPDF.php 0000664 00000006067 15177100670 0013544 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PhpWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\WriterInterface; /** * MPDF writer * * @see http://www.mpdf1.com/ * @since 0.11.0 */ class MPDF extends AbstractRenderer implements WriterInterface { /** * Overridden to set the correct includefile, only needed for MPDF 5 * * @codeCoverageIgnore * @param PhpWord $phpWord */ public function __construct(PhpWord $phpWord) { if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) { // MPDF version 5.* needs this file to be included, later versions not $this->includeFile = 'mpdf.php'; } parent::__construct($phpWord); } /** * Gets the implementation of external PDF library that should be used. * * @return Mpdf implementation */ protected function createExternalWriterInstance() { $mPdfClass = $this->getMPdfClassName(); return new $mPdfClass(); } /** * Save PhpWord to file. * * @param string $filename Name of the file to save as */ public function save($filename = null) { $fileHandle = parent::prepareForSave($filename); // PDF settings $paperSize = strtoupper('A4'); $orientation = strtoupper('portrait'); // Create PDF $pdf = $this->createExternalWriterInstance(); $pdf->_setPageSize($paperSize, $orientation); $pdf->addPage($orientation); // Write document properties $phpWord = $this->getPhpWord(); $docProps = $phpWord->getDocInfo(); $pdf->setTitle($docProps->getTitle()); $pdf->setAuthor($docProps->getCreator()); $pdf->setSubject($docProps->getSubject()); $pdf->setKeywords($docProps->getKeywords()); $pdf->setCreator($docProps->getCreator()); $pdf->writeHTML($this->getContent()); // Write to file fwrite($fileHandle, $pdf->output($filename, 'S')); parent::restoreStateAfterSave($fileHandle); } /** * Return classname of MPDF to instantiate * * @codeCoverageIgnore * @return string */ private function getMPdfClassName() { if ($this->includeFile != null) { // MPDF version 5.* return '\mpdf'; } // MPDF version > 6.* return '\Mpdf\Mpdf'; } } phpword/src/PhpWord/Writer/PDF/AbstractRenderer.php 0000664 00000010736 15177100670 0016246 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PhpWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\HTML; /** * Abstract PDF renderer * * @since 0.10.0 */ abstract class AbstractRenderer extends HTML { /** * Name of renderer include file * * @var string */ protected $includeFile; /** * Temporary storage directory * * @var string */ protected $tempDir = ''; /** * Font * * @var string */ protected $font; /** * Paper size * * @var int */ protected $paperSize; /** * Orientation * * @var string */ protected $orientation; /** * Paper Sizes xRef List * * @var array */ protected static $paperSizes = array( 9 => 'A4', // (210 mm by 297 mm) ); /** * Create new instance * * @param PhpWord $phpWord PhpWord object * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) { parent::__construct($phpWord); if ($this->includeFile != null) { $includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile; if (file_exists($includeFile)) { /** @noinspection PhpIncludeInspection Dynamic includes */ require_once $includeFile; } else { // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. throw new Exception('Unable to load PDF Rendering library'); // @codeCoverageIgnoreEnd } } } /** * Get Font * * @return string */ public function getFont() { return $this->font; } /** * Set font. Examples: * 'arialunicid0-chinese-simplified' * 'arialunicid0-chinese-traditional' * 'arialunicid0-korean' * 'arialunicid0-japanese' * * @param string $fontName * @return self */ public function setFont($fontName) { $this->font = $fontName; return $this; } /** * Get Paper Size * * @return int */ public function getPaperSize() { return $this->paperSize; } /** * Set Paper Size * * @param int $value Paper size = PAPERSIZE_A4 * @return self */ public function setPaperSize($value = 9) { $this->paperSize = $value; return $this; } /** * Get Orientation * * @return string */ public function getOrientation() { return $this->orientation; } /** * Set Orientation * * @param string $value Page orientation ORIENTATION_DEFAULT * @return self */ public function setOrientation($value = 'default') { $this->orientation = $value; return $this; } /** * Save PhpWord to PDF file, pre-save * * @param string $filename Name of the file to save as * * @throws \PhpOffice\PhpWord\Exception\Exception * @return resource */ protected function prepareForSave($filename = null) { $fileHandle = fopen($filename, 'w'); // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. if ($fileHandle === false) { throw new Exception("Could not open file $filename for writing."); } // @codeCoverageIgnoreEnd $this->isPdf = true; return $fileHandle; } /** * Save PhpWord to PDF file, post-save * * @param resource $fileHandle * * @throws Exception */ protected function restoreStateAfterSave($fileHandle) { fclose($fileHandle); } } phpword/src/PhpWord/Writer/ODText/Element/Text.php 0000664 00000012432 15177100670 0016062 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Exception\Exception; /** * Text element writer * * @since 0.10.0 */ class Text extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Text) { return; } $fontStyle = $element->getFontStyle(); $paragraphStyle = $element->getParagraphStyle(); // @todo Commented for TextRun. Should really checkout this value // $fStyleIsObject = ($fontStyle instanceof Font) ? true : false; //$fStyleIsObject = false; //if ($fStyleIsObject) { // Don't never be the case, because I browse all sections for cleaning all styles not declared // throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object'); //} if (!$this->withoutP) { $xmlWriter->startElement('text:p'); // text:p } if ($element->getTrackChange() != null && $element->getTrackChange()->getChangeType() == TrackChange::DELETED) { $xmlWriter->startElement('text:change'); $xmlWriter->writeAttribute('text:change-id', $element->getTrackChange()->getElementId()); $xmlWriter->endElement(); } else { if (empty($fontStyle)) { if (empty($paragraphStyle)) { if (!$this->withoutP) { $xmlWriter->writeAttribute('text:style-name', 'Normal'); } } elseif (is_string($paragraphStyle)) { if (!$this->withoutP) { $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); } } $this->writeChangeInsertion(true, $element->getTrackChange()); $this->replaceTabs($element->getText(), $xmlWriter); $this->writeChangeInsertion(false, $element->getTrackChange()); } else { if (empty($paragraphStyle)) { if (!$this->withoutP) { $xmlWriter->writeAttribute('text:style-name', 'Normal'); } } elseif (is_string($paragraphStyle)) { if (!$this->withoutP) { $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); } } // text:span $xmlWriter->startElement('text:span'); if (is_string($fontStyle)) { $xmlWriter->writeAttribute('text:style-name', $fontStyle); } $this->writeChangeInsertion(true, $element->getTrackChange()); $this->replaceTabs($element->getText(), $xmlWriter); $this->writeChangeInsertion(false, $element->getTrackChange()); $xmlWriter->endElement(); } } if (!$this->withoutP) { $xmlWriter->endElement(); // text:p } } private function replacetabs($text, $xmlWriter) { if (preg_match('/^ +/', $text, $matches)) { $num = strlen($matches[0]); $xmlWriter->startElement('text:s'); $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num"); $xmlWriter->endElement(); $text = preg_replace('/^ +/', '', $text); } preg_match_all('/([\\s\\S]*?)(\\t| +| ?$)/', $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $this->writeText($match[1]); if ($match[2] === '') { break; } elseif ($match[2] === "\t") { $xmlWriter->writeElement('text:tab'); } elseif ($match[2] === ' ') { $xmlWriter->writeElement('text:s'); break; } else { $num = strlen($match[2]); $xmlWriter->startElement('text:s'); $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num"); $xmlWriter->endElement(); } } } private function writeChangeInsertion($start = true, TrackChange $trackChange = null) { if ($trackChange == null || $trackChange->getChangeType() != TrackChange::INSERTED) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('text:change-' . ($start ? 'start' : 'end')); $xmlWriter->writeAttribute('text:change-id', $trackChange->getElementId()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/ODText/Element/Table.php 0000664 00000006062 15177100670 0016167 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Table as TableElement; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Table element writer * * @since 0.10.0 */ class Table extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Table) { return; } $rows = $element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $xmlWriter->startElement('table:table'); $xmlWriter->writeAttribute('table:name', $element->getElementId()); $xmlWriter->writeAttribute('table:style', $element->getElementId()); // Write columns $this->writeColumns($xmlWriter, $element); // Write rows foreach ($rows as $row) { $this->writeRow($xmlWriter, $row); } $xmlWriter->endElement(); // table:table } } /** * Write column. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Table $element */ private function writeColumns(XMLWriter $xmlWriter, TableElement $element) { $colCount = $element->countColumns(); for ($i = 0; $i < $colCount; $i++) { $xmlWriter->startElement('table:table-column'); $xmlWriter->writeAttribute('table:style-name', $element->getElementId() . '.' . $i); $xmlWriter->endElement(); } } /** * Write row. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Row $row */ private function writeRow(XMLWriter $xmlWriter, RowElement $row) { $xmlWriter->startElement('table:table-row'); /** @var $row \PhpOffice\PhpWord\Element\Row Type hint */ foreach ($row->getCells() as $cell) { $xmlWriter->startElement('table:table-cell'); $xmlWriter->writeAttribute('office:value-type', 'string'); $containerWriter = new Container($xmlWriter, $cell); $containerWriter->write(); $xmlWriter->endElement(); // table:table-cell } $xmlWriter->endElement(); // table:table-row } } phpword/src/PhpWord/Writer/ODText/Element/PageBreak.php 0000664 00000002056 15177100670 0016760 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * PageBreak element writer */ class PageBreak extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('text:p'); $xmlWriter->writeAttribute('text:style-name', 'PB'); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/ODText/Element/Container.php 0000664 00000002171 15177100670 0017057 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Writer\Word2007\Element\Container as Word2007Container; /** * Container element writer (section, textrun, header, footnote, cell, etc.) * * @since 0.11.0 */ class Container extends Word2007Container { /** * Namespace; Can't use __NAMESPACE__ in inherited class (ODText) * * @var string */ protected $namespace = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element'; } phpword/src/PhpWord/Writer/ODText/Element/Title.php 0000664 00000005023 15177100670 0016215 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * Title element writer * * @since 0.11.0 */ class Title extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Title) { return; } $xmlWriter->startElement('text:h'); $hdname = 'HD'; $sect = $element->getParent(); if ($sect instanceof \PhpOffice\PhpWord\Element\Section) { if (self::compareToFirstElement($element, $sect->getElements())) { $hdname = 'HE'; } } $depth = $element->getDepth(); $xmlWriter->writeAttribute('text:style-name', "$hdname$depth"); $xmlWriter->writeAttribute('text:outline-level', $depth); $xmlWriter->startElement('text:span'); if ($depth > 0) { $xmlWriter->writeAttribute('text:style-name', 'Heading_' . $depth); } else { $xmlWriter->writeAttribute('text:style-name', 'Title'); } $text = $element->getText(); if (is_string($text)) { $this->writeText($text); } elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { $containerWriter = new Container($xmlWriter, $text); $containerWriter->write(); } $xmlWriter->endElement(); // text:span $xmlWriter->endElement(); // text:h } /** * Test if element is same as first element in array * * @param \PhpOffice\PhpWord\Element\AbstractElement $elem * * @param \PhpOffice\PhpWord\Element\AbstractElement[] $elemarray * * @return bool */ private static function compareToFirstElement($elem, $elemarray) { return $elem === $elemarray[0]; } } phpword/src/PhpWord/Writer/ODText/Element/AbstractElement.php 0000664 00000001656 15177100670 0020221 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement as Word2007AbstractElement; /** * Abstract element writer * * @since 0.11.0 */ abstract class AbstractElement extends Word2007AbstractElement { } phpword/src/PhpWord/Writer/ODText/Element/TextBreak.php 0000664 00000002110 15177100670 0017017 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * TextBreak element writer * * @since 0.10.0 */ class TextBreak extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('text:p'); $xmlWriter->writeAttribute('text:style-name', 'Standard'); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/ODText/Element/TextRun.php 0000664 00000002551 15177100670 0016550 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * TextRun element writer * * @since 0.10.0 */ class TextRun extends Text { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); $xmlWriter->startElement('text:p'); /** @scrutinizer ignore-call */ $pStyle = $element->getParagraphStyle(); if (!is_string($pStyle)) { $pStyle = 'Normal'; } $xmlWriter->writeAttribute('text:style-name', $pStyle); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/ODText/Element/Image.php 0000664 00000004537 15177100670 0016167 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Shared\Converter; /** * Image element writer * * @since 0.10.0 */ class Image extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Image) { return; } $mediaIndex = $element->getMediaIndex(); $target = 'Pictures/' . $element->getTarget(); $style = $element->getStyle(); $width = Converter::pixelToCm($style->getWidth()); $height = Converter::pixelToCm($style->getHeight()); $xmlWriter->startElement('text:p'); $xmlWriter->writeAttribute('text:style-name', 'IM' . $mediaIndex); $xmlWriter->startElement('draw:frame'); $xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex); $xmlWriter->writeAttribute('draw:name', $element->getElementId()); $xmlWriter->writeAttribute('text:anchor-type', 'as-char'); $xmlWriter->writeAttribute('svg:width', $width . 'cm'); $xmlWriter->writeAttribute('svg:height', $height . 'cm'); $xmlWriter->writeAttribute('draw:z-index', $mediaIndex); $xmlWriter->startElement('draw:image'); $xmlWriter->writeAttribute('xlink:href', $target); $xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:show', 'embed'); $xmlWriter->writeAttribute('xlink:actuate', 'onLoad'); $xmlWriter->endElement(); // draw:image $xmlWriter->endElement(); // draw:frame $xmlWriter->endElement(); // text:p } } phpword/src/PhpWord/Writer/ODText/Element/Link.php 0000664 00000003051 15177100670 0016030 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * Text element writer * * @since 0.10.0 */ class Link extends AbstractElement { /** * Write element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Link) { return; } if (!$this->withoutP) { $xmlWriter->startElement('text:p'); // text:p } $xmlWriter->startElement('text:a'); $xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:href', ($element->isInternal() ? '#' : '') . $element->getSource()); $this->writeText($element->getText()); $xmlWriter->endElement(); // text:a if (!$this->withoutP) { $xmlWriter->endElement(); // text:p } } } phpword/src/PhpWord/Writer/ODText/Element/Field.php 0000664 00000005035 15177100670 0016162 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ // Not fully implemented // - supports only PAGE and NUMPAGES // - supports only default formats and options // - supports style only if specified by name // - spaces before and after field may be dropped namespace PhpOffice\PhpWord\Writer\ODText\Element; /** * Field element writer * * @since 0.11.0 */ class Field extends Text { /** * Write field element. */ public function write() { $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Field) { return; } $type = strtolower($element->getType()); switch ($type) { case 'date': case 'page': case 'numpages': $this->writeDefault($element, $type); break; } } private function writeDefault(\PhpOffice\PhpWord\Element\Field $element, $type) { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('text:span'); if (method_exists($element, 'getFontStyle')) { $fstyle = $element->getFontStyle(); if (is_string($fstyle)) { $xmlWriter->writeAttribute('text:style-name', $fstyle); } } switch ($type) { case 'date': $xmlWriter->startElement('text:date'); $xmlWriter->writeAttribute('text:fixed', 'false'); $xmlWriter->endElement(); break; case 'page': $xmlWriter->startElement('text:page-number'); $xmlWriter->writeAttribute('text:fixed', 'false'); $xmlWriter->endElement(); break; case 'numpages': $xmlWriter->startElement('text:page-count'); $xmlWriter->endElement(); break; } $xmlWriter->endElement(); // text:span } } phpword/src/PhpWord/Writer/ODText/Style/Table.php 0000664 00000004725 15177100670 0015702 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; /** * Table style writer * * @since 0.11.0 */ class Table extends AbstractStyle { /** * Write style. */ public function write() { /** @var \PhpOffice\PhpWord\Style\Table $style Type hint */ $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Table) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('style:style'); $xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:family', 'table'); $xmlWriter->startElement('style:table-properties'); //$xmlWriter->writeAttribute('style:width', 'table'); $xmlWriter->writeAttribute('style:rel-width', 100); $xmlWriter->writeAttribute('table:align', 'center'); $xmlWriter->writeAttributeIf($style->isBidiVisual(), 'style:writing-mode', 'rl-tb'); $xmlWriter->endElement(); // style:table-properties $xmlWriter->endElement(); // style:style $cellWidths = $style->getColumnWidths(); $countCellWidths = $cellWidths === null ? 0 : count($cellWidths); for ($i = 0; $i < $countCellWidths; $i++) { $width = $cellWidths[$i]; $xmlWriter->startElement('style:style'); $xmlWriter->writeAttribute('style:name', $style->getStyleName() . '.' . $i); $xmlWriter->writeAttribute('style:family', 'table-column'); $xmlWriter->startElement('style:table-column-properties'); $xmlWriter->writeAttribute('style:column-width', number_format($width * 0.0017638889, 2, '.', '') . 'cm'); $xmlWriter->endElement(); // style:table-column-properties $xmlWriter->endElement(); // style:style } } } phpword/src/PhpWord/Writer/ODText/Style/AbstractStyle.php 0000664 00000001627 15177100670 0017435 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; use PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle as Word2007AbstractStyle; /** * Style writer * * @since 0.10.0 */ abstract class AbstractStyle extends Word2007AbstractStyle { } phpword/src/PhpWord/Writer/ODText/Style/Paragraph.php 0000664 00000014225 15177100670 0016554 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; use PhpOffice\PhpWord\Shared\Converter; /** * Font style writer * * @since 0.10.0 */ class Paragraph extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { return; } $xmlWriter = $this->getXmlWriter(); $marginTop = $style->getSpaceBefore(); $marginBottom = $style->getSpaceAfter(); $xmlWriter->startElement('style:style'); $styleName = $style->getStyleName(); $styleAuto = false; $mpm = ''; $psm = ''; $pagestart = -1; $breakafter = $breakbefore = $breakauto = false; if ($style->isAuto()) { if (substr($styleName, 0, 2) === 'PB') { $styleAuto = true; $breakafter = true; } elseif (substr($styleName, 0, 2) === 'SB') { $styleAuto = true; $mpm = 'Standard' . substr($styleName, 2); $psn = $style->getNumLevel(); $pagestart = $psn; } elseif (substr($styleName, 0, 2) === 'HD') { $styleAuto = true; $psm = 'Heading_' . substr($styleName, 2); $stylep = \PhpOffice\PhpWord\Style::getStyle($psm); if ($stylep instanceof \PhpOffice\PhpWord\Style\Font) { if (method_exists($stylep, 'getParagraph')) { $stylep = $stylep->getParagraph(); } } if ($stylep instanceof \PhpOffice\PhpWord\Style\Paragraph) { if ($stylep->hasPageBreakBefore()) { $breakbefore = true; } } } elseif (substr($styleName, 0, 2) === 'HE') { $styleAuto = true; $psm = 'Heading_' . substr($styleName, 2); $breakauto = true; } else { $styleAuto = true; $psm = 'Normal'; if (preg_match('/^P\\d+_(\\w+)$/', $styleName, $matches)) { $psm = $matches[1]; } } } $xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:family', 'paragraph'); if ($styleAuto) { $xmlWriter->writeAttributeIf($psm !== '', 'style:parent-style-name', $psm); $xmlWriter->writeAttributeIf($mpm !== '', 'style:master-page-name', $mpm); } $xmlWriter->startElement('style:paragraph-properties'); if ($styleAuto) { if ($breakafter) { $xmlWriter->writeAttribute('fo:break-after', 'page'); $xmlWriter->writeAttribute('fo:margin-top', '0cm'); $xmlWriter->writeAttribute('fo:margin-bottom', '0cm'); } elseif ($breakbefore) { $xmlWriter->writeAttribute('fo:break-before', 'page'); } elseif ($breakauto) { $xmlWriter->writeAttribute('fo:break-before', 'auto'); } if ($pagestart > 0) { $xmlWriter->writeAttribute('style:page-number', $pagestart); } } if (!$breakafter && !$breakbefore && !$breakauto) { $twipToPoint = Converter::INCH_TO_TWIP / Converter::INCH_TO_POINT; // 20 $xmlWriter->writeAttributeIf($marginTop !== null, 'fo:margin-top', ($marginTop / $twipToPoint) . 'pt'); $xmlWriter->writeAttributeIf($marginBottom !== null, 'fo:margin-bottom', ($marginBottom / $twipToPoint) . 'pt'); } $temp = $style->getAlignment(); $xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp); $temp = $style->getLineHeight(); $xmlWriter->writeAttributeIf($temp !== null, 'fo:line-height', ((string) ($temp * 100) . '%')); $xmlWriter->writeAttributeIf($style->hasPageBreakBefore() === true, 'fo:break-before', 'page'); $tabs = $style->getTabs(); if ($tabs !== null && count($tabs) > 0) { $xmlWriter->startElement('style:tab-stops'); foreach ($tabs as $tab) { $xmlWriter->startElement('style:tab-stop'); $xmlWriter->writeAttribute('style:type', $tab->getType()); $xmlWriter->writeAttribute('style:position', (string) ($tab->getPosition() / Converter::INCH_TO_TWIP) . 'in'); $xmlWriter->endElement(); } $xmlWriter->endElement(); } //Right to left $xmlWriter->writeAttributeIf($style->isBidi(), 'style:writing-mode', 'rl-tb'); //Indentation $indent = $style->getIndentation(); //if ($indent instanceof \PhpOffice\PhpWord\Style\Indentation) { if (!empty($indent)) { $marg = $indent->getLeft(); $xmlWriter->writeAttributeIf($marg !== null, 'fo:margin-left', (string) ($marg / Converter::INCH_TO_TWIP) . 'in'); $marg = $indent->getRight(); $xmlWriter->writeAttributeIf($marg !== null, 'fo:margin-right', (string) ($marg / Converter::INCH_TO_TWIP) . 'in'); } $xmlWriter->endElement(); //style:paragraph-properties if ($styleAuto && substr($styleName, 0, 2) === 'SB') { $xmlWriter->startElement('style:text-properties'); $xmlWriter->writeAttribute('text:display', 'none'); $xmlWriter->endElement(); } $xmlWriter->endElement(); //style:style } } phpword/src/PhpWord/Writer/ODText/Style/Font.php 0000664 00000010716 15177100670 0015556 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; /** * Font style writer * * @since 0.10.0 */ class Font extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { return; } $xmlWriter = $this->getXmlWriter(); $stylep = (method_exists($style, 'getParagraph')) ? $style->getParagraph() : null; if ($stylep instanceof \PhpOffice\PhpWord\Style\Paragraph) { $temp1 = clone $stylep; $temp1->setStyleName($style->getStyleName()); $temp2 = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $temp1); $temp2->write(); } $xmlWriter->startElement('style:style'); $xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:family', 'text'); $xmlWriter->startElement('style:text-properties'); // Name $font = $style->getName(); $xmlWriter->writeAttributeIf($font != '', 'style:font-name', $font); $xmlWriter->writeAttributeIf($font != '', 'style:font-name-complex', $font); $size = $style->getSize(); // Size $xmlWriter->writeAttributeIf(is_numeric($size), 'fo:font-size', $size . 'pt'); $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-asian', $size . 'pt'); $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-complex', $size . 'pt'); // Color $color = $style->getColor(); $xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . \PhpOffice\PhpWord\Shared\Converter::stringToRgb($color)); // Bold & italic $xmlWriter->writeAttributeIf($style->isBold(), 'fo:font-weight', 'bold'); $xmlWriter->writeAttributeIf($style->isBold(), 'style:font-weight-asian', 'bold'); $xmlWriter->writeAttributeIf($style->isItalic(), 'fo:font-style', 'italic'); $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-asian', 'italic'); $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-complex', 'italic'); // Underline // @todo Various mode of underline $underline = $style->getUnderline(); $xmlWriter->writeAttributeIf($underline != 'none', 'style:text-underline-style', 'solid'); // Strikethrough, double strikethrough $xmlWriter->writeAttributeIf($style->isStrikethrough(), 'style:text-line-through-type', 'single'); $xmlWriter->writeAttributeIf($style->isDoubleStrikethrough(), 'style:text-line-through-type', 'double'); // Small caps, all caps $xmlWriter->writeAttributeIf($style->isSmallCaps(), 'fo:font-variant', 'small-caps'); $xmlWriter->writeAttributeIf($style->isAllCaps(), 'fo:text-transform', 'uppercase'); //Hidden text $xmlWriter->writeAttributeIf($style->isHidden(), 'text:display', 'none'); // Superscript/subscript $xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super'); $xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub'); if ($style->isNoProof()) { $xmlWriter->writeAttribute('fo:language', 'zxx'); $xmlWriter->writeAttribute('style:language-asian', 'zxx'); $xmlWriter->writeAttribute('style:language-complex', 'zxx'); $xmlWriter->writeAttribute('fo:country', 'none'); $xmlWriter->writeAttribute('style:country-asian', 'none'); $xmlWriter->writeAttribute('style:country-complex', 'none'); } // @todo Foreground-Color // @todo Background color $xmlWriter->endElement(); // style:text-properties $xmlWriter->endElement(); // style:style } } phpword/src/PhpWord/Writer/ODText/Style/Image.php 0000664 00000003250 15177100670 0015665 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; /** * Image style writer * * @since 0.11.0 */ class Image extends AbstractStyle { /** * Write style. */ public function write() { /** @var \PhpOffice\PhpWord\Style\Image $style Type hint */ $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('style:style'); $xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:family', 'graphic'); $xmlWriter->writeAttribute('style:parent-style-name', 'Graphics'); $xmlWriter->startElement('style:graphic-properties'); $xmlWriter->writeAttribute('style:vertical-pos', 'top'); $xmlWriter->writeAttribute('style:vertical-rel', 'baseline'); $xmlWriter->endElement(); // style:graphic-properties $xmlWriter->endElement(); // style:style } } phpword/src/PhpWord/Writer/ODText/Style/Section.php 0000664 00000003223 15177100670 0016247 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Style; /** * Section style writer * * @since 0.11.0 */ class Section extends AbstractStyle { /** * Write style. */ public function write() { /** @var \PhpOffice\PhpWord\Style\Section $style Type hint */ $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Section) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('style:style'); $xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:family', 'section'); $xmlWriter->startElement('style:section-properties'); $xmlWriter->startElement('style:columns'); $xmlWriter->writeAttribute('fo:column-count', $style->getColsNum()); $xmlWriter->endElement(); // style:columns $xmlWriter->endElement(); // style:section-properties $xmlWriter->endElement(); // style:style } } phpword/src/PhpWord/Writer/ODText/Part/Mimetype.php 0000664 00000001720 15177100670 0016242 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; /** * ODText mimetype part writer: mimetype */ class Mimetype extends AbstractPart { /** * Write part * * @return string */ public function write() { return 'application/vnd.oasis.opendocument.text'; } } phpword/src/PhpWord/Writer/ODText/Part/AbstractPart.php 0000664 00000012302 15177100670 0017041 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart; /** * ODText writer part abstract */ abstract class AbstractPart extends Word2007AbstractPart { /** * @var string Date format */ protected $dateFormat = 'Y-m-d\TH:i:s.000'; /** * Write common root attributes. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ protected function writeCommonRootAttributes(XMLWriter $xmlWriter) { $xmlWriter->writeAttribute('office:version', '1.2'); $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); } /** * Write font faces declaration. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ protected function writeFontFaces(XMLWriter $xmlWriter) { $xmlWriter->startElement('office:font-face-decls'); $fontTable = array(); $styles = Style::getStyles(); $numFonts = 0; if (count($styles) > 0) { foreach ($styles as $style) { // Font if ($style instanceof Font) { $numFonts++; $name = $style->getName(); if (!in_array($name, $fontTable)) { $fontTable[] = $name; // style:font-face $xmlWriter->startElement('style:font-face'); $xmlWriter->writeAttribute('style:name', $name); $xmlWriter->writeAttribute('svg:font-family', $name); $xmlWriter->endElement(); } } } } if (!in_array(Settings::getDefaultFontName(), $fontTable)) { $xmlWriter->startElement('style:font-face'); $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName()); $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName()); $xmlWriter->endElement(); } $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/ODText/Part/Manifest.php 0000664 00000004761 15177100670 0016227 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Media; /** * ODText manifest part writer: META-INF/manifest.xml */ class Manifest extends AbstractPart { /** * Write part * * @return string */ public function write() { $parts = array('content.xml', 'meta.xml', 'styles.xml'); $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('manifest:manifest'); $xmlWriter->writeAttribute('manifest:version', '1.2'); $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); $xmlWriter->startElement('manifest:file-entry'); $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text'); $xmlWriter->writeAttribute('manifest:full-path', '/'); $xmlWriter->writeAttribute('manifest:version', '1.2'); $xmlWriter->endElement(); // Parts foreach ($parts as $part) { $xmlWriter->startElement('manifest:file-entry'); $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); $xmlWriter->writeAttribute('manifest:full-path', $part); $xmlWriter->endElement(); } // Media files $media = Media::getElements('section'); foreach ($media as $medium) { if ($medium['type'] == 'image') { $xmlWriter->startElement('manifest:file-entry'); $xmlWriter->writeAttribute('manifest:media-type', $medium['imageType']); $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . $medium['target']); $xmlWriter->endElement(); } } $xmlWriter->endElement(); // manifest:manifest return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/ODText/Part/Meta.php 0000664 00000010147 15177100670 0015342 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Shared\XMLWriter; /** * ODText meta part writer: meta.xml * * @since 0.11.0 */ class Meta extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $docProps = $phpWord->getDocInfo(); $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('office:document-meta'); $xmlWriter->writeAttribute('office:version', '1.2'); $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $xmlWriter->startElement('office:meta'); // Core properties $xmlWriter->writeElement('dc:title', $docProps->getTitle()); $xmlWriter->writeElement('dc:subject', $docProps->getSubject()); $xmlWriter->writeElement('dc:description', $docProps->getDescription()); $xmlWriter->writeElement('dc:creator', $docProps->getLastModifiedBy()); $xmlWriter->writeElement('dc:date', gmdate($this->dateFormat, $docProps->getModified())); // Extended properties $xmlWriter->writeElement('meta:generator', 'PHPWord'); $xmlWriter->writeElement('meta:initial-creator', $docProps->getCreator()); $xmlWriter->writeElement('meta:creation-date', gmdate($this->dateFormat, $docProps->getCreated())); $xmlWriter->writeElement('meta:keyword', $docProps->getKeywords()); // Category, company, and manager are put in meta namespace $properties = array('Category', 'Company', 'Manager'); foreach ($properties as $property) { $method = "get{$property}"; if ($docProps->$method() !== null) { $this->writeCustomProperty($xmlWriter, $property, $docProps->$method()); } } // Other custom properties // @todo Check type. Currently all assumed as string foreach ($docProps->getCustomProperties() as $property) { $value = $docProps->getCustomPropertyValue($property); $this->writeCustomProperty($xmlWriter, $property, $value); } $xmlWriter->endElement(); // office:meta $xmlWriter->endElement(); // office:document-meta return $xmlWriter->getData(); } /** * Write individual property * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $property * @param string $value * * @todo Handle other `$type`: double|date|dateTime|duration|boolean (4th arguments) */ private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value) { $xmlWriter->startElement('meta:user-defined'); $xmlWriter->writeAttribute('meta:name', $property); // if ($type !== null) { // $xmlWriter->writeAttribute('meta:value-type', $type); // } $this->writeText($value); $xmlWriter->endElement(); // meta:user-defined } } phpword/src/PhpWord/Writer/ODText/Part/Content.php 0000664 00000040230 15177100670 0016062 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Element\AbstractContainer; use PhpOffice\PhpWord\Element\Field; use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\Element\Text; use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Writer\ODText\Element\Container; use PhpOffice\PhpWord\Writer\ODText\Style\Paragraph as ParagraphStyleWriter; /** * ODText content part writer: content.xml */ class Content extends AbstractPart { /** * Auto style collection * * Collect inline style information from section, image, and table elements * * @todo Merge font and paragraph styles * @var array */ private $autoStyles = array('Section' => array(), 'Image' => array(), 'Table' => array()); private $imageParagraphStyles = array(); /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $phpWord = $this->getParentWriter()->getPhpWord(); $this->getAutoStyles($phpWord); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('office:document-content'); $this->writeCommonRootAttributes($xmlWriter); $xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); $xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); $xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); // Font declarations and automatic styles $this->writeFontFaces($xmlWriter); // office:font-face-decls $this->writeAutoStyles($xmlWriter); // office:automatic-styles // Body $xmlWriter->startElement('office:body'); $xmlWriter->startElement('office:text'); // Tracked changes declarations $trackedChanges = array(); $sections = $phpWord->getSections(); foreach ($sections as $section) { $this->collectTrackedChanges($section, $trackedChanges); } $xmlWriter->startElement('text:tracked-changes'); foreach ($trackedChanges as $trackedElement) { $trackedChange = $trackedElement->getTrackChange(); $xmlWriter->startElement('text:changed-region'); $trackedChange->setElementId(); $xmlWriter->writeAttribute('text:id', $trackedChange->getElementId()); if (($trackedChange->getChangeType() == TrackChange::INSERTED)) { $xmlWriter->startElement('text:insertion'); } elseif ($trackedChange->getChangeType() == TrackChange::DELETED) { $xmlWriter->startElement('text:deletion'); } $xmlWriter->startElement('office:change-info'); $xmlWriter->writeElement('dc:creator', $trackedChange->getAuthor()); if ($trackedChange->getDate() != null) { $xmlWriter->writeElement('dc:date', $trackedChange->getDate()->format('Y-m-d\TH:i:s\Z')); } $xmlWriter->endElement(); // office:change-info if ($trackedChange->getChangeType() == TrackChange::DELETED) { $xmlWriter->writeElement('text:p', $trackedElement->getText()); } $xmlWriter->endElement(); // text:insertion|text:deletion $xmlWriter->endElement(); // text:changed-region } $xmlWriter->endElement(); // text:tracked-changes // Sequence declarations $sequences = array('Illustration', 'Table', 'Text', 'Drawing'); $xmlWriter->startElement('text:sequence-decls'); foreach ($sequences as $sequence) { $xmlWriter->startElement('text:sequence-decl'); $xmlWriter->writeAttribute('text:display-outline-level', 0); $xmlWriter->writeAttribute('text:name', $sequence); $xmlWriter->endElement(); } $xmlWriter->endElement(); // text:sequence-decl // Sections $sections = $phpWord->getSections(); foreach ($sections as $section) { $name = 'Section' . $section->getSectionId(); $xmlWriter->startElement('text:section'); $xmlWriter->writeAttribute('text:name', $name); $xmlWriter->writeAttribute('text:style-name', $name); $xmlWriter->startElement('text:p'); $xmlWriter->writeAttribute('text:style-name', 'SB' . $section->getSectionId()); $xmlWriter->endElement(); $containerWriter = new Container($xmlWriter, $section); $containerWriter->write(); $xmlWriter->endElement(); // text:section } $xmlWriter->endElement(); // office:text $xmlWriter->endElement(); // office:body $xmlWriter->endElement(); // office:document-content return $xmlWriter->getData(); } /** * Write automatic styles other than fonts and paragraphs. * * @since 0.11.0 * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeAutoStyles(XMLWriter $xmlWriter) { $xmlWriter->startElement('office:automatic-styles'); $this->writeTextStyles($xmlWriter); foreach ($this->autoStyles as $element => $styles) { $writerClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $element; foreach ($styles as $style) { /** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */ $styleWriter = new $writerClass($xmlWriter, $style); $styleWriter->write(); } } $xmlWriter->endElement(); // office:automatic-styles } /** * Write automatic styles. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeTextStyles(XMLWriter $xmlWriter) { $styles = Style::getStyles(); $paragraphStyleCount = 0; $style = new Paragraph(); $style->setStyleName('PB'); $style->setAuto(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $style); $styleWriter->write(); $sects = $this->getParentWriter()->getPhpWord()->getSections(); $countsects = count($sects); for ($i = 0; $i < $countsects; ++$i) { $iplus1 = $i + 1; $style = new Paragraph(); $style->setStyleName("SB$iplus1"); $style->setAuto(); $pnstart = $sects[$i]->getStyle()->getPageNumberingStart(); $style->setNumLevel($pnstart); $styleWriter = new ParagraphStyleWriter($xmlWriter, $style); $styleWriter->write(); } foreach ($styles as $style) { $sty = $style->getStyleName(); if (substr($sty, 0, 8) === 'Heading_') { $style = new Paragraph(); $style->setStyleName('HD' . substr($sty, 8)); $style->setAuto(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $style); $styleWriter->write(); $style = new Paragraph(); $style->setStyleName('HE' . substr($sty, 8)); $style->setAuto(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $style); $styleWriter->write(); } } foreach ($styles as $style) { if ($style->isAuto() === true) { $styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style)); if (class_exists($styleClass)) { /** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */ $styleWriter = new $styleClass($xmlWriter, $style); $styleWriter->write(); } if ($style instanceof Paragraph) { $paragraphStyleCount++; } } } foreach ($this->imageParagraphStyles as $style) { $styleWriter = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $style); $styleWriter->write(); } } /** * Get automatic styles. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ private function getAutoStyles(PhpWord $phpWord) { $sections = $phpWord->getSections(); $paragraphStyleCount = 0; $fontStyleCount = 0; foreach ($sections as $section) { $style = $section->getStyle(); $style->setStyleName("Section{$section->getSectionId()}"); $this->autoStyles['Section'][] = $style; $this->getContainerStyle($section, $paragraphStyleCount, $fontStyleCount); } } /** * Get all styles of each elements in container recursively * * Table style can be null or string of the style name * * @param \PhpOffice\PhpWord\Element\AbstractContainer $container * @param int $paragraphStyleCount * @param int $fontStyleCount * @todo Simplify the logic */ private function getContainerStyle($container, &$paragraphStyleCount, &$fontStyleCount) { $elements = $container->getElements(); foreach ($elements as $element) { if ($element instanceof TextRun) { $this->getElementStyleTextRun($element, $paragraphStyleCount); $this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount); } elseif ($element instanceof Text) { $this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount); } elseif ($element instanceof Field) { $this->getElementStyleField($element, $fontStyleCount); } elseif ($element instanceof Image) { $style = $element->getStyle(); $style->setStyleName('fr' . $element->getMediaIndex()); $this->autoStyles['Image'][] = $style; $sty = new \PhpOffice\PhpWord\Style\Paragraph(); $sty->setStyleName('IM' . $element->getMediaIndex()); $sty->setAuto(); $sty->setAlignment($style->getAlignment()); $this->imageParagraphStyles[] = $sty; } elseif ($element instanceof Table) { /** @var \PhpOffice\PhpWord\Style\Table $style */ $style = $element->getStyle(); if (is_string($style)) { $style = Style::getStyle($style); } if ($style === null) { $style = new TableStyle(); } $style->setStyleName($element->getElementId()); $style->setColumnWidths($element->findFirstDefinedCellWidths()); $this->autoStyles['Table'][] = $style; } } } /** * Get style of individual element * * @param \PhpOffice\PhpWord\Element\Text $element * @param int $paragraphStyleCount * @param int $fontStyleCount */ private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount) { $fontStyle = $element->getFontStyle(); $paragraphStyle = $element->getParagraphStyle(); $phpWord = $this->getParentWriter()->getPhpWord(); if ($fontStyle instanceof Font) { // Font $name = $fontStyle->getStyleName(); if (!$name) { $fontStyleCount++; $style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null); $style->setAuto(); $style->setParagraph(null); $element->setFontStyle("T{$fontStyleCount}"); } else { $element->setFontStyle($name); } } if ($paragraphStyle instanceof Paragraph) { // Paragraph $name = $paragraphStyle->getStyleName(); if (!$name) { $paragraphStyleCount++; $style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle); $style->setAuto(); $element->setParagraphStyle("P{$paragraphStyleCount}"); } else { $element->setParagraphStyle($name); } } elseif ($paragraphStyle) { $paragraphStyleCount++; $parstylename = "P$paragraphStyleCount" . "_$paragraphStyle"; $style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle); $style->setAuto(); $element->setParagraphStyle($parstylename); } } /** * Get font style of individual field element * * @param \PhpOffice\PhpWord\Element\Field $element * @param int $paragraphStyleCount * @param int $fontStyleCount */ private function getElementStyleField($element, &$fontStyleCount) { $fontStyle = $element->getFontStyle(); $phpWord = $this->getParentWriter()->getPhpWord(); if ($fontStyle instanceof Font) { $name = $fontStyle->getStyleName(); if (!$name) { $fontStyleCount++; $style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null); $style->setAuto(); $style->setParagraph(null); $element->setFontStyle("T{$fontStyleCount}"); } else { $element->setFontStyle($name); } } } /** * Get style of individual element * * @param \PhpOffice\PhpWord\Element\TextRun $element * @param int $paragraphStyleCount */ private function getElementStyleTextRun($element, &$paragraphStyleCount) { $paragraphStyle = $element->getParagraphStyle(); $phpWord = $this->getParentWriter()->getPhpWord(); if ($paragraphStyle instanceof Paragraph) { // Paragraph $name = $paragraphStyle->getStyleName(); if (!$name) { $paragraphStyleCount++; $style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle); $style->setAuto(); $element->setParagraphStyle("P{$paragraphStyleCount}"); } else { $element->setParagraphStyle($name); } } elseif ($paragraphStyle) { $paragraphStyleCount++; $parstylename = "P$paragraphStyleCount" . "_$paragraphStyle"; $style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle); $style->setAuto(); $element->setParagraphStyle($parstylename); } } /** * Finds all tracked changes * * @param AbstractContainer $container * @param \PhpOffice\PhpWord\Element\AbstractElement[] $trackedChanges */ private function collectTrackedChanges(AbstractContainer $container, &$trackedChanges = array()) { $elements = $container->getElements(); foreach ($elements as $element) { if ($element->getTrackChange() != null) { $trackedChanges[] = $element; } if (is_callable(array($element, 'getElements'))) { $this->collectTrackedChanges($element, $trackedChanges); } } } } phpword/src/PhpWord/Writer/ODText/Part/Styles.php 0000664 00000031554 15177100670 0015744 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\Converter; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; /** * ODText styles part writer: styles.xml */ class Styles extends AbstractPart { /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); // XML header $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('office:document-styles'); $this->writeCommonRootAttributes($xmlWriter); // Font declarations $this->writeFontFaces($xmlWriter); // Office styles $xmlWriter->startElement('office:styles'); $this->writeDefault($xmlWriter); $this->writeNamed($xmlWriter); $xmlWriter->endElement(); // Automatic styles $xmlWriter->startElement('office:automatic-styles'); $this->writePageLayout($xmlWriter); $xmlWriter->endElement(); // office:automatic-styles // Master style $this->writeMaster($xmlWriter); $xmlWriter->endElement(); // office:document-styles return $xmlWriter->getData(); } /** * Write default styles. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeDefault(XMLWriter $xmlWriter) { $xmlWriter->startElement('style:default-style'); $xmlWriter->writeAttribute('style:family', 'paragraph'); // Paragraph $xmlWriter->startElement('style:paragraph-properties'); $xmlWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit'); $xmlWriter->writeAttribute('style:text-autospace', 'ideograph-alpha'); $xmlWriter->writeAttribute('style:punctuation-wrap', 'hanging'); $xmlWriter->writeAttribute('style:line-break', 'strict'); $xmlWriter->writeAttribute('style:tab-stop-distance', '1.249cm'); $xmlWriter->writeAttribute('style:writing-mode', 'page'); $xmlWriter->endElement(); // style:paragraph-properties $language = $this->getParentWriter()->getPhpWord()->getSettings()->getThemeFontLang(); $latinLang = $language != null && is_string($language->getLatin()) ? explode('-', $language->getLatin()) : array('fr', 'FR'); $asianLang = $language != null && is_string($language->getEastAsia()) ? explode('-', $language->getEastAsia()) : array('zh', 'CN'); $complexLang = $language != null && is_string($language->getBidirectional()) ? explode('-', $language->getBidirectional()) : array('hi', 'IN'); if ($this->getParentWriter()->getPhpWord()->getSettings()->hasHideGrammaticalErrors()) { $latinLang = $asianLang = $complexLang = array('zxx', 'none'); } // Font $xmlWriter->startElement('style:text-properties'); $xmlWriter->writeAttribute('style:use-window-font-color', 'true'); $xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName()); $xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt'); $xmlWriter->writeAttribute('fo:language', $latinLang[0]); $xmlWriter->writeAttribute('fo:country', $latinLang[1]); $xmlWriter->writeAttribute('style:letter-kerning', 'true'); $xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2'); $xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt'); $xmlWriter->writeAttribute('style:language-asian', $asianLang[0]); $xmlWriter->writeAttribute('style:country-asian', $asianLang[1]); $xmlWriter->writeAttribute('style:font-name-complex', Settings::getDefaultFontName() . '2'); $xmlWriter->writeAttribute('style:font-size-complex', Settings::getDefaultFontSize() . 'pt'); $xmlWriter->writeAttribute('style:language-complex', $complexLang[0]); $xmlWriter->writeAttribute('style:country-complex', $complexLang[1]); $xmlWriter->writeAttribute('fo:hyphenate', 'false'); $xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2'); $xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2'); $xmlWriter->endElement(); // style:text-properties $xmlWriter->endElement(); // style:default-style } /** * Write named styles. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeNamed(XMLWriter $xmlWriter) { $styles = Style::getStyles(); if (count($styles) > 0) { foreach ($styles as $style) { if ($style->isAuto() === false) { $styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style)); if (class_exists($styleClass)) { /** @var $styleWriter \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle Type hint */ $styleWriter = new $styleClass($xmlWriter, $style); $styleWriter->write(); } } } } } /** * Convert int in twips to inches/cm then to string and append unit * * @param int|float $twips * @param float $factor * return string */ private static function cvttwiptostr($twips, $factor = 1.0) { $ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in'; $cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm'; return (strlen($ins) < strlen($cms)) ? $ins : $cms; } /** * call writePageLayoutIndiv to write page layout styles for each page * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writePageLayout(XMLWriter $xmlWriter) { $sections = $this->getParentWriter()->getPhpWord()->getSections(); $countsects = count($sections); for ($i = 0; $i < $countsects; ++$i) { $this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1); } } /** * Write page layout styles. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section * @param int $sectionNbr */ private function writePageLayoutIndiv(XMLWriter $xmlWriter, $section, $sectionNbr) { $sty = $section->getStyle(); if (count($section->getHeaders()) > 0) { $topfactor = 0.5; } else { $topfactor = 1.0; } if (count($section->getFooters()) > 0) { $botfactor = 0.5; } else { $botfactor = 1.0; } $orient = $sty->getOrientation(); $pwidth = self::cvttwiptostr($sty->getPageSizeW()); $pheight = self::cvttwiptostr($sty->getPageSizeH()); $mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor); $mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor); $mleft = self::cvttwiptostr($sty->getMarginRight()); $mright = self::cvttwiptostr($sty->getMarginLeft()); $xmlWriter->startElement('style:page-layout'); $xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr"); $xmlWriter->startElement('style:page-layout-properties'); $xmlWriter->writeAttribute('fo:page-width', $pwidth); $xmlWriter->writeAttribute('fo:page-height', $pheight); $xmlWriter->writeAttribute('style:num-format', '1'); $xmlWriter->writeAttribute('style:print-orientation', $orient); $xmlWriter->writeAttribute('fo:margin-top', $mtop); $xmlWriter->writeAttribute('fo:margin-bottom', $mbottom); $xmlWriter->writeAttribute('fo:margin-left', $mleft); $xmlWriter->writeAttribute('fo:margin-right', $mright); $xmlWriter->writeAttribute('style:writing-mode', 'lr-tb'); $xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0'); $xmlWriter->writeAttribute('style:layout-grid-lines', '25199'); $xmlWriter->writeAttribute('style:layout-grid-base-height', '0.423cm'); $xmlWriter->writeAttribute('style:layout-grid-ruby-height', '0cm'); $xmlWriter->writeAttribute('style:layout-grid-mode', 'none'); $xmlWriter->writeAttribute('style:layout-grid-ruby-below', 'false'); $xmlWriter->writeAttribute('style:layout-grid-print', 'false'); $xmlWriter->writeAttribute('style:layout-grid-display', 'false'); $xmlWriter->writeAttribute('style:layout-grid-base-width', '0.37cm'); $xmlWriter->writeAttribute('style:layout-grid-snap-to', 'true'); $xmlWriter->writeAttribute('style:footnote-max-height', '0cm'); $xmlWriter->startElement('style:footnote-sep'); $xmlWriter->writeAttribute('style:width', '0.018cm'); $xmlWriter->writeAttribute('style:line-style', 'solid'); $xmlWriter->writeAttribute('style:adjustment', 'left'); $xmlWriter->writeAttribute('style:rel-width', '25%'); $xmlWriter->writeAttribute('style:color', '#000000'); $xmlWriter->endElement(); //style:footnote-sep $xmlWriter->endElement(); // style:page-layout-properties $xmlWriter->startElement('style:header-style'); if ($topfactor < 1.0) { $xmlWriter->startElement('style:header-footer-properties'); $xmlWriter->writeAttribute('fo:min-height', $mtop); $xmlWriter->writeAttribute('fo:margin-bottom', $mtop); $xmlWriter->writeAttribute('style:dynamic-spacing', 'true'); $xmlWriter->endElement(); // style:header-footer-properties } $xmlWriter->endElement(); // style:header-style $xmlWriter->startElement('style:footer-style'); if ($botfactor < 1.0) { $xmlWriter->startElement('style:header-footer-properties'); $xmlWriter->writeAttribute('fo:min-height', $mbottom); $xmlWriter->writeAttribute('fo:margin-top', $mbottom); $xmlWriter->writeAttribute('style:dynamic-spacing', 'true'); $xmlWriter->endElement(); // style:header-footer-properties } $xmlWriter->endElement(); // style:footer-style $xmlWriter->endElement(); // style:page-layout } /** * Write master style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeMaster(XMLWriter $xmlWriter) { $xmlWriter->startElement('office:master-styles'); $sections = $this->getParentWriter()->getPhpWord()->getSections(); $countsects = count($sections); for ($i = 0; $i < $countsects; ++$i) { $iplus1 = $i + 1; $xmlWriter->startElement('style:master-page'); $xmlWriter->writeAttribute('style:name', "Standard$iplus1"); $xmlWriter->writeAttribute('style:page-layout-name', "Mpm$iplus1"); // Multiple headers and footers probably not supported, // and, even if they are, I'm not sure how, // so quit after generating one. foreach ($sections[$i]->getHeaders() as $hdr) { $xmlWriter->startElement('style:header'); foreach ($hdr->getElements() as $elem) { $cl1 = get_class($elem); $cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1); if (class_exists($cl2)) { $wtr = new $cl2($xmlWriter, $elem); $wtr->write(); } } $xmlWriter->endElement(); // style:header break; } foreach ($sections[$i]->getFooters() as $hdr) { $xmlWriter->startElement('style:footer'); foreach ($hdr->getElements() as $elem) { $cl1 = get_class($elem); $cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1); if (class_exists($cl2)) { $wtr = new $cl2($xmlWriter, $elem); $wtr->write(); } } $xmlWriter->endElement(); // style:footer break; } $xmlWriter->endElement(); // style:master-page } $xmlWriter->endElement(); // office:master-styles } } phpword/src/PhpWord/Writer/Word2007/Element/TableAlignment.php 0000664 00000002670 15177100670 0020104 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * @since 0.13.0 */ class TableAlignment { private $name = 'w:jc'; private $attributes = array(); /** * @since 0.13.0 * * @param string $value Any value provided by JcTable simple type * * @see \PhpOffice\PhpWord\SimpleType\JcTable For the allowed values of $value parameter. */ final public function __construct($value) { $this->attributes['w:val'] = $value; } /** * @since 0.13.0 * * @return string */ final public function getName() { return $this->name; } /** * @since 0.13.0 * * @return string[] */ final public function getAttributes() { return $this->attributes; } } phpword/src/PhpWord/Writer/Word2007/Element/Text.php 0000664 00000005704 15177100670 0016143 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\TrackChange; /** * Text element writer * * @since 0.10.0 */ class Text extends AbstractElement { /** * Write text element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Text) { return; } $this->startElementP(); $this->writeOpeningTrackChange(); $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $textElement = 'w:t'; //'w:delText' in case of deleted text $changed = $element->getTrackChange(); if ($changed != null && $changed->getChangeType() == TrackChange::DELETED) { $textElement = 'w:delText'; } $xmlWriter->startElement($textElement); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($this->getText($element->getText())); $xmlWriter->endElement(); $xmlWriter->endElement(); // w:r $this->writeClosingTrackChange(); $this->endElementP(); // w:p } /** * Write opening of changed element */ protected function writeOpeningTrackChange() { $changed = $this->getElement()->getTrackChange(); if ($changed == null) { return; } $xmlWriter = $this->getXmlWriter(); if (($changed->getChangeType() == TrackChange::INSERTED)) { $xmlWriter->startElement('w:ins'); } elseif ($changed->getChangeType() == TrackChange::DELETED) { $xmlWriter->startElement('w:del'); } $xmlWriter->writeAttribute('w:author', $changed->getAuthor()); if ($changed->getDate() != null) { $xmlWriter->writeAttribute('w:date', $changed->getDate()->format('Y-m-d\TH:i:s\Z')); } $xmlWriter->writeAttribute('w:id', $this->getElement()->getElementId()); } /** * Write ending */ protected function writeClosingTrackChange() { $changed = $this->getElement()->getTrackChange(); if ($changed == null) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->endElement(); // w:ins|w:del } } phpword/src/PhpWord/Writer/Word2007/Element/Chart.php 0000664 00000005122 15177100670 0016252 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\Chart as ChartElement; /** * Chart element writer * * @since 0.12.0 */ class Chart extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof ChartElement) { return; } $rId = $element->getRelationId(); $style = $element->getStyle(); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:drawing'); $xmlWriter->startElement('wp:inline'); // EMU $xmlWriter->writeElementBlock('wp:extent', array('cx' => $style->getWidth(), 'cy' => $style->getHeight())); $xmlWriter->writeElementBlock('wp:docPr', array('id' => $rId, 'name' => "Chart{$rId}")); $xmlWriter->startElement('a:graphic'); $xmlWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $xmlWriter->startElement('a:graphicData'); $xmlWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); $xmlWriter->startElement('c:chart'); $xmlWriter->writeAttribute('r:id', "rId{$rId}"); $xmlWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->endElement(); // c:chart $xmlWriter->endElement(); // a:graphicData $xmlWriter->endElement(); // a:graphic $xmlWriter->endElement(); // wp:inline $xmlWriter->endElement(); // w:drawing $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/Table.php 0000664 00000010427 15177100670 0016244 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\Cell as CellElement; use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Table as TableElement; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Cell as CellStyle; use PhpOffice\PhpWord\Style\Row as RowStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Row as RowStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Table as TableStyleWriter; /** * Table element writer * * @since 0.10.0 */ class Table extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof TableElement) { return; } $rows = $element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $xmlWriter->startElement('w:tbl'); // Write columns $this->writeColumns($xmlWriter, $element); // Write style $styleWriter = new TableStyleWriter($xmlWriter, $element->getStyle()); $styleWriter->setWidth($element->getWidth()); $styleWriter->write(); // Write rows for ($i = 0; $i < $rowCount; $i++) { $this->writeRow($xmlWriter, $rows[$i]); } $xmlWriter->endElement(); // w:tbl } } /** * Write column. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Table $element */ private function writeColumns(XMLWriter $xmlWriter, TableElement $element) { $cellWidths = $element->findFirstDefinedCellWidths(); $xmlWriter->startElement('w:tblGrid'); foreach ($cellWidths as $width) { $xmlWriter->startElement('w:gridCol'); if ($width !== null) { $xmlWriter->writeAttribute('w:w', $width); $xmlWriter->writeAttribute('w:type', 'dxa'); } $xmlWriter->endElement(); } $xmlWriter->endElement(); // w:tblGrid } /** * Write row. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Row $row */ private function writeRow(XMLWriter $xmlWriter, RowElement $row) { $xmlWriter->startElement('w:tr'); // Write style $rowStyle = $row->getStyle(); if ($rowStyle instanceof RowStyle) { $styleWriter = new RowStyleWriter($xmlWriter, $rowStyle); $styleWriter->setHeight($row->getHeight()); $styleWriter->write(); } // Write cells foreach ($row->getCells() as $cell) { $this->writeCell($xmlWriter, $cell); } $xmlWriter->endElement(); // w:tr } /** * Write cell. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Cell $cell */ private function writeCell(XMLWriter $xmlWriter, CellElement $cell) { $xmlWriter->startElement('w:tc'); // Write style $cellStyle = $cell->getStyle(); if ($cellStyle instanceof CellStyle) { $styleWriter = new CellStyleWriter($xmlWriter, $cellStyle); $styleWriter->setWidth($cell->getWidth()); $styleWriter->write(); } // Write content $containerWriter = new Container($xmlWriter, $cell); $containerWriter->write(); $xmlWriter->endElement(); // w:tc } } phpword/src/PhpWord/Writer/Word2007/Element/ListItemRun.php 0000664 00000004770 15177100670 0017440 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\ListItemRun as ListItemRunElement; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; /** * ListItemRun element writer * * @since 0.10.0 */ class ListItemRun extends AbstractElement { /** * Write list item element. */ public function write() { $element = $this->getElement(); if (!$element instanceof ListItemRunElement) { return; } $this->writeParagraph($element); } private function writeParagraph(ListItemRunElement $element) { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:p'); $this->writeParagraphProperties($element); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); // w:p } private function writeParagraphProperties(ListItemRunElement $element) { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:pPr'); $styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle()); $styleWriter->setIsInline(true); $styleWriter->setWithoutPPR(true); $styleWriter->write(); $this->writeParagraphPropertiesNumbering($element); $xmlWriter->endElement(); // w:pPr } private function writeParagraphPropertiesNumbering(ListItemRunElement $element) { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:numPr'); $xmlWriter->writeElementBlock('w:ilvl', array( 'w:val' => $element->getDepth(), )); $xmlWriter->writeElementBlock('w:numId', array( 'w:val' => $element->getStyle()->getNumId(), )); $xmlWriter->endElement(); // w:numPr } } phpword/src/PhpWord/Writer/Word2007/Element/PageBreak.php 0000664 00000002512 15177100670 0017032 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * PageBreak element writer * * @since 0.10.0 */ class PageBreak extends AbstractElement { /** * Write element. * * @usedby \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement::startElementP() */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:br'); $xmlWriter->writeAttribute('w:type', 'page'); $xmlWriter->endElement(); // w:br $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/Line.php 0000664 00000006102 15177100670 0016077 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\Line as LineElement; use PhpOffice\PhpWord\Writer\Word2007\Style\Line as LineStyleWriter; /** * Line element writer */ class Line extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof LineElement) { return; } $style = $element->getStyle(); $styleWriter = new LineStyleWriter($xmlWriter, $style); $elementId = $element->getElementIndex(); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:pict'); // Shapetype could be defined for each line separately, but then a unique id would be necessary if ($elementId == 1) { $xmlWriter->startElement('v:shapetype'); $xmlWriter->writeAttribute('id', '_x0000_t32'); $xmlWriter->writeAttribute('coordsize', '21600,21600'); $xmlWriter->writeAttribute('o:spt', '32'); $xmlWriter->writeAttribute('o:oned', 't'); $xmlWriter->writeAttribute('path', 'm,l21600,21600e'); $xmlWriter->writeAttribute('filled', 'f'); $xmlWriter->startElement('v:path'); $xmlWriter->writeAttribute('arrowok', 't'); $xmlWriter->writeAttribute('fillok', 'f'); $xmlWriter->writeAttribute('o:connecttype', 'none'); $xmlWriter->endElement(); // v:path $xmlWriter->startElement('o:lock'); $xmlWriter->writeAttribute('v:ext', 'edit'); $xmlWriter->writeAttribute('shapetype', 't'); $xmlWriter->endElement(); // o:lock $xmlWriter->endElement(); // v:shapetype } $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('id', sprintf('_x0000_s1%1$03d', $elementId)); $xmlWriter->writeAttribute('type', '#_x0000_t32'); //type should correspond to shapetype id $styleWriter->write(); $styleWriter->writeStroke(); $xmlWriter->endElement(); // v:shape $xmlWriter->endElement(); // w:pict $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/ListItem.php 0000664 00000004123 15177100670 0016743 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; /** * ListItem element writer * * @since 0.10.0 */ class ListItem extends AbstractElement { /** * Write list item element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\ListItem) { return; } $textObject = $element->getTextObject(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $textObject->getParagraphStyle()); $styleWriter->setWithoutPPR(true); $styleWriter->setIsInline(true); $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:pPr'); $styleWriter->write(); $xmlWriter->startElement('w:numPr'); $xmlWriter->startElement('w:ilvl'); $xmlWriter->writeAttribute('w:val', $element->getDepth()); $xmlWriter->endElement(); // w:ilvl $xmlWriter->startElement('w:numId'); $xmlWriter->writeAttribute('w:val', $element->getStyle()->getNumId()); $xmlWriter->endElement(); // w:numId $xmlWriter->endElement(); // w:numPr $xmlWriter->endElement(); // w:pPr $elementWriter = new Text($xmlWriter, $textObject, true); $elementWriter->write(); $xmlWriter->endElement(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/Container.php 0000664 00000006531 15177100670 0017140 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Container element writer (section, textrun, header, footnote, cell, etc.) * * @since 0.11.0 */ class Container extends AbstractElement { /** * Namespace; Can't use __NAMESPACE__ in inherited class (ODText) * * @var string */ protected $namespace = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element'; /** * Write element. */ public function write() { $container = $this->getElement(); if (!$container instanceof ContainerElement) { return; } $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote', 'ListItemRun')); $xmlWriter = $this->getXmlWriter(); // Loop through elements $elements = $container->getElements(); $elementClass = ''; foreach ($elements as $element) { $elementClass = $this->writeElement($xmlWriter, $element, $withoutP); } // Special case for Cell: They have to contain a w:p element at the end. // The $elementClass contains the last element name. If it's empty string // or Table, the last element is not w:p $writeLastTextBreak = ($containerClass == 'Cell') && ($elementClass == '' || $elementClass == 'Table'); if ($writeLastTextBreak) { $writerClass = $this->namespace . '\\TextBreak'; /** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */ $writer = new $writerClass($xmlWriter, new TextBreakElement(), $withoutP); $writer->write(); } } /** * Write individual element * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP * @return string */ private function writeElement(XMLWriter $xmlWriter, Element $element, $withoutP) { $elementClass = substr(get_class($element), strrpos(get_class($element), '\\') + 1); $writerClass = $this->namespace . '\\' . $elementClass; if (class_exists($writerClass)) { /** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */ $writer = new $writerClass($xmlWriter, $element, $withoutP); $writer->write(); } return $elementClass; } } phpword/src/PhpWord/Writer/Word2007/Element/PreserveText.php 0000664 00000005600 15177100670 0017652 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * PreserveText element writer * * @since 0.10.0 */ class PreserveText extends Text { /** * Write preserve text element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\PreserveText) { return; } $texts = $element->getText(); if (!is_array($texts)) { $texts = array($texts); } $this->startElementP(); foreach ($texts as $text) { if (substr($text, 0, 1) == '{') { $text = substr($text, 1, -1); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($text); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'separate'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); $xmlWriter->endElement(); } else { $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($this->getText($text)); $xmlWriter->endElement(); $xmlWriter->endElement(); } } $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/Shape.php 0000664 00000012150 15177100670 0016250 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\Shape as ShapeElement; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Shape as ShapeStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Shape as ShapeStyleWriter; /** * Shape element writer * * @since 0.12.0 * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ class Shape extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof ShapeElement) { return; } $style = $element->getStyle(); $styleWriter = new ShapeStyleWriter($xmlWriter, $style); $type = $element->getType(); if ($type == 'rect' && $style->getRoundness() !== null) { $type = 'roundrect'; } $method = "write{$type}"; if (!$this->withoutP) { $xmlWriter->startElement('w:p'); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:pict'); $xmlWriter->startElement("v:{$type}"); // Element style if (method_exists($this, $method)) { $this->$method($xmlWriter, $style); } // Child style $styleWriter->write(); $xmlWriter->endElement(); // v:$type $xmlWriter->endElement(); // w:pict $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } /** * Write arc. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style */ private function writeArc(XMLWriter $xmlWriter, ShapeStyle $style) { $points = $this->getPoints('arc', $style->getPoints()); $xmlWriter->writeAttributeIf($points['start'] !== null, 'startAngle', $points['start']); $xmlWriter->writeAttributeIf($points['end'] !== null, 'endAngle', $points['end']); } /** * Write curve. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style */ private function writeCurve(XMLWriter $xmlWriter, ShapeStyle $style) { $points = $this->getPoints('curve', $style->getPoints()); $this->writeLine($xmlWriter, $style); $xmlWriter->writeAttributeIf($points['point1'] !== null, 'control1', $points['point1']); $xmlWriter->writeAttributeIf($points['point2'] !== null, 'control2', $points['point2']); } /** * Write line. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style */ private function writeLine(XMLWriter $xmlWriter, ShapeStyle $style) { $points = $this->getPoints('line', $style->getPoints()); $xmlWriter->writeAttributeIf($points['start'] !== null, 'from', $points['start']); $xmlWriter->writeAttributeIf($points['end'] !== null, 'to', $points['end']); } /** * Write polyline. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style */ private function writePolyline(XMLWriter $xmlWriter, ShapeStyle $style) { $xmlWriter->writeAttributeIf($style->getPoints() !== null, 'points', $style->getPoints()); } /** * Write rectangle. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style */ private function writeRoundRect(XMLWriter $xmlWriter, ShapeStyle $style) { $xmlWriter->writeAttribute('arcsize', $style->getRoundness()); } /** * Set points * * @param string $type * @param string $value * @return array */ private function getPoints($type, $value) { $points = array(); switch ($type) { case 'arc': case 'line': $points = explode(' ', $value); list($start, $end) = array_pad($points, 2, null); $points = array('start' => $start, 'end' => $end); break; case 'curve': $points = explode(' ', $value); list($start, $end, $point1, $point2) = array_pad($points, 4, null); $points = array('start' => $start, 'end' => $end, 'point1' => $point1, 'point2' => $point2); break; } return $points; } } phpword/src/PhpWord/Writer/Word2007/Element/Title.php 0000664 00000005234 15177100670 0016276 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * TextRun element writer * * @since 0.10.0 */ class Title extends AbstractElement { /** * Write title element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Title) { return; } $style = $element->getStyle(); $xmlWriter->startElement('w:p'); if (!empty($style)) { $xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pStyle'); $xmlWriter->writeAttribute('w:val', $style); $xmlWriter->endElement(); $xmlWriter->endElement(); } $bookmarkRId = null; if ($element->getDepth() !== 0) { $rId = $element->getRelationId(); $bookmarkRId = $element->getPhpWord()->addBookmark(); // Bookmark start for TOC $xmlWriter->startElement('w:bookmarkStart'); $xmlWriter->writeAttribute('w:id', $bookmarkRId); $xmlWriter->writeAttribute('w:name', "_Toc{$rId}"); $xmlWriter->endElement(); //w:bookmarkStart } // Actual text $text = $element->getText(); if (is_string($text)) { $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:t'); $this->writeText($text); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r } elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { $containerWriter = new Container($xmlWriter, $text); $containerWriter->write(); } if ($element->getDepth() !== 0) { // Bookmark end $xmlWriter->startElement('w:bookmarkEnd'); $xmlWriter->writeAttribute('w:id', $bookmarkRId); $xmlWriter->endElement(); //w:bookmarkEnd } $xmlWriter->endElement(); //w:p } } phpword/src/PhpWord/Writer/Word2007/Element/AbstractElement.php 0000664 00000015077 15177100670 0020300 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Abstract element writer * * @since 0.11.0 */ abstract class AbstractElement { /** * XML writer * * @var \PhpOffice\PhpWord\Shared\XMLWriter */ private $xmlWriter; /** * Element * * @var \PhpOffice\PhpWord\Element\AbstractElement */ private $element; /** * Without paragraph * * @var bool */ protected $withoutP = false; /** * Write element */ abstract public function write(); /** * Create new instance * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP */ public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false) { $this->xmlWriter = $xmlWriter; $this->element = $element; $this->withoutP = $withoutP; } /** * Get XML Writer * * @return \PhpOffice\PhpWord\Shared\XMLWriter */ protected function getXmlWriter() { return $this->xmlWriter; } /** * Get element * * @return \PhpOffice\PhpWord\Element\AbstractElement */ protected function getElement() { return $this->element; } /** * Start w:p DOM element. * * @uses \PhpOffice\PhpWord\Writer\Word2007\Element\PageBreak::write() */ protected function startElementP() { if (!$this->withoutP) { $this->xmlWriter->startElement('w:p'); // Paragraph style if (method_exists($this->element, 'getParagraphStyle')) { $this->writeParagraphStyle(); } } $this->writeCommentRangeStart(); } /** * End w:p DOM element. */ protected function endElementP() { $this->writeCommentRangeEnd(); if (!$this->withoutP) { $this->xmlWriter->endElement(); // w:p } } /** * Writes the w:commentRangeStart DOM element */ protected function writeCommentRangeStart() { if ($this->element->getCommentRangeStart() != null) { $comment = $this->element->getCommentRangeStart(); //only set the ID if it is not yet set, otherwise it will overwrite it if ($comment->getElementId() == null) { $comment->setElementId(); } $this->xmlWriter->writeElementBlock('w:commentRangeStart', array('w:id' => $comment->getElementId())); } } /** * Writes the w:commentRangeEnd DOM element */ protected function writeCommentRangeEnd() { if ($this->element->getCommentRangeEnd() != null) { $comment = $this->element->getCommentRangeEnd(); //only set the ID if it is not yet set, otherwise it will overwrite it, this should normally not happen if ($comment->getElementId() == null) { $comment->setElementId(); // @codeCoverageIgnore } // @codeCoverageIgnore $this->xmlWriter->writeElementBlock('w:commentRangeEnd', array('w:id' => $comment->getElementId())); $this->xmlWriter->startElement('w:r'); $this->xmlWriter->writeElementBlock('w:commentReference', array('w:id' => $comment->getElementId())); $this->xmlWriter->endElement(); } elseif ($this->element->getCommentRangeStart() != null && $this->element->getCommentRangeStart()->getEndElement() == null) { $comment = $this->element->getCommentRangeStart(); //only set the ID if it is not yet set, otherwise it will overwrite it, this should normally not happen if ($comment->getElementId() == null) { $comment->setElementId(); // @codeCoverageIgnore } // @codeCoverageIgnore $this->xmlWriter->writeElementBlock('w:commentRangeEnd', array('w:id' => $comment->getElementId())); $this->xmlWriter->startElement('w:r'); $this->xmlWriter->writeElementBlock('w:commentReference', array('w:id' => $comment->getElementId())); $this->xmlWriter->endElement(); } } /** * Write ending. */ protected function writeParagraphStyle() { $this->writeTextStyle('Paragraph'); } /** * Write ending. */ protected function writeFontStyle() { $this->writeTextStyle('Font'); } /** * Write text style. * * @param string $styleType Font|Paragraph */ private function writeTextStyle($styleType) { $method = "get{$styleType}Style"; $class = "PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\{$styleType}"; $styleObject = $this->element->$method(); /** @var \PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle $styleWriter Type Hint */ $styleWriter = new $class($this->xmlWriter, $styleObject); if (method_exists($styleWriter, 'setIsInline')) { $styleWriter->setIsInline(true); } $styleWriter->write(); } /** * Convert text to valid format * * @param string $text * @return string */ protected function getText($text) { return SharedText::controlCharacterPHP2OOXML($text); } /** * Write an XML text, this will call text() or writeRaw() depending on the value of Settings::isOutputEscapingEnabled() * * @param string $content The text string to write * @return bool Returns true on success or false on failure */ protected function writeText($content) { if (Settings::isOutputEscapingEnabled()) { return $this->getXmlWriter()->text($content); } return $this->getXmlWriter()->writeRaw($content); } } phpword/src/PhpWord/Writer/Word2007/Element/Bookmark.php 0000664 00000002715 15177100670 0016763 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * Bookmark element writer * * @since 0.12.0 */ class Bookmark extends AbstractElement { /** * Write bookmark element */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Bookmark) { return; } $rId = $element->getRelationId(); $xmlWriter->startElement('w:bookmarkStart'); $xmlWriter->writeAttribute('w:id', $rId); $xmlWriter->writeAttribute('w:name', $element->getName()); $xmlWriter->endElement(); $xmlWriter->startElement('w:bookmarkEnd'); $xmlWriter->writeAttribute('w:id', $rId); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Element/TextBreak.php 0000664 00000002751 15177100670 0017107 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * TextBreak element writer * * @since 0.10.0 */ class TextBreak extends Text { /** * Write text break element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\TextBreak) { return; } if (!$this->withoutP) { $hasStyle = $element->hasStyle(); $this->startElementP(); if ($hasStyle) { $xmlWriter->startElement('w:pPr'); $this->writeFontStyle(); $xmlWriter->endElement(); // w:pPr } $this->endElementP(); // w:p } else { $xmlWriter->writeElement('w:br'); } } } phpword/src/PhpWord/Writer/Word2007/Element/TextRun.php 0000664 00000002205 15177100670 0016621 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * TextRun element writer * * @since 0.10.0 */ class TextRun extends Text { /** * Write textrun element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); $this->startElementP(); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/SDT.php 0000664 00000010673 15177100670 0015652 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\SDT as SDTElement; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Structured document tag element writer * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtBlock.html * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ class SDT extends Text { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof SDTElement) { return; } $type = $element->getType(); $writeFormField = "write{$type}"; $alias = $element->getAlias(); $tag = $element->getTag(); $value = $element->getValue(); if ($value === null) { $value = 'Pick value'; } $this->startElementP(); $xmlWriter->startElement('w:sdt'); // Properties $xmlWriter->startElement('w:sdtPr'); $xmlWriter->writeElementIf($alias != null, 'w:alias', 'w:val', $alias); $xmlWriter->writeElementBlock('w:lock', 'w:val', 'sdtLocked'); $xmlWriter->writeElementBlock('w:id', 'w:val', rand(100000000, 999999999)); $xmlWriter->writeElementIf($tag != null, 'w:tag', 'w:val', $tag); $this->$writeFormField($xmlWriter, $element); $xmlWriter->endElement(); // w:sdtPr // Content $xmlWriter->startElement('w:sdtContent'); $xmlWriter->startElement('w:r'); $xmlWriter->writeElement('w:t', $value); $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:sdtContent $xmlWriter->endElement(); // w:sdt $this->endElementP(); // w:p } /** * Write text. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtText.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writePlainText(XMLWriter $xmlWriter) { $xmlWriter->startElement('w:text'); $xmlWriter->endElement(); // w:text } /** * Write combo box. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtComboBox.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element */ private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element) { $type = $element->getType(); $listItems = $element->getListItems(); $xmlWriter->startElement("w:{$type}"); foreach ($listItems as $key => $val) { $xmlWriter->writeElementBlock('w:listItem', array('w:value' => $key, 'w:displayText' => $val)); } $xmlWriter->endElement(); // w:{$type} } /** * Write drop down list. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDropDownList.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element */ private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) { $this->writeComboBox($xmlWriter, $element); } /** * Write date. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDate.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element */ private function writeDate(XMLWriter $xmlWriter, SDTElement $element) { $type = $element->getType(); $xmlWriter->startElement("w:{$type}"); $xmlWriter->writeElementBlock('w:dateFormat', 'w:val', 'd/M/yyyy'); $xmlWriter->writeElementBlock('w:lid', 'w:val', 'en-US'); $xmlWriter->writeElementBlock('w:storeMappedDataAs', 'w:val', 'dateTime'); $xmlWriter->writeElementBlock('w:calendar', 'w:val', 'gregorian'); $xmlWriter->endElement(); // w:date } } phpword/src/PhpWord/Writer/Word2007/Element/CheckBox.php 0000664 00000006240 15177100670 0016701 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * CheckBox element writer * * @since 0.10.0 */ class CheckBox extends Text { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\CheckBox) { return; } $this->startElementP(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->startElement('w:ffData'); $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', $this->getText($element->getName())); $xmlWriter->endElement(); //w:name $xmlWriter->writeAttribute('w:enabled', ''); $xmlWriter->startElement('w:calcOnExit'); $xmlWriter->writeAttribute('w:val', '0'); $xmlWriter->endElement(); //w:calcOnExit $xmlWriter->startElement('w:checkBox'); $xmlWriter->writeAttribute('w:sizeAuto', ''); $xmlWriter->startElement('w:default'); $xmlWriter->writeAttribute('w:val', 0); $xmlWriter->endElement(); //w:default $xmlWriter->endElement(); //w:checkBox $xmlWriter->endElement(); // w:ffData $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text(' FORMCHECKBOX '); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'separate'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($this->getText($element->getText())); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/Image.php 0000664 00000010133 15177100670 0016231 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\Image as ImageElement; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Frame as FrameStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter; /** * Image element writer * * @since 0.10.0 */ class Image extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof ImageElement) { return; } if ($element->isWatermark()) { $this->writeWatermark($xmlWriter, $element); } else { $this->writeImage($xmlWriter, $element); } } /** * Write image element. */ private function writeImage(XMLWriter $xmlWriter, ImageElement $element) { $rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0); $style = $element->getStyle(); $styleWriter = new ImageStyleWriter($xmlWriter, $style); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); // Write position $position = $style->getPosition(); if ($position && $style->getWrap() == FrameStyle::WRAP_INLINE) { $fontStyle = new FontStyle('text'); $fontStyle->setPosition($position); $fontStyleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $fontStyleWriter->write(); } $xmlWriter->startElement('w:pict'); $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('type', '#_x0000_t75'); $xmlWriter->writeAttribute('stroked', 'f'); $styleWriter->write(); $xmlWriter->startElement('v:imagedata'); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->writeAttribute('o:title', ''); $xmlWriter->endElement(); // v:imagedata $xmlWriter->endElement(); // v:shape $xmlWriter->endElement(); // w:pict $xmlWriter->endElement(); // w:r $this->endElementP(); } /** * Write watermark element. */ private function writeWatermark(XMLWriter $xmlWriter, ImageElement $element) { $rId = $element->getRelationId(); $style = $element->getStyle(); $style->setPositioning('absolute'); $styleWriter = new ImageStyleWriter($xmlWriter, $style); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); } $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:pict'); $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('type', '#_x0000_t75'); $xmlWriter->writeAttribute('stroked', 'f'); $styleWriter->write(); $xmlWriter->startElement('v:imagedata'); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->writeAttribute('o:title', ''); $xmlWriter->endElement(); // v:imagedata $xmlWriter->endElement(); // v:shape $xmlWriter->endElement(); // w:pict $xmlWriter->endElement(); // w:r if (!$this->withoutP) { $xmlWriter->endElement(); // w:p } } } phpword/src/PhpWord/Writer/Word2007/Element/ParagraphAlignment.php 0000664 00000002662 15177100670 0020763 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * @since 0.13.0 */ class ParagraphAlignment { private $name = 'w:jc'; private $attributes = array(); /** * @since 0.13.0 * * @param string $value Any value provided by Jc simple type * * @see \PhpOffice\PhpWord\SimpleType\Jc For the allowed values of $value parameter. */ final public function __construct($value) { $this->attributes['w:val'] = $value; } /** * @since 0.13.0 * * @return string */ final public function getName() { return $this->name; } /** * @since 0.13.0 * * @return string[] */ final public function getAttributes() { return $this->attributes; } } phpword/src/PhpWord/Writer/Word2007/Element/Endnote.php 0000664 00000001647 15177100670 0016615 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * Endnote element writer * * @since 0.10.0 */ class Endnote extends Footnote { /** * Reference type * * @var string */ protected $referenceType = 'endnoteReference'; } phpword/src/PhpWord/Writer/Word2007/Element/TextBox.php 0000664 00000004312 15177100670 0016606 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Writer\Word2007\Style\TextBox as TextBoxStyleWriter; /** * TextBox element writer * * @since 0.11.0 */ class TextBox extends Image { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\TextBox) { return; } $style = $element->getStyle(); $styleWriter = new TextBoxStyleWriter($xmlWriter, $style); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:pict'); $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('type', '#_x0000_t0202'); $styleWriter->write(); $styleWriter->writeBorder(); $xmlWriter->startElement('v:textbox'); $styleWriter->writeInnerMargin(); // TextBox content, serving as a container $xmlWriter->startElement('w:txbxContent'); $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); // w:txbxContent $xmlWriter->endElement(); // v: textbox $xmlWriter->endElement(); // v:shape $xmlWriter->endElement(); // w:pict $xmlWriter->endElement(); // w:r $this->endElementP(); } } phpword/src/PhpWord/Writer/Word2007/Element/Link.php 0000664 00000003537 15177100670 0016116 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * Link element writer * * @since 0.10.0 */ class Link extends Text { /** * Write link element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Link) { return; } $rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0); $this->startElementP(); $xmlWriter->startElement('w:hyperlink'); if ($element->isInternal()) { $xmlWriter->writeAttribute('w:anchor', $element->getSource()); } else { $xmlWriter->writeAttribute('r:id', 'rId' . $rId); } $xmlWriter->writeAttribute('w:history', '1'); $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($element->getText()); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:hyperlink $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/FormField.php 0000664 00000013475 15177100670 0017072 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\FormField as FormFieldElement; use PhpOffice\PhpWord\Shared\XMLWriter; /** * FormField element writer * * Note: DropDown is active when document protection is set to `forms` * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ class FormField extends Text { /** @const int Length of filler when value is null */ const FILLER_LENGTH = 30; /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof FormFieldElement) { return; } $type = $element->getType(); $instructions = array('textinput' => 'FORMTEXT', 'checkbox' => 'FORMCHECKBOX', 'dropdown' => 'FORMDROPDOWN'); $instruction = $instructions[$type]; $writeFormField = "write{$type}"; $name = $element->getName(); if ($name === null) { $name = $type . $element->getElementId(); } $value = $element->getValue(); if ($value === null) { $value = str_repeat(' ', self::FILLER_LENGTH); } $this->startElementP(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->startElement('w:ffData'); $xmlWriter->writeElementBlock('w:enabled', 'w:val', 1); $xmlWriter->writeElementBlock('w:name', 'w:val', $name); $xmlWriter->writeElementBlock('w:calcOnExit', 'w:val', 0); $this->$writeFormField($xmlWriter, $element); $xmlWriter->endElement(); // w:ffData $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text("{$instruction}"); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->writeElementBlock('w:fldChar', 'w:fldCharType', 'separate'); $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $this->writeText($value); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->writeElementBlock('w:fldChar', 'w:fldCharType', 'end'); $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } /** * Write textinput. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFTextInput.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element */ private function writeTextInput(XMLWriter $xmlWriter, FormFieldElement $element) { $default = $element->getDefault(); $xmlWriter->startElement('w:textInput'); $xmlWriter->writeElementBlock('w:default', 'w:val', $default); $xmlWriter->endElement(); } /** * Write checkbox. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFCheckBox.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element */ private function writeCheckBox(XMLWriter $xmlWriter, FormFieldElement $element) { $default = $element->getDefault() ? 1 : 0; $value = $element->getValue(); if ($value == null) { $value = $default; } $value = $value ? 1 : 0; $xmlWriter->startElement('w:checkBox'); $xmlWriter->writeElementBlock('w:sizeAuto', 'w:val', ''); $xmlWriter->writeElementBlock('w:default', 'w:val', $default); $xmlWriter->writeElementBlock('w:checked', 'w:val', $value); $xmlWriter->endElement(); } /** * Write dropdown. * * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFDDList.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element */ private function writeDropDown(XMLWriter $xmlWriter, FormFieldElement $element) { $default = $element->getDefault(); $value = $element->getValue(); if ($value == null) { $value = $default; } $entries = $element->getEntries(); $xmlWriter->startElement('w:ddList'); $xmlWriter->writeElementBlock('w:result', 'w:val', $value); $xmlWriter->writeElementBlock('w:default', 'w:val', $default); foreach ($entries as $entry) { if ($entry == null || $entry == '') { $entry = str_repeat(' ', self::FILLER_LENGTH); } $xmlWriter->writeElementBlock('w:listEntry', 'w:val', $entry); } $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Element/Field.php 0000664 00000017230 15177100670 0016237 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * Field element writer * * @since 0.11.0 */ class Field extends Text { /** * Write field element. */ public function write() { $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Field) { return; } $methodName = 'write' . ucfirst(strtolower($element->getType())); if (method_exists($this, $methodName)) { $this->$methodName($element); } else { $this->writeDefault($element); } } private function writeDefault(\PhpOffice\PhpWord\Element\Field $element) { $xmlWriter = $this->getXmlWriter(); $this->startElementP(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $instruction = ' ' . $element->getType() . ' '; if ($element->getText() != null) { if (is_string($element->getText())) { $instruction .= '"' . $element->getText() . '" '; $instruction .= $this->buildPropertiesAndOptions($element); } else { $instruction .= '"'; } } else { $instruction .= $this->buildPropertiesAndOptions($element); } $xmlWriter->startElement('w:r'); $this->writeFontStyle(); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text($instruction); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r if ($element->getText() != null) { if ($element->getText() instanceof \PhpOffice\PhpWord\Element\TextRun) { $containerWriter = new Container($xmlWriter, $element->getText(), true); $containerWriter->write(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->text('"' . $this->buildPropertiesAndOptions($element)); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text(' '); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r } } $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'separate'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:noProof'); $xmlWriter->endElement(); // w:noProof $xmlWriter->endElement(); // w:rPr $xmlWriter->writeElement('w:t', $element->getText() != null && is_string($element->getText()) ? $element->getText() : '1'); $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } /** * Writes a macrobutton field * * //TODO A lot of code duplication with general method, should maybe be refactored * @param \PhpOffice\PhpWord\Element\Field $element */ protected function writeMacrobutton(\PhpOffice\PhpWord\Element\Field $element) { $xmlWriter = $this->getXmlWriter(); $this->startElementP(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $instruction = ' ' . $element->getType() . ' ' . $this->buildPropertiesAndOptions($element); if (is_string($element->getText())) { $instruction .= $element->getText() . ' '; } $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text($instruction); $xmlWriter->endElement(); // w:instrText $xmlWriter->endElement(); // w:r if ($element->getText() != null) { if ($element->getText() instanceof \PhpOffice\PhpWord\Element\TextRun) { $containerWriter = new Container($xmlWriter, $element->getText(), true); $containerWriter->write(); } } $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); // w:fldChar $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } private function buildPropertiesAndOptions(\PhpOffice\PhpWord\Element\Field $element) { $propertiesAndOptions = ''; $properties = $element->getProperties(); foreach ($properties as $propkey => $propval) { switch ($propkey) { case 'format': $propertiesAndOptions .= '\* ' . $propval . ' '; break; case 'numformat': $propertiesAndOptions .= '\# ' . $propval . ' '; break; case 'dateformat': $propertiesAndOptions .= '\@ "' . $propval . '" '; break; case 'macroname': $propertiesAndOptions .= $propval . ' '; break; default: $propertiesAndOptions .= '"' . $propval . '" '; break; } } $options = $element->getOptions(); foreach ($options as $option) { switch ($option) { case 'PreserveFormat': $propertiesAndOptions .= '\* MERGEFORMAT '; break; case 'LunarCalendar': $propertiesAndOptions .= '\h '; break; case 'SakaEraCalendar': $propertiesAndOptions .= '\s '; break; case 'LastUsedFormat': $propertiesAndOptions .= '\l '; break; case 'Bold': $propertiesAndOptions .= '\b '; break; case 'Italic': $propertiesAndOptions .= '\i '; break; default: $propertiesAndOptions .= $option . ' '; } } return $propertiesAndOptions; } } phpword/src/PhpWord/Writer/Word2007/Element/TOC.php 0000664 00000015314 15177100670 0015642 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\TOC as TOCElement; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Tab as TabStyleWriter; /** * TOC element writer * * @since 0.10.0 */ class TOC extends AbstractElement { /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof TOCElement) { return; } $titles = $element->getTitles(); $writeFieldMark = true; foreach ($titles as $title) { $this->writeTitle($xmlWriter, $element, $title, $writeFieldMark); if ($writeFieldMark) { $writeFieldMark = false; } } $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->endElement(); } /** * Write title * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\Title $title * @param bool $writeFieldMark */ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $writeFieldMark) { $tocStyle = $element->getStyleTOC(); $fontStyle = $element->getStyleFont(); $isObject = ($fontStyle instanceof Font) ? true : false; $rId = $title->getRelationId(); $indent = ($title->getDepth() - 1) * $tocStyle->getIndent(); $xmlWriter->startElement('w:p'); // Write style and field mark $this->writeStyle($xmlWriter, $element, $indent); if ($writeFieldMark) { $this->writeFieldMark($xmlWriter, $element); } // Hyperlink $xmlWriter->startElement('w:hyperlink'); $xmlWriter->writeAttribute('w:anchor', "_Toc{$rId}"); $xmlWriter->writeAttribute('w:history', '1'); // Title text $xmlWriter->startElement('w:r'); if ($isObject) { $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $styleWriter->write(); } $xmlWriter->startElement('w:t'); $this->writeText($title->getText()); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); $xmlWriter->writeElement('w:tab', null); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text("PAGEREF _Toc{$rId} \h"); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'end'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->endElement(); // w:hyperlink $xmlWriter->endElement(); // w:p } /** * Write style * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @param int $indent */ private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent) { $tocStyle = $element->getStyleTOC(); $fontStyle = $element->getStyleFont(); $isObject = ($fontStyle instanceof Font) ? true : false; $xmlWriter->startElement('w:pPr'); // Paragraph if ($isObject && !is_null($fontStyle->getParagraph())) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraph()); $styleWriter->write(); } // Font if (!empty($fontStyle) && !$isObject) { $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rStyle'); $xmlWriter->writeAttribute('w:val', $fontStyle); $xmlWriter->endElement(); $xmlWriter->endElement(); // w:rPr } // Tab $xmlWriter->startElement('w:tabs'); $styleWriter = new TabStyleWriter($xmlWriter, $tocStyle); $styleWriter->write(); $xmlWriter->endElement(); // Indent if ($indent > 0) { $xmlWriter->startElement('w:ind'); $xmlWriter->writeAttribute('w:left', $indent); $xmlWriter->endElement(); } $xmlWriter->endElement(); // w:pPr } /** * Write TOC Field. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element */ private function writeFieldMark(XMLWriter $xmlWriter, TOCElement $element) { $minDepth = $element->getMinDepth(); $maxDepth = $element->getMaxDepth(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'begin'); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text("TOC \o {$minDepth}-{$maxDepth} \h \z \u"); $xmlWriter->endElement(); $xmlWriter->endElement(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:fldChar'); $xmlWriter->writeAttribute('w:fldCharType', 'separate'); $xmlWriter->endElement(); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Element/Footnote.php 0000664 00000003445 15177100670 0017014 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; /** * Footnote element writer * * @since 0.10.0 */ class Footnote extends Text { /** * Reference type footnoteReference|endnoteReference * * @var string */ protected $referenceType = 'footnoteReference'; /** * Write element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\Footnote) { return; } $this->startElementP(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rStyle'); $xmlWriter->writeAttribute('w:val', ucfirst($this->referenceType)); $xmlWriter->endElement(); // w:rStyle $xmlWriter->endElement(); // w:rPr $xmlWriter->startElement("w:{$this->referenceType}"); $xmlWriter->writeAttribute('w:id', $element->getRelationId()); $xmlWriter->endElement(); // w:$referenceType $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Element/OLEObject.php 0000664 00000006022 15177100670 0016757 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter; /** * OLEObject element writer * * @since 0.10.0 */ class OLEObject extends AbstractElement { /** * Write object element. */ public function write() { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); if (!$element instanceof \PhpOffice\PhpWord\Element\OLEObject) { return; } $rIdObject = $element->getRelationId() + ($element->isInSection() ? 6 : 0); $rIdImage = $element->getImageRelationId() + ($element->isInSection() ? 6 : 0); $shapeId = md5($rIdObject . '_' . $rIdImage); $objectId = $element->getRelationId() + 1325353440; $style = $element->getStyle(); $styleWriter = new ImageStyleWriter($xmlWriter, $style); if (!$this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } $this->writeCommentRangeStart(); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:object'); $xmlWriter->writeAttribute('w:dxaOrig', '249'); $xmlWriter->writeAttribute('w:dyaOrig', '160'); // Icon $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('id', $shapeId); $xmlWriter->writeAttribute('type', '#_x0000_t75'); $xmlWriter->writeAttribute('style', 'width:104px;height:67px'); $xmlWriter->writeAttribute('o:ole', ''); $xmlWriter->startElement('v:imagedata'); $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage); $xmlWriter->writeAttribute('o:title', ''); $xmlWriter->endElement(); // v:imagedata $xmlWriter->endElement(); // v:shape // Object $xmlWriter->startElement('o:OLEObject'); $xmlWriter->writeAttribute('Type', 'Embed'); $xmlWriter->writeAttribute('ProgID', 'Package'); $xmlWriter->writeAttribute('ShapeID', $shapeId); $xmlWriter->writeAttribute('DrawAspect', 'Icon'); $xmlWriter->writeAttribute('ObjectID', '_' . $objectId); $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject); $xmlWriter->endElement(); // o:OLEObject $xmlWriter->endElement(); // w:object $xmlWriter->endElement(); // w:r $this->endElementP(); // w:p } } phpword/src/PhpWord/Writer/Word2007/Style/Table.php 0000664 00000016134 15177100670 0015754 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\SimpleType\TblWidth; use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Writer\Word2007\Element\TableAlignment; /** * Table style writer * * @since 0.10.0 */ class Table extends AbstractStyle { /** * @var int Table width */ private $width; /** * Write style. */ public function write() { $style = $this->getStyle(); $xmlWriter = $this->getXmlWriter(); if ($style instanceof TableStyle) { $this->writeStyle($xmlWriter, $style); } elseif (is_string($style)) { $xmlWriter->startElement('w:tblPr'); $xmlWriter->startElement('w:tblStyle'); $xmlWriter->writeAttribute('w:val', $style); $xmlWriter->endElement(); if (null !== $this->width) { $this->writeTblWidth($xmlWriter, 'w:tblW', TblWidth::PERCENT, $this->width); } $xmlWriter->endElement(); } } /** * Write full style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeStyle(XMLWriter $xmlWriter, TableStyle $style) { // w:tblPr $xmlWriter->startElement('w:tblPr'); // Table alignment if ('' !== $style->getAlignment()) { $tableAlignment = new TableAlignment($style->getAlignment()); $xmlWriter->startElement($tableAlignment->getName()); foreach ($tableAlignment->getAttributes() as $attributeName => $attributeValue) { $xmlWriter->writeAttribute($attributeName, $attributeValue); } $xmlWriter->endElement(); } $this->writeTblWidth($xmlWriter, 'w:tblW', $style->getUnit(), $style->getWidth()); $this->writeTblWidth($xmlWriter, 'w:tblCellSpacing', TblWidth::TWIP, $style->getCellSpacing()); $this->writeIndent($xmlWriter, $style); $this->writeLayout($xmlWriter, $style->getLayout()); // Position $styleWriter = new TablePosition($xmlWriter, $style->getPosition()); $styleWriter->write(); //Right to left $xmlWriter->writeElementIf($style->isBidiVisual() !== null, 'w:bidiVisual', 'w:val', $this->writeOnOf($style->isBidiVisual())); $this->writeMargin($xmlWriter, $style); $this->writeBorder($xmlWriter, $style); $xmlWriter->endElement(); // w:tblPr $this->writeShading($xmlWriter, $style); // First row style $firstRow = $style->getFirstRow(); if ($firstRow instanceof TableStyle) { $this->writeFirstRow($xmlWriter, $firstRow); } } /** * Enable/Disable automatic resizing of the table * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $layout autofit / fixed */ private function writeLayout(XMLWriter $xmlWriter, $layout) { $xmlWriter->startElement('w:tblLayout'); $xmlWriter->writeAttribute('w:type', $layout); $xmlWriter->endElement(); // w:tblLayout } /** * Write margin. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeMargin(XMLWriter $xmlWriter, TableStyle $style) { if ($style->hasMargin()) { $xmlWriter->startElement('w:tblCellMar'); $styleWriter = new MarginBorder($xmlWriter); $styleWriter->setSizes($style->getCellMargin()); $styleWriter->write(); $xmlWriter->endElement(); // w:tblCellMar } } /** * Write border. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeBorder(XMLWriter $xmlWriter, TableStyle $style) { if ($style->hasBorder()) { $xmlWriter->startElement('w:tblBorders'); $styleWriter = new MarginBorder($xmlWriter); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setColors($style->getBorderColor()); $styleWriter->write(); $xmlWriter->endElement(); // w:tblBorders } } /** * Writes a table width * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $elementName * @param string $unit * @param int|float $width */ private function writeTblWidth(XMLWriter $xmlWriter, $elementName, $unit, $width = null) { if (null === $width) { return; } $xmlWriter->startElement($elementName); $xmlWriter->writeAttributeIf(null !== $width, 'w:w', $width); $xmlWriter->writeAttribute('w:type', $unit); $xmlWriter->endElement(); } /** * Write row style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeFirstRow(XMLWriter $xmlWriter, TableStyle $style) { $xmlWriter->startElement('w:tblStylePr'); $xmlWriter->writeAttribute('w:type', 'firstRow'); $xmlWriter->startElement('w:tcPr'); $this->writeBorder($xmlWriter, $style); $this->writeShading($xmlWriter, $style); $xmlWriter->endElement(); // w:tcPr $xmlWriter->endElement(); // w:tblStylePr } /** * Write shading. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeShading(XMLWriter $xmlWriter, TableStyle $style) { if (null !== $style->getShading()) { $xmlWriter->startElement('w:tcPr'); $styleWriter = new Shading($xmlWriter, $style->getShading()); $styleWriter->write(); $xmlWriter->endElement(); } } /** * Set width. * * @param int $value */ public function setWidth($value = null) { $this->width = $value; } /** * @param XMLWriter $xmlWriter * @param TableStyle $style */ private function writeIndent(XMLWriter $xmlWriter, TableStyle $style) { $indent = $style->getIndent(); if ($indent === null) { return; } $this->writeTblWidth($xmlWriter, 'w:tblInd', $indent->getType(), $indent->getValue()); } } phpword/src/PhpWord/Writer/Word2007/Style/TablePosition.php 0000664 00000003554 15177100670 0017503 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * TablePosition style writer */ class TablePosition extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\TablePosition) { return; } $values = array(); $properties = array( 'leftFromText', 'rightFromText', 'topFromText', 'bottomFromText', 'vertAnchor', 'horzAnchor', 'tblpXSpec', 'tblpX', 'tblpYSpec', 'tblpY', ); foreach ($properties as $property) { $method = 'get' . $property; if (method_exists($style, $method)) { $values[$property] = $style->$method(); } } $values = array_filter($values); if ($values) { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:tblpPr'); foreach ($values as $property => $value) { $xmlWriter->writeAttribute('w:' . $property, $value); } $xmlWriter->endElement(); } } } phpword/src/PhpWord/Writer/Word2007/Style/Shading.php 0000664 00000002650 15177100670 0016300 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Shading style writer * * @since 0.10.0 */ class Shading extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Shading) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:shd'); $xmlWriter->writeAttributeIf(!is_null($style->getPattern()), 'w:val', $style->getPattern()); $xmlWriter->writeAttributeIf(!is_null($style->getColor()), 'w:color', $style->getColor()); $xmlWriter->writeAttributeIf(!is_null($style->getFill()), 'w:fill', $style->getFill()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/LineNumbering.php 0000664 00000003002 15177100670 0017451 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Line numbering style writer * * @since 0.10.0 */ class LineNumbering extends AbstractStyle { /** * Write style. * The w:start seems to be zero based so we have to decrement by one */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\LineNumbering) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:lnNumType'); $xmlWriter->writeAttribute('w:start', $style->getStart() - 1); $xmlWriter->writeAttribute('w:countBy', $style->getIncrement()); $xmlWriter->writeAttribute('w:distance', $style->getDistance()); $xmlWriter->writeAttribute('w:restart', $style->getRestart()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Line.php 0000664 00000004661 15177100670 0015616 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Style\Line as LineStyle; /** * Line style writer */ class Line extends Frame { /** * Write Line stroke. * @todo Merge with `Stroke` style */ public function writeStroke() { $xmlWriter = $this->getXmlWriter(); $style = $this->getStyle(); if (!$style instanceof LineStyle) { return; } $dash = $style->getDash(); $dashStyles = array( LineStyle::DASH_STYLE_DASH => 'dash', LineStyle::DASH_STYLE_ROUND_DOT => '1 1', LineStyle::DASH_STYLE_SQUARE_DOT => '1 1', LineStyle::DASH_STYLE_DASH_DOT => 'dashDot', LineStyle::DASH_STYLE_LONG_DASH => 'longDash', LineStyle::DASH_STYLE_LONG_DASH_DOT => 'longDashDot', LineStyle::DASH_STYLE_LONG_DASH_DOT_DOT => 'longDashDotDot', ); $xmlWriter->startElement('v:stroke'); $xmlWriter->writeAttributeIf($style->getWeight() !== null, 'weight', $style->getWeight() . 'pt'); $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); $xmlWriter->writeAttributeIf($style->getBeginArrow() !== null, 'startarrow', $style->getBeginArrow()); $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow()); if ($dash !== null) { if (isset($dashStyles[$dash])) { $xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]); } if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) { $xmlWriter->writeAttribute('endcap', 'round'); } } $xmlWriter->endElement(); //v:stroke } } phpword/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php 0000664 00000007331 15177100670 0017510 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Style writer * * @since 0.10.0 */ abstract class AbstractStyle { /** * XML writer * * @var \PhpOffice\PhpWord\Shared\XMLWriter */ private $xmlWriter; /** * Style; set protected for a while * * @var string|\PhpOffice\PhpWord\Style\AbstractStyle */ protected $style; /** * Write style */ abstract public function write(); /** * Create new instance. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style */ public function __construct(XMLWriter $xmlWriter, $style = null) { $this->xmlWriter = $xmlWriter; $this->style = $style; } /** * Get XML Writer * * @return \PhpOffice\PhpWord\Shared\XMLWriter */ protected function getXmlWriter() { return $this->xmlWriter; } /** * Get Style * * @return string|\PhpOffice\PhpWord\Style\AbstractStyle */ protected function getStyle() { return $this->style; } /** * Convert twip value * * @param int|float $value * @param int $default (int|float) * @return int|float */ protected function convertTwip($value, $default = 0) { $factors = array( Settings::UNIT_CM => 567, Settings::UNIT_MM => 56.7, Settings::UNIT_INCH => 1440, Settings::UNIT_POINT => 20, Settings::UNIT_PICA => 240, ); $unit = Settings::getMeasurementUnit(); $factor = 1; if (array_key_exists($unit, $factors) && $value != $default) { $factor = $factors[$unit]; } return $value * $factor; } /** * Write child style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $name * @param mixed $value */ protected function writeChildStyle(XMLWriter $xmlWriter, $name, $value) { if ($value !== null) { $class = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\' . $name; /** @var \PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle $writer */ $writer = new $class($xmlWriter, $value); $writer->write(); } } /** * Writes boolean as 0 or 1 * * @param bool $value * @return null|string */ protected function writeOnOf($value = null) { if ($value === null) { return null; } return $value ? '1' : '0'; } /** * Assemble style array into style string * * @param array $styles * @return string */ protected function assembleStyle($styles = array()) { $style = ''; foreach ($styles as $key => $value) { if (!is_null($value) && $value != '') { $style .= "{$key}:{$value}; "; } } return trim($style); } } phpword/src/PhpWord/Writer/Word2007/Style/Row.php 0000664 00000003475 15177100670 0015500 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Row style writer * * @since 0.11.0 */ class Row extends AbstractStyle { /** * @var int Row height */ private $height; /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Row) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:trPr'); if ($this->height !== null) { $xmlWriter->startElement('w:trHeight'); $xmlWriter->writeAttribute('w:val', $this->height); $xmlWriter->writeAttribute('w:hRule', ($style->isExactHeight() ? 'exact' : 'atLeast')); $xmlWriter->endElement(); } $xmlWriter->writeElementIf($style->isTblHeader(), 'w:tblHeader', 'w:val', '1'); $xmlWriter->writeElementIf($style->isCantSplit(), 'w:cantSplit', 'w:val', '1'); $xmlWriter->endElement(); // w:trPr } /** * Set height. * * @param int $value */ public function setHeight($value = null) { $this->height = $value; } } phpword/src/PhpWord/Writer/Word2007/Style/Spacing.php 0000664 00000003613 15177100670 0016307 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Spacing between lines and above/below paragraph style writer * * @since 0.10.0 */ class Spacing extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Spacing) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:spacing'); $before = $style->getBefore(); $xmlWriter->writeAttributeIf(!is_null($before), 'w:before', $this->convertTwip($before)); $after = $style->getAfter(); $xmlWriter->writeAttributeIf(!is_null($after), 'w:after', $this->convertTwip($after)); $line = $style->getLine(); //if linerule is auto, the spacing is supposed to include the height of the line itself, which is 240 twips if (null !== $line && 'auto' === $style->getLineRule()) { $line += \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT; } $xmlWriter->writeAttributeIf(!is_null($line), 'w:line', $line); $xmlWriter->writeAttributeIf(!is_null($line), 'w:lineRule', $style->getLineRule()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Cell.php 0000664 00000006112 15177100670 0015577 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Style\Cell as CellStyle; /** * Cell style writer * * @since 0.10.0 */ class Cell extends AbstractStyle { /** * @var int Cell width */ private $width; /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof CellStyle) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:tcPr'); // Width if (!is_null($this->width) || !is_null($style->getWidth())) { $width = is_null($this->width) ? $style->getWidth() : $this->width; $xmlWriter->startElement('w:tcW'); $xmlWriter->writeAttribute('w:w', $width); $xmlWriter->writeAttribute('w:type', $style->getUnit()); $xmlWriter->endElement(); // w:tcW } // Text direction $textDir = $style->getTextDirection(); $xmlWriter->writeElementIf(!is_null($textDir), 'w:textDirection', 'w:val', $textDir); // Vertical alignment $vAlign = $style->getVAlign(); $xmlWriter->writeElementIf(!is_null($vAlign), 'w:vAlign', 'w:val', $vAlign); // Border if ($style->hasBorder()) { $xmlWriter->startElement('w:tcBorders'); $styleWriter = new MarginBorder($xmlWriter); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setColors($style->getBorderColor()); $styleWriter->setStyles($style->getBorderStyle()); $styleWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR)); $styleWriter->write(); $xmlWriter->endElement(); } // Shading $shading = $style->getShading(); if (!is_null($shading)) { $styleWriter = new Shading($xmlWriter, $shading); $styleWriter->write(); } // Colspan & rowspan $gridSpan = $style->getGridSpan(); $vMerge = $style->getVMerge(); $xmlWriter->writeElementIf(!is_null($gridSpan), 'w:gridSpan', 'w:val', $gridSpan); $xmlWriter->writeElementIf(!is_null($vMerge), 'w:vMerge', 'w:val', $vMerge); $xmlWriter->endElement(); // w:tcPr } /** * Set width. * * @param int $value */ public function setWidth($value = null) { $this->width = $value; } } phpword/src/PhpWord/Writer/Word2007/Style/Shape.php 0000664 00000002463 15177100670 0015765 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Shape style writer * * @since 0.12.0 */ class Shape extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Shape) { return; } $xmlWriter = $this->getXmlWriter(); $childStyles = array('Frame', 'Fill', 'Outline', 'Shadow', 'Extrusion'); foreach ($childStyles as $childStyle) { $method = "get{$childStyle}"; $this->writeChildStyle($xmlWriter, $childStyle, $style->$method()); } } } phpword/src/PhpWord/Writer/Word2007/Style/MarginBorder.php 0000664 00000007233 15177100670 0017300 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Margin border style writer * * @since 0.10.0 */ class MarginBorder extends AbstractStyle { /** * Sizes * * @var int[] */ private $sizes = array(); /** * Colors * * @var string[] */ private $colors = array(); /** * Border styles * * @var string[] */ private $styles = array(); /** * Other attributes * * @var array */ private $attributes = array(); /** * Write style. */ public function write() { $xmlWriter = $this->getXmlWriter(); $sides = array('top', 'left', 'right', 'bottom', 'insideH', 'insideV'); foreach ($this->sizes as $i => $size) { if ($size !== null) { $color = null; if (isset($this->colors[$i])) { $color = $this->colors[$i]; } $style = isset($this->styles[$i]) ? $this->styles[$i] : 'single'; $this->writeSide($xmlWriter, $sides[$i], $this->sizes[$i], $color, $style); } } } /** * Write side. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $side * @param int $width * @param string $color * @param string $borderStyle */ private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null, $borderStyle = 'solid') { $xmlWriter->startElement('w:' . $side); if (!empty($this->colors)) { if ($color === null && !empty($this->attributes)) { if (isset($this->attributes['defaultColor'])) { $color = $this->attributes['defaultColor']; } } $xmlWriter->writeAttribute('w:val', $borderStyle); $xmlWriter->writeAttribute('w:sz', $width); $xmlWriter->writeAttributeIf($color != null, 'w:color', $color); if (!empty($this->attributes)) { if (isset($this->attributes['space'])) { $xmlWriter->writeAttribute('w:space', $this->attributes['space']); } } } else { $xmlWriter->writeAttribute('w:w', $width); $xmlWriter->writeAttribute('w:type', 'dxa'); } $xmlWriter->endElement(); } /** * Set sizes. * * @param int[] $value */ public function setSizes($value) { $this->sizes = $value; } /** * Set colors. * * @param string[] $value */ public function setColors($value) { $this->colors = $value; } /** * Set border styles. * * @param string[] $value */ public function setStyles($value) { $this->styles = $value; } /** * Set attributes. * * @param array $value */ public function setAttributes($value) { $this->attributes = $value; } } phpword/src/PhpWord/Writer/Word2007/Style/Paragraph.php 0000664 00000015162 15177100670 0016632 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; /** * Paragraph style writer * * @since 0.10.0 */ class Paragraph extends AbstractStyle { /** * Without w:pPr * * @var bool */ private $withoutPPR = false; /** * Is inline in element * * @var bool */ private $isInline = false; /** * Write style. */ public function write() { $xmlWriter = $this->getXmlWriter(); $isStyleName = $this->isInline && !is_null($this->style) && is_string($this->style); if ($isStyleName) { if (!$this->withoutPPR) { $xmlWriter->startElement('w:pPr'); } $xmlWriter->startElement('w:pStyle'); $xmlWriter->writeAttribute('w:val', $this->style); $xmlWriter->endElement(); if (!$this->withoutPPR) { $xmlWriter->endElement(); } } else { $this->writeStyle(); } } /** * Write full style. */ private function writeStyle() { $style = $this->getStyle(); if (!$style instanceof ParagraphStyle) { return; } $xmlWriter = $this->getXmlWriter(); $styles = $style->getStyleValues(); if (!$this->withoutPPR) { $xmlWriter->startElement('w:pPr'); } // Style name if ($this->isInline === true) { $xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']); } // Pagination $xmlWriter->writeElementIf($styles['pagination']['widowControl'] === false, 'w:widowControl', 'w:val', '0'); $xmlWriter->writeElementIf($styles['pagination']['keepNext'] === true, 'w:keepNext', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['keepLines'] === true, 'w:keepLines', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['pageBreak'] === true, 'w:pageBreakBefore', 'w:val', '1'); // Paragraph alignment if ('' !== $styles['alignment']) { $paragraphAlignment = new ParagraphAlignment($styles['alignment']); $xmlWriter->startElement($paragraphAlignment->getName()); foreach ($paragraphAlignment->getAttributes() as $attributeName => $attributeValue) { $xmlWriter->writeAttribute($attributeName, $attributeValue); } $xmlWriter->endElement(); } //Right to left $xmlWriter->writeElementIf($styles['bidi'] === true, 'w:bidi'); //Paragraph contextualSpacing $xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing'); //Paragraph textAlignment $xmlWriter->writeElementIf($styles['textAlignment'] !== null, 'w:textAlignment', 'w:val', $styles['textAlignment']); // Hyphenation $xmlWriter->writeElementIf($styles['suppressAutoHyphens'] === true, 'w:suppressAutoHyphens'); // Child style: alignment, indentation, spacing, and shading $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']); $this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']); $this->writeChildStyle($xmlWriter, 'Shading', $styles['shading']); // Tabs $this->writeTabs($xmlWriter, $styles['tabs']); // Numbering $this->writeNumbering($xmlWriter, $styles['numbering']); // Border if ($style->hasBorder()) { $xmlWriter->startElement('w:pBdr'); $styleWriter = new MarginBorder($xmlWriter); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setStyles($style->getBorderStyle()); $styleWriter->setColors($style->getBorderColor()); $styleWriter->write(); $xmlWriter->endElement(); } if (!$this->withoutPPR) { $xmlWriter->endElement(); // w:pPr } } /** * Write tabs. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Tab[] $tabs */ private function writeTabs(XMLWriter $xmlWriter, $tabs) { if (!empty($tabs)) { $xmlWriter->startElement('w:tabs'); foreach ($tabs as $tab) { $styleWriter = new Tab($xmlWriter, $tab); $styleWriter->write(); } $xmlWriter->endElement(); } } /** * Write numbering. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param array $numbering */ private function writeNumbering(XMLWriter $xmlWriter, $numbering) { $numStyle = $numbering['style']; $numLevel = $numbering['level']; /** @var \PhpOffice\PhpWord\Style\Numbering $numbering */ $numbering = Style::getStyle($numStyle); if ($numStyle !== null && $numbering !== null) { $xmlWriter->startElement('w:numPr'); $xmlWriter->startElement('w:numId'); $xmlWriter->writeAttribute('w:val', $numbering->getIndex()); $xmlWriter->endElement(); // w:numId $xmlWriter->startElement('w:ilvl'); $xmlWriter->writeAttribute('w:val', $numLevel); $xmlWriter->endElement(); // w:ilvl $xmlWriter->endElement(); // w:numPr $xmlWriter->startElement('w:outlineLvl'); $xmlWriter->writeAttribute('w:val', $numLevel); $xmlWriter->endElement(); // w:outlineLvl } } /** * Set without w:pPr. * * @param bool $value */ public function setWithoutPPR($value) { $this->withoutPPR = $value; } /** * Set is inline. * * @param bool $value */ public function setIsInline($value) { $this->isInline = $value; } } phpword/src/PhpWord/Writer/Word2007/Style/Indentation.php 0000664 00000003154 15177100670 0017177 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Paragraph indentation style writer * * @since 0.10.0 */ class Indentation extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:ind'); $xmlWriter->writeAttribute('w:left', $this->convertTwip($style->getLeft())); $xmlWriter->writeAttribute('w:right', $this->convertTwip($style->getRight())); $firstLine = $style->getFirstLine(); $xmlWriter->writeAttributeIf(!is_null($firstLine), 'w:firstLine', $this->convertTwip($firstLine)); $hanging = $style->getHanging(); $xmlWriter->writeAttributeIf(!is_null($hanging), 'w:hanging', $this->convertTwip($hanging)); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Font.php 0000664 00000015567 15177100670 0015644 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Font style writer * * @since 0.10.0 */ class Font extends AbstractStyle { /** * Is inline in element * * @var bool */ private $isInline = false; /** * Write style. */ public function write() { $xmlWriter = $this->getXmlWriter(); $isStyleName = $this->isInline && !is_null($this->style) && is_string($this->style); if ($isStyleName) { $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rStyle'); $xmlWriter->writeAttribute('w:val', $this->style); $xmlWriter->endElement(); $style = \PhpOffice\PhpWord\Style::getStyle($this->style); if ($style instanceof \PhpOffice\PhpWord\Style\Font) { $xmlWriter->writeElementIf($style->isRTL(), 'w:rtl'); } $xmlWriter->endElement(); } else { $this->writeStyle(); } } /** * Write full style. */ private function writeStyle() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:rPr'); // Style name if ($this->isInline === true) { $styleName = $style->getStyleName(); $xmlWriter->writeElementIf($styleName !== null, 'w:rStyle', 'w:val', $styleName); } // Font name/family $font = $style->getName(); $hint = $style->getHint(); if ($font !== null) { $xmlWriter->startElement('w:rFonts'); $xmlWriter->writeAttribute('w:ascii', $font); $xmlWriter->writeAttribute('w:hAnsi', $font); $xmlWriter->writeAttribute('w:eastAsia', $font); $xmlWriter->writeAttribute('w:cs', $font); $xmlWriter->writeAttributeIf($hint !== null, 'w:hint', $hint); $xmlWriter->endElement(); } //Language $language = $style->getLang(); if ($language != null && ($language->getLatin() !== null || $language->getEastAsia() !== null || $language->getBidirectional() !== null)) { $xmlWriter->startElement('w:lang'); $xmlWriter->writeAttributeIf($language->getLatin() !== null, 'w:val', $language->getLatin()); $xmlWriter->writeAttributeIf($language->getEastAsia() !== null, 'w:eastAsia', $language->getEastAsia()); $xmlWriter->writeAttributeIf($language->getBidirectional() !== null, 'w:bidi', $language->getBidirectional()); //if bidi is not set but we are writing RTL, write the latin language in the bidi tag if ($style->isRTL() && $language->getBidirectional() === null && $language->getLatin() !== null) { $xmlWriter->writeAttribute('w:bidi', $language->getLatin()); } $xmlWriter->endElement(); } // Color $color = $style->getColor(); $xmlWriter->writeElementIf($color !== null, 'w:color', 'w:val', $color); // Size $size = $style->getSize(); $xmlWriter->writeElementIf($size !== null, 'w:sz', 'w:val', $size * 2); $xmlWriter->writeElementIf($size !== null, 'w:szCs', 'w:val', $size * 2); // Bold, italic $xmlWriter->writeElementIf($style->isBold() !== null, 'w:b', 'w:val', $this->writeOnOf($style->isBold())); $xmlWriter->writeElementIf($style->isBold() !== null, 'w:bCs', 'w:val', $this->writeOnOf($style->isBold())); $xmlWriter->writeElementIf($style->isItalic() !== null, 'w:i', 'w:val', $this->writeOnOf($style->isItalic())); $xmlWriter->writeElementIf($style->isItalic() !== null, 'w:iCs', 'w:val', $this->writeOnOf($style->isItalic())); // Strikethrough, double strikethrough $xmlWriter->writeElementIf($style->isStrikethrough() !== null, 'w:strike', 'w:val', $this->writeOnOf($style->isStrikethrough())); $xmlWriter->writeElementIf($style->isDoubleStrikethrough() !== null, 'w:dstrike', 'w:val', $this->writeOnOf($style->isDoubleStrikethrough())); // Small caps, all caps $xmlWriter->writeElementIf($style->isSmallCaps() !== null, 'w:smallCaps', 'w:val', $this->writeOnOf($style->isSmallCaps())); $xmlWriter->writeElementIf($style->isAllCaps() !== null, 'w:caps', 'w:val', $this->writeOnOf($style->isAllCaps())); //Hidden text $xmlWriter->writeElementIf($style->isHidden(), 'w:vanish', 'w:val', $this->writeOnOf($style->isHidden())); // Underline $xmlWriter->writeElementIf($style->getUnderline() != 'none', 'w:u', 'w:val', $style->getUnderline()); // Foreground-Color $xmlWriter->writeElementIf($style->getFgColor() !== null, 'w:highlight', 'w:val', $style->getFgColor()); // Superscript/subscript $xmlWriter->writeElementIf($style->isSuperScript(), 'w:vertAlign', 'w:val', 'superscript'); $xmlWriter->writeElementIf($style->isSubScript(), 'w:vertAlign', 'w:val', 'subscript'); // Spacing $xmlWriter->writeElementIf($style->getScale() !== null, 'w:w', 'w:val', $style->getScale()); $xmlWriter->writeElementIf($style->getSpacing() !== null, 'w:spacing', 'w:val', $style->getSpacing()); $xmlWriter->writeElementIf($style->getKerning() !== null, 'w:kern', 'w:val', $style->getKerning() * 2); // noProof $xmlWriter->writeElementIf($style->isNoProof() !== null, 'w:noProof', 'w:val', $this->writeOnOf($style->isNoProof())); // Background-Color $shading = $style->getShading(); if (!is_null($shading)) { $styleWriter = new Shading($xmlWriter, $shading); $styleWriter->write(); } // RTL if ($this->isInline === true) { $styleName = $style->getStyleName(); $xmlWriter->writeElementIf($styleName === null && $style->isRTL(), 'w:rtl'); } // Position $xmlWriter->writeElementIf($style->getPosition() !== null, 'w:position', 'w:val', $style->getPosition()); $xmlWriter->endElement(); } /** * Set is inline. * * @param bool $value */ public function setIsInline($value) { $this->isInline = $value; } } phpword/src/PhpWord/Writer/Word2007/Style/Outline.php 0000664 00000003610 15177100670 0016337 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Outline style writer * * @since 0.12.0 */ class Outline extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Outline) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('v:stroke'); $xmlWriter->writeAttribute('on', 't'); $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); $xmlWriter->writeAttributeIf($style->getWeight() !== null, 'weight', $style->getWeight() . $style->getUnit()); $xmlWriter->writeAttributeIf($style->getDash() !== null, 'dashstyle', $style->getDash()); $xmlWriter->writeAttributeIf($style->getLine() !== null, 'linestyle', $style->getLine()); $xmlWriter->writeAttributeIf($style->getEndCap() !== null, 'endcap', $style->getEndCap()); $xmlWriter->writeAttributeIf($style->getStartArrow() !== null, 'startarrow', $style->getStartArrow()); $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Image.php 0000664 00000001451 15177100670 0015743 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Image style writer * * @since 0.10.0 */ class Image extends Frame { } phpword/src/PhpWord/Writer/Word2007/Style/Fill.php 0000664 00000002275 15177100670 0015614 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Fill style writer * * @since 0.12.0 */ class Fill extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Fill) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->writeAttribute('on', 't'); $xmlWriter->writeAttributeIf($style->getColor() !== null, 'fillcolor', $style->getColor()); } } phpword/src/PhpWord/Writer/Word2007/Style/TextBox.php 0000664 00000003437 15177100670 0016324 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle; /** * TextBox style writer * * @since 0.11.0 */ class TextBox extends Frame { /** * Writer inner margin. */ public function writeInnerMargin() { $style = $this->getStyle(); if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) { return; } $xmlWriter = $this->getXmlWriter(); $margins = implode(', ', $style->getInnerMargin()); $xmlWriter->writeAttribute('inset', $margins); } /** * Writer border. */ public function writeBorder() { $style = $this->getStyle(); if (!$style instanceof TextBoxStyle) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('v:stroke'); $xmlWriter->writeAttributeIf($style->getBorderSize() !== null, 'weight', $style->getBorderSize() . 'pt'); $xmlWriter->writeAttributeIf($style->getBorderColor() !== null, 'color', $style->getBorderColor()); $xmlWriter->endElement(); // v:stroke } } phpword/src/PhpWord/Writer/Word2007/Style/Shadow.php 0000664 00000002562 15177100670 0016152 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Shadow style writer * * @since 0.12.0 */ class Shadow extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Shadow) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('v:shadow'); $xmlWriter->writeAttribute('on', 't'); $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); $xmlWriter->writeAttributeIf($style->getOffset() !== null, 'offset', $style->getOffset()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Extrusion.php 0000664 00000002573 15177100670 0016727 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * 3D extrusion style writer * * @since 0.12.0 */ class Extrusion extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Extrusion) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('o:extrusion'); $xmlWriter->writeAttribute('on', 't'); $xmlWriter->writeAttributeIf($style->getType() !== null, 'type', $style->getType()); $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Tab.php 0000664 00000002534 15177100670 0015432 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; /** * Line numbering style writer * * @since 0.10.0 */ class Tab extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:tab'); $xmlWriter->writeAttribute('w:val', $style->getType()); $xmlWriter->writeAttribute('w:leader', $style->getLeader()); $xmlWriter->writeAttribute('w:pos', $this->convertTwip($style->getPosition())); $xmlWriter->endElement(); } } phpword/src/PhpWord/Writer/Word2007/Style/Section.php 0000664 00000007355 15177100670 0016336 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Style\Section as SectionStyle; /** * Section style writer * * @since 0.10.0 */ class Section extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof SectionStyle) { return; } $xmlWriter = $this->getXmlWriter(); // Break type $breakType = $style->getBreakType(); $xmlWriter->writeElementIf(!is_null($breakType), 'w:type', 'w:val', $breakType); // Page size & orientation $xmlWriter->startElement('w:pgSz'); $xmlWriter->writeAttribute('w:orient', $style->getOrientation()); $xmlWriter->writeAttribute('w:w', $style->getPageSizeW()); $xmlWriter->writeAttribute('w:h', $style->getPageSizeH()); $xmlWriter->endElement(); // w:pgSz // Vertical alignment $vAlign = $style->getVAlign(); $xmlWriter->writeElementIf(!is_null($vAlign), 'w:vAlign', 'w:val', $vAlign); // Margins $margins = array( 'w:top' => array('getMarginTop', SectionStyle::DEFAULT_MARGIN), 'w:right' => array('getMarginRight', SectionStyle::DEFAULT_MARGIN), 'w:bottom' => array('getMarginBottom', SectionStyle::DEFAULT_MARGIN), 'w:left' => array('getMarginLeft', SectionStyle::DEFAULT_MARGIN), 'w:header' => array('getHeaderHeight', SectionStyle::DEFAULT_HEADER_HEIGHT), 'w:footer' => array('getFooterHeight', SectionStyle::DEFAULT_FOOTER_HEIGHT), 'w:gutter' => array('getGutter', SectionStyle::DEFAULT_GUTTER), ); $xmlWriter->startElement('w:pgMar'); foreach ($margins as $attribute => $value) { list($method, $default) = $value; $xmlWriter->writeAttribute($attribute, $this->convertTwip($style->$method(), $default)); } $xmlWriter->endElement(); // Borders if ($style->hasBorder()) { $xmlWriter->startElement('w:pgBorders'); $xmlWriter->writeAttribute('w:offsetFrom', 'page'); $styleWriter = new MarginBorder($xmlWriter); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setColors($style->getBorderColor()); $styleWriter->setAttributes(array('space' => '24')); $styleWriter->write(); $xmlWriter->endElement(); } // Columns $colsSpace = $style->getColsSpace(); $xmlWriter->startElement('w:cols'); $xmlWriter->writeAttribute('w:num', $style->getColsNum()); $xmlWriter->writeAttribute('w:space', $this->convertTwip($colsSpace, SectionStyle::DEFAULT_COLUMN_SPACING)); $xmlWriter->endElement(); // Page numbering start $pageNum = $style->getPageNumberingStart(); $xmlWriter->writeElementIf(!is_null($pageNum), 'w:pgNumType', 'w:start', $pageNum); // Line numbering $styleWriter = new LineNumbering($xmlWriter, $style->getLineNumbering()); $styleWriter->write(); } } phpword/src/PhpWord/Writer/Word2007/Style/Frame.php 0000664 00000013126 15177100670 0015755 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Frame as FrameStyle; use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; /** * Frame style writer * * @since 0.12.0 */ class Frame extends AbstractStyle { const PHP_32BIT_INT_MAX = 2147483647; /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof FrameStyle) { return; } $xmlWriter = $this->getXmlWriter(); $maxZIndex = min(PHP_INT_MAX, self::PHP_32BIT_INT_MAX); $zIndices = array(FrameStyle::WRAP_INFRONT => $maxZIndex, FrameStyle::WRAP_BEHIND => -$maxZIndex); $properties = array( 'width' => 'width', 'height' => 'height', 'left' => 'margin-left', 'top' => 'margin-top', 'wrapDistanceTop' => 'mso-wrap-distance-top', 'wrapDistanceBottom' => 'mso-wrap-distance-bottom', 'wrapDistanceLeft' => 'mso-wrap-distance-left', 'wrapDistanceRight' => 'mso-wrap-distance-right', ); $sizeStyles = $this->getStyles($style, $properties, $style->getUnit()); $properties = array( 'pos' => 'position', 'hPos' => 'mso-position-horizontal', 'vPos' => 'mso-position-vertical', 'hPosRelTo' => 'mso-position-horizontal-relative', 'vPosRelTo' => 'mso-position-vertical-relative', ); $posStyles = $this->getStyles($style, $properties); $styles = array_merge($sizeStyles, $posStyles); // zIndex for infront & behind wrap $wrap = $style->getWrap(); if ($wrap !== null && isset($zIndices[$wrap])) { $styles['z-index'] = $zIndices[$wrap]; $wrap = null; } // Style attribute $xmlWriter->writeAttribute('style', $this->assembleStyle($styles)); $this->writeWrap($xmlWriter, $style, $wrap); } /** * Write alignment. */ public function writeAlignment() { $style = $this->getStyle(); if (!$style instanceof FrameStyle) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:pPr'); if ('' !== $style->getAlignment()) { $paragraphAlignment = new ParagraphAlignment($style->getAlignment()); $xmlWriter->startElement($paragraphAlignment->getName()); foreach ($paragraphAlignment->getAttributes() as $attributeName => $attributeValue) { $xmlWriter->writeAttribute($attributeName, $attributeValue); } $xmlWriter->endElement(); } $xmlWriter->endElement(); } /** * Write wrap. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Frame $style * @param string $wrap */ private function writeWrap(XMLWriter $xmlWriter, FrameStyle $style, $wrap) { if ($wrap !== null) { $xmlWriter->startElement('w10:wrap'); $xmlWriter->writeAttribute('type', $wrap); $relativePositions = array( FrameStyle::POS_RELTO_MARGIN => 'margin', FrameStyle::POS_RELTO_PAGE => 'page', FrameStyle::POS_RELTO_TMARGIN => 'margin', FrameStyle::POS_RELTO_BMARGIN => 'page', FrameStyle::POS_RELTO_LMARGIN => 'margin', FrameStyle::POS_RELTO_RMARGIN => 'page', ); $pos = $style->getPos(); $hPos = $style->getHPosRelTo(); $vPos = $style->getVPosRelTo(); if ($pos == FrameStyle::POS_ABSOLUTE) { $xmlWriter->writeAttribute('anchorx', 'page'); $xmlWriter->writeAttribute('anchory', 'page'); } elseif ($pos == FrameStyle::POS_RELATIVE) { if (isset($relativePositions[$hPos])) { $xmlWriter->writeAttribute('anchorx', $relativePositions[$hPos]); } if (isset($relativePositions[$vPos])) { $xmlWriter->writeAttribute('anchory', $relativePositions[$vPos]); } } $xmlWriter->endElement(); // w10:wrap } } /** * Get style values in associative array * * @param \PhpOffice\PhpWord\Style\Frame $style * @param array $properties * @param string $suffix * @return array */ private function getStyles(FrameStyle $style, $properties, $suffix = '') { $styles = array(); foreach ($properties as $key => $property) { $method = "get{$key}"; $value = $style->$method(); if ($value !== null) { $styles[$property] = $style->$method() . $suffix; } } return $styles; } } phpword/src/PhpWord/Writer/Word2007/Part/Chart.php 0000664 00000041450 15177100670 0015573 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Element\Chart as ChartElement; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Word2007 chart part writer: word/charts/chartx.xml * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/e-draw-chart_chartSpace.html */ class Chart extends AbstractPart { /** * Chart element * * @var \PhpOffice\PhpWord\Element\Chart */ private $element; /** * Type definition * * @var array */ private $types = array( 'pie' => array('type' => 'pie', 'colors' => 1), 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), 'percent_stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'percentStacked'), 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), 'percent_stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'percentStacked'), 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), ); /** * Chart options * * @var array */ private $options = array(); /** * Set chart element. * * @param \PhpOffice\PhpWord\Element\Chart $element */ public function setElement(ChartElement $element) { $this->element = $element; } /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('c:chartSpace'); $xmlWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); $xmlWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $this->writeChart($xmlWriter); $this->writeShape($xmlWriter); $xmlWriter->endElement(); // c:chartSpace return $xmlWriter->getData(); } /** * Write chart * * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_Chart.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writeChart(XMLWriter $xmlWriter) { $xmlWriter->startElement('c:chart'); $this->writePlotArea($xmlWriter); $xmlWriter->endElement(); // c:chart } /** * Write plot area. * * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_PlotArea.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_PieChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_DoughnutChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_BarChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_LineChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_AreaChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_RadarChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_ScatterChart.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter */ private function writePlotArea(XMLWriter $xmlWriter) { $type = $this->element->getType(); $style = $this->element->getStyle(); $this->options = $this->types[$type]; $title = $style->getTitle(); $showLegend = $style->isShowLegend(); $legendPosition = $style->getLegendPosition(); //Chart title if ($title) { $xmlWriter->startElement('c:title'); $xmlWriter->startElement('c:tx'); $xmlWriter->startElement('c:rich'); $xmlWriter->writeRaw(' <a:bodyPr/> <a:lstStyle/> <a:p> <a:pPr> <a:defRPr/></a:pPr><a:r><a:rPr/><a:t>' . $title . '</a:t></a:r> <a:endParaRPr/> </a:p>'); $xmlWriter->endElement(); // c:rich $xmlWriter->endElement(); // c:tx $xmlWriter->endElement(); // c:title } else { $xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1); } //Chart legend if ($showLegend) { $xmlWriter->writeRaw('<c:legend><c:legendPos val="' . $legendPosition . '"/></c:legend>'); } $xmlWriter->startElement('c:plotArea'); $xmlWriter->writeElement('c:layout'); // Chart $chartType = $this->options['type']; $chartType .= $style->is3d() && !isset($this->options['no3d']) ? '3D' : ''; $chartType .= 'Chart'; $xmlWriter->startElement("c:{$chartType}"); $xmlWriter->writeElementBlock('c:varyColors', 'val', $this->options['colors']); if ($type == 'area') { $xmlWriter->writeElementBlock('c:grouping', 'val', 'standard'); } if (isset($this->options['hole'])) { $xmlWriter->writeElementBlock('c:holeSize', 'val', $this->options['hole']); } if (isset($this->options['bar'])) { $xmlWriter->writeElementBlock('c:barDir', 'val', $this->options['bar']); // bar|col $xmlWriter->writeElementBlock('c:grouping', 'val', $this->options['grouping']); // 3d; standard = percentStacked } if (isset($this->options['radar'])) { $xmlWriter->writeElementBlock('c:radarStyle', 'val', $this->options['radar']); } if (isset($this->options['scatter'])) { $xmlWriter->writeElementBlock('c:scatterStyle', 'val', $this->options['scatter']); } // Series $this->writeSeries($xmlWriter, isset($this->options['scatter'])); // don't overlap if grouping is 'clustered' if (!isset($this->options['grouping']) || $this->options['grouping'] != 'clustered') { $xmlWriter->writeElementBlock('c:overlap', 'val', '100'); } // Axes if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:axId', 'val', 1); $xmlWriter->writeElementBlock('c:axId', 'val', 2); } $xmlWriter->endElement(); // chart type // Axes if (isset($this->options['axes'])) { $this->writeAxis($xmlWriter, 'cat'); $this->writeAxis($xmlWriter, 'val'); } $xmlWriter->endElement(); // c:plotArea } /** * Write series. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param bool $scatter */ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) { $series = $this->element->getSeries(); $style = $this->element->getStyle(); $colors = $style->getColors(); $index = 0; $colorIndex = 0; foreach ($series as $seriesItem) { $categories = $seriesItem['categories']; $values = $seriesItem['values']; $xmlWriter->startElement('c:ser'); $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); if (!is_null($seriesItem['name']) && $seriesItem['name'] != '') { $xmlWriter->startElement('c:tx'); $xmlWriter->startElement('c:strRef'); $xmlWriter->startElement('c:strCache'); $xmlWriter->writeElementBlock('c:ptCount', 'val', 1); $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', 0); $xmlWriter->startElement('c:v'); $xmlWriter->writeRaw($seriesItem['name']); $xmlWriter->endElement(); // c:v $xmlWriter->endElement(); // c:pt $xmlWriter->endElement(); // c:strCache $xmlWriter->endElement(); // c:strRef $xmlWriter->endElement(); // c:tx } // The c:dLbls was added to make word charts look more like the reports in SurveyGizmo // This section needs to be made configurable before a pull request is made $xmlWriter->startElement('c:dLbls'); foreach ($style->getDataLabelOptions() as $option => $val) { $xmlWriter->writeElementBlock("c:{$option}", 'val', (int) $val); } $xmlWriter->endElement(); // c:dLbls if (isset($this->options['scatter'])) { $this->writeShape($xmlWriter); } if ($scatter === true) { $this->writeSeriesItem($xmlWriter, 'xVal', $categories); $this->writeSeriesItem($xmlWriter, 'yVal', $values); } else { $this->writeSeriesItem($xmlWriter, 'cat', $categories); $this->writeSeriesItem($xmlWriter, 'val', $values); // check that there are colors if (is_array($colors) && count($colors) > 0) { // assign a color to each value $valueIndex = 0; for ($i = 0; $i < count($values); $i++) { // check that there are still enought colors $xmlWriter->startElement('c:dPt'); $xmlWriter->writeElementBlock('c:idx', 'val', $valueIndex); $xmlWriter->startElement('c:spPr'); $xmlWriter->startElement('a:solidFill'); $xmlWriter->writeElementBlock('a:srgbClr', 'val', $colors[$colorIndex++ % count($colors)]); $xmlWriter->endElement(); // a:solidFill $xmlWriter->endElement(); // c:spPr $xmlWriter->endElement(); // c:dPt $valueIndex++; } } } $xmlWriter->endElement(); // c:ser $index++; } } /** * Write series items. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $type * @param array $values */ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) { $types = array( 'cat' => array('c:cat', 'c:strLit'), 'val' => array('c:val', 'c:numLit'), 'xVal' => array('c:xVal', 'c:strLit'), 'yVal' => array('c:yVal', 'c:numLit'), ); list($itemType, $itemLit) = $types[$type]; $xmlWriter->startElement($itemType); $xmlWriter->startElement($itemLit); $xmlWriter->writeElementBlock('c:ptCount', 'val', count($values)); $index = 0; foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { $xmlWriter->writeElement('c:v', $value); } else { $xmlWriter->startElement('c:v'); $xmlWriter->writeRaw($value); $xmlWriter->endElement(); // c:v } $xmlWriter->endElement(); // c:pt $index++; } $xmlWriter->endElement(); // $itemLit $xmlWriter->endElement(); // $itemType } /** * Write axis * * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_CatAx.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $type */ private function writeAxis(XMLWriter $xmlWriter, $type) { $style = $this->element->getStyle(); $types = array( 'cat' => array('c:catAx', 1, 'b', 2), 'val' => array('c:valAx', 2, 'l', 1), ); list($axisType, $axisId, $axisPos, $axisCross) = $types[$type]; $xmlWriter->startElement($axisType); $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); $categoryAxisTitle = $style->getCategoryAxisTitle(); $valueAxisTitle = $style->getValueAxisTitle(); if ($axisType == 'c:catAx') { if (!is_null($categoryAxisTitle)) { $this->writeAxisTitle($xmlWriter, $categoryAxisTitle); } } elseif ($axisType == 'c:valAx') { if (!is_null($valueAxisTitle)) { $this->writeAxisTitle($xmlWriter, $valueAxisTitle); } } $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); $xmlWriter->writeElementBlock('c:auto', 'val', 1); if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:delete', 'val', 0); $xmlWriter->writeElementBlock('c:majorTickMark', 'val', $style->getMajorTickPosition()); $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); if ($style->showAxisLabels()) { if ($axisType == 'c:catAx') { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition()); } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); } } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'none'); } $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } if (isset($this->options['radar']) || ($type == 'cat' && $style->showGridX()) || ($type == 'val' && $style->showGridY())) { $xmlWriter->writeElement('c:majorGridlines'); } $xmlWriter->startElement('c:scaling'); $xmlWriter->writeElementBlock('c:orientation', 'val', 'minMax'); $xmlWriter->endElement(); // c:scaling $this->writeShape($xmlWriter, true); $xmlWriter->endElement(); // $axisType } /** * Write shape * * @see http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param bool $line */ private function writeShape(XMLWriter $xmlWriter, $line = false) { $xmlWriter->startElement('c:spPr'); $xmlWriter->startElement('a:ln'); if ($line === true) { $xmlWriter->writeElement('a:solidFill'); } else { $xmlWriter->writeElement('a:noFill'); } $xmlWriter->endElement(); // a:ln $xmlWriter->endElement(); // c:spPr } private function writeAxisTitle(XMLWriter $xmlWriter, $title) { $xmlWriter->startElement('c:title'); //start c:title $xmlWriter->startElement('c:tx'); //start c:tx $xmlWriter->startElement('c:rich'); // start c:rich $xmlWriter->writeElement('a:bodyPr'); $xmlWriter->writeElement('a:lstStyle'); $xmlWriter->startElement('a:p'); $xmlWriter->startElement('a:pPr'); $xmlWriter->writeElement('a:defRPr'); $xmlWriter->endElement(); // end a:pPr $xmlWriter->startElement('a:r'); $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); $xmlWriter->startElement('a:t'); $xmlWriter->writeRaw($title); $xmlWriter->endElement(); //end a:t $xmlWriter->endElement(); // end a:r $xmlWriter->endElement(); //end a:p $xmlWriter->endElement(); //end c:rich $xmlWriter->endElement(); // end c:tx $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); $xmlWriter->endElement(); // end c:title } } phpword/src/PhpWord/Writer/Word2007/Part/WebSettings.php 0000664 00000003143 15177100670 0016765 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 web settings part writer: word/webSettings.xml */ class WebSettings extends Settings { /** * Write part * * @return string */ public function write() { $settings = array( 'w:optimizeForBrowser' => '', ); $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:webSettings'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); foreach ($settings as $settingKey => $settingValue) { $this->writeSetting($xmlWriter, $settingKey, $settingValue); } $xmlWriter->endElement(); // w:settings return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/Word2007/Part/Rels.php 0000664 00000011053 15177100670 0015433 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Word2007 main relationship writer: _rels/.rels * * @since 0.10.0 */ class Rels extends AbstractPart { /** * Write part * * @return string */ public function write() { $xmlRels = array( 'docProps/core.xml' => 'package/2006/relationships/metadata/core-properties', 'docProps/app.xml' => 'officeDocument/2006/relationships/extended-properties', 'docProps/custom.xml' => 'officeDocument/2006/relationships/custom-properties', 'word/document.xml' => 'officeDocument/2006/relationships/officeDocument', ); $xmlWriter = $this->getXmlWriter(); $this->writeRels($xmlWriter, $xmlRels); return $xmlWriter->getData(); } /** * Write relationships. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param array $xmlRels * @param array $mediaRels * @param int $relId */ protected function writeRels(XMLWriter $xmlWriter, $xmlRels = array(), $mediaRels = array(), $relId = 1) { $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('Relationships'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); // XML files relationships foreach ($xmlRels as $target => $type) { $this->writeRel($xmlWriter, $relId++, $type, $target); } // Media relationships foreach ($mediaRels as $mediaRel) { $this->writeMediaRel($xmlWriter, $relId++, $mediaRel); } $xmlWriter->endElement(); // Relationships } /** * Write media relationships. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param int $relId * @param array $mediaRel */ private function writeMediaRel(XMLWriter $xmlWriter, $relId, $mediaRel) { $typePrefix = 'officeDocument/2006/relationships/'; $typeMapping = array('image' => 'image', 'object' => 'oleObject', 'link' => 'hyperlink'); $targetMapping = array('image' => 'media/', 'object' => 'embeddings/'); $mediaType = $mediaRel['type']; $type = isset($typeMapping[$mediaType]) ? $typeMapping[$mediaType] : $mediaType; $targetPrefix = isset($targetMapping[$mediaType]) ? $targetMapping[$mediaType] : ''; $target = $mediaRel['target']; $targetMode = ($type == 'hyperlink') ? 'External' : ''; $this->writeRel($xmlWriter, $relId, $typePrefix . $type, $targetPrefix . $target, $targetMode); } /** * Write individual rels entry. * * Format: * <Relationship Id="rId..." Type="http://..." Target="....xml" TargetMode="..." /> * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param int $relId Relationship ID * @param string $type Relationship type * @param string $target Relationship target * @param string $targetMode Relationship target mode * * @throws \PhpOffice\PhpWord\Exception\Exception */ private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '') { if ($type != '' && $target != '') { if (strpos($relId, 'rId') === false) { $relId = 'rId' . $relId; } $xmlWriter->startElement('Relationship'); $xmlWriter->writeAttribute('Id', $relId); $xmlWriter->writeAttribute('Type', 'http://schemas.openxmlformats.org/' . $type); $xmlWriter->writeAttribute('Target', $target); if ($targetMode != '') { $xmlWriter->writeAttribute('TargetMode', $targetMode); } $xmlWriter->endElement(); } else { throw new Exception('Invalid parameters passed.'); } } } phpword/src/PhpWord/Writer/Word2007/Part/RelsDocument.php 0000664 00000003363 15177100670 0017137 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 document relationship writer: word/_rels/document.xml.rels * * @since 0.11.0 */ class RelsDocument extends Rels { /** * Write part * * @return string */ public function write() { $xmlRels = array( 'styles.xml' => 'officeDocument/2006/relationships/styles', 'numbering.xml' => 'officeDocument/2006/relationships/numbering', 'settings.xml' => 'officeDocument/2006/relationships/settings', 'theme/theme1.xml' => 'officeDocument/2006/relationships/theme', 'webSettings.xml' => 'officeDocument/2006/relationships/webSettings', 'fontTable.xml' => 'officeDocument/2006/relationships/fontTable', ); $xmlWriter = $this->getXmlWriter(); /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships()); return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/Word2007/Part/AbstractPart.php 0000664 00000005704 15177100670 0017126 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\AbstractWriter; /** * Word2007 writer part abstract class */ abstract class AbstractPart { /** * Parent writer * * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ protected $parentWriter; /** * @var string Date format */ protected $dateFormat = 'Y-m-d\TH:i:sP'; /** * Write part * * @return string */ abstract public function write(); /** * Set parent writer. * * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer */ public function setParentWriter(AbstractWriter $writer = null) { $this->parentWriter = $writer; } /** * Get parent writer * * @throws \PhpOffice\PhpWord\Exception\Exception * @return \PhpOffice\PhpWord\Writer\AbstractWriter */ public function getParentWriter() { if (!is_null($this->parentWriter)) { return $this->parentWriter; } throw new Exception('No parent WriterInterface assigned.'); } /** * Get XML Writer * * @return \PhpOffice\PhpWord\Shared\XMLWriter */ protected function getXmlWriter() { $useDiskCaching = false; if (!is_null($this->parentWriter)) { if ($this->parentWriter->isUseDiskCaching()) { $useDiskCaching = true; } } if ($useDiskCaching) { return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory(), Settings::hasCompatibility()); } return new XMLWriter(XMLWriter::STORAGE_MEMORY, './', Settings::hasCompatibility()); } /** * Write an XML text, this will call text() or writeRaw() depending on the value of Settings::isOutputEscapingEnabled() * * @param string $content The text string to write * @return bool Returns true on success or false on failure */ protected function writeText($content) { if (Settings::isOutputEscapingEnabled()) { return $this->getXmlWriter()->text($content); } return $this->getXmlWriter()->writeRaw($content); } } phpword/src/PhpWord/Writer/Word2007/Part/Theme.php 0000664 00000035634 15177100670 0015603 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 theme writer: word/theme/theme1.xml * * @todo Generate content dynamically * @since 0.10.0 */ class Theme extends AbstractPart { /** * Write part * * @return string */ public function write() { $str = ''; $str .= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'; $str .= '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">'; $str .= '<a:themeElements>'; $str .= $this->writeColorScheme(); $str .= $this->writeFontScheme(); $str .= $this->writeFormatScheme(); $str .= '</a:themeElements>'; $str .= '<a:objectDefaults />'; $str .= '<a:extraClrSchemeLst />'; $str .= '</a:theme>'; return $str; } /** * Write color scheme * * @return string */ private function writeColorScheme() { $str = ''; $str .= '<a:clrScheme name="Office">'; $str .= '<a:dk1>'; $str .= '<a:sysClr val="windowText" lastClr="000000" />'; $str .= '</a:dk1>'; $str .= '<a:lt1>'; $str .= '<a:sysClr val="window" lastClr="FFFFFF" />'; $str .= '</a:lt1>'; $str .= '<a:dk2>'; $str .= '<a:srgbClr val="1F497D" />'; $str .= '</a:dk2>'; $str .= '<a:lt2>'; $str .= '<a:srgbClr val="EEECE1" />'; $str .= '</a:lt2>'; $str .= '<a:accent1>'; $str .= '<a:srgbClr val="4F81BD" />'; $str .= '</a:accent1>'; $str .= '<a:accent2>'; $str .= '<a:srgbClr val="C0504D" />'; $str .= '</a:accent2>'; $str .= '<a:accent3>'; $str .= '<a:srgbClr val="9BBB59" />'; $str .= '</a:accent3>'; $str .= '<a:accent4>'; $str .= '<a:srgbClr val="8064A2" />'; $str .= '</a:accent4>'; $str .= '<a:accent5>'; $str .= '<a:srgbClr val="4BACC6" />'; $str .= '</a:accent5>'; $str .= '<a:accent6>'; $str .= '<a:srgbClr val="F79646" />'; $str .= '</a:accent6>'; $str .= '<a:hlink>'; $str .= '<a:srgbClr val="0000FF" />'; $str .= '</a:hlink>'; $str .= '<a:folHlink>'; $str .= '<a:srgbClr val="800080" />'; $str .= '</a:folHlink>'; $str .= '</a:clrScheme>'; return $str; } /** * Write font scheme * * @return string */ private function writeFontScheme() { $str = ''; $str .= '<a:fontScheme name="Office">'; $str .= '<a:majorFont>'; $str .= '<a:latin typeface="Cambria" />'; $str .= '<a:ea typeface="" />'; $str .= '<a:cs typeface="" />'; $str .= '<a:font script="Jpan" typeface="MS ゴシック" />'; $str .= '<a:font script="Hang" typeface="맑은 고딕" />'; $str .= '<a:font script="Hans" typeface="宋体" />'; $str .= '<a:font script="Hant" typeface="新細明體" />'; $str .= '<a:font script="Arab" typeface="Times New Roman" />'; $str .= '<a:font script="Hebr" typeface="Times New Roman" />'; $str .= '<a:font script="Thai" typeface="Angsana New" />'; $str .= '<a:font script="Ethi" typeface="Nyala" />'; $str .= '<a:font script="Beng" typeface="Vrinda" />'; $str .= '<a:font script="Gujr" typeface="Shruti" />'; $str .= '<a:font script="Khmr" typeface="MoolBoran" />'; $str .= '<a:font script="Knda" typeface="Tunga" />'; $str .= '<a:font script="Guru" typeface="Raavi" />'; $str .= '<a:font script="Cans" typeface="Euphemia" />'; $str .= '<a:font script="Cher" typeface="Plantagenet Cherokee" />'; $str .= '<a:font script="Yiii" typeface="Microsoft Yi Baiti" />'; $str .= '<a:font script="Tibt" typeface="Microsoft Himalaya" />'; $str .= '<a:font script="Thaa" typeface="MV Boli" />'; $str .= '<a:font script="Deva" typeface="Mangal" />'; $str .= '<a:font script="Telu" typeface="Gautami" />'; $str .= '<a:font script="Taml" typeface="Latha" />'; $str .= '<a:font script="Syrc" typeface="Estrangelo Edessa" />'; $str .= '<a:font script="Orya" typeface="Kalinga" />'; $str .= '<a:font script="Mlym" typeface="Kartika" />'; $str .= '<a:font script="Laoo" typeface="DokChampa" />'; $str .= '<a:font script="Sinh" typeface="Iskoola Pota" />'; $str .= '<a:font script="Mong" typeface="Mongolian Baiti" />'; $str .= '<a:font script="Viet" typeface="Times New Roman" />'; $str .= '<a:font script="Uigh" typeface="Microsoft Uighur" />'; $str .= '</a:majorFont>'; $str .= '<a:minorFont>'; $str .= '<a:latin typeface="Calibri" />'; $str .= '<a:ea typeface="" />'; $str .= '<a:cs typeface="" />'; $str .= '<a:font script="Jpan" typeface="MS 明朝" />'; $str .= '<a:font script="Hang" typeface="맑은 고딕" />'; $str .= '<a:font script="Hans" typeface="宋体" />'; $str .= '<a:font script="Hant" typeface="新細明體" />'; $str .= '<a:font script="Arab" typeface="Arial" />'; $str .= '<a:font script="Hebr" typeface="Arial" />'; $str .= '<a:font script="Thai" typeface="Cordia New" />'; $str .= '<a:font script="Ethi" typeface="Nyala" />'; $str .= '<a:font script="Beng" typeface="Vrinda" />'; $str .= '<a:font script="Gujr" typeface="Shruti" />'; $str .= '<a:font script="Khmr" typeface="DaunPenh" />'; $str .= '<a:font script="Knda" typeface="Tunga" />'; $str .= '<a:font script="Guru" typeface="Raavi" />'; $str .= '<a:font script="Cans" typeface="Euphemia" />'; $str .= '<a:font script="Cher" typeface="Plantagenet Cherokee" />'; $str .= '<a:font script="Yiii" typeface="Microsoft Yi Baiti" />'; $str .= '<a:font script="Tibt" typeface="Microsoft Himalaya" />'; $str .= '<a:font script="Thaa" typeface="MV Boli" />'; $str .= '<a:font script="Deva" typeface="Mangal" />'; $str .= '<a:font script="Telu" typeface="Gautami" />'; $str .= '<a:font script="Taml" typeface="Latha" />'; $str .= '<a:font script="Syrc" typeface="Estrangelo Edessa" />'; $str .= '<a:font script="Orya" typeface="Kalinga" />'; $str .= '<a:font script="Mlym" typeface="Kartika" />'; $str .= '<a:font script="Laoo" typeface="DokChampa" />'; $str .= '<a:font script="Sinh" typeface="Iskoola Pota" />'; $str .= '<a:font script="Mong" typeface="Mongolian Baiti" />'; $str .= '<a:font script="Viet" typeface="Arial" />'; $str .= '<a:font script="Uigh" typeface="Microsoft Uighur" />'; $str .= '</a:minorFont>'; $str .= '</a:fontScheme>'; return $str; } /** * Write format scheme * * @return string */ private function writeFormatScheme() { $str = ''; $str .= '<a:fmtScheme name="Office">'; $str .= $this->writeFormatFill(); $str .= $this->writeFormatLine(); $str .= $this->writeFormatEffect(); $str .= $this->writeFormatBackground(); $str .= '</a:fmtScheme>'; return $str; } /** * Write fill format scheme * * @return string */ private function writeFormatFill() { $str = ''; $str .= '<a:fillStyleLst>'; $str .= '<a:solidFill>'; $str .= '<a:schemeClr val="phClr" />'; $str .= '</a:solidFill>'; $str .= '<a:gradFill rotWithShape="1">'; $str .= '<a:gsLst>'; $str .= '<a:gs pos="0">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="50000" />'; $str .= '<a:satMod val="300000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="35000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="37000" />'; $str .= '<a:satMod val="300000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="100000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="15000" />'; $str .= '<a:satMod val="350000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '</a:gsLst>'; $str .= '<a:lin ang="16200000" scaled="1" />'; $str .= '</a:gradFill>'; $str .= '<a:gradFill rotWithShape="1">'; $str .= '<a:gsLst>'; $str .= '<a:gs pos="0">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="51000" />'; $str .= '<a:satMod val="130000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="80000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="93000" />'; $str .= '<a:satMod val="130000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="100000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="94000" />'; $str .= '<a:satMod val="135000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '</a:gsLst>'; $str .= '<a:lin ang="16200000" scaled="0" />'; $str .= '</a:gradFill>'; $str .= '</a:fillStyleLst>'; return $str; } /** * Write line format scheme * * @return string */ private function writeFormatLine() { $str = ''; $str .= '<a:lnStyleLst>'; $str .= '<a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">'; $str .= '<a:solidFill>'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="95000" />'; $str .= '<a:satMod val="105000" />'; $str .= '</a:schemeClr>'; $str .= '</a:solidFill>'; $str .= '<a:prstDash val="solid" />'; $str .= '</a:ln>'; $str .= '<a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">'; $str .= '<a:solidFill>'; $str .= '<a:schemeClr val="phClr" />'; $str .= '</a:solidFill>'; $str .= '<a:prstDash val="solid" />'; $str .= '</a:ln>'; $str .= '<a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">'; $str .= '<a:solidFill>'; $str .= '<a:schemeClr val="phClr" />'; $str .= '</a:solidFill>'; $str .= '<a:prstDash val="solid" />'; $str .= '</a:ln>'; $str .= '</a:lnStyleLst>'; return $str; } /** * Write effect format scheme * * @return string */ private function writeFormatEffect() { $str = ''; $str .= '<a:effectStyleLst>'; $str .= '<a:effectStyle>'; $str .= '<a:effectLst>'; $str .= '<a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0">'; $str .= '<a:srgbClr val="000000">'; $str .= '<a:alpha val="38000" />'; $str .= '</a:srgbClr>'; $str .= '</a:outerShdw>'; $str .= '</a:effectLst>'; $str .= '</a:effectStyle>'; $str .= '<a:effectStyle>'; $str .= '<a:effectLst>'; $str .= '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">'; $str .= '<a:srgbClr val="000000">'; $str .= '<a:alpha val="35000" />'; $str .= '</a:srgbClr>'; $str .= '</a:outerShdw>'; $str .= '</a:effectLst>'; $str .= '</a:effectStyle>'; $str .= '<a:effectStyle>'; $str .= '<a:effectLst>'; $str .= '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">'; $str .= '<a:srgbClr val="000000">'; $str .= '<a:alpha val="35000" />'; $str .= '</a:srgbClr>'; $str .= '</a:outerShdw>'; $str .= '</a:effectLst>'; $str .= '<a:scene3d>'; $str .= '<a:camera prst="orthographicFront">'; $str .= '<a:rot lat="0" lon="0" rev="0" />'; $str .= '</a:camera>'; $str .= '<a:lightRig rig="threePt" dir="t">'; $str .= '<a:rot lat="0" lon="0" rev="1200000" />'; $str .= '</a:lightRig>'; $str .= '</a:scene3d>'; $str .= '<a:sp3d>'; $str .= '<a:bevelT w="63500" h="25400" />'; $str .= '</a:sp3d>'; $str .= '</a:effectStyle>'; $str .= '</a:effectStyleLst>'; return $str; } /** * Write background format scheme * * @return string */ private function writeFormatBackground() { $str = ''; $str .= '<a:bgFillStyleLst>'; $str .= '<a:solidFill>'; $str .= '<a:schemeClr val="phClr" />'; $str .= '</a:solidFill>'; $str .= '<a:gradFill rotWithShape="1">'; $str .= '<a:gsLst>'; $str .= '<a:gs pos="0">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="40000" />'; $str .= '<a:satMod val="350000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="40000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="45000" />'; $str .= '<a:shade val="99000" />'; $str .= '<a:satMod val="350000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="100000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="20000" />'; $str .= '<a:satMod val="255000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '</a:gsLst>'; $str .= '<a:path path="circle">'; $str .= '<a:fillToRect l="50000" t="-80000" r="50000" b="180000" />'; $str .= '</a:path>'; $str .= '</a:gradFill>'; $str .= '<a:gradFill rotWithShape="1">'; $str .= '<a:gsLst>'; $str .= '<a:gs pos="0">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:tint val="80000" />'; $str .= '<a:satMod val="300000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '<a:gs pos="100000">'; $str .= '<a:schemeClr val="phClr">'; $str .= '<a:shade val="30000" />'; $str .= '<a:satMod val="200000" />'; $str .= '</a:schemeClr>'; $str .= '</a:gs>'; $str .= '</a:gsLst>'; $str .= '<a:path path="circle">'; $str .= '<a:fillToRect l="50000" t="50000" r="50000" b="50000" />'; $str .= '</a:path>'; $str .= '</a:gradFill>'; $str .= '</a:bgFillStyleLst>'; return $str; } } phpword/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php 0000664 00000006021 15177100670 0017451 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 custom document properties part writer: docProps/custom.xml * * @since 0.11.0 */ class DocPropsCustom extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('Properties'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties'); $xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); $docProps = $phpWord->getDocInfo(); $properties = $docProps->getCustomProperties(); foreach ($properties as $key => $property) { $propertyValue = $docProps->getCustomPropertyValue($property); $propertyType = $docProps->getCustomPropertyType($property); $xmlWriter->startElement('property'); $xmlWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'); $xmlWriter->writeAttribute('pid', $key + 2); $xmlWriter->writeAttribute('name', $property); switch ($propertyType) { case 'i': $xmlWriter->writeElement('vt:i4', $propertyValue); break; case 'f': $xmlWriter->writeElement('vt:r8', $propertyValue); break; case 'b': $xmlWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false'); break; case 'd': if ($propertyValue instanceof \DateTime) { $xmlWriter->writeElement('vt:filetime', $propertyValue->format($this->dateFormat)); } else { $xmlWriter->writeElement('vt:filetime', date($this->dateFormat, $propertyValue)); } break; default: $xmlWriter->writeElement('vt:lpwstr', $propertyValue); break; } $xmlWriter->endElement(); // property } $xmlWriter->endElement(); // Properties return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/Word2007/Part/ContentTypes.php 0000664 00000007443 15177100670 0017175 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Shared\XMLWriter; /** * Word2007 contenttypes part writer: [Content_Types].xml */ class ContentTypes extends AbstractPart { /** * Write part * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $contentTypes = $parentWriter->getContentTypes(); $openXMLPrefix = 'application/vnd.openxmlformats-'; $wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.'; $drawingMLPrefix = $openXMLPrefix . 'officedocument.drawingml.'; $overrides = array( '/docProps/core.xml' => $openXMLPrefix . 'package.core-properties+xml', '/docProps/app.xml' => $openXMLPrefix . 'officedocument.extended-properties+xml', '/docProps/custom.xml' => $openXMLPrefix . 'officedocument.custom-properties+xml', '/word/document.xml' => $wordMLPrefix . 'document.main+xml', '/word/styles.xml' => $wordMLPrefix . 'styles+xml', '/word/numbering.xml' => $wordMLPrefix . 'numbering+xml', '/word/settings.xml' => $wordMLPrefix . 'settings+xml', '/word/theme/theme1.xml' => $openXMLPrefix . 'officedocument.theme+xml', '/word/webSettings.xml' => $wordMLPrefix . 'webSettings+xml', '/word/fontTable.xml' => $wordMLPrefix . 'fontTable+xml', '/word/comments.xml' => $wordMLPrefix . 'comments+xml', ); $defaults = $contentTypes['default']; if (!empty($contentTypes['override'])) { foreach ($contentTypes['override'] as $key => $val) { if ($val == 'chart') { $overrides[$key] = $drawingMLPrefix . $val . '+xml'; } else { $overrides[$key] = $wordMLPrefix . $val . '+xml'; } } } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('Types'); $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); $this->writeContentType($xmlWriter, $defaults, true); $this->writeContentType($xmlWriter, $overrides, false); $xmlWriter->endElement(); // Types return $xmlWriter->getData(); } /** * Write content types element * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer * @param array $parts * @param bool $isDefault */ private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault) { foreach ($parts as $partName => $contentType) { $partType = $isDefault ? 'Default' : 'Override'; $partAttribute = $isDefault ? 'Extension' : 'PartName'; $xmlWriter->startElement($partType); $xmlWriter->writeAttribute($partAttribute, $partName); $xmlWriter->writeAttribute('ContentType', $contentType); $xmlWriter->endElement(); } } } phpword/src/PhpWord/Writer/Word2007/Part/Comments.php 0000664 00000007215 15177100670 0016320 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Element\Comment; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; /** * Word2007 comments part writer: word/comments.xml */ class Comments extends AbstractPart { /** * Comments collection to be written * * @var \PhpOffice\PhpWord\Element\Comment[] */ protected $elements; /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:comments'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); if ($this->elements !== null) { foreach ($this->elements as $element) { if ($element instanceof Comment) { $this->writeComment($xmlWriter, $element); } } } $xmlWriter->endElement(); // w:comments return $xmlWriter->getData(); } /** * Write comment item. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Comment $comment */ protected function writeComment(XMLWriter $xmlWriter, Comment $comment) { $xmlWriter->startElement('w:comment'); $xmlWriter->writeAttribute('w:id', $comment->getElementId()); $xmlWriter->writeAttribute('w:author', $comment->getAuthor()); if ($comment->getDate() != null) { $xmlWriter->writeAttribute('w:date', $comment->getDate()->format($this->dateFormat)); } $xmlWriter->writeAttributeIf($comment->getInitials() != null, 'w:initials', $comment->getInitials()); $containerWriter = new Container($xmlWriter, $comment); $containerWriter->write(); $xmlWriter->endElement(); // w:comment } /** * Set element * * @param \PhpOffice\PhpWord\Element\Comment[] $elements * @return self */ public function setElements($elements) { $this->elements = $elements; return $this; } } phpword/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php 0000664 00000005603 15177100670 0017074 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 core document properties part writer: docProps/core.xml * * @since 0.11.0 */ class DocPropsCore extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $xmlWriter = $this->getXmlWriter(); $schema = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('cp:coreProperties'); $xmlWriter->writeAttribute('xmlns:cp', $schema); $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xmlWriter->writeElement('dc:creator', $phpWord->getDocInfo()->getCreator()); $xmlWriter->writeElement('dc:title', $phpWord->getDocInfo()->getTitle()); $xmlWriter->writeElement('dc:description', $phpWord->getDocInfo()->getDescription()); $xmlWriter->writeElement('dc:subject', $phpWord->getDocInfo()->getSubject()); $xmlWriter->writeElement('cp:keywords', $phpWord->getDocInfo()->getKeywords()); $xmlWriter->writeElement('cp:category', $phpWord->getDocInfo()->getCategory()); $xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocInfo()->getLastModifiedBy()); // dcterms:created $xmlWriter->startElement('dcterms:created'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getCreated())); $xmlWriter->endElement(); // dcterms:modified $xmlWriter->startElement('dcterms:modified'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getModified())); $xmlWriter->endElement(); $xmlWriter->endElement(); // cp:coreProperties return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/Word2007/Part/FontTable.php 0000664 00000011276 15177100670 0016413 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 font table writer: word/fontTable.xml * * @todo Generate content dynamically * @since 0.10.0 */ class FontTable extends AbstractPart { /** * Write fontTable.xml. * * @return string */ public function write() { $str = ''; $str .= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'; $str .= '<w:fonts ' . 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' . 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">'; $str .= '<w:font w:name="Times New Roman">'; $str .= '<w:panose1 w:val="02020603050405020304" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="roman" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="E0002AFF" w:usb1="C0007841" w:usb2="00000009" w:usb3="00000000" ' . 'w:csb0="000001FF" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Courier New">'; $str .= '<w:panose1 w:val="02070309020205020404" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="modern" />'; $str .= '<w:pitch w:val="fixed" />'; $str .= '<w:sig w:usb0="E0002AFF" w:usb1="C0007843" w:usb2="00000009" w:usb3="00000000" ' . 'w:csb0="000001FF" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Wingdings">'; $str .= '<w:panose1 w:val="05000000000000000000" />'; $str .= '<w:charset w:val="02" />'; $str .= '<w:family w:val="auto" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" ' . 'w:csb0="80000000" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Symbol">'; $str .= '<w:panose1 w:val="05050102010706020507" />'; $str .= '<w:charset w:val="02" />'; $str .= '<w:family w:val="roman" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" ' . 'w:csb0="80000000" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Arial">'; $str .= '<w:panose1 w:val="020B0604020202020204" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="swiss" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="E0002AFF" w:usb1="C0007843" w:usb2="00000009" w:usb3="00000000" ' . 'w:csb0="000001FF" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Cambria">'; $str .= '<w:panose1 w:val="02040503050406030204" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="roman" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="A00002EF" w:usb1="4000004B" w:usb2="00000000" w:usb3="00000000" ' . 'w:csb0="0000019F" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Calibri">'; $str .= '<w:panose1 w:val="020F0502020204030204" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="swiss" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="E10002FF" w:usb1="4000ACFF" w:usb2="00000009" w:usb3="00000000" ' . 'w:csb0="0000019F" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '<w:font w:name="Garamond">'; $str .= '<w:panose1 w:val="02020404030301010803" />'; $str .= '<w:charset w:val="00" />'; $str .= '<w:family w:val="roman" />'; $str .= '<w:pitch w:val="variable" />'; $str .= '<w:sig w:usb0="00000287" w:usb1="00000002" w:usb2="00000000" w:usb3="00000000" ' . 'w:csb0="0000009F" w:csb1="00000000" />'; $str .= '</w:font>'; $str .= '</w:fonts>'; return $str; } } phpword/src/PhpWord/Writer/Word2007/Part/RelsPart.php 0000664 00000002613 15177100670 0016264 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 part relationship writer: word/_rels/(header|footer|footnotes|endnotes)*.xml.rels * * @since 0.11.0 */ class RelsPart extends Rels { /** * Media relationships * * @var array */ private $media = array(); /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $this->writeRels($xmlWriter, array(), $this->media); return $xmlWriter->getData(); } /** * Set media * * @param array $media * @return self */ public function setMedia($media) { $this->media = $media; return $this; } } phpword/src/PhpWord/Writer/Word2007/Part/Numbering.php 0000664 00000016375 15177100670 0016470 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\NumberingLevel; /** * Word2007 numbering part writer: word/numbering.xml * * @since 0.10.0 */ class Numbering extends AbstractPart { /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $styles = Style::getStyles(); $drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:numbering'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:wp', $drawingSchema); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); // Abstract numbering definitions foreach ($styles as $style) { if ($style instanceof NumberingStyle) { $levels = $style->getLevels(); $xmlWriter->startElement('w:abstractNum'); $xmlWriter->writeAttribute('w:abstractNumId', $style->getIndex()); $xmlWriter->startElement('w:nsid'); $xmlWriter->writeAttribute('w:val', $this->getRandomHexNumber()); $xmlWriter->endElement(); // w:nsid $xmlWriter->startElement('w:multiLevelType'); $xmlWriter->writeAttribute('w:val', $style->getType()); $xmlWriter->endElement(); // w:multiLevelType if (is_array($levels)) { foreach ($levels as $level) { $this->writeLevel($xmlWriter, $level); } } $xmlWriter->endElement(); // w:abstractNum } } // Numbering definition instances foreach ($styles as $style) { if ($style instanceof NumberingStyle) { $xmlWriter->startElement('w:num'); $xmlWriter->writeAttribute('w:numId', $style->getIndex()); $xmlWriter->startElement('w:abstractNumId'); $xmlWriter->writeAttribute('w:val', $style->getIndex()); $xmlWriter->endElement(); // w:abstractNumId $xmlWriter->endElement(); // w:num } } $xmlWriter->endElement(); // w:numbering return $xmlWriter->getData(); } /** * Write level. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level */ private function writeLevel(XMLWriter $xmlWriter, NumberingLevel $level) { $xmlWriter->startElement('w:lvl'); $xmlWriter->writeAttribute('w:ilvl', $level->getLevel()); // Numbering level properties $properties = array( 'start' => 'start', 'format' => 'numFmt', 'restart' => 'lvlRestart', 'pStyle' => 'pStyle', 'suffix' => 'suff', 'text' => 'lvlText', 'alignment' => 'lvlJc', ); foreach ($properties as $property => $nodeName) { $getMethod = "get{$property}"; if ('' !== $level->$getMethod() // this condition is now supported by `alignment` only && !is_null($level->$getMethod())) { $xmlWriter->startElement("w:{$nodeName}"); $xmlWriter->writeAttribute('w:val', $level->$getMethod()); $xmlWriter->endElement(); // w:start } } // Paragraph & font styles $this->writeParagraph($xmlWriter, $level); $this->writeFont($xmlWriter, $level); $xmlWriter->endElement(); // w:lvl } /** * Write level paragraph. * * @since 0.11.0 * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @todo Use paragraph style writer */ private function writeParagraph(XMLWriter $xmlWriter, NumberingLevel $level) { $tabPos = $level->getTabPos(); $left = $level->getLeft(); $hanging = $level->getHanging(); $xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:tabs'); $xmlWriter->startElement('w:tab'); $xmlWriter->writeAttribute('w:val', 'num'); $xmlWriter->writeAttributeIf($tabPos !== null, 'w:pos', $tabPos); $xmlWriter->endElement(); // w:tab $xmlWriter->endElement(); // w:tabs $xmlWriter->startElement('w:ind'); $xmlWriter->writeAttributeIf($left !== null, 'w:left', $left); $xmlWriter->writeAttributeIf($hanging !== null, 'w:hanging', $hanging); $xmlWriter->endElement(); // w:ind $xmlWriter->endElement(); // w:pPr } /** * Write level font. * * @since 0.11.0 * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @todo Use font style writer */ private function writeFont(XMLWriter $xmlWriter, NumberingLevel $level) { $font = $level->getFont(); $hint = $level->getHint(); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rFonts'); $xmlWriter->writeAttributeIf($font !== null, 'w:ascii', $font); $xmlWriter->writeAttributeIf($font !== null, 'w:hAnsi', $font); $xmlWriter->writeAttributeIf($font !== null, 'w:cs', $font); $xmlWriter->writeAttributeIf($hint !== null, 'w:hint', $hint); $xmlWriter->endElement(); // w:rFonts $xmlWriter->endElement(); // w:rPr } /** * Get random hexadecimal number value * * @param int $length * @return string */ private function getRandomHexNumber($length = 8) { return strtoupper(substr(md5(rand()), 0, $length)); } } phpword/src/PhpWord/Writer/Word2007/Part/Header.php 0000664 00000001632 15177100670 0015720 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 header part writer: word/headerx.xml */ class Header extends Footer { /** * Root element name * * @var string */ protected $rootElement = 'w:hdr'; } phpword/src/PhpWord/Writer/Word2007/Part/Settings.php 0000664 00000032337 15177100670 0016336 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\ComplexType\ProofState; use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder; use PhpOffice\PhpWord\Style\Language; /** * Word2007 settings part writer: word/settings.xml * * @see http://www.schemacentral.com/sc/ooxml/t-w_CT_Settings.html */ class Settings extends AbstractPart { /** * Settings value * * @var array */ private $settings = array(); /** * Write part * * @return string */ public function write() { $this->getSettings(); $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:settings'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:sl', 'http://schemas.openxmlformats.org/schemaLibrary/2006/main'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); foreach ($this->settings as $settingKey => $settingValue) { $this->writeSetting($xmlWriter, $settingKey, $settingValue); } $xmlWriter->endElement(); // w:settings return $xmlWriter->getData(); } /** * Write indivual setting, recursive to any child settings. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $settingKey * @param array|string $settingValue */ protected function writeSetting($xmlWriter, $settingKey, $settingValue) { if ($settingValue == '') { $xmlWriter->writeElement($settingKey); } elseif (is_array($settingValue) && !empty($settingValue)) { $xmlWriter->startElement($settingKey); /** @var array $settingValue Type hint */ foreach ($settingValue as $childKey => $childValue) { if ($childKey == '@attributes') { foreach ($childValue as $key => $val) { $xmlWriter->writeAttribute($key, $val); } } else { $this->writeSetting($xmlWriter, $childKey, $childValue); } } $xmlWriter->endElement(); } } /** * Get settings. */ private function getSettings() { /** @var \PhpOffice\PhpWord\Metadata\Settings $documentSettings */ $documentSettings = $this->getParentWriter()->getPhpWord()->getSettings(); // Default settings $this->settings = array( 'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')), 'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')), 'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')), 'w:decimalSymbol' => array('@attributes' => array('w:val' => $documentSettings->getDecimalSymbol())), 'w:listSeparator' => array('@attributes' => array('w:val' => ';')), 'w:compat' => array(), 'm:mathPr' => array( 'm:mathFont' => array('@attributes' => array('m:val' => 'Cambria Math')), 'm:brkBin' => array('@attributes' => array('m:val' => 'before')), 'm:brkBinSub' => array('@attributes' => array('m:val' => '--')), 'm:smallFrac' => array('@attributes' => array('m:val' => 'off')), 'm:dispDef' => '', 'm:lMargin' => array('@attributes' => array('m:val' => '0')), 'm:rMargin' => array('@attributes' => array('m:val' => '0')), 'm:defJc' => array('@attributes' => array('m:val' => 'centerGroup')), 'm:wrapIndent' => array('@attributes' => array('m:val' => '1440')), 'm:intLim' => array('@attributes' => array('m:val' => 'subSup')), 'm:naryLim' => array('@attributes' => array('m:val' => 'undOvr')), ), 'w:clrSchemeMapping' => array( '@attributes' => array( 'w:bg1' => 'light1', 'w:t1' => 'dark1', 'w:bg2' => 'light2', 'w:t2' => 'dark2', 'w:accent1' => 'accent1', 'w:accent2' => 'accent2', 'w:accent3' => 'accent3', 'w:accent4' => 'accent4', 'w:accent5' => 'accent5', 'w:accent6' => 'accent6', 'w:hyperlink' => 'hyperlink', 'w:followedHyperlink' => 'followedHyperlink', ), ), ); $this->setOnOffValue('w:mirrorMargins', $documentSettings->hasMirrorMargins()); $this->setOnOffValue('w:hideSpellingErrors', $documentSettings->hasHideSpellingErrors()); $this->setOnOffValue('w:hideGrammaticalErrors', $documentSettings->hasHideGrammaticalErrors()); $this->setOnOffValue('w:trackRevisions', $documentSettings->hasTrackRevisions()); $this->setOnOffValue('w:doNotTrackMoves', $documentSettings->hasDoNotTrackMoves()); $this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting()); $this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders()); $this->setOnOffValue('w:updateFields', $documentSettings->hasUpdateFields()); $this->setOnOffValue('w:autoHyphenation', $documentSettings->hasAutoHyphenation()); $this->setOnOffValue('w:doNotHyphenateCaps', $documentSettings->hasDoNotHyphenateCaps()); $this->setThemeFontLang($documentSettings->getThemeFontLang()); $this->setRevisionView($documentSettings->getRevisionView()); $this->setDocumentProtection($documentSettings->getDocumentProtection()); $this->setProofState($documentSettings->getProofState()); $this->setZoom($documentSettings->getZoom()); $this->setConsecutiveHyphenLimit($documentSettings->getConsecutiveHyphenLimit()); $this->setHyphenationZone($documentSettings->getHyphenationZone()); $this->setCompatibility(); } /** * Adds a boolean attribute to the settings array * * @param string $settingName * @param bool|null $booleanValue */ private function setOnOffValue($settingName, $booleanValue) { if (!is_bool($booleanValue)) { return; } $value = $booleanValue ? 'true' : 'false'; $this->settings[$settingName] = array('@attributes' => array('w:val' => $value)); } /** * Get protection settings. * * @param \PhpOffice\PhpWord\Metadata\Protection $documentProtection */ private function setDocumentProtection($documentProtection) { if ($documentProtection->getEditing() !== null) { if ($documentProtection->getPassword() == null) { $this->settings['w:documentProtection'] = array( '@attributes' => array( 'w:enforcement' => 1, 'w:edit' => $documentProtection->getEditing(), ), ); } else { if ($documentProtection->getSalt() == null) { $documentProtection->setSalt(openssl_random_pseudo_bytes(16)); } $passwordHash = PasswordEncoder::hashPassword($documentProtection->getPassword(), $documentProtection->getAlgorithm(), $documentProtection->getSalt(), $documentProtection->getSpinCount()); $this->settings['w:documentProtection'] = array( '@attributes' => array( 'w:enforcement' => 1, 'w:edit' => $documentProtection->getEditing(), 'w:cryptProviderType' => 'rsaFull', 'w:cryptAlgorithmClass' => 'hash', 'w:cryptAlgorithmType' => 'typeAny', 'w:cryptAlgorithmSid' => PasswordEncoder::getAlgorithmId($documentProtection->getAlgorithm()), 'w:cryptSpinCount' => $documentProtection->getSpinCount(), 'w:hash' => $passwordHash, 'w:salt' => base64_encode($documentProtection->getSalt()), ), ); } } } /** * Set the Proof state * * @param ProofState $proofState */ private function setProofState(ProofState $proofState = null) { if ($proofState != null && $proofState->getGrammar() !== null && $proofState->getSpelling() !== null) { $this->settings['w:proofState'] = array( '@attributes' => array( 'w:spelling' => $proofState->getSpelling(), 'w:grammar' => $proofState->getGrammar(), ), ); } } /** * Set the Revision View * * @param TrackChangesView $trackChangesView */ private function setRevisionView(TrackChangesView $trackChangesView = null) { if ($trackChangesView != null) { $revisionView = array(); $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true' : 'false'; $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true' : 'false'; $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true' : 'false'; $revisionView['w:formatting'] = $trackChangesView->hasFormatting() ? 'true' : 'false'; $revisionView['w:inkAnnotations'] = $trackChangesView->hasInkAnnotations() ? 'true' : 'false'; $this->settings['w:revisionView'] = array('@attributes' => $revisionView); } } /** * Sets the language * * @param Language $language */ private function setThemeFontLang(Language $language = null) { $latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin(); $lang = array(); $lang['w:val'] = $latinLanguage; if ($language != null) { $lang['w:eastAsia'] = $language->getEastAsia() === null ? 'x-none' : $language->getEastAsia(); $lang['w:bidi'] = $language->getBidirectional() === null ? 'x-none' : $language->getBidirectional(); } $this->settings['w:themeFontLang'] = array('@attributes' => $lang); } /** * Set the magnification * * @param mixed $zoom */ private function setZoom($zoom = null) { if ($zoom !== null) { $attr = is_int($zoom) ? 'w:percent' : 'w:val'; $this->settings['w:zoom'] = array('@attributes' => array($attr => $zoom)); } } /** * @param int|null $consecutiveHyphenLimit */ private function setConsecutiveHyphenLimit($consecutiveHyphenLimit) { if ($consecutiveHyphenLimit === null) { return; } $this->settings['w:consecutiveHyphenLimit'] = array( '@attributes' => array('w:val' => $consecutiveHyphenLimit), ); } /** * @param float|null $hyphenationZone */ private function setHyphenationZone($hyphenationZone) { if ($hyphenationZone === null) { return; } $this->settings['w:hyphenationZone'] = array( '@attributes' => array('w:val' => $hyphenationZone), ); } /** * Get compatibility setting. */ private function setCompatibility() { $compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility(); if ($compatibility->getOoxmlVersion() !== null) { $this->settings['w:compat']['w:compatSetting'] = array( '@attributes' => array( 'w:name' => 'compatibilityMode', 'w:uri' => 'http://schemas.microsoft.com/office/word', 'w:val' => $compatibility->getOoxmlVersion(), ), ); } } } phpword/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php 0000664 00000003347 15177100670 0016727 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 extended document properties part writer: docProps/app.xml * * @since 0.11.0 */ class DocPropsApp extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $xmlWriter = $this->getXmlWriter(); $schema = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('Properties'); $xmlWriter->writeAttribute('xmlns', $schema); $xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); $xmlWriter->writeElement('Application', 'PHPWord'); $xmlWriter->writeElement('Company', $phpWord->getDocInfo()->getCompany()); $xmlWriter->writeElement('Manager', $phpWord->getDocInfo()->getManager()); $xmlWriter->endElement(); // Properties return $xmlWriter->getData(); } } phpword/src/PhpWord/Writer/Word2007/Part/Document.php 0000664 00000014276 15177100670 0016316 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; /** * Word2007 document part writer: word/document.xml */ class Document extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $xmlWriter = $this->getXmlWriter(); $sections = $phpWord->getSections(); $sectionCount = count($sections); $currentSection = 0; $drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:document'); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:wp', $drawingSchema); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $xmlWriter->startElement('w:body'); if ($sectionCount > 0) { foreach ($sections as $section) { $currentSection++; $containerWriter = new Container($xmlWriter, $section); $containerWriter->write(); if ($currentSection == $sectionCount) { $this->writeSectionSettings($xmlWriter, $section); } else { $this->writeSection($xmlWriter, $section); } } } $xmlWriter->endElement(); // w:body $xmlWriter->endElement(); // w:document return $xmlWriter->getData(); } /** * Write begin section. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section */ private function writeSection(XMLWriter $xmlWriter, Section $section) { $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:pPr'); $this->writeSectionSettings($xmlWriter, $section); $xmlWriter->endElement(); $xmlWriter->endElement(); } /** * Write end section. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section */ private function writeSectionSettings(XMLWriter $xmlWriter, Section $section) { $xmlWriter->startElement('w:sectPr'); // Header reference foreach ($section->getHeaders() as $header) { $rId = $header->getRelationId(); $xmlWriter->startElement('w:headerReference'); $xmlWriter->writeAttribute('w:type', $header->getType()); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->endElement(); } // Footer reference foreach ($section->getFooters() as $footer) { $rId = $footer->getRelationId(); $xmlWriter->startElement('w:footerReference'); $xmlWriter->writeAttribute('w:type', $footer->getType()); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->endElement(); } // Different first page if ($section->hasDifferentFirstPage()) { $xmlWriter->startElement('w:titlePg'); $xmlWriter->endElement(); } // Footnote properties if ($section->getFootnoteProperties() !== null) { $xmlWriter->startElement('w:footnotePr'); if ($section->getFootnoteProperties()->getPos() != null) { $xmlWriter->startElement('w:pos'); $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos()); $xmlWriter->endElement(); } if ($section->getFootnoteProperties()->getNumFmt() != null) { $xmlWriter->startElement('w:numFmt'); $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt()); $xmlWriter->endElement(); } if ($section->getFootnoteProperties()->getNumStart() != null) { $xmlWriter->startElement('w:numStart'); $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart()); $xmlWriter->endElement(); } if ($section->getFootnoteProperties()->getNumRestart() != null) { $xmlWriter->startElement('w:numRestart'); $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart()); $xmlWriter->endElement(); } $xmlWriter->endElement(); } // Section settings $styleWriter = new SectionStyleWriter($xmlWriter, $section->getStyle()); $styleWriter->write(); $xmlWriter->endElement(); // w:sectPr } } phpword/src/PhpWord/Writer/Word2007/Part/Footer.php 0000664 00000005414 15177100670 0015770 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; /** * Word2007 footer part writer: word/footerx.xml */ class Footer extends AbstractPart { /** * Root element name * * @var string */ protected $rootElement = 'w:ftr'; /** * Footer/header element to be written * * @var \PhpOffice\PhpWord\Element\Footer */ protected $element; /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement($this->rootElement); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:wp', $drawingSchema); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $containerWriter = new Container($xmlWriter, $this->element); $containerWriter->write(); $xmlWriter->endElement(); // $this->rootElement return $xmlWriter->getData(); } /** * Set element * * @param \PhpOffice\PhpWord\Element\Footer|\PhpOffice\PhpWord\Element\Header $element * @return self */ public function setElement($element) { $this->element = $element; return $this; } } phpword/src/PhpWord/Writer/Word2007/Part/Endnotes.php 0000664 00000002416 15177100670 0016310 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; /** * Word2007 endnotes part writer: word/endnotes.xml */ class Endnotes extends Footnotes { /** * Name of XML root element * * @var string */ protected $rootNode = 'w:endnotes'; /** * Name of XML node element * * @var string */ protected $elementNode = 'w:endnote'; /** * Name of XML reference element * * @var string */ protected $refNode = 'w:endnoteRef'; /** * Reference style name * * @var string */ protected $refStyle = 'EndnoteReference'; } phpword/src/PhpWord/Writer/Word2007/Part/Footnotes.php 0000664 00000014026 15177100670 0016511 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Element\Footnote; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; /** * Word2007 footnotes part writer: word/(footnotes|endnotes).xml */ class Footnotes extends AbstractPart { /** * Name of XML root element * * @var string */ protected $rootNode = 'w:footnotes'; /** * Name of XML node element * * @var string */ protected $elementNode = 'w:footnote'; /** * Name of XML reference element * * @var string */ protected $refNode = 'w:footnoteRef'; /** * Reference style name * * @var string */ protected $refStyle = 'FootnoteReference'; /** * Footnotes/endnotes collection to be written * * @var \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes */ protected $elements; /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement($this->rootNode); $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $xmlWriter->writeAttribute('xmlns:wp', $drawingSchema); $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); // Separator and continuation separator $xmlWriter->startElement($this->elementNode); $xmlWriter->writeAttribute('w:id', -1); $xmlWriter->writeAttribute('w:type', 'separator'); $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:separator'); $xmlWriter->endElement(); // w:separator $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // $this->elementNode $xmlWriter->startElement($this->elementNode); $xmlWriter->writeAttribute('w:id', 0); $xmlWriter->writeAttribute('w:type', 'continuationSeparator'); $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:continuationSeparator'); $xmlWriter->endElement(); // w:continuationSeparator $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // $this->elementNode /** @var array $elements Type hint */ $elements = $this->elements; foreach ($elements as $element) { if ($element instanceof Footnote) { $this->writeNote($xmlWriter, $element); } } $xmlWriter->endElement(); // $this->rootNode return $xmlWriter->getData(); } /** * Set element * * @param \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes $elements * @return self */ public function setElements($elements) { $this->elements = $elements; return $this; } /** * Write note item. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element */ protected function writeNote(XMLWriter $xmlWriter, $element) { $xmlWriter->startElement($this->elementNode); $xmlWriter->writeAttribute('w:id', $element->getRelationId()); $xmlWriter->startElement('w:p'); // Paragraph style $styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle()); $styleWriter->setIsInline(true); $styleWriter->write(); // Reference symbol $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rStyle'); $xmlWriter->writeAttribute('w:val', $this->refStyle); $xmlWriter->endElement(); // w:rStyle $xmlWriter->endElement(); // w:rPr $xmlWriter->writeElement($this->refNode); $xmlWriter->endElement(); // w:r // Empty space after refence symbol $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); $xmlWriter->text(' '); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $containerWriter = new Container($xmlWriter, $element); $containerWriter->write(); $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // $this->elementNode } } phpword/src/PhpWord/Writer/Word2007/Part/Styles.php 0000664 00000025705 15177100670 0016022 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Table as TableStyleWriter; /** * Word2007 styles part writer: word/styles.xml * * @todo Do something with the numbering style introduced in 0.10.0 * @SuppressWarnings(PHPMD.UnusedPrivateMethod) For writeFontStyle, writeParagraphStyle, and writeTableStyle */ class Styles extends AbstractPart { /** * Write part * * @return string */ public function write() { $xmlWriter = $this->getXmlWriter(); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:styles'); $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); // Write default styles $styles = Style::getStyles(); $this->writeDefaultStyles($xmlWriter, $styles); // Write styles if (count($styles) > 0) { foreach ($styles as $styleName => $style) { if ($styleName == 'Normal') { continue; } // Get style class and execute if the private method exists $styleClass = substr(get_class($style), strrpos(get_class($style), '\\') + 1); $method = "write{$styleClass}Style"; if (method_exists($this, $method)) { $this->$method($xmlWriter, $styleName, $style); } } } $xmlWriter->endElement(); // w:styles return $xmlWriter->getData(); } /** * Write default font and other default styles. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\AbstractStyle[] $styles */ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles) { $phpWord = $this->getParentWriter()->getPhpWord(); $fontName = $phpWord->getDefaultFontName(); $fontSize = $phpWord->getDefaultFontSize(); $language = $phpWord->getSettings()->getThemeFontLang(); $latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin(); // Default font $xmlWriter->startElement('w:docDefaults'); $xmlWriter->startElement('w:rPrDefault'); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:rFonts'); $xmlWriter->writeAttribute('w:ascii', $fontName); $xmlWriter->writeAttribute('w:hAnsi', $fontName); $xmlWriter->writeAttribute('w:eastAsia', $fontName); $xmlWriter->writeAttribute('w:cs', $fontName); $xmlWriter->endElement(); // w:rFonts $xmlWriter->startElement('w:sz'); $xmlWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->endElement(); // w:sz $xmlWriter->startElement('w:szCs'); $xmlWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->endElement(); // w:szCs $xmlWriter->startElement('w:lang'); $xmlWriter->writeAttribute('w:val', $latinLanguage); if ($language != null) { $xmlWriter->writeAttributeIf($language->getEastAsia() !== null, 'w:eastAsia', $language->getEastAsia()); $xmlWriter->writeAttributeIf($language->getBidirectional() !== null, 'w:bidi', $language->getBidirectional()); } $xmlWriter->endElement(); // w:lang $xmlWriter->endElement(); // w:rPr $xmlWriter->endElement(); // w:rPrDefault $xmlWriter->endElement(); // w:docDefaults // Normal style $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', 'paragraph'); $xmlWriter->writeAttribute('w:default', '1'); $xmlWriter->writeAttribute('w:styleId', 'Normal'); $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->endElement(); // w:name if (isset($styles['Normal'])) { $normalStyle = $styles['Normal']; // w:pPr if ($normalStyle instanceof Fontstyle && $normalStyle->getParagraph() != null) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $normalStyle->getParagraph()); $styleWriter->write(); } elseif ($normalStyle instanceof ParagraphStyle) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $normalStyle); $styleWriter->write(); } // w:rPr $styleWriter = new FontStyleWriter($xmlWriter, $normalStyle); $styleWriter->write(); } $xmlWriter->endElement(); // w:style // FootnoteReference style if (!isset($styles['FootnoteReference'])) { $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', 'character'); $xmlWriter->writeAttribute('w:styleId', 'FootnoteReference'); $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', 'Footnote Reference'); $xmlWriter->endElement(); // w:name $xmlWriter->writeElement('w:semiHidden'); $xmlWriter->writeElement('w:unhideWhenUsed'); $xmlWriter->startElement('w:rPr'); $xmlWriter->startElement('w:vertAlign'); $xmlWriter->writeAttribute('w:val', 'superscript'); $xmlWriter->endElement(); // w:vertAlign $xmlWriter->endElement(); // w:rPr $xmlWriter->endElement(); // w:style } } /** * Write font style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Font $style */ private function writeFontStyle(XMLWriter $xmlWriter, $styleName, FontStyle $style) { $paragraphStyle = $style->getParagraph(); $styleType = $style->getStyleType(); $type = ($styleType == 'title') ? 'paragraph' : 'character'; if (!is_null($paragraphStyle)) { $type = 'paragraph'; } $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', $type); // Heading style if ($styleType == 'title') { $arrStyle = explode('_', $styleName); if (count($arrStyle) > 1) { $styleId = 'Heading' . $arrStyle[1]; $styleName = 'heading ' . $arrStyle[1]; $styleLink = 'Heading' . $arrStyle[1] . 'Char'; } else { $styleId = $styleName; $styleName = strtolower($styleName); $styleLink = $styleName . 'Char'; } $xmlWriter->writeAttribute('w:styleId', $styleId); $xmlWriter->startElement('w:link'); $xmlWriter->writeAttribute('w:val', $styleLink); $xmlWriter->endElement(); } elseif (!is_null($paragraphStyle)) { // if type is 'paragraph' it should have a styleId $xmlWriter->writeAttribute('w:styleId', $styleName); } // Style name $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', $styleName); $xmlWriter->endElement(); // Parent style if (!is_null($paragraphStyle)) { if ($paragraphStyle->getStyleName() != null) { $xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName()); } elseif ($paragraphStyle->getBasedOn() != null) { $xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getBasedOn()); } } // w:pPr if (!is_null($paragraphStyle)) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle); $styleWriter->write(); } // w:rPr $styleWriter = new FontStyleWriter($xmlWriter, $style); $styleWriter->write(); $xmlWriter->endElement(); } /** * Write paragraph style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Paragraph $style */ private function writeParagraphStyle(XMLWriter $xmlWriter, $styleName, ParagraphStyle $style) { $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', 'paragraph'); $xmlWriter->writeAttribute('w:customStyle', '1'); $xmlWriter->writeAttribute('w:styleId', $styleName); $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', $styleName); $xmlWriter->endElement(); // Parent style $basedOn = $style->getBasedOn(); $xmlWriter->writeElementIf(!is_null($basedOn), 'w:basedOn', 'w:val', $basedOn); // Next paragraph style $next = $style->getNext(); $xmlWriter->writeElementIf(!is_null($next), 'w:next', 'w:val', $next); // w:pPr $styleWriter = new ParagraphStyleWriter($xmlWriter, $style); $styleWriter->write(); $xmlWriter->endElement(); } /** * Write table style. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Table $style */ private function writeTableStyle(XMLWriter $xmlWriter, $styleName, TableStyle $style) { $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', 'table'); $xmlWriter->writeAttribute('w:customStyle', '1'); $xmlWriter->writeAttribute('w:styleId', $styleName); $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', $styleName); $xmlWriter->endElement(); $xmlWriter->startElement('w:uiPriority'); $xmlWriter->writeAttribute('w:val', '99'); $xmlWriter->endElement(); $styleWriter = new TableStyleWriter($xmlWriter, $style); $styleWriter->write(); $xmlWriter->endElement(); // w:style } } phpword/src/PhpWord/Writer/RTF/Element/Text.php 0000664 00000003011 15177100670 0015337 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * Text element RTF writer * * @since 0.10.0 */ class Text extends AbstractElement { /** * Write element * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $elementClass = str_replace('\\Writer\\RTF', '', get_class($this)); if (!$element instanceof $elementClass || !is_string($element->getText())) { return ''; } $this->getStyles(); $content = ''; $content .= $this->writeOpening(); $content .= '{'; $content .= $this->writeFontStyle(); $content .= $this->writeText($element->getText()); $content .= '}'; $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/RTF/Element/Table.php 0000664 00000007055 15177100670 0015456 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; use PhpOffice\PhpWord\Element\Cell as CellElement; use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Table as TableElement; /** * Table element RTF writer * * @since 0.11.0 */ class Table extends AbstractElement { /** * Write element * * @return string */ public function write() { if (!$this->element instanceof TableElement) { return ''; } $element = $this->element; // No nesting table for now if ($element->getNestedLevel() >= 1) { return ''; } $content = ''; $rows = $element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $content .= '\pard' . PHP_EOL; for ($i = 0; $i < $rowCount; $i++) { $content .= '\trowd '; $content .= $this->writeRowDef($rows[$i]); $content .= PHP_EOL; $content .= $this->writeRow($rows[$i]); $content .= '\row' . PHP_EOL; } $content .= '\pard' . PHP_EOL; } return $content; } /** * Write column * * @param \PhpOffice\PhpWord\Element\Row $row * @return string */ private function writeRowDef(RowElement $row) { $content = ''; $rightMargin = 0; foreach ($row->getCells() as $cell) { $width = $cell->getWidth(); $vMerge = $this->getVMerge($cell->getStyle()->getVMerge()); if ($width === null) { $width = 720; // Arbitrary default width } $rightMargin += $width; $content .= "{$vMerge}\cellx{$rightMargin} "; } return $content; } /** * Write row * * @param \PhpOffice\PhpWord\Element\Row $row * @return string */ private function writeRow(RowElement $row) { $content = ''; // Write cells foreach ($row->getCells() as $cell) { $content .= $this->writeCell($cell); } return $content; } /** * Write cell * * @param \PhpOffice\PhpWord\Element\Cell $cell * @return string */ private function writeCell(CellElement $cell) { $content = '\intbl' . PHP_EOL; // Write content $writer = new Container($this->parentWriter, $cell); $content .= $writer->write(); $content .= '\cell' . PHP_EOL; return $content; } /** * Get vertical merge style * * @param string $value * @return string * @todo Move to style */ private function getVMerge($value) { $style = ''; if ($value == 'restart') { $style = '\clvmgf'; } elseif ($value == 'continue') { $style = '\clvmrg'; } return $style; } } phpword/src/PhpWord/Writer/RTF/Element/PageBreak.php 0000664 00000001712 15177100670 0016242 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * PageBreak element RTF writer * * @since 0.11.0 */ class PageBreak extends AbstractElement { /** * Write element * * @return string */ public function write() { return '\page' . PHP_EOL; } } phpword/src/PhpWord/Writer/RTF/Element/ListItem.php 0000664 00000001504 15177100670 0016152 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * ListItem element RTF writer; extends from text * * @since 0.11.0 */ class ListItem extends Text { } phpword/src/PhpWord/Writer/RTF/Element/Container.php 0000664 00000002067 15177100670 0016347 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; use PhpOffice\PhpWord\Writer\HTML\Element\Container as HTMLContainer; /** * Container element RTF writer * * @since 0.11.0 */ class Container extends HTMLContainer { /** * Namespace; Can't use __NAMESPACE__ in inherited class (RTF) * * @var string */ protected $namespace = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element'; } phpword/src/PhpWord/Writer/RTF/Element/Title.php 0000664 00000005711 15177100670 0015505 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * Title element RTF writer; extends from text * * @since 0.11.0 */ class Title extends Text { protected function getStyles() { /** @var \PhpOffice\PhpWord\Element\Title $element Type hint */ $element = $this->element; $style = $element->getStyle(); $style = str_replace('Heading', 'Heading_', $style); $style = \PhpOffice\PhpWord\Style::getStyle($style); if ($style instanceof \PhpOffice\PhpWord\Style\Font) { $this->fontStyle = $style; $pstyle = $style->getParagraph(); if ($pstyle instanceof \PhpOffice\PhpWord\Style\Paragraph && $pstyle->hasPageBreakBefore()) { $sect = $element->getParent(); if ($sect instanceof \PhpOffice\PhpWord\Element\Section) { $elems = $sect->getElements(); if ($elems[0] === $element) { $pstyle = clone $pstyle; $pstyle->setPageBreakBefore(false); } } } $this->paragraphStyle = $pstyle; } } /** * Write element * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Element\Title $element Type hint */ $element = $this->element; $elementClass = str_replace('\\Writer\\RTF', '', get_class($this)); if (!$element instanceof $elementClass || !is_string($element->getText())) { return ''; } $this->getStyles(); $content = ''; $content .= $this->writeOpening(); $endout = ''; $style = $element->getStyle(); if (is_string($style)) { $style = str_replace('Heading', '', $style); if (is_numeric($style)) { $style = (int) $style - 1; if ($style >= 0 && $style <= 8) { $content .= '{\\outlinelevel' . $style; $endout = '}'; } } } $content .= '{'; $content .= $this->writeFontStyle(); $content .= $this->writeText($element->getText()); $content .= '}'; $content .= $this->writeClosing(); $content .= $endout; return $content; } } phpword/src/PhpWord/Writer/RTF/Element/AbstractElement.php 0000664 00000012425 15177100670 0017501 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Escaper\Rtf; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Writer\AbstractWriter; use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; /** * Abstract RTF element writer * * @since 0.11.0 */ abstract class AbstractElement extends HTMLAbstractElement { /** * Font style * * @var \PhpOffice\PhpWord\Style\Font */ protected $fontStyle; /** * Paragraph style * * @var \PhpOffice\PhpWord\Style\Paragraph */ protected $paragraphStyle; public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false) { parent::__construct($parentWriter, $element, $withoutP); $this->escaper = new Rtf(); } /** * Get font and paragraph styles. */ protected function getStyles() { /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; // Font style if (method_exists($element, 'getFontStyle')) { $this->fontStyle = $element->getFontStyle(); if (is_string($this->fontStyle)) { $this->fontStyle = Style::getStyle($this->fontStyle); } } // Paragraph style if (method_exists($element, 'getParagraphStyle')) { $this->paragraphStyle = $element->getParagraphStyle(); if (is_string($this->paragraphStyle)) { $this->paragraphStyle = Style::getStyle($this->paragraphStyle); } if ($this->paragraphStyle !== null && !$this->withoutP) { if ($parentWriter->getLastParagraphStyle() != $element->getParagraphStyle()) { $parentWriter->setLastParagraphStyle($element->getParagraphStyle()); } else { $parentWriter->setLastParagraphStyle(); $this->paragraphStyle = null; } } else { $parentWriter->setLastParagraphStyle(); $this->paragraphStyle = null; } } } /** * Write opening * * @return string */ protected function writeOpening() { if ($this->withoutP || !$this->paragraphStyle instanceof ParagraphStyle) { return ''; } $styleWriter = new ParagraphStyleWriter($this->paragraphStyle); $styleWriter->setNestedLevel($this->element->getNestedLevel()); return $styleWriter->write(); } /** * Write text * * @param string $text * @return string */ protected function writeText($text) { if (Settings::isOutputEscapingEnabled()) { return $this->escaper->escape($text); } return SharedText::toUnicode($text); // todo: replace with `return $text;` later. } /** * Write closing * * @return string */ protected function writeClosing() { if ($this->withoutP) { return ''; } return '\par' . PHP_EOL; } /** * Write font style * * @return string */ protected function writeFontStyle() { if (!$this->fontStyle instanceof FontStyle) { return ''; } /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; // Create style writer and set color/name index $styleWriter = new FontStyleWriter($this->fontStyle); if ($this->fontStyle->getColor() != null) { $colorIndex = array_search($this->fontStyle->getColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { $styleWriter->setColorIndex($colorIndex + 1); } } if ($this->fontStyle->getName() != null) { $fontIndex = array_search($this->fontStyle->getName(), $parentWriter->getFontTable()); if ($fontIndex !== false) { $styleWriter->setNameIndex($fontIndex); } } // Write style $content = $styleWriter->write(); return $content; } } phpword/src/PhpWord/Writer/RTF/Element/TextBreak.php 0000664 00000002166 15177100670 0016316 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * TextBreak element RTF writer * * @since 0.10.0 */ class TextBreak extends AbstractElement { /** * Write element * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; $parentWriter->setLastParagraphStyle(); return '\pard\par' . PHP_EOL; } } phpword/src/PhpWord/Writer/RTF/Element/TextRun.php 0000664 00000002346 15177100670 0016036 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * TextRun element RTF writer * * @since 0.10.0 */ class TextRun extends AbstractElement { /** * Write element * * @return string */ public function write() { $writer = new Container($this->parentWriter, $this->element); $this->getStyles(); $content = ''; $content .= $this->writeOpening(); $content .= '{'; $content .= $writer->write(); $content .= '}'; $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/RTF/Element/Image.php 0000664 00000003250 15177100670 0015442 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; use PhpOffice\PhpWord\Element\Image as ImageElement; use PhpOffice\PhpWord\Shared\Converter; /** * Image element RTF writer * * @since 0.11.0 */ class Image extends AbstractElement { /** * Write element * * @return string */ public function write() { if (!$this->element instanceof ImageElement) { return ''; } $this->getStyles(); $style = $this->element->getStyle(); $content = ''; $content .= $this->writeOpening(); $content .= '{\*\shppict {\pict'; $content .= '\pngblip\picscalex100\picscaley100'; $content .= '\picwgoal' . round(Converter::pixelToTwip($style->getWidth())); $content .= '\pichgoal' . round(Converter::pixelToTwip($style->getHeight())); $content .= PHP_EOL; $content .= $this->element->getImageStringData(); $content .= '}}'; $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/RTF/Element/Link.php 0000664 00000002641 15177100670 0015320 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * Link element RTF writer * * @since 0.11.0 */ class Link extends AbstractElement { /** * Write element * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { return ''; } $this->getStyles(); $content = ''; $content .= $this->writeOpening(); $content .= '{\field {\*\fldinst {HYPERLINK "' . $this->element->getSource() . '"}}{\\fldrslt {'; $content .= $this->writeFontStyle(); $content .= $this->writeText($this->element->getText()); $content .= '}}}'; $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/RTF/Element/Field.php 0000664 00000004217 15177100670 0015447 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2019 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; /** * Field element writer * * Note: for now, only date, page and numpages fields are implemented for RTF. */ class Field extends Text { /** * Write field element. */ public function write() { $element = $this->element; if (!$element instanceof \PhpOffice\PhpWord\Element\Field) { return; } $this->getStyles(); $content = ''; $content .= $this->writeOpening(); $content .= '{'; $content .= $this->writeFontStyle(); $methodName = 'write' . ucfirst(strtolower($element->getType())); if (!method_exists($this, $methodName)) { // Unsupported field $content .= ''; } else { $content .= '\\field{\\*\\fldinst '; $content .= $this->$methodName($element); $content .= '}{\\fldrslt}'; } $content .= '}'; $content .= $this->writeClosing(); return $content; } protected function writePage() { return 'PAGE'; } protected function writeNumpages() { return 'NUMPAGES'; } protected function writeDate(\PhpOffice\PhpWord\Element\Field $element) { $content = ''; $content .= 'DATE'; $properties = $element->getProperties(); if (isset($properties['dateformat'])) { $content .= ' \\\\@ "' . $properties['dateformat'] . '"'; } return $content; } } phpword/src/PhpWord/Writer/RTF/Style/AbstractStyle.php 0000664 00000001625 15177100670 0016717 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; use PhpOffice\PhpWord\Writer\HTML\Style\AbstractStyle as HTMLAbstractStyle; /** * Abstract RTF style writer * * @since 0.11.0 */ abstract class AbstractStyle extends HTMLAbstractStyle { } phpword/src/PhpWord/Writer/RTF/Style/Paragraph.php 0000664 00000006734 15177100671 0016047 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; use PhpOffice\PhpWord\SimpleType\Jc; /** * RTF paragraph style writer * * @since 0.11.0 */ class Paragraph extends AbstractStyle { /** * 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; /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { return ''; } $alignments = array( Jc::START => '\ql', Jc::END => '\qr', Jc::CENTER => '\qc', Jc::BOTH => '\qj', ); $spaceAfter = $style->getSpaceAfter(); $spaceBefore = $style->getSpaceBefore(); $content = ''; if ($this->nestedLevel == 0) { $content .= '\pard\nowidctlpar '; } if (isset($alignments[$style->getAlignment()])) { $content .= $alignments[$style->getAlignment()]; } $content .= $this->writeIndentation($style->getIndentation()); $content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore)); $content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter)); $lineHeight = $style->getLineHeight(); if ($lineHeight) { $lineHeightAdjusted = (int) ($lineHeight * 240); $content .= "\\sl$lineHeightAdjusted\\slmult1"; } if ($style->hasPageBreakBefore()) { $content .= '\\page'; } $styles = $style->getStyleValues(); $content .= $this->writeTabs($styles['tabs']); return $content; } /** * Writes an \PhpOffice\PhpWord\Style\Indentation * * @param null|\PhpOffice\PhpWord\Style\Indentation $indent * @return string */ private function writeIndentation($indent = null) { if (isset($indent) && $indent instanceof \PhpOffice\PhpWord\Style\Indentation) { $writer = new Indentation($indent); return $writer->write(); } return ''; } /** * Writes tabs * * @param \PhpOffice\PhpWord\Style\Tab[] $tabs * @return string */ private function writeTabs($tabs = null) { $content = ''; if (!empty($tabs)) { foreach ($tabs as $tab) { $styleWriter = new Tab($tab); $content .= $styleWriter->write(); } } return $content; } /** * Set nested level. * * @param int $value */ public function setNestedLevel($value) { $this->nestedLevel = $value; } } phpword/src/PhpWord/Writer/RTF/Style/Indentation.php 0000664 00000002370 15177100671 0016406 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; /** * RTF indentation style writer * * @since 0.11.0 */ class Indentation extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) { return ''; } $content = '\fi' . round($style->getFirstLine()); $content .= '\li' . round($style->getLeft()); $content .= '\ri' . round($style->getRight()); return $content . ' '; } } phpword/src/PhpWord/Writer/RTF/Style/Font.php 0000664 00000004476 15177100671 0015051 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; /** * RTF font style writer * * @since 0.11.0 */ class Font extends AbstractStyle { /** * @var int Font name index */ private $nameIndex = 0; /** * @var int Font color index */ private $colorIndex = 0; /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof FontStyle) { return ''; } $content = ''; $content .= $this->getValueIf($style->isRTL(), '\rtlch'); $content .= '\cf' . $this->colorIndex; $content .= '\f' . $this->nameIndex; $size = $style->getSize(); $content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2)); $content .= $this->getValueIf($style->isBold(), '\b'); $content .= $this->getValueIf($style->isItalic(), '\i'); $content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul'); $content .= $this->getValueIf($style->isStrikethrough(), '\strike'); $content .= $this->getValueIf($style->isSuperScript(), '\super'); $content .= $this->getValueIf($style->isSubScript(), '\sub'); return $content . ' '; } /** * Set font name index. * * * @param int $value */ public function setNameIndex($value = 0) { $this->nameIndex = $value; } /** * Set font color index. * * @param int $value */ public function setColorIndex($value = 0) { $this->colorIndex = $value; } } phpword/src/PhpWord/Writer/RTF/Style/Tab.php 0000664 00000002714 15177100671 0014642 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; /** * Line numbering style writer * * @since 0.10.0 */ class Tab extends AbstractStyle { /** * Write style. */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) { return; } $tabs = array( \PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT => '\tqr', \PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER => '\tqc', \PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL => '\tqdec', ); $content = ''; if (isset($tabs[$style->getType()])) { $content .= $tabs[$style->getType()]; } $content .= '\tx' . round($style->getPosition()); return $content; } } phpword/src/PhpWord/Writer/RTF/Style/Border.php 0000664 00000006043 15177100671 0015350 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; /** * Border style writer * * @since 0.12.0 */ class Border extends AbstractStyle { /** * Sizes * * @var array */ private $sizes = array(); /** * Colors * * @var array */ private $colors = array(); /** * Write style * * @return string */ public function write() { $content = ''; $sides = array('top', 'left', 'right', 'bottom'); $sizeCount = count($this->sizes); // Page border measure // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off $content .= '\pgbrdropt32'; for ($i = 0; $i < $sizeCount; $i++) { if ($this->sizes[$i] !== null) { $color = null; if (isset($this->colors[$i])) { $color = $this->colors[$i]; } $content .= $this->writeSide($sides[$i], $this->sizes[$i], $color); } } return $content; } /** * Write side * * @param string $side * @param int $width * @param string $color * @return string */ private function writeSide($side, $width, $color = '') { /** @var \PhpOffice\PhpWord\Writer\RTF $rtfWriter */ $rtfWriter = $this->getParentWriter(); $colorIndex = 0; if ($rtfWriter !== null) { $colorTable = $rtfWriter->getColorTable(); $index = array_search($color, $colorTable); if ($index !== false && $colorIndex !== null) { $colorIndex = $index + 1; } } $content = ''; $content .= '\pgbrdr' . substr($side, 0, 1); $content .= '\brdrs'; // Single-thickness border; @todo Get other type of border $content .= '\brdrw' . round($width); // Width $content .= '\brdrcf' . $colorIndex; // Color $content .= '\brsp480'; // Space in twips between borders and the paragraph (24pt, following OOXML) $content .= ' '; return $content; } /** * Set sizes. * * @param int[] $value */ public function setSizes($value) { $this->sizes = $value; } /** * Set colors. * * @param string[] $value */ public function setColors($value) { $this->colors = $value; } } phpword/src/PhpWord/Writer/RTF/Style/Section.php 0000664 00000005411 15177100671 0015535 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; use PhpOffice\PhpWord\Style\Section as SectionStyle; /** * RTF section style writer * * @since 0.12.0 */ class Section extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof SectionStyle) { return ''; } $content = ''; $content .= '\sectd '; // Size & margin $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); $content .= ' '; $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop())); $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight())); $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom())); $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft())); $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight())); $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight())); $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter())); $content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart'); $content .= ' '; // Borders if ($style->hasBorder()) { $styleWriter = new Border($style); $styleWriter->setParentWriter($this->getParentWriter()); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setColors($style->getBorderColor()); $content .= $styleWriter->write(); } return $content . PHP_EOL; } } phpword/src/PhpWord/Writer/RTF/Part/AbstractPart.php 0000664 00000003402 15177100671 0016327 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Part; use PhpOffice\PhpWord\Escaper\Rtf; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Writer\AbstractWriter; /** * @since 0.11.0 */ abstract class AbstractPart { /** * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ private $parentWriter; /** * @var \PhpOffice\PhpWord\Escaper\EscaperInterface */ protected $escaper; public function __construct() { $this->escaper = new Rtf(); } /** * @return string */ abstract public function write(); /** * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer */ public function setParentWriter(AbstractWriter $writer = null) { $this->parentWriter = $writer; } /** * @throws \PhpOffice\PhpWord\Exception\Exception * @return \PhpOffice\PhpWord\Writer\AbstractWriter */ public function getParentWriter() { if ($this->parentWriter !== null) { return $this->parentWriter; } throw new Exception('No parent WriterInterface assigned.'); } } phpword/src/PhpWord/Writer/RTF/Part/Header.php 0000664 00000013637 15177100671 0015140 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Part; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\Converter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; /** * RTF header part writer * * - Character set * - Font table * - File table (not supported yet) * - Color table * - Style sheet (not supported yet) * - List table (not supported yet) * * @since 0.11.0 * @see http://www.biblioscape.com/rtf15_spec.htm#Heading6 */ class Header extends AbstractPart { /** * Font table * * @var array */ private $fontTable = array(); /** * Color table * * @var array */ private $colorTable = array(); /** * Get font table. * * @return array */ public function getFontTable() { return $this->fontTable; } /** * Get color table. * * @return array */ public function getColorTable() { return $this->colorTable; } /** * Write part * * @return string */ public function write() { $this->registerFont(); $content = ''; $content .= $this->writeCharset(); $content .= $this->writeDefaults(); $content .= $this->writeFontTable(); $content .= $this->writeColorTable(); $content .= $this->writeGenerator(); $content .= PHP_EOL; return $content; } /** * Write character set * * @return string */ private function writeCharset() { $content = ''; $content .= '\ansi'; $content .= '\ansicpg1252'; $content .= PHP_EOL; return $content; } /** * Write header defaults * * @return string */ private function writeDefaults() { $content = ''; $content .= '\deff0'; $content .= PHP_EOL; return $content; } /** * Write font table * * @return string */ private function writeFontTable() { $content = ''; $content .= '{'; $content .= '\fonttbl'; foreach ($this->fontTable as $index => $font) { $content .= "{\\f{$index}\\fnil\\fcharset0 {$font};}"; } $content .= '}'; $content .= PHP_EOL; return $content; } /** * Write color table * * @return string */ private function writeColorTable() { $content = ''; $content .= '{'; $content .= '\colortbl;'; foreach ($this->colorTable as $color) { list($red, $green, $blue) = Converter::htmlToRgb($color); $content .= "\\red{$red}\\green{$green}\\blue{$blue};"; } $content .= '}'; $content .= PHP_EOL; return $content; } /** * Write * * @return string */ private function writeGenerator() { $content = ''; $content .= '{\*\generator PHPWord;}'; // Set the generator $content .= PHP_EOL; return $content; } /** * Register all fonts and colors in both named and inline styles to appropriate header table. */ private function registerFont() { $phpWord = $this->getParentWriter()->getPhpWord(); $this->fontTable[] = Settings::getDefaultFontName(); // Search named styles $styles = Style::getStyles(); foreach ($styles as $style) { $this->registerFontItems($style); } // Search inline styles $sections = $phpWord->getSections(); foreach ($sections as $section) { $elements = $section->getElements(); $this->registerBorderColor($section->getStyle()); foreach ($elements as $element) { if (method_exists($element, 'getFontStyle')) { $style = $element->getFontStyle(); $this->registerFontItems($style); } } } } /** * Register border colors. * * @param \PhpOffice\PhpWord\Style\Border $style */ private function registerBorderColor($style) { $colors = $style->getBorderColor(); foreach ($colors as $color) { if ($color !== null) { $this->registerTableItem($this->colorTable, $color); } } } /** * Register fonts and colors. * * @param \PhpOffice\PhpWord\Style\AbstractStyle $style */ private function registerFontItems($style) { $defaultFont = Settings::getDefaultFontName(); $defaultColor = Settings::DEFAULT_FONT_COLOR; if ($style instanceof Font) { $this->registerTableItem($this->fontTable, $style->getName(), $defaultFont); $this->registerTableItem($this->colorTable, $style->getColor(), $defaultColor); $this->registerTableItem($this->colorTable, $style->getFgColor(), $defaultColor); } } /** * Register individual font and color. * * @param array &$table * @param string $value * @param string $default */ private function registerTableItem(&$table, $value, $default = null) { if (in_array($value, $table) === false && $value !== null && $value != $default) { $table[] = $value; } } } phpword/src/PhpWord/Writer/RTF/Part/Document.php 0000664 00000017347 15177100671 0015530 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Part; use PhpOffice\PhpWord\Element\Footer; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\RTF\Element\Container; use PhpOffice\PhpWord\Writer\RTF\Style\Section as SectionStyleWriter; /** * RTF document part writer * * @since 0.11.0 * @see http://www.biblioscape.com/rtf15_spec.htm#Heading24 */ class Document extends AbstractPart { /** * Write part * * @return string */ public function write() { $content = ''; $content .= $this->writeInfo(); $content .= $this->writeFormatting(); $content .= $this->writeSections(); return $content; } /** * Write document information * * @return string */ private function writeInfo() { $docProps = $this->getParentWriter()->getPhpWord()->getDocInfo(); $properties = array('title', 'subject', 'category', 'keywords', 'comment', 'author', 'operator', 'creatim', 'revtim', 'company', 'manager', ); $mapping = array( 'comment' => 'description', 'author' => 'creator', 'operator' => 'lastModifiedBy', 'creatim' => 'created', 'revtim' => 'modified', ); $dateFields = array('creatim', 'revtim'); $content = ''; $content .= '{'; $content .= '\info'; foreach ($properties as $property) { $method = 'get' . (isset($mapping[$property]) ? $mapping[$property] : $property); if (!in_array($property, $dateFields) && Settings::isOutputEscapingEnabled()) { $value = $this->escaper->escape($docProps->$method()); } else { $value = $docProps->$method(); } $value = in_array($property, $dateFields) ? $this->getDateValue($value) : $value; $content .= "{\\{$property} {$value}}"; } $content .= '}'; $content .= PHP_EOL; return $content; } /** * Write document formatting properties * * @return string */ private function writeFormatting() { $docSettings = $this->getParentWriter()->getPhpWord()->getSettings(); // Applies a language to a text run (defaults to 1036 : French (France)) $langId = $docSettings->getThemeFontLang() != null && $docSettings->getThemeFontLang()->getLangId() != null ? $docSettings->getThemeFontLang()->getLangId() : 1036; $content = ''; $content .= '\deftab720'; // Set the default tab size (720 twips) $content .= '\viewkind1'; // Set the view mode of the document $content .= '\uc1'; // Set the numberof bytes that follows a unicode character $content .= '\pard'; // Resets to default paragraph properties. $content .= '\nowidctlpar'; // No widow/orphan control $content .= '\lang' . $langId; $content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs $content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points if ($docSettings->hasEvenAndOddHeaders()) { $content .= '\\facingp'; } $content .= PHP_EOL; return $content; } /** * Write titlepg directive if any "f" headers or footers * * @param \PhpOffice\PhpWord\Element\Section $section * @return string */ private static function writeTitlepg($section) { foreach ($section->getHeaders() as $header) { if ($header->getType() === Footer::FIRST) { return '\\titlepg' . PHP_EOL; } } foreach ($section->getFooters() as $header) { if ($header->getType() === Footer::FIRST) { return '\\titlepg' . PHP_EOL; } } return ''; } /** * Write sections * * @return string */ private function writeSections() { $content = ''; $sections = $this->getParentWriter()->getPhpWord()->getSections(); $evenOdd = $this->getParentWriter()->getPhpWord()->getSettings()->hasEvenAndOddHeaders(); foreach ($sections as $section) { $styleWriter = new SectionStyleWriter($section->getStyle()); $styleWriter->setParentWriter($this->getParentWriter()); $content .= $styleWriter->write(); $content .= self::writeTitlepg($section); foreach ($section->getHeaders() as $header) { $type = $header->getType(); if ($evenOdd || $type !== FOOTER::EVEN) { $content .= '{\\header'; if ($type === Footer::FIRST) { $content .= 'f'; } elseif ($evenOdd) { $content .= ($type === FOOTER::EVEN) ? 'l' : 'r'; } foreach ($header->getElements() as $element) { $cl = get_class($element); $cl2 = str_replace('Element', 'Writer\\RTF\\Element', $cl); if (class_exists($cl2)) { $elementWriter = new $cl2($this->getParentWriter(), $element); $content .= $elementWriter->write(); } } $content .= '}' . PHP_EOL; } } foreach ($section->getFooters() as $footer) { $type = $footer->getType(); if ($evenOdd || $type !== FOOTER::EVEN) { $content .= '{\\footer'; if ($type === Footer::FIRST) { $content .= 'f'; } elseif ($evenOdd) { $content .= ($type === FOOTER::EVEN) ? 'l' : 'r'; } foreach ($footer->getElements() as $element) { $cl = get_class($element); $cl2 = str_replace('Element', 'Writer\\RTF\\Element', $cl); if (class_exists($cl2)) { $elementWriter = new $cl2($this->getParentWriter(), $element); $content .= $elementWriter->write(); } } $content .= '}' . PHP_EOL; } } $elementWriter = new Container($this->getParentWriter(), $section); $content .= $elementWriter->write(); $content .= '\sect' . PHP_EOL; } return $content; } /** * Get date value * * The format of date value is `\yr?\mo?\dy?\hr?\min?\sec?` * * @param int $value * @return string */ private function getDateValue($value) { $dateParts = array( 'Y' => 'yr', 'm' => 'mo', 'd' => 'dy', 'H' => 'hr', 'i' => 'min', 's' => 'sec', ); $result = ''; foreach ($dateParts as $dateFormat => $controlWord) { $result .= '\\' . $controlWord . date($dateFormat, $value); } return $result; } } phpword/src/PhpWord/Writer/HTML/Element/Text.php 0000664 00000015646 15177100671 0015472 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Paragraph as ParagraphStyleWriter; /** * Text element HTML writer * * @since 0.10.0 */ class Text extends AbstractElement { /** * Text written after opening * * @var string */ private $openingText = ''; /** * Text written before closing * * @var string */ private $closingText = ''; /** * Opening tags * * @var string */ private $openingTags = ''; /** * Closing tag * * @var string */ private $closingTags = ''; /** * Write text * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $this->getFontStyle(); $content = ''; $content .= $this->writeOpening(); $content .= $this->openingText; $content .= $this->openingTags; if (Settings::isOutputEscapingEnabled()) { $content .= $this->escaper->escapeHtml($element->getText()); } else { $content .= $element->getText(); } $content .= $this->closingTags; $content .= $this->closingText; $content .= $this->writeClosing(); return $content; } /** * Set opening text. * * @param string $value */ public function setOpeningText($value) { $this->openingText = $value; } /** * Set closing text. * * @param string $value */ public function setClosingText($value) { $this->closingText = $value; } /** * Write opening * * @return string */ protected function writeOpening() { $content = ''; if (!$this->withoutP) { $style = ''; if (method_exists($this->element, 'getParagraphStyle')) { $style = $this->getParagraphStyle(); } $content .= "<p{$style}>"; } //open track change tag $content .= $this->writeTrackChangeOpening(); return $content; } /** * Write ending * * @return string */ protected function writeClosing() { $content = ''; //close track change tag $content .= $this->writeTrackChangeClosing(); if (!$this->withoutP) { if (Settings::isOutputEscapingEnabled()) { $content .= $this->escaper->escapeHtml($this->closingText); } else { $content .= $this->closingText; } $content .= '</p>' . PHP_EOL; } return $content; } /** * writes the track change opening tag * * @return string the HTML, an empty string if no track change information */ private function writeTrackChangeOpening() { $changed = $this->element->getTrackChange(); if ($changed == null) { return ''; } $content = ''; if (($changed->getChangeType() == TrackChange::INSERTED)) { $content .= '<ins data-phpword-prop=\''; } elseif ($changed->getChangeType() == TrackChange::DELETED) { $content .= '<del data-phpword-prop=\''; } $changedProp = array('changed' => array('author'=> $changed->getAuthor(), 'id' => $this->element->getElementId())); if ($changed->getDate() != null) { $changedProp['changed']['date'] = $changed->getDate()->format('Y-m-d\TH:i:s\Z'); } $content .= json_encode($changedProp); $content .= '\' '; $content .= 'title="' . $changed->getAuthor(); if ($changed->getDate() != null) { $dateUser = $changed->getDate()->format('Y-m-d H:i:s'); $content .= ' - ' . $dateUser; } $content .= '">'; return $content; } /** * writes the track change closing tag * * @return string the HTML, an empty string if no track change information */ private function writeTrackChangeClosing() { $changed = $this->element->getTrackChange(); if ($changed == null) { return ''; } $content = ''; if (($changed->getChangeType() == TrackChange::INSERTED)) { $content .= '</ins>'; } elseif ($changed->getChangeType() == TrackChange::DELETED) { $content .= '</del>'; } return $content; } /** * Write paragraph style * * @return string */ private function getParagraphStyle() { /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $style = ''; if (!method_exists($element, 'getParagraphStyle')) { return $style; } $paragraphStyle = $element->getParagraphStyle(); $pStyleIsObject = ($paragraphStyle instanceof Paragraph); if ($pStyleIsObject) { $styleWriter = new ParagraphStyleWriter($paragraphStyle); $style = $styleWriter->write(); } elseif (is_string($paragraphStyle)) { $style = $paragraphStyle; } if ($style) { $attribute = $pStyleIsObject ? 'style' : 'class'; $style = " {$attribute}=\"{$style}\""; } return $style; } /** * Get font style. */ private function getFontStyle() { /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $style = ''; $fontStyle = $element->getFontStyle(); $fStyleIsObject = ($fontStyle instanceof Font); if ($fStyleIsObject) { $styleWriter = new FontStyleWriter($fontStyle); $style = $styleWriter->write(); } elseif (is_string($fontStyle)) { $style = $fontStyle; } if ($style) { $attribute = $fStyleIsObject ? 'style' : 'class'; $this->openingTags = "<span {$attribute}=\"{$style}\">"; $this->closingTags = '</span>'; } } } phpword/src/PhpWord/Writer/HTML/Element/Table.php 0000664 00000014061 15177100671 0015563 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * Table element HTML writer * * @since 0.10.0 */ class Table extends AbstractElement { /** * Write table * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) { return ''; } $content = ''; $rows = $this->element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $content .= '<table' . self::getTableStyle($this->element->getStyle()) . '>' . PHP_EOL; for ($i = 0; $i < $rowCount; $i++) { /** @var $row \PhpOffice\PhpWord\Element\Row Type hint */ $rowStyle = $rows[$i]->getStyle(); // $height = $row->getHeight(); $tblHeader = $rowStyle->isTblHeader(); $content .= '<tr>' . PHP_EOL; $rowCells = $rows[$i]->getCells(); $rowCellCount = count($rowCells); for ($j = 0; $j < $rowCellCount; $j++) { $cellStyle = $rowCells[$j]->getStyle(); $cellBgColor = $cellStyle->getBgColor(); $cellBgColor === 'auto' && $cellBgColor = null; // auto cannot be parsed to hexadecimal number $cellFgColor = null; if ($cellBgColor) { $red = hexdec(substr($cellBgColor, 0, 2)); $green = hexdec(substr($cellBgColor, 2, 2)); $blue = hexdec(substr($cellBgColor, 4, 2)); $cellFgColor = (($red * 0.299 + $green * 0.587 + $blue * 0.114) > 186) ? null : 'ffffff'; } $cellColSpan = $cellStyle->getGridSpan(); $cellRowSpan = 1; $cellVMerge = $cellStyle->getVMerge(); // If this is the first cell of the vertical merge, find out how man rows it spans if ($cellVMerge === 'restart') { for ($k = $i + 1; $k < $rowCount; $k++) { $kRowCells = $rows[$k]->getCells(); if (isset($kRowCells[$j])) { if ($kRowCells[$j]->getStyle()->getVMerge() === 'continue') { $cellRowSpan++; } else { break; } } else { break; } } } // Ignore cells that are merged vertically with previous rows if ($cellVMerge !== 'continue') { $cellTag = $tblHeader ? 'th' : 'td'; $cellColSpanAttr = (is_numeric($cellColSpan) && ($cellColSpan > 1) ? " colspan=\"{$cellColSpan}\"" : ''); $cellRowSpanAttr = ($cellRowSpan > 1 ? " rowspan=\"{$cellRowSpan}\"" : ''); $cellBgColorAttr = (is_null($cellBgColor) ? '' : " bgcolor=\"#{$cellBgColor}\""); $cellFgColorAttr = (is_null($cellFgColor) ? '' : " color=\"#{$cellFgColor}\""); $content .= "<{$cellTag}{$cellColSpanAttr}{$cellRowSpanAttr}{$cellBgColorAttr}{$cellFgColorAttr}>" . PHP_EOL; $writer = new Container($this->parentWriter, $rowCells[$j]); $content .= $writer->write(); if ($cellRowSpan > 1) { // There shouldn't be any content in the subsequent merged cells, but lets check anyway for ($k = $i + 1; $k < $rowCount; $k++) { $kRowCells = $rows[$k]->getCells(); if (isset($kRowCells[$j])) { if ($kRowCells[$j]->getStyle()->getVMerge() === 'continue') { $writer = new Container($this->parentWriter, $kRowCells[$j]); $content .= $writer->write(); } else { break; } } else { break; } } } $content .= "</{$cellTag}>" . PHP_EOL; } } $content .= '</tr>' . PHP_EOL; } $content .= '</table>' . PHP_EOL; } return $content; } /** * Translates Table style in CSS equivalent * * @param string|\PhpOffice\PhpWord\Style\Table|null $tableStyle * @return string */ private function getTableStyle($tableStyle = null) { if ($tableStyle == null) { return ''; } if (is_string($tableStyle)) { $style = ' class="' . $tableStyle; } else { $style = ' style="'; if ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_FIXED) { $style .= 'table-layout: fixed;'; } elseif ($tableStyle->getLayout() == \PhpOffice\PhpWord\Style\Table::LAYOUT_AUTO) { $style .= 'table-layout: auto;'; } } return $style . '"'; } } phpword/src/PhpWord/Writer/HTML/Element/ListItemRun.php 0000664 00000002247 15177100671 0016756 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * ListItem element HTML writer * * @since 0.10.0 */ class ListItemRun extends TextRun { /** * Write list item * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { return ''; } $writer = new Container($this->parentWriter, $this->element); $content = $writer->write() . PHP_EOL; return $content; } } phpword/src/PhpWord/Writer/HTML/Element/PageBreak.php 0000664 00000002341 15177100671 0016353 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * PageBreak element HTML writer * * @since 0.10.0 */ class PageBreak extends TextBreak { /** * Write page break * * @since 0.12.0 * * @return string */ public function write() { /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->parentWriter; if ($parentWriter->isPdf()) { return '<pagebreak style="page-break-before: always;" pagebreak="true"></pagebreak>'; } return ''; } } phpword/src/PhpWord/Writer/HTML/Element/ListItem.php 0000664 00000002573 15177100671 0016273 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Settings; /** * ListItem element HTML writer * * @since 0.10.0 */ class ListItem extends AbstractElement { /** * Write list item * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) { return ''; } if (Settings::isOutputEscapingEnabled()) { $content = '<p>' . $this->escaper->escapeHtml($this->element->getTextObject()->getText()) . '</p>' . PHP_EOL; } else { $content = '<p>' . $this->element->getTextObject()->getText() . '</p>' . PHP_EOL; } return $content; } } phpword/src/PhpWord/Writer/HTML/Element/Container.php 0000664 00000004102 15177100671 0016451 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; /** * Container element HTML writer * * @since 0.11.0 */ class Container extends AbstractElement { /** * Namespace; Can't use __NAMESPACE__ in inherited class (RTF) * * @var string */ protected $namespace = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element'; /** * Write container * * @return string */ public function write() { $container = $this->element; if (!$container instanceof ContainerElement) { return ''; } $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote')) ? true : false; $content = ''; $elements = $container->getElements(); foreach ($elements as $element) { $elementClass = get_class($element); $writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass); if (class_exists($writerClass)) { /** @var \PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement $writer Type hint */ $writer = new $writerClass($this->parentWriter, $element, $withoutP); $content .= $writer->write(); } } return $content; } } phpword/src/PhpWord/Writer/HTML/Element/Title.php 0000664 00000003107 15177100671 0015614 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Settings; /** * TextRun element HTML writer * * @since 0.10.0 */ class Title extends AbstractElement { /** * Write heading * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) { return ''; } $tag = 'h' . $this->element->getDepth(); $text = $this->element->getText(); if (is_string($text)) { if (Settings::isOutputEscapingEnabled()) { $text = $this->escaper->escapeHtml($text); } } elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { $writer = new Container($this->parentWriter, $text); $text = $writer->write(); } $content = "<{$tag}>{$text}</{$tag}>" . PHP_EOL; return $content; } } phpword/src/PhpWord/Writer/HTML/Element/AbstractElement.php 0000664 00000004140 15177100671 0017606 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use Laminas\Escaper\Escaper; use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Writer\AbstractWriter; /** * Abstract HTML element writer * * @since 0.11.0 */ abstract class AbstractElement { /** * Parent writer * * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ protected $parentWriter; /** * Element * * @var \PhpOffice\PhpWord\Element\AbstractElement */ protected $element; /** * Without paragraph * * @var bool */ protected $withoutP = false; /** * @var \Laminas\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper */ protected $escaper; /** * Write element */ abstract public function write(); /** * Create new instance * * @param \PhpOffice\PhpWord\Writer\AbstractWriter $parentWriter * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP */ public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false) { $this->parentWriter = $parentWriter; $this->element = $element; $this->withoutP = $withoutP; $this->escaper = new Escaper(); } /** * Set without paragraph. * * @param bool $value */ public function setWithoutP($value) { $this->withoutP = $value; } } phpword/src/PhpWord/Writer/HTML/Element/Bookmark.php 0000664 00000002326 15177100671 0016302 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * Bookmark element HTML writer * * @since 0.15.0 */ class Bookmark extends Text { /** * Write bookmark * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Bookmark) { return ''; } $content = ''; $content .= $this->writeOpening(); $content .= "<a name=\"{$this->element->getName()}\"/>"; $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/HTML/Element/TextBreak.php 0000664 00000002136 15177100671 0016425 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * TextBreak element HTML writer * * @since 0.10.0 */ class TextBreak extends AbstractElement { /** * Write text break * * @return string */ public function write() { if ($this->withoutP) { $content = '<br />' . PHP_EOL; } else { $content = '<p> </p>' . PHP_EOL; } return $content; } } phpword/src/PhpWord/Writer/HTML/Element/TextRun.php 0000664 00000002220 15177100671 0016137 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * TextRun element HTML writer * * @since 0.10.0 */ class TextRun extends Text { /** * Write text run * * @return string */ public function write() { $content = ''; $content .= $this->writeOpening(); $writer = new Container($this->parentWriter, $this->element); $content .= $writer->write(); $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/HTML/Element/Image.php 0000664 00000003217 15177100671 0015557 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Element\Image as ImageElement; use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter; /** * Image element HTML writer * * @since 0.10.0 */ class Image extends Text { /** * Write image * * @return string */ public function write() { if (!$this->element instanceof ImageElement) { return ''; } $content = ''; $imageData = $this->element->getImageStringData(true); if ($imageData !== null) { $styleWriter = new ImageStyleWriter($this->element->getStyle()); $style = $styleWriter->write(); $imageData = 'data:' . $this->element->getImageType() . ';base64,' . $imageData; $content .= $this->writeOpening(); $content .= "<img border=\"0\" style=\"{$style}\" src=\"{$imageData}\"/>"; $content .= $this->writeClosing(); } return $content; } } phpword/src/PhpWord/Writer/HTML/Element/Endnote.php 0000664 00000001625 15177100671 0016132 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * Endnote element HTML writer * * @since 0.10.0 */ class Endnote extends Footnote { /** * Note type * * @var string */ protected $noteType = 'endnote'; } phpword/src/PhpWord/Writer/HTML/Element/Link.php 0000664 00000003057 15177100671 0015434 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; use PhpOffice\PhpWord\Settings; /** * Link element HTML writer * * @since 0.10.0 */ class Link extends Text { /** * Write link * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { return ''; } $prefix = $this->element->isInternal() ? '#' : ''; $content = $this->writeOpening(); if (Settings::isOutputEscapingEnabled()) { $content .= "<a href=\"{$prefix}{$this->escaper->escapeHtmlAttr($this->element->getSource())}\">{$this->escaper->escapeHtml($this->element->getText())}</a>"; } else { $content .= "<a href=\"{$prefix}{$this->element->getSource()}\">{$this->element->getText()}</a>"; } $content .= $this->writeClosing(); return $content; } } phpword/src/PhpWord/Writer/HTML/Element/Footnote.php 0000664 00000003222 15177100671 0016326 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; /** * Footnote element HTML writer * * @since 0.10.0 */ class Footnote extends AbstractElement { /** * Note type footnote|endnote * * @var string */ protected $noteType = 'footnote'; /** * Write footnote/endnote marks; The actual content is written in parent writer (HTML) * * @return string */ public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) { return ''; } /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->parentWriter; $noteId = count($parentWriter->getNotes()) + 1; $noteMark = $this->noteType . '-' . $this->element->getRelationId(); $content = "<a name=\"{$noteMark}\"><a href=\"#note-{$noteId}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>"; $parentWriter->addNote($noteId, $noteMark); return $content; } } phpword/src/PhpWord/Writer/HTML/Style/AbstractStyle.php 0000664 00000005410 15177100671 0017025 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; use PhpOffice\PhpWord\Style\AbstractStyle as Style; /** * Style writer * * @since 0.10.0 */ abstract class AbstractStyle { /** * Parent writer * * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ private $parentWriter; /** * Style * * @var array|\PhpOffice\PhpWord\Style\AbstractStyle */ private $style; /** * Write style */ abstract public function write(); /** * Create new instance * * @param array|\PhpOffice\PhpWord\Style\AbstractStyle $style */ public function __construct($style = null) { $this->style = $style; } /** * Set parent writer. * * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer */ public function setParentWriter($writer) { $this->parentWriter = $writer; } /** * Get parent writer * * @return \PhpOffice\PhpWord\Writer\AbstractWriter */ public function getParentWriter() { return $this->parentWriter; } /** * Get style * * @return array|\PhpOffice\PhpWord\Style\AbstractStyle $style */ public function getStyle() { if (!$this->style instanceof Style && !is_array($this->style)) { return ''; } return $this->style; } /** * Takes array where of CSS properties / values and converts to CSS string * * @param array $css * @return string */ protected function assembleCss($css) { $pairs = array(); $string = ''; foreach ($css as $key => $value) { if ($value != '') { $pairs[] = $key . ': ' . $value; } } if (!empty($pairs)) { $string = implode('; ', $pairs) . ';'; } return $string; } /** * Get value if ... * * @param bool|null $condition * @param string $value * @return string */ protected function getValueIf($condition, $value) { return $condition == true ? $value : ''; } } phpword/src/PhpWord/Writer/HTML/Style/Paragraph.php 0000664 00000004762 15177100671 0016157 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; use PhpOffice\PhpWord\SimpleType\Jc; /** * Paragraph style HTML writer * * @since 0.10.0 */ class Paragraph extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { return ''; } $css = array(); // Alignment if ('' !== $style->getAlignment()) { $textAlign = ''; switch ($style->getAlignment()) { case Jc::CENTER: $textAlign = 'center'; break; case Jc::END: case Jc::MEDIUM_KASHIDA: case Jc::HIGH_KASHIDA: case Jc::LOW_KASHIDA: case Jc::RIGHT: $textAlign = 'right'; break; case Jc::BOTH: case Jc::DISTRIBUTE: case Jc::THAI_DISTRIBUTE: case Jc::JUSTIFY: $textAlign = 'justify'; break; default: //all others, align left $textAlign = 'left'; break; } $css['text-align'] = $textAlign; } // Spacing $spacing = $style->getSpace(); if (!is_null($spacing)) { $before = $spacing->getBefore(); $after = $spacing->getAfter(); $css['margin-top'] = $this->getValueIf(!is_null($before), ($before / 20) . 'pt'); $css['margin-bottom'] = $this->getValueIf(!is_null($after), ($after / 20) . 'pt'); } else { $css['margin-top'] = '0'; $css['margin-bottom'] = '0'; } return $this->assembleCss($css); } } phpword/src/PhpWord/Writer/HTML/Style/Font.php 0000664 00000005220 15177100671 0015146 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; /** * Font style HTML writer * * @since 0.10.0 */ class Font extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof FontStyle) { return ''; } $css = array(); $font = $style->getName(); $size = $style->getSize(); $color = $style->getColor(); $fgColor = $style->getFgColor(); $underline = $style->getUnderline() != FontStyle::UNDERLINE_NONE; $lineThrough = $style->isStrikethrough() || $style->isDoubleStrikethrough(); $css['font-family'] = $this->getValueIf($font !== null, "'{$font}'"); $css['font-size'] = $this->getValueIf($size !== null, "{$size}pt"); $css['color'] = $this->getValueIf($color !== null, "#{$color}"); $css['background'] = $this->getValueIf($fgColor != '', $fgColor); $css['font-weight'] = $this->getValueIf($style->isBold(), 'bold'); $css['font-style'] = $this->getValueIf($style->isItalic(), 'italic'); $css['vertical-align'] = ''; $css['vertical-align'] .= $this->getValueIf($style->isSuperScript(), 'super'); $css['vertical-align'] .= $this->getValueIf($style->isSubScript(), 'sub'); $css['text-decoration'] = ''; $css['text-decoration'] .= $this->getValueIf($underline, 'underline '); $css['text-decoration'] .= $this->getValueIf($lineThrough, 'line-through '); $css['text-transform'] = $this->getValueIf($style->isAllCaps(), 'uppercase'); $css['font-variant'] = $this->getValueIf($style->isSmallCaps(), 'small-caps'); $css['display'] = $this->getValueIf($style->isHidden(), 'none'); $spacing = $style->getSpacing(); $css['letter-spacing'] = $this->getValueIf(!is_null($spacing), ($spacing / 20) . 'pt'); return $this->assembleCss($css); } } phpword/src/PhpWord/Writer/HTML/Style/Image.php 0000664 00000002522 15177100671 0015264 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; /** * Paragraph style HTML writer * * @since 0.10.0 */ class Image extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { return ''; } $css = array(); $width = $style->getWidth(); $height = $style->getHeight(); $css['width'] = $this->getValueIf(is_numeric($width), $width . 'px'); $css['height'] = $this->getValueIf(is_numeric($height), $height . 'px'); return $this->assembleCss($css); } } phpword/src/PhpWord/Writer/HTML/Style/Generic.php 0000664 00000002127 15177100671 0015617 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; /** * Generic style writer * * @since 0.10.0 */ class Generic extends AbstractStyle { /** * Write style * * @return string */ public function write() { $style = $this->getStyle(); $css = array(); if (is_array($style) && !empty($style)) { $css = $style; } return $this->assembleCss($css); } } phpword/src/PhpWord/Writer/HTML/Part/AbstractPart.php 0000664 00000003365 15177100671 0016450 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Part; use Laminas\Escaper\Escaper; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Writer\AbstractWriter; /** * @since 0.11.0 */ abstract class AbstractPart { /** * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ private $parentWriter; /** * @var \Laminas\Escaper\Escaper */ protected $escaper; public function __construct() { $this->escaper = new Escaper(); } /** * @return string */ abstract public function write(); /** * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer */ public function setParentWriter(AbstractWriter $writer = null) { $this->parentWriter = $writer; } /** * @throws \PhpOffice\PhpWord\Exception\Exception * * @return \PhpOffice\PhpWord\Writer\AbstractWriter */ public function getParentWriter() { if ($this->parentWriter !== null) { return $this->parentWriter; } throw new Exception('No parent WriterInterface assigned.'); } } phpword/src/PhpWord/Writer/HTML/Part/Head.php 0000664 00000011102 15177100671 0014703 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Part; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Generic as GenericStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Paragraph as ParagraphStyleWriter; /** * RTF head part writer * * @since 0.11.0 */ class Head extends AbstractPart { /** * Write part * * @return string */ public function write() { $docProps = $this->getParentWriter()->getPhpWord()->getDocInfo(); $propertiesMapping = array( 'creator' => 'author', 'title' => '', 'description' => '', 'subject' => '', 'keywords' => '', 'category' => '', 'company' => '', 'manager' => '', ); $title = $docProps->getTitle(); $title = ($title != '') ? $title : 'PHPWord'; $content = ''; $content .= '<head>' . PHP_EOL; $content .= '<meta charset="UTF-8" />' . PHP_EOL; $content .= '<title>' . $title . '</title>' . PHP_EOL; foreach ($propertiesMapping as $key => $value) { $value = ($value == '') ? $key : $value; $method = 'get' . $key; if ($docProps->$method() != '') { $content .= '<meta name="' . $value . '"' . ' content="' . (Settings::isOutputEscapingEnabled() ? $this->escaper->escapeHtmlAttr($docProps->$method()) : $docProps->$method()) . '"' . ' />' . PHP_EOL; } } $content .= $this->writeStyles(); $content .= '</head>' . PHP_EOL; return $content; } /** * Get styles * * @return string */ private function writeStyles() { $css = '<style>' . PHP_EOL; // Default styles $defaultStyles = array( '*' => array( 'font-family' => Settings::getDefaultFontName(), 'font-size' => Settings::getDefaultFontSize() . 'pt', ), 'a.NoteRef' => array( 'text-decoration' => 'none', ), 'hr' => array( 'height' => '1px', 'padding' => '0', 'margin' => '1em 0', 'border' => '0', 'border-top' => '1px solid #CCC', ), 'table' => array( 'border' => '1px solid black', 'border-spacing' => '0px', 'width ' => '100%', ), 'td' => array( 'border' => '1px solid black', ), ); foreach ($defaultStyles as $selector => $style) { $styleWriter = new GenericStyleWriter($style); $css .= $selector . ' {' . $styleWriter->write() . '}' . PHP_EOL; } // Custom styles $customStyles = Style::getStyles(); if (is_array($customStyles)) { foreach ($customStyles as $name => $style) { if ($style instanceof Font) { $styleWriter = new FontStyleWriter($style); if ($style->getStyleType() == 'title') { $name = str_replace('Heading_', 'h', $name); } else { $name = '.' . $name; } $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL; } elseif ($style instanceof Paragraph) { $styleWriter = new ParagraphStyleWriter($style); $name = '.' . $name; $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL; } } } $css .= '</style>' . PHP_EOL; return $css; } } phpword/src/PhpWord/Writer/HTML/Part/Body.php 0000664 00000005316 15177100671 0014751 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Part; use PhpOffice\PhpWord\Writer\HTML\Element\Container; use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter; /** * RTF body part writer * * @since 0.11.0 */ class Body extends AbstractPart { /** * Write part * * @return string */ public function write() { $phpWord = $this->getParentWriter()->getPhpWord(); $content = ''; $content .= '<body>' . PHP_EOL; $sections = $phpWord->getSections(); foreach ($sections as $section) { $writer = new Container($this->getParentWriter(), $section); $content .= $writer->write(); } $content .= $this->writeNotes(); $content .= '</body>' . PHP_EOL; return $content; } /** * Write footnote/endnote contents as textruns * * @return string */ private function writeNotes() { /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $phpWord = $parentWriter->getPhpWord(); $notes = $parentWriter->getNotes(); $content = ''; if (!empty($notes)) { $content .= '<hr />' . PHP_EOL; foreach ($notes as $noteId => $noteMark) { list($noteType, $noteTypeId) = explode('-', $noteMark); $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $collection = $phpWord->$method()->getItems(); if (isset($collection[$noteTypeId])) { $element = $collection[$noteTypeId]; $noteAnchor = "<a name=\"note-{$noteId}\" />"; $noteAnchor .= "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>"; $writer = new TextRunWriter($this->getParentWriter(), $element); $writer->setOpeningText($noteAnchor); $content .= $writer->write(); } } } return $content; } } phpword/src/PhpWord/Writer/RTF.php 0000664 00000005734 15177100671 0013041 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; /** * RTF writer * * @since 0.7.0 */ class RTF extends AbstractWriter implements WriterInterface { /** * Last paragraph style * * @var mixed */ private $lastParagraphStyle; /** * Create new instance * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function __construct(PhpWord $phpWord = null) { $this->setPhpWord($phpWord); $this->parts = array('Header', 'Document'); foreach ($this->parts as $partName) { $partClass = get_class($this) . '\\Part\\' . $partName; if (class_exists($partClass)) { /** @var \PhpOffice\PhpWord\Writer\RTF\Part\AbstractPart $part Type hint */ $part = new $partClass(); $part->setParentWriter($this); $this->writerParts[strtolower($partName)] = $part; } } } /** * Save content to file. * * @param string $filename * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { $this->writeFile($this->openFile($filename), $this->getContent()); } /** * Get content * * @return string * @since 0.11.0 */ private function getContent() { $content = ''; $content .= '{'; $content .= '\rtf1' . PHP_EOL; $content .= $this->getWriterPart('Header')->write(); $content .= $this->getWriterPart('Document')->write(); $content .= '}'; return $content; } /** * Get font table. * * @return array */ public function getFontTable() { return $this->getWriterPart('Header')->getFontTable(); } /** * Get color table. * * @return array */ public function getColorTable() { return $this->getWriterPart('Header')->getColorTable(); } /** * Get last paragraph style. * * @return mixed */ public function getLastParagraphStyle() { return $this->lastParagraphStyle; } /** * Set last paragraph style. * * @param mixed $value */ public function setLastParagraphStyle($value = '') { $this->lastParagraphStyle = $value; } } phpword/src/PhpWord/Writer/PDF.php 0000664 00000005246 15177100671 0013015 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PhpWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; /** * PDF Writer * * @since 0.10.0 */ class PDF { /** * The wrapper for the requested PDF rendering engine * * @var \PhpOffice\PhpWord\Writer\PDF\AbstractRenderer */ private $renderer = null; /** * Instantiate a new renderer of the configured type within this container class * * @param \PhpOffice\PhpWord\PhpWord $phpWord * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) { $pdfLibraryName = Settings::getPdfRendererName(); $pdfLibraryPath = Settings::getPdfRendererPath(); if (is_null($pdfLibraryName) || is_null($pdfLibraryPath)) { throw new Exception('PDF rendering library or library path has not been defined.'); } $includePath = str_replace('\\', '/', get_include_path()); $rendererPath = str_replace('\\', '/', $pdfLibraryPath); if (strpos($rendererPath, $includePath) === false) { set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath); } $rendererName = get_class($this) . '\\' . $pdfLibraryName; $this->renderer = new $rendererName($phpWord); } /** * Magic method to handle direct calls to the configured PDF renderer wrapper class. * * @param string $name Renderer library method name * @param mixed[] $arguments Array of arguments to pass to the renderer method * @return mixed Returned data from the PDF renderer wrapper method */ public function __call($name, $arguments) { // Note: Commented because all exceptions should already be catched by `__construct` // if ($this->renderer === null) { // throw new Exception("PDF Rendering library has not been defined."); // } return call_user_func_array(array($this->renderer, $name), $arguments); } } phpword/src/PhpWord/Writer/Word2007.php 0000664 00000027220 15177100671 0013624 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\ZipArchive; /** * Word2007 writer */ class Word2007 extends AbstractWriter implements WriterInterface { /** * Content types values * * @var array */ private $contentTypes = array('default' => array(), 'override' => array()); /** * Document relationship * * @var array */ private $relationships = array(); /** * Create new Word2007 writer * * @param \PhpOffice\PhpWord\PhpWord */ public function __construct(PhpWord $phpWord = null) { // Assign PhpWord $this->setPhpWord($phpWord); // Create parts $this->parts = array( 'ContentTypes' => '[Content_Types].xml', 'Rels' => '_rels/.rels', 'DocPropsApp' => 'docProps/app.xml', 'DocPropsCore' => 'docProps/core.xml', 'DocPropsCustom' => 'docProps/custom.xml', 'RelsDocument' => 'word/_rels/document.xml.rels', 'Document' => 'word/document.xml', 'Comments' => 'word/comments.xml', 'Styles' => 'word/styles.xml', 'Numbering' => 'word/numbering.xml', 'Settings' => 'word/settings.xml', 'WebSettings' => 'word/webSettings.xml', 'FontTable' => 'word/fontTable.xml', 'Theme' => 'word/theme/theme1.xml', 'RelsPart' => '', 'Header' => '', 'Footer' => '', 'Footnotes' => '', 'Endnotes' => '', 'Chart' => '', ); foreach (array_keys($this->parts) as $partName) { $partClass = get_class($this) . '\\Part\\' . $partName; if (class_exists($partClass)) { /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $part Type hint */ $part = new $partClass(); $part->setParentWriter($this); $this->writerParts[strtolower($partName)] = $part; } } // Set package paths $this->mediaPaths = array('image' => 'word/media/', 'object' => 'word/embeddings/'); } /** * Save document by name. * * @param string $filename */ public function save($filename = null) { $filename = $this->getTempFile($filename); $zip = $this->getZipArchive($filename); $phpWord = $this->getPhpWord(); // Content types $this->contentTypes['default'] = array( 'rels' => 'application/vnd.openxmlformats-package.relationships+xml', 'xml' => 'application/xml', ); // Add section media files $sectionMedia = Media::getElements('section'); if (!empty($sectionMedia)) { $this->addFilesToPackage($zip, $sectionMedia); $this->registerContentTypes($sectionMedia); foreach ($sectionMedia as $element) { $this->relationships[] = $element; } } // Add header/footer media files & relations $this->addHeaderFooterMedia($zip, 'header'); $this->addHeaderFooterMedia($zip, 'footer'); // Add header/footer contents $rId = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements $sections = $phpWord->getSections(); foreach ($sections as $section) { $this->addHeaderFooterContent($section, $zip, 'header', $rId); $this->addHeaderFooterContent($section, $zip, 'footer', $rId); } $this->addNotes($zip, $rId, 'footnote'); $this->addNotes($zip, $rId, 'endnote'); $this->addComments($zip, $rId); $this->addChart($zip, $rId); // Write parts foreach ($this->parts as $partName => $fileName) { if ($fileName != '') { $zip->addFromString($fileName, $this->getWriterPart($partName)->write()); } } // Close zip archive and cleanup temp file $zip->close(); $this->cleanupTempFile(); } /** * Get content types * * @return array */ public function getContentTypes() { return $this->contentTypes; } /** * Get content types * * @return array */ public function getRelationships() { return $this->relationships; } /** * Add header/footer media files, e.g. footer1.xml.rels. * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param string $docPart */ private function addHeaderFooterMedia(ZipArchive $zip, $docPart) { $elements = Media::getElements($docPart); if (!empty($elements)) { foreach ($elements as $file => $media) { if (count($media) > 0) { if (!empty($media)) { $this->addFilesToPackage($zip, $media); $this->registerContentTypes($media); } /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $writerPart Type hint */ $writerPart = $this->getWriterPart('relspart')->setMedia($media); $zip->addFromString("word/_rels/{$file}.xml.rels", $writerPart->write()); } } } } /** * Add header/footer content. * * @param \PhpOffice\PhpWord\Element\Section &$section * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param string $elmType header|footer * @param int &$rId */ private function addHeaderFooterContent(Section &$section, ZipArchive $zip, $elmType, &$rId) { $getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters'; $elmCount = ($section->getSectionId() - 1) * 3; $elements = $section->$getFunction(); /** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */ foreach ($elements as &$element) { $elmCount++; $element->setRelationId(++$rId); $elmFile = "{$elmType}{$elmCount}.xml"; // e.g. footer1.xml $this->contentTypes['override']["/word/$elmFile"] = $elmType; $this->relationships[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rId); /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $writerPart Type hint */ $writerPart = $this->getWriterPart($elmType)->setElement($element); $zip->addFromString("word/$elmFile", $writerPart->write()); } } /** * Add footnotes/endnotes * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param int &$rId * @param string $noteType */ private function addNotes(ZipArchive $zip, &$rId, $noteType = 'footnote') { $phpWord = $this->getPhpWord(); $noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote'; $partName = "{$noteType}s"; $method = 'get' . $partName; $collection = $phpWord->$method(); // Add footnotes media files, relations, and contents /** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collection Type hint */ if ($collection->countItems() > 0) { $media = Media::getElements($noteType); $this->addFilesToPackage($zip, $media); $this->registerContentTypes($media); $this->contentTypes['override']["/word/{$partName}.xml"] = $partName; $this->relationships[] = array('target' => "{$partName}.xml", 'type' => $partName, 'rID' => ++$rId); // Write relationships file, e.g. word/_rels/footnotes.xml if (!empty($media)) { /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $writerPart Type hint */ $writerPart = $this->getWriterPart('relspart')->setMedia($media); $zip->addFromString("word/_rels/{$partName}.xml.rels", $writerPart->write()); } // Write content file, e.g. word/footnotes.xml $writerPart = $this->getWriterPart($partName)->setElements($collection->getItems()); $zip->addFromString("word/{$partName}.xml", $writerPart->write()); } } /** * Add comments * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param int &$rId */ private function addComments(ZipArchive $zip, &$rId) { $phpWord = $this->getPhpWord(); $collection = $phpWord->getComments(); $partName = 'comments'; // Add comment relations and contents /** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collection Type hint */ if ($collection->countItems() > 0) { $this->relationships[] = array('target' => "{$partName}.xml", 'type' => $partName, 'rID' => ++$rId); // Write content file, e.g. word/comments.xml $writerPart = $this->getWriterPart($partName)->setElements($collection->getItems()); $zip->addFromString("word/{$partName}.xml", $writerPart->write()); } } /** * Add chart. * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param int &$rId */ private function addChart(ZipArchive $zip, &$rId) { $phpWord = $this->getPhpWord(); $collection = $phpWord->getCharts(); $index = 0; if ($collection->countItems() > 0) { /** @var \PhpOffice\PhpWord\Element\Chart $chart */ foreach ($collection->getItems() as $chart) { $index++; $rId++; $filename = "charts/chart{$index}.xml"; // ContentTypes.xml $this->contentTypes['override']["/word/{$filename}"] = 'chart'; // word/_rels/document.xml.rel $this->relationships[] = array('target' => $filename, 'type' => 'chart', 'rID' => $rId); // word/charts/chartN.xml $chart->setRelationId($rId); $writerPart = $this->getWriterPart('Chart'); $writerPart->setElement($chart); $zip->addFromString("word/{$filename}", $writerPart->write()); } } } /** * Register content types for each media. * * @param array $media */ private function registerContentTypes($media) { foreach ($media as $medium) { $mediumType = $medium['type']; if ($mediumType == 'image') { $extension = $medium['imageExtension']; if (!isset($this->contentTypes['default'][$extension])) { $this->contentTypes['default'][$extension] = $medium['imageType']; } } elseif ($mediumType == 'object') { if (!isset($this->contentTypes['default']['bin'])) { $this->contentTypes['default']['bin'] = 'application/vnd.openxmlformats-officedocument.oleObject'; } } } } } phpword/src/PhpWord/Writer/HTML.php 0000664 00000006231 15177100671 0013143 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; /** * HTML writer * * Not supported: PreserveText, PageBreak, Object * @since 0.10.0 */ class HTML extends AbstractWriter implements WriterInterface { /** * Is the current writer creating PDF? * * @var bool */ protected $isPdf = false; /** * Footnotes and endnotes collection * * @var array */ protected $notes = array(); /** * Create new instance */ public function __construct(PhpWord $phpWord = null) { $this->setPhpWord($phpWord); $this->parts = array('Head', 'Body'); foreach ($this->parts as $partName) { $partClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Part\\' . $partName; if (class_exists($partClass)) { /** @var \PhpOffice\PhpWord\Writer\HTML\Part\AbstractPart $part Type hint */ $part = new $partClass(); $part->setParentWriter($this); $this->writerParts[strtolower($partName)] = $part; } } } /** * Save PhpWord to file. * * @param string $filename * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { $this->writeFile($this->openFile($filename), $this->getContent()); } /** * Get content * * @return string * @since 0.11.0 */ public function getContent() { $content = ''; $content .= '<!DOCTYPE html>' . PHP_EOL; $content .= '<!-- Generated by PHPWord -->' . PHP_EOL; $content .= '<html>' . PHP_EOL; $content .= $this->getWriterPart('Head')->write(); $content .= $this->getWriterPart('Body')->write(); $content .= '</html>' . PHP_EOL; return $content; } /** * Get is PDF * * @return bool */ public function isPdf() { return $this->isPdf; } /** * Get notes * * @return array */ public function getNotes() { return $this->notes; } /** * Add note. * * @param int $noteId * @param string $noteMark */ public function addNote($noteId, $noteMark) { $this->notes[$noteId] = $noteMark; } /** * Write document * * @deprecated 0.11.0 * * @return string * * @codeCoverageIgnore */ public function writeDocument() { return $this->getContent(); } } phpword/src/PhpWord/Writer/AbstractWriter.php 0000664 00000025177 15177100671 0015351 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Exception\CopyFileException; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\ZipArchive; /** * Abstract writer class * * @since 0.10.0 */ abstract class AbstractWriter implements WriterInterface { /** * PHPWord object * * @var \PhpOffice\PhpWord\PhpWord */ protected $phpWord = null; /** * Part name and file name pairs * * @var array */ protected $parts = array(); /** * Individual writers * * @var array */ protected $writerParts = array(); /** * Paths to store media files * * @var array */ protected $mediaPaths = array('image' => '', 'object' => ''); /** * Use disk caching * * @var bool */ private $useDiskCaching = false; /** * Disk caching directory * * @var string */ private $diskCachingDirectory = './'; /** * Temporary directory * * @var string */ private $tempDir = ''; /** * Original file name * * @var string */ private $originalFilename; /** * Temporary file name * * @var string */ private $tempFilename; /** * Get PhpWord object * * @throws \PhpOffice\PhpWord\Exception\Exception * @return \PhpOffice\PhpWord\PhpWord */ public function getPhpWord() { if (!is_null($this->phpWord)) { return $this->phpWord; } throw new Exception('No PhpWord assigned.'); } /** * Set PhpWord object * * @param \PhpOffice\PhpWord\PhpWord * @return self */ public function setPhpWord(PhpWord $phpWord = null) { $this->phpWord = $phpWord; return $this; } /** * Get writer part * * @param string $partName Writer part name * @return mixed */ public function getWriterPart($partName = '') { if ($partName != '' && isset($this->writerParts[strtolower($partName)])) { return $this->writerParts[strtolower($partName)]; } return null; } /** * Get use disk caching status * * @return bool */ public function isUseDiskCaching() { return $this->useDiskCaching; } /** * Set use disk caching status * * @param bool $value * @param string $directory * * @throws \PhpOffice\PhpWord\Exception\Exception * @return self */ public function setUseDiskCaching($value = false, $directory = null) { $this->useDiskCaching = $value; if (!is_null($directory)) { if (is_dir($directory)) { $this->diskCachingDirectory = $directory; } else { throw new Exception("Directory does not exist: $directory"); } } return $this; } /** * Get disk caching directory * * @return string */ public function getDiskCachingDirectory() { return $this->diskCachingDirectory; } /** * Get temporary directory * * @return string */ public function getTempDir() { return $this->tempDir; } /** * Set temporary directory * * @param string $value * @return self */ public function setTempDir($value) { if (!is_dir($value)) { mkdir($value); } $this->tempDir = $value; return $this; } /** * Get temporary file name * * If $filename is php://output or php://stdout, make it a temporary file * * @param string $filename * @return string */ protected function getTempFile($filename) { // Temporary directory $this->setTempDir(Settings::getTempDir() . uniqid('/PHPWordWriter_', true) . '/'); // Temporary file $this->originalFilename = $filename; if (strpos(strtolower($filename), 'php://') === 0) { $filename = tempnam(Settings::getTempDir(), 'PhpWord'); if (false === $filename) { $filename = $this->originalFilename; // @codeCoverageIgnore } // @codeCoverageIgnore } $this->tempFilename = $filename; return $this->tempFilename; } /** * Cleanup temporary file. * * @throws \PhpOffice\PhpWord\Exception\CopyFileException */ protected function cleanupTempFile() { if ($this->originalFilename != $this->tempFilename) { // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. if (false === copy($this->tempFilename, $this->originalFilename)) { throw new CopyFileException($this->tempFilename, $this->originalFilename); } // @codeCoverageIgnoreEnd @unlink($this->tempFilename); } $this->clearTempDir(); } /** * Clear temporary directory. */ protected function clearTempDir() { if (is_dir($this->tempDir)) { $this->deleteDir($this->tempDir); } } /** * Get ZipArchive object * * @param string $filename * * @throws \Exception * * @return \PhpOffice\PhpWord\Shared\ZipArchive */ protected function getZipArchive($filename) { // Remove any existing file if (file_exists($filename)) { unlink($filename); } // Try opening the ZIP file $zip = new ZipArchive(); // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. if ($zip->open($filename, ZipArchive::OVERWRITE) !== true) { if ($zip->open($filename, ZipArchive::CREATE) !== true) { throw new \Exception("Could not open '{$filename}' for writing."); } } // @codeCoverageIgnoreEnd return $zip; } /** * Open file for writing * * @since 0.11.0 * * @param string $filename * * @throws \Exception * * @return resource */ protected function openFile($filename) { $filename = $this->getTempFile($filename); $fileHandle = fopen($filename, 'w'); // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. if ($fileHandle === false) { throw new \Exception("Could not open '{$filename}' for writing."); } // @codeCoverageIgnoreEnd return $fileHandle; } /** * Write content to file. * * @since 0.11.0 * * @param resource $fileHandle * @param string $content */ protected function writeFile($fileHandle, $content) { fwrite($fileHandle, $content); fclose($fileHandle); $this->cleanupTempFile(); } /** * Add files to package. * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip * @param mixed $elements */ protected function addFilesToPackage(ZipArchive $zip, $elements) { foreach ($elements as $element) { $type = $element['type']; // image|object|link // Skip nonregistered types and set target if (!isset($this->mediaPaths[$type])) { continue; } $target = $this->mediaPaths[$type] . $element['target']; // Retrive GD image content or get local media if (isset($element['isMemImage']) && $element['isMemImage']) { $image = call_user_func($element['createFunction'], $element['source']); if ($element['imageType'] === 'image/png') { // PNG images need to preserve alpha channel information imagesavealpha($image, true); } ob_start(); call_user_func($element['imageFunction'], $image); $imageContents = ob_get_contents(); ob_end_clean(); $zip->addFromString($target, $imageContents); imagedestroy($image); } else { $this->addFileToPackage($zip, $element['source'], $target); } } } /** * Add file to package. * * Get the actual source from an archive image. * * @param \PhpOffice\PhpWord\Shared\ZipArchive $zipPackage * @param string $source * @param string $target */ protected function addFileToPackage($zipPackage, $source, $target) { $isArchive = strpos($source, 'zip://') !== false; $actualSource = null; if ($isArchive) { $source = substr($source, 6); list($zipFilename, $imageFilename) = explode('#', $source); $zip = new ZipArchive(); if ($zip->open($zipFilename) !== false) { if ($zip->locateName($imageFilename)) { $zip->extractTo($this->getTempDir(), $imageFilename); $actualSource = $this->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename; } } $zip->close(); } else { $actualSource = $source; } if (!is_null($actualSource)) { $zipPackage->addFile($actualSource, $target); } } /** * Delete directory. * * @param string $dir */ private function deleteDir($dir) { foreach (scandir($dir) as $file) { if ($file === '.' || $file === '..') { continue; } elseif (is_file($dir . '/' . $file)) { unlink($dir . '/' . $file); } elseif (is_dir($dir . '/' . $file)) { $this->deleteDir($dir . '/' . $file); } } rmdir($dir); } /** * Get use disk caching status * * @deprecated 0.10.0 * * @codeCoverageIgnore */ public function getUseDiskCaching() { return $this->isUseDiskCaching(); } } phpword/src/PhpWord/Writer/WriterInterface.php 0000664 00000001602 15177100671 0015471 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; /** * Writer interface */ interface WriterInterface { /** * Save PhpWord to file * * @param string $filename */ public function save($filename = null); } phpword/src/PhpWord/Writer/ODText.php 0000664 00000005260 15177100671 0013547 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; /** * ODText writer * * @since 0.7.0 */ class ODText extends AbstractWriter implements WriterInterface { /** * Create new ODText writer * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function __construct(PhpWord $phpWord = null) { // Assign PhpWord $this->setPhpWord($phpWord); // Create parts $this->parts = array( 'Mimetype' => 'mimetype', 'Content' => 'content.xml', 'Meta' => 'meta.xml', 'Styles' => 'styles.xml', 'Manifest' => 'META-INF/manifest.xml', ); foreach (array_keys($this->parts) as $partName) { $partClass = get_class($this) . '\\Part\\' . $partName; if (class_exists($partClass)) { /** @var $partObject \PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart Type hint */ $partObject = new $partClass(); $partObject->setParentWriter($this); $this->writerParts[strtolower($partName)] = $partObject; } } // Set package paths $this->mediaPaths = array('image' => 'Pictures/'); } /** * Save PhpWord to file. * * @param string $filename */ public function save($filename = null) { $filename = $this->getTempFile($filename); $zip = $this->getZipArchive($filename); // Add section media files $sectionMedia = Media::getElements('section'); if (!empty($sectionMedia)) { $this->addFilesToPackage($zip, $sectionMedia); } // Write parts foreach ($this->parts as $partName => $fileName) { if ($fileName != '') { $zip->addFromString($fileName, $this->getWriterPart($partName)->write()); } } // Close zip archive and cleanup temp file $zip->close(); $this->cleanupTempFile(); } } phpword/src/PhpWord/Exception/Exception.php 0000664 00000001421 15177100671 0015013 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * General exception */ class Exception extends \Exception { } phpword/src/PhpWord/Exception/CopyFileException.php 0000664 00000002541 15177100671 0016452 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * @since 0.12.0 */ final class CopyFileException extends Exception { /** * @param string $source The fully qualified source file name * @param string $destination The fully qualified destination file name * @param int $code The user defined exception code * @param \Exception $previous The previous exception used for the exception chaining */ final public function __construct($source, $destination, $code = 0, \Exception $previous = null) { parent::__construct( sprintf('Could not copy \'%s\' file to \'%s\'.', $source, $destination), $code, $previous ); } } phpword/src/PhpWord/Exception/CreateTemporaryFileException.php 0000664 00000002320 15177100671 0020641 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * @since 0.12.0 */ final class CreateTemporaryFileException extends Exception { /** * @param int $code The user defined exception code * @param \Exception $previous The previous exception used for the exception chaining */ final public function __construct($code = 0, \Exception $previous = null) { parent::__construct( 'Could not create a temporary file with unique name in the specified directory.', $code, $previous ); } } phpword/src/PhpWord/Exception/InvalidObjectException.php 0000664 00000001471 15177100671 0017456 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * Exception used for when an image is not found */ class InvalidObjectException extends Exception { } phpword/src/PhpWord/Exception/InvalidImageException.php 0000664 00000001470 15177100671 0017271 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * Exception used for when an image is not found */ class InvalidImageException extends Exception { } phpword/src/PhpWord/Exception/UnsupportedImageTypeException.php 0000664 00000001507 15177100671 0021076 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; /** * Exception used for when an image type is unsupported */ class UnsupportedImageTypeException extends Exception { } phpword/src/PhpWord/Exception/InvalidStyleException.php 0000664 00000001551 15177100671 0017347 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Exception; use InvalidArgumentException; /** * Exception used for when a style value is invalid */ class InvalidStyleException extends InvalidArgumentException { } phpword/src/PhpWord/Element/Text.php 0000664 00000007526 15177100671 0013450 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; /** * Text element */ class Text extends AbstractElement { /** * Text content * * @var string */ protected $text; /** * Text style * * @var string|\PhpOffice\PhpWord\Style\Font */ protected $fontStyle; /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ protected $paragraphStyle; /** * Create a new Text Element * * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) { $this->setText($text); $paragraphStyle = $this->setParagraphStyle($paragraphStyle); $this->setFontStyle($fontStyle, $paragraphStyle); } /** * Set Text style * * @param string|array|\PhpOffice\PhpWord\Style\Font $style * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle * @return string|\PhpOffice\PhpWord\Style\Font */ public function setFontStyle($style = null, $paragraphStyle = null) { if ($style instanceof Font) { $this->fontStyle = $style; $this->setParagraphStyle($paragraphStyle); } elseif (is_array($style)) { $this->fontStyle = new Font('text', $paragraphStyle); $this->fontStyle->setStyleByArray($style); } elseif (null === $style) { $this->fontStyle = new Font('text', $paragraphStyle); } else { $this->fontStyle = $style; $this->setParagraphStyle($paragraphStyle); } return $this->fontStyle; } /** * Get Text style * * @return string|\PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { return $this->fontStyle; } /** * Set Paragraph style * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function setParagraphStyle($style = null) { if (is_array($style)) { $this->paragraphStyle = new Paragraph(); $this->paragraphStyle->setStyleByArray($style); } elseif ($style instanceof Paragraph) { $this->paragraphStyle = $style; } elseif (null === $style) { $this->paragraphStyle = new Paragraph(); } else { $this->paragraphStyle = $style; } return $this->paragraphStyle; } /** * Get Paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Set text content * * @param string $text * @return self */ public function setText($text) { $this->text = SharedText::toUTF8($text); return $this; } /** * Get Text content * * @return string */ public function getText() { return $this->text; } } phpword/src/PhpWord/Element/Chart.php 0000664 00000005470 15177100671 0013561 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Chart as ChartStyle; /** * Chart element * * @since 0.12.0 */ class Chart extends AbstractElement { /** * Is part of collection * * @var bool */ protected $collectionRelation = true; /** * Type * * @var string */ private $type = 'pie'; /** * Series * * @var array */ private $series = array(); /** * Chart style * * @var \PhpOffice\PhpWord\Style\Chart */ private $style; /** * Create new instance * * @param string $type * @param array $categories * @param array $values * @param array $style * @param null|mixed $seriesName */ public function __construct($type, $categories, $values, $style = null, $seriesName = null) { $this->setType($type); $this->addSeries($categories, $values, $seriesName); $this->style = $this->setNewStyle(new ChartStyle(), $style, true); } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set type. * * @param string $value */ public function setType($value) { $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter'); $this->type = $this->setEnumVal($value, $enum, 'pie'); } /** * Add series * * @param array $categories * @param array $values * @param null|mixed $name */ public function addSeries($categories, $values, $name = null) { $this->series[] = array( 'categories' => $categories, 'values' => $values, 'name' => $name, ); } /** * Get series * * @return array */ public function getSeries() { return $this->series; } /** * Get chart style * * @return \PhpOffice\PhpWord\Style\Chart */ public function getStyle() { return $this->style; } } phpword/src/PhpWord/Element/Table.php 0000664 00000007222 15177100671 0013544 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Table as TableStyle; /** * Table element */ class Table extends AbstractElement { /** * Table style * * @var \PhpOffice\PhpWord\Style\Table */ private $style; /** * Table rows * * @var \PhpOffice\PhpWord\Element\Row[] */ private $rows = array(); /** * Table width * * @var int */ private $width = null; /** * Create a new table * * @param mixed $style */ public function __construct($style = null) { $this->style = $this->setNewStyle(new TableStyle(), $style); } /** * Add a row * * @param int $height * @param mixed $style * @return \PhpOffice\PhpWord\Element\Row */ public function addRow($height = null, $style = null) { $row = new Row($height, $style); $row->setParentContainer($this); $this->rows[] = $row; return $row; } /** * Add a cell * * @param int $width * @param mixed $style * @return \PhpOffice\PhpWord\Element\Cell */ public function addCell($width = null, $style = null) { $index = count($this->rows) - 1; $row = $this->rows[$index]; $cell = $row->addCell($width, $style); return $cell; } /** * Get all rows * * @return \PhpOffice\PhpWord\Element\Row[] */ public function getRows() { return $this->rows; } /** * Get table style * * @return \PhpOffice\PhpWord\Style\Table */ public function getStyle() { return $this->style; } /** * Get table width * * @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 int */ public function countColumns() { $columnCount = 0; $rowCount = count($this->rows); for ($i = 0; $i < $rowCount; $i++) { /** @var \PhpOffice\PhpWord\Element\Row $row Type hint */ $row = $this->rows[$i]; $cellCount = count($row->getCells()); if ($columnCount < $cellCount) { $columnCount = $cellCount; } } return $columnCount; } /** * The first declared cell width for each column * * @return int[] */ public function findFirstDefinedCellWidths() { $cellWidths = array(); foreach ($this->rows as $row) { $cells = $row->getCells(); if (count($cells) <= count($cellWidths)) { continue; } $cellWidths = array(); foreach ($cells as $cell) { $cellWidths[] = $cell->getWidth(); } } return $cellWidths; } } phpword/src/PhpWord/Element/Comment.php 0000664 00000005505 15177100671 0014121 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Comment element * @see http://datypic.com/sc/ooxml/t-w_CT_Comment.html */ class Comment extends TrackChange { /** * Initials * * @var string */ private $initials; /** * The Element where this comment starts * * @var AbstractElement */ private $startElement; /** * The Element where this comment ends * * @var AbstractElement */ private $endElement; /** * Is part of collection * * @var bool */ protected $collectionRelation = true; /** * Create a new Comment Element * * @param string $author * @param null|\DateTime $date * @param string $initials */ public function __construct($author, $date = null, $initials = null) { parent::__construct(null, $author, $date); $this->initials = $initials; } /** * Get Initials * * @return string */ public function getInitials() { return $this->initials; } /** * Sets the element where this comment starts * * @param \PhpOffice\PhpWord\Element\AbstractElement $value */ public function setStartElement(AbstractElement $value) { $this->startElement = $value; if ($value->getCommentRangeStart() == null) { $value->setCommentRangeStart($this); } } /** * Get the element where this comment starts * * @return \PhpOffice\PhpWord\Element\AbstractElement */ public function getStartElement() { return $this->startElement; } /** * Sets the element where this comment ends * * @param \PhpOffice\PhpWord\Element\AbstractElement $value */ public function setEndElement(AbstractElement $value) { $this->endElement = $value; if ($value->getCommentRangeEnd() == null) { $value->setCommentRangeEnd($this); } } /** * Get the element where this comment ends * * @return \PhpOffice\PhpWord\Element\AbstractElement */ public function getEndElement() { return $this->endElement; } } phpword/src/PhpWord/Element/AbstractContainer.php 0000664 00000027233 15177100671 0016127 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Container abstract class * * @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null) * @method TextRun addTextRun(mixed $pStyle = null) * @method Bookmark addBookmark(string $name) * @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false) * @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null) * @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null) * @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null) * @method ListItemRun addListItemRun(int $depth = 0, mixed $listStyle = null, mixed $pStyle = null) * @method Footnote addFootnote(mixed $pStyle = null) * @method Endnote addEndnote(mixed $pStyle = null) * @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null) * @method Title addTitle(mixed $text, int $depth = 1) * @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9) * @method PageBreak addPageBreak() * @method Table addTable(mixed $style = null) * @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false, $name = null) * @method OLEObject addOLEObject(string $source, mixed $style = null) * @method TextBox addTextBox(mixed $style = null) * @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null) * @method Line addLine(mixed $lineStyle = null) * @method Shape addShape(string $type, mixed $style = null) * @method Chart addChart(string $type, array $categories, array $values, array $style = null, $seriesName = null) * @method FormField addFormField(string $type, mixed $fStyle = null, mixed $pStyle = null) * @method SDT addSDT(string $type) * * @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null) deprecated, use addOLEObject instead * * @since 0.10.0 */ abstract class AbstractContainer extends AbstractElement { /** * Elements collection * * @var \PhpOffice\PhpWord\Element\AbstractElement[] */ protected $elements = array(); /** * Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun|TrackChange * * @var string */ 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', 'Bookmark', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'OLEObject', 'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line', 'Shape', 'Title', 'TOC', 'PageBreak', 'Chart', 'FormField', 'SDT', 'Comment', ); $functions = array(); foreach ($elements as $element) { $functions['add' . strtolower($element)] = $element == 'Object' ? 'OLEObject' : $element; } // Run valid `add` command $function = strtolower($function); if (isset($functions[$function])) { $element = $functions[$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) = array_pad($args, 3, null); if ($count === null) { $count = 1; } for ($i = 1; $i <= $count; $i++) { $this->addElement($element, $fontStyle, $paragraphStyle); } } else { // All other elements 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 } // 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 parent container $element->setParentContainer($this); $element->setElementIndex($this->countElements() + 1); $element->setElementId(); $this->elements[] = $element; return $element; } /** * Get all elements * * @return \PhpOffice\PhpWord\Element\AbstractElement[] */ public function getElements() { return $this->elements; } /** * Returns the element at the requested position * * @param int $index * @return \PhpOffice\PhpWord\Element\AbstractElement|null */ public function getElement($index) { if (array_key_exists($index, $this->elements)) { return $this->elements[$index]; } return null; } /** * Removes the element at requested index * * @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove */ public function removeElement($toRemove) { if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) { unset($this->elements[$toRemove]); } elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) { foreach ($this->elements as $key => $element) { if ($element->getElementId() === $toRemove->getElementId()) { unset($this->elements[$key]); return; } } } } /** * Count elements * * @return int */ public function countElements() { return count($this->elements); } /** * Check if a method is allowed for the current container * * @param string $method * * @throws \BadMethodCallException * @return bool */ private function checkValidity($method) { $generalContainers = array( 'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun', 'TrackChange', ); $validContainers = array( 'Text' => $generalContainers, 'Bookmark' => $generalContainers, 'Link' => $generalContainers, 'TextBreak' => $generalContainers, 'Image' => $generalContainers, 'OLEObject' => $generalContainers, 'Field' => $generalContainers, 'Line' => $generalContainers, 'Shape' => $generalContainers, 'FormField' => $generalContainers, 'SDT' => $generalContainers, 'TrackChange' => $generalContainers, 'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox', 'TrackChange', 'ListItemRun'), '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', 'TextRun'), 'TextBox' => array('Section', 'Header', 'Footer', 'Cell'), 'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'), 'Endnote' => array('Section', 'TextRun', 'Cell'), 'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'), 'Title' => array('Section', 'Cell'), 'TOC' => array('Section'), 'PageBreak' => array('Section'), 'Chart' => array('Section', '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', 'Section')), 'Footnote' => array(array('Cell', 'TextRun'), array('Section')), 'Endnote' => array(array('Cell', 'TextRun'), array('Section')), ); // Check if a method is valid for current container if (isset($validContainers[$method])) { if (!in_array($this->container, $validContainers[$method])) { throw new \BadMethodCallException("Cannot add {$method} in {$this->container}."); } } // Check if a method is valid for current container, located in other container if (isset($validSubcontainers[$method])) { $rules = $validSubcontainers[$method]; $containers = $rules[0]; $allowedDocParts = $rules[1]; foreach ($containers as $container) { if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) { throw new \BadMethodCallException("Cannot add {$method} in {$this->container}."); } } } return true; } /** * Create textrun element * * @deprecated 0.10.0 * * @param mixed $paragraphStyle * * @return \PhpOffice\PhpWord\Element\TextRun * * @codeCoverageIgnore */ public function createTextRun($paragraphStyle = null) { return $this->addTextRun($paragraphStyle); } /** * Create footnote element * * @deprecated 0.10.0 * * @param mixed $paragraphStyle * * @return \PhpOffice\PhpWord\Element\Footnote * * @codeCoverageIgnore */ public function createFootnote($paragraphStyle = null) { return $this->addFootnote($paragraphStyle); } } phpword/src/PhpWord/Element/ListItemRun.php 0000664 00000004046 15177100671 0014735 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; /** * 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->setNewStyle(new ListItemStyle(), $listStyle, true); } parent::__construct($paragraphStyle); } /** * Get ListItem style. * * @return \PhpOffice\PhpWord\Style\ListItem */ public function getStyle() { return $this->style; } /** * Get ListItem depth. * * @return int */ public function getDepth() { return $this->depth; } } phpword/src/PhpWord/Element/PageBreak.php 0000664 00000001560 15177100671 0014335 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Page break element */ class PageBreak extends AbstractElement { /** * Create new page break */ public function __construct() { } } phpword/src/PhpWord/Element/Line.php 0000664 00000002425 15177100671 0013404 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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->setNewStyle(new LineStyle(), $style); } /** * Get line style * * @return \PhpOffice\PhpWord\Style\Line */ public function getStyle() { return $this->style; } } phpword/src/PhpWord/Element/ListItem.php 0000664 00000005123 15177100671 0014245 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; /** * List item element */ class ListItem extends AbstractElement { /** * Element style * * @var \PhpOffice\PhpWord\Style\ListItem */ private $style; /** * Text object * * @var \PhpOffice\PhpWord\Element\Text */ private $textObject; /** * Depth * * @var int */ private $depth; /** * Create a new ListItem * * @param string $text * @param int $depth * @param mixed $fontStyle * @param array|string|null $listStyle * @param mixed $paragraphStyle */ public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null) { $this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle); $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); // @codeCoverageIgnore } else { $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); } } /** * Get style * * @return \PhpOffice\PhpWord\Style\ListItem */ public function getStyle() { return $this->style; } /** * Get Text object * * @return \PhpOffice\PhpWord\Element\Text */ public function getTextObject() { return $this->textObject; } /** * 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(); } } phpword/src/PhpWord/Element/Row.php 0000664 00000004317 15177100671 0013266 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Row as RowStyle; /** * Table row element * * @since 0.8.0 */ class Row extends AbstractElement { /** * Row height * * @var int */ private $height = null; /** * Row style * * @var \PhpOffice\PhpWord\Style\Row */ private $style; /** * Row cells * * @var \PhpOffice\PhpWord\Element\Cell[] */ private $cells = array(); /** * Create a new table row * * @param int $height * @param mixed $style */ public function __construct($height = null, $style = null) { $this->height = $height; $this->style = $this->setNewStyle(new RowStyle(), $style, true); } /** * Add a cell * * @param int $width * @param mixed $style * @return \PhpOffice\PhpWord\Element\Cell */ public function addCell($width = null, $style = null) { $cell = new Cell($width, $style); $cell->setParentContainer($this); $this->cells[] = $cell; return $cell; } /** * Get all cells * * @return \PhpOffice\PhpWord\Element\Cell[] */ public function getCells() { return $this->cells; } /** * Get row style * * @return \PhpOffice\PhpWord\Style\Row */ public function getStyle() { return $this->style; } /** * Get row height * * @return int */ public function getHeight() { return $this->height; } } phpword/src/PhpWord/Element/Cell.php 0000664 00000003270 15177100671 0013373 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Cell as CellStyle; /** * Table cell element */ class Cell extends AbstractContainer { /** * @var string Container type */ protected $container = 'Cell'; /** * Cell width * * @var int */ private $width = null; /** * Cell style * * @var \PhpOffice\PhpWord\Style\Cell */ private $style; /** * Create new instance * * @param int $width * @param array|\PhpOffice\PhpWord\Style\Cell $style */ public function __construct($width = null, $style = null) { $this->width = $width; $this->style = $this->setNewStyle(new CellStyle(), $style, true); } /** * Get cell style * * @return \PhpOffice\PhpWord\Style\Cell */ public function getStyle() { return $this->style; } /** * Get cell width * * @return int */ public function getWidth() { return $this->width; } } phpword/src/PhpWord/Element/PreserveText.php 0000664 00000004613 15177100671 0015156 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; /** * Preserve text/field element */ class PreserveText extends AbstractElement { /** * Text content * * @var string|array */ private $text; /** * Text style * * @var string|\PhpOffice\PhpWord\Style\Font */ private $fontStyle; /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ private $paragraphStyle; /** * Create a new Preserve Text Element * * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) { $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->text = SharedText::toUTF8($text); $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) { $this->text = $matches; } } /** * Get Text style * * @return string|\PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { return $this->fontStyle; } /** * Get Paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Get Text content * * @return string|array */ public function getText() { return $this->text; } } phpword/src/PhpWord/Element/Shape.php 0000664 00000003627 15177100671 0013562 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Shape as ShapeStyle; /** * Shape element * * @since 0.12.0 */ class Shape extends AbstractElement { /** * Shape type arc|curve|line|polyline|rect|oval * * @var string */ private $type; /** * Shape style * * @var \PhpOffice\PhpWord\Style\Shape */ private $style; /** * Create new instance * * @param string $type * @param mixed $style */ public function __construct($type, $style = null) { $this->setType($type); $this->style = $this->setNewStyle(new ShapeStyle(), $style); } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set pattern * * @param string $value * @return self */ public function setType($value = null) { $enum = array('arc', 'curve', 'line', 'polyline', 'rect', 'oval'); $this->type = $this->setEnumVal($value, $enum, null); return $this; } /** * Get shape style * * @return \PhpOffice\PhpWord\Style\Shape */ public function getStyle() { return $this->style; } } phpword/src/PhpWord/Element/Title.php 0000664 00000004526 15177100671 0013602 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style; /** * Title element */ class Title extends AbstractElement { /** * Title Text content * * @var string|TextRun */ private $text; /** * Title depth * * @var int */ private $depth = 1; /** * Name of the heading style, e.g. 'Heading1' * * @var string */ private $style; /** * Is part of collection * * @var bool */ protected $collectionRelation = true; /** * Create a new Title Element * * @param string|TextRun $text * @param int $depth */ public function __construct($text, $depth = 1) { if (is_string($text)) { $this->text = SharedText::toUTF8($text); } elseif ($text instanceof TextRun) { $this->text = $text; } else { throw new \InvalidArgumentException('Invalid text, should be a string or a TextRun'); } $this->depth = $depth; $styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}"; if (array_key_exists($styleName, Style::getStyles())) { $this->style = str_replace('_', '', $styleName); } } /** * Get Title Text content * * @return string */ public function getText() { return $this->text; } /** * Get depth * * @return int */ public function getDepth() { return $this->depth; } /** * Get Title style * * @return string */ public function getStyle() { return $this->style; } } phpword/src/PhpWord/Element/AbstractElement.php 0000664 00000026665 15177100671 0015606 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; /** * Element abstract class * * @since 0.10.0 */ abstract class AbstractElement { /** * PhpWord object * * @var \PhpOffice\PhpWord\PhpWord */ protected $phpWord; /** * Section Id * * @var int */ protected $sectionId; /** * Document part type: Section|Header|Footer|Footnote|Endnote * * Used by textrun and cell container to determine where the element is * located because it will affect the availability of other element, * e.g. footnote will not be available when $docPart is header or footer. * * @var string */ protected $docPart = 'Section'; /** * Document part Id * * For header and footer, this will be = ($sectionId - 1) * 3 + $index * because the max number of header/footer in every page is 3, i.e. * AUTO, FIRST, and EVEN (AUTO = ODD) * * @var int */ protected $docPartId = 1; /** * Index of element in the elements collection (start with 1) * * @var int */ protected $elementIndex = 1; /** * Unique Id for element * * @var string */ protected $elementId; /** * Relation Id * * @var int */ 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; /** * A reference to the parent * * @var AbstractElement|null */ private $parent; /** * changed element info * * @var TrackChange */ private $trackChange; /** * Parent container type * * @var string */ private $parentContainer; /** * Has media relation flag; true for Link, Image, and Object * * @var bool */ protected $mediaRelation = false; /** * Is part of collection; true for Title, Footnote, Endnote, Chart, and Comment * * @var bool */ protected $collectionRelation = false; /** * The start position for the linked comment * * @var Comment */ protected $commentRangeStart; /** * The end position for the linked comment * * @var Comment */ protected $commentRangeEnd; /** * Get PhpWord * * @return \PhpOffice\PhpWord\PhpWord */ public function getPhpWord() { return $this->phpWord; } /** * Set PhpWord as reference. * * @param \PhpOffice\PhpWord\PhpWord $phpWord */ public function setPhpWord(PhpWord $phpWord = null) { $this->phpWord = $phpWord; } /** * Get section number * * @return int */ public function getSectionId() { return $this->sectionId; } /** * Set doc part. * * @param string $docPart * @param int $docPartId */ public function setDocPart($docPart, $docPartId = 1) { $this->docPart = $docPart; $this->docPartId = $docPartId; } /** * Get doc part * * @return string */ public function getDocPart() { return $this->docPart; } /** * Get doc part Id * * @return int */ public function getDocPartId() { return $this->docPartId; } /** * Return media element (image, object, link) container name * * @return string section|headerx|footerx|footnote|endnote */ private function getMediaPart() { $mediaPart = $this->docPart; if ($mediaPart == 'Header' || $mediaPart == 'Footer') { $mediaPart .= $this->docPartId; } return strtolower($mediaPart); } /** * Get element index * * @return int */ public function getElementIndex() { return $this->elementIndex; } /** * Set element index. * * @param int $value */ public function setElementIndex($value) { $this->elementIndex = $value; } /** * Get element unique ID * * @return string */ public function getElementId() { return $this->elementId; } /** * Set element unique ID from 6 first digit of md5. */ public function setElementId() { $this->elementId = substr(md5(rand()), 0, 6); } /** * Get relation Id * * @return int */ public function getRelationId() { return $this->relationId; } /** * Set relation Id. * * @param int $value */ public function setRelationId($value) { $this->relationId = $value; } /** * Get nested level * * @return int */ public function getNestedLevel() { return $this->nestedLevel; } /** * Get comment start * * @return Comment */ public function getCommentRangeStart() { return $this->commentRangeStart; } /** * Set comment start * * @param Comment $value */ public function setCommentRangeStart(Comment $value) { if ($this instanceof Comment) { throw new \InvalidArgumentException('Cannot set a Comment on a Comment'); } $this->commentRangeStart = $value; $this->commentRangeStart->setStartElement($this); } /** * Get comment end * * @return Comment */ public function getCommentRangeEnd() { return $this->commentRangeEnd; } /** * Set comment end * * @param Comment $value */ public function setCommentRangeEnd(Comment $value) { if ($this instanceof Comment) { throw new \InvalidArgumentException('Cannot set a Comment on a Comment'); } $this->commentRangeEnd = $value; $this->commentRangeEnd->setEndElement($this); } /** * Get parent element * * @return AbstractElement|null */ public function getParent() { return $this->parent; } /** * Set parent container * * Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell) * * @param \PhpOffice\PhpWord\Element\AbstractElement $container */ public function setParentContainer(self $container) { $this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $this->parent = $container; // Set nested level $this->nestedLevel = $container->getNestedLevel(); if ($this->parentContainer == 'Cell') { $this->nestedLevel++; } // Set phpword $this->setPhpWord($container->getPhpWord()); // Set doc part if (!$this instanceof Footnote) { $this->setDocPart($container->getDocPart(), $container->getDocPartId()); } $this->setMediaRelation(); $this->setCollectionRelation(); } /** * Set relation Id for media elements (link, image, object; legacy of OOXML) * * - Image element needs to be passed to Media object * - Icon needs to be set for Object element */ private function setMediaRelation() { if (!$this instanceof Link && !$this instanceof Image && !$this instanceof OLEObject) { return; } $elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1); if ($elementName == 'OLEObject') { $elementName = 'Object'; } $mediaPart = $this->getMediaPart(); $source = $this->getSource(); $image = null; if ($this instanceof Image) { $image = $this; } $rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image); $this->setRelationId($rId); if ($this instanceof OLEObject) { $icon = $this->getIcon(); $rId = Media::addElement($mediaPart, 'image', $icon, new Image($icon)); $this->setImageRelationId($rId); } } /** * Set relation Id for elements that will be registered in the Collection subnamespaces. */ private function setCollectionRelation() { if ($this->collectionRelation === true && $this->phpWord instanceof PhpWord) { $elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1); $addMethod = "add{$elementName}"; $rId = $this->phpWord->$addMethod($this); $this->setRelationId($rId); } } /** * Check if element is located in Section doc part (as opposed to Header/Footer) * * @return bool */ public function isInSection() { return $this->docPart == 'Section'; } /** * Set new style value * * @param mixed $styleObject Style object * @param mixed $styleValue Style value * @param bool $returnObject Always return object * @return mixed */ protected function setNewStyle($styleObject, $styleValue = null, $returnObject = false) { if (!is_null($styleValue) && is_array($styleValue)) { $styleObject->setStyleByArray($styleValue); $style = $styleObject; } else { $style = $returnObject ? $styleObject : $styleValue; } return $style; } /** * Sets the trackChange information * * @param TrackChange $trackChange */ public function setTrackChange(TrackChange $trackChange) { $this->trackChange = $trackChange; } /** * Gets the trackChange information * * @return TrackChange */ public function getTrackChange() { return $this->trackChange; } /** * Set changed * * @param string $type INSERTED|DELETED * @param string $author * @param null|int|\DateTime $date allways in UTC */ public function setChangeInfo($type, $author, $date = null) { $this->trackChange = new TrackChange($type, $author, $date); } /** * Set enum value * * @param string|null $value * @param string[] $enum * @param string|null $default * * @throws \InvalidArgumentException * @return string|null * * @todo Merge with the same method in AbstractStyle */ protected function setEnumVal($value = null, $enum = array(), $default = null) { if ($value !== null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) { throw new \InvalidArgumentException("Invalid style value: {$value}"); } elseif ($value === null || trim($value) == '') { $value = $default; } return $value; } } phpword/src/PhpWord/Element/Bookmark.php 0000664 00000002524 15177100671 0014262 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; /** * Bookmark element */ class Bookmark extends AbstractElement { /** * Bookmark Name * * @var string */ private $name; /** * Is part of collection * * @var bool */ protected $collectionRelation = true; /** * Create a new Bookmark Element * * @param string $name */ public function __construct($name = '') { $this->name = SharedText::toUTF8($name); } /** * Get Bookmark name * * @return string */ public function getName() { return $this->name; } } phpword/src/PhpWord/Element/TextBreak.php 0000664 00000006552 15177100671 0014413 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; /** * Text break element */ class TextBreak extends AbstractElement { /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ private $paragraphStyle = null; /** * Text style * * @var string|\PhpOffice\PhpWord\Style\Font */ private $fontStyle = null; /** * Create a new TextBreak Element * * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($fontStyle = null, $paragraphStyle = null) { if (!is_null($paragraphStyle)) { $paragraphStyle = $this->setParagraphStyle($paragraphStyle); } if (!is_null($fontStyle)) { $this->setFontStyle($fontStyle, $paragraphStyle); } } /** * Set Text style * * @param mixed $style * @param mixed $paragraphStyle * @return string|\PhpOffice\PhpWord\Style\Font */ public function setFontStyle($style = null, $paragraphStyle = null) { if ($style instanceof Font) { $this->fontStyle = $style; $this->setParagraphStyle($paragraphStyle); } elseif (is_array($style)) { $this->fontStyle = new Font('text', $paragraphStyle); $this->fontStyle->setStyleByArray($style); } else { $this->fontStyle = $style; $this->setParagraphStyle($paragraphStyle); } return $this->fontStyle; } /** * Get Text style * * @return string|\PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { return $this->fontStyle; } /** * Set Paragraph style * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function setParagraphStyle($style = null) { if (is_array($style)) { $this->paragraphStyle = new Paragraph(); $this->paragraphStyle->setStyleByArray($style); } elseif ($style instanceof Paragraph) { $this->paragraphStyle = $style; } else { $this->paragraphStyle = $style; } return $this->paragraphStyle; } /** * Get Paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Has font/paragraph style defined * * @return bool */ public function hasStyle() { return !is_null($this->fontStyle) || !is_null($this->paragraphStyle); } } phpword/src/PhpWord/Element/TextRun.php 0000664 00000004236 15177100671 0014130 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Paragraph; /** * Textrun/paragraph element */ class TextRun extends AbstractContainer { /** * @var string Container type */ protected $container = 'TextRun'; /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ protected $paragraphStyle; /** * Create new instance * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle */ public function __construct($paragraphStyle = null) { $this->paragraphStyle = $this->setParagraphStyle($paragraphStyle); } /** * Get Paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Set Paragraph style * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function setParagraphStyle($style = null) { if (is_array($style)) { $this->paragraphStyle = new Paragraph(); $this->paragraphStyle->setStyleByArray($style); } elseif ($style instanceof Paragraph) { $this->paragraphStyle = $style; } elseif (null === $style) { $this->paragraphStyle = new Paragraph(); } else { $this->paragraphStyle = $style; } return $this->paragraphStyle; } } phpword/src/PhpWord/Element/SDT.php 0000664 00000006445 15177100671 0013155 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Structured document tag (SDT) element * * @since 0.12.0 */ class SDT extends Text { /** * Form field type: comboBox|dropDownList|date * * @var string */ private $type; /** * Value * * @var string|bool|int */ private $value; /** * CheckBox/DropDown list entries * * @var array */ private $listItems = array(); /** * Alias * * @var string */ private $alias; /** * Tag * * @var string */ private $tag; /** * Create new instance * * @param string $type * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($type, $fontStyle = null, $paragraphStyle = null) { parent::__construct(null, $fontStyle, $paragraphStyle); $this->setType($type); } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set type * * @param string $value * @return self */ public function setType($value) { $enum = array('plainText', 'comboBox', 'dropDownList', 'date'); $this->type = $this->setEnumVal($value, $enum, 'comboBox'); return $this; } /** * Get value * * @return string|bool|int */ public function getValue() { return $this->value; } /** * Set value * * @param string|bool|int $value * @return self */ public function setValue($value) { $this->value = $value; return $this; } /** * Get listItems * * @return array */ public function getListItems() { return $this->listItems; } /** * Set listItems * * @param array $value * @return self */ public function setListItems($value) { $this->listItems = $value; return $this; } /** * Get tag * * @return string */ public function getTag() { return $this->tag; } /** * Set tag * * @param string $tag * @return self */ public function setTag($tag) { $this->tag = $tag; return $this; } /** * Get alias * * @return string */ public function getAlias() { return $this->alias; } /** * Set alias * * @param string $alias * @return self */ public function setAlias($alias) { $this->alias = $alias; return $this; } } phpword/src/PhpWord/Element/CheckBox.php 0000664 00000003200 15177100671 0014173 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; /** * Check box element * * @since 0.10.0 */ class CheckBox extends Text { /** * Name content * * @var string */ private $name; /** * Create new instance * * @param string $name * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null) { $this->setName($name); parent::__construct($text, $fontStyle, $paragraphStyle); } /** * Set name content * * @param string $name * @return self */ public function setName($name) { $this->name = SharedText::toUTF8($name); return $this; } /** * Get name content * * @return string */ public function getName() { return $this->name; } } phpword/src/PhpWord/Element/Image.php 0000664 00000036302 15177100671 0013540 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; use PhpOffice\PhpWord\Exception\InvalidImageException; use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\ZipArchive; use PhpOffice\PhpWord\Style\Image as ImageStyle; /** * Image element */ class Image extends AbstractElement { /** * Image source type constants */ const SOURCE_LOCAL = 'local'; // Local images const SOURCE_GD = 'gd'; // Generated using GD const SOURCE_ARCHIVE = 'archive'; // Image in archives zip://$archive#$image const SOURCE_STRING = 'string'; // Image from string /** * Image source * * @var string */ private $source; /** * Source type: local|gd|archive * * @var string */ private $sourceType; /** * Image style * * @var ImageStyle */ private $style; /** * Is watermark * * @var bool */ private $watermark; /** * Name of image * * @var string */ private $name; /** * Image type * * @var string */ private $imageType; /** * Image create function * * @var string */ private $imageCreateFunc; /** * Image function * * @var string */ private $imageFunc; /** * Image extension * * @var string */ private $imageExtension; /** * Is memory image * * @var bool */ private $memoryImage; /** * Image target file name * * @var string */ private $target; /** * Image media index * * @var int */ private $mediaIndex; /** * Has media relation flag; true for Link, Image, and Object * * @var bool */ protected $mediaRelation = true; /** * Create new image element * * @param string $source * @param mixed $style * @param bool $watermark * @param string $name * * @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ public function __construct($source, $style = null, $watermark = false, $name = null) { $this->source = $source; $this->style = $this->setNewStyle(new ImageStyle(), $style, true); $this->setIsWatermark($watermark); $this->setName($name); $this->checkImage(); } /** * Get Image style * * @return ImageStyle */ public function getStyle() { return $this->style; } /** * Get image source * * @return string */ public function getSource() { return $this->source; } /** * Get image source type * * @return string */ public function getSourceType() { return $this->sourceType; } /** * Sets the image name * * @param string $value */ public function setName($value) { $this->name = $value; } /** * Get image name * * @return null|string */ public function getName() { return $this->name; } /** * Get image media ID * * @return string */ public function getMediaId() { return md5($this->source); } /** * Get is watermark * * @return bool */ public function isWatermark() { return $this->watermark; } /** * Set is watermark * * @param bool $value */ public function setIsWatermark($value) { $this->watermark = $value; } /** * Get image type * * @return string */ public function getImageType() { return $this->imageType; } /** * Get image create function * * @return string */ public function getImageCreateFunction() { return $this->imageCreateFunc; } /** * Get image function * * @return string */ public function getImageFunction() { return $this->imageFunc; } /** * Get image extension * * @return string */ public function getImageExtension() { return $this->imageExtension; } /** * Get is memory image * * @return bool */ public function isMemImage() { return $this->memoryImage; } /** * Get target file name * * @return string */ public function getTarget() { return $this->target; } /** * Set target file name. * * @param string $value */ public function setTarget($value) { $this->target = $value; } /** * Get media index * * @return int */ public function getMediaIndex() { return $this->mediaIndex; } /** * Set media index. * * @param int $value */ public function setMediaIndex($value) { $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) !== false) { $isTemp = true; $zip->extractTo(Settings::getTempDir(), $imageFilename); $actualSource = Settings::getTempDir() . 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); if ($this->imageType === 'image/png') { // PNG images need to preserve alpha channel information imagesavealpha($imageResource, true); } ob_start(); call_user_func($this->imageFunc, $imageResource); $imageBinary = ob_get_contents(); ob_end_clean(); } elseif ($this->sourceType == self::SOURCE_STRING) { $imageBinary = $this->source; } 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. * * @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ private function checkImage() { $this->setSourceType(); // Check image data if ($this->sourceType == self::SOURCE_ARCHIVE) { $imageData = $this->getArchiveImageSize($this->source); } elseif ($this->sourceType == self::SOURCE_STRING) { $imageData = $this->getStringImageSize($this->source); } else { $imageData = @getimagesize($this->source); } if (!is_array($imageData)) { throw new InvalidImageException(sprintf('Invalid image: %s', $this->source)); } list($actualWidth, $actualHeight, $imageType) = $imageData; // Check image type support $supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG); if ($this->sourceType != self::SOURCE_GD && $this->sourceType != self::SOURCE_STRING) { $supportedTypes = array_merge($supportedTypes, array(IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)); } if (!in_array($imageType, $supportedTypes)) { throw new UnsupportedImageTypeException(); } // Define image functions $this->imageType = image_type_to_mime_type($imageType); $this->setFunctions(); $this->setProportionalSize($actualWidth, $actualHeight); } /** * Set source type. */ private function setSourceType() { if (stripos(strrev($this->source), strrev('.php')) === 0) { $this->memoryImage = true; $this->sourceType = self::SOURCE_GD; } elseif (strpos($this->source, 'zip://') !== false) { $this->memoryImage = false; $this->sourceType = self::SOURCE_ARCHIVE; } elseif (filter_var($this->source, FILTER_VALIDATE_URL) !== false) { $this->memoryImage = true; if (strpos($this->source, 'https') === 0) { $fileContent = file_get_contents($this->source); $this->source = $fileContent; $this->sourceType = self::SOURCE_STRING; } else { $this->sourceType = self::SOURCE_GD; } } elseif ((strpos($this->source, chr(0)) === false) && @file_exists($this->source)) { $this->memoryImage = false; $this->sourceType = self::SOURCE_LOCAL; } else { $this->memoryImage = true; $this->sourceType = self::SOURCE_STRING; } } /** * Get image size from archive * * @since 0.12.0 Throws CreateTemporaryFileException. * * @param string $source * * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException * * @return array|null */ private function getArchiveImageSize($source) { $imageData = null; $source = substr($source, 6); list($zipFilename, $imageFilename) = explode('#', $source); $tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage'); if (false === $tempFilename) { throw new CreateTemporaryFileException(); // @codeCoverageIgnore } $zip = new ZipArchive(); if ($zip->open($zipFilename) !== false) { if ($zip->locateName($imageFilename) !== false) { $imageContent = $zip->getFromName($imageFilename); if ($imageContent !== false) { file_put_contents($tempFilename, $imageContent); $imageData = getimagesize($tempFilename); unlink($tempFilename); } } $zip->close(); } return $imageData; } /** * get image size from string * * @param string $source * * @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4 */ private function getStringImageSize($source) { $result = false; if (!function_exists('getimagesizefromstring')) { $uri = 'data://application/octet-stream;base64,' . base64_encode($source); $result = @getimagesize($uri); } else { $result = @getimagesizefromstring($source); } return $result; } /** * Set image functions and extensions. */ private function setFunctions() { switch ($this->imageType) { case 'image/png': $this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefrompng'; $this->imageFunc = 'imagepng'; $this->imageExtension = 'png'; break; case 'image/gif': $this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromgif'; $this->imageFunc = 'imagegif'; $this->imageExtension = 'gif'; break; case 'image/jpeg': case 'image/jpg': $this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromjpeg'; $this->imageFunc = 'imagejpeg'; $this->imageExtension = 'jpg'; break; case 'image/bmp': case 'image/x-ms-bmp': $this->imageType = 'image/bmp'; $this->imageExtension = 'bmp'; break; case 'image/tiff': $this->imageExtension = 'tif'; break; } } /** * Set proportional width/height if one dimension not available. * * @param int $actualWidth * @param int $actualHeight */ private function setProportionalSize($actualWidth, $actualHeight) { $styleWidth = $this->style->getWidth(); $styleHeight = $this->style->getHeight(); if (!($styleWidth && $styleHeight)) { if ($styleWidth == null && $styleHeight == null) { $this->style->setWidth($actualWidth); $this->style->setHeight($actualHeight); } elseif ($styleWidth) { $this->style->setHeight($actualHeight * ($styleWidth / $actualWidth)); } else { $this->style->setWidth($actualWidth * ($styleHeight / $actualHeight)); } } } /** * 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(); } } phpword/src/PhpWord/Element/Endnote.php 0000664 00000002150 15177100671 0014104 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Endnote element * * @since 0.10.0 */ class Endnote extends Footnote { /** * @var string Container type */ protected $container = 'Endnote'; /** * Create new instance * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle */ public function __construct($paragraphStyle = null) { parent::__construct($paragraphStyle); } } phpword/src/PhpWord/Element/TextBox.php 0000664 00000002634 15177100671 0014114 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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->setNewStyle(new TextBoxStyle(), $style); } /** * Get textbox style * * @return \PhpOffice\PhpWord\Style\TextBox */ public function getStyle() { return $this->style; } } phpword/src/PhpWord/Element/Link.php 0000664 00000007147 15177100671 0013420 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Shared\Text as SharedText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; /** * Link element */ class Link extends AbstractElement { /** * Link source * * @var string */ private $source; /** * Link text * * @var string */ private $text; /** * Font style * * @var string|\PhpOffice\PhpWord\Style\Font */ private $fontStyle; /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ private $paragraphStyle; /** * Has media relation flag; true for Link, Image, and Object * * @var bool */ protected $mediaRelation = true; /** * Has internal flag - anchor to internal bookmark * * @var bool */ protected $internal = false; /** * Create a new Link Element * * @param string $source * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle * @param bool $internal */ public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) { $this->source = SharedText::toUTF8($source); $this->text = is_null($text) ? $this->source : SharedText::toUTF8($text); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->internal = $internal; } /** * Get link source * * @return string */ public function getSource() { return $this->source; } /** * Get link text * * @return string */ public function getText() { return $this->text; } /** * Get Text style * * @return string|\PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { return $this->fontStyle; } /** * Get Paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Get link target * * @deprecated 0.12.0 * * @return string * * @codeCoverageIgnore */ public function getTarget() { return $this->source; } /** * Get Link source * * @deprecated 0.10.0 * * @return string * * @codeCoverageIgnore */ public function getLinkSrc() { return $this->getSource(); } /** * Get Link name * * @deprecated 0.10.0 * * @return string * * @codeCoverageIgnore */ public function getLinkName() { return $this->getText(); } /** * is internal * * @return bool */ public function isInternal() { return $this->internal; } } phpword/src/PhpWord/Element/Header.php 0000664 00000002123 15177100671 0013700 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Header element */ class Header extends Footer { /** * @var string Container type */ protected $container = 'Header'; /** * Add a Watermark Element * * @param string $src * @param mixed $style * @return Image */ public function addWatermark($src, $style = null) { return $this->addImage($src, $style, true); } } phpword/src/PhpWord/Element/FormField.php 0000664 00000007007 15177100671 0014365 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Form field element * * @since 0.12.0 * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html */ class FormField extends Text { /** * Form field type: textinput|checkbox|dropdown * * @var string */ private $type = 'textinput'; /** * Form field name * * @var string|bool|int */ private $name; /** * Default value * * - TextInput: string * - CheckBox: bool * - DropDown: int Index of entries (zero based) * * @var string|bool|int */ private $default; /** * Value * * @var string|bool|int */ private $value; /** * Dropdown entries * * @var array */ private $entries = array(); /** * Create new instance * * @param string $type * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($type, $fontStyle = null, $paragraphStyle = null) { parent::__construct(null, $fontStyle, $paragraphStyle); $this->setType($type); } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set type * * @param string $value * @return self */ public function setType($value) { $enum = array('textinput', 'checkbox', 'dropdown'); $this->type = $this->setEnumVal($value, $enum, $this->type); return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set name * * @param string|bool|int $value * @return self */ public function setName($value) { $this->name = $value; return $this; } /** * Get default * * @return string|bool|int */ public function getDefault() { return $this->default; } /** * Set default * * @param string|bool|int $value * @return self */ public function setDefault($value) { $this->default = $value; return $this; } /** * Get value * * @return string|bool|int */ public function getValue() { return $this->value; } /** * Set value * * @param string|bool|int $value * @return self */ public function setValue($value) { $this->value = $value; return $this; } /** * Get entries * * @return array */ public function getEntries() { return $this->entries; } /** * Set entries * * @param array $value * @return self */ public function setEntries($value) { $this->entries = $value; return $this; } } phpword/src/PhpWord/Element/Field.php 0000664 00000021375 15177100671 0013545 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Font; /** * Field element * * @since 0.11.0 * @see 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', 'CardText', 'DollarText', 'Ordinal', 'OrdText', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN', 'Caps', 'FirstCap', 'Lower', 'Upper', ), 'numformat' => array('0', '0,00', '#.##0', '#.##0,00', '€ #.##0,00(€ #.##0,00)', '0%', '0,00%'), ), 'options' => array('PreserveFormat'), ), 'DATE' => array( 'properties' => array( 'dateformat' => array( /* Generic formats */ 'yyyy-MM-dd', 'yyyy-MM', 'MMM-yy', 'MMM-yyyy', 'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss', /* Day-Month-Year formats */ 'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-MMM-yy', 'd MMM. yy', 'd-M-yy', 'd-M-yy h:mm', 'd-M-yy h:mm:ss', 'd-M-yy h:mm am/pm', 'd-M-yy h:mm:ss am/pm', 'd-M-yy HH:mm', 'd-M-yy HH:mm:ss', 'd/M/yy', 'd/M/yy h:mm', 'd/M/yy h:mm:ss', 'd/M/yy h:mm am/pm', 'd/M/yy h:mm:ss am/pm', 'd/M/yy HH:mm', 'd/M/yy HH:mm:ss', 'd-M-yyyy', 'd-M-yyyy h:mm', 'd-M-yyyy h:mm:ss', 'd-M-yyyy h:mm am/pm', 'd-M-yyyy h:mm:ss am/pm', 'd-M-yyyy HH:mm', 'd-M-yyyy HH:mm:ss', 'd/M/yyyy', 'd/M/yyyy h:mm', 'd/M/yyyy h:mm:ss', 'd/M/yyyy h:mm am/pm', 'd/M/yyyy h:mm:ss am/pm', 'd/M/yyyy HH:mm', 'd/M/yyyy HH:mm:ss', /* Month-Day-Year formats */ 'dddd, MMMM d yyyy', 'MMMM d yyyy', 'MMM-d-yy', 'MMM. d yy', 'M-d-yy', 'M-d-yy h:mm', 'M-d-yy h:mm:ss', 'M-d-yy h:mm am/pm', 'M-d-yy h:mm:ss am/pm', 'M-d-yy HH:mm', 'M-d-yy HH:mm:ss', 'M/d/yy', 'M/d/yy h:mm', 'M/d/yy h:mm:ss', 'M/d/yy h:mm am/pm', 'M/d/yy h:mm:ss am/pm', 'M/d/yy HH:mm', 'M/d/yy HH:mm:ss', 'M-d-yyyy', 'M-d-yyyy h:mm', 'M-d-yyyy h:mm:ss', 'M-d-yyyy h:mm am/pm', 'M-d-yyyy h:mm:ss am/pm', 'M-d-yyyy HH:mm', 'M-d-yyyy HH:mm:ss', 'M/d/yyyy', 'M/d/yyyy h:mm', 'M/d/yyyy h:mm:ss', 'M/d/yyyy h:mm am/pm', 'M/d/yyyy h:mm:ss am/pm', 'M/d/yyyy HH:mm', 'M/d/yyyy HH:mm:ss', ), ), 'options' => array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat'), ), 'MACROBUTTON' => array( 'properties' => array('macroname' => ''), ), 'XE' => array( 'properties' => array(), 'options' => array('Bold', 'Italic'), ), 'INDEX' => array( 'properties' => array(), 'options' => array('PreserveFormat'), ), 'STYLEREF' => array( 'properties' => array('StyleIdentifier' => ''), 'options' => array('PreserveFormat'), ), ); /** * Field type * * @var string */ protected $type; /** * Field text * * @var TextRun|string */ protected $text; /** * Field properties * * @var array */ protected $properties = array(); /** * Field options * * @var array */ protected $options = array(); /** * Font style * * @var string|\PhpOffice\PhpWord\Style\Font */ protected $fontStyle; /** * Set Font style * * @param string|array|\PhpOffice\PhpWord\Style\Font $style * @return string|\PhpOffice\PhpWord\Style\Font */ public function setFontStyle($style = null) { if ($style instanceof Font) { $this->fontStyle = $style; } elseif (is_array($style)) { $this->fontStyle = new Font('text'); $this->fontStyle->setStyleByArray($style); } elseif (null === $style) { $this->fontStyle = null; } else { $this->fontStyle = $style; } return $this->fontStyle; } /** * Get Font style * * @return string|\PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { return $this->fontStyle; } /** * Create a new Field Element * * @param string $type * @param array $properties * @param array $options * @param TextRun|string|null $text * @param string|array|\PhpOffice\PhpWord\Style\Font $fontStyle */ public function __construct($type = null, $properties = array(), $options = array(), $text = null, $fontStyle = null) { $this->setType($type); $this->setProperties($properties); $this->setOptions($options); $this->setText($text); $this->setFontStyle($fontStyle); } /** * Set Field type * * @param string $type * * @throws \InvalidArgumentException * @return string */ public function setType($type = null) { if (isset($type)) { if (isset($this->fieldsArray[$type])) { $this->type = $type; } else { throw new \InvalidArgumentException("Invalid type '$type'"); } } return $this->type; } /** * Get Field type * * @return string */ public function getType() { return $this->type; } /** * Set Field properties * * @param array $properties * * @throws \InvalidArgumentException * @return self */ public function setProperties($properties = array()) { if (is_array($properties)) { foreach (array_keys($properties) as $propkey) { if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) { throw new \InvalidArgumentException("Invalid property '$propkey'"); } } $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 * * @throws \InvalidArgumentException * @return self */ public function setOptions($options = array()) { if (is_array($options)) { foreach (array_keys($options) as $optionkey) { if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey])) && substr($optionkey, 0, 1) !== '\\') { throw new \InvalidArgumentException("Invalid option '$optionkey', possible values are " . implode(', ', $this->fieldsArray[$this->type]['options'])); } } $this->options = array_merge($this->options, $options); } return $this->options; } /** * Get Field properties * * @return array */ public function getOptions() { return $this->options; } /** * Set Field text * * @param string|TextRun $text * * @throws \InvalidArgumentException * @return null|string|TextRun */ public function setText($text = null) { if (isset($text)) { if (is_string($text) || $text instanceof TextRun) { $this->text = $text; } else { throw new \InvalidArgumentException('Invalid text'); } } return $this->text; } /** * Get Field text * * @return string|TextRun */ public function getText() { return $this->text; } } phpword/src/PhpWord/Element/Footer.php 0000664 00000005010 15177100671 0013744 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * Footer element */ class Footer extends AbstractContainer { /** * Header/footer types constants * * @var string * @see http://www.datypic.com/sc/ooxml/t-w_ST_HdrFtr.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 */ protected $type = self::AUTO; /** * Create new instance * * @param int $sectionId * @param int $containerId * @param string $type */ public function __construct($sectionId, $containerId = 1, $type = self::AUTO) { $this->sectionId = $sectionId; $this->setType($type); $this->setDocPart($this->container, ($sectionId - 1) * 3 + $containerId); } /** * Set type. * * @since 0.10.0 * * @param string $value */ public function setType($value = self::AUTO) { if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) { $value = self::AUTO; } $this->type = $value; } /** * Get type * * @return string * @since 0.10.0 */ 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; } } phpword/src/PhpWord/Element/TrackChange.php 0000664 00000004443 15177100671 0014671 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; /** * TrackChange element * @see http://datypic.com/sc/ooxml/t-w_CT_TrackChange.html * @see http://datypic.com/sc/ooxml/t-w_CT_RunTrackChange.html */ class TrackChange extends AbstractContainer { const INSERTED = 'INSERTED'; const DELETED = 'DELETED'; /** * @var string Container type */ protected $container = 'TrackChange'; /** * The type of change, (insert or delete), not applicable for PhpOffice\PhpWord\Element\Comment * * @var string */ private $changeType; /** * Author * * @var string */ private $author; /** * Date * * @var \DateTime */ private $date; /** * Create a new TrackChange Element * * @param string $changeType * @param string $author * @param null|int|bool|\DateTime $date */ public function __construct($changeType = null, $author = null, $date = null) { $this->changeType = $changeType; $this->author = $author; if ($date !== null && $date !== false) { $this->date = ($date instanceof \DateTime) ? $date : new \DateTime('@' . $date); } } /** * Get TrackChange Author * * @return string */ public function getAuthor() { return $this->author; } /** * Get TrackChange Date * * @return \DateTime */ public function getDate() { return $this->date; } /** * Get the Change type * * @return string */ public function getChangeType() { return $this->changeType; } } phpword/src/PhpWord/Element/Section.php 0000664 00000015154 15177100671 0014124 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\ComplexType\FootnoteProperties; use PhpOffice\PhpWord\Style\Section as SectionStyle; class Section extends AbstractContainer { /** * @var string Container type */ protected $container = 'Section'; /** * Section style * * @var \PhpOffice\PhpWord\Style\Section */ private $style; /** * Section headers, indexed from 1, not zero * * @var Header[] */ private $headers = array(); /** * Section footers, indexed from 1, not zero * * @var Footer[] */ private $footers = array(); /** * The properties for the footnote of this section * * @var FootnoteProperties */ private $footnoteProperties; /** * Create new instance * * @param int $sectionCount * @param null|array|\PhpOffice\PhpWord\Style $style */ public function __construct($sectionCount, $style = null) { $this->sectionId = $sectionCount; $this->setDocPart($this->container, $this->sectionId); if (null === $style) { $style = new SectionStyle(); } $this->style = $this->setNewStyle(new SectionStyle(), $style); } /** * Set section style. * * @param array $style */ public function setStyle($style = null) { if (!is_null($style) && is_array($style)) { $this->style->setStyleByArray($style); } } /** * Get section style * * @return \PhpOffice\PhpWord\Style\Section */ public function getStyle() { return $this->style; } /** * Add header * * @since 0.10.0 * * @param string $type * * @return Header */ public function addHeader($type = Header::AUTO) { return $this->addHeaderFooter($type, true); } /** * Add footer * * @since 0.10.0 * * @param string $type * * @return Footer */ public function addFooter($type = Header::AUTO) { return $this->addHeaderFooter($type, false); } /** * Get header elements * * @return Header[] */ public function getHeaders() { return $this->headers; } /** * Get footer elements * * @return Footer[] */ public function getFooters() { return $this->footers; } /** * Get the footnote properties * * @return FootnoteProperties */ public function getFootnoteProperties() { return $this->footnoteProperties; } /** * Get the footnote properties * * @deprecated Use the `getFootnoteProperties` method instead * * @return FootnoteProperties * * @codeCoverageIgnore */ public function getFootnotePropoperties() { return $this->footnoteProperties; } /** * Set the footnote properties * * @param FootnoteProperties $footnoteProperties */ public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null) { $this->footnoteProperties = $footnoteProperties; } /** * Is there a header for this section that is for the first page only? * * If any of the Header instances have a type of Header::FIRST then this method returns true. * False otherwise. * * @return bool */ public function hasDifferentFirstPage() { foreach ($this->headers as $header) { if ($header->getType() == Header::FIRST) { return true; } } foreach ($this->footers as $footer) { if ($footer->getType() == Header::FIRST) { return true; } } return false; } /** * Add header/footer * * @since 0.10.0 * * @param string $type * @param bool $header * * @throws \Exception * * @return Header|Footer */ 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'; $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; } throw new \Exception('Invalid header/footer type.'); } /** * Set section style * * @deprecated 0.12.0 * * @param array $settings * * @codeCoverageIgnore */ public function setSettings($settings = null) { $this->setStyle($settings); } /** * Get section style * * @deprecated 0.12.0 * * @return \PhpOffice\PhpWord\Style\Section * * @codeCoverageIgnore */ public function getSettings() { return $this->getStyle(); } /** * Create header * * @deprecated 0.10.0 * * @return Header * * @codeCoverageIgnore */ public function createHeader() { return $this->addHeader(); } /** * Create footer * * @deprecated 0.10.0 * * @return Footer * * @codeCoverageIgnore */ public function createFooter() { return $this->addFooter(); } /** * Get footer * * @deprecated 0.10.0 * * @return Footer * * @codeCoverageIgnore */ public function getFooter() { if (empty($this->footers)) { return null; } return $this->footers[1]; } } phpword/src/PhpWord/Element/TOC.php 0000664 00000007226 15177100671 0013146 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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\Font; use PhpOffice\PhpWord\Style\TOC as TOCStyle; /** * Table of contents */ class TOC extends AbstractElement { /** * TOC style * * @var \PhpOffice\PhpWord\Style\TOC */ private $TOCStyle; /** * Font style * * @var \PhpOffice\PhpWord\Style\Font|string */ private $fontStyle; /** * Min title depth to show * * @var int */ private $minDepth = 1; /** * Max title depth to show * * @var int */ private $maxDepth = 9; /** * Create a new Table-of-Contents Element * * @param mixed $fontStyle * @param array $tocStyle * @param int $minDepth * @param int $maxDepth */ public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9) { $this->TOCStyle = new TOCStyle(); if (!is_null($tocStyle) && is_array($tocStyle)) { $this->TOCStyle->setStyleByArray($tocStyle); } if (!is_null($fontStyle) && is_array($fontStyle)) { $this->fontStyle = new Font(); $this->fontStyle->setStyleByArray($fontStyle); } else { $this->fontStyle = $fontStyle; } $this->minDepth = $minDepth; $this->maxDepth = $maxDepth; } /** * Get all titles * * @return array */ public function getTitles() { if (!$this->phpWord instanceof PhpWord) { return array(); } $titles = $this->phpWord->getTitles()->getItems(); foreach ($titles as $i => $title) { /** @var \PhpOffice\PhpWord\Element\Title $title Type hint */ $depth = $title->getDepth(); if ($this->minDepth > $depth) { unset($titles[$i]); } if (($this->maxDepth != 0) && ($this->maxDepth < $depth)) { unset($titles[$i]); } } return $titles; } /** * Get TOC Style * * @return \PhpOffice\PhpWord\Style\TOC */ public function getStyleTOC() { return $this->TOCStyle; } /** * Get Font Style * * @return \PhpOffice\PhpWord\Style\Font|string */ public function getStyleFont() { return $this->fontStyle; } /** * Set max depth. * * @param int $value */ public function setMaxDepth($value) { $this->maxDepth = $value; } /** * Get Max Depth * * @return int Max depth of titles */ public function getMaxDepth() { return $this->maxDepth; } /** * Set min depth. * * @param int $value */ public function setMinDepth($value) { $this->minDepth = $value; } /** * Get Min Depth * * @return int Min depth of titles */ public function getMinDepth() { return $this->minDepth; } } phpword/src/PhpWord/Element/Footnote.php 0000664 00000004100 15177100671 0014302 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\Paragraph; class Footnote extends AbstractContainer { /** * @var string Container type */ protected $container = 'Footnote'; /** * Paragraph style * * @var string|\PhpOffice\PhpWord\Style\Paragraph */ protected $paragraphStyle; /** * Is part of collection * * @var bool */ protected $collectionRelation = true; /** * Create new instance * * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle */ public function __construct($paragraphStyle = null) { $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->setDocPart($this->container); } /** * Get paragraph style * * @return string|\PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } /** * Get Footnote Reference ID * * @deprecated 0.10.0 * @codeCoverageIgnore * * @return int */ public function getReferenceId() { return $this->getRelationId(); } /** * Set Footnote Reference ID * * @deprecated 0.10.0 * @codeCoverageIgnore * * @param int $rId */ public function setReferenceId($rId) { $this->setRelationId($rId); } } phpword/src/PhpWord/Element/OLEObject.php 0000664 00000006731 15177100671 0014267 0 ustar 00 <?php /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 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; /** * OLEObject element */ class OLEObject extends AbstractElement { /** * Ole-Object Src * * @var string */ private $source; /** * Image Style * * @var \PhpOffice\PhpWord\Style\Image */ private $style; /** * Icon * * @var string */ private $icon; /** * Image Relation ID * * @var int */ private $imageRelationId; /** * Has media relation flag; true for Link, Image, and Object * * @var bool */ protected $mediaRelation = true; /** * Create a new Ole-Object Element * * @param string $source * @param mixed $style * * @throws \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function __construct($source, $style = null) { $supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx'); $pathInfo = pathinfo($source); 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->setNewStyle(new ImageStyle(), $style, true); $this->icon = realpath(__DIR__ . "/../resources/{$ext}.png"); return; } throw new InvalidObjectException(); } /** * Get object source * * @return string */ public function getSource() { return $this->source; } /** * 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 */ public function getImageRelationId() { return $this->imageRelationId; } /** * Set Image Relation ID. * * @param int $rId */ public function setImageRelationId($rId) { $this->imageRelationId = $rId; } /** * Get Object ID * * @deprecated 0.10.0 * * @return int * * @codeCoverageIgnore */ public function getObjectId() { return $this->relationId + 1325353440; } /** * Set Object ID * * @deprecated 0.10.0 * * @param int $objId * * @codeCoverageIgnore */ public function setObjectId($objId) { $this->relationId = $objId; } } phpword/src/PhpWord/resources/xls.png 0000664 00000003604 15177100671 0013741 0 ustar 00 �PNG IHDR h C G��f tEXtSoftware Adobe ImageReadyq�e<