Compare commits

...

268 Commits

Author SHA1 Message Date
8550bdeed6 Generate all projects if ommited 2024-10-24 18:05:56 +04:00
5aae57aad8 Log generated project files 2024-10-24 17:43:04 +04:00
1d4f825ea6 Add note to change builder directory for cpp & cs 2024-10-23 13:53:30 +04:00
0527472fef Use space indentation for consistency 2024-10-22 22:00:45 +04:00
c911733bd7 Fix crash on mac 2024-10-22 21:51:21 +04:00
46f254c85d Fix incorrect convertation to string 2024-10-22 20:43:03 +04:00
a6a7d919e6 Add README.md 2024-10-21 16:47:52 +04:00
755d6cd970 Add some Java samples 2024-10-21 15:04:22 +04:00
604dc14d23 Add some python samples 2024-10-18 18:00:54 +04:00
2263d7bf80 Fix Makefile for mac 2024-10-18 14:04:30 +04:00
ef415aad3f Fixes for mac 2024-10-17 18:55:42 +04:00
6744c172f4 Remove C++ compile warnings 2024-10-17 17:43:53 +04:00
6ea3a9551e Add generation of Makefile 2024-10-17 17:35:51 +04:00
f48ab0351c Update help message with C# projects 2024-10-17 15:28:29 +04:00
632ddf9805 Remove asterisks due to portability 2024-10-17 15:22:27 +04:00
2c61e84e94 Fix unresolved symbols on linux 2024-10-17 14:38:21 +04:00
375b37e9aa Add include paths for utils 2024-10-16 19:07:29 +04:00
bb3e2e3bc2 Fix issue with relative paths to resources 2024-10-16 18:20:04 +04:00
1a5b8b4bbd Add generation of Qt C++ projects 2024-10-16 18:17:40 +04:00
901c44b486 Add generation of VS .NET projects 2024-10-15 19:00:29 +04:00
88eadd9955 Add remaining C++ samples 2024-10-15 16:04:23 +04:00
b5f88cebaf Fix C++ projects for old VS versions
+ Add spreadsheet test
2024-10-15 14:52:14 +04:00
e0e7e31568 Add generation of VS C++ projects 2024-10-14 20:18:57 +04:00
00344df9ad Fix for -D with brackets 2024-10-09 11:27:54 +03:00
cfb060e142 Fix build 2024-10-09 11:05:28 +03:00
0565e6164b Add data for hard update hunspell module 2024-10-09 10:47:24 +03:00
306cc3f985 For bug 70578 2024-10-08 23:31:46 +03:00
2739dd3abd Fix bug 69154 2024-10-08 22:54:19 +03:00
70e6df5aae fix bug #70440 2024-10-08 22:00:45 +03:00
96030aa322 Set timelimits of dictionaries tester bigger 2024-10-08 15:18:40 +03:00
fee801eeeb Merge pull request 'Add custom timelimits logic in dictionariestester' (#59) from fix/dictionariestester into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/59
2024-10-08 11:55:37 +00:00
750273b526 Change timelimits 2024-10-08 14:51:48 +03:00
cfdb541c28 Add custom timelimits logic in dictionariestester 2024-10-08 14:36:30 +03:00
11121961d9 Fix typo 2024-10-08 08:47:12 +00:00
45828709ee Merge pull request 'Fix bug #70515' (#57) from fix/bug70515 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/57
2024-10-08 08:15:23 +00:00
40916e5ccc Merge pull request 'Fix bug 60796' (#56) from fix/bug60796 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/56
2024-10-08 08:07:18 +00:00
319610c58d Fix bug 60796 2024-10-08 10:22:32 +03:00
1837a2737e Fix RefTo id 2024-10-07 15:17:03 +00:00
686fc60860 For bug 61203 2024-10-07 15:17:03 +00:00
51216f27f4 Fix bug 70466 2024-10-07 17:47:12 +03:00
2eb33ddd22 Merge pull request 'Fix bug #70484' (#30) from fix/bug70484 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/30
2024-10-07 14:05:10 +00:00
58c80b052b Merge pull request 'Fix bug #70492' (#34) from fix/bug70492 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/34
2024-10-07 14:04:42 +00:00
5eee408eeb Merge pull request 'Fix bug #70617' (#54) from fix/bug70617 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/54
2024-10-07 14:04:20 +00:00
b6ae1f272c Fix bug #70617 2024-10-07 15:41:28 +05:00
045f23d921 Fix bug 68091 2024-10-07 02:46:38 +03:00
d06b52988c Fix bug 70352 2024-10-06 18:56:06 +00:00
4717b47388 Fix bug in metafile conversion 2024-10-06 17:11:32 +00:00
31ce9f6a18 Fix bug #66337 2024-10-06 17:11:32 +00:00
e44c9fa4c9 Fix bug #31062 2024-10-06 17:11:32 +00:00
3c59ba7a13 fixed a bug with the location of the embedded metafile 2024-10-06 17:11:32 +00:00
42e84249e8 For bug #68708 2024-10-06 17:11:32 +00:00
e2dbde8722 fix bug #70163 2024-10-06 11:43:33 +03:00
36c67d79d5 fix bug #70717 2024-10-06 11:17:16 +03:00
cdc14d22f0 fix bug #70684 2024-10-04 22:22:16 +03:00
baed05236b fix bug #70368 2024-10-04 20:41:18 +03:00
c644f94c0b fix bug #69104 2024-10-04 20:23:36 +03:00
087e4433f2 For bug 69977 2024-10-04 13:31:36 +00:00
bc11a5cf5f Fix bug 70574 2024-10-04 16:28:30 +03:00
d86303e290 Fix bug 69704 2024-10-03 15:44:14 +00:00
51f1faa51a Fix uncheckedsqrfx conversion to xlsx
(cherry picked from commit 9f62108376)
2024-10-03 18:12:10 +03:00
6775dccc2c Fix font tables 2024-10-03 13:29:46 +00:00
ee3b4c612d Merge pull request 'Fix bug 70563' (#45) from fix/bug-70563 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/45
2024-10-03 12:37:44 +00:00
1144bb166c Remove using bitcode on ios 2024-10-03 14:19:08 +03:00
a9752208f6 Fix bug #70515 2024-10-03 15:43:45 +05:00
84016cf8cf Fix bug 70563 2024-10-03 13:00:18 +03:00
cb7edc373c Disable bitcode for ios builds with xcode 16+ 2024-10-03 12:11:31 +03:00
d1e43d68dc Fix getOriginPage 2024-10-03 11:47:04 +03:00
b5ab5f9b2b Fix bug 70559 2024-10-03 11:31:39 +03:00
761c5bec53 Fix detect allfonts path for builder 2024-10-03 00:11:28 +03:00
8cc7034c22 For bug 70566 2024-10-02 15:48:33 +00:00
ee1c385b54 Fix Bug 70566 2024-10-02 15:48:33 +00:00
ded640825b Fix alpha 2024-10-02 15:48:33 +00:00
84301531c8 . 2024-10-02 17:54:59 +03:00
310cd6d8fd Add full GetContext function 2024-10-02 13:51:43 +00:00
2d37cf634a Add new dependent libraries 2024-10-02 13:51:43 +00:00
04880b4e1d Merge pull request 'Fix bug 70590' (#41) from fix/bug-70590 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/41
2024-10-02 13:38:15 +00:00
1000b5d5bd Merge pull request 'Add full GetContext function to docbuilder python wrapper' (#40) from feature/docbuilder-wrappers-getcontext into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/40
2024-10-02 12:56:45 +00:00
c324b4a11c Add to python wrapper 2024-10-02 16:02:23 +04:00
a51fe4134c fix bug #68406 2024-10-01 19:37:56 +03:00
985d258bc1 Fix bug with rotated crop 2024-10-01 17:22:30 +03:00
fee5c112b4 Merge pull request 'fix bug70534' (#37) from fix/bug70534 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/37
2024-10-01 12:23:24 +00:00
9b50f9fbc2 Fix bug 68091 2024-10-01 14:43:27 +03:00
10f770fdbc Fix bug 70566 2024-10-01 13:10:52 +03:00
eb53c40135 fix 2024-10-01 12:32:29 +03:00
ded1655a04 Fix bug 70561 2024-10-01 12:20:54 +03:00
20c11889aa Fix bug 70590 2024-10-01 11:49:33 +03:00
910c2418d6 fix chartEx 2024-10-01 08:33:39 +03:00
e6ffdc0ae8 Merge remote-tracking branch 'origin/for-bug#68406' into release/v8.2.0 2024-09-30 19:27:52 +03:00
0335d330b8 Merge pull request 'Fix bug 69602' (#33) from fix/pdf-bugs into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/33
2024-09-30 14:55:14 +00:00
af2e86e777 Fix name OUserID 2024-09-30 17:16:30 +03:00
bcf7d08c51 Fix bug 69602 2024-09-30 16:26:03 +03:00
11886dcdf7 Add user-id for annots 2024-09-30 15:05:39 +03:00
615d0b682c formula size calculation 2024-09-30 12:50:46 +03:00
535028fa0e For bug 70559 2024-09-30 12:44:09 +03:00
5a6386e08b Fix bug #70492 2024-09-27 20:07:14 +05:00
7ca8b22160 fix bug #70518 2024-09-27 16:59:57 +03:00
ec16e247e9 Fix build 2024-09-27 13:39:27 +00:00
9a76575082 Fix bug 2024-09-27 13:39:27 +00:00
c1a586cb56 Fix bug 69974 2024-09-27 16:14:24 +03:00
7707aeb914 Fix NULL borderStyle in FreeText 2024-09-27 15:56:16 +03:00
50a8540f75 Fix build 2024-09-27 15:45:06 +03:00
cc2e755bca Fix bug 2024-09-26 15:18:30 +00:00
9c1efdeac2 Fix bug with text 2024-09-26 15:18:30 +00:00
ea1538bc11 Fix bug in xps 2024-09-26 15:18:30 +00:00
c0d0fb6f5c Critical fix 2024-09-26 15:18:30 +00:00
5e5e07b406 Fix bug 67321 2024-09-26 15:18:30 +00:00
9b5f762420 Fix bug #70484 2024-09-26 17:35:25 +05:00
7020548f06 Merge pull request 'Fix bug 69009' (#28) from fix/docx-renderer into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/28
2024-09-26 10:43:03 +00:00
2d2e15671a Fix bug 69009 2024-09-26 13:36:28 +03:00
00ad32d420 Merge pull request 'For bug #70040' (#27) from fix/bug70040 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/27
2024-09-26 08:23:58 +00:00
ba2cf66c31 Fix build 2024-09-26 10:44:12 +03:00
57ed9d0c32 Fix build 2024-09-26 06:15:42 +00:00
40d82f3287 Fix 2024-09-26 06:15:42 +00:00
9bdcbf0d89 Rollback std::vector 2024-09-26 06:15:42 +00:00
c1774219ec Fix pdf editor build 2024-09-26 06:15:42 +00:00
2a6f0bb1b6 Close any clip-path fix 2024-09-26 06:15:42 +00:00
a23ce22950 Add unit-tests 2024-09-26 06:15:42 +00:00
b4f0d32b6d Fix bugs 2024-09-26 06:15:42 +00:00
83db7f2165 Remove STL from export 2024-09-26 06:15:42 +00:00
3ce03d897d Fix bug 2024-09-26 06:15:42 +00:00
be12237042 Fix bug 2024-09-26 06:15:42 +00:00
cf7252b92d Fix bounds 2024-09-26 06:15:42 +00:00
523f3f24f9 Fix wrong bounds 2024-09-26 06:15:42 +00:00
0196a4bb57 Fix one inters 2024-09-26 06:15:42 +00:00
9ee9192cd4 Refactoring 2024-09-26 06:15:42 +00:00
5df63a58b7 Add more bullets 2024-09-26 06:15:42 +00:00
d107bd5df2 Fix unused font names in PDF 2024-09-26 06:15:42 +00:00
f51c1fced2 Fix bug 69109 2024-09-26 06:15:42 +00:00
86cba0bdcd Fix bug 70340 2024-09-26 06:15:42 +00:00
cceec83568 Transition from pointers to smart pointers 2024-09-26 06:15:42 +00:00
f733543b44 Fix memory leak 2024-09-26 06:15:42 +00:00
bb9d777c14 Refactoring 2024-09-26 06:15:42 +00:00
694dd852d0 Fix bug 2024-09-26 06:15:42 +00:00
18a18eaa40 Fix linux build 2024-09-26 06:15:42 +00:00
fb021b33ec Add limits 2024-09-26 06:15:42 +00:00
95ecd8468a Refactoring 2024-09-26 06:15:42 +00:00
fbb57d7009 Fix memory leak 2024-09-26 06:15:42 +00:00
22e9873208 Done gradients support 2024-09-26 06:15:42 +00:00
2581e9235d Develop rtl support 2024-09-26 06:15:42 +00:00
270fd0601f Fix close path 2024-09-26 06:15:42 +00:00
5f69b4f8e6 Fix bug with gradient 2024-09-26 06:15:42 +00:00
bdaf9fa10b Fix bug 2024-09-26 06:15:42 +00:00
77e64af80c Fix bug with gradient 2024-09-26 06:15:42 +00:00
6e3beac6bf Fix one point inters and refactoring 2024-09-26 06:15:42 +00:00
641297ac48 Fix bug with non-closed-paths 2024-09-26 06:15:42 +00:00
dcca1f06f4 Developing gradients 2024-09-26 06:15:42 +00:00
22d7cfb240 Fix bug 2024-09-26 06:15:42 +00:00
fa51ea21b4 Developing gradient support 2024-09-26 06:15:42 +00:00
7632be9f2f Fix stack overflow 2024-09-26 06:15:42 +00:00
cbf40d36f5 Develop gradient support (in porgress) 2024-09-26 06:15:42 +00:00
2b8e70e67f Add compound paths 2024-09-26 06:15:42 +00:00
4b05eb9a50 Indents fix + gitignore 2024-09-26 06:15:42 +00:00
3221e41e89 Add subtraction for all overlap 2024-09-26 06:15:42 +00:00
58cc6cf6e8 Fix epsilon 2024-09-26 06:15:42 +00:00
c86a8edd30 Fix 2024-09-26 06:15:42 +00:00
db1d6a935f Add metainfo in ToXmlPptx (CContText)
+ fix main in test
2024-09-26 06:15:42 +00:00
cb9589f6b4 Fix curve for pdf 2024-09-26 06:15:42 +00:00
cbad285a9f FIx curve conversion 2024-09-26 06:15:42 +00:00
82a3fa6132 Fix 2024-09-26 06:15:42 +00:00
0821eefbd3 Add figure "Cross" to test 2024-09-26 06:15:42 +00:00
38a9dfcd14 Fix subtract 2024-09-26 06:15:42 +00:00
0f222c15e9 Fix all overlap 2024-09-26 06:15:42 +00:00
d0a554c701 Fix overlap paths 2024-09-26 06:15:42 +00:00
acfec0ceb1 Rollback 2024-09-26 06:15:42 +00:00
899b27d697 Fix bug with stride for adobe 2024-09-26 06:15:42 +00:00
5a5db3e8c6 Fix bug with close 2024-09-26 06:15:42 +00:00
57fdf7eed5 Add test for negative vertices 2024-09-26 06:15:42 +00:00
7f13020f2f Fix bug with no clear clip vector 2024-09-26 06:15:42 +00:00
020298b023 Update clip logic
crop
2024-09-26 06:15:42 +00:00
8eb249056b Fix negative vertices 2024-09-26 06:15:42 +00:00
2ed7e803ca Fix 2024-09-26 06:15:42 +00:00
b9230ef5ff Develop clip + tile images 2024-09-26 06:15:42 +00:00
3907110e44 Fix + refactoring 2024-09-26 06:15:42 +00:00
787575a53f Fix including paths 2024-09-26 06:15:42 +00:00
b58554a3da Refactorting
in progress
2024-09-26 06:15:42 +00:00
9e8c0dfb16 Add clip logic
clip on clip is not working for now
2024-09-26 06:15:42 +00:00
6831820dd4 Fix 2024-09-26 06:15:42 +00:00
cac79cb66e Refactor includes + fix build dll 2024-09-26 06:15:42 +00:00
323213a63d Refacoring 2024-09-26 06:15:42 +00:00
473ef17be3 Fix 2024-09-26 06:15:42 +00:00
5e56d26a06 Fix bugs 2024-09-26 06:15:42 +00:00
a390c1ee18 Fix 2024-09-26 06:15:42 +00:00
4158ebcd98 FIx 2024-09-26 06:15:42 +00:00
7fc65a84ab Fix 2024-09-26 06:15:42 +00:00
69ffd656af Fix 2024-09-26 06:15:42 +00:00
cb929fc5c5 Fix 2024-09-26 06:15:42 +00:00
7cd7c9f98f Refactoring Winding 2024-09-26 06:15:42 +00:00
015c10495c Refactoring 2024-09-26 06:15:42 +00:00
e973c8f70b Refactoring test 2024-09-26 06:15:42 +00:00
a77987488b Refactoring 2024-09-26 06:15:42 +00:00
1cfd17e2f3 Fix and Refactoring 2024-09-26 06:15:42 +00:00
b4c6f69cee Add Test for Clip 2024-09-26 06:15:42 +00:00
67194499a8 Fix 2024-09-26 06:15:42 +00:00
9ec6489083 Fix 2024-09-26 06:15:42 +00:00
3971400c78 Fix 2024-09-26 06:15:42 +00:00
e21ed47019 Finish CGraphicsPathClip 2024-09-26 06:15:42 +00:00
2cf83df7d0 add new methods for clip 2024-09-26 06:15:42 +00:00
7f96336e75 add mathematical functions for clip 2024-09-26 06:15:42 +00:00
99da1e3b8c Move CPathForClip methods to CGraphicsPath 2024-09-26 06:15:42 +00:00
6d152880bd Add Clip lib for GraphicsPath 2024-09-26 06:15:42 +00:00
dd9fca2a5c Fix hor/ver shape trough logic 2024-09-26 06:15:42 +00:00
67043cf718 Fix & add logic 2024-09-26 06:15:42 +00:00
ba239f139d Images -> shapes 2024-09-26 06:15:42 +00:00
a99733c5a1 Fix bug 70119 2024-09-25 23:42:03 +03:00
a60bc542c7 Fix bug 70043 2024-09-25 14:36:12 +00:00
97d36fa1cd Fix multiline Text Widget indentation 2024-09-25 14:36:12 +00:00
87fa0f93be Fix bug 69972 2024-09-25 14:36:12 +00:00
29a48da730 Fix bug 69976 2024-09-25 14:36:12 +00:00
e0352541be Fix bug 69990 2024-09-25 16:53:33 +03:00
2e26a3697d For bug #70040 2024-09-25 18:23:21 +05:00
cd124d5112 Fix page sizes on build pdf file 2024-09-25 15:28:08 +03:00
4242d32d95 Fix release build 2024-09-25 12:18:18 +03:00
a6b5e7e010 Merge remote-tracking branch 'origin/release/v8.2.0' into release/v8.2.0 2024-09-24 22:05:25 +03:00
57800ec8dd fix bug #33177 2024-09-24 21:46:58 +03:00
0f3de35eb4 Fix bug 69927 2024-09-24 21:44:52 +03:00
8c83b18216 fix bug #70440 2024-09-24 21:23:16 +03:00
e1c2bf19d9 Fix build 2024-09-24 18:08:40 +03:00
f38767ccbb Merge pull request 'Fix bug #69036' (#22) from fix/bug-69036 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/22
2024-09-24 11:25:57 +00:00
fc94de8549 Refactoring and improving the debug mod 2024-09-24 11:48:59 +03:00
812fae8f6c Fix bug #69036 2024-09-24 11:46:34 +03:00
c938e2756e Merge pull request 'Fix bug #44363' (#20) from fix/bug44363 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/20
2024-09-24 07:23:22 +00:00
5679a7902f Merge pull request 'Fix placeholder styles conversion' (#19) from fix/placeholder_conversion into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/19
2024-09-24 07:22:22 +00:00
056bfb84ce Fix typo 2024-09-23 22:40:21 +03:00
2d745de7e2 Merge branch 'feature/pdf-font' into release/v8.2.0 2024-09-23 22:02:48 +03:00
a5c73127fd Fix pdf bugs (add build with embedded fonts in changes) 2024-09-23 21:59:36 +03:00
f0f4e39f5c Fix bug 70042 2024-09-23 19:08:27 +03:00
b536d6eb41 Create test GetEmbeddedFont 2024-09-23 15:43:48 +03:00
0af65b1137 Convert odp placeholder styles to pptx 2024-09-23 16:44:16 +05:00
5c3a697880 Fix for drawingfile 2024-09-23 13:31:55 +03:00
1b8c59ff87 Separate GetFontPath 2024-09-23 13:15:39 +03:00
6b4b645180 Create GetEmbeddedFontPath 2024-09-23 13:09:05 +03:00
30868b81bc Fix bug #70339 2024-09-21 16:16:53 +03:00
4c44edc9c9 Merge branch 'fix/bug70318' into fix/placeholder_conversion 2024-09-21 00:07:59 +05:00
60f9021bdd Merge pull request 'Fix bug #70318' (#15) from fix/bug70318 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/15
2024-09-19 14:57:52 +00:00
fd90fbae21 Fix bug #70318 2024-09-19 13:01:07 +05:00
c4979075aa Merge pull request 'Fix bug #70320' (#14) from fix/bug-70320 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/14
2024-09-19 05:16:16 +00:00
6c067ba6ee Merge pull request 'Fix SVG conversion' (#13) from fix/SVG into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/13
2024-09-19 05:16:01 +00:00
2456501f1d Fixes for txt/csv 2024-09-19 08:03:30 +03:00
07c0c58375 Fix bug #70320 2024-09-18 20:50:33 +03:00
db28751875 Fix placeholder conversion 2024-09-18 22:02:54 +05:00
81c9ae120f Fix bug 70293 2024-09-18 14:45:20 +03:00
830c5ec12c fix bug #46132 2024-09-18 10:52:04 +03:00
375f79cdac fix bug #69904 2024-09-17 21:22:24 +03:00
33627ab79c Added support for marker orientation in svg conversion 2024-09-17 19:45:13 +03:00
9f81e37196 fox bug #70227 2024-09-17 18:11:18 +03:00
32a409bb13 Merge pull request 'Enter new contexts by default' (#10) from feature/scoped-context into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/10
2024-09-17 14:27:31 +00:00
b53a1b3cd6 Merge pull request 'Add static CreateObject function to builder' (#11) from fix/bug70010 into release/v8.2.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/11
2024-09-17 14:27:12 +00:00
f5f0630b2d Redesigned the drawing of markers in svg conversion 2024-09-16 22:02:10 +03:00
19e5a2db2d fix bug #70240 2024-09-16 19:06:11 +03:00
8ad7b123aa Fix build pdf files 2024-09-16 14:39:43 +03:00
312a95d9e1 Fix bug #70010 2024-09-13 16:08:42 +04:00
0ac882b207 Merge branch hotfix/v8.1.3 into release/v8.2.0 2024-09-13 10:37:31 +00:00
4378becd0b Enter new contexts by default 2024-09-13 14:30:53 +04:00
8c62dc448a Fixed bug width text position in svg conversion 2024-09-12 20:04:22 +03:00
7f7e89babf fix bug #69781 2024-09-12 18:07:19 +03:00
d89d63e0db fix bug #70136 2024-09-12 14:50:41 +03:00
3c16ba01f0 Fix max font size in svg conversion 2024-09-11 13:23:36 +03:00
0b16086ff5 Fix bugs in svg conversion and optimization 2024-09-10 21:08:12 +03:00
5904bb3507 Fix bug #69865 2024-09-10 21:07:39 +03:00
6a2d3838ae Fix bug #70044 2024-09-10 03:24:57 +05:00
f6c48c1edb Fix bug #70039 2024-09-04 20:48:28 +05:00
4c9c79628f Fix bug #69957 2024-09-03 13:20:36 +05:00
58c35139ea Merge branch 'fix/bug44363' of https://github.com/ONLYOFFICE/core into fix/bug44363
# Conflicts:
#	OdfFile/Reader/Format/text_elements.cpp
2024-08-29 19:41:23 +05:00
7d804f1c70 Fix bug #44363 2024-08-29 19:39:34 +05:00
5b156d72c0 Fix bug #44363 2024-08-06 01:19:19 +03:00
caf90eb3a3 Merge branch hotfix/v8.1.1 into master 2024-07-26 08:04:53 +00:00
90d46b55d8 Merge branch hotfix/v8.1.1 into master 2024-07-15 11:40:21 +00:00
bc56b97ce0 Merge branch release/v8.1.0 into master 2024-06-26 10:42:10 +00:00
260 changed files with 13390 additions and 2786 deletions

2
.gitignore vendored
View File

@ -46,3 +46,5 @@ DesktopEditor/fontengine/js/common/freetype-2.10.4
.qtc_clangd
Common/3dParty/openssl/openssl/
msvc_make.bat

View File

@ -27,7 +27,7 @@ CLEAN=
BOOST_VERSION=1.72.0
BOOST_VERSION2=1_72_0
MIN_IOS_VERSION=8.0
IOS_SDK_VERSION=`xcodebuild BITCODE_GENERATION_MODE="bitcode" ENABLE_BITCODE="YES" OTHER_CFLAGS="-fembed-bitcode" -showsdks | grep iphoneos | \
IOS_SDK_VERSION=`xcodebuild BITCODE_GENERATION_MODE="bitcode" ENABLE_BITCODE="NO" -showsdks | grep iphoneos | \
egrep "[[:digit:]]+\.[[:digit:]]+" -o | tail -1`
OSX_SDK_VERSION=`xcodebuild BITCODE_GENERATION_MODE="bitcode" ENABLE_BITCODE="YES" OTHER_CFLAGS="-fembed-bitcode" -showsdks | grep macosx | \
egrep "[[:digit:]]+\.[[:digit:]]+" -o | tail -1`
@ -42,7 +42,7 @@ XCODE_ROOT=`xcode-select -print-path`
#
# Should perhaps also consider/use instead: -BOOST_SP_USE_PTHREADS
EXTRA_CPPFLAGS="-DBOOST_AC_USE_PTHREADS -DBOOST_SP_USE_PTHREADS -g -DNDEBUG \
-std=c++11 -stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden -fembed-bitcode"
-std=c++11 -stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden"
EXTRA_IOS_CPPFLAGS="$EXTRA_CPPFLAGS -mios-version-min=$MIN_IOS_VERSION"
EXTRA_OSX_CPPFLAGS="$EXTRA_CPPFLAGS"
@ -259,20 +259,20 @@ buildBoost()
echo Building Boost for iPhone
# Install this one so we can copy the headers for the frameworks...
./b2 -j16 --build-dir=iphone-build --stagedir=iphone-build/stage \
cxxflags="-fembed-bitcode" \
cxxflags="" \
--prefix=$PREFIXDIR toolset=darwin architecture=arm target-os=iphone \
macosx-version=iphone-${IOS_SDK_VERSION} define=_LITTLE_ENDIAN \
link=static stage
./b2 -j16 --build-dir=iphone-build --stagedir=iphone-build/stage \
--prefix=$PREFIXDIR toolset=darwin architecture=arm \
cxxflags="-fembed-bitcode" \
cxxflags="" \
target-os=iphone macosx-version=iphone-${IOS_SDK_VERSION} \
define=_LITTLE_ENDIAN link=static install
doneSection
echo Building Boost for iPhoneSimulator
./b2 -j16 --build-dir=iphonesim-build --stagedir=iphonesim-build/stage \
cxxflags="-fembed-bitcode" \
cxxflags="" \
toolset=darwin-${IOS_SDK_VERSION}~iphonesim architecture=x86 \
target-os=iphone macosx-version=iphonesim-${IOS_SDK_VERSION} \
link=static stage

View File

@ -78,24 +78,24 @@ function set_ios_cpu_feature() {
armv7)
export CC="xcrun -sdk iphoneos clang -arch armv7"
export CXX="xcrun -sdk iphoneos clang++ -arch armv7"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64)
export CC="xcrun -sdk iphoneos clang -arch arm64"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64e)
# -march=armv8.3 ???
export CC="xcrun -sdk iphoneos clang -arch arm64e"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64e"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
i386)
export CC="xcrun -sdk iphonesimulator clang -arch i386"

View File

@ -14,6 +14,15 @@ namespace NSCSS
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
}
void CNode::Clear()
{
m_wsName .clear();
m_wsClass .clear();
m_wsId .clear();
m_wsStyle .clear();
m_mAttributes.clear();
}
std::vector<std::wstring> CNode::GetData() const
{
std::vector<std::wstring> arValues;

View File

@ -22,6 +22,8 @@ namespace NSCSS
bool Empty() const;
void Clear();
std::vector<std::wstring> GetData() const;
bool operator< (const CNode& oNode) const;
bool operator== (const CNode& oNode) const;

View File

@ -7,12 +7,18 @@ namespace NSCSS
return sValue < oStatistickElement.sValue;
}
void CTree::Clear()
{
m_arrChild.clear();
m_oNode.Clear();
}
void CTree::CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics)
{
if (!oTree.m_oNode.m_wsId.empty())
++mStatictics[StatistickElement{StatistickElement::IsId, L'#' + oTree.m_oNode.m_wsId}];
if (!oTree.m_oNode.m_wsStyle.empty())
++mStatictics[StatistickElement{StatistickElement::IsStyle, oTree.m_oNode.m_wsStyle}];
if (!oTree.m_oNode.m_wsStyle.empty())
++mStatictics[StatistickElement{StatistickElement::IsStyle, oTree.m_oNode.m_wsStyle}];
if (!oTree.m_arrChild.empty())
for (const CTree& oChildren : oTree.m_arrChild)
@ -82,7 +88,7 @@ namespace NSCSS
{L"gainsboro", L"DCDCDC"}, {L"lightgray", L"D3D3D3"}, {L"silver", L"C0C0C0"},
{L"darkgray", L"A9A9A9"}, {L"gray", L"808080"}, {L"dimgray", L"696969"},
{L"lightslategray", L"778899"}, {L"slategray", L"708090"}, {L"darkslategray", L"2F4F4F"},
{L"black", L"000000"},
{L"black", L"000000"}, {L"grey", L"808080"},
/* Outdated */
{L"windowtext", L"000000"}, {L"transparent", L"000000"}
};

View File

@ -33,6 +33,8 @@ namespace NSCSS
NSCSS::CNode m_oNode;
std::vector<CTree> m_arrChild;
void Clear();
static void CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics);
};

View File

@ -614,11 +614,11 @@ namespace NSCSS
void CColor::SetHEX(const std::wstring &wsValue)
{
Clear();
if (6 != wsValue.length() && 3 != wsValue.length())
return;
Clear();
if (6 == wsValue.length())
m_oValue = new std::wstring(wsValue);
else
@ -632,8 +632,6 @@ namespace NSCSS
void CColor::SetUrl(const std::wstring &wsValue)
{
Clear();
if (wsValue.empty())
return;
@ -648,6 +646,8 @@ namespace NSCSS
return;
}
Clear();
m_oValue = pURL;
m_enType = ColorUrl;
}
@ -659,6 +659,16 @@ namespace NSCSS
m_enType = ColorNone;
}
char NormalizeNegativeColorValue(INT nValue)
{
if (nValue > 255)
return 0xff;
else if (nValue < 0)
return (char)(std::abs(nValue) % 255);
return (char)nValue;
}
bool CColor::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
if ((CHECK_CONDITIONS && !bHardMode) || (wsValue.empty() && unLevel == m_unLevel))
@ -692,6 +702,16 @@ namespace NSCSS
SetNone();
bResult = true;
}
else if (L"context-stroke" == wsNewValue)
{
Clear();
m_enType = ColorContextStroke;
}
else if (L"context-fill" == wsNewValue)
{
Clear();
m_enType = ColorContextFill;
}
else if (10 <= wsNewValue.length() && wsNewValue.substr(0, 3) == L"rgb")
{
size_t unEnd = wsNewValue.find(L')', 4);
@ -704,29 +724,18 @@ namespace NSCSS
if (3 > arValues.size())
return false;
INT nRed = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[0], 255));
INT nGreen = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[1], 255));
INT nBlue = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[2], 255));
const char chRed = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[0], 255)));
const char chGreen = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[1], 255)));
const char chBlue = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[2], 255)));
if (nRed < 0 || nGreen < 0 || nBlue < 0)
{
SetEmpty(unLevel);
return false;
}
if (255 < nRed) nRed = 255;
if (255 < nGreen) nGreen = 255;
if (255 < nBlue) nBlue = 255;
SetRGB(nRed, nGreen, nBlue);
SetRGB(chRed, chGreen, chBlue);
if (wsNewValue.substr(0, 4) == L"rgba" && 4 == arValues.size())
m_oOpacity.SetValue(arValues[3], unLevel, bHardMode);
bResult = true;
}
if (5 <= wsNewValue.length())
else if (5 <= wsNewValue.length())
{
SetUrl(wsValue);

View File

@ -215,7 +215,9 @@ namespace NSCSS
ColorNone,
ColorRGB,
ColorHEX,
ColorUrl
ColorUrl,
ColorContextStroke,
ColorContextFill
} ColorType;
class CColor : public CValue<void*>

View File

@ -2,3 +2,4 @@ emsdk/
hunspell/
deploy/
o
hunspell.data

View File

@ -14,6 +14,12 @@ def get_hunspell(stable_commit):
base.replaceInFile("./src/hunspell/csutil.cxx", "void free_utf_tbl() {", "void free_utf_tbl() { \n return;\n")
# bug fix, we need to keep this utf table
# free_utf_tbl doesnt delete anything so we can destroy hunspell object
# replace & add defines to easy control of time limits (CUSTOM_LIMIT)
default_tl_defines = "#define TIMELIMIT_GLOBAL (CLOCKS_PER_SEC / 4)\n#define TIMELIMIT_SUGGESTION (CLOCKS_PER_SEC / 10)\n#define TIMELIMIT (CLOCKS_PER_SEC / 20)\n"
custom_tl_defines_tl = "#define TIMELIMIT_GLOBAL CUSTOM_TIMELIMIT_GLOBAL\n#define TIMELIMIT_SUGGESTION CUSTOM_TIMELIMIT_SUGGESTION\n#define TIMELIMIT CUSTOM_TIMELIMIT\n"
tl_defines = "#ifndef CUSTOM_TIMELIMITS\n" + default_tl_defines + "#else\n" + custom_tl_defines_tl + "#endif\n"
base.replaceInFile("./src/hunspell/atypes.hxx", default_tl_defines, tl_defines)
os.chdir("../")

View File

@ -14,12 +14,32 @@ DEFINES += KERNEL_USE_DYNAMIC_LIBRARY
TEMPLATE = app
CONFIG += hunspell_build_static
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
include($$CORE_ROOT_DIR/Common/3dParty/hunspell/qt/hunspell.pri)
ADD_DEPENDENCY(UnicodeConverter kernel hunspell)
# custom time limits of hunspell in clocks (if before.py was executed)
# when increasing the limit for each case, it is important to consider that the total time will
# also increase, so it is good to increase the global limit. this works the same for the candidate limit with suggest limit
DEFINES += CUSTOM_TIMELIMITS
escape_bracket=
!core_windows:escape_bracket=\\
# total time limit per word for all cases. (default is CLOCKS_PER_SEC/4)
DEFINES += "CUSTOM_TIMELIMIT_GLOBAL=$${escape_bracket}(20*CLOCKS_PER_SEC$${escape_bracket})"
# total time limit per "1 case" - forgotten char, double char, moved char and so on for all candidates. (default is CLOCKS_PER_SEC/10)
DEFINES += "CUSTOM_TIMELIMIT_SUGGESTION=$${escape_bracket}(5*CLOCKS_PER_SEC$${escape_bracket})"
# time limit per candidate (default is CLOCKS_PER_SEC/20)
DEFINES += "CUSTOM_TIMELIMIT=$${escape_bracket}(CLOCKS_PER_SEC$${escape_bracket}\)"
ADD_DEPENDENCY(UnicodeConverter kernel)
core_windows:LIBS += -lgdi32 -ladvapi32 -luser32 -lshell32

View File

@ -20,9 +20,9 @@ CONFIG_PREFIX=" --enable-extras=yes \
--enable-dyload=no \
--with-data-packaging=static"
CFLAGS="-O3 -D__STDC_INT64__ -fno-exceptions -fno-short-wchar -fno-short-enums -fembed-bitcode"
CFLAGS="-O3 -D__STDC_INT64__ -fno-exceptions -fno-short-wchar -fno-short-enums"
CXXFLAGS="${CFLAGS} -std=c++11 -fembed-bitcode"
CXXFLAGS="${CFLAGS} -std=c++11"
#will set value to 1
defines_config_set_1=(
@ -215,9 +215,9 @@ function build() {
export CXX="$(xcrun -find clang++)"
export CC="$(xcrun -find clang)"
export CFLAGS="-fembed-bitcode -isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH $IOS_MIN_VER $ICU_FLAGS $CFLAGS ${ADDITION_FLAG}"
export CXXFLAGS="${CXXFLAGS} -fembed-bitcode -stdlib=libc++ -isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH $IOS_MIN_VER $ICU_FLAGS ${ADDITION_FLAG}"
export LDFLAGS="-fembed-bitcode -stdlib=libc++ -L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip $IOS_MIN_VER -lstdc++ ${ADDITION_FLAG}"
export CFLAGS="-isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH $IOS_MIN_VER $ICU_FLAGS $CFLAGS ${ADDITION_FLAG}"
export CXXFLAGS="${CXXFLAGS} -stdlib=libc++ -isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH $IOS_MIN_VER $ICU_FLAGS ${ADDITION_FLAG}"
export LDFLAGS="-stdlib=libc++ -L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip $IOS_MIN_VER -lstdc++ ${ADDITION_FLAG}"
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}

View File

@ -84,24 +84,24 @@ function set_ios_cpu_feature() {
armv7)
export CC="xcrun -sdk iphoneos clang -arch armv7"
export CXX="xcrun -sdk iphoneos clang++ -arch armv7"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64)
export CC="xcrun -sdk iphoneos clang -arch arm64"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64e)
# -march=armv8.3 ???
export CC="xcrun -sdk iphoneos clang -arch arm64e"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64e"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -isysroot ${sysroot} -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
i386)
export CC="xcrun -sdk iphonesimulator clang -arch i386"
@ -120,9 +120,9 @@ function set_ios_cpu_feature() {
sim-arm64)
export CC="xcrun -sdk iphonesimulator clang -arch arm64"
export CXX="xcrun -sdk iphonesimulator clang++ -arch arm64"
export CFLAGS="-arch arm64 -target aarch64-apple-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aaarch64-apple-darwin -march=armv8 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-apple-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -DIOS -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64 -target aarch64-apple-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aaarch64-apple-darwin -march=armv8 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++11 -arch arm64 -target aarch64-apple-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -DIOS -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
*)
log_error "not support" && exit 1

View File

@ -107,26 +107,26 @@ function configure_make() {
# openssl1.1.1d can be set normally, 1.1.0f does not take effect
./Configure iphoneos-cross no-shared --prefix="${PREFIX_DIR}" enable-ssl3 enable-ssl3-method enable-md2
sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
#sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
elif [[ "${ARCH_NAME}" == "arm64" ]]; then
# openssl1.1.1d can be set normally, 1.1.0f does not take effect
./Configure iphoneos-cross no-shared --prefix="${PREFIX_DIR}" enable-ssl3 enable-ssl3-method enable-md2
sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
#sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
elif [[ "${ARCH_NAME}" == "i386" ]]; then
# openssl1.1.1d can be set normally, 1.1.0f does not take effect
./Configure darwin-i386-cc no-shared --prefix="${PREFIX_DIR}" enable-ssl3 enable-ssl3-method enable-md2
sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
#sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
sed -i -e 's/-mtune=intel//g' "Makefile"
elif [[ "${ARCH_NAME}" == "sim_arm64" ]]; then
# openssl1.1.1d can be set normally, 1.1.0f does not take effect
./Configure iphoneos-cross no-shared --prefix="${PREFIX_DIR}" enable-ssl3 enable-ssl3-method enable-md2
sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
#sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile"
else
log_error "not support" && exit 1

View File

@ -238,11 +238,24 @@ bool COfficeFileFormatChecker::isPdfFormatFile(unsigned char *pBuffer, int dwByt
if (NULL == pFirst)
{
//skip special
_UINT16 sz = pBuffer[0] + (pBuffer[1] << 8);
if (sz < dwBytes - 8)
char* pData = (char*)pBuffer;
for (int i = 0; i < dwBytes - 5; ++i)
{
pFirst = strstr((char*)(pBuffer + sz), "%PDF-");
int nPDF = strncmp(&pData[i], "%PDF-", 5);
if (!nPDF)
{
pFirst = (char*)pBuffer + i;
break;
}
}
if (NULL == pFirst)
{
//skip special
_UINT16 sz = pBuffer[0] + (pBuffer[1] << 8);
if (sz < dwBytes - 8)
{
pFirst = strstr((char*)(pBuffer + sz), "%PDF-");
}
}
}
if (NULL != pFirst)

View File

@ -148,7 +148,7 @@ mac {
CONFIG += core_mac
CONFIG += core_mac_64
DEFINES += _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
DEFINES += _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
}
}
@ -185,7 +185,7 @@ core_mac {
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11
QMAKE_LFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
# xcode15 add new linker
# xcode15 add new linker
QMAKE_LFLAGS += -Wl,-ld_classic
QMAKE_CFLAGS += "-Wno-implicit-function-declaration"
@ -301,22 +301,25 @@ linux_arm64 {
core_ios {
CORE_BUILDS_PLATFORM_PREFIX = ios
!versionAtLeast(QMAKE_XCODE_VERSION, 16.0) {
QMAKE_CFLAGS += -fembed-bitcode
QMAKE_CXXFLAGS += -fembed-bitcode
QMAKE_LFLAGS += -fembed-bitcode
} else {
CONFIG -= bitcode
}
CONFIG(iphonesimulator, iphoneos|iphonesimulator): {
message("iphonesimulator")
CORE_BUILDS_PLATFORM_PREFIX = ios_simulator
QMAKE_CFLAGS += -fembed-bitcode
QMAKE_CXXFLAGS += -fembed-bitcode
QMAKE_LFLAGS += -fembed-bitcode
QMAKE_CFLAGS += -fobjc-arc
QMAKE_CXXFLAGS += -fobjc-arc
} else {
QMAKE_IOS_DEPLOYMENT_TARGET = 11.0
QMAKE_CFLAGS += -fembed-bitcode
QMAKE_CXXFLAGS += -fembed-bitcode
QMAKE_LFLAGS += -fembed-bitcode
QMAKE_CFLAGS += -fobjc-arc
QMAKE_CXXFLAGS += -fobjc-arc
@ -573,7 +576,7 @@ defineTest(ADD_DEPENDENCY) {
libs = $$ARGS
for(lib, libs) {
CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH
isEqual(lib, videoplayer) {
libvlc {
CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH/mediaplayer
@ -586,7 +589,7 @@ defineTest(ADD_DEPENDENCY) {
isEqual(lib, qtascdocumentscore):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH_DST/xp
isEqual(lib, videoplayer):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH_DST/xp
isEqual(lib, ooxmlsignature):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH_DST/xp
}
}
!bundle_dylibs:LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH_DST -l$$lib
bundle_dylibs:LIBS += -F$$CORE_BUILDS_LIBRARIES_PATH_DST -framework $$lib
}

View File

@ -648,7 +648,7 @@ namespace NSStringUtils
}
void CStringBuilder::AddInt(int val)
{
AddSize(10);
AddSize(11);
AddIntNoCheck(val);
}
void CStringBuilder::AddUInt(unsigned int val)
@ -683,6 +683,9 @@ namespace NSStringUtils
if (val < 0)
{
val = -val;
if (val < 0)
val = 2147483647;
*m_pDataCur++ = (wchar_t)'-';
++m_lSizeCur;
}

View File

@ -145,13 +145,23 @@ namespace NSDoctRenderer
NSHyphen::CEngine::Init(private_GetFile(sConfigDir, oNodeDict.GetText()));
}
bool bIsAbsoluteFontsPath = false;
if (!m_bIsNotUseConfigAllFontsDir)
{
std::wstring sAllFontsPath = oNode.ReadNodeText(L"allfonts");
if (!sAllFontsPath.empty())
{
m_strAllFonts = private_GetFile(sConfigDir, sAllFontsPath);
if (NSFile::CFileBinary::Exists(sConfigDir + sAllFontsPath))
m_strAllFonts = sConfigDir + sAllFontsPath;
else if (NSFile::CFileBinary::Exists(sAllFontsPath))
m_strAllFonts = sAllFontsPath;
else
{
std::wstring sAllFontsDir = NSFile::GetDirectoryName(sAllFontsPath);
if (NSDirectory::Exists(sConfigDir + sAllFontsDir))
m_strAllFonts = sConfigDir + sAllFontsPath;
else
m_strAllFonts = sAllFontsPath;
}
// на папку может не быть прав
if (!NSFile::CFileBinary::Exists(m_strAllFonts))
@ -163,20 +173,16 @@ namespace NSDoctRenderer
if (NSDirectory::CreateDirectory(sAppDir + L"/docbuilder"))
{
m_strAllFonts = sAppDir + L"/docbuilder/AllFonts.js";
// файл может не существовать пока - и тогда private_GetFile не учтет его
bIsAbsoluteFontsPath = true;
}
}
else
{
fclose(pFileNative);
NSFile::CFileBinary::Remove(m_strAllFonts);
}
}
}
}
if (!bIsAbsoluteFontsPath)
m_strAllFonts = private_GetFile(sConfigDir, m_strAllFonts);
}
m_strSdkPath = oNode.ReadNodeText(L"sdkjs");

View File

@ -68,8 +68,8 @@ namespace NSDoctRenderer
return m_pInternal->ExecuteCommand(command, retValue);
}
CDocBuilderContext CDocBuilder::GetContext()
CDocBuilderContext CDocBuilder::GetContext(bool enterContext)
{
return m_pInternal->GetContext();
return m_pInternal->GetContext(enterContext);
}
}

View File

@ -204,6 +204,11 @@ namespace NSDoctRenderer
* Creates an array. This method returns the current context and calls its CreateArray method.
*/
static CDocBuilderValue CreateArray(const int& length);
/**
* Please use CDocBuilderContext::CreateObject
* Creates an object. This method returns the current context and calls its CreateObject method.
*/
static CDocBuilderValue CreateObject();
public:
/**
@ -492,9 +497,10 @@ namespace NSDoctRenderer
/**
* Returns the current JS context.
* @param enterContext Whether returned context should be entered or not.
* @return The current JS context
*/
CDocBuilderContext GetContext();
CDocBuilderContext GetContext(bool enterContext = true);
public:
/**

View File

@ -83,6 +83,10 @@ public class CDocBuilder {
return new CDocBuilderContext(c_GetContext(c_internal));
}
public CDocBuilderContext getContext(boolean enterContext) {
return new CDocBuilderContext(c_GetContextWithEnterParam(c_internal, enterContext));
}
public static void initialize() {
c_Initialize();
}
@ -135,6 +139,7 @@ public class CDocBuilder {
private static native String c_GetVersion(long self);
private static native long c_GetContext(long self);
private static native long c_GetContextWithEnterParam(long self, boolean enterContext);
private static native void c_Initialize();
private static native void c_InitializeWithDirectory(String directory);

View File

@ -40,7 +40,7 @@ public class NativeLibraryLoader {
throw new RuntimeException("Unsupported OS");
}
String[] libs = {"UnicodeConverter", "kernel", "kernel_network", "graphics", "doctrenderer", "docbuilder.jni"};
String[] libs = {"UnicodeConverter", "kernel", "kernel_network", "graphics", "PdfFile", "XpsFile", "DjVuFile", "DocxRenderer", "doctrenderer", "docbuilder.jni"};
String prefix = "";
if (OSChecker.isMac() || OSChecker.isLinux()) {

View File

@ -162,6 +162,12 @@ jlong Java_docbuilder_CDocBuilder_c_1GetContext(JNIEnv* env, jclass cls, jlong s
return reinterpret_cast<jlong>(new CDocBuilderContext(pSelf->GetContext()));
}
jlong Java_docbuilder_CDocBuilder_c_1GetContextWithEnterParam(JNIEnv* env, jclass cls, jlong self, jboolean enterContext)
{
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
return reinterpret_cast<jlong>(new CDocBuilderContext(pSelf->GetContext((bool)enterContext)));
}
void Java_docbuilder_CDocBuilder_c_1Initialize(JNIEnv* env, jclass cls)
{
CDocBuilder::Initialize();

View File

@ -167,6 +167,14 @@ JNIEXPORT jstring JNICALL Java_docbuilder_CDocBuilder_c_1GetVersion
JNIEXPORT jlong JNICALL Java_docbuilder_CDocBuilder_c_1GetContext
(JNIEnv *, jclass, jlong);
/*
* Class: docbuilder_CDocBuilder
* Method: c_GetContextWithEnterParam
* Signature: (JZ)J
*/
JNIEXPORT jlong JNICALL Java_docbuilder_CDocBuilder_c_1GetContextWithEnterParam
(JNIEnv *, jclass, jlong, jboolean);
/*
* Class: docbuilder_CDocBuilder
* Method: c_Initialize

View File

@ -17,7 +17,6 @@ public class Program {
builder.createFile(FileTypes.Document.DOCX);
CDocBuilderContext context = builder.getContext();
CDocBuilderContextScope scope = context.createScope();
CDocBuilderValue global = context.getGlobal();

View File

@ -121,6 +121,9 @@ def _loadLibrary(path):
_lib.CDocBuilderValue_CreateArray.argtypes = [ctypes.c_int]
_lib.CDocBuilderValue_CreateArray.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateObject.argtypes = []
_lib.CDocBuilderValue_CreateObject.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call0.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilderValue_Call0.restype = OBJECT_HANDLE
@ -200,7 +203,7 @@ def _loadLibrary(path):
_lib.CDocBuilder_GetVersion.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_GetVersion.restype = STRING_HANDLE
_lib.CDocBuilder_GetContext.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_GetContext.argtypes = [OBJECT_HANDLE, ctypes.c_bool]
_lib.CDocBuilder_GetContext.restype = OBJECT_HANDLE
_lib.CDocBuilder_Initialize.argtypes = []
@ -280,6 +283,12 @@ class CDocBuilderValue:
self._internal = _lib.CDocBuilderValue_CreateArray(length)
for i in range(length):
self.Set(i, value[i])
elif isinstance(value, dict):
self._internal = _lib.CDocBuilderValue_CreateObject()
for key in value.keys():
if not isinstance(key, str):
raise TypeError("CDocBuilderValue constructor supports only str keys in dict")
self.SetProperty(key, value[key])
elif isinstance(value, CDocBuilderValue):
self._internal = _lib.CDocBuilderValue_Copy(value._internal)
elif isinstance(value, OBJECT_HANDLE):
@ -385,6 +394,10 @@ class CDocBuilderValue:
def CreateArray(length):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_CreateArray(length)))
@staticmethod
def CreateObject():
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_CreateObject()))
def Call(self, name, *args):
if len(args) == 0:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call0(self._internal, ctypes.c_wchar_p(name))))
@ -479,8 +492,8 @@ class CDocBuilder:
_lib.DeleteCharP(ctypes.cast(strVersion, ctypes.c_char_p))
return version
def GetContext(self):
return CDocBuilderContext(OBJECT_HANDLE(_lib.CDocBuilder_GetContext(self._internal)))
def GetContext(self, enterContext=True):
return CDocBuilderContext(OBJECT_HANDLE(_lib.CDocBuilder_GetContext(self._internal, ctypes.c_bool(enterContext))))
@classmethod
def Initialize(cls, directory=None):

View File

@ -164,6 +164,11 @@ CDocBuilderValue* CDocBuilderValue_CreateArray(int length)
return new CDocBuilderValue(CDocBuilderValue::CreateArray(length));
}
CDocBuilderValue* CDocBuilderValue_CreateObject()
{
return new CDocBuilderValue(CDocBuilderValue::CreateObject());
}
CDocBuilderValue* CDocBuilderValue_Call0(CDocBuilderValue* self, const wchar_t* name)
{
return new CDocBuilderValue(self->Call(name));
@ -296,9 +301,9 @@ char* CDocBuilder_GetVersion(CDocBuilder* self)
return self->GetVersion();
}
CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self)
CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self, bool enterContext)
{
return new CDocBuilderContext(self->GetContext());
return new CDocBuilderContext(self->GetContext(enterContext));
}
void CDocBuilder_Initialize()

View File

@ -56,6 +56,7 @@ DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithString(const w
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateUndefined();
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateNull();
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateArray(int length);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateObject();
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call0(CDocBuilderValue* self, const wchar_t* name);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call1(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1);
@ -96,7 +97,7 @@ DOCBUILDER_FUNC_DECL bool CDocBuilder_IsSaveWithDoctrendererMode(CDocBuilder* se
DOCBUILDER_FUNC_DECL char* CDocBuilder_GetVersion(CDocBuilder* self);
DOCBUILDER_FUNC_DECL CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self);
DOCBUILDER_FUNC_DECL CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self, bool enterContext);
DOCBUILDER_FUNC_DECL void CDocBuilder_Initialize();
DOCBUILDER_FUNC_DECL void CDocBuilder_InitializeWithDirectory(const wchar_t* directory);

View File

@ -821,6 +821,14 @@ namespace NSDoctRenderer
return ret;
}
CDocBuilderValue CDocBuilderValue::CreateObject()
{
CDocBuilderValue ret;
ret.m_internal->m_context = NSJSBase::CJSContext::GetCurrent();
ret.m_internal->m_value = NSJSBase::CJSContext::createObject();
return ret;
}
// Functions
CDocBuilderValue CDocBuilderValue::Call(const char* name)
{

View File

@ -407,6 +407,11 @@ public:
{
m_scopes.push_back(scope);
}
void AddNewScope(NSDoctRenderer::CDocBuilderContextScopeWrap* scope)
{
m_scopes.emplace_back(scope);
}
};
class CV8RealTimeWorker
@ -1284,7 +1289,7 @@ namespace NSDoctRenderer
return m_pWorker->ExecuteCommand(command, retValue);
}
CDocBuilderContext GetContext()
CDocBuilderContext GetContext(bool enterContext)
{
CDocBuilderContext ctx;
@ -1292,6 +1297,14 @@ namespace NSDoctRenderer
ctx.m_internal->m_context = m_pWorker->m_context;
ctx.m_internal->m_context_data = &m_pWorker->m_oContextData;
if (enterContext)
{
CDocBuilderContextScopeWrap* scopeWrap = new CDocBuilderContextScopeWrap();
scopeWrap->m_scope = new CJSContextScope(m_pWorker->m_context);
m_pWorker->m_oContextData.AddNewScope(scopeWrap);
}
return ctx;
}

View File

@ -445,7 +445,7 @@ namespace NSDoctRenderer
strError = L"code=\"save\"";
bIsBreak = true;
}
else
else if (!js_result2->isNull())
{
JSSmart<CJSTypedArray> typedArray = js_result2->toTypedArray();
NSJSBase::CJSDataBuffer oBuffer = typedArray->getData();

View File

@ -42,6 +42,8 @@
#include "../../HtmlRenderer/include/HTMLRendererText.h"
#include "../../DocxRenderer/DocxRenderer.h"
#define CHECKER_FILE_BUFFER_LEN 4096
class CDrawingFile
{
private:
@ -122,18 +124,38 @@ public:
{
CloseFile();
if (NULL == m_pFile)
int nType = DetectFormat(sFile);
switch (nType)
{
case 0:
{
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
if (4 != ((CPdfFile*)m_pFile)->GetError())
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
else
m_nType = 0;
break;
}
case 1:
{
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
m_nType = 1;
break;
}
if (NULL == m_pFile)
case 2:
{
m_pFile = new CXpsFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
@ -143,16 +165,8 @@ public:
else
m_nType = 2;
}
if (NULL == m_pFile)
{
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 1;
default:
break;
}
return m_pFile ? true : false;
@ -162,37 +176,48 @@ public:
{
CloseFile();
if (NULL == m_pFile)
int nType = DetectFormat(data, size);
switch (nType)
{
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
case 0:
{
RELEASEOBJECT(m_pFile);
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
if (4 != ((CPdfFile*)m_pFile)->GetError())
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
else
m_nType = 0;
break;
}
else
m_nType = 0;
}
if (NULL == m_pFile)
{
m_pFile = new CXpsFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
case 1:
{
RELEASEOBJECT(m_pFile);
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 1;
break;
}
else
m_nType = 2;
}
if (NULL == m_pFile)
{
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
case 2:
{
RELEASEOBJECT(m_pFile);
m_pFile = new CXpsFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 2;
}
else
m_nType = 1;
default:
break;
}
return m_pFile ? true : false;
@ -484,6 +509,14 @@ public:
return NULL;
}
std::wstring GetFontBinaryNative(const std::wstring& sName)
{
if (0 != m_nType)
return L"";
return ((CPdfFile*)m_pFile)->GetEmbeddedFontPath(sName);
}
private:
int GetPagesCount()
{
@ -514,7 +547,44 @@ private:
nPageDpiX = dPageDpiX;
}
int DetectFormat(const std::wstring& sFile)
{
NSFile::CFileBinary oFile;
if (oFile.OpenFile(sFile))
{
LONG size = oFile.GetFileSize();
if (size > CHECKER_FILE_BUFFER_LEN)
size = CHECKER_FILE_BUFFER_LEN;
BYTE* data = new BYTE[size];
oFile.ReadFile(data, size);
int nType = DetectFormat(data, size);
RELEASEARRAYOBJECTS(data);
return nType;
}
return -1;
}
int DetectFormat(BYTE* data, LONG size)
{
// 0 - PDF
// 1 - DJVU
// 2 - XPS
LONG nSize = size < CHECKER_FILE_BUFFER_LEN ? size : CHECKER_FILE_BUFFER_LEN;
char* pData = (char*)data;
for (int i = 0; i < nSize - 5; ++i)
{
int nPDF = strncmp(&pData[i], "%PDF-", 5);
if (!nPDF)
return 0;
}
if ( (8 <= size) && (0x41 == data[0] && 0x54 == data[1] && 0x26 == data[2] && 0x54 == data[3] &&
0x46 == data[4] && 0x4f == data[5] && 0x52 == data[6] && 0x4d == data[7]))
return 1;
return 2;
}
};
#endif // DRAWINGFILE_H

View File

@ -71,6 +71,19 @@ JSSmart<CJSValue> CDrawingFileEmbed::DestroyPixmap(JSSmart<CJSValue> typedArray)
return NULL;
}
JSSmart<CJSValue> CDrawingFileEmbed::GetFontBinary(JSSmart<CJSValue> Id)
{
if (0 != m_pFile->GetType())
return NULL;
std::wstring sName = Id->toStringW();
std::wstring sFile = m_pFile->GetFontBinaryNative(sName);
if (sFile.empty())
return NULL;
return CJSContext::createUint8Array(sFile);
}
JSSmart<CJSValue> CDrawingFileEmbed::GetGlyphs(JSSmart<CJSValue> nPageIndex)
{
return WasmMemoryToJS(m_pFile->GetGlyphs(nPageIndex->toInt32()));

View File

@ -40,6 +40,7 @@ public:
JSSmart<CJSValue> GetAnnotationsInfo(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetAnnotationsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nAnnot, JSSmart<CJSValue> nView);
JSSmart<CJSValue> GetFontBinary(JSSmart<CJSValue> Id);
JSSmart<CJSValue> GetGlyphs(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> DestroyTextInfo();

View File

@ -20,6 +20,7 @@
-(JSValue*) GetButtonIcons : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)bBase64 : (JSValue*)nButtonWidget : (JSValue*)nIconView;
-(JSValue*) GetAnnotationsInfo : (JSValue*)nPageIndex;
-(JSValue*) GetAnnotationsAP : (JSValue*)nRasterW : (JSValue*)nRasterH : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)nAnnot : (JSValue*)nView;
-(JSValue*) GetFontBinary : (JSValue*)Id;
-(JSValue*) GetGlyphs : (JSValue*)nPageIndex;
-(JSValue*) DestroyTextInfo;
-(JSValue*) IsNeedCMap;
@ -53,6 +54,7 @@ FUNCTION_WRAPPER_JS_7(GetInteractiveFormsAP, GetInteractiveFormsAP)
FUNCTION_WRAPPER_JS_5(GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_JS_1(GetAnnotationsInfo, GetAnnotationsInfo)
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_0(IsNeedCMap, IsNeedCMap)

View File

@ -23,6 +23,7 @@ namespace NSDrawingFileEmbed
FUNCTION_WRAPPER_V8_5(_GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_V8_1(_GetAnnotationsInfo, GetAnnotationsInfo)
FUNCTION_WRAPPER_V8_6(_GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_V8_1(_GetFontBinary, GetFontBinary)
FUNCTION_WRAPPER_V8_1(_GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_V8_0(_DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_V8_0(_IsNeedCMap, IsNeedCMap)
@ -51,6 +52,7 @@ namespace NSDrawingFileEmbed
NSV8Objects::Template_Set(result, "GetButtonIcons", _GetButtonIcons);
NSV8Objects::Template_Set(result, "GetAnnotationsInfo", _GetAnnotationsInfo);
NSV8Objects::Template_Set(result, "GetAnnotationsAP", _GetAnnotationsAP);
NSV8Objects::Template_Set(result, "GetFontBinary", _GetFontBinary);
NSV8Objects::Template_Set(result, "GetGlyphs", _GetGlyphs);
NSV8Objects::Template_Set(result, "DestroyTextInfo", _DestroyTextInfo);
NSV8Objects::Template_Set(result, "IsNeedCMap", _IsNeedCMap);

View File

@ -0,0 +1,9 @@
!*.vcxproj.user
!Makefile
out/
*.docx
*.pptx
*.xlsx
*.class

View File

@ -0,0 +1,156 @@
- [Document Builder samples](#document-builder-samples)
- [About](#about)
- [Project generator: configure.py](#project-generator-configurepy)
- [Running C++ samples](#running-c-samples)
- [Visual Studio](#visual-studio)
- [Qt](#qt)
- [Makefile](#makefile)
- [Running C# samples](#running-c-samples-1)
- [Visual Studio](#visual-studio-1)
- [Running Python samples](#running-python-samples)
- [Running Java samples](#running-java-samples)
# Document Builder samples
## About
Here you can find some code samples for Document Builder library in different programming languages:
1. [C++](#running-c-samples)
2. [C# (.NET)](#running-c-samples-1)
3. [Python](#running-python-samples)
4. [Java](#running-java-samples)
## Project generator: configure.py
For running C++ and C# code samples use python script `configure/configure.py` which is able to generate:
+ Visual Studio project files
+ Qt project file
+ Makefile
To use `configure.py` you need to specify following options:
1. Which project files to generate: `--vs`, `--qt` or `--make`. Several options are available at the same time, but some of them are not supported on all platforms. In case you provide none of these options, all available projects will be generated.
2. Test samples with `--test TEST`. Some available options:
- `--test all` generate projects for both C++ and C#.
- `--test cpp` generate projects only for C++ samples
- `--test cs` generate projects only for C# samples.
- `--test cpp/creating_basic_form` generate only project for the specified sample.
Several test options are available at the same time. To see all available `TEST` options call `configure.py -l`.
3. Directory to the Document Builder with `--dir DIR`. If Document Builder is not installed in default path you have to provide path to it.
Generated files will be located in the `out` directory inside of the corresponding test folders.
## Running C++ samples
If Document Builder is not installed in `C:/Program Files/ONLYOFFICE/DocumentBuilder`, for every C++ sample you should change the `workDir` variable at the beginning of *main.cpp* to actual location of Document Builder directory.
### Visual Studio
> **NOTE:** Only available on Windows
1. Use `configure.py` to generate VS project files. For example:
```shell
python configure.py --vs --test cpp/creating_basic_form --test cpp/creating_advanced_form
```
2. Open `.sln` file in Visual Studio. It will prompt you to retarget Windows SDK and VS toolset to your installed version click "OK".
3. The solution is ready to be built and run. Documents will be created in the project files directory.
### Qt
1. Use `configure.py` to generate Qt project files. For example:
```shell
python configure.py --qt --test cpp
```
2. Open `.pro` file in Qt Creator.
3. The project is ready to be built and run. Documents will be created in the `build` directory.
### Makefile
> **NOTE:** Only available on Linux and Mac OS.
1. Use `configure.py` to generate Makefile. For example:
```shell
python configure.py --make --test cpp/filling_spreadsheet
```
2. Go to the directory with generated Makefile:
```shell
cd ../out/cpp/filling_spreadsheet
```
3. Call
```shell
make
```
`make` will build and run the executable. Documents will be created in the same directory as Makefile is.
## Running C# samples
> **NOTE:** Only available on Windows with Visual Studio and .NET SDK installed
If Document Builder is not installed in `C:/Program Files/ONLYOFFICE/DocumentBuilder`, for every C# sample you should change the `workDirectory` variable at the beginning of `Main` function to actual location of Document Builder directory.
### Visual Studio
1. Use `configure.py` to generate VS project files. For example:
```shell
python configure.py --vs --test cs
```
2. Open `.sln` file in Visual Studio. Depending on your installed .NET SDK version you may need to set different target framework by setting it in Visual Studio project properties or editing it directly in the `.csproj` file.
3. The solution is ready to be built and run. Documents will be created in the project files directory.
## Running Python samples
1. Go to test directory:
```shell
cd python/creating_basic_form
```
2. If it is needed, edit path to builder directory at the beginning of the python script:
```py
sys.path.append('C:/Program Files/ONLYOFFICE/DocumentBuilder')
```
3. Run the script
```shell
python main.py
```
Documents will be created in the test directory.
## Running Java samples
> **NOTE:** JDK 8 or newer is required
1. Go to test directory:
```shell
cd java/creating_presentation
```
2. Compile the `Program.java` providing the path to ***docbuilder.jar***, located in the Document Builder directory:
```shell
javac -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar" Program.java
```
3. `.class` file should appear in the directory. Run the program:
```shell
java -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar;." Program
```
Note, that on UNIX systems the path separator is `:` instead of `;`. Thus, on Linux or Mac OS it should be:
```shell
java -cp "/opt/onlyoffice/documentbuilder/docbuilder.jar:." Program
```
3. Documents will be created in the test directory.

View File

@ -0,0 +1,293 @@
import os
import argparse
import platform
import uuid
langs = ['cpp', 'cs']
os_name = platform.system().lower()
def mkdir(dir):
if not os.path.exists(dir):
os.mkdir(dir)
def log(level, message):
print('configure.py: ' + level + ': ' + message)
def getDefaultBuilderDir():
dir = ''
if os_name == 'windows':
dir = 'C:\\Program Files\\ONLYOFFICE\\DocumentBuilder'
elif os_name == 'linux':
dir = '/opt/onlyoffice/documentbuilder'
return dir
def getAllTests():
tests = {}
for lang in langs:
tests[lang] = []
test_dirs = os.listdir(lang)
for test_dir in test_dirs:
if not os.path.isdir(lang + '/' + test_dir):
continue
tests[lang].append(lang + '/' + test_dir)
return tests
def printAvailableTests():
all_tests = getAllTests()
print('all')
for lang in langs:
print('-----')
print(lang)
tests = all_tests[lang]
for test in tests:
print(test)
class PrintTestsList(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
printAvailableTests()
exit()
def getSelectedTests(tests):
all_tests = getAllTests()
# make set of all available tests
tests_set = {'all'}
for lang in langs:
tests_set.add(lang)
tests_set.update(all_tests[lang])
# make dict with set of selected tests
tests_selected = {lang: set() for lang in langs}
# filter tests through only available ones
for test in tests:
if not test in tests_set:
log('warning', 'wrong test "' + test + '". Call script with --list (or -l) to see all available tests')
continue
if test == 'all':
for lang in langs:
tests_selected[lang].update(all_tests[lang])
elif not '/' in test:
lang = test
tests_selected[lang].update(all_tests[lang])
else:
lang = test.split('/')[0]
tests_selected[lang].add(test)
# delete empty tests
for lang in langs:
if not tests_selected[lang]:
del tests_selected[lang]
return tests_selected
def replacePlaceholders(template_file, output_file, replacements):
content = ''
# open and read template file
with open(template_file, 'r') as file:
content = file.read()
# replace all placeholders with corresponding values
for placeholder, replacement in replacements.items():
content = content.replace(placeholder, replacement)
# write result to output file
with open(output_file, 'w') as file:
file.write(content)
def genVSProjectsCPP(tests, builder_dir):
for test in tests:
test_dir = 'out/' + test
mkdir(test_dir)
test_name = test.split('/')[1]
if os.path.exists(test_dir + '/' + test_name + '.vcxproj'):
log('info', 'VS C++ project for sample "' + test + '" already exists. Skipping.')
continue
else:
log('info', 'generating VS C++ project for sample "' + test + '"...')
# .vcxproj
project_guid = str(uuid.uuid4())
replacements = {
'[PROJECT_GUID]': project_guid,
'[TEST_NAME]': test_name,
'[BUILDER_DIR]': builder_dir,
'[ROOT_DIR]': os.getcwd()
}
replacePlaceholders('configure/project_templates/cpp/template.vcxproj', test_dir + '/' + test_name + '.vcxproj', replacements)
# .sln
replacements = {
'[SOLUTION_GUID]': str(uuid.uuid4()).upper(),
'[TEST_NAME]': test_name,
'[PROJECT_GUID]': project_guid.upper(),
'[EXT_GLOBALS_GUID]': str(uuid.uuid4()).upper()
}
replacePlaceholders('configure/project_templates/cpp/template.sln', test_dir + '/' + test_name + '.sln', replacements)
# .vcxproj.filters
replacements = {
'[GUID_SOURCE_FILES]': str(uuid.uuid4()).upper(),
'[GUID_HEADER_FILES]': str(uuid.uuid4()).upper(),
'[GUID_RESOURCE_FILES]': str(uuid.uuid4()).upper(),
'[TEST_NAME]': test_name
}
replacePlaceholders('configure/project_templates/cpp/template.vcxproj.filters', test_dir + '/' + test_name + '.vcxproj.filters', replacements)
# .vcxproj.user
replacements = {
'[BUILDER_DIR]': builder_dir
}
replacePlaceholders('configure/project_templates/cpp/template.vcxproj.user', test_dir + '/' + test_name + '.vcxproj.user', replacements)
def genVSProjectsCS(tests, builder_dir):
for test in tests:
test_dir = 'out/' + test
mkdir(test_dir)
test_name = test.split('/')[1]
if os.path.exists(test_dir + '/' + test_name + '.csproj'):
log('info', 'VS C# project for sample "' + test + '" already exists. Skipping.')
continue
else:
log('info', 'generating VS C# project for sample "' + test + '"...')
# .csproj
project_guid = str(uuid.uuid4())
replacements = {
'[TEST_NAME]': test_name,
'[BUILDER_DIR]': builder_dir,
}
replacePlaceholders('configure/project_templates/cs/template.csproj', test_dir + '/' + test_name + '.csproj', replacements)
# .sln
replacements = {
'[SOLUTION_GUID]': str(uuid.uuid4()).upper(),
'[TEST_NAME]': test_name,
'[PROJECT_GUID]': project_guid.upper(),
'[EXT_GLOBALS_GUID]': str(uuid.uuid4()).upper()
}
replacePlaceholders('configure/project_templates/cs/template.sln', test_dir + '/' + test_name + '.sln', replacements)
def genVSProjects(tests_selected, builder_dir):
if os_name != 'windows':
log('warning', 'generating Visual Studio projects is only available on Windows')
return
builder_dir = builder_dir.replace('/', '\\')
for lang, tests in tests_selected.items():
mkdir('out/' + lang)
if lang == 'cpp':
genVSProjectsCPP(tests, builder_dir)
elif lang == 'cs':
genVSProjectsCS(tests, builder_dir)
def genQtProjects(tests_selected, builder_dir):
# only for C++ projects
if 'cpp' not in tests_selected:
return
root_dir = os.getcwd()
if os_name == 'windows':
builder_dir = builder_dir.replace('\\', '/')
root_dir = root_dir.replace('\\', '/')
tests = tests_selected['cpp']
mkdir('out/cpp')
for test in tests:
test_dir = 'out/' + test
mkdir(test_dir)
test_name = test.split('/')[1]
if os.path.exists(test_dir + '/' + test_name + '.pro'):
log('info', 'Qt project for sample "' + test + '" already exists. Skipping.')
continue
else:
log('info', 'generating Qt C++ project for sample "' + test + '"...')
# .pro
replacements = {
'[TEST_NAME]': test_name,
'[BUILDER_DIR]': builder_dir,
'[ROOT_DIR]': root_dir
}
replacePlaceholders('configure/project_templates/cpp/template.pro', test_dir + '/' + test_name + '.pro', replacements)
def genMakefile(tests_selected, builder_dir):
# only for C++ projects
if 'cpp' not in tests_selected:
return
if os_name == 'windows':
log('warning', 'generating Makefile is not available on Windows')
return
# initialize variables
compiler = ''
lflags = ''
env_lib_path = ''
if os_name == 'linux':
compiler = 'g++'
lflags = '-Wl,--unresolved-symbols=ignore-in-shared-libs'
env_lib_path = 'LD_LIBRARY_PATH'
elif os_name == 'darwin':
compiler = 'clang++'
env_lib_path = 'DYLD_LIBRARY_PATH'
root_dir = os.getcwd()
tests = tests_selected['cpp']
mkdir('out/cpp')
for test in tests:
test_dir = 'out/' + test
mkdir(test_dir)
test_name = test.split('/')[1]
if os.path.exists(test_dir + '/Makefile'):
log('info', 'Makefile for sample "' + test + '" already exists. Skipping.')
else:
log('info', 'generating Makefile for C++ sample "' + test + '"...')
continue
# Makefile
replacements = {
'[TEST_NAME]': test_name,
'[BUILDER_DIR]': builder_dir,
'[ROOT_DIR]': root_dir,
'[COMPILER]': compiler,
'[LFLAGS]': lflags,
'[ENV_LIB_PATH]': env_lib_path
}
replacePlaceholders('configure/project_templates/cpp/Makefile', test_dir + '/Makefile', replacements)
if __name__ == '__main__':
# go to root dir
file_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(file_dir + '/..')
# initialize argument parser
parser = argparse.ArgumentParser(description='Generate project files for Document Builder samples')
parser.add_argument('--vs', action='store_true', help='create Visual Studio (.vcxproj and .csproj) project files')
parser.add_argument('--qt', action='store_true', help='create Qt (.pro) project files')
parser.add_argument('--make', action='store_true', help='create Makefile')
parser.add_argument('-t', '--test', dest='tests', action='append', help='specifies tests to generate project files', required=True)
parser.add_argument('-l', '--list', action=PrintTestsList, nargs=0, help='show list of available tests and exit')
builder_dir = getDefaultBuilderDir()
if builder_dir:
parser.add_argument('--dir', action='store', help='specifies Document Builder directory (default: ' + builder_dir + ')', default=builder_dir)
else:
parser.add_argument('--dir', action='store', help='specifies Document Builder directory', required=True)
args = parser.parse_args()
# validate arguments
if not os.path.exists(args.dir):
log('error', 'Document Builder directory doesn\'t exist: ' + args.dir)
exit(1)
if not (args.vs or args.qt or args.make):
if os_name == 'windows':
args.vs = True
args.qt = True
if os_name != 'windows':
args.make = True
# filter tests
tests_selected = getSelectedTests(args.tests)
# generate projects
mkdir('out')
# VS
if args.vs:
genVSProjects(tests_selected, args.dir)
elif 'cs' in tests_selected:
log('warning', 'generating C# projects only available ' + ('on Windows ' if os_name != 'windows' else '') + 'with --vs')
# Qt
if args.qt:
genQtProjects(tests_selected, args.dir)
# Makefile
if args.make:
genMakefile(tests_selected, args.dir)

View File

@ -0,0 +1,29 @@
CXX = [COMPILER]
CXXFLAGS = -std=gnu++11 -Wall -W -fPIC
INCPATH = -I[BUILDER_DIR]/include -I[ROOT_DIR]
LINK = [COMPILER]
LFLAGS = [LFLAGS]
LIBS = -L[BUILDER_DIR] -ldoctrenderer
BUILD_DIR = build
SRC = ../../../cpp/[TEST_NAME]/main.cpp
OBJ = $(BUILD_DIR)/main.o
TARGET = $(BUILD_DIR)/[TEST_NAME]
.PHONY: all run clean
all: $(TARGET) run
$(TARGET): $(OBJ)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJ) $(LIBS)
$(OBJ): $(SRC)
@test -d $(BUILD_DIR) || mkdir -p $(BUILD_DIR)
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJ) $(SRC)
run: $(TARGET)
[ENV_LIB_PATH]="[BUILDER_DIR]" ./$(TARGET)
clean:
@rm -rf $(BUILD_DIR)

View File

@ -0,0 +1,17 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
TARGET = [TEST_NAME]
DESTDIR = $$PWD/build
BUILDER_DIR = "[BUILDER_DIR]"
ROOT_DIR = "[ROOT_DIR]"
INCLUDEPATH += $$BUILDER_DIR/include
INCLUDEPATH += $$ROOT_DIR
LIBS += -L$$BUILDER_DIR -ldoctrenderer
linux: QMAKE_LFLAGS += -Wl,--unresolved-symbols=ignore-in-shared-libs
SOURCES += ../../../cpp/[TEST_NAME]/main.cpp

View File

@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 12.00
MinimumVisualStudioVersion = 10.0.40219.1
Project("{[SOLUTION_GUID]}") = "[TEST_NAME]", "[TEST_NAME].vcxproj", "{[PROJECT_GUID]}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{[PROJECT_GUID]}.Debug|x64.ActiveCfg = Debug|x64
{[PROJECT_GUID]}.Debug|x64.Build.0 = Debug|x64
{[PROJECT_GUID]}.Debug|x86.ActiveCfg = Debug|Win32
{[PROJECT_GUID]}.Debug|x86.Build.0 = Debug|Win32
{[PROJECT_GUID]}.Release|x64.ActiveCfg = Release|x64
{[PROJECT_GUID]}.Release|x64.Build.0 = Release|x64
{[PROJECT_GUID]}.Release|x86.ActiveCfg = Release|Win32
{[PROJECT_GUID]}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {[EXT_GLOBALS_GUID]}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{[PROJECT_GUID]}</ProjectGuid>
<RootNamespace>[TEST_NAME]</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>[BUILDER_DIR]\include;[ROOT_DIR];$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>[BUILDER_DIR]\include;[ROOT_DIR];$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>[BUILDER_DIR];%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>doctrenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>[BUILDER_DIR];%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>doctrenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\cpp\[TEST_NAME]\main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{[GUID_SOURCE_FILES]}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{[GUID_HEADER_FILES]}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{[GUID_RESOURCE_FILES]}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\cpp\[TEST_NAME]\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerEnvironment>PATH=[BUILDER_DIR];%PATH%
$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerEnvironment>PATH=[BUILDER_DIR];%PATH%
$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\cs\[TEST_NAME]\Program.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="[BUILDER_DIR]\docbuilder.net.dll" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
MinimumVisualStudioVersion = 10.0.40219.1
Project("{[SOLUTION_GUID]}") = "[TEST_NAME]", "[TEST_NAME].csproj", "{[PROJECT_GUID]}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{[PROJECT_GUID]}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{[PROJECT_GUID]}.Debug|Any CPU.Build.0 = Debug|Any CPU
{[PROJECT_GUID]}.Release|Any CPU.ActiveCfg = Release|Any CPU
{[PROJECT_GUID]}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {[EXT_GLOBALS_GUID]}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,90 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <string>
#include "common.h"
#include "docbuilder.h"
#include "resources/utils/utils.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.xlsx";
// Helper functions
void CheckCell(CValue oWorksheet, wstring cell, int row, int col)
{
if (cell.find('#') != std::wstring::npos)
{
wstring commentMsg = L"Error: " + cell;
CValue errorCell = oWorksheet.Call("GetRangeByNumber", row, col);
errorCell.Call("AddComment", commentMsg.c_str());
}
}
// Main function
int main()
{
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
// Open file and get context
wstring templatePath = NSUtils::GetResourcesDirectory() + L"/docs/spreadsheet_with_errors.xlsx";
oBuilder.OpenFile(templatePath.c_str(), L"");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Find and comment formula errors
CValue oWorksheet = oApi.Call("GetActiveSheet");
CValue oRange = oWorksheet.Call("GetUsedRange");
CValue data = oRange.Call("GetValue");
for (int row = 0; row < (int)data.GetLength(); row++)
{
for (int col = 0; col < (int)data[0].GetLength(); col++)
{
CheckCell(oWorksheet, data[row][col].ToString().c_str(), row, col);
}
}
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_SPREADSHEET_XLSX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,206 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <string>
#include "common.h"
#include "docbuilder.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.docx";
// Helper functions
string cValueToString(CValue value)
{
wchar_t* txt = value.ToString().c_str();
wstring ws(txt);
string str(ws.begin(), ws.end());
return str;
}
void setTableBorders(CValue oTable, int borderColor)
{
oTable.Call("SetTableBorderTop", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderBottom", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderLeft", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderRight", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderInsideV", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderInsideH", "single", 4, 0, borderColor, borderColor, borderColor);
}
CValue createFullWidthTable(CValue oApi, int rows, int cols, int borderColor)
{
CValue oTable = oApi.Call("CreateTable", cols, rows);
oTable.Call("SetWidth", "percent", 100);
setTableBorders(oTable, borderColor);
return oTable;
}
CValue getTableCellParagraph(CValue oTable, int row, int col)
{
return oTable.Call("GetCell", row, col).Call("GetContent").Call("GetElement", 0);
}
void addTextToParagraph(CValue oParagraph, std::string text, int fontSize, bool isBold)
{
oParagraph.Call("AddText", text.c_str());
oParagraph.Call("SetFontSize", fontSize);
oParagraph.Call("SetBold", isBold);
}
void setPictureFormProperties(CValue oPictureForm, std::string key, std::string tip, bool required, std::string placeholder, std::string scaleFlag, bool lockAspectRatio, bool respectBorders, int shiftX, int shiftY, std::string imageUrl)
{
oPictureForm.Call("SetFormKey", key.c_str());
oPictureForm.Call("SetTipText", tip.c_str());
oPictureForm.Call("SetRequired", required);
oPictureForm.Call("SetPlaceholderText", placeholder.c_str());
oPictureForm.Call("SetScaleFlag", scaleFlag.c_str());
oPictureForm.Call("SetLockAspectRatio", lockAspectRatio);
oPictureForm.Call("SetRespectBorders", respectBorders);
oPictureForm.Call("SetPicturePosition", shiftX, shiftY);
oPictureForm.Call("SetImage", imageUrl.c_str());
}
void setTextFormProperties(CValue oTextForm, string key, string tip, bool required, string placeholder, bool comb, int maxCharacters, int cellWidth, bool multiLine, bool autoFit)
{
oTextForm.Call("SetFormKey", key.c_str());
oTextForm.Call("SetTipText", tip.c_str());
oTextForm.Call("SetRequired", required);
oTextForm.Call("SetPlaceholderText", placeholder.c_str());
oTextForm.Call("SetComb", comb);
oTextForm.Call("SetCharactersLimit", maxCharacters);
oTextForm.Call("SetCellWidth", cellWidth);
oTextForm.Call("SetCellWidth", multiLine);
oTextForm.Call("SetMultiline", autoFit);
}
void addTextFormToParagraph(CValue oParagraph, CValue oTextForm, int fontSize, string jc, bool hasBorder, int borderColor)
{
if (hasBorder)
{
oTextForm.Call("SetBorderColor", borderColor, borderColor, borderColor);
}
oParagraph.Call("AddElement", oTextForm);
oParagraph.Call("SetFontSize", fontSize);
oParagraph.Call("SetJc", jc.c_str());
}
// Main function
int main()
{
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
oBuilder.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Create advanced form
CValue oDocument = oApi.Call("GetDocument");
CValue oTable = createFullWidthTable(oApi, 1, 2, 255);
CValue oParagraph = getTableCellParagraph(oTable, 0, 0);
addTextToParagraph(oParagraph, "PURCHASE ORDER", 36, true);
oParagraph = getTableCellParagraph(oTable, 0, 1);
addTextToParagraph(oParagraph, "Serial # ", 25, true);
CValue oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Serial", "Enter serial number", false, "Serial", true, 6, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 25, "left", true, 255);
oDocument.Call("Push", oTable);
CValue oPictureForm = oApi.Call("CreatePictureForm");
setPictureFormProperties(oPictureForm, "Photo", "Upload company logo", false, "Photo", "tooBig", false, false, 0, 0, "https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oPictureForm);
oDocument.Call("Push", oParagraph);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Company Name", "Enter company name", false, "Company Name", true, 20, 1, false, false);
oParagraph = oApi.Call("CreateParagraph");
addTextFormToParagraph(oParagraph, oTextForm, 35, "left", false, 255);
oDocument.Call("Push", oParagraph);
oParagraph = oApi.Call("CreateParagraph");
addTextToParagraph(oParagraph, "Date: ", 25, true);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Date", "Date", false, "DD.MM.YYYY", true, 10, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 25, "left", true, 255);
oDocument.Call("Push", oParagraph);
oParagraph = oApi.Call("CreateParagraph");
addTextToParagraph(oParagraph, "To:", 35, true);
oDocument.Call("Push", oParagraph);
oTable = createFullWidthTable(oApi, 1, 1, 200);
oParagraph = getTableCellParagraph(oTable, 0, 0);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Recipient", "Recipient", false, "Recipient", true, 25, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 32, "left", false, 255);
oDocument.Call("Push", oTable);
oTable = createFullWidthTable(oApi, 10, 2, 200);
oTable.Call("GetRow", 0).Call("SetBackgroundColor", 245, 245, 245, false);
CValue oCell = oTable.Call("GetCell", 0, 0);
oCell.Call("SetWidth", "percent", 30);
oParagraph = getTableCellParagraph(oTable, 0, 0);
addTextToParagraph(oParagraph, "Qty.", 30, true);
oParagraph = getTableCellParagraph(oTable, 0, 1);
addTextToParagraph(oParagraph, "Description", 30, true);
for (int i = 1; i < 10; i++)
{
CValue oTempParagraph = getTableCellParagraph(oTable, i, 0);
CValue oTempTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTempTextForm, "Qty" + std::to_string(i), "Qty" + std::to_string(i), false, " ", true, 9, 1, false, false);
addTextFormToParagraph(oTempParagraph, oTempTextForm, 30, "left", false, 255);
oTempParagraph = getTableCellParagraph(oTable, i, 1);
oTempTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTempTextForm, "Description" + std::to_string(i), "Description" + std::to_string(i), false, " ", true, 22, 1, false, false);
addTextFormToParagraph(oTempParagraph, oTempTextForm, 30, "left", false, 255);
}
oDocument.Call("Push", oTable);
oDocument.Call("RemoveElement", 0);
oDocument.Call("RemoveElement", 1);
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,108 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <string>
#include "common.h"
#include "docbuilder.h"
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.docx";
// Helper functions
void setPictureFormProperties(CValue oPictureForm, std::string key, std::string tip, bool required, std::string placeholder, std::string scaleFlag, bool lockAspectRatio, bool respectBorders, int shiftX, int shiftY, std::string imageUrl)
{
oPictureForm.Call("SetFormKey", key.c_str());
oPictureForm.Call("SetTipText", tip.c_str());
oPictureForm.Call("SetRequired", required);
oPictureForm.Call("SetPlaceholderText", placeholder.c_str());
oPictureForm.Call("SetScaleFlag", scaleFlag.c_str());
oPictureForm.Call("SetLockAspectRatio", lockAspectRatio);
oPictureForm.Call("SetRespectBorders", respectBorders);
oPictureForm.Call("SetPicturePosition", shiftX, shiftY);
oPictureForm.Call("SetImage", imageUrl.c_str());
}
void setTextFormProperties(CValue oTextForm, std::string key, std::string tip, bool required, std::string placeholder, bool comb, int maxCharacters, int cellWidth, bool multiLine, bool autoFit)
{
oTextForm.Call("SetFormKey", key.c_str());
oTextForm.Call("SetTipText", tip.c_str());
oTextForm.Call("SetRequired", required);
oTextForm.Call("SetPlaceholderText", placeholder.c_str());
oTextForm.Call("SetComb", comb);
oTextForm.Call("SetCharactersLimit", maxCharacters);
oTextForm.Call("SetCellWidth", cellWidth);
oTextForm.Call("SetCellWidth", multiLine);
oTextForm.Call("SetMultiline", autoFit);
}
// Main function
int main()
{
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
oBuilder.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Create basic form
CValue oDocument = oApi.Call("GetDocument");
CValue oParagraph = oDocument.Call("GetElement", 0);
CValue oHeadingStyle = oDocument.Call("GetStyle", "Heading 3");
oParagraph.Call("AddText", "Employee pass card");
oParagraph.Call("SetStyle", oHeadingStyle);
oDocument.Call("Push", oParagraph);
CValue oPictureForm = oApi.Call("CreatePictureForm");
setPictureFormProperties(oPictureForm, "Photo", "Upload your photo", false, "Photo", "tooBig", true, false, 50, 50, "https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oPictureForm);
oDocument.Call("Push", oParagraph);
CValue oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "First name", "Enter your first name", false, "First name", true, 13, 3, false, false);
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oTextForm);
oDocument.Call("Push", oParagraph);
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,156 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <string>
#include <vector>
#include "common.h"
#include "docbuilder.h"
#include "resources/utils/utils.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.pptx";
void addText(CValue oApi, int fontSize, string text, CValue oSlide, CValue oShape, CValue oParagraph, CValue oFill, string jc)
{
CValue oRun = oApi.Call("CreateRun");
CValue oTextPr = oRun.Call("GetTextPr");
oTextPr.Call("SetFontSize", fontSize);
oTextPr.Call("SetFill", oFill);
oTextPr.Call("SetFontFamily", "Tahoma");
oParagraph.Call("SetJc", jc.c_str());
oRun.Call("AddText", text.c_str());
oRun.Call("AddLineBreak");
oParagraph.Call("AddElement", oRun);
oSlide.Call("AddObject", oShape);
}
// Main function
int main()
{
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
// Read chart data from xlsx
wstring templatePath = NSUtils::GetResourcesDirectory() + L"/docs/chart_data.xlsx";
oBuilder.OpenFile(templatePath.c_str(), L"");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
CValue oWorksheet = oApi.Call("GetActiveSheet");
CValue values = oWorksheet.Call("GetUsedRange").Call("GetValue");
int sizeX = values.GetLength();
int sizeY = values[0].GetLength();
vector<vector<wstring>> data(sizeX, vector<wstring>(sizeY));
for (int i = 0; i < sizeX; i++)
{
for (int j = 0; j < sizeY; j++)
{
data[i][j] = values[i][j].ToString().c_str();
}
}
oBuilder.CloseFile();
// Create chart presentation
oBuilder.CreateFile(OFFICESTUDIO_FILE_PRESENTATION_PPTX);
oContext = oBuilder.GetContext();
oScope = oContext.CreateScope();
oGlobal = oContext.GetGlobal();
oApi = oGlobal["Api"];
CValue oPresentation = oApi.Call("GetPresentation");
CValue oSlide = oPresentation.Call("GetSlideByIndex", 0);
oSlide.Call("RemoveAllObjects");
CValue oRGBColor = oApi.Call("CreateRGBColor", 255, 244, 240);
CValue oFill = oApi.Call("CreateSolidFill", oRGBColor);
oSlide.Call("SetBackground", oFill);
CValue oStroke = oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill"));
CValue oShapeTitle = oApi.Call("CreateShape", "rect", 300 * 36000, 20 * 36000, oApi.Call("CreateNoFill"), oStroke);
CValue oShapeText = oApi.Call("CreateShape", "rect", 120 * 36000, 80 * 36000, oApi.Call("CreateNoFill"), oStroke);
oShapeTitle.Call("SetPosition", 20 * 36000, 20 * 36000);
oShapeText.Call("SetPosition", 210 * 36000, 50 * 36000);
CValue oParagraphTitle = oShapeTitle.Call("GetDocContent").Call("GetElement", 0);
CValue oParagraphText = oShapeText.Call("GetDocContent").Call("GetElement", 0);
oRGBColor = oApi.Call("CreateRGBColor", 115, 81, 68);
oFill = oApi.Call("CreateSolidFill", oRGBColor);
string titleContent = "Price Type Report";
string textContent = "This is an overview of price types. As we can see, May was the price peak, but even in June the price went down, the annual upward trend persists.";
addText(oApi, 80, titleContent, oSlide, oShapeTitle, oParagraphTitle, oFill, "center");
addText(oApi, 42, textContent, oSlide, oShapeText, oParagraphText, oFill, "left");
// Transform 2d array into cols names, rows names and data
CValue cols = oContext.CreateArray(sizeY - 1);
for (int col = 1; col < sizeY; col++)
{
cols[col - 1] = data[0][col].c_str();
}
CValue rows = oContext.CreateArray(sizeX - 1);
for (int row = 1; row < sizeX; row++)
{
rows[row - 1] = data[row][0].c_str();
}
CValue vals = oContext.CreateArray(sizeY - 1);
for (int row = 1; row < sizeY; row++)
{
CValue row_data = oContext.CreateArray(sizeX - 1);
for (int col = 1; col < sizeX; col++)
{
row_data[col - 1] = data[col][row].c_str();
}
vals[row - 1] = row_data;
}
// Pass CValue data to the CreateChart method
CValue oChart = oApi.Call("CreateChart", "lineStacked", vals, cols, rows);
oChart.Call("SetSize", 180 * 36000, 100 * 36000);
oChart.Call("SetPosition", 20 * 36000, 50 * 36000);
oChart.Call("ApplyChartStyle", 24);
oChart.Call("SetLegendFontSize", 12);
oChart.Call("SetLegendPos", "top");
oSlide.Call("AddObject", oChart);
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_PRESENTATION_PPTX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,156 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <map>
#include <string>
#include "common.h"
#include "docbuilder.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.pptx";
// Helper functions
CValue createImageSlide(CValue oApi, CValue oPresentation, string image_url)
{
CValue oSlide = oApi.Call("CreateSlide");
oPresentation.Call("AddSlide", oSlide);
CValue oFill = oApi.Call("CreateBlipFill", image_url.c_str(), "stretch");
oSlide.Call("SetBackground", oFill);
oSlide.Call("RemoveAllObjects");
return oSlide;
}
void addTextToSlideShape(CValue oApi, CValue oContent, string text, int fontSize, bool isBold, string js)
{
CValue oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("SetSpacingBefore", 0);
oParagraph.Call("SetSpacingAfter", 0);
oContent.Call("Push", oParagraph);
CValue oRun = oParagraph.Call("AddText", text.c_str());
oRun.Call("SetFill", oApi.Call("CreateSolidFill", oApi.Call("CreateRGBColor", 0xff, 0xff, 0xff)));
oRun.Call("SetFontSize", fontSize);
oRun.Call("SetFontFamily", "Georgia");
oRun.Call("SetBold", isBold);
oParagraph.Call("SetJc", js.c_str());
}
// Main function
int main()
{
map<string, string>slideImages;
slideImages["gun"] = "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_gun.png";
slideImages["axe"] = "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_axe.png";
slideImages["knight"] = "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_knight.png";
slideImages["sky"] = "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_sky.png";
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
oBuilder.CreateFile(OFFICESTUDIO_FILE_PRESENTATION_PPTX);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Create presentation
CValue oPresentation = oApi.Call("GetPresentation");
oPresentation.Call("SetSizes", 9144000, 6858000);
CValue oSlide = createImageSlide(oApi, oPresentation, slideImages["gun"]);
oPresentation.Call("GetSlideByIndex", 0).Call("Delete");
CValue oShape = oApi.Call("CreateShape", "rect", 8056800, 3020400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 608400, 1267200);
CValue oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "How They", 160, true, "left");
addTextToSlideShape(oApi, oContent, "Throw Out", 132, false, "left");
addTextToSlideShape(oApi, oContent, "a Challenge", 132, false, "left");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["axe"]);
oShape = oApi.Call("CreateShape", "rect", 6904800, 1724400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 1764000, 1191600);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "American Indians ", 110, true, "right");
addTextToSlideShape(oApi, oContent, "(XVII century)", 94, false, "right");
oSlide.Call("AddObject", oShape);
oShape = oApi.Call("CreateShape", "rect", 4986000, 2419200, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 3834000, 3888000);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "put a tomahawk on the ground in the ", 84, false, "right");
addTextToSlideShape(oApi, oContent, "rival's camp", 84, false, "right");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["knight"]);
oShape = oApi.Call("CreateShape", "rect", 6904800, 1724400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 1764000, 1191600);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "European Knights", 110, true, "right");
addTextToSlideShape(oApi, oContent, " (XII-XVI centuries)", 94, false, "right");
oSlide.Call("AddObject", oShape);
oShape = oApi.Call("CreateShape", "rect", 4986000, 2419200, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 3834000, 3888000);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "threw a glove", 84, false, "right");
addTextToSlideShape(oApi, oContent, "in the rival's face", 84, false, "right");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["sky"]);
oShape = oApi.Call("CreateShape", "rect", 7887600, 3063600, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 630000, 1357200);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "OnlyOffice", 176, false, "center");
addTextToSlideShape(oApi, oContent, "stands for Peace", 132, false, "center");
oSlide.Call("AddObject", oShape);
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_PRESENTATION_PPTX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,94 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <map>
#include <string>
#include "common.h"
#include "docbuilder.h"
#include "resources/utils/utils.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.docx";
// Main function
int main()
{
std::map<wstring, wstring> formData;
formData[L"Photo"] = L"https://api.onlyoffice.com/content/img/docbuilder/examples/blue_cloud.png";
formData[L"Serial"] = L"A1345";
formData[L"Company Name"] = L"Blue Cloud";
formData[L"Date"] = L"25.12.2023";
formData[L"Recipient"] = L"Space Corporation";
formData[L"Qty1"] = L"25";
formData[L"Description1"] = L"Frame";
formData[L"Qty2"] = L"2";
formData[L"Description2"] = L"Stack";
formData[L"Qty3"] = L"34";
formData[L"Description3"] = L"Shifter";
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
wstring templatePath = NSUtils::GetResourcesDirectory() + L"/docs/form.docx";
oBuilder.OpenFile(templatePath.c_str(), L"");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Fill form
CValue oDocument = oApi.Call("GetDocument");
CValue aForms = oDocument.Call("GetAllForms");
int formNum = 0;
while (formNum < (int)aForms.GetLength())
{
CValue form = aForms[formNum];
wstring type = aForms[formNum].Call("GetFormType").ToString().c_str();
wstring value = formData[aForms[formNum].Call("GetFormKey").ToString().c_str()];
if (type == L"textForm") form.Call("SetText", value.c_str());
if (type == L"pictureForm") form.Call("SetImage", value.c_str());
formNum++;
}
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,100 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include <string>
#include "common.h"
#include "docbuilder.h"
using namespace std;
using namespace NSDoctRenderer;
const wchar_t* workDir = L"C:\\Program Files\\ONLYOFFICE\\DocumentBuilder";
const wchar_t* resultPath = L"result.xlsx";
// Main function
int main()
{
string data[9][4] = {
{ "Id", "Product", "Price", "Available" },
{ "1001", "Item A", "12.2", "true" },
{ "1002", "Item B", "18.8", "true" },
{ "1003", "Item C", "70.1", "false" },
{ "1004", "Item D", "60.6", "true" },
{ "1005", "Item E", "32.6", "true" },
{ "1006", "Item F", "28.3", "false" },
{ "1007", "Item G", "11.1", "false" },
{ "1008", "Item H", "41.4", "true" }
};
// Init DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder oBuilder;
oBuilder.SetProperty("--work-directory", workDir);
oBuilder.CreateFile(OFFICESTUDIO_FILE_SPREADSHEET_XLSX);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Find and comment formula errors
CValue oWorksheet = oApi.Call("GetActiveSheet");
// Create CValue array from data
int rowsLen = sizeof data / sizeof data[0];
int colsLen = sizeof data[0] / sizeof(string);
CValue oArray = oContext.CreateArray(rowsLen);
for (int row = 0; row < rowsLen; row++)
{
CValue oArrayCol = oContext.CreateArray(colsLen);
for (int col = 0; col < colsLen; col++)
{
oArrayCol[col] = data[row][col].c_str();
}
oArray[row] = oArrayCol;
}
// First cell in the range (A1) is equal to (0,0)
CValue startCell = oWorksheet.Call("GetRangeByNumber", 0, 0);
// Last cell in the range is equal to array length -1
CValue endCell = oWorksheet.Call("GetRangeByNumber", oArray.GetLength() - 1, oArray[0].GetLength() - 1);
oWorksheet.Call("GetRange", startCell, endCell).Call("SetValue", oArray);
// Save and close
oBuilder.SaveFile(OFFICESTUDIO_FILE_SPREADSHEET_XLSX, resultPath);
oBuilder.CloseFile();
CDocBuilder::Dispose();
return 0;
}

View File

@ -0,0 +1,98 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
namespace Sample
{
public class CommentingErrors
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.xlsx";
string filePath = "../../../../../../resources/docs/spreadsheet_with_errors.xlsx";
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
CommentErrors(workDirectory, resultPath, filePath);
}
public static void CommentErrors(string workDirectory, string resultPath, string filePath)
{
var doctype = (int)OfficeFileTypes.Spreadsheet.XLSX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.OpenFile(filePath, "xlsx");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Find and comment formula errors
CValue oWorksheet = oApi.Call("GetActiveSheet");
CValue oRange = oWorksheet.Call("GetUsedRange");
var data = oRange.Call("GetValue");
for (int row = 0; row < data.GetLength(); row++)
{
for (int col = 0; col < data[0].GetLength(); col++)
{
CheckCell(oWorksheet, data[row][col].ToString(), row, col);
}
}
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static void CheckCell(CValue oWorksheet, string cell, int row, int col)
{
if (cell.Contains("#"))
{
string comment = "Error" + cell;
CValue errorCell = oWorksheet.Call("GetRangeByNumber", row, col);
errorCell.Call("AddComment", comment);
}
}
}
}

View File

@ -0,0 +1,212 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
namespace Sample
{
public class CreatingAdvancedForm
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.docx";
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
CreateAdvancedForm(workDirectory, resultPath);
}
public static void CreateAdvancedForm(string workDirectory, string resultPath)
{
var doctype = (int)OfficeFileTypes.Document.DOCX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.CreateFile(doctype);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Create advanced form
CValue oDocument = oApi.Call("GetDocument");
CValue oTable = createFullWidthTable(oApi, 1, 2, 255);
CValue oParagraph = getTableCellParagraph(oTable, 0, 0);
addTextToParagraph(oParagraph, "PURCHASE ORDER", 36, true);
oParagraph = getTableCellParagraph(oTable, 0, 1);
addTextToParagraph(oParagraph, "Serial # ", 25, true);
CValue oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Serial", "Enter serial number", false, "Serial", true, 6, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 25, "left", true, 255);
oDocument.Call("Push", oTable);
CValue oPictureForm = oApi.Call("CreatePictureForm");
setPictureFormProperties(oPictureForm, "Photo", "Upload company logo", false, "Photo", "tooBig", false, false, 0, 0, "https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oPictureForm);
oDocument.Call("Push", oParagraph);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Company Name", "Enter company name", false, "Company Name", true, 20, 1, false, false);
oParagraph = oApi.Call("CreateParagraph");
addTextFormToParagraph(oParagraph, oTextForm, 35, "left", false, 255);
oDocument.Call("Push", oParagraph);
oParagraph = oApi.Call("CreateParagraph");
addTextToParagraph(oParagraph, "Date: ", 25, true);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Date", "Date", false, "DD.MM.YYYY", true, 10, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 25, "left", true, 255);
oDocument.Call("Push", oParagraph);
oParagraph = oApi.Call("CreateParagraph");
addTextToParagraph(oParagraph, "To:", 35, true);
oDocument.Call("Push", oParagraph);
oTable = createFullWidthTable(oApi, 1, 1, 200);
oParagraph = getTableCellParagraph(oTable, 0, 0);
oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "Recipient", "Recipient", false, "Recipient", true, 25, 1, false, false);
addTextFormToParagraph(oParagraph, oTextForm, 32, "left", false, 255);
oDocument.Call("Push", oTable);
oTable = createFullWidthTable(oApi, 10, 2, 200);
oTable.Call("GetRow", 0).Call("SetBackgroundColor", 245, 245, 245, false);
CValue oCell = oTable.Call("GetCell", 0, 0);
oCell.Call("SetWidth", "percent", 30);
oParagraph = getTableCellParagraph(oTable, 0, 0);
addTextToParagraph(oParagraph, "Qty.", 30, true);
oParagraph = getTableCellParagraph(oTable, 0, 1);
addTextToParagraph(oParagraph, "Description", 30, true);
for (var i = 1; i < 10; i++)
{
CValue oTempParagraph = getTableCellParagraph(oTable, i, 0);
CValue oTempTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTempTextForm, "Qty" + i, "Qty" + i, false, " ", true, 9, 1, false, false);
addTextFormToParagraph(oTempParagraph, oTempTextForm, 30, "left", false, 255);
oTempParagraph = getTableCellParagraph(oTable, i, 1);
oTempTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTempTextForm, "Description" + i, "Description" + i, false, " ", true, 22, 1, false, false);
addTextFormToParagraph(oTempParagraph, oTempTextForm, 30, "left", false, 255);
}
oDocument.Call("Push", oTable);
oDocument.Call("RemoveElement", 0);
oDocument.Call("RemoveElement", 1);
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static CValue createFullWidthTable(CValue oApi, int rows, int cols, int borderColor)
{
CValue oTable = oApi.Call("CreateTable", cols, rows);
oTable.Call("SetWidth", "percent", 100);
setTableBorders(oTable, borderColor);
return oTable;
}
public static void setTableBorders(CValue oTable, int borderColor)
{
oTable.Call("SetTableBorderTop", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderBottom", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderLeft", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderRight", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderInsideV", "single", 4, 0, borderColor, borderColor, borderColor);
oTable.Call("SetTableBorderInsideH", "single", 4, 0, borderColor, borderColor, borderColor);
}
public static CValue getTableCellParagraph(CValue oTable, int row, int col)
{
return oTable.Call("GetCell", row, col).Call("GetContent").Call("GetElement", 0);
}
public static void addTextToParagraph(CValue oParagraph, string text, int fontSize, bool isBold)
{
oParagraph.Call("AddText", text);
oParagraph.Call("SetFontSize", fontSize);
oParagraph.Call("SetBold", isBold);
}
public static void setPictureFormProperties(CValue oPictureForm, string key, string tip, bool required, string placeholder, string scaleFlag, bool lockAspectRatio, bool respectBorders, int shiftX, int shiftY, string imageUrl)
{
oPictureForm.Call("SetFormKey", key);
oPictureForm.Call("SetTipText", tip);
oPictureForm.Call("SetRequired", required);
oPictureForm.Call("SetPlaceholderText", placeholder);
oPictureForm.Call("SetScaleFlag", scaleFlag);
oPictureForm.Call("SetLockAspectRatio", lockAspectRatio);
oPictureForm.Call("SetRespectBorders", respectBorders);
oPictureForm.Call("SetPicturePosition", shiftX, shiftY);
oPictureForm.Call("SetImage", imageUrl);
}
public static void setTextFormProperties(CValue oTextForm, string key, string tip, bool required, string placeholder, bool comb, int maxCharacters, int cellWidth, bool multiLine, bool autoFit)
{
oTextForm.Call("SetFormKey", key);
oTextForm.Call("SetTipText", tip);
oTextForm.Call("SetRequired", required);
oTextForm.Call("SetPlaceholderText", placeholder);
oTextForm.Call("SetComb", comb);
oTextForm.Call("SetCharactersLimit", maxCharacters);
oTextForm.Call("SetCellWidth", cellWidth);
oTextForm.Call("SetCellWidth", multiLine);
oTextForm.Call("SetMultiline", autoFit);
}
public static void addTextFormToParagraph(CValue oParagraph, CValue oTextForm, int fontSize, string jc, bool hasBorder, int borderColor)
{
if (hasBorder)
{
oTextForm.Call("SetBorderColor", borderColor, borderColor, borderColor);
}
oParagraph.Call("AddElement", oTextForm);
oParagraph.Call("SetFontSize", fontSize);
oParagraph.Call("SetJc", jc);
}
}
}

View File

@ -0,0 +1,123 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
namespace Sample
{
public class CreatingBasicForm
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.docx";
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
CreateBasicForm(workDirectory, resultPath);
}
public static void CreateBasicForm(string workDirectory, string resultPath)
{
var doctype = (int)OfficeFileTypes.Document.DOCX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.CreateFile(doctype);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Create basic form
CValue oDocument = oApi.Call("GetDocument");
CValue oParagraph = oDocument.Call("GetElement", 0);
CValue oHeadingStyle = oDocument.Call("GetStyle", "Heading 3");
oParagraph.Call("AddText", "Employee pass card");
oParagraph.Call("SetStyle", oHeadingStyle);
oDocument.Call("Push", oParagraph);
CValue oPictureForm = oApi.Call("CreatePictureForm");
setPictureFormProperties(oPictureForm, "Photo", "Upload your photo", false, "Photo", "tooBig", true, false, 50, 50, "https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oPictureForm);
oDocument.Call("Push", oParagraph);
CValue oTextForm = oApi.Call("CreateTextForm");
setTextFormProperties(oTextForm, "First name", "Enter your first name", false, "First name", true, 13, 3, false, false);
oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("AddElement", oTextForm);
oDocument.Call("Push", oParagraph);
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static void setPictureFormProperties(CValue oPictureForm, string key, string tip, bool required, string placeholder, string scaleFlag, bool lockAspectRatio, bool respectBorders, int shiftX, int shiftY, string imageUrl)
{
oPictureForm.Call("SetFormKey", key);
oPictureForm.Call("SetTipText", tip);
oPictureForm.Call("SetRequired", required);
oPictureForm.Call("SetPlaceholderText", placeholder);
oPictureForm.Call("SetScaleFlag", scaleFlag);
oPictureForm.Call("SetLockAspectRatio", lockAspectRatio);
oPictureForm.Call("SetRespectBorders", respectBorders);
oPictureForm.Call("SetPicturePosition", shiftX, shiftY);
oPictureForm.Call("SetImage", imageUrl);
}
public static void setTextFormProperties(CValue oTextForm, string key, string tip, bool required, string placeholder, bool comb, int maxCharacters, int cellWidth, bool multiLine, bool autoFit)
{
oTextForm.Call("SetFormKey", key);
oTextForm.Call("SetTipText", tip);
oTextForm.Call("SetRequired", required);
oTextForm.Call("SetPlaceholderText", placeholder);
oTextForm.Call("SetComb", comb);
oTextForm.Call("SetCharactersLimit", maxCharacters);
oTextForm.Call("SetCellWidth", cellWidth);
oTextForm.Call("SetCellWidth", multiLine);
oTextForm.Call("SetMultiline", autoFit);
}
}
}

View File

@ -0,0 +1,196 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
namespace Sample
{
public class CreatingChartPresentation
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.pptx";
string filePath = "../../../../../../resources/docs/chart_data.xlsx";
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
CreateChartPresentation(workDirectory, resultPath, filePath);
}
public static void CreateChartPresentation(string workDirectory, string resultPath, string filePath)
{
var doctype = (int)OfficeFileTypes.Presentation.PPTX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
// Read chart data from xlsx
oBuilder.OpenFile(filePath, "xlsx");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
CValue oWorksheet = oApi.Call("GetActiveSheet");
CValue oRange = oWorksheet.Call("GetUsedRange").Call("GetValue");
object[,] array = oRangeTo2dArray(oRange, oContext);
oBuilder.CloseFile();
// Create chart presentation
oBuilder.CreateFile(doctype);
oContext = oBuilder.GetContext();
oScope = oContext.CreateScope();
oGlobal = oContext.GetGlobal();
oApi = oGlobal["Api"];
CValue oPresentation = oApi.Call("GetPresentation");
CValue oSlide = oPresentation.Call("GetSlideByIndex", 0);
oSlide.Call("RemoveAllObjects");
CValue oRGBColor = oApi.Call("CreateRGBColor", 255, 244, 240);
CValue oFill = oApi.Call("CreateSolidFill", oRGBColor);
oSlide.Call("SetBackground", oFill);
CValue oStroke = oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill"));
CValue oShapeTitle = oApi.Call("CreateShape", "rect", 300 * 36000, 20 * 36000, oApi.Call("CreateNoFill"), oStroke);
CValue oShapeText = oApi.Call("CreateShape", "rect", 120 * 36000, 80 * 36000, oApi.Call("CreateNoFill"), oStroke);
oShapeTitle.Call("SetPosition", 20 * 36000, 20 * 36000);
oShapeText.Call("SetPosition", 210 * 36000, 50 * 36000);
CValue oParagraphTitle = oShapeTitle.Call("GetDocContent").Call("GetElement", 0);
CValue oParagraphText = oShapeText.Call("GetDocContent").Call("GetElement", 0);
oRGBColor = oApi.Call("CreateRGBColor", 115, 81, 68);
oFill = oApi.Call("CreateSolidFill", oRGBColor);
string titleContent = "Price Type Report";
string textContent = "This is an overview of price types. As we can see, May was the price peak, but even in June the price went down, the annual upward trend persists.";
addText(oApi, 80, titleContent, oSlide, oShapeTitle, oParagraphTitle, oFill, "center");
addText(oApi, 42, textContent, oSlide, oShapeText, oParagraphText, oFill, "left");
// Transform 2d array into cols names, rows names and data
CValue array_cols = colsFromArray(array, oContext);
CValue array_rows = rowsFromArray(array, oContext);
CValue array_data = dataFromArray(array, oContext);
// Pass CValue data to the CreateChart method
CValue oChart = oApi.Call("CreateChart", "lineStacked", array_data, array_cols, array_rows);
oChart.Call("SetSize", 180 * 36000, 100 * 36000);
oChart.Call("SetPosition", 20 * 36000, 50 * 36000);
oChart.Call("ApplyChartStyle", 24);
oChart.Call("SetVertAxisLabelsFontSize", 16);
oChart.Call("SetHorAxisLabelsFontSize", 16);
oChart.Call("SetLegendFontSize", 16);
oChart.Call("SetLegendPos", "top");
oSlide.Call("AddObject", oChart);
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static object[,] oRangeTo2dArray(CValue oRange, CContext oContext)
{
int rowsLen = (int)oRange.GetLength();
int colsLen = (int)oRange[0].GetLength();
object[,] oArray = new object[rowsLen, colsLen];
for (int col = 0; col < colsLen; col++)
{
CValue oArrayRow = oContext.CreateArray(rowsLen);
for (int row = 0; row < rowsLen; row++)
{
oArray[row, col] = oRange[row][col].ToString();
}
}
return oArray;
}
public static CValue colsFromArray(object[,] array, CContext oContext)
{
int colsLen = array.GetLength(1) - 1;
CValue cols = oContext.CreateArray(colsLen);
for (int col = 1; col <= colsLen; col++)
{
cols[col - 1] = array[0, col].ToString();
}
return cols;
}
public static CValue rowsFromArray(object[,] array, CContext oContext)
{
int rowsLen = array.GetLength(0) - 1;
CValue rows = oContext.CreateArray(rowsLen);
for (int row = 1; row <= rowsLen; row++)
{
rows[row - 1] = array[row, 0].ToString();
}
return rows;
}
public static CValue dataFromArray(object[,] array, CContext oContext)
{
int colsLen = array.GetLength(0) - 1;
int rowsLen = array.GetLength(1) - 1;
CValue data = oContext.CreateArray(rowsLen);
for (int row = 1; row <= rowsLen; row++)
{
CValue row_data = oContext.CreateArray(colsLen);
for (int col = 1; col <= colsLen; col++)
{
row_data[col - 1] = array[col, row].ToString();
}
data[row - 1] = row_data;
}
return data;
}
public static void addText(CValue oApi, int fontSize, string text, CValue oSlide, CValue oShape, CValue oParagraph, CValue oFill, string jc)
{
CValue oRun = oApi.Call("CreateRun");
var oTextPr = oRun.Call("GetTextPr");
oTextPr.Call("SetFontSize", fontSize);
oTextPr.Call("SetFill", oFill);
oTextPr.Call("SetFontFamily", "Tahoma");
oParagraph.Call("SetJc", jc);
oRun.Call("AddText", text);
oRun.Call("AddLineBreak");
oParagraph.Call("AddElement", oRun);
oSlide.Call("AddObject", oShape);
}
}
}

View File

@ -0,0 +1,168 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
using System.Collections.Generic;
namespace Sample
{
public class CreatingPresentation
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.pptx";
IDictionary<string, string> slideImages = new Dictionary<string, string>() {
{ "gun", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_gun.png" },
{ "axe","https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_axe.png" },
{ "knight", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_knight.png" },
{ "sky","https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_sky.png" }
};
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
CreatePresentation(workDirectory, resultPath, slideImages);
}
public static void CreatePresentation(string workDirectory, string resultPath, IDictionary<string, string> slideImages)
{
var doctype = (int)OfficeFileTypes.Presentation.PPTX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
// Create presentation
oBuilder.CreateFile(doctype);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
CValue oPresentation = oApi.Call("GetPresentation");
oPresentation.Call("SetSizes", 9144000, 6858000);
CValue oSlide = createImageSlide(oApi, oPresentation, slideImages["gun"]);
oPresentation.Call("GetSlideByIndex", 0).Call("Delete");
CValue oShape = oApi.Call("CreateShape", "rect", 8056800, 3020400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 608400, 1267200);
CValue oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "How They", 160, true, "left");
addTextToSlideShape(oApi, oContent, "Throw Out", 132, false, "left");
addTextToSlideShape(oApi, oContent, "a Challenge", 132, false, "left");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["axe"]);
oShape = oApi.Call("CreateShape", "rect", 6904800, 1724400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 1764000, 1191600);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "American Indians ", 110, true, "right");
addTextToSlideShape(oApi, oContent, "(XVII century)", 94, false, "right");
oSlide.Call("AddObject", oShape);
oShape = oApi.Call("CreateShape", "rect", 4986000, 2419200, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 3834000, 3888000);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "put a tomahawk on the ground in the ", 84, false, "right");
addTextToSlideShape(oApi, oContent, "rival's camp", 84, false, "right");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["knight"]);
oShape = oApi.Call("CreateShape", "rect", 6904800, 1724400, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 1764000, 1191600);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "European Knights", 110, true, "right");
addTextToSlideShape(oApi, oContent, " (XII-XVI centuries)", 94, false, "right");
oSlide.Call("AddObject", oShape);
oShape = oApi.Call("CreateShape", "rect", 4986000, 2419200, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 3834000, 3888000);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "threw a glove", 84, false, "right");
addTextToSlideShape(oApi, oContent, "in the rival's face", 84, false, "right");
oSlide.Call("AddObject", oShape);
oSlide = createImageSlide(oApi, oPresentation, slideImages["sky"]);
oShape = oApi.Call("CreateShape", "rect", 7887600, 3063600, oApi.Call("CreateNoFill"), oApi.Call("CreateStroke", 0, oApi.Call("CreateNoFill")));
oShape.Call("SetPosition", 630000, 1357200);
oContent = oShape.Call("GetDocContent");
oContent.Call("RemoveAllElements");
addTextToSlideShape(oApi, oContent, "OnlyOffice", 176, false, "center");
addTextToSlideShape(oApi, oContent, "stands for Peace", 132, false, "center");
oSlide.Call("AddObject", oShape);
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static CValue createImageSlide(CValue oApi, CValue oPresentation, string image_url)
{
CValue oSlide = oApi.Call("CreateSlide");
oPresentation.Call("AddSlide", oSlide);
var oFill = oApi.Call("CreateBlipFill", image_url, "stretch");
oSlide.Call("SetBackground", oFill);
oSlide.Call("RemoveAllObjects");
return oSlide;
}
public static void addTextToSlideShape(CValue oApi, CValue oContent, string text, int fontSize, bool isBold, string js)
{
var oParagraph = oApi.Call("CreateParagraph");
oParagraph.Call("SetSpacingBefore", 0);
oParagraph.Call("SetSpacingAfter", 0);
oContent.Call("Push", oParagraph);
var oRun = oParagraph.Call("AddText", text);
oRun.Call("SetFill", oApi.Call("CreateSolidFill", oApi.Call("CreateRGBColor", 0xff, 0xff, 0xff)));
oRun.Call("SetFontSize", fontSize);
oRun.Call("SetFontFamily", "Georgia");
oRun.Call("SetBold", isBold);
oParagraph.Call("SetJc", js);
}
}
}

View File

@ -0,0 +1,115 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
using System;
using System.Collections.Generic;
namespace Sample
{
public class FillingForm
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string filePath = "../../../../../../resources/docs/form.docx";
string resultPath = "../../../result.docx";
IDictionary<string, string> formData = new Dictionary<string, string>() {
{ "Photo", "https://api.onlyoffice.com/content/img/docbuilder/examples/blue_cloud.png" },
{ "Serial","A1345" },
{ "Company Name", "Blue Cloud" },
{ "Date", "25.12.2023" },
{ "Recipient", "Space Corporation" },
{ "Qty1", "25" },
{ "Description1", "Frame" },
{ "Qty2", "2" },
{ "Description2", "Stack" },
{ "Qty3", "34" },
{ "Description3", "Shifter" }
};
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
FillForm(workDirectory, resultPath, filePath, formData);
}
public static void FillForm(string workDirectory, string resultPath, string filePath, IDictionary<string, string> formData)
{
var doctype = (int)OfficeFileTypes.Document.DOCX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.OpenFile(filePath, "docxf");
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
// Fill form
CValue oDocument = oApi.Call("GetDocument");
CValue aForms = oDocument.Call("GetAllForms");
int formNum = 0;
while (formNum < aForms.GetLength())
{
CValue form = aForms[formNum];
string type = form.Call("GetFormType").ToString();
string value;
try
{
value = formData[form.Call("GetFormKey").ToString()];
}
catch (Exception e)
{
value = "";
}
if (type == "textForm") form.Call("SetText", value);
if (type == "pictureForm") form.Call("SetImage", value);
formNum++;
}
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
}
}

View File

@ -0,0 +1,114 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using docbuilder_net;
using OfficeFileTypes = docbuilder_net.FileTypes;
using CValue = docbuilder_net.CDocBuilderValue;
using CContext = docbuilder_net.CDocBuilderContext;
using CContextScope = docbuilder_net.CDocBuilderContextScope;
namespace Sample
{
public class FillingSpreadsheet
{
public static void Main(string[] args)
{
string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
string resultPath = "../../../result.xlsx";
object[,] data = {
{ "Id", "Product", "Price", "Available"},
{ 1001, "Item A", 12.2, true },
{ 1002, "Item B", 18.8, true },
{ 1003, "Item C", 70.1, false },
{ 1004, "Item D", 60.6, true },
{ 1005, "Item E", 32.6, true },
{ 1006, "Item F", 28.3, false },
{ 1007, "Item G", 11.1, false },
{ 1008, "Item H", 41.4, true }
};
// add Docbuilder dlls in path
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory);
FillSpreadsheet(workDirectory, resultPath, data);
}
public static void FillSpreadsheet(string workDirectory, string resultPath, object[,] data)
{
var doctype = (int)OfficeFileTypes.Spreadsheet.XLSX;
// Init DocBuilder
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.CreateFile(doctype);
CContext oContext = oBuilder.GetContext();
CContextScope oScope = oContext.CreateScope();
CValue oGlobal = oContext.GetGlobal();
CValue oApi = oGlobal["Api"];
CValue oWorksheet = oApi.Call("GetActiveSheet");
// pass data
CValue oArray = TwoDimArrayToCValue(data, oContext);
// First cell in the range (A1) is equal to (0,0)
CValue startCell = oWorksheet.Call("GetRangeByNumber", 0, 0);
// Last cell in the range is equal to array length -1
CValue endCell = oWorksheet.Call("GetRangeByNumber", oArray.GetLength() - 1, oArray[0].GetLength() - 1);
oWorksheet.Call("GetRange", startCell, endCell).Call("SetValue", oArray);
// Save file and close DocBuilder
oBuilder.SaveFile(doctype, resultPath);
oBuilder.CloseFile();
CDocBuilder.Destroy();
}
public static CValue TwoDimArrayToCValue(object[,] data, CContext oContext)
{
int rowsLen = data.GetLength(0);
int colsLen = data.GetLength(1);
CValue oArray = oContext.CreateArray(rowsLen);
for (int row = 0; row < rowsLen; row++)
{
CValue oArrayCol = oContext.CreateArray(colsLen);
for (int col = 0; col < colsLen; col++)
{
oArrayCol[col] = data[row, col].ToString();
}
oArray[row] = oArrayCol;
}
return oArray;
}
}
}

View File

@ -0,0 +1,76 @@
import docbuilder.*;
public class Program {
public static void main(String[] args) {
String resultPath = "result.docx";
createBasicForm(resultPath);
// Need to explicitly call System.gc() to free up resources
System.gc();
}
public static void createBasicForm(String resultPath) {
int doctype = FileTypes.Document.DOCX;
// Initialize builder with docbuilder.jar directory by passing empty string
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.createFile(doctype);
CDocBuilderContext context = builder.getContext();
CDocBuilderValue global = context.getGlobal();
CDocBuilderValue api = global.get("Api");
// Create basic form
CDocBuilderValue document = api.call("GetDocument");
CDocBuilderValue paragraph = document.call("GetElement", 0);
CDocBuilderValue headingStyle = document.call("GetStyle", "Heading 3");
paragraph.call("AddText", "Employee pass card");
paragraph.call("SetStyle", headingStyle);
document.call("Push", paragraph);
CDocBuilderValue pictureForm = api.call("CreatePictureForm");
setPictureFormProperties(pictureForm, "Photo", "Upload your photo", false, "Photo", "tooBig", true, false, 50, 50, "https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png");
paragraph = api.call("CreateParagraph");
paragraph.call("AddElement", pictureForm);
document.call("Push", paragraph);
CDocBuilderValue textForm = api.call("CreateTextForm");
setTextFormProperties(textForm, "First name", "Enter your first name", false, "First name", true, 13, 3, false, false);
paragraph = api.call("CreateParagraph");
paragraph.call("AddElement", textForm);
document.call("Push", paragraph);
// Save file and close DocBuilder
builder.saveFile(doctype, resultPath);
builder.closeFile();
CDocBuilder.dispose();
}
public static void setPictureFormProperties(CDocBuilderValue pictureForm, String key, String tip, boolean required, String placeholder, String scaleFlag, boolean lockAspectRatio, boolean respectBorders, int shiftX, int shiftY, String imageUrl) {
pictureForm.call("SetFormKey", key);
pictureForm.call("SetTipText", tip);
pictureForm.call("SetRequired", required);
pictureForm.call("SetPlaceholderText", placeholder);
pictureForm.call("SetScaleFlag", scaleFlag);
pictureForm.call("SetLockAspectRatio", lockAspectRatio);
pictureForm.call("SetRespectBorders", respectBorders);
pictureForm.call("SetPicturePosition", shiftX, shiftY);
pictureForm.call("SetImage", imageUrl);
}
public static void setTextFormProperties(CDocBuilderValue textForm, String key, String tip, boolean required, String placeholder, boolean comb, int maxCharacters, int cellWidth, boolean multiLine, boolean autoFit) {
textForm.call("SetFormKey", key);
textForm.call("SetTipText", tip);
textForm.call("SetRequired", required);
textForm.call("SetPlaceholderText", placeholder);
textForm.call("SetComb", comb);
textForm.call("SetCharactersLimit", maxCharacters);
textForm.call("SetCellWidth", cellWidth);
textForm.call("SetCellWidth", multiLine);
textForm.call("SetMultiline", autoFit);
}
}

View File

@ -0,0 +1,123 @@
import docbuilder.*;
import java.util.HashMap;
public class Program {
public static void main(String[] args) {
String resultPath = "result.pptx";
// Fill slide images
HashMap<String, String> slideImages = new HashMap<String, String>();
slideImages.put("gun", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_gun.png");
slideImages.put("axe", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_axe.png");
slideImages.put("knight", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_knight.png");
slideImages.put("sky", "https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_sky.png");
createPresentation(resultPath, slideImages);
// Need to explicitly call System.gc() to free up resources
System.gc();
}
public static void createPresentation(String resultPath, HashMap<String, String> slideImages) {
int doctype = FileTypes.Presentation.PPTX;
// Initialize builder with docbuilder.jar directory by passing empty String
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.createFile(doctype);
CDocBuilderContext context = builder.getContext();
CDocBuilderValue global = context.getGlobal();
CDocBuilderValue api = global.get("Api");
// Create presentation
CDocBuilderValue presentation = api.call("GetPresentation");
presentation.call("SetSizes", 9144000, 6858000);
CDocBuilderValue slide = createImageSlide(api, presentation, slideImages.get("gun"));
presentation.call("GetSlideByIndex", 0).call("Delete");
CDocBuilderValue shape = api.call("CreateShape", "rect", 8056800, 3020400, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 608400, 1267200);
CDocBuilderValue content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "How They", 160, true, "left");
addTextToSlideShape(api, content, "Throw Out", 132, false, "left");
addTextToSlideShape(api, content, "a Challenge", 132, false, "left");
slide.call("AddObject", shape);
slide = createImageSlide(api, presentation, slideImages.get("axe"));
shape = api.call("CreateShape", "rect", 6904800, 1724400, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 1764000, 1191600);
content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "American Indians ", 110, true, "right");
addTextToSlideShape(api, content, "(XVII century)", 94, false, "right");
slide.call("AddObject", shape);
shape = api.call("CreateShape", "rect", 4986000, 2419200, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 3834000, 3888000);
content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "put a tomahawk on the ground in the ", 84, false, "right");
addTextToSlideShape(api, content, "rival's camp", 84, false, "right");
slide.call("AddObject", shape);
slide = createImageSlide(api, presentation, slideImages.get("knight"));
shape = api.call("CreateShape", "rect", 6904800, 1724400, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 1764000, 1191600);
content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "European Knights", 110, true, "right");
addTextToSlideShape(api, content, " (XII-XVI centuries)", 94, false, "right");
slide.call("AddObject", shape);
shape = api.call("CreateShape", "rect", 4986000, 2419200, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 3834000, 3888000);
content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "threw a glove", 84, false, "right");
addTextToSlideShape(api, content, "in the rival's face", 84, false, "right");
slide.call("AddObject", shape);
slide = createImageSlide(api, presentation, slideImages.get("sky"));
shape = api.call("CreateShape", "rect", 7887600, 3063600, api.call("CreateNoFill"), api.call("CreateStroke", 0, api.call("CreateNoFill")));
shape.call("SetPosition", 630000, 1357200);
content = shape.call("GetDocContent");
content.call("RemoveAllElements");
addTextToSlideShape(api, content, "OnlyOffice", 176, false, "center");
addTextToSlideShape(api, content, "stands for Peace", 132, false, "center");
slide.call("AddObject", shape);
// Save file and close DocBuilder
builder.saveFile(doctype, resultPath);
builder.closeFile();
CDocBuilder.dispose();
}
public static CDocBuilderValue createImageSlide(CDocBuilderValue api, CDocBuilderValue presentation, String imageUrl) {
CDocBuilderValue slide = api.call("CreateSlide");
presentation.call("AddSlide", slide);
CDocBuilderValue fill = api.call("CreateBlipFill", imageUrl, "stretch");
slide.call("SetBackground", fill);
slide.call("RemoveAllObjects");
return slide;
}
public static void addTextToSlideShape(CDocBuilderValue api, CDocBuilderValue content, String text, int fontSize, boolean isBold, String js) {
CDocBuilderValue paragraph = api.call("CreateParagraph");
paragraph.call("SetSpacingBefore", 0);
paragraph.call("SetSpacingAfter", 0);
content.call("Push", paragraph);
CDocBuilderValue run = paragraph.call("AddText", text);
run.call("SetFill", api.call("CreateSolidFill", api.call("CreateRGBColor", 0xff, 0xff, 0xff)));
run.call("SetFontSize", fontSize);
run.call("SetFontFamily", "Georgia");
run.call("SetBold", isBold);
paragraph.call("SetJc", js);
}
}

View File

@ -0,0 +1,54 @@
import docbuilder.*;
public class Program {
public static void main(String[] args) {
String resultPath = "result.xlsx";
// Fill table data
Object[][] data = {
{ "Id", "Product", "Price", "Available" },
{ 1001, "Item A", 12.2, true },
{ 1002, "Item B", 18.8, true },
{ 1003, "Item C", 70.1, false },
{ 1004, "Item D", 60.6, true },
{ 1005, "Item E", 32.6, true },
{ 1006, "Item F", 28.3, false },
{ 1007, "Item G", 11.1, false },
{ 1008, "Item H", 41.4, true }
};
fillSpreadsheet(resultPath, data);
// Need to explicitly call System.gc() to free up resources
System.gc();
}
public static void fillSpreadsheet(String resultPath, Object[][] data) {
int doctype = FileTypes.Spreadsheet.XLSX;
// Initialize builder with docbuilder.jar directory by passing empty String
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.createFile(doctype);
CDocBuilderContext context = builder.getContext();
CDocBuilderValue global = context.getGlobal();
CDocBuilderValue api = global.get("Api");
// Create spreadsheet
CDocBuilderValue worksheet = api.call("GetActiveSheet");
// Convert data to array value type
CDocBuilderValue array = new CDocBuilderValue(data);
// First cell in the range (A1) is equal to (0,0)
CDocBuilderValue startCell = worksheet.call("GetRangeByNumber", 0, 0);
// Last cell in the range is equal to array length -1
CDocBuilderValue endCell = worksheet.call("GetRangeByNumber", array.getLength() - 1, array.get(0).getLength() - 1);
worksheet.call("GetRange", startCell, endCell).call("SetValue", array);
// Save file and close DocBuilder
builder.saveFile(doctype, resultPath);
builder.closeFile();
CDocBuilder.dispose();
}
}

View File

@ -0,0 +1,60 @@
import os
import sys
sys.path.append('C:/Program Files/ONLYOFFICE/DocumentBuilder')
import docbuilder
# Helper functions
def setPictureFormProperties(pictureForm, key, tip, required, placeholder, scaleFlag, lockAspectRatio, respectBorders, shiftX, shiftY, imageUrl):
pictureForm.Call('SetFormKey', key)
pictureForm.Call('SetTipText', tip)
pictureForm.Call('SetRequired', required)
pictureForm.Call('SetPlaceholderText', placeholder)
pictureForm.Call('SetScaleFlag', scaleFlag)
pictureForm.Call('SetLockAspectRatio', lockAspectRatio)
pictureForm.Call('SetRespectBorders', respectBorders)
pictureForm.Call('SetPicturePosition', shiftX, shiftY)
pictureForm.Call('SetImage', imageUrl)
def setTextFormProperties(textForm, key, tip, required, placeholder, comb, maxCharacters, cellWidth, multiLine, autoFit):
textForm.Call('SetFormKey', key)
textForm.Call('SetTipText', tip)
textForm.Call('SetRequired', required)
textForm.Call('SetPlaceholderText', placeholder)
textForm.Call('SetComb', comb)
textForm.Call('SetCharactersLimit', maxCharacters)
textForm.Call('SetCellWidth', cellWidth)
textForm.Call('SetCellWidth', multiLine)
textForm.Call('SetMultiline', autoFit)
if __name__ == '__main__':
builder = docbuilder.CDocBuilder()
builder.CreateFile(docbuilder.FileTypes.Document.DOCX)
context = builder.GetContext()
globalObj = context.GetGlobal()
api = globalObj['Api']
document = api.Call('GetDocument')
paragraph = document.Call('GetElement', 0)
headingStyle = document.Call('GetStyle', 'Heading 3')
paragraph.Call('AddText', 'Employee pass card')
paragraph.Call('SetStyle', headingStyle)
document.Call('Push', paragraph)
pictureForm = api.Call('CreatePictureForm')
setPictureFormProperties(pictureForm, 'Photo', 'Upload your photo', False, 'Photo', 'tooBig', True, False, 50, 50, 'https://api.onlyoffice.com/content/img/docbuilder/examples/user-profile.png')
paragraph = api.Call('CreateParagraph')
paragraph.Call('AddElement', pictureForm)
document.Call('Push', paragraph)
textForm = api.Call('CreateTextForm')
setTextFormProperties(textForm, 'First name', 'Enter your first name', False, 'First name', True, 13, 3, False, False)
paragraph = api.Call('CreateParagraph')
paragraph.Call('AddElement', textForm)
document.Call('Push', paragraph)
# Save and close
resultPath = os.getcwd() + '/result.docx'
builder.SaveFile(docbuilder.FileTypes.Document.DOCX, resultPath)
builder.CloseFile()

View File

@ -0,0 +1,105 @@
import os
import sys
sys.path.append('C:/Program Files/ONLYOFFICE/DocumentBuilder')
import docbuilder
def createImageSlide(api, presentation, image_url):
slide = api.Call('CreateSlide')
presentation.Call('AddSlide', slide)
fill = api.Call('CreateBlipFill', image_url, 'stretch')
slide.Call('SetBackground', fill)
slide.Call('RemoveAllObjects')
return slide
def addTextToSlideShape(api, content, text, fontSize, isBold, js):
paragraph = api.Call('CreateParagraph')
paragraph.Call('SetSpacingBefore', 0)
paragraph.Call('SetSpacingAfter', 0)
content.Call('Push', paragraph)
run = paragraph.Call('AddText', text)
run.Call('SetFill', api.Call('CreateSolidFill', api.Call('CreateRGBColor', 0xff, 0xff, 0xff)))
run.Call('SetFontSize', fontSize)
run.Call('SetFontFamily', 'Georgia')
run.Call('SetBold', isBold)
paragraph.Call('SetJc', js)
if __name__ == '__main__':
slideImages = {}
slideImages['gun'] = 'https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_gun.png'
slideImages['axe'] = 'https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_axe.png'
slideImages['knight'] = 'https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_knight.png'
slideImages['sky'] = 'https://api.onlyoffice.com/content/img/docbuilder/examples/presentation_sky.png'
builder = docbuilder.CDocBuilder()
builder.CreateFile(docbuilder.FileTypes.Presentation.PPTX)
context = builder.GetContext()
globalObj = context.GetGlobal()
api = globalObj['Api']
# Create presentation
presentation = api.Call('GetPresentation')
presentation.Call('SetSizes', 9144000, 6858000)
slide = createImageSlide(api, presentation, slideImages['gun'])
presentation.Call('GetSlideByIndex', 0).Call('Delete')
shape = api.Call('CreateShape', 'rect', 8056800, 3020400, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 608400, 1267200)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'How They', 160, True, 'left')
addTextToSlideShape(api, content, 'Throw Out', 132, False, 'left')
addTextToSlideShape(api, content, 'a Challenge', 132, False, 'left')
slide.Call('AddObject', shape)
slide = createImageSlide(api, presentation, slideImages['axe'])
shape = api.Call('CreateShape', 'rect', 6904800, 1724400, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 1764000, 1191600)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'American Indians ', 110, True, 'right')
addTextToSlideShape(api, content, '(XVII century)', 94, False, 'right')
slide.Call('AddObject', shape)
shape = api.Call('CreateShape', 'rect', 4986000, 2419200, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 3834000, 3888000)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'put a tomahawk on the ground in the ', 84, False, 'right')
addTextToSlideShape(api, content, 'rival\'s camp', 84, False, 'right')
slide.Call('AddObject', shape)
slide = createImageSlide(api, presentation, slideImages['knight'])
shape = api.Call('CreateShape', 'rect', 6904800, 1724400, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 1764000, 1191600)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'European Knights', 110, True, 'right')
addTextToSlideShape(api, content, ' (XII-XVI centuries)', 94, False, 'right')
slide.Call('AddObject', shape)
shape = api.Call('CreateShape', 'rect', 4986000, 2419200, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 3834000, 3888000)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'threw a glove', 84, False, 'right')
addTextToSlideShape(api, content, 'in the rival\'s face', 84, False, 'right')
slide.Call('AddObject', shape)
slide = createImageSlide(api, presentation, slideImages['sky'])
shape = api.Call('CreateShape', 'rect', 7887600, 3063600, api.Call('CreateNoFill'), api.Call('CreateStroke', 0, api.Call('CreateNoFill')))
shape.Call('SetPosition', 630000, 1357200)
content = shape.Call('GetDocContent')
content.Call('RemoveAllElements')
addTextToSlideShape(api, content, 'OnlyOffice', 176, False, 'center')
addTextToSlideShape(api, content, 'stands for Peace', 132, False, 'center')
slide.Call('AddObject', shape)
# Save and close
resultPath = os.getcwd() + '/result.pptx'
builder.SaveFile(docbuilder.FileTypes.Presentation.PPTX, resultPath)
builder.CloseFile()

View File

@ -0,0 +1,42 @@
import os
import sys
sys.path.append('C:/Program Files/ONLYOFFICE/DocumentBuilder')
import docbuilder
if __name__ == '__main__':
data = [
[ 'Id', 'Product', 'Price', 'Available' ],
[ '1001', 'Item A', "12.2", 'true' ],
[ '1002', 'Item B', "18.8", 'true' ],
[ '1003', 'Item C', "70.1", 'false' ],
[ '1004', 'Item D', "60.6", 'true' ],
[ '1005', 'Item E', "32.6", 'true' ],
[ '1006', 'Item F', "28.3", 'false' ],
[ '1007', 'Item G', "11.1", 'false' ],
[ '1008', 'Item H', "41.4", 'true' ]
]
builder = docbuilder.CDocBuilder()
builder.CreateFile(docbuilder.FileTypes.Spreadsheet.XLSX)
context = builder.GetContext()
globalObj = context.GetGlobal()
api = globalObj['Api']
# Find and comment formula errors
worksheet = api.Call('GetActiveSheet')
# Create array from data
array = docbuilder.CDocBuilderValue(data)
# First cell in the range (A1) is equal to (0,0)
startCell = worksheet.Call('GetRangeByNumber', 0, 0)
# Last cell in the range is equal to array length -1
endCell = worksheet.Call('GetRangeByNumber', len(data) - 1, len(data[0]) - 1)
worksheet.Call('GetRange', startCell, endCell).Call('SetValue', array)
# Save and close
resultPath = os.getcwd() + '/result.xlsx'
builder.SaveFile(docbuilder.FileTypes.Spreadsheet.XLSX, resultPath)
builder.CloseFile()

View File

@ -0,0 +1,258 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
// convenient macro definitions
#if defined(__linux__) || defined(__linux)
#define _LINUX
#elif defined(__APPLE__) || defined(__MACH__)
#define _MAC
#endif
#include <string>
#ifdef _WIN32
#include <wchar.h>
#include <windows.h>
#endif
#if defined(_LINUX) || defined(_MAC)
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#endif
#ifdef _MAC
#include <mach-o/dyld.h>
#endif
#ifdef CreateFile
#undef CreateFile
#endif
namespace NSUtils
{
#ifdef _WIN32
#define PATH_SEPARATOR '\\'
#define WriteCodepoint(code) \
if (code < 0x10000) \
*unicodes_cur++ = code; \
else \
{ \
code -= 0x10000; \
*unicodes_cur++ = 0xD800 | ((code >> 10) & 0x03FF); \
*unicodes_cur++ = 0xDC00 | (code & 0x03FF); \
}
#else
#define PATH_SEPARATOR '/'
#define WriteCodepoint(code) *unicodes_cur++ = (wchar_t)code;
#endif
std::wstring GetStringFromUtf8(const unsigned char* utf8, size_t length)
{
wchar_t* unicodes = new wchar_t[length + 1];
wchar_t* unicodes_cur = unicodes;
size_t index = 0;
while (index < length)
{
unsigned char byteMain = utf8[index];
if (0x00 == (byteMain & 0x80))
{
// 1 byte
WriteCodepoint(byteMain)
++index;
}
else if (0x00 == (byteMain & 0x20))
{
// 2 byte
int val = 0;
if ((index + 1) < length)
{
val = (int)(((byteMain & 0x1F) << 6) |
(utf8[index + 1] & 0x3F));
}
WriteCodepoint(val)
index += 2;
}
else if (0x00 == (byteMain & 0x10))
{
// 3 byte
int val = 0;
if ((index + 2) < length)
{
val = (int)(((byteMain & 0x0F) << 12) |
((utf8[index + 1] & 0x3F) << 6) |
(utf8[index + 2] & 0x3F));
}
WriteCodepoint(val)
index += 3;
}
else if (0x00 == (byteMain & 0x0F))
{
// 4 byte
int val = 0;
if ((index + 3) < length)
{
val = (int)(((byteMain & 0x07) << 18) |
((utf8[index + 1] & 0x3F) << 12) |
((utf8[index + 2] & 0x3F) << 6) |
(utf8[index + 3] & 0x3F));
}
WriteCodepoint(val)
index += 4;
}
else if (0x00 == (byteMain & 0x08))
{
// 4 byte
int val = 0;
if ((index + 3) < length)
{
val = (int)(((byteMain & 0x07) << 18) |
((utf8[index + 1] & 0x3F) << 12) |
((utf8[index + 2] & 0x3F) << 6) |
(utf8[index + 3] & 0x3F));
}
WriteCodepoint(val)
index += 4;
}
else if (0x00 == (byteMain & 0x04))
{
// 5 byte
int val = 0;
if ((index + 4) < length)
{
val = (int)(((byteMain & 0x03) << 24) |
((utf8[index + 1] & 0x3F) << 18) |
((utf8[index + 2] & 0x3F) << 12) |
((utf8[index + 3] & 0x3F) << 6) |
(utf8[index + 4] & 0x3F));
}
WriteCodepoint(val)
index += 5;
}
else
{
// 6 byte
int val = 0;
if ((index + 5) < length)
{
val = (int)(((byteMain & 0x01) << 30) |
((utf8[index + 1] & 0x3F) << 24) |
((utf8[index + 2] & 0x3F) << 18) |
((utf8[index + 3] & 0x3F) << 12) |
((utf8[index + 4] & 0x3F) << 6) |
(utf8[index + 5] & 0x3F));
}
WriteCodepoint(val)
index += 5;
}
}
*unicodes_cur++ = 0;
std::wstring sOutput(unicodes);
delete[] unicodes;
return sOutput;
}
}
namespace NSUtils
{
#define NS_FILE_MAX_PATH 32768
std::wstring GetProcessPath()
{
#ifdef _WIN32
wchar_t buf [NS_FILE_MAX_PATH];
GetModuleFileNameW(GetModuleHandle(NULL), buf, NS_FILE_MAX_PATH);
return std::wstring(buf);
#endif
#if defined(_LINUX) || defined(_MAC)
char buf[NS_FILE_MAX_PATH];
memset(buf, 0, NS_FILE_MAX_PATH);
if (readlink ("/proc/self/exe", buf, NS_FILE_MAX_PATH) <= 0)
{
#ifdef _MAC
uint32_t _size = NS_FILE_MAX_PATH;
_NSGetExecutablePath(buf, &_size);
#endif
}
return GetStringFromUtf8((unsigned char*)buf, strlen(buf));
#endif
}
std::wstring GetProcessDirectory()
{
std::wstring path = GetProcessPath();
size_t pos = path.find_last_of(PATH_SEPARATOR);
if (pos != std::wstring::npos)
path = path.substr(0, pos);
return path;
}
std::wstring GetResourcesDirectory()
{
std::wstring path = GetProcessDirectory();
while (!path.empty())
{
size_t pos = path.find_last_of(PATH_SEPARATOR);
if (pos != std::wstring::npos)
{
std::wstring currDir = path.substr(pos + 1);
if (currDir == L"samples")
{
path += PATH_SEPARATOR;
path += L"resources";
break;
}
else
{
path = path.substr(0, pos);
}
}
else
{
path = L"";
}
}
return path;
}
}

View File

@ -109,7 +109,7 @@ FT_Error FT_Load_Glyph_Wrapper( FT_Face face,
FT_Err_Invalid_Reference = 0x86;
*/
if ((bHintsSupport == TRUE) && ((nErr > 0x10 && nErr < 0x28) || nErr == 0x83 || nErr == 0x86))
if ((bHintsSupport == TRUE) && ((nErr > 0x10 && nErr < 0x28) || (nErr >= 0x83 && nErr <= 0x8D)))
{
int nErr2 = FT_Load_Glyph(face, glyph_index, 40970);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,178 @@
#ifndef BOOLEANOPERATIONS_H
#define BOOLEANOPERATIONS_H
#include "GraphicsPath.h"
#include <memory>
namespace Aggplus
{
struct Location;
struct Segment
{
PointD P{};
PointD HI{};
PointD HO{};
bool IsCurve = false;
bool Visited = false;
bool PolyClosed = false;
int Index = -1;
int Id = 0;
int Winding = 0;
std::shared_ptr<Location> Inters{nullptr};
Segment() noexcept;
Segment(const std::vector<PointD>& points, const bool& isCurve,
const int& index, const int& id, const bool& polyClosed) noexcept;
Segment(const PointD& point, const bool& isCurve, const int& index,
const int& id, const bool& polyClosed) noexcept;
Segment(const PointD& p) noexcept;
Segment(const PointD& p, const PointD& hi, const PointD& ho) noexcept;
void SetHandles(const PointD& hi, const PointD& ho) noexcept;
void UpdateHandles(const PointD& hi, const PointD& ho) noexcept;
bool IsValid(const BooleanOpType& op) const noexcept;
bool IsEmpty() const noexcept;
bool operator==(const Segment& other) const noexcept;
bool operator!=(const Segment& other) const noexcept;
};
struct Curve
{
Segment Segment1{};
Segment Segment2{};
Curve() noexcept;
Curve(const Segment& segment1, const Segment& segment2) noexcept;
Curve(const std::vector<double>& values) noexcept;
Curve(const double& x0, const double& y0, const double& x1, const double& y1,
const double& x2, const double& y2, const double& x3, const double& y3) noexcept;
std::vector<double> GetXValues() const noexcept;
std::vector<double> GetYValues() const noexcept;
std::vector<double> GetPeeks() const;
double GetLength(double a = 0, double b = 1) const;
double GetSquaredLineLength() const noexcept;
double GetTimeOf(const PointD& point) const noexcept;
double GetTimeAt(const double& offset) const noexcept;
PointD Get(const double& t, const int& type) const noexcept;
PointD GetPoint(const double& t) const noexcept;
PointD GetTangent(const double& t) const noexcept;
PointD GetTangent(const double& t, const double& offset,
const bool& inside, const PointD& p) const noexcept;
Curve GetPart(double from, double to) const noexcept;
std::vector<Curve> GetMonoCurves(const bool& dir) const noexcept;
std::vector<double> GetCurveLineIntersection(const double& px, const double& py,
const double& vx, const double& vy) const noexcept;
std::vector<std::pair<double, double>> GetOverlaps(const Curve& curve) const noexcept;
std::vector<Curve> Subdivide(const double& t) const noexcept;
Curve DivideAtTime(const double& time) noexcept;
int SolveCubic(const int& coord, const double& value, std::vector<double>& roots,
const double& mn, const double& mx) const noexcept;
int SolveCubic(double a, double b, double c, double d, std::vector<double>& roots,
const double& mn, const double& mx) const noexcept;
void Flip() noexcept;
bool IsStraight() const noexcept;
bool HasHandle() const noexcept;
bool operator==(const Curve& other) const noexcept;
bool operator!=(const Curve& other) const noexcept;
};
struct Location
{
Curve C{};
Segment S{};
double Time = -1.0;
bool Overlap = false;
bool Ends = false;
std::shared_ptr<Location> Inters{nullptr};
std::shared_ptr<Location> Next{nullptr};
std::shared_ptr<Location> Prev{nullptr};
Location() noexcept;
Location(const Curve& curve, const double& time, const bool& overlap, const bool& ends) noexcept;
bool IsTouching() noexcept;
};
class CBooleanOperations
{
public:
CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op);
~CBooleanOperations();
CGraphicsPath&& GetResult();
// BooleanOp
void TraceBoolean();
void TraceOneInters();
void TraceAllOverlap();
void TracePaths();
// Path
void PreparePath(const CGraphicsPath& path, int id, std::vector<Segment>& segments,
std::vector<Curve>& curves, bool reverse = false);
void InsertSegment(Segment& segment, const Segment& handles, bool updateHandles);
Curve GetCurve(const Segment& segment) const noexcept;
Curve GetPreviousCurve(const Curve& curve) const noexcept;
Curve GetNextCurve(const Curve& curve) const noexcept;
Segment GetNextSegment(const Segment& segment) const noexcept;
void SetVisited(const Segment& segment);
// Bounds
std::vector<std::vector<double>> GetBoundsForCurves(const std::vector<Curve>& curves) const noexcept;
std::vector<std::vector<int>> FindBoundsCollisions();
// Intersection
bool IsCrossing(std::shared_ptr<Location> loc) noexcept;
bool FilterIntersections(std::shared_ptr<Location> loc) noexcept;
bool IntersectsBounds() noexcept;
void GetIntersection();
void GetCurveIntersection(const Curve& curve1, const Curve& curve2);
void LinkIntersection(std::shared_ptr<Location> form, std::shared_ptr<Location> to);
void AddLineIntersection(const Curve& curve1, const Curve& curve2);
void AddCurveLineIntersection(const Curve& curve1, const Curve& curve2, bool flip);
int AddCurveIntersection(Curve curve1, Curve curve2, const Curve& startCurve1, const Curve& startCurve2, bool flip,
int recursion = 0, int calls = 0, double tMin = 0.0, double tMax = 1.0, double uMin = 0.0, double uMax = 1.0);
int CheckInters(const PointD& point, const Segment& segment, const Curve& curve, int& touchCount) const;
void SetWinding();
// Location
void DivideLocations();
void AddLocation(Curve curve1, Curve curve2, double t1, double t2, bool overlap = false, bool filter = true, bool bothEnds = false);
void InsertLocation(std::shared_ptr<Location> loc, bool overlap);
bool AllOverlap() const noexcept;
bool AllInters(const std::vector<Segment>& segments) const noexcept;
void AddOffsets(std::vector<double>& offsets, const Curve& curve, bool end);
private:
BooleanOpType Op = Intersection;
bool Close1 = true;
bool Close2 = true;
CGraphicsPath Path1;
CGraphicsPath Path2;
CGraphicsPath Result;
std::vector<Segment> Segments1;
std::vector<Segment> Segments2;
std::vector<Curve> OriginCurves1;
std::vector<Curve> OriginCurves2;
std::vector<Curve> Curves1;
std::vector<Curve> Curves2;
std::vector<std::shared_ptr<Location>> Locations;
};
} // namespace Aggplus
#endif // BOOLEANOPERATIONS_H

File diff suppressed because it is too large Load Diff

View File

@ -42,125 +42,155 @@
namespace Aggplus
{
class CGraphicsPath_private;
class GRAPHICS_DECL CGraphicsPath : public NSFonts::ISimpleGraphicsPath
{
public:
CGraphicsPath();
~CGraphicsPath();
class CGraphicsPath_private;
class GRAPHICS_DECL CGraphicsPath : public NSFonts::ISimpleGraphicsPath
{
public:
CGraphicsPath();
CGraphicsPath(const CGraphicsPath& other) noexcept;
CGraphicsPath(CGraphicsPath&& other) noexcept;
CGraphicsPath(const std::vector<CGraphicsPath>& paths) noexcept;
virtual ~CGraphicsPath();
CGraphicsPath* Clone();
CGraphicsPath* Clone();
Status Reset();
void SetRuler(bool bEvenOdd);
Status Reset();
void SetRuler(bool bEvenOdd);
Status StartFigure();
Status CloseFigure();
bool Is_poly_closed();
Status MoveTo(double x, double y);
Status LineTo(double x, double y);
Status CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
Status StartFigure();
Status CloseFigure();
bool Is_poly_closed() const;
Status MoveTo(double x, double y);
Status LineTo(double x, double y);
Status CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
// методы, которые просто будем сводить к трем основным
Status AddLine(double x1, double y1, double x2, double y2);
Status AddLines(double* pPoints, int nCount);
Status AddBezier(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
Status AddBeziers(double* pPoints, int nCount);
Status AddCurve(double* pPoints, int nCount);
Status AddEllipse(double x, double y, double width, double height);
Status AddRectangle(double x, double y, double width, double height);
Status AddPolygon(double* pPoints, int nCount);
Status AddPath(const CGraphicsPath& oPath);
Status AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle);
// методы, которые просто будем сводить к трем основным
Status AddLine(double x1, double y1, double x2, double y2);
Status AddLines(double* pPoints, int nCount);
Status AddBezier(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
Status AddBeziers(double* pPoints, int nCount);
Status AddCurve(double* pPoints, int nCount);
Status AddEllipse(double x, double y, double width, double height);
Status AddRectangle(double x, double y, double width, double height);
Status AddPolygon(double* pPoints, int nCount);
Status AddPath(const CGraphicsPath& oPath);
Status AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle);
ULONG GetPointCount() const;
Status GetPathPoints(PointF* points, int count) const;
Status GetLastPoint(double& x, double& y);
Status GetPathPoints(double* points, int count) const;
void GetBounds(double& left, double& top, double& width, double& height);
ULONG GetPointCount() const;
Status GetPathPoints(PointF* points, int count) const;
Status GetLastPoint(double& x, double& y);
Status GetPathPoints(double* points, int count) const;
void GetBounds(double& left, double& top, double& width, double& height) const;
void GetBoundsAccurate(double& left, double& top, double& width, double& height) const;
Status Transform(const CMatrix* matrix);
virtual bool _MoveTo(double x, double y);
virtual bool _LineTo(double x, double y);
virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
virtual bool _Close();
Status Transform(const CMatrix* matrix);
virtual bool _MoveTo(double x, double y);
virtual bool _LineTo(double x, double y);
virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
virtual bool _Close();
Status AddString(const std::wstring& strText, NSFonts::IFontManager* pFont, double x, double y);
Status AddString(const unsigned int* pGids, const unsigned int nGidsCount, NSFonts::IFontManager* pFont, double x, double y);
Status AddStringC(const LONG& lText, NSFonts::IFontManager* pFont, double x, double y);
void z_Stroke(const double& size);
void Widen(const double& size, const Aggplus::LineJoin& join, const CMatrix* matrix, float flatness);
Status AddString(const std::wstring& strText, NSFonts::IFontManager* pFont, double x, double y);
Status AddString(const unsigned int* pGids, const unsigned int nGidsCount, NSFonts::IFontManager* pFont, double x, double y);
Status AddStringC(const LONG& lText, NSFonts::IFontManager* pFont, double x, double y);
void z_Stroke(const double& size);
void Widen(const double& size, const Aggplus::LineJoin& join, const CMatrix* matrix, float flatness);
int EllipseArc(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
double AngToEllPrm(double fAngle, double fXRad, double fYRad);
int EllipseArc2(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
int EllipseArc3(double fX, double fY, double fXRad, double fYRad, double dAngle1, double dAngle2, double *pfXCur, double *pfYCur, INT bClockDirection = FALSE);
int Ellipse(double fX, double fY, double fXRad, double fYRad);
Status AddArc2(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
bool IsPointInPath(const double& x, const double& y);
int EllipseArc(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
double AngToEllPrm(double fAngle, double fXRad, double fYRad);
int EllipseArc2(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
int EllipseArc3(double fX, double fY, double fXRad, double fYRad, double dAngle1, double dAngle2, double* pfXCur, double* pfYCur, INT bClockDirection = FALSE);
int Ellipse(double fX, double fY, double fXRad, double fYRad);
Status AddArc2(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
bool IsPointInPath(const double& x, const double& y);
public:
CGraphicsPath_private* m_internal;
};
// Methods for Path Clip
unsigned GetCloseCount() const noexcept;
unsigned GetMoveCount() const noexcept;
bool IsClockwise() const noexcept;
bool IsMovePoint(unsigned idx) const noexcept;
bool IsCurvePoint(unsigned idx) const noexcept;
bool IsLinePoint(unsigned idx) const noexcept;
bool IsClosePoint(unsigned idx) const noexcept;
double GetArea() const noexcept;
double GetArea(unsigned idx, bool isCurve) const noexcept;
std::vector<PointD> GetPoints(unsigned idx, unsigned count) const noexcept;
std::vector<CGraphicsPath> GetSubPaths() const;
class CGraphicsPathSimpleConverter_private;
class GRAPHICS_DECL CGraphicsPathSimpleConverter : public NSFonts::ISimpleGraphicsPath
{
private:
IRenderer* m_pRenderer;
CGraphicsPathSimpleConverter_private* m_internal;
CGraphicsPath& operator=(const CGraphicsPath& other) noexcept;
CGraphicsPath& operator=(CGraphicsPath&& other) noexcept;
bool operator==(const CGraphicsPath& other) noexcept;
public:
CGraphicsPathSimpleConverter();
~CGraphicsPathSimpleConverter();
public:
CGraphicsPath_private* m_internal;
};
public:
void SetRenderer(IRenderer* pRenderer);
IRenderer* GetRenderer(INT bIsAddref = FALSE);
class CGraphicsPathSimpleConverter_private;
class GRAPHICS_DECL CGraphicsPathSimpleConverter : public NSFonts::ISimpleGraphicsPath
{
private:
IRenderer* m_pRenderer;
CGraphicsPathSimpleConverter_private* m_internal;
public:
bool PathCommandMoveTo(double fX, double fY);
bool PathCommandLineTo(double fX, double fY);
bool PathCommandLinesTo(double* pPoints, LONG lCount);
bool PathCommandCurveTo(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3);
bool PathCommandCurvesTo(double* pData, LONG lCount);
bool PathCommandArcTo(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
bool PathCommandClose();
bool PathCommandEnd();
bool PathCommandStart();
bool PathCommandGetCurrentPoint(double* fX, double* fY);
bool PathCommandText(const std::wstring& bsText, NSFonts::IFontManager* pManager, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
bool PathCommandTextEx(std::wstring& bsText, std::wstring& bsGidText, NSFonts::IFontManager* pManager, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
public:
CGraphicsPathSimpleConverter();
~CGraphicsPathSimpleConverter();
bool PathCommandText2(const int* pUnicodes, const int* pGids, const int& nCount, NSFonts::IFontManager* pManager,
const double& x, const double& y, const double& w, const double& h);
bool PathCommandText2(const std::wstring& sUnicodes, const int* pGids, const int& nCount, NSFonts::IFontManager* pManager,
const double& x, const double& y, const double& w, const double& h);
public:
void SetRenderer(IRenderer* pRenderer);
IRenderer* GetRenderer(INT bIsAddref = FALSE);
bool PathCommandGetBounds(double& left, double& top, double& width, double &height);
public:
bool PathCommandMoveTo(double fX, double fY);
bool PathCommandLineTo(double fX, double fY);
bool PathCommandLinesTo(double* pPoints, LONG lCount);
bool PathCommandCurveTo(double fX1, double fY1, double fX2, double fY2, double fX3, double fY3);
bool PathCommandCurvesTo(double* pData, LONG lCount);
bool PathCommandArcTo(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
bool PathCommandClose();
bool PathCommandEnd();
bool PathCommandStart();
bool PathCommandGetCurrentPoint(double* fX, double* fY);
bool PathCommandText(const std::wstring& bsText, NSFonts::IFontManager* pManager, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset);
bool
PathCommandTextEx(std::wstring& bsText, std::wstring& bsGidText, NSFonts::IFontManager* pManager, double fX, double fY, double fWidth, double fHeight, double fBaseLineOffset, DWORD lFlags);
public:
bool PathCommandText2(const int* pUnicodes, const int* pGids, const int& nCount, NSFonts::IFontManager* pManager, const double& x, const double& y, const double& w, const double& h);
bool PathCommandText2(const std::wstring& sUnicodes, const int* pGids, const int& nCount, NSFonts::IFontManager* pManager, const double& x, const double& y, const double& w, const double& h);
virtual bool _MoveTo(double x, double y);
virtual bool _LineTo(double x, double y);
virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
virtual bool _Close();
bool _Reset();
bool _Start();
bool PathCommandGetBounds(double& left, double& top, double& width, double& height);
protected:
bool AddString(const std::wstring& bstrText, NSFonts::IFontManager* pFont, double x, double y);
public:
virtual bool _MoveTo(double x, double y);
virtual bool _LineTo(double x, double y);
virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
virtual bool _Close();
bool _Reset();
bool _Start();
int EllipseArc(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
double AngToEllPrm(double fAngle, double fXRad, double fYRad);
int EllipseArc2(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
int EllipseArc3(double fX, double fY, double fXRad, double fYRad, double dAngle1, double dAngle2, double *pfXCur, double *pfYCur, INT bClockDirection = FALSE);
int Ellipse(double fX, double fY, double fXRad, double fYRad);
protected:
bool AddString(const std::wstring& bstrText, NSFonts::IFontManager* pFont, double x, double y);
bool AddArc(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
int EllipseArc(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
double AngToEllPrm(double fAngle, double fXRad, double fYRad);
int EllipseArc2(double fX, double fY, double fXRad, double fYRad, double fAngle1, double fAngle2, INT bClockDirection);
int EllipseArc3(double fX, double fY, double fXRad, double fYRad, double dAngle1, double dAngle2, double* pfXCur, double* pfYCur, INT bClockDirection = FALSE);
int Ellipse(double fX, double fY, double fXRad, double fYRad);
bool Is_poly_closed();
};
}
bool AddArc(double fX, double fY, double fWidth, double fHeight, double fStartAngle, double fSweepAngle);
bool Is_poly_closed();
};
enum BooleanOpType
{
Intersection = 1,
Union = 0,
Subtraction = 2,
Exclusion = 3
};
GRAPHICS_DECL CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op);
} // namespace Aggplus
#endif // _BUILD_GRAPHICSPATH_H_

View File

@ -123,8 +123,10 @@ public:
PointF_T(T x, T y) : X(x), Y(y) { }
//~PointF() { }
INT Equals(const PointF_T& point) const { return(X==point.X && Y==point.Y); }
bool IsZero() const noexcept { return X == 0.0 && Y == 0.0; }
PointF_T operator+(const PointF_T& point) const { return PointF_T(X + point.X, Y + point.Y); }
PointF_T operator-(const PointF_T& point) const { return PointF_T(X - point.X, Y - point.Y); }
PointF_T& operator=(const PointF_T& other) noexcept {X = other.X; Y = other.Y; return *this;}
public:
T X, Y;
};

View File

@ -0,0 +1,482 @@
#ifndef CLIPMATH_H
#define CLIPMATH_H
#include "aggplustypes.h"
#include <vector>
#include <algorithm>
#include <limits>
constexpr double EPSILON = 1e-12;
constexpr double POINT_EPSILON = 1e-2;
constexpr double GEOMETRIC_EPSILON = 1e-7;
constexpr double LOCATION_EPSILON = 1e-7;
constexpr double TIME_EPSILON = 1e-8;
constexpr double MACHINE_EPSILON = 1.12e-16;
constexpr double TRIGANOMETRIC_EPSILON = 1e-8;
constexpr double CURVETIME_EPSILON = 1e-8;
constexpr double LINE_EPSILON = 1e-9;
constexpr double MIN = std::numeric_limits<double>::min();
constexpr double MAX = std::numeric_limits<double>::max();
const Aggplus::PointD MIN_POINT = Aggplus::PointD(-100000.0, -100000.0);
const std::vector<double> ABSCISSAS[16] = {
{0.5773502691896257645091488},
{0,0.7745966692414833770358531},
{0.3399810435848562648026658,0.8611363115940525752239465},
{0,0.5384693101056830910363144,0.9061798459386639927976269},
{0.2386191860831969086305017,0.6612093864662645136613996,0.9324695142031520278123016},
{0,0.4058451513773971669066064,0.7415311855993944398638648,0.9491079123427585245261897},
{0.1834346424956498049394761,0.5255324099163289858177390,0.7966664774136267395915539,
0.9602898564975362316835609},
{0,0.3242534234038089290385380,0.6133714327005903973087020,0.8360311073266357942994298,
0.9681602395076260898355762},
{0.1488743389816312108848260,0.4333953941292471907992659,0.6794095682990244062343274,
0.8650633666889845107320967,0.9739065285171717200779640},
{0,0.2695431559523449723315320,0.5190961292068118159257257,0.7301520055740493240934163,
0.8870625997680952990751578,0.9782286581460569928039380},
{0.1252334085114689154724414,0.3678314989981801937526915,0.5873179542866174472967024,
0.7699026741943046870368938,0.9041172563704748566784659,0.9815606342467192506905491},
{0,0.2304583159551347940655281,0.4484927510364468528779129,0.6423493394403402206439846,
0.8015780907333099127942065,0.9175983992229779652065478,0.9841830547185881494728294},
{0.1080549487073436620662447,0.3191123689278897604356718,0.5152486363581540919652907,
0.6872929048116854701480198,0.8272013150697649931897947,0.9284348836635735173363911,
0.9862838086968123388415973},
{0,0.2011940939974345223006283,0.3941513470775633698972074,0.5709721726085388475372267,
0.7244177313601700474161861,0.8482065834104272162006483,0.9372733924007059043077589,
0.9879925180204854284895657},
{0.0950125098376374401853193,0.2816035507792589132304605,0.4580167776572273863424194,
0.6178762444026437484466718,0.7554044083550030338951012,0.8656312023878317438804679,
0.9445750230732325760779884,0.9894009349916499325961542}
};
const std::vector<double> WEIGHT[16] {
{1},
{0.8888888888888888888888889,0.5555555555555555555555556},
{0.6521451548625461426269361,0.3478548451374538573730639},
{0.5688888888888888888888889,0.4786286704993664680412915,0.2369268850561890875142640},
{0.4679139345726910473898703,0.3607615730481386075698335,0.1713244923791703450402961},
{0.4179591836734693877551020,0.3818300505051189449503698,0.2797053914892766679014678,
0.1294849661688696932706114},
{0.3626837833783619829651504,0.3137066458778872873379622,0.2223810344533744705443560,
0.1012285362903762591525314},
{0.3302393550012597631645251,0.3123470770400028400686304,0.2606106964029354623187429,
0.1806481606948574040584720,0.0812743883615744119718922},
{0.2955242247147528701738930,0.2692667193099963550912269,0.2190863625159820439955349,
0.1494513491505805931457763,0.0666713443086881375935688},
{0.2729250867779006307144835,0.2628045445102466621806889,0.2331937645919904799185237,
0.1862902109277342514260976,0.1255803694649046246346943,0.0556685671161736664827537},
{0.2491470458134027850005624,0.2334925365383548087608499,0.2031674267230659217490645,
0.1600783285433462263346525,0.1069393259953184309602547,0.0471753363865118271946160},
{0.2325515532308739101945895,0.2262831802628972384120902,0.2078160475368885023125232,
0.1781459807619457382800467,0.1388735102197872384636018,0.0921214998377284479144218,
0.0404840047653158795200216},
{0.2152638534631577901958764,0.2051984637212956039659241,0.1855383974779378137417166,
0.1572031671581935345696019,0.1215185706879031846894148,0.0801580871597602098056333,
0.0351194603317518630318329},
{0.2025782419255612728806202,0.1984314853271115764561183,0.1861610000155622110268006,
0.1662692058169939335532009,0.1395706779261543144478048,0.1071592204671719350118695,
0.0703660474881081247092674,0.0307532419961172683546284},
{0.1894506104550684962853967,0.1826034150449235888667637,0.1691565193950025381893121,
0.1495959888165767320815017,0.1246289712555338720524763,0.0951585116824927848099251,
0.0622535239386478928628438,0.0271524594117540948517806}
};
inline double max(const double& v1, const double& v2, const double& v3, const double& v4)
{
return std::max(std::max(v1, v2), std::max(v3, v4));
}
inline double max(const double& v1, const double& v2, const double& v3)
{
return std::max(std::max(v1, v2), v3);
}
inline double min(const double& v1, const double& v2, const double& v3, const double& v4)
{
return std::min(std::min(v1, v2), std::min(v3, v4));
}
inline double min(const double& v1, const double& v2, const double& v3)
{
return std::min(std::min(v1, v2), v3);
}
inline bool isZero(const double& value)
{
return value >= -EPSILON && value <= EPSILON;
}
inline bool isMachineZero(const double& value)
{
return value >= -MACHINE_EPSILON && value <= MACHINE_EPSILON;
}
inline bool isInRange(const double& angle, const double& mn, const double& mx)
{
return (mn < mx) ? (angle > mn && angle < mx) : (angle > mn || angle < mx);
}
inline double clamp(const double& value, const double& mn, const double& mx)
{
return value < mn ? mn : value > mx ? mx : value;
}
inline bool isCollinear(const Aggplus::PointD& p1, const Aggplus::PointD& p2)
{
return fabs(p1.X * p2.X + p1.Y * p2.Y) <= sqrt((p1.X * p1.X + p1.Y * p1.Y) * (p2.X * p2.X + p2.Y * p2.Y)) * TRIGANOMETRIC_EPSILON;
}
inline int getIterations(const double& a, const double& b)
{
double n1 = 2.0, n2 = 16.0;
return std::max(n1, std::min(n2, ceil(fabs(b - a) * 32)));
}
inline double CurveLength(const double& t, const double& ax, const double& bx, const double& cx,
const double& ay, const double& by, const double& cy)
{
return sqrt((((ax * t) + bx) * t + cx) * (((ax * t) + bx) * t + cx) + (((ay * t) + by) * t + cy) * (((ay * t) + by) * t + cy));
}
inline double integrate(const double& ax, const double& bx, const double& cx, const double& ay,
const double& by, const double& cy, const double& a, const double& b, size_t n = 16)
{
std::vector<double> x = ABSCISSAS[n - 2],
w = WEIGHT[n - 2];
double A = (b - a) * 0.5,
B = A + a;
double sum = n & 1 ? CurveLength(B, ax, bx, cx, ay, by, cy) : 0.0;
for (size_t i = 0; i < (n + 1) >> 1; i++)
{
double Ax = A * x[i];
sum += w[i] * (CurveLength(B + Ax, ax, bx, cx, ay, by, cy) +
CurveLength(B - Ax, ax, bx, cx, ay, by, cy));
}
return A * sum;
}
double fLength(const double& t, double& length, double& start, const double& offset,
const double& ax, const double& bx, const double& cx, const double& ay,
const double& by, const double& cy)
{
length += integrate(ax, bx, cx, ay, by, cy, start, t, getIterations(start, t));
start = t;
return length - offset;
}
double findRoot(double& length, double& start, const double& offset, const double& ax,
const double& bx, const double& cx, const double& ay, const double& by,
const double& cy, double x, double a, double b)
{
for (size_t i = 0; i < 32; i++)
{
double fx = fLength(x, length, start, offset, ax, bx, cx, ay, by, cy),
dx = fx / CurveLength(x, ax, bx, cx, ay, by, cy),
nx = x - dx;
if (fabs(dx) < EPSILON)
{
x = nx;
break;
}
if (fx > 0)
{
b = x;
x = nx <= a ? (a + b) * 0.5 : nx;
}
else{
a = x;
x = nx >= b ? (a + b) * 0.5 : nx;
}
}
return clamp(x, a, b);
}
bool intersect(std::vector<double> v, Aggplus::PointD& res)
{
v[2] -= v[0];
v[3] -= v[1];
v[6] -= v[4];
v[7] -= v[5];
double cross = v[2] * v[7] - v[3] * v[6];
if (!isMachineZero(cross))
{
double dx = v[0] - v[4],
dy = v[1] - v[5],
u1 = (v[6] * dy - v[7] * dx) / cross,
u2 = (v[2] * dy - v[3] * dx) / cross,
uMin = -EPSILON,
uMax = 1 + EPSILON;
if (uMin < u1 && u1 < uMax && uMin < u2 && u2 < uMax)
{
u1 = u1 <= 0 ? 0 : u1 >= 1 ? 1 : u1;
res = Aggplus::PointD(v[0] + u1 * v[2], v[1] + u1 * v[3]);
return true;
}
}
return false;
}
std::vector<std::vector<Aggplus::PointD>> getConvexHull(const double& dq0, const double& dq1,
const double& dq2, const double& dq3)
{
Aggplus::PointD p0 = Aggplus::PointD(0.0, dq0),
p1 = Aggplus::PointD(1.0 / 3.0, dq1),
p2 = Aggplus::PointD(2.0 / 3.0, dq2),
p3 = Aggplus::PointD(1.0, dq3);
double dist1 = dq1 - (2.0 * dq0 + dq3) / 3.0,
dist2 = dq2 - (dq0 + 2.0 * dq3) / 3.0;
std::vector<std::vector<Aggplus::PointD>> hull;
if (dist1 * dist2 < 0.0)
{
hull = {{p0, p1, p3}, {p0, p2, p3}};
}
else
{
double distRatio = dist1 / dist2;
if (distRatio >= 2.0)
hull = {{p0, p1, p3}, {p0, p3}};
else if (distRatio <= 0.5)
hull = {{p0, p2, p3}, {p0, p3}};
else
hull = {{p0, p1, p2, p3}, {p0, p3}};
}
if (dist1 < 0.0 || dist2 < 0.0)
std::reverse(hull.begin(), hull.end());
return hull;
}
double clipConvexHullPart(const std::vector<Aggplus::PointD>& part, const bool& top,
const double& threshold)
{
double px = part[0].X,
py = part[0].Y;
for (size_t i = 1; i < part.size(); i++)
{
double qx = part[i].X,
qy = part[i].Y;
if (top ? qy >= threshold : qy <= threshold)
return qy == threshold ? qx : px + (threshold - py) * (qx - px) / (qy - py);
px = qx;
py = qy;
}
return MIN;
}
inline double clipConvexHull(const std::vector<Aggplus::PointD>& top,
const std::vector<Aggplus::PointD>& bottom,
const double& dMin, const double& dMax)
{
if (top[0].Y < dMin)
return clipConvexHullPart(top, true, dMin);
else if (bottom[0].Y > dMax)
return clipConvexHullPart(bottom, false, dMax);
else
return top[0].X;
}
inline int binarySearch(const std::vector<std::vector<double>>& allBounds,
const std::vector<int>& indices, const size_t& coord, const double& value)
{
int lo = 0,
hi = static_cast<int>(indices.size());
while(lo < hi)
{
int mid = (hi + lo) >> 1;
if (allBounds[indices[mid]][coord] < value)
lo = mid + 1;
else
hi = mid;
}
return lo - 1;
}
inline double getSignedDistance(const double& px, const double& py, double vx, double vy,
const double& x, const double& y, bool asVector = false)
{
if (!asVector)
{
vx -= px;
vy -= py;
}
bool vx0 = vx == 0.0,
vyG = vy > 0.0,
vxL = vx < 0.0,
vy0 = vy == 0.0,
vyGvx = vy > vx;
double distX = vyG ? x - px : px - x,
distY = vxL ? y - py : py - y,
distGY = vy * sqrt(1.0 + (vx * vx) / (vy * vy)),
distGX = vx * sqrt(1.0 + (vy * vy) / (vx * vx)),
distXY = ((x - px) * vy - (y - py) * vx) / (vyGvx ? distGY : distGX);
return vx0 ? distX : vy0 ? distY : distXY;
}
inline double getDistance(const double& px, const double& py, const double& vx, const double& vy,
const double& x, const double& y, const bool& asVector)
{
return fabs(getSignedDistance(px, py, vx, vy, x, y, asVector));
}
inline double getDistance(const double& px, const double& py, const double& vx, const double& vy,
const double& x, const double& y)
{
if (vx == 0)
{
if (vy > 0)
return std::abs(x - px);
else
return std::abs(px - x);
}
if (vy == 0)
{
if (vx < 0)
return std::abs(y - py);
else
return std::abs(py -y);
}
bool dir = vy > vx;
double dist = (x- px) * vy - (y - py) * vx,
epsY = vy * sqrt(1 + (vx * vx) / (vy * vy)),
epsX = vx * sqrt(1 + (vy * vy) / (vx * vx));
return dist / (dir ? epsY : epsX);
}
inline double getDistance(const double& x1, const double& y1, const double& x2, const double& y2)
{
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
inline double getDistance(const Aggplus::PointD& point1, const Aggplus::PointD& point2)
{
return getDistance(point1.X, point1.Y, point2.X, point2.Y);
}
inline std::pair<double, double> split(const double& v)
{
double x = v * 134217729.0,
y = v - x,
hi = y + x,
lo = v - hi;
return std::pair<double, double>(hi, lo);
}
inline double getDiscriminant(const double& a, const double& b, const double& c)
{
double D = b * b - a * c,
E = b * b + a * c;
if (fabs(D) * 3 < E)
{
std::pair<double, double> ad = split(a),
bd = split(b),
cd = split(c);
double p = b * b,
dp = (bd.first * bd.first -
p + 2 * bd.first * bd.second) +
bd.second * bd.second,
q = a * c,
dq = (ad.first * cd.first -
q + ad.first * cd.second +
ad.second * cd.first) +
ad.second * cd.second;
D = (p - q) + (dp - dq);
}
return D;
}
int solveQuadratic(double a, double b, double c, std::vector<double>& roots,
const double& mn, const double& mx)
{
double x1 = MAX, x2 = MAX;
if (fabs(a) < EPSILON)
{
if (fabs(b) < EPSILON)
return fabs(c) < EPSILON ? -1 : 0;
x1 = -c / b;
}
else
{
b *= -0.5;
double D = getDiscriminant(a, b, c);
if (D != 0 && fabs(D) < MACHINE_EPSILON)
{
double f = max(fabs(a), fabs(b), fabs(c));
if ((f != 0) && (f < 1e-8 || f < 1e8))
{
f = pow(2, -round(log2(f)));
a *= f;
b *= f;
c *= f;
D = getDiscriminant(a, b, c);
}
}
if (D >= -MACHINE_EPSILON)
{
double Q = D < 0 ? 0 : sqrt(D),
R = b + (b < 0 ? -Q : Q);
if (R == 0)
{
x1 = c / a;
x2 = -x1;
}
else
{
x1 = R / a;
x2 = c / R;
}
}
}
int count = 0;
double minB = mn - EPSILON,
maxB = mx + EPSILON;
if (x1 != MAX && x1 > minB && x1 < maxB)
{
roots.push_back(clamp(x1, mn, mx));
count++;
}
if (x2 != x1 && x2 != MAX && x2 > minB && x2 < maxB)
{
roots.push_back(clamp(x2, mn, mx));
count++;
}
return count;
}
#endif //CLIPMATH_H

View File

@ -221,6 +221,7 @@ BYTE* CAnnotFieldInfo::GetRender(LONG& nLen)
}
const std::wstring& CAnnotFieldInfo::GetNM() { return m_wsNM; }
const std::wstring& CAnnotFieldInfo::GetLM() { return m_wsLM; }
const std::wstring& CAnnotFieldInfo::GetOUserID() { return m_wsOUserID; }
const std::wstring& CAnnotFieldInfo::GetContents() { return m_wsContents; }
const std::vector<double>& CAnnotFieldInfo::GetC() { return m_arrC; }
@ -348,6 +349,8 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
m_pRender = pReader->GetCurrentBuffer();
pReader->Skip(m_nRenderLen);
}
if (nFlags & (1 << 7))
m_wsOUserID = pReader->ReadString();
if (IsMarkup())
{

View File

@ -414,6 +414,7 @@ public:
BYTE* GetRender(LONG& nLen);
const std::wstring& GetNM();
const std::wstring& GetLM();
const std::wstring& GetOUserID();
const std::wstring& GetContents();
const std::vector<double>& GetC();
@ -466,6 +467,7 @@ private:
int m_nPage;
std::wstring m_wsNM;
std::wstring m_wsLM;
std::wstring m_wsOUserID;
std::wstring m_wsContents;
std::pair<BYTE, double> m_pBE;
std::vector<double> m_arrC;

View File

@ -49,10 +49,13 @@ SOURCES += \
# paths
HEADERS += \
./../GraphicsPath_private.h \
./../GraphicsPath.h
./../GraphicsPath.h \
./../BooleanOperations.h \
./../boolean_operations_math.h
SOURCES += \
./../GraphicsPath.cpp
./../GraphicsPath.cpp \
./../BooleanOperations.cpp
# alpha mask
HEADERS += \

View File

@ -143,7 +143,7 @@
},
{
"folder": "../../",
"files": ["GraphicsRenderer.cpp", "pro/pro_Graphics.cpp", "pro/pro_Fonts.cpp", "pro/pro_Image.cpp", "Graphics.cpp", "Brush.cpp", "BaseThread.cpp", "GraphicsPath.cpp", "Image.cpp", "Matrix.cpp", "Clip.cpp", "TemporaryCS.cpp", "AlphaMask.cpp", "GraphicsLayer.cpp", "commands/DocInfo.cpp", "commands/AnnotField.cpp", "commands/FormField.cpp"]
"files": ["GraphicsRenderer.cpp", "pro/pro_Graphics.cpp", "pro/pro_Fonts.cpp", "pro/pro_Image.cpp", "Graphics.cpp", "Brush.cpp", "BaseThread.cpp", "GraphicsPath.cpp", "BooleanOperations.cpp", "Image.cpp", "Matrix.cpp", "Clip.cpp", "TemporaryCS.cpp", "AlphaMask.cpp", "GraphicsLayer.cpp", "commands/DocInfo.cpp", "commands/AnnotField.cpp", "commands/FormField.cpp"]
},
{
"folder": "../../../fontengine/",

View File

@ -53,6 +53,8 @@ HEADERS += \
../../../Matrix.h \
../../../Matrix_private.h \
../../../GraphicsPath.h \
../../../BooleanOperations.h \
../../../boolean_operations_math.h \
../../../GraphicsPath_private.h \
../../../AlphaMask.h \
\
@ -105,6 +107,7 @@ HEADERS += \
SOURCES += \
../../../Matrix.cpp \
../../../GraphicsPath.cpp \
../../../BooleanOperations.cpp \
../../../AlphaMask.cpp \
../../../../raster/BgraFrame.cpp \
../../../../raster/ImageFileFormatChecker.cpp \
@ -680,6 +683,7 @@ HEADERS += \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Paragraph.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Shape.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/TextLine.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/ExternalImageStorage.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontStyleManager.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/ImageManager.h \
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontManager.h \

View File

@ -73,9 +73,9 @@ CFile.prototype.getOriginPage = function(originIndex)
for (let i = 0; i < this.pages.length; ++i)
{
if (this.pages[i]["originIndex"] == originIndex)
return this.pages[i];
return i;
}
return null;
return -1;
};
CFile.prototype["getPages"] = function()
@ -115,7 +115,7 @@ CFile.prototype["loadFromDataWithPassword"] = function(password)
if (0 != this.nativeFile)
this._closeFile();
let isSuccess = this._openFile(arrayBuffer, password);
let isSuccess = this._openFile(undefined, password);
let error = this._getError(); // 0 - ok, 4 - password, else: error
this.type = this._getType();
@ -236,14 +236,17 @@ CFile.prototype["getLinks"] = function(pageIndex)
// TEXT
CFile.prototype["getGlyphs"] = function(pageIndex)
{
let page = this.getOriginPage(pageIndex);
let i = this.getOriginPage(pageIndex);
if (i < 0)
return null;
let page = this.pages[i];
if (!page || page.fonts.length > 0)
{
// waiting fonts
return null;
}
this.lockPageNumForFontsLoader(pageIndex, UpdateFontsSource.Page);
this.lockPageNumForFontsLoader(i, UpdateFontsSource.Page);
let res = this._getGlyphs(pageIndex);
// there is no need to delete the result; this buffer is used as a text buffer
// for text commands on other pages. After receiving ALL text pages,
@ -488,7 +491,11 @@ function readAnnot(reader, rec)
// Date of last change - M
if (flags & (1 << 5))
rec["LastModified"] = reader.readString();
// AP
rec["AP"]["have"] = (flags >> 6) & 1;
// User ID
if (flags & (1 << 7))
rec["OUserID"] = reader.readString();
}
function readAnnotAP(reader, AP)
{
@ -841,6 +848,8 @@ CFile.prototype["getButtonIcons"] = function(pageIndex, width, height, backgroun
let reader = ptr.getReader();
if (!reader) return {};
let res = {};
res["MK"] = [];
res["View"] = [];
@ -1368,14 +1377,17 @@ CFile.prototype["free"] = function(pointer)
// PIXMAP
CFile.prototype["getPagePixmap"] = function(pageIndex, width, height, backgroundColor)
{
let page = this.getOriginPage(pageIndex);
let i = this.getOriginPage(pageIndex);
if (i < 0)
return null;
let page = this.pages[i];
if (!page || page.fonts.length > 0)
{
// waiting fonts
return null;
}
this.lockPageNumForFontsLoader(pageIndex, UpdateFontsSource.Page);
this.lockPageNumForFontsLoader(i, UpdateFontsSource.Page);
let ptr = this._getPixmap(pageIndex, width, height, backgroundColor);
this.unlockPageNumForFontsLoader();
@ -1433,6 +1445,43 @@ function fontToMemory(file, isCheck)
Module["_free"](idPointer);
}
// FONTS
CFile.prototype["addPage"] = function(pageIndex, pageObj)
{
this.pages.splice(pageIndex, 0, pageObj);
if (this.fontStreams)
{
for (let i in this.fontStreams)
{
let pages = this.fontStreams[i].pages;
for (let j = 0; j < pages.length; j++)
{
if (pages[j] >= pageIndex)
pages[j] += 1;
}
}
}
};
CFile.prototype["removePage"] = function(pageIndex)
{
let result = this.pages.splice(pageIndex, 1);
if (this.fontStreams)
{
for (let i in this.fontStreams)
{
let pages = this.fontStreams[i].pages;
for (let j = 0; j < pages.length; j++)
{
if (pages[j] > pageIndex)
pages[j] -= 1;
else if (pages[j] == pageIndex)
pages.splice(j, 1);
}
}
}
return result;
};
// ONLY WEB
self["AscViewer"]["Free"] = function(pointer)
{

View File

@ -107,7 +107,7 @@ CFile.prototype._setCMap = function(memoryBuffer)
CFile.prototype._getFontByID = function(ID)
{
return null;
return g_native_drawing_file["GetFontBinary"](ID);
};
CFile.prototype._getInteractiveFormsFonts = function(type)

View File

@ -82,7 +82,7 @@ CFile.prototype._getUint8ClampedArray = function(ptr, len)
// FILE
CFile.prototype._openFile = function(buffer, password)
{
if (this.stream && buffer)
if (buffer)
{
let data = new Uint8Array(buffer);
this.stream_size = data.length;
@ -94,7 +94,7 @@ CFile.prototype._openFile = function(buffer, password)
if (password)
{
let passwordBuf = password.toUtf8();
let passwordPtr = Module["_malloc"](passwordBuf.length);
passwordPtr = Module["_malloc"](passwordBuf.length);
Module["HEAP8"].set(passwordBuf, passwordPtr);
}

View File

@ -267,6 +267,13 @@ void ReadAnnot(BYTE* pWidgets, int& i)
std::cout << "YES AP, ";
else
std::cout << "NO AP, ";
if (nFlags & (1 << 7))
{
nPathLength = READ_INT(pWidgets + i);
i += 4;
std::cout << "User ID " << std::string((char*)(pWidgets + i), nPathLength) << ", ";
i += nPathLength;
}
}
void ReadInteractiveForms(BYTE* pWidgets, int& i)
@ -821,7 +828,7 @@ void ReadFileAttachment(BYTE* pAnnots, int& i, int n)
RELEASEARRAYOBJECTS(res);
}
void ReadInteractiveFormsFonts(CGraphicsFileDrawing* pGrFile, int nType)
void ReadInteractiveFormsFonts(CDrawingFile* pGrFile, int nType)
{
BYTE* pFonts = GetInteractiveFormsFonts(pGrFile, nType);
int nLength = READ_INT(pFonts);
@ -923,7 +930,7 @@ int main(int argc, char* argv[])
if (!NSFile::CFileBinary::ReadAllBytes(sFilePath, &pFileData, nFileDataLen))
return 1;
CGraphicsFileDrawing* pGrFile = Open(pFileData, (LONG)nFileDataLen, "");
CDrawingFile* pGrFile = Open(pFileData, (LONG)nFileDataLen, "");
int nError = GetErrorCode(pGrFile);
if (nError != 0)
@ -1084,7 +1091,7 @@ int main(int argc, char* argv[])
}
// INTERACTIVE FORMS
if (false)
if (true)
{
ReadInteractiveFormsFonts(pGrFile, 1);
ReadInteractiveFormsFonts(pGrFile, 2);
@ -1199,7 +1206,7 @@ int main(int argc, char* argv[])
}
// ANNOTS
if (false)
if (true)
{
BYTE* pAnnots = GetAnnotationsInfo(pGrFile, -1);
nLength = READ_INT(pAnnots);
@ -1801,6 +1808,13 @@ int main(int argc, char* argv[])
free(pAnnotAP);
}
if (true)
{
BYTE* pScan = ScanPage(pGrFile, nTestPage, 1);
if (pScan)
free(pScan);
}
Close(pGrFile);
RELEASEARRAYOBJECTS(pFileData);
RELEASEARRAYOBJECTS(pCMapData);

View File

@ -35,6 +35,7 @@
#include "../agg-2.4/include/agg_color_rgba.h"
#include "../graphics/aggplustypes.h"
#include "../graphics/Matrix.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
@ -102,6 +103,23 @@ namespace NSStructures
}
}
void set_x_min(float x_min)
{
x_domain_min = x_min;
}
void set_x_max(float x_max)
{
x_domain_max = x_max;
}
void set_y_min(float y_min)
{
y_domain_min = y_min;
}
void set_y_max(float y_max)
{
y_domain_max = y_max;
}
float get_x_min()
{
return x_domain_min;
@ -386,6 +404,75 @@ namespace NSStructures
{
discrete_step = 1.0f / n;
}
void transform(const Aggplus::CMatrix& matrix)
{
// shading transform
auto& point1 = shading.point1;
auto& point2 = shading.point2;
double point1_x = static_cast<double>(point1.x);
double point1_y = static_cast<double>(point1.y);
double point2_x = static_cast<double>(point2.x);
double point2_y = static_cast<double>(point2.y);
matrix.TransformPoint(point1_x, point1_y);
matrix.TransformPoint(point2_x, point2_y);
point1.x = static_cast<float>(point1_x);
point1.y = static_cast<float>(point1_y);
point2.x = static_cast<float>(point2_x);
point2.y = static_cast<float>(point2_y);
// triangle transform
for (auto& p : shading.triangle)
{
double triangle_x = static_cast<double>(p.x);
double triangle_y = static_cast<double>(p.y);
matrix.TransformPoint(triangle_x, triangle_y);
p.x = static_cast<float>(triangle_x);
p.y = static_cast<float>(triangle_y);
}
// domains transform
double x_domain_min = static_cast<double>(shading.function.get_x_min());
double y_domain_min = static_cast<double>(shading.function.get_y_min());
double x_domain_max = static_cast<double>(shading.function.get_x_max());
double y_domain_max = static_cast<double>(shading.function.get_y_max());
matrix.TransformPoint(x_domain_min, y_domain_min);
matrix.TransformPoint(x_domain_max, y_domain_max);
shading.function.set_x_min(static_cast<float>(x_domain_min));
shading.function.set_y_min(static_cast<float>(y_domain_min));
shading.function.set_x_max(static_cast<float>(x_domain_max));
shading.function.set_y_max(static_cast<float>(y_domain_max));
// center transform
double center_x = static_cast<double>(centerX);
double center_y = static_cast<double>(centerY);
matrix.TransformPoint(center_x, center_y);
double p0_x = static_cast<double>(p0.x);
double p0_y = static_cast<double>(p0.y);
double p1_x = static_cast<double>(p1.x);
double p1_y = static_cast<double>(p1.y);
matrix.TransformPoint(p0_x, p0_y);
matrix.TransformPoint(p1_x, p1_y);
p0.x = static_cast<float>(p0_x);
p0.y = static_cast<float>(p0_y);
p1.x = static_cast<float>(p1_x);
p1.y = static_cast<float>(p1_y);
// sizes scale
double sqrt_det = sqrt(fabs(matrix.Determinant()));
r0 *= sqrt_det;
r1 *= sqrt_det;
}
Point p0, p1;
float r0, r1;

View File

@ -0,0 +1,17 @@
include(../../../../Common/3dParty/googletest/googletest.pri)
TEMPLATE = app
CONFIG += console c++14
CONFIG -= app_bundle
CONFIG += thread
CONFIG -= qt
SOURCES += \
tst_booleanoperations.cpp
PWD_ROOT_DIR = $$PWD
CORE_ROOT_DIR = $$PWD/../../../../../core
include($$CORE_ROOT_DIR/Common/base.pri)
ADD_DEPENDENCY(kernel, graphics, UnicodeConverter)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)

View File

@ -0,0 +1,17 @@
isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR)
isEmpty(GOOGLETEST_DIR) {
GOOGLETEST_DIR = ""
!isEmpty(GOOGLETEST_DIR) {
warning("Using googletest src dir specified at Qt Creator wizard")
message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message")
}
}
!isEmpty(GOOGLETEST_DIR): {
INCLUDEPATH *= "$$GOOGLETEST_DIR/include"
LIBS *= -L"$$GOOGLETEST_DIR/lib" -lgtest -lgmock
} else {
LIBS *= -lgtest -lgmock
}

View File

@ -0,0 +1,459 @@
//#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
#include "../../GraphicsPath.h"
using namespace testing;
TEST(BooleanOperations, NoIntersOutside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 200.0);
path1.LineTo(200.0, 200.0);
path1.LineTo(200.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(300.0, 300.0);
path2.LineTo(300.0, 400.0);
path2.LineTo(400.0, 400.0);
path2.LineTo(400.0, 300.0);
path2.LineTo(300.0, 300.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 200.0);
resultUnite.LineTo(200.0, 200.0);
resultUnite.LineTo(200.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.MoveTo(300.0, 300.0);
resultUnite.LineTo(300.0, 400.0);
resultUnite.LineTo(400.0, 400.0);
resultUnite.LineTo(400.0, 300.0);
resultUnite.LineTo(300.0, 300.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 200.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(200.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, NoIntersInside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 400.0);
path1.LineTo(400.0, 400.0);
path1.LineTo(400.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(300.0, 300.0);
path2.LineTo(300.0, 200.0);
path2.LineTo(200.0, 200.0);
path2.LineTo(200.0, 300.0);
path2.LineTo(300.0, 300.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(300.0, 300.0);
resultIntersect.LineTo(300.0, 200.0);
resultIntersect.LineTo(200.0, 200.0);
resultIntersect.LineTo(200.0, 300.0);
resultIntersect.LineTo(300.0, 300.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 400.0);
resultUnite.LineTo(400.0, 400.0);
resultUnite.LineTo(400.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 400.0);
resultSubtract.LineTo(400.0, 400.0);
resultSubtract.LineTo(400.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.MoveTo(300.0, 300.0);
resultSubtract.LineTo(200.0, 300.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(300.0, 200.0);
resultSubtract.LineTo(300.0, 300.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, OneIntersOutside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 200.0);
path1.LineTo(200.0, 200.0);
path1.LineTo(200.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(200.0, 150.0);
path2.LineTo(300.0, 150.0);
path2.LineTo(250.0, 200.0);
path2.LineTo(200.0, 150.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(200.0, 150.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 200.0);
resultUnite.LineTo(200.0, 200.0);
resultUnite.LineTo(200.0, 150.0);
resultUnite.LineTo(250.0, 200.0);
resultUnite.LineTo(300.0, 150.0);
resultUnite.LineTo(200.0, 150.0);
resultUnite.LineTo(200.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 200.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(200.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, OneIntersInside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 200.0);
path1.LineTo(200.0, 200.0);
path1.LineTo(200.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(200.0, 150.0);
path2.LineTo(150.0, 150.0);
path2.LineTo(175.0, 175.0);
path2.LineTo(200.0, 150.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(200.0, 150.0);
resultIntersect.LineTo(150.0, 150.0);
resultIntersect.LineTo(175.0, 175.0);
resultIntersect.LineTo(200.0, 150.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 200.0);
resultUnite.LineTo(200.0, 200.0);
resultUnite.LineTo(200.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 200.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(200.0, 150.0);
resultSubtract.LineTo(175.0, 175.0);
resultSubtract.LineTo(150.0, 150.0);
resultSubtract.LineTo(200.0, 150.0);
resultSubtract.LineTo(200.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, OverlapOutside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 300.0);
path1.LineTo(300.0, 300.0);
path1.LineTo(300.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(300.0, 200.0);
path2.LineTo(300.0, 400.0);
path2.LineTo(400.0, 400.0);
path2.LineTo(400.0, 200.0);
path2.LineTo(300.0, 200.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(300.0, 300.0);
resultIntersect.LineTo(300.0, 200.0);
resultIntersect.LineTo(300.0, 300.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 300.0);
resultUnite.LineTo(300.0, 300.0);
resultUnite.LineTo(300.0, 400.0);
resultUnite.LineTo(400.0, 400.0);
resultUnite.LineTo(400.0, 200.0);
resultUnite.LineTo(300.0, 200.0);
resultUnite.LineTo(300.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 300.0);
resultSubtract.LineTo(300.0, 300.0);
resultSubtract.LineTo(300.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, OverlapInside)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 400.0);
path1.LineTo(400.0, 400.0);
path1.LineTo(400.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(200.0, 200.0);
path2.LineTo(400.0, 200.0);
path2.LineTo(400.0, 300.0);
path2.LineTo(200.0, 300.0);
path2.LineTo(200.0, 200.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(400.0, 300.0);
resultIntersect.LineTo(400.0, 200.0);
resultIntersect.LineTo(200.0, 200.0);
resultIntersect.LineTo(200.0, 300.0);
resultIntersect.LineTo(400.0, 300.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 400.0);
resultUnite.LineTo(400.0, 400.0);
resultUnite.LineTo(400.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 400.0);
resultSubtract.LineTo(400.0, 400.0);
resultSubtract.LineTo(400.0, 300.0);
resultSubtract.LineTo(200.0, 300.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(400.0, 200.0);
resultSubtract.LineTo(400.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, LineIntersLine)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.StartFigure();
path1.MoveTo(100.0, 100.0);
path1.LineTo(100.0, 300.0);
path1.LineTo(300.0, 300.0);
path1.LineTo(300.0, 100.0);
path1.LineTo(100.0, 100.0);
path1.CloseFigure();
path2.StartFigure();
path2.MoveTo(200.0, 200.0);
path2.LineTo(400.0, 200.0);
path2.LineTo(400.0, 400.0);
path2.LineTo(200.0, 400.0);
path2.LineTo(200.0, 200.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(200.0, 300.0);
resultIntersect.LineTo(300.0, 300.0);
resultIntersect.LineTo(300.0, 200.0);
resultIntersect.LineTo(200.0, 200.0);
resultIntersect.LineTo(200.0, 300.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(100.0, 100.0);
resultUnite.LineTo(100.0, 300.0);
resultUnite.LineTo(200.0, 300.0);
resultUnite.LineTo(200.0, 400.0);
resultUnite.LineTo(400.0, 400.0);
resultUnite.LineTo(400.0, 200.0);
resultUnite.LineTo(300.0, 200.0);
resultUnite.LineTo(300.0, 100.0);
resultUnite.LineTo(100.0, 100.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(100.0, 100.0);
resultSubtract.LineTo(100.0, 300.0);
resultSubtract.LineTo(200.0, 300.0);
resultSubtract.LineTo(200.0, 200.0);
resultSubtract.LineTo(300.0, 200.0);
resultSubtract.LineTo(300.0, 100.0);
resultSubtract.LineTo(100.0, 100.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, CurveIntersLine)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.AddEllipse(-300.0, -300.0, 200.0, 200.0);
path2.StartFigure();
path2.MoveTo(-200.0, -200.0);
path2.LineTo(0.0, -200.0);
path2.LineTo(0.0, 0.0);
path2.LineTo(-200.0, 0.0);
path2.LineTo(-200.0, -200.0);
path2.CloseFigure();
resultIntersect.StartFigure();
resultIntersect.MoveTo(-100.0, -200.0);
resultIntersect.CurveTo(-100.0, -144.772, -144.772, -100.0, -200.0, -100.0);
resultIntersect.LineTo(-200.0, -200.0);
resultIntersect.LineTo(-100.0, -200.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(-100.0, -200.0);
resultUnite.LineTo(0.0, -200.0);
resultUnite.LineTo(0.0, 0.0);
resultUnite.LineTo(-200.0, 0.0);
resultUnite.LineTo(-200.0, -100.0);
resultUnite.CurveTo(-255.228, -100.0, -300.0, -144.772, -300.0, -200.0);
resultUnite.CurveTo(-300.0, -255.228, -255.228, -300.0, -200.0, -300.0);
resultUnite.CurveTo(-144.772, -300.0, -100.0, -255.228, -100.0, -200.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(-100.0, -200.0);
resultSubtract.LineTo(-200.0, -200.0);
resultSubtract.LineTo(-200.0, -100.0);
resultSubtract.CurveTo(-255.228, -100.0, -300.0, -144.772, -300.0, -200.0);
resultSubtract.CurveTo(-300.0, -255.228, -255.228, -300.0, -200.0, -300.0);
resultSubtract.CurveTo(-144.772, -300.0, -100.0, -255.228, -100.0, -200.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}
TEST(BooleanOperations, CurveIntersCurve)
{
Aggplus::CGraphicsPath path1, path2, resultIntersect, resultUnite, resultSubtract;
path1.AddEllipse(-300.0, -300.0, 200.0, 200.0);
path2.AddEllipse(-200.0, -200.0, 200.0, 200.0);
resultIntersect.StartFigure();
resultIntersect.MoveTo(-100.0, -200.0);
resultIntersect.CurveTo(-100.0, -144.772, -144.772, -100.0, -200.0, -100.0);
resultIntersect.CurveTo(-200.0, -155.228, -155.228, -200.0, -100.0, -200.0);
resultIntersect.CloseFigure();
resultUnite.StartFigure();
resultUnite.MoveTo(-100.0, -200.0);
resultUnite.CurveTo(-44.772, -200.0, 0.0, -155.228, 0.0, -100.0);
resultUnite.CurveTo(0.0, -44.772, -44.772, 0.0, -100.0, 0.0);
resultUnite.CurveTo(-155.228, 0.0, -200.0, -44.772, -200.0, -100.0);
resultUnite.CurveTo(-255.228, -100.0, -300.0, -144.772, -300.0, -200.0);
resultUnite.CurveTo(-300.0, -255.228, -255.228, -300.0, -200.0, -300.0);
resultUnite.CurveTo(-144.772, -300.0, -100.0, -255.228, -100.0, -200.0);
resultUnite.CloseFigure();
resultSubtract.StartFigure();
resultSubtract.MoveTo(-100.0, -200.0);
resultSubtract.CurveTo(-155.228, -200.0, -200.0, -155.228, -200.0, -100.0);
resultSubtract.CurveTo(-255.228, -100.0, -300.0, -144.772, -300.0, -200.0);
resultSubtract.CurveTo(-300.0, -255.228, -255.228, -300.0, -200.0, -300.0);
resultSubtract.CurveTo(-144.772, -300.0, -100.0, -255.228, -100.0, -200.0);
resultSubtract.CloseFigure();
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Intersection) == resultIntersect);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Union) == resultUnite);
EXPECT_TRUE(Aggplus::CalcBooleanOperation(path1, path2, Aggplus::Subtraction) == resultSubtract);
}

View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,396 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vector>
CustomLabel::CustomLabel(QWidget *parent) : QLabel(parent)
{
setMouseTracking(true);
}
QPointF CustomLabel::GetStartPoint() const noexcept
{
return StartP;
}
double CustomLabel::GetDifferenceX() const noexcept
{
return CurrP.x() - StartP.x();
}
double CustomLabel::GetDifferenceY() const noexcept
{
return CurrP.y() - StartP.y();
}
bool CustomLabel::GetMovable() const noexcept
{
return Movable;
}
void CustomLabel::mousePressEvent(QMouseEvent *event)
{
StartP = event->pos();
Movable = true;
emit mousePress();
}
void CustomLabel::mouseReleaseEvent(QMouseEvent *event)
{
CurrP = event->pos();
Movable = false;
emit mousePress();
}
void CustomLabel::mouseMoveEvent(QMouseEvent *event)
{
CurrP = event->pos();
emit mouseMove();
}
CustomButton::CustomButton(QWidget *parent) : QPushButton(parent)
{
}
BooleanButton::BooleanButton(QWidget *parent) : QPushButton(parent)
{
}
std::vector<QObject*> GetChildsByClassName(QObject* parent, const QString& name)
{
std::vector<QObject*> res;
foreach (QObject* child, parent->children())
{
if (QString(child->metaObject()->className()) == name)
res.push_back(child);
else
{
if (!child->children().empty())
{
std::vector<QObject*> resChilds = GetChildsByClassName(child, name);
res.insert(res.end(), resChilds.begin(), resChilds.end());
}
}
}
return res;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
Figure1 = "";
Figure2 = "";
Op = Aggplus::Intersection;
std::vector<QObject*> arrPathButtons = GetChildsByClassName(this, "CustomButton");
std::vector<QObject*> arrBooleanButtons = GetChildsByClassName(this, "BooleanButton");
for (std::vector<QObject*>::iterator i = arrPathButtons.begin(); i != arrPathButtons.end(); i++)
connect((QPushButton*)(*i), &QPushButton::clicked, this, &MainWindow::SetFigure);
for (std::vector<QObject*>::iterator i = arrBooleanButtons.begin(); i != arrBooleanButtons.end(); i++)
connect((QPushButton*)(*i), &QPushButton::clicked, this, &MainWindow::SetCommand);
Path1.StartFigure();
Path1.MoveTo(100.0, 100.0);
Path1.LineTo(150.0, 150.0);
Path1.LineTo(200.0, 150.0);
Path1.LineTo(100.0, 100.0);
Path1.CloseFigure();
Path1.MoveTo(300.0, 300.0);
Path1.LineTo(400.0, 300.0);
Path1.LineTo(400.0, 400.0);
Path1.LineTo(300.0, 400.0);
Path1.LineTo(300.0, 300.0);
Path1.CloseFigure();
Path2.StartFigure();
Path2.MoveTo(100.0, 125.0);
Path2.LineTo(100.0, 350.0);
Path2.LineTo(350.0, 350.0);
Path2.LineTo(350.0, 125.0);
Path2.LineTo(100.0, 125.0);
Path2.CloseFigure();
Result = Aggplus::CalcBooleanOperation(Path1, Path2, Aggplus::Intersection);
Draw(true);
}
void MainWindow::SetFigure()
{
QPushButton* sender = (QPushButton*)this->sender();
if (((QGroupBox*)sender->parentWidget())->title() == "Path1")
{
Figure1 = sender->text();
DrawPath1();
}
if (((QGroupBox*)sender->parentWidget())->title() == "Path2")
{
Figure2 = sender->text();
DrawPath2();
}
}
void MainWindow::SetCommand()
{
QString text = ((QPushButton*)sender())->text();
if (text == "Unite")
Op = Aggplus::Union;
else if (text == "Intersect")
Op = Aggplus::Intersection;
else
Op = Aggplus::Subtraction;
BooleanOp();
}
MainWindow::~MainWindow()
{
delete ui;
}
Aggplus::CGraphicsPath MainWindow::SetPath(double scale, double offsetX, double offsetY, QString Figure)
{
Aggplus::CGraphicsPath path;
path.StartFigure();
if (Figure == "Rectangle")
{
path.MoveTo(RECTANGLE[0] + offsetX,
RECTANGLE[1] + offsetY);
path.LineTo(RECTANGLE[0] + scale * RECTANGLE[2] + offsetX,
RECTANGLE[1] + offsetY);
path.LineTo(RECTANGLE[0] + scale * RECTANGLE[2] + offsetX,
RECTANGLE[1] + scale * RECTANGLE[3] + offsetY);
path.LineTo(RECTANGLE[0] + offsetX,
RECTANGLE[1] + scale * RECTANGLE[3] + offsetY);
path.LineTo(RECTANGLE[0] + offsetX,
RECTANGLE[1] + offsetY);
}
else if (Figure == "Ellipse")
{
path.AddEllipse(RECTANGLE[0] + offsetX,
RECTANGLE[1] + offsetY,
scale * RECTANGLE[2],
scale * RECTANGLE[3]);
}
else if (Figure == "Triangle")
{
path.MoveTo(TRIANGLE[0] + offsetX,
TRIANGLE[1] + offsetY);
for (size_t i = 2; i < std::size(TRIANGLE); i += 2)
path.LineTo(TRIANGLE[0] + scale * TRIANGLE[i] + offsetX,
TRIANGLE[1] + scale * TRIANGLE[i + 1] + offsetY);
path.LineTo(TRIANGLE[0] + offsetX,
TRIANGLE[1] + offsetY);
}
else if (Figure == "Cross")
{
path.MoveTo(CROSS[0] + offsetX,
CROSS[1] + offsetY);
for (size_t i = 2; i < std::size(CROSS); i += 2)
path.LineTo(CROSS[0] + scale * CROSS[i] + offsetX,
CROSS[1] + scale * CROSS[i + 1] + offsetY);
path.LineTo(CROSS[0] + offsetX,
CROSS[1] + offsetY);
}
path.CloseFigure();
return path;
}
void MainWindow::AddPath(NSGraphics::IGraphicsRenderer* pathRenderer, const Aggplus::CGraphicsPath& path, bool isResult)
{
if (path.GetPointCount() == 0)
return;
pathRenderer->PathCommandStart();
pathRenderer->BeginCommand(c_nPathType);
size_t length = path.GetPointCount(),
compound = path.GetCloseCount();
std::vector<Aggplus::PointD> points = path.GetPoints(0, length + compound);
for (size_t i = 0; i < length + compound; i++)
{
if (path.IsCurvePoint(i))
{
pathRenderer->PathCommandCurveTo(points[i].X + NEGATIVE_OFFSET, points[i].Y + NEGATIVE_OFFSET,
points[i + 1].X + NEGATIVE_OFFSET, points[i + 1].Y + NEGATIVE_OFFSET,
points[i + 2].X + NEGATIVE_OFFSET, points[i + 2].Y + NEGATIVE_OFFSET);
i += 2;
}
else if (path.IsMovePoint(i))
pathRenderer->PathCommandMoveTo(points[i].X + NEGATIVE_OFFSET, points[i].Y + NEGATIVE_OFFSET);
else if (path.IsLinePoint(i))
pathRenderer->PathCommandLineTo(points[i].X + NEGATIVE_OFFSET, points[i].Y + NEGATIVE_OFFSET);
}
if (isResult)
{
pathRenderer->put_BrushColor1(0xFF0000);
pathRenderer->Fill();
}
pathRenderer->put_PenColor(!isResult ? 0x000000 : 0x0000FF);
pathRenderer->DrawPath(c_nStroke);
pathRenderer->EndCommand(c_nPathType);
pathRenderer->PathCommandEnd();
}
void MainWindow::Draw(bool drawResult)
{
ui->label->clear();
NSGraphics::IGraphicsRenderer* pathRenderer = NSGraphics::Create();
NSFonts::IFontManager* fmp = NSFonts::NSFontManager::Create();
pathRenderer->SetFontManager(fmp);
int nW = ui->label->width();
int nH = ui->label->height();
BYTE* pData = new BYTE[4 * nW * nH];
CBgraFrame oFrame;
oFrame.put_Data(pData);
oFrame.put_Width(nW);
oFrame.put_Height(nH);
oFrame.put_Stride(4 * nW);
pathRenderer->CreateFromBgraFrame(&oFrame);
pathRenderer->SetSwapRGB(true);
pathRenderer->put_Width(nW);
pathRenderer->put_Height(nH);
AddPath(pathRenderer, Path1);
AddPath(pathRenderer, Path2);
if (drawResult)
{
AddPath(pathRenderer, Result, true);
}
QImage img = QImage(pData, nW, nH, QImage::Format_RGBA8888, [](void *data){
delete [] (BYTE*)data;
});
ui->label->setPixmap(QPixmap::fromImage(img));
}
void MainWindow::SetCoords(QLabel *label, const Aggplus::CGraphicsPath& path)
{
size_t length = path.GetPointCount();
std::vector<Aggplus::PointD> points = path.GetPoints(0, length);
QString text = "";
for (size_t i = 0; i < length; i++)
text += "(" + QString::number(points[i].X) +
"; " + QString::number(points[i].Y) + "); ";
label->setText(text);
}
void MainWindow::DrawPath1()
{
if (Path1.GetPointCount() > 0) Path1.Reset();
Path1 = SetPath(Scale[0], Offsets[0], Offsets[1], Figure1);
Draw();
SetCoords(ui->label_4, Path1);
}
void MainWindow::DrawPath2()
{
if (Path2.GetPointCount() > 0) Path2.Reset();
Path2 = SetPath(Scale[1], Offsets[2], Offsets[3], Figure2);
Draw();
SetCoords(ui->label_5, Path2);
}
void MainWindow::BooleanOp()
{
if (Path1.GetPointCount() == 0 || Path2.GetPointCount() == 0)
return;
Result = Aggplus::CalcBooleanOperation(Path1, Path2, Op);
Draw(true);
SetCoords(ui->label_7, Result);
}
void MainWindow::CheckMousePress()
{
if (!ui->label->GetMovable())
{
Move1 = false;
Move2 = false;
disconnect(ui->label, SIGNAL(mouseMove()), this, SLOT(Move()));
return;
}
QRectF rect1(RECTANGLE[0] + NEGATIVE_OFFSET + Offsets[0],
RECTANGLE[1] + NEGATIVE_OFFSET + Offsets[1],
Scale[0] * RECTANGLE[2],
Scale[0] * RECTANGLE[3]),
rect2(RECTANGLE[0] + NEGATIVE_OFFSET + Offsets[2],
RECTANGLE[1] + NEGATIVE_OFFSET + Offsets[3],
Scale[1] * RECTANGLE[2],
Scale[1] * RECTANGLE[3]);
Move1 = rect1.contains(ui->label->GetStartPoint()) && Path1.GetPointCount() != 0;
Move2 = rect2.contains(ui->label->GetStartPoint()) && Path2.GetPointCount() != 0;
if (Move2)
Move1 = false;
if (Move1 || Move2)
{
for (size_t i = 0; i < 4; i++)
OldOffsets[i] = Offsets[i];
connect(ui->label, SIGNAL(mouseMove()), this, SLOT(Move()));
}
}
inline double CheckOffset(double offset, double min, double max)
{
return std::max(min, std::min(max, offset));
}
void MainWindow::Move()
{
if (Move1)
{
Offsets[0] = CheckOffset(OldOffsets[0] + ui->label->GetDifferenceX(),
static_cast<double>(ui->label->x()),
static_cast<double>(ui->label->width()));
Offsets[1] = CheckOffset(OldOffsets[1] + ui->label->GetDifferenceY(),
static_cast<double>(ui->label->y()),
static_cast<double>(ui->label->height()));
DrawPath1();
}
if (Move2)
{
Offsets[2] = CheckOffset(OldOffsets[2] + ui->label->GetDifferenceX(),
static_cast<double>(ui->label->x()),
static_cast<double>(ui->label->width()));
Offsets[3] = CheckOffset(OldOffsets[3] + ui->label->GetDifferenceY(),
static_cast<double>(ui->label->y()),
static_cast<double>(ui->label->height()));
DrawPath2();
}
}
void MainWindow::on_horizontalSlider_sliderMoved(int position)
{
Scale[0] = position / 100.0;
DrawPath1();
}
void MainWindow::on_horizontalSlider_2_sliderMoved(int position)
{
Scale[1] = position / 100.0;
DrawPath2();
}

View File

@ -0,0 +1,111 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <QPushButton>
#include <QPoint>
#include <QMouseEvent>
#include "../../pro/Graphics.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
const double NEGATIVE_OFFSET= 400.0;
const double RECTANGLE[4] = {-400.0, -400.0, 200.0, 200.0};
const double TRIANGLE[6] = {-300.0, -400.0, 100.0, 200.0, -100.0, 100.0};
const double CROSS[24] = {-375.0, -325.0, 50.0, 0.0, 50.0, -50.0,
100.0, -50.0, 100.0, 0.0, 150.0, 0.0,
150.0, 50.0, 100.0, 50.0, 100.0, 100.0,
50.0, 100.0, 50.0, 50.0, 0.0, 50.0};
class CustomLabel : public QLabel
{
Q_OBJECT
public:
CustomLabel(QWidget *parent = nullptr);
QPointF GetStartPoint() const noexcept;
double GetDifferenceX() const noexcept;
double GetDifferenceY() const noexcept;
bool GetMovable() const noexcept;
signals:
void mousePress();
void mouseMove();
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
bool Movable = false;
QPointF StartP = {0.0, 0.0};
QPointF CurrP = {0.0, 0.0};
};
class CustomButton : public QPushButton
{
Q_OBJECT
public:
CustomButton(QWidget *parent = nullptr);
};
class BooleanButton : public QPushButton
{
Q_OBJECT
public:
BooleanButton(QWidget *parent = nullptr);
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
Aggplus::CGraphicsPath SetPath(double scale, double offsetX, double offsetY, QString Figure);
void AddPath(NSGraphics::IGraphicsRenderer* pathRenderer, const Aggplus::CGraphicsPath& path, bool isResult = false);
void Draw(bool drawResult = false);
void SetCoords(QLabel* label, const Aggplus::CGraphicsPath& path);
void DrawPath1();
void DrawPath2();
void BooleanOp();
private slots:
void CheckMousePress();
void Move();
void SetCommand();
void SetFigure();
void on_horizontalSlider_sliderMoved(int position);
void on_horizontalSlider_2_sliderMoved(int position);
public:
QString Figure1;
QString Figure2;
Aggplus::BooleanOpType Op;
double Scale[2] = {1.0, 1.0};
double Offsets[4] = {100.0, 100.0, 200.0, 200.0};
double OldOffsets[4];
bool Move1 = false;
bool Move2 = false;
Aggplus::CGraphicsPath Path1;
Aggplus::CGraphicsPath Path2;
Aggplus::CGraphicsPath Result;
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,437 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1441</width>
<height>859</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="CustomLabel" name="label">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>800</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>810</x>
<y>0</y>
<width>610</width>
<height>500</height>
</rect>
</property>
<property name="title">
<string/>
</property>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>191</width>
<height>480</height>
</rect>
</property>
<property name="title">
<string>Path1</string>
</property>
<widget class="CustomButton" name="pushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Rectangle</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Ellipse</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_6">
<property name="geometry">
<rect>
<x>20</x>
<y>120</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Triangle</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Coords:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>170</width>
<height>200</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QSlider" name="horizontalSlider">
<property name="geometry">
<rect>
<x>10</x>
<y>230</y>
<width>160</width>
<height>16</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="sliderPosition">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Scale:</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_8">
<property name="geometry">
<rect>
<x>20</x>
<y>160</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Cross</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>210</x>
<y>10</y>
<width>191</width>
<height>480</height>
</rect>
</property>
<property name="title">
<string>Path2</string>
</property>
<widget class="CustomButton" name="pushButton_7">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Rectangle</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_10">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Ellipse</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_12">
<property name="geometry">
<rect>
<x>20</x>
<y>120</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Triangle</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Coords:</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>170</width>
<height>200</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QSlider" name="horizontalSlider_2">
<property name="geometry">
<rect>
<x>10</x>
<y>230</y>
<width>160</width>
<height>16</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="sliderPosition">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Scale:</string>
</property>
</widget>
<widget class="CustomButton" name="pushButton_9">
<property name="geometry">
<rect>
<x>20</x>
<y>160</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Cross</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>410</x>
<y>10</y>
<width>191</width>
<height>480</height>
</rect>
</property>
<property name="title">
<string>Result</string>
</property>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Coords:</string>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>170</width>
<height>200</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="BooleanButton" name="pushButton_15">
<property name="geometry">
<rect>
<x>20</x>
<y>120</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Subtract</string>
</property>
</widget>
<widget class="BooleanButton" name="pushButton_16">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Intersect</string>
</property>
</widget>
<widget class="BooleanButton" name="pushButton_17">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>83</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Unite</string>
</property>
</widget>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1441</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>CustomButton</class>
<extends>QPushButton</extends>
<header>mainwindow.h</header>
</customwidget>
<customwidget>
<class>BooleanButton</class>
<extends>QPushButton</extends>
<header>mainwindow.h</header>
</customwidget>
<customwidget>
<class>CustomLabel</class>
<extends>QLabel</extends>
<header>mainwindow.h</header>
<slots>
<signal>mousePress()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>label</sender>
<signal>mousePress()</signal>
<receiver>MainWindow</receiver>
<slot>CheckMousePress()</slot>
<hints>
<hint type="sourcelabel">
<x>249</x>
<y>274</y>
</hint>
<hint type="destinationlabel">
<x>561</x>
<y>276</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>CheckMousePress()</slot>
</slots>
</ui>

View File

@ -0,0 +1,20 @@
QT += core gui widgets
QMAKE_CXXFLAGS += /permissive-
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
PWD_ROOT_DIR = $$PWD
CORE_ROOT_DIR = $$PWD/../../../../../core
include($$CORE_ROOT_DIR/Common/base.pri)
ADD_DEPENDENCY(kernel, graphics, UnicodeConverter)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)

View File

@ -177,7 +177,8 @@ namespace MetaFile
std::wstring CEmfLogFont::GetFaceName() const
{
return NSFile::CUtf8Converter::GetWStringFromUTF16(oLogFontEx.oLogFont.ushFaceName, 32);
const std::wstring wsFaceName{NSFile::CUtf8Converter::GetWStringFromUTF16(oLogFontEx.oLogFont.ushFaceName, 32)};
return wsFaceName.substr(0, wsFaceName.find(L'\0'));
}
int CEmfLogFont::GetWeight() const

View File

@ -1640,8 +1640,8 @@ namespace MetaFile
BYTE* pNewBuffer = GetClipedImage(pPixels, nWidth, nHeight, oClipRect);
const unsigned int unWidth = std::min(((unsigned int)fabs(oClipRect.Right - oClipRect.Left)), ((unsigned int)nWidth ));
const unsigned int unHeight = std::min(((unsigned int)fabs(oClipRect.Bottom - oClipRect.Top)), ((unsigned int)nHeight));
const unsigned int unWidth = std::min(((unsigned int)abs(oClipRect.Right - oClipRect.Left)), ((unsigned int)nWidth ));
const unsigned int unHeight = std::min(((unsigned int)abs(oClipRect.Bottom - oClipRect.Top)), ((unsigned int)nHeight));
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X - m_pDC->GetPixelWidth(), arPoints[2].Y - arPoints[0].Y - m_pDC->GetPixelHeight(),
(NULL != pNewBuffer) ? pNewBuffer : pPixels, unWidth, unHeight);
@ -1655,8 +1655,6 @@ namespace MetaFile
oParser.PlayFile();
const TXForm& oXForm{m_pDC->GetTransform()};
TRectD oRect;
oRect.Left = arPoints[0].X;
@ -1671,9 +1669,7 @@ namespace MetaFile
oTempSrcRect.Right = oTempSrcRect.Left + ((dFileWidth > oSrcRect.dWidth) ? oSrcRect.dWidth - GetPixelWidth() : dFileWidth);
oTempSrcRect.Bottom = oTempSrcRect.Top + ((dFileHeight > oSrcRect.dHeight) ? oSrcRect.dHeight - GetPixelHeight() : dFileHeight);
TXForm oTransform;
oTransform.Copy(oXForm);
TXForm oTransform(m_pDC->GetTransform());
oTransform.Dx -= m_oHeader.oFramePx.Left;
oTransform.Dy -= m_oHeader.oFramePx.Top;
@ -3210,8 +3206,6 @@ namespace MetaFile
m_oStream >> oMatrix;
UpdateMatrix(oMatrix);
m_pDC->MultiplyTransform(oMatrix, MWT_SET);
UpdateOutputDC();
}

View File

@ -721,14 +721,14 @@ namespace MetaFile
TEmfXForm oViewportXForm(GetPixelWidth() * dM11, 0, 0, GetPixelHeight() * dM22, oViewPort.lX, oViewPort.lY);
m_oFinalTransform.Init();
m_oFinalTransform.Multiply(oViewportXForm, MWT_RIGHTMULTIPLY);
m_oFinalTransform.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
m_oFinalTransform.Multiply(oWindowXForm, MWT_RIGHTMULTIPLY);
m_oFinalTransform.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
m_oFinalTransform.Multiply(oViewportXForm, MWT_RIGHTMULTIPLY);
m_oFinalTransform2.Init();
m_oFinalTransform2.Multiply(oViewportXForm, MWT_RIGHTMULTIPLY);
m_oFinalTransform2.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
m_oFinalTransform2.Multiply(oWindowXForm, MWT_RIGHTMULTIPLY);
m_oFinalTransform2.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
m_oFinalTransform2.Multiply(oViewportXForm, MWT_RIGHTMULTIPLY);
}
void CEmfDC::FixIsotropic()

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