Compare commits

...

279 Commits

Author SHA1 Message Date
7908abacf6 fix/bug79610
fix bug #79610
2026-02-18 20:08:01 +03:00
dfe7a64e1a fix/bug79610 2026-02-18 16:33:49 +03:00
65f89c1e4b fix/bug79610
fix bug #79610
2026-02-18 16:32:15 +03:00
8ef0713adc Merge pull request 'fix bug #80172' (#678) from fix/fix-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/678
2026-02-18 07:37:33 +00:00
2f74b3b69b fix bug #80172 2026-02-18 10:30:46 +03:00
7ce71b6f5d Merge pull request 'fix/fix-bugs' (#677) from fix/fix-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/677
2026-02-18 06:28:02 +00:00
9b5847e653 for bug #76556 2026-02-17 22:36:15 +03:00
d81e26eff7 fix bug #80155 2026-02-17 22:11:25 +03:00
67e987e389 Merge pull request 'Fix bug 80103' (#676) from fix/bug80103 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/676
2026-02-17 15:08:26 +00:00
bc91106ea4 Merge pull request 'Fix right postiton via width in font' (#675) from fix/docx-renderer into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/675
2026-02-17 13:44:18 +00:00
d91a19cbc2 Fix right postiton via width in font 2026-02-17 16:17:26 +03:00
970720575a Fix bug 80103 2026-02-17 14:51:18 +03:00
f11045c87f Merge pull request 'Fix bugs in html to md conversion' (#674) from fix/html2md into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/674
2026-02-17 07:14:42 +00:00
70e819c56b Added a new constructor to CStringBuilder 2026-02-17 01:52:35 +03:00
5a662b3567 Fix bug #80116 2026-02-17 01:51:21 +03:00
0f920531ac Fix bugs in html2md conversion 2026-02-16 22:25:31 +03:00
84d3ea7a21 Fix bug #80121 2026-02-16 20:16:50 +03:00
4893ff96fd Fix bug in html2md conversion 2026-02-16 18:45:44 +03:00
6a7791ae0a Fix bug #80119 2026-02-16 18:23:37 +03:00
78ac7bb427 Refactoring 2026-02-16 17:50:54 +03:00
8180a20cb8 Fix bug #80112 2026-02-16 17:37:59 +03:00
eb51861f39 fix bug #80117 2026-02-16 17:36:32 +03:00
e4cc737c38 . 2026-02-16 16:14:00 +03:00
6c89a66b3d Merge pull request 'Fix set Kids for widget Parents' (#672) from fix/pdf-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/672
2026-02-16 12:49:12 +00:00
b127bd3ac1 Fix set Kids for widget Parents 2026-02-16 15:42:50 +03:00
0cca75b662 fix build 2026-02-16 15:39:29 +03:00
08dc0c99cf Merge pull request 'for bug #54521' (#579) from fix/bug54521 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/579
2026-02-16 09:47:25 +00:00
d2af89a2f6 Merge pull request 'fix bug #80011' (#670) from fix/bug80011 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/670
2026-02-16 09:46:48 +00:00
836787f151 fix bug #80012 2026-02-16 12:18:20 +03:00
eb78332705 Merge pull request 'Fix bug 80093' (#671) from fix/bug-80093 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/671
2026-02-16 09:17:27 +00:00
f232d0ca51 Fix bug 80093 2026-02-16 12:11:25 +03:00
24d436fb9c fix bug #80011 2026-02-15 20:48:31 +03:00
1d362cf69a Merge remote-tracking branch 'origin/feature/add-xls-writing' into release/v9.3.0 2026-02-15 16:45:38 +03:00
6c0326d660 Merge pull request 'fix/bug79610' (#669) from fix/bug79610 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/669
2026-02-14 19:23:55 +00:00
4400c9d4f4 Api => Asc.editor 2026-02-14 00:07:22 +03:00
71c7d25c9e fix/bug79610
fix bug #79610
2026-02-13 22:41:51 +03:00
ab1dd7a48b fix/bug79610
fix bug #79610
2026-02-13 22:34:41 +03:00
6e3d625420 Merge pull request 'fix/docx-renderer' (#668) from fix/docx-renderer into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/668
2026-02-13 16:11:11 +00:00
ebb0eb8136 Merge pull request 'Add signature info' (#667) from fix/pdf-signature into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/667
2026-02-13 15:24:55 +00:00
10f34fb67d Add signature info 2026-02-13 18:17:25 +03:00
98d2f62f9e Fix paragraphs splits with overlapping text lines 2026-02-13 18:07:58 +03:00
096df8fc31 Fix logic with paragraph lines 2026-02-13 16:48:47 +03:00
a7886c5cd6 Fix bugs 2026-02-13 15:27:18 +03:00
ee6ea683d1 Added definition of md text styles from html styles 2026-02-13 15:06:39 +03:00
9343f73818 Merge pull request 'Fix bug 80055' (#666) from fix/pdf-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/666
2026-02-13 11:53:56 +00:00
61aeb6f386 Fixed a bug with the initial number of the list element 2026-02-13 14:41:10 +03:00
06e8d136bf Merge pull request 'To Markdown conversion' (#660) from feature/html2md into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/660
2026-02-13 11:28:47 +00:00
c1d649b506 Fix bug 80055 2026-02-13 14:23:53 +03:00
4386e9c794 Fix shape merging 2026-02-12 23:12:00 +03:00
4900305b4a Merge branch 'release/v9.3.0' of https://git.onlyoffice.com/ONLYOFFICE/core into release/v9.3.0 2026-02-12 18:32:29 +03:00
e1f923c593 fix bug #79470 2026-02-12 18:32:03 +03:00
07ef2269ac Merge pull request 'For bug 80007' (#665) from fix/bug-80007 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/665
2026-02-12 15:31:48 +00:00
cf44441645 For bug 80007 2026-02-12 18:29:43 +03:00
7157d209d7 add worksheet drawing conversion 2026-02-12 20:02:41 +06:00
64a560679c add cell anchor pos getter 2026-02-12 18:29:29 +06:00
2682e49090 fix drawing conversion 2026-02-12 18:28:28 +06:00
7fd4219ff4 add clientAnchorSheet writing 2026-02-12 16:35:48 +06:00
4f9c229f77 Merge pull request 'Fix bug 79949' (#664) from fix/bug-79949 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/664
2026-02-12 09:10:37 +00:00
6d8454c39d Fix bug 79949 2026-02-12 12:03:08 +03:00
58deecba88 Merge pull request 'Fix bug #79894' (#663) from fix/bug-79894 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/663
2026-02-11 16:06:57 +00:00
1940bc53f7 Fix bug #79894 2026-02-11 18:58:35 +03:00
a6ac765676 add office art client data writing 2026-02-11 21:24:12 +06:00
08624e8334 Merge pull request 'Fix bug 79999' (#662) from fix/pdf-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/662
2026-02-11 14:59:29 +00:00
1f078c8c49 Merge pull request 'Fix bug 79885' (#661) from fix/bug-79885 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/661
2026-02-11 14:53:51 +00:00
e6036b37be Fix bug 79885 2026-02-11 17:51:17 +03:00
04f1c30036 The possible md conversion formats have been expanded 2026-02-11 17:44:05 +03:00
86f84f89de Fix bugs in html2md conversion 2026-02-11 17:30:42 +03:00
17b80ac96e fix bug #79968 2026-02-11 17:00:25 +03:00
710bfef301 Add clientAnchor writing 2026-02-11 17:32:08 +06:00
aa75825a73 Fix bug 79999 2026-02-11 13:53:29 +03:00
f74caacbd0 Merge pull request 'fix/bug56564' (#659) from fix/bug56564 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/659
2026-02-11 10:50:48 +00:00
4d903b58b8 fix/bug56564
fix bug #56564
2026-02-11 13:45:41 +03:00
6434965f09 Merge pull request 'Fix pdf signature' (#658) from fix/pdf-signature into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/658
2026-02-11 09:03:17 +00:00
f60f957d00 Fix comment 2026-02-11 11:58:04 +03:00
bad5b172d5 Fix x2t 2026-02-11 11:37:55 +03:00
7b6f29a5f0 Merge pull request 'HTML to Markdown' (#657) from feature/html2md into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/657
2026-02-11 07:59:58 +00:00
b5e1cf9d06 Change PrepareSignature 2026-02-11 10:03:50 +03:00
0f73b2aa8b Added html to md conversion in x2t 2026-02-10 22:34:04 +03:00
e3b5d72ec8 add client anchor writing 2026-02-10 21:43:50 +06:00
8f8a9ad29b fix bug #56683 2026-02-10 16:12:41 +03:00
1417b4bbd4 add embedded chartsheet substream writing 2026-02-10 18:26:39 +06:00
87c9f66c58 Merge pull request 'Fix pdf bugs' (#656) from fix/pdf-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/656
2026-02-10 11:27:36 +00:00
d0a9d2cfe2 Merge pull request 'fix/bug78280' (#654) from fix/bug78280 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/654
2026-02-10 11:19:41 +00:00
627d5913e6 Merge pull request 'feature/x2ttester' (#655) from feature/x2ttester into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/655
2026-02-10 10:57:05 +00:00
5ca60f6bcd Add md suppot and fix default delim in tsv 2026-02-10 13:55:38 +03:00
72f679b649 Fix actrion GoTo flag 2026-02-10 13:50:54 +03:00
c84c35933e Add more parms for tsv format 2026-02-10 13:44:07 +03:00
63f160641d Fix bug 79962
Add tsv format
2026-02-10 13:39:31 +03:00
7a8ccfdfa0 fix bug 2026-02-10 12:58:13 +03:00
6091a7b5cd Fix build 2026-02-10 11:58:52 +03:00
95b4461961 Fix bug 79937 2026-02-10 11:15:48 +03:00
ec5afc1f17 fix bug #79859 2026-02-10 11:11:04 +03:00
9dd13a2f74 Merge pull request 'Fix docx-renderer' (#653) from fix/docx-renderer into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/653
2026-02-10 06:30:00 +00:00
b850450c25 Fix build 2026-02-10 03:42:13 +03:00
098d40d44f Modification of the html converter 2026-02-10 02:18:38 +03:00
82769d3c0e Fix paragraph build 2026-02-09 23:30:30 +03:00
5121f74851 Fix subscript/superscript 2026-02-09 23:15:28 +03:00
6fa8b51541 Merge pull request 'Fix missprint' (#652) from fix/docx-renderer-missprint into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/652
2026-02-09 19:51:15 +00:00
3b32ba4d14 Fix missprint 2026-02-09 22:47:22 +03:00
e23acc8881 Merge pull request 'Fix flipY in tiles' (#651) from fix/docx-renderer into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/651
2026-02-09 18:23:25 +00:00
c266ffa85f Fix flipY in tiles 2026-02-09 21:13:18 +03:00
bd2af5f455 Merge pull request 'Fix bug 75900' (#648) from fix/bug-75900 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/648
2026-02-09 15:54:39 +00:00
ec8c0182c3 Merge pull request 'Fix bug 79790' (#650) from fix/bug-79790 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/650
2026-02-09 15:47:17 +00:00
04ad9d4e47 Merge pull request 'Fix bug 79879' (#649) from fix/bug-79879 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/649
2026-02-09 15:47:04 +00:00
3261ba0d0c Fix bug 79790 2026-02-09 18:19:41 +03:00
2189934a50 Fix bug 79879 2026-02-09 17:45:04 +03:00
e3842c796a fix bug #79811 2026-02-09 17:08:56 +03:00
7507b6c71f Fix bug 75900 2026-02-09 16:48:07 +03:00
8a406c9612 fix value axis conversion 2026-02-09 19:44:40 +06:00
3a004e8495 fix scatter chart conversion 2026-02-09 17:47:16 +06:00
404748ec5a fix axis conversion 2026-02-09 14:46:19 +06:00
d4f7767c45 fix bug #78279 2026-02-08 12:19:50 +03:00
f91cc79e7d for bug #79472 2026-02-08 12:18:34 +03:00
b14e7fd3a2 Merge pull request 'fix/bug79610' (#646) from fix/bug79610 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/646
2026-02-07 19:14:06 +00:00
fce8173ce4 Merge pull request 'Fix bug 78774' (#647) from fix/bug78774 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/647
2026-02-07 19:13:34 +00:00
8f5bfef6b2 Merge pull request 'Fix bug 59750' (#645) from fix/bug67390 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/645
2026-02-07 19:13:22 +00:00
f6bf73dfab Fix bug 78774 2026-02-06 18:48:55 +03:00
3b10e1a0f3 add axis hiding 2026-02-06 21:13:12 +06:00
f7555af6b3 fix/bug79610
fix bug #79610
2026-02-06 17:33:50 +03:00
3e09e5ad48 Fix bug 59750 2026-02-06 16:24:20 +03:00
655bc0698f Merge pull request 'Fix pdf signature' (#644) from fix/pdf-signature into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/644
2026-02-06 12:40:51 +00:00
e16b85f671 Fix x2t pdfSign 2026-02-06 15:04:30 +03:00
981b8b16a3 Fix unsuccessful signing 2026-02-06 14:26:54 +03:00
70aa8c7e64 add val axis style conversion 2026-02-06 17:13:37 +06:00
4144723822 Merge pull request 'fix/bug-79086' (#643) from fix/bug-79086 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/643
2026-02-06 09:47:04 +00:00
2663e412ef Fix AppFonts initialize 2026-02-06 12:41:52 +03:00
9a91e8192c Fix xref 2026-02-06 11:34:38 +03:00
bff86db600 Merge branch 'develop' into feature/add-xls-writing 2026-02-06 14:05:44 +06:00
668804035a fix svg in base64 2026-02-06 10:47:59 +03:00
cb97ee9fdc Fix bug 79867 2026-02-06 09:31:41 +03:00
56b8e41875 Added some alternative tags 2026-02-05 23:38:21 +03:00
565b2ec494 Fix bugs 2026-02-05 23:09:46 +03:00
a243e60e5a add axis line format conversion 2026-02-05 22:00:39 +06:00
96ce3c22f1 Fix bug 79086 2026-02-05 18:57:33 +03:00
6b58358186 Create PrepareSignature and FinalizeSignature 2026-02-05 18:55:26 +03:00
6c95810f63 add chart gridlines 2026-02-05 21:25:54 +06:00
d9260e5eee Fix bug with heading styles 2026-02-05 17:26:33 +03:00
63510a1fe9 Merge pull request 'Fix bug #79431' (#642) from fix/bug-79478 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/642
2026-02-05 13:00:42 +00:00
1e05ab9acb for bug #70264 2026-02-04 22:33:00 +03:00
c1236815a3 Fix bug #79431 2026-02-04 19:55:12 +03:00
c822a995c1 Merge pull request 'Fix bugs' (#641) from fix/bug-72703 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/641
2026-02-04 14:04:36 +00:00
e612306d75 fix chart size 2026-02-04 19:54:10 +06:00
2d6382e61a Fix bug #79797 2026-02-04 16:51:54 +03:00
2f34fd917e Refactoring 2026-02-04 16:30:08 +03:00
024a5e0192 Merge pull request 'Fix pdf bugs' (#640) from fix/pdf-bugs into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/640
2026-02-04 11:26:56 +00:00
a6183fa4cd Fix bug 79336 2026-02-04 11:18:47 +03:00
13912c93ef Fix different FontKey 2026-02-04 10:54:57 +03:00
adcdbc164f Fix buid 2026-02-04 10:18:35 +03:00
a48a78c1c5 Merge pull request 'Fix clipRect clear' (#639) from fix/bug-79522 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/639
2026-02-03 20:01:10 +00:00
da57bd115c Fix clipRect clear 2026-02-03 22:46:34 +03:00
71b21ea79d add window conversion for chartsheet 2026-02-03 21:42:48 +06:00
5fbb998524 For bug 79437 2026-02-03 18:15:35 +03:00
ea47a90763 Merge pull request 'fix/bug79616' (#637) from fix/bug79554 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/637
2026-02-03 13:16:49 +00:00
daefd8744a Merge pull request 'Fix repeat font name' (#638) from fix/pdf-font into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/638
2026-02-03 12:30:38 +00:00
647327a0c5 Fix repeat font name 2026-02-03 15:12:56 +03:00
58b221f4fa fix/bug79616
for bug #79616
2026-02-03 13:31:14 +03:00
22eaf8241b fix legend pos conversion 2026-02-03 15:18:46 +06:00
64c7b7a3fd handout binary 2026-02-02 22:36:39 +03:00
858c2e14c8 Fix bug #79697 2026-02-02 20:54:26 +03:00
2024302fbe Merge pull request 'Fix bug 79443' (#617) from fix/bug-79443 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/617
2026-02-02 17:42:29 +00:00
00f4752dda Fix bug #72703 2026-02-02 18:36:03 +03:00
90b329e06c fix sheet ref conversion 2026-02-02 20:34:04 +06:00
d286b8459b Add offset for unexisted symbol (last width) 2026-02-02 15:36:07 +03:00
ff93f1e8b3 Merge pull request 'Fix bug #79712' (#636) from fix/bug-79712 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/636
2026-02-02 11:08:52 +00:00
65a4fa90a5 Fixed bugs 2026-02-01 23:53:35 +03:00
4471940b92 Fix bug #79712 2026-01-31 18:26:05 +03:00
c4daa0acd4 for bug #79472 2026-01-30 17:43:32 +03:00
6df0cf26f3 Merge pull request 'fix bug #79684' (#634) from fix/bug79684 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/634
2026-01-30 14:24:20 +00:00
720d66ad74 Merge pull request 'fix bug #79698' (#633) from fix/bug79698 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/633
2026-01-30 14:23:49 +00:00
e6522c6ce4 Merge pull request 'fix bug #79699' (#632) from fix/bug79699 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/632
2026-01-30 14:23:23 +00:00
9b3c2291d8 Merge pull request 'Fix subset tag font' (#635) from fix/pdf-font into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/635
2026-01-30 13:49:31 +00:00
e7cfb67962 Fix subset tag font 2026-01-30 16:44:57 +03:00
8725be55f0 fix bug #79699 2026-01-30 18:48:21 +06:00
37ae77d0d2 fix bug #79698 2026-01-30 16:23:03 +06:00
4c6ded76a1 Merge pull request 'Fix bug 67390' (#631) from fix/bug67390 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/631
2026-01-30 08:54:09 +00:00
2d8701cd4f Fix bug 67390 2026-01-30 11:25:45 +03:00
d5c321d47d fix bug #79684 2026-01-30 14:25:41 +06:00
bddfadabb2 fix bug #78280 2026-01-30 11:00:00 +03:00
324f7b3933 Merge pull request 'feature/add-xls-writing' (#630) from feature/add-xls-writing into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/630
2026-01-30 07:21:45 +00:00
edef6a83c8 Merge pull request 'feature/docx-renderer' (#629) from feature/docx-renderer into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/629
2026-01-30 05:02:42 +00:00
e7c21fb2cd Fix bugs 2026-01-30 06:43:34 +03:00
be8ba62c3f Merge pull request 'release/v9.3.0' from release/v9.3.0 into feature/docx-renderer 2026-01-29 22:26:04 +00:00
fda8c8e445 No calc asc/desc using spaces in text lines 2026-01-30 01:15:24 +03:00
d9ebae1724 Change single line width 2026-01-29 23:53:19 +03:00
92ec3d854e Added html to md conversion for some tags 2026-01-29 23:19:02 +03:00
f4867bd9f9 Fix more bugs 2026-01-29 22:26:37 +03:00
9b9da90dcc Fix bugs 2026-01-29 22:03:24 +03:00
cba4bc8085 add legend conversion 2026-01-29 20:41:24 +06:00
325c2d3000 Fix text line shape between lines of paragraph 2026-01-29 16:50:48 +03:00
3187913c8e fix bug #79660 2026-01-29 16:46:05 +03:00
8958d13b56 fix bug #78766 2026-01-29 15:25:40 +03:00
9d13526724 add line 3d chart conversion 2026-01-29 16:56:37 +06:00
93f70176bc add area chart3d conversion 2026-01-29 16:40:44 +06:00
e2ad965d7c add 3dBarChartConversion 2026-01-29 15:58:06 +06:00
d535aa64ef Merge pull request 'Fix bug 75486' (#607) from fix/bug75486 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/607
2026-01-29 09:46:37 +00:00
c155a4c53a add chart3d conversion 2026-01-29 15:11:42 +06:00
97cbd8dcc7 Fix text shape offsets 2026-01-29 09:42:54 +03:00
5e58298d1e Migrated most of the html conversion to the new architecture 2026-01-29 00:38:08 +03:00
d38576085c Merge pull request 'fix/bug79554' (#627) from fix/bug79554 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/627
2026-01-28 17:48:19 +00:00
46dd9efa2e for bug #47231 2026-01-28 16:58:30 +03:00
6af52920a2 fix/bug79554
fix bug #79554
2026-01-28 16:51:11 +03:00
f13baca136 Fix build with c++14 2026-01-28 16:16:32 +03:00
28a91a1519 add area chart conversion 2026-01-28 17:57:30 +06:00
0e48e65ef1 add radar chart conversion 2026-01-28 17:44:31 +06:00
ad1709d4af Merge pull request 'Fix include' (#626) from fix/pdf-font into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/626
2026-01-28 11:26:33 +00:00
e2c6ecec9b Fix include 2026-01-28 14:20:27 +03:00
ef55594f90 Merge pull request 'Fix pdf font' (#625) from fix/pdf-font into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/625
2026-01-28 09:48:08 +00:00
223bbe3347 Fix bug 79318 2026-01-28 12:23:29 +03:00
eca0cdb318 Fix GIDByUnicode for non-CID font 2026-01-28 11:35:21 +03:00
4a52368c30 Merge remote-tracking branch 'origin/release/v9.3.0' into release/v9.3.0 2026-01-27 16:23:22 +00:00
73f4e20c56 Fix qmake bug 2026-01-27 19:21:05 +03:00
d53768969b . 2026-01-27 16:20:16 +00:00
324d6ec0bd Merge pull request 'fix/bug79433' (#624) from fix/bug79433 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/624
2026-01-27 13:25:07 +00:00
767b652ef2 fix/bug79433
fix bug #79433 and fix 51965
2026-01-27 16:10:42 +03:00
68f2f0760d fix surface conversion 2026-01-27 18:35:55 +06:00
694282a013 Merge pull request 'Fix bug 79426' (#623) from fix/bug-79426 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/623
2026-01-27 10:39:07 +00:00
e64eeb26af Fix bug 79426 2026-01-27 13:31:41 +03:00
873b2b9351 Add scatter chart conversion 2026-01-27 16:23:03 +06:00
d5ecb00472 Add surf chart conversion 2026-01-27 16:22:46 +06:00
2ac6801afa add area chart conversion 2026-01-27 14:39:29 +06:00
213c65fe54 Add line chart conversion 2026-01-27 14:23:07 +06:00
8269c14207 Merge pull request 'fix/bug77970' (#622) from fix/bug77970 into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/622
2026-01-27 08:20:57 +00:00
f438a17779 fix bug #79483 2026-01-27 00:39:19 +03:00
9c8b739d0e fix bug #77970 2026-01-27 00:38:21 +03:00
a9dc790f92 Migrated most of the html conversion to the new architecture 2026-01-26 19:03:34 +03:00
7f0720bb95 Merge pull request 'Fix merging conts' (#621) from fix/docx-renderer-merge-conts-fix into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/621
2026-01-26 15:28:13 +00:00
846b212882 Fix merging conts 2026-01-26 18:22:05 +03:00
344a096e24 Merge pull request 'PdfWriter use embedded fonts' (#619) from fix/pdf-font into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/619
2026-01-26 14:07:14 +00:00
15eb4793f5 Fix CodeToUnicode and CodeToGID 2026-01-26 15:31:44 +03:00
3ce4b4bfe8 Merge pull request 'Fix readAnnotationsInfoFromBinary Link' (#620) from fix/pdf-action into release/v9.3.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/620
2026-01-26 10:00:29 +00:00
b8fab6f4df Fix readAnnotationsInfoFromBinary Link 2026-01-26 12:56:03 +03:00
14bb45d2fe Migrated most of the html conversion to the new architecture 2026-01-25 22:53:08 +03:00
347c1f82a9 Migrated most of the html conversion to the new architecture 2026-01-25 01:39:48 +03:00
7ebf12c1e4 Complete PdfFont 2026-01-23 17:16:58 +03:00
1813e09e1f add chart title conversion 2026-01-23 20:02:11 +06:00
e32b48524e Migrated most of the html conversion to the new architecture 2026-01-22 20:16:47 +03:00
575e379c4b Develop PdfFont 2026-01-22 15:11:17 +03:00
86d8c7bfa3 Change anchor 2026-01-22 14:20:41 +03:00
a3e1efb75b add pie chart conversion 2026-01-22 17:13:59 +06:00
e1f7feb5c1 fix bar chart conversion 2026-01-22 15:43:49 +06:00
2a3f565b44 Fix bug 79443 2026-01-22 01:53:25 +03:00
e820a9c936 fix chart conversion 2026-01-21 19:08:27 +06:00
0b6ea2a399 Create PdfFont 2026-01-21 15:51:28 +03:00
fc422bb2e7 fix chartsheet writing 2026-01-21 16:30:57 +06:00
f359f180bb Merge branch 'develop' into feature/add-xls-writing 2026-01-21 13:26:04 +06:00
79f8e14d07 The division of the html converter into components has begun 2026-01-20 20:22:40 +03:00
83745da5f3 add attached label conversion 2026-01-20 21:47:55 +06:00
b64b31a972 Merge remote-tracking branch 'origin/release/v9.3.0' into develop 2026-01-20 11:35:55 +03:00
ef9f25aa4d Fix bug 75486 2026-01-19 16:04:31 +03:00
0c2a5eac1b fix barChart conversion 2026-01-19 16:58:32 +06:00
31f274fbc4 add barChart crt conversion 2026-01-16 21:37:14 +06:00
6e696daa15 add dv axis conversion 2026-01-16 20:15:31 +06:00
c4708222c6 Merge branch 'develop' into feature/add-xls-writing 2026-01-16 19:02:08 +06:00
ead20d7bfe Merge commit '2ff12c06a428232d1742d5f76970e8e87d83dc4f' into develop 2026-01-14 15:39:56 +03:00
116ec89cd2 add ivaxis conversion 2026-01-13 19:20:37 +06:00
8133e3f7b7 add axisParent conversion 2025-12-30 16:07:33 +06:00
3081d02c9c Add ser2crt conversion 2025-12-29 19:24:13 +06:00
91afd3d340 Merge branch 'develop' into feature/add-xls-writing 2025-12-29 15:28:05 +06:00
b616ce6fd7 Merge branch 'release/v9.3.0' into develop 2025-12-28 14:35:30 +03:00
048eebc613 Merge branch hotfix/v9.2.1 into develop 2025-12-26 16:24:54 +00:00
578118380e add series style conversion 2025-12-26 19:53:11 +06:00
59f376908c Merge branch 'develop' into feature/add-xls-writing 2025-12-26 18:35:06 +06:00
5d6caf8a93 Add BRAI records conversion 2025-12-25 18:10:16 +06:00
6283a68841 add seriesFormat conversion 2025-12-25 16:06:52 +06:00
527cc5f89f Merge branch 'release/v9.3.0' into develop 2025-12-25 11:53:08 +03:00
50ae7db2f0 add area format conversion 2025-12-24 17:38:27 +06:00
dd17cb7243 add frame conversion 2025-12-23 19:16:45 +06:00
b3988b002f add chartformats conversion 2025-12-22 18:51:32 +06:00
bb3091b6f1 Merge branch 'develop' into feature/add-xls-writing 2025-12-22 13:26:37 +06:00
dde96288ed for bug #54521 2025-12-19 16:21:52 +06:00
482810712e Merge branch hotfix/v9.2.1 into develop 2025-12-17 15:27:40 +00:00
ea338db68a add chart drawing conversion 2025-12-17 14:17:37 +06:00
76f3afc6c0 Merge branch 'develop' into feature/add-xls-writing 2025-12-16 16:16:04 +06:00
9c12c0b30a Merge remote-tracking branch 'origin/release/v9.3.0' into develop 2025-12-11 11:20:42 +03:00
e232fc779d Merge remote-tracking branch 'origin/hotfix/v9.2.1' into develop 2025-12-11 11:19:31 +03:00
981df3fce7 add chart sheet conversion 2025-12-10 20:43:38 +06:00
c3b3a1b5ef Fix SetDV for radiobutton 2025-12-10 15:23:40 +03:00
85d98daedd Merge branch 'develop' into feature/add-xls-writing 2025-12-10 15:43:25 +06:00
dd00be6dce add fontlist writing 2025-12-04 13:53:42 +06:00
282 changed files with 15081 additions and 3034 deletions

View File

@ -6,12 +6,13 @@ import os
if not base.is_dir("glm"):
base.cmd("git", ["clone", "https://github.com/g-truc/glm.git"])
base.cmd_in_dir("glm", "git", ["checkout", "33b4a621a697a305bc3a7610d290677b96beb181", "--quiet"])
base.replaceInFile("./glm/glm/detail/func_common.inl", "vec<L, T, Q> v;", "vec<L, T, Q> v{};")
if not base.is_dir("mdds"):
base.cmd("git", ["clone", "https://github.com/kohei-us/mdds.git"])
base.cmd_in_dir("mdds", "git", ["checkout", "0783158939c6ce4b0b1b89e345ab983ccb0f0ad0"], "--quiet")
fix_cpp_version = "#if __cplusplus < 201402L\n"
fix_cpp_version = "#if __cplusplus < 201703L\n"
fix_cpp_version += "#ifndef _MSC_VER\n"
fix_cpp_version += "namespace std {\n"
fix_cpp_version += " template<bool __v>\n"

View File

@ -7,7 +7,6 @@
#include <iterator>
#include <map>
#include <iostream>
#include "../../../../../DesktopEditor/common/File.h"
#include "StaticFunctions.h"
#include "ConstValues.h"
@ -18,14 +17,16 @@ namespace NSCSS
{
typedef std::map<std::wstring, std::wstring>::const_iterator styles_iterator;
CCompiledStyle::CCompiledStyle() : m_nDpi(96), m_UnitMeasure(Point), m_dCoreFontSize(DEFAULT_FONT_SIZE)
CCompiledStyle::CCompiledStyle()
: m_nDpi(96), m_UnitMeasure(Point), m_dCoreFontSize(DEFAULT_FONT_SIZE)
{}
CCompiledStyle::CCompiledStyle(const CCompiledStyle& oStyle) :
m_arParentsStyles(oStyle.m_arParentsStyles), m_sId(oStyle.m_sId),
m_nDpi(oStyle.m_nDpi), m_UnitMeasure(oStyle.m_UnitMeasure), m_dCoreFontSize(oStyle.m_dCoreFontSize),
m_oFont(oStyle.m_oFont), m_oMargin(oStyle.m_oMargin), m_oPadding(oStyle.m_oPadding), m_oBackground(oStyle.m_oBackground),
m_oText(oStyle.m_oText), m_oBorder(oStyle.m_oBorder), m_oDisplay(oStyle.m_oDisplay), m_oTransform(oStyle.m_oTransform){}
m_oText(oStyle.m_oText), m_oBorder(oStyle.m_oBorder), m_oDisplay(oStyle.m_oDisplay), m_oTransform(oStyle.m_oTransform)
{}
CCompiledStyle::~CCompiledStyle()
{
@ -34,6 +35,8 @@ namespace NSCSS
CCompiledStyle& CCompiledStyle::operator+= (const CCompiledStyle &oElement)
{
m_arParentsStyles.insert(oElement.m_arParentsStyles.begin(), oElement.m_arParentsStyles.end());
if (oElement.Empty())
return *this;
@ -49,8 +52,6 @@ namespace NSCSS
if (!oElement.m_sId.empty())
m_sId += L'+' + oElement.m_sId;
m_arParentsStyles.insert(oElement.m_arParentsStyles.begin(), oElement.m_arParentsStyles.end());
return *this;
}

View File

@ -15,29 +15,33 @@ inline static std::wstring StringifyValueList(const KatanaArray* oValues);
inline static std::wstring StringifyValue(const KatanaValue* oValue);
inline static bool IsTableElement(const std::wstring& wsNameTag);
bool operator<(const std::vector<NSCSS::CNode> &arLeftSelectors, const std::vector<NSCSS::CNode> &arRightSelectors)
{
const size_t& sizeLeftSelectors = arLeftSelectors.size();
const size_t& sizeRightSelectors = arRightSelectors.size();
if (sizeLeftSelectors < sizeRightSelectors)
return true;
else if (sizeLeftSelectors > sizeRightSelectors)
return false;
for (size_t i = 0; i < arLeftSelectors.size(); ++i)
{
if (arLeftSelectors[i] < arRightSelectors[i])
return true;
}
return false;
}
namespace NSCSS
{
bool operator<(const std::vector<NSCSS::CNode> &arLeftSelectors, const std::vector<NSCSS::CNode> &arRightSelectors)
{
if (arLeftSelectors.size() < arRightSelectors.size())
return true;
else if (arLeftSelectors.size() > arRightSelectors.size())
return false;
for (size_t i = 0; i < arLeftSelectors.size(); ++i)
{
if (arLeftSelectors[i] == arRightSelectors[i])
continue;
if (arLeftSelectors[i] < arRightSelectors[i])
return true;
else if (arRightSelectors[i] < arLeftSelectors[i])
return false;
}
return false;
}
CStyleStorage::CStyleStorage()
{}
{
InitDefaultStyles();
}
CStyleStorage::~CStyleStorage()
{
@ -62,6 +66,7 @@ namespace NSCSS
m_arEmptyStyleFiles.clear();
ClearEmbeddedStyles();
ClearDefaultStyles();
ClearAllowedStyleFiles();
#ifdef CSS_CALCULATOR_WITH_XHTML
@ -208,6 +213,16 @@ namespace NSCSS
return nullptr;
}
const CElement* CStyleStorage::FindDefaultElement(const std::wstring& wsSelector) const
{
if (wsSelector.empty())
return nullptr;
const CElement* pFoundElement = FindSelectorFromStyleData(wsSelector, m_mDefaultStyleData);
return (nullptr != pFoundElement) ? pFoundElement : nullptr;
}
void CStyleStorage::AddStyles(const std::string& sStyle, std::map<std::wstring, CElement*>& mStyleData)
{
if (sStyle.empty())
@ -227,6 +242,15 @@ namespace NSCSS
m_mEmbeddedStyleData.clear();
}
void CStyleStorage::ClearDefaultStyles()
{
for (std::map<std::wstring, CElement*>::iterator oIter = m_mDefaultStyleData.begin(); oIter != m_mDefaultStyleData.end(); ++oIter)
if (oIter->second != nullptr)
delete oIter->second;
m_mDefaultStyleData.clear();
}
void CStyleStorage::ClearAllowedStyleFiles()
{
m_arAllowedStyleFiles.clear();
@ -480,7 +504,33 @@ namespace NSCSS
return nullptr;
}
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_sEncoding(L"UTF-8"){}
void CStyleStorage::InitDefaultStyles()
{
m_mDefaultStyleData[L"b"] = new CElement(L"b", {{L"font-weight", L"bold"}});
m_mDefaultStyleData[L"center"] = new CElement(L"center", {{L"text-align", L"center"}});
m_mDefaultStyleData[L"i"] = new CElement(L"i", {{L"font-style", L"italic"}});
m_mDefaultStyleData[L"code"] = new CElement(L"code", {{L"font-family", L"Courier New"}});
m_mDefaultStyleData[L"kbd"] = new CElement(L"kbd", {{L"font-family", L"Courier New"},
{L"font_weight", L"bold"}});
m_mDefaultStyleData[L"s"] = new CElement(L"s", {{L"text-decoration", L"line-through"}});
m_mDefaultStyleData[L"u"] = new CElement(L"u", {{L"text-decoration", L"underline"}});
m_mDefaultStyleData[L"mark"] = new CElement(L"mark", {{L"background-color", L"yellow"}});
m_mDefaultStyleData[L"sup"] = new CElement(L"sup", {{L"vertical-align", L"top"}});
m_mDefaultStyleData[L"sub"] = new CElement(L"sub", {{L"vertical-align", L"bottom"}});
m_mDefaultStyleData[L"dd"] = new CElement(L"dd", {{L"margin-left", L"720tw"}});
m_mDefaultStyleData[L"pre"] = new CElement(L"pre", {{L"font-family", L"Courier New"},
{L"margin-top", L"0"},
{L"margin-bottom", L"0"}});
m_mDefaultStyleData[L"blockquote"] = new CElement(L"blockquote", {{L"margin", L"0px"}});
m_mDefaultStyleData[L"ul"] = new CElement(L"ul", {{L"margin-top", L"100tw"},
{L"margin-bottom", L"100tw"}});
m_mDefaultStyleData[L"textarea"] = new CElement(L"textarea", {{L"border", L"1px solid black"}});
}
CCssCalculator_Private::CCssCalculator_Private()
: m_nDpi(96), m_nCountNodes(0), m_sEncoding(L"UTF-8")
{
}
CCssCalculator_Private::~CCssCalculator_Private()
{}
@ -503,12 +553,17 @@ namespace NSCSS
arSelectors.back().m_pCompiledStyle->m_oBorder.Clear();
}
if (arSelectors.size() > 1)
arSelectors.back().m_pCompiledStyle->AddParent(arSelectors[arSelectors.size() - 2].m_wsName);
arSelectors.back().m_pCompiledStyle->SetID(L"text-" + std::to_wstring(++m_nCountNodes));
return true;
}
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
const std::map<std::vector<CNode>, CCompiledStyle>::const_iterator oItem = m_mUsedStyles.find(arSelectors);
if (oItem != m_mUsedStyles.end())
if (oItem != m_mUsedStyles.cend() && (arSelectors.back().m_wsId.empty() || !HaveStylesById(arSelectors.back().m_wsId)))
{
arSelectors.back().SetCompiledStyle(new CCompiledStyle(oItem->second));
return true;
@ -542,7 +597,8 @@ namespace NSCSS
if (0 != i)
*arSelectors[i].m_pCompiledStyle += *arSelectors[i - 1].m_pCompiledStyle;
arSelectors[i].m_pCompiledStyle->AddParent(arSelectors[i].m_wsName);
if (i != arSelectors.size() - 1)
arSelectors[i].m_pCompiledStyle->AddParent(arSelectors[i].m_wsName);
if (!bInTable)
bInTable = IsTableElement(arSelectors[i].m_wsName);
@ -615,8 +671,8 @@ namespace NSCSS
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' ';}));
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
}
else
arNodes.push_back(L'.' + oNode->m_wsClass);
@ -644,6 +700,36 @@ namespace NSCSS
arFindedElements.insert(arFindedElements.end(), arTempKins.begin(), arTempKins.end());
}
inline std::wstring GetAlternativeDefaultNodeName(const std::wstring& wsNodeName)
{
if (L"strong" == wsNodeName)
return L"b";
if (L"cite" == wsNodeName || L"dfn" == wsNodeName || L"em" == wsNodeName ||
L"var" == wsNodeName || L"adress" == wsNodeName)
return L"i";
if (L"tt" == wsNodeName || L"samp" == wsNodeName)
return L"code";
if (L"strike" == wsNodeName || L"del" == wsNodeName)
return L"s";
if (L"ins" == wsNodeName)
return L"u";
if (L"xmp" == wsNodeName || L"nobr" == wsNodeName)
return L"pre";
if (L"ol" == wsNodeName)
return L"ul";
if (L"fieldset" == wsNodeName)
return L"textarea";
return wsNodeName;
}
std::vector<const CElement*> CCssCalculator_Private::FindElements(std::vector<std::wstring> &arNodes, std::vector<std::wstring> &arNextNodes)
{
if (arNodes.empty())
@ -702,6 +788,11 @@ namespace NSCSS
}
}
const CElement* pFoundDefault = m_oStyleStorage.FindDefaultElement(GetAlternativeDefaultNodeName(wsName));
if (nullptr != pFoundDefault)
arFindedElements.push_back(pFoundDefault);
const CElement* pFoundName = m_oStyleStorage.FindElement(wsName);
if (nullptr != pFoundName)

View File

@ -27,6 +27,7 @@ namespace NSCSS
void AddStylesFromFile(const std::wstring& wsFileName);
void ClearEmbeddedStyles();
void ClearDefaultStyles();
void ClearAllowedStyleFiles();
void ClearStylesFromFile(const std::wstring& wsFileName);
@ -38,6 +39,7 @@ namespace NSCSS
#endif
const CElement* FindElement(const std::wstring& wsSelector) const;
const CElement* FindDefaultElement(const std::wstring& wsSelector) const;
private:
typedef struct
{
@ -49,6 +51,7 @@ namespace NSCSS
std::set<std::wstring> m_arAllowedStyleFiles;
std::vector<TStyleFileData*> m_arStyleFiles;
std::map<std::wstring, CElement*> m_mEmbeddedStyleData;
std::map<std::wstring, CElement*> m_mDefaultStyleData;
#ifdef CSS_CALCULATOR_WITH_XHTML
typedef struct
@ -78,6 +81,8 @@ namespace NSCSS
void GetOutputData(KatanaOutput* oOutput, std::map<std::wstring, CElement*>& mStyleData);
const CElement* FindSelectorFromStyleData(const std::wstring& wsSelector, const std::map<std::wstring, CElement*>& mStyleData) const;
void InitDefaultStyles();
};
class CCssCalculator_Private

View File

@ -9,6 +9,13 @@ namespace NSCSS
CElement::CElement()
{
}
CElement::CElement(const std::wstring& wsSelector, std::map<std::wstring, std::wstring> mStyle)
: m_mStyle(mStyle), m_sSelector(wsSelector), m_sFullSelector(wsSelector)
{
UpdateWeight();
}
CElement::~CElement()
{
for (CElement* oElement : m_arPrevElements)
@ -18,7 +25,6 @@ namespace NSCSS
continue;
m_mStyle.clear();
}
std::wstring CElement::GetSelector() const

View File

@ -22,6 +22,7 @@ namespace NSCSS
public:
CElement();
CElement(const std::wstring& wsSelector, std::map<std::wstring, std::wstring> mStyle);
~CElement();
std::wstring GetSelector() const;

View File

@ -17,8 +17,7 @@ namespace NSCSS
m_wsStyle(oNode.m_wsStyle), m_mAttributes(oNode.m_mAttributes)
{
#ifdef CSS_CALCULATOR_WITH_XHTML
m_pCompiledStyle = new CCompiledStyle();
*m_pCompiledStyle = *oNode.m_pCompiledStyle;
m_pCompiledStyle = new CCompiledStyle(*oNode.m_pCompiledStyle);
#endif
}
@ -42,6 +41,23 @@ namespace NSCSS
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
}
bool CNode::GetAttributeValue(const std::wstring& wsAttributeName, std::wstring& wsAttributeValue) const
{
const std::map<std::wstring, std::wstring>::const_iterator itFound{m_mAttributes.find(wsAttributeName)};
if (m_mAttributes.cend() == itFound)
return false;
wsAttributeValue = itFound->second;
return true;
}
std::wstring CNode::GetAttributeValue(const std::wstring& wsAttributeName) const
{
const std::map<std::wstring, std::wstring>::const_iterator itFound{m_mAttributes.find(wsAttributeName)};
return (m_mAttributes.cend() != itFound) ? itFound->second : std::wstring();
}
#ifdef CSS_CALCULATOR_WITH_XHTML
void CNode::SetCompiledStyle(CCompiledStyle* pCompiledStyle)
{
@ -86,6 +102,9 @@ namespace NSCSS
if(m_wsStyle != oNode.m_wsStyle)
return m_wsStyle < oNode.m_wsStyle;
if (m_mAttributes.size() != oNode.m_mAttributes.size())
return m_mAttributes.size() < oNode.m_mAttributes.size();
if (m_mAttributes != oNode.m_mAttributes)
return m_mAttributes < oNode.m_mAttributes;
@ -94,10 +113,9 @@ namespace NSCSS
bool CNode::operator==(const CNode& oNode) const
{
return((m_wsId == oNode.m_wsId) &&
(m_wsName == oNode.m_wsName) &&
(m_wsClass == oNode.m_wsClass) &&
(m_wsStyle == oNode.m_wsStyle) &&
(m_mAttributes == oNode.m_mAttributes));
return((m_wsName == oNode.m_wsName) &&
(m_wsClass == oNode.m_wsClass) &&
(m_wsStyle == oNode.m_wsStyle) &&
(m_mAttributes == oNode.m_mAttributes));
}
}

View File

@ -31,6 +31,9 @@ namespace NSCSS
bool Empty() const;
bool GetAttributeValue(const std::wstring& wsAttributeName, std::wstring& wsAttributeValue) const;
std::wstring GetAttributeValue(const std::wstring& wsAttributeName) const;
#ifdef CSS_CALCULATOR_WITH_XHTML
void SetCompiledStyle(CCompiledStyle* pCompiledStyle);
#endif

View File

@ -70,7 +70,9 @@ namespace NSCSS
R_Shd,
R_SmallCaps,
R_Kern,
R_Vanish
R_Vanish,
R_Strike,
R_VertAlign
} RunnerProperties;
typedef enum

View File

@ -600,12 +600,6 @@ namespace NSCSS
return true;
}
void CColor::SetNone()
{
Clear();
m_oValue.reset();
}
char NormalizeNegativeColorValue(INT nValue)
{
@ -647,18 +641,21 @@ namespace NSCSS
}
else if (L"none" == wsNewValue || wsNewValue == L"transparent")
{
SetNone();
Clear();
m_oValue = CColorValue();
bResult = true;
}
else if (L"context-stroke" == wsNewValue)
{
Clear();
m_oValue = CColorValueContextStroke();
bResult = true;
}
else if (L"context-fill" == wsNewValue)
{
Clear();
m_oValue = CColorValueContextFill();
bResult = true;
}
else if (10 <= wsNewValue.length() && wsNewValue.substr(0, 3) == L"rgb")
{

View File

@ -343,7 +343,6 @@ namespace NSCSS
void SetRGB(const TRGB& oRGB);
void SetHEX(const std::wstring& wsValue);
bool SetUrl(const std::wstring& wsValue);
void SetNone();
};
typedef enum

View File

@ -22,6 +22,11 @@ namespace NSCSS
: m_oStyle(oStyle), m_bIsPStyle(bIsPStyle)
{}
void CStyleUsed::SetFinalId(const std::wstring& wsFinalId)
{
m_wsFinalId = wsFinalId;
}
bool CheckArrays(const std::vector<std::wstring>& arInitial, const std::set<std::wstring>& arFirst, const std::set<std::wstring>& arSecond)
{
std::unordered_set<std::wstring> arInitialSet(arInitial.begin(), arInitial.end());
@ -57,19 +62,14 @@ namespace NSCSS
m_oStyle == oUsedStyle.m_oStyle;
}
std::wstring CStyleUsed::getId()
std::wstring CStyleUsed::GetId() const
{
if (m_bIsPStyle)
return m_oStyle.GetId();
return m_oStyle.GetId() + L"-c";
return m_wsFinalId;
}
CDocumentStyle::CDocumentStyle() : m_arStandardStyles(Names_Standard_Styles)
{
for (const std::wstring& oNameStandardStyle : Names_Standard_Styles)
m_arStandardStyles.push_back(oNameStandardStyle + L"-c");
}
CDocumentStyle::CDocumentStyle()
: m_arStandardStyles(Names_Standard_Styles)
{}
CDocumentStyle::~CDocumentStyle()
{
@ -85,7 +85,7 @@ namespace NSCSS
std::wstring CDocumentStyle::GetIdAndClear()
{
std::wstring sId = m_sId;
const std::wstring sId = m_sId;
Clear();
return sId;
}
@ -110,10 +110,10 @@ namespace NSCSS
m_sId = sId;
}
void CDocumentStyle::CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement)
bool CDocumentStyle::CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement)
{
if (arStandartedStyles.empty())
return;
return false;
std::vector<std::wstring> arStyles;
for (const std::wstring& sStyleName : arStandartedStyles)
@ -123,7 +123,7 @@ namespace NSCSS
}
if (arStyles.empty())
return;
return false;
std::wstring sId;
for (std::vector<std::wstring>::const_reverse_iterator iStyleName = arStyles.rbegin(); iStyleName != arStyles.rend(); ++iStyleName)
@ -142,18 +142,25 @@ namespace NSCSS
oElement.AddBasicProperties(BProperties::B_Name, sId);
oElement.AddBasicProperties(BProperties::B_StyleId, sId);
return true;
}
void CDocumentStyle::CreateStandardStyle(const std::wstring& sNameStyle, CXmlElement& oElement)
bool CDocumentStyle::CreateStandardStyle(const std::wstring& sNameStyle, CXmlElement& oElement)
{
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sNameStyle) != m_arStandardStyles.end())
{
oElement.CreateDefaultElement(sNameStyle);
return true;
}
return false;
}
void CDocumentStyle::ConvertStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle)
bool CDocumentStyle::ConvertStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle)
{
if (oStyle.GetId().empty())
return;
return false;
std::wstring sName = oStyle.GetId();
const size_t posPoint = sName.find(L'.');
@ -183,25 +190,25 @@ namespace NSCSS
for (std::wstring& sParentName : arParentsName)
sParentName += L"-c";
bool bResult{false};
if (!arParentsName.empty())
{
CombineStandardStyles(arParentsName, oParentStyle);
bResult = CombineStandardStyles(arParentsName, oParentStyle);
if (!oParentStyle.Empty())
{
oParentStyle.AddBasicProperties(BProperties::B_BasedOn, L"normal");
oParentStyle.AddBasicProperties(BProperties::B_StyleId, L"(" + oParentStyle.GetStyleId() + L")");
oParentStyle.AddBasicProperties(BProperties::B_StyleId, oParentStyle.GetStyleId());
if (!bIsPStyle)
{
oParentStyle.AddBasicProperties(BProperties::B_StyleId, oParentStyle.GetStyleId() + L"-c");
oParentStyle.AddBasicProperties(BProperties::B_Type, L"character");
}
}
}
CXmlElement oStandardXmlElement;
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sName) != m_arStandardStyles.end())
CreateStandardStyle(sName, oStandardXmlElement);
if (CreateStandardStyle(sName, oStandardXmlElement))
bResult = true;
if (oStandardXmlElement.Empty() && !oParentStyle.Empty())
{
@ -221,7 +228,7 @@ namespace NSCSS
if (oStyle.Empty())
{
m_sId = sParentsStyleID;
return;
return true;
}
oElement.AddBasicProperties(BProperties::B_BasedOn, sParentsStyleID);
@ -234,7 +241,7 @@ namespace NSCSS
if (oStyle.Empty())
{
m_sId = sStandPlusParent;
return;
return true;
}
oElement.AddBasicProperties(BProperties::B_BasedOn, sStandPlusParent);
}
@ -258,7 +265,7 @@ namespace NSCSS
if (oStyle.Empty())
{
m_sId = sStandPlusParent;
return;
return true;
}
oElement.AddBasicProperties(BProperties::B_BasedOn, oTempElement.GetStyleId());
}
@ -281,7 +288,7 @@ namespace NSCSS
if (oStyle.Empty())
{
m_sId = sStandartStyleID;
return;
return true;
}
oElement.AddBasicProperties(BProperties::B_BasedOn, sStandartStyleID);
}
@ -289,7 +296,7 @@ namespace NSCSS
if (oStyle.Empty() && oElement.Empty())
{
m_sId = L"normal";
return;
return true;
}
m_sId = oStyle.GetId();
@ -302,15 +309,19 @@ namespace NSCSS
oElement.AddBasicProperties(BProperties::B_Name, m_sId);
oElement.AddBasicProperties(BProperties::B_Type, bIsPStyle ? L"paragraph" : L"character");
oElement.AddBasicProperties(BProperties::B_CustomStyle, L"1");
return bResult;
}
void CDocumentStyle::SetPStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
bool CDocumentStyle::SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
{
bool bResult{false};
if (!bIsLite)
ConvertStyle(oStyle, oXmlElement, true);
bResult = ConvertStyle(oStyle, oXmlElement, true);
if (oStyle.Empty())
return;
return bResult;
const bool bInTable{oStyle.HaveThisParent(L"table")};
@ -390,6 +401,8 @@ namespace NSCSS
SetBorderStyle(oStyle, oXmlElement, PProperties::P_LeftBorder);
}
}
return bResult || !oXmlElement.Empty();
}
void CDocumentStyle::SetBorderStyle(const CCompiledStyle &oStyle, CXmlElement &oXmlElement, const PProperties &enBorderProperty)
@ -473,13 +486,15 @@ namespace NSCSS
return L"w:val=\"" + wsStyle + L"\" w:sz=\"" + std::to_wstring(nWidth) + + L"\" w:space=\"" + std::to_wstring(nSpace) + L"\" w:color=\"" + wsColor + L"\"";
}
void CDocumentStyle::SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
bool CDocumentStyle::SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
{
bool bResult{false};
if (!bIsLite)
ConvertStyle(oStyle, oXmlElement, false);
bResult = ConvertStyle(oStyle, oXmlElement, false);
if (oStyle.Empty() && oXmlElement.Empty())
return;
return bResult;
if (!oStyle.m_oFont.GetSize().Empty())
oXmlElement.AddPropertiesInR(RProperties::R_Sz, std::to_wstring(static_cast<int>(oStyle.m_oFont.GetSize().ToDouble(NSCSS::Point) * 2. * oStyle.m_oTransform.GetMatrix().GetFinalValue().sy() + 0.5))); // Значения шрифта увеличивает на 2
@ -516,6 +531,18 @@ namespace NSCSS
oXmlElement.AddPropertiesInR(RProperties::R_I, oStyle.m_oFont.GetStyle().ToWString());
oXmlElement.AddPropertiesInR(RProperties::R_B, oStyle.m_oFont.GetWeight().ToWString());
oXmlElement.AddPropertiesInR(RProperties::R_SmallCaps, oStyle.m_oFont.GetVariant().ToWString());
if (oStyle.m_oText.LineThrough())
{
if (L"double" == oStyle.m_oText.GetDecoration().m_oStyle.ToWString())
oXmlElement.AddPropertiesInR(RProperties::R_Strike, L"dstrike");
else
oXmlElement.AddPropertiesInR(RProperties::R_Strike, L"strike");
}
oXmlElement.AddPropertiesInR(RProperties::R_VertAlign, oStyle.m_oDisplay.GetVAlign().ToWString());
return bResult || !oXmlElement.Empty();
}
bool CDocumentStyle::WriteRStyle(const NSCSS::CCompiledStyle& oStyle)
@ -531,16 +558,16 @@ namespace NSCSS
if (oItem != m_arStyleUsed.end())
{
m_sId = (*oItem).getId();
m_sId = (*oItem).GetId();
return true;
}
CXmlElement oXmlElement;
SetRStyle(oStyle, oXmlElement);
if (oXmlElement.Empty())
if (!SetRStyle(oStyle, oXmlElement))
return false;
structStyle.SetFinalId(m_sId);
m_arStyleUsed.push_back(structStyle);
m_sStyle += oXmlElement.GetRStyle();
@ -593,16 +620,16 @@ namespace NSCSS
if (oItem != m_arStyleUsed.end())
{
m_sId = (*oItem).getId();
m_sId = (*oItem).GetId();
return true;
}
CXmlElement oXmlElement;
SetPStyle(oStyle, oXmlElement);
if (oXmlElement.Empty())
if (!SetPStyle(oStyle, oXmlElement))
return false;
structStyle.SetFinalId(m_sId);
m_arStyleUsed.push_back(structStyle);
m_sStyle += oXmlElement.GetPStyle();

View File

@ -12,16 +12,19 @@ namespace NSCSS
{
CCompiledStyle m_oStyle;
bool m_bIsPStyle;
std::wstring m_wsFinalId;
public:
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle);
void SetFinalId(const std::wstring& wsFinalId);
bool operator==(const CStyleUsed& oUsedStyle) const;
std::wstring getId();
std::wstring GetId() const;
};
static const std::vector<std::wstring> Names_Standard_Styles = {L"a", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6",L"p", L"div"};
static const std::vector<std::wstring> Names_Standard_Styles = {L"a", L"a-c", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6", L"h1-c", L"h2-c", L"h3-c", L"h4-c", L"h5-c", L"h6-c"};
class CSSCALCULATOR_EXPORT CDocumentStyle
{
@ -36,12 +39,12 @@ namespace NSCSS
std::wstring m_sStyle;
std::wstring m_sId;
void CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
bool CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
bool CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
bool ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
bool SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
bool SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
void SetBorderStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, const PProperties& enBorderProperty);
public:

View File

@ -5,7 +5,6 @@
#include <cwctype>
#include <functional>
#include <iostream>
#include "../ConstValues.h"
#define DEFAULTFONTNAME L"Times New Roman"
@ -67,7 +66,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h1-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"0");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h2")
{
@ -78,7 +77,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h2-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"1");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h3")
{
@ -89,7 +88,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h3-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"2");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h4")
{
@ -100,7 +99,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h4-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"3");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h5")
{
@ -111,7 +110,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h5-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"4");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h6")
@ -123,13 +122,13 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h6-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"5");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h1-c")
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h1-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 1 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 1 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h1");
@ -142,7 +141,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h2-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 2 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 2 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
@ -155,7 +154,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h3-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 3 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 3 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
@ -168,7 +167,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h4-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 4 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 4 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
@ -181,7 +180,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h5-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 5 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 5 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
@ -194,7 +193,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
{
AddBasicProperties(CSSProperties::BasicProperties::B_Type, L"character");
AddBasicProperties(CSSProperties::BasicProperties::B_StyleId, L"h6-c");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Title 6 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_Name, L"Heading 6 Sign");
AddBasicProperties(CSSProperties::BasicProperties::B_CustomStyle, L"1");
AddBasicProperties(CSSProperties::BasicProperties::B_UiPriority, L"9");
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
@ -479,6 +478,19 @@ std::wstring CXmlElement::ConvertRStyle(bool bIsLite) const
sRStyle += L"<w:vanish/>";
break;
}
case CSSProperties::RunnerProperties::R_Strike:
{
sRStyle += L"<w:" + oItem.second + L"/>";
break;
}
case CSSProperties::RunnerProperties::R_VertAlign:
{
if (L"top" == oItem.second)
sRStyle += L"<w:vertAlign w:val=\"superscript\"/>";
else if (L"bottom" == oItem.second)
sRStyle += L"<w:vertAlign w:val=\"subscript\"/>";
break;
}
default:
break;
}

View File

@ -7,4 +7,5 @@ core_windows:INCLUDEPATH += $$PWD/gumbo-parser/visualc/include
HEADERS += $$files($$PWD/gumbo-parser/src/*.h, true) \
$$PWD/htmltoxhtml.h
SOURCES += $$files($$PWD/gumbo-parser/src/*.c, true)
SOURCES += $$files($$PWD/gumbo-parser/src/*.c, true) \
$$PWD/htmltoxhtml.cpp

View File

@ -0,0 +1,657 @@
#include "htmltoxhtml.h"
#include <map>
#include <cctype>
#include <vector>
#include <algorithm>
#include "gumbo-parser/src/gumbo.h"
#include "../../../DesktopEditor/common/File.h"
#include "../../../DesktopEditor/common/Directory.h"
#include "../../../DesktopEditor/common/StringBuilder.h"
#include "../../../UnicodeConverter/UnicodeConverter.h"
#include "../../../HtmlFile2/src/StringFinder.h"
namespace HTML
{
#if defined(CreateDirectory)
#undef CreateDirectory
#endif
static std::string nonbreaking_inline = "|a|abbr|acronym|b|bdo|big|cite|code|dfn|em|font|i|img|kbd|nobr|s|small|span|strike|strong|sub|sup|tt|";
static std::string empty_tags = "|area|base|basefont|bgsound|br|command|col|embed|event-source|frame|hr|image|img|input|keygen|link|menuitem|meta|param|source|spacer|track|wbr|";
static std::string preserve_whitespace = "|pre|textarea|script|style|";
static std::string special_handling = "|html|body|";
static std::string treat_like_inline = "|p|";
static std::vector<std::string> html_tags = {"div","span","a","img","p","h1","h2","h3","h4","h5","h6",
"ul", "ol", "li","td","tr","table","thead","tbody","tfoot","th",
"br","form","input","button","section","nav","header","footer",
"main","figure","figcaption","strong","em","i", "b", "u","pre",
"code","blockquote","hr","script","link","meta","style","title",
"head","body","html","legend","optgroup","option","select","dl",
"dt","dd","time","data","abbr","address","area","base","bdi",
"bdo","cite","col","iframe","video","source","track","textarea",
"label","fieldset","colgroup","del","ins","details","summary",
"dialog","embed","kbd","map","mark","menu","meter","object",
"output","param","progress","q","samp","small","sub","sup","var",
"wbr","acronym","applet","article","aside","audio","basefont",
"bgsound","big","blink","canvas","caption","center","command",
"comment","datalist","dfn","dir","font","frame","frameset",
"hgroup","isindex","keygen","marquee","nobr","noembed","noframes",
"noscript","plaintext","rp","rt","ruby","s","strike","tt","xmp"};
static std::vector<std::string> unchecked_nodes_new = {"svg"};
static void replace_all(std::string& s, const std::string& s1, const std::string& s2)
{
size_t pos = s.find(s1);
while(pos != std::string::npos)
{
s.replace(pos, s1.length(), s2);
pos = s.find(s1, pos + s2.length());
}
}
static bool NodeIsUnprocessed(const std::string& sTagName)
{
return "xml" == sTagName;
}
static bool IsUnckeckedNodes(const std::string& sValue)
{
return unchecked_nodes_new.end() != std::find(unchecked_nodes_new.begin(), unchecked_nodes_new.end(), sValue);
}
static std::string Base64ToString(const std::string& sContent, const std::string& sCharset)
{
std::string sRes;
int nSrcLen = (int)sContent.length();
int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(nSrcLen);
BYTE* pData = new BYTE[nDecodeLen];
if (TRUE == NSBase64::Base64Decode(sContent.c_str(), nSrcLen, pData, &nDecodeLen))
{
std::wstring sConvert;
if(!sCharset.empty() && NSStringFinder::Equals<std::string>("utf-8", sCharset))
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sConvert = oConverter.toUnicode(reinterpret_cast<char *>(pData), (unsigned)nDecodeLen, sCharset.data());
}
sRes = sConvert.empty() ? std::string(reinterpret_cast<char *>(pData), nDecodeLen) : U_TO_UTF8(sConvert);
}
RELEASEARRAYOBJECTS(pData);
return sRes;
}
static std::string QuotedPrintableDecode(const std::string& sContent, std::string& sCharset)
{
NSStringUtils::CStringBuilderA sRes;
size_t ip = 0;
size_t i = sContent.find('=');
if(i == 0)
{
size_t nIgnore = 12;
std::string charset = sContent.substr(0, nIgnore);
if(charset == "=00=00=FE=FF")
sCharset = "UTF-32BE";
else if(charset == "=FF=FE=00=00")
sCharset = "UTF-32LE";
else if(charset == "=2B=2F=76=38" || charset == "=2B=2F=76=39" ||
charset == "=2B=2F=76=2B" || charset == "=2B=2F=76=2F")
sCharset = "UTF-7";
else if(charset == "=DD=73=66=73")
sCharset = "UTF-EBCDIC";
else if(charset == "=84=31=95=33")
sCharset = "GB-18030";
else
{
nIgnore -= 3;
charset.erase(nIgnore);
if(charset == "=EF=BB=BF")
sCharset = "UTF-8";
else if(charset == "=F7=64=4C")
sCharset = "UTF-1";
else if(charset == "=0E=FE=FF")
sCharset = "SCSU";
else if(charset == "=FB=EE=28")
sCharset = "BOCU-1";
else
{
nIgnore -= 3;
charset.erase(nIgnore);
if(charset == "=FE=FF")
sCharset = "UTF-16BE";
else if(charset == "=FF=FE")
sCharset = "UTF-16LE";
else
nIgnore -= 6;
}
}
ip = nIgnore;
i = sContent.find('=', ip);
}
while(i != std::string::npos && i + 2 < sContent.length())
{
sRes.WriteString(sContent.c_str() + ip, i - ip);
std::string str = sContent.substr(i + 1, 2);
if(str.front() == '\n' || str.front() == '\r')
{
char ch = str[1];
if(ch != '\n' && ch != '\r')
sRes.WriteString(&ch, 1);
}
else
{
char* err;
char ch = (int)strtol(str.data(), &err, 16);
if(*err)
sRes.WriteString('=' + str);
else
sRes.WriteString(&ch, 1);
}
ip = i + 3;
i = sContent.find('=', ip);
}
if(ip != std::string::npos)
sRes.WriteString(sContent.c_str() + ip);
return sRes.GetData();
}
static std::string mhtTohtml(const std::string& sFileContent);
static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::string>& sRes, NSStringUtils::CStringBuilderA& oRes)
{
size_t unContentPosition = 0, unCharsetBegin = 0, unCharsetEnd = std::string::npos;
NSStringFinder::TFoundedData<char> oData;
// Content-Type
oData = NSStringFinder::FindProperty(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"});
const std::string sContentType{oData.m_sValue};
if (sContentType.empty())
return;
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
{
oRes.WriteString(mhtTohtml(sMhtContent.substr(oData.m_unEndPosition, sMhtContent.length() - oData.m_unEndPosition)));
return;
}
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetBegin = oData.m_unEndPosition;
// name
// std::string sName = NSStringFinder::FindProperty(sMhtContent, "name", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
// unContentPosition = std::max(unContentPosition, unLastPosition);
// Content-Location
oData = NSStringFinder::FindProperty(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"});
std::string sContentLocation{oData.m_sValue};
if (!oData.Empty())
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
// Content-ID
oData = NSStringFinder::FindProperty(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"});
std::string sContentID{oData.m_sValue};
if (!oData.Empty())
{
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
NSStringFinder::CutInside<std::string>(sContentID, "<", ">");
}
if (sContentLocation.empty() && !sContentID.empty())
sContentLocation = "cid:" + sContentID;
// Content-Transfer-Encoding
oData = NSStringFinder::FindProperty(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"});
const std::string sContentEncoding{oData.m_sValue};
if (!oData.Empty())
{
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
}
// charset
std::string sCharset = "utf-8";
if (std::string::npos != unCharsetEnd && unCharsetBegin < unCharsetEnd)
{
sCharset = NSStringFinder::FindProperty(sMhtContent.substr(unCharsetBegin, unCharsetEnd - unCharsetBegin), "charset", {"="}, {";", "\\n", "\\r"}).m_sValue;
NSStringFinder::CutInside<std::string>(sCharset, "\"");
}
// Content
std::string sContent = sMhtContent.substr(unContentPosition, sMhtContent.length() - unContentPosition);
// std::wstring sExtention = NSFile::GetFileExtention(UTF8_TO_U(sName));
// std::transform(sExtention.begin(), sExtention.end(), sExtention.begin(), tolower);
// Основной документ
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
oRes.WriteString(mhtTohtml(sContent));
else if ((NSStringFinder::Find(sContentType, "text") /*&& (sExtention.empty() || NSStringFinder::EqualOf(sExtention, {L"htm", L"html", L"xhtml", L"css"}))*/)
|| (NSStringFinder::Equals(sContentType, "application/octet-stream") && NSStringFinder::Find(sContentLocation, "css")))
{
// Стили заключаются в тэг <style>
const bool bAddTagStyle = NSStringFinder::Equals(sContentType, "text/css") /*|| NSStringFinder::Equals(sExtention, L"css")*/ || NSStringFinder::Find(sContentLocation, "css");
if (bAddTagStyle)
oRes.WriteString("<style>");
if (NSStringFinder::Equals(sContentEncoding, "base64"))
sContent = Base64ToString(sContent, sCharset);
else if (NSStringFinder::EqualOf(sContentEncoding, {"8bit", "7bit"}) || sContentEncoding.empty())
{
if (!NSStringFinder::Equals(sCharset, "utf-8") && !sCharset.empty())
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
}
else if (NSStringFinder::Equals(sContentEncoding, "quoted-printable"))
{
sContent = QuotedPrintableDecode(sContent, sCharset);
if (!NSStringFinder::Equals(sCharset, "utf-8") && !sCharset.empty())
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
}
if (NSStringFinder::Equals(sContentType, "text/html"))
sContent = U_TO_UTF8(htmlToXhtml(sContent, false));
oRes.WriteString(sContent);
if(bAddTagStyle)
oRes.WriteString("</style>");
}
// Картинки
else if ((NSStringFinder::Find(sContentType, "image") /*|| NSStringFinder::Equals(sExtention, L"gif")*/ || NSStringFinder::Equals(sContentType, "application/octet-stream")) &&
NSStringFinder::Equals(sContentEncoding, "base64"))
{
// if (NSStringFinder::Equals(sExtention, L"ico") || NSStringFinder::Find(sContentType, "ico"))
// sContentType = "image/jpg";
// else if(NSStringFinder::Equals(sExtention, L"gif"))
// sContentType = "image/gif";
int nSrcLen = (int)sContent.length();
int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(nSrcLen);
BYTE* pData = new BYTE[nDecodeLen];
if (TRUE == NSBase64::Base64Decode(sContent.c_str(), nSrcLen, pData, &nDecodeLen))
sRes.insert(std::make_pair(sContentLocation, "data:" + sContentType + ";base64," + sContent));
RELEASEARRAYOBJECTS(pData);
}
}
static std::string mhtTohtml(const std::string& sFileContent)
{
std::map<std::string, std::string> sRes;
NSStringUtils::CStringBuilderA oRes;
// Поиск boundary
NSStringFinder::TFoundedData<char> oData{NSStringFinder::FindProperty(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""})};
size_t nFound{oData.m_unEndPosition};
std::string sBoundary{oData.m_sValue};
if (sBoundary.empty())
{
size_t nFoundEnd = sFileContent.length();
nFound = 0;
ReadMht(sFileContent.substr(nFound, nFoundEnd), sRes, oRes);
return oRes.GetData();
}
NSStringFinder::CutInside<std::string>(sBoundary, "\"");
size_t nFoundEnd{nFound};
sBoundary = "--" + sBoundary;
size_t nBoundaryLength = sBoundary.length();
nFound = sFileContent.find(sBoundary, nFound) + nBoundaryLength;
// Цикл по boundary
while(nFound != std::string::npos)
{
nFoundEnd = sFileContent.find(sBoundary, nFound + nBoundaryLength);
if(nFoundEnd == std::string::npos)
break;
ReadMht(sFileContent.substr(nFound, nFoundEnd - nFound), sRes, oRes);
nFound = sFileContent.find(sBoundary, nFoundEnd);
}
std::string sFile = oRes.GetData();
for(const std::pair<std::string, std::string>& item : sRes)
{
std::string sName = item.first;
size_t found = sFile.find(sName);
size_t sfound = sName.rfind('/');
if(found == std::string::npos && sfound != std::string::npos)
found = sFile.find(sName.erase(0, sfound + 1));
while(found != std::string::npos)
{
size_t fq = sFile.find_last_of("\"\'>=", found);
if (std::string::npos == fq)
break;
char ch = sFile[fq];
if(ch != '\"' && ch != '\'')
fq++;
size_t tq = sFile.find_first_of("\"\'<> ", found) + 1;
if (std::string::npos == tq)
break;
if(sFile[tq] != '\"' && sFile[tq] != '\'')
tq--;
if(ch != '>')
{
std::string is = '\"' + item.second + '\"';
sFile.replace(fq, tq - fq, is);
found = sFile.find(sName, fq + is.length());
}
else
found = sFile.find(sName, tq);
}
}
return sFile;
}
// Заменяет сущности &,<,> в text
static void substitute_xml_entities_into_text(std::string& text)
{
// replacing & must come first
replace_all(text, "&", "&amp;");
replace_all(text, "<", "&lt;");
replace_all(text, ">", "&gt;");
}
// After running through Gumbo, the values of type "&#1;" are replaced with the corresponding code '0x01'
// Since the attribute value does not use control characters (value <= 0x09),
// then just delete them, otherwise XmlUtils::CXmlLiteReader crashes on them.
// bug#73486
static void remove_control_symbols(std::string& text)
{
std::string::iterator itFound = std::find_if(text.begin(), text.end(), [](unsigned char chValue){ return chValue <= 0x09; });
while (itFound != text.end())
{
itFound = text.erase(itFound);
itFound = std::find_if(itFound, text.end(), [](unsigned char chValue){ return chValue <= 0x09; });
}
}
// Заменяет сущности " в text
static void substitute_xml_entities_into_attributes(std::string& text)
{
remove_control_symbols(text);
substitute_xml_entities_into_text(text);
replace_all(text, "\"", "&quot;");
}
static std::string handle_unknown_tag(GumboStringPiece* text)
{
if (text->data == NULL)
return "";
GumboStringPiece gsp = *text;
gumbo_tag_from_original_text(&gsp);
std::string sAtr = std::string(gsp.data, gsp.length);
size_t found = sAtr.find_first_of("-'+,./=?;!*#@$_%<>&;\"\'()[]{}");
while(found != std::string::npos)
{
sAtr.erase(found, 1);
found = sAtr.find_first_of("-'+,./=?;!*#@$_%<>&;\"\'()[]{}", found);
}
return sAtr;
}
static std::string get_tag_name(GumboNode* node)
{
std::string tagname = (node->type == GUMBO_NODE_DOCUMENT ? "document" : gumbo_normalized_tagname(node->v.element.tag));
if (tagname.empty())
tagname = handle_unknown_tag(&node->v.element.original_tag);
return tagname;
}
static void build_doctype(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilder)
{
if (node->v.document.has_doctype)
{
oBuilder.WriteString("<!DOCTYPE ");
oBuilder.WriteString(node->v.document.name);
std::string pi(node->v.document.public_identifier);
remove_control_symbols(pi);
if ((node->v.document.public_identifier != NULL) && !pi.empty())
{
oBuilder.WriteString(" PUBLIC \"");
oBuilder.WriteString(pi);
oBuilder.WriteString("\" \"");
oBuilder.WriteString(node->v.document.system_identifier);
oBuilder.WriteString("\"");
}
oBuilder.WriteString(">");
}
}
static void build_attributes(const GumboVector* attribs, NSStringUtils::CStringBuilderA& atts)
{
std::vector<std::string> arrRepeat;
for (size_t i = 0; i < attribs->length; ++i)
{
GumboAttribute* at = static_cast<GumboAttribute*>(attribs->data[i]);
std::string sVal(at->value);
std::string sName(at->name);
remove_control_symbols(sVal);
remove_control_symbols(sName);
atts.WriteString(" ");
bool bCheck = false;
size_t nBad = sName.find_first_of("+,.=?#%<>&;\"\'()[]{}");
while(nBad != std::string::npos)
{
sName.erase(nBad, 1);
nBad = sName.find_first_of("+,.=?#%<>&;\"\'()[]{}", nBad);
if(sName.empty())
break;
bCheck = true;
}
if(sName.empty())
continue;
while(sName.front() >= '0' && sName.front() <= '9')
{
sName.erase(0, 1);
if(sName.empty())
break;
bCheck = true;
}
if(bCheck)
{
GumboAttribute* check = gumbo_get_attribute(attribs, sName.c_str());
if(check || std::find(arrRepeat.begin(), arrRepeat.end(), sName) != arrRepeat.end())
continue;
else
arrRepeat.push_back(sName);
}
if(sName.empty())
continue;
atts.WriteString(sName);
// determine original quote character used if it exists
std::string qs ="\"";
atts.WriteString("=");
atts.WriteString(qs);
substitute_xml_entities_into_attributes(sVal);
atts.WriteString(sVal);
atts.WriteString(qs);
}
}
static void prettyprint(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilder, bool bCheckValidNode = true);
static void prettyprint_contents(GumboNode* node, NSStringUtils::CStringBuilderA& contents, bool bCheckValidNode)
{
std::string key = "|" + get_tag_name(node) + "|";
bool keep_whitespace = preserve_whitespace.find(key) != std::string::npos;
bool is_inline = nonbreaking_inline.find(key) != std::string::npos;
bool is_like_inline = treat_like_inline.find(key) != std::string::npos;
GumboVector* children = &node->v.element.children;
for (size_t i = 0; i < children->length; i++)
{
GumboNode* child = static_cast<GumboNode*> (children->data[i]);
if (child->type == GUMBO_NODE_TEXT)
{
std::string val(child->v.text.text);
remove_control_symbols(val);
substitute_xml_entities_into_text(val);
// Избавление от FF
size_t found = val.find_first_of("\014");
while(found != std::string::npos)
{
val.erase(found, 1);
found = val.find_first_of("\014", found);
}
contents.WriteString(val);
}
else if ((child->type == GUMBO_NODE_ELEMENT) || (child->type == GUMBO_NODE_TEMPLATE))
prettyprint(child, contents, bCheckValidNode);
else if (child->type == GUMBO_NODE_WHITESPACE)
{
if (keep_whitespace || is_inline || is_like_inline)
contents.WriteString(child->v.text.text);
}
else if (child->type != GUMBO_NODE_COMMENT)
{
// Сообщение об ошибке
// Does this actually exist: (child->type == GUMBO_NODE_CDATA)
// fprintf(stderr, "unknown element of type: %d\n", child->type);
}
}
}
static void prettyprint(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilder, bool bCheckValidNode)
{
// special case the document node
if (node->type == GUMBO_NODE_DOCUMENT)
{
build_doctype(node, oBuilder);
prettyprint_contents(node, oBuilder, bCheckValidNode);
return;
}
std::string tagname = get_tag_name(node);
remove_control_symbols(tagname);
if (NodeIsUnprocessed(tagname))
return;
if (bCheckValidNode)
bCheckValidNode = !IsUnckeckedNodes(tagname);
if (bCheckValidNode && html_tags.end() == std::find(html_tags.begin(), html_tags.end(), tagname))
{
prettyprint_contents(node, oBuilder, bCheckValidNode);
return;
}
std::string close = "";
std::string closeTag = "";
std::string key = "|" + tagname + "|";
bool is_empty_tag = empty_tags.find(key) != std::string::npos;
// determine closing tag type
if (is_empty_tag)
close = "/";
else
closeTag = "</" + tagname + ">";
// build results
oBuilder.WriteString("<" + tagname);
// build attr string
const GumboVector* attribs = &node->v.element.attributes;
build_attributes(attribs, oBuilder);
oBuilder.WriteString(close + ">");
// prettyprint your contents
prettyprint_contents(node, oBuilder, bCheckValidNode);
oBuilder.WriteString(closeTag);
}
std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
{
if (bNeedConvert)
{ // Определение кодировки
std::string sEncoding = NSStringFinder::FindProperty(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\"", "'"}).m_sValue;
if (sEncoding.empty())
sEncoding = NSStringFinder::FindProperty(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "}).m_sValue;
if (!sEncoding.empty() && !NSStringFinder::Equals("utf-8", sEncoding))
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
}
}
// Избавляемся от лишних символов до <...
boost::regex oRegex("<[a-zA-Z]");
boost::match_results<typename std::string::const_iterator> oResult;
if (boost::regex_search(sFileContent, oResult, oRegex))
sFileContent.erase(0, oResult.position());
//Избавление от <a ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "a"));
//Избавление от <title ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "title"));
//Избавление от <script ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "script"));
// Gumbo
GumboOptions options = kGumboDefaultOptions;
GumboOutput* output = gumbo_parse_with_options(&options, sFileContent.data(), sFileContent.length());
// prettyprint
NSStringUtils::CStringBuilderA oBuilder;
prettyprint(output->document, oBuilder);
// Конвертирование из string utf8 в wstring
return UTF8_TO_U(oBuilder.GetData());
}
std::wstring mhtToXhtml(std::string& sFileContent)
{
sFileContent = mhtTohtml(sFileContent);
// Gumbo
GumboOptions options = kGumboDefaultOptions;
GumboOutput* output = gumbo_parse_with_options(&options, sFileContent.data(), sFileContent.length());
// prettyprint
NSStringUtils::CStringBuilderA oBuilder;
prettyprint(output->document, oBuilder);
// Конвертирование из string utf8 в wstring
return UTF8_TO_U(oBuilder.GetData());
}
}

View File

@ -2,658 +2,11 @@
#define HTMLTOXHTML_H
#include <string>
#include <map>
#include <cctype>
#include <vector>
#include <algorithm>
#include "gumbo-parser/src/gumbo.h"
#include "../../../DesktopEditor/common/File.h"
#include "../../../DesktopEditor/common/Directory.h"
#include "../../../DesktopEditor/common/StringBuilder.h"
#include "../../../DesktopEditor/xml/include/xmlutils.h"
#include "../../../UnicodeConverter/UnicodeConverter.h"
#include "../../../HtmlFile2/src/StringFinder.h"
#if defined(CreateDirectory)
#undef CreateDirectory
#endif
static std::string nonbreaking_inline = "|a|abbr|acronym|b|bdo|big|cite|code|dfn|em|font|i|img|kbd|nobr|s|small|span|strike|strong|sub|sup|tt|";
static std::string empty_tags = "|area|base|basefont|bgsound|br|command|col|embed|event-source|frame|hr|image|img|input|keygen|link|menuitem|meta|param|source|spacer|track|wbr|";
static std::string preserve_whitespace = "|pre|textarea|script|style|";
static std::string special_handling = "|html|body|";
static std::string treat_like_inline = "|p|";
static std::vector<std::string> html_tags = {"div","span","a","img","p","h1","h2","h3","h4","h5","h6",
"ul", "ol", "li","td","tr","table","thead","tbody","tfoot","th",
"br","form","input","button","section","nav","header","footer",
"main","figure","figcaption","strong","em","i", "b", "u","pre",
"code","blockquote","hr","script","link","meta","style","title",
"head","body","html","legend","optgroup","option","select","dl",
"dt","dd","time","data","abbr","address","area","base","bdi",
"bdo","cite","col","iframe","video","source","track","textarea",
"label","fieldset","colgroup","del","ins","details","summary",
"dialog","embed","kbd","map","mark","menu","meter","object",
"output","param","progress","q","samp","small","sub","sup","var",
"wbr","acronym","applet","article","aside","audio","basefont",
"bgsound","big","blink","canvas","caption","center","command",
"comment","datalist","dfn","dir","font","frame","frameset",
"hgroup","isindex","keygen","marquee","nobr","noembed","noframes",
"noscript","plaintext","rp","rt","ruby","s","strike","tt","xmp"};
static std::vector<std::string> unchecked_nodes_new = {"svg"};
static void prettyprint(GumboNode*, NSStringUtils::CStringBuilderA& oBuilder, bool bCheckValidNode = true);
static std::string mhtTohtml(const std::string &sFileContent);
// Заменяет в строке s все символы s1 на s2
static void replace_all(std::string& s, const std::string& s1, const std::string& s2)
namespace HTML
{
size_t pos = s.find(s1);
while(pos != std::string::npos)
{
s.replace(pos, s1.length(), s2);
pos = s.find(s1, pos + s2.length());
}
}
static bool NodeIsUnprocessed(const std::string& wsTagName)
{
return "xml" == wsTagName;
}
static bool IsUnckeckedNodes(const std::string& sValue)
{
return unchecked_nodes_new.end() != std::find(unchecked_nodes_new.begin(), unchecked_nodes_new.end(), sValue);
}
static std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
{
if (bNeedConvert)
{ // Определение кодировки
std::string sEncoding = NSStringFinder::FindProperty(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\"", "'"}).m_sValue;
if (sEncoding.empty())
sEncoding = NSStringFinder::FindProperty(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "}).m_sValue;
if (!sEncoding.empty() && !NSStringFinder::Equals("utf-8", sEncoding))
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
}
}
// Избавляемся от лишних символов до <...
boost::regex oRegex("<[a-zA-Z]");
boost::match_results<typename std::string::const_iterator> oResult;
if (boost::regex_search(sFileContent, oResult, oRegex))
sFileContent.erase(0, oResult.position());
//Избавление от <a ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "a"));
//Избавление от <title ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "title"));
//Избавление от <script ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "script"));
// Gumbo
GumboOptions options = kGumboDefaultOptions;
GumboOutput* output = gumbo_parse_with_options(&options, sFileContent.data(), sFileContent.length());
// prettyprint
NSStringUtils::CStringBuilderA oBuilder;
prettyprint(output->document, oBuilder);
// Конвертирование из string utf8 в wstring
return UTF8_TO_U(oBuilder.GetData());
}
static std::string Base64ToString(const std::string& sContent, const std::string& sCharset)
{
std::string sRes;
int nSrcLen = (int)sContent.length();
int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(nSrcLen);
BYTE* pData = new BYTE[nDecodeLen];
if (TRUE == NSBase64::Base64Decode(sContent.c_str(), nSrcLen, pData, &nDecodeLen))
{
std::wstring sConvert;
if(!sCharset.empty() && NSStringFinder::Equals<std::string>("utf-8", sCharset))
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sConvert = oConverter.toUnicode(reinterpret_cast<char *>(pData), (unsigned)nDecodeLen, sCharset.data());
}
sRes = sConvert.empty() ? std::string(reinterpret_cast<char *>(pData), nDecodeLen) : U_TO_UTF8(sConvert);
}
RELEASEARRAYOBJECTS(pData);
return sRes;
}
static std::string QuotedPrintableDecode(const std::string& sContent, std::string& sCharset)
{
NSStringUtils::CStringBuilderA sRes;
size_t ip = 0;
size_t i = sContent.find('=');
if(i == 0)
{
size_t nIgnore = 12;
std::string charset = sContent.substr(0, nIgnore);
if(charset == "=00=00=FE=FF")
sCharset = "UTF-32BE";
else if(charset == "=FF=FE=00=00")
sCharset = "UTF-32LE";
else if(charset == "=2B=2F=76=38" || charset == "=2B=2F=76=39" ||
charset == "=2B=2F=76=2B" || charset == "=2B=2F=76=2F")
sCharset = "UTF-7";
else if(charset == "=DD=73=66=73")
sCharset = "UTF-EBCDIC";
else if(charset == "=84=31=95=33")
sCharset = "GB-18030";
else
{
nIgnore -= 3;
charset.erase(nIgnore);
if(charset == "=EF=BB=BF")
sCharset = "UTF-8";
else if(charset == "=F7=64=4C")
sCharset = "UTF-1";
else if(charset == "=0E=FE=FF")
sCharset = "SCSU";
else if(charset == "=FB=EE=28")
sCharset = "BOCU-1";
else
{
nIgnore -= 3;
charset.erase(nIgnore);
if(charset == "=FE=FF")
sCharset = "UTF-16BE";
else if(charset == "=FF=FE")
sCharset = "UTF-16LE";
else
nIgnore -= 6;
}
}
ip = nIgnore;
i = sContent.find('=', ip);
}
while(i != std::string::npos && i + 2 < sContent.length())
{
sRes.WriteString(sContent.c_str() + ip, i - ip);
std::string str = sContent.substr(i + 1, 2);
if(str.front() == '\n' || str.front() == '\r')
{
char ch = str[1];
if(ch != '\n' && ch != '\r')
sRes.WriteString(&ch, 1);
}
else
{
char* err;
char ch = (int)strtol(str.data(), &err, 16);
if(*err)
sRes.WriteString('=' + str);
else
sRes.WriteString(&ch, 1);
}
ip = i + 3;
i = sContent.find('=', ip);
}
if(ip != std::string::npos)
sRes.WriteString(sContent.c_str() + ip);
return sRes.GetData();
}
static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::string>& sRes, NSStringUtils::CStringBuilderA& oRes)
{
size_t unContentPosition = 0, unCharsetBegin = 0, unCharsetEnd = std::string::npos;
NSStringFinder::TFoundedData<char> oData;
// Content-Type
oData = NSStringFinder::FindProperty(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"});
const std::string sContentType{oData.m_sValue};
if (sContentType.empty())
return;
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
{
oRes.WriteString(mhtTohtml(sMhtContent.substr(oData.m_unEndPosition, sMhtContent.length() - oData.m_unEndPosition)));
return;
}
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetBegin = oData.m_unEndPosition;
// name
// std::string sName = NSStringFinder::FindProperty(sMhtContent, "name", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
// unContentPosition = std::max(unContentPosition, unLastPosition);
// Content-Location
oData = NSStringFinder::FindProperty(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"});
std::string sContentLocation{oData.m_sValue};
if (!oData.Empty())
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
// Content-ID
oData = NSStringFinder::FindProperty(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"});
std::string sContentID{oData.m_sValue};
if (!oData.Empty())
{
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
NSStringFinder::CutInside<std::string>(sContentID, "<", ">");
}
if (sContentLocation.empty() && !sContentID.empty())
sContentLocation = "cid:" + sContentID;
// Content-Transfer-Encoding
oData = NSStringFinder::FindProperty(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"});
const std::string sContentEncoding{oData.m_sValue};
if (!oData.Empty())
{
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
}
// charset
std::string sCharset = "utf-8";
if (std::string::npos != unCharsetEnd && unCharsetBegin < unCharsetEnd)
{
sCharset = NSStringFinder::FindProperty(sMhtContent.substr(unCharsetBegin, unCharsetEnd - unCharsetBegin), "charset", {"="}, {";", "\\n", "\\r"}).m_sValue;
NSStringFinder::CutInside<std::string>(sCharset, "\"");
}
// Content
std::string sContent = sMhtContent.substr(unContentPosition, sMhtContent.length() - unContentPosition);
// std::wstring sExtention = NSFile::GetFileExtention(UTF8_TO_U(sName));
// std::transform(sExtention.begin(), sExtention.end(), sExtention.begin(), tolower);
// Основной документ
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
oRes.WriteString(mhtTohtml(sContent));
else if ((NSStringFinder::Find(sContentType, "text") /*&& (sExtention.empty() || NSStringFinder::EqualOf(sExtention, {L"htm", L"html", L"xhtml", L"css"}))*/)
|| (NSStringFinder::Equals(sContentType, "application/octet-stream") && NSStringFinder::Find(sContentLocation, "css")))
{
// Стили заключаются в тэг <style>
const bool bAddTagStyle = NSStringFinder::Equals(sContentType, "text/css") /*|| NSStringFinder::Equals(sExtention, L"css")*/ || NSStringFinder::Find(sContentLocation, "css");
if (bAddTagStyle)
oRes.WriteString("<style>");
if (NSStringFinder::Equals(sContentEncoding, "base64"))
sContent = Base64ToString(sContent, sCharset);
else if (NSStringFinder::EqualOf(sContentEncoding, {"8bit", "7bit"}) || sContentEncoding.empty())
{
if (!NSStringFinder::Equals(sCharset, "utf-8") && !sCharset.empty())
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
}
else if (NSStringFinder::Equals(sContentEncoding, "quoted-printable"))
{
sContent = QuotedPrintableDecode(sContent, sCharset);
if (!NSStringFinder::Equals(sCharset, "utf-8") && !sCharset.empty())
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
}
if (NSStringFinder::Equals(sContentType, "text/html"))
sContent = U_TO_UTF8(htmlToXhtml(sContent, false));
oRes.WriteString(sContent);
if(bAddTagStyle)
oRes.WriteString("</style>");
}
// Картинки
else if ((NSStringFinder::Find(sContentType, "image") /*|| NSStringFinder::Equals(sExtention, L"gif")*/ || NSStringFinder::Equals(sContentType, "application/octet-stream")) &&
NSStringFinder::Equals(sContentEncoding, "base64"))
{
// if (NSStringFinder::Equals(sExtention, L"ico") || NSStringFinder::Find(sContentType, "ico"))
// sContentType = "image/jpg";
// else if(NSStringFinder::Equals(sExtention, L"gif"))
// sContentType = "image/gif";
int nSrcLen = (int)sContent.length();
int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(nSrcLen);
BYTE* pData = new BYTE[nDecodeLen];
if (TRUE == NSBase64::Base64Decode(sContent.c_str(), nSrcLen, pData, &nDecodeLen))
sRes.insert(std::make_pair(sContentLocation, "data:" + sContentType + ";base64," + sContent));
RELEASEARRAYOBJECTS(pData);
}
}
static std::string mhtTohtml(const std::string& sFileContent)
{
std::map<std::string, std::string> sRes;
NSStringUtils::CStringBuilderA oRes;
// Поиск boundary
NSStringFinder::TFoundedData<char> oData{NSStringFinder::FindProperty(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""})};
size_t nFound{oData.m_unEndPosition};
std::string sBoundary{oData.m_sValue};
if (sBoundary.empty())
{
size_t nFoundEnd = sFileContent.length();
nFound = 0;
ReadMht(sFileContent.substr(nFound, nFoundEnd), sRes, oRes);
return oRes.GetData();
}
NSStringFinder::CutInside<std::string>(sBoundary, "\"");
size_t nFoundEnd{nFound};
sBoundary = "--" + sBoundary;
size_t nBoundaryLength = sBoundary.length();
nFound = sFileContent.find(sBoundary, nFound) + nBoundaryLength;
// Цикл по boundary
while(nFound != std::string::npos)
{
nFoundEnd = sFileContent.find(sBoundary, nFound + nBoundaryLength);
if(nFoundEnd == std::string::npos)
break;
ReadMht(sFileContent.substr(nFound, nFoundEnd - nFound), sRes, oRes);
nFound = sFileContent.find(sBoundary, nFoundEnd);
}
std::string sFile = oRes.GetData();
for(const std::pair<std::string, std::string>& item : sRes)
{
std::string sName = item.first;
size_t found = sFile.find(sName);
size_t sfound = sName.rfind('/');
if(found == std::string::npos && sfound != std::string::npos)
found = sFile.find(sName.erase(0, sfound + 1));
while(found != std::string::npos)
{
size_t fq = sFile.find_last_of("\"\'>=", found);
if (std::string::npos == fq)
break;
char ch = sFile[fq];
if(ch != '\"' && ch != '\'')
fq++;
size_t tq = sFile.find_first_of("\"\'<> ", found) + 1;
if (std::string::npos == tq)
break;
if(sFile[tq] != '\"' && sFile[tq] != '\'')
tq--;
if(ch != '>')
{
std::string is = '\"' + item.second + '\"';
sFile.replace(fq, tq - fq, is);
found = sFile.find(sName, fq + is.length());
}
else
found = sFile.find(sName, tq);
}
}
return sFile;
}
static std::wstring mhtToXhtml(std::string& sFileContent)
{
sFileContent = mhtTohtml(sFileContent);
// Gumbo
GumboOptions options = kGumboDefaultOptions;
GumboOutput* output = gumbo_parse_with_options(&options, sFileContent.data(), sFileContent.length());
// prettyprint
NSStringUtils::CStringBuilderA oBuilder;
prettyprint(output->document, oBuilder);
// Конвертирование из string utf8 в wstring
return UTF8_TO_U(oBuilder.GetData());
}
// Заменяет сущности &,<,> в text
static void substitute_xml_entities_into_text(std::string& text)
{
// replacing & must come first
replace_all(text, "&", "&amp;");
replace_all(text, "<", "&lt;");
replace_all(text, ">", "&gt;");
}
// After running through Gumbo, the values of type "&#1;" are replaced with the corresponding code '0x01'
// Since the attribute value does not use control characters (value <= 0x09),
// then just delete them, otherwise XmlUtils::CXmlLiteReader crashes on them.
// bug#73486
static void remove_control_symbols(std::string& text)
{
std::string::iterator itFound = std::find_if(text.begin(), text.end(), [](unsigned char chValue){ return chValue <= 0x09; });
while (itFound != text.end())
{
itFound = text.erase(itFound);
itFound = std::find_if(itFound, text.end(), [](unsigned char chValue){ return chValue <= 0x09; });
}
}
// Заменяет сущности " в text
static void substitute_xml_entities_into_attributes(std::string& text)
{
remove_control_symbols(text);
substitute_xml_entities_into_text(text);
replace_all(text, "\"", "&quot;");
}
static std::string handle_unknown_tag(GumboStringPiece* text)
{
if (text->data == NULL)
return "";
GumboStringPiece gsp = *text;
gumbo_tag_from_original_text(&gsp);
std::string sAtr = std::string(gsp.data, gsp.length);
size_t found = sAtr.find_first_of("-'+,./=?;!*#@$_%<>&;\"\'()[]{}");
while(found != std::string::npos)
{
sAtr.erase(found, 1);
found = sAtr.find_first_of("-'+,./=?;!*#@$_%<>&;\"\'()[]{}", found);
}
return sAtr;
}
static std::string get_tag_name(GumboNode* node)
{
std::string tagname = (node->type == GUMBO_NODE_DOCUMENT ? "document" : gumbo_normalized_tagname(node->v.element.tag));
if (tagname.empty())
tagname = handle_unknown_tag(&node->v.element.original_tag);
return tagname;
}
static void build_doctype(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilder)
{
if (node->v.document.has_doctype)
{
oBuilder.WriteString("<!DOCTYPE ");
oBuilder.WriteString(node->v.document.name);
std::string pi(node->v.document.public_identifier);
remove_control_symbols(pi);
if ((node->v.document.public_identifier != NULL) && !pi.empty())
{
oBuilder.WriteString(" PUBLIC \"");
oBuilder.WriteString(pi);
oBuilder.WriteString("\" \"");
oBuilder.WriteString(node->v.document.system_identifier);
oBuilder.WriteString("\"");
}
oBuilder.WriteString(">");
}
}
static void build_attributes(const GumboVector* attribs, NSStringUtils::CStringBuilderA& atts)
{
std::vector<std::string> arrRepeat;
for (size_t i = 0; i < attribs->length; ++i)
{
GumboAttribute* at = static_cast<GumboAttribute*>(attribs->data[i]);
std::string sVal(at->value);
std::string sName(at->name);
remove_control_symbols(sVal);
remove_control_symbols(sName);
atts.WriteString(" ");
bool bCheck = false;
size_t nBad = sName.find_first_of("+,.=?#%<>&;\"\'()[]{}");
while(nBad != std::string::npos)
{
sName.erase(nBad, 1);
nBad = sName.find_first_of("+,.=?#%<>&;\"\'()[]{}", nBad);
if(sName.empty())
break;
bCheck = true;
}
if(sName.empty())
continue;
while(sName.front() >= '0' && sName.front() <= '9')
{
sName.erase(0, 1);
if(sName.empty())
break;
bCheck = true;
}
if(bCheck)
{
GumboAttribute* check = gumbo_get_attribute(attribs, sName.c_str());
if(check || std::find(arrRepeat.begin(), arrRepeat.end(), sName) != arrRepeat.end())
continue;
else
arrRepeat.push_back(sName);
}
if(sName.empty())
continue;
atts.WriteString(sName);
// determine original quote character used if it exists
std::string qs ="\"";
atts.WriteString("=");
atts.WriteString(qs);
substitute_xml_entities_into_attributes(sVal);
atts.WriteString(sVal);
atts.WriteString(qs);
}
}
static void prettyprint_contents(GumboNode* node, NSStringUtils::CStringBuilderA& contents, bool bCheckValidNode)
{
std::string key = "|" + get_tag_name(node) + "|";
bool keep_whitespace = preserve_whitespace.find(key) != std::string::npos;
bool is_inline = nonbreaking_inline.find(key) != std::string::npos;
bool is_like_inline = treat_like_inline.find(key) != std::string::npos;
GumboVector* children = &node->v.element.children;
for (size_t i = 0; i < children->length; i++)
{
GumboNode* child = static_cast<GumboNode*> (children->data[i]);
if (child->type == GUMBO_NODE_TEXT)
{
std::string val(child->v.text.text);
remove_control_symbols(val);
substitute_xml_entities_into_text(val);
// Избавление от FF
size_t found = val.find_first_of("\014");
while(found != std::string::npos)
{
val.erase(found, 1);
found = val.find_first_of("\014", found);
}
contents.WriteString(val);
}
else if ((child->type == GUMBO_NODE_ELEMENT) || (child->type == GUMBO_NODE_TEMPLATE))
prettyprint(child, contents, bCheckValidNode);
else if (child->type == GUMBO_NODE_WHITESPACE)
{
if (keep_whitespace || is_inline || is_like_inline)
contents.WriteString(child->v.text.text);
}
else if (child->type != GUMBO_NODE_COMMENT)
{
// Сообщение об ошибке
// Does this actually exist: (child->type == GUMBO_NODE_CDATA)
// fprintf(stderr, "unknown element of type: %d\n", child->type);
}
}
}
static void prettyprint(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilder, bool bCheckValidNode)
{
// special case the document node
if (node->type == GUMBO_NODE_DOCUMENT)
{
build_doctype(node, oBuilder);
prettyprint_contents(node, oBuilder, bCheckValidNode);
return;
}
std::string tagname = get_tag_name(node);
remove_control_symbols(tagname);
if (NodeIsUnprocessed(tagname))
return;
if (bCheckValidNode)
bCheckValidNode = !IsUnckeckedNodes(tagname);
if (bCheckValidNode && html_tags.end() == std::find(html_tags.begin(), html_tags.end(), tagname))
{
prettyprint_contents(node, oBuilder, bCheckValidNode);
return;
}
std::string close = "";
std::string closeTag = "";
std::string key = "|" + tagname + "|";
bool is_empty_tag = empty_tags.find(key) != std::string::npos;
// determine closing tag type
if (is_empty_tag)
close = "/";
else
closeTag = "</" + tagname + ">";
// build results
oBuilder.WriteString("<" + tagname);
// build attr string
const GumboVector* attribs = &node->v.element.attributes;
build_attributes(attribs, oBuilder);
oBuilder.WriteString(close + ">");
// prettyprint your contents
prettyprint_contents(node, oBuilder, bCheckValidNode);
oBuilder.WriteString(closeTag);
std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert);
std::wstring mhtToXhtml(std::string& sFileContent);
}
#endif // HTMLTOXHTML_H

View File

@ -967,6 +967,10 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT;
else if (0 == sExt.compare(L".md"))
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MD;
else if (0 == sExt.compare(L".tsv"))
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV;
else if (0 == sExt.compare(L".scsv"))
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV;
else if (0 == sExt.compare(L".csv") || 0 == sExt.compare(L".tsv") || 0 == sExt.compare(L".dsv") || 0 == sExt.compare(L".cssv")
|| 0 == sExt.compare(L".xls") || 0 == sExt.compare(L".xlsx") || 0 == sExt.compare(L".xlsb"))
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
@ -1800,6 +1804,10 @@ std::wstring COfficeFileFormatChecker::GetExtensionByType(int type)
return L".ods";
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV:
return L".csv";
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV:
return L".tsv";
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV:
return L".scsv";
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT:
return L".fods";
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS:
@ -1989,7 +1997,11 @@ int COfficeFileFormatChecker::GetFormatByExtension(const std::wstring &sExt)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB;
if (L".xls" == ext)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
if (L".csv" == ext)
if (L".tsv" == ext)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV;
if (L".scsv" == ext)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV;
if (L".csv" == ext || L".dsv" == ext)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
if (L".fods" == ext)
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT;

View File

@ -87,13 +87,14 @@
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0005
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0006
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0007
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0008
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0009
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000a
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000b
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_PACKAGE AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000c
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000d
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0014
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0024
#define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM 0x0200
#define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0001

View File

@ -199,6 +199,13 @@ core_win_64 {
DEFINES += WIN64 _WIN64
}
defineTest(startsWith) {
tmp = $$2
tmp ~= s,^$$re_escape($$1),,
!equals(tmp, $$2): return(true)
return(false)
}
core_linux {
DEFINES += LINUX _LINUX
@ -213,7 +220,7 @@ core_linux {
}
QMAKE_CUSTOM_SYSROOT_BIN = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , /)
contains(QMAKE_CUSTOM_SYSROOT_BIN, $$QMAKE_CUSTOM_SYSROOT) {
startsWith($$QMAKE_CUSTOM_SYSROOT, $$QMAKE_CUSTOM_SYSROOT_BIN) {
message("Using compilers from same sysroot")
QMAKE_CC = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "gcc")
QMAKE_CXX = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")

View File

@ -195,6 +195,16 @@ namespace NSStringUtils
m_pDataCur = m_pData;
m_lSizeCur = m_lSize;
}
CStringBuilder::CStringBuilder(size_t nSize)
{
m_lSize = nSize;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
m_lSizeCur = 0;
m_pDataCur = m_pData;
return;
}
CStringBuilder::~CStringBuilder()
{
if (NULL != m_pData)

View File

@ -86,6 +86,7 @@ namespace NSStringUtils
public:
CStringBuilder();
CStringBuilder(size_t nSize);
virtual ~CStringBuilder();
virtual void AddSize(size_t nSize);

View File

@ -347,11 +347,11 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
}
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"Api.asc_nativeInitBuilder();");
bIsBreak = !this->ExecuteCommand(L"Asc.editor.asc_nativeInitBuilder();");
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"Api.asc_SetSilentMode(true);");
bIsBreak = !this->ExecuteCommand(L"Asc.editor.asc_SetSilentMode(true);");
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"Api.asc_showComments();");
bIsBreak = !this->ExecuteCommand(L"Asc.editor.asc_showComments();");
LOGGER_SPEED_LAP("open");
@ -425,7 +425,7 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
bIsSilentMode = true;
if (bIsSilentMode)
this->ExecuteCommand(L"Api.asc_SetSilentMode(false);", NULL, isEnterContext);
this->ExecuteCommand(L"Asc.editor.asc_SetSilentMode(false);", NULL, isEnterContext);
std::wstring strError;
bool bIsError = Doct_renderer_SaveFile_ForBuilder(_formatDst,
@ -437,7 +437,7 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
sJsonParams);
if (bIsSilentMode)
this->ExecuteCommand(L"Api.asc_SetSilentMode(true);", NULL, isEnterContext);
this->ExecuteCommand(L"Asc.editor.asc_SetSilentMode(true);", NULL, isEnterContext);
if (isEnterContext)
m_context->Exit();
@ -1507,7 +1507,7 @@ namespace NSDoctRenderer
if (m_pInternal->m_oParams.m_bSaveWithDoctrendererMode)
{
// перед сохранением в такой схеме нужно скинуть изменения
this->ExecuteCommand(L"Api.asc_Save();");
this->ExecuteCommand(L"Asc.editor.asc_Save();");
}
const wchar_t* sParams = NULL;

View File

@ -287,7 +287,10 @@ namespace NSDoctRenderer
JSSmart<CJSObject> js_objectApi = api_js_maybe_null;
if (!js_objectApi.IsInit() || js_objectApi->isUndefined())
js_objectApi = global_js->get("Api")->toObject();
{
JSSmart<CJSObject> js_objectAsc = global_js->get("Asc")->toObject();
js_objectApi = js_objectAsc->get("editor")->toObject();
}
bool bIsBreak = false;
if (js_objectApi->isUndefined() || !js_objectApi->isObject())
@ -687,7 +690,8 @@ namespace NSDoctRenderer
bIsBreak = true;
}
js_objectApi = global_js->get("Api")->toObject();
JSSmart<CJSObject> js_objectAsc = global_js->get("Asc")->toObject();
js_objectApi = js_objectAsc->get("editor")->toObject();
if (try_catch->Check())
{
strError = L"code=\"open\"";

View File

@ -602,6 +602,12 @@ public:
std::wstring sFontName = UTF8_TO_U(sPathA);
return ((CPdfFile*)m_pFile)->GetGIDByUnicode(sFontName);
}
BYTE* GetGIDByUnicode(const std::wstring& wsPathA)
{
if (m_nType != 0)
return NULL;
return ((CPdfFile*)m_pFile)->GetGIDByUnicode(wsPathA);
}
std::wstring GetFontBinaryNative(const std::wstring& sName)
{

View File

@ -137,6 +137,10 @@ JSSmart<CJSValue> CDrawingFileEmbed::DestroyTextInfo()
m_pFile->DestroyTextInfo();
return CJSContext::createUndefined();
}
JSSmart<CJSValue> CDrawingFileEmbed::GetGIDByUnicode(JSSmart<CJSValue> sId)
{
return WasmMemoryToJS(m_pFile->GetGIDByUnicode(sId->toStringW()));
}
JSSmart<CJSValue> CDrawingFileEmbed::IsNeedCMap()
{
return CJSContext::createBool(false);
@ -145,6 +149,11 @@ JSSmart<CJSValue> CDrawingFileEmbed::ScanPage(JSSmart<CJSValue> nPageIndex, JSSm
{
return WasmMemoryToJS(m_pFile->ScanPage(nPageIndex->toInt32(), mode->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::SetScanPageFonts(JSSmart<CJSValue> nPageIndex)
{
m_pFile->SetScanPageFonts(nPageIndex->toInt32());
return CJSContext::createUndefined();
}
JSSmart<CJSValue> CDrawingFileEmbed::GetImageBase64(JSSmart<CJSValue> rId)
{
@ -243,6 +252,17 @@ JSSmart<CJSValue> CDrawingFileEmbed::UndoRedact()
return CJSContext::createBool(false);
}
JSSmart<CJSValue> CDrawingFileEmbed::CheckOwnerPassword(JSSmart<CJSValue> sPassword)
{
std::wstring wsPassword = sPassword->isString() ? sPassword->toStringW() : L"";
bool bResult = m_pFile->CheckOwnerPassword(sPassword->isString() ? wsPassword.c_str() : NULL);
return CJSContext::createBool(bResult);
}
JSSmart<CJSValue> CDrawingFileEmbed::CheckPerm(JSSmart<CJSValue> nPerm)
{
return CJSContext::createBool(m_pFile->CheckPerm(nPerm->toInt32()));
}
bool EmbedDrawingFile(JSSmart<NSJSBase::CJSContext>& context, IOfficeDrawingFile* pFile)
{
CJSContext::Embed<CDrawingFileEmbed>(false);

View File

@ -43,9 +43,11 @@ public:
JSSmart<CJSValue> GetFontBinary(JSSmart<CJSValue> Id);
JSSmart<CJSValue> GetGlyphs(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> DestroyTextInfo();
JSSmart<CJSValue> GetGIDByUnicode(JSSmart<CJSValue> sId);
JSSmart<CJSValue> IsNeedCMap();
JSSmart<CJSValue> ScanPage(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> mode);
JSSmart<CJSValue> SetScanPageFonts(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetImageBase64(JSSmart<CJSValue> rId);
@ -57,6 +59,9 @@ public:
JSSmart<CJSValue> RedactPage(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> arrRedactBox, JSSmart<CJSValue> dataFiller);
JSSmart<CJSValue> UndoRedact();
JSSmart<CJSValue> CheckOwnerPassword(JSSmart<CJSValue> sPassword);
JSSmart<CJSValue> CheckPerm(JSSmart<CJSValue> nPerm);
DECLARE_EMBED_METHODS
};

View File

@ -23,8 +23,10 @@
-(JSValue*) GetFontBinary : (JSValue*)Id;
-(JSValue*) GetGlyphs : (JSValue*)nPageIndex;
-(JSValue*) DestroyTextInfo;
-(JSValue*) GetGIDByUnicode : (JSValue*)sId;
-(JSValue*) IsNeedCMap;
-(JSValue*) ScanPage : (JSValue*)nPageIndex : (JSValue*)mode;
-(JSValue*) SetScanPageFonts : (JSValue*)nPageIndex;
-(JSValue*) GetImageBase64 : (JSValue*)rId;
-(JSValue*) FreeWasmData : (JSValue*)typedArray;
-(JSValue*) SplitPages : (JSValue*)arrPageIndexes : (JSValue*)data;
@ -32,6 +34,8 @@
-(JSValue*) UnmergePages;
-(JSValue*) RedactPage : (JSValue*)nPageIndex : (JSValue*)arrRedactBox : (JSValue*)dataFiller;
-(JSValue*) UndoRedact;
-(JSValue*) CheckOwnerPassword : (JSValue*)sPassword;
-(JSValue*) CheckPerm : (JSValue*)nPerm;
@end
@interface CJSCDrawingFileEmbed : NSObject<IJSCDrawingFileEmbed, JSEmbedObjectProtocol>
@ -62,8 +66,10 @@ FUNCTION_WRAPPER_JS_6(GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_JS_1(GetFontBinary, GetFontBinary)
FUNCTION_WRAPPER_JS_1(GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_JS_0(DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_JS_1(GetGIDByUnicode, GetGIDByUnicode)
FUNCTION_WRAPPER_JS_0(IsNeedCMap, IsNeedCMap)
FUNCTION_WRAPPER_JS_2(ScanPage, ScanPage)
FUNCTION_WRAPPER_JS_1(SetScanPageFonts, SetScanPageFonts)
FUNCTION_WRAPPER_JS_1(GetImageBase64, GetImageBase64)
FUNCTION_WRAPPER_JS_1(FreeWasmData, FreeWasmData)
FUNCTION_WRAPPER_JS_2(SplitPages, SplitPages)
@ -71,6 +77,8 @@ FUNCTION_WRAPPER_JS_3(MergePages, MergePages)
FUNCTION_WRAPPER_JS_0(UnmergePages, UnmergePages)
FUNCTION_WRAPPER_JS_3(RedactPage, RedactPage)
FUNCTION_WRAPPER_JS_0(UndoRedact, UndoRedact)
FUNCTION_WRAPPER_JS_1(CheckOwnerPassword, CheckOwnerPassword)
FUNCTION_WRAPPER_JS_1(CheckPerm, CheckPerm)
@end
class CDrawingFileEmbedAdapter : public CJSEmbedObjectAdapterJSC

View File

@ -26,8 +26,10 @@ namespace NSDrawingFileEmbed
FUNCTION_WRAPPER_V8_1(_GetFontBinary, GetFontBinary)
FUNCTION_WRAPPER_V8_1(_GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_V8_0(_DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_V8_1(_GetGIDByUnicode, GetGIDByUnicode)
FUNCTION_WRAPPER_V8_0(_IsNeedCMap, IsNeedCMap)
FUNCTION_WRAPPER_V8_2(_ScanPage, ScanPage)
FUNCTION_WRAPPER_V8_1(_SetScanPageFonts, SetScanPageFonts)
FUNCTION_WRAPPER_V8_1(_GetImageBase64, GetImageBase64)
FUNCTION_WRAPPER_V8_1(_FreeWasmData, FreeWasmData)
FUNCTION_WRAPPER_V8_2(_SplitPages, SplitPages)
@ -35,6 +37,8 @@ namespace NSDrawingFileEmbed
FUNCTION_WRAPPER_V8_0(_UnmergePages, UnmergePages)
FUNCTION_WRAPPER_V8_3(_RedactPage, RedactPage)
FUNCTION_WRAPPER_V8_0(_UndoRedact, UndoRedact)
FUNCTION_WRAPPER_V8_1(_CheckOwnerPassword, CheckOwnerPassword)
FUNCTION_WRAPPER_V8_1(_CheckPerm, CheckPerm)
v8::Handle<v8::ObjectTemplate> CreateTemplate(v8::Isolate* isolate)
{
@ -60,8 +64,10 @@ namespace NSDrawingFileEmbed
NSV8Objects::Template_Set(result, "GetFontBinary", _GetFontBinary);
NSV8Objects::Template_Set(result, "GetGlyphs", _GetGlyphs);
NSV8Objects::Template_Set(result, "DestroyTextInfo", _DestroyTextInfo);
NSV8Objects::Template_Set(result, "GetGIDByUnicode", _GetGIDByUnicode);
NSV8Objects::Template_Set(result, "IsNeedCMap", _IsNeedCMap);
NSV8Objects::Template_Set(result, "ScanPage", _ScanPage);
NSV8Objects::Template_Set(result, "SetScanPageFonts", _SetScanPageFonts);
NSV8Objects::Template_Set(result, "GetImageBase64", _GetImageBase64);
NSV8Objects::Template_Set(result, "FreeWasmData", _FreeWasmData);
NSV8Objects::Template_Set(result, "SplitPages", _SplitPages);
@ -69,6 +75,8 @@ namespace NSDrawingFileEmbed
NSV8Objects::Template_Set(result, "UnmergePages", _UnmergePages);
NSV8Objects::Template_Set(result, "RedactPage", _RedactPage);
NSV8Objects::Template_Set(result, "UndoRedact", _UndoRedact);
NSV8Objects::Template_Set(result, "CheckOwnerPassword", _CheckOwnerPassword);
NSV8Objects::Template_Set(result, "CheckPerm", _CheckPerm);
return handle_scope.Escape(result);
}

View File

@ -85,6 +85,13 @@ bool Segment::IsEmpty() const noexcept
return Id == 0 && Index == -1 && P.IsZero() && HI.IsZero() && HO.IsZero();
}
bool Segment::Equals(const Segment& other) const noexcept
{
return isZero(P.X - other.P.X) && isZero(P.Y - other.P.Y) &&
isZero(HI.X - other.HI.X) && isZero(HI.Y - other.HI.Y) &&
isZero(HO.X - other.HO.X) && isZero(HO.Y - other.HO.Y);
}
bool Segment::operator==(const Segment& other) const noexcept
{
return (Index == other.Index) && (Id == other.Id);
@ -690,6 +697,12 @@ bool Curve::IsStraight() const noexcept
return !Segment2.IsCurve;
}
bool Curve::Equals(const Curve& other) const noexcept
{
return Segment1.Equals(other.Segment1) &&
Segment2.Equals(other.Segment2);
}
bool Curve::operator==(const Curve& other) const noexcept
{
return Segment1 == other.Segment1 &&
@ -830,7 +843,7 @@ void CBooleanOperations::TraceBoolean()
return;
}
if (!Locations.empty())
if (!Locations.empty() && !IsOnlyEnds())
{
int length = static_cast<int>(Locations.size());
for (int i = 0; i < length; i++)
@ -1845,7 +1858,7 @@ void CBooleanOperations::GetCurveIntersection(const Curve& curve1, const Curve&
AddCurveIntersection(flip ? curve2 : curve1, flip ? curve1 : curve2,
flip ? curve2 : curve1, flip ? curve1 : curve2, flip);
if (Locations.size() == before && (!straight || Locations.empty()))
if (Locations.size() == before && (!straight /*|| Locations.empty()*/))
{
double t = curve2.GetTimeOf(curve1.Segment1.P);
if (t != -1.0)
@ -2058,17 +2071,27 @@ bool CBooleanOperations::IsInside(const Segment& segment) const
void CBooleanOperations::SetWinding()
{
if (Locations.empty() || (Locations.size() == 2 && Locations[0]->Ends))
if (Locations.empty() || (Locations.size() == 2 && Locations[0]->Ends) || IsOnlyEnds())
{
Segment s1, s2;
Segment s1 = Segments1[0], s2 = Segments2[0];
for (const auto& s : Segments1)
if (!s.Inters)
{
bool skip = false;
for (const auto& ss : Segments2)
skip = skip || !s.Equals(ss);
if (!s.Inters && !skip)
s1 = s;
}
for (const auto& s : Segments2)
if (!s.Inters)
{
bool skip = false;
for (const auto& ss : Segments1)
skip = skip || !s.Equals(ss);
if (!s.Inters && !skip)
s2 = s;
}
bool winding = IsInside(s1);
@ -2285,8 +2308,8 @@ bool CBooleanOperations::IsOneCurvePath(int pathIndex) const noexcept
void CBooleanOperations::AddLocation(Curve curve1, Curve curve2, double t1,
double t2, bool overlap, bool filter, bool ends)
{
bool excludeStart = !overlap && GetPreviousCurve(curve1) == curve2,
excludeEnd = !overlap && curve1 != curve2 && GetNextCurve(curve1) == curve2;
bool excludeStart = !overlap && GetPreviousCurve(curve1).Equals(curve2),
excludeEnd = !overlap && curve1 != curve2 && GetNextCurve(curve1).Equals(curve2);
double tMin = CURVETIME_EPSILON,
tMax = 1 - tMin;
@ -2345,6 +2368,18 @@ bool CBooleanOperations::CheckLocation(std::shared_ptr<Location> loc, bool start
return false;
}
bool CBooleanOperations::IsOnlyEnds() const noexcept
{
bool onlyEnds1 = true;
bool onlyEnds2 = true;
for (const auto& l : Locations)
{
onlyEnds1 = onlyEnds1 && l->Ends;
onlyEnds2 = onlyEnds2 && l->Inters->Ends;
}
return onlyEnds1 || onlyEnds2;
}
CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
const CGraphicsPath& path2,
BooleanOpType op,

View File

@ -37,6 +37,7 @@ namespace Aggplus
bool IsValid(const BooleanOpType& op) const noexcept;
bool IsEmpty() const noexcept;
bool Equals(const Segment& other) const noexcept;
bool operator==(const Segment& other) const noexcept;
bool operator!=(const Segment& other) const noexcept;
};
@ -82,6 +83,7 @@ namespace Aggplus
void Flip() noexcept;
bool IsStraight() const noexcept;
bool Equals(const Curve& other) const noexcept;
bool operator==(const Curve& other) const noexcept;
bool operator!=(const Curve& other) const noexcept;
};
@ -159,6 +161,7 @@ namespace Aggplus
bool IsOneCurvePath(int pathIndex) const noexcept;
void AddOffsets(std::vector<double>& offsets, const Curve& curve, bool end);
bool CheckLocation(std::shared_ptr<Location> loc, bool start) const noexcept;
bool IsOnlyEnds() const noexcept;
private:
BooleanOpType Op = Intersection;

View File

@ -1007,16 +1007,18 @@ namespace Aggplus
bool CGraphicsPath::operator==(const CGraphicsPath& other) noexcept
{
unsigned pointsCount = GetPointCount(),
otherPointsCount = other.GetPointCount();
otherPointsCount = other.GetPointCount();
if (pointsCount != otherPointsCount)
return false;
std::vector<PointD> points = GetPoints(0, pointsCount),
otherPoints = other.GetPoints(0, otherPointsCount);
otherPoints = other.GetPoints(0, otherPointsCount);
bool reverse = IsClockwise() ^ other.IsClockwise();
for (unsigned i = 0; i < pointsCount; i++)
if (!points[i].Equals(otherPoints[i]))
if (!points[i].Equals(otherPoints[reverse ? pointsCount - i - 1 : i]))
return false;
return true;

View File

@ -481,6 +481,8 @@ namespace NSOnlineOfficeBinToPdf
double m3 = oReader.ReadDouble();
double m4 = oReader.ReadDouble();
clipRect = Aggplus::RectF_T<double>(m1, m2, m3, m4);
long type;
pRenderer->get_BrushTextureMode(&type);
if (type != c_BrushTextureModeStretch)
@ -489,7 +491,6 @@ namespace NSOnlineOfficeBinToPdf
m2 = 0.0;
}
clipRect = Aggplus::RectF_T<double>(m1, m2, m3, m4);
pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4);
break;
}
@ -498,7 +499,10 @@ namespace NSOnlineOfficeBinToPdf
bIsEnableBrushRect = oReader.ReadBool();
if (!bIsEnableBrushRect)
{
pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, 0, 0, 1, 1);
clipRect = Aggplus::RectF_T<double>();
}
break;
}
case ctBrushTexturePathOld:
@ -770,7 +774,6 @@ namespace NSOnlineOfficeBinToPdf
clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection);
clipRect = Aggplus::RectF_T<double>();
}
pRenderer->AddPath(path);

View File

@ -70,7 +70,7 @@ CAnnotFieldInfo::CActionFieldPr* ReadAction(NSOnlineOfficeBinToPdf::CBufferReade
case 6:
case 7:
{
pRes->nFlags = pReader->ReadByte();
pRes->nFlags = pReader->ReadInt();
if (pRes->nFlags & (1 << 0))
pRes->dD[0] = pReader->ReadDouble();
if (pRes->nFlags & (1 << 1))

View File

@ -197,7 +197,7 @@
},
{
"folder": "../../../../PdfFile/SrcReader/",
"files": ["Adaptors.cpp", "GfxClip.cpp", "RendererOutputDev.cpp", "JPXStream2.cpp", "PdfAnnot.cpp"]
"files": ["Adaptors.cpp", "GfxClip.cpp", "RendererOutputDev.cpp", "JPXStream2.cpp", "PdfAnnot.cpp", "PdfFont.cpp"]
},
{
"folder": "../../../../PdfFile/SrcWriter/",

View File

@ -639,6 +639,7 @@ SOURCES += \
$$PDF_ROOT_DIR/SrcReader/Adaptors.cpp \
$$PDF_ROOT_DIR/SrcReader/GfxClip.cpp \
$$PDF_ROOT_DIR/SrcReader/PdfAnnot.cpp \
$$PDF_ROOT_DIR/SrcReader/PdfFont.cpp \
$$PDF_ROOT_DIR/Resources/BaseFonts.cpp \
$$PDF_ROOT_DIR/Resources/CMapMemory/cmap_memory.cpp
@ -664,6 +665,7 @@ HEADERS +=\
$$PDF_ROOT_DIR/SrcReader/MemoryUtils.h \
$$PDF_ROOT_DIR/SrcReader/GfxClip.h \
$$PDF_ROOT_DIR/SrcReader/FontsWasm.h \
$$PDF_ROOT_DIR/SrcReader/PdfFont.h \
$$PDF_ROOT_DIR/SrcReader/PdfAnnot.h
DEFINES += CRYPTOPP_DISABLE_ASM

View File

@ -364,7 +364,22 @@ CFile.prototype["getFontByID"] = function(ID)
CFile.prototype["getGIDByUnicode"] = function(ID)
{
return this._getGIDByUnicode(ID);
let ptr = this._getGIDByUnicode(ID);
let reader = ptr.getReader();
if (!reader)
return {};
let res = {};
let nFontLength = reader.readInt();
for (let i = 0; i < nFontLength; i++)
{
let np1 = reader.readInt();
let np2 = reader.readInt();
res[np2] = np1;
}
ptr.free();
return res;
};
CFile.prototype["setCMap"] = function(memoryBuffer)
@ -414,7 +429,7 @@ function readAction(reader, rec, readDoubleFunc, readStringFunc)
case 6:
case 7:
{
let nFlag = reader.readByte();
let nFlag = reader.readInt();
if (nFlag & (1 << 0))
rec["left"] = readDoubleFunc.call(reader);
if (nFlag & (1 << 1))
@ -1047,11 +1062,15 @@ function readAnnotType(reader, rec, readDoubleFunc, readDouble2Func, readStringF
if (flags & (1 << 0))
{
rec["A"] = {};
if (isRead)
readStringFunc.call(reader);
readAction(reader, rec["A"], readDoubleFunc, readStringFunc);
}
if (flags & (1 << 1))
{
rec["PA"] = {};
if (isRead)
readStringFunc.call(reader);
readAction(reader, rec["PA"], readDoubleFunc, readStringFunc);
}
// Selection mode - H

View File

@ -296,22 +296,7 @@ CFile.prototype._getGIDByUnicode = function(ID)
Module["HEAP8"].set(idBuffer, idPointer);
g_module_pointer.ptr = Module["_GetGIDByUnicode"](this.nativeFile, idPointer);
Module["_free"](idPointer);
let reader = g_module_pointer.getReader();
if (!reader)
return null;
let res = {};
let nFontLength = reader.readInt();
for (let i = 0; i < nFontLength; i++)
{
let np1 = reader.readInt();
let np2 = reader.readInt();
res[np2] = np1;
}
g_module_pointer.free();
return res;
return g_module_pointer;
}
CFile.prototype._getInteractiveFormsFonts = function(type)

View File

@ -1194,7 +1194,7 @@ int main(int argc, char* argv[])
}
// RASTER
if (true)
if (false)
{
int i = nTestPage;
//for (int i = 0; i < nPagesCount; ++i)

View File

@ -349,7 +349,7 @@ bool CImageFileFormatChecker::isSvgFile(BYTE* pBuffer,DWORD dwBytes)
{
if (eFileType)return false;
if ( (6 <= dwBytes) &&(0x3C == pBuffer[0] && 0x3F == pBuffer[1] && 0x78 == pBuffer[2] && 0x6D == pBuffer[3]
if ( (6 <= dwBytes) && (0x3C == pBuffer[0] && 0x3F == pBuffer[1] && 0x78 == pBuffer[2] && 0x6D == pBuffer[3]
&& 0x6C == pBuffer[4] && 0x20 == pBuffer[5]))
{
std::string sXml_part = std::string((char*)pBuffer, dwBytes);
@ -358,6 +358,11 @@ bool CImageFileFormatChecker::isSvgFile(BYTE* pBuffer,DWORD dwBytes)
return true;
}
}
else if ( (6 <= dwBytes) && (0x3C == pBuffer[0] && 's' == pBuffer[1] && 'v' == pBuffer[2] && 'g' == pBuffer[3]
&& 0x20 == pBuffer[4]))
{
return true;
}
return false;
}

View File

@ -74,7 +74,7 @@ namespace MetaFile
virtual void EndClipPath(unsigned int unMode) = 0;
virtual void UpdateDC() = 0;
virtual void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) = 0;
virtual void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) = 0;
virtual void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) = 0;
};

View File

@ -914,7 +914,7 @@ namespace MetaFile
m_bStartedPath = false;
}
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY)
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{
double dKoefX = m_dScaleX;
double dKoefY = m_dScaleY;
@ -1270,19 +1270,6 @@ namespace MetaFile
if ((NULL != pDataDash && 0 != unSizeDash) || PS_SOLID != ulPenStyle)
{
// Дублированный код из Graphics
// Без этого используется оригинальный код в Graphics, который отрисовывает уже неверно
double dDashWidth{dWidth};
if (!Equals(dWidthMinSize, dWidth))
{
double dDet = oMatrix.Determinant();
if (fabs(dDet) < 0.0001)
dDashWidth *= dSqrtDet;
}
// -----------------------------
if (NULL != pDataDash && 0 != unSizeDash)
{
m_pRenderer->put_PenDashOffset(pPen->GetDashOffset());
@ -1290,7 +1277,7 @@ namespace MetaFile
std::vector<double> arDashes(unSizeDash);
for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex)
arDashes[unIndex] = pDataDash[unIndex] * dDashWidth;
arDashes[unIndex] = pDataDash[unIndex] * dWidth;
m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash);
@ -1304,35 +1291,35 @@ namespace MetaFile
{
case PS_DASH:
{
arDashPattern.push_back(9 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(9 * dWidth);
arDashPattern.push_back(3 * dWidth);
break;
}
case PS_DOT:
{
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(3 * dWidth);
arDashPattern.push_back(3 * dWidth);
break;
}
case PS_DASHDOT:
{
arDashPattern.push_back(9 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
arDashPattern.push_back(3 * dDashWidth);
arDashPattern.push_back(6 * dDashWidth);
arDashPattern.push_back(9 * dWidth);
arDashPattern.push_back(6 * dWidth);
arDashPattern.push_back(3 * dWidth);
arDashPattern.push_back(6 * dWidth);
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);
arDashPattern.push_back(9 * dWidth);
arDashPattern.push_back(6 * dWidth);
arDashPattern.push_back(3 * dWidth);
arDashPattern.push_back(6 * dWidth);
arDashPattern.push_back(3 * dWidth);
arDashPattern.push_back(6 * dWidth);
break;
}

View File

@ -239,7 +239,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override {};
void UpdateDC() override {};
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {};
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override {};
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
};
}

View File

@ -182,7 +182,7 @@ namespace MetaFile
pInterpretator->UpdateDC();
}
void CEmfInterpretatorArray::SetTransform(double &dM11, double &dM12, double &dM21, double &dM22, double &dX, double &dY)
void CEmfInterpretatorArray::SetTransform(const double &dM11, const double &dM12, const double &dM21, const double &dM22, const double &dX, const double &dY)
{
for (CEmfInterpretatorBase* pInterpretator : m_arInterpretators)
pInterpretator->SetTransform(dM11, dM12, dM21, dM22, dX, dY);

View File

@ -57,7 +57,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override;
void UpdateDC() override;
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override;
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override;
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override;
void HANDLE_EMR_HEADER(const TEmfHeader& oTEmfHeader) override;

View File

@ -18,8 +18,8 @@ namespace MetaFile
void CEmfInterpretatorRender::ChangeConditional()
{
if (NULL != m_pMetaFileRenderer)
m_pMetaFileRenderer->ChangeConditional();
if (NULL != m_pMetaFileRenderer)
m_pMetaFileRenderer->ChangeConditional();
}
void CEmfInterpretatorRender::Begin()
@ -143,7 +143,7 @@ namespace MetaFile
m_pMetaFileRenderer->UpdateDC();
}
void CEmfInterpretatorRender::SetTransform(double &dM11, double &dM12, double &dM21, double &dM22, double &dX, double &dY)
void CEmfInterpretatorRender::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{
if (NULL != m_pMetaFileRenderer)
m_pMetaFileRenderer->SetTransform(dM11, dM12, dM21, dM22, dX, dY);

View File

@ -43,7 +43,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override;
void UpdateDC() override;
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override;
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override;
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override;
CMetaFileRenderer* GetRenderer() const;

View File

@ -223,7 +223,7 @@ namespace MetaFile
void EndPath() override {};
void UpdateDC() override {};
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {};
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override {};
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
void SwapClips(CSvgClip& oFirstClip, CSvgClip& oSecondClip);

View File

@ -237,7 +237,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override {};
void UpdateDC() override {};
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {};
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override {};
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
};
}

View File

@ -1264,7 +1264,11 @@ namespace MetaFile
if (NULL != m_pPath)
{
m_pDC->GetClip()->SetPath(*m_pPath, unRegionMode, m_pDC->GetFinalTransform(GM_ADVANCED));
TEmfXForm oTransform{m_pDC->GetFinalTransform(GM_ADVANCED)};
oTransform.Dx -= GetDCBounds().Left;
oTransform.Dy -= GetDCBounds().Top;
m_pDC->GetClip()->SetPath(*m_pPath, unRegionMode, oTransform);
RELEASEOBJECT(m_pPath);
UpdateOutputDC();
}

View File

@ -3284,6 +3284,10 @@ namespace MetaFile
void CEmfPlusParser::Read_EMFPLUS_SETCLIPRECT(unsigned short unShFlags)
{
short shCM = ExpressValue(unShFlags, 8, 11);
if (0 == shCM)
shCM = RGN_COPY;
TEmfPlusRectF oRect;
m_oStream >> oRect;

View File

@ -627,15 +627,13 @@ namespace MetaFile
void CInterpretatorSvgBase::PathClip(const CPath &oPath, int nClipMode, TXForm *pTransform)
{
std::wstring wsPath = CreatePath(oPath, pTransform);
const std::wstring wsPath = CreatePath(oPath, pTransform);
if (wsPath.empty())
return;
const std::wstring wsClipId = L"PATHCLIP_" + ConvertToWString(++m_unNumberDefs, 0);
const std::wstring wsValue = L"<path d=\"" + wsPath + L"\"/>";
m_oClip.AddClipValue(wsClipId, wsValue, nClipMode);
m_oClip.AddClipValue(L"PATHCLIP_" + ConvertToWString(++m_unNumberDefs, 0),
L"<path d=\"" + wsPath + L"\"/>", nClipMode);
}
void CInterpretatorSvgBase::AddStroke(NodeAttributes &arAttributes) const

View File

@ -131,7 +131,7 @@ namespace MetaFile
m_pMetaFileRenderer->UpdateDC();
}
void CWmfInterpretatorRender::SetTransform(double &dM11, double &dM12, double &dM21, double &dM22, double &dX, double &dY)
void CWmfInterpretatorRender::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{
if (NULL != m_pMetaFileRenderer)
m_pMetaFileRenderer->SetTransform(dM11, dM12, dM21, dM22, dX, dY);

View File

@ -40,7 +40,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override;
void UpdateDC() override;
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override;
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override;
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override;
CMetaFileRenderer* GetRenderer() const;

View File

@ -130,7 +130,7 @@ namespace MetaFile
void EndClipPath(unsigned int unMode) override {};
void UpdateDC() override {};
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {};
void SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) override {};
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
};

View File

@ -358,7 +358,7 @@ namespace SVG
bool CRenderedObject::ApplyStroke(IRenderer *pRenderer, const TStroke *pStroke, bool bUseDefault, const CRenderedObject* pContextObject) const
{
if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::EColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))
if (NULL == pRenderer || NULL == pStroke || pStroke->m_oColor.None() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))
{
pRenderer->put_PenSize(0);
return false;
@ -401,7 +401,7 @@ namespace SVG
bool CRenderedObject::ApplyFill(IRenderer *pRenderer, const NSCSS::NSProperties::CColor *pFill, const CSvgFile *pFile, bool bUseDefault, const CRenderedObject* pContextObject) const
{
if (NULL == pRenderer || NULL == pFill || NSCSS::NSProperties::EColorType::ColorNone == pFill->GetType() || (!bUseDefault && pFill->Empty()))
if (NULL == pRenderer || NULL == pFill || pFill->None() || (!bUseDefault && pFill->Empty()))
{
pRenderer->put_BrushType(c_BrushTypeNoFill);
return false;

View File

@ -40,13 +40,14 @@
CPictFile::CPictFile()
{
m_pRenderer = NSGraphics::Create();
m_pFontManager = NSFonts::NSFontManager::Create();
m_pRenderer->SetFontManager(m_pFontManager);
}
CPictFile::~CPictFile()
{
RELEASEINTERFACE(m_pFontManager);
if (m_pAppFonts)
RELEASEINTERFACE(m_pAppFonts);
if (m_pFontManager)
RELEASEINTERFACE(m_pFontManager);
RELEASEINTERFACE(m_pRenderer);
}
@ -1671,6 +1672,7 @@ void CPictFile::DrawArc()
void CPictFile::ReadAndDrawText(int x, int y)
{
InitializeRenderer();
InitializeFonts();
char text[256];
char byte_len = fgetc(m_pFile);
@ -1695,6 +1697,20 @@ void CPictFile::ReadAndDrawText(int x, int y)
m_pRenderer->EndCommand(c_nTextGraphicType);
}
void CPictFile::InitializeFonts()
{
if (m_pAppFonts)
return;
m_pAppFonts = NSFonts::NSApplication::Create();
m_pAppFonts->Initialize();
m_pFontManager = m_pAppFonts->GenerateFontManager();
NSFonts::IFontsCache* fonts_cache = NSFonts::NSFontCache::Create();
fonts_cache->SetStreams(m_pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(fonts_cache);
m_pRenderer->SetFontManager(m_pFontManager);
}
void CPictFile::InitializeRenderer()
{
if (m_pFrameData)

View File

@ -247,6 +247,7 @@ private:
void DrawArc();
void ReadAndDrawText(int x, int y);
void InitializeFonts();
void InitializeRenderer();
private:
@ -257,8 +258,8 @@ private:
CBgraFrame m_oFrame{};
BYTE* m_pFrameData{nullptr};
size_t m_nPenHeight{0};
size_t m_nPenWidth{0};
size_t m_nPenHeight{1};
size_t m_nPenWidth{1};
int m_nFontStyle{0};
int m_nFontSize{0};
@ -275,6 +276,7 @@ private:
std::vector<Aggplus::Point> m_arLastPolygon{};
NSGraphics::IGraphicsRenderer* m_pRenderer{nullptr};
NSFonts::IApplicationFonts* m_pAppFonts{nullptr};
NSFonts::IFontManager* m_pFontManager{nullptr};
};

View File

@ -105,13 +105,13 @@ namespace NSHeif {
inline bool CHeifFile::Decode(heif_context* ctx, CBgraFrame* frame, bool isRGBA)
{
heif_image_handle* handle;
heif_image_handle* handle = nullptr;
defer(heif_image_handle_release(handle););
if (IsError(heif_context_get_primary_image_handle(ctx, &handle)))
return false;
heif_image* img;
heif_image* img = nullptr;
defer(heif_image_release(img););
if (IsError(heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_444, nullptr)))

View File

@ -130,6 +130,7 @@ std::vector<std::wstring> CDocxRenderer::ScanPage(IOfficeDrawingFile* pFile, siz
m_pInternal->m_oDocument.Init(false);
m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bFirstParagraphLineCorrection = true;
m_pInternal->m_bIsSupportShapeCommands = false;
m_pInternal->m_oDocument.m_bIsRecord = false;
@ -147,6 +148,7 @@ std::vector<std::wstring> CDocxRenderer::ScanPagePptx(IOfficeDrawingFile* pFile,
m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bFirstParagraphLineCorrection = true;
m_pInternal->m_bIsSupportShapeCommands = true;
m_pInternal->m_oDocument.m_bIsRecord = false;
@ -165,7 +167,11 @@ NSWasm::CData CDocxRenderer::ScanPageBin(IOfficeDrawingFile* pFile, size_t nPage
m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bFirstParagraphLineCorrection = true;
m_pInternal->m_oDocument.m_bIsRecord = false;
m_pInternal->m_bIsSupportShapeCommands = true;
m_pInternal->m_oDocument.m_oFontStyleManager.Clear();
m_pInternal->m_oDocument.m_oFontSelector.ClearCache();
DrawPage(pFile, nPage);

View File

@ -648,11 +648,15 @@ namespace NSDocxRenderer
if ((nType > 0xFF) && (c_BrushTypeTexture == m_oCurrentPage.m_oBrush.Type))
{
double x = 0, y = 0, w = 0, h = 0;
if (m_oCurrentPage.IsCurrVectorClockwise())
h = -1; // to flip image later
if (m_oCurrentPage.m_oBrush.Image)
pInfo = m_oImageManager.WriteImage(m_oCurrentPage.m_oBrush.Image, x, y, w, h);
else
pInfo = m_oImageManager.WriteImage(m_oCurrentPage.m_oBrush.TexturePath, x, y, w, h);
pInfo = m_oImageManager.WriteImage(m_oCurrentPage.m_oBrush.TexturePath);
}
m_oCurrentPage.DrawPath(nType, pInfo);
return S_OK;
}
@ -712,7 +716,7 @@ namespace NSDocxRenderer
}
HRESULT CDocument::DrawImageFromFile(const std::wstring& sVal, double fX, double fY, double fWidth, double fHeight)
{
m_oCurrentPage.WriteImage(m_oImageManager.WriteImage(sVal, fX, fY, fWidth, fHeight), fX, fY, fWidth, fHeight);
m_oCurrentPage.WriteImage(m_oImageManager.WriteImage(sVal), fX, fY, fWidth, fHeight);
return S_OK;
}
//------------------------------------------------------------------------------------------

View File

@ -70,6 +70,8 @@ namespace NSDocxRenderer
m_oContBuilder.Clear();
m_arCompleteObjectsXml.clear();
m_arLuminosityShapes.clear();
m_bFontSubstitution = false;
}
CPage::~CPage()
@ -275,6 +277,10 @@ namespace NSDocxRenderer
m_arShapes.push_back(shape);
}
}
bool CPage::IsCurrVectorClockwise() const
{
return m_oCurrVectorGraphics.IsClockwise();
}
void CPage::AddText(
const PUINT pUnicodes,
@ -331,14 +337,11 @@ namespace NSDocxRenderer
m_oManagers.pFontManager->MeasureStringGids(pUnicodes, nCount, dTextX, dTextY, _x, _y, _w, _h, CFontManager::mtPosition);
}
_h = m_oManagers.pFontManager->GetFontHeight();
double baseline = dTextY + fBaseLineOffset;
double top = baseline - _h;
double left = dTextX;
double right = dTextR;
if (left == right) // XPS
right = left + _w;
double right = left + _w;
// use forced fold option
const auto& oParams = m_oManagers.pFontManager->GetFontSelectParams();
@ -511,7 +514,7 @@ namespace NSDocxRenderer
cont->CalculateSpace() * c_dSPACE_WIDTH_COEF;
if (curr_line && fabs(curr_line->m_dBot - cont->m_dBot) <= c_dTHE_SAME_STRING_Y_PRECISION_MM &&
fabs(curr_line->m_dRight - cont->m_dLeft) <= 3 * space_width)
fabs(curr_line->m_dRight - cont->m_dLeft) <= 4 * space_width)
{
curr_line->AddCont(cont);
continue;
@ -575,7 +578,7 @@ namespace NSDocxRenderer
shape_ref_ptr_t val = m_arShapes[i];
shape_ref_ptr_t next_val = m_arShapes[i + 1];
if (!val.get() || ! next_val.get())
if (!val.get() || !next_val.get() || next_val.get()->m_nOrder - val.get()->m_nOrder != 1)
continue;
next_val.get()->TryMergeShape(val.get());
@ -760,6 +763,19 @@ namespace NSDocxRenderer
if (line && line->m_arConts.empty())
line = nullptr;
for (auto& line : m_arTextLines)
if (line)
{
bool is_remove = true;
for(auto& cont : line->m_arConts)
if (cont && !cont->IsOnlySpaces())
is_remove = false;
if (is_remove)
line = nullptr;
}
auto right = MoveNullptr(m_arTextLines.begin(), m_arTextLines.end());
m_arTextLines.erase(right, m_arTextLines.end());
@ -891,7 +907,9 @@ namespace NSDocxRenderer
pNextLine->m_pLine = pCurrLine;
}
}
else if (!is_font_effect && pCurrCont->IsDuplicate(pNextCont.get(), eVType, eHType))
else if (!is_font_effect && pCurrCont->IsDuplicate(pNextCont.get(), eVType, eHType)
&& (fabs(pCurrCont->m_dLeft - pNextCont->m_dLeft) < c_dTHE_STRING_X_PRECISION_MM ||
fabs(pCurrCont->m_dRight - pNextCont->m_dRight) < c_dTHE_STRING_X_PRECISION_MM))
{
pNextCont = nullptr;
pCurrCont->m_iNumDuplicates++;
@ -1345,6 +1363,21 @@ namespace NSDocxRenderer
return IsHorizontalLineTrough(dummy_cont);
}
bool CPage::IsTextLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept
{
double left = std::min(pFirst->m_dLeft, pSecond->m_dLeft);
double right = std::max(pFirst->m_dRight, pSecond->m_dRight);
double top = std::min(pFirst->m_dBotWithMaxDescent, pSecond->m_dBotWithMaxDescent);
double bot = std::max(pFirst->m_dTopWithMaxAscent, pSecond->m_dTopWithMaxAscent);
auto dummy_cont = std::make_shared<CContText>();
dummy_cont->m_dLeft = left - c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dRight = right + c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dTop = top - c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dBot = bot + c_dGRAPHICS_ERROR_MM;
return IsTextLineTrough(dummy_cont);
}
bool CPage::IsVerticalLineTrough(base_item_ptr_t pFirst) const noexcept
{
@ -1372,6 +1405,16 @@ namespace NSDocxRenderer
return false;
}
bool CPage::IsTextLineTrough(base_item_ptr_t pFirst) const noexcept
{
for (const auto& text_line : m_arShapes)
if (text_line && text_line->m_eType == CShape::eShapeType::stTextBox && text_line->m_dBot > pFirst->m_dTop &&
text_line->m_dBot < pFirst->m_dBot && !(
text_line->m_dRight < pFirst->m_dLeft || text_line->m_dLeft > pFirst->m_dRight))
return true;
return false;
}
void CPage::SplitLines()
{
@ -1441,7 +1484,7 @@ namespace NSDocxRenderer
for (const auto& line : m_arTextLines)
{
if (fabs(line->m_dBotWithMaxDescent - curr_bot) < 4 * c_dTHE_SAME_STRING_Y_PRECISION_MM)
if (fabs(line->m_dBot - curr_bot) < 4 * c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
bot_aligned_text_lines.back().push_back(line);
}
@ -1449,7 +1492,7 @@ namespace NSDocxRenderer
{
bot_aligned_text_lines.push_back({});
bot_aligned_text_lines.back().push_back(line);
curr_bot = line->m_dBotWithMaxDescent;
curr_bot = line->m_dBot;
}
}
@ -1604,9 +1647,9 @@ namespace NSDocxRenderer
// lamda to setup and add paragpraph
auto add_paragraph = [this, &max_right, &min_left, &ar_paragraphs] (paragraph_ptr_t& paragraph) {
double additional_bottom = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent - paragraph->m_arTextLines.front()->m_dTop;
paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBot + additional_bottom;
paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent;
std::shared_ptr<CTextLine>& firstLine = paragraph->m_arTextLines.front();
paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBotWithMaxDescent;
paragraph->m_dTop = firstLine->m_dTopWithMaxAscent;
paragraph->m_dRight = max_right;
paragraph->m_dLeft = min_left;
@ -1623,6 +1666,25 @@ namespace NSDocxRenderer
paragraph->MergeLines();
// Correct first line position
if (m_bFirstParagraphLineCorrection)
{
double firstLine_height = firstLine->m_dBotWithMaxDescent - firstLine->m_dTopWithMaxAscent;
if (paragraph->m_dLineHeight > firstLine_height)
{
double offset = paragraph->m_dLineHeight - firstLine_height;
paragraph->m_dTop -= offset;
paragraph->m_dBot -= offset;
}
else
{
double ascent = firstLine->m_dBot - firstLine->m_dTopWithMaxAscent;
double newAscent = ascent * paragraph->m_dLineHeight / firstLine_height;
double offset = ascent - newAscent;
paragraph->m_dTop += offset;
paragraph->m_dBot += offset;
}
}
// setting TextAlignmentType
if (paragraph->m_arTextLines.size() > 1)
{
@ -1868,6 +1930,9 @@ namespace NSDocxRenderer
double curr_max_right = text_lines[0]->m_dRight;
double curr_min_left = text_lines[0]->m_dLeft;
double line_with_first_right_min = std::numeric_limits<double>::max();
double line_with_first_left_max = std::numeric_limits<double>::lowest();
for (size_t index = 0; index < ar_positions.size() - 1; ++index)
{
Position position = ar_positions[index];
@ -1878,6 +1943,10 @@ namespace NSDocxRenderer
{
curr_max_right = line_bot->m_dRight;
curr_min_left = line_bot->m_dLeft;
line_with_first_right_min = std::numeric_limits<double>::max();
line_with_first_left_max = std::numeric_limits<double>::lowest();
continue;
}
@ -1885,17 +1954,18 @@ namespace NSDocxRenderer
double line_with_first_right = line_top->m_dRight + line_bot->m_dFirstWordWidth;
double line_with_first_left = line_top->m_dLeft - line_bot->m_dFirstWordWidth;
line_with_first_right_min = std::min(line_with_first_right_min, line_with_first_right);
line_with_first_left_max = std::max(line_with_first_left_max, line_with_first_left);
curr_max_right = std::max(curr_max_right, line_bot->m_dRight);
curr_min_left = std::min(curr_min_left, line_bot->m_dLeft);
double diff = 0;
if (position.right && !position.left)
diff = line_with_first_left - curr_min_left;
else if (position.left || ar_indents[index])
diff = curr_max_right - line_with_first_right;
else if (position.center)
continue;
diff = line_with_first_left_max - curr_min_left;
else if (position.left || ar_indents[index] || position.center)
diff = curr_max_right - line_with_first_right_min;
if (diff <= 0)
continue;
@ -1904,6 +1974,8 @@ namespace NSDocxRenderer
ar_delims[index] = true;
curr_max_right = line_bot->m_dRight;
curr_min_left = line_bot->m_dLeft;
line_with_first_right_min = std::numeric_limits<double>::max();
line_with_first_left_max = std::numeric_limits<double>::lowest();
}
}
@ -1920,6 +1992,8 @@ namespace NSDocxRenderer
{
if (IsHorizontalLineBetween(text_lines[index], text_lines[index + 1]))
ar_delims[index] = true;
if (IsTextLineBetween(text_lines[index], text_lines[index + 1]))
ar_delims[index] = true;
}
// на основе ar_delims разбиваем на параграфы
@ -2553,9 +2627,9 @@ namespace NSDocxRenderer
pParagraph->m_arTextLines.push_back(pLine);
pParagraph->m_dLeft = pLine->m_dLeft;
pParagraph->m_dTop = pLine->m_dTopWithMaxAscent;
pParagraph->m_dBot = pLine->m_dBot + (pLine->m_dTopWithMaxAscent - pLine->m_dTop);
pParagraph->m_dWidth = pLine->m_dWidth * 1.05;
pParagraph->m_dHeight = pLine->m_dHeight;
pParagraph->m_dBot = pLine->m_dBotWithMaxDescent;
pParagraph->m_dWidth = pLine->m_dWidth;
pParagraph->m_dHeight = pLine->m_dBotWithMaxDescent - pLine->m_dTopWithMaxAscent;
pParagraph->m_dRight = pLine->m_dRight;
pParagraph->m_dLineHeight = pParagraph->m_dHeight;
pParagraph->m_nOrder = pLine->m_nOrder;
@ -2572,11 +2646,11 @@ namespace NSDocxRenderer
pShape->m_eType = CShape::eShapeType::stTextBox;
pShape->m_dLeft = pParagraph->m_dLeft;
pShape->m_dRight = pParagraph->m_dRight * 1.025;
pShape->m_dTop = pParagraph->m_dTop;
pShape->m_dBot = pParagraph->m_dBot;
pShape->m_dWidth = pParagraph->m_dWidth;
pShape->m_dWidth = pShape->m_dRight - pShape->m_dLeft;
pShape->m_dHeight = pParagraph->m_dHeight;
pShape->m_dRight = pParagraph->m_dRight;
pShape->m_nOrder = pParagraph->m_nOrder;
pShape->m_bIsBehindDoc = false;
@ -2588,11 +2662,12 @@ namespace NSDocxRenderer
auto pShape = std::make_shared<CShape>();
pShape->m_dLeft = pParagraph->m_dLeft;
pShape->m_dTop = pParagraph->m_dTop;
pShape->m_dRight = pParagraph->m_dRight;
if (pParagraph->m_arTextLines.size() == 1) pShape->m_dRight *= 1.025;
pShape->m_dTop = pParagraph->m_dTop;
pShape->m_dBot = pParagraph->m_dBot;
pShape->m_dHeight = pParagraph->m_dHeight;
pShape->m_dWidth = pParagraph->m_dWidth;
pShape->m_dWidth = pShape->m_dRight - pShape->m_dLeft;
pShape->m_nOrder = pParagraph->m_nOrder;
if (pParagraph->m_bIsNeedFirstLineIndent && pParagraph->m_dFirstLine < 0)

View File

@ -50,6 +50,7 @@ namespace NSDocxRenderer
bool m_bIsBuildTables {false};
bool m_bIsLuminosityShapesFiled{false};
bool m_bFontSubstitution {false};
bool m_bFirstParagraphLineCorrection{false};
CPage(NSFonts::IApplicationFonts* pAppFonts, const CManagers& oManagers);
~CPage();
@ -68,6 +69,7 @@ namespace NSDocxRenderer
void PathEnd();
void PathClose();
void DrawPath(LONG lType, const std::shared_ptr<CImageInfo> pInfo);
bool IsCurrVectorClockwise() const;
void AddText(
const PUINT pUnicodes,
@ -194,9 +196,11 @@ namespace NSDocxRenderer
bool IsVerticalLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsHorizontalLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsTextLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsVerticalLineTrough(base_item_ptr_t pFirst) const noexcept;
bool IsHorizontalLineTrough(base_item_ptr_t pFirst) const noexcept;
bool IsTextLineTrough(base_item_ptr_t pFirst) const noexcept;
void ToXml(NSStringUtils::CStringBuilder& oWriter) const noexcept;
void WriteSectionToFile(bool bLastPage, NSStringUtils::CStringBuilder& oWriter) const noexcept;

View File

@ -208,34 +208,34 @@ namespace NSDocxRenderer
return eVerticalCrossingType::vctCurrentInsideNext;
else if (this_top < other_top && this_bot > other_bot)
return eVerticalCrossingType::vctCurrentOutsideNext;
return eVerticalCrossingType::vctCurrentOutsideNext;
else if (this_top < other_top && this_bot < other_bot &&
(this_bot >= other_top || fabs(this_bot - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM))
return eVerticalCrossingType::vctCurrentAboveNext;
else if (this_top < other_top && this_bot < other_bot && this_bot > other_top &&
this_bot - other_top > c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctCurrentAboveNext;
else if (this_top > other_top && this_bot > other_bot &&
(this_top <= other_bot || fabs(this_top - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM))
return eVerticalCrossingType::vctCurrentBelowNext;
else if (this_top > other_top && this_bot > other_bot && this_top < other_bot &&
other_bot - this_top > c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctCurrentBelowNext;
else if (this_top == other_top && this_bot == other_bot)
return eVerticalCrossingType::vctDublicate;
else if (fabs(this_top - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM &&
fabs(this_bot - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctTopAndBottomBordersMatch;
return eVerticalCrossingType::vctTopAndBottomBordersMatch;
else if (fabs(this_top - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctTopBorderMatch;
return eVerticalCrossingType::vctTopBorderMatch;
else if (fabs(this_bot - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctBottomBorderMatch;
return eVerticalCrossingType::vctBottomBorderMatch;
else if (this_bot < other_top)
return eVerticalCrossingType::vctNoCrossingCurrentAboveNext;
else if (other_top - this_bot > -c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctNoCrossingCurrentAboveNext;
else if (this_top > other_bot)
return eVerticalCrossingType::vctNoCrossingCurrentBelowNext;
else if (this_top - other_bot > -c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctNoCrossingCurrentBelowNext;
else
return eVerticalCrossingType::vctUnknown;
@ -555,6 +555,9 @@ namespace NSDocxRenderer
std::wstring origin_lefts{};
for (auto& l : m_arOriginLefts)
origin_lefts += std::to_wstring(static_cast<int>(l * c_dMMToEMU)) + L";";
// add offset for last symbol
if (!m_arSymWidths.empty())
origin_lefts += std::to_wstring(static_cast<int>((m_arOriginLefts.back() + m_arSymWidths.back()) * c_dMMToEMU)) + L";";
oWriter.WriteBYTE(5); oWriter.WriteStringUtf16(origin_lefts); // Origin lefts
oWriter.WriteBYTE(6); oWriter.WriteBool(m_bFontSubstitution); // Font Substitution (just pass from pdf)
@ -658,6 +661,7 @@ namespace NSDocxRenderer
bool CContText::IsEqual(const CContText *pCont) const noexcept
{
bool bIf0 = IsFontsEqual(m_oSelectedFont, pCont->m_oSelectedFont);
bool bIf1 = m_pFontStyle->wsFontStyleId == pCont->m_pFontStyle->wsFontStyleId;
bool bIf2 = m_bIsStrikeoutPresent == pCont->m_bIsStrikeoutPresent;
bool bIf3 = m_bIsDoubleStrikeout == pCont->m_bIsDoubleStrikeout;
@ -674,7 +678,7 @@ namespace NSDocxRenderer
bool bIf14 = m_eVertAlignType == eVertAlignType::vatUnknown && pCont->m_eVertAlignType == eVertAlignType::vatBase;
bool bIf15 = m_eVertAlignType == eVertAlignType::vatBase && pCont->m_eVertAlignType == eVertAlignType::vatUnknown;
return (bIf1 && bIf2 && bIf3 && bIf4 && bIf5 && bIf6 && bIf7 &&
return (bIf0 && bIf1 && bIf2 && bIf3 && bIf4 && bIf5 && bIf6 && bIf7 &&
bIf8 && bIf9 && bIf10 && bIf11 && bIf12 && (bIf13 || bIf14 || bIf15));
}
@ -894,12 +898,12 @@ namespace NSDocxRenderer
eHorizontalCrossingType eHType)
{
//Условие пересечения по вертикали
bool bIf1 = eVType == eVerticalCrossingType::vctCurrentAboveNext; //текущий cont выше
bool bIf2 = eVType == eVerticalCrossingType::vctCurrentBelowNext; //текущий cont ниже
bool bIf1 = eVType == eVerticalCrossingType::vctCurrentAboveNext;
bool bIf2 = eVType == eVerticalCrossingType::vctCurrentBelowNext;
//Условие пересечения по горизонтали
bool bIf3 = eHType == eHorizontalCrossingType::hctCurrentLeftOfNext; //текущий cont левее
bool bIf4 = eHType == eHorizontalCrossingType::hctCurrentRightOfNext; //текущий cont правее
bool bIf3 = eHType == eHorizontalCrossingType::hctCurrentLeftOfNext;
bool bIf4 = eHType == eHorizontalCrossingType::hctCurrentRightOfNext;
//Размеры шрифта и текст должны бать одинаковыми
bool bIf5 = pFirstCont->m_pFontStyle->dFontSize == pSecondCont->m_pFontStyle->dFontSize;
@ -915,9 +919,7 @@ namespace NSDocxRenderer
bool bIf11 = pFirstCont->m_pFontStyle->oBrush.Color1 == c_iGreyColor2;
bool bIf12 = pSecondCont->m_pFontStyle->oBrush.Color1 == c_iGreyColor2;
//note Каждый символ с Emboss или Engrave разбиваются на 3 символа с разными цветами
//note Логика подобрана для конкретного примера - возможно нужно будет ее обобщить.
//todo существует проблема неправильного определением FontEffects с физически пересекаемыми строчками - файл generaltest.pdf p.14
// каждый символ с Emboss или Engrave разбиваются на 3 символа с разными цветами
if (bIf5 && bIf6)
{
if (bIf12 && pFirstCont->m_bIsEmbossPresent)
@ -977,18 +979,20 @@ namespace NSDocxRenderer
eHorizontalCrossingType eHType)
{
double first_height = pFirstCont->m_dBotWithDescent - pFirstCont->m_dTopWithAscent;
bool bIf1 = eVType == eVerticalCrossingType::vctCurrentAboveNext ||
eVType == eVerticalCrossingType::vctCurrentInsideNext;
eVType == eVerticalCrossingType::vctCurrentInsideNext &&
pSecondCont->m_dBotWithDescent - pFirstCont->m_dBotWithDescent > first_height * 0.2;
bool bIf2 = eVType == eVerticalCrossingType::vctCurrentBelowNext;
bool bIf3 = (eHType == eHorizontalCrossingType::hctNoCrossingCurrentLeftOfNext ||
eHType == eHorizontalCrossingType::hctCurrentLeftOfNext) &&
fabs(pFirstCont->m_dRight - pSecondCont->m_dLeft) < c_dTHE_STRING_X_PRECISION_MM * 3;
fabs(pFirstCont->m_dRight - pSecondCont->m_dLeft) < c_dTHE_STRING_X_PRECISION_MM;
bool bIf4 = (eHType == eHorizontalCrossingType::hctNoCrossingCurrentRightOfNext ||
eHType == eHorizontalCrossingType::hctCurrentRightOfNext) &&
fabs(pFirstCont->m_dLeft - pSecondCont->m_dRight) < c_dTHE_STRING_X_PRECISION_MM * 3;
fabs(pFirstCont->m_dLeft - pSecondCont->m_dRight) < c_dTHE_STRING_X_PRECISION_MM;
//Размеры шрифта должны бать разными
bool bIf5 = pFirstCont->m_pFontStyle->dFontSize * 0.8 > pSecondCont->m_pFontStyle->dFontSize;
@ -1090,6 +1094,19 @@ namespace NSDocxRenderer
{
return 0x0300 <= cSym && 0x036F >= cSym;
}
bool CContText::IsFontsEqual(const NSStructures::CFont& oFont1, const NSStructures::CFont& oFont2)
{
bool res = oFont1.Name == oFont2.Name;
res = res && oFont1.Path == oFont2.Path;
res = res && oFont1.FaceIndex == oFont2.FaceIndex;
res = res && oFont1.StringGID == oFont2.StringGID;
res = res && oFont1.Size == oFont2.Size;
res = res && oFont1.Bold == oFont2.Bold;
res = res && oFont1.Italic == oFont2.Italic;
res = res && oFont1.Underline == oFont2.Underline;
res = res && oFont1.Strikeout == oFont2.Strikeout;
return res;
}
double CContText::CalculateSpace() const noexcept
{
@ -1245,12 +1262,11 @@ namespace NSDocxRenderer
pCont->m_dWidth = dWidth;
pCont->m_dRight = dRight;
double font_size = oFont.Size;
double em_height = oMetrics.dEmHeight;
double ratio = font_size / em_height * c_dPtToMM;
double ascent = pFontManager->GetFontAscent();
double descent = pFontManager->GetFontDescent();
pCont->m_dTopWithAscent = pCont->m_dBot - (oMetrics.dAscent * ratio);
pCont->m_dBotWithDescent = pCont->m_dBot + (oMetrics.dDescent * ratio);
pCont->m_dTopWithAscent = pCont->m_dBot - ascent;
pCont->m_dBotWithDescent = pCont->m_dBot + fabs(descent);
pCont->m_dSpaceWidthMM = pFontManager->GetSpaceWidthMM();
pCont->m_wsOriginFontName = oFont.Name;

View File

@ -159,6 +159,8 @@ namespace NSDocxRenderer
static bool IsUnicodeSymbol(uint32_t symbol);
static bool IsUnicodeDiacriticalMark(uint32_t symbol);
static bool IsFontsEqual(const NSStructures::CFont& oFont1, const NSStructures::CFont& oFont2);
private:
NSStringUtils::CStringUTF32 m_oText{};
std::vector<double> m_arSymWidths{};

View File

@ -1311,8 +1311,8 @@ namespace NSDocxRenderer
{
oWriter.StartRecord(2);
oWriter.WriteBYTE(kBin_g_nodeAttributeStart);
oWriter.WriteBYTE(0); oWriter.AddInt(100);
oWriter.WriteBYTE(1); oWriter.AddInt(100);
oWriter.WriteBYTE(0); oWriter.AddInt(100 * 1000);
oWriter.WriteBYTE(1); oWriter.AddInt(100 * 1000);
oWriter.WriteBYTE(kBin_g_nodeAttributeEnd);
oWriter.EndRecord();
}
@ -1343,7 +1343,7 @@ namespace NSDocxRenderer
// WriteRecord WriteBodyPr
oWriter.StartRecord(0);
oWriter.WriteBYTE(kBin_g_nodeAttributeStart);
oWriter.WriteBYTE(1); oWriter.WriteBYTE(1); // anchor
oWriter.WriteBYTE(1); oWriter.WriteBYTE(4); // anchor
oWriter.WriteBYTE(2); oWriter.WriteBool(false); // anchorCtr
oWriter.WriteBYTE(3); oWriter.AddInt(0); // bIns
oWriter.WriteBYTE(4); oWriter.WriteBool(true); // compatLnSpc

View File

@ -66,6 +66,8 @@ namespace NSDocxRenderer
std::sort(m_arConts.begin(), m_arConts.end(), [] (const cont_ptr_t& a, const cont_ptr_t& b) {
if (!a) return false;
if (!b) return true;
if (fabs(a->m_dLeft - b->m_dLeft) < c_dTHE_SAME_STRING_X_PRECISION_MM)
return a->m_dRight < b->m_dRight;
return a->m_dLeft < b->m_dLeft;
});
@ -243,15 +245,15 @@ namespace NSDocxRenderer
return eVerticalCrossingType::vctCurrentInsideNext;
else if (this_top < other_top && this_bot > other_bot)
return eVerticalCrossingType::vctCurrentOutsideNext;
return eVerticalCrossingType::vctCurrentOutsideNext;
else if (this_top < other_top && this_bot < other_bot &&
(this_bot >= other_top || fabs(this_bot - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM))
return eVerticalCrossingType::vctCurrentAboveNext;
else if (this_top < other_top && this_bot < other_bot && this_bot > other_top &&
this_bot - other_top > c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctCurrentAboveNext;
else if (this_top > other_top && this_bot > other_bot &&
(this_top <= other_bot || fabs(this_top - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM))
return eVerticalCrossingType::vctCurrentBelowNext;
else if (this_top > other_top && this_bot > other_bot && this_top < other_bot &&
other_bot - this_top > c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctCurrentBelowNext;
else if (this_top == other_top && this_bot == other_bot &&
m_dLeft == pLine->m_dLeft && m_dRight == pLine->m_dRight)
@ -259,31 +261,33 @@ namespace NSDocxRenderer
else if (fabs(this_top - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM &&
fabs(this_bot - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctTopAndBottomBordersMatch;
return eVerticalCrossingType::vctTopAndBottomBordersMatch;
else if (fabs(this_top - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctTopBorderMatch;
return eVerticalCrossingType::vctTopBorderMatch;
else if (fabs(this_bot - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM)
return eVerticalCrossingType::vctBottomBorderMatch;
return eVerticalCrossingType::vctBottomBorderMatch;
else if (this_bot < other_top)
return eVerticalCrossingType::vctNoCrossingCurrentAboveNext;
else if (other_top - this_bot > -c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctNoCrossingCurrentAboveNext;
else if (this_top > other_bot)
return eVerticalCrossingType::vctNoCrossingCurrentBelowNext;
else if (this_top - other_bot > -c_dOVERLAP_TEXT_LINE_ERROR_MM)
return eVerticalCrossingType::vctNoCrossingCurrentBelowNext;
else
return eVerticalCrossingType::vctUnknown;
return eVerticalCrossingType::vctUnknown;
}
void CTextLine::RecalcWithNewItem(const CContText* pCont)
{
CBaseItem::RecalcWithNewItem(pCont);
if (m_dTopWithMaxAscent == 0.0) m_dTopWithMaxAscent = pCont->m_dTopWithAscent;
else m_dTopWithMaxAscent = std::min(m_dTopWithMaxAscent, pCont->m_dTopWithAscent);
m_dBotWithMaxDescent = std::max(m_dBotWithMaxDescent, pCont->m_dBotWithDescent);
if (!pCont->IsOnlySpaces())
{
if (m_dTopWithMaxAscent == 0.0) m_dTopWithMaxAscent = pCont->m_dTopWithAscent;
else m_dTopWithMaxAscent = std::min(m_dTopWithMaxAscent, pCont->m_dTopWithAscent);
m_dBotWithMaxDescent = std::max(m_dBotWithMaxDescent, pCont->m_dBotWithDescent);
}
}
void CTextLine::SetVertAlignType(const eVertAlignType& oType)

View File

@ -581,6 +581,16 @@ namespace NSDocxRenderer
{
return c_dPtToMM * (m_oFontMetrics.dLineSpacing * m_oFont.Size) / m_oFontMetrics.dEmHeight;
}
double CFontManager::GetFontAscent() const
{
//double tmp = m_oFontMetrics.dAscent;
double tmp = m_oFontMetrics.dLineSpacing - fabs(m_oFontMetrics.dDescent);
return c_dPtToMM * (tmp * m_oFont.Size) / m_oFontMetrics.dEmHeight;
}
double CFontManager::GetFontDescent() const
{
return c_dPtToMM * (m_oFontMetrics.dDescent * m_oFont.Size) / m_oFontMetrics.dEmHeight;
}
double CFontManager::GetSpaceWidthMM() const
{
double dSpaceWidthMM = 0.0;

View File

@ -124,6 +124,9 @@ namespace NSDocxRenderer
const CFontMetrics& GetFontMetrics() const noexcept;
double GetFontHeight() const;
double GetFontAscent() const;
double GetFontDescent() const;
double GetSpaceWidthMM() const;
void SetStringGid(const LONG& lGid);

View File

@ -147,7 +147,7 @@ namespace NSDocxRenderer
return GenerateImageID(pImage);
}
std::shared_ptr<CImageInfo> CImageManager::WriteImage(const std::wstring& strFile, double& x, double& y, double& width, double& height)
std::shared_ptr<CImageInfo> CImageManager::WriteImage(const std::wstring& strFile)
{
Aggplus::CImage image(strFile);
return GenerateImageID(&image);

View File

@ -20,14 +20,14 @@ namespace NSDocxRenderer
void Clear();
std::shared_ptr<CImageInfo> WriteImage(Aggplus::CImage* pImage, double& x, double& y, double& width, double& height);
std::shared_ptr<CImageInfo> WriteImage(const std::wstring& strFile, double& x, double& y, double& width, double& height);
std::shared_ptr<CImageInfo> WriteImage(const std::wstring& strFile);
std::shared_ptr<CImageInfo> GenerateImageID(Aggplus::CImage* pImage);
static CImageInfo::ImageType GetImageType(Aggplus::CImage* pFrame);
static void FlipY(Aggplus::CImage* pImage);
private:
std::shared_ptr<CImageInfo> GenerateImageID(const std::wstring& strFileName);
void FlipY(Aggplus::CImage* pImage);
int m_lMaxSizeImage {1200};
int m_lNextIDImage {0};
CCalculatorCRC32 m_oCRC;

View File

@ -24,10 +24,11 @@ constexpr double c_dPtToEMU = 12700.0;
constexpr double c_dDegreeToAngle = 60000.0;
const double c_dSTANDART_STRING_HEIGHT_MM = 4.2333333333333334;
const double c_dTHE_SAME_STRING_Y_PRECISION_MM = 0.03;
const double c_dTHE_SAME_STRING_Y_PRECISION_MM = 0.015;
const double c_dTHE_SAME_STRING_X_PRECISION_MM = 0.03;
const double c_dTHE_SAME_SPACING_ERROR = 0.1;
const double c_dLINE_DISTANCE_ERROR_MM = 0.3;
const double c_dOVERLAP_TEXT_LINE_ERROR_MM = 0.7;
const double c_dERROR_OF_PARAGRAPH_BORDERS_MM = 1.0;
const double c_dCENTER_POSITION_ERROR_MM = 1.5;
const double c_dTHE_STRING_X_PRECISION_MM = 0.5;

View File

@ -195,7 +195,7 @@ namespace NSDocxRenderer
double x0 = m_arData.back().points.back().x;
double y0 = m_arData.back().points.back().y;
std::list<Point> points = {{x1, y1}, {x2, y2}, {x3, y3}};
std::vector<Point> points = {{x1, y1}, {x2, y2}, {x3, y3}};
ePathCommandType type = ePathCommandType::pctCurve;
m_arData.push_back({type, points});
@ -308,6 +308,45 @@ namespace NSDocxRenderer
}
}
}
bool CVectorGraphics::IsClockwise() const
{
if (m_arData.empty())
return false;
double area = 0;
double last_x = 0;
double last_y = 0;
bool is_first = true;
for (const auto& command : m_arData)
{
if (is_first)
{
is_first = false;
last_x = command.points.back().x;
last_y = command.points.back().y;
continue;
}
if (command.type == ePathCommandType::pctClose)
break;
const auto& points = command.points;
if (command.type == ePathCommandType::pctCurve)
{
area += 3.0 * ((points[2].y - last_y) * (points[0].x + points[1].x)
- (points[2].x - last_x) * (points[0].y + points[1].y)
+ points[0].y * (last_x - points[1].x)
- points[0].x * (last_y - points[1].y)
+ points[2].y * (points[1].x + last_x / 3.0)
- points[2].x * (points[1].y + last_y / 3.0)) / 20.0;
}
else
area += (points[0].y * last_x - points[0].x * last_y) / 2.0;
last_x = command.points.back().x;
last_y = command.points.back().y;
}
return area >= 0;
}
// ClipRegionTypeWinding = 0x0000;
// ClipRegionTypeEvenOdd = 0x0001;

View File

@ -31,7 +31,7 @@ namespace NSDocxRenderer
struct CPathCommand
{
ePathCommandType type;
std::list<Point> points;
std::vector<Point> points;
};
CVectorGraphics() noexcept;
@ -79,6 +79,7 @@ namespace NSDocxRenderer
void Rotate(const double& rotation);
void Transform(const Aggplus::CMatrix& matrix);
void DrawOnRenderer(IRenderer* renderer) const noexcept;
bool IsClockwise() const;
static CVectorGraphics CalcBoolean(const CVectorGraphics& vg1, const CVectorGraphics& vg2, long clipType, long fillType = c_nWindingFillMode, bool isLuminosity = false);

View File

@ -142,7 +142,7 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
*/
CHtmlFile2 oFile;
CHtmlParams oFileParams;
HTML::THTMLParameters oFileParams;
oFileParams.SetAuthors (m_oBookInfo.GetCreators());
oFileParams.SetGenres (m_oBookInfo.GetSubjects());
@ -155,7 +155,7 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
std::wstring sDocxFileTempDir = m_sTempDir + L"/tmp";
NSDirectory::CreateDirectory(sDocxFileTempDir);
oFile.SetTmpDirectory(sDocxFileTempDir);
oFile.SetTempDirectory(sDocxFileTempDir);
oFile.SetCoreDirectory(NSFile::GetDirectoryName(sContent));
std::vector<std::wstring> arFiles;
@ -182,7 +182,7 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
sOutputDir = sOutputFile;
NSDirectory::CreateDirectory(sOutputDir);
HRESULT hRes = oFile.OpenBatchHtml(arFiles, sOutputDir, &oFileParams);
HRESULT hRes = oFile.ConvertHTML2OOXML(arFiles, sOutputDir, &oFileParams);
if (bIsOutCompress && S_OK == hRes)
hRes = oOfficeUtils.CompressFileOrDirectory(sOutputDir, sOutputFile);

View File

@ -2170,7 +2170,7 @@ HRESULT CFb2File::FromHtml(const std::wstring& sHtmlFile, const std::wstring& sD
RELEASEARRAYOBJECTS(pData);
//XmlUtils::CXmlLiteReader oIndexHtml;
std::wstring xhtml = htmlToXhtml(sContent, bNeedConvert);
std::wstring xhtml = HTML::htmlToXhtml(sContent, bNeedConvert);
if (!m_internal->m_oLightReader.FromString(xhtml))
return S_FALSE;

64
HtmlFile2/Common.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef COMMON_H
#define COMMON_H
#include <string>
#include "../DesktopEditor/common/StringBuilder.h"
namespace HTML
{
#define MAX_STRING_BLOCK_SIZE (size_t)10485760
using XmlString = NSStringUtils::CStringBuilder;
inline void replace_all(std::wstring& s, const std::wstring& s1, const std::wstring& s2)
{
size_t pos = s.find(s1);
size_t l = s2.length();
while (pos != std::string::npos)
{
if (!(s1 == L"&" && s2 == L"&amp;" && s.length() > pos + 4 && s[pos] == L'&' && s[pos + 1] == L'a' && s[pos + 2] == L'm' && s[pos + 3] == L'p' && s[pos + 4] == L';'))
s.replace(pos, s1.length(), s2);
pos = s.find(s1, pos + l);
}
}
inline std::wstring EncodeXmlString(const std::wstring& s)
{
std::wstring sRes = s;
replace_all(sRes, L"&", L"&amp;");
replace_all(sRes, L"<", L"&lt;");
replace_all(sRes, L">", L"&gt;");
replace_all(sRes, L"\"", L"&quot;");
replace_all(sRes, L"\'", L"&#39;");
replace_all(sRes, L"\n", L"&#xA;");
replace_all(sRes, L"\r", L"&#xD;");
replace_all(sRes, L"\t", L"&#x9;");
return sRes;
}
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;
}
}
}
#endif // COMMON_H

View File

@ -0,0 +1,69 @@
#ifndef HTMLPARAMETERS_H
#define HTMLPARAMETERS_H
#include <string>
namespace HTML
{
struct THTMLParameters
{
std::wstring m_sGenres; // Жанры
std::wstring m_sAuthors; // Авторы
std::wstring m_sBookTitle; // Название
std::wstring m_sDate; // Дата
std::wstring m_sDescription; // описание
std::wstring m_sLanguage; // Язык
bool m_bNeedPageBreakBefore; // Новый html с новой страницы
std::wstring m_sdocDefaults; // Стиль docDefaults
std::wstring m_sNormal; // Стиль normal
THTMLParameters() : m_bNeedPageBreakBefore(false) {}
void SetNormal(const std::wstring& sStyle)
{
m_sNormal = sStyle;
}
void SetDocDefaults(const std::wstring& sStyle)
{
m_sdocDefaults = sStyle;
}
void SetPageBreakBefore(bool bNeed)
{
m_bNeedPageBreakBefore = bNeed;
}
void SetDate(const std::wstring& sDate)
{
m_sDate = sDate;
}
void SetDescription(const std::wstring& sDescription)
{
m_sDescription = sDescription;
}
void SetGenres(const std::wstring& sGenres)
{
m_sGenres = sGenres;
}
void SetAuthors(const std::wstring& sAuthors)
{
m_sAuthors = sAuthors;
}
void SetTitle(const std::wstring& sTitle)
{
m_sBookTitle = sTitle;
}
void SetLanguage(const std::wstring& sLanguage)
{
m_sLanguage = sLanguage;
}
};
}
#endif // HTMLPARAMETERS_H

1507
HtmlFile2/HTMLReader.cpp Normal file

File diff suppressed because it is too large Load Diff

92
HtmlFile2/HTMLReader.h Normal file
View File

@ -0,0 +1,92 @@
#ifndef HTMLREADER_H
#define HTMLREADER_H
#include <unordered_map>
#include "../Common/3dParty/html/css/src/CCssCalculator.h"
#include "../DesktopEditor/xml/include/xmlutils.h"
#include "HTMLParameters.h"
#include "MarkdownParameters.h"
#include "Writers/IWriter.h"
#include "Tags/HTMLTags.h"
#include "Table.h"
namespace HTML
{
class CHTMLReader
{
XmlUtils::CXmlLiteReader m_oLightReader; // SAX Reader
NSCSS::CCssCalculator m_oCSSCalculator; // Css калькулятор
std::wstring m_wsTempDirectory; // Temp папка
std::wstring m_wsSrcDirectory; // Директория источника
std::wstring m_wsDstDirectory; // Директория назначения
std::wstring m_wsBaseDirectory; // Полный базовый адрес
std::wstring m_wsCoreDirectory; // Путь до корневого файла (используется для работы с Epub)
IWriter *m_pWriter;
std::unordered_map<UINT, std::shared_ptr<ITag>> m_mTags;
public:
CHTMLReader();
~CHTMLReader();
void SetTempDirectory(const std::wstring& wsPath);
void SetCoreDirectory(const std::wstring& wsPath);
HRESULT ConvertHTML2OOXML (const std::wstring& wsPath, const std::wstring& wsDirectory, THTMLParameters* pParameters = nullptr);
HRESULT ConvertHTML2Markdown(const std::wstring& wsPath, const std::wstring& wsFinalFile, TMarkdownParameters* pParameters = nullptr);
HRESULT ConvertHTML2OOXML (const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, THTMLParameters* pParameters = nullptr);
HRESULT ConvertHTML2Markdown(const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, TMarkdownParameters* pParameters = nullptr);
HRESULT ConvertMHT2OOXML (const std::wstring& wsPath, const std::wstring& wsDirectory, THTMLParameters* pParameters = nullptr);
HRESULT ConvertMHT2Markdown (const std::wstring& wsPath, const std::wstring& wsFinalFile, TMarkdownParameters* pParameters = nullptr);
HRESULT ConvertMHT2OOXML (const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, THTMLParameters* pParameters = nullptr);
HRESULT ConvertMHT2Markdown (const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, TMarkdownParameters* pParameters = nullptr);
NSCSS::CCssCalculator* GetCSSCalculator();
private:
void Clear();
void InitOOXMLTags(THTMLParameters* pParametrs = nullptr);
void InitMDTags(TMarkdownParameters* pParametrs = nullptr);
bool IsHTML();
typedef std::function<bool(const std::wstring&, XmlUtils::CXmlLiteReader&)> Convert_Func;
HRESULT InitAndConvert2OOXML(const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, Convert_Func Convertation, THTMLParameters* pParameters = nullptr);
HRESULT InitAndConvert2Markdown(const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, Convert_Func Convertation, TMarkdownParameters* pParameters = nullptr);
bool Convert(const std::wstring& wsPath, Convert_Func Convertation);
void ReadStyle();
void ReadStyle2();
void ReadStyleFromNetwork();
void ReadDocument();
void ReadHead();
void ReadBody();
bool ReadStream(std::vector<NSCSS::CNode>& arSelectors, bool bInsertEmptyP = false);
bool ReadInside(std::vector<NSCSS::CNode>& arSelectors);
bool ReadText(std::vector<NSCSS::CNode>& arSelectors);
bool ReadSVG(const std::vector<NSCSS::CNode>& arSelectors);
bool ReadEmptyTag(UINT unTag, const std::vector<NSCSS::CNode>& arSelectors);
bool ReadDefaultTag(UINT unTag, std::vector<NSCSS::CNode>& arSelectors);
bool ReadTable(std::vector<NSCSS::CNode>& arSelectors);
void ReadTableCaption(CStorageTable& oTable, std::vector<NSCSS::CNode>& arSelectors);
void ReadTableRows(CStorageTable& oTable, std::vector<NSCSS::CNode>& arSelectors, ERowParseMode eMode);
void ReadTableColspan(CStorageTable& oTable);
void GetSubClass(std::vector<NSCSS::CNode>& arSelectors);
};
}
#endif // HTMLREADER_H

View File

@ -13,6 +13,7 @@ DEFINES += CSSCALCULATOR_LIBRARY_STATIC
DEFINES += CSS_CALCULATOR_WITH_XHTML
DEFINES += DISABLE_RUBY_SUPPORT
DEFINES += MDCONVERTER_DECL_EXPORT
DEFINES += HTML_NORMALIZER_DECL_EXPORT
CORE_ROOT_DIR = $$PWD/..
PWD_ROOT_DIR = $$PWD
@ -31,8 +32,25 @@ include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, kernel_network)
SOURCES += htmlfile2.cpp
SOURCES += htmlfile2.cpp \
./Writers/OOXMLWriter.cpp \
HTMLReader.cpp \
Tags/MDTags.cpp \
Writers/MDWriter.cpp \
Table.cpp \
Tags/OOXMLTags.cpp
HEADERS += htmlfile2.h \
./src/StringFinder.h \
./src/Languages.h
./src/Languages.h \
Common.h \
./Writers/OOXMLWriter.h \
./Writers/IWriter.h \
HTMLParameters.h \
HTMLReader.h \
./Tags/HTMLTags.h \
MarkdownParameters.h \
Tags/MDTags.h \
Writers/MDWriter.h \
Table.h \
Tags/OOXMLTags.h

View File

@ -0,0 +1,14 @@
#ifndef MARKDOWNPARAMETERS_H
#define MARKDOWNPARAMETERS_H
namespace HTML
{
struct TMarkdownParameters
{
bool m_bUseAlternativeHTMLTags = false; //Использовать html теги там, где нет стандартной реализации в md(например для подчеркиваний)
wchar_t m_wchUnorderedList = L'-'; // Возможные варианты в md: -, +, *
wchar_t m_wchOrderedList = L'.'; // Возможные варианты в md: ., )
};
}
#endif // MARKDOWNPARAMETERS_H

715
HtmlFile2/Table.cpp Normal file
View File

@ -0,0 +1,715 @@
#include "Table.h"
#include "Common.h"
#include "src/StringFinder.h"
namespace HTML
{
#define MAX_STRING_BLOCK_SIZE (size_t)10485760
#define RELEASE_VECTOR_PTR(vector_object, object_type) \
for (object_type* pElement : vector_object) \
RELEASEOBJECT(pElement)
#define FIRST_ELEMENT 0x00000001
#define LAST_ELEMENT 0x00000002
#define MID_ELEMENT 0x00000004
#define PARSE_MODE_HEADER 0x00000100
#define PARSE_MODE_BODY 0x00000200
#define PARSE_MODE_FOOTHER 0x00000400
#define COL_POSITION_MASK 0x0000000F
#define ROW_POSITION_MASK 0x000000F0
#define PARSE_MODE_MASK 0x00000F00
#define DEFAULT_PAGE_WIDTH 12240 // Значение в Twips
#define DEFAULT_PAGE_HEIGHT 15840 // Значение в Twips
TTableRowStyle::TTableRowStyle()
: m_unMaxIndex(0), m_unMaxHeight(0), m_bIsHeader(false)
{}
bool TTableRowStyle::Empty() const
{
return 0 == m_unMaxHeight && false == m_bIsHeader;
}
TTableCellStyle::TTableCellStyle()
{}
bool TTableCellStyle::Empty()
{
return m_oWidth.Empty() && m_oHeight.Empty() && m_oBorder.Empty() && m_oPadding.Empty() && m_wsVAlign.empty() && m_wsVAlign.empty();
}
void TTableCellStyle::Copy(const TTableCellStyle* pTableCellStyle)
{
if (NULL == pTableCellStyle)
return;
m_oWidth = pTableCellStyle->m_oWidth;
m_oHeight = pTableCellStyle->m_oHeight;
m_oBorder = pTableCellStyle->m_oBorder;
m_oPadding = pTableCellStyle->m_oPadding;
m_oBackground = pTableCellStyle->m_oBackground;
m_wsHAlign = pTableCellStyle->m_wsHAlign;
m_wsVAlign = pTableCellStyle->m_wsVAlign;
}
TTableCellStyle& TTableCellStyle::operator+=(const TTableCellStyle* pCellStyle)
{
if (NULL == pCellStyle)
return *this;
m_oWidth += pCellStyle->m_oWidth;
m_oHeight += pCellStyle->m_oHeight;
m_oBorder += pCellStyle->m_oBorder;
m_oPadding += pCellStyle->m_oPadding;
m_oBackground += pCellStyle->m_oBackground;
if (m_wsHAlign.empty())
m_wsHAlign = pCellStyle->m_wsHAlign;
if (m_wsVAlign.empty())
m_wsVAlign = pCellStyle->m_wsVAlign;
return *this;
}
CStorageTableCell::CStorageTableCell()
: m_unColspan(1), m_unRowSpan(1), m_bIsMerged(false), m_bIsEmpty(false), m_oData(30)
{}
CStorageTableCell::CStorageTableCell(UINT unColspan, UINT unRowspan, bool bIsMerged, bool bIsEmpty)
: m_unColspan(unColspan), m_unRowSpan(unRowspan), m_bIsMerged(bIsMerged),
m_bIsEmpty(bIsEmpty)
{}
CStorageTableCell::CStorageTableCell(CStorageTableCell& oCell)
: 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)
{
WriteToStringBuilder(oCell.m_oData, m_oData);
}
bool CStorageTableCell::Empty() const
{
return m_bIsEmpty;
}
bool CStorageTableCell::Merged() const
{
return m_bIsMerged;
}
CStorageTableCell* CStorageTableCell::Copy()
{
return new CStorageTableCell(*this);
}
CStorageTableCell* CStorageTableCell::CreateEmpty(UINT unColspan, bool m_bIsMerged, const TTableCellStyle* pStyle)
{
CStorageTableCell *pCell = new CStorageTableCell(unColspan, 1, m_bIsMerged, true);
pCell->m_oStyles.Copy(pStyle);
return pCell;
}
CStorageTableCell* CStorageTableCell::CreateEmpty(const TTableCellStyle* pStyle)
{
CStorageTableCell *pCell = new CStorageTableCell(1, 1, false, true);
pCell->m_oStyles.Copy(pStyle);
return pCell;
}
void CStorageTableCell::SetColspan(UINT unColspan, UINT unCurrentIndex)
{
if (MAXCOLUMNSINTABLE - 1 != unCurrentIndex)
m_unColspan = std::min(MAXCOLUMNSINTABLE - 1 - unCurrentIndex, unColspan);
else
m_unColspan = 1;
}
UINT CStorageTableCell::GetColspan() const
{
return m_unColspan;
}
void CStorageTableCell::SetRowspan(UINT unRowspan)
{
m_unRowSpan = unRowspan;
}
UINT CStorageTableCell::GetRowspan() const
{
return m_unRowSpan;
}
NSStringUtils::CStringBuilder* CStorageTableCell::GetData()
{
return &m_oData;
}
const TTableCellStyle* CStorageTableCell::GetStyles() const
{
return &m_oStyles;
}
TTableCellStyle* CStorageTableCell::GetStyles()
{
return &m_oStyles;
}
void CStorageTableCell::SetWidth(const NSCSS::NSProperties::CDigit& oWidth)
{
m_oStyles.m_oWidth = oWidth;
}
void CStorageTableCell::SetHeight(const NSCSS::NSProperties::CDigit& oHeight)
{
m_oStyles.m_oHeight = oHeight;
}
UINT CStorageTableCell::GetWidth() const
{
return m_oStyles.m_oWidth.ToInt(NSCSS::Twips, DEFAULT_PAGE_WIDTH);
}
UINT CStorageTableCell::GetHeight() const
{
return m_oStyles.m_oHeight.ToInt(NSCSS::Twips, DEFAULT_PAGE_HEIGHT);
}
void CStorageTableCell::SetBorder(const NSCSS::NSProperties::CBorder& oBorder)
{
m_oStyles.m_oBorder = oBorder;
}
void CStorageTableCell::ClearTopBorder()
{
m_oStyles.m_oBorder.SetTopSide(L"none", 0, true);
}
void CStorageTableCell::ClearLeftBorder()
{
m_oStyles.m_oBorder.SetLeftSide(L"none", 0, true);
}
void CStorageTableCell::ClearBottomBorder()
{
m_oStyles.m_oBorder.SetBottomSide(L"none", 0, true);
}
void CStorageTableCell::ClearRightBorder()
{
m_oStyles.m_oBorder.SetRightSide(L"none", 0, true);
}
void CStorageTableCell::SetPadding(const NSCSS::NSProperties::CIndent& oPadding)
{
m_oStyles.m_oPadding = oPadding;
}
void CStorageTableCell::SetHAlign(const std::wstring& wsAlign)
{
m_oStyles.m_wsHAlign = wsAlign;
}
void CStorageTableCell::SetVAlign(const std::wstring& wsAlign)
{
m_oStyles.m_wsVAlign = wsAlign;
}
void CStorageTableCell::SetBackground(const NSCSS::NSProperties::CColor& oColor)
{
m_oStyles.m_oBackground = oColor;
}
CStorageTableRow::CStorageTableRow()
{}
CStorageTableRow::~CStorageTableRow()
{
for (CStorageTableCell* pCell : m_arCells)
RELEASEOBJECT(pCell);
}
void CStorageTableRow::AddCell(CStorageTableCell* pCell)
{
InsertCell(pCell, -1);
}
void CStorageTableRow::InsertCell(CStorageTableCell* pCell, int nPosition)
{
if (NULL == pCell)
return;
if (nPosition < 0)
{
std::vector<CStorageTableCell*>::iterator itFoundEmpty = std::find_if(m_arCells.begin(), m_arCells.end(), [](CStorageTableCell* pCell) { return pCell->Empty() && !pCell->Merged(); });
if (m_arCells.end() != itFoundEmpty)
{
--m_oStyles.m_unMaxIndex;
delete *itFoundEmpty;
*itFoundEmpty = pCell;
if (1 != pCell->GetColspan())
{
++itFoundEmpty;
UINT unColspan = pCell->GetColspan() - 1;
while (m_arCells.end() != itFoundEmpty && (*itFoundEmpty)->Empty() && unColspan > 0)
{
--m_oStyles.m_unMaxIndex;
--unColspan;
delete (*itFoundEmpty);
itFoundEmpty = m_arCells.erase(itFoundEmpty);
}
if (unColspan != 0)
pCell->SetColspan(pCell->GetColspan() - unColspan, MAXCOLUMNSINTABLE);
}
}
else
m_arCells.push_back(pCell);
}
else if (nPosition >= m_arCells.size())
{
const UINT unMissingCount = nPosition - m_arCells.size();
for (UINT unIndex = 0; unIndex < unMissingCount; ++unIndex)
m_arCells.push_back(CStorageTableCell::CreateEmpty());
m_oStyles.m_unMaxIndex += unMissingCount;
m_arCells.push_back(pCell);
}
else if (m_arCells[nPosition]->Empty())
{
delete m_arCells[nPosition];
--m_oStyles.m_unMaxIndex;
m_arCells[nPosition] = pCell;
if (1 != pCell->GetColspan())
{
++nPosition;
UINT unDeleteCount = pCell->GetColspan() - 1;
while (nPosition < m_arCells.size() && m_arCells[nPosition]->Empty() && !m_arCells[nPosition]->Merged() && unDeleteCount > 0)
{
delete m_arCells[nPosition];
--m_oStyles.m_unMaxIndex;
m_arCells.erase(m_arCells.begin() + nPosition);
--unDeleteCount;
}
if (0 != unDeleteCount)
pCell->SetColspan(pCell->GetColspan() - unDeleteCount, MAXCOLUMNSINTABLE);
}
}
else
m_arCells.insert(m_arCells.begin() + nPosition, pCell);
m_oStyles.m_unMaxIndex += pCell->GetColspan();
if (1 == pCell->GetColspan() && 1 == pCell->GetRowspan())
m_oStyles.m_unMaxHeight = std::max(m_oStyles.m_unMaxHeight, pCell->GetHeight());
}
UINT CStorageTableRow::GetIndex() const
{
return m_oStyles.m_unMaxIndex;
}
UINT CStorageTableRow::GetCount() const
{
return m_arCells.size();
}
CStorageTableCell* CStorageTableRow::operator[](UINT unIndex)
{
if (unIndex >= m_arCells.size())
return NULL;
return m_arCells[unIndex];
}
bool CStorageTableRow::Empty() const
{
return m_arCells.empty();
}
const TTableRowStyle& CStorageTableRow::GetStyles() const
{
return m_oStyles;
}
const std::vector<CStorageTableCell*>& CStorageTableRow::GetCells() const
{
return m_arCells;
}
CTableCol::CTableCol(UINT unSpan)
: m_unSpan(unSpan)
{}
CTableCol::CTableCol(const NSCSS::CNode& oTableColNode)
: m_unSpan(1)
{
m_unSpan = NSStringFinder::ToInt(oTableColNode.GetAttributeValue(L"span"));
}
UINT CTableCol::GetSpan() const
{
return m_unSpan;
}
TTableCellStyle* CTableCol::GetStyle()
{
return &m_oStyle;
}
const TTableCellStyle* CTableCol::GetStyle() const
{
return &m_oStyle;
}
CTableColgroup::CTableColgroup(NSCSS::CNode& oTableColgroupNode)
: m_unWidth(0)
{
m_unWidth = NSStringFinder::ToInt(oTableColgroupNode.GetAttributeValue(L"width"), 0);
}
CTableColgroup::~CTableColgroup()
{
RELEASE_VECTOR_PTR(m_arCols, CTableCol)
}
bool CTableColgroup::Empty() const
{
return m_arCols.empty();
}
void CTableColgroup::AddCol(CTableCol* pCol)
{
if (NULL != pCol)
m_arCols.push_back(pCol);
}
const std::vector<CTableCol*>& CTableColgroup::GetCols() const
{
return m_arCols;
}
TTableStyles::TTableStyles()
: m_nCellSpacing(-1), m_enRules(None)
{}
bool TTableStyles::Empty() const
{
return m_oPadding.Empty() && m_oMargin.Empty() && m_oBorder.Empty() && m_oWidth.Empty() && -1 == m_nCellSpacing && m_wsAlign.empty();
}
CStorageTable::CStorageTable()
: m_unMaxColumns(0)
{}
CStorageTable::~CStorageTable()
{
for (std::vector<CStorageTableRow*>& arHeaders : m_arHeaders)
RELEASE_VECTOR_PTR(arHeaders, CStorageTableRow)
RELEASE_VECTOR_PTR(m_arFoother, CStorageTableRow)
RELEASE_VECTOR_PTR(m_arRows, CStorageTableRow)
RELEASE_VECTOR_PTR(m_arColgroups, CTableColgroup)
}
CStorageTableRow* CStorageTable::operator[](UINT unIndex)
{
if (unIndex < m_arRows.size())
return m_arRows[unIndex];
return NULL;
}
bool CStorageTable::Empty() const
{
return m_arHeaders.empty() && m_arRows.empty() && m_arFoother.empty();
}
bool CStorageTable::HaveCaption()
{
return 0 != m_oCaption.GetCurSize();
}
bool CStorageTable::HaveColgroups() const
{
return !m_arColgroups.empty();
}
bool CStorageTable::HaveHeader() const
{
return !m_arHeaders.empty();
}
UINT CStorageTable::GetRowCount() const
{
return m_arRows.size();
}
const TTableStyles& CStorageTable::GetTableStyles() const
{
return m_oStyles;
}
const TTableCellStyle* CStorageTable::GetColStyle(UINT unColumnNumber) const
{
if (m_arColgroups.empty())
return NULL;
UINT unCurrentNumber = 0;
for (const CTableColgroup* pColgroup : m_arColgroups)
{
for (const CTableCol* pCol : pColgroup->GetCols())
{
unCurrentNumber += pCol->GetSpan();
if (unCurrentNumber >= unColumnNumber)
return pCol->GetStyle();
}
}
return NULL;
}
void CStorageTable::AddRows(std::vector<CStorageTableRow*>& arRows, ERowParseMode eParseMode)
{
if (arRows.empty())
return;
if (ERowParseMode::Foother == eParseMode && !m_arFoother.empty())
eParseMode = ERowParseMode::Header;
if (ERowParseMode::Header == eParseMode)
m_arHeaders.push_back({});
for (CStorageTableRow* pRow : arRows)
AddRow(pRow, eParseMode);
}
void CStorageTable::AddRow(CStorageTableRow* pRow, ERowParseMode eParseMode)
{
if (NULL == pRow)
return;
for (UINT unIndex = 0; unIndex < pRow->GetCount(); ++unIndex)
{
if (unIndex >= m_arMinColspan.size())
m_arMinColspan.push_back((*pRow)[unIndex]->GetColspan());
else if ((*pRow)[unIndex]->GetColspan() < m_arMinColspan[unIndex])
m_arMinColspan[unIndex] = (*pRow)[unIndex]->GetColspan();
}
switch (eParseMode)
{
default:
case ERowParseMode::Body:
{
m_arRows.push_back(pRow);
break;
}
case ERowParseMode::Header:
{
if (m_arHeaders.empty())
m_arHeaders.push_back({});
m_arHeaders.back().push_back(pRow);
break;
}
case ERowParseMode::Foother:
{
m_arFoother.push_back(pRow);
break;
}
}
}
NSStringUtils::CStringBuilder* CStorageTable::GetCaptionData()
{
return &m_oCaption;
}
void CStorageTable::SetPadding(const NSCSS::NSProperties::CIndent& oPadding)
{
m_oStyles.m_oPadding = oPadding;
}
const NSCSS::NSProperties::CIndent& CStorageTable::GetPadding() const
{
return m_oStyles.m_oPadding;
}
void CStorageTable::SetMargin(const NSCSS::NSProperties::CIndent& oMargin)
{
m_oStyles.m_oMargin = oMargin;
}
void CStorageTable::SetBorder(const NSCSS::NSProperties::CBorder& oBorder)
{
m_oStyles.m_oBorder = oBorder;
}
void CStorageTable::SetWidth(const NSCSS::NSProperties::CDigit& oWidth)
{
m_oStyles.m_oWidth = oWidth;
}
void CStorageTable::SetCellSpacing(int nCellSpacing)
{
m_oStyles.m_nCellSpacing = nCellSpacing;
}
void CStorageTable::SetAlign(const std::wstring& wsValue)
{
m_oStyles.m_wsAlign = wsValue;
}
void CStorageTable::SetRules(const std::wstring& wsValue)
{
if (wsValue.empty())
return;
if (NSStringFinder::Equals(wsValue, L"all"))
m_oStyles.m_enRules = TTableStyles::ETableRules::All;
else if (NSStringFinder::Equals(wsValue, L"groups"))
m_oStyles.m_enRules = TTableStyles::ETableRules::Groups;
else if (NSStringFinder::Equals(wsValue, L"cols"))
m_oStyles.m_enRules = TTableStyles::ETableRules::Cols;
else if (NSStringFinder::Equals(wsValue, L"none"))
m_oStyles.m_enRules = TTableStyles::ETableRules::None;
else if (NSStringFinder::Equals(wsValue, L"rows"))
m_oStyles.m_enRules = TTableStyles::ETableRules::Rows;
}
void CStorageTable::AddColgroup(CTableColgroup* pElement)
{
if (NULL != pElement)
m_arColgroups.push_back(pElement);
}
void CStorageTable::RecalculateMaxColumns()
{
for (const std::vector<CStorageTableRow*>& arHeaders : m_arHeaders)
for (const CStorageTableRow* pHeader : arHeaders)
m_unMaxColumns = std::max(m_unMaxColumns, pHeader->GetIndex());
for (const CStorageTableRow* pRow : m_arRows)
m_unMaxColumns = std::max(m_unMaxColumns, pRow->GetIndex());
for (const CStorageTableRow* pFoother : m_arFoother)
m_unMaxColumns = std::max(m_unMaxColumns, pFoother->GetIndex());
}
void CStorageTable::Shorten()
{
UINT unIndex = 0;
CStorageTableCell* pCell = NULL;
UINT unMaxIndex = 0; //Максимальный индекс без учета строк, где имеется только 1 ячейка
for (const CStorageTableRow* pRow : m_arRows)
{
if (1 < pRow->GetCount())
unMaxIndex = std::max(unMaxIndex, pRow->GetIndex());
}
while (unIndex < m_arMinColspan.size())
{
for (CStorageTableRow* pRow : m_arRows)
{
if (0 != unMaxIndex && 1 == pRow->GetCount() && pRow->GetIndex() > unMaxIndex)
{
pCell = (*pRow)[unIndex];
if (NULL == pCell)
continue;
pCell->SetColspan(unMaxIndex, MAXCOLUMNSINTABLE);
continue;
}
if (1 == m_arMinColspan[unIndex])
break;
pCell = (*pRow)[unIndex];
if (NULL == pCell)
continue;
if (1 < pCell->GetColspan() && pCell->GetColspan() > m_arMinColspan[unIndex])
{
pCell->SetColspan(m_arMinColspan[unIndex], MAXCOLUMNSINTABLE);
continue;
}
if ((*pRow)[unIndex]->GetColspan() == m_arMinColspan[unIndex] + 1)
(*pRow)[unIndex]->SetColspan(2, MAXCOLUMNSINTABLE);
else if ((*pRow)[unIndex]->GetColspan() > m_arMinColspan[unIndex])
(*pRow)[unIndex]->SetColspan((*pRow)[unIndex]->GetColspan() - m_arMinColspan[unIndex], MAXCOLUMNSINTABLE);
}
++unIndex;
}
}
void CStorageTable::CompleteTable()
{
UINT unMaxIndex = 0;
for (CStorageTableRow* pRow : m_arRows)
unMaxIndex = std::max(unMaxIndex, pRow->GetIndex());
for (CStorageTableRow* pRow : m_arRows)
{
if (NULL == pRow || 0 == pRow->GetCount())
continue;
for (UINT unIndex = pRow->GetIndex(); unIndex < unMaxIndex; ++unIndex)
pRow->InsertCell(CStorageTableCell::CreateEmpty(), unIndex);
}
RecalculateMaxColumns();
}
const std::vector<std::vector<CStorageTableRow*>>& CStorageTable::GetHeaders() const
{
return m_arHeaders;
}
const std::vector<CStorageTableRow*>& CStorageTable::GetFoothers() const
{
return m_arFoother;
}
const std::vector<CStorageTableRow*>& CStorageTable::GetRows() const
{
return m_arRows;
}
const std::vector<CTableColgroup*> CStorageTable::GetColgroups() const
{
return m_arColgroups;
}
UINT CStorageTable::GetMaxColumns() const
{
return m_unMaxColumns;
}
}

255
HtmlFile2/Table.h Normal file
View File

@ -0,0 +1,255 @@
#ifndef TABLE_H
#define TABLE_H
#include "../DesktopEditor/common/StringBuilder.h"
#include "../Common/3dParty/html/css/src/StyleProperties.h"
#include "../Common/3dParty/html/css/src/CNode.h"
#include <vector>
namespace HTML
{
#define MAXCOLUMNSINTABLE 63
#define MAXROWSINTABLE 32767
enum class ERowParseMode
{
Header,
Body,
Foother
};
enum class ERowPosition
{
First,
Middle,
Last
};
struct TTableRowStyle
{
UINT m_unMaxIndex;
UINT m_unMaxHeight;
bool m_bIsHeader;
TTableRowStyle();
bool Empty() const;
};
struct TTableCellStyle
{
NSCSS::NSProperties::CDigit m_oWidth;
NSCSS::NSProperties::CDigit m_oHeight;
NSCSS::NSProperties::CBorder m_oBorder;
NSCSS::NSProperties::CIndent m_oPadding;
NSCSS::NSProperties::CColor m_oBackground;
std::wstring m_wsHAlign;
std::wstring m_wsVAlign;
TTableCellStyle();
bool Empty();
void Copy(const TTableCellStyle* pTableCellStyle);
TTableCellStyle& operator+=(const TTableCellStyle* pCellStyle);
};
class CStorageTable;
class CStorageTableCell
{
public:
CStorageTableCell();
CStorageTableCell(UINT unColspan, UINT unRowspan, bool bIsMerged, bool bIsEmpty);
CStorageTableCell(CStorageTableCell& oCell);
bool Empty() const;
bool Merged() const;
CStorageTableCell* Copy();
static CStorageTableCell* CreateEmpty(UINT unColspan = 1, bool m_bIsMerged = false, const TTableCellStyle* pStyle = NULL);
static CStorageTableCell* CreateEmpty(const TTableCellStyle* pStyle);
void SetColspan(UINT unColspan, UINT unCurrentIndex);
UINT GetColspan() const;
void SetRowspan(UINT unRowspan);
UINT GetRowspan() const;
NSStringUtils::CStringBuilder* GetData();
const TTableCellStyle* GetStyles() const;
TTableCellStyle* GetStyles();
void SetWidth(const NSCSS::NSProperties::CDigit& oWidth);
void SetHeight(const NSCSS::NSProperties::CDigit& oHeight);
UINT GetWidth() const;
UINT GetHeight() const;
void SetBorder(const NSCSS::NSProperties::CBorder& oBorder);
void ClearTopBorder();
void ClearLeftBorder();
void ClearBottomBorder();
void ClearRightBorder();
void SetPadding(const NSCSS::NSProperties::CIndent& oPadding);
void SetHAlign(const std::wstring& wsAlign);
void SetVAlign(const std::wstring& wsAlign);
void SetBackground(const NSCSS::NSProperties::CColor& oColor);
private:
UINT m_unColspan;
UINT m_unRowSpan;
bool m_bIsMerged;
bool m_bIsEmpty;
TTableCellStyle m_oStyles;
NSStringUtils::CStringBuilder m_oData;
};
class CStorageTableRow
{
public:
CStorageTableRow();
~CStorageTableRow();
void AddCell(CStorageTableCell* pCell);
void InsertCell(CStorageTableCell *pCell, int nPosition);
UINT GetIndex() const;
UINT GetCount() const;
CStorageTableCell* operator[](UINT unIndex);
bool Empty() const;
const TTableRowStyle& GetStyles() const;
const std::vector<CStorageTableCell*>& GetCells() const;
private:
TTableRowStyle m_oStyles;
std::vector<CStorageTableCell*> m_arCells;
};
class CTableCol
{
public:
CTableCol(UINT unSpan);
CTableCol(const NSCSS::CNode& oTableColNode);
UINT GetSpan() const;
TTableCellStyle* GetStyle();
const TTableCellStyle* GetStyle() const;
private:
UINT m_unSpan;
TTableCellStyle m_oStyle;
};
class CTableColgroup
{
public:
CTableColgroup(NSCSS::CNode& oTableColgroupNode);
~CTableColgroup();
bool Empty() const;
void AddCol(CTableCol* pCol);
const std::vector<CTableCol*>& GetCols() const;
private:
std::vector<CTableCol*> m_arCols;
UINT m_unWidth;
};
//Необходимые стили таблицы
struct TTableStyles
{
NSCSS::NSProperties::CIndent m_oPadding;
NSCSS::NSProperties::CIndent m_oMargin;
NSCSS::NSProperties::CBorder m_oBorder;
NSCSS::NSProperties::CDigit m_oWidth;
int m_nCellSpacing;
std::wstring m_wsAlign;
enum ETableRules
{
All,
Groups,
Cols,
None,
Rows
} m_enRules;
TTableStyles();
bool Empty() const;
};
class CStorageTable
{
public:
CStorageTable();
~CStorageTable();
CStorageTableRow* operator[](UINT unIndex);
bool Empty() const;
bool HaveCaption();
bool HaveColgroups() const;
bool HaveHeader() const;
UINT GetRowCount() const;
const TTableStyles& GetTableStyles() const;
const TTableCellStyle* GetColStyle(UINT unColumnNumber) const;
void AddRows(std::vector<CStorageTableRow*>& m_arRows, ERowParseMode eParseMode = ERowParseMode::Body);
void AddRow(CStorageTableRow* pRow, ERowParseMode eParseMode = ERowParseMode::Body);
NSStringUtils::CStringBuilder* GetCaptionData();
void SetPadding(const NSCSS::NSProperties::CIndent& oPadding);
const NSCSS::NSProperties::CIndent& GetPadding() const;
void SetMargin(const NSCSS::NSProperties::CIndent& oMargin);
void SetBorder(const NSCSS::NSProperties::CBorder& oBorder);
void SetWidth(const NSCSS::NSProperties::CDigit& oWidth);
void SetCellSpacing(int nCellSpacing);
void SetAlign(const std::wstring& wsValue);
void SetRules(const std::wstring& wsValue);
void AddColgroup(CTableColgroup* pElement);
void RecalculateMaxColumns();
void Shorten();
void CompleteTable();
//TODO:: переделать на const std::vector<const T*> Get...() const;
const std::vector<std::vector<CStorageTableRow*>>& GetHeaders() const;
const std::vector<CStorageTableRow*>& GetFoothers() const;
const std::vector<CStorageTableRow*>& GetRows() const;
const std::vector<CTableColgroup*> GetColgroups() const;
UINT GetMaxColumns() const;
private:
std::vector<std::vector<CStorageTableRow*>> m_arHeaders;
std::vector<CStorageTableRow*> m_arFoother;
std::vector<CStorageTableRow*> m_arRows;
std::vector<UINT> m_arMinColspan;
NSStringUtils::CStringBuilder m_oCaption;
std::vector<CTableColgroup*> m_arColgroups;
TTableStyles m_oStyles;
UINT m_unMaxColumns;
};
}
#endif // TABLE_H

90
HtmlFile2/Tags/HTMLTags.h Normal file
View File

@ -0,0 +1,90 @@
#ifndef HTMLTAGS_H
#define HTMLTAGS_H
#include "../Common/3dParty/html/css/src/CNode.h"
#include <boost/any.hpp>
namespace HTML
{
class ITag
{
public:
virtual ~ITag() = default;
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) = 0;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) = 0;
};
class CEmptyTag : public ITag
{
public:
virtual ~CEmptyTag() = default;
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any())
{
return true;
};
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) {};
};
template<class T>
class CTag : public ITag
{
protected:
T* m_pWriter;
public:
CTag(T* pWriter)
: m_pWriter(pWriter)
{}
virtual ~CTag() = default;
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) = 0;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) = 0;
bool ValidWriter() const
{
return nullptr != m_pWriter;
}
};
#define CREATE_TAG(tag_name)\
template<class T>\
class tag_name : public CTag<T>\
{\
public:\
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors) = 0;\
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) = 0;\
}
CREATE_TAG(CAnchor);
CREATE_TAG(CAbbr);
CREATE_TAG(CBold);
CREATE_TAG(CBidirectional);
CREATE_TAG(CBreak);
CREATE_TAG(CCenter);
CREATE_TAG(CItalic);
CREATE_TAG(CKbd);
CREATE_TAG(CStrike);
CREATE_TAG(CUnderline);
CREATE_TAG(CMark);
CREATE_TAG(CQuotation);
CREATE_TAG(CSup);
CREATE_TAG(CSpan);
CREATE_TAG(CDD);
CREATE_TAG(CPreformatted);
CREATE_TAG(CHeader);
CREATE_TAG(CDivision);
CREATE_TAG(CImage);
CREATE_TAG(CFont);
CREATE_TAG(CInput);
CREATE_TAG(CBaseFont);
CREATE_TAG(CBlockquote);
CREATE_TAG(CHorizontalRule);
CREATE_TAG(CList);
CREATE_TAG(CListElement);
CREATE_TAG(CCaption);
CREATE_TAG(CTable);
CREATE_TAG(CTableRow);
CREATE_TAG(CTableCell);
CREATE_TAG(CCode);
CREATE_TAG(CHTML);
}
#endif // HTMLTAGS_H

520
HtmlFile2/Tags/MDTags.cpp Normal file
View File

@ -0,0 +1,520 @@
#include "MDTags.h"
#include "../src/StringFinder.h"
#include "../Table.h"
#include <boost/tuple/tuple.hpp>
namespace HTML
{
CAnchor<CMDWriter>::CAnchor(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CAnchor<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteString(L"[");
return true;
}
void CAnchor<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->WriteString(L"]");
std::wstring wsHref, wsTitle;
arSelectors.back().GetAttributeValue(L"href", wsHref);
arSelectors.back().GetAttributeValue(L"title", wsTitle);
m_pWriter->WriteString(L'(' + wsHref);
if (!wsTitle.empty())
m_pWriter->WriteString(L" \"" + wsTitle + L'"');
m_pWriter->WriteString(L")");
}
CBold<CMDWriter>::CBold(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CBold<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
if (m_pWriter->IsBold())
return true;
m_pWriter->WriteOpenSpecialString(L"**");
m_pWriter->EneteredBold();
return true;
}
void CBold<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter() || !m_pWriter->IsBold())
return;
m_pWriter->WriteCloseSpecialString(L"**");
m_pWriter->OutBold();
}
CBreak<CMDWriter>::CBreak(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CBreak<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteBreakLine();
return true;
}
void CBreak<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{}
CItalic<CMDWriter>::CItalic(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CItalic<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
if (m_pWriter->IsItalic())
return true;
m_pWriter->WriteOpenSpecialString(L"*");
m_pWriter->EneteredItalic();
return true;
}
void CItalic<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter() || !m_pWriter->IsItalic())
return;
m_pWriter->WriteCloseSpecialString(L"*");
m_pWriter->OutItalic();
}
CStrike<CMDWriter>::CStrike(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CStrike<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
if (m_pWriter->IsStrike())
return true;
m_pWriter->WriteOpenSpecialString(L"~~");
m_pWriter->EneteredStrike();
return true;
}
void CStrike<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter() || !m_pWriter->IsStrike())
return;
m_pWriter->WriteCloseSpecialString(L"~~");
m_pWriter->OutStrike();
}
CQuotation<CMDWriter>::CQuotation(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CQuotation<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
return true;
}
void CQuotation<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{}
CPreformatted<CMDWriter>::CPreformatted(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CPreformatted<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteOpenSpecialString(L"```");
m_pWriter->EnteredPreformatted();
return true;
}
void CPreformatted<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
bool bNeedBreakLine{false};
for (std::vector<NSCSS::CNode>::const_reverse_iterator itElement{arSelectors.crbegin()}; itElement < arSelectors.crend(); ++itElement)
{
if (L"pre" == itElement->m_wsName)
{
bNeedBreakLine = true;
break;
}
}
if (bNeedBreakLine && !m_pWriter->InTable())
m_pWriter->WriteBreakLine();
m_pWriter->WriteCloseSpecialString(L"```");
m_pWriter->OutPreformatted();
if (bNeedBreakLine && !m_pWriter->InTable())
m_pWriter->WriteBreakLine(false);
}
CHeader<CMDWriter>::CHeader(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CHeader<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
switch(arSelectors.back().m_wsName[1])
{
case L'1' : m_pWriter->WriteString(L"# ", true); break;
case L'2' : m_pWriter->WriteString(L"## ", true); break;
case L'3' : m_pWriter->WriteString(L"### ", true); break;
case L'4' : m_pWriter->WriteString(L"#### ", true); break;
case L'5' : m_pWriter->WriteString(L"##### ", true); break;
case L'6' : m_pWriter->WriteString(L"###### ", true); break;
default:
return false;
}
return true;
}
void CHeader<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
}
CImage<CMDWriter>::CImage(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CImage<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
std::wstring wsAlt, wsSrc, wsTitle;
if (!arSelectors.back().GetAttributeValue(L"src", wsSrc) &&
!arSelectors.back().GetAttributeValue(L"alt", wsAlt))
return false;
arSelectors.back().GetAttributeValue(L"title", wsTitle);
m_pWriter->WriteString(L"![" + wsAlt + L"](" + wsSrc);
if (!wsTitle.empty())
m_pWriter->WriteString(L" \"" + wsTitle + L'"');
m_pWriter->WriteString(L")");
return true;
}
void CImage<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->WriteBreakLine();
}
CHorizontalRule<CMDWriter>::CHorizontalRule(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CHorizontalRule<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteBreakLine(false);
m_pWriter->WriteString(L"---");
m_pWriter->WriteBreakLine(false);
return true;
}
void CHorizontalRule<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{}
CBlockquote<CMDWriter>::CBlockquote(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CBlockquote<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteBreakLine();
m_pWriter->EnteredBlockquote();
return true;
}
void CBlockquote<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->OutBlockquote();
m_pWriter->WriteBreakLine();
m_pWriter->WriteBreakLine(false);
}
CTable<CMDWriter>::CTable(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CTable<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter() || m_pWriter->InTable()) //В MD не поддерживаются вложенные таблицы
return false;
m_pWriter->WriteBreakLine();
m_pWriter->EnteredTable();
if (m_pWriter->InCode())
{
if (!m_pWriter->InPreformatted())
m_pWriter->WriteCloseSpecialString(L"`");
m_pWriter->OutCode();
}
if (m_pWriter->InPreformatted())
{
m_pWriter->WriteBreakLine();
m_pWriter->WriteCloseSpecialString(L"```");
m_pWriter->WriteBreakLine(false);
m_pWriter->OutPreformatted();
}
return true;
}
void CTable<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->OutTable();
m_pWriter->WriteBreakLine();
}
CTableRow<CMDWriter>::CTableRow(CMDWriter* pWriter)
: CTag(pWriter), m_unLastRowType(static_cast<UINT>(ERowParseMode::Foother))
{}
bool CTableRow<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
using DataForRow = boost::tuple<const TTableRowStyle*, const CStorageTable&, ERowParseMode, ERowPosition>;
if (!ValidWriter() || oExtraData.empty() || typeid(DataForRow) != oExtraData.type())
return false;
m_pWriter->EnteredTable();
const DataForRow& oDataForRow(boost::any_cast<DataForRow>(oExtraData));
const CStorageTable& oStorageTable{boost::get<1>(oDataForRow)};
if (nullptr == boost::get<0>(oDataForRow) && ERowParseMode::Header == boost::get<2>(oDataForRow))
{
for (UINT unIndex = 0; unIndex < oStorageTable.GetMaxColumns(); ++unIndex)
m_pWriter->WriteOpenSpecialString(L"| ");
m_pWriter->WriteOpenSpecialString(L"|");
m_pWriter->WriteBreakLine();
m_unLastRowType = static_cast<UINT>(ERowParseMode::Header);
return true;
}
if (m_unLastRowType == static_cast<UINT>(ERowParseMode::Header))
{
for (UINT unIndex = 0; unIndex < oStorageTable.GetMaxColumns(); ++unIndex)
m_pWriter->WriteString(L"|-");
m_pWriter->WriteOpenSpecialString(L"|");
m_pWriter->WriteBreakLine(false);
}
m_pWriter->WriteOpenSpecialString(L"| ");
m_unLastRowType = static_cast<UINT>(boost::get<2>(oDataForRow));
return true;
}
void CTableRow<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->WriteBreakLine(false);
}
CTableCell<CMDWriter>::CTableCell(CMDWriter* pWriter)
: CTag(pWriter), m_unNeedEmptyCells(0)
{}
bool CTableCell<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
using DataForCell = boost::tuple<const CStorageTableCell&, const CStorageTable&, UINT, ERowParseMode, ERowPosition>;
if (!ValidWriter() || oExtraData.empty() || typeid(DataForCell) != oExtraData.type())
return false;
const DataForCell& oDataForCell{boost::any_cast<const DataForCell>(oExtraData)};
m_unNeedEmptyCells = boost::get<0>(oDataForCell).GetColspan() - 1;
return true;
}
void CTableCell<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
for (UINT unIndex = 0; unIndex < m_unNeedEmptyCells; ++unIndex)
m_pWriter->WriteOpenSpecialString(L" |");
m_unNeedEmptyCells = 0;
m_pWriter->WriteOpenSpecialString(L" | ");
}
CList<CMDWriter>::CList(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CList<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->WriteBreakLine();
m_pWriter->EnteredList(L"ol" == arSelectors.back().m_wsName);
if (!m_pWriter->InOrederedList())
return true;
std::wstring wsIndex;
if (arSelectors.back().GetAttributeValue(L"start", wsIndex))
m_pWriter->SetIndexOrderedList(NSStringFinder::ToInt(wsIndex, 1));
return true;
}
void CList<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
m_pWriter->OutList();
}
CListElement<CMDWriter>::CListElement(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CListElement<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
if (0 != m_pWriter->GetLevelList())
{
for (UINT unLevelList = 0; unLevelList < m_pWriter->GetLevelList() - 1; ++unLevelList)
m_pWriter->WriteString(L" ");
}
if (m_pWriter->InOrederedList())
{
m_pWriter->WriteString(std::to_wstring(m_pWriter->GetIndexOrderedList()) + m_pWriter->GetParametrs().m_wchOrderedList + L' ');
m_pWriter->IncreaseIndexOrderedList();
}
else
m_pWriter->WriteString({m_pWriter->GetParametrs().m_wchUnorderedList, L' '});
return true;
}
void CListElement<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{}
CCode<CMDWriter>::CCode(CMDWriter* pWriter)
: CTag(pWriter)
{}
bool CCode<CMDWriter>::Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData)
{
if (!ValidWriter())
return false;
m_pWriter->EnteredCode();
if (m_pWriter->InPreformatted())
{
if (!arSelectors.back().m_wsClass.empty() && arSelectors.back().m_wsClass.size() >= 9 &&
0 == arSelectors.back().m_wsClass.compare(0, 9, L"language-"))
m_pWriter->WriteString(arSelectors.back().m_wsClass.substr(9, arSelectors.back().m_wsClass.size() - 9));
m_pWriter->WriteBreakLine(false);
}
else
m_pWriter->WriteOpenSpecialString(L"`");
return true;
}
void CCode<CMDWriter>::Close(const std::vector<NSCSS::CNode>& arSelectors)
{
if (!ValidWriter())
return;
if (!m_pWriter->InPreformatted())
m_pWriter->WriteCloseSpecialString(L"`");
m_pWriter->OutCode();
}
}

165
HtmlFile2/Tags/MDTags.h Normal file
View File

@ -0,0 +1,165 @@
#ifndef MDTAGS_H
#define MDTAGS_H
#include "HTMLTags.h"
#include "../Writers/MDWriter.h"
namespace HTML
{
template<>
class CAnchor<CMDWriter> : public CTag<CMDWriter>
{
public:
CAnchor(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBold<CMDWriter> : public CTag<CMDWriter>
{
public:
CBold(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBreak<CMDWriter> : public CTag<CMDWriter>
{
public:
CBreak(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CItalic<CMDWriter> : public CTag<CMDWriter>
{
public:
CItalic(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CStrike<CMDWriter> : public CTag<CMDWriter>
{
public:
CStrike(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CQuotation<CMDWriter> : public CTag<CMDWriter>
{
public:
CQuotation(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CPreformatted<CMDWriter> : public CTag<CMDWriter>
{
public:
CPreformatted(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CHeader<CMDWriter> : public CTag<CMDWriter>
{
public:
CHeader(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CImage<CMDWriter> : public CTag<CMDWriter>
{
public:
CImage(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CHorizontalRule<CMDWriter> : public CTag<CMDWriter>
{
public:
CHorizontalRule(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBlockquote<CMDWriter> : public CTag<CMDWriter>
{
public:
CBlockquote(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTable<CMDWriter> : public CTag<CMDWriter>
{
public:
CTable(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTableRow<CMDWriter> : public CTag<CMDWriter>
{
UINT m_unLastRowType;
public:
CTableRow(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTableCell<CMDWriter> : public CTag<CMDWriter>
{
UINT m_unNeedEmptyCells;
public:
CTableCell(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CList<CMDWriter> : public CTag<CMDWriter>
{
public:
CList(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CListElement<CMDWriter> : public CTag<CMDWriter>
{
public:
CListElement(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CCode<CMDWriter> : public CTag<CMDWriter>
{
public:
CCode(CMDWriter* pWriter);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
}
#endif // MDTAGS_H

1492
HtmlFile2/Tags/OOXMLTags.cpp Normal file

File diff suppressed because it is too large Load Diff

167
HtmlFile2/Tags/OOXMLTags.h Normal file
View File

@ -0,0 +1,167 @@
#ifndef OOXMLTAGS_H
#define OOXMLTAGS_H
#include "HTMLTags.h"
#include "../Writers/OOXMLWriter.h"
namespace HTML
{
template<>
class CAnchor<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CAnchor(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CAbbr<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CAbbr(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBreak<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CBreak(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CDivision<COOXMLWriter> : public CTag<COOXMLWriter>
{
std::stack<UINT> m_arFootnoteIDs;
public:
CDivision(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CImage<COOXMLWriter> : public CTag<COOXMLWriter>
{
std::vector<std::wstring> m_arrImages;
public:
CImage(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CFont<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CFont(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CInput<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CInput(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBaseFont<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CBaseFont(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CBlockquote<COOXMLWriter> : public CTag<COOXMLWriter>
{
std::map<std::wstring, UINT> m_mDivs;
public:
CBlockquote(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CHorizontalRule<COOXMLWriter> : public CTag<COOXMLWriter>
{
UINT m_unShapeId;
public:
CHorizontalRule(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CList<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CList(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CListElement<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CListElement(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CCaption<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CCaption(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTable<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CTable(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTableRow<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CTableRow(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CTableCell<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CTableCell(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
template<>
class CHTML<COOXMLWriter> : public CTag<COOXMLWriter>
{
public:
CHTML(COOXMLWriter* pInterpretator);
virtual bool Open(const std::vector<NSCSS::CNode>& arSelectors, const boost::any& oExtraData = boost::any()) override;
virtual void Close(const std::vector<NSCSS::CNode>& arSelectors) override;
};
}
#endif // OOXMLTAGS_H

View File

@ -0,0 +1,34 @@
#ifndef IWRITER_H
#define IWRITER_H
#include "../../Common/3dParty/html/css/src/CNode.h"
#include "../Common.h"
namespace HTML
{
class IWriter
{
public:
IWriter() = default;
virtual ~IWriter() = default;
virtual void Begin(const std::wstring& wsDst) = 0;
virtual void End(const std::wstring& wsDst) = 0;
virtual bool WriteText(std::wstring wsText, const std::vector<NSCSS::CNode>& arSelectors) = 0;
virtual void WriteEmptyParagraph(bool bVahish = false, bool bInP = false) = 0;
virtual void PageBreak() = 0;
virtual void BeginBlock() = 0;
virtual void EndBlock(bool bAddBlock) = 0;
virtual void SetDataOutput(XmlString* pOutputData) = 0; // Задаем место вывода для интерпретатора
virtual void RevertDataOutput() = 0; // Возвращаем место вывода к исходному
virtual XmlString* GetCurrentDocument() const = 0;
};
}
#endif // IWRITER_H

View File

@ -0,0 +1,403 @@
#include "MDWriter.h"
#include <cwctype>
#include "../../DesktopEditor/common/File.h"
#include "../../Common/3dParty/html/css/src/CCompiledStyle.h"
namespace HTML
{
CMDWriter::CMDWriter(const TMarkdownParameters& oMDParametrs)
: m_oMDParametrs(oMDParametrs)
{
m_arStates.push(TState{});
m_arStates.top().m_pCurrentDocument = &m_oDocument;
}
void CMDWriter::Begin(const std::wstring& wsDst)
{
}
void CMDWriter::End(const std::wstring& wsDst)
{
NSFile::CFileBinary oDocument;
if (!oDocument.CreateFileW(wsDst))
return;
oDocument.WriteStringUTF8(m_oDocument.GetData());
oDocument.CloseFile();
}
inline void ReplaceSpaces(std::wstring& wsValue)
{
// boost::wregex oRegex(L"\\s+");
// wsValue = boost::regex_replace(wsValue, oRegex, L" ");
std::wstring::const_iterator itBegin = std::find_if(wsValue.cbegin(), wsValue.cend(), [](wchar_t wchValue){ return std::iswspace(wchValue) && 0xa0 != wchValue; });
std::wstring::const_iterator itEnd;
while (wsValue.cend() != itBegin)
{
itEnd = std::find_if(itBegin, wsValue.cend(), [](wchar_t wchValue){ return !std::iswspace(wchValue) || 0xa0 == wchValue; });
wsValue.replace(itBegin, itEnd, L" ");
itBegin = std::find_if(itBegin + 1, wsValue.cend(), [](wchar_t wchValue){ return std::iswspace(wchValue) && 0xa0 != wchValue; });
}
}
bool CMDWriter::WriteText(std::wstring wsText, const std::vector<NSCSS::CNode>& arSelectors)
{
bool bPreformatted{InPreformatted()};
const NSCSS::CCompiledStyle* pCompiledStyle{arSelectors.back().m_pCompiledStyle};
if (!bPreformatted && nullptr != pCompiledStyle)
{
// TODO::поведение должно быть немного разное (реализовать)
switch(pCompiledStyle->m_oDisplay.GetWhiteSpace().ToInt())
{
case NSCSS::NSProperties::EWhiteSpace::Pre:
case NSCSS::NSProperties::EWhiteSpace::Pre_Wrap:
case NSCSS::NSProperties::EWhiteSpace::Pre_Line:
bPreformatted = true;
default:
break;
}
}
if (!bPreformatted && wsText.end() == std::find_if_not(wsText.begin(), wsText.end(), [](wchar_t wchChar){ return iswspace(wchChar) && 0xa0 != wchChar;}))
return false;
if (bPreformatted && !m_arStates.top().m_bEmptyLine && !m_arStates.top().m_bInTable)
{
for (std::vector<NSCSS::CNode>::const_reverse_iterator itElement{arSelectors.crbegin()}; itElement < arSelectors.crend(); ++itElement)
{
if (L"pre" == itElement->m_wsName)
{
GetCurrentDocument()->AddCharSafe(L'\n');
break;
}
}
}
//Пока корректно работает только для текста (необходимо проверить и с другими нодами)
if (m_arStates.top().m_bEmptyLine)
{
for (UINT unIndex = 0; unIndex < GetLevelBlockquote(); ++unIndex)
WriteString(L"> ", true);
}
if (!bPreformatted && !InCode())
ReplaceSpaces(wsText);
bool bNeedBold{false}, bNeedItalic{false}, bNeedStrike{false};
if (nullptr != pCompiledStyle)
{
if (!IsBold() && pCompiledStyle->m_oFont.Bold())
bNeedBold = true;
if (!IsItalic() && pCompiledStyle->m_oFont.Italic())
bNeedItalic = true;
if (!IsStrike() && pCompiledStyle->m_oText.LineThrough())
bNeedStrike = true;
}
if (bNeedBold)
WriteString(L"**");
if (bNeedItalic)
WriteString(L"*");
if (bNeedStrike)
WriteString(L"~~");
ApplyAlternativeTags(pCompiledStyle);
WriteString(wsText);
ApplyAlternativeTags(pCompiledStyle, true);
if (bNeedBold)
WriteString(L"**");
if (bNeedItalic)
WriteString(L"*");
if (bNeedStrike)
WriteString(L"~~");
if (L'\n' == wsText.back())
m_arStates.top().m_bNeedBreakLine = false;
return true;
}
void CMDWriter::WriteEmptyParagraph(bool bVahish, bool bInP)
{}
void CMDWriter::PageBreak()
{}
void CMDWriter::BeginBlock()
{
if (!m_arStates.top().m_bInList)
WriteBreakLine();
}
void CMDWriter::EndBlock(bool bAddBlock)
{
if (!m_arStates.top().m_bInTable)
WriteBreakLine();
}
void CMDWriter::SetDataOutput(XmlString* pOutputData)
{
SaveState();
m_arStates.top().m_pCurrentDocument = pOutputData;
}
void CMDWriter::RevertDataOutput()
{
RollBackState();
}
TMarkdownParameters CMDWriter::GetParametrs() const
{
return m_oMDParametrs;
}
void CMDWriter::WriteString(const std::wstring& wsString, bool bSpecialString)
{
GetCurrentDocument()->WriteString(wsString);
if (m_arStates.top().m_bEmptyLine)
m_arStates.top().m_bEmptyLine = wsString.empty();
if (!bSpecialString)
m_arStates.top().m_bNeedBreakLine = true;
}
void CMDWriter::WriteOpenSpecialString(const std::wstring& wsString)
{
if (m_arStates.top().m_wsLastSpecialString == wsString)
GetCurrentDocument()->WriteString(L" ");
m_arStates.top().m_wsLastSpecialString.clear();
WriteString(wsString, true);
}
void CMDWriter::WriteCloseSpecialString(const std::wstring& wsString)
{
m_arStates.top().m_wsLastSpecialString = wsString;
WriteString(wsString, true);
}
XmlString* CMDWriter::GetCurrentDocument() const
{
return m_arStates.top().m_pCurrentDocument;
}
void CMDWriter::WriteBreakLine(bool bNeedChecked)
{
if (bNeedChecked && !m_arStates.top().m_bNeedBreakLine)
return;
if (m_arStates.top().m_bInTable && bNeedChecked)
{
if (m_oMDParametrs.m_bUseAlternativeHTMLTags)
WriteString(L"</br>");
m_arStates.top().m_bNeedBreakLine = false;
return;
}
if (m_arStates.top().m_bEmptyLine)
{
for (UINT unIndex = 0; unIndex < GetLevelBlockquote(); ++unIndex)
WriteString(L"> ", true);
}
GetCurrentDocument()->WriteString(L" \n");
m_arStates.top().m_bEmptyLine = true;
m_arStates.top().m_bNeedBreakLine = false;
m_arStates.top().m_wsLastSpecialString.clear();
}
void CMDWriter::EneteredBold()
{
m_arStates.top().m_bBold = true;
}
void CMDWriter::OutBold()
{
m_arStates.top().m_bBold = false;
}
bool CMDWriter::IsBold()
{
return m_arStates.top().m_bBold;
}
void CMDWriter::EneteredItalic()
{
m_arStates.top().m_bItalic = true;
}
void CMDWriter::OutItalic()
{
m_arStates.top().m_bItalic = false;
}
bool CMDWriter::IsItalic()
{
return m_arStates.top().m_bItalic;
}
void CMDWriter::EneteredStrike()
{
m_arStates.top().m_bStrike = true;
}
void CMDWriter::OutStrike()
{
m_arStates.top().m_bStrike = false;
}
bool CMDWriter::IsStrike()
{
return m_arStates.top().m_bStrike;
}
void CMDWriter::EnteredBlockquote()
{
m_arStates.top().m_unLevelBlockquote++;
}
void CMDWriter::OutBlockquote()
{
if (m_arStates.top().m_unLevelBlockquote > 0)
m_arStates.top().m_unLevelBlockquote--;
}
UINT CMDWriter::GetLevelBlockquote()
{
return m_arStates.top().m_unLevelBlockquote;
}
void CMDWriter::EnteredTable()
{
m_arStates.top().m_bInTable = true;
}
void CMDWriter::OutTable()
{
m_arStates.top().m_bInTable = false;
}
bool CMDWriter::InTable() const
{
return m_arStates.top().m_bInTable;
}
void CMDWriter::EnteredPreformatted()
{
m_arStates.top().m_bInPreformatted = true;
}
void CMDWriter::OutPreformatted()
{
m_arStates.top().m_bInPreformatted = false;
}
bool CMDWriter::InPreformatted() const
{
return m_arStates.top().m_bInPreformatted;
}
void CMDWriter::EnteredCode()
{
m_arStates.top().m_bInCode = true;
}
void CMDWriter::OutCode()
{
m_arStates.top().m_bInCode = false;
}
bool CMDWriter::InCode() const
{
return m_arStates.top().m_bInCode;
}
void CMDWriter::EnteredList(bool bOrderedList)
{
SaveState();
m_arStates.top().m_bInList = true;
m_arStates.top().m_bIsOrederedList = bOrderedList;
m_arStates.top().m_unLevelList++;
}
void CMDWriter::OutList()
{
RollBackState();
}
void CMDWriter::SetIndexOrderedList(UINT unIndex)
{
m_arStates.top().m_unIndexListElement = unIndex;
}
void CMDWriter::IncreaseIndexOrderedList()
{
m_arStates.top().m_unIndexListElement++;
}
bool CMDWriter::InOrederedList() const
{
return m_arStates.top().m_bIsOrederedList;
}
UINT CMDWriter::GetIndexOrderedList() const
{
return m_arStates.top().m_unIndexListElement;
}
UINT CMDWriter::GetLevelList() const
{
return m_arStates.top().m_unLevelList;
}
void CMDWriter::SaveState()
{
m_arStates.push(m_arStates.top());
}
void CMDWriter::RollBackState()
{
if (m_arStates.size() > 1)
m_arStates.pop();
}
void CMDWriter::ApplyAlternativeTags(const NSCSS::CCompiledStyle* pCompiledStyle, bool bIsCloseTag)
{
if (nullptr == pCompiledStyle || !m_oMDParametrs.m_bUseAlternativeHTMLTags)
return;
if (pCompiledStyle->m_oText.Underline())
GetCurrentDocument()->WriteString(bIsCloseTag ? L"</u>" : L"<u>");
if (L"top" == pCompiledStyle->m_oDisplay.GetVAlign().ToWString())
GetCurrentDocument()->WriteString(bIsCloseTag ? L"</sup>" : L"<sup>");
else if (L"bottom" == pCompiledStyle->m_oDisplay.GetVAlign().ToWString())
GetCurrentDocument()->WriteString(bIsCloseTag ? L"</sub>" : L"<sub>");
if (L"FFFF00" == pCompiledStyle->m_oBackground.GetColor().ToHEX())
GetCurrentDocument()->WriteString(bIsCloseTag ? L"</mark>" : L"<mark>");
}
}

View File

@ -0,0 +1,117 @@
#ifndef MDWRITER_H
#define MDWRITER_H
#include "IWriter.h"
#include "../MarkdownParameters.h"
#include <stack>
namespace HTML
{
class CMDWriter : public IWriter
{
XmlString m_oDocument;
struct TState
{
XmlString *m_pCurrentDocument{nullptr};
bool m_bNeedBreakLine{false};
bool m_bEmptyLine{true};
UINT m_unLevelBlockquote{0};
bool m_bBold{false};
bool m_bItalic{false};
bool m_bStrike{false};
bool m_bInTable{false};
bool m_bInPreformatted{false};
bool m_bInCode{false};
bool m_bInList{false};
bool m_bIsOrederedList{false};
UINT m_unLevelList{0};
UINT m_unIndexListElement{1};
std::wstring m_wsLastSpecialString;
};
std::stack<TState> m_arStates;
TMarkdownParameters m_oMDParametrs;
public:
CMDWriter(const TMarkdownParameters& oMDParametrs);
void Begin(const std::wstring& wsDst) override;
void End(const std::wstring& wsDst) override;
bool WriteText(std::wstring wsText, const std::vector<NSCSS::CNode>& arSelectors) override;
void WriteEmptyParagraph(bool bVahish = false, bool bInP = false) override;
void PageBreak() override;
void BeginBlock() override;
void EndBlock(bool bAddBlock) override;
void SetDataOutput(XmlString* pOutputData) override;
void RevertDataOutput() override;
TMarkdownParameters GetParametrs() const;
void WriteString(const std::wstring& wsString, bool bSpecialString = false);
void WriteOpenSpecialString(const std::wstring& wsString);
void WriteCloseSpecialString(const std::wstring& wsString);
XmlString* GetCurrentDocument() const override;
void WriteBreakLine(bool bNeedChecked = true);
void EneteredBold();
void OutBold();
bool IsBold();
void EneteredItalic();
void OutItalic();
bool IsItalic();
void EneteredStrike();
void OutStrike();
bool IsStrike();
void EnteredBlockquote();
void OutBlockquote();
UINT GetLevelBlockquote();
void EnteredTable();
void OutTable();
bool InTable() const;
void EnteredPreformatted();
void OutPreformatted();
bool InPreformatted() const;
void EnteredCode();
void OutCode();
bool InCode() const;
void EnteredList(bool bOrderedList);
void OutList();
void SetIndexOrderedList(UINT unIndex);
void IncreaseIndexOrderedList();
bool InOrederedList() const;
UINT GetIndexOrderedList() const;
UINT GetLevelList() const;
void SetLinePrefix(const std::wstring& wsPrefix);
void ClearLinePrefix();
private:
void SaveState();
void RollBackState();
void ApplyAlternativeTags(const NSCSS::CCompiledStyle* pCompiledStyle, bool bIsCloseTag = false);
};
}
#endif // MDWRITER_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,214 @@
#ifndef OOXMLWRITER_H
#define OOXMLWRITER_H
#include "../../Common/3dParty/html/css/src/xhtml/CDocumentStyle.h"
#include "../../Common/3dParty/html/css/src/CCssCalculator.h"
#include "../HTMLParameters.h"
#include "IWriter.h"
#include <stack>
namespace NSFonts { class IApplicationFonts; }
namespace HTML
{
struct TImageData
{
UINT m_unWidth;
UINT m_unHeight;
int m_nHSpace;
int m_nVSpace;
std::wstring m_wsAlign;
TImageData()
: m_unWidth(0), m_unHeight(0), m_nHSpace(0), m_nVSpace(0), m_wsAlign(L"left")
{}
bool ZeroSize() const
{
return 0 == m_unWidth || 0 == m_unHeight;
}
bool ZeroSpaces() const
{
return 0 == m_nHSpace && 0 == m_nVSpace;
}
};
class COOXMLWriter : public IWriter
{
const std::wstring *m_pDstPath; // Директория назначения
const std::wstring *m_pTempDir; // Temp папка
const std::wstring *m_pSrcPath; // Директория источника
const std::wstring *m_pBasePath; // Полный базовый адрес
const std::wstring *m_pCorePath; // Путь до корневого файла (используется для работы с Epub)
XmlString m_oStylesXml; // styles.xml
XmlString m_oDocXmlRels; // document.xml.rels
XmlString m_oNoteXmlRels; // footnotes.xml.rels
XmlString m_oDocXml; // document.xml
XmlString m_oNoteXml; // footnotes.xml
XmlString m_oNumberXml; // numbering.xml
XmlString m_oWebSettings; // webSettings.xml
NSCSS::CDocumentStyle m_oXmlStyle; // Ooxml стиль
NSCSS::NSProperties::CPage m_oPageData; // Стили страницы
NSCSS::CCssCalculator *m_pStylesCalculator;
THTMLParameters *m_pHTMLParameters;
struct TState
{
bool m_bInP; // <w:p> открыт?
bool m_bInR; // <w:r> открыт?
bool m_bInT; // <w:t> открыт?
bool m_bWasPStyle; // <w:pStyle> записан?
bool m_bWasSpace; // Был пробел?
bool m_bInHyperlink; // <w:hyperlink> открыт?
std::wstring m_wsTooltip;
std::wstring m_wsHref;
std::wstring m_wsFootnote;
bool m_bIsFootnote;
bool m_bISCrossHyperlink;
XmlString *m_pCurrentDocument; //Текущее место записи
bool m_bRemoveCurrentDocument;
TState(XmlString *pCurrentDocument)
: m_bInP(false), m_bInR(false), m_bInT(false),
m_bWasPStyle(false), m_bWasSpace(true), m_bInHyperlink(false),
m_bIsFootnote(false), m_bISCrossHyperlink(false),
m_pCurrentDocument(pCurrentDocument), m_bRemoveCurrentDocument(false)
{}
~TState()
{
if (m_bRemoveCurrentDocument && nullptr != m_pCurrentDocument)
delete m_pCurrentDocument;
}
void CreateNewCurrentDocument()
{
m_pCurrentDocument = new XmlString();
m_bRemoveCurrentDocument = true;
}
};
std::stack<TState> m_arStates;
int m_nFootnoteId; // ID сноски
int m_nHyperlinkId; // ID ссылки
int m_nListId; // ID списка
int m_nElementId; // ID остальные элементы
bool m_bBanUpdatePageData; // Запретить обновление данных о странице?
std::stack<std::wstring> m_arDivId;
bool m_bWasDivs;
std::map<std::wstring, std::wstring> m_mFootnotes; // Сноски
std::map<std::wstring, UINT> m_mBookmarks; // Закладки
using anchors_map = std::map<std::wstring, std::wstring>;
anchors_map m_mAnchors; // Map якорей с индивидуальными id
NSFonts::IApplicationFonts* m_pFonts; // Необходимо для оптимизации работы со шрифтами
public:
COOXMLWriter(THTMLParameters* pHTMLParameters = nullptr, NSCSS::CCssCalculator* pCSSCalculator = nullptr);
void SetSrcDirectory (const std::wstring& wsPath);
void SetDstDirectory (const std::wstring& wsPath);
void SetTempDirectory(const std::wstring& wsPath);
void SetBaseDirectory(const std::wstring& wsPath);
void SetCoreDirectory(const std::wstring& wsPath);
void Begin(const std::wstring& wsDst) override;
void End(const std::wstring& wsDst) override;
bool OpenP();
bool OpenR();
bool OpenT();
void OpenHyperlink();
void CloseP();
void CloseR();
void CloseT();
void CloseHyperlink();
void PageBreak() override;
void BeginBlock() override;
void EndBlock(bool bAddBlock) override;
void SetDataOutput(XmlString* pOutputData) override;
void RevertDataOutput() override;
void SaveState();
void RollBackState();
void SetCurrentDocument(XmlString* pNewDocument);
void Break(const std::vector<NSCSS::CNode>& arSelectors);
void SetHyperlinkData(const std::wstring& wsRef, const std::wstring& wsTooltip, bool bIsCross, const std::wstring& wsFootnote, bool bIsFootnote);
void ClearHyperlinkData();
void OpenCrossHyperlink(const std::wstring& wsRef);
void OpenExternalHyperlink(const std::wstring& wsRef, const std::wstring& wsTooltip);
void CloseCrossHyperlink(const std::vector<NSCSS::CNode>& arSelectors, std::wstring wsFootnote, const std::wstring& wsRef);
void CloseExternalHyperlink();
std::wstring WritePPr(const std::vector<NSCSS::CNode>& arSelectors);
std::wstring WriteRPr(XmlString& oXml, const std::vector<NSCSS::CNode>& arSelectors);
bool WriteText(std::wstring wsText, const std::vector<NSCSS::CNode>& arSelectors) override;
void WriteEmptyParagraph(bool bVahish = false, bool bInP = false) override;
void WriteSpace();
void WriteEmptyBookmark(const std::wstring& wsId);
std::wstring AddLiteBookmark();
std::wstring WriteBookmark(const std::wstring& wsId);
std::wstring AddAnchor(const std::wstring& wsAnchorValue);
void WriteImage(const TImageData& oImageData, const std::wstring& wsId);
void WriteAlternativeImage(const std::wstring& wsAlt, const std::wstring& wsSrc, const TImageData& oImageData);
void WriteEmptyImage(int nWidth, int nHeight, const std::wstring& wsName = L"", const std::wstring& wsDescr = L"");
void WriteImageRels(const std::wstring& wsImageId, const std::wstring& wsImageName);
std::wstring GetStyle(const NSCSS::CCompiledStyle& oStyle, bool bParagraphStyle);
void UpdatePageStyle(const std::vector<NSCSS::CNode>& arSelectors);
void SetBaseFont(const std::wstring& wsFontStyles);
void SetDivId(const std::wstring& wsDivId);
void RollBackDivId();
void IncreaseListId();
int GetListId() const;
std::wstring FindFootnote(const std::wstring& wsId);
void OpenFootnote(const std::wstring& wsFootnoteID);
void CloseFootnote();
XmlString& GetStylesXml();
XmlString& GetDocRelsXml();
XmlString& GetNotesRelsXml();
XmlString& GetDocumentXml();
XmlString& GetNotesXml();
XmlString& GetNumberingXml();
XmlString& GetWebSettingsXml();
XmlString* GetCurrentDocument() const override;
const NSCSS::NSProperties::CPage* GetPageData() const;
NSFonts::IApplicationFonts* GetFonts();
std::wstring GetMediaDir() const;
std::wstring GetTempDir() const;
std::wstring GetSrcPath() const;
std::wstring GetBasePath() const;
std::wstring GetCorePath() const;
};
}
#endif // OOXMLWRITER_H

View File

@ -5,9 +5,11 @@
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include "../Common/3dParty/html/htmltoxhtml.h"
#include "htmlfile2.h"
#ifdef USE_OLD_HTML_CONVERTER
#include "../Common/3dParty/html/htmltoxhtml.h".
#include "../Common/3dParty/html/css/src/CCssCalculator.h"
#include "../Common/3dParty/html/css/src/xhtml/CDocumentStyle.h"
#include "../Common/Network/FileTransporter/include/FileTransporter.h"
@ -23,7 +25,6 @@
#include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/graphics/pro/Graphics.h"
#include "htmlfile2.h"
#include "src/Languages.h"
#include <boost/regex.hpp>
@ -267,7 +268,7 @@ struct CTextSettings
bool bPre; // Сохранение форматирования (Сохранение пробелов, табуляций, переносов строк)
bool bQ; // Цитата
bool bAddSpaces; // Добавлять пробелы перед текстом?
bool bMergeText; // Объединять подяр идущий текст в 1?
bool bMergeText; // Объединять подряд идущий текст в 1?
int nLi; // Уровень списка
bool bNumberingLi; // Является ли список нумерованным
@ -2488,16 +2489,6 @@ private:
sSelectors.push_back(NSCSS::CNode(L"html", L"", L""));
GetSubClass(&m_oDocXml, sSelectors);
/*
std::wstring sCrossId = std::to_wstring(m_nCrossId++);
m_oDocXml.WriteString(L"<w:bookmarkStart w:id=\"");
m_oDocXml.WriteString(sCrossId);
m_oDocXml.WriteString(L"\" w:name=\"");
m_oDocXml.WriteString(sFileName);
m_oDocXml.WriteString(L"\"/><w:bookmarkEnd w:id=\"");
m_oDocXml.WriteString(sCrossId);
m_oDocXml.WriteString(L"\"/>");
*/
if (!sSelectors.back().m_mAttributes.empty())
{
@ -2573,7 +2564,7 @@ private:
NSStringUtils::CStringBuilder oPPr;
const std::wstring sPStyle = wrP(&oPPr, arSelectors, oTS);
wrP(&oPPr, arSelectors, oTS);
WriteToStringBuilder(oPPr, *pXml);
@ -2590,9 +2581,6 @@ private:
sRStyle = wrRPr(&oRPr, arSelectors, oTS);
WriteToStringBuilder(oRPr, *pXml);
if (oTS.bQ)
pXml->WriteString(L"<w:t xml:space=\"preserve\">&quot;</w:t>");
}
if (oTS.bQ)
@ -2608,10 +2596,7 @@ private:
while (std::wstring::npos != unBegin)
{
if (OpenR(pXml))
{
pXml->WriteString(L"<w:test/>");
WriteToStringBuilder(oRPr, *pXml);
}
OpenT(pXml);
if (unEnd == std::wstring::npos)
@ -2684,11 +2669,13 @@ private:
wrP(pXml, arSelectors, oTS);
const std::wstring wsName{L"Bookmark" + std::to_wstring(m_mBookmarks.size() + 1)};
m_mBookmarks.insert(std::make_pair(wsName, m_mBookmarks.size() + 1));
pXml->WriteString(L"<w:r><w:fldChar w:fldCharType=\"begin\"/></w:r><w:r><w:instrText>HYPERLINK \\l \"" + wsName + L"\" \\o \"");
pXml->WriteString(L"<w:r><w:fldChar w:fldCharType=\"begin\"/></w:r><w:r><w:instrText>HYPERLINK \\l \"" + wsName + L"\" \\o \"");
pXml->WriteEncodeXmlString(wsNote);
pXml->WriteString(L"\"</w:instrText></w:r>");
pXml->WriteString(L"<w:r><w:fldChar w:fldCharType=\"separate\"/></w:r>");
const bool bResult = readStream(pXml, arSelectors, oTS);
pXml->WriteString(L"<w:r><w:fldChar w:fldCharType=\"end\"/></w:r>");
wsNote.clear();
@ -2701,7 +2688,7 @@ private:
return false;
CTextSettings oTSR(oTS);
oTSR.oAdditionalStyle.m_oFont.SetWeight(L"bold", UINT_MAX, true);
// oTSR.oAdditionalStyle.m_oFont.SetWeight(L"bold", UINT_MAX, true);
return readStream(pXml, arSelectors, oTSR);
}
@ -3843,7 +3830,7 @@ private:
CTextSettings oNewSettings{oTS};
const std::wstring wsHighlight{sSelectors.back().m_pCompiledStyle->m_oBackground.GetColor()
.EquateToColor({{{0, 0, 0}, L"black"}, {{0, 0, 255}, L"blue"}, {{0, 255, 255}, L"cyan"},
.EquateToColor({{{0, 0, 0}, L"black"}, {{0, 0, 255}, L"blue"}, {{0, 255, 255}, L"cyan"},
{{0, 255, 0}, L"green"}, {{255, 0, 255}, L"magenta"}, {{255, 0, 0}, L"red"},
{{255, 255, 0}, L"yellow"}, {{255, 255, 255}, L"white"}, {{0, 0, 139}, L"darkBlue"},
{{0, 139, 139}, L"darkCyan"}, {{0, 100, 0}, L"darkGreen"}, {{139, 0, 139}, L"darkMagenta"},
@ -4094,71 +4081,7 @@ private:
if(m_oLightReader.IsEmptyNode())
return false;
CloseP(oXml, arSelectors);
CTextSettings oTSLi(oTS);
++oTSLi.nLi;
//Нумерованный список
if (L"ol" == arSelectors.back().m_wsName)
{
int nStart = 1;
while(m_oLightReader.MoveToNextAttribute())
if(m_oLightReader.GetName() == L"start")
nStart = NSStringFinder::ToInt(m_oLightReader.GetText(), 1);
m_oLightReader.MoveToElement();
oTSLi.bNumberingLi = true;
const std::wstring wsStart(std::to_wstring(nStart));
m_oNumberXml.WriteString(L"<w:abstractNum w:abstractNumId=\"");
m_oNumberXml.WriteString(std::to_wstring(m_nNumberingId++));
m_oNumberXml.WriteString(L"\"><w:multiLevelType w:val=\"hybridMultilevel\"/><w:lvl w:ilvl=\"0\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%1.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"709\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"1\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%2.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"1429\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"2\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%3.\"/><w:lvlJc w:val=\"right\"/><w:pPr><w:ind w:left=\"2149\" w:hanging=\"180\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"3\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%4.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"2869\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"4\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%5.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"3589\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"5\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%6.\"/><w:lvlJc w:val=\"right\"/><w:pPr><w:ind w:left=\"4309\" w:hanging=\"180\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"6\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%7.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"5029\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"7\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%8.\"/><w:lvlJc w:val=\"left\"/><w:pPr><w:ind w:left=\"5749\" w:hanging=\"360\"/></w:pPr></w:lvl><w:lvl w:ilvl=\"8\"><w:start w:val=\"");
m_oNumberXml.WriteString(wsStart);
m_oNumberXml.WriteString(L"\"/><w:numFmt w:val=\"decimal\"/><w:isLgl w:val=\"false\"/><w:suff w:val=\"tab\"/><w:lvlText w:val=\"%9.\"/><w:lvlJc w:val=\"right\"/><w:pPr><w:ind w:left=\"6469\" w:hanging=\"180\"/></w:pPr></w:lvl></w:abstractNum>");
}
else
oTSLi.bNumberingLi = false;
CTextSettings oTSList{oTSLi};
oTSList.oAdditionalStyle.m_oMargin.SetTop (100, NSCSS::UnitMeasure::Twips, 0, true);
oTSList.oAdditionalStyle.m_oMargin.SetBottom(100, NSCSS::UnitMeasure::Twips, 0, true);
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode2(nDeath))
{
const std::wstring wsName = m_oLightReader.GetName();
if (L"li" == wsName)
ReadListElement(oXml, arSelectors, oTSList);
else
{
CloseP(oXml, arSelectors);
readInside(oXml, arSelectors, oTSLi, wsName);
}
}
CloseP(oXml, arSelectors);
return true;
}
bool readLi (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, CTextSettings& oTS, bool bType)
@ -5081,17 +5004,29 @@ private:
return true;
}
};
#else
#include "HTMLReader.h"
#endif
CHtmlFile2::CHtmlFile2()
{
#ifdef USE_OLD_HTML_CONVERTER
m_internal = new CHtmlFile2_Private();
#else
m_pReader = new HTML::CHTMLReader();
#endif
}
CHtmlFile2::~CHtmlFile2()
{
#ifdef USE_OLD_HTML_CONVERTER
RELEASEOBJECT(m_internal);
#else
RELEASEOBJECT(m_pReader);
#endif
}
#ifdef USE_OLD_HTML_CONVERTER
bool CHtmlFile2::IsHtmlFile(const std::wstring& sFile)
{
// Конвертируем в xhtml
@ -5109,47 +5044,77 @@ bool CHtmlFile2::IsMhtFile(const std::wstring& sFile)
// Читаем html
return m_internal->isHtml();
}
#endif
void CHtmlFile2::SetTmpDirectory(const std::wstring& sFolder)
void CHtmlFile2::SetTempDirectory(const std::wstring& wsFolder)
{
m_internal->m_sTmp = NSSystemPath::NormalizePath(sFolder);
#ifdef USE_OLD_HTML_CONVERTER
m_internal->m_sTmp = NSSystemPath::NormalizePath(wsFolder);
#else
m_pReader->SetTempDirectory(wsFolder);
#endif
}
void CHtmlFile2::SetCoreDirectory(const std::wstring& wsFolder)
{
#ifdef USE_OLD_HTML_CONVERTER
m_internal->m_sCore = NSSystemPath::NormalizePath(wsFolder);
#else
m_pReader->SetCoreDirectory(wsFolder);
#endif
}
HRESULT CHtmlFile2::OpenHtml(const std::wstring& sSrc, const std::wstring& sDst, CHtmlParams* oParams)
HRESULT CHtmlFile2::ConvertHTML2OOXML(const std::wstring& wsPath, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs)
{
#ifndef USE_OLD_HTML_CONVERTER
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertHTML2OOXML(wsPath, wsDirectory, pParametrs);
#else
if(!m_internal->m_oLightReader.IsValid())
if(!IsHtmlFile(sSrc))
return S_FALSE;
m_internal->m_sSrc = NSSystemPath::GetDirectoryName(sSrc);
m_internal->m_sDst = sDst;
m_internal->CreateDocxEmpty(oParams);
m_internal->CreateDocxEmpty(pParametrs);
m_internal->readStyle();
// Переходим в начало
if(!m_internal->m_oLightReader.MoveToStart())
return S_FALSE;
if(oParams && oParams->m_bNeedPageBreakBefore)
if(pParametrs && pParametrs->m_bNeedPageBreakBefore)
m_internal->PageBreakBefore();
m_internal->readSrc();
m_internal->write();
return S_OK;
#endif
}
HRESULT CHtmlFile2::OpenMht(const std::wstring& sSrc, const std::wstring& sDst, CHtmlParams* oParams)
HRESULT CHtmlFile2::ConvertHTML2Markdown(const std::wstring& wsPath, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
return S_FALSE;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertHTML2Markdown(wsPath, wsFinalFile, pParametrs);
#endif
}
HRESULT CHtmlFile2::ConvertMHT2OOXML(const std::wstring& wsPath, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
if(!m_internal->m_oLightReader.IsValid())
if(!IsMhtFile(sSrc))
if(!IsMhtFile(wsPath))
return S_FALSE;
m_internal->m_sSrc = NSSystemPath::GetDirectoryName(sSrc);
m_internal->m_sDst = sDst;
m_internal->m_sSrc = NSSystemPath::GetDirectoryName(wsPath);
m_internal->m_sDst = sDirectory;
m_internal->CreateDocxEmpty(oParams);
m_internal->readStyle();
@ -5162,19 +5127,38 @@ HRESULT CHtmlFile2::OpenMht(const std::wstring& sSrc, const std::wstring& sDst,
m_internal->readSrc();
m_internal->write();
return S_OK;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertMHT2OOXML(wsPath, wsDirectory, pParametrs);
#endif
}
HRESULT CHtmlFile2::OpenBatchHtml(const std::vector<std::wstring>& sSrc, const std::wstring& sDst, CHtmlParams* oParams)
HRESULT CHtmlFile2::ConvertMHT2Markdown(const std::wstring& wsPath, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs)
{
m_internal->m_sDst = sDst;
#ifdef USE_OLD_HTML_CONVERTER
return S_FALSE;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertMHT2Markdown(wsPath, wsFinalFile, pParametrs);
#endif
}
HRESULT CHtmlFile2::ConvertHTML2OOXML(const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
m_internal->m_sDst = wsDirectory;
m_internal->CreateDocxEmpty(oParams);
bool bFirst = true;
for(const std::wstring& sS : sSrc)
for(const std::wstring& sS : arPaths)
{
#ifdef _DEBUG
#ifdef _DEBUG
std::wcout << NSFile::GetFileName(sS) << std::endl;
#endif
#endif
m_internal->m_sSrc = NSSystemPath::GetDirectoryName(sS);
if(!IsHtmlFile(sS))
@ -5202,8 +5186,51 @@ HRESULT CHtmlFile2::OpenBatchHtml(const std::vector<std::wstring>& sSrc, const s
m_internal->write();
return S_OK;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertHTML2OOXML(arPaths, wsDirectory, pParametrs);
#endif
}
HRESULT CHtmlFile2::ConvertHTML2Markdown(const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
return S_FALSE;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertHTML2Markdown(arPaths, wsFinalFile, pParametrs);
#endif
}
HRESULT CHtmlFile2::ConvertMHT2OOXML(const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
return S_FALSE;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertMHT2OOXML(arPaths, wsDirectory, pParametrs);
#endif
}
HRESULT CHtmlFile2::ConvertMHT2Markdown(const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs)
{
#ifdef USE_OLD_HTML_CONVERTER
return S_FALSE;
#else
if (nullptr == m_pReader)
return S_FALSE;
return m_pReader->ConvertMHT2Markdown(arPaths, wsFinalFile, pParametrs);
#endif
}
#ifdef USE_OLD_HTML_CONVERTER
std::wstring CTableRow::ConvertToOOXML(const CTable& oTable, int nInstruction)
{
if (m_arCells.empty())
@ -5359,3 +5386,4 @@ std::wstring CTableCell::ConvertToOOXML(const CTable& oTable, UINT unColumnNumbe
return oCell.GetData();
}
#endif

View File

@ -5,6 +5,9 @@
#include <vector>
#include "../DesktopEditor/common/Types.h"
#include "HTMLParameters.h"
#include "MarkdownParameters.h"
#ifndef HTMLFILE2_USE_DYNAMIC_LIBRARY
#define HTMLFILE2_DECL_EXPORT
#else
@ -12,82 +15,43 @@
#define HTMLFILE2_DECL_EXPORT Q_DECL_EXPORT
#endif
struct CHtmlParams
{
std::wstring m_sGenres; // Жанры
std::wstring m_sAuthors; // Авторы
std::wstring m_sBookTitle; // Название
std::wstring m_sDate; // Дата
std::wstring m_sDescription; // описание
std::wstring m_sLanguage; // Язык
bool m_bNeedPageBreakBefore; // Новый html с новой страницы
std::wstring m_sdocDefaults; // Стиль docDefaults
std::wstring m_sNormal; // Стиль normal
CHtmlParams() : m_bNeedPageBreakBefore(false) {}
void SetNormal(const std::wstring& sStyle)
{
m_sNormal = sStyle;
}
void SetDocDefaults(const std::wstring& sStyle)
{
m_sdocDefaults = sStyle;
}
void SetPageBreakBefore(bool bNeed)
{
m_bNeedPageBreakBefore = bNeed;
}
void SetDate(const std::wstring& sDate)
{
m_sDate = sDate;
}
void SetDescription(const std::wstring& sDescription)
{
m_sDescription = sDescription;
}
void SetGenres(const std::wstring& sGenres)
{
m_sGenres = sGenres;
}
void SetAuthors(const std::wstring& sAuthors)
{
m_sAuthors = sAuthors;
}
void SetTitle(const std::wstring& sTitle)
{
m_sBookTitle = sTitle;
}
void SetLanguage(const std::wstring& sLanguage)
{
m_sLanguage = sLanguage;
}
};
#ifdef USE_OLD_HTML_CONVERTER
class CHtmlFile2_Private;
#else
namespace HTML { class CHTMLReader; }
#endif
class HTMLFILE2_DECL_EXPORT CHtmlFile2
{
private:
#ifdef USE_OLD_HTML_CONVERTER
CHtmlFile2_Private* m_internal;
#else
HTML::CHTMLReader* m_pReader;
#endif
public:
CHtmlFile2();
~CHtmlFile2();
bool IsHtmlFile(const std::wstring& sFile);
bool IsMhtFile (const std::wstring& sFile);
void SetTmpDirectory(const std::wstring& sFolder);
#ifdef USE_OLD_HTML_CONVERTER
bool IsHtmlFile(const std::wstring& wsFile);
bool IsMhtFile (const std::wstring& wsFile);
#endif
void SetTempDirectory(const std::wstring& wsFolder);
void SetCoreDirectory(const std::wstring& wsFolder);
HRESULT OpenHtml(const std::wstring& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL);
HRESULT OpenMht (const std::wstring& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL);
HRESULT OpenBatchHtml(const std::vector<std::wstring>& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL);
HRESULT ConvertHTML2OOXML (const std::wstring& wsPath, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs = nullptr);
HRESULT ConvertHTML2Markdown(const std::wstring& wsPath, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs = nullptr);
HRESULT ConvertMHT2OOXML (const std::wstring& wsPath, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs = nullptr);
HRESULT ConvertMHT2Markdown (const std::wstring& wsPath, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs = nullptr);
HRESULT ConvertHTML2OOXML (const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs = nullptr);
HRESULT ConvertHTML2Markdown(const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs = nullptr);
HRESULT ConvertMHT2OOXML (const std::vector<std::wstring>& arPaths, const std::wstring& wsDirectory, HTML::THTMLParameters* pParametrs = nullptr);
HRESULT ConvertMHT2Markdown (const std::vector<std::wstring>& arPaths, const std::wstring& wsFinalFile, HTML::TMarkdownParameters* pParametrs = nullptr);
};
#endif // _HTMLFILE2_HTMLFILE2_H

View File

@ -60,23 +60,23 @@ namespace NSStringFinder
return sValue;
}
std::string FindProperty(const std::string& sString, const std::string& sProperty, const std::string& sDelimiter, const std::string& sEnding, const size_t& unStarting, size_t& unEndPosition)
inline std::string FindProperty(const std::string& sString, const std::string& sProperty, const std::string& sDelimiter, const std::string& sEnding, const size_t& unStarting, size_t& unEndPosition)
{
return FindPropertyTemplate<char>(sString, sProperty, sDelimiter, sEnding, unStarting, unEndPosition);
}
std::wstring FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::wstring& wsDelimiter, const std::wstring& wsEnding, const size_t& unStarting, size_t& unEndPosition)
inline std::wstring FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::wstring& wsDelimiter, const std::wstring& wsEnding, const size_t& unStarting, size_t& unEndPosition)
{
return FindPropertyTemplate<wchar_t>(wsString, wsProperty, wsDelimiter, wsEnding, unStarting, unEndPosition);
}
std::string FindProperty(const std::string& sString, const std::string& sProperty, const std::string& sDelimiter, const std::string& sEnding, const size_t& unStarting = 0)
inline std::string FindProperty(const std::string& sString, const std::string& sProperty, const std::string& sDelimiter, const std::string& sEnding, const size_t& unStarting = 0)
{
size_t unEndPosition = 0;
return FindPropertyTemplate<char>(sString, sProperty, sDelimiter, sEnding, unStarting, unEndPosition);
}
std::wstring FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::wstring& wsDelimiter, const std::wstring& wsEnding, const size_t& unStarting = 0)
inline std::wstring FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::wstring& wsDelimiter, const std::wstring& wsEnding, const size_t& unStarting = 0)
{
size_t unEndPosition = 0;
return FindPropertyTemplate<wchar_t>(wsString, wsProperty, wsDelimiter, wsEnding, unStarting, unEndPosition);
@ -130,12 +130,12 @@ namespace NSStringFinder
return oData;
}
TFoundedData<char> FindProperty(const std::string& sString, const std::string& sProperty, const std::vector<std::string>& arDelimiters, const std::vector<std::string>& arEndings, const size_t& unStarting = 0)
inline TFoundedData<char> FindProperty(const std::string& sString, const std::string& sProperty, const std::vector<std::string>& arDelimiters, const std::vector<std::string>& arEndings, const size_t& unStarting = 0)
{
return FindPropertyTemplate<char>(sString, sProperty, arDelimiters, arEndings, unStarting);
}
TFoundedData<wchar_t> FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector<std::wstring>& arDelimiters, const std::vector<std::wstring>& arEndings, const size_t& unStarting = 0)
inline TFoundedData<wchar_t> FindProperty(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector<std::wstring>& arDelimiters, const std::vector<std::wstring>& arEndings, const size_t& unStarting = 0)
{
return FindPropertyTemplate<wchar_t>(wsString, wsProperty, arDelimiters, arEndings, unStarting);
}
@ -154,12 +154,12 @@ namespace NSStringFinder
return true;
}
bool RemoveEmptyTag(std::string& sValue, const std::string& sTagName, size_t unStart = 0)
inline bool RemoveEmptyTag(std::string& sValue, const std::string& sTagName, size_t unStart = 0)
{
return RemoveEmptyTagTemplate<char>(sValue, sTagName, unStart);
}
bool RemoveEmptyTag(std::wstring& sValue, const std::wstring& sTagName, size_t unStart = 0)
inline bool RemoveEmptyTag(std::wstring& sValue, const std::wstring& sTagName, size_t unStart = 0)
{
return RemoveEmptyTagTemplate<wchar_t>(sValue, sTagName, unStart);
}
@ -223,7 +223,7 @@ namespace NSStringFinder
return !boost::algorithm::ifind_first(sString, sValue).empty();
}
int ToInt(const std::wstring& oValue, int nMinValue = 0)
inline int ToInt(const std::wstring& oValue, int nMinValue = 0)
{
boost::wregex oRegex(LR"((-?\.\d+|-?\d+(\.\d+)?))");
@ -237,7 +237,7 @@ namespace NSStringFinder
return std::max(nMinValue, nValue);
}
int ToDouble(const std::wstring& oValue, double dMinValue = 0.)
inline int ToDouble(const std::wstring& oValue, double dMinValue = 0.)
{
boost::wregex oRegex(LR"((-?\.\d+|-?\d+(\.\d+)?))");

View File

@ -6,6 +6,13 @@
#include "../../DesktopEditor/common/Directory.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "../../Common/3dParty/md/md2html.h"
#include <iostream>
#include <map>
#include <memory>
#include <string>
void getDirectories(const std::wstring& sDirectory, std::vector<std::wstring>& arrDirectory)
{
arrDirectory.push_back(sDirectory);
@ -15,6 +22,15 @@ void getDirectories(const std::wstring& sDirectory, std::vector<std::wstring>& a
int main()
{
// if (Md::ConvertMdFileToHtml(L"C:\\ONLYOFFICE\\Files\\md\\Bugs\\74626\\file-1.md",
// L"C:\\ONLYOFFICE\\Files\\md\\Bugs\\74626\\file-1.html"))
// std::wcout << L"Good" << std::endl;
// else
// std::wcout << L"Bad" << std::endl;
// return 0;
bool bBatchMode = false;
bool bMhtMode = false;
if(bBatchMode)
@ -97,7 +113,7 @@ int main()
oParams.SetDescription(L"Description");
// Файл, который открываем
std::wstring sFile = NSFile::GetProcessDirectory() + L"/test.html";
std::wstring sFile = L"C:\\ONLYOFFICE\\Files\\html\\test_tag_a_1.html";
CHtmlFile2 oFile;
oFile.SetTmpDirectory(sOutputDirectory);
nResConvert = (bMhtMode ? oFile.OpenMht(sFile, sOutputDirectory, &oParams) : oFile.OpenHtml(sFile, sOutputDirectory, &oParams));

View File

@ -1261,12 +1261,10 @@ void CConverter2OOXML::WriteEqEditShape(const CCtrlEqEdit* pEqEditShape, short s
OpenParagraph(shParaShapeID, shParaStyleID, oBuilder, oState);
oBuilder.WriteString(L"<w:r><w:t xml:space=\"preserve\">");
oBuilder.WriteString(L"<w:r/>");
StarMath::CStarMathConverter oConverterStarMath;
oBuilder.WriteString(oConverterStarMath.ConvertEQNToOOXml(pEqEditShape->GetEqn()));
oBuilder.WriteString(L"</w:t></w:r>");
}
void CConverter2OOXML::WriteOleShape(const CCtrlShapeOle* pOleShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState)

View File

@ -113,10 +113,46 @@ namespace DocFileFormat
{
//Todo сделать определение симольного шрифта через fontManager
//Заглушка под Google Docs, они пишут bullet в Arial
if (-1 != m_sAsciiFont.find (L"Arial") && -1 != m_sEastAsiaFont.find (L"Arial") && -1 != m_shAnsiFont.find (L"Arial"))
return false;
const std::wstring* fonts[] = {&m_sAsciiFont, &m_sEastAsiaFont, &m_shAnsiFont};
for (const auto& pFont : fonts)
{
if (!pFont->empty())
{
std::wstring fontLower = *pFont;
return true;
for (size_t i = 0; i < fontLower.length(); ++i)
fontLower[i] = towlower(fontLower[i]);
if (fontLower == L"symbol" ||
fontLower.find(L"wingdings") != std::wstring::npos ||
fontLower == L"webdings" ||
fontLower == L"marlett" ||
fontLower == L"mt extra" ||
fontLower.find(L"dingbats") != std::wstring::npos ||
fontLower.find(L"zapf") != std::wstring::npos)
{
return true;
}
if (fontLower.find(L"times") != std::wstring::npos ||
fontLower.find(L"arial") != std::wstring::npos ||
fontLower.find(L"courier") != std::wstring::npos ||
fontLower.find(L"calibri") != std::wstring::npos ||
fontLower.find(L"cambria") != std::wstring::npos ||
fontLower.find(L"georgia") != std::wstring::npos ||
fontLower.find(L"verdana") != std::wstring::npos ||
fontLower.find(L"tahoma") != std::wstring::npos ||
fontLower.find(L"helvetica") != std::wstring::npos ||
fontLower.find(L"segoe") != std::wstring::npos)
{
return false;
}
}
}
return true;
}
/*========================================================================================================*/

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