Compare commits

..

268 Commits

Author SHA1 Message Date
6aa68f1c81 Add GetPropertyInt method 2025-03-06 15:56:30 +03:00
e9852e812f Turn on ligatures for arabic & syriac scripts 2025-03-05 19:13:38 +03:00
d2ea9521b5 Add support license 2025-03-05 18:59:59 +03:00
06f8099497 Merge pull request 'Fix pdf properties exists' (#244) from fix/pdf-properties into hotfix/v8.3.2
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/244
2025-03-04 17:24:26 +00:00
ba9d3bcda5 Fix pdf properties exists 2025-03-04 19:46:43 +03:00
3d7638c3cc Merge branch hotfix/v8.3.1 into master 2025-02-27 13:17:57 +00:00
dd60367d01 Fix building fonts module 2025-02-27 11:18:24 +03:00
54bbbbc3d7 Merge pull request 'fix bug #73349' (#241) from fix/bug73349 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/241
2025-02-26 19:29:42 +00:00
9b901f7834 fix bug #73349 2025-02-26 17:56:41 +03:00
4f59af17b8 Fix bug 72130 2025-02-26 15:08:48 +03:00
b9258429f6 Merge pull request 'Fix bug #73343' (#240) from fix/bug73343 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/240
2025-02-25 15:20:32 +00:00
e8f2c55ad4 Merge pull request 'Fix bug #72788' (#239) from fix/bug72788 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/239
2025-02-25 15:20:12 +00:00
46f6ba4d0a Fix for subsystem python module 2025-02-25 16:55:32 +03:00
09b55bd1f1 Merge pull request 'Fix bug 71688' (#238) from fix/bug-71688 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/238
2025-02-24 13:29:36 +00:00
176053e8d8 Fix bug 71688 2025-02-24 16:16:51 +03:00
01365f938c Fix bug 73299 2025-02-24 15:09:43 +03:00
d168e4594f Fix bug #73343 2025-02-24 17:09:36 +05:00
0c9fa4709f Merge branch release/v8.3.0 into master 2025-02-24 09:08:09 +00:00
27d2e40da7 Merge pull request 'fix bug #73336' (#237) from fix/bug73336 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/237
2025-02-24 09:00:39 +00:00
14b09ce582 fix bug #73336 2025-02-24 11:49:41 +03:00
aeeab690b1 Fix builder bugs. Recteate context with snapshots if needed. 2025-02-24 01:10:39 +03:00
016a0a971b Fix bug #72788 2025-02-20 20:28:22 +05:00
afe55a456f Merge branch 'fix/bug70671' into hotfix/v8.3.1 2025-02-19 18:06:22 +03:00
efc1149235 Merge pull request 'Fix bug #70575' (#236) from fix/bug70575 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/236
2025-02-19 14:58:17 +00:00
567cc14bc7 Merge pull request 'Fix bug #72790' (#232) from fix/bug72790 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/232
2025-02-19 12:51:51 +00:00
2c27cfc720 . 2025-02-19 15:32:12 +03:00
1d31e5836b fix fileFormatChecker 2025-02-18 20:23:49 +03:00
6adf65d3a8 fix bug #73221 2025-02-18 09:51:43 +03:00
093e1348fa Merge pull request 'Fix bug #71975' (#235) from fix/bug71975 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/235
2025-02-17 13:40:22 +00:00
b78157487a Merge pull request 'Fix bug #73238' (#233) from fix/bug73238 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/233
2025-02-17 13:37:03 +00:00
77b30109f0 Merge remote-tracking branch 'origin/hotfix/v8.3.1' into fix/bug71975 2025-02-17 18:33:19 +05:00
efd047be74 Fix bug #71975 2025-02-17 18:27:48 +05:00
61abfdb272 Merge pull request 'Fix bugs 73220, 73178' (#234) from fix/bug-73220 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/234
2025-02-17 11:16:05 +00:00
f5088f43d8 Fix bug 73178 2025-02-17 14:10:38 +03:00
6b3c395220 Fix bug 73220 2025-02-17 13:44:01 +03:00
67cb29652d Fix bug #73238 2025-02-15 17:41:26 +05:00
d0cb082b33 Fix bug #72790 2025-02-15 12:53:35 +05:00
2eff67efc3 Merge pull request 'Fix bug #73222' (#231) from fix/bug73222 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/231
2025-02-14 12:09:16 +00:00
84416ef5b6 Merge pull request 'Fix bug #72871' (#230) from fix/bug72871 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/230
2025-02-14 12:08:56 +00:00
447ade207f Fix bug #73222 2025-02-14 13:56:53 +05:00
ddd7628bbe fix bug #73097 2025-02-13 17:48:33 +03:00
1f86b0265a Fix bug #72871 2025-02-13 18:20:31 +05:00
e484db496b . 2025-02-13 15:14:51 +03:00
5bc1c8d860 fix bug #73215 2025-02-13 15:12:58 +03:00
dbdf4bd120 Merge pull request 'Fix Metafile conversion' (#228) from fix/bugs-metafile into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/228
2025-02-13 09:59:40 +00:00
a93db0e012 . 2025-02-12 18:15:00 +03:00
f145378002 fix additional sdtPr 2025-02-12 15:35:26 +03:00
8098fec345 Merge pull request 'Fix bug #72825' (#227) from fix/bug72825 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/227
2025-02-11 18:11:08 +00:00
7bfcea0fff Merge pull request 'Fix bug #72875' (#226) from fix/bug72875 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/226
2025-02-11 18:10:41 +00:00
4b4845c558 Merge pull request 'Fix bug #72414' (#225) from fix/bug72414 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/225
2025-02-11 18:10:03 +00:00
b26e3e2fee Merge pull request 'fix/bug70675' (#224) from fix/bug70675 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/224
2025-02-11 18:09:33 +00:00
388951670c Merge pull request 'Fix bug #72790' (#223) from fix/bug72790 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/223
2025-02-11 18:08:55 +00:00
7d3488abc9 Merge pull request 'fix/bug-68408' (#229) from fix/bug-68408 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/229
2025-02-11 11:10:20 +00:00
fea3910254 adding reading attributes 2025-02-11 13:22:50 +03:00
2d58b08f0f Merge pull request 'PDF MovePage' (#222) from fix/pre8.3.1 into hotfix/v8.3.1
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/222
2025-02-11 09:06:33 +00:00
612142f0ae Refactoring 2025-02-11 11:24:08 +03:00
2a0c84513b For bug #72962 2025-02-11 11:24:07 +03:00
b7d3464609 Edited default mode ShapeRendering for metafile to svg conversion 2025-02-11 11:24:07 +03:00
beb8574dfd Fix bug #72962 2025-02-11 11:24:07 +03:00
c22cc89ef0 Merge remote-tracking branch 'origin/release/v8.3.0' into fix/bug71975 2025-02-11 13:10:43 +05:00
58255093bf Fix bug #70575 2025-02-11 05:49:33 +05:00
50846677d5 Add missed files 2025-02-10 13:30:46 +03:00
3b450306f1 Merge branch 'hotfix/v8.3.1' of git.onlyoffice.com:ONLYOFFICE/core into hotfix/v8.3.1 2025-02-10 12:07:58 +03:00
c67ec5f632 Add missed file 2025-02-10 11:20:06 +03:00
62450ee1fb add additional props sdt 2025-02-10 10:46:34 +03:00
ad301b6f50 Merge branch 'feature/docbuilder-license' into hotfix/v8.3.1 2025-02-09 00:46:23 +03:00
d251682639 Refactoring 2025-02-09 00:32:48 +03:00
896427db83 For bug 72964 2025-02-08 21:59:52 +03:00
e03f02103b For bug #70575 2025-02-07 18:22:26 +05:00
27c7920def Fix actual pos MovePage 2025-02-07 13:02:22 +03:00
a1b0421ec1 Fix MovePage 2025-02-07 13:02:21 +03:00
b7972ea391 Create MovePage 2025-02-07 13:02:21 +03:00
17840c5ed7 for bug #68408 2025-02-06 16:58:59 +03:00
ff4726e6ec for bug #68408 2025-02-06 15:53:53 +03:00
4e9cd74367 for bug #68408 2025-02-06 15:52:02 +03:00
b8737d2474 for bug #68408 2025-02-06 15:50:15 +03:00
2f4b7442c7 Fix CJSContext::GetCurrent method for jsc version 2025-02-06 12:44:39 +03:00
d97d2668d2 Merge branch release/v8.3.0 into master 2025-02-05 17:15:43 +00:00
45da53e9ae Refactoring standarttester 2025-02-04 20:12:07 +03:00
618a7ea09e Merge remote-tracking branch 'origin/release/v8.3.0' into fix/bug70675 2025-02-04 17:19:00 +05:00
a33743cff2 fix bug #73052 2025-02-04 13:44:41 +06:00
a83e19cbdf fix bug #72176 2025-02-03 16:35:23 +00:00
8a991ae24a Merge pull request 'Fix bug #72857' (#208) from fix/bug72857 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/208
2025-02-03 14:35:21 +00:00
6caca87b64 Merge pull request 'For bug #72496' (#207) from fix/bug72496 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/207
2025-02-03 14:35:10 +00:00
9ab884ae24 Merge pull request 'Fix hwp conversion' (#217) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/217
2025-02-03 14:15:54 +00:00
e493d976e3 Fix bug #73036 2025-02-03 16:59:47 +03:00
d75e7342cf Fix bug #73042 2025-02-03 15:45:09 +03:00
ddd750be9c Merge pull request 'Fix write base fonts' (#216) from fix/pdf-standart-fonts into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/216
2025-02-03 12:40:28 +00:00
79a4434583 Fix bug #73040 2025-02-03 15:35:39 +03:00
44ff2aff3c Fix empty FreeText AP 2025-02-03 15:32:41 +03:00
2f4b3e41b3 Fix write base fonts 2025-02-03 15:24:08 +03:00
fe208f5243 Merge pull request 'Fix bug #72961' (#215) from fix/bug-72961 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/215
2025-02-03 11:15:35 +00:00
e41c1d9703 Fix bug #72961 2025-02-03 14:12:29 +03:00
1cb56e532c Fix bug #72790 2025-02-03 15:39:18 +05:00
5c5f98a6e3 Fix bug 73014 2025-02-03 10:45:38 +03:00
f9dd82ad47 Merge pull request 'Fix HWP conversion' (#211) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/211
2025-02-03 06:43:31 +00:00
084c8f4b94 Fix bug #72999 2025-02-03 07:17:39 +03:00
bf15325a9e Fix bug #73000 2025-02-03 05:25:55 +03:00
1b50b3a53a Fix bug 72868 2025-02-01 17:39:08 +03:00
70b40c46d2 Fix bug #72721 2025-02-01 11:36:52 +03:00
23798f3c96 Fix ios build 2025-01-31 17:14:07 +03:00
1e8d22080d Merge pull request 'Fix hwp bugs' (#209) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/209
2025-01-31 05:08:55 +00:00
90bcd47fb7 The conversion of the character spacing to hwp has been removed 2025-01-31 03:15:19 +03:00
c1adf0b30c Fix bug #72685 2025-01-31 03:15:12 +03:00
b65ed1ccb4 Fix bug #72825 2025-01-31 03:40:47 +05:00
8e4bbb5e27 Fix bug #72875 2025-01-30 22:13:22 +05:00
81a4d9ccd0 Fix bug 72936 2025-01-30 16:51:25 +03:00
a97014c173 Disable use filesystem in metafiles (js module) 2025-01-30 14:26:57 +03:00
b3951d083a Fix elements align in html conversion 2025-01-30 10:37:42 +00:00
7d78b37540 Fix bug #72932 2025-01-30 10:37:42 +00:00
ff162d451e Merge pull request 'Fix hwp bug' (#205) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/205
2025-01-30 10:33:13 +00:00
5dc6402006 Fix test file 2025-01-30 13:12:27 +03:00
fae17d9bfc Merge pull request 'For bug #72694' (#204) from fix/bug72694 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/204
2025-01-30 08:02:28 +00:00
931f4edae4 For bug #72694 2025-01-30 13:36:42 +06:00
3609cf1237 Fix bug #72933 2025-01-30 00:49:49 +03:00
cc8fa641aa Merge pull request 'Fix bug 72811' (#203) from fix/bug-72811 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/203
2025-01-29 16:20:19 +00:00
3b9a865d77 Fix bug 72811 2025-01-29 19:07:58 +03:00
f3b0a992bd Fix typo 2025-01-29 18:57:35 +03:00
74f3e7f279 Merge pull request 'Fix hwp conversion' (#202) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/202
2025-01-29 15:45:08 +00:00
d195aa4a79 Fix build 2025-01-29 18:31:12 +03:00
4a384edf08 For bug #72496 2025-01-29 20:23:33 +05:00
30f96cbc6c Fix bug #72705 2025-01-29 18:15:29 +03:00
007362d8be Fix bug #72780 2025-01-29 17:57:54 +03:00
f4aac048ea fix bug #72012 2025-01-29 17:44:17 +03:00
f815fec8ed Fix bug #72714 2025-01-29 17:14:53 +03:00
4ec217226d Fix bug #72721 2025-01-29 16:32:43 +03:00
3cef41e876 Added bookmark conversion, fix bugs, refactoring in hwp format 2025-01-29 16:22:03 +03:00
20bff1d6fe for bug #72794 2025-01-29 11:17:21 +00:00
8da1a109de Fix bug #72857 2025-01-29 02:28:47 +05:00
704cef604e fix bug #72496 2025-01-28 19:26:15 +03:00
3c850e2086 Fix bug #72667 2025-01-28 13:47:20 +00:00
ab660cb8a3 Merge pull request 'for bug #72496' (#198) from For/bug72496 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/198
2025-01-28 13:12:05 +00:00
af4343b1d8 for bug #72496 2025-01-28 16:06:39 +03:00
7e4fe558f4 Fix bug #72847 2025-01-28 15:17:08 +03:00
f942e56361 fix namespaces 2025-01-28 13:46:28 +03:00
8b85f6987f Merge pull request 'Fix bug #72839' (#197) from fix/bug-72839 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/197
2025-01-28 09:13:21 +00:00
cbe412d3c7 Fix bug #72839 2025-01-28 12:03:31 +03:00
6913cae8f3 Fix bug #72414 2025-01-28 06:09:12 +05:00
d3d9c8df94 Added text indent in hwp conversion 2025-01-27 22:14:25 +03:00
01b582c4b9 Added BorderFill in hwp conversion 2025-01-27 22:01:41 +03:00
4568144a22 Merge branch 'fix/bug72794' into release/v8.3.0 2025-01-27 20:38:15 +03:00
cc4df3726a fix bug #72745 2025-01-27 20:37:02 +03:00
696610862a . 2025-01-27 18:27:20 +03:00
da6a5e9e98 for binary 2025-01-27 15:30:56 +03:00
d395e63b80 Merge pull request 'Fix bug #72657' (#188) from fix/bug72657 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/188
2025-01-27 12:30:02 +00:00
0350675df6 Fix min version 2025-01-27 13:58:30 +03:00
aead2e9fb8 Merge pull request 'Fix bug#72779' (#196) from fix/bug72779 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/196
2025-01-27 10:03:20 +00:00
d12bad7bd1 Fix bug#72779 2025-01-27 15:58:25 +06:00
da2284fff6 Fix bug #72712 2025-01-26 18:26:03 +00:00
1382aa0b3d Fix bug #72780 2025-01-26 18:26:03 +00:00
8ba5df60d9 Fix bug #72705 2025-01-26 18:26:03 +00:00
5299872b17 Fixes for snapshots 2025-01-26 20:18:14 +03:00
e1757dd5d1 fix bug #72796 2025-01-26 12:10:44 +03:00
b5c5a5f1ed Fix bug #72781 2025-01-25 17:56:11 +00:00
6979e17c3d Added polygon and curve conversion in hwp format 2025-01-25 17:56:11 +00:00
c43fb92860 Fixed the correction of large text size in svg 2025-01-25 18:27:22 +03:00
63887c95b6 Use wmf&emf instead conversion to svg in zip images (for native convertations) 2025-01-25 13:39:35 +03:00
d3d4e86925 Merge pull request 'Fix bug #72365' (#179) from fix/bug72365 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/179
2025-01-25 09:25:56 +00:00
f6383571eb fix bug #72794 2025-01-25 12:18:30 +03:00
a6f6a67aed Fix prev commit 2025-01-24 23:30:51 +03:00
f9543ef9de Year Up 2025-01-24 23:03:42 +03:00
bb58be4f18 Add new method for images inside zip 2025-01-24 22:51:04 +03:00
40efe7dabc Fix build 2025-01-24 18:10:29 +00:00
80b7caaf7a Fix bug #72721 2025-01-24 18:10:29 +00:00
08e3dfb061 Fix bug #72772 2025-01-24 18:10:29 +00:00
3a9d91b291 Fix bug #72719 2025-01-24 18:10:29 +00:00
45b26554b2 Merge pull request 'Fix bug #72175' (#191) from fix/bug72175 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/191
2025-01-24 16:19:30 +00:00
09c4df8e05 Fix remove AP when transform 2025-01-24 17:53:23 +03:00
85533a6553 fix bug #72768 2025-01-24 17:35:53 +03:00
65898a94ad Merge pull request 'Fix hwp bugs' (#187) from fix/hwp into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/187
2025-01-24 11:31:39 +00:00
86009ff6fa Fix bug #72175 2025-01-24 12:46:02 +03:00
b91dfb075e Fix bug #72657 2025-01-24 13:42:37 +06:00
f057a16bc1 Fix bug #72700 2025-01-24 04:32:32 +03:00
bd76adc97f Fix bug #72714 2025-01-23 23:36:47 +03:00
27b5dbf15e Fix bad conversion hwp to ooxml 2025-01-23 23:08:52 +03:00
58a7c7cd9d Merge branch 'release/v8.3.0' of git.onlyoffice.com:ONLYOFFICE/core into release/v8.3.0 2025-01-23 15:12:51 +03:00
18fa4639b0 fix convert to ooxml 2025-01-23 15:12:43 +03:00
389e5314df Fix bug #72692 2025-01-23 15:03:17 +03:00
42636a8ab1 Merge pull request 'Fix bug #72173' (#185) from fix/bug72173 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/185
2025-01-23 11:45:45 +00:00
a3c87e7119 Fix crash with fonts with symbol > 0x10FFFF and wirh \n in name 2025-01-23 14:41:39 +03:00
2115371c0c Fix bug #72173 2025-01-23 13:17:46 +03:00
bd95478d77 Fix build 2025-01-22 19:40:15 +03:00
965680de23 Fix build 2025-01-22 19:32:31 +03:00
ad44ddf682 Fix build 2025-01-22 18:55:57 +03:00
06386d5458 Fix build 2025-01-22 18:25:41 +03:00
ffda83848d Fix bug 70819 2025-01-22 15:48:26 +03:00
55dc0b789f Merge remote-tracking branch 'origin/feature/hwpx' into release/v8.3.0 2025-01-22 14:28:50 +03:00
53e3f8c561 Merge pull request 'feature/docx-renderer' (#183) from feature/docx-renderer into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/183
2025-01-22 11:25:17 +00:00
731a7addee Comment logic 2025-01-22 12:57:21 +03:00
36b82c1ef9 add default font size on odf math 2025-01-22 12:42:46 +03:00
229a8f9dad . 2025-01-22 12:14:08 +03:00
5f5d74df92 . 2025-01-22 12:13:15 +03:00
66ea88bf14 fix bug #72043 2025-01-22 12:08:39 +03:00
3953044063 Add clearing 2025-01-22 11:36:13 +03:00
9a4a1546cb Fix bug #72655 2025-01-21 23:19:08 +03:00
4085ee5002 Merge pull request 'Fix bug #69572' (#180) from fix/bug69572 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/180
2025-01-21 15:03:02 +00:00
f6ef582658 Merge pull request 'Fix bug#72187' (#176) from fix/bug72187 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/176
2025-01-21 15:02:15 +00:00
7b62295149 Fix bug 72544 2025-01-21 17:38:05 +03:00
421dcd780d Fix bug #69572 2025-01-21 20:17:24 +06:00
b9e7a3143c Fix bug 72595 2025-01-21 15:57:35 +03:00
6026841c00 Refactoring 2025-01-21 13:01:02 +03:00
1e6d0a9f25 fix text entry 2025-01-21 12:14:13 +03:00
adad3a05ba Fix build 2025-01-21 11:51:14 +03:00
99fa27e693 Merge branch 'release/v8.3.0' into feature/hwpx 2025-01-21 11:50:09 +03:00
6b66c8fb50 Merge pull request 'Fix bug#72189' (#177) from fix/bug72189 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/177
2025-01-21 07:49:05 +00:00
9faa7fb69d Added hwpx format to ASCConverter 2025-01-21 02:49:51 +03:00
84042360ab Fixed bugs in hwpx conversion 2025-01-21 02:49:10 +03:00
8a8a6e78eb fix bug #72578 2025-01-20 21:49:25 +03:00
8bd655dd17 fix bug #72611 2025-01-20 21:22:45 +03:00
34ecf84835 Merge pull request 'Fix bug #72414' (#161) from fix/bug72414 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/161
2025-01-20 18:05:36 +00:00
4cf79c985d Merge pull request 'Fix bug #72432' (#162) from fix/bug72432 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/162
2025-01-20 18:05:05 +00:00
18e359c1a6 Merge pull request 'Fix bug #72375' (#163) from fix/bug72375 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/163
2025-01-20 18:04:21 +00:00
dc777f43d9 Merge pull request 'Fix bug #72264' (#164) from fix/bug72264 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/164
2025-01-20 18:03:52 +00:00
8cd7ca9731 Merge pull request 'Fix bug #72039' (#165) from fix/bug72039 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/165
2025-01-20 18:03:13 +00:00
8f91c47178 Merge pull request 'Fix bug #69238' (#166) from fix/bug69238 into release/v8.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/166
2025-01-20 18:02:44 +00:00
fdac954df5 Add main logic of tables (in developing) 2025-01-20 16:14:28 +03:00
70c98eb9f3 Fix build 2025-01-20 15:42:37 +03:00
024efd2e35 Fix bug #72535 2025-01-20 11:12:14 +00:00
da252bfa5e Fix bug #72589 2025-01-20 11:05:28 +00:00
c9ce68eab3 Improved work with external style files in html 2025-01-20 11:05:28 +00:00
3af549a158 Fix bug #72586 2025-01-20 11:05:28 +00:00
34627ff1c5 Fix bug #72519 2025-01-20 11:05:28 +00:00
0c2b49af11 Fix build for win XP 2025-01-20 10:53:51 +03:00
4324ea847c Reafactoring and fixed bugs in hwp conversion 2025-01-19 20:06:41 +03:00
aa0ba83d32 Fix bug#72189 2025-01-17 18:44:27 +03:00
b78e2cb33c Adding parsing of hwpx format elements 2025-01-17 02:42:21 +03:00
7c2105b613 Fix bug #72365 2025-01-15 22:13:04 +05:00
2027defafb Fix bug #69238
Merge remote-tracking branch 'origin/release/v8.3.0' into fix/bug69238
2025-01-15 21:11:24 +05:00
2ea586ec6f Fix bug #72414 2025-01-15 20:13:21 +05:00
43f1ac0596 Adding parsing of hwpx format elements 2025-01-15 01:28:37 +03:00
02bd5c4b0b Fix bug#72187 2025-01-14 10:17:09 +03:00
6c79ab37fa Fix bug 72193 2025-01-13 17:16:52 +03:00
fdcb2cf7ba Fix bug #72432 2025-01-13 18:19:42 +05:00
07bf7a44aa Fix bug #72375 2025-01-13 17:08:46 +05:00
a2bfbd8368 Adding parsing of hwpx format elements 2025-01-13 01:12:37 +03:00
25553904df Adding parsing of hwpx format elements 2025-01-12 17:25:13 +03:00
954ef08975 Adding parsing of hwpx format elements 2025-01-12 00:34:45 +03:00
00abbab370 Fix bug #72264 2024-12-26 17:52:59 +05:00
91eb74773b Merge branch 'fix/bug72039' of git.onlyoffice.com:ONLYOFFICE/core into fix/bug72039
# Conflicts:
#	OdfFile/Reader/Format/draw_shapes_docx.cpp
2024-12-23 20:31:41 +05:00
5b8d2660aa Fix bug #72039 2024-12-23 20:24:05 +05:00
36b0cc524e Fix bug #72039 2024-12-23 17:33:13 +05:00
5f2d7b2f5a Add base xml for tables 2024-12-20 19:27:23 +03:00
02aeaa6a64 Fix bug with ascent/descent 2024-12-20 17:38:56 +03:00
6fe92e1725 Fix table header columns conversion 2024-12-20 17:58:52 +05:00
48d86cb7ce Add base classes 2024-12-17 15:39:50 +03:00
9991cc8c03 Rewrite split lines logic 2024-12-17 15:13:53 +03:00
36a3b693d5 Update paragraph logic for enums 2024-12-17 13:44:31 +03:00
d58424d089 Fix build 2024-12-14 11:38:11 +03:00
fe2ca8c566 Delete unused headers & add new files 2024-12-14 11:33:47 +03:00
20d2ff7954 Refactoring 2024-12-14 11:18:42 +03:00
b125c19d02 Remove useless call 2024-12-14 07:13:48 +03:00
2f2d11a5f6 Fix bug with recalc size of space 2024-12-14 06:51:59 +03:00
de4897fdef Add HorVerLinesCollector 2024-12-13 16:54:16 +03:00
f9952d0f94 Refactoring for future tables 2024-12-13 15:50:32 +03:00
d7b435a446 Delete unused file 2024-12-13 12:28:13 +03:00
a1ebcaea23 Merge branch hotfix/v8.2.2 into develop 2024-12-09 12:00:03 +00:00
8489127f71 Merge pull request 'release/v8.3.0' (#114) from release/v8.3.0 into develop
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/114
2024-12-04 11:00:36 +00:00
168dc1ddb8 Merge remote-tracking branch 'origin/develop' into fix/bug69238 2024-12-03 13:27:22 +05:00
8918b7fae0 Fix formula conversion order 2024-12-03 13:26:51 +05:00
925ffa09e2 Merge remote-tracking branch 'origin/develop' into fix/bug69238 2024-11-29 19:33:13 +05:00
87b5ae8f75 Merge branch hotfix/v8.2.2 into master 2024-11-28 12:16:10 +00:00
10ff332f4d Merge remote-tracking branch 'origin/develop' into fix/bug69238 2024-11-27 15:45:33 +05:00
ce0f8251d3 Fix bug #69238 2024-11-22 17:32:40 +05:00
6b21323e8c Merge branch hotfix/v8.2.1 into master 2024-11-22 10:46:53 +00:00
42466cf648 Fix atan2 custom shape formula conversion 2024-10-31 18:08:36 +05:00
d21d0caa68 Fix bug #70675 2024-10-16 18:42:07 +05:00
63bf1797c0 Fix bug #70671 2024-10-14 17:57:28 +05:00
f8ba0c59a6 Add license check for onlyoffice docbuilder builds 2024-09-25 16:04:17 +04:00
336 changed files with 9670 additions and 3074 deletions

View File

@ -63,6 +63,26 @@ namespace NSCSS
return m_pInternal->GetDpi();
}
void CCssCalculator::ClearPageData()
{
m_pInternal->ClearPageData();
}
void CCssCalculator::ClearEmbeddedStyles()
{
m_pInternal->ClearEmbeddedStyles();
}
void CCssCalculator::ClearAllowedStyleFiles()
{
m_pInternal->ClearAllowedStyleFiles();
}
void CCssCalculator::ClearStylesFromFile(const std::wstring& wsFilePath)
{
m_pInternal->ClearStylesFromFile(wsFilePath);
}
void CCssCalculator::Clear()
{
m_pInternal->Clear();

View File

@ -35,6 +35,10 @@ namespace NSCSS
std::wstring GetEncoding() const;
unsigned short int GetDpi() const;
void ClearPageData();
void ClearEmbeddedStyles();
void ClearAllowedStyleFiles();
void ClearStylesFromFile(const std::wstring& wsFilePath);
void Clear();
};
}

View File

@ -5,12 +5,9 @@
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <numeric>
#include "../../katana-parser/src/selector.h"
#include "../../../../../UnicodeConverter/UnicodeConverter.h"
#include "ConstValues.h"
#include "../../../../../DesktopEditor/common/File.h"
#include "StaticFunctions.h"
@ -41,58 +38,120 @@ bool operator<(const std::vector<NSCSS::CNode> &arLeftSelectors, const std::vect
namespace NSCSS
{
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_sEncoding(L"UTF-8"){}
CStyleStorage::CStyleStorage()
{}
CCssCalculator_Private::~CCssCalculator_Private()
CStyleStorage::~CStyleStorage()
{
m_arFiles.clear();
for (std::map<std::wstring, CElement*>::iterator oIter = m_mData.begin(); oIter != m_mData.end(); ++oIter)
if (oIter->second != NULL)
delete oIter->second;
m_mData.clear();
Clear();
}
inline void CCssCalculator_Private::GetOutputData(KatanaOutput *oOutput)
void CStyleStorage::Clear()
{
if ( NULL == oOutput )
return;
for (TStyleFileData* pStyleFileData : m_arStyleFiles)
{
if (nullptr == pStyleFileData)
continue;
switch (oOutput->mode) {
case KatanaParserModeStylesheet:
GetStylesheet(oOutput->stylesheet);
break;
case KatanaParserModeRule:
GetRule(oOutput->rule);
break;
case KatanaParserModeKeyframeRule:
case KatanaParserModeKeyframeKeyList:
case KatanaParserModeMediaList:
case KatanaParserModeValue:
case KatanaParserModeSelector:
case KatanaParserModeDeclarationList:
break;
for (std::map<std::wstring, CElement*>::iterator oIter = pStyleFileData->m_mStyleData.begin(); oIter != pStyleFileData->m_mStyleData.end(); ++oIter)
if (oIter->second != nullptr)
delete oIter->second;
delete pStyleFileData;
}
m_arStyleFiles.clear();
m_arEmptyStyleFiles.clear();
ClearEmbeddedStyles();
ClearAllowedStyleFiles();
#ifdef CSS_CALCULATOR_WITH_XHTML
ClearPageData();
#endif
}
void CStyleStorage::AddStyles(const std::string& sStyle)
{
if (sStyle.empty())
return;
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
this->GetOutputData(output, m_mEmbeddedStyleData);
katana_destroy_output(output);
}
void CStyleStorage::AddStyles(const std::wstring& wsStyle)
{
if (wsStyle.empty())
return;
#ifdef CSS_CALCULATOR_WITH_XHTML
std::wregex oRegex(L"@page\\s*([^{]*)(\\{[^}]*\\})");
std::wsmatch oMatch;
std::wstring::const_iterator oSearchStart(wsStyle.cbegin());
while (std::regex_search(oSearchStart, wsStyle.cend(), oMatch, oRegex))
{
AddPageData(oMatch[1].str(), oMatch[2].str());
oSearchStart = oMatch.suffix().first;
}
#endif
AddStyles(U_TO_UTF8(wsStyle));
}
void CStyleStorage::AddStylesFromFile(const std::wstring& wsFileName)
{
std::set<std::wstring>::const_iterator itEmptyFileFound = m_arEmptyStyleFiles.find(wsFileName);
if (m_arEmptyStyleFiles.cend() != itEmptyFileFound)
return;
std::vector<TStyleFileData*>::const_iterator itFound = std::find_if(m_arStyleFiles.cbegin(), m_arStyleFiles.cend(),
[wsFileName](const TStyleFileData* pStyleFileData)
{ return wsFileName == pStyleFileData->m_wsStyleFilepath; });
m_arAllowedStyleFiles.insert(wsFileName);
if (m_arStyleFiles.cend() != itFound)
return;
TStyleFileData *pStyleFileData = new TStyleFileData();
pStyleFileData->m_wsStyleFilepath = wsFileName;
AddStyles(NS_STATIC_FUNCTIONS::GetContentAsUTF8(wsFileName), pStyleFileData->m_mStyleData);
if (!pStyleFileData->m_mStyleData.empty())
m_arStyleFiles.push_back(pStyleFileData);
else
{
m_arEmptyStyleFiles.insert(wsFileName);
delete pStyleFileData;
}
}
void CStyleStorage::ClearStylesFromFile(const std::wstring& wsFileName)
{
std::vector<TStyleFileData*>::const_iterator itFound = std::find_if(m_arStyleFiles.cbegin(), m_arStyleFiles.cend(),
[wsFileName](const TStyleFileData* pStyleFileData)
{ return wsFileName == pStyleFileData->m_wsStyleFilepath; });
if (m_arStyleFiles.cend() != itFound)
{
m_arStyleFiles.erase(itFound);
delete *itFound;
}
}
#ifdef CSS_CALCULATOR_WITH_XHTML
std::map<std::wstring, std::wstring> CCssCalculator_Private::GetPageData(const std::wstring &wsPageName)
void CStyleStorage::AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles)
{
if (m_arPageDatas.empty())
return {};
for (const TPageData& oPageData : m_arPageDatas)
{
if (std::find(oPageData.m_wsNames.begin(), oPageData.m_wsNames.end(), wsPageName) != oPageData.m_wsNames.end())
return oPageData.m_mData;
}
return {};
m_arPageDatas.push_back({NS_STATIC_FUNCTIONS::GetWordsW(wsPageName), NS_STATIC_FUNCTIONS::GetRules(wsStyles)});
}
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
void CStyleStorage::SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode)
{
for (const std::pair<std::wstring, std::wstring> &oData : mData)
{
@ -107,149 +166,84 @@ namespace NSCSS
}
}
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors)
std::map<std::wstring, std::wstring> CStyleStorage::GetPageData(const std::wstring& wsPageName)
{
std::vector<std::wstring> arNodes;
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
if (!oNode->m_wsName.empty())
arNodes.push_back(oNode->m_wsName);
if (!oNode->m_wsClass.empty())
{
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, false, L" ");
arNodes.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
}
else
arNodes.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_wsId.empty())
arNodes.push_back(L'#' + oNode->m_wsId);
}
return arNodes;
}
void CCssCalculator_Private::FindPrevAndKindElements(const CElement *pElement, const std::vector<std::wstring> &arNextNodes, std::vector<CElement*>& arFindedElements, const std::wstring &wsName, const std::vector<std::wstring> &arClasses)
{
if (arNextNodes.empty())
return;
const std::vector<CElement*> arTempPrev = pElement->GetPrevElements(arNextNodes.crbegin() + 1, arNextNodes.crend());
const std::vector<CElement*> arTempKins = pElement->GetNextOfKin(wsName, arClasses);
if (!arTempPrev.empty())
arFindedElements.insert(arFindedElements.end(), arTempPrev.begin(), arTempPrev.end());
if (!arTempKins.empty())
arFindedElements.insert(arFindedElements.end(), arTempKins.begin(), arTempKins.end());
}
std::vector<CElement*> CCssCalculator_Private::FindElements(std::vector<std::wstring> &arNodes, std::vector<std::wstring> &arNextNodes)
{
if (arNodes.empty())
if (m_arPageDatas.empty())
return {};
std::vector<CElement*> arFindedElements;
std::wstring wsName, wsId;
std::vector<std::wstring> arClasses;
if (!arNodes.empty() && arNodes.back()[0] == L'#')
for (const TPageData& oPageData : m_arPageDatas)
{
wsId = arNodes.back();
arNodes.pop_back();
arNextNodes.push_back(wsId);
if (std::find(oPageData.m_wsNames.begin(), oPageData.m_wsNames.end(), wsPageName) != oPageData.m_wsNames.end())
return oPageData.m_mData;
}
if (!arNodes.empty() && arNodes.back()[0] == L'.')
{
arClasses = NS_STATIC_FUNCTIONS::GetWordsW(arNodes.back(), false, L" ");
arNextNodes.push_back(arNodes.back());
arNodes.pop_back();
}
return {};
}
if (!arNodes.empty())
{
wsName = arNodes.back();
arNodes.pop_back();
arNextNodes.push_back(wsName);
}
const std::map<std::wstring, CElement*>::const_iterator oFindName = m_mData.find(wsName);
std::map<std::wstring, CElement*>::const_iterator oFindId;
if (!wsId.empty())
{
oFindId = m_mData.find(wsId);
if (m_mData.cend() != oFindId)
{
if (!oFindId->second->Empty())
arFindedElements.push_back(oFindId->second);
FindPrevAndKindElements(oFindId->second, arNextNodes, arFindedElements, wsName);
}
}
if (!arClasses.empty())
{
for (std::vector<std::wstring>::const_reverse_iterator iClass = arClasses.rbegin(); iClass != arClasses.rend(); ++iClass)
{
const std::map<std::wstring, CElement*>::const_iterator oFindClass = m_mData.find(*iClass);
if (oFindClass != m_mData.cend())
{
if (!oFindClass->second->Empty())
arFindedElements.push_back(oFindClass->second);
FindPrevAndKindElements(oFindClass->second, arNextNodes, arFindedElements, wsName);
}
}
}
if (oFindName != m_mData.cend())
{
if (!oFindName->second->Empty())
arFindedElements.push_back(oFindName->second);
FindPrevAndKindElements(oFindName->second, arNextNodes, arFindedElements, wsName, arClasses);
}
if (arFindedElements.size() > 1)
{
std::sort(arFindedElements.rbegin(), arFindedElements.rend(),
[](CElement* oFirstElement, CElement* oSecondElement)
{
return oFirstElement->GetWeight() > oSecondElement->GetWeight();
});
}
return arFindedElements;
void CStyleStorage::ClearPageData()
{
m_arPageDatas.clear();
}
#endif
void CCssCalculator_Private::AddPageData(const std::wstring &wsPageNames, const std::wstring &wsStyles)
const CElement* CStyleStorage::FindElement(const std::wstring& wsSelector)
{
m_arPageDatas.push_back({NS_STATIC_FUNCTIONS::GetWordsW(wsPageNames), NS_STATIC_FUNCTIONS::GetRules(wsStyles)});
if (wsSelector.empty())
return nullptr;
const CElement* pFoundElement = FindSelectorFromStyleData(wsSelector, m_mEmbeddedStyleData);
if (nullptr != pFoundElement)
return pFoundElement;
for (std::vector<TStyleFileData*>::const_reverse_iterator itIter = m_arStyleFiles.crbegin(); itIter < m_arStyleFiles.crend(); ++itIter)
{
if (m_arAllowedStyleFiles.cend() == std::find(m_arAllowedStyleFiles.cbegin(), m_arAllowedStyleFiles.cend(), (*itIter)->m_wsStyleFilepath))
continue;
pFoundElement = FindSelectorFromStyleData(wsSelector, (*itIter)->m_mStyleData);
if (nullptr != pFoundElement)
return pFoundElement;
}
return nullptr;
}
inline void CCssCalculator_Private::GetStylesheet(const KatanaStylesheet *oStylesheet)
void CStyleStorage::AddStyles(const std::string& sStyle, std::map<std::wstring, CElement*>& mStyleData)
{
if (sStyle.empty())
return;
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
this->GetOutputData(output, mStyleData);
katana_destroy_output(output);
}
void CStyleStorage::ClearEmbeddedStyles()
{
for (std::map<std::wstring, CElement*>::iterator oIter = m_mEmbeddedStyleData.begin(); oIter != m_mEmbeddedStyleData.end(); ++oIter)
if (oIter->second != nullptr)
delete oIter->second;
m_mEmbeddedStyleData.clear();
}
void CStyleStorage::ClearAllowedStyleFiles()
{
m_arAllowedStyleFiles.clear();
}
void CStyleStorage::GetStylesheet(const KatanaStylesheet* oStylesheet, std::map<std::wstring, CElement*>& mStyleData)
{
for (size_t i = 0; i < oStylesheet->imports.length; ++i)
GetRule((KatanaRule*)oStylesheet->imports.data[i]);
GetRule((KatanaRule*)oStylesheet->imports.data[i], mStyleData);
for (size_t i = 0; i < oStylesheet->rules.length; ++i)
GetRule((KatanaRule*)oStylesheet->rules.data[i]);
GetRule((KatanaRule*)oStylesheet->rules.data[i], mStyleData);
}
inline void CCssCalculator_Private::GetRule(const KatanaRule *oRule)
void CStyleStorage::GetRule(const KatanaRule* oRule, std::map<std::wstring, CElement*>& mStyleData)
{
if ( NULL == oRule )
return;
@ -257,7 +251,7 @@ namespace NSCSS
switch (oRule->type) {
case KatanaRuleStyle:
{
GetStyleRule((KatanaStyleRule*)oRule);
GetStyleRule((KatanaStyleRule*)oRule, mStyleData);
break;
}
default:
@ -265,7 +259,7 @@ namespace NSCSS
}
}
inline void CCssCalculator_Private::GetStyleRule(const KatanaStyleRule *oRule)
void CStyleStorage::GetStyleRule(const KatanaStyleRule* oRule, std::map<std::wstring, CElement*>& mStyleData)
{
if (oRule->declarations->length == 0)
return;
@ -281,7 +275,7 @@ namespace NSCSS
for (std::vector<std::wstring>::reverse_iterator oWord = arWords.rbegin(); oWord != arWords.rend(); ++oWord)
{
const size_t posPoint = oWord->find(L'.');
const size_t posPoint = oWord->find(L'.');
const size_t posLattice = oWord->find(L'#');
const std::wstring sName = (posPoint != std::wstring::npos) ? oWord->substr(0, posPoint) : (posLattice != std::wstring::npos) ? oWord->substr(0, posLattice) : *oWord;
@ -297,8 +291,8 @@ namespace NSCSS
{
if (NULL == oFirstElement && bCreateFirst)
{
const std::map<std::wstring, CElement*>::const_iterator& oFindId = m_mData.find(sId);
if (oFindId != m_mData.end())
const std::map<std::wstring, CElement*>::const_iterator& oFindId = mStyleData.find(sId);
if (oFindId != mStyleData.end())
{
oIdElement = oFindId->second;
bCreateFirst = false;
@ -326,8 +320,8 @@ namespace NSCSS
{
if (NULL == oFirstElement && bCreateFirst)
{
const std::map<std::wstring, CElement*>::const_iterator& oFindClass = m_mData.find(sClass);
if (oFindClass != m_mData.end())
const std::map<std::wstring, CElement*>::const_iterator& oFindClass = mStyleData.find(sClass);
if (oFindClass != mStyleData.end())
{
oClassElement = oFindClass->second;
bCreateFirst = false;
@ -359,8 +353,8 @@ namespace NSCSS
{
if (NULL == oFirstElement && bCreateFirst)
{
const std::map<std::wstring, CElement*>::const_iterator& oFindName = m_mData.find(sName);
if (oFindName != m_mData.end())
const std::map<std::wstring, CElement*>::const_iterator& oFindName = mStyleData.find(sName);
if (oFindName != mStyleData.end())
{
oNameElement = oFindName->second;
bCreateFirst = false;
@ -392,11 +386,16 @@ namespace NSCSS
oLastElement->AddProperties(mStyle);
if (NULL != oFirstElement)
m_mData[oFirstElement->GetSelector()] = oFirstElement;
mStyleData[oFirstElement->GetSelector()] = oFirstElement;
}
}
inline std::vector<std::wstring> CCssCalculator_Private::GetSelectorList(const KatanaArray* oSelectors) const
std::wstring CStyleStorage::GetValueList(const KatanaArray* oValues)
{
return StringifyValueList(oValues);
}
std::vector<std::wstring> CStyleStorage::GetSelectorList(const KatanaArray* oSelectors) const
{
if (oSelectors->length == 0)
return std::vector<std::wstring>();
@ -409,7 +408,7 @@ namespace NSCSS
return arSelectors;
}
inline std::wstring CCssCalculator_Private::GetSelector(const KatanaSelector *oSelector) const
std::wstring CStyleStorage::GetSelector(const KatanaSelector* oSelector) const
{
KatanaParser oParser;
oParser.options = &kKatanaDefaultOptions;
@ -428,7 +427,7 @@ namespace NSCSS
return wsText;
}
inline std::map<std::wstring, std::wstring> CCssCalculator_Private::GetDeclarationList(const KatanaArray* oDeclarations) const
std::map<std::wstring, std::wstring> CStyleStorage::GetDeclarationList(const KatanaArray* oDeclarations) const
{
if(oDeclarations->length == 0)
return std::map<std::wstring, std::wstring>();
@ -441,7 +440,7 @@ namespace NSCSS
return arDeclarations;
}
inline std::pair<std::wstring, std::wstring> CCssCalculator_Private::GetDeclaration(const KatanaDeclaration* oDecl) const
std::pair<std::wstring, std::wstring> CStyleStorage::GetDeclaration(const KatanaDeclaration* oDecl) const
{
std::wstring sValueList = StringifyValueList(oDecl->values);
@ -451,9 +450,184 @@ namespace NSCSS
return std::make_pair(UTF8_TO_U(std::string(oDecl->property)), sValueList);
}
inline std::wstring CCssCalculator_Private::GetValueList(const KatanaArray *oValues)
void CStyleStorage::GetOutputData(KatanaOutput* oOutput, std::map<std::wstring, CElement*>& mStyleData)
{
return StringifyValueList(oValues);
if ( NULL == oOutput )
return;
switch (oOutput->mode) {
case KatanaParserModeStylesheet:
GetStylesheet(oOutput->stylesheet, mStyleData);
break;
case KatanaParserModeRule:
GetRule(oOutput->rule, mStyleData);
break;
case KatanaParserModeKeyframeRule:
case KatanaParserModeKeyframeKeyList:
case KatanaParserModeMediaList:
case KatanaParserModeValue:
case KatanaParserModeSelector:
case KatanaParserModeDeclarationList:
break;
}
}
const CElement* CStyleStorage::FindSelectorFromStyleData(const std::wstring& wsSelector, const std::map<std::wstring, CElement*>& mStyleData)
{
std::map<std::wstring, CElement*>::const_iterator itFound = mStyleData.find(wsSelector);
if (mStyleData.cend() != itFound)
return itFound->second;
return nullptr;
}
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_sEncoding(L"UTF-8"){}
CCssCalculator_Private::~CCssCalculator_Private()
{}
#ifdef CSS_CALCULATOR_WITH_XHTML
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
{
//TODO:: пересмотреть данный метод
m_oStyleStorage.SetPageData(oPage, mData, unLevel, bHardMode);
}
std::map<std::wstring, std::wstring> CCssCalculator_Private::GetPageData(const std::wstring &wsPageName)
{
return m_oStyleStorage.GetPageData(wsPageName);
}
void CCssCalculator_Private::ClearPageData()
{
m_oStyleStorage.ClearPageData();
}
#endif
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors)
{
std::vector<std::wstring> arNodes;
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
if (!oNode->m_wsName.empty())
arNodes.push_back(oNode->m_wsName);
if (!oNode->m_wsClass.empty())
{
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, false, L" ");
arNodes.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
}
else
arNodes.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_wsId.empty())
arNodes.push_back(L'#' + oNode->m_wsId);
}
return arNodes;
}
void CCssCalculator_Private::FindPrevAndKindElements(const CElement *pElement, const std::vector<std::wstring> &arNextNodes, std::vector<const CElement*>& arFindedElements, const std::wstring &wsName, const std::vector<std::wstring> &arClasses)
{
if (arNextNodes.empty())
return;
const std::vector<CElement*> arTempPrev = pElement->GetPrevElements(arNextNodes.crbegin() + 1, arNextNodes.crend());
const std::vector<CElement*> arTempKins = pElement->GetNextOfKin(wsName, arClasses);
if (!arTempPrev.empty())
arFindedElements.insert(arFindedElements.end(), arTempPrev.begin(), arTempPrev.end());
if (!arTempKins.empty())
arFindedElements.insert(arFindedElements.end(), arTempKins.begin(), arTempKins.end());
}
std::vector<const CElement*> CCssCalculator_Private::FindElements(std::vector<std::wstring> &arNodes, std::vector<std::wstring> &arNextNodes)
{
if (arNodes.empty())
return {};
std::vector<const CElement*> arFindedElements;
std::wstring wsName, wsId;
std::vector<std::wstring> arClasses;
if (!arNodes.empty() && arNodes.back()[0] == L'#')
{
wsId = arNodes.back();
arNodes.pop_back();
arNextNodes.push_back(wsId);
}
if (!arNodes.empty() && arNodes.back()[0] == L'.')
{
arClasses = NS_STATIC_FUNCTIONS::GetWordsW(arNodes.back(), false, L" ");
arNextNodes.push_back(arNodes.back());
arNodes.pop_back();
}
if (!arNodes.empty())
{
wsName = arNodes.back();
arNodes.pop_back();
arNextNodes.push_back(wsName);
}
if (!wsId.empty())
{
const CElement* pFoundId = m_oStyleStorage.FindElement(wsId);
if(nullptr != pFoundId)
{
if (!pFoundId->Empty())
arFindedElements.push_back(pFoundId);
FindPrevAndKindElements(pFoundId, arNextNodes, arFindedElements, wsName);
}
}
if (!arClasses.empty())
{
for (std::vector<std::wstring>::const_reverse_iterator iClass = arClasses.rbegin(); iClass != arClasses.rend(); ++iClass)
{
const CElement* pFoundClass = m_oStyleStorage.FindElement(*iClass);
if (nullptr != pFoundClass)
{
if (!pFoundClass->Empty())
arFindedElements.push_back(pFoundClass);
FindPrevAndKindElements(pFoundClass, arNextNodes, arFindedElements, wsName);
}
}
}
const CElement* pFoundName = m_oStyleStorage.FindElement(wsName);
if (nullptr != pFoundName)
{
if (!pFoundName->Empty())
arFindedElements.push_back(pFoundName);
FindPrevAndKindElements(pFoundName, arNextNodes, arFindedElements, wsName, arClasses);
}
if (arFindedElements.size() > 1)
{
std::sort(arFindedElements.rbegin(), arFindedElements.rend(),
[](const CElement* oFirstElement, const CElement* oSecondElement)
{ return oFirstElement->GetWeight() > oSecondElement->GetWeight(); });
}
return arFindedElements;
}
#ifdef CSS_CALCULATOR_WITH_XHTML
@ -566,42 +740,20 @@ namespace NSCSS
return true;
}
#endif
void CCssCalculator_Private::AddStyles(const std::string &sStyle)
{
if (sStyle.empty())
return;
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
this->GetOutputData(output);
katana_destroy_output(output);
void CCssCalculator_Private::AddStyles(const std::string& sStyle)
{
m_oStyleStorage.AddStyles(sStyle);
}
void CCssCalculator_Private::AddStyles(const std::wstring &wsStyle)
void CCssCalculator_Private::AddStyles(const std::wstring& wsStyle)
{
if (wsStyle.empty())
return;
std::wregex oRegex(L"@page\\s*([^{]*)(\\{[^}]*\\})");
std::wsmatch oMatch;
std::wstring::const_iterator oSearchStart(wsStyle.cbegin());
while (std::regex_search(oSearchStart, wsStyle.cend(), oMatch, oRegex))
{
AddPageData(oMatch[1].str(), oMatch[2].str());
oSearchStart = oMatch.suffix().first;
}
AddStyles(U_TO_UTF8(wsStyle));
m_oStyleStorage.AddStyles(wsStyle);
}
void CCssCalculator_Private::AddStylesFromFile(const std::wstring& wsFileName)
{
if (std::find(m_arFiles.begin(), m_arFiles.end(), wsFileName) != m_arFiles.end())
return;
m_arFiles.push_back(wsFileName);
AddStyles(NS_STATIC_FUNCTIONS::GetContentAsUTF8(wsFileName));
m_oStyleStorage.AddStylesFromFile(wsFileName);
}
void CCssCalculator_Private::SetDpi(unsigned short int nValue)
@ -614,9 +766,23 @@ namespace NSCSS
return m_nDpi;
}
const std::map<std::wstring, CElement *> *CCssCalculator_Private::GetData() const
void CCssCalculator_Private::ClearEmbeddedStyles()
{
return &m_mData;
m_oStyleStorage.ClearEmbeddedStyles();
#ifdef CSS_CALCULATOR_WITH_XHTML
m_mUsedStyles.clear();
#endif
}
void CCssCalculator_Private::ClearAllowedStyleFiles()
{
m_oStyleStorage.ClearAllowedStyleFiles();
}
void CCssCalculator_Private::ClearStylesFromFile(const std::wstring& wsFilePath)
{
m_oStyleStorage.ClearStylesFromFile(wsFilePath);
}
std::wstring CCssCalculator_Private::GetEncoding() const
@ -629,10 +795,21 @@ namespace NSCSS
m_sEncoding = L"UTF-8";
m_nDpi = 96;
m_mData.clear();
m_arFiles.clear();
m_oStyleStorage.Clear();
#ifdef CSS_CALCULATOR_WITH_XHTML
m_mUsedStyles.clear();
#endif
}
bool IsTableElement(const std::wstring& wsNameTag)
{
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
L"th" == wsNameTag;
}
}
inline static std::wstring StringifyValueList(const KatanaArray* oValues)
{
if (NULL == oValues)
@ -733,11 +910,4 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
return str;
}
inline static bool IsTableElement(const std::wstring& wsNameTag)
{
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
L"th" == wsNameTag;
}

View File

@ -3,11 +3,9 @@
#include <vector>
#include <map>
#include <list>
#include <functional>
#include <set>
#include "CElement.h"
#include "ConstValues.h"
#include "CUnitMeasureConverter.h"
#include "StyleProperties.h"
#include "../../katana-parser/src/katana.h"
#ifdef CSS_CALCULATOR_WITH_XHTML
@ -16,15 +14,43 @@
namespace NSCSS
{
class CCssCalculator_Private
class CStyleStorage
{
unsigned short int m_nDpi;
unsigned short int m_nCountNodes;
public:
CStyleStorage();
~CStyleStorage();
std::list<std::wstring> m_arFiles;
void Clear();
std::map<std::wstring, CElement*> m_mData;
void AddStyles(const std::string& sStyle);
void AddStyles(const std::wstring& wsStyle);
void AddStylesFromFile(const std::wstring& wsFileName);
void ClearEmbeddedStyles();
void ClearAllowedStyleFiles();
void ClearStylesFromFile(const std::wstring& wsFileName);
#ifdef CSS_CALCULATOR_WITH_XHTML
void AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles);
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
void ClearPageData();
#endif
const CElement* FindElement(const std::wstring& wsSelector);
private:
typedef struct
{
std::wstring m_wsStyleFilepath;
std::map<std::wstring, CElement*> m_mStyleData;
} TStyleFileData;
std::set<std::wstring> m_arEmptyStyleFiles;
std::set<std::wstring> m_arAllowedStyleFiles;
std::vector<TStyleFileData*> m_arStyleFiles;
std::map<std::wstring, CElement*> m_mEmbeddedStyleData;
#ifdef CSS_CALCULATOR_WITH_XHTML
typedef struct
{
std::vector<std::wstring> m_wsNames;
@ -32,27 +58,14 @@ namespace NSCSS
} TPageData;
std::vector<TPageData> m_arPageDatas;
#ifdef CSS_CALCULATOR_WITH_XHTML
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
void FindPrevAndKindElements(const CElement* pElement, const std::vector<std::wstring>& arNextNodes, std::vector<CElement*>& arFindedElements, const std::wstring& wsName, const std::vector<std::wstring>& arClasses = {});
std::vector<CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes);
#endif
private:
void AddStyles(const std::string& sStyle, std::map<std::wstring, CElement*>& mStyleData);
std::wstring m_sEncoding;
void GetStylesheet(const KatanaStylesheet* oStylesheet, std::map<std::wstring, CElement*>& mStyleData);
void GetRule(const KatanaRule* oRule, std::map<std::wstring, CElement*>& mStyleData);
void AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles);
void GetStylesheet(const KatanaStylesheet* oStylesheet);
void GetRule(const KatanaRule* oRule);
void GetStyleRule(const KatanaStyleRule* oRule);
void GetStyleRule(const KatanaStyleRule* oRule, std::map<std::wstring, CElement*>& mStyleData);
std::wstring GetValueList(const KatanaArray* oValues);
@ -62,8 +75,28 @@ namespace NSCSS
std::map<std::wstring, std::wstring> GetDeclarationList(const KatanaArray* oDeclarations) const;
std::pair<std::wstring, std::wstring> GetDeclaration(const KatanaDeclaration* oDecl) const;
void GetOutputData(KatanaOutput* oOutput);
void GetOutputData(KatanaOutput* oOutput, std::map<std::wstring, CElement*>& mStyleData);
const CElement* FindSelectorFromStyleData(const std::wstring& wsSelector, const std::map<std::wstring, CElement*>& mStyleData);
};
class CCssCalculator_Private
{
unsigned short int m_nDpi;
unsigned short int m_nCountNodes;
CStyleStorage m_oStyleStorage;
#ifdef CSS_CALCULATOR_WITH_XHTML
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
std::map<std::wstring, std::wstring> GetPageData(const std::wstring &wsPageName);
#endif
void FindPrevAndKindElements(const CElement* pElement, const std::vector<std::wstring>& arNextNodes, std::vector<const CElement*>& arFindedElements, const std::wstring& wsName, const std::vector<std::wstring>& arClasses = {});
std::wstring m_sEncoding;
public:
CCssCalculator_Private();
~CCssCalculator_Private();
@ -74,8 +107,13 @@ namespace NSCSS
std::wstring CalculateStyleId(const CNode& oNode);
bool CalculatePageStyle(NSProperties::CPage& oPageData, const std::vector<CNode> &arSelectors);
void ClearPageData();
#endif
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
std::vector<const CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes);
void AddStyles(const std::string& sStyle);
void AddStyles(const std::wstring& wsStyle);
void AddStylesFromFile(const std::wstring& wsFileName);
@ -85,10 +123,12 @@ namespace NSCSS
std::wstring GetEncoding() const;
unsigned short int GetDpi() const;
const std::map<std::wstring, CElement*>* GetData() const;
void ClearEmbeddedStyles();
void ClearAllowedStyleFiles();
void ClearStylesFromFile(const std::wstring& wsFilePath);
void Clear();
};
inline bool IsTableElement(const std::wstring& wsNameTag);
}
#endif // CCSSCALCULATOR_PRIVATE_H

View File

@ -40,6 +40,7 @@ namespace NSCSS
{
m_sSelector = sSelector;
m_sFullSelector = m_sSelector;
UpdateWeight();
}
void NSCSS::CElement::AddPropertie(const std::wstring &sName, const std::wstring& sValue)
@ -67,6 +68,7 @@ namespace NSCSS
m_arPrevElements.push_back(oPrevElement);
oPrevElement->m_sFullSelector += L' ' + m_sFullSelector;
UpdateWeight();
}
void CElement::AddKinElement(CElement *oKinElement)
@ -76,6 +78,7 @@ namespace NSCSS
m_arKinElements.push_back(oKinElement);
oKinElement->m_sFullSelector += m_sFullSelector;
oKinElement->UpdateWeight();
}
std::map<std::wstring, std::wstring> CElement::GetStyle() const
@ -230,11 +233,14 @@ namespace NSCSS
return NULL;
}
std::vector<unsigned short> CElement::GetWeight()
void CElement::UpdateWeight()
{
if (m_arWeight.empty())
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
}
std::vector<unsigned short> CElement::GetWeight() const
{
return m_arWeight;
}

View File

@ -44,7 +44,8 @@ namespace NSCSS
CElement *FindPrevElement(const std::wstring& sSelector) const;
std::vector<unsigned short int> GetWeight();
void UpdateWeight();
std::vector<unsigned short int> GetWeight() const;
void IncreasedWeight();
};
}

View File

@ -48,7 +48,6 @@ namespace NS_STATIC_FUNCTIONS
if (sEncoding.empty())
sEncoding = "utf-8";
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
{
NSUnicodeConverter::CUnicodeConverter oConverter;

View File

@ -316,7 +316,7 @@ namespace NSCSS
std::wstring wsTextAlign{oStyle.m_oText.GetAlign().ToWString()};
if (wsTextAlign.empty() && bInTable)
if (wsTextAlign.empty())
wsTextAlign = oStyle.m_oDisplay.GetHAlign().ToWString();
oXmlElement.AddPropertiesInP(PProperties::P_Jc, wsTextAlign);

View File

@ -68,6 +68,7 @@ public:
bool isOOXFormatFile(const std::wstring& fileName, bool unpacked = false);
bool isOpenOfficeFormatFile(const std::wstring& fileName, std::wstring& documentID);
bool isOnlyOfficeFormatFile(const std::wstring& fileName);
bool isMacFormatFile(const std::wstring& fileName);
bool isDocFormatFile(const std::wstring& fileName);
bool isXlsFormatFile(const std::wstring& fileName);
@ -80,6 +81,7 @@ public:
bool isMS_MITCRYPTOFormatFile(POLE::Storage* storage, std::wstring& documentID);
bool isVbaProjectFile(POLE::Storage* storage);
bool isMS_OFFCRYPTOFormatFile(const std::wstring& fileName, std::wstring& documentID);
bool isHwpFile(POLE::Storage* storage);
bool iXmlFile(const std::wstring& fileName);

View File

@ -451,6 +451,20 @@ bool COfficeFileFormatChecker::isVbaProjectFile(POLE::Storage *storage)
}
return true;
}
bool COfficeFileFormatChecker::isHwpFile(POLE::Storage* storage)
{
if (storage == NULL)
return false;
unsigned char buffer[10];
POLE::Stream stream(storage, L"BodyText/Section0");
if (stream.read(buffer, 10) < 1)
{
return false;
}
return true;
}
bool COfficeFileFormatChecker::isXlsFormatFile(POLE::Storage *storage)
{
if (storage == NULL)
@ -721,6 +735,11 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
nFileType = AVS_OFFICESTUDIO_FILE_OTHER_MS_VBAPROJECT;
return true;
}
else if (isHwpFile(&storage))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HWP;
return true;
}
}
NSFile::CFileBinary file;
if (!file.OpenFile(fileName))
@ -767,6 +786,13 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
bufferDetect = NULL;
return true;
}
else if (isMacFormatFile(fileName))
{
if (bufferDetect)
delete[] bufferDetect;
bufferDetect = NULL;
return true;
}
}
//-----------------------------------------------------------------------------------------------
@ -1133,6 +1159,58 @@ bool COfficeFileFormatChecker::isOnlyOfficeFormatFile(const std::wstring &fileNa
}
return false;
}
bool COfficeFileFormatChecker::isMacFormatFile(const std::wstring& fileName)
{
COfficeUtils OfficeUtils(NULL);
ULONG nBufferSize = 0;
BYTE* pBuffer = NULL;
HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Document.iwa", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES;
delete[] pBuffer;
pBuffer = NULL;
hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Slide.iwa", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
delete[] pBuffer;
pBuffer = NULL;
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY;
return true;
}
hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Tables/DataList.iwa", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
delete[] pBuffer;
pBuffer = NULL;
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS;
return true;
}
std::wstring::size_type nExtPos = fileName.rfind(L'.');
std::wstring sExt = L"unknown";
if (nExtPos != std::wstring::npos)
sExt = fileName.substr(nExtPos);
std::transform(sExt.begin(), sExt.end(), sExt.begin(), tolower);
if (0 == sExt.compare(L".pages"))
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES;
else if (0 == sExt.compare(L".numbers"))
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS;
else if (0 == sExt.compare(L".key"))
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY;
return true;
}
return false;
}
bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring &fileName, std::wstring &documentID)
{
documentID.clear();

View File

@ -0,0 +1,61 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef DOC_BUILDER_ADDON_PRIVATE
#define DOC_BUILDER_ADDON_PRIVATE
#include <string>
#include "../docbuilder.h"
namespace NSDoctRenderer
{
class CDocBuilderAddon
{
private:
std::wstring m_sWorkDirectory;
public:
CDocBuilderAddon(const std::wstring& sWorkDir)
{
m_sWorkDirectory = sWorkDir;
}
public:
std::wstring GetX2tSaveAddon(NSDoctRenderer::CDocBuilder* builder, const int& filetype)
{
return L"";
}
int GetX2tPreSaveError(NSDoctRenderer::CDocBuilder* builder, const int& filetype)
{
return 0;
}
};
}
#endif // DOC_BUILDER_ADDON_PRIVATE

View File

@ -33,6 +33,7 @@
#include "./../common_deploy.h"
#include "../docbuilder.h"
#include "../../common/File.h"
#include "../../common/SystemUtils.h"
#ifdef LINUX
#include "../../../DesktopEditor/common/File.h"
@ -78,6 +79,13 @@ void parse_args(NSDoctRenderer::CDocBuilder* builder, int argc, char *argv[])
}
}
bool CheckLicense(const std::wstring& sSrc, const std::wstring& sDst)
{
NSFile::CFileBinary::Remove(sDst);
NSFile::CFileBinary::Copy(sSrc, sDst);
return NSFile::CFileBinary::Exists(sDst);
}
#ifdef WIN32
int wmain(int argc, wchar_t *argv[])
#else
@ -89,6 +97,7 @@ int main(int argc, char *argv[])
bool bIsHelp = false;
bool bIsFonts = false;
bool bIsLicense = false;
for (int i = 0; i < argc; ++i)
{
#ifdef WIN32
@ -121,6 +130,33 @@ int main(int argc, char *argv[])
{
bIsFonts = true;
}
else if (sParam == "-register")
{
bIsLicense = true;
}
else
{
if (bIsLicense)
{
std::wstring sLicensePathSrc = UTF8_TO_U(sParam);
if (!NSFile::CFileBinary::Exists(sLicensePathSrc))
return 1;
std::wstring sLicensePath = NSSystemUtils::GetEnvVariable(L"ONLYOFFICE_BUILDER_LICENSE");
if (CheckLicense(sLicensePathSrc, sLicensePath))
return 0;
sLicensePath = NSFile::GetProcessDirectory() + L"/license.xml";
if (CheckLicense(sLicensePathSrc, sLicensePath))
return 0;
sLicensePath = NSSystemUtils::GetAppDataDir() + L"/docbuilder/license.xml";
if (CheckLicense(sLicensePathSrc, sLicensePath))
return 0;
return 1;
}
}
}
if (bIsFonts)

View File

@ -191,7 +191,7 @@ namespace NSDoctRenderer
m_strSdkPath = oNode.ReadNodeText(L"sdkjs");
if (!m_strSdkPath.empty())
{
if (!NSDirectory::Exists(m_strSdkPath))
if (0 == m_strSdkPath.find(L"./") || !NSDirectory::Exists(m_strSdkPath))
m_strSdkPath = sConfigDir + m_strSdkPath;
}

View File

@ -47,14 +47,6 @@ namespace NSDoctRenderer
RELEASEOBJECT(m_pInternal);
}
int CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
{
m_pInternal->m_nFileType = -1;
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
return m_pInternal->OpenFile(path, params);
}
int CDocBuilder::SaveFile(const int& type, const wchar_t* path, const wchar_t* params)
{
return m_pInternal->SaveFile(type, path, params);

View File

@ -475,6 +475,13 @@ namespace NSDoctRenderer
*/
void SetPropertyW(const wchar_t* param, const wchar_t* value);
/**
* GetProperty method.
* @param param The parameter name in the Unicode format, the value is always --argument.
* @return int value for property
*/
int GetPropertyInt(const wchar_t* param);
/**
* Writes data to the log file. It is used for logs in JS code.
* @param path The path to the file where all the logs will be written.
@ -526,6 +533,7 @@ namespace NSDoctRenderer
CDocBuilder_Private* m_pInternal;
friend class CBuilderDocumentEmbed;
friend class CBuilderEmbed;
};
/**

View File

@ -612,4 +612,10 @@ builder_path = os.path.dirname(os.path.realpath(__file__))
_loadLibrary(builder_path)
CDocBuilder.Initialize(builder_path)
def registerLibrary(license_path):
docbuilder_bin = os.path.dirname(os.path.realpath(__file__)) + os.pathsep + "docbuilder"
if ("windows" == platform.system().lower()):
docbuilder_bin += ".exe"
return subprocess.call([docbuilder_bin, license_path], stderr=subprocess.STDOUT, shell=True)
atexit.register(CDocBuilder.Dispose)

View File

@ -82,7 +82,7 @@ CV8RealTimeWorker::~CV8RealTimeWorker()
m_context->Dispose();
}
bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue)
bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue, const bool& isEnterContext)
{
LOGGER_SPEED_START();
@ -92,14 +92,20 @@ bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRender
std::string commandA = U_TO_UTF8(command);
//commandA = "Api." + commandA;
CJSContextScope scope(m_context);
if (isEnterContext)
m_context->Enter();
JSSmart<CJSTryCatch> try_catch = m_context->GetExceptions();
LOGGER_SPEED_LAP("compile_command");
JSSmart<CJSValue> retNativeVal = m_context->runScript(commandA, try_catch);
if(try_catch->Check())
{
if (isEnterContext)
m_context->Exit();
return false;
}
if (retValue)
{
@ -110,6 +116,9 @@ bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRender
LOGGER_SPEED_LAP("run_command");
if (isEnterContext)
m_context->Exit();
return true;
}
@ -240,6 +249,14 @@ bool CV8RealTimeWorker::InitVariables()
if (try_catch->Check())
return false;
}
if (!m_sJSCodeStart.empty())
{
m_context->runScript(m_sJSCodeStart, try_catch);
if (try_catch->Check())
return false;
}
return true;
}
@ -336,7 +353,17 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
return !bIsBreak;
}
bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams)
bool CV8RealTimeWorker::NewSimpleJSInstance()
{
return InitVariables();
}
bool CV8RealTimeWorker::IsSimpleJSInstance()
{
return (-1 == m_nFileType);
}
bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams, const bool& isEnterContext)
{
NSDoctRenderer::DoctRendererFormat::FormatFile _formatDst = NSDoctRenderer::DoctRendererFormat::DOCT;
if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
@ -362,7 +389,9 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
}
}
CJSContextScope scope(m_context);
if (isEnterContext)
m_context->Enter();
JSSmart<CJSTryCatch> try_catch = m_context->GetExceptions();
NSNativeControl::CNativeControl* pNative = NULL;
@ -391,7 +420,7 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
bIsSilentMode = true;
if (bIsSilentMode)
this->ExecuteCommand(L"Api.asc_SetSilentMode(false);");
this->ExecuteCommand(L"Api.asc_SetSilentMode(false);", NULL, isEnterContext);
std::wstring strError;
bool bIsError = Doct_renderer_SaveFile_ForBuilder(_formatDst,
@ -403,7 +432,10 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
sJsonParams);
if (bIsSilentMode)
this->ExecuteCommand(L"Api.asc_SetSilentMode(true);");
this->ExecuteCommand(L"Api.asc_SetSilentMode(true);", NULL, isEnterContext);
if (isEnterContext)
m_context->Exit();
return bIsError;
}
@ -1231,8 +1263,29 @@ namespace NSDoctRenderer
nCount = nIndex;
}
int CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
{
if (m_pInternal->m_nFileType != -1 && m_pInternal->m_bIsOpenedFromSimpleJS)
{
m_pInternal->m_bIsOpenedFromSimpleJS = false;
return true;
}
m_pInternal->m_nFileType = -1;
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
return m_pInternal->OpenFile(path, params);
}
bool CDocBuilder::CreateFile(const int& type)
{
if (m_pInternal->m_nFileType != -1 && m_pInternal->m_bIsOpenedFromSimpleJS)
{
m_pInternal->m_bIsOpenedFromSimpleJS = false;
return true;
}
m_pInternal->m_nFileType = -1;
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
@ -1391,7 +1444,7 @@ namespace NSDoctRenderer
if (!sJsCommands.empty())
{
std::wstring sUnicodeCommand = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length());
bIsNoError = this->ExecuteCommand(sUnicodeCommand.c_str());
bIsNoError = this->m_pInternal->ExecuteCommand(sUnicodeCommand.c_str(), NULL, bIsBuilderJSCloseFile);
sJsCommands = "";
if (!bIsNoError)
return false;
@ -1413,6 +1466,10 @@ namespace NSDoctRenderer
if (0 == _builder_params[nCheckParam].find(L"jsValue(") && _builder_params[nCheckParam].length() > 9)
{
std::wstring sParam = _builder_params[nCheckParam].substr(8, _builder_params[nCheckParam].length() - 9);
if (NULL == m_pInternal->m_pWorker)
m_pInternal->CheckWorker();
_builder_params[nCheckParam] = m_pInternal->m_pWorker->GetJSVariable(sParam);
}
}
@ -1478,7 +1535,7 @@ namespace NSDoctRenderer
{
// Такого быть не должно!!! Так как результат никуда не сохранится. пустое действие.
std::wstring sUnicodeCommand = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length());
bool bIsNoError = this->ExecuteCommand(sUnicodeCommand.c_str());
bool bIsNoError = this->m_pInternal->ExecuteCommand(sUnicodeCommand.c_str(), NULL, true);
sJsCommands = "";
if (!bIsNoError)
return false;
@ -1539,6 +1596,15 @@ namespace NSDoctRenderer
return this->SetProperty(sA.c_str(), value);
}
int CDocBuilder::GetPropertyInt(const wchar_t* param)
{
std::wstring sParam = std::wstring(param);
std::string sParamA = U_TO_UTF8(sParam);
if ("--save-use-only-names" == sParamA)
return m_pInternal->m_bIsServerSafeVersion ? 1 : 0;
return -1;
}
void CDocBuilder::Initialize(const wchar_t* directory)
{
std::wstring sDirectory = L"";

View File

@ -63,6 +63,8 @@
#include "../common/ProcessEnv.h"
#include "docbuilder_addon.h"
#ifdef CreateFile
#undef CreateFile
#endif
@ -422,6 +424,7 @@ public:
int m_nFileType;
std::string m_sUtf8ArgumentJSON;
std::string m_sGlobalVariable;
std::string m_sJSCodeStart;
CJSContextData m_oContextData;
@ -434,14 +437,17 @@ public:
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError);
bool ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue = NULL);
bool ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue = NULL, const bool& isEnterContext = true);
std::string GetGlobalVariable();
std::wstring GetJSVariable(std::wstring sParam);
bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const NSDoctRenderer::DoctRendererEditorType& editorType, NSDoctRenderer::CDoctRendererConfig* config, CV8Params* pParams = NULL);
bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L"");
bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L"", const bool& isEnterContext = true);
bool InitVariables();
bool NewSimpleJSInstance();
bool IsSimpleJSInstance();
};
namespace NSDoctRenderer
@ -455,7 +461,8 @@ namespace NSDoctRenderer
std::wstring m_sTmpFolder;
std::wstring m_sFileDir;
int m_nFileType;
bool m_bJavascriptBeforeEditor;
std::wstring m_sCommandsBeforeContextCreated;
std::wstring m_sX2tPath;
@ -474,11 +481,13 @@ namespace NSDoctRenderer
NSDoctRenderer::CDocBuilder* m_pParent;
bool m_bIsOpenedFromSimpleJS;
static std::wstring m_sExternalDirectory;
public:
CDocBuilder_Private() : CDoctRendererConfig(), m_sTmpFolder(NSFile::CFileBinary::GetTempPath()), m_nFileType(-1),
m_pWorker(NULL), m_pAdditionalData(NULL), m_bIsInit(false), m_bIsServerSafeVersion(false),
m_sGlobalVariable(""), m_bIsGlobalVariableUse(false), m_pParent(NULL), m_bJavascriptBeforeEditor(false)
m_sGlobalVariable(""), m_bIsGlobalVariableUse(false), m_pParent(NULL), m_sCommandsBeforeContextCreated(L""), m_bIsOpenedFromSimpleJS(false)
{
}
@ -637,10 +646,14 @@ namespace NSDoctRenderer
{
NSDirectory::CreateDirectory(m_sFileDir + L"/media");
NSDirectory::CreateDirectory(m_sFileDir + L"/changes");
}
if (m_bJavascriptBeforeEditor)
CheckWorkerAfterOpen();
if (m_pWorker && m_pWorker->IsSimpleJSInstance() && !m_bIsOpenedFromSimpleJS)
{
RELEASEOBJECT(m_pWorker);
CheckWorker();
}
return bRet;
}
return bRet;
#else
@ -931,8 +944,11 @@ namespace NSDoctRenderer
if (0 == nReturnCode)
{
if (m_bJavascriptBeforeEditor)
CheckWorkerAfterOpen();
if (m_pWorker && m_pWorker->IsSimpleJSInstance() && !m_bIsOpenedFromSimpleJS)
{
RELEASEOBJECT(m_pWorker);
CheckWorker();
}
return 0;
}
@ -981,10 +997,16 @@ namespace NSDoctRenderer
return _path;
}
int SaveFile(const int& type, const std::wstring& path, const wchar_t* params = NULL)
int SaveFile(const int& type, const std::wstring& path, const wchar_t* params = NULL, const bool& isEnterContext = true)
{
Init();
CDocBuilderAddon oSaveAddon(m_sX2tPath);
int nPreSaveError = oSaveAddon.GetX2tPreSaveError(m_pParent, m_nFileType);
if (0 != nPreSaveError)
return nPreSaveError;
if (-1 == m_nFileType)
{
CV8RealTimeWorker::_LOGGING_ERROR_(L"error (save)", L"file not opened!");
@ -1023,7 +1045,7 @@ namespace NSDoctRenderer
}
}
this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams);
this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams, isEnterContext);
sFileBin = L"/Editor2.bin";
}
@ -1068,6 +1090,8 @@ namespace NSDoctRenderer
if (!sOptions.empty())
oBuilder.WriteString(UTF8_TO_U(sOptions));
oBuilder.WriteString(oSaveAddon.GetX2tSaveAddon(m_pParent, m_nFileType));
oBuilder.WriteString(L"</TaskQueueDataConvert>");
std::wstring sXmlConvert = oBuilder.GetData();
@ -1220,62 +1244,75 @@ namespace NSDoctRenderer
{
if (NULL == m_pWorker)
{
m_pWorker = new CV8RealTimeWorker(m_pParent, GetEditorType(), this);
NSDoctRenderer::DoctRendererEditorType editorType = GetEditorType();
m_pWorker = new CV8RealTimeWorker(m_pParent, editorType, this);
m_pWorker->m_sUtf8ArgumentJSON = m_oParams.m_sArgumentJSON;
m_pWorker->m_sGlobalVariable = m_sGlobalVariable;
m_pWorker->m_sJSCodeStart = U_TO_UTF8(m_sCommandsBeforeContextCreated);
return CheckWorkerAfterOpen();
m_pWorker->m_nFileType = m_nFileType;
if (-1 != m_nFileType)
m_sCommandsBeforeContextCreated = L"";
else
{
m_pWorker->NewSimpleJSInstance();
return true;
}
CV8Params oParams;
oParams.IsServerSaveVersion = m_bIsServerSafeVersion;
oParams.DocumentDirectory = m_sFileDir;
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, editorType, this, &oParams);
}
return true;
}
bool CheckWorkerAfterOpen()
{
if (!m_pWorker)
return false;
m_pWorker->m_nFileType = m_nFileType;
if (-1 == m_nFileType)
{
m_bJavascriptBeforeEditor = true;
return false;
}
m_bJavascriptBeforeEditor = false;
CV8Params oParams;
oParams.IsServerSaveVersion = m_bIsServerSafeVersion;
oParams.DocumentDirectory = m_sFileDir;
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetEditorType(), this, &oParams);
}
int SaveFile(const std::wstring& ext, const std::wstring& path, const wchar_t* params = NULL)
{
int nType = GetFormatByTexExtention(ext);
return SaveFile(nType, path, params);
}
bool ExecuteCommand(const std::wstring& command, CDocBuilderValue* retValue = NULL)
bool ExecuteCommand(const std::wstring& command, CDocBuilderValue* retValue = NULL, const bool& forceExecute = false)
{
if (command.length() < 7 && !retValue) // minimum command (!!!)
return true;
if (m_nFileType == -1 && !forceExecute)
{
m_sCommandsBeforeContextCreated += command;
return true;
}
Init();
bool bRes = CheckWorker();
if (CheckWorker())
{
bool bIsOpenedFromSimpleJSOld = m_bIsOpenedFromSimpleJS;
bool bResult = m_pWorker->ExecuteCommand(command, retValue);
if (!bResult && !bIsOpenedFromSimpleJSOld && m_bIsOpenedFromSimpleJS)
{
RELEASEOBJECT(m_pWorker);
CheckWorker();
return m_pWorker->ExecuteCommand(command, retValue);
}
else
{
return bResult;
}
}
if (!bRes && m_pWorker && m_bJavascriptBeforeEditor)
m_pWorker->InitVariables();
return m_pWorker->ExecuteCommand(command, retValue);
return false;
}
CDocBuilderContext GetContext(bool enterContext)
{
CDocBuilderContext ctx;
CheckWorker();
if (!CheckWorker())
return ctx;
ctx.m_internal->m_context = m_pWorker->m_context;
ctx.m_internal->m_context_data = &m_pWorker->m_oContextData;

View File

@ -0,0 +1,130 @@
QT -= core
QT -= gui
VERSION = 1.0.0.3
TARGET = doctrenderer
TEMPLATE = lib
CONFIG += shared
CONFIG += plugin
CORE_ROOT_DIR = $$PWD/../..
PWD_ROOT_DIR = $$PWD
PWD_CUR = $$PWD
include($$PWD_CUR/../../Common/base.pri)
DEFINES += DOCTRENDERER_USE_DYNAMIC_LIBRARY_BUILDING
DEFINES += JSBASE_USE_DYNAMIC_LIBRARY_BUILDING
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
#CONFIG += build_xp
#CONFIG += v8_version_60
core_android:DEFINES += DISABLE_MEMORY_LIMITATION
HEADERS += \
$$PWD_CUR/config.h \
$$PWD_CUR/editors.h \
$$PWD_CUR/doctrenderer.h \
$$PWD_CUR/docbuilder.h
SOURCES += \
$$PWD_CUR/editors.cpp \
$$PWD_CUR/nativecontrol.cpp \
$$PWD_CUR/doctrenderer.cpp \
$$PWD_CUR/docbuilder.cpp \
$$PWD_CUR/docbuilder_p.cpp \
$$PWD_CUR/graphics.cpp \
$$PWD_CUR/hash.cpp
SOURCES += \
$$PWD_CUR/../../Common/OfficeFileFormatChecker2.cpp \
$$PWD_CUR/../../Common/3dParty/pole/pole.cpp \
$$PWD_CUR/../../OOXML/Base/unicode_util.cpp
HEADERS += \
$$PWD_CUR/docbuilder_p.h \
$$PWD_CUR/nativecontrol.h \
$$PWD_CUR/graphics.h \
$$PWD_CUR/hash.h \
$$PWD_CUR/server.h
HEADERS += \
$$PWD_CUR/embed/PointerEmbed.h \
$$PWD_CUR/embed/ZipEmbed.h \
$$PWD_CUR/embed/GraphicsEmbed.h \
$$PWD_CUR/embed/MemoryStreamEmbed.h \
$$PWD_CUR/embed/NativeControlEmbed.h \
$$PWD_CUR/embed/NativeBuilderEmbed.h \
$$PWD_CUR/embed/NativeBuilderDocumentEmbed.h \
$$PWD_CUR/embed/TextMeasurerEmbed.h \
$$PWD_CUR/embed/HashEmbed.h \
$$PWD_CUR/embed/Default.h \
$$PWD_CUR/js_internal/js_base.h
SOURCES += \
$$PWD_CUR/embed/PointerEmbed.cpp \
$$PWD_CUR/embed/ZipEmbed.cpp \
$$PWD_CUR/embed/GraphicsEmbed.cpp \
$$PWD_CUR/embed/MemoryStreamEmbed.cpp \
$$PWD_CUR/embed/NativeControlEmbed.cpp \
$$PWD_CUR/embed/NativeBuilderEmbed.cpp \
$$PWD_CUR/embed/NativeBuilderDocumentEmbed.cpp \
$$PWD_CUR/embed/TextMeasurerEmbed.cpp \
$$PWD_CUR/embed/HashEmbed.cpp \
$$PWD_CUR/embed/Default.cpp
# Serialize objects to JS
HEADERS += \
$$PWD_CUR/json/json.h \
$$PWD_CUR/json/json_p.h \
$$PWD_CUR/json/json_values.h \
$$PWD_CUR/json/serialization.h
SOURCES += \
$$PWD_CUR/json/json.cpp \
$$PWD_CUR/json/json_values.cpp
include($$PWD_CUR/js_internal/js_base.pri)
!use_javascript_core {
build_xp:DESTDIR=$$DESTDIR/xp
}
use_javascript_core {
OBJECTIVE_SOURCES += $$PWD_CUR/../common/Mac/NSString+StringUtils.mm
}
# files for embedded classes
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/GraphicsEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/HashEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/MemoryStreamEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeBuilderEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeBuilderDocumentEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeControlEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/PointerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/TextMeasurerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/ZipEmbed.h)
include($$PWD_CUR/../graphics/pro/textshaper.pri)
include($$PWD_CUR/../../Common/3dParty/openssl/openssl.pri)
# downloader
DEFINES += BUIDLER_OPEN_DOWNLOAD_ENABLED
DEFINES += BUIDLER_OPEN_BASE64_ENABLED
CONFIG += drawingfile_support
drawingfile_support {
DEFINES += WASM_SERIALIZER_USE_ALLOCATOR
ADD_DEPENDENCY(PdfFile, XpsFile, DjVuFile, DocxRenderer)
HEADERS += \
$$PWD_CUR/drawingfile.h \
$$PWD_CUR/embed/DrawingFileEmbed.h
SOURCES += \
$$PWD_CUR/../graphics/pro/js/wasm/src/HTMLRendererText.cpp \
$$PWD_CUR/embed/DrawingFileEmbed.cpp
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/DrawingFileEmbed.h)
}

View File

@ -1,128 +1,3 @@
QT -= core
QT -= gui
INCLUDEPATH += $$PWD/addon
VERSION = 1.0.0.3
TARGET = doctrenderer
TEMPLATE = lib
CONFIG += shared
CONFIG += plugin
CORE_ROOT_DIR = $$PWD/../..
PWD_ROOT_DIR = $$PWD
include(../../Common/base.pri)
DEFINES += DOCTRENDERER_USE_DYNAMIC_LIBRARY_BUILDING
DEFINES += JSBASE_USE_DYNAMIC_LIBRARY_BUILDING
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
#CONFIG += build_xp
#CONFIG += v8_version_60
core_android:DEFINES += DISABLE_MEMORY_LIMITATION
HEADERS += \
config.h \
editors.h \
doctrenderer.h \
docbuilder.h
SOURCES += \
editors.cpp \
nativecontrol.cpp \
doctrenderer.cpp \
docbuilder.cpp \
docbuilder_p.cpp \
graphics.cpp \
hash.cpp
SOURCES += \
../../Common/OfficeFileFormatChecker2.cpp \
../../Common/3dParty/pole/pole.cpp \
../../OOXML/Base/unicode_util.cpp
HEADERS += \
docbuilder_p.h \
nativecontrol.h \
graphics.h \
hash.h \
server.h
HEADERS += \
embed/PointerEmbed.h \
embed/ZipEmbed.h \
embed/GraphicsEmbed.h \
embed/MemoryStreamEmbed.h \
embed/NativeControlEmbed.h \
embed/NativeBuilderEmbed.h \
embed/NativeBuilderDocumentEmbed.h \
embed/TextMeasurerEmbed.h \
embed/HashEmbed.h \
embed/Default.h \
js_internal/js_base.h
SOURCES += \
embed/PointerEmbed.cpp \
embed/ZipEmbed.cpp \
embed/GraphicsEmbed.cpp \
embed/MemoryStreamEmbed.cpp \
embed/NativeControlEmbed.cpp \
embed/NativeBuilderEmbed.cpp \
embed/NativeBuilderDocumentEmbed.cpp \
embed/TextMeasurerEmbed.cpp \
embed/HashEmbed.cpp \
embed/Default.cpp
# Serialize objects to JS
HEADERS += \
json/json.h \
json/json_p.h \
json/json_values.h \
json/serialization.h
SOURCES += \
json/json.cpp \
json/json_values.cpp
include($$PWD/js_internal/js_base.pri)
!use_javascript_core {
build_xp:DESTDIR=$$DESTDIR/xp
}
use_javascript_core {
OBJECTIVE_SOURCES += ../common/Mac/NSString+StringUtils.mm
}
# files for embedded classes
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/GraphicsEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/HashEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/MemoryStreamEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeBuilderEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeBuilderDocumentEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeControlEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/PointerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/TextMeasurerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/ZipEmbed.h)
include(../graphics/pro/textshaper.pri)
include(../../Common/3dParty/openssl/openssl.pri)
# downloader
DEFINES += BUIDLER_OPEN_DOWNLOAD_ENABLED
DEFINES += BUIDLER_OPEN_BASE64_ENABLED
CONFIG += drawingfile_support
drawingfile_support {
DEFINES += WASM_SERIALIZER_USE_ALLOCATOR
ADD_DEPENDENCY(PdfFile, XpsFile, DjVuFile, DocxRenderer)
HEADERS += \
drawingfile.h \
embed/DrawingFileEmbed.h
SOURCES += \
../graphics/pro/js/wasm/src/HTMLRendererText.cpp \
embed/DrawingFileEmbed.cpp
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/DrawingFileEmbed.h)
}
include(doctrenderer.pri)

View File

@ -6,16 +6,16 @@ namespace NSDoctRenderer
{
namespace
{
void AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path)
bool AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path, const std::string& header = "", const std::string& footer = "")
{
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(path))
return;
return false;
int size = (int)oFile.GetFileSize();
if (size < 3)
return;
return false;
BYTE* pData = new BYTE[size];
DWORD dwReadSize = 0;
@ -26,9 +26,18 @@ namespace NSDoctRenderer
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
nOffset = 3;
if (!header.empty())
builder->WriteString(header);
builder->WriteString((char*)(pData + nOffset), size - nOffset);
if (!footer.empty())
builder->WriteString(footer);
builder->WriteString("\n\n");
RELEASEARRAYOBJECTS(pData);
return true;
}
bool RunScript(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, const std::wstring& path)
@ -114,6 +123,7 @@ namespace NSDoctRenderer
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/engine/drawingfile_native.js");
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/annotations/stamps.json", "window[\"native_pdf_stamps\"]=", ";");
sCachePath = config->m_strSdkPath + L"/pdf/sdk-all";
break;
}

View File

@ -1,5 +1,6 @@
#include "DrawingFileEmbed.h"
#include "../drawingfile.h"
#include "../../raster/BgraFrame.h"
JSSmart<CJSValue> WasmMemoryToJS(BYTE* pWasmData)
{

View File

@ -160,16 +160,30 @@ void CGraphicsEmbed::SetAppImage(CGraphicsAppImage* appImage)
JSSmart<CJSValue> CGraphicsEmbed::create(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm)
{
NSNativeControl::CNativeControl* pControl = NULL;
if (!Native->isNull())
{
pControl = (NSNativeControl::CNativeControl*)Native->toObject()->getNative()->getObject();
JSSmart<CJSObject> pNativeObject = Native->toObject();
CJSEmbedObject* pNativeEmbedObject = pNativeObject->getNative();
if (m_pInternal->m_pAppImage)
delete m_pInternal->m_pAppImage;
m_pInternal->m_pAppImage = new CGraphicsAppImage();
m_pInternal->m_pAppImage->SetFontsDirectory(pControl->m_strFontsDirectory);
m_pInternal->m_pAppImage->SetImagesDirectory(pControl->m_strImagesDirectory);
if (pNativeEmbedObject)
{
NSNativeControl::CNativeControl* pControl = (NSNativeControl::CNativeControl*)pNativeEmbedObject->getObject();
m_pInternal->m_pAppImage->SetFontsDirectory(pControl->m_strFontsDirectory);
m_pInternal->m_pAppImage->SetImagesDirectory(pControl->m_strImagesDirectory);
}
else
{
JSSmart<CJSValue> checkResources = pNativeObject->get("isResourcesObject");
if (checkResources->isBool() && true == checkResources->toBool())
{
m_pInternal->m_pAppImage->SetFontsDirectory(pNativeObject->get("fontsDirectory")->toStringW());
m_pInternal->m_pAppImage->SetImagesDirectory(pNativeObject->get("imagesDirectory")->toStringW());
}
}
}
m_pInternal->init(width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble());

View File

@ -8,7 +8,22 @@ JSSmart<CJSValue> CBuilderEmbed::OpenFile(JSSmart<CJSValue> sPath, JSSmart<CJSVa
{
std::wstring Path = sPath->toStringW();
std::wstring Params = sParams->toStringW();
// Since we now use snapshots, and we can't always determine which editor is needed
// (since the code may be BEFORE opening the file). And if the opening came from
// builderJS.OpenFile - in this case we skip reopening.
NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate();
if (pPrivate->m_pWorker->IsSimpleJSInstance())
pPrivate->m_bIsOpenedFromSimpleJS = true;
int ret = m_pBuilder->OpenFile(Path.c_str(), Params.c_str());
if (pPrivate->m_pWorker->IsSimpleJSInstance())
{
JSSmart<CJSContext> current = CJSContext::GetCurrent();
current->runScript("throw 0;");
}
return CJSContext::createInt(ret);
}
@ -20,7 +35,21 @@ JSSmart<CJSValue> CBuilderEmbed::CreateFile(JSSmart<CJSValue> type)
else
nFormat = type->toInt32();
// Since we now use snapshots, and we can't always determine which editor is needed
// (since the code may be BEFORE opening the file). And if the opening came from
// builderJS.OpenFile - in this case we skip reopening.
NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate();
if (pPrivate->m_pWorker->IsSimpleJSInstance())
pPrivate->m_bIsOpenedFromSimpleJS = true;
bool ret = m_pBuilder->CreateFile(nFormat);
if (pPrivate->m_pWorker->IsSimpleJSInstance())
{
JSSmart<CJSContext> current = CJSContext::GetCurrent();
current->runScript("throw 0;");
}
return CJSContext::createBool(ret);
}
@ -41,7 +70,7 @@ JSSmart<CJSValue> CBuilderEmbed::SaveFile(JSSmart<CJSValue> type, JSSmart<CJSVal
std::wstring sPath = path->toStringW();
std::wstring sParams = params->toStringW();
int ret = m_pBuilder->SaveFile(nFormat, sPath.c_str(), sParams.empty() ? NULL : sParams.c_str());
int ret = GetPrivate()->SaveFile(nFormat, sPath.c_str(), sParams.empty() ? NULL : sParams.c_str(), false);
return CJSContext::createInt(ret);
}

View File

@ -50,6 +50,7 @@ public:
~CBuilderEmbed() { if(m_pBuilder) RELEASEOBJECT(m_pBuilder); }
virtual void* getObject() { return (void*)m_pBuilder; }
NSDoctRenderer::CDocBuilder_Private* GetPrivate() { return m_pBuilder->GetPrivate(); }
public:
JSSmart<CJSValue> OpenFile(JSSmart<CJSValue> sPath, JSSmart<CJSValue> sParams);

View File

@ -258,3 +258,64 @@ JSSmart<CJSValue> CZipEmbed::getImageType(JSSmart<CJSValue> typedArray)
oBuffer.Free();
return CJSContext::createInt(bIsImageFile ? oChecker.eFileType : 0);
}
JSSmart<CJSValue> CZipEmbed::getImageBuffer(JSSmart<CJSValue> filePath)
{
if (!m_pFolder || !filePath->isString())
return CJSContext::createNull();
std::wstring sFilePath = filePath->toStringW();
IFolder::CBuffer* pBuffer;
if (!m_pFolder->read(sFilePath, pBuffer))
return CJSContext::createNull();
size_t nBufferSize = (size_t)pBuffer->Size;
CImageFileFormatChecker oChecker;
bool bIsImageFile = oChecker.isImageFile(pBuffer->Buffer, (DWORD)pBuffer->Size);
if (!bIsImageFile)
{
RELEASEOBJECT(pBuffer);
return CJSContext::createNull();
}
bool bIsNeedConvertMetfileToSvg = false;
// Make as wasm module
if (oChecker.eFileType == _CXIMAGE_FORMAT_WMF || oChecker.eFileType == _CXIMAGE_FORMAT_EMF)
oChecker.eFileType = _CXIMAGE_FORMAT_SVG;
else
bIsNeedConvertMetfileToSvg = false;
if (!bIsNeedConvertMetfileToSvg)
{
BYTE* pMemory = NSJSBase::NSAllocator::Alloc(nBufferSize);
memcpy(pMemory, pBuffer->Buffer, nBufferSize);
RELEASEOBJECT(pBuffer);
JSSmart<CJSObject> retObject = CJSContext::createObject();
retObject->set("type", CJSContext::createInt(oChecker.eFileType));
retObject->set("data", NSJSBase::CJSContext::createUint8Array(pMemory, (int)nBufferSize, false));
return retObject->toValue();
}
#ifndef GRAPHICS_DISABLE_METAFILE
MetaFile::IMetaFile* pMetaFile = MetaFile::Create(NULL);
pMetaFile->LoadFromBuffer(pBuffer->Buffer, (unsigned int)pBuffer->Size);
std::wstring wsSvg = pMetaFile->ConvertToSvg();
std::string sSvg = U_TO_UTF8(wsSvg);
pMetaFile->Release();
RELEASEOBJECT(pBuffer);
BYTE* pData = NSAllocator::Alloc(sSvg.length());
memcpy(pData, sSvg.c_str(), sSvg.length());
JSSmart<CJSObject> retObject = CJSContext::createObject();
retObject->set("type", CJSContext::createInt(24));
retObject->set("data", NSJSBase::CJSContext::createUint8Array(pData, sSvg.length(), false));
return retObject->toValue();
#else
return CJSContext::createNull();
#endif
}

View File

@ -36,6 +36,7 @@ public:
JSSmart<CJSValue> encodeImageData(JSSmart<CJSValue> typedArray, JSSmart<CJSValue> w, JSSmart<CJSValue> h, JSSmart<CJSValue> stride, JSSmart<CJSValue> format, JSSmart<CJSValue> isRgba);
JSSmart<CJSValue> encodeImage(JSSmart<CJSValue> typedArray, JSSmart<CJSValue> format);
JSSmart<CJSValue> getImageType(JSSmart<CJSValue> typedArray);
JSSmart<CJSValue> getImageBuffer(JSSmart<CJSValue> path);
DECLARE_EMBED_METHODS
};

View File

@ -17,6 +17,7 @@
-(JSValue*) encodeImageData : (JSValue*)typedArray : (JSValue*)w : (JSValue*)h : (JSValue*)stride : (JSValue*)format : (JSValue*)isRgba;
-(JSValue*) encodeImage : (JSValue*)typedArray : (JSValue*)format;
-(JSValue*) getImageType : (JSValue*)typedArray;
-(JSValue*) getImageBuffer : (JSValue*)path;
@end
@interface CJSCZipEmbed : NSObject<IJSCZipEmbed, JSEmbedObjectProtocol>
@ -41,6 +42,7 @@ FUNCTION_WRAPPER_JS_2(decodeImage, decodeImage)
FUNCTION_WRAPPER_JS_6(encodeImageData, encodeImageData)
FUNCTION_WRAPPER_JS_2(encodeImage, encodeImage)
FUNCTION_WRAPPER_JS_1(getImageType, getImageType)
FUNCTION_WRAPPER_JS_1(getImageBuffer, getImageBuffer)
@end
class CZipEmbedAdapter : public CJSEmbedObjectAdapterJSC

View File

@ -20,6 +20,7 @@ namespace NSZipEmbed
FUNCTION_WRAPPER_V8_6(_encodeImageData, encodeImageData)
FUNCTION_WRAPPER_V8_2(_encodeImage, encodeImage)
FUNCTION_WRAPPER_V8_1(_getImageType, getImageType)
FUNCTION_WRAPPER_V8_1(_getImageBuffer, getImageBuffer)
v8::Handle<v8::ObjectTemplate> CreateTemplate(v8::Isolate* isolate)
{
@ -39,6 +40,7 @@ namespace NSZipEmbed
NSV8Objects::Template_Set(result, "encodeImageData", _encodeImageData);
NSV8Objects::Template_Set(result, "encodeImage", _encodeImage);
NSV8Objects::Template_Set(result, "getImageType", _getImageType);
NSV8Objects::Template_Set(result, "getImageBuffer", _getImageBuffer);
return handle_scope.Escape(result);
}

View File

@ -374,7 +374,7 @@ namespace NSJSBase
JSSmart<CJSContext> CJSContext::GetCurrent()
{
CJSContext* ret = new CJSContext();
CJSContext* ret = new CJSContext(false);
ret->m_internal->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
return ret;
}

View File

@ -356,6 +356,8 @@ public:
virtual void Check(const int& nCode, const unsigned int& nIndex)
{
if (nCode > m_nMaxSymbols)
return;
if (nCode > m_nMax)
m_nMax = nCode;
if (nCode < m_nMin)
@ -794,6 +796,8 @@ public:
std::wstring sNameCorrect = pPair->second.m_sName;
NSStringUtils::string_replace(sNameCorrect, L"\\", L"\\\\");
NSStringUtils::string_replace(sNameCorrect, L"\"", L"\\\"");
NSStringUtils::string_replace(sNameCorrect, L"\n", L"");
NSStringUtils::string_replace(sNameCorrect, L"\r", L"");
oWriterJS += sNameCorrect;
oWriterJS.AddSize(120);

View File

@ -693,6 +693,13 @@ namespace NSShaper
g_userfeatures_init = true;
}
// Turn on ligatures on arabic script
if (nScript == HB_SCRIPT_ARABIC ||
nScript == HB_SCRIPT_SYRIAC)
{
nFeatures |= 1;
}
// font
hb_font_t* pFont;
if (NULL == font)

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
@ -594,6 +594,13 @@ WASM_EXPORT unsigned char* ASC_HB_ShapeText(FT_Face pFace, hb_font_t* pFont, cha
g_userfeatures_init = true;
}
// Turn on ligatures on arabic script
if (nScript == HB_SCRIPT_ARABIC ||
nScript == HB_SCRIPT_SYRIAC)
{
nFeatures |= 1;
}
// font
if (NULL == pFont)
{

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
@ -531,6 +531,45 @@ ZLib.prototype.getImageAsSvg = function(path)
return string;
};
/**
* Get image file raw data. this memory was copied and detach from archive.
* @returns {Uint8Array}
*/
ZLib.prototype.getImageBuffer = function(path)
{
let result = {
type : 0,
data : null
};
result.type = this.getImageType(path);
if (result.type === 0)
return null;
let fileData = this.getFile(path);
result.data = new Uint8Array(fileData.length);
result.data.set(fileData);
if (result.type != 10 &&
result.type != 21)
{
return result;
}
result.type = 24;
// Source was saved as result.data for using original image in native convertations.
// But for js we need svg for metafiles.
let encodedData = Module["_Raster_Encode"](this.files[path].p + 4, fileData.length, 24);
let encodedSize = Module["_Raster_GetEncodedSize"](encodedData);
let encodedBuffer = Module["_Raster_GetEncodedBuffer"](encodedData);
let fileDataEnc = new Uint8Array(Module["HEAP8"].buffer, encodedBuffer, encodedSize);
result.dataBlob = new Uint8Array(fileDataEnc.length);
result.dataBlob.set(fileDataEnc);
Module["_Raster_DestroyEncodedData"](encodedData);
return result;
};
/**
* Get image blob for browser
* @returns {Blob}

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
@ -35,7 +35,7 @@
window['AscFonts'] = window['AscFonts'] || {};
var AscFonts = window['AscFonts'];
var g_native_engine = CreateEmbedObject("CTextMeasurerEmbed");
var g_native_engine = null;
function CReturnObject()
{
@ -236,4 +236,6 @@ AscFonts.Hyphen_Word = function(lang, word)
AscFonts.onLoadModule();
AscFonts.onLoadModule();
window["InitNativeTextMeasurer"] = function() { g_native_engine = CreateEmbedObject("CTextMeasurerEmbed"); };
})(window, undefined);

View File

@ -100,6 +100,7 @@
"FT_CONFIG_OPTION_SYSTEM_ZLIB",
"GRAPHICS_NO_USE_DYNAMIC_LIBRARY",
"HYPHEN_ENGINE_DISABLE_FILESYSTEM",
"METAFILE_DISABLE_FILESYSTEM",
"HAVE_UNISTD_H", "HAVE_FCNTL_H", "_ARM_ALIGN_",
"METAFILE_SUPPORT_WMF_EMF",
@ -259,10 +260,13 @@
"folder": "../../../OfficeUtils/js",
"files": ["../src/ZipBuffer.cpp", "wasm/src/base.cpp", "../src/zlib_addon.c"]
},
{
"folder": "../../",
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp"]
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp"]
},
{
"folder": "../../agg-2.4/src/",
"files": ["agg_trans_affine.cpp"]
},
{
"folder": "../../raster/",

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
@ -761,6 +761,14 @@ function onLoadFontsModule(window, undefined)
{
return this.engine["getImageBlob"](path);
};
/**
* Get image file raw data. this memory was copied and detach from archive.
* @returns {Uint8Array}
*/
ZLib.prototype.getImageBuffer = function(path)
{
return this.engine["getImageBuffer"](path);
};
/**
* Get all file paths in archive
* @returns {Array}
@ -772,10 +780,84 @@ function onLoadFontsModule(window, undefined)
AscCommon.ZLib = ZLib;
function ZlibImageBlobs()
{
this.url2BlobUrl = {};
this.blobUrl2Data = {};
this.url2Base64 = {};
this.nativeBlobCounter = 1;
}
ZlibImageBlobs.prototype.getBlobUrl = function(path, zip)
{
if (this.url2BlobUrl[path])
return this.url2BlobUrl[path];
let result = zip.getImageBuffer(path);
if (result == null)
return "";
let blobUrl = "";
let blobType = AscCommon.openXml.GetMimeType((24 !== result["type"]) ? AscCommon.GetFileExtension(path) : "svg");
if (window["NATIVE_EDITOR_ENJINE"])
{
blobUrl = "blob:internal-image" + this.nativeBlobCounter++;
}
else
{
try
{
let blob = new Blob([result["dataBlob"] ? result["dataBlob"] : result["data"]], {type: blobType});
blobUrl = window.URL.createObjectURL(blob);
}
catch (e)
{
blobUrl = "error";
AscCommon.consoleLog("ERROR: Image blob was not loaded");
}
}
this.blobUrl2Data[blobUrl] = result;
this.url2BlobUrl[path] = blobUrl;
return blobUrl;
};
ZlibImageBlobs.prototype.getImageBase64 = function(url)
{
if (this.url2Base64[url])
return this.url2Base64[url];
let obj = this.blobUrl2Data[url];
if (!obj)
return url;
let header = "";
switch (obj.type)
{
case 3:
header = "data:image/jpeg;base64,";
break;
case 24:
header = "data:image/svg+xml;base64,";
break;
case 4:
default:
header = "data:image/png;base64,";
}
this.url2Base64[url] = header + AscCommon.Base64.encode(obj.data);
return this.url2Base64[url];
};
window["AscCommon"].g_oDocumentBlobUrls = new ZlibImageBlobs();
if (AscCommon["CZLibEngineJS"])
AscCommon["CZLibEngineJS"].prototype["isModuleInit"] = true;
window.nativeZlibEngine = new ZLib();
if (window["NATIVE_EDITOR_ENJINE"])
window["InitNativeZLib"] = function() { window.nativeZlibEngine = new ZLib(); };
else
window.nativeZlibEngine = new ZLib();
function Hyphenation()
{

View File

@ -153,13 +153,6 @@ IMetafileToRenderter::IMetafileToRenderter(IRenderer* pRenderer)
}
IMetafileToRenderter::~IMetafileToRenderter()
{
for (std::vector<std::wstring>::iterator i = m_arTempFiles.begin(); i != m_arTempFiles.end(); i++)
{
std::wstring sPath = *i;
if (NSFile::CFileBinary::Exists(sPath))
NSFile::CFileBinary::Remove(sPath);
}
if (m_pPicker)
{
CMetafileFontPicker* pPicker = (CMetafileFontPicker*)m_pPicker;
@ -234,8 +227,6 @@ std::wstring IMetafileToRenderter::GetImagePath(const std::wstring& sPath)
oFrame.put_Data(NULL);
sImagePath = sTempFile;
}
m_arTempFiles.push_back(sTempFile);
}
RELEASEARRAYOBJECTS(pImageBuffer);

View File

@ -49,7 +49,6 @@ public:
protected:
std::wstring m_sTempDir;
std::vector<std::wstring> m_arTempFiles;
std::wstring m_sThemesDir;
std::wstring m_sMediaDir;

View File

@ -223,7 +223,7 @@
},
{
"folder": "../../../../DocxRenderer/src/logic/elements",
"files": ["BaseItem.cpp", "ContText.cpp", "Paragraph.cpp", "Shape.cpp", "TextLine.cpp"]
"files": ["BaseItem.cpp", "ContText.cpp", "Paragraph.cpp", "Shape.cpp", "TextLine.cpp", "Table.cpp"]
},
{
"folder": "../../../common",

View File

@ -682,6 +682,7 @@ HEADERS += \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/DropCap.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Paragraph.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Shape.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Table.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/TextLine.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/ExternalImageStorage.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontStyleManager.h \
@ -706,6 +707,7 @@ SOURCES += \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/ContText.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Paragraph.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Shape.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Table.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/TextLine.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontManager.cpp \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontStyleManager.cpp \

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)

View File

@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)

View File

@ -100,8 +100,6 @@ namespace MetaFile
m_bStartedPath = false;
m_bUpdatedClip = true;
m_pRenderer->CommandLong(c_nPenWidth0As1px, 1);
//int alpha = 0xff;
//m_pRenderer->put_BrushAlpha1(alpha);
//m_pRenderer->put_BrushType(c_BrushTypeSolid);
@ -1218,7 +1216,41 @@ namespace MetaFile
else if (PS_JOIN_MITER == ulPenJoin)
nJoinStyle = Aggplus::LineJoinMiter;
const double dWidth = pPen->GetWidth() * m_dScaleX;
double dWidth = pPen->GetWidth();
// Повторение кода из Graphics для вычисления минимальной ширины пера
double dM11, dM12, dM21, dM22, dDx, dDy;
m_pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy);
Aggplus::CMatrix oMatrix;
oMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy);
oMatrix.Scale(1. / m_dScaleX, 1. / m_dScaleY);
// Вычисление минимально возможной ширины пера
// # Код явялется дублированным из Graphics
const double dSqrtDet = sqrt(abs(oMatrix.Determinant()));
const double dWidthMinSize = (dSqrtDet != 0) ? (1.0 / dSqrtDet) : dWidth;
if (0 == pPen->GetWidth())
{
double dX = 0.72, dY = 0.72;
oMatrix.Invert();
oMatrix.TransformPoint(dX, dY);
dX -= oMatrix.OffsetX();
dY -= oMatrix.OffsetY();
dWidth = std::min(abs(dX), abs(dY));
}
//------------------------
else
{
dWidth *= m_dScaleX;
if (dWidth < dWidthMinSize)
dWidth = dWidthMinSize;
}
const double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX;
BYTE nDashStyle = Aggplus::DashStyleSolid;
@ -1228,79 +1260,83 @@ namespace MetaFile
pPen->GetDashData(pDataDash, unSizeDash);
if (NULL != pDataDash && 0 != unSizeDash)
if ((NULL != pDataDash && 0 != unSizeDash) || PS_SOLID != ulPenStyle)
{
m_pRenderer->put_PenDashOffset(pPen->GetDashOffset());
// Дублированный код из Graphics
// Без этого используется оригинальный код в Graphics, который отрисовывает уже неверно
double dDashWidth{dWidth};
double dM11, dTemp;
m_pRenderer->GetTransform(&dM11, &dTemp, &dTemp, &dTemp, &dTemp, &dTemp);
double dDpi;
m_pRenderer->get_DpiX(&dDpi);
const double dNewWidth{dWidth * dM11 * dDpi / 25.4};
std::vector<double> arDashes(unSizeDash);
for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex)
arDashes[unIndex] = pDataDash[unIndex] * dNewWidth;
m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash);
nDashStyle = Aggplus::DashStyleCustom;
}
else if (PS_SOLID != ulPenStyle)
{
std::vector<double> arDashPattern;
double dM11, dTemp;
m_pRenderer->GetTransform(&dM11, &dTemp, &dTemp, &dTemp, &dTemp, &dTemp);
double dDpi;
m_pRenderer->get_DpiX(&dDpi);
const double dNewWidth{dWidth * dM11 * dDpi / 25.4};
switch (ulPenStyle)
if (!Equals(dWidthMinSize, dWidth))
{
case PS_DASH:
{
arDashPattern.push_back(9 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
double dDet = oMatrix.Determinant();
break;
}
case PS_DOT:
{
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
break;
}
case PS_DASHDOT:
{
arDashPattern.push_back(9 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
break;
}
case PS_DASHDOTDOT:
{
arDashPattern.push_back(9 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
arDashPattern.push_back(3 * dNewWidth);
break;
}
if (fabs(dDet) < 0.0001)
dDashWidth *= dSqrtDet;
}
// -----------------------------
if (!arDashPattern.empty())
if (NULL != pDataDash && 0 != unSizeDash)
{
m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size());
m_pRenderer->put_PenDashOffset(pPen->GetDashOffset());
std::vector<double> arDashes(unSizeDash);
for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex)
arDashes[unIndex] = pDataDash[unIndex] * dDashWidth;
m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash);
nDashStyle = Aggplus::DashStyleCustom;
nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat;
nJoinStyle = Aggplus::LineJoinMiter;
}
else
{
std::vector<double> arDashPattern;
switch (ulPenStyle)
{
case PS_DASH:
{
arDashPattern.push_back(9 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
break;
}
case PS_DOT:
{
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
break;
}
case PS_DASHDOT:
{
arDashPattern.push_back(9 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
break;
}
case PS_DASHDOTDOT:
{
arDashPattern.push_back(9 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
break;
}
}
if (!arDashPattern.empty())
{
m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size());
nDashStyle = Aggplus::DashStyleCustom;
nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat;
nJoinStyle = Aggplus::LineJoinMiter;
}
}
}

View File

@ -44,7 +44,8 @@ namespace MetaFile
: r(_r), g(_g), b(_b), a(_a)
{}
TRGBA::TRGBA(int nValue) : r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF)
TRGBA::TRGBA(int nValue)
: r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF)
{}
void TRGBA::Set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
@ -94,7 +95,18 @@ namespace MetaFile
return a;
}
TXForm::TXForm() : M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0)
TRGBA& TRGBA::operator=(const TRGBA& oRGBA)
{
r = oRGBA.r;
g = oRGBA.g;
b = oRGBA.b;
a = oRGBA.a;
return *this;
}
TXForm::TXForm()
: M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0)
{}
TXForm::TXForm(const TXForm &oXForm)

View File

@ -558,6 +558,8 @@ namespace MetaFile
unsigned char GetGreen() const;
unsigned char GetBlue() const;
unsigned char GetAlpha() const;
TRGBA& operator=(const TRGBA& oRGBA);
};
struct TXForm

View File

@ -147,6 +147,10 @@ namespace MetaFile
if (BI_JPEG != unCompression || BI_PNG != unCompression)
return false;
#ifdef METAFILE_DISABLE_FILESYSTEM
return false;
#endif
std::wstring wsTempFileName = GetTempFilename();
if (wsTempFileName.empty())
return false;
@ -233,7 +237,9 @@ namespace MetaFile
}
for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++)
{
int nByte = *pBuffer; pBuffer++; lBufLen--;
// int nByte = *pBuffer;
++pBuffer;
--lBufLen;
}
}
}
@ -267,7 +273,9 @@ namespace MetaFile
}
for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++)
{
int nByte = *pBuffer; pBuffer++; lBufLen--;
// int nByte = *pBuffer;
++pBuffer;
--lBufLen;
}
}
}
@ -486,7 +494,12 @@ namespace MetaFile
}
if (lBufLen < (nWidth + nAdd) * abs(nHeight))
{
if (pUncompressedBuffer)
delete[] pUncompressedBuffer;
return false;
}
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
if (NULL == pBgraBuffer)
@ -639,7 +652,7 @@ namespace MetaFile
*pulWidth = ulWidth;
*pulHeight = ulHeight;
return false;
return true;
}
else if (BI_BITCOUNT_5 == ushBitCount)
{
@ -986,29 +999,6 @@ namespace MetaFile
}
}
std::wstring ascii_to_unicode(const char *src)
{
size_t nSize = mbstowcs(0, src, 0);
wchar_t* pBuffer = new wchar_t[nSize];
nSize = mbstowcs(pBuffer, src, nSize);
std::wstring sRes;
if (nSize != (size_t)-1)
sRes = std::wstring(pBuffer, nSize);
delete[] pBuffer;
return sRes;
}
std::string unicode_to_ascii(const wchar_t *src)
{
size_t nSize = wcstombs(0, src, 0);
char* pBuffer = new char[nSize];
nSize = wcstombs(pBuffer, src, nSize);
std::string sRes;
if (nSize != (size_t)-1)
sRes = std::string(pBuffer, nSize);
delete[] pBuffer;
return sRes;
}
std::wstring GetTempFilename(const std::wstring& sFolder)
{
std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(sFolder.empty() ? NSFile::CFileBinary::GetTempPath() : sFolder, L"wmf");

View File

@ -1512,26 +1512,5 @@ namespace MetaFile
std::swap(oFirstClip, oSecondClip);
}
TRectD CEmfInterpretatorSvg::TranslateRect(const TRectL &oRect) const
{
TRectD oNewRect(oRect.Left, oRect.Top, oRect.Right, oRect.Bottom);
if (oNewRect.Right < oNewRect.Left)
{
double dTempValue = oNewRect.Left;
oNewRect.Left = oNewRect.Right;
oNewRect.Right = dTempValue;
}
if (oNewRect.Bottom < oNewRect.Top)
{
double dTempValue = oNewRect.Top;
oNewRect.Top = oNewRect.Bottom;
oNewRect.Bottom = dTempValue;
}
return oNewRect;
}
}

View File

@ -227,8 +227,6 @@ namespace MetaFile
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
void SwapClips(CSvgClip& oFirstClip, CSvgClip& oSecondClip);
TRectD TranslateRect(const TRectL &oRect) const;
};
}

View File

@ -30,7 +30,6 @@
*
*/
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common/MetaFileUtils.h"

View File

@ -593,6 +593,8 @@ namespace MetaFile
if (!BanEMFProcesses())
HANDLE_EMR_CREATEBRUSHINDIRECT(ulBrushIndex, pBrush);
else
delete pBrush;
}
void CEmfParser::Read_EMR_SETTEXTCOLOR()
@ -630,6 +632,8 @@ namespace MetaFile
if (!BanEMFProcesses())
HANDLE_EMR_EXTCREATEFONTINDIRECTW(ulIndex, pFont);
else
delete pFont;
}
void CEmfParser::Read_EMR_SETTEXTALIGN()
@ -722,6 +726,8 @@ namespace MetaFile
if (!BanEMFProcesses())
HANDLE_EMR_EXTCREATEPEN(ulPenIndex, pPen, arUnused);
else
delete pPen;
}
void CEmfParser::Read_EMR_CREATEPEN()
@ -744,6 +750,8 @@ namespace MetaFile
if (!BanEMFProcesses())
HANDLE_EMR_CREATEPEN(ulPenIndex, widthX, pPen);
else
delete pPen;
}
void CEmfParser::Read_EMR_SETPOLYFILLMODE()
@ -1011,6 +1019,8 @@ namespace MetaFile
if (!BanEMFProcesses())
HANDLE_EMR_CREATEPALETTE(ulPaletteIndex, pPalette);
else
delete pPalette;
}
void CEmfParser::Read_EMR_SELECTPALETTE()

View File

@ -763,7 +763,7 @@ namespace MetaFile
if (InterpretatorType::Svg == oInterpretatorType)
{
CEmfInterpretatorSvg *pEmfInterpretatorSvg = new CEmfInterpretatorSvg(this, dWidth, dHeight);
pEmfInterpretatorSvg->SetShapeRendering(EShapeRendering::CrispEdges);
pEmfInterpretatorSvg->SetShapeRendering(EShapeRendering::OptimizeSpeed);
m_pInterpretator = pEmfInterpretatorSvg;
}
}

View File

@ -1,10 +1,6 @@
#ifndef CEMFPARSERBASE_H
#define CEMFPARSERBASE_H
//#include "../EmfTypes.h"
//#include "../EmfObjects.h"
//#include "../../Common/MetaFileUtils.h"
#include "../EmfPlayer.h"
#include "../../Common/MetaFile.h"

View File

@ -67,15 +67,11 @@
#define EMFPLUS_TRANSLATEWORLDTRANSFORM 0x402D
#include <map>
#include <iostream>
#include "CEmfParser.h"
#include "../../Wmf/WmfFile.h"
#include "../../Wmf/WmfInterpretator/CWmfInterpretatorSvg.h"
#include "../EmfInterpretator/CEmfInterpretator.h"
#include "../EmfInterpretator/CEmfInterpretatorSvg.h"
#include "../EmfInterpretator/CEmfInterpretatorArray.h"
#include "../EmfInterpretator/CEmfInterpretatorRender.h"
#ifdef METAFILE_SUPPORT_WMF_EMF_XML
@ -664,6 +660,9 @@ namespace MetaFile
for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex)
m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first;
pEmfPlusBrush->oColor = pEmfPlusBrush->arGradientColors.back() .first;
pEmfPlusBrush->oColorBack = pEmfPlusBrush->arGradientColors.front().first;
}
}
@ -772,7 +771,7 @@ namespace MetaFile
switch (nEndCap)
{
case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break;
case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break;
case 1: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_SQUARE; break;
case 2: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_ROUND; break;
}
@ -785,7 +784,7 @@ namespace MetaFile
switch (nJoin)
{
case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break;
case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break;
case 1: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_BEVEL; break;
case 2: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_ENDCAP_ROUND; break;
}
@ -871,7 +870,7 @@ namespace MetaFile
m_oStream >> *pLineCapData;
if (CustomLineCapDataFillPath == pLineCapData->unCustomLineCapDataFlags ||
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
{
m_oStream.Skip(4); // FillPathLength or LinePathLength
pLineCapData->pPath = ReadPath();
@ -1343,7 +1342,7 @@ namespace MetaFile
if (oImageAttributes.eWrapMode == WrapModeClamp)
{
if (oRectangle.dX < 0 || oRectangle.dX < 0 ||
oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight)
oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight)
return oImageAttributes.oClampColor;
}
@ -1541,14 +1540,10 @@ namespace MetaFile
case MetafileDataTypeEmf:
case MetafileDataTypeEmfPlusOnly:
case MetafileDataTypeEmfPlusDual:
{
return DrawMetafile<CEmfParser>(pBuffer, unSizeBuffer, oSrcRect, arPoints);
}
case MetafileDataTypeWmf:
case MetafileDataTypeWmfPlaceable:
{
return DrawMetafile<CWmfParser>(pBuffer, unSizeBuffer, oSrcRect, arPoints);
}
}
}
}
@ -1661,7 +1656,7 @@ namespace MetaFile
BYTE* pNewBuffer = GetClipedImage(pPixels, nWidth, nHeight, oClipRect, nW, nH);
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X - m_pDC->GetPixelWidth(), arPoints[2].Y - arPoints[0].Y - m_pDC->GetPixelHeight(),
(NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH);
(NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH);
RELEASEINTERFACE(pGrRenderer);
RELEASEARRAYOBJECTS(pNewBuffer);
@ -1740,7 +1735,7 @@ namespace MetaFile
BYTE* pNewBuffer = GetClipedImage(pBytes, unWidth, unHeight, oClipRect, nW, nH);
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X, arPoints[2].Y - arPoints[0].Y,
(NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH);
(NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH);
if (!bExternalBuffer)
RELEASEARRAYOBJECTS(pBytes);
@ -1803,17 +1798,15 @@ namespace MetaFile
m_pDC->SetPen(pPen);
if (AD_COUNTERCLOCKWISE != m_pDC->GetArcDirection())
{
dSweepAngle = dSweepAngle - 360;
}
TEmfPlusRectF oConvertedRect = GetConvertedRectangle(oRect);
MoveTo(oConvertedRect.dX, oConvertedRect.dY);
ArcTo(oConvertedRect.dX, oConvertedRect.dY,
oConvertedRect.dX + oConvertedRect.dWidth,
oConvertedRect.dY + oConvertedRect.dHeight,
dStartAngle, dSweepAngle);
oConvertedRect.dX + oConvertedRect.dWidth,
oConvertedRect.dY + oConvertedRect.dHeight,
dStartAngle, dSweepAngle);
DrawPath(true, false);
if (NULL != m_pInterpretator)
@ -2290,13 +2283,13 @@ namespace MetaFile
if (NULL != m_pInterpretator)
{
CPathConverter oPathConverter;
CPath oNewPath, oLineCapPath;
oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen);
if (InterpretatorType::Render == m_pInterpretator->GetType())
{
CPathConverter oPathConverter;
CPath oNewPath, oLineCapPath;
oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen);
oNewPath.DrawOn(m_pInterpretator, true, false);
oLineCapPath.DrawOn(m_pInterpretator, false, true);
}
@ -2833,7 +2826,7 @@ namespace MetaFile
void CEmfPlusParser::Read_EMFPLUS_FILLREGION(unsigned short unShFlags)
{
short shOgjectIndex = ExpressValue(unShFlags, 0, 7);
// short shOgjectIndex = ExpressValue(unShFlags, 0, 7);
unsigned int unBrushId;
m_oStream >> unBrushId;
@ -2992,34 +2985,34 @@ namespace MetaFile
void CEmfPlusParser::Read_EMFPLUS_SETANTIALIASMODE(unsigned short unShFlags)
{
short shSmoothingMode = ExpressValue(unShFlags, 1, 7);
// short shSmoothingMode = ExpressValue(unShFlags, 1, 7);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGMODE(unsigned short unShFlags)
{
short shCompositingMode = ExpressValue(unShFlags, 0, 7);
// short shCompositingMode = ExpressValue(unShFlags, 0, 7);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGQUALITY(unsigned short unShFlags)
{
short shCompositingQuality = ExpressValue(unShFlags, 0, 7);
// short shCompositingQuality = ExpressValue(unShFlags, 0, 7);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMFPLUS_SETINTERPOLATIONMODE(unsigned short unShFlags)
{
short shInterpolationMode = ExpressValue(unShFlags, 0, 7);
// short shInterpolationMode = ExpressValue(unShFlags, 0, 7);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMFPLUS_SETPIXELOFFSETMODE(unsigned short unShFlags)
{
short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7);
// short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7);
//TODO: реализовать
}
@ -3036,20 +3029,20 @@ namespace MetaFile
void CEmfPlusParser::Read_EMFPLUS_SETTEXTCONTRAST(unsigned short unShFlags)
{
short shTextContrast = ExpressValue(unShFlags, 0, 11);
// short shTextContrast = ExpressValue(unShFlags, 0, 11);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMRPLUS_SETTEXTRENDERINGHINT(unsigned short unShFlags)
{
short shTextRenderingHint = ExpressValue(unShFlags, 0, 7);
// short shTextRenderingHint = ExpressValue(unShFlags, 0, 7);
//TODO: реализовать
}
void CEmfPlusParser::Read_EMFPLUS_BEGINCONTAINER(unsigned short unShFlags)
{
short shPageUnit = ExpressValue(unShFlags, 8, 15);
// short shPageUnit = ExpressValue(unShFlags, 8, 15);
TEmfPlusRectF oDestRect, oSrcRect;
unsigned int unStackIndex;

View File

@ -1,8 +1,6 @@
#ifndef CEMFPLUSPARSER_H
#define CEMFPLUSPARSER_H
//#include "../../Common/MetaFileUtils.h"
//#include "../../Common/MetaFile.h"
#include "../EmfPlusObjects.h"
#include "CEmfParserBase.h"
#include "../EmfPlusTypes.h"

View File

@ -106,6 +106,16 @@ namespace MetaFile
chRed = oARGB.chRed;
chAlpha = oARGB.chAlpha;
}
TEmfPlusARGB& operator=(const TEmfPlusARGB& oARGB)
{
chBlue = oARGB.chBlue;
chGreen = oARGB.chGreen;
chRed = oARGB.chRed;
chAlpha = oARGB.chAlpha;
return *this;
}
};
struct TGUID

View File

@ -611,6 +611,9 @@ namespace MetaFile
void CMetaFile::ConvertToRaster(const wchar_t* wsOutFilePath, unsigned int unFileType, int nWidth, int nHeight)
{
if (nWidth == 0 || nHeight == 0)
return;
NSGraphics::IGraphicsRenderer* pGrRenderer = NSGraphics::Create();
NSFonts::IFontManager* pFontManager = m_pAppFonts->GenerateFontManager();

View File

@ -266,6 +266,7 @@ void CSvmFile::Read_META_LINE()
{
case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break;
case LINE_DASH: last_pen->PenStyle = PS_DASH ; break;
default: break;
}
}
}
@ -323,6 +324,7 @@ void CSvmFile::Read_META_POLYLINE()
{
case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break;
case LINE_DASH: last_pen->PenStyle = PS_DASH ; break;
default: break;
}
if (last_pen->Width < 1)

View File

@ -560,16 +560,18 @@ namespace MetaFile
void CInterpretatorSvgBase::IntersectClip(const TRectD &oClip)
{
double dLeft = oClip.Left;
double dTop = oClip.Top;
double dRight = oClip.Right;
double dBottom = oClip.Bottom;
TRectD oUpdatedClip{oClip};
m_pParser->GetTransform().Apply(dLeft, dTop);
m_pParser->GetTransform().Apply(dRight, dBottom);
NormalizeRect(oUpdatedClip);
m_pParser->GetTransform().Apply(oUpdatedClip.Left, oUpdatedClip.Top);
m_pParser->GetTransform().Apply(oUpdatedClip.Right, oUpdatedClip.Bottom);
const std::wstring wsId = L"INTERSECTCLIP_" + ConvertToWString(++m_unNumberDefs, 0);
const std::wstring wsValue = L"<rect x=\"" + ConvertToWString(dLeft, 0) + L"\" y=\"" + ConvertToWString(dTop, 0) + L"\" width=\"" + ConvertToWString(dRight - dLeft, 0) + L"\" height=\"" + ConvertToWString(dBottom - dTop, 0) + L"\"/>";
const std::wstring wsValue = L"<rect x=\"" + ConvertToWString(oUpdatedClip.Left, 0) +
L"\" y=\"" + ConvertToWString(oUpdatedClip.Top, 0) +
L"\" width=\"" + ConvertToWString(oUpdatedClip.Right - oUpdatedClip.Left, 0) +
L"\" height=\"" + ConvertToWString(oUpdatedClip.Bottom - oUpdatedClip.Top, 0) + L"\"/>";
m_oClip.AddClipValue(wsId, wsValue);
}
@ -577,28 +579,24 @@ namespace MetaFile
void CInterpretatorSvgBase::ExcludeClip(const TRectD &oClip, const TRectD &oBB)
{
const TXForm &oTransform{m_pParser->GetTransform()};
double dClipLeft = oClip.Left;
double dClipTop = oClip.Top;
double dClipRight = oClip.Right;
double dClipBottom = oClip.Bottom;
oTransform.Apply(dClipLeft, dClipTop);
oTransform.Apply(dClipRight, dClipBottom);
TRectD oUpdatedClip{oClip};
NormalizeRect(oUpdatedClip);
double dBBLeft = oBB.Left;
double dBBTop = oBB.Top;
double dBBRight = oBB.Right;
double dBBBottom = oBB.Bottom;
oTransform.Apply(oUpdatedClip.Left, oUpdatedClip.Top);
oTransform.Apply(oUpdatedClip.Right, oUpdatedClip.Bottom);
oTransform.Apply(dBBLeft, dBBTop);
oTransform.Apply(dBBRight, dBBBottom);
TRectD oBBRect{oBB};
NormalizeRect(oBBRect);
oTransform.Apply(oBBRect.Left, oBBRect.Top);
oTransform.Apply(oBBRect.Right, oBBRect.Bottom);
const std::wstring wsId = L"EXCLUDECLIP_" + ConvertToWString(++m_unNumberDefs, 0);
const std::wstring wsValue = L"<path d=\"M" + ConvertToWString(dBBLeft) + L' ' + ConvertToWString(dBBTop) + L", L" + ConvertToWString(dBBRight) + L' ' + ConvertToWString(dBBTop) + L", " +
ConvertToWString(dBBRight) + L' ' + ConvertToWString(dBBBottom) + L", " + ConvertToWString(dBBLeft ) + L' ' + ConvertToWString(dBBBottom) + L", M" +
ConvertToWString(dClipLeft) + L' ' + ConvertToWString(dClipTop) + L", L" + ConvertToWString(dClipRight) + L' ' + ConvertToWString(dClipTop) + L", " +
ConvertToWString(dClipRight) + L' ' + ConvertToWString(dClipBottom) + L", " + ConvertToWString(dClipLeft) + L' ' + ConvertToWString(dClipLeft ) + L"\" clip-rule=\"evenodd\"/>";
const std::wstring wsValue = L"<path d=\"M" + ConvertToWString(oBBRect.Left) + L' ' + ConvertToWString(oBBRect.Top) + L", L" + ConvertToWString(oBBRect.Right) + L' ' + ConvertToWString(oBBRect.Top) + L", " +
ConvertToWString(oBBRect.Right) + L' ' + ConvertToWString(oBBRect.Bottom) + L", " + ConvertToWString(oBBRect.Left) + L' ' + ConvertToWString(oBBRect.Bottom) + L", Z M" +
ConvertToWString(oUpdatedClip.Left) + L' ' + ConvertToWString(oUpdatedClip.Top) + L", L" + ConvertToWString(oUpdatedClip.Right) + L' ' + ConvertToWString(oUpdatedClip.Top) + L", " +
ConvertToWString(oUpdatedClip.Right) + L' ' + ConvertToWString(oUpdatedClip.Bottom) + L", " + ConvertToWString(oUpdatedClip.Left) + L' ' + ConvertToWString(oUpdatedClip.Bottom) + L" Z\" clip-rule=\"evenodd\"/>";
m_oClip.AddClipValue(wsId, wsValue);
}
@ -2080,4 +2078,21 @@ namespace MetaFile
return CalculateColor(unColor, chAlpha);
}
void NormalizeRect(TRectD& oRect)
{
if (oRect.Right < oRect.Left)
std::swap(oRect.Right, oRect.Left);
if (oRect.Bottom < oRect.Top)
std::swap(oRect.Bottom, oRect.Top);
}
TRectD TranslateRect(const TRectL& oRect)
{
TRectD oNewRect(oRect.Left, oRect.Top, oRect.Right, oRect.Bottom);
NormalizeRect(oNewRect);
return oNewRect;
}
}

View File

@ -161,6 +161,8 @@ namespace MetaFile
std::wstring CalculateColor(unsigned int unColor);
std::wstring CalculateColor(unsigned int unColor, BYTE uchAlpha);
std::wstring CalculateColor(BYTE uchRed, BYTE uchGreen, BYTE uchBlue, BYTE uchAlpha);
void NormalizeRect(TRectD& oRect);
TRectD TranslateRect(const TRectL &oRect);
}
#endif // CINTERPRETATORSVGBASE_H

View File

@ -153,7 +153,13 @@ namespace MetaFile
const std::wstring wsText{ConvertToUnicode(pString, (long)shStringLength, (NULL != pFont) ? pFont->GetCharSet() : DEFAULT_CHARSET)};
TPointD oScale((m_pParser->IsWindowFlippedX()) ? -1 : 1, (m_pParser->IsWindowFlippedY()) ? -1 : 1);
TPointD oScale(1, 1);
if (NULL != m_pParser)
{
oScale.X = m_pParser->IsWindowFlippedX() ? -1 : 1;
oScale.Y = m_pParser->IsWindowFlippedY() ? -1 : 1;
}
std::vector<double> arDx(0);
@ -346,12 +352,7 @@ namespace MetaFile
void CWmfInterpretatorSvg::HANDLE_META_RECTANGLE(short shB, short shR, short shT, short shL)
{
TRectD oNewRect;
oNewRect.Left = shL;
oNewRect.Top = shT;
oNewRect.Right = shR;
oNewRect.Bottom = shB;
TRectD oNewRect = TranslateRect({shL, shT, shR, shB});
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
{L"y", ConvertToWString(oNewRect.Top)},
@ -369,12 +370,7 @@ namespace MetaFile
void CWmfInterpretatorSvg::HANDLE_META_ROUNDRECT(short shH, short shW, short shB, short shR, short shT, short shL)
{
TRectD oNewRect;
oNewRect.Left = shL;
oNewRect.Top = shT;
oNewRect.Right = shR;
oNewRect.Bottom = shB;
TRectD oNewRect = TranslateRect({shL, shT, shR, shB});
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
{L"y", ConvertToWString(oNewRect.Top)},

View File

@ -298,7 +298,7 @@ namespace MetaFile
m_oStream >> oBitmap;
unsigned int unRecordSizeDWORD = m_unRecordSize >> 1;
unsigned int unValue = (META_STRETCHBLT >> 8) + 3;
// unsigned int unValue = (META_STRETCHBLT >> 8) + 3;
if (unRecordSizeDWORD == ((META_STRETCHBLT >> 8) + 3))
{

View File

@ -196,7 +196,7 @@ namespace MetaFile
if (InterpretatorType::Svg == oInterpretatorType)
{
CWmfInterpretatorSvg *pWmfInterpretatorSvg = new CWmfInterpretatorSvg(this, unWidth, unHeight);
pWmfInterpretatorSvg->SetShapeRendering(EShapeRendering::CrispEdges);
pWmfInterpretatorSvg->SetShapeRendering(EShapeRendering::OptimizeSpeed);
m_pInterpretator = pWmfInterpretatorSvg;
}
}
@ -241,10 +241,10 @@ namespace MetaFile
{
const double dKoef = 96. / (double)m_oPlaceable.ushInch;
m_oDCRect.Left = std::round(m_oDCRect.Left * dKoef);
m_oDCRect.Top = std::round(m_oDCRect.Top * dKoef);
m_oDCRect.Right = std::round(m_oDCRect.Right * dKoef);
m_oDCRect.Bottom = std::round(m_oDCRect.Bottom * dKoef);
m_oDCRect.Left = static_cast<int>(std::round(m_oDCRect.Left * dKoef));
m_oDCRect.Top = static_cast<int>(std::round(m_oDCRect.Top * dKoef));
m_oDCRect.Right = static_cast<int>(std::round(m_oDCRect.Right * dKoef));
m_oDCRect.Bottom = static_cast<int>(std::round(m_oDCRect.Bottom * dKoef));
}
// Иногда m_oPlaceable.BoundingBox задается нулевой ширины и высоты
@ -292,6 +292,16 @@ namespace MetaFile
m_pDC->SetCurPos(shX, shY);
}
void CWmfParserBase::MoveToD(double dX, double dY)
{
if (NULL != m_pInterpretator)
m_pInterpretator->MoveTo(dX, dY);
else
RegisterPoint(static_cast<short>(dX), static_cast<short>(dY));
m_pDC->SetCurPos(static_cast<short>(dX), static_cast<short>(dY));
}
void CWmfParserBase::LineTo(short shX, short shY)
{
if (NULL != m_pInterpretator)
@ -396,7 +406,7 @@ namespace MetaFile
NSFonts::IFontManager* pFontManager = GetFontManager();
if (pFontManager)
{
int lLogicalFontHeight = pFont->GetHeight();
int lLogicalFontHeight = static_cast<int>(pFont->GetHeight());
if (lLogicalFontHeight < 0)
lLogicalFontHeight = -lLogicalFontHeight;
if (lLogicalFontHeight < 0.01)
@ -444,8 +454,8 @@ namespace MetaFile
{
pFontManager->LoadString1(wsText, 0, 0);
TBBox oBox = pFontManager->MeasureString2();
fL = (float)(oBox.fMinX);
fW = (float)(oBox.fMaxX - oBox.fMinX);
fL = static_cast<float>(oBox.fMinX);
fW = static_cast<float>(oBox.fMaxX - oBox.fMinX);
}
pFontManager->LoadString1(wsText, 0, 0);
@ -520,7 +530,7 @@ namespace MetaFile
}
else
{
int lLogicalFontHeight = pFont->GetHeight();
int lLogicalFontHeight = static_cast<int>(pFont->GetHeight());
if (lLogicalFontHeight < 0)
lLogicalFontHeight = -lLogicalFontHeight;
if (lLogicalFontHeight < 0.01)
@ -548,7 +558,7 @@ namespace MetaFile
fW = (float)(dFontHeight * wsText.length());
}
fH = dFontHeight * 1.2;
fH = (float)dFontHeight * 1.2f;
double dTheta = -((((double)pFont->GetEscapement()) / 10) * 3.14159265358979323846 / 180);
double dCosTheta = (float)cos(dTheta);
@ -724,17 +734,17 @@ namespace MetaFile
oNewRect.Top < 0 || oNewRect.Bottom < 0)
return NULL;
if (unHeight < (oNewRect.Bottom - oNewRect.Top))
oNewRect.Bottom = oNewRect.Top + unWidth;
if (unHeight < static_cast<unsigned int>(std::abs(oNewRect.Bottom - oNewRect.Top)))
oNewRect.Bottom = oNewRect.Top + unHeight;
if (unWidth < (oNewRect.Right - oNewRect.Left))
if (unWidth < static_cast<unsigned int>(std::abs(oNewRect.Right - oNewRect.Left)))
oNewRect.Right = oNewRect.Left + unWidth;
if (unHeight == (oNewRect.Bottom - oNewRect.Top) &&
unWidth == (oNewRect.Right - oNewRect.Left))
return NULL;
int nBeginX, nBeginY, nEndX, nEndY;
ULONG nBeginX, nBeginY, nEndX, nEndY;
nBeginX = (std::min)(oNewRect.Left, oNewRect.Right);
nBeginY = (std::min)(oNewRect.Top, oNewRect.Bottom);
@ -924,7 +934,7 @@ namespace MetaFile
double dSweepAngle = GetSweepAngle(dStartAngle, dEndAngle);
MoveTo(dX1, dY1);
MoveToD(dX1, dY1);
ArcTo(shLeft, shTop, shRight, shBottom, dStartAngle, dSweepAngle);
DrawPath(true, false);
}

View File

@ -188,6 +188,7 @@ namespace MetaFile
inline double GetSweepAngle(const double& dStartAngle, const double& dEndAngle) const;
void MoveTo(short shX, short shY);
void MoveToD(double dX, double dY);
void LineTo(short shX, short shY);
void ArcTo(short shL, short shT, short shR, short shB, double dStart, double dSweep);
void ClosePath();

View File

@ -29,139 +29,22 @@ namespace SVG
if (NULL == pSvgObject)
return;
const std::map<std::wstring, NSCSS::CElement *> *pData = m_pInternal->GetData();
const std::vector<NSCSS::CNode> arSelectors = pSvgObject->GetFullPath();
if ((NULL == pData || pData->empty()) && arSelectors.empty())
return;
std::vector<std::wstring> arWords;
arWords.reserve(arSelectors.size() * 2);
std::vector<std::wstring> arNextNodes;
arNextNodes.reserve(arSelectors.size() * 2);
for (std::vector<NSCSS::CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
arWords.push_back(oNode->m_wsName);
if (!oNode->m_wsClass.empty())
{
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NSCSS::NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, false, L" ");
if (arClasses.size() > 1)
arClasses.resize(unique(arClasses.begin(),arClasses.end()) - arClasses.begin());
arWords.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
}
else
arWords.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_wsId.empty())
arWords.push_back(L'#' + oNode->m_wsId);
}
std::vector<NSCSS::CElement*> arElements;
std::vector<std::wstring> arNodes = m_pInternal->CalculateAllNodes(arSelectors);
std::vector<std::wstring> arPrevNodes;
for (size_t i = 0; i < arSelectors.size(); ++i)
{
std::wstring sName, sId;
std::vector<std::wstring> arClasses;
if (arWords.back()[0] == L'#')
{
sId = arWords.back();
arWords.pop_back();
arNextNodes.push_back(sId);
}
if (arWords.back()[0] == L'.')
{
arClasses = NSCSS::NS_STATIC_FUNCTIONS::GetWordsW(arWords.back(), false, L" ");
arNextNodes.push_back(arWords.back());
arWords.pop_back();
}
sName = arWords.back();
arWords.pop_back();
arNextNodes.push_back(sName);
const std::map<std::wstring, NSCSS::CElement*>::const_iterator oFindName = pData->find(sName);
std::map<std::wstring, NSCSS::CElement*>::const_iterator oFindId;
std::vector<NSCSS::CElement*> arFindElements;
if (!sId.empty())
{
oFindId = pData->find(sId);
if (oFindId != std::end(*pData))
{
if (!oFindId->second->Empty())
arFindElements.push_back(oFindId->second);
const std::vector<NSCSS::CElement*> arTempPrev = oFindId->second->GetPrevElements(arNextNodes.rbegin() + ((arClasses.empty()) ? 1 : 2), arNextNodes.rend());
if (!arTempPrev.empty())
arFindElements.insert(arFindElements.end(), arTempPrev.begin(), arTempPrev.end());
}
}
if (!arClasses.empty())
{
for (std::vector<std::wstring>::const_reverse_iterator iClass = arClasses.rbegin(); iClass != arClasses.rend(); ++iClass)
{
const std::map<std::wstring, NSCSS::CElement*>::const_iterator oFindClass = pData->find(*iClass);
if (oFindClass != std::end(*pData))
{
if (!oFindClass->second->Empty())
arFindElements.push_back(oFindClass->second);
const std::vector<NSCSS::CElement*> arTempPrev = oFindClass->second->GetPrevElements(arNextNodes.rbegin() + 2, arNextNodes.rend());
const std::vector<NSCSS::CElement*> arTempKins = oFindClass->second->GetNextOfKin(sName);
if (!arTempPrev.empty())
arFindElements.insert(arFindElements.end(), arTempPrev.begin(), arTempPrev.end());
if (!arTempKins.empty())
arFindElements.insert(arFindElements.end(), arTempKins.begin(), arTempKins.end());
}
}
}
if (oFindName != std::end(*pData))
{
if (!oFindName->second->Empty())
arFindElements.push_back(oFindName->second);
const std::vector<NSCSS::CElement*> arTempPrev = oFindName->second->GetPrevElements(arNextNodes.rbegin() + 1, arNextNodes.rend());
const std::vector<NSCSS::CElement*> arTempKins = oFindName->second->GetNextOfKin(sName, arClasses);
if (!arTempPrev.empty())
arFindElements.insert(arFindElements.end(), arTempPrev.begin(), arTempPrev.end());
if (!arTempKins.empty())
arFindElements.insert(arFindElements.end(), arTempKins.begin(), arTempKins.end());
}
if (arFindElements.size() > 1)
{
std::sort(arFindElements.rbegin(), arFindElements.rend(),
[](NSCSS::CElement* oFirstElement, NSCSS::CElement* oSecondElement)
{
return oFirstElement->GetWeight() > oSecondElement->GetWeight();
});
}
pSvgObject->SetData(arSelectors[i].m_mAttributes, i + 1);
pSvgObject->SetData(arSelectors[i].m_wsStyle, i + 1, true);
for (const NSCSS::CElement* oElement : arFindElements)
for (const NSCSS::CElement* oElement : m_pInternal->FindElements(arNodes, arPrevNodes))
pSvgObject->SetData(oElement->GetStyle(), i + 1);
if (!arSelectors[i].m_wsStyle.empty())
pSvgObject->SetData(arSelectors[i].m_wsStyle, i + 1, true);
}
return;
}
}

View File

@ -442,14 +442,14 @@ namespace SVG
if (!Equals(0., dFontHeight) && dFontHeight < MIN_FONT_SIZE)
{
dXScale *= dFontHeight / MIN_FONT_SIZE;
dYScale *= dFontHeight / MIN_FONT_SIZE;
dXScale *= MIN_FONT_SIZE / dFontHeight;
dYScale *= MIN_FONT_SIZE / dFontHeight;
dFontHeight = MIN_FONT_SIZE;
}
else if (!Equals(0., dFontHeight) && dFontHeight > MAX_FONT_SIZE)
{
dXScale *= MAX_FONT_SIZE / dFontHeight;
dYScale *= MAX_FONT_SIZE / dFontHeight;
dXScale *= dFontHeight / MAX_FONT_SIZE;
dYScale *= dFontHeight / MAX_FONT_SIZE;
dFontHeight = MAX_FONT_SIZE;
}

View File

@ -126,20 +126,7 @@ std::vector<std::wstring> CDocxRenderer::ScanPage(IOfficeDrawingFile* pFile, siz
DrawPage(pFile, nPage);
std::vector<std::wstring> xml_shapes;
for (const auto& shape : m_pInternal->m_oDocument.m_oCurrentPage.m_arShapes)
{
if (!shape) continue;
auto writer = new NSStringUtils::CStringBuilder();
shape->ToXml(*writer);
xml_shapes.push_back(writer->GetData());
delete writer;
}
std::vector<std::wstring>& arComleteObjects = m_pInternal->m_oDocument.m_oCurrentPage.m_arCompleteObjectsXml;
if (!arComleteObjects.empty())
xml_shapes.insert(xml_shapes.end(), arComleteObjects.begin(), arComleteObjects.end());
auto xml_shapes = m_pInternal->m_oDocument.m_oCurrentPage.GetXmlShapes();
m_pInternal->m_oDocument.Clear();
return xml_shapes;
}
@ -154,23 +141,7 @@ std::vector<std::wstring> CDocxRenderer::ScanPagePptx(IOfficeDrawingFile* pFile,
DrawPage(pFile, nPage);
// for drawingml is no tag behind-doc - so we need to reorder shapes
m_pInternal->m_oDocument.m_oCurrentPage.ReorderShapesForPptx();
std::vector<std::wstring> xml_shapes;
for (const auto& shape : m_pInternal->m_oDocument.m_oCurrentPage.m_arShapes)
{
if (!shape) continue;
auto writer = new NSStringUtils::CStringBuilder();
shape->ToXmlPptx(*writer);
xml_shapes.push_back(writer->GetData());
delete writer;
}
std::vector<std::wstring>& arComleteObjects = m_pInternal->m_oDocument.m_oCurrentPage.m_arCompleteObjectsXml;
if (!arComleteObjects.empty())
xml_shapes.insert(xml_shapes.end(), arComleteObjects.begin(), arComleteObjects.end());
auto xml_shapes = m_pInternal->m_oDocument.m_oCurrentPage.GetXmlShapesPptx();
m_pInternal->m_oDocument.Clear();
return xml_shapes;
}
@ -241,7 +212,7 @@ HRESULT CDocxRenderer::AdvancedCommand(IAdvancedCommand* command)
std::string sNewId = "r:embed=\"rId" + std::to_string(pInfo->m_nId + c_iStartingIdForImages) + "\"";
NSStringUtils::string_replaceA(sUtf8Shape, "r:embed=\"\"", sNewId);
}
m_pInternal->m_oDocument.m_oCurrentPage.m_arCompleteObjectsXml.push_back(UTF8_TO_U(sUtf8Shape));
m_pInternal->m_oDocument.m_oCurrentPage.AddCompleteXml(UTF8_TO_U(sUtf8Shape));
return S_OK;
}
case IAdvancedCommand::AdvancedCommandType::ShapeEnd:

View File

@ -32,6 +32,7 @@ HEADERS += \
src/logic/elements/ContText.h \
src/logic/elements/Paragraph.h \
src/logic/elements/Shape.h \
src/logic/elements/Table.h \
src/logic/elements/TextLine.h \
src/logic/managers/ExternalImageStorage.h \
src/logic/managers/FontStyleManager.h \
@ -56,6 +57,7 @@ SOURCES += \
src/logic/elements/ContText.cpp \
src/logic/elements/Paragraph.cpp \
src/logic/elements/Shape.cpp \
src/logic/elements/Table.cpp \
src/logic/elements/TextLine.cpp \
src/logic/managers/FontManager.cpp \
src/logic/managers/FontStyleManager.cpp \

View File

@ -1,126 +0,0 @@
#include "BaseItem.h"
#include "../resources/Constants.h"
#include <math.h>
namespace NSDocxRenderer
{
CBaseItem& CBaseItem::operator=(const CBaseItem& oSrc)
{
if (this == &oSrc)
{
return *this;
}
m_eType = oSrc.m_eType;
m_bIsNotNecessaryToUse = oSrc.m_bIsNotNecessaryToUse;
m_dLeft = oSrc.m_dLeft;
m_dTop = oSrc.m_dTop;
m_dWidth = oSrc.m_dWidth;
m_dHeight = oSrc.m_dHeight;
m_dBaselinePos = oSrc.m_dBaselinePos;
m_dRight = oSrc.m_dRight;
return *this;
}
bool CBaseItem::IsBigger(const CBaseItem* oSrc)
{
return (m_dLeft > oSrc->m_dLeft) ? true : false;
}
bool CBaseItem::IsBiggerOrEqual(const CBaseItem* oSrc)
{
return (m_dLeft >= oSrc->m_dLeft) ? true : false;
}
eVerticalCrossingType CBaseItem::GetVerticalCrossingType(const CBaseItem* oSrc)
{
if (m_dTop > oSrc->m_dTop && m_dBaselinePos < oSrc->m_dBaselinePos)
{
return eVerticalCrossingType::vctCurrentInsideNext;
}
else if (m_dTop < oSrc->m_dTop && m_dBaselinePos > oSrc->m_dBaselinePos)
{
return eVerticalCrossingType::vctCurrentOutsideNext;
}
else if (m_dTop < oSrc->m_dTop && m_dBaselinePos < oSrc->m_dBaselinePos && m_dBaselinePos > oSrc->m_dTop)
{
return eVerticalCrossingType::vctCurrentAboveNext;
}
else if (m_dTop > oSrc->m_dTop && m_dBaselinePos > oSrc->m_dBaselinePos && m_dTop < oSrc->m_dBaselinePos)
{
return eVerticalCrossingType::vctCurrentBelowNext;
}
else if (m_dTop == oSrc->m_dTop && m_dBaselinePos == oSrc->m_dBaselinePos &&
m_dLeft == oSrc->m_dLeft && m_dRight == oSrc->m_dRight)
{
return eVerticalCrossingType::vctDublicate;
}
else if (fabs(m_dTop - oSrc->m_dTop) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
return eVerticalCrossingType::vctTopBordersMatch;
}
else if (fabs(m_dBaselinePos - oSrc->m_dBaselinePos) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
return eVerticalCrossingType::vctBottomBordersMatch;
}
else if (m_dBaselinePos < oSrc->m_dTop)
{
return eVerticalCrossingType::vctNoCrossingCurrentAboveNext;
}
else if (m_dTop > oSrc->m_dBaselinePos)
{
return eVerticalCrossingType::vctNoCrossingCurrentBelowNext;
}
else
{
return eVerticalCrossingType::vctUnknown;
}
}
eHorizontalCrossingType CBaseItem::GetHorizontalCrossingType(const CBaseItem* oSrc)
{
if (m_dLeft > oSrc->m_dLeft && m_dRight < oSrc->m_dRight)
{
return eHorizontalCrossingType::hctCurrentInsideNext;
}
else if (m_dLeft < oSrc->m_dLeft && m_dRight > oSrc->m_dRight)
{
return eHorizontalCrossingType::hctCurrentOutsideNext;
}
else if (m_dLeft < oSrc->m_dLeft && m_dRight < oSrc->m_dRight && m_dRight > oSrc->m_dLeft)
{
return eHorizontalCrossingType::hctCurrentLeftOfNext;
}
else if (m_dLeft > oSrc->m_dLeft && m_dRight > oSrc->m_dRight && m_dLeft < oSrc->m_dRight)
{
return eHorizontalCrossingType::hctCurrentRightOfNext;
}
else if (m_dLeft == oSrc->m_dLeft && m_dRight == oSrc->m_dRight &&
m_dTop == oSrc->m_dTop && m_dBaselinePos == oSrc->m_dBaselinePos)
{
return eHorizontalCrossingType::hctDublicate;
}
else if (fabs(m_dLeft - oSrc->m_dLeft) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
return eHorizontalCrossingType::hctLeftBordersMatch;
}
else if (fabs(m_dRight - oSrc->m_dRight) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
return eHorizontalCrossingType::hctRightBordersMatch;
}
else if (m_dRight < oSrc->m_dLeft)
{
return eHorizontalCrossingType::hctNoCrossingCurrentLeftOfNext;
}
else if (m_dLeft > oSrc->m_dRight)
{
return eHorizontalCrossingType::hctNoCrossingCurrentRightOfNext;
}
else
{
return eHorizontalCrossingType::hctUnknown;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
#pragma once
#include "elements/Paragraph.h"
#include "elements/Table.h"
#include "elements/Shape.h"
#include "managers/ImageManager.h"
#include "managers/FontStyleManager.h"
@ -18,47 +19,34 @@ namespace NSDocxRenderer
CManagers(const CManagers& other) = default;
~CManagers() = default;
CImageManager* pImageManager;
CFontStyleManager* pFontStyleManager;
CParagraphStyleManager* pParagraphStyleManager;
CFontManager* pFontManager;
CFontSelector* pFontSelector;
CImageManager* pImageManager;
CFontStyleManager* pFontStyleManager;
CParagraphStyleManager* pParagraphStyleManager;
CFontManager* pFontManager;
CFontSelector* pFontSelector;
};
double m_dWidth {0.0};
double m_dHeight {0.0};
double m_dHeight{0.0};
LONG m_lCurrentCommand{0};
LONG m_lClipMode{0};
LONG m_lClipMode {0};
TextAssociationType m_eTextAssociationType{TextAssociationType::tatPlainParagraph};
TextAssociationType m_eTextAssociationType{TextAssociationType::tatPlainParagraph};
NSFonts::IApplicationFonts* m_pAppFonts{nullptr};
NSStructures::CFont m_oFont;
NSStructures::CPen m_oPen;
NSStructures::CBrush m_oBrush;
NSStructures::CShadow m_oShadow;
NSStructures::CEdgeText m_oEdgeText;
Aggplus::CMatrix m_oTransform;
CManagers m_oManagers;
CVectorGraphics m_oCurrVectorGraphics, m_oClipVectorGraphics;
CContTextBuilder m_oContBuilder;
std::vector<std::shared_ptr<CContText>> m_arConts;
std::vector<std::shared_ptr<CTextLine>> m_arTextLines;
std::vector<std::shared_ptr<CContText>> m_arDiacriticalSymbols;
std::vector<std::shared_ptr<CShape>> m_arShapes;
std::vector<std::wstring> m_arCompleteObjectsXml;
std::vector<std::shared_ptr<CBaseItem>> m_arOutputObjects;
NSStructures::CFont m_oFont{};
NSStructures::CPen m_oPen{};
NSStructures::CBrush m_oBrush{};
NSStructures::CShadow m_oShadow{};
NSStructures::CEdgeText m_oEdgeText{};
Aggplus::CMatrix m_oTransform{};
bool m_bIsDeleteTextClipPage{true};
bool m_bIsRecalcFontSize {true};
bool m_bIsGradient {false};
bool m_bUseDefaultFont {false};
bool m_bWriteStyleRaw {false};
bool m_bIsBuildTables {false};
CPage(NSFonts::IApplicationFonts* pAppFonts, const CManagers& oManagers);
~CPage();
@ -67,7 +55,6 @@ namespace NSDocxRenderer
void EndCommand(DWORD lType);
void Clear();
void DeleteTextClipPage();
void WriteImage(const std::shared_ptr<CImageInfo> pInfo, double& fX, double& fY, double& fWidth, double& fHeight);
@ -77,8 +64,8 @@ namespace NSDocxRenderer
void PathStart();
void PathEnd();
void PathClose();
void DrawPath(LONG lType, const std::shared_ptr<CImageInfo> pInfo);
void AddText(
const PUINT pUnicodes,
const PUINT pGids,
@ -91,50 +78,134 @@ namespace NSDocxRenderer
void Analyze();
void Record(NSStringUtils::CStringBuilder& oWriter, bool bIsLastPage);
void ReorderShapesForPptx();
std::vector<std::wstring> GetXmlShapes();
std::vector<std::wstring> GetXmlShapesPptx();
void AddCompleteXml(const std::wstring oXml);
private:
void BuildDiacriticalSymbols();
void BuildTextLines();
using shape_ptr_t = std::shared_ptr<CShape>;
using cont_ptr_t = std::shared_ptr<CContText>;
using line_ptr_t = std::shared_ptr<CTextLine>;
using item_ptr_t = std::shared_ptr<CBaseItem>;
using paragraph_ptr_t = std::shared_ptr<CParagraph>;
using table_ptr_t = std::shared_ptr<CTable>;
// returns std::vector of conts with diac. symbols and remove it from m_arConts
std::vector<cont_ptr_t> MoveDiacriticalSymbols();
// returns std::vector of text lines builded from m_arConts
std::vector<line_ptr_t> BuildTextLines();
// returns std::vector of paragraphs builded from m_arTextLines
std::vector<paragraph_ptr_t> BuildParagraphs();
// returns std::vector of tables builded from shapes and paragraphes
std::vector<table_ptr_t> BuildTables();
// returns std::vector of cells for tables
std::vector<CTable::cell_ptr_t> BuildCells();
// returns std::vector of rows for tables
std::vector<CTable::row_ptr_t> BuildRows(std::vector<CTable::cell_ptr_t>& arCells);
// returns std::vector of base items builded from m_arParagraphs
std::vector<item_ptr_t> BuildOutputObjects();
// analyze shapes (set lines type)
void AnalyzeShapes();
// analyze type of lines (double, wave, etc.)
void AnalyzeLinesType();
// analyze m_arTextLines and add effects, adds diac, super-sub scripts etc.
void AnalyzeTextLines();
void SplitLines();
void CalcSelected();
void BuildParagraphes();
std::vector<std::vector<std::shared_ptr<CTextLine>>> GetLinesByGroups();
// analyze drop caps (creates shapes)
void AnalyzeDropCaps();
void MergeShapes();
void CalcShapesRotation();
// analyze conts in text lines
void AnalyzeConts();
// strikeouts, underlines, highlights, outline
void AnalyzeEffects();
bool IsLineCrossingText(std::shared_ptr<CShape> pShape, std::shared_ptr<CContText> pCont);
bool IsLineBelowText(std::shared_ptr<CShape> pShape, std::shared_ptr<CContText> pCont);
bool IsHighlight(std::shared_ptr<CShape> pShape, std::shared_ptr<CContText> pCont);
bool IsOutline(std::shared_ptr<CShape> pShape, std::shared_ptr<CContText> pCont);
void AnalyzeDropCaps();
void AnalyzeConts();
// adds diacritical symbols in conts
void AddDiacriticalSymbols();
void MergeLinesByVertAlignType();
void AnalyzeShapes();
void DetermineLinesType();
// super-sub scripts line merge
void MergeTextLinesByVatType();
// remove out of bounds text lines
void DeleteTextClipPage();
// merging conts in text lines
void MergeConts();
// get horizontal and vertical lines from shapes
void GetHorVerLines();
// set dominant shapes
void DetermineDominantGraphics();
bool IsShapeBorderBetweenVertical(std::shared_ptr<CTextLine> pFirst, std::shared_ptr<CTextLine> pSecond) const noexcept;
bool IsShapeBorderBetweenHorizontal(std::shared_ptr<CTextLine> pFirst, std::shared_ptr<CTextLine> pSecond) const noexcept;
bool IsShapeBorderTrough(std::shared_ptr<CContText> pItem, double& dXCrossing, double& dYCrossing) const noexcept;
// split lines by graphics
void SplitLines();
std::shared_ptr<CShape> CreateSingleLineShape(std::shared_ptr<CTextLine>& pLine);
std::shared_ptr<CShape> CreateSingleParagraphShape(std::shared_ptr<CParagraph>& pParagraph);
// creates shapes from overlapping text lines
void AnalyzeOverlapLines();
// конвертим m_arImages, m_arShapes, m_arParagraphs в xml-строку
void ToXml(NSStringUtils::CStringBuilder& oWriter);
void WriteSectionToFile(bool bLastPage, NSStringUtils::CStringBuilder& oWriter);
// calc selected sizes of conts
void CalcSelected();
// merge shapes with each other
void MergeShapes();
// calc true shapes rotation for ooxml format
void CalcShapesRotation();
// for drawingml is no tag behind-doc - so we need to reorder shapes
void ReorderShapesForPptx();
// get lines by groups by X
std::vector<std::vector<line_ptr_t>> GetLinesByGroups();
bool IsLineCrossingText(shape_ptr_t pShape, cont_ptr_t pCont) const noexcept;
bool IsLineBelowText(shape_ptr_t pShape, cont_ptr_t pCont) const noexcept;
bool IsHighlight(shape_ptr_t pShape, cont_ptr_t pCont) const noexcept;
bool IsOutline(shape_ptr_t pShape, cont_ptr_t pCont) const noexcept;
bool IsVerticalLineBetween(item_ptr_t pFirst, item_ptr_t pSecond) const noexcept;
bool IsHorizontalLineBetween(item_ptr_t pFirst, item_ptr_t pSecond) const noexcept;
bool IsVerticalLineBetween(line_ptr_t pFirst, line_ptr_t pSecond) const noexcept;
bool IsHorizontalLineBetween(line_ptr_t pFirst, line_ptr_t pSecond) const noexcept;
bool IsVerticalLineTrough(item_ptr_t pFirst) const noexcept;
bool IsHorizontalLineTrough(item_ptr_t pFirst) const noexcept;
void ToXml(NSStringUtils::CStringBuilder& oWriter) const noexcept;
void WriteSectionToFile(bool bLastPage, NSStringUtils::CStringBuilder& oWriter) const noexcept;
static shape_ptr_t CreateSingleLineShape(line_ptr_t& pLine);
static shape_ptr_t CreateSingleParagraphShape(paragraph_ptr_t& pParagraph);
CManagers m_oManagers;
CVectorGraphics m_oCurrVectorGraphics;
CVectorGraphics m_oClipVectorGraphics;
CContTextBuilder m_oContBuilder;
CHorVerLinesCollector m_oHorVerLinesCollector;
std::vector<cont_ptr_t> m_arConts;
std::vector<line_ptr_t> m_arTextLines;
std::vector<cont_ptr_t> m_arDiacriticalSymbols;
std::vector<shape_ptr_t> m_arShapes;
std::vector<paragraph_ptr_t> m_arParagraphs;
std::vector<table_ptr_t> m_arTables;
std::vector<item_ptr_t> m_arOutputObjects;
std::vector<std::wstring> m_arCompleteObjectsXml;
size_t m_nShapeOrder = 0;
};

View File

@ -1,6 +1,4 @@
#pragma once
#include <vector>
#include <memory>
#include "../../../../DesktopEditor/common/StringBuilder.h"

View File

@ -6,18 +6,6 @@
namespace NSDocxRenderer
{
bool IsTextOnlySpaces(const NSStringUtils::CStringUTF32& oText)
{
bool only_spaces = true;
for (size_t j = 0; j < oText.length(); ++j)
if (!CContText::IsUnicodeSpace(oText.at(j)))
{
only_spaces = false;
break;
}
return only_spaces;
}
CSelectedSizes::CSelectedSizes(const CSelectedSizes& oSelectedSizes)
{
*this = oSelectedSizes;
@ -108,8 +96,13 @@ namespace NSDocxRenderer
double dBoxWidth;
double dBoxHeight;
m_pManager->SetStringGid(0);
m_pManager->MeasureString(m_oText.ToStdWString(), 0, 0, dBoxX, dBoxY, dBoxWidth, dBoxHeight, CFontManager::mtPosition);
if (m_oText.ToStdWString() == L" ")
dBoxWidth = m_pManager->GetSpaceWidthMM();
else
{
m_pManager->SetStringGid(0);
m_pManager->MeasureString(m_oText.ToStdWString(), 0, 0, dBoxX, dBoxY, dBoxWidth, dBoxHeight, CFontManager::mtPosition);
}
m_oSelectedSizes.dWidth = dBoxWidth;
m_oSelectedSizes.dHeight = dBoxHeight;
@ -544,7 +537,19 @@ namespace NSDocxRenderer
bool CContText::IsOnlySpaces() const
{
return IsTextOnlySpaces(m_oText);
bool only_spaces = true;
for (size_t j = 0; j < m_oText.length(); ++j)
if (!CContText::IsUnicodeSpace(m_oText.at(j)))
{
only_spaces = false;
break;
}
return only_spaces;
}
bool CContText::IsDiacritical() const noexcept
{
const auto& text = GetText();
return text.length() == 1 && CContText::IsUnicodeDiacriticalMark(text.at(0));
}
void CContText::AddTextBack(const NSStringUtils::CStringUTF32& oText, const std::vector<double>& arSymWidths)
@ -831,7 +836,14 @@ namespace NSDocxRenderer
return is_bullet || is_another;
}
bool CContText::IsUnicodeEnumEnd(uint32_t cSym)
{
return cSym == 0x29 || cSym == 0x2e;
}
bool CContText::IsUnicodeNumber(uint32_t cSym)
{
return cSym >= 0x30 && cSym <= 0x39;
}
bool CContText::IsUnicodeSpace(uint32_t cSym)
{
return (0x20 == cSym || 0xA0 == cSym || 0x2003 == cSym);

View File

@ -117,6 +117,7 @@ namespace NSDocxRenderer
bool IsDuplicate(CContText* pCont, eVerticalCrossingType eVType, eHorizontalCrossingType eHType) const noexcept;
bool IsOnlySpaces() const;
bool IsDiacritical() const noexcept;
double CalculateSpace() const noexcept;
// check font effect and delete not needed cont
@ -135,6 +136,8 @@ namespace NSDocxRenderer
static bool IsUnicodeRtl(uint32_t cSym);
static bool IsUnicodeBullet(uint32_t cSym);
static bool IsUnicodeEnumEnd(uint32_t cSym);
static bool IsUnicodeNumber(uint32_t cSym);
static bool IsUnicodeSpace(uint32_t c);
static bool IsUnicodeSymbol(uint32_t symbol);
static bool IsUnicodeDiacriticalMark(uint32_t symbol);
@ -154,7 +157,7 @@ namespace NSDocxRenderer
CContTextBuilder(CFontStyleManager* pFontStyleManager, CFontSelector* pFontSelector);
~CContTextBuilder() = default;
// after call CContTextBuilder is empty.
// after call CContTextBuilder is empty
std::vector<cont_ptr_t> GetConts();
void AddUnicode(
double dTop,

View File

@ -9,6 +9,15 @@ namespace NSDocxRenderer
{
UINT CShape::m_gRelativeHeight = c_iStandartRelativeHeight;
unsigned int ClampUIntSign(const double& value)
{
if (value < 0)
return 0;
if (value > 0x7FFFFFFF)
return 0x7FFFFFFF;
return (unsigned int)value;
}
CShape::CShape()
{
m_nRelativeHeight = m_gRelativeHeight;
@ -234,69 +243,49 @@ namespace NSDocxRenderer
void CShape::DetermineGraphicsType(double dWidth, double dHeight,size_t nPeacks, size_t nCurves) noexcept
{
//note параллельно для каждой текстовой строки создается шейп, который содержит цвет фона для данного текста.
if ((m_bIsNoStroke && m_bIsNoFill) ||
(m_oBrush.Color1 == c_iWhiteColor && m_oPen.Color == c_iWhiteColor))
{
if ((m_bIsNoStroke && m_bIsNoFill) || (m_oBrush.Color1 == c_iWhiteColor && m_oPen.Color == c_iWhiteColor))
m_eGraphicsType = eGraphicsType::gtNoGraphics;
}
else if ((nPeacks == 5 || nPeacks == 2) && !nCurves) //1 move + 4 Peacks или 2 Peacks
{
m_eGraphicsType = eGraphicsType::gtRectangle;
if (dHeight < 0.7)
{
if (dWidth > 2.0) //note длинное тире - 2.8mm у times new roman
{
if (dWidth > 2.0) // длинное тире - 2.8mm у times new roman
m_eSimpleLineType = eSimpleLineType::sltHLongDash;
}
else if (dWidth > 0.7) //минимальное тире - 0.75mm у dotDotDash
{
else if (dWidth > 0.7) // минимальное тире - 0.75mm у dotDotDash
m_eSimpleLineType = eSimpleLineType::sltHDash;
}
else //максимальная точка - 0.5mm
{
m_eSimpleLineType = eSimpleLineType::sltHDot;
}
else
m_eSimpleLineType = eSimpleLineType::sltHDot; // максимальная точка - 0.5mm
}
else if (dWidth < 0.7)
{
if (dHeight > 2.0) //note длинное тире - 2.8mm у times new roman
{
if (dHeight > 2.0) // длинное тире - 2.8mm у times new roman
m_eSimpleLineType = eSimpleLineType::sltVLongDash;
}
else if (dHeight > 0.7) //минимальное тире - 0.75mm у dotDotDash
{
else if (dHeight > 0.7) // минимальное тире - 0.75mm у dotDotDash
m_eSimpleLineType = eSimpleLineType::sltVDash;
}
else //максимальна точка - 0.5mm
{
m_eSimpleLineType = eSimpleLineType::sltVDot;
}
else
m_eSimpleLineType = eSimpleLineType::sltVDot; // максимальна точка - 0.5mm
}
}
else if (nCurves > 0 && nPeacks <= 1) //1 move
else if (nCurves > 0 && nPeacks <= 1) // 1 move
{
m_eGraphicsType = eGraphicsType::gtCurve;
if (dHeight < dWidth)
{
m_eSimpleLineType = eSimpleLineType::sltHWave;
}
else
{
m_eSimpleLineType = eSimpleLineType::sltVWave;
}
}
else if (nCurves > 0 && nPeacks > 1)
{
m_eGraphicsType = eGraphicsType::gtComplicatedFigure;
}
}
bool CShape::IsItFitLine() const noexcept
{
return (m_eGraphicsType == eGraphicsType::gtRectangle && (m_eSimpleLineType == eSimpleLineType::sltHDot || m_eSimpleLineType == eSimpleLineType::sltHDash || m_eSimpleLineType == eSimpleLineType::sltHLongDash)) ||
(m_eGraphicsType == eGraphicsType::gtCurve && m_eSimpleLineType == eSimpleLineType::sltHWave);
return (m_eGraphicsType == eGraphicsType::gtRectangle && (
m_eSimpleLineType == eSimpleLineType::sltHDot ||
m_eSimpleLineType == eSimpleLineType::sltHDash ||
m_eSimpleLineType == eSimpleLineType::sltHLongDash)) ||
(m_eGraphicsType == eGraphicsType::gtCurve && m_eSimpleLineType == eSimpleLineType::sltHWave);
}
bool CShape::IsCorrelated(std::shared_ptr<const CShape> pShape) const noexcept
@ -323,7 +312,7 @@ namespace NSDocxRenderer
void CShape::CheckLineType(std::shared_ptr<CShape>& pFirstShape)
{
if(!pFirstShape)
if (!pFirstShape)
return;
if (pFirstShape->m_eLineType == eLineType::ltUnknown && pFirstShape->m_eSimpleLineType == eSimpleLineType::sltHLongDash)
@ -338,103 +327,68 @@ namespace NSDocxRenderer
return;
if (!pFirstShape->IsItFitLine() || !pSecondShape->IsItFitLine() || !pFirstShape->IsCorrelated(pSecondShape) ||
fabs(pFirstShape->m_dHeight - pSecondShape->m_dHeight) > c_dGRAPHICS_ERROR_IN_LINES_MM) // линия должна быть одного размера по высоте
fabs(pFirstShape->m_dHeight - pSecondShape->m_dHeight) > c_dGRAPHICS_ERROR_IN_LINES_MM)
{
return; // линия должна быть одного размера по высоте
}
auto set_line_type = [] (std::shared_ptr<CShape>& master, std::shared_ptr<CShape>& slave, eLineType type) {
master->m_eLineType = type;
master->RecalcWithNewItem(slave.get());
master->m_oVector.Join(std::move(slave->m_oVector));
slave = nullptr;
};
// проверка на двойную линию
if (pFirstShape->m_eLineType == eLineType::ltDouble)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
set_line_type(pFirstShape, pSecondShape, eLineType::ltDouble);
else
set_line_type(pSecondShape, pFirstShape, eLineType::ltDouble);
return;
}
if (pFirstShape->m_eLineType == eLineType::ltWavyDouble)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
set_line_type(pFirstShape, pSecondShape, eLineType::ltWavyDouble);
else
set_line_type(pSecondShape, pFirstShape, eLineType::ltWavyDouble);
return;
}
// проверка на двойную линию
if (pFirstShape->m_eLineType == eLineType::ltDouble || pFirstShape->m_eLineType == eLineType::ltWavyDouble)
{
if (pFirstShape->m_eLineType == eLineType::ltDouble)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
{
pFirstShape->m_eLineType = eLineType::ltDouble;
pFirstShape->RecalcWithNewItem(pSecondShape.get());
pFirstShape->m_oVector.Join(std::move(pSecondShape->m_oVector));
pSecondShape = nullptr;
}
else
{
pSecondShape->m_eLineType = eLineType::ltDouble;
pSecondShape->RecalcWithNewItem(pFirstShape.get());
pSecondShape->m_oVector.Join(std::move(pFirstShape->m_oVector));
pFirstShape = nullptr;
}
}
else if (pFirstShape->m_eLineType == eLineType::ltWavyDouble)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
{
pFirstShape->m_eLineType = eLineType::ltWavyDouble;
pFirstShape->RecalcWithNewItem(pSecondShape.get());
pFirstShape->m_oVector.Join(std::move(pSecondShape->m_oVector));
pSecondShape = nullptr;
}
else
{
pSecondShape->m_eLineType = eLineType::ltWavyDouble;
pSecondShape->RecalcWithNewItem(pFirstShape.get());
pSecondShape->m_oVector.Join(std::move(pFirstShape->m_oVector));
pFirstShape = nullptr;
}
}
return;
}
else if (fabs(pFirstShape->m_dTop - pSecondShape->m_dTop) < c_dGRAPHICS_ERROR_IN_LINES_MM * 5 &&
fabs(pFirstShape->m_dWidth - pSecondShape->m_dWidth) < c_dGRAPHICS_ERROR_IN_LINES_MM &&
fabs(pFirstShape->m_dLeft - pSecondShape->m_dLeft) < c_dGRAPHICS_ERROR_IN_LINES_MM)
{
//Условие первого определения
// условие первого определения
if (pFirstShape->m_eSimpleLineType == eSimpleLineType::sltHLongDash && pSecondShape->m_eSimpleLineType == eSimpleLineType::sltHLongDash)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
{
pFirstShape->m_eLineType = eLineType::ltDouble;
pFirstShape->RecalcWithNewItem(pSecondShape.get());
pFirstShape->m_oVector.Join(std::move(pSecondShape->m_oVector));
pSecondShape = nullptr;
}
set_line_type(pFirstShape, pSecondShape, eLineType::ltDouble);
else
{
pSecondShape->m_eLineType = eLineType::ltDouble;
pSecondShape->RecalcWithNewItem(pFirstShape.get());
pSecondShape->m_oVector.Join(std::move(pFirstShape->m_oVector));
pFirstShape = nullptr;
}
set_line_type(pSecondShape, pFirstShape, eLineType::ltDouble);
}
else if (pFirstShape->m_eSimpleLineType == eSimpleLineType::sltHWave && pSecondShape->m_eSimpleLineType == eSimpleLineType::sltHWave)
{
if (pFirstShape->m_dTop < pSecondShape->m_dTop)
{
pFirstShape->m_eLineType = eLineType::ltWavyDouble;
pFirstShape->RecalcWithNewItem(pSecondShape.get());
pFirstShape->m_oVector.Join(std::move(pSecondShape->m_oVector));
pSecondShape = nullptr;
}
set_line_type(pFirstShape, pSecondShape, eLineType::ltWavyDouble);
else
{
pSecondShape->m_eLineType = eLineType::ltWavyDouble;
pSecondShape->RecalcWithNewItem(pFirstShape.get());
pSecondShape->m_oVector.Join(std::move(pFirstShape->m_oVector));
pFirstShape = nullptr;
}
set_line_type(pSecondShape, pFirstShape, eLineType::ltWavyDouble);
}
return;
}
else if (fabs(pFirstShape->m_dTop - pSecondShape->m_dTop) > c_dGRAPHICS_ERROR_IN_LINES_MM)
{
// все должно быть на одной линии
return;
}
return; // все должно быть на одной линии
// теперь считаем, что графика находится на одной линии
if (fabs(pFirstShape->m_dLeft +pFirstShape->m_dWidth - pSecondShape->m_dLeft) > c_dGRAPHICS_ERROR_IN_LINES_MM * 5)
// расстояние между объектами на одной линии должно быть небольшим
if (fabs(pFirstShape->m_dLeft + pFirstShape->m_dWidth - pSecondShape->m_dLeft) > c_dGRAPHICS_ERROR_IN_LINES_MM * 5)
{
// расстояние между объектами на одной линии должно быть небольшим
if (pFirstShape->m_eLineType == eLineType::ltUnknown && pFirstShape->m_eSimpleLineType == eSimpleLineType::sltHLongDash)
pFirstShape->m_eLineType =pFirstShape-> m_dHeight > 0.3 ? eLineType::ltThick : eLineType::ltSingle;
pFirstShape->m_eLineType = pFirstShape-> m_dHeight > 0.3 ? eLineType::ltThick : eLineType::ltSingle;
else if (pFirstShape->m_eLineType == eLineType::ltUnknown && pFirstShape->m_eSimpleLineType == eSimpleLineType::sltHWave)
pFirstShape->m_eLineType = pFirstShape->m_oPen.Size > 0.3 ? eLineType::ltWavyHeavy : eLineType::ltWave;
@ -924,6 +878,27 @@ namespace NSDocxRenderer
}
oWriter.WriteString(L"</a:solidFill>");
if (m_oPen.DashStyle == Aggplus::DashStyleCustom)
{
// dash pattern
std::vector<double> dash_pattern(m_oPen.Count);
long count = m_oPen.Count;
m_oPen.GetDashPattern(dash_pattern.data(), count);
oWriter.WriteString(L"<a:custDash>");
for (size_t i = 0; i < count; i+= 2)
{
double to_percentage = 100.0 * 1000.0 / m_oPen.Size;
oWriter.WriteString(L"<a:ds d=\"");
oWriter.AddUInt(ClampUIntSign(dash_pattern[i] * to_percentage));
oWriter.WriteString(L"\" ");
oWriter.WriteString(L"sp=\"");
oWriter.AddUInt(ClampUIntSign(dash_pattern[i + 1] * to_percentage));
oWriter.WriteString(L"\" />");
}
oWriter.WriteString(L"</a:custDash>");
}
// Aggplus::DashStyleSolid
oWriter.WriteString(L"</a:ln>");
}
}
@ -1072,6 +1047,4 @@ namespace NSDocxRenderer
}
oWriter.WriteString(L"</p:sp>");
}
}; // namespace NSDocxRenderer

View File

@ -1,4 +1,7 @@
#pragma once
#include <memory>
#include "../../../../DesktopEditor/graphics/structures.h"
#include "../../resources/ImageInfo.h"
@ -62,7 +65,6 @@ namespace NSDocxRenderer
std::vector<std::shared_ptr<CBaseItem>> m_arOutputObjects;
public:
CShape();
CShape(std::shared_ptr<CImageInfo> pInfo, const std::wstring& strDstMedia);

View File

@ -0,0 +1,127 @@
#include "Table.h"
#include "../../resources/SingletonTemplate.h"
#include "../../resources/utils.h"
namespace NSDocxRenderer
{
void CTable::CCell::Clear()
{
m_arParagraphs.clear();
}
void CTable::CCell::ToXml(NSStringUtils::CStringBuilder& oWriter) const
{
oWriter.WriteString(L"<w:tc>");
oWriter.WriteString(L"<w:tcPr>");
oWriter.WriteString(L"<w:tcW w:w=\"");
oWriter.AddUInt(static_cast<unsigned int>(m_dWidth * c_dMMToDx));
oWriter.WriteString(L"\"w:type=\"dxa\"/>");
oWriter.WriteString(L"<w:tcBorders>");
auto write_border = [&oWriter] (const CBorder& border, const std::wstring& prefix) {
oWriter.WriteString(L"<w:");
oWriter.WriteString(prefix);
oWriter.WriteString(L" w:val=");
oWriter.WriteString(SingletonInstance<LinesTable>().ConvertLineToString(border.lineType));
oWriter.WriteString(L" w:sz=\"");
oWriter.AddUInt(static_cast<unsigned int>(border.dWidth * c_dMMToPt / 8));
oWriter.WriteString(L"\" w:space=\"");
oWriter.AddUInt(static_cast<unsigned int>(border.dSpacing * c_dMMToPt));
oWriter.WriteString(L"\" w:color=\"");
oWriter.WriteHexInt3(ConvertColorBGRToRGB(border.lColor));
oWriter.WriteString(L"\" />");
};
write_border(m_oBorderTop, L"top");
write_border(m_oBorderBot, L"bot");
write_border(m_oBorderLeft, L"left");
write_border(m_oBorderRight, L"right");
oWriter.WriteString(L"</w:tcBorders>");
oWriter.WriteString(L"</w:tcPr>");
for (const auto& p : m_arParagraphs)
p->ToXml(oWriter);
oWriter.WriteString(L"</w:tc>");
}
void CTable::CCell::ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const
{
}
void CTable::CCell::AddParagraph(const paragraph_ptr_t& pParagraph)
{
m_arParagraphs.push_back(pParagraph);
}
void CTable::CRow::Clear()
{
m_arCells.clear();
}
void CTable::CRow::ToXml(NSStringUtils::CStringBuilder& oWriter) const
{
oWriter.WriteString(L"<w:tr>");
oWriter.WriteString(L"<w:trPr>");
oWriter.WriteString(L"<w:trHeight w:val=\"");
oWriter.AddUInt(static_cast<unsigned int>(m_dHeight * c_dMMToDx));
oWriter.WriteString(L"\" w:hRule=\"exact\"/>");
oWriter.WriteString(L"</w:trPr>");
for (const auto& c : m_arCells)
c->ToXml(oWriter);
oWriter.WriteString(L"</w:tr>");
}
void CTable::CRow::ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const
{
}
void CTable::CRow::AddCell(const cell_ptr_t& pCell)
{
CBaseItem::RecalcWithNewItem(pCell.get());
m_arCells.push_back(pCell);
}
bool CTable::CRow::IsEmpty() const
{
return m_arCells.empty();
}
void CTable::Clear()
{
m_arRows.clear();
}
void CTable::ToXml(NSStringUtils::CStringBuilder& oWriter) const
{
oWriter.WriteString(L"<w:tbl>");
oWriter.WriteString(L"<w:tblPr>");
oWriter.WriteString(L"<w:tblW w:w=\"");
oWriter.AddUInt(static_cast<unsigned int>(m_dWidth * c_dMMToDx));
oWriter.WriteString(L"\"w:type=\"dxa\"/>");
oWriter.WriteString(L"</w:tblPr>");
oWriter.WriteString(L"<w:tblGrid>");
oWriter.WriteString(L"</w:tblGrid>");
for (const auto& r : m_arRows)
r->ToXml(oWriter);
oWriter.WriteString(L"</w:tbl>");
}
void CTable::ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const
{
}
void CTable::AddRow(const row_ptr_t& pRow)
{
CBaseItem::RecalcWithNewItem(pRow.get());
m_arRows.push_back(pRow);
}
bool CTable::IsEmpty() const
{
return m_arRows.empty();
}
} // namespace NSDocxRenderer

View File

@ -0,0 +1,82 @@
#pragma once
#include <vector>
#include <memory>
#include "BaseItem.h"
#include "Paragraph.h"
#include "../../resources/LinesTable.h"
namespace NSDocxRenderer
{
class CTable : public CBaseItem
{
public:
class CCell;
class CRow;
using cell_ptr_t = std::shared_ptr<CCell>;
using row_ptr_t = std::shared_ptr<CRow>;
using paragraph_ptr_t = std::shared_ptr<CParagraph>;
public:
class CCell : public CBaseItem
{
public:
struct CBorder
{
double dWidth{};
double dSpacing{};
long lColor{};
eLineType lineType{};
};
CCell() = default;
virtual ~CCell() = default;
virtual void Clear() override final;
virtual void ToXml(NSStringUtils::CStringBuilder& oWriter) const override final;
virtual void ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const override final;
void AddParagraph(const paragraph_ptr_t& pParagraph);
CBorder m_oBorderTop;
CBorder m_oBorderBot;
CBorder m_oBorderLeft;
CBorder m_oBorderRight;
private:
std::vector<paragraph_ptr_t> m_arParagraphs;
};
class CRow : public CBaseItem
{
public:
CRow() = default;
virtual ~CRow() = default;
virtual void Clear() override final;
virtual void ToXml(NSStringUtils::CStringBuilder& oWriter) const override final;
virtual void ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const override final;
void AddCell(const cell_ptr_t& pCell);
bool IsEmpty() const;
private:
std::vector<cell_ptr_t> m_arCells;
};
CTable() = default;
virtual ~CTable() = default;
virtual void Clear() override final;
virtual void ToXml(NSStringUtils::CStringBuilder& oWriter) const override final;
virtual void ToXmlPptx(NSStringUtils::CStringBuilder& oWriter) const override final;
void AddRow(const row_ptr_t& pRow);
bool IsEmpty() const;
private:
std::vector<row_ptr_t> m_arRows;
};
} // namespace NSDocxRenderer

View File

@ -37,6 +37,25 @@ namespace NSDocxRenderer
return true;
}
double CTextLine::GetLeftNoEnum() const noexcept
{
double left_no_enum = m_dLeft;
const auto& first_sym = m_arConts.front()->GetText().at(0);
size_t i = 0, j = 0;
GetNextSym(i, j);
if (CContText::IsUnicodeBullet(first_sym))
{
while (CContText::IsUnicodeSpace(m_arConts[i]->GetText().at(j)) && i && j) GetNextSym(i, j);
// one more time to get next
GetNextSym(i, j);
left_no_enum = (!i && !j) ? m_arConts.back()->m_dRight : m_arConts[i]->GetSymLefts().at(j);
}
return left_no_enum;
}
void CTextLine::MergeConts()
{
if (m_arConts.empty())
@ -97,9 +116,6 @@ namespace NSDocxRenderer
wide_space->m_pFontStyle = pFirst->m_pFontStyle;
wide_space->m_pShape = nullptr;
wide_space->m_iNumDuplicates = 0;
// cache that value? (calls rarely)
wide_space->CalcSelected();
};
if (bIsEqual)
@ -206,7 +222,7 @@ namespace NSDocxRenderer
m_dHeight = 0.0;
for (const auto& cont : m_arConts)
if(cont)
if (cont)
RecalcWithNewItem(cont.get());
}
@ -306,4 +322,21 @@ namespace NSDocxRenderer
return len;
}
void CTextLine::GetNextSym(size_t& nContPos, size_t& nSymPos) const noexcept
{
++nSymPos;
if (m_arConts[nContPos]->GetLength() <= nSymPos)
for (nContPos = nContPos + 1; nContPos < m_arConts.size(); ++nContPos)
if (m_arConts[nContPos] && m_arConts[nContPos]->GetLength() != 0)
{
nSymPos = 0;
break;
}
if (m_arConts.size() <= nContPos)
{
nContPos = 0;
nSymPos = 0;
}
}
}

View File

@ -50,6 +50,9 @@ namespace NSDocxRenderer
bool IsShadingPresent(const CTextLine* pLine) const noexcept;
bool IsCanBeDeleted() const;
double GetLeftNoEnum() const noexcept;
size_t GetLength() const;
void GetNextSym(size_t& nContPos, size_t& nSymPos) const noexcept;
};
}

View File

@ -1,7 +1,6 @@
#pragma once
#include "../../../../DesktopEditor/raster/BgraFrame.h"
#include "../../../../DesktopEditor/graphics/Image.h"
#include "../../resources/ImageInfo.h"
#include <map>
#include <memory>
#ifndef DOCXRENDERER_USE_DYNAMIC_LIBRARY

View File

@ -530,13 +530,15 @@ namespace NSDocxRenderer
RELEASEINTERFACE(m_pManager);
}
void CFontManager::LoadFontByFile(const NSStructures::CFont& oFont)
bool CFontManager::LoadFontByFile(const NSStructures::CFont& oFont)
{
if(m_oFont.IsEqual2(&oFont))
return;
if (m_oFont.IsEqual2(&oFont))
return true;
if (!m_pManager->LoadFontFromFile(oFont.Path, (int)oFont.FaceIndex, (float)oFont.Size, c_dDpiX, c_dDpiY))
return false;
m_oFont = oFont;
m_pManager->LoadFontFromFile(m_oFont.Path, (int)m_oFont.FaceIndex, (float)m_oFont.Size, c_dDpiX, c_dDpiY);
m_pManager->AfterLoad();
LoadFontMetrics();
@ -546,18 +548,24 @@ namespace NSDocxRenderer
m_oFontSelectParams.wsDefaultName = m_oFont.Name;
CheckPdfResources();
return true;
}
void CFontManager::LoadFontByName(const NSStructures::CFont& oFont)
bool CFontManager::LoadFontByName(const NSStructures::CFont& oFont)
{
if(m_oFont.IsEqual2(&oFont))
return;
if (m_oFont.IsEqual2(&oFont))
return true;
m_oFont = oFont;
m_pManager->LoadFontByName(m_oFont.Name, (float)m_oFont.Size, m_oFont.GetStyle2(), c_dDpiX, c_dDpiY);
m_pManager->AfterLoad();
if (!m_pManager->LoadFontByName(m_oFont.Name, (float)m_oFont.Size, m_oFont.GetStyle2(), c_dDpiX, c_dDpiY))
return false;
m_pManager->AfterLoad();
LoadFontMetrics();
LoadFontSelectParams();
return true;
}
const CFontSelectParams& CFontManager::GetFontSelectParams() const noexcept

View File

@ -117,8 +117,8 @@ namespace NSDocxRenderer
CFontManager(NSFonts::IApplicationFonts* pFonts);
~CFontManager();
void LoadFontByFile(const NSStructures::CFont& oFont);
void LoadFontByName(const NSStructures::CFont& oFont);
bool LoadFontByFile(const NSStructures::CFont& oFont);
bool LoadFontByName(const NSStructures::CFont& oFont);
const CFontSelectParams& GetFontSelectParams() const noexcept;
const CFontMetrics& GetFontMetrics() const noexcept;

View File

@ -1,6 +1,7 @@
#include "ImageManager.h"
#include "../../../../DesktopEditor/common/Directory.h"
#include "../../../../DesktopEditor/raster/BgraFrame.h"
#include "../../resources/Constants.h"

View File

@ -1,4 +1,7 @@
#pragma once
#include <map>
#include "../../../../DesktopEditor/common/CalculatorCRC32.h"
#include "ExternalImageStorage.h"

View File

@ -1,6 +1,5 @@
#pragma once
#include <list>
#include <memory>
#include "../elements/Paragraph.h"
#include "../styles/ParagraphStyle.h"

View File

@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <map>
#include <algorithm>
class ColorTable
{

View File

@ -1,8 +1,6 @@
#include "VectorGraphics.h"
#include <algorithm>
#include <string.h>
#include <numeric>
#include <limits>
#include "../../../DesktopEditor/graphics/Matrix.h"
@ -390,4 +388,50 @@ namespace NSDocxRenderer
return points;
}
CHorVerLinesCollector::CHorVerLine::CHorVerLine(const double& _min, const double& _max, const double& _pos)
{
min = _min;
max = _max;
pos = _pos;
}
const std::vector<CHorVerLinesCollector::CHorVerLine>& CHorVerLinesCollector::GetHorizontal() const
{
return m_arHorizontal;
}
const std::vector<CHorVerLinesCollector::CHorVerLine>& CHorVerLinesCollector::GetVertical() const
{
return m_arVertical;
}
void CHorVerLinesCollector::AddVector(const CVectorGraphics& oVector)
{
double last_x{};
double last_y{};
for (const auto& command : oVector.GetData())
{
if (command.type == CVectorGraphics::ePathCommandType::pctLine)
{
double x = command.points.front().x;
double y = command.points.front().y;
if (x - last_x <= std::numeric_limits<double>::epsilon())
m_arVertical.push_back({std::min(last_y, y), std::max(last_y, y), x});
else if (y - last_y <= std::numeric_limits<double>::epsilon())
m_arHorizontal.push_back({std::min(last_x, x), std::max(last_x, x), y});
}
if (!command.points.empty())
{
last_x = command.points.back().x;
last_y = command.points.back().y;
}
}
}
void CHorVerLinesCollector::Clear()
{
m_arVertical.clear();
m_arHorizontal.clear();
}
}

View File

@ -2,7 +2,6 @@
#include "../../../DesktopEditor/graphics/GraphicsPath.h"
#include <list>
#include <memory>
#include <array>
namespace NSDocxRenderer
@ -15,7 +14,8 @@ namespace NSDocxRenderer
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point(const Point& point) : x(point.x), y(point.y) {}
};
Point& operator=(const Point& point) {x = point.x; y = point.y; return *this;}
};;
class CVectorGraphics
{
@ -96,4 +96,31 @@ namespace NSDocxRenderer
static Aggplus::BooleanOpType GetOpType(long nClipType);
static std::vector<Point> GetPointsCurve(const std::array<Point, 4>& curve, double step = 0.05);
};
// collect and contains horizontal and vertical lines
class CHorVerLinesCollector
{
public:
struct CHorVerLine
{
double min{};
double max{};
double pos{};
CHorVerLine(const double& _min, const double& _max, const double& _pos);
};
CHorVerLinesCollector() = default;
~CHorVerLinesCollector() = default;
const std::vector<CHorVerLine>& GetHorizontal() const;
const std::vector<CHorVerLine>& GetVertical() const;
void AddVector(const CVectorGraphics& oVector);
void Clear();
private:
std::vector<CHorVerLine> m_arHorizontal;
std::vector<CHorVerLine> m_arVertical;
};
}

View File

@ -80,7 +80,7 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
if (nContent != std::wstring::npos)
{
nContent += 11;
sContent = sFileContent.substr(nContent, sFileContent.find(L'\"', nContent) - nContent);
sContent = sFileContent.substr(nContent, sFileContent.find_first_of(L"\"'", nContent) - nContent);
}
std::wstring sContentPath;

View File

@ -6,8 +6,6 @@
#include <vector>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <iterator>
#include "../Common/3dParty/html/htmltoxhtml.h"
#include "../Common/3dParty/html/css/src/CCssCalculator.h"
@ -63,6 +61,8 @@ const static double HTML_FONTS[7] = {7.5, 10, 12, 13.5, 18, 24, 36};
#define HtmlTag GumboTag
#define MAX_STRING_BLOCK_SIZE (size_t)10485760
const std::map<std::wstring, HtmlTag> m_HTML_TAGS
{
ADD_TAG(L"a", A),
@ -217,6 +217,27 @@ static inline HtmlTag GetHtmlTag(const std::wstring& wsStrTag)
return oFound->second;
}
static inline void WriteToStringBuilder(NSStringUtils::CStringBuilder& oSrcStringBuilder, NSStringUtils::CStringBuilder& oDstStringBuilder)
{
if (oSrcStringBuilder.GetCurSize() < MAX_STRING_BLOCK_SIZE)
{
oDstStringBuilder.Write(oSrcStringBuilder);
return;
}
size_t ulSize = oSrcStringBuilder.GetCurSize();
size_t ulCurrentBlockSize = 0, ulPosition = 0;
while (ulSize > 0)
{
ulCurrentBlockSize = std::min(ulSize, MAX_STRING_BLOCK_SIZE);
oDstStringBuilder.WriteString(oSrcStringBuilder.GetSubData(ulPosition, ulCurrentBlockSize));
ulSize -= ulCurrentBlockSize;
ulPosition += ulCurrentBlockSize;
}
}
// Ячейка таблицы
struct CTc
{
@ -591,7 +612,7 @@ public:
: m_unColspan(oCell.m_unColspan), m_unRowSpan(oCell.m_unRowSpan), m_bIsMerged(oCell.m_bIsMerged),
m_bIsEmpty(oCell.m_bIsEmpty), m_oStyles(oCell.m_oStyles)
{
m_oData.SetText(oCell.m_oData.GetData());
WriteToStringBuilder(oCell.m_oData, m_oData);
}
bool Empty()
@ -771,6 +792,7 @@ public:
if (1 != pCell->GetColspan())
{
++itFoundEmpty;
UINT unColspan = pCell->GetColspan() - 1;
while (m_arCells.end() != itFoundEmpty && (*itFoundEmpty)->Empty() && unColspan > 0)
@ -803,12 +825,13 @@ public:
{
delete m_arCells[nPosition];
--m_oStyles.m_unMaxIndex;
m_arCells[nPosition++] = pCell;
m_arCells[nPosition] = pCell;
if (1 != pCell->GetColspan())
{
++nPosition;
UINT unDeleteCount = pCell->GetColspan() - 1;
while (m_arCells[nPosition]->Empty() && nPosition < m_arCells.size() && unDeleteCount > 0)
while (nPosition < m_arCells.size() && m_arCells[nPosition]->Empty() && !m_arCells[nPosition]->Merged() && unDeleteCount > 0)
{
delete m_arCells[nPosition];
--m_oStyles.m_unMaxIndex;
@ -1082,7 +1105,7 @@ public:
void AddCaption(NSStringUtils::CStringBuilder& oCaption)
{
m_oCaption += oCaption.GetData();
WriteToStringBuilder(oCaption, m_oCaption);
}
void SetPadding(const NSCSS::NSProperties::CIndent& oPadding)
@ -1173,7 +1196,7 @@ public:
if (NULL == pCell)
continue;
pCell->SetColspan(unMaxIndex , MAXCOLUMNSINTABLE);
pCell->SetColspan(unMaxIndex, MAXCOLUMNSINTABLE);
continue;
}
@ -1185,9 +1208,9 @@ public:
if (NULL == pCell)
continue;
if (1 < pCell->GetColspan() && unIndex + pCell->GetColspan() > m_arMinColspan[unIndex])
if (1 < pCell->GetColspan() && pCell->GetColspan() > m_arMinColspan[unIndex])
{
pCell->SetColspan(m_arMinColspan[unIndex] - unIndex, MAXCOLUMNSINTABLE);
pCell->SetColspan(m_arMinColspan[unIndex], MAXCOLUMNSINTABLE);
continue;
}
@ -1220,42 +1243,40 @@ public:
RecalculateMaxColumns();
}
std::wstring ConvertToOOXML()
bool ConvertToOOXML(NSStringUtils::CStringBuilder& oStringBuilder)
{
if (m_arRows.empty())
return std::wstring();
return false;
NSStringUtils::CStringBuilder oTable;
oTable.WriteNodeBegin(L"w:tbl");
oTable.WriteNodeBegin(L"w:tblPr");
oStringBuilder.WriteNodeBegin(L"w:tbl");
oStringBuilder.WriteNodeBegin(L"w:tblPr");
if (!m_oStyles.m_oWidth.Empty() && !m_oStyles.m_oWidth.Zero())
{
if (NSCSS::UnitMeasure::Percent == m_oStyles.m_oWidth.GetUnitMeasure())
oTable += L"<w:tblW w:w=\"" + std::to_wstring(m_oStyles.m_oWidth.ToInt(NSCSS::UnitMeasure::Percent, 5000)) + L"\" w:type=\"pct\"/>";
oStringBuilder += L"<w:tblW w:w=\"" + std::to_wstring(m_oStyles.m_oWidth.ToInt(NSCSS::UnitMeasure::Percent, 5000)) + L"\" w:type=\"pct\"/>";
else
oTable += L"<w:tblW w:w=\"" + std::to_wstring(m_oStyles.m_oWidth.ToInt(NSCSS::UnitMeasure::Twips)) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:tblW w:w=\"" + std::to_wstring(m_oStyles.m_oWidth.ToInt(NSCSS::UnitMeasure::Twips)) + L"\" w:type=\"dxa\"/>";
}
else
oTable += L"<w:tblW w:w=\"0\" w:type=\"auto\"/>";
oStringBuilder += L"<w:tblW w:w=\"0\" w:type=\"auto\"/>";
if (!m_oStyles.m_oMargin.GetLeft().Empty() && !m_oStyles.m_oMargin.GetLeft().Zero())
{
if (NSCSS::UnitMeasure::Percent == m_oStyles.m_oMargin.GetLeft().GetUnitMeasure())
oTable += L"<w:tblInd w:w=\"" + std::to_wstring(m_oStyles.m_oMargin.GetLeft().ToInt(NSCSS::UnitMeasure::Percent, 5000)) + L"\" w:type=\"pct\"/>";
oStringBuilder += L"<w:tblInd w:w=\"" + std::to_wstring(m_oStyles.m_oMargin.GetLeft().ToInt(NSCSS::UnitMeasure::Percent, 5000)) + L"\" w:type=\"pct\"/>";
else
oTable += L"<w:tblInd w:w=\"" + std::to_wstring(m_oStyles.m_oMargin.GetLeft().ToInt(NSCSS::UnitMeasure::Twips)) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:tblInd w:w=\"" + std::to_wstring(m_oStyles.m_oMargin.GetLeft().ToInt(NSCSS::UnitMeasure::Twips)) + L"\" w:type=\"dxa\"/>";
}
if (!m_oStyles.m_wsAlign.empty())
oTable += L"<w:jc w:val=\"" + m_oStyles.m_wsAlign + L"\"/>";
oStringBuilder += L"<w:jc w:val=\"" + m_oStyles.m_wsAlign + L"\"/>";
if (0 < m_oStyles.m_nCellSpacing && m_oStyles.m_oBorder.GetCollapse() != NSCSS::NSProperties::BorderCollapse::Collapse)
oTable += L"<w:tblCellSpacing w:w=\"" + std::to_wstring(m_oStyles.m_nCellSpacing) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:tblCellSpacing w:w=\"" + std::to_wstring(m_oStyles.m_nCellSpacing) + L"\" w:type=\"dxa\"/>";
if (!m_oStyles.m_oBorder.Empty() && !m_oStyles.m_oBorder.Zero())
oTable += L"<w:tblBorders>" + CreateBorders(m_oStyles.m_oBorder, NULL, true, (TTableStyles::ETableRules::Groups == m_oStyles.m_enRules && !m_arColgroups.empty()) ? TTableStyles::ETableRules::Cols : m_oStyles.m_enRules) + L"</w:tblBorders>";
oStringBuilder += L"<w:tblBorders>" + CreateBorders(m_oStyles.m_oBorder, NULL, true, (TTableStyles::ETableRules::Groups == m_oStyles.m_enRules && !m_arColgroups.empty()) ? TTableStyles::ETableRules::Cols : m_oStyles.m_enRules) + L"</w:tblBorders>";
if (!m_oStyles.m_oPadding.Empty() && !m_oStyles.m_oPadding.Zero())
{
@ -1264,42 +1285,42 @@ public:
const int nBottomPadding = std::max(0, m_oStyles.m_oPadding.GetBottom().ToInt(NSCSS::UnitMeasure::Twips, DEFAULT_PAGE_HEIGHT));
const int nRightPadding = std::max(0, m_oStyles.m_oPadding.GetRight() .ToInt(NSCSS::UnitMeasure::Twips, DEFAULT_PAGE_WIDTH ));
oTable.WriteNodeBegin(L"w:tblCellMar");
oStringBuilder.WriteNodeBegin(L"w:tblCellMar");
if (0 != nTopPadding)
oTable += L"<w:top w:w=\"" + std::to_wstring(nTopPadding) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:top w:w=\"" + std::to_wstring(nTopPadding) + L"\" w:type=\"dxa\"/>";
if (0 != nLeftPadding)
oTable += L"<w:left w:w=\"" + std::to_wstring(nLeftPadding) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:left w:w=\"" + std::to_wstring(nLeftPadding) + L"\" w:type=\"dxa\"/>";
if (0 != nBottomPadding)
oTable += L"<w:bottom w:w=\"" + std::to_wstring(nBottomPadding) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:bottom w:w=\"" + std::to_wstring(nBottomPadding) + L"\" w:type=\"dxa\"/>";
if (0 != nRightPadding)
oTable += L"<w:right w:w=\"" + std::to_wstring(nRightPadding) + L"\" w:type=\"dxa\"/>";
oStringBuilder += L"<w:right w:w=\"" + std::to_wstring(nRightPadding) + L"\" w:type=\"dxa\"/>";
oTable.WriteNodeEnd(L"w:tblCellMar");
oStringBuilder.WriteNodeEnd(L"w:tblCellMar");
}
else
oTable += L"<w:tblCellMar><w:top w:w=\"15\" w:type=\"dxa\"/><w:left w:w=\"15\" w:type=\"dxa\"/><w:bottom w:w=\"15\" w:type=\"dxa\"/><w:right w:w=\"15\" w:type=\"dxa\"/></w:tblCellMar>";
oStringBuilder += L"<w:tblCellMar><w:top w:w=\"15\" w:type=\"dxa\"/><w:left w:w=\"15\" w:type=\"dxa\"/><w:bottom w:w=\"15\" w:type=\"dxa\"/><w:right w:w=\"15\" w:type=\"dxa\"/></w:tblCellMar>";
oTable += L"<w:tblLook w:val=\"04A0\" w:noVBand=\"1\" w:noHBand=\"0\" w:lastColumn=\"0\" w:firstColumn=\"1\" w:lastRow=\"0\" w:firstRow=\"1\"/>";
oTable.WriteNodeEnd(L"w:tblPr");
oStringBuilder += L"<w:tblLook w:val=\"04A0\" w:noVBand=\"1\" w:noHBand=\"0\" w:lastColumn=\"0\" w:firstColumn=\"1\" w:lastRow=\"0\" w:firstRow=\"1\"/>";
oStringBuilder.WriteNodeEnd(L"w:tblPr");
if (HaveCaption())
{
oTable.WriteNodeBegin(L"w:tr");
oTable.WriteNodeBegin(L"w:tc");
oTable.WriteNodeBegin(L"w:tcPr");
oTable += L"<w:tcW w:w=\"0\" w:type=\"auto\"/>";
oTable += L"<w:gridSpan w:val=\"" + std::to_wstring(m_unMaxColumns) + L"\"/>";
oTable += L"<w:tcBorders><w:top w:val=\"nil\"/><w:left w:val=\"nil\"/><w:bottom w:val=\"nil\"/><w:right w:val=\"nil\"/></w:tcBorders>";
oTable += L"<w:vAlign w:val=\"center\"/>";
oTable += L"<w:hideMark/>";
oTable.WriteNodeEnd(L"w:tcPr");
oTable.WriteString(m_oCaption.GetData());
oTable.WriteNodeEnd(L"w:tc");
oTable.WriteNodeEnd(L"w:tr");
oStringBuilder.WriteNodeBegin(L"w:tr");
oStringBuilder.WriteNodeBegin(L"w:tc");
oStringBuilder.WriteNodeBegin(L"w:tcPr");
oStringBuilder += L"<w:tcW w:w=\"0\" w:type=\"auto\"/>";
oStringBuilder += L"<w:gridSpan w:val=\"" + std::to_wstring(m_unMaxColumns) + L"\"/>";
oStringBuilder += L"<w:tcBorders><w:top w:val=\"nil\"/><w:left w:val=\"nil\"/><w:bottom w:val=\"nil\"/><w:right w:val=\"nil\"/></w:tcBorders>";
oStringBuilder += L"<w:vAlign w:val=\"center\"/>";
oStringBuilder += L"<w:hideMark/>";
oStringBuilder.WriteNodeEnd(L"w:tcPr");
WriteToStringBuilder(m_oCaption, oStringBuilder);
oStringBuilder.WriteNodeEnd(L"w:tc");
oStringBuilder.WriteNodeEnd(L"w:tr");
}
#define CONVERT_ROWS(rows, mode) \
@ -1314,7 +1335,7 @@ public:
else if (0 != unRowIndex) \
nInstruction |= MID_ELEMENT << 4; \
nInstruction |= mode; \
oTable += rows[unRowIndex]->ConvertToOOXML(*this, nInstruction); \
oStringBuilder += rows[unRowIndex]->ConvertToOOXML(*this, nInstruction); \
} \
}
@ -1324,9 +1345,9 @@ public:
CONVERT_ROWS(m_arRows, PARSE_MODE_BODY)
CONVERT_ROWS(m_arFoother, PARSE_MODE_FOOTHER)
oTable.WriteNodeEnd(L"w:tbl");
oStringBuilder.WriteNodeEnd(L"w:tbl");
return oTable.GetData();
return true;
}
private:
std::vector<std::vector<CTableRow*>> m_arHeaders;
@ -1725,6 +1746,15 @@ public:
oRelsWriter.CloseFile();
}
for (const std::pair<std::wstring, std::wstring>& oFootnote : m_mFootnotes)
{
m_oNoteXml.WriteString(L"<w:footnote w:id=\"");
m_oNoteXml.WriteString(oFootnote.second);
m_oNoteXml.WriteString(L"\"><w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r><w:r><w:t xml:space=\"preserve\">");
m_oNoteXml.WriteEncodeXmlString(oFootnote.first);
m_oNoteXml.WriteString(L"</w:t></w:r></w:p></w:footnote>");
}
m_oNoteXmlRels.WriteString(L"</Relationships>");
if (oRelsWriter.CreateFileW(m_sDst + L"/word/_rels/footnotes.xml.rels"))
{
@ -2357,7 +2387,7 @@ private:
std::wstring sPStyle = wrP(&oPPr, arSelectors, oTS);
pXml->WriteString(oPPr.GetData());
WriteToStringBuilder(oPPr, *pXml);
NSStringUtils::CStringBuilder oRPr;
std::wstring sRStyle;
@ -2366,7 +2396,7 @@ private:
{
sRStyle = wrRPr(&oRPr, arSelectors, oTS);
pXml->WriteString(oRPr.GetData());
WriteToStringBuilder(oRPr, *pXml);
if (oTS.bQ)
pXml->WriteString(L"<w:t xml:space=\"preserve\">&quot;</w:t>");
@ -2411,12 +2441,12 @@ private:
{
CloseP(pXml, arSelectors);
OpenP(pXml);
pXml->WriteString(oPPr.GetData());
WriteToStringBuilder(oPPr, *pXml);
sText.erase(0, nAfter + 1);
nAfter = 0;
}
OpenR(pXml);
pXml->WriteString(oRPr.GetData());
WriteToStringBuilder(oRPr, *pXml);
nAfter = sText.find_first_of(L"\n\r\t", nAfter);
}
@ -2966,12 +2996,12 @@ private:
}
} while (m_oLightReader.ReadNextSiblingNode2(nDeath));
pXml->WriteString(oSummary.GetData());
WriteToStringBuilder(oSummary, *pXml);
if (bOpened)
{
m_oState = oBodyState;
pXml->WriteString(oBody.GetData());
WriteToStringBuilder(oBody, *pXml);
}
return true;
@ -3277,7 +3307,7 @@ private:
CloseP(&oXmlData, sSelectors);
if (bResult)
oXml->WriteString(oXmlData.GetData());
WriteToStringBuilder(oXmlData, *oXml);
else
m_oState = oCurentState;
}
@ -3643,13 +3673,17 @@ private:
OpenR(oXml);
oXml->WriteString(L"<w:ruby><w:rubyPr><w:rubyAlign w:val=\"" + std::wstring((bConsistsChineseCharacters) ? L"distributeSpace" : L"center") + L"\"/><w:hps w:val=\"" + std::to_wstring(nFontSize) + L"\"/><w:hpsRaise w:val=\"" + std::to_wstring(nFontSize - 2) + L"\"/><w:hpsBaseText w:val=\"" + std::to_wstring(nFontSize) + L"\"/></w:rubyPr>");
oXml->WriteString(L"<w:rt>" + oRT.GetData() + L"</w:rt>");
oXml->WriteString(L"<w:rubyBase>" + oBase.GetData() + L"</w:rubyBase>");
oXml->WriteString(L"<w:rt>");
WriteToStringBuilder(oRT, *oXml);
oXml->WriteString(L"</w:rt>");
oXml->WriteString(L"<w:rubyBase>");
WriteToStringBuilder(oBase, *oXml);
oXml->WriteString(L"</w:rubyBase>");
oXml->WriteString(L"</w:ruby>");
CloseR(oXml);
}
else
oXml->WriteString(oBase.GetData());
WriteToStringBuilder(oBase, *oXml);
CloseP(oXml, sSelectors);
@ -3773,7 +3807,7 @@ private:
oTable.Shorten();
oTable.CompleteTable();
oXml->WriteString(oTable.ConvertToOOXML());
oTable.ConvertToOOXML(*oXml);
WriteEmptyParagraph(oXml, true);
return true;
@ -4766,8 +4800,13 @@ HRESULT CHtmlFile2::OpenBatchHtml(const std::vector<std::wstring>& sSrc, const s
m_internal->m_oLightReader.Clear();
m_internal->m_sBase.clear();
}
//Если очищать, то каждый раз при использовании внешнего css файла он заново парсится
// m_internal->m_oStylesCalculator.Clear();
// Очищаем разрешенные файлы стилей
// Это необходимо, чтобы мы не могли взять стили из не подключенного файла, но при этом, чтобы данные оставались,
// т.к. ко многим файлам может быть подключен один и тот же файл (проблема возникает когда он большой)
// и подключать (в нашем случае заново парсить) его будет долго
m_internal->m_oStylesCalculator.ClearAllowedStyleFiles();
m_internal->m_oStylesCalculator.ClearEmbeddedStyles();
}
m_internal->write();

View File

@ -1,12 +1,12 @@
#include "HWPFile.h"
#include "HwpDoc/HWPFile_Private.h"
#include "HwpDoc/Common/WriterContext.h"
#include "../DesktopEditor/common/File.h"
#include "HwpDoc/Conversion/Converter2OOXML.h"
CHWPFile::CHWPFile(const std::wstring& wsFileName)
: m_pInternal(new HWP::CHWPFile_Private(wsFileName))
CHWPFile::CHWPFile()
: m_pInternal(new HWP::CWriterContext())
{}
CHWPFile::~CHWPFile()
@ -20,12 +20,20 @@ void CHWPFile::SetTempDirectory(const std::wstring& wsTempDirectory)
m_wsTempDirectory = wsTempDirectory;
}
bool CHWPFile::Open()
bool CHWPFile::OpenHWP(const std::wstring& wsFilePath)
{
if (nullptr == m_pInternal)
return false;
return m_pInternal->Open();
return m_pInternal->Open(wsFilePath, HWP::EHanType::HWP);
}
bool CHWPFile::OpenHWPX(const std::wstring& wsFilePath)
{
if (nullptr == m_pInternal)
return false;
return m_pInternal->Open(wsFilePath, HWP::EHanType::HWPX);
}
void CHWPFile::Close()
@ -38,7 +46,7 @@ bool CHWPFile::ConvertToOOXML(const std::wstring& wsFilePath)
{
HWP::CConverter2OOXML oConverter;
oConverter.SetHWPFile(m_pInternal);
oConverter.SetContext(m_pInternal);
oConverter.SetTempDirectory(m_wsTempDirectory);
return oConverter.ConvertToFile(wsFilePath);
@ -48,7 +56,17 @@ bool CHWPFile::ConvertToOOXML_Dir(const std::wstring& wsDirectoryPath)
{
HWP::CConverter2OOXML oConverter;
oConverter.SetHWPFile(m_pInternal);
oConverter.SetContext(m_pInternal);
return oConverter.ConvertToDir(wsDirectoryPath);
}
bool CHWPFile::IsHWPFormat(const std::wstring& wsFilePath)
{
return HWP::EHanType::HWP == HWP::CWriterContext::DetectHancom(wsFilePath);
}
bool CHWPFile::IsHWPXFormat(const std::wstring& wsFilePath)
{
return HWP::EHanType::HWPX == HWP::CWriterContext::DetectHancom(wsFilePath);
}

View File

@ -10,21 +10,26 @@
#define HWP_FILE_DECL_EXPORT Q_DECL_EXPORT
#endif
namespace HWP { class CHWPFile_Private; }
namespace HWP { class CWriterContext; }
class HWP_FILE_DECL_EXPORT CHWPFile
{
HWP::CHWPFile_Private *m_pInternal;
HWP::CWriterContext *m_pInternal;
std::wstring m_wsFileName;
std::wstring m_wsTempDirectory;
public:
CHWPFile(const std::wstring& wsFileName);
CHWPFile();
~CHWPFile();
void SetTempDirectory(const std::wstring& wsTempDirectory);
bool Open();
bool OpenHWP(const std::wstring& wsFilePath);
bool OpenHWPX(const std::wstring& wsFilePath);
void Close();
bool ConvertToOOXML(const std::wstring& wsFilePath);
bool ConvertToOOXML_Dir(const std::wstring& wsDirectoryPath);
static bool IsHWPFormat(const std::wstring& wsFilePath);
static bool IsHWPXFormat(const std::wstring& wsFilePath);
};
#endif // HWPFILE_H

View File

@ -12,12 +12,16 @@ PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics)
DEFINES += HWPFILE_USE_DYNAMIC_LIBRARY
SOURCES += \
HWPFile.cpp \
HwpDoc/Common/XMLReader.cpp \
HwpDoc/Common/WriterContext.cpp \
HwpDoc/Conversion/Converter2OOXML.cpp \
HwpDoc/Conversion/FootnoteConverter.cpp \
HwpDoc/Conversion/NumberingConverter.cpp \
@ -41,9 +45,10 @@ SOURCES += \
HwpDoc/HWPElements/HWPRecordParaText.cpp \
HwpDoc/HWPElements/HWPRecordStyle.cpp \
HwpDoc/HWPElements/HwpRecordTabDef.cpp \
HwpDoc/HWPFile_Private.cpp \
HwpDoc/HWPFile.cpp \
HwpDoc/HWPSection.cpp \
HwpDoc/HWPStream.cpp \
HwpDoc/HWPXFile.cpp \
HwpDoc/HwpFileHeader.cpp \
HwpDoc/OLEdoc/CompoundFile.cpp \
HwpDoc/OLEdoc/DirectoryEntry.cpp \
@ -59,6 +64,7 @@ SOURCES += \
HwpDoc/Paragraph/CtrlContainer.cpp \
HwpDoc/Paragraph/CtrlEmpty.cpp \
HwpDoc/Paragraph/CtrlEqEdit.cpp \
HwpDoc/Paragraph/CtrlField.cpp \
HwpDoc/Paragraph/CtrlForm.cpp \
HwpDoc/Paragraph/CtrlGeneralShape.cpp \
HwpDoc/Paragraph/CtrlHeadFoot.cpp \
@ -89,7 +95,9 @@ SOURCES += \
HEADERS += \
HWPFile.h \
HwpDoc/Common.h \
HwpDoc/Common/Common.h \
HwpDoc/Common/XMLNode.h \
HwpDoc/Common/WriterContext.h \
HwpDoc/Conversion/Converter2OOXML.h \
HwpDoc/Conversion/FootnoteConverter.h \
HwpDoc/Conversion/NumberingConverter.h \
@ -119,9 +127,10 @@ HEADERS += \
HwpDoc/HWPElements/HWPType.h \
HwpDoc/HWPElements/HwpRecordTabDef.h \
HwpDoc/HWPElements/HwpRecordTypes.h \
HwpDoc/HWPFile_Private.h \
HwpDoc/HWPFile.h \
HwpDoc/HWPSection.h \
HwpDoc/HWPStream.h \
HwpDoc/HWPXFile.h \
HwpDoc/HanType.h \
HwpDoc/HwpFileHeader.h \
HwpDoc/OLEdoc/CompoundFile.h \
@ -141,6 +150,7 @@ HEADERS += \
HwpDoc/Paragraph/CtrlContainer.h \
HwpDoc/Paragraph/CtrlEmpty.h \
HwpDoc/Paragraph/CtrlEqEdit.h \
HwpDoc/Paragraph/CtrlField.h \
HwpDoc/Paragraph/CtrlForm.h \
HwpDoc/Paragraph/CtrlGeneralShape.h \
HwpDoc/Paragraph/CtrlHeadFoot.h \

View File

@ -25,6 +25,26 @@ typedef char HWP_BYTE;
#define CASE(value) case value : return value
#define DEFAULT(value) case value: default: return value
#define MAKE_STR(value) #value
#define MAKE_WSTR(value) L##value
#define WSTR(value) MAKE_WSTR(#value)
#define IF_STRING_IN_ENUM(checked_value, value, enum_type)\
if (WSTR(checked_value) == value)\
return enum_type::checked_value
#define ELSE_IF_STRING_IN_ENUM(checked_value, value, enum_type)\
else if (WSTR(checked_value) == value)\
return enum_type::checked_value
#define ELSE_STRING_IN_ENUM(checked_value, enum_type)\
else\
return enum_type::checked_value
#define RETURN_VECTOR_CONST_PTR(type, array_values) \
std::vector<const type*> arTempVector(array_values.size()); \
for (unsigned int unIndex = 0; unIndex < array_values.size(); ++unIndex) \
arTempVector[unIndex] = dynamic_cast<const type*>(array_values[unIndex]); \
return arTempVector
class IRef
{
unsigned long m_ulRef;

View File

@ -0,0 +1,346 @@
#include "WriterContext.h"
#include "../HWPFile.h"
#include "../HWPXFile.h"
#include <sstream>
#include <iomanip>
namespace HWP
{
CWriterContext::CWriterContext()
: m_eType(EHanType::NONE), m_pHWPFile(nullptr), m_pHWPXFile(nullptr)
{}
CWriterContext::~CWriterContext()
{
if (nullptr != m_pHWPFile)
delete m_pHWPFile;
if (nullptr != m_pHWPXFile)
delete m_pHWPXFile;
}
void CWriterContext::Clear()
{
m_eType = EHanType::NONE;
if (nullptr != m_pHWPFile)
{
delete m_pHWPFile;
m_pHWPFile = nullptr;
}
if (nullptr != m_pHWPXFile)
{
delete m_pHWPXFile;
m_pHWPXFile = nullptr;
}
}
EHanType CWriterContext::GetType()
{
return m_eType;
}
VECTOR<const CHWPSection*> CWriterContext::GetSections()
{
switch(m_eType)
{
case EHanType::NONE: break;
case EHanType::HWP:
{
if (nullptr != m_pHWPFile)
return m_pHWPFile->GetSections();
break;
}
case EHanType::HWPX:
{
if(nullptr != m_pHWPXFile)
return m_pHWPXFile->GetSections();
break;
}
}
return VECTOR<const CHWPSection*>();
}
EHanType CWriterContext::DetectHancom(const HWP_STRING& sPathToFile)
{
bool bDetected = false;
CHWPFile* pHwpTemp = new CHWPFile(sPathToFile);
if (nullptr != pHwpTemp)
{
if (pHwpTemp->Detect())
{
bDetected = true;
pHwpTemp->Close();
}
delete pHwpTemp;
}
if (bDetected)
return EHanType::HWP;
CHWPXFile* pHwpxTemp = new CHWPXFile(sPathToFile);
if (nullptr != pHwpxTemp)
{
if (pHwpxTemp->Detect())
{
bDetected = true;
pHwpxTemp->Close();
}
delete pHwpxTemp;
}
if (bDetected)
return EHanType::HWPX;
return EHanType::NONE;
}
bool CWriterContext::Detect()
{
switch(m_eType)
{
case EHanType::HWP:
{
if (nullptr == m_pHWPFile)
return false;
return m_pHWPFile->Detect();
}
case EHanType::HWPX:
{
if (nullptr == m_pHWPXFile)
return false;
return m_pHWPXFile->Detect();
}
case EHanType::NONE:
return false;
}
}
bool CWriterContext::Open(const HWP_STRING& sPathToFile, EHanType eHanType)
{
Clear();
m_eType = eHanType;
switch (m_eType)
{
case EHanType::HWP:
{
m_pHWPFile = new CHWPFile(sPathToFile);
if (nullptr == m_pHWPFile)
return false;
return m_pHWPFile->Open();
}
case EHanType::HWPX:
{
m_pHWPXFile = new CHWPXFile(sPathToFile);
if (nullptr == m_pHWPXFile)
return false;
return m_pHWPXFile->Open();
}
case EHanType::NONE:
break;
}
return false;
}
void CWriterContext::Close()
{
switch (m_eType)
{
case EHanType::HWP:
{
if (nullptr != m_pHWPFile)
m_pHWPFile->Close();
break;
}
case EHanType::HWPX:
{
if (nullptr != m_pHWPXFile)
m_pHWPXFile->Close();
break;
}
case EHanType::NONE:
break;
}
}
const CHWPDocInfo* CWriterContext::GetDocInfo()
{
switch (m_eType)
{
case EHanType::HWP:
{
if (nullptr == m_pHWPFile)
return nullptr;
return m_pHWPFile->GetDocInfo();
}
case EHanType::HWPX:
{
if (nullptr == m_pHWPXFile)
return nullptr;
return m_pHWPXFile->GetDocInfo();
}
case EHanType::NONE:
return nullptr;
}
}
const CHWPRecordBorderFill* CWriterContext::GetBorderFill(short shId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordBorderFill*)pDocInfo->GetBorderFill(shId);
}
const CHWPRecordParaShape* CWriterContext::GetParaShape(int nId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordParaShape*)pDocInfo->GetParaShape(nId);
}
const CHWPRecordStyle* CWriterContext::GetParaStyle(short shId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordStyle*)pDocInfo->GetStyle(shId);
}
const CHWPRecordCharShape* CWriterContext::GetCharShape(int nId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordCharShape*)pDocInfo->GetCharShape(nId);
}
const CHWPRecordNumbering* CWriterContext::GetNumbering(short shId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordNumbering*)pDocInfo->GetNumbering(shId);
}
const CHWPRecordBullet* CWriterContext::GetBullet(short shId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHWPRecordBullet*)pDocInfo->GetBullet(shId);
}
const CHwpRecordTabDef* CWriterContext::GetTabDef(short shId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return nullptr;
return (CHwpRecordTabDef*)pDocInfo->GetTabDef(shId);
}
HWP_STRING CWriterContext::GetBinFilename(const HWP_STRING& sId)
{
const CHWPDocInfo* pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return HWP_STRING();
const CHWPRecordBinData* pBinData = dynamic_cast<const CHWPRecordBinData*>(pDocInfo->GetBinData(sId));
return (nullptr != pBinData) ? pBinData->GetPath() : HWP_STRING();
}
bool CWriterContext::GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFileName)
{
const CHWPDocInfo* pDocInfo = nullptr;
pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return false;
const CHWPRecordBinData* pBinData = dynamic_cast<const CHWPRecordBinData*>(pDocInfo->GetBinData(sId));
if (nullptr == pBinData)
return false;
if (EType::LINK == pBinData->GetType())
{
switch (m_eType)
{
case EHanType::HWPX:
{
sFileName = NSFile::GetFileName(pBinData->GetPath());
return m_pHWPXFile->GetChildStream(pBinData->GetPath(), oBuffer);
}
default:
return false;
}
}
else
{
std::wostringstream oStringStream;
switch (m_eType)
{
case EHanType::HWP:
{
oStringStream << L"BIN" << std::setw(4) << std::setfill(L'0') << std::hex << pBinData->GetBinDataID() << L"." << pBinData->GetFormat();
sFileName = oStringStream.str();
return m_pHWPFile->GetChildStream(oStringStream.str(), pBinData->GetCompressed(), oBuffer);
}
case EHanType::HWPX:
{
oStringStream << sId << L"." << pBinData->GetFormat();
sFileName = oStringStream.str();
return m_pHWPXFile->GetChildStream(L"BinData/" + oStringStream.str(), oBuffer);
}
default:
return false;
}
}
return false;
}
HWP_STRING CWriterContext::GetBinFormat(const HWP_STRING& sId)
{
//TODO::реализовать
return HWP_STRING();
}
}

View File

@ -0,0 +1,50 @@
#ifndef WRITERCONTEXT_H
#define WRITERCONTEXT_H
#include "../HanType.h"
#include "../HWPFile.h"
#include "../HWPXFile.h"
#include "../HWPElements/HWPRecordParaShape.h"
#include "../HWPElements/HWPRecordStyle.h"
#include "../HWPElements/HWPRecordCharShape.h"
#include "../HWPElements/HWPRecordNumbering.h"
#include "../HWPElements/HWPRecordBullet.h"
#include "../HWPElements/HwpRecordTabDef.h"
namespace HWP
{
class CWriterContext
{
EHanType m_eType;
CHWPFile* m_pHWPFile;
CHWPXFile* m_pHWPXFile;
public:
CWriterContext();
~CWriterContext();
void Clear();
EHanType GetType();
VECTOR<const CHWPSection*> GetSections();
static EHanType DetectHancom(const HWP_STRING& sPathToFile);
bool Detect();
bool Open(const HWP_STRING& sPathToFile, EHanType eHanType);
void Close();
const CHWPDocInfo* GetDocInfo();
const CHWPRecordBorderFill* GetBorderFill(short shId);
const CHWPRecordParaShape* GetParaShape(int nId);
const CHWPRecordStyle* GetParaStyle(short shId);
const CHWPRecordCharShape* GetCharShape(int nId);
const CHWPRecordNumbering* GetNumbering(short shId);
const CHWPRecordBullet* GetBullet(short shId);
const CHwpRecordTabDef* GetTabDef(short shId);
HWP_STRING GetBinFilename(const HWP_STRING& sId);
bool GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFileName);
HWP_STRING GetBinFormat(const HWP_STRING& sId);
};
}
#endif // WRITERCONTEXT_H

View File

@ -0,0 +1,24 @@
#ifndef XMLNODEH_H
#define XMLNODEH_H
#include "../../../DesktopEditor/xml/include/xmlutils.h"
namespace HWP
{
class CXMLNode : public XmlUtils::CXmlNode
{
public:
CXMLNode();
CXMLNode(const XmlUtils::CXmlNode& oNode);
bool GetAttributeBool(const std::wstring& wsName);
int GetAttributeColor(const std::wstring& wsName, const int& _default = 0x00000000);
CXMLNode GetChild(const std::wstring& wsName);
std::vector<CXMLNode> GetChilds();
std::vector<CXMLNode> GetChilds(const std::wstring& wsName);
};
int ConvertWidthToHWP(const std::wstring& wsValue);
}
#endif // XMLNODEH_H

View File

@ -0,0 +1,101 @@
#include "XMLNode.h"
namespace HWP
{
CXMLNode::CXMLNode()
: XmlUtils::CXmlNode()
{}
CXMLNode::CXMLNode(const CXmlNode& oNode)
: XmlUtils::CXmlNode(oNode)
{}
bool CXMLNode::GetAttributeBool(const std::wstring& wsName)
{
return L"1" == XmlUtils::CXmlNode::GetAttribute(wsName, L"0");
}
int CXMLNode::GetAttributeColor(const std::wstring& wsName, const int& _default)
{
std::wstring sColor = XmlUtils::CXmlNode::GetAttribute(wsName);
if (L"none" != sColor)
{
if (L'#' == sColor.front())
sColor.erase(0, 1);
if (sColor.length() < 6)
return _default;
return std::stoi(sColor.substr(0, 6), nullptr, 16);
}
return _default;
}
CXMLNode CXMLNode::GetChild(const std::wstring& wsName)
{
return CXMLNode(XmlUtils::CXmlNode::GetNode(wsName));
}
std::vector<CXMLNode> CXMLNode::GetChilds()
{
std::vector<XmlUtils::CXmlNode> arChilds;
XmlUtils::CXmlNode::GetChilds(arChilds);
std::vector<CXMLNode> arNewChilds(arChilds.size());
for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex)
arNewChilds[unIndex] = CXMLNode(arChilds[unIndex]);
return arNewChilds;
}
std::vector<CXMLNode> CXMLNode::GetChilds(const std::wstring& wsName)
{
std::vector<XmlUtils::CXmlNode> arChilds{XmlUtils::CXmlNode::GetNodes(wsName)};
std::vector<CXMLNode> arNewChilds(arChilds.size());
for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex)
arNewChilds[unIndex] = CXMLNode(arChilds[unIndex]);
return arNewChilds;
}
int ConvertWidthToHWP(const std::wstring& wsValue)
{
if (wsValue.empty() || L"0.1" == wsValue || L"0.1 mm" == wsValue)
return 0;
else if (L"0.12" == wsValue || L"0.12 mm" == wsValue)
return 1;
else if (L"0.15" == wsValue || L"0.15 mm" == wsValue)
return 2;
else if (L"0.2" == wsValue || L"0.2 mm" == wsValue)
return 3;
else if (L"0.25" == wsValue || L"0.25 mm" == wsValue)
return 4;
else if (L"0.3" == wsValue || L"0.3 mm" == wsValue)
return 5;
else if (L"0.4" == wsValue || L"0.4 mm" == wsValue)
return 6;
else if (L"0.5" == wsValue || L"0.5 mm" == wsValue)
return 7;
else if (L"0.6" == wsValue || L"0.6 mm" == wsValue)
return 8;
else if (L"0.7" == wsValue || L"0.7 mm" == wsValue)
return 9;
else if (L"1.0" == wsValue || L"1.0 mm" == wsValue)
return 10;
else if (L"1.5" == wsValue || L"1.5 mm" == wsValue)
return 11;
else if (L"2.0" == wsValue || L"2.0 mm" == wsValue)
return 12;
else if (L"3.0" == wsValue || L"3.0 mm" == wsValue)
return 13;
else if (L"4.0" == wsValue || L"4.0 mm" == wsValue)
return 14;
else if (L"5.0" == wsValue || L"5.0 mm" == wsValue)
return 15;
return 0;
}
}

Some files were not shown because too many files have changed in this diff Show More