Compare commits

...

201 Commits

Author SHA1 Message Date
dc485997f0 Merge pull request #1539 from ONLYOFFICE/feature/StarMath
Fix StarMath
2024-06-06 22:15:52 +03:00
2e6d5450b4 fix bug #66811 2024-06-06 16:22:04 +03:00
b428487d07 Merge pull request #1535 from ONLYOFFICE/fix/bug-68123
Fix bug 68123
2024-06-06 13:22:30 +03:00
96ea86e3c0 Fix bug 68123 2024-06-06 13:09:07 +03:00
5c7d0a61be fix bug 68332 2024-06-06 11:59:48 +03:00
4014d4914f fix bug 68327 2024-06-06 11:02:30 +03:00
0b77fb2bba fix bug 68333 2024-06-06 10:38:01 +03:00
2e1ccbc985 For bug 46629 2024-06-06 10:21:51 +03:00
f5202108a1 Merge pull request #1534 from ONLYOFFICE/fix/bug-68252
Fix bug #68252
2024-06-06 09:45:18 +03:00
2f7407bd8e Merge pull request #1533 from ONLYOFFICE/fix/bug-67967
Fix bug 67967
2024-06-06 09:45:00 +03:00
ac721572f2 Fix bug #67967 2024-06-06 08:51:59 +03:00
33da43b2f4 Fix bug 67747 2024-06-05 19:57:56 +03:00
591dffc965 Merge pull request #1531 from ONLYOFFICE/feature/StarMath
fix bug 68328
2024-06-05 15:57:20 +03:00
cd74ef4ded fix bug 68328 2024-06-05 15:52:33 +03:00
c7612a259d Add support create & save pdf forms 2024-06-05 14:41:41 +03:00
586455310a Merge pull request #1530 from ONLYOFFICE/fix/pdf-tilingPattern
Fix swap RGB pdf tilingPattern
2024-06-05 12:25:31 +03:00
96008085d6 Fix swap RGB 2024-06-05 11:46:30 +03:00
282b87e518 Merge pull request #1529 from ONLYOFFICE/fix/bug-63346
Fix bugs 63346, 66523
2024-06-05 11:16:00 +03:00
115a60c273 For bug 68216 2024-06-05 02:26:58 +03:00
66d48673cf Fix min tilingPattern 2024-06-04 15:41:58 +03:00
29ef74770a Fix bug 66523 2024-06-04 13:22:18 +03:00
15247d39f0 Fix bug 63346 2024-06-04 12:22:21 +03:00
145154690b Merge pull request #1528 from ONLYOFFICE/fix/bug-68349
For bug 68349
2024-06-04 09:59:16 +03:00
4f28d8d3d8 For bug 68349 2024-06-04 09:55:42 +03:00
2fdd88bee2 Merge remote-tracking branch 'origin/fix/bug68170' into release/v8.1.0 2024-06-03 14:50:28 +03:00
7c501fe5a3 Fix bug #68252 2024-06-03 12:06:29 +03:00
acbf5b0c40 Fix bug #68170
Add image alternative text and description
2024-06-03 13:22:38 +05:00
d843cf1fe1 Fix bug #63489
Convert text divided into columns
2024-06-03 13:21:35 +05:00
50529346e4 Merge remote-tracking branch 'origin/release/v8.1.0' into fix/bug63489 2024-06-03 13:21:03 +05:00
803fcf3602 fix bug #68304 2024-06-02 17:35:48 +03:00
d83930bf67 fix bug #68307 2024-06-02 16:59:20 +03:00
cd5ca284e1 Change IsDouble method: return true if value has integer type 2024-06-02 15:37:04 +03:00
7a1a59a883 For bug 68028 2024-06-02 10:20:52 +03:00
bfb97ef026 Merge pull request #1526 from ONLYOFFICE/fix/pdf-tilepattern
Fix pdf rotate point
2024-05-31 16:47:41 +03:00
742cfde620 Fix rotate point 2024-05-31 16:39:41 +03:00
600fd26e30 fix build 2024-05-31 13:45:15 +03:00
92fa08303e Merge pull request #1525 from ONLYOFFICE/fix/pdf-default-color
Fix default color
2024-05-31 11:52:22 +03:00
17bd0f99dd Fix default color 2024-05-31 11:49:05 +03:00
d5d4d06553 Merge pull request #1517 from ONLYOFFICE/fix/bug66009
Fix bug #66009
2024-05-30 16:47:53 +03:00
400da99fa9 Merge pull request #1522 from ONLYOFFICE/fix/bug68229
Fix bug #68229
2024-05-30 16:46:56 +03:00
b209e00333 fix bug #68276 2024-05-30 16:30:59 +03:00
1859173fb6 Merge pull request #1523 from ONLYOFFICE/fix/bug-68256
Fix bug 68256
2024-05-30 13:06:54 +03:00
dfb0aeefcb Fix read/write tilingPattern in pdf 2024-05-30 12:45:56 +03:00
6ba5d1141e Fix bug 68256 2024-05-30 12:45:17 +03:00
8d6a13b24a Fix bug #68229 2024-05-30 15:41:52 +06:00
a66fdc73a5 fix bug #68264 2024-05-29 20:35:44 +03:00
a2b8fcc5e1 for bug #61035 2024-05-29 20:03:17 +03:00
7ac5ff5383 Merge pull request #1521 from ONLYOFFICE/fix/bug-68233
Fix bug 68233
2024-05-29 15:50:42 +03:00
5e560528a4 Fix bug 68233 2024-05-29 15:08:32 +03:00
b8c57da779 Merge pull request #1519 from ONLYOFFICE/fix/html
Fix html/mht bugs
2024-05-29 11:43:39 +03:00
19951d807c Merge pull request #1520 from ONLYOFFICE/feature/jsc-inspectable-context
Set contexts inspectable for JSC
2024-05-29 09:58:59 +03:00
49d1426831 Fix bug #68230 2024-05-29 01:33:56 +03:00
e8ae960a26 Fix bug #68235 2024-05-29 01:32:54 +03:00
11ddc0ab4f Set contexts inspectable for JSC 2024-05-28 23:50:21 +04:00
5361740a02 Merge pull request #1518 from ONLYOFFICE/fix/bug-68225
Fix bug 68225
2024-05-28 16:44:09 +03:00
0050c6148c Fix bug 68225 2024-05-28 16:33:41 +03:00
8e3df68ffc fix bug #50594 2024-05-28 15:27:12 +03:00
ab829fa8db fix bug #68213 2024-05-28 11:28:19 +03:00
bc56de19c1 Fix bug #66009 2024-05-27 20:11:30 +06:00
1de6787014 Merge pull request #1516 from ONLYOFFICE/feature/StarMath
fix StarMath attribute
2024-05-27 13:32:11 +03:00
b02189c14d Merge pull request #1504 from ONLYOFFICE/fix/html
Fix html bugs
2024-05-27 13:23:40 +03:00
63003a5e76 fix bug 68094 2024-05-27 11:57:54 +03:00
499810dbae . 2024-05-27 08:01:06 +03:00
f55d822c4f fix build 2024-05-26 20:17:44 +03:00
4c51371b96 Merge pull request #1513 from ONLYOFFICE/fix/pdf-rotate
Fix pdf rotate
2024-05-25 21:53:19 +03:00
986bcae0e2 Merge pull request #1514 from ONLYOFFICE/fix/bug68109
Fix bug #68109
2024-05-24 17:20:27 +03:00
96b87265bb Merge pull request #1515 from ONLYOFFICE/fix/bug68113
Fix bug #68113
2024-05-24 17:19:24 +03:00
0be217ba05 Fix bug #68109 2024-05-24 18:23:17 +06:00
af12226bfa Fix FlateDecode for annot view 2024-05-24 14:51:30 +03:00
d51f035561 Fix AddShape for NewPage 2024-05-24 14:32:29 +03:00
d01681bb1e Fix bug #66549 2024-05-24 12:02:18 +03:00
72e975f7d9 Merge pull request #1512 from ONLYOFFICE/fix/pdf-bug
Fix bugs 54371, 67641
2024-05-24 09:57:00 +03:00
ba87df6b9d Fix bug 67641 2024-05-24 09:36:51 +03:00
a1fed79a78 Fix bug 54371 2024-05-24 09:36:31 +03:00
08111e8fde fix bug #67992 2024-05-23 17:46:02 +03:00
1286b7f458 fix bug #68122 2024-05-23 17:27:42 +03:00
dcb4364410 Fix bug 67641 2024-05-23 17:23:06 +03:00
55a009713e Fix bug 54371 2024-05-23 16:56:40 +03:00
474828364f Merge remote-tracking branch 'origin/release/v8.1.0' into fix/pdf-rotate 2024-05-23 16:31:30 +03:00
9e145ef9e0 Merge pull request #1511 from ONLYOFFICE/fix/pdf-bug
Fix 67740
2024-05-23 16:27:40 +03:00
40b6178a0d Fix c_nPenWidth0As1px for annot/field renderer 2024-05-23 16:22:52 +03:00
a70f50206d fix bug #67917 2024-05-23 14:36:14 +03:00
40fa3e60c4 Merge remote-tracking branch 'origin/release/v8.1.0' into fix/bug63489 2024-05-23 16:35:05 +05:00
105a193742 fix bug #68143 2024-05-23 14:00:28 +03:00
4ca9a94609 Fix bugs in html 2024-05-23 13:00:50 +03:00
3bfb3ee045 Fix bug #68113 2024-05-23 15:17:23 +06:00
512df584ba Merge branch 'release/v8.1.0' of https://github.com/ONLYOFFICE/core into release/v8.1.0 2024-05-23 12:03:20 +03:00
84eebc69e1 fix bug #68135 2024-05-23 12:03:14 +03:00
7abb3899a7 Merge pull request #1499 from ONLYOFFICE/fix/bug65948
fix bug #65948
2024-05-23 11:48:49 +03:00
f19906c14c Merge pull request #1500 from ONLYOFFICE/fix/bug66694
Fix bug #66694
2024-05-23 11:48:09 +03:00
fd15cdf4d0 Merge pull request #1508 from ONLYOFFICE/fix/bug66675
Fix bug #66675
2024-05-23 11:47:32 +03:00
9d3e553086 Merge pull request #1510 from ONLYOFFICE/fix/bug68111
Fix bug #68111
2024-05-23 11:46:11 +03:00
a19b4a03b3 Fixed a bug with attributes of functions and indexes 2024-05-23 11:27:28 +03:00
90650b1af8 Merge remote-tracking branch 'origin/fix/bug67380' into release/v8.1.0 2024-05-22 19:27:19 +03:00
3780922610 Fix bug #68111 2024-05-22 21:42:33 +06:00
fbb7ab93d6 Fix bug 67740 2024-05-22 17:37:33 +03:00
ca5201e704 FreeText has Rotate 2024-05-22 16:49:19 +03:00
2b13696379 Merge pull request #1509 from ONLYOFFICE/feature/docbuilder-python
Add new features to python docbuilder wrapper
2024-05-22 16:41:20 +03:00
24b32a2ba7 Fix bug #67380 2024-05-22 17:56:53 +05:00
1cdb2b0f15 Add list constructor and automatic conversion to CValue in functions 2024-05-22 16:52:13 +04:00
7758da7173 Add number constants for file types 2024-05-22 15:55:39 +04:00
3cd89354bc Fix pdf rotate for drawingfile 2024-05-22 11:08:12 +03:00
5fbed3db1c Fix double hashtag for color in RC 2024-05-22 10:30:09 +03:00
f28119e646 fix bug #68010 2024-05-21 20:47:23 +03:00
a2b0495254 Fix bug #66675 2024-05-21 21:11:57 +06:00
28f873be5c Merge pull request #1507 from ONLYOFFICE/feature/docbuilder-python
Add functionality in docbuilder python wrapper
2024-05-21 18:10:39 +03:00
5dede9304b Add support added images on recognize 2024-05-21 16:52:54 +03:00
ab52ee7486 Move PATH modify to windows-only section 2024-05-21 17:37:34 +04:00
8f711f607f fix bug #67989 2024-05-21 11:25:57 +03:00
f2c5fed3c1 Merge pull request #1506 from ONLYOFFICE/fix/pdf-free-text
Fix FreeText renderer length
2024-05-21 10:54:01 +03:00
1602fb2106 Fix FreeText renderer length 2024-05-21 10:49:49 +03:00
c3f72756a4 Merge pull request #1505 from ONLYOFFICE/fix/pdf-build 2024-05-21 10:19:51 +03:00
5f8b557eb5 Fix pdf build 2024-05-21 10:18:18 +03:00
9d8e75a957 Fix library names for linux and mac 2024-05-20 19:40:40 +04:00
839844cb4f Merge pull request #1503 from ONLYOFFICE/fix/pdf-shape-img
Fix pdf shape image
2024-05-20 17:57:59 +03:00
fac976a22e Read and write image ref for OShapes 2024-05-20 17:52:22 +03:00
84cb59d7b2 Merge pull request #1502 from ONLYOFFICE/fix/pdf-freetext-rc
Fix pdf freetext
2024-05-20 14:09:06 +03:00
788620079d Add loadLibrary() check and automatic Dispose() 2024-05-20 14:33:43 +04:00
0e5b95f1d8 Refactoring 2024-05-20 13:29:38 +04:00
d0a82d71ee Fix build 2024-05-20 12:29:00 +03:00
97f742f816 Merge remote-tracking branch 'origin/release/v8.1.0' into fix/pdf-freetext-rc
# Conflicts:
#	PdfFile/PdfEditor.cpp
2024-05-20 10:14:57 +03:00
58980e61b7 Fix typo and create folder for tests 2024-05-19 12:02:37 +03:00
5a04f9033b Fix build 2024-05-19 11:33:45 +03:00
28785f13bc Merge pull request #1501 from ONLYOFFICE/feature/docbuilder-python
Feature/docbuilder python
2024-05-19 11:23:46 +03:00
7a73d3288c Refactoring 2024-05-19 11:21:18 +03:00
d82b2dc6ef Fix bug #68073 2024-05-18 14:14:05 +03:00
6ad319554d Fix bug with font-size 2024-05-18 13:42:32 +03:00
ff3b94a23a Fix bug #68036 2024-05-18 13:05:58 +03:00
5227a593ed Fix bug #68034 2024-05-18 13:05:34 +03:00
c802944d3b Fixes in docbuilder.py
+ Add more complex example
+ Add .gitignore
2024-05-17 23:16:02 +04:00
93d77ee945 Added all classes to docbuilder.py 2024-05-17 22:09:38 +04:00
4c101b21d0 Changed lines ending for consistency 2024-05-17 22:07:17 +04:00
05366635c1 Remove development 2024-05-17 18:10:30 +03:00
d853d42090 Fix calculating glyph widths for Base14 fonts 2024-05-17 16:00:23 +03:00
cb06eae63e Merge remote-tracking branch 'origin/release/v8.1.0' into fix/bug63489 2024-05-17 17:20:42 +05:00
6ba40aba51 Fix bug #67380 2024-05-17 16:57:40 +05:00
b8d54fb295 fix bug #65948 2024-05-17 17:55:02 +06:00
84d7eb03f2 Add example of python wrapper 2024-05-17 14:11:22 +04:00
28cd584393 Fix delete functions and add simple c++ example 2024-05-17 14:10:50 +04:00
bd6cc8a759 Merge remote-tracking branch 'origin/fix/bug67926' into release/v8.1.0 2024-05-17 12:21:01 +03:00
7cfd4e2dfa Merge remote-tracking branch 'origin/fix/bug67822' into release/v8.1.0 2024-05-17 12:20:45 +03:00
f923f4e03d Merge remote-tracking branch 'origin/fix/bug67823' into release/v8.1.0 2024-05-17 12:20:32 +03:00
e8898ce424 Merge remote-tracking branch 'origin/fix/bug61378' into release/v8.1.0 2024-05-17 12:19:39 +03:00
ebe045a833 fix bug #67995 2024-05-17 11:56:18 +03:00
140f9970f9 Add wrapper library docbuilder_functions.dll and tests for it 2024-05-17 12:07:22 +04:00
3d23e74818 Fix bug #61378 2024-05-16 21:48:26 +05:00
c24c78267b Write Base14 fonts to pdf 2024-05-16 18:56:59 +03:00
a7501e370b Fix bug #66694 2024-05-16 19:06:13 +06:00
68200895d0 Merge pull request #1496 from ONLYOFFICE/fix/StarMath
Fix/StarMath
2024-05-16 13:57:28 +03:00
b6b99ee9f0 Redirect to annotation rendering 2024-05-15 17:43:59 +03:00
5ea601cde9 fix bug #67973 2024-05-15 16:25:51 +03:00
1e7611f3f9 Add method for duplicate image links on recognize 2024-05-15 13:20:20 +03:00
c14856ac6f fix bug #68011 2024-05-15 11:15:31 +03:00
8857d3daca fix bug #67972 2024-05-15 11:00:27 +03:00
ad1bd06bb3 fix bug #67968 2024-05-15 09:55:58 +03:00
52555f4d9d fix bug #67963 2024-05-15 09:24:08 +03:00
d85b3dd7f0 Support images on recognize 2024-05-14 21:43:21 +03:00
6af44146e5 Merge pull request #1495 from ONLYOFFICE/fix/bug66658
Fix bug 66658
2024-05-14 18:30:42 +03:00
f704c44e9e Merge pull request #1497 from ONLYOFFICE/fix/bug66678
Fix bug #66678
2024-05-14 18:30:10 +03:00
a9884c1efb Merge pull request #1498 from ONLYOFFICE/fix/bug66677
Fix bug #66677
2024-05-14 18:29:50 +03:00
2dc0956b3c Create CAnnotRenderer 2024-05-14 17:52:04 +03:00
7dbe7eb3e1 Fix bug #66677 2024-05-14 19:16:08 +06:00
5617968a0c Fix bug #67926 2024-05-14 17:51:19 +05:00
3b029ae4cd Merge branch 'release/v8.1.0' into fix/StarMath 2024-05-14 14:43:16 +03:00
73dc770870 Fix bug #66678 2024-05-14 17:41:48 +06:00
46e56afa5c bug fix(crashes, parsing correction) 2024-05-14 14:31:24 +03:00
e6842f50b3 Fix bug #bug66658 2024-05-14 15:20:51 +06:00
f008857ab2 Find Font for FreeText 2024-05-13 18:12:23 +03:00
e7022472ff Merge pull request #1492 from ONLYOFFICE/fix/bug67936
Fix bug #67936
2024-05-13 18:00:11 +03:00
b470c4b259 Merge pull request #1493 from ONLYOFFICE/fix/bug67933
Fix bug #67933
2024-05-13 17:59:56 +03:00
155103b40f Fix bug #67933 2024-05-13 15:30:01 +06:00
0eee7ea548 Merge pull request #1491 from ONLYOFFICE/fix/bug-67916
Fix bug #67916
2024-05-13 01:58:54 -07:00
b53527c9fd Fix bug #67936 2024-05-13 14:53:32 +06:00
7a842c4b14 Merge pull request #1489 from ONLYOFFICE/fix/html
Fix html
2024-05-12 12:45:44 -07:00
9779e53fe7 The algorithm for checking arrays has been rewritten 2024-05-12 21:50:04 +03:00
6bccf233ee Merge pull request #1477 from ONLYOFFICE/fix/html
Fix bugs in html converter
2024-05-12 06:46:37 -07:00
83e020f492 Fix bug #67916 2024-05-10 14:32:23 +03:00
5c7b7615dd Fix find FreeText Fonts object 2024-05-08 17:40:11 +03:00
d8bed77b67 Fix bug #67823 2024-05-08 17:05:49 +05:00
7ae79f20b8 Fix bug #67822 2024-05-08 15:12:22 +05:00
bb2967c3ea Write RD and CA for FreeText AP.N 2024-05-07 17:43:26 +03:00
88aba1cb02 Fix MK.IF.A default value 2024-05-07 11:43:20 +03:00
f1fbcf653b Create StartDrawFreeText 2024-05-06 17:48:12 +03:00
a2e76364e9 Fix bug #67827 2024-05-04 15:19:06 +03:00
051ae3fab6 Fix bug #67836 2024-05-04 00:34:50 +03:00
f1544a6f6c Fix bug#67829 2024-05-03 22:50:16 +03:00
715facaefc Create AP for FreeText 2024-05-03 17:32:37 +03:00
6de671ccd5 Added language consideration when converting EPUB files 2024-05-03 15:57:29 +03:00
9dceffdbeb Fix write RC to NSStringUtils::CStringBuilder 2024-05-03 15:36:51 +03:00
e107a67f55 Fix delete Link annot in edit mode 2024-05-03 15:36:14 +03:00
ddc413a1b3 Fix EditPage when adding Link in edit mode 2024-05-03 13:39:03 +03:00
5c6aaed51f Fix svg file size 2024-05-03 13:18:53 +03:00
234c1766dc Fix bug #67770 2024-05-03 13:18:26 +03:00
95d8fd2871 Fix bug #67767 2024-05-03 13:17:41 +03:00
013d6990ce Write RC to FreeText 2024-05-02 18:32:32 +03:00
f9bfdee8c3 Merge pull request #1470 from ONLYOFFICE/release/v8.1.0
Release/v8.1.0
2024-04-27 11:53:22 +03:00
4880ff705b Merge branch 'release/v8.1.0' into fix/StarMath 2024-04-26 17:30:39 +03:00
3acb44a5c9 Fixed drop in assessment. fix bugs. 2024-04-26 17:08:50 +03:00
1e18eb4335 Merge pull request #1459 from ONLYOFFICE/fix/x2t_date_time 2024-04-12 20:32:58 +03:00
ddb01d9478 Sets bDateTime true by default 2024-04-12 20:19:12 +03:00
10c6def10e Bug fixed. Editing sqrt and nroot, dropping parentheses. 2024-04-05 15:54:31 +03:00
226 changed files with 6093 additions and 1977 deletions

View File

@ -110,7 +110,7 @@ namespace NSCSS
void CCompiledStyle::AddStyle(const std::map<std::wstring, std::wstring>& mStyle, const unsigned int unLevel, const bool& bHardMode)
{
const bool bIsThereBorder = (m_oBorder.Empty()) ? false : true;
const double dFontSize = (!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Twips) : DEFAULT_FONT_SIZE;
const double dFontSize = (!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Point) : DEFAULT_FONT_SIZE;
for (std::pair<std::wstring, std::wstring> pPropertie : mStyle)
{
@ -180,7 +180,6 @@ namespace NSCSS
break;
m_oMargin.SetTop(pPropertie.second, unLevel, bHardMode);
m_oMargin.UpdateTop(dFontSize);
break;
}
CASE(L"margin-right"):
@ -489,6 +488,11 @@ namespace NSCSS
return arParentsName;
}
std::set<std::wstring> CCompiledStyle::GetParentsNamesSet() const
{
return m_arParentsStyles;
}
void CCompiledStyle::SetID(const std::wstring& sId)
{
m_sId = sId;

View File

@ -48,6 +48,7 @@ namespace NSCSS
void AddParent(const std::wstring& sParentName);
std::vector<std::wstring> GetParentsName() const;
std::set<std::wstring> GetParentsNamesSet() const;
void SetID(const std::wstring& sId);
std::wstring GetId() const;

View File

@ -52,13 +52,6 @@ namespace NSCSS
m_mData.clear();
#ifdef CSS_CALCULATOR_WITH_XHTML
for (std::map<std::vector<CNode>, CCompiledStyle*>::iterator iter = m_mUsedStyles.begin(); iter != m_mUsedStyles.end(); ++iter)
delete iter->second;
m_mUsedStyles.clear();
#endif
if (NULL != m_mStatictics)
delete m_mStatictics;
}
@ -494,11 +487,11 @@ namespace NSCSS
if (!bIsSettings)
{
const std::map<std::vector<CNode>, CCompiledStyle*>::iterator oItem = m_mUsedStyles.find(arSelectors);
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
if (oItem != m_mUsedStyles.end())
{
oStyle = *oItem->second;
oStyle = oItem->second;
return true;
}
}
@ -517,22 +510,22 @@ namespace NSCSS
std::vector<std::wstring> arNodes = CalculateAllNodes(arSelectors);
std::vector<std::wstring> arPrevNodes;
bool bInTable = false;
for (size_t i = 0; i < arSelectors.size(); ++i)
{
oStyle.AddParent(arSelectors[i].m_wsName);
// Скидываем некоторые внешние стили, которые внутри таблицы переопределяются
if (L"table" == arSelectors[i].m_wsName)
bInTable = true;
if (bInTable)
{
oStyle.m_oFont.GetLineHeight().Clear();
oStyle.m_oPadding.Clear();
oStyle.m_oMargin.Clear();
bInTable = true;
}
if (bInTable)
oStyle.m_oBorder.Clear();
}
CCompiledStyle oTempStyle;
@ -562,14 +555,10 @@ namespace NSCSS
oStyle += oTempStyle;
}
if (!bIsSettings)
{
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
CCompiledStyle *pTemp = new CCompiledStyle(oStyle);
m_mUsedStyles[arSelectors] = pTemp;
}
if (!bIsSettings && !oStyle.Empty())
m_mUsedStyles[arSelectors] = oStyle;
return true;
}

View File

@ -37,7 +37,7 @@ namespace NSCSS
std::map<StatistickElement, unsigned int> *m_mStatictics; // Количество повторений свойств id и style у селекторов
#ifdef CSS_CALCULATOR_WITH_XHTML
std::map<std::vector<CNode>, CCompiledStyle*> m_mUsedStyles;
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);

View File

@ -25,7 +25,7 @@ namespace NSCSS
}
CString::CString()
: CValue(L"", 0, false)
: CValue(L"", 0, false)
{}
CString::CString(const std::wstring &wsValue, unsigned int unLevel, bool bImportant)
@ -63,7 +63,7 @@ namespace NSCSS
if (m_bImportant && !bImportant)
return false;
if (arValiableValues.end() != std::find(arValiableValues.begin(), arValiableValues.end(), wsNewValue))\
if (arValiableValues.end() != std::find(arValiableValues.begin(), arValiableValues.end(), wsNewValue))
{
m_oValue = wsNewValue;
m_unLevel = unLevel;
@ -254,8 +254,9 @@ namespace NSCSS
bool CDigit::operator==(const CDigit &oDigit) const
{
return (std::abs(oDigit.m_oValue - m_oValue) <= DBL_EPSILON) &&
m_enUnitMeasure == oDigit.m_enUnitMeasure;
return (Empty() && oDigit.Empty()) ||
((std::abs(oDigit.m_oValue - m_oValue) <= DBL_EPSILON) &&
m_enUnitMeasure == oDigit.m_enUnitMeasure);
}
bool CDigit::operator!=(const double &oValue) const
@ -374,7 +375,7 @@ namespace NSCSS
bool CDigit::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
if (wsValue.empty() || (CHECK_CONDITIONS && !bHardMode))
if (wsValue.empty() || (CHECK_CONDITIONS && !bHardMode) || unLevel < m_unLevel)
return false;
std::wstring wsNewValue = wsValue;
@ -404,7 +405,12 @@ namespace NSCSS
m_enUnitMeasure = oValue.m_enUnitMeasure;
}
else if (NSCSS::Percent == oValue.m_enUnitMeasure)
m_oValue *= oValue.m_oValue / 100.;
{
if (m_unLevel == oValue.m_unLevel)
m_oValue = oValue.m_oValue;
else
m_oValue *= oValue.m_oValue / 100.;
}
else
m_oValue = oValue.ToDouble(m_enUnitMeasure);
@ -599,6 +605,11 @@ namespace NSCSS
return m_oValue.Empty();
}
bool CColor::None() const
{
return ColorNone == m_oValue.m_enType;
}
void CColor::Clear()
{
m_oValue.Clear();
@ -616,10 +627,10 @@ namespace NSCSS
if (m_oOpacity.Empty())
return 1.;
if (Percent == m_oOpacity.GetUnitMeasure())
if (UnitMeasure::Percent == m_oOpacity.GetUnitMeasure())
return m_oOpacity.ToDouble() / 100.;
if (None == m_oOpacity.GetUnitMeasure() && m_oOpacity.ToDouble() <= 1.)
if (UnitMeasure::None == m_oOpacity.GetUnitMeasure() && m_oOpacity.ToDouble() <= 1.)
return m_oOpacity.ToDouble();
return 1.;
@ -1126,7 +1137,7 @@ namespace NSCSS
bool CDisplay::SetDisplay(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
return m_oHAlign.SetValue(wsValue, NSConstValues::DISPLAY_VALUES, unLevel, bHardMode);
return m_oDisplay.SetValue(wsValue, NSConstValues::DISPLAY_VALUES, unLevel, bHardMode);
}
const CDigit& CDisplay::GetX() const
@ -1471,7 +1482,7 @@ namespace NSCSS
bool CBorderSide::Empty() const
{
return m_oWidth.Empty();
return m_oWidth.Empty() || m_oColor.None();
}
bool CBorderSide::Zero() const
@ -1503,6 +1514,15 @@ namespace NSCSS
m_oColor == oBorderSide.m_oColor;
}
CBorderSide &CBorderSide::operator =(const CBorderSide &oBorderSide)
{
m_oWidth = oBorderSide.m_oWidth;
m_oStyle = oBorderSide.m_oStyle;
m_oColor = oBorderSide.m_oColor;
return *this;
}
// BORDER
CBorder::CBorder()
{
@ -1739,6 +1759,18 @@ namespace NSCSS
m_oBottom == oBorder.m_oBottom;
}
CBorder &CBorder::operator =(const CBorder &oBorder)
{
m_oLeft = oBorder.m_oLeft;
m_oTop = oBorder.m_oTop;
m_oRight = oBorder.m_oRight;
m_oBottom = oBorder.m_oBottom;
m_enCollapse = oBorder.m_enCollapse;
return *this;
}
// TEXT
CText::CText()
{}
@ -1978,10 +2010,10 @@ namespace NSCSS
CIndent &CIndent::operator+=(const CIndent &oIndent)
{
m_oTop = oIndent.m_oTop;
m_oRight = oIndent.m_oRight;
m_oBottom = oIndent.m_oBottom;
m_oLeft = oIndent.m_oLeft;
if (!oIndent.m_oTop.Empty()) m_oTop = oIndent.m_oTop;
if (!oIndent.m_oRight.Empty()) m_oRight = oIndent.m_oRight;
if (!oIndent.m_oBottom.Empty()) m_oBottom = oIndent.m_oBottom;
if (!oIndent.m_oLeft.Empty()) m_oLeft = oIndent.m_oLeft;
return *this;
}
@ -2186,16 +2218,16 @@ namespace NSCSS
bool CFont::SetSize(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
const std::map<std::wstring, std::wstring> arAbsoluteFontValues =
{{L"xx-small", L"7.5pt"}, {L"x-small", L"10pt" },
const std::vector<std::pair<std::wstring, std::wstring>> arAbsoluteFontValues =
{{L"xx-small", L"7.5pt"}, {L"xx-large", L"36pt" },
{L"x-small", L"10pt" }, {L"x-large", L"24pt" },
{L"small", L"12pt" }, {L"medium", L"13.5pt"},
{L"large", L"18pt" }, {L"x-large", L"24pt" },
{L"xx-large", L"36pt" }};
{L"large", L"18pt" }};
size_t unFoundPos = std::wstring::npos;
std::wstring wsNewValue(wsValue);
for (const std::pair<std::wstring, std::wstring> oAbsValue : arAbsoluteFontValues)
for (const std::pair<std::wstring, std::wstring>& oAbsValue : arAbsoluteFontValues)
{
unFoundPos = wsNewValue.find(oAbsValue.first);
if (std::wstring::npos != unFoundPos)

View File

@ -229,6 +229,7 @@ namespace NSCSS
bool SetOpacity(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true);
bool Empty() const override;
bool None() const;
void Clear() override;
ColorType GetType() const;
@ -444,6 +445,7 @@ namespace NSCSS
CBorderSide& operator+=(const CBorderSide& oBorderSide);
bool operator==(const CBorderSide& oBorderSide) const;
CBorderSide& operator =(const CBorderSide& oBorderSide);
private:
CDigit m_oWidth;
CString m_oStyle;
@ -513,6 +515,8 @@ namespace NSCSS
CBorder& operator+=(const CBorder& oBorder);
bool operator==(const CBorder& oBorder) const;
CBorder& operator =(const CBorder& oBorder);
private:
CBorderSide m_oLeft;
CBorderSide m_oTop;

View File

@ -1,6 +1,7 @@
#include "CDocumentStyle.h"
#include <iostream>
#include <unordered_set>
#include <wchar.h>
#include <math.h>
#include <cmath>
@ -10,33 +11,66 @@
#define DEFAULT_LINEHEIGHT 240
#define LINEHEIGHTSCALE 10 // Значение LineHeight в OOXML должно быть в 10 раз больше чем указано в стиле
#define VALUE_TO_INT(value, unit_measure) \
(NSCSS::UnitMeasure::None != value.GetUnitMeasure()) ? \
value.ToInt(unit_measure) : \
static_cast<int>(NSCSS::CUnitMeasureConverter::ConvertPx(value.ToDouble(), unit_measure, 96) + 0.5)
namespace NSCSS
{
CStyleUsed::CStyleUsed(const std::wstring &wsId, bool bIsPStyle)
: m_bIsPStyle(bIsPStyle), m_wsId(wsId)
CStyleUsed::CStyleUsed(const CCompiledStyle &oStyle, bool bIsPStyle)
: m_oStyle(oStyle), m_bIsPStyle(bIsPStyle)
{}
bool CheckArrays(const std::vector<std::wstring>& arInitial, const std::set<std::wstring>& arFirst, const std::set<std::wstring>& arSecond)
{
std::unordered_set<std::wstring> arInitialSet(arInitial.begin(), arInitial.end());
std::vector<std::wstring> arCommonElements1;
std::vector<std::wstring> arCommonElements2;
for (const std::wstring& wsValue : arFirst)
{
if (arInitialSet.count(wsValue) > 0)
arCommonElements1.push_back(wsValue);
}
for (const std::wstring& wsValue : arSecond)
{
if (arInitialSet.count(wsValue) > 0)
arCommonElements2.push_back(wsValue);
}
if (arCommonElements1.size() != arCommonElements2.size())
return false;
std::sort(arCommonElements1.begin(), arCommonElements1.end());
std::sort(arCommonElements2.begin(), arCommonElements2.end());
return arCommonElements1 == arCommonElements2;
}
bool CStyleUsed::operator==(const CStyleUsed &oUsedStyle) const
{
return (m_bIsPStyle == oUsedStyle.m_bIsPStyle) && (m_wsId == oUsedStyle.m_wsId);
return m_bIsPStyle == oUsedStyle.m_bIsPStyle &&
CheckArrays(Names_Standard_Styles, m_oStyle.GetParentsNamesSet(), oUsedStyle.m_oStyle.GetParentsNamesSet()) &&
m_oStyle == oUsedStyle.m_oStyle;
}
std::wstring CStyleUsed::getId()
{
if (m_bIsPStyle)
return m_wsId;
return m_oStyle.GetId();
return m_wsId + L"-c";
return m_oStyle.GetId() + L"-c";
}
void CStyleUsed::setId(const std::wstring &sId)
CDocumentStyle::CDocumentStyle() : m_arStandardStyles(Names_Standard_Styles)
{
m_wsId = sId;
for (const std::wstring& oNameStandardStyle : Names_Standard_Styles)
m_arStandardStyles.push_back(oNameStandardStyle + L"-c");
}
CDocumentStyle::CDocumentStyle() : m_arStandardStyles({L"a", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6", L"h1-c",
L"h2-c", L"h3-c", L"h4-c", L"h5-c", L"h6-c", L"p-c", L"p", L"div-c", L"div", L"a-c"}) {}
CDocumentStyle::~CDocumentStyle()
{
m_arStandardStyles. clear();
@ -270,9 +304,10 @@ namespace NSCSS
oElement.AddBasicProperties(BProperties::B_CustomStyle, L"1");
}
void CDocumentStyle::SetPStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
void CDocumentStyle::SetPStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
{
ConvertStyle(oStyle, oXmlElement, true);
if (!bIsLite)
ConvertStyle(oStyle, oXmlElement, true);
if (oStyle.Empty())
return;
@ -306,10 +341,12 @@ namespace NSCSS
sSpacingValue.reserve(128);
if (!oStyle.m_oMargin.GetTop().Empty() && !oStyle.m_oMargin.GetTop().Zero())
sSpacingValue += L"w:before=\"" + std::to_wstring(oStyle.m_oMargin.GetTop().ToInt(NSCSS::Twips)) + L"\" ";
sSpacingValue += L"w:before=\"" + std::to_wstring(VALUE_TO_INT(oStyle.m_oMargin.GetTop(), NSCSS::Twips)) + L"\" w:beforeAutospacing=\"0\" ";
if (!oStyle.m_oMargin.GetBottom().Empty() && !oStyle.m_oMargin.GetBottom().Zero())
sSpacingValue += L"w:after=\"" + std::to_wstring(oStyle.m_oMargin.GetBottom().ToInt(NSCSS::Twips)) + L"\" ";
sSpacingValue += L"w:after=\"" + std::to_wstring(VALUE_TO_INT(oStyle.m_oMargin.GetBottom(), NSCSS::Twips)) + L"\" w:afterAutospacing=\"0\" ";
else if (oStyle.m_oMargin.GetBottom().Zero() || bInTable)
sSpacingValue += L"w:after=\"0\" ";
if (!oStyle.m_oFont.GetLineHeight().Empty() && !oStyle.m_oFont.GetLineHeight().Zero())
{
@ -318,6 +355,8 @@ namespace NSCSS
sSpacingValue += L" w:line=\"" + wsLine + L"\" w:lineRule=\"" + wsLineRule + L"\"";
}
else if (oStyle.m_oFont.GetLineHeight().Zero() || bInTable)
sSpacingValue += L"w:lineRule=\"auto\" w:line=\"240\"";
if (!sSpacingValue.empty())
oXmlElement.AddPropertiesInP(PProperties::P_Spacing, sSpacingValue);
@ -435,9 +474,11 @@ namespace NSCSS
return L"w:val=\"" + wsStyle + L"\" w:sz=\"" + std::to_wstring(nWidth) + + L"\" w:space=\"" + std::to_wstring(nSpace) + L"\" w:color=\"" + wsColor + L"\"";
}
void CDocumentStyle::SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
void CDocumentStyle::SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite)
{
ConvertStyle(oStyle, oXmlElement, false);
if (!bIsLite)
ConvertStyle(oStyle, oXmlElement, false);
if (oStyle.Empty() && oXmlElement.Empty())
return;
@ -482,9 +523,9 @@ namespace NSCSS
return false;
}
CStyleUsed structStyle(oStyle.GetId(), false);
CStyleUsed structStyle(oStyle, false);
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
std::vector<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
if (oItem != m_arStyleUsed.end())
{
@ -506,11 +547,13 @@ namespace NSCSS
bool CDocumentStyle::WriteLitePStyle(const CCompiledStyle &oStyle)
{
Clear();
if (oStyle.Empty())
return false;
CXmlElement oXmlElement;
SetPStyle(oStyle, oXmlElement);
SetPStyle(oStyle, oXmlElement, true);
if (oXmlElement.Empty())
return false;
@ -521,11 +564,13 @@ namespace NSCSS
bool CDocumentStyle::WriteLiteRStyle(const CCompiledStyle &oStyle)
{
Clear();
if (oStyle.Empty())
return false;
CXmlElement oXmlElement;
SetRStyle(oStyle, oXmlElement);
SetRStyle(oStyle, oXmlElement, true);
if (oXmlElement.Empty())
return false;
@ -544,8 +589,8 @@ namespace NSCSS
return true;
}
CStyleUsed structStyle(oStyle.GetId(), true);
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
CStyleUsed structStyle(oStyle, true);
std::vector<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
if (oItem != m_arStyleUsed.end())
{
@ -559,11 +604,6 @@ namespace NSCSS
if (oXmlElement.Empty())
return false;
structStyle.setId(oXmlElement.GetStyleId());
if (structStyle.getId().empty())
structStyle.setId(m_sId);
m_arStyleUsed.push_back(structStyle);
m_sStyle += oXmlElement.GetPStyle();

View File

@ -10,27 +10,28 @@ namespace NSCSS
{
class CStyleUsed
{
CCompiledStyle m_oStyle;
bool m_bIsPStyle;
std::wstring m_wsId;
public:
CStyleUsed(const std::wstring& wsId, bool bIsPStyle);
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle);
bool operator==(const CStyleUsed& oUsedStyle) const;
std::wstring getId();
void setId(const std::wstring& sId);
};
static const std::vector<std::wstring> Names_Standard_Styles = {L"a", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6",L"p", L"div"};
class CSSCALCULATOR_EXPORT CDocumentStyle
{
typedef NSConstValues::NSProperties::BasicProperties BProperties;
typedef NSConstValues::NSProperties::ParagraphProperties PProperties;
typedef NSConstValues::NSProperties::RunnerProperties RProperties;
std::list<std::wstring> m_arStandardStylesUsed;
std::list<std::wstring> m_arStandardStyles;
std::list<CStyleUsed> m_arStyleUsed;
std::vector<std::wstring> m_arStandardStylesUsed;
std::vector<std::wstring> m_arStandardStyles;
std::vector<CStyleUsed> m_arStyleUsed;
std::wstring m_sStyle;
std::wstring m_sId;
@ -39,8 +40,8 @@ namespace NSCSS
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, bool bIsLite = false);
void SetBorderStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement, const PProperties& enBorderProperty);
public:

View File

@ -45,7 +45,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_UnhideWhenUsed, L"true");
AddBasicProperties(CSSProperties::BasicProperties::B_SemiHidden, L"true");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"li")
{
@ -67,7 +67,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h1-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"0");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h2")
{
@ -78,7 +78,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h2-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"1");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h3")
{
@ -89,7 +89,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h3-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"2");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h4")
{
@ -100,7 +100,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h4-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"3");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h5")
{
@ -111,7 +111,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h5-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"4");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h6")
@ -123,7 +123,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring& sNameDefaultElement)
AddBasicProperties(CSSProperties::BasicProperties::B_Link, L"h6-c");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_OutlineLvl, L"5");
AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
// AddPropertiesInP(CSSProperties::ParagraphProperties::P_Spacing, L"w:before=\"100\" w:beforeAutospacing=\"1\" w:after=\"100\" w:afterAutospacing=\"1\"");
}
else if (sNameDefaultElement == L"h1-c")
{
@ -298,7 +298,7 @@ CXmlElement& CXmlElement::operator=(const CXmlElement& oElement)
return *this;
}
bool CXmlElement::operator==(const CXmlElement &oElement)
bool CXmlElement::operator==(const CXmlElement &oElement) const
{
return m_mBasicValues == oElement.m_mBasicValues &&
m_mPStyleValues == oElement.m_mPStyleValues &&

View File

@ -47,7 +47,7 @@ public:
CXmlElement& operator+=(const CXmlElement& oElement);
CXmlElement& operator= (const CXmlElement& oelement);
bool operator== (const CXmlElement& oElement);
bool operator== (const CXmlElement& oElement) const;
};
#endif // CXMLELEMENT_H

View File

@ -5,7 +5,6 @@ sys.path.append('../../../../build_tools/scripts')
import config
import base
import os
import build
base_directory = os.getcwd()

View File

@ -22,6 +22,23 @@ static std::string special_handling = "|html|body|";
static std::string no_entity_sub = ""; //"|style|";
static std::string treat_like_inline = "|p|";
static std::vector<std::string> html_tags = {"div","span","a","img","p","h1","h2","h3","h4","h5","h6",
"ul", "ol", "li","td","tr","table","thead","tbody","tfoot","th",
"br","form","input","button","section","nav","header","footer",
"main","figure","figcaption","strong","em","i", "b", "u","pre",
"code","blockquote","hr","script","link","meta","style","title",
"head","body","html","legend","optgroup","option","select","dl",
"dt","dd","time","data","abbr","address","area","base","bdi",
"bdo","cite","col","iframe","video","source","track","textarea",
"label","fieldset","colgroup","del","ins","details","summary",
"dialog","embed","kbd","map","mark","menu","meter","object",
"output","param","progress","q","samp","small","sub","sup","var",
"wbr","acronym","applet","article","aside","audio","basefont",
"bgsound","big","blink","canvas","caption","center","command",
"comment","datalist","dfn","dir","font","frame","frameset",
"hgroup","isindex","keygen","marquee","nobr","noembed","noframes",
"noscript","plaintext","rp","rt","ruby","s","strike","tt","xmp"};
static void prettyprint(GumboNode*, NSStringUtils::CStringBuilderA& oBuilder);
static std::string mhtTohtml(const std::string &sFileContent);
@ -40,10 +57,10 @@ static std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
{
if (bNeedConvert)
{ // Определение кодировки
std::string sEncoding = NSStringFinder::FindPropety(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\""});
std::string sEncoding = NSStringFinder::FindPropety(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\""}).m_sValue;
if (sEncoding.empty())
sEncoding = NSStringFinder::FindPropety(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "});
sEncoding = NSStringFinder::FindPropety(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "}).m_sValue;
if (!sEncoding.empty() && !NSStringFinder::Equals("utf-8", sEncoding))
{
@ -59,39 +76,12 @@ static std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
if (boost::regex_search(sFileContent, oResult, oRegex))
sFileContent.erase(0, oResult.position());
// Избавление от <a/>
size_t posA = sFileContent.find("<a ");
while(posA != std::string::npos)
{
size_t nBegin = sFileContent.find('<', posA + 1);
size_t nEnd = sFileContent.find("/>", posA);
if(nEnd < nBegin)
sFileContent.replace(nEnd, 2, "></a>");
posA = sFileContent.find("<a ", nBegin);
}
// Избавление от <title/>
posA = sFileContent.find("<title/>");
while (posA != std::string::npos)
{
sFileContent.replace(posA, 8, "<title></title>");
posA = sFileContent.find("<title/>", posA);
}
// Избавление от <script/>
posA = sFileContent.find("<script");
while (posA != std::string::npos)
{
size_t nEnd = 0;
size_t nEnd1 = sFileContent.find("/>", posA);
size_t nEnd2 = sFileContent.find("</script>", posA);
if (nEnd1 != std::string::npos)
nEnd = nEnd1 + 2;
if (nEnd2 != std::string::npos && (nEnd == 0 || (nEnd > 0 && nEnd2 < nEnd)))
nEnd = nEnd2 + 9;
sFileContent.erase(posA, nEnd - posA);
posA = sFileContent.find("<script", posA);
}
//Избавление от <a ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "a"));
//Избавление от <title ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "title"));
//Избавление от <script ... />
while (NSStringFinder::RemoveEmptyTag(sFileContent, "script"));
// Gumbo
GumboOptions options = kGumboDefaultOptions;
@ -204,49 +194,69 @@ static std::string QuotedPrintableDecode(const std::string& sContent, std::strin
static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::string>& sRes, NSStringUtils::CStringBuilderA& oRes)
{
size_t unContentPosition = 0, unLastPosition = 0;
size_t unContentPosition = 0, unCharsetBegin = 0, unCharsetEnd = std::string::npos;
NSStringFinder::TFoundedData<char> oData;
// Content-Type
std::string sContentType = NSStringFinder::FindPropety(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
oData = NSStringFinder::FindPropety(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"});
const std::string sContentType{oData.m_sValue};
if (sContentType.empty())
return;
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
{
oRes.WriteString(mhtTohtml(sMhtContent.substr(unLastPosition, sMhtContent.length() - unLastPosition)));
oRes.WriteString(mhtTohtml(sMhtContent.substr(oData.m_unEndPosition, sMhtContent.length() - oData.m_unEndPosition)));
return;
}
unContentPosition = std::max(unContentPosition, unLastPosition);
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetBegin = oData.m_unEndPosition;
// name
// std::string sName = NSStringFinder::FindPropety(sMhtContent, "name", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
// unContentPosition = std::max(unContentPosition, unLastPosition);
// charset
std::string sCharset = NSStringFinder::FindPropety(sMhtContent, "charset", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
unContentPosition = std::max(unContentPosition, unLastPosition);
NSStringFinder::CutInside<std::string>(sCharset, "\"");
// Content-Location
std::string sContentLocation = NSStringFinder::FindPropety(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
unContentPosition = std::max(unContentPosition, unLastPosition);
oData = NSStringFinder::FindPropety(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"});
std::string sContentLocation{oData.m_sValue};
if (sContentLocation.empty())
if (!oData.Empty())
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
// Content-ID
oData = NSStringFinder::FindPropety(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"});
std::string sContentID{oData.m_sValue};
if (!oData.Empty())
{
// Content-ID
std::string sContentID = NSStringFinder::FindPropety(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
unContentPosition = std::max(unContentPosition, unLastPosition);
NSStringFinder::CutInside<std::string>(sCharset, "<", ">");
if (!sContentID.empty())
sContentLocation = "cid:" + sContentID;
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
NSStringFinder::CutInside<std::string>(sContentID, "<", ">");
}
if (sContentLocation.empty() && !sContentID.empty())
sContentLocation = "cid:" + sContentID;
// Content-Transfer-Encoding
std::string sContentEncoding = NSStringFinder::FindPropety(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
unContentPosition = std::max(unContentPosition, unLastPosition);
oData = NSStringFinder::FindPropety(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"});
const std::string sContentEncoding{oData.m_sValue};
if (!oData.Empty())
{
unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
}
// charset
std::string sCharset = "utf-8";
if (std::string::npos != unCharsetEnd && unCharsetBegin < unCharsetEnd)
{
sCharset = NSStringFinder::FindPropety(sMhtContent.substr(unCharsetBegin, unCharsetEnd - unCharsetBegin), "charset", {"="}, {";", "\\n", "\\r"}).m_sValue;
NSStringFinder::CutInside<std::string>(sCharset, "\"");
}
// Content
std::string sContent = sMhtContent.substr(unContentPosition, sMhtContent.length() - unContentPosition);
@ -266,7 +276,7 @@ static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::s
oRes.WriteString("<style>");
if (NSStringFinder::Equals(sContentEncoding, "base64"))
oRes.WriteString(Base64ToString(sContent, sCharset));
sContent = Base64ToString(sContent, sCharset);
else if (NSStringFinder::EqualOf(sContentEncoding, {"8bit", "7bit"}) || sContentEncoding.empty())
{
if (!NSStringFinder::Equals(sCharset, "utf-8") && !sCharset.empty())
@ -274,7 +284,6 @@ static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::s
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
oRes.WriteString(sContent);
}
else if (NSStringFinder::Equals(sContentEncoding, "quoted-printable"))
{
@ -284,9 +293,13 @@ static void ReadMht(const std::string& sMhtContent, std::map<std::string, std::s
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sCharset.data()));
}
oRes.WriteString(sContent);
}
if (NSStringFinder::Equals(sContentType, "text/html"))
sContent = U_TO_UTF8(htmlToXhtml(sContent, false));
oRes.WriteString(sContent);
if(bAddTagStyle)
oRes.WriteString("</style>");
}
@ -312,9 +325,11 @@ static std::string mhtTohtml(const std::string& sFileContent)
std::map<std::string, std::string> sRes;
NSStringUtils::CStringBuilderA oRes;
size_t nFound = 0;
// Поиск boundary
std::string sBoundary = NSStringFinder::FindPropety(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""}, 0, nFound);
NSStringFinder::TFoundedData<char> oData{NSStringFinder::FindPropety(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""})};
size_t nFound{oData.m_unEndPosition};
std::string sBoundary{oData.m_sValue};
if (sBoundary.empty())
{
@ -568,13 +583,20 @@ static void prettyprint(GumboNode* node, NSStringUtils::CStringBuilderA& oBuilde
return;
}
std::string tagname = get_tag_name(node);
if (html_tags.end() == std::find(html_tags.begin(), html_tags.end(), tagname))
{
prettyprint_contents(node, oBuilder);
return;
}
std::string close = "";
std::string closeTag = "";
std::string tagname = get_tag_name(node);
std::string key = "|" + tagname + "|";
bool is_empty_tag = empty_tags.find(key) != std::string::npos;
bool no_entity_substitution = no_entity_sub.find(key) != std::string::npos;
// determine closing tag type
if (is_empty_tag)
close = "/";

View File

@ -326,27 +326,33 @@ bool COfficeFileFormatChecker::isOleObjectFile(POLE::Storage *storage)
if (sz_obj > 4)
Program = ReadStringFromOle(&streamCompObject, sz_obj);
}
if (std::string::npos != Program.find("Excel") || std::string::npos != UserType.find("Excel"))
POLE::Stream streamPackage(storage, L"Package");
if (false == streamPackage.fail())
{
nFileType = AVS_OFFICESTUDIO_FILE_OTHER_PACKAGE_IN_OLE;
}
else if (std::string::npos != Program.find("Excel") || std::string::npos != UserType.find("Excel"))
{
if (isXlsFormatFile(storage))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
}
}
if (std::string::npos != Program.find("Word") || std::string::npos != UserType.find("Word"))
else if (std::string::npos != Program.find("Word") || std::string::npos != UserType.find("Word"))
{
if (isDocFormatFile(storage))
{
//nFileType inside
}
}
if (std::string::npos != Program.find("PowerPoint") || std::string::npos != UserType.find("PowerPoint"))
else if (std::string::npos != Program.find("PowerPoint") || std::string::npos != UserType.find("PowerPoint"))
{
if (isPptFormatFile(storage))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT;
}
}
return true;
}
else
@ -858,7 +864,7 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
nFileType = AVS_OFFICESTUDIO_FILE_CANVAS_PDF;
else if (0 == sExt.compare(L".doct")) // случай архива с html viewer
nFileType = AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY;
else if (0 == sExt.compare(L".txt") || 0 == sExt.compare(L".xml") || 0 == sExt.compare(L".rtf") || 0 == sExt.compare(L".doc") || 0 == sExt.compare(L".docx"))
else if (0 == sExt.compare(L".txt") || 0 == sExt.compare(L".xml") || 0 == sExt.compare(L".rtf") || 0 == sExt.compare(L".doc") || 0 == sExt.compare(L".docx") || 0 == sExt.compare(L".md"))
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT;
if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN)

View File

@ -127,6 +127,7 @@
#define AVS_OFFICESTUDIO_FILE_OTHER_ODF AVS_OFFICESTUDIO_FILE_OTHER + 0x000a
#define AVS_OFFICESTUDIO_FILE_OTHER_MS_MITCRYPTO AVS_OFFICESTUDIO_FILE_OTHER + 0x000b
#define AVS_OFFICESTUDIO_FILE_OTHER_MS_VBAPROJECT AVS_OFFICESTUDIO_FILE_OTHER + 0x000c
#define AVS_OFFICESTUDIO_FILE_OTHER_PACKAGE_IN_OLE AVS_OFFICESTUDIO_FILE_OTHER + 0x000d
#define AVS_OFFICESTUDIO_FILE_TEAMLAB 0x1000
#define AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY AVS_OFFICESTUDIO_FILE_TEAMLAB + 0x0001

View File

@ -16,6 +16,7 @@
#define OFFICESTUDIO_FILE_DOCUMENT_DOTX OFFICESTUDIO_FILE_DOCUMENT + 0x000c
#define OFFICESTUDIO_FILE_DOCUMENT_OTT OFFICESTUDIO_FILE_DOCUMENT + 0x000f
#define OFFICESTUDIO_FILE_DOCUMENT_HTML OFFICESTUDIO_FILE_DOCUMENT + 0x0012
#define OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF OFFICESTUDIO_FILE_DOCUMENT + 0x0017
#define OFFICESTUDIO_FILE_PRESENTATION 0x0080
#define OFFICESTUDIO_FILE_PRESENTATION_PPTX OFFICESTUDIO_FILE_PRESENTATION + 0x0001

View File

@ -357,6 +357,7 @@ namespace NSDoctRenderer
/**
* Creates a new file. The type of the file which will be created needs to be set.
* @param type The type of the file to be created set as a hexadecimal integer for the C++ code or docx, xlsx or pptx for the .docbuilder script file (see AVS_OFFICESTUDIO_FILE_XXX values).
* Possible values for wchar_t version: "docx", "pptx", "xlsx", "pdf", "form"
* @return True if the operation is successful
*/
bool CreateFile(const int& type);

View File

@ -50,7 +50,8 @@ namespace docbuilder_net
TXT = MASK + 0x0005,
DOTX = MASK + 0x000c,
OTT = MASK + 0x000f,
HTML = MASK + 0x0012
HTML = MASK + 0x0012,
OFORM_PDF = MASK + 0x0017
};
public enum class Spreadsheet : int

View File

@ -0,0 +1,2 @@
result.docx
*.pyc

View File

@ -0,0 +1,596 @@
import ctypes
import os
import platform
import atexit
OBJECT_HANDLE = ctypes.c_void_p
STRING_HANDLE = ctypes.c_void_p
_lib = None
def _loadLibrary(path):
global _lib
if _lib is not None:
return
os_name = platform.system().lower()
library_name = ''
if 'windows' == os_name:
# modify PATH to load all DLLs
os.environ['PATH'] = path + os.pathsep + os.environ['PATH']
library_name = 'docbuilder.c.dll'
elif 'linux' == os_name:
library_name = 'libdocbuilder.c.so'
elif 'darwin' == os_name:
library_name = 'libdocbuilder.c.dylib'
_lib = ctypes.CDLL(path + '/' + library_name)
# init all function signatures
# ===== CDocBuilderValue =====
_lib.CDocBuilderValue_Create.argtypes = []
_lib.CDocBuilderValue_Create.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Copy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_Copy.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Destroy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_Destroy.restype = None
_lib.CDocBuilderValue_IsEmpty.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsEmpty.restype = ctypes.c_bool
_lib.CDocBuilderValue_Clear.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_Clear.restype = None
_lib.CDocBuilderValue_IsNull.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsNull.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsUndefined.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsUndefined.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsInt.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsInt.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsDouble.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsDouble.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsString.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsString.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsFunction.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsFunction.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsObject.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsObject.restype = ctypes.c_bool
_lib.CDocBuilderValue_IsArray.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_IsArray.restype = ctypes.c_bool
_lib.CDocBuilderValue_GetLength.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_GetLength.restype = ctypes.c_uint
_lib.CDocBuilderValue_ToBool.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_ToBool.restype = ctypes.c_bool
_lib.CDocBuilderValue_ToInt.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_ToInt.restype = ctypes.c_int
_lib.CDocBuilderValue_ToDouble.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_ToDouble.restype = ctypes.c_double
_lib.CDocBuilderValue_ToString.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderValue_ToString.restype = STRING_HANDLE
_lib.CDocBuilderValue_GetProperty.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilderValue_GetProperty.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_GetByIndex.argtypes = [OBJECT_HANDLE, ctypes.c_int]
_lib.CDocBuilderValue_GetByIndex.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_SetProperty.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE]
_lib.CDocBuilderValue_SetProperty.restype = None
_lib.CDocBuilderValue_SetByIndex.argtypes = [OBJECT_HANDLE, ctypes.c_int, OBJECT_HANDLE]
_lib.CDocBuilderValue_SetByIndex.restype = None
_lib.CDocBuilderValue_CreateWithBool.argtypes = [ctypes.c_bool]
_lib.CDocBuilderValue_CreateWithBool.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateWithInt.argtypes = [ctypes.c_int]
_lib.CDocBuilderValue_CreateWithInt.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateWithUInt.argtypes = [ctypes.c_uint]
_lib.CDocBuilderValue_CreateWithUInt.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateWithDouble.argtypes = [ctypes.c_double]
_lib.CDocBuilderValue_CreateWithDouble.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateWithString.argtypes = [ctypes.c_wchar_p]
_lib.CDocBuilderValue_CreateWithString.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateUndefined.argtypes = []
_lib.CDocBuilderValue_CreateUndefined.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateNull.argtypes = []
_lib.CDocBuilderValue_CreateNull.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_CreateArray.argtypes = [ctypes.c_int]
_lib.CDocBuilderValue_CreateArray.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call0.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilderValue_Call0.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call1.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call1.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call2.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call2.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call3.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call3.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call4.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call4.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call5.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call5.restype = OBJECT_HANDLE
_lib.CDocBuilderValue_Call6.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE, OBJECT_HANDLE]
_lib.CDocBuilderValue_Call6.restype = OBJECT_HANDLE
# ===== CDocBuilder =====
_lib.CDocBuilder_Create.argtypes = []
_lib.CDocBuilder_Create.restype = OBJECT_HANDLE
_lib.CDocBuilder_Destroy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_Destroy.restype = None
_lib.CDocBuilder_OpenFile.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, ctypes.c_wchar_p]
_lib.CDocBuilder_OpenFile.restype = ctypes.c_int
_lib.CDocBuilder_CreateFileByType.argtypes = [OBJECT_HANDLE, ctypes.c_int]
_lib.CDocBuilder_CreateFileByType.restype = ctypes.c_bool
_lib.CDocBuilder_CreateFileByExtension.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilder_CreateFileByExtension.restype = ctypes.c_bool
_lib.CDocBuilder_SetTmpFolder.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilder_SetTmpFolder.restype = None
_lib.CDocBuilder_SaveFileByType.argtypes = [OBJECT_HANDLE, ctypes.c_int, ctypes.c_wchar_p]
_lib.CDocBuilder_SaveFileByType.restype = ctypes.c_int
_lib.CDocBuilder_SaveFileByTypeWithParams.argtypes = [OBJECT_HANDLE, ctypes.c_int, ctypes.c_wchar_p, ctypes.c_wchar_p]
_lib.CDocBuilder_SaveFileByTypeWithParams.restype = ctypes.c_int
_lib.CDocBuilder_SaveFileByExtension.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, ctypes.c_wchar_p]
_lib.CDocBuilder_SaveFileByExtension.restype = ctypes.c_int
_lib.CDocBuilder_SaveFileByExtensionWithParams.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p]
_lib.CDocBuilder_SaveFileByExtensionWithParams.restype = ctypes.c_int
_lib.CDocBuilder_CloseFile.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_CloseFile.restype = None
_lib.CDocBuilder_ExecuteCommand.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilder_ExecuteCommand.restype = ctypes.c_bool
_lib.CDocBuilder_ExecuteCommandWithRetValue.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, OBJECT_HANDLE]
_lib.CDocBuilder_ExecuteCommandWithRetValue.restype = ctypes.c_bool
_lib.CDocBuilder_Run.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilder_Run.restype = ctypes.c_bool
_lib.CDocBuilder_RunText.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p]
_lib.CDocBuilder_RunText.restype = ctypes.c_bool
_lib.CDocBuilder_SetProperty.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, ctypes.c_wchar_p]
_lib.CDocBuilder_SetProperty.restype = None
_lib.CDocBuilder_WriteData.argtypes = [OBJECT_HANDLE, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_bool]
_lib.CDocBuilder_WriteData.restype = None
_lib.CDocBuilder_IsSaveWithDoctrendererMode.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_IsSaveWithDoctrendererMode.restype = ctypes.c_bool
_lib.CDocBuilder_GetVersion.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_GetVersion.restype = STRING_HANDLE
_lib.CDocBuilder_GetContext.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilder_GetContext.restype = OBJECT_HANDLE
_lib.CDocBuilder_Initialize.argtypes = []
_lib.CDocBuilder_Initialize.restype = None
_lib.CDocBuilder_InitializeWithDirectory.argtypes = [ctypes.c_wchar_p]
_lib.CDocBuilder_InitializeWithDirectory.restype = None
_lib.CDocBuilder_Dispose.argtypes = []
_lib.CDocBuilder_Dispose.restype = None
# ===== CDocBuilderContextScope =====
_lib.CDocBuilderContextScope_Create.argtypes = []
_lib.CDocBuilderContextScope_Create.restype = OBJECT_HANDLE
_lib.CDocBuilderContextScope_Copy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContextScope_Copy.restype = OBJECT_HANDLE
_lib.CDocBuilderContextScope_Destroy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContextScope_Destroy.restype = None
_lib.CDocBuilderContextScope_Close.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContextScope_Close.restype = None
# ===== CDocBuilderContext =====
_lib.CDocBuilderContext_Create.argtypes = []
_lib.CDocBuilderContext_Create.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_Copy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_Copy.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_Destroy.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_Destroy.restype = None
_lib.CDocBuilderContext_CreateUndefined.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_CreateUndefined.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_CreateNull.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_CreateNull.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_CreateObject.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_CreateObject.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_CreateArray.argtypes = [OBJECT_HANDLE, ctypes.c_int]
_lib.CDocBuilderContext_CreateArray.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_GetGlobal.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_GetGlobal.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_CreateScope.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_CreateScope.restype = OBJECT_HANDLE
_lib.CDocBuilderContext_IsError.argtypes = [OBJECT_HANDLE]
_lib.CDocBuilderContext_IsError.restype = ctypes.c_bool
# ===== Utility =====
_lib.DeleteWCharP.argtypes = [ctypes.c_wchar_p]
_lib.DeleteWCharP.restype = None
_lib.DeleteCharP.argtypes = [ctypes.c_char_p]
_lib.DeleteCharP.restype = None
class CDocBuilderValue:
def __init__(self, value=None):
if value is None:
self._internal = _lib.CDocBuilderValue_Create()
elif isinstance(value, bool):
self._internal = _lib.CDocBuilderValue_CreateWithBool(ctypes.c_bool(value))
elif isinstance(value, int):
self._internal = _lib.CDocBuilderValue_CreateWithInt(ctypes.c_int(value))
elif isinstance(value, float):
self._internal = _lib.CDocBuilderValue_CreateWithDouble(ctypes.c_double(value))
elif isinstance(value, str):
self._internal = _lib.CDocBuilderValue_CreateWithString(ctypes.c_wchar_p(value))
elif isinstance(value, list):
length = len(value)
self._internal = _lib.CDocBuilderValue_CreateArray(length)
for i in range(length):
self.Set(i, value[i])
elif isinstance(value, CDocBuilderValue):
self._internal = _lib.CDocBuilderValue_Copy(value._internal)
elif isinstance(value, OBJECT_HANDLE):
self._internal = value
else:
raise TypeError("Unsupported type for CDocBuilderValue constructor")
self._lib = _lib
def __del__(self):
# using self._lib instead of global _lib because it might be already garbage collected during this function call
self._lib.CDocBuilderValue_Destroy(self._internal)
def IsEmpty(self):
return _lib.CDocBuilderValue_IsEmpty(self._internal)
def Clear(self):
_lib.CDocBuilderValue_Clear(self._internal)
def IsNull(self):
return _lib.CDocBuilderValue_IsNull(self._internal)
def IsUndefined(self):
return _lib.CDocBuilderValue_IsUndefined(self._internal)
def IsInt(self):
return _lib.CDocBuilderValue_IsInt(self._internal)
def IsDouble(self):
return _lib.CDocBuilderValue_IsDouble(self._internal)
def IsString(self):
return _lib.CDocBuilderValue_IsString(self._internal)
def IsFunction(self):
return _lib.CDocBuilderValue_IsFunction(self._internal)
def IsObject(self):
return _lib.CDocBuilderValue_IsObject(self._internal)
def IsArray(self):
return _lib.CDocBuilderValue_IsArray(self._internal)
def GetLength(self):
return _lib.CDocBuilderValue_GetLength(self._internal)
def ToBool(self):
return _lib.CDocBuilderValue_ToBool(self._internal)
def ToInt(self):
return _lib.CDocBuilderValue_ToInt(self._internal)
def ToDouble(self):
return _lib.CDocBuilderValue_ToDouble(self._internal)
def ToString(self):
strRes = _lib.CDocBuilderValue_ToString(self._internal)
res = ctypes.cast(strRes, ctypes.c_wchar_p).value
_lib.DeleteWCharP(ctypes.cast(strRes, ctypes.c_wchar_p))
return res
def GetProperty(self, name):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_GetProperty(self._internal, ctypes.c_wchar_p(name))))
def Get(self, key):
if isinstance(key, int):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_GetByIndex(self._internal, ctypes.c_int(key))))
elif isinstance(key, str):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_GetProperty(self._internal, ctypes.c_wchar_p(key))))
else:
return None
def SetProperty(self, name, value):
if not isinstance(value, CDocBuilderValue):
value = CDocBuilderValue(value)
_lib.CDocBuilderValue_SetProperty(self._internal, ctypes.c_wchar_p(name), value._internal)
def Set(self, key, value):
if not isinstance(value, CDocBuilderValue):
value = CDocBuilderValue(value)
if isinstance(key, int):
_lib.CDocBuilderValue_SetByIndex(self._internal, ctypes.c_int(key), value._internal)
elif isinstance(key, str):
_lib.CDocBuilderValue_SetProperty(self._internal, ctypes.c_wchar_p(key), value._internal)
def __getitem__(self, key):
return self.Get(key)
def __setitem__(self, key, value):
self.Set(key, value)
@staticmethod
def CreateUndefined():
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_CreateUndefined()))
@staticmethod
def CreateNull():
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_CreateNull()))
@staticmethod
def CreateArray(length):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_CreateArray(length)))
def Call(self, name, *args):
if len(args) == 0:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call0(self._internal, ctypes.c_wchar_p(name))))
elif len(args) < 7:
values = []
for i in range(len(args)):
p = args[i]
if not isinstance(p, CDocBuilderValue):
p = CDocBuilderValue(p)
values.append(p)
if len(args) == 1:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call1(self._internal, ctypes.c_wchar_p(name), values[0]._internal)))
elif len(args) == 2:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call2(self._internal, ctypes.c_wchar_p(name), values[0]._internal, values[1]._internal)))
elif len(args) == 3:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call3(self._internal, ctypes.c_wchar_p(name), values[0]._internal, values[1]._internal, values[2]._internal)))
elif len(args) == 4:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call4(self._internal, ctypes.c_wchar_p(name), values[0]._internal, values[1]._internal, values[2]._internal, values[3]._internal)))
elif len(args) == 5:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call5(self._internal, ctypes.c_wchar_p(name), values[0]._internal, values[1]._internal, values[2]._internal, values[3]._internal, values[4]._internal)))
elif len(args) == 6:
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderValue_Call6(self._internal, ctypes.c_wchar_p(name), values[0]._internal, values[1]._internal, values[2]._internal, values[3]._internal, values[4]._internal, values[5]._internal)))
else:
raise TypeError("Call() expects at most 6 arguments")
class CDocBuilder:
_initialized = False
def __init__(self):
self._internal = _lib.CDocBuilder_Create()
self._lib = _lib
def __del__(self):
# using self._lib instead of global _lib because it might be already garbage collected during this function call
self._lib.CDocBuilder_Destroy(self._internal)
def OpenFile(self, path, params):
return _lib.CDocBuilder_OpenFile(self._internal, ctypes.c_wchar_p(path), ctypes.c_wchar_p(params))
def CreateFile(self, type):
if isinstance(type, int):
return _lib.CDocBuilder_CreateFileByType(self._internal, ctypes.c_int(type))
elif isinstance(type, str):
return _lib.CDocBuilder_CreateFileByExtension(self._internal, ctypes.c_wchar_p(type))
else:
return False
def SetTmpFolder(self, folder):
_lib.CDocBuilder_SetTmpFolder(self._internal, ctypes.c_wchar_p(folder))
def SaveFile(self, type, path, params=None):
if isinstance(type, int):
if params is None:
return _lib.CDocBuilder_SaveFileByType(self._internal, ctypes.c_int(type), ctypes.c_wchar_p(path))
else:
return _lib.CDocBuilder_SaveFileByTypeWithParams(self._internal, ctypes.c_int(type), ctypes.c_wchar_p(path), ctypes.c_wchar_p(params))
elif isinstance(type, str):
if params is None:
return _lib.CDocBuilder_SaveFileByExtension(self._internal, ctypes.c_wchar_p(type), ctypes.c_wchar_p(path))
else:
return _lib.CDocBuilder_SaveFileByExtensionWithParams(self._internal, ctypes.c_wchar_p(type), ctypes.c_wchar_p(path), ctypes.c_wchar_p(params))
else:
return -1
def CloseFile(self):
_lib.CDocBuilder_CloseFile(self._internal)
def ExecuteCommand(self, command, retValue=None):
if retValue is None:
return _lib.CDocBuilder_ExecuteCommand(self._internal, ctypes.c_wchar_p(command))
else:
return _lib.CDocBuilder_ExecuteCommandWithRetValue(self._internal, ctypes.c_wchar_p(command), retValue._internal)
def Run(self, path):
return _lib.CDocBuilder_Run(self._internal, ctypes.c_wchar_p(path))
def RunText(self, commands):
return _lib.CDocBuilder_RunText(self._internal, ctypes.c_wchar_p(commands))
def SetProperty(self, param, value):
_lib.CDocBuilder_SetProperty(self._internal, ctypes.c_wchar_p(param), ctypes.c_wchar_p(value))
def WriteData(self, path, value, append):
_lib.CDocBuilder_WriteData(self._internal, ctypes.c_wchar_p(path), ctypes.c_wchar_p(value), ctypes.c_bool(append))
def IsSaveWithDoctrendererMode(self):
return _lib.CDocBuilder_IsSaveWithDoctrendererMode(self._internal)
def GetVersion(self):
strVersion = _lib.CDocBuilder_GetVersion(self._internal)
version = ctypes.cast(strVersion, ctypes.c_char_p).value
_lib.DeleteCharP(ctypes.cast(strVersion, ctypes.c_char_p))
return version
def GetContext(self):
return CDocBuilderContext(OBJECT_HANDLE(_lib.CDocBuilder_GetContext(self._internal)))
@classmethod
def Initialize(cls, directory=None):
if directory is None:
_lib.CDocBuilder_Initialize()
else:
_lib.CDocBuilder_InitializeWithDirectory(ctypes.c_wchar_p(directory))
cls._initialized = True
@classmethod
def Dispose(cls):
if (cls._initialized):
_lib.CDocBuilder_Dispose()
cls._initialized = False
class CDocBuilderContextScope:
def __init__(self, value=None):
self._lib = _lib
if value is None:
self._internal = _lib.CDocBuilderContextScope_Create()
elif isinstance(value, CDocBuilderContextScope):
self._internal = _lib.CDocBuilderContextScope_Copy(value._internal)
elif isinstance(value, OBJECT_HANDLE):
self._internal = value
else:
raise TypeError("Unsupported type for CDocBuilderContextScope constructor")
self._lib = _lib
def __del__(self):
# using self._lib instead of global _lib because it might be already garbage collected during this function call
self._lib.CDocBuilderContextScope_Destroy(self._internal)
def Close(self):
_lib.CDocBuilderContextScope_Close(self._internal)
class CDocBuilderContext:
def __init__(self, value=None):
if value is None:
self._internal = _lib.CDocBuilderContext_Create()
elif isinstance(value, CDocBuilderContext):
self._internal = _lib.CDocBuilderContext_Copy(value._internal)
elif isinstance(value, OBJECT_HANDLE):
self._internal = value
else:
raise TypeError("Unsupported type for CDocBuilderContext constructor")
self._lib = _lib
def __del__(self):
# using self._lib instead of global _lib because it might be already garbage collected during this function call
self._lib.CDocBuilderContext_Destroy(self._internal)
def CreateUndefined(self):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderContext_CreateUndefined(self._internal)))
def CreateNull(self):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderContext_CreateNull(self._internal)))
def CreateObject(self):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderContext_CreateObject(self._internal)))
def CreateArray(self, length):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderContext_CreateArray(self._internal, ctypes.c_int(length))))
def GetGlobal(self):
return CDocBuilderValue(OBJECT_HANDLE(_lib.CDocBuilderContext_GetGlobal(self._internal)))
def CreateScope(self):
return CDocBuilderContextScope(OBJECT_HANDLE(_lib.CDocBuilderContext_CreateScope(self._internal)))
def IsError(self):
return _lib.CDocBuilderContext_IsError(self._internal)
# Constants
class FileTypes:
class Document:
_MASK = 0x0040
DOCX = _MASK + 0x0001
DOC = _MASK + 0x0002
ODT = _MASK + 0x0003
RTF = _MASK + 0x0004
TXT = _MASK + 0x0005
DOTX = _MASK + 0x000c
OTT = _MASK + 0x000f
HTML = _MASK + 0x0012
OFORM_PDF = _MASK + 0x0017
class Presentation:
_MASK = 0x0080
PPTX = _MASK + 0x0001
PPT = _MASK + 0x0002
ODP = _MASK + 0x0003
PPSX = _MASK + 0x0004
POTX = _MASK + 0x0007
OTP = _MASK + 0x000a
class Spreadsheet:
_MASK = 0x0100
XLSX = _MASK + 0x0001
XLS = _MASK + 0x0002
ODS = _MASK + 0x0003
CSV = _MASK + 0x0004
XLTX = _MASK + 0x0006
OTS = _MASK + 0x0009
class Graphics:
_PDF_MASK = 0x0200
PDF = _PDF_MASK + 0x0001
PDFA = _PDF_MASK + 0x0009
_IMAGE_MASK = 0x0400
JPG = _IMAGE_MASK + 0x0001
PNG = _IMAGE_MASK + 0x0005
BMP = _IMAGE_MASK + 0x0008
builder_path = os.path.dirname(os.path.realpath(__file__))
_loadLibrary(builder_path)
CDocBuilder.Initialize(builder_path)
atexit.register(CDocBuilder.Dispose)

View File

@ -0,0 +1,27 @@
QT -= core
QT -= gui
TARGET = docbuilder.c
TEMPLATE = lib
CONFIG += shared
CONFIG += plugin
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
ADD_DEPENDENCY(graphics, kernel, kernel_network, UnicodeConverter, doctrenderer)
INCLUDEPATH += ../..
DEFINES += DOCBUILDER_FUNCTIONS_EXPORT
SOURCES += \
docbuilder_functions.cpp
HEADERS += \
docbuilder_functions.h

View File

@ -0,0 +1,395 @@
#include "docbuilder_functions.h"
#include <cstring>
#include <wchar.h>
// ===== CDocBuilderValue =====
CDocBuilderValue* CDocBuilderValue_Create()
{
return new CDocBuilderValue();
}
CDocBuilderValue* CDocBuilderValue_Copy(CDocBuilderValue* other)
{
return new CDocBuilderValue(*other);
}
void CDocBuilderValue_Destroy(CDocBuilderValue* self)
{
delete self;
}
bool CDocBuilderValue_IsEmpty(CDocBuilderValue* self)
{
return self->IsEmpty();
}
void CDocBuilderValue_Clear(CDocBuilderValue* self)
{
self->Clear();
}
bool CDocBuilderValue_IsNull(CDocBuilderValue* self)
{
return self->IsNull();
}
bool CDocBuilderValue_IsUndefined(CDocBuilderValue* self)
{
return self->IsUndefined();
}
bool CDocBuilderValue_IsInt(CDocBuilderValue* self)
{
return self->IsInt();
}
bool CDocBuilderValue_IsDouble(CDocBuilderValue* self)
{
return self->IsDouble();
}
bool CDocBuilderValue_IsString(CDocBuilderValue* self)
{
return self->IsString();
}
bool CDocBuilderValue_IsFunction(CDocBuilderValue* self)
{
return self->IsFunction();
}
bool CDocBuilderValue_IsObject(CDocBuilderValue* self)
{
return self->IsObject();
}
bool CDocBuilderValue_IsArray(CDocBuilderValue* self)
{
return self->IsArray();
}
unsigned int CDocBuilderValue_GetLength(CDocBuilderValue* self)
{
return self->GetLength();
}
bool CDocBuilderValue_ToBool(CDocBuilderValue* self)
{
return self->ToBool();
}
int CDocBuilderValue_ToInt(CDocBuilderValue* self)
{
return self->ToInt();
}
double CDocBuilderValue_ToDouble(CDocBuilderValue* self)
{
return self->ToDouble();
}
const wchar_t* CDocBuilderValue_ToString(CDocBuilderValue* self)
{
// NOTE: User is responsible for calling DeleteWCharP() on returned pointer
CString strValue = self->ToString();
size_t len = wcslen(strValue.c_str());
wchar_t* strRes = new wchar_t[len + 1];
memcpy(strRes, strValue.c_str(), (len + 1) + sizeof(wchar_t));
return strRes;
}
CDocBuilderValue* CDocBuilderValue_GetProperty(CDocBuilderValue* self, const wchar_t* name)
{
return new CDocBuilderValue(self->GetProperty(name));
}
CDocBuilderValue* CDocBuilderValue_GetByIndex(CDocBuilderValue* self, int index)
{
return new CDocBuilderValue(self->Get(index));
}
void CDocBuilderValue_SetProperty(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* value)
{
self->Set(name, *value);
}
void CDocBuilderValue_SetByIndex(CDocBuilderValue* self, int index, CDocBuilderValue* value)
{
self->Set(index, *value);
}
CDocBuilderValue* CDocBuilderValue_CreateWithBool(bool value)
{
return new CDocBuilderValue(value);
}
CDocBuilderValue* CDocBuilderValue_CreateWithInt(int value)
{
return new CDocBuilderValue(value);
}
CDocBuilderValue* CDocBuilderValue_CreateWithUInt(unsigned int value)
{
return new CDocBuilderValue(value);
}
CDocBuilderValue* CDocBuilderValue_CreateWithDouble(double value)
{
return new CDocBuilderValue(value);
}
CDocBuilderValue* CDocBuilderValue_CreateWithString(const wchar_t* value)
{
return new CDocBuilderValue(value);
}
CDocBuilderValue* CDocBuilderValue_CreateUndefined()
{
return new CDocBuilderValue(CDocBuilderValue::CreateUndefined());
}
CDocBuilderValue* CDocBuilderValue_CreateNull()
{
return new CDocBuilderValue(CDocBuilderValue::CreateNull());
}
CDocBuilderValue* CDocBuilderValue_CreateArray(int length)
{
return new CDocBuilderValue(CDocBuilderValue::CreateArray(length));
}
CDocBuilderValue* CDocBuilderValue_Call0(CDocBuilderValue* self, const wchar_t* name)
{
return new CDocBuilderValue(self->Call(name));
}
CDocBuilderValue* CDocBuilderValue_Call1(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1)
{
return new CDocBuilderValue(self->Call(name, *p1));
}
CDocBuilderValue* CDocBuilderValue_Call2(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2)
{
return new CDocBuilderValue(self->Call(name, *p1, *p2));
}
CDocBuilderValue* CDocBuilderValue_Call3(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3)
{
return new CDocBuilderValue(self->Call(name, *p1, *p2, *p3));
}
CDocBuilderValue* CDocBuilderValue_Call4(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4)
{
return new CDocBuilderValue(self->Call(name, *p1, *p2, *p3, *p4));
}
CDocBuilderValue* CDocBuilderValue_Call5(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4, CDocBuilderValue* p5)
{
return new CDocBuilderValue(self->Call(name, *p1, *p2, *p3, *p4, *p5));
}
CDocBuilderValue* CDocBuilderValue_Call6(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4, CDocBuilderValue* p5, CDocBuilderValue* p6)
{
return new CDocBuilderValue(self->Call(name, *p1, *p2, *p3, *p4, *p5, *p6));
}
// ===== CDocBuilder =====
CDocBuilder* CDocBuilder_Create()
{
return new CDocBuilder();
}
void CDocBuilder_Destroy(CDocBuilder* self)
{
delete self;
}
int CDocBuilder_OpenFile(CDocBuilder* self, const wchar_t* path, const wchar_t* params)
{
return self->OpenFile(path, params);
}
bool CDocBuilder_CreateFileByType(CDocBuilder* self, int type)
{
return self->CreateFile(type);
}
bool CDocBuilder_CreateFileByExtension(CDocBuilder* self, const wchar_t* extension)
{
return self->CreateFile(extension);
}
void CDocBuilder_SetTmpFolder(CDocBuilder* self, const wchar_t* folder)
{
self->SetTmpFolder(folder);
}
int CDocBuilder_SaveFileByType(CDocBuilder* self, int type, const wchar_t* path)
{
return self->SaveFile(type, path);
}
int CDocBuilder_SaveFileByTypeWithParams(CDocBuilder* self, int type, const wchar_t* path, const wchar_t* params)
{
return self->SaveFile(type, path, params);
}
int CDocBuilder_SaveFileByExtension(CDocBuilder* self, const wchar_t* extension, const wchar_t* path)
{
return self->SaveFile(extension, path);
}
int CDocBuilder_SaveFileByExtensionWithParams(CDocBuilder* self, const wchar_t* extension, const wchar_t* path, const wchar_t* params)
{
return self->SaveFile(extension, path, params);
}
void CDocBuilder_CloseFile(CDocBuilder* self)
{
self->CloseFile();
}
bool CDocBuilder_ExecuteCommand(CDocBuilder* self, const wchar_t* command)
{
return self->ExecuteCommand(command);
}
bool CDocBuilder_ExecuteCommandWithRetValue(CDocBuilder* self, const wchar_t* command, CDocBuilderValue* retValue)
{
return self->ExecuteCommand(command, retValue);
}
bool CDocBuilder_Run(CDocBuilder* self, const wchar_t* path)
{
return self->Run(path);
}
bool CDocBuilder_RunText(CDocBuilder* self, const wchar_t* commands)
{
return self->RunTextW(commands);
}
void CDocBuilder_SetProperty(CDocBuilder* self, const wchar_t* param, const wchar_t* value)
{
self->SetPropertyW(param, value);
}
void CDocBuilder_WriteData(CDocBuilder* self, const wchar_t* path, const wchar_t* value, bool append)
{
self->WriteData(path, value, append);
}
bool CDocBuilder_IsSaveWithDoctrendererMode(CDocBuilder* self)
{
return self->IsSaveWithDoctrendererMode();
}
char* CDocBuilder_GetVersion(CDocBuilder* self)
{
// NOTE: User is responsible for calling DeleteCharP() on returned pointer
return self->GetVersion();
}
CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self)
{
return new CDocBuilderContext(self->GetContext());
}
void CDocBuilder_Initialize()
{
CDocBuilder::Initialize();
}
void CDocBuilder_InitializeWithDirectory(const wchar_t* directory)
{
CDocBuilder::Initialize(directory);
}
void CDocBuilder_Dispose()
{
CDocBuilder::Dispose();
}
// ===== CDocBuilderContextScope =====
CDocBuilderContextScope* CDocBuilderContextScope_Create()
{
return new CDocBuilderContextScope();
}
CDocBuilderContextScope* CDocBuilderContextScope_Copy(CDocBuilderContextScope* other)
{
return new CDocBuilderContextScope(*other);
}
void CDocBuilderContextScope_Destroy(CDocBuilderContextScope* self)
{
delete self;
}
void CDocBuilderContextScope_Close(CDocBuilderContextScope* self)
{
self->Close();
}
// ===== CDocBuilderContext =====
CDocBuilderContext* CDocBuilderContext_Create()
{
return new CDocBuilderContext();
}
CDocBuilderContext* CDocBuilderContext_Copy(CDocBuilderContext* other)
{
return new CDocBuilderContext(*other);
}
void CDocBuilderContext_Destroy(CDocBuilderContext* self)
{
delete self;
}
CDocBuilderValue* CDocBuilderContext_CreateUndefined(CDocBuilderContext* self)
{
return new CDocBuilderValue(self->CreateUndefined());
}
CDocBuilderValue* CDocBuilderContext_CreateNull(CDocBuilderContext* self)
{
return new CDocBuilderValue(self->CreateNull());
}
CDocBuilderValue* CDocBuilderContext_CreateObject(CDocBuilderContext* self)
{
return new CDocBuilderValue(self->CreateObject());
}
CDocBuilderValue* CDocBuilderContext_CreateArray(CDocBuilderContext* self, int length)
{
return new CDocBuilderValue(self->CreateArray(length));
}
CDocBuilderValue* CDocBuilderContext_GetGlobal(CDocBuilderContext* self)
{
return new CDocBuilderValue(self->GetGlobal());
}
CDocBuilderContextScope* CDocBuilderContext_CreateScope(CDocBuilderContext* self)
{
return new CDocBuilderContextScope(self->CreateScope());
}
bool CDocBuilderContext_IsError(CDocBuilderContext* self)
{
return self->IsError();
}
// ===== Utility =====
void DeleteWCharP(wchar_t* str)
{
delete[] str;
}
void DeleteCharP(char* str)
{
delete[] str;
}

View File

@ -0,0 +1,134 @@
#ifndef DOCBUILDER_FUNCTIONS_H
#define DOCBUILDER_FUNCTIONS_H
#include "docbuilder.h"
#include "../common/base_export.h"
#ifdef DOCBUILDER_FUNCTIONS_EXPORT
#define DOCBUILDER_FUNC_DECL Q_DECL_EXPORT
#else
#define DOCBUILDER_FUNC_DECL Q_DECL_IMPORT
#endif
using namespace NSDoctRenderer;
extern "C"
{
// ===== CDocBuilderValue =====
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Create();
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Copy(CDocBuilderValue* other);
DOCBUILDER_FUNC_DECL void CDocBuilderValue_Destroy(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsEmpty(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL void CDocBuilderValue_Clear(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsNull(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsUndefined(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsInt(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsDouble(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsString(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsFunction(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsObject(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsArray(CDocBuilderValue* self);
// TODO:
// DOCBUILDER_FUNC_DECL bool CDocBuilderValue_IsTypedArray(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL unsigned int CDocBuilderValue_GetLength(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderValue_ToBool(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL int CDocBuilderValue_ToInt(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL double CDocBuilderValue_ToDouble(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL const wchar_t* CDocBuilderValue_ToString(CDocBuilderValue* self);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_GetProperty(CDocBuilderValue* self, const wchar_t* name);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_GetByIndex(CDocBuilderValue* self, int index);
DOCBUILDER_FUNC_DECL void CDocBuilderValue_SetProperty(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* value);
DOCBUILDER_FUNC_DECL void CDocBuilderValue_SetByIndex(CDocBuilderValue* self, int index, CDocBuilderValue* value);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithBool(bool value);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithInt(int value);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithUInt(unsigned int value);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithDouble(double value);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_CreateWithString(const wchar_t* value);
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_Call0(CDocBuilderValue* self, const wchar_t* name);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call1(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call2(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call3(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call4(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call5(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4, CDocBuilderValue* p5);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderValue_Call6(CDocBuilderValue* self, const wchar_t* name, CDocBuilderValue* p1, CDocBuilderValue* p2, CDocBuilderValue* p3, CDocBuilderValue* p4, CDocBuilderValue* p5, CDocBuilderValue* p6);
// ===== CDocBuilder =====
DOCBUILDER_FUNC_DECL CDocBuilder* CDocBuilder_Create();
DOCBUILDER_FUNC_DECL void CDocBuilder_Destroy(CDocBuilder* self);
DOCBUILDER_FUNC_DECL int CDocBuilder_OpenFile(CDocBuilder* self, const wchar_t* path, const wchar_t* params);
DOCBUILDER_FUNC_DECL bool CDocBuilder_CreateFileByType(CDocBuilder* self, int type);
DOCBUILDER_FUNC_DECL bool CDocBuilder_CreateFileByExtension(CDocBuilder* self, const wchar_t* extension);
DOCBUILDER_FUNC_DECL void CDocBuilder_SetTmpFolder(CDocBuilder* self, const wchar_t* folder);
DOCBUILDER_FUNC_DECL int CDocBuilder_SaveFileByType(CDocBuilder* self, int type, const wchar_t* path);
DOCBUILDER_FUNC_DECL int CDocBuilder_SaveFileByTypeWithParams(CDocBuilder* self, int type, const wchar_t* path, const wchar_t* params);
DOCBUILDER_FUNC_DECL int CDocBuilder_SaveFileByExtension(CDocBuilder* self, const wchar_t* extension, const wchar_t* path);
DOCBUILDER_FUNC_DECL int CDocBuilder_SaveFileByExtensionWithParams(CDocBuilder* self, const wchar_t* extension, const wchar_t* path, const wchar_t* params);
DOCBUILDER_FUNC_DECL void CDocBuilder_CloseFile(CDocBuilder* self);
DOCBUILDER_FUNC_DECL bool CDocBuilder_ExecuteCommand(CDocBuilder* self, const wchar_t* command);
DOCBUILDER_FUNC_DECL bool CDocBuilder_ExecuteCommandWithRetValue(CDocBuilder* self, const wchar_t* command, CDocBuilderValue* retValue);
DOCBUILDER_FUNC_DECL bool CDocBuilder_Run(CDocBuilder* self, const wchar_t* path);
DOCBUILDER_FUNC_DECL bool CDocBuilder_RunText(CDocBuilder* self, const wchar_t* commands);
DOCBUILDER_FUNC_DECL void CDocBuilder_SetProperty(CDocBuilder* self, const wchar_t* param, const wchar_t* value);
DOCBUILDER_FUNC_DECL void CDocBuilder_WriteData(CDocBuilder* self, const wchar_t* path, const wchar_t* value, bool append);
DOCBUILDER_FUNC_DECL bool CDocBuilder_IsSaveWithDoctrendererMode(CDocBuilder* self);
DOCBUILDER_FUNC_DECL char* CDocBuilder_GetVersion(CDocBuilder* self);
DOCBUILDER_FUNC_DECL CDocBuilderContext* CDocBuilder_GetContext(CDocBuilder* self);
DOCBUILDER_FUNC_DECL void CDocBuilder_Initialize();
DOCBUILDER_FUNC_DECL void CDocBuilder_InitializeWithDirectory(const wchar_t* directory);
DOCBUILDER_FUNC_DECL void CDocBuilder_Dispose();
// ===== CDocBuilderContextScope =====
DOCBUILDER_FUNC_DECL CDocBuilderContextScope* CDocBuilderContextScope_Create();
DOCBUILDER_FUNC_DECL CDocBuilderContextScope* CDocBuilderContextScope_Copy(CDocBuilderContextScope* other);
DOCBUILDER_FUNC_DECL void CDocBuilderContextScope_Destroy(CDocBuilderContextScope* self);
DOCBUILDER_FUNC_DECL void CDocBuilderContextScope_Close(CDocBuilderContextScope* self);
// ===== CDocBuilderContext =====
DOCBUILDER_FUNC_DECL CDocBuilderContext* CDocBuilderContext_Create();
DOCBUILDER_FUNC_DECL CDocBuilderContext* CDocBuilderContext_Copy(CDocBuilderContext* other);
DOCBUILDER_FUNC_DECL void CDocBuilderContext_Destroy(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderContext_CreateUndefined(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderContext_CreateNull(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderContext_CreateObject(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderContext_CreateArray(CDocBuilderContext* self, int length);
// TODO:
// CDocBuilderContext_CreateTypedArray(CDocBuilderContext* self, unsigned char* buffer);
DOCBUILDER_FUNC_DECL CDocBuilderValue* CDocBuilderContext_GetGlobal(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL CDocBuilderContextScope* CDocBuilderContext_CreateScope(CDocBuilderContext* self);
DOCBUILDER_FUNC_DECL bool CDocBuilderContext_IsError(CDocBuilderContext* self);
// ===== Utility =====
DOCBUILDER_FUNC_DECL void DeleteWCharP(wchar_t* str);
DOCBUILDER_FUNC_DECL void DeleteCharP(char* str);
}
#endif // DOCBUILDER_FUNCTIONS_H

View File

@ -0,0 +1,27 @@
QT -= core
QT -= gui
TARGET = test
TEMPLATE = app
CONFIG -= app_bundle
CONFIG += console
CORE_ROOT_DIR = $$PWD/../../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
# Set docbuilder path here
DOCUMENT_BUILDER_INSTALL_PATH=C:/Program Files/ONLYOFFICE/DocumentBuilder
DEFINES += "DOCUMENT_BUILDER_INSTALL_PATH=\"$$DOCUMENT_BUILDER_INSTALL_PATH\""
LIBS += -L'$$DOCUMENT_BUILDER_INSTALL_PATH' -ldocbuilder.c
DESTDIR = $$PWD/build
INCLUDEPATH += ../../..
SOURCES += \
main.cpp

View File

@ -0,0 +1,74 @@
#include "docbuilder.python/src/docbuilder_functions.h"
#include <string>
#include <iostream>
#include "app_builder_lib/utils.cpp"
#define DECLARE_RAII_DOCBUILDER_FUNC_CLASS( CLASS_NAME ) \
class CLASS_NAME ## F \
{ \
public: \
CLASS_NAME ## F(CLASS_NAME* internal) { m_internal = internal; } \
~CLASS_NAME ## F() { CLASS_NAME ## _Destroy(m_internal); } \
\
CLASS_NAME* get() { return m_internal; } \
\
private: \
CLASS_NAME* m_internal; \
};
DECLARE_RAII_DOCBUILDER_FUNC_CLASS(CDocBuilder)
DECLARE_RAII_DOCBUILDER_FUNC_CLASS(CDocBuilderValue)
DECLARE_RAII_DOCBUILDER_FUNC_CLASS(CDocBuilderContext)
DECLARE_RAII_DOCBUILDER_FUNC_CLASS(CDocBuilderContextScope)
int main()
{
std::wstring sWorkDirectory = NSUtils::GetBuilderDirectory();
#if 0
// Simple test that shows builder version if everything is correct
CDocBuilder_InitializeWithDirectory(sWorkDirectory.c_str());
CDocBuilder* pBuilder = CDocBuilder_Create();
char* sVersion = CDocBuilder_GetVersion(pBuilder);
std::cout << sVersion << std::endl;
DeleteCharP(sVersion);
CDocBuilder_Dispose();
CDocBuilder_Destroy(pBuilder);
#else
// Test is identical to app_builder_lib.pro
// The test uses RAII wrappers - classes with 'F' postfix, which are destroyed automatically
CDocBuilder_InitializeWithDirectory(sWorkDirectory.c_str());
CDocBuilderF oBuilder = CDocBuilder_Create();
CDocBuilder_SetProperty(oBuilder.get(), L"--work-directory", sWorkDirectory.c_str());
CDocBuilder_CreateFileByExtension(oBuilder.get(), L"docx");
CDocBuilderContextF oContext = CDocBuilder_GetContext(oBuilder.get());
CDocBuilderContextScopeF oScope = CDocBuilderContext_CreateScope(oContext.get());
CDocBuilderValueF oGlobal = CDocBuilderContext_GetGlobal(oContext.get());
CDocBuilderValueF oApi = CDocBuilderValue_GetProperty(oGlobal.get(), L"Api");
CDocBuilderValueF oDocument = CDocBuilderValue_Call0(oApi.get(), L"GetDocument");
CDocBuilderValueF oParagraph = CDocBuilderValue_Call0(oApi.get(), L"CreateParagraph");
CDocBuilderValue_Call2(oParagraph.get(), L"SetSpacingAfter", CDocBuilderValueF(CDocBuilderValue_CreateWithInt(1000)).get(), CDocBuilderValueF(CDocBuilderValue_CreateWithBool(false)).get());
CDocBuilderValue_Call1(oParagraph.get(), L"AddText", CDocBuilderValueF(CDocBuilderValue_CreateWithString(L"Hello, world!")).get());
CDocBuilderValueF oContent = CDocBuilderContext_CreateArray(oContext.get(), 1);
CDocBuilderValue_SetByIndex(oContent.get(), 0, oParagraph.get());
CDocBuilderValue_Call1(oDocument.get(), L"InsertContent", oContent.get());
std::wstring sProcessDirectory = NSUtils::GetProcessDirectory();
std::wstring sDstPath = sProcessDirectory + L"/result.docx";
CDocBuilder_SaveFileByExtension(oBuilder.get(), L"docx", sDstPath.c_str());
CDocBuilder_CloseFile(oBuilder.get());
CDocBuilder_Dispose();
#endif
return 0;
}

View File

@ -0,0 +1,29 @@
import os
import sys
sys.path.append('path_to_docbuilder')
import docbuilder
builder = docbuilder.CDocBuilder()
builder.CreateFile(docbuilder.FileTypes.Document.DOCX)
context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj['Api']
document = api.Call('GetDocument')
paragraph1 = api.Call('CreateParagraph')
paragraph1.Call('SetSpacingAfter', 1000, False)
paragraph1.Call('AddText', 'Hello from Python!')
paragraph2 = api.Call('CreateParagraph')
paragraph2.Call('AddText', 'Goodbye!')
content = [paragraph1, paragraph2]
document.Call('InsertContent', content)
dstPath = os.getcwd() + '/result.docx'
builder.SaveFile(docbuilder.FileTypes.Document.DOCX, dstPath)
builder.CloseFile()

View File

@ -1440,7 +1440,11 @@ namespace NSDoctRenderer
bIsNoError = (0 == this->OpenFile(_builder_params[0].c_str(), _builder_params[1].c_str()));
else if ("CreateFile" == sFuncNum)
{
if (L"docx" == _builder_params[0] || L"docxf" == _builder_params[0] || L"oform" == _builder_params[0])
if (L"docx" == _builder_params[0] ||
L"docxf" == _builder_params[0] ||
L"oform" == _builder_params[0] ||
L"pdf" == _builder_params[0] ||
L"form" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX);
else if (L"pptx" == _builder_params[0])
bIsNoError = this->CreateFile(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX);

View File

@ -110,6 +110,8 @@ namespace NSDoctRenderer
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM;
else if (L"html" == sExt)
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER;
else if (L"form" == sExt)
nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF;
return nFormat;
}
}
@ -619,7 +621,10 @@ namespace NSDoctRenderer
if (type & AVS_OFFICESTUDIO_FILE_DOCUMENT)
{
sEmptyPath = sEmptyPath + L"new.docx";
if (type == AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF)
sEmptyPath = sEmptyPath + L"new.pdf";
else
sEmptyPath = sEmptyPath + L"new.docx";
m_nFileType = 0;
}
else if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)

View File

@ -219,6 +219,13 @@ namespace NSJSBase
{
m_internal->context = [[JSContext alloc] init];
#ifdef _DEBUG
if (@available(macOS 10.11, iOS 16.0, *))
{
JSGlobalContextSetInspectable(m_internal->context.JSGlobalContextRef, true);
}
#endif
ASC_THREAD_ID nThreadId = NSThreads::GetCurrentThreadId();
MoveToThread(&nThreadId);
if (CGlobalContext::GetInstance().IsOldVersion())

View File

@ -65,7 +65,7 @@ namespace NSJSON
bool CPrimitive::isDouble() const
{
return m_type == ptDouble;
return m_type == ptDouble || m_type == ptInteger;
}
bool CPrimitive::isStringA() const

View File

@ -247,7 +247,8 @@ TEST_F(CJSONTest, bool_)
TEST_F(CJSONTest, int_)
{
CValue val = 42;
EXPECT_FALSE(val.IsDouble());
EXPECT_TRUE(val.IsDouble());
EXPECT_TRUE(val.IsInt());
JSSmart<CJSValue> jsVal = CJSContext::createInt(42);
EXPECT_TRUE(compare(val, jsVal));
val = 100;

View File

@ -110,7 +110,9 @@
"_getcwd=getcwd",
"NO_CONSOLE_IO",
"BUILD_ZLIB_AS_SOURCES",
"IMAGE_CHECKER_DISABLE_XML"
"IMAGE_CHECKER_DISABLE_XML",
"BUILDING_WASM_MODULE"
],
"compile_files_array": [
{

View File

@ -625,7 +625,7 @@ namespace Aggplus
}
double dWidth = pPen->Size;
double dWidthMinSize = 1.0 / sqrt(m_oCoordTransform.m_internal->m_agg_mtx.determinant());
double dWidthMinSize = 1.0 / sqrt(m_oFullTransform.m_internal->m_agg_mtx.determinant());
if ((0 == dWidth && !m_bIntegerGrid) || dWidth < dWidthMinSize)
{
@ -762,6 +762,7 @@ namespace Aggplus
}
}
dWidthMinSize = 1.0 / sqrt(m_oCoordTransform.m_internal->m_agg_mtx.determinant());
if ((0 == dWidth && !m_bIntegerGrid) || dWidth < dWidthMinSize)
dWidth = dWidthMinSize;

View File

@ -563,11 +563,11 @@ HRESULT CGraphicsRenderer::get_BrushTextureImage(Aggplus::CImage** pImage)
}
HRESULT CGraphicsRenderer::put_BrushTextureImage(Aggplus::CImage *pImage)
{
if (NULL == pImage)
return S_FALSE;
RELEASEINTERFACE(m_oBrush.Image);
if (NULL == pImage)
return S_OK;
m_oBrush.Image = pImage;
m_oBrush.Image->AddRef();

View File

@ -370,15 +370,20 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
return m_nType != -1;
}
CAnnotFieldInfo::CMarkupAnnotPr::~CMarkupAnnotPr()
{
for (int i = 0; i < m_arrRC.size(); ++i)
RELEASEOBJECT(m_arrRC[i]);
}
BYTE CAnnotFieldInfo::CMarkupAnnotPr::GetRT() const { return m_nRT; }
int CAnnotFieldInfo::CMarkupAnnotPr::GetFlag() const { return m_nFlag; }
int CAnnotFieldInfo::CMarkupAnnotPr::GetPopupID() const { return m_nPopupID; }
int CAnnotFieldInfo::CMarkupAnnotPr::GetIRTID() const { return m_nIRTID; }
double CAnnotFieldInfo::CMarkupAnnotPr::GetCA() const { return m_dCA; }
const std::wstring& CAnnotFieldInfo::CMarkupAnnotPr::GetT() { return m_wsT; }
const std::wstring& CAnnotFieldInfo::CMarkupAnnotPr::GetRC() { return m_wsRC; }
const std::wstring& CAnnotFieldInfo::CMarkupAnnotPr::GetCD() { return m_wsCD; }
const std::wstring& CAnnotFieldInfo::CMarkupAnnotPr::GetSubj() { return m_wsSubj; }
const std::vector<CAnnotFieldInfo::CMarkupAnnotPr::CFontData*>& CAnnotFieldInfo::CMarkupAnnotPr::GetRC() { return m_arrRC; }
void CAnnotFieldInfo::CMarkupAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
{
m_nFlag = nFlags;
@ -389,7 +394,26 @@ void CAnnotFieldInfo::CMarkupAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
if (nFlags & (1 << 2))
m_dCA = pReader->ReadDouble();
if (nFlags & (1 << 3))
m_wsRC = pReader->ReadString();
{
int nFont = pReader->ReadInt();
for (int i = 0; i < nFont; ++i)
{
CFontData* pFont = new CFontData();
pFont->nAlignment = pReader->ReadByte();
pFont->nFontFlag = pReader->ReadInt();
if (pFont->nFontFlag & (1 << 5))
pFont->dVAlign = pReader->ReadDouble();
if (pFont->nFontFlag & (1 << 6))
pFont->sActualFont = pReader->ReadString();
pFont->dFontSise = pReader->ReadDouble();
pFont->dColor[0] = pReader->ReadDouble();
pFont->dColor[1] = pReader->ReadDouble();
pFont->dColor[2] = pReader->ReadDouble();
pFont->sFontFamily = pReader->ReadString();
pFont->sText = pReader->ReadString();
m_arrRC.push_back(pFont);
}
}
if (nFlags & (1 << 4))
m_wsCD = pReader->ReadString();
if (nFlags & (1 << 5))
@ -538,12 +562,20 @@ void CAnnotFieldInfo::CPolygonLineAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferR
BYTE CAnnotFieldInfo::CFreeTextAnnotPr::GetQ() const { return m_nQ; }
BYTE CAnnotFieldInfo::CFreeTextAnnotPr::GetIT() const { return m_nIT; }
BYTE CAnnotFieldInfo::CFreeTextAnnotPr::GetLE() const { return m_nLE; }
int CAnnotFieldInfo::CFreeTextAnnotPr::GetRotate() { return m_nRotate; }
const std::wstring& CAnnotFieldInfo::CFreeTextAnnotPr::GetDS() { return m_wsDS; }
void CAnnotFieldInfo::CFreeTextAnnotPr::GetRD(double& dRD1, double& dRD2, double& dRD3, double& dRD4) { dRD1 = m_dRD[0]; dRD2 = m_dRD[1]; dRD3 = m_dRD[2]; dRD4 = m_dRD[3]; }
const std::vector<double>& CAnnotFieldInfo::CFreeTextAnnotPr::GetCL() { return m_arrCL; }
const std::vector<double>& CAnnotFieldInfo::CFreeTextAnnotPr::GetIC() { return m_arrIC; }
BYTE* CAnnotFieldInfo::CFreeTextAnnotPr::GetRender(LONG& nLen)
{
nLen = m_nRenderLen;
return m_pRender;
}
void CAnnotFieldInfo::CFreeTextAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
{
m_nQ = pReader->ReadByte();
m_nRotate = pReader->ReadInt();
if (nFlags & (1 << 15))
{
m_dRD[0] = pReader->ReadDouble();
@ -563,6 +595,18 @@ void CAnnotFieldInfo::CFreeTextAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferRead
m_nLE = pReader->ReadByte();
if (nFlags & (1 << 20))
m_nIT = pReader->ReadByte();
if (nFlags & (1 << 21))
{
int n = pReader->ReadInt();
for (int i = 0; i < n; ++i)
m_arrIC.push_back(pReader->ReadDouble());
}
if (nFlags & (1 << 22))
{
m_nRenderLen = pReader->ReadInt() - 4;
m_pRender = pReader->GetCurrentBuffer();
pReader->Skip(m_nRenderLen);
}
}
BYTE CAnnotFieldInfo::CCaretAnnotPr::GetSy() const { return m_nSy; }

View File

@ -201,15 +201,29 @@ public:
class GRAPHICS_DECL CMarkupAnnotPr
{
public:
struct GRAPHICS_DECL CFontData
{
BYTE nAlignment;
int nFontFlag;
double dFontSise;
double dVAlign;
double dColor[3];
std::wstring sFontFamily;
std::wstring sActualFont;
std::wstring sText;
};
virtual ~CMarkupAnnotPr();
BYTE GetRT() const;
int GetFlag() const;
int GetPopupID() const;
int GetIRTID() const;
double GetCA() const;
const std::wstring& GetT();
const std::wstring& GetRC();
const std::wstring& GetCD();
const std::wstring& GetSubj();
const std::vector<CFontData*>& GetRC();
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
@ -223,6 +237,7 @@ public:
std::wstring m_wsRC;
std::wstring m_wsCD;
std::wstring m_wsSubj;
std::vector<CFontData*> m_arrRC;
};
class GRAPHICS_DECL CTextAnnotPr
@ -352,9 +367,12 @@ public:
BYTE GetQ() const;
BYTE GetIT() const;
BYTE GetLE() const;
int GetRotate();
const std::wstring& GetDS();
void GetRD(double& dRD1, double& dRD2, double& dRD3, double& dRD4);
const std::vector<double>& GetCL();
const std::vector<double>& GetIC();
BYTE* GetRender(LONG& nLen);
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
@ -362,9 +380,13 @@ public:
BYTE m_nQ;
BYTE m_nIT;
BYTE m_nLE;
int m_nRotate;
std::wstring m_wsDS;
double m_dRD[4]{};
std::vector<double> m_arrCL;
std::vector<double> m_arrIC;
LONG m_nRenderLen;
BYTE* m_pRender;
};
class GRAPHICS_DECL CCaretAnnotPr

View File

@ -129,9 +129,25 @@ bool CDocInfoCommand::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
return true;
}
CShapeStart::CShapeStart() : IAdvancedCommand(AdvancedCommandType::ShapeStart) {}
CShapeStart::CShapeStart() : IAdvancedCommand(AdvancedCommandType::ShapeStart)
{
m_pImage = NULL;
}
CShapeStart::~CShapeStart()
{
RELEASEINTERFACE(m_pImage);
}
void CShapeStart::SetShapeXML(const std::string& sShapeXML) { m_sShapeXML = sShapeXML; }
const std::string& CShapeStart::GetShapeXML() { return m_sShapeXML; }
void CShapeStart::SetShapeImage(BYTE* pImgData, int nWidth, int nHeight)
{
if (pImgData)
{
m_pImage = new Aggplus::CImage();
m_pImage->Create(pImgData, nWidth, nHeight, -4 * nWidth);
}
}
std::string& CShapeStart::GetShapeXML() { return m_sShapeXML; }
Aggplus::CImage* CShapeStart::GetShapeImage() { return m_pImage; }
bool CShapeStart::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector)
{
m_sShapeXML = pReader->ReadStringA();

View File

@ -136,14 +136,19 @@ class GRAPHICS_DECL CShapeStart : public IAdvancedCommand
{
public:
CShapeStart();
~CShapeStart();
std::string& GetShapeXML();
Aggplus::CImage* GetShapeImage();
void SetShapeXML(const std::string& sShapeXML);
const std::string& GetShapeXML();
void SetShapeImage(BYTE* pImgData, int nWidth, int nHeight);
bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector);
private:
std::string m_sShapeXML;
Aggplus::CImage* m_pImage;
};
class GRAPHICS_DECL CEmptyComand : public IAdvancedCommand

View File

@ -45,7 +45,11 @@
"_DestroyTextInfo",
"_IsNeedCMap",
"_SetCMapData",
"_ScanPage"
"_ScanPage",
"_GetImageBase64",
"_GetImageBase64Len",
"_GetImageBase64Ptr",
"_GetImageBase64Free"
],
"include_path": [
"wasm/src/lib",

View File

@ -158,6 +158,8 @@
this.fontPageIndex = -1;
this.fontPageUpdateType = UpdateFontsSource.Undefined;
this.fontStreams = {};
this.scannedImages = {};
}
CFile.prototype["loadFromData"] = function(arrayBuffer)
@ -1345,6 +1347,7 @@
}
// 0 - left-justified, 1 - centered, 2 - right-justified
rec["alignment"] = reader.readByte();
rec["Rotate"] = reader.readInt();
// Rect and RD differences
if (flags & (1 << 15))
{
@ -1641,6 +1644,37 @@
return shapes;
};
CFile.prototype["getImageBase64"] = function(rId)
{
let strId = "" + rId;
if (this.scannedImages[strId])
return this.scannedImages[strId];
let strPtr = Module["_GetImageBase64"](this.nativeFile, rId);
if (0 == strPtr)
{
this.scannedImages[strId] = "error";
return this.scannedImages[strId];
}
let len = Module["_GetImageBase64Len"](strPtr);
let ptr = Module["_GetImageBase64Ptr"](strPtr);
var buffer = new Uint8Array(Module["HEAP8"].buffer, ptr, len);
this.scannedImages[strId] = String.prototype.fromUtf8(buffer, 0, len);
Module["_GetImageBase64Free"](strPtr);
return this.scannedImages[strId];
};
CFile.prototype["changeImageUrl"] = function(baseUrl, resultUrl)
{
for (let i in this.scannedImages)
{
if (this.scannedImages[i] == baseUrl)
this.scannedImages[i] = resultUrl;
}
};
CFile.prototype.memory = function()
{
return Module["HEAP8"];

View File

@ -267,6 +267,23 @@ WASM_EXPORT BYTE* ScanPage(CGraphicsFileDrawing* pGraphics, int nPageIndex, int
return pGraphics->GetPageShapes(nPageIndex, mode);
}
WASM_EXPORT void* GetImageBase64(CGraphicsFileDrawing* pGraphics, int rId)
{
return pGraphics->GetImageBase64(rId);
}
WASM_EXPORT int GetImageBase64Len(std::string* p)
{
return (int)p->length();
}
WASM_EXPORT char* GetImageBase64Ptr(std::string* p)
{
return (char*)p->c_str();
}
WASM_EXPORT void GetImageBase64Free(std::string* p)
{
*p = "";
}
#ifdef __cplusplus
}
#endif

View File

@ -220,6 +220,13 @@ public:
oRes.ClearWithoutAttack();
return res;
}
std::string* GetImageBase64(int nRId)
{
if (NULL == pImageStorage)
return NULL;
return pImageStorage->GetBase64(nRId);
}
};
#endif // _WASM_GRAPHICS_

View File

@ -1597,6 +1597,10 @@ int main(int argc, char* argv[])
i += 1;
std::cout << "Q " << arrQ[nPathLength] << ", ";
nPathLength = READ_INT(pAnnots + i);
i += 4;
std::cout << "Rotate " << nPathLength << ", ";
if (nFlags & (1 << 15))
{
std::cout << "RD";

View File

@ -149,6 +149,7 @@ void CPdfWriter::Sign(const double& dX, const double& dY, const double& dW, cons
HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWidgetsInfo* pFieldInfo, const std::wstring& wsTempDirectory) { return 0; }
PdfWriter::CDocument* CPdfWriter::GetDocument() { return NULL; }
PdfWriter::CPage* CPdfWriter::GetPage() { return NULL; }
void CPdfWriter::AddFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, const std::wstring& wsFontPath, const LONG& lFaceIndex) {}
PdfWriter::CImageDict* CPdfWriter::LoadImage(Aggplus::CImage* pImage, BYTE nAlpha) { return NULL; }
PdfWriter::CImageDict* CPdfWriter::DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { return NULL; }
bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY) { return false; }

View File

@ -442,6 +442,8 @@ namespace NSStructures
Alpha2 = other.Alpha2;
Image = other.Image;
if (Image)
((IGrObject*)Image)->AddRef();
Transform = other.Transform;
TexturePath = other.TexturePath;

View File

@ -93,7 +93,7 @@ namespace MetaFile
{
public:
CDataStream() : pBuffer(NULL)
CDataStream() : pBuffer(NULL), pBufferEnd(NULL), pEnd(NULL), pCur(NULL)
{
}
@ -103,10 +103,25 @@ namespace MetaFile
void SetStream(BYTE* pBuf, unsigned int unSize)
{
pBuffer = pBuf;
pCur = pBuf;
pEnd = pBuf + unSize;
};
pBuffer = pBuf;
pCur = pBuf;
pBufferEnd = pBuf + unSize;
pEnd = pBufferEnd;
}
void SetCurrentBlockSize(unsigned int unSize)
{
if (pCur + unSize >= pBufferEnd)
pEnd = pBufferEnd;
else
pEnd = pCur + unSize;
}
void ClearCurrentBlockSize()
{
pEnd = pBufferEnd;
}
BYTE* GetCurPtr()
{
return pCur;
@ -120,7 +135,7 @@ namespace MetaFile
unsigned char unResult = pCur[0];
pCur++;
return unResult;
};
}
unsigned short ReadUShort()
{
if (pCur + 1 >= pEnd)
@ -129,7 +144,7 @@ namespace MetaFile
unsigned short ushResult = (pCur[0]) | ((pCur[1]) << 8);
pCur += 2;
return ushResult;
};
}
unsigned int ReadULong()
{
if (pCur + 3 >= pEnd)
@ -138,7 +153,7 @@ namespace MetaFile
unsigned int unResult = (unsigned int)((pCur[0] << 0) | ((pCur[1]) << 8) | ((pCur[2]) << 16) | ((pCur[3]) << 24));
pCur += 4;
return unResult;
};
}
double ReadDouble()
{
if (pCur + 3 >= pEnd)
@ -159,19 +174,19 @@ namespace MetaFile
int lFracValue = (int)(pCur[3]);
pCur += 4;
return (double)(lIntValue + (lFracValue / 16.0));
};
}
char ReadChar()
{
return (char)ReadUChar();
};
}
short ReadShort()
{
return (short)ReadUShort();
};
}
int ReadLong()
{
return (int)ReadULong();
};
}
void ReadBytes(unsigned char* pBuffer, unsigned int ulSize)
{
size_t ulRemainSize = (pEnd - pCur);
@ -181,7 +196,7 @@ namespace MetaFile
{
pBuffer[ulIndex] = ReadChar();
}
};
}
void ReadBytes(unsigned short* pBuffer, unsigned int ulSize)
{
size_t ulRemainSize = (pEnd - pCur) / 2;
@ -1047,7 +1062,7 @@ namespace MetaFile
bool IsEof() const
{
if (pCur >= pEnd)
if (pCur >= pBufferEnd)
return true;
return false;
@ -1060,7 +1075,10 @@ namespace MetaFile
void Skip(unsigned int ulSkip)
{
pCur += ulSkip;
if (pCur + ulSkip >= pEnd)
pCur = pEnd;
else
pCur += ulSkip;
}
void SeekBack(unsigned int ulSkipBack)
@ -1071,6 +1089,7 @@ namespace MetaFile
void SeekToStart()
{
pCur = pBuffer;
ClearCurrentBlockSize();
}
unsigned int CanRead()
@ -1085,21 +1104,31 @@ namespace MetaFile
*this >> oText;
// Читаем OutputString
const unsigned int unCharsCount = oText.unChars;
int nSkip = oText.unOffString - (unOffset + 40); // 40 - размер структуры TEmfEmrText
Skip(nSkip);
T* pString = new T[unCharsCount + 1];
oText.unChars = std::min(oText.unChars, (UINT)(CanRead() / sizeof(T)));
if (0 == oText.unChars)
return;
if (oText.unOffString - 40 > unOffset)
Skip(oText.unOffString - (unOffset + 40)); // 40 - размер структуры TEmfEmrText
T* pString = new T[oText.unChars + 1];
if (pString)
{
pString[unCharsCount] = 0x00;
ReadBytes(pString, unCharsCount);
pString[oText.unChars] = 0x00;
ReadBytes(pString, oText.unChars);
oText.pOutputString = pString;
}
// Читаем OutputDx
nSkip = oText.unOffDx - oText.unOffString - 2 * unCharsCount;
Skip(nSkip);
const unsigned int unDxCount = oText.unOptions & ETO_PDY ? 2 * unCharsCount : unCharsCount;
if (oText.unChars < (UINT32_MAX / 2) && (oText.unOffDx > oText.unOffString) && (oText.unOffDx - oText.unOffString > 2 * oText.unChars))
Skip(oText.unOffDx - oText.unOffString - 2 * oText.unChars);
const unsigned int unDxCount = (oText.unOptions & ETO_PDY ? 2 * oText.unChars : oText.unChars);
if ((CanRead() / 4) < unDxCount || 0 == unDxCount)
return;
unsigned int* pDx = new unsigned int[unDxCount];
if (pDx)
{
@ -1116,6 +1145,7 @@ namespace MetaFile
private:
BYTE *pBuffer;
BYTE *pBufferEnd;
BYTE *pCur;
BYTE *pEnd;
};

View File

@ -1169,6 +1169,7 @@ namespace MetaFile
std::wstring wsFontName = pFont->GetFaceName();
#ifndef BUILDING_WASM_MODULE
if (!wsFontName.empty())
{
NSFonts::CFontSelectFormat oFormat;
@ -1179,6 +1180,7 @@ namespace MetaFile
if (NULL != pFontInfo && !StringEquals(wsFontName, pFontInfo->m_wsFontName))
wsFontName = L"&apos;" + wsFontName + L"&apos;, &apos;" + pFontInfo->m_wsFontName + L"&apos;";
}
#endif
if (!wsFontName.empty())
arNodeAttributes.push_back({L"font-family", wsFontName});

View File

@ -63,6 +63,8 @@ namespace MetaFile
m_ulRecordPos = m_oStream.Tell();
m_ulRecordSize = ulSize - 8;
m_oStream.SetCurrentBlockSize(m_ulRecordSize);
if (ulType < EMR_MIN || ulType > EMR_MAX)
{
if (ENHMETA_SIGNATURE != m_oHeader.ulSignature || 0x00010000 != m_oHeader.ulVersion)
@ -213,6 +215,8 @@ namespace MetaFile
m_oStream.Skip(need_skip);
ulRecordIndex++;
m_oStream.ClearCurrentBlockSize();
} while (!CheckError());
if (!CheckError())

View File

@ -234,6 +234,8 @@ namespace MetaFile
m_oStream >> unSize;
m_oStream >> m_ulRecordSize;
m_oStream.SetCurrentBlockSize(m_ulRecordSize);
unsigned int unRecordPos = m_oStream.Tell();
LOGGING(ActionNamesEmfPlus[unShType] << L" DataSize = " << m_ulRecordSize)
@ -318,6 +320,7 @@ namespace MetaFile
LOGGING(L"Skip: " << nNeedSkip)
m_oStream.ClearCurrentBlockSize();
m_ulRecordSize = 0;
}while(m_oStream.CanRead() >= 12 && !m_bEof);

View File

@ -283,6 +283,7 @@ namespace MetaFile
std::wstring wsFontName = pFont->GetFaceName();
#ifndef BUILDING_WASM_MODULE
if (!wsFontName.empty())
{
NSFonts::CFontSelectFormat oFormat;
@ -293,6 +294,7 @@ namespace MetaFile
if (NULL != pFontInfo && !StringEquals(wsFontName, pFontInfo->m_wsFontName))
wsFontName = L"&apos;" + wsFontName + L"&apos;, &apos;" + pFontInfo->m_wsFontName + L"&apos;";
}
#endif
if (!wsFontName.empty())
arNodeAttributes.push_back({L"font-family", wsFontName});

View File

@ -52,6 +52,8 @@ namespace MetaFile
m_unRecordSize = unSize * 2; // Размер указан в WORD
m_oStream.SetCurrentBlockSize(m_unRecordSize);
switch (ushType)
{
//-----------------------------------------------------------
@ -161,6 +163,7 @@ namespace MetaFile
// Пропускаем лишние байты, которые могли быть в записи
int need_skip = m_unRecordSize - (m_oStream.Tell() - m_unRecordPos);
m_oStream.Skip(need_skip);
m_oStream.ClearCurrentBlockSize();
};
if (!m_bEof)

View File

@ -42,30 +42,40 @@ bool CSvgFile::GetBounds(double &dX, double &dY, double &dWidth, double &dHeight
SVG::TRect oWindow = m_oContainer.GetWindow();
dX = oWindow.m_oX .ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
dY = oWindow.m_oY .ToDouble(NSCSS::Pixel, SVG_FILE_HEIGHT);
dX = oWindow.m_oX.ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
dY = oWindow.m_oY.ToDouble(NSCSS::Pixel, SVG_FILE_HEIGHT);
dWidth = 0.;
dHeight = 0.;
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero())
{
if (NSCSS::Percent != oWindow.m_oWidth.GetUnitMeasure() && !m_oContainer.GetViewBox().m_oWidth.Empty() && !m_oContainer.GetViewBox().m_oWidth.Zero())
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel));
if (NSCSS::Percent == oWindow.m_oWidth.GetUnitMeasure())
{
if (!m_oContainer.GetViewBox().m_oWidth.Empty() && !m_oContainer.GetViewBox().m_oWidth.Zero())
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel));
else
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
}
else
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel);
}
else if (!m_oContainer.GetViewBox().m_oWidth.Empty() && !m_oContainer.GetViewBox().m_oWidth.Zero())
else
dWidth = m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel);
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero())
{
if (NSCSS::Percent != oWindow.m_oHeight.GetUnitMeasure() && !m_oContainer.GetViewBox().m_oHeight.Empty() && !m_oContainer.GetViewBox().m_oHeight.Zero())
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel));
if (NSCSS::Percent == oWindow.m_oHeight.GetUnitMeasure())
{
if (!m_oContainer.GetViewBox().m_oHeight.Empty() && !m_oContainer.GetViewBox().m_oHeight.Zero())
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel));
else
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
}
else
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
}
else if (!m_oContainer.GetViewBox().m_oHeight.Empty() && !m_oContainer.GetViewBox().m_oHeight.Zero())
else
dHeight = m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel);
if (0. == dWidth)

View File

@ -52,37 +52,21 @@ namespace SVG
bool CGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
{
if (NULL == pRenderer)
if (NULL == pRenderer || m_arObjects.empty())
return false;
if (m_arObjects.empty())
{
if (m_wsXlinkHref.empty() || NULL == pFile)
return false;
std::vector<LONG> arColors;
std::vector<double> arPositions;
CGradient *pGradiend = dynamic_cast<CGradient*>(pFile->GetMarkedObject(m_wsXlinkHref));
if (NULL == pGradiend)
return false;
pGradiend->Apply(pRenderer, pFile, oObjectBounds);
}
else
for (const CStopElement* pStopElement : m_arObjects)
{
std::vector<LONG> arColors;
std::vector<double> arPositions;
for (const CStopElement* pStopElement : m_arObjects)
{
arColors.push_back(((unsigned int)(pStopElement->GetColor().ToInt() | ((unsigned char)(255. * pStopElement->GetColor().GetOpacity()) << 24))));
arPositions.push_back(pStopElement->GetOffset().ToDouble());
}
pRenderer->put_BrushGradientColors(arColors.data(), arPositions.data(), arColors.size());
arColors.push_back(((unsigned int)(pStopElement->GetColor().ToInt() | ((unsigned char)(255. * pStopElement->GetColor().GetOpacity()) << 24))));
arPositions.push_back(pStopElement->GetOffset().ToDouble());
}
pRenderer->put_BrushGradientColors(arColors.data(), arPositions.data(), arColors.size());
pRenderer->put_BrushTransform(m_oTransform.GetMatrix().GetFinalValue());
return true;
}
@ -108,6 +92,31 @@ namespace SVG
pRenderer->BrushBounds(oNewBounds.m_dLeft, oNewBounds.m_dTop, oNewBounds.m_dRight - oNewBounds.m_dLeft, oNewBounds.m_dBottom - oNewBounds.m_dTop);
}
CGradient *CGradient::GetRefGradient(const CSvgFile *pFile) const
{
if (m_wsXlinkHref.empty() || NULL == pFile)
return NULL;
CGradient *pGradiend = dynamic_cast<CGradient*>(pFile->GetMarkedObject(m_wsXlinkHref));
if (NULL == pGradiend)
return NULL;
CGradient *pRefGradient = pGradiend->GetRefGradient(pFile);
return (NULL != pRefGradient) ? pRefGradient : pGradiend;
}
bool CGradient::ApplyRefGradient(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) const
{
CGradient *pRefGradient = GetRefGradient(pFile);
if (NULL == pRefGradient)
return false;
return pRefGradient->Apply(pRenderer, pFile, oObjectBounds);
}
CLinearGradient::CLinearGradient(XmlUtils::CXmlNode& oNode)
: CGradient(oNode)
{
@ -120,10 +129,8 @@ namespace SVG
bool CLinearGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
{
if (!CGradient::Apply(pRenderer, pFile, oObjectBounds))
return false;
return ApplyRefGradient(pRenderer, pFile, oObjectBounds);
pRenderer->put_BrushType(c_BrushTypePathGradient1);
if (m_oX1 == m_oX2 && m_oY1 == m_oY2)
{
pRenderer->put_BrushType(c_BrushTypeSolid);
@ -132,6 +139,8 @@ namespace SVG
return true;
}
pRenderer->put_BrushType(c_BrushTypePathGradient1);
double dAngle = 0.;
TBounds oNewBounds(oObjectBounds);
@ -171,8 +180,8 @@ namespace SVG
bool CRadialGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
{
if (!CGradient::Apply(pRenderer, pFile, oObjectBounds) || m_oR.Zero())
return false;
return ApplyRefGradient(pRenderer, pFile, oObjectBounds);
double dCX = (oObjectBounds.m_dRight + oObjectBounds.m_dLeft) / 2.;
double dCY = (oObjectBounds.m_dBottom + oObjectBounds.m_dTop) / 2.;
double dR = oObjectBounds.m_dBottom - oObjectBounds.m_dTop;

View File

@ -47,6 +47,9 @@ namespace SVG
bool Apply(IRenderer* pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) override;
void ApplyTransform(IRenderer *pRenderer, const TBounds& oBounds, double& dAngle) const;
private:
CGradient* GetRefGradient(const CSvgFile *pFile) const;
bool ApplyRefGradient(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) const;
std::wstring m_wsXlinkHref;
GradientUnits m_enGradientUnits;
SpreadMethod m_enSpreadMethod;

View File

@ -29,35 +29,33 @@
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
//#include <QCoreApplication>
// #include <QCoreApplication>
#include "../../../../fontengine/ApplicationFontsWorker.h"
#include "../../../../graphics/pro/Fonts.h"
#include "../../../../graphics/pro/Graphics.h"
#include "../../../../fontengine/ApplicationFontsWorker.h"
#include "../../../../raster/BgraFrame.h"
#include "../../../../common/Directory.h"
#include "../../../../raster/BgraFrame.h"
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
// Check system fonts
CApplicationFontsWorker oWorker;
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
oWorker.m_bIsNeedThumbnails = false;
// Check system fonts
CApplicationFontsWorker oWorker;
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
oWorker.m_bIsNeedThumbnails = false;
if (!NSDirectory::Exists(oWorker.m_sDirectory))
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
if (!NSDirectory::Exists(oWorker.m_sDirectory))
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
MetaFile::IMetaFile* pMetafile = MetaFile::Create(pFonts);
pMetafile->LoadFromFile(L"PATH_TO_METAFILE");
MetaFile::IMetaFile* pMetafile = MetaFile::Create(pFonts);
pMetafile->LoadFromFile(L"D:/image1.wmf");
std::wstring wsData;
pMetafile->ConvertToSvg(wsData);
std::wstring wsData = pMetafile->ConvertToSvg();
pMetafile->Release();
pFonts->Release();
return 0;
pFonts->Release();
return 0;
}

View File

@ -237,7 +237,14 @@ HRESULT CDocxRenderer::AdvancedCommand(IAdvancedCommand* command)
case IAdvancedCommand::AdvancedCommandType::ShapeStart:
{
CShapeStart* pShape = (CShapeStart*)command;
const std::string& sUtf8Shape = pShape->GetShapeXML();
std::string& sUtf8Shape = pShape->GetShapeXML();
Aggplus::CImage* pImage = pShape->GetShapeImage();
if (pImage)
{
std::shared_ptr<NSDocxRenderer::CImageInfo> pInfo = m_pInternal->m_oDocument.m_oImageManager.GenerateImageID(pImage);
std::string sNewId = "r:embed=\"rId" + std::to_string(pInfo->m_nId + c_iStartingIdForImages) + "\"";
NSStringUtils::string_replaceA(sUtf8Shape, "r:embed=\"\"", sNewId);
}
m_pInternal->m_oDocument.m_oCurrentPage.m_arCompleteObjectsXml.push_back(UTF8_TO_U(sUtf8Shape));
return S_OK;
}
@ -466,8 +473,23 @@ HRESULT CDocxRenderer::put_BrushGradientColors(LONG* pColors, double* pPositions
// TODO:
return S_OK;
}
HRESULT CDocxRenderer::get_BrushTextureImage(Aggplus::CImage** pImage) { return S_OK; }
HRESULT CDocxRenderer::put_BrushTextureImage(Aggplus::CImage* pImage) { return S_OK; }
HRESULT CDocxRenderer::get_BrushTextureImage(Aggplus::CImage** pImage)
{
*pImage = m_pInternal->m_oDocument.m_oBrush.Image;
return S_OK;
}
HRESULT CDocxRenderer::put_BrushTextureImage(Aggplus::CImage* pImage)
{
RELEASEINTERFACE(m_pInternal->m_oDocument.m_oBrush.Image);
if (NULL == pImage)
return S_FALSE;
m_pInternal->m_oDocument.m_oBrush.Image = pImage;
m_pInternal->m_oDocument.m_oBrush.Image->AddRef();
return S_OK;
}
HRESULT CDocxRenderer::get_BrushTransform(Aggplus::CMatrix& oMatrix) { return S_OK; }
HRESULT CDocxRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix) { return S_OK; }
//----------------------------------------------------------------------------------------

View File

@ -635,7 +635,10 @@ namespace NSDocxRenderer
double y = 0;
double w = 0;
double h = 0;
pInfo = m_oImageManager.WriteImage(m_oBrush.TexturePath, x, y, w, h);
if (m_oBrush.Image)
pInfo = m_oImageManager.WriteImage(m_oBrush.Image, x, y, w, h);
else
pInfo = m_oImageManager.WriteImage(m_oBrush.TexturePath, x, y, w, h);
}
m_oCurrentPage.DrawPath(nType, pInfo);

View File

@ -1028,6 +1028,8 @@ namespace NSDocxRenderer
{
for (auto& pCont : line->m_arConts)
{
if (!pCont)
continue;
if (base_line->m_dLeft > pCont->m_dLeft)
base_line->m_dLeft = pCont->m_dLeft;
if (base_line->m_dRight < pCont->m_dRight)

View File

@ -709,6 +709,8 @@ namespace NSDocxRenderer
void CShape::BuildPictureProperties(NSStringUtils::CStringBuilder &oWriter) const
{
// TODO: Clip path as geometry + tile!!!
oWriter.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
oWriter.WriteString(L"<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
@ -944,6 +946,39 @@ namespace NSDocxRenderer
}
void CShape::ToXmlPptx(NSStringUtils::CStringBuilder &oWriter) const
{
if (m_eType == eShapeType::stPicture ||
m_eType == eShapeType::stVectorTexture)
{
// TODO: Clip path as geometry + tile!!!
oWriter.WriteString(L"<p:pic>");
oWriter.WriteString(L"<p:nvPicPr>");
oWriter.WriteString(L"<p:cNvPr id=\"");
oWriter.AddUInt(m_pImageInfo->m_nId);
oWriter.WriteString(L"\" name=\"Picture ");
oWriter.AddUInt(m_pImageInfo->m_nId);
oWriter.WriteString(L"\"/>");
oWriter.WriteString(L"<p:cNvPicPr><a:picLocks noChangeAspect=\"1\"/></p:cNvPicPr>");
oWriter.WriteString(L"<p:nvPr/>");
oWriter.WriteString(L"</p:nvPicPr>");
oWriter.WriteString(L"<p:blipFill>");
oWriter.WriteString(L"<a:blip r:embed=\"rId");
oWriter.AddUInt(c_iStartingIdForImages + m_pImageInfo->m_nId);
oWriter.WriteString(L"\">");
oWriter.WriteString(L"</a:blip>");
oWriter.WriteString(L"<a:stretch><a:fillRect/></a:stretch>");
oWriter.WriteString(L"</p:blipFill>");
oWriter.WriteString(L"<p:spPr>");
BuildForm(oWriter, true);
oWriter.WriteString(L"<a:prstGeom prst=\"rect\">");
oWriter.WriteString(L"<a:avLst/>");
oWriter.WriteString(L"</a:prstGeom>");
oWriter.WriteString(L"</p:spPr>");
oWriter.WriteString(L"</p:pic>");
return;
}
oWriter.WriteString(L"<p:sp>");
oWriter.WriteString(L"<p:spPr>");

View File

@ -21,7 +21,7 @@ namespace NSDocxRenderer
public:
virtual std::shared_ptr<CImageInfo> GenerateImageID(Aggplus::CImage* pImage) = 0;
virtual std::map<std::wstring, std::string>* GetImages() = 0;
virtual std::string* GetBase64(const int& nRId) = 0;
};
DOCXRENDERER_DECL_EXPORT IImageStorage* CreateWasmImageStorage();

View File

@ -1,5 +1,6 @@
#include "ImageManager.h"
#include "../../../../DesktopEditor/common/Directory.h"
#include "../../resources/Constants.h"
namespace NSDocxRenderer
{
@ -10,7 +11,7 @@ namespace NSDocxRenderer
{
private:
std::map<DWORD, std::shared_ptr<CImageInfo>> m_mapImageData;
std::map<std::wstring, std::string> m_mapImages;
std::map<int, std::string> m_mapImages;
int m_lMaxSizeImage{1200};
int m_lNextIDImage{0};
@ -87,21 +88,31 @@ namespace NSDocxRenderer
oBgraFrame.put_Data(NULL);
int nBase64DataSize = NSBase64::Base64EncodeGetRequiredLength(nEncodeBufferSize);
char* pBase64Data = new char[nBase64DataSize];
int nHeaderSize = (pInfo->m_eType == CImageInfo::itPNG) ? 22 : 23;
NSBase64::Base64Encode(pEncodeBuffer, nEncodeBufferSize, (BYTE*)pBase64Data, &nBase64DataSize, NSBase64::B64_BASE64_FLAG_NOCRLF);
char* pBase64Data = new char[nBase64DataSize + nHeaderSize];
if (pInfo->m_eType == CImageInfo::itPNG)
memcpy(pBase64Data, "data:image/png;base64,", nHeaderSize);
else
memcpy(pBase64Data, "data:image/jpeg;base64,", nHeaderSize);
NSBase64::Base64Encode(pEncodeBuffer, nEncodeBufferSize, (BYTE*)pBase64Data + nHeaderSize, &nBase64DataSize, NSBase64::B64_BASE64_FLAG_NOCRLF);
RELEASEARRAYOBJECTS(pEncodeBuffer);
m_mapImages.insert(std::pair<std::wstring, std::string>(pInfo->m_strFileName, std::string(pBase64Data, nBase64DataSize)));
m_mapImages.insert(std::pair<int, std::string>((int)pInfo->m_nId, std::string(pBase64Data, nHeaderSize + nBase64DataSize)));
RELEASEARRAYOBJECTS(pBase64Data);
m_mapImageData.insert(std::pair<DWORD, std::shared_ptr<CImageInfo>>(dwSum, pInfo));
return pInfo;
}
virtual std::map<std::wstring, std::string>* GetImages()
virtual std::string* GetBase64(const int& nRId)
{
return &m_mapImages;
std::map<int, std::string>::iterator iter = m_mapImages.find(nRId - c_iStartingIdForImages);
if (iter == m_mapImages.end())
return NULL;
return &iter->second;
}
};

View File

@ -37,8 +37,6 @@ namespace NSDocxRenderer
void SaveImage(Aggplus::CImage* pImage, std::shared_ptr<CImageInfo> pInfo);
std::shared_ptr<CImageInfo> GenerateImageID(Aggplus::CImage* pImage);
std::shared_ptr<CImageInfo> GenerateImageID(const std::wstring& strFileName);
void FlipY(Aggplus::CImage* pImage);
@ -47,5 +45,6 @@ namespace NSDocxRenderer
public:
static CImageInfo::ImageType GetImageType(Aggplus::CImage* pFrame);
std::shared_ptr<CImageInfo> GenerateImageID(Aggplus::CImage* pImage);
};
}

View File

@ -146,6 +146,13 @@ const std::wstring CBookInfo::GetLanguages() const
return sLanguages;
}
const std::wstring CBookInfo::GetLanguage() const
{
if (m_arLanguages.empty())
return L"";
return m_arLanguages.front();
}
const std::wstring CBookInfo::GetContibutors() const
{
if (m_arContributors.empty())

View File

@ -30,6 +30,7 @@ public:
const std::wstring GetCreators() const;
const std::wstring GetPublishers() const;
const std::wstring GetLanguages() const;
const std::wstring GetLanguage() const;
const std::wstring GetContibutors() const;
const std::wstring GetDescriptions() const;
const std::wstring GetSubjects() const;

View File

@ -137,11 +137,13 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
CHtmlFile2 oFile;
CHtmlParams oFileParams;
oFileParams.SetAuthors(m_oBookInfo.GetCreators());
oFileParams.SetGenres (m_oBookInfo.GetSubjects());
oFileParams.SetTitle (m_oBookInfo.GetTitle());
oFileParams.SetDate (m_oBookInfo.GetDate());
oFileParams.SetDescription(m_oBookInfo.GetDescriptions());
oFileParams.SetAuthors (m_oBookInfo.GetCreators());
oFileParams.SetGenres (m_oBookInfo.GetSubjects());
oFileParams.SetTitle (m_oBookInfo.GetTitle());
oFileParams.SetDate (m_oBookInfo.GetDate());
oFileParams.SetDescription (m_oBookInfo.GetDescriptions());
oFileParams.SetLanguage (m_oBookInfo.GetLanguage());
oFileParams.SetPageBreakBefore(true);
std::wstring sDocxFileTempDir = m_sTempDir + L"/tmp";

View File

@ -31,4 +31,5 @@ ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, kernel_network)
SOURCES += htmlfile2.cpp
HEADERS += htmlfile2.h \
./src/StringFinder.h
./src/StringFinder.h \
./src/Languages.h

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@ struct CHtmlParams
std::wstring m_sBookTitle; // Название
std::wstring m_sDate; // Дата
std::wstring m_sDescription; // описание
std::wstring m_sLanguage; // Язык
bool m_bNeedPageBreakBefore; // Новый html с новой страницы
std::wstring m_sdocDefaults; // Стиль docDefaults
std::wstring m_sNormal; // Стиль normal
@ -64,6 +65,11 @@ struct CHtmlParams
{
m_sBookTitle = sTitle;
}
void SetLanguage(const std::wstring& sLanguage)
{
m_sLanguage = sLanguage;
}
};
class CHtmlFile2_Private;

84
HtmlFile2/src/Languages.h Normal file
View File

@ -0,0 +1,84 @@
#ifndef LANGUAGES_LIST_H
#define LANGUAGES_LIST_H
#include <map>
#include <string>
#include <algorithm>
const static std::map<std::wstring, std::wstring> m_Languages_HTML
{
//Язык, Регион
{L"en", L"US"}, // Английский - США
{L"ru", L"RU"}, // Русский - Россия
{L"es", L"ES"}, // Испанский - Испания
{L"de", L"DE"}, // Немецкий - Германия
{L"fr", L"FR"}, // Французский - Франция
{L"it", L"IT"}, // Итальянский - Италия
{L"pt", L"PT"}, // Португальский - Португалия
{L"pl", L"PL"}, // Польский - Польша
{L"nl", L"NL"}, // Нидерландский - Нидерланды
{L"sv", L"SE"}, // Шведский - Швеция
{L"nb", L"NO"}, // Норвежский - Новегия
{L"da", L"DK"}, // Датский - Дания
{L"fi", L"FI"}, // Финский - Финляндия
{L"el", L"GR"}, // Греческий - Греция
{L"tr", L"TR"}, // Турецкий - Турция
{L"ar", L"SA"}, // Арабский - Саудовская Аравия
{L"he", L"IL"}, // Иврит - Израиль
{L"ja", L"JP"}, // Японский - Япония
{L"zh", L"CN"}, // Китайский (упрощенный) - Китай
{L"hu", L"HU"}, // Венгерский - Венгрия
{L"cs", L"CZ"}, // Чешский - Чехия
{L"ro", L"RO"}, // Румынский - Румыния
{L"bg", L"BG"}, // Болгарский - Болгария
{L"hr", L"HR"}, // Хорватский - Хорватия
{L"sr", L"Latn-RS"}, //Сербский - Сербия
{L"sl", L"SI"}, // Словенский - Словения
{L"lt", L"LT"}, // Литовский - Литва
{L"lv", L"LV"}, // Латышский - Латвия
{L"et", L"EE"}, // Эстонский - Эстония
{L"uk", L"UA"}, // Украинский - Украина
{L"be", L"BY"}, // Белорусский - Беларусь
{L"kk", L"KZ"}, // Казахский - Казахстан
{L"hi", L"IN"}, // Хинди - Индия
{L"th", L"TH"}, // Тайский - Таиланд
{L"vi", L"VN"}, // Вьетнамский - Вьетнам
{L"id", L"ID"}, // Индонезийский - Индонезия
{L"ms", L"MY"}, // Малайский - Малайзия
{L"fil", L"PH"}, // Филиппинский - Филиппины
{L"ko", L"KR"}, // Корейский - Южная Корея
{L"is", L"IS"}, // Исландский - Исландия
{L"ga", L"IE"}, // Ирландский - Ирландия
{L"cy", L"GB"}, // Валлийский - Великобритания
{L"ca", L"ES"}, // Каталанский - Испания
{L"eu", L"ES"}, // Баскский - Испания
{L"gl", L"ES"}, // Галисийский - Испания
{L"af", L"ZA"}, // Африкаанс - Южная Африка
{L"zu", L"ZA"}, // Зулу - Южная Африка
{L"ha", L"Latn-NG"}, // Хауса - Нигерия
{L"yo", L"NG"}, // Йоруба - Нигерия
{L"sw", L"KE"}, // Суахили - Кения
{L"am", L"ET"}, // Амхарский - Эфиопия
{L"ti", L"ET"}, // Тигринья - Эфиопия
{L"ur", L"PK"}, // Урду - Пакистан
{L"pa", L"IN"}, // Панджаби - Индия
{L"gu", L"IN"}, // Гуджарати - Индия
{L"ta", L"IN"}, // Тамильский - Индия
{L"te", L"IN"}, // Телугу - Индия
{L"ml", L"IN"}, // Малаялам - Индия
{L"kn", L"IN"} // Каннада - Индия
};
static std::wstring IndentifyLanguage(std::wstring wsLanguage)
{
std::transform(wsLanguage.begin(), wsLanguage.end(), wsLanguage.begin(), towlower);
std::map<std::wstring, std::wstring>::const_iterator itFounded = m_Languages_HTML.find(wsLanguage);
if (m_Languages_HTML.end() != itFounded)
return itFounded->first + L"-" + itFounded->second;
return std::wstring();
}
#endif // LANGUAGES_LIST_H

View File

@ -13,6 +13,23 @@
namespace NSStringFinder
{
template<class CharType, class StringType = std::basic_string<CharType, std::char_traits<CharType>, std::allocator<CharType>>>
struct TFoundedData
{
size_t m_unBeginPosition;
size_t m_unEndPosition;
StringType m_sValue;
TFoundedData()
: m_unBeginPosition(0), m_unEndPosition(0)
{}
bool Empty() const
{
return 0 == m_unEndPosition || StringType::npos == m_unEndPosition;
}
};
template<class CharType, class StringType = std::basic_string<CharType, std::char_traits<CharType>, std::allocator<CharType>>>
StringType FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const StringType& sDelimiter, const StringType& sEnding, const size_t& unStarting, size_t& unEndPosition)
{
@ -66,70 +83,85 @@ namespace NSStringFinder
}
template<class CharType, class StringType = std::basic_string<CharType, std::char_traits<CharType>, std::allocator<CharType>>>
StringType FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const std::vector<StringType>& arDelimiters, const std::vector<StringType>& arEndings, const size_t& unStarting, size_t& unEndPosition)
TFoundedData<CharType> FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const std::vector<StringType>& arDelimiters, const std::vector<StringType>& arEndings, const size_t& unStarting)
{
if (sString.length() < unStarting)
return StringType();
return TFoundedData<CharType>();
std::string sRegexValue = "(?i)" + std::string(sProperty.begin(), sProperty.end());
std::wstring wsRegexValue = L"(?i)" + std::wstring(sProperty.begin(), sProperty.end());
if (!arDelimiters.empty())
{
sRegexValue += "\\s*[";
for (const StringType& sDelimiter : arDelimiters)
sRegexValue += std::string(sDelimiter.begin(), sDelimiter.end()) + "|";
sRegexValue.pop_back();
sRegexValue += "]{1}";
wsRegexValue += L"\\s*[";
for (const StringType& wsDelimiter : arDelimiters)
wsRegexValue += std::wstring(wsDelimiter.begin(), wsDelimiter.end()) + L"|";
wsRegexValue.pop_back();
wsRegexValue += L"]{1}";
}
if (!arEndings.empty())
{
std::string sEndingValue;
std::wstring wsEndingValue;
for (const StringType& sEnding : arEndings)
sEndingValue += std::string(sEnding.begin(), sEnding.end()) + "|";
wsEndingValue += std::wstring(sEnding.begin(), sEnding.end()) + L"|";
sEndingValue.pop_back();
wsEndingValue.pop_back();
sRegexValue += "\\s*(.[^" + sEndingValue + "]*)\\s*[" + sEndingValue + "]?";
wsRegexValue += L"\\s*(.[^" + wsEndingValue + L"]*)\\s*[" + wsEndingValue + L"]?";
}
else
sRegexValue += "\\s*(.*)[\\n|\\r]?";
wsRegexValue += L"\\s*(.*)[\\n|\\r]?";
boost::regex oRegex(sRegexValue);
boost::wregex oRegex(wsRegexValue);
boost::match_results<typename StringType::const_iterator> oResult;
if (!boost::regex_search(sString.begin() + unStarting, sString.end(), oResult, oRegex))
return StringType();
return TFoundedData<CharType>();
unEndPosition = unStarting + oResult.position() + oResult.length();
TFoundedData<CharType> oData;
StringType sValue(oResult[1]);
boost::algorithm::trim(sValue);
oData.m_unBeginPosition = unStarting + oResult.position();
oData.m_unEndPosition = unStarting + oResult.position() + oResult.length();
return sValue;
oData.m_sValue = oResult[1];
boost::algorithm::trim(oData.m_sValue);
return oData;
}
std::string FindPropety(const std::string& sString, const std::string& sProperty, const std::vector<std::string>& arDelimiters, const std::vector<std::string>& arEndings, const size_t& unStarting, size_t& unEndPosition)
TFoundedData<char> FindPropety(const std::string& sString, const std::string& sProperty, const std::vector<std::string>& arDelimiters, const std::vector<std::string>& arEndings, const size_t& unStarting = 0)
{
return FindPropetyTemplate<char>(sString, sProperty, arDelimiters, arEndings, unStarting, unEndPosition);
return FindPropetyTemplate<char>(sString, sProperty, arDelimiters, arEndings, unStarting);
}
std::wstring FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector<std::wstring>& arDelimiters, const std::vector<std::wstring>& arEndings, const size_t& unStarting, size_t& unEndPosition)
TFoundedData<wchar_t> FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector<std::wstring>& arDelimiters, const std::vector<std::wstring>& arEndings, const size_t& unStarting = 0)
{
return FindPropetyTemplate<wchar_t>(wsString, wsProperty, arDelimiters, arEndings, unStarting, unEndPosition);
return FindPropetyTemplate<wchar_t>(wsString, wsProperty, arDelimiters, arEndings, unStarting);
}
std::string FindPropety(const std::string& sString, const std::string& sProperty, const std::vector<std::string>& arDelimiters, const std::vector<std::string>& arEndings, const size_t& unStarting = 0)
template<class CharType, class StringType = std::basic_string<CharType, std::char_traits<CharType>, std::allocator<CharType>>>
bool RemoveEmptyTagTemplate(StringType& sValue, const StringType& sTagName, size_t unStart)
{
size_t unEndPosition = 0;
return FindPropetyTemplate<char>(sString, sProperty, arDelimiters, arEndings, unStarting, unEndPosition);
boost::wregex oRegex(L"<\\s*(?i)" + std::wstring(sTagName.begin(), sTagName.end()) + L"\\s*[^>]*/>");
boost::match_results<typename StringType::const_iterator> oResult;
if (unStart >= sValue.length() || !boost::regex_search(sValue.cbegin() + unStart, sValue.cend(), oResult, oRegex))
return false;
sValue.erase(unStart + oResult.position(), oResult.length());
return true;
}
std::wstring FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector<std::wstring>& arDelimiters, const std::vector<std::wstring>& arEndings, const size_t& unStarting = 0)
bool RemoveEmptyTag(std::string& sValue, const std::string& sTagName, size_t unStart = 0)
{
size_t unEndPosition = 0;
return FindPropetyTemplate<wchar_t>(wsString, wsProperty, arDelimiters, arEndings, unStarting, unEndPosition);
return RemoveEmptyTagTemplate<char>(sValue, sTagName, unStart);
}
bool RemoveEmptyTag(std::wstring& sValue, const std::wstring& sTagName, size_t unStart = 0)
{
return RemoveEmptyTagTemplate<wchar_t>(sValue, sTagName, unStart);
}
template <typename StringType, typename StringEndgeType>

View File

@ -41,6 +41,8 @@ namespace VBA
bool DirStreamObject::loadContent()
{
if (!reader) return false;
InformationRecord = boost::make_shared<PROJECTINFORMATION>(reader);
ReferencesRecord = boost::make_shared<PROJECTREFERENCES>(reader);
ModulesRecord = boost::make_shared<PROJECTMODULES>(reader);
@ -50,12 +52,16 @@ bool DirStreamObject::loadContent()
bool ModuleStreamObject::loadContent()
{
SourceCode = convert_string_icu((char*)reader->getData(), (unsigned int)reader->getDataSize(), reader->CodePage);
if (!reader) return false;
SourceCode = convert_string_icu((char*)reader->getData(), (unsigned int)reader->getDataSize(), reader->CodePage);
return true;
}
bool ProjectStreamObject::loadContent()
{
if (!reader) return false;
std::string strProps((char*)reader->getData(), reader->getDataSize());
std::vector<std::string> arrProps;
@ -72,6 +78,8 @@ bool ProjectStreamObject::loadContent()
}
bool VBFrameObject::loadContent()
{
if (!reader) return false;
std::wstring strProps = convert_string_icu((char*)reader->getData(), (unsigned int)reader->getDataSize(), reader->CodePage);
std::vector<std::wstring> arrProps;
@ -94,6 +102,8 @@ bool VBFrameObject::loadContent()
bool FormControlStream::loadContent()
{
if (!reader) return false;
unsigned char MinorVersion, MajorVersion;
_UINT16 cbForm;

View File

@ -171,7 +171,8 @@ bool OleObject::processPackageStream(const std::wstring& packageStream)
POLE::Stream* pPackageStream = new POLE::Stream(oleStorage, packageStream);
if ((pPackageStream) && (false == pPackageStream->fail()))
{
{
// AVS_OFFICESTUDIO_FILE_OTHER_PACKAGE_IN_OLE
VirtualStreamReader reader(pPackageStream, 0, false);
size_t sz = reader.GetSize();

View File

@ -83,32 +83,48 @@ namespace DocFileFormat
if (_ctx->_doc->FIB->m_FibBase.fWriteReservation)
{
m_oXmlWriter.WriteNodeBegin( L"w:writeProtection", TRUE );
WideString* passw = static_cast<WideString*>(_ctx->_doc->AssocNames->operator[]( 17 ));
CRYPT::_ecmaWriteProtectData data;
WideString* passw = static_cast<WideString*>(_ctx->_doc->AssocNames->operator[]( 17 ));
if (passw && false == passw->empty())
{
CRYPT::_ecmaWriteProtectData data;
CRYPT::ECMAWriteProtect protect;
protect.SetCryptData(data);
protect.SetPassword(*passw);
protect.Generate();
protect.GetCryptData(data);
}
m_oXmlWriter.WriteNodeBegin(L"w:writeProtection", TRUE);
if (false == data.saltValue.empty())
{
//m_oXmlWriter.WriteAttribute ( L"w:cryptProviderType", L"rsaAES");
//m_oXmlWriter.WriteAttribute ( L"w:cryptAlgorithmSid", 14); //sha-512
//m_oXmlWriter.WriteAttribute ( L"w:cryptAlgorithmType", L"typeAny");
//m_oXmlWriter.WriteAttribute ( L"w:cryptAlgorithmClass", L"hash");
//m_oXmlWriter.WriteAttribute ( L"w:cryptSpinCount", data.spinCount);
//m_oXmlWriter.WriteAttribute ( L"w:hash", EncodeBase64(data.hashValue));
//m_oXmlWriter.WriteAttribute ( L"w:salt", EncodeBase64(data.saltValue));
m_oXmlWriter.WriteAttribute ( L"w:algorithmName", L"SHA-512");
m_oXmlWriter.WriteAttribute ( L"w:spinCount", data.spinCount);
m_oXmlWriter.WriteAttribute ( L"w:hashValue", EncodeBase64(data.hashValue));
m_oXmlWriter.WriteAttribute ( L"w:saltValue", EncodeBase64(data.saltValue));
m_oXmlWriter.WriteAttribute ( L"w:saltValue", EncodeBase64(data.saltValue));
}
m_oXmlWriter.WriteNodeEnd( L"", TRUE, TRUE );
if (false == data.saltValue.empty())
{
m_oXmlWriter.WriteNodeBegin(L"w:documentProtection", TRUE);
m_oXmlWriter.WriteAttribute(L"w:edit", L"readOnly");
m_oXmlWriter.WriteAttribute(L"w:enforcement", L"1");
m_oXmlWriter.WriteAttribute(L"w:cryptProviderType", L"rsaAES");
m_oXmlWriter.WriteAttribute(L"w:cryptAlgorithmClass", L"hash");
m_oXmlWriter.WriteAttribute(L"w:cryptAlgorithmType", L"typeAny");
m_oXmlWriter.WriteAttribute(L"w:cryptAlgorithmSid", 14); //sha-512
m_oXmlWriter.WriteAttribute(L"w:cryptSpinCount", data.spinCount);
m_oXmlWriter.WriteAttribute(L"w:spinCount", data.spinCount);
m_oXmlWriter.WriteAttribute(L"w:hash", EncodeBase64(data.hashValue));
m_oXmlWriter.WriteAttribute(L"w:salt", EncodeBase64(data.saltValue));
m_oXmlWriter.WriteNodeEnd(L"", TRUE, TRUE);
}
}
//zoom
m_oXmlWriter.WriteNodeBegin ( L"w:zoom", TRUE );

View File

@ -109,7 +109,7 @@ bool COfficePPTFile::CloseFile()
PPT::CPPTFileReader* r = (PPT::CPPTFileReader*)m_pReader; RELEASEOBJECT(r);
m_pReader = NULL;
return S_OK;
return true;
}
_UINT32 COfficePPTFile::LoadFromFile(std::wstring sSrcFileName, std::wstring sDstPath, std::wstring password, bool &bMacros)

View File

@ -178,11 +178,16 @@ std::wstring CMediaManager::GenerateMedia(const std::wstring& strInput, const st
if (strExts == L".video" || strExts == L".audio")
{
std::wstring strInput1 = strInput.substr(0, nIndexExt);
nIndexExt = strInput1.rfind(wchar_t('.'));
strExts = nIndexExt < 0 ? L"" : strInput1.substr(nIndexExt);
strExts.clear();
}
if (strExts == L".tmp" || strExts.empty()) strExts = strDefaultExt;
if (strDefaultExt == L"sfil")
{
strExts = L".wav";
//todooo - detect format by file
}
std::wstring strMediaName = Template + std::to_wstring(++Indexer);
std::wstring strOutput = m_strDstMedia + strMediaName + strExts;

View File

@ -243,7 +243,15 @@ bool ProtoTable::fillCells(std::vector<CElementPtr> &arrCells)
if (top == m_arrTop[posRow]) break;
for (; posCol < countCol; posCol++)
if (left == m_arrLeft[posCol]) break;
TCell* pParent = &m_table[posRow][posCol];
TCell* pParent = NULL;
if (posRow < m_table.size())
{
if (posCol < m_table[posRow].size())
{
pParent = &m_table[posRow][posCol];
}
}
UINT posRightCol = 0, posBottomRow = 0;
for (; posBottomRow < countRow; posBottomRow++)
@ -263,9 +271,11 @@ bool ProtoTable::fillCells(std::vector<CElementPtr> &arrCells)
if (posRow == cRow)
tCell.setRowSpan(posBottomRow - cRow);
}
pParent->setPParent(nullptr);
pParent->setPShape(ptrCell);
if (pParent)
{
pParent->setPParent(nullptr);
pParent->setPShape(ptrCell);
}
// pParent->setGridSpan(posRightCol - posCol);
// pParent->setRowSpan(posBottomRow - posRow);
}
@ -562,7 +572,7 @@ bool TCell::isRealCell() const
return true;
}
void TCell::FillTxBody(PPTX::Logic::TxBody &oTxBody, CTextCFRun* pLastCF)
void TCell::FillTxBody(PPTX::Logic::TxBody& oTxBody, CTextCFRun* pLastCF)
{
TxBodyConverter txBodyConverter(m_ptrSpElCell, m_pRels, pLastCF);
txBodyConverter.FillTxBody(oTxBody);
@ -570,6 +580,8 @@ void TCell::FillTxBody(PPTX::Logic::TxBody &oTxBody, CTextCFRun* pLastCF)
void TCell::FillTcPr(PPTX::Logic::TableCellProperties &oTcPr)
{
if (!m_ptrSpElCell) return;
auto pShapeEl = static_cast<CShapeElement*>(m_ptrSpElCell.get());
auto pShape = pShapeEl->m_pShape;
//anchor

View File

@ -144,6 +144,8 @@ bool CPPTDocumentInfo::LoadDocument()
{
m_arUsers[0]->ReadExtenalObjects(); // todooo ???? прочитать по всем (см 66864)
m_arUsers[0]->FromDocument();
m_bMacroEnabled = m_arUsers[0]->m_bMacroEnabled;
}
catch(int) //error code
{

View File

@ -229,8 +229,9 @@ void CPPTElement::SetUpProperties(CElementPtr pElement, CTheme* pTheme, CSlideIn
{
if (reset_default)
{
pElement->m_oBrush.Type = c_BrushTypeTexture; // or 3000 set ???
pElement->m_bIsFilled = false;
pElement->m_bLine = false;
pElement->m_oBrush.Type = c_BrushTypeTexture; // or 3000 set ???
}
for (size_t i = 0; i < lCount; ++i)
{
@ -249,6 +250,7 @@ void CPPTElement::SetUpProperties(CElementPtr pElement, CTheme* pTheme, CSlideIn
{
if (reset_default)
{
pElement->m_bIsFilled = false;
pElement->m_bLine = false;
}
for (size_t i = 0; i < lCount; ++i)

View File

@ -37,7 +37,7 @@
namespace XLS
{
char CFRecord::intData[MAX_RECORD_SIZE];
char CFRecord::intData[MAX_RECORD_SIZE_XLSB];
// Create a record and read its data from the stream
CFRecord::CFRecord(CFStreamPtr stream, GlobalWorkbookInfoPtr global_info)
@ -262,6 +262,10 @@ const BYTE CFRecord::getSizeOfRecordTypeRecordLength() const
const size_t CFRecord::getMaxRecordSize() const
{
if(global_info_ && (global_info_.get()->Version == 0x0800))
{
return MAX_RECORD_SIZE_XLSB;
}
return MAX_RECORD_SIZE;
}
@ -302,6 +306,11 @@ void CFRecord::appendRawDataToStatic(const unsigned char *raw_data, const size_t
memcpy(&intData[rdPtr], raw_data, size);
rdPtr += size;
}
else if(global_info_ && (global_info_.get()->Version == 0x0800) && (MAX_RECORD_SIZE_XLSB - rdPtr > size))
{
memcpy(&intData[rdPtr], raw_data, size);
rdPtr += size;
}
}
void CFRecord::appendRawDataToStatic(const wchar_t *raw_data, const size_t size)
@ -311,6 +320,11 @@ void CFRecord::appendRawDataToStatic(const wchar_t *raw_data, const size_t size)
for(int i = 0; i < size; ++i)
storeAnyData(raw_data[i]);
}
else if(global_info_ && (global_info_.get()->Version == 0x0800) && (MAX_RECORD_SIZE_XLSB - rdPtr > size))
{
for(int i = 0; i < size; ++i)
storeAnyData(raw_data[i]);
}
}
@ -387,6 +401,8 @@ const bool CFRecord::checkFitReadSafe(const size_t size) const
const bool CFRecord::checkFitWriteSafe(const size_t size) const
{
if(global_info_ && (global_info_.get()->Version == 0x0800))
return (rdPtr + size <= MAX_RECORD_SIZE_XLSB);
return (rdPtr + size <= MAX_RECORD_SIZE);
}
@ -432,6 +448,12 @@ void CFRecord::reserveNunBytes(const size_t n)
if (rdPtr + n < MAX_RECORD_SIZE)
for (size_t i = 0; i < n; ++i)
intData[rdPtr++] = 0;
else if(global_info_ && (global_info_.get()->Version == 0x0800) && (rdPtr + n < MAX_RECORD_SIZE_XLSB))
{
for (size_t i = 0; i < n; ++i)
intData[rdPtr++] = 0;
}
}

View File

@ -131,6 +131,12 @@ public:
rdPtr += sizeof(T);
return true;
}
else if(global_info_ && (global_info_.get()->Version == 0x0800) && (rdPtr + sizeof(T) < MAX_RECORD_SIZE_XLSB))
{
memcpy(&intData[rdPtr], &val, sizeof(T));
rdPtr += sizeof(T);
return true;
}
return false;
}
@ -161,7 +167,8 @@ public:
CFRecord& operator << (bool& val);
private:
static const size_t MAX_RECORD_SIZE = 8224;
static const size_t MAX_RECORD_SIZE = 8224;
static const size_t MAX_RECORD_SIZE_XLSB = 0xFFFFFFF;
CFStream::ReceiverItems receiver_items;
CFStream::SourceItems source_items;
@ -172,7 +179,7 @@ private:
char* data_;
BYTE sizeOfRecordTypeRecordLength; //размер RecordType и RecordLength
size_t rdPtr;
static char intData[MAX_RECORD_SIZE];
static char intData[MAX_RECORD_SIZE_XLSB];
GlobalWorkbookInfoPtr global_info_;
};

View File

@ -74,6 +74,8 @@ void BOF::readFields(CFRecord& record)
if (type_id_ == rt_BOF_BIFF8)
{
if (vers > 0x0700) vers = 0x0600;
record >> rupBuild >> rupYear; // biff 5 - 8
if ( record.checkFitReadSafe(8)) // biff 8

View File

@ -70,5 +70,31 @@ void FileSharing::readFields(CFRecord& record)
}
}
void FileSharing::writeFields(CFRecord& record)
{
if(record.getGlobalWorkbookInfo()->Version == 0x0800)
{
auto readOnlyrec = fReadOnlyRec.value();
if(readOnlyrec.is_initialized() &&(readOnlyrec.get() == 1 || readOnlyrec.get() == 0))
record << fReadOnlyRec;
else
{
_UINT16 defaulTRec = 0;
record << defaulTRec;
}
if(!wResPass.empty())
{
try
{
wResPassNum = std::stoi(wResPass, nullptr, 16);
}
catch(const std::exception&)
{
wResPassNum = 0;
}
}
record << wResPassNum << stUserName;
}
}
} // namespace XLS

View File

@ -51,6 +51,7 @@ public:
BaseObjectPtr clone();
void readFields(CFRecord& record);
void writeFields(CFRecord& record) override;
static const ElementType type = typeFileSharing;

View File

@ -57,7 +57,7 @@ void Label::readFields(CFRecord& record)
record >> cell;
if (global_info_->Version == 0x0200)
if (global_info_->Version == 0x0200 || global_info_->Version == 0x0400)
{
ShortXLAnsiString name;
record >> name;

View File

@ -94,7 +94,7 @@ int Number::serialize(std::wostream & stream)
return 0;
}
//---------------------------------------------------------------------------------
Integer_BIFF2::Integer_BIFF2()
Integer_BIFF2::Integer_BIFF2() : num(0)
{}
Integer_BIFF2::~Integer_BIFF2()
{}
@ -106,7 +106,18 @@ void Integer_BIFF2::readFields(CFRecord& record)
{
global_info_ = record.getGlobalWorkbookInfo();
record >> cell >> num;
record >> cell;
if (record.getRdPtr() + 2 < record.getDataSize())
{
record >> num;
}
else
{
_INT16 num_2byte = 0;
record >> num_2byte;
num = num_2byte;
}
}
const CellRef Integer_BIFF2::getLocation() const
{

View File

@ -69,7 +69,7 @@ void Pane::readFields(CFRecord& record)
else
{
record >> xnumXSplit >> xnumYSplit >> rwTop >> colLeft >> pnnAcct_xlsb;
topLeftCell = static_cast<std::wstring >(CellRef(rwTop, colLeft, true, true));
topLeftCell = CellRef(rwTop, colLeft, true, true).toString(true);
unsigned char flags;
record >> flags;

View File

@ -80,12 +80,12 @@ void Selection::readFields(CFRecord& record)
{
XLSB::UncheckedSqRfX sqrfx;
record >> pnn_xlsb >> rwAct >> colAct >> irefAct >> sqrfx;
activeCell = static_cast<std::wstring >(CellRef(rwAct, colAct, true, true));
activeCell = CellRef(rwAct, colAct, true, true).toString(true);
std::wstring sqref_str;
int i = 0, cref = sqrfx.rgrfx.size();
std::for_each(sqrfx.rgrfx.begin(), sqrfx.rgrfx.end(), [&](XLSB::UncheckedRfX &refu) {
sqref_str += std::wstring (refu.toString(false).c_str()) + ((i == cref - 1) ? L"" : L" ");
sqref_str += std::wstring (refu.toString(false, true).c_str()) + ((i == cref - 1) ? L"" : L" ");
});
sqref = sqref_str;

View File

@ -152,7 +152,7 @@ void Window2::readFields(CFRecord& record)
record >> xlView >> rwTop >> colLeft;
topLeftCell = static_cast<std::wstring >(CellRef(rwTop, colLeft, true, true));
topLeftCell = CellRef(rwTop, colLeft, true, true).toString(true);
BYTE icvHdr_1b;
record >> icvHdr_1b;

View File

@ -59,7 +59,8 @@ void Cell::load(CFRecord& record)
{
record >> rw >> col;
if (record.getGlobalWorkbookInfo()->Version == 0x0200)
if (record.getGlobalWorkbookInfo()->Version == 0x0200 ||
record.getGlobalWorkbookInfo()->Version == 0x0400)
{
unsigned char flags1, flags2, flags3;

View File

@ -100,7 +100,7 @@ const std::wstring CellRef::toString(const bool xlsb) const
{
column_norm = maxCol;
}
return to_string_cache = AUX::loc2str(row_norm, rowRelative, column_norm, colRelative);
return to_string_cache = AUX::loc2str(row_norm, rowRelative, column_norm, colRelative, xlsb);
}
return to_string_cache;

View File

@ -93,7 +93,7 @@ void DVParsedFormula::save(CFRecord& record, bool bSave)
else
{
cce = 0;
auto cb = 0;
_UINT32 cb = 0;
record << cce << cb;
}
}

View File

@ -69,48 +69,52 @@ void DXFFntD::load(CFRecord& record)
record >> ich >> cch >> iFnt;
}
int DXFFntD::serialize(std::wostream & stream)
int DXFFntD::serialize(std::wostream & stream, bool extOnly)
{
std::map<ExtProp::_type, ExtProp>::iterator pFind;
if (parent && parent->xfext)
pFind = parent->xfext->mapRgExt.find(ExtProp::FontScheme);
CP_XML_WRITER(stream)
{
CP_XML_NODE(L"font")
{
if (!stFontName.value().empty())
{
std::wstring name = stFontName.value();
if (parent->xfext)
pFind = parent->xfext->mapRgExt.find(ExtProp::FontScheme);
BYTE font_scheme = (parent->xfext && pFind != parent->xfext->mapRgExt.end()) ? pFind->second.extPropData.font_scheme : 0;
{
std::wstring name = stFontName.value();
if (global_info->m_pTheme && font_scheme == 0x01)
if (parent && parent->xfext)
{
BYTE font_scheme = (pFind != parent->xfext->mapRgExt.end()) ? pFind->second.extPropData.font_scheme : 0;
if (global_info && global_info->m_pTheme && font_scheme == 0x01)
{
name = global_info->m_pTheme->themeElements.fontScheme.majorFont.latin.typeface;
}
else if (global_info->m_pTheme && font_scheme == 0x02)
else if (global_info && global_info->m_pTheme && font_scheme == 0x02)
{
name = global_info->m_pTheme->themeElements.fontScheme.minorFont.latin.typeface;
}
}
if (!name.empty())
{
CP_XML_NODE(L"name")
{
CP_XML_ATTR(L"val", name.substr(0, 31));
}
}
if (stxp.twpHeight > 20)
if (!extOnly && stxp.twpHeight > 20)
{
CP_XML_NODE(L"sz")
{
CP_XML_ATTR(L"val", stxp.twpHeight/20.f);
}
}
if (parent->xfext)
if ((parent && parent->xfext) && (pFind == parent->xfext->mapRgExt.end()))
pFind = parent->xfext->mapRgExt.find(ExtProp::ForeColor);
if (parent->xfext && pFind != parent->xfext->mapRgExt.end())
if ((parent && parent->xfext) && pFind != parent->xfext->mapRgExt.end())
{
pFind->second.extPropData.color.serialize(CP_XML_STREAM(), L"color");
}
@ -121,68 +125,71 @@ int DXFFntD::serialize(std::wostream & stream)
CP_XML_ATTR(L"indexed", icvFore);
}
}
CP_XML_NODE(L"charset")
{
CP_XML_ATTR(L"val", stxp.bCharSet);
}
//CP_XML_NODE(L"condense")
//{
// CP_XML_ATTR(L"val", 1);
//}
//CP_XML_NODE(L"extend")
//{
// CP_XML_ATTR(L"val", stxp.fExtend);
//}
CP_XML_NODE(L"family")
if (!extOnly)
{
CP_XML_ATTR(L"val", stxp.bFamily);
}
if (tsNinch.ftsItalic == 0)
{
CP_XML_NODE(L"i")
CP_XML_NODE(L"charset")
{
CP_XML_ATTR(L"val", stxp.ts.ftsItalic);
CP_XML_ATTR(L"val", stxp.bCharSet);
}
}
if (fBlsNinch == 0)
{
CP_XML_NODE(L"b")
//CP_XML_NODE(L"condense")
//{
// CP_XML_ATTR(L"val", 1);
//}
//CP_XML_NODE(L"extend")
//{
// CP_XML_ATTR(L"val", stxp.fExtend);
//}
CP_XML_NODE(L"family")
{
CP_XML_ATTR(L"val", stxp.bls == 700 ? 1 : 0);
}
}
if (tsNinch.ftsStrikeout == 0)
{
CP_XML_NODE(L"strike")
CP_XML_ATTR(L"val", stxp.bFamily);
}
if (tsNinch.ftsItalic == 0)
{
CP_XML_ATTR(L"val", stxp.ts.ftsStrikeout);
}
}
if (fUlsNinch == 0)
{
CP_XML_NODE(L"u")
{
switch(stxp.uls)
CP_XML_NODE(L"i")
{
CP_XML_ATTR(L"val", stxp.ts.ftsItalic);
}
}
if (fBlsNinch == 0)
{
CP_XML_NODE(L"b")
{
CP_XML_ATTR(L"val", stxp.bls == 700 ? 1 : 0);
}
}
if (tsNinch.ftsStrikeout == 0)
{
CP_XML_NODE(L"strike")
{
CP_XML_ATTR(L"val", stxp.ts.ftsStrikeout);
}
}
if (fUlsNinch == 0)
{
CP_XML_NODE(L"u")
{
switch (stxp.uls)
{
case 0: CP_XML_ATTR(L"val", L"none"); break;
case 1: CP_XML_ATTR(L"val", L"single"); break;
case 2: CP_XML_ATTR(L"val", L"double"); break;
case 33: CP_XML_ATTR(L"val", L"singleAccounting");break;
case 34: CP_XML_ATTR(L"val", L"doubleAccounting");break;
case 33: CP_XML_ATTR(L"val", L"singleAccounting"); break;
case 34: CP_XML_ATTR(L"val", L"doubleAccounting"); break;
}
}
}
}
if (fSssNinch == 0)
{
CP_XML_NODE(L"vertAlign")
if (fSssNinch == 0)
{
switch(stxp.sss)
CP_XML_NODE(L"vertAlign")
{
switch (stxp.sss)
{
case 0: CP_XML_ATTR(L"val", L"baseline"); break;
case 1: CP_XML_ATTR(L"val", L"superscript");break;
case 1: CP_XML_ATTR(L"val", L"superscript"); break;
case 2: CP_XML_ATTR(L"val", L"subscript"); break;
}
}
}
}
}

View File

@ -50,26 +50,25 @@ class DXFFntD : public BiffStructure
public:
BiffStructurePtr clone();
static const ElementType type = typeDXFFntD;
static const ElementType type = typeDXFFntD;
virtual void load(CFRecord& record);
int serialize(std::wostream & stream);
int serialize(std::wostream & stream, bool extOnly = false);
XLUnicodeStringNoCch stFontName;
Stxp stxp;
_INT32 icvFore;
_INT32 icvFore = 0;
Ts tsNinch;
_UINT32 fSssNinch;
_UINT32 fUlsNinch;
_UINT32 fBlsNinch;
_INT32 ich;
_INT32 cch;
_UINT16 iFnt;
_UINT32 fSssNinch = 0;
_UINT32 fUlsNinch = 0;
_UINT32 fBlsNinch = 0;
_INT32 ich = 0;
_INT32 cch = 0;
_UINT16 iFnt = 0;
//------------------------------------------------
GlobalWorkbookInfoPtr global_info;

View File

@ -122,9 +122,9 @@ int DXFN::serialize(std::wostream & stream)
{
CP_XML_NODE(L"dxf")
{
if(ibitAtrFnt)
if (ibitAtrFnt || (xfext && (xfext->mapRgExt.end() != xfext->mapRgExt.find(ExtProp::FontScheme))))
{
dxffntd.serialize(CP_XML_STREAM());
dxffntd.serialize(CP_XML_STREAM(), ibitAtrFnt == false);
}
if(ibitAtrNum)
{

View File

@ -48,7 +48,7 @@ public:
virtual void load(CFRecord& record);
static const ElementType type = typeExtProp;
static const ElementType type = typeExtProp;
unsigned short cb;
@ -72,8 +72,8 @@ public:
{
FullColorExt color;
XFExtGradient gradient_fill;
unsigned char font_scheme;
unsigned short indent_level;
unsigned char font_scheme = 0;
unsigned short indent_level = 0;
} extPropData;
};

View File

@ -521,15 +521,15 @@ Ftab_Cetab::ValuesDetermination::ValuesDetermination()
params_fixed.insert(ParamsFixed(0x01D6, 4, L"ACCRINTM"));
params_fixed.insert(ParamsFixed(0x01D7, 2, L"WORKDAY"));
params_fixed.insert(ParamsFixed(0x01D8, 2, L"NETWORKDAYS"));
params_fixed.insert(ParamsFixed(0x01D9, 1, L"GCD"));
params_fixed.insert(ParamsFixed(0x01D9, -1, L"GCD"));
params_fixed.insert(ParamsFixed(0x01DA, 1, L"MULTINOMIAL"));
params_fixed.insert(ParamsFixed(0x01DB, 1, L"LCM"));
params_fixed.insert(ParamsFixed(0x01DB, -1, L"LCM"));
params_fixed.insert(ParamsFixed(0x01DC, 2, L"FVSCHEDULE"));
params_fixed.insert(ParamsFixed(0x01DD, 3, L"CUBEKPIMEMBER"));
params_fixed.insert(ParamsFixed(0x01DE, 1, L"CUBESET"));
params_fixed.insert(ParamsFixed(0x01DF, 1, L"CUBESETCOUNT"));
params_fixed.insert(ParamsFixed(0x01E0, 2, L"IFERROR"));
params_fixed.insert(ParamsFixed(0x01E1, 2, L"COUNTIFS"));
params_fixed.insert(ParamsFixed(0x01E1, -1, L"COUNTIFS"));
params_fixed.insert(ParamsFixed(0x01E2, 3, L"SUMIFS"));
params_fixed.insert(ParamsFixed(0x01E3, 2, L"AVERAGEIF"));
params_fixed.insert(ParamsFixed(0x01E4, 3, L"AVERAGEIFS"));

View File

@ -62,8 +62,14 @@ int FullColorExt::serialize(std::wostream & stream, const std::wstring &node_nam
case 0: CP_XML_ATTR(L"auto", 1); break;
case 1: CP_XML_ATTR(L"indexed", xclrValue); break;
case 3: CP_XML_ATTR(L"theme", xclrValue); break;
default:
CP_XML_ATTR(L"rgb", xclrValue); break;
default:
{
BYTE r = GETBITS(xclrValue, 0, 7);
BYTE g = GETBITS(xclrValue, 8, 15);
BYTE b = GETBITS(xclrValue, 16, 23);
BYTE a = GETBITS(xclrValue, 24, 31);
CP_XML_ATTR(L"rgb", STR::toARGB(r, g, b, a));
}break;
}
if (nTintShade != 0)
{

View File

@ -49,11 +49,11 @@ public:
virtual void load(CFRecord& record);
int serialize(std::wostream & stream, const std::wstring &sNode);
static const ElementType type = typeFullColorExt;
static const ElementType type = typeFullColorExt;
unsigned short xclrType;
short nTintShade;
_UINT32 xclrValue;
unsigned short xclrType = 0;
short nTintShade = 0;
_UINT32 xclrValue = 0;
};
} // namespace XLS

View File

@ -106,68 +106,68 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
switch (rc_header.recType)
{
case OfficeArtRecord::BlipEMF:
{
pict_type = L".emf";
if (rc_header.recInstance == 0x3D4)
rgbUid1 = ReadMD4Digest(record);
else
{
pict_type = L".emf";
if (rc_header.recInstance == 0x3D4)
rgbUid1 = ReadMD4Digest(record);
else
{
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
break;
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
}
break;
case OfficeArtRecord::BlipWMF:
{
pict_type = L".wmf";
if (rc_header.recInstance == 0x216)
rgbUid1 = ReadMD4Digest(record);
else
{
pict_type = L".wmf";
if (rc_header.recInstance == 0x216)
rgbUid1 = ReadMD4Digest(record);
else
{
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
break;
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
}
break;
case OfficeArtRecord::BlipPICT:
{
pict_type = L".pcz";
if (rc_header.recInstance == 0x542)
rgbUid1 = ReadMD4Digest(record);
else
{
pict_type = L".pcz";
if (rc_header.recInstance == 0x542)
rgbUid1 = ReadMD4Digest(record);
else
{
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
rgbUid1 = ReadMD4Digest(record);
rgbUid2 = ReadMD4Digest(record);
}
break;
OfficeArtMetafileHeader metafileHeader;
record >> metafileHeader;
if (metafileHeader.compression == 0)
{
isCompressed = true;
readCompressedData(record, metafileHeader);
}
}
break;
case OfficeArtRecord::BlipJPEG:
pict_type = L".jpeg";
if ((rc_header.recInstance == 0x46A) || (rc_header.recInstance == 0x6E2))
@ -232,7 +232,12 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
record.RollRdPtrBack(32);
}
break;
default:
case 0xf018:
{
record.skipNunBytes(rc_header.recLen);
return;
}break;
default: //0xf007
record.RollRdPtrBack(rc_header.size());
return;
}

View File

@ -55,7 +55,7 @@ void PtgArray::loadFields(CFRecord& record)
if (record.getGlobalWorkbookInfo()->Version < 0x0800)
record.skipNunBytes(7); // unused
else
record.skipNunBytes(16); // unused
record.skipNunBytes(14); // unused
}
void PtgArray::writeFields(CFRecord& record)
@ -63,7 +63,7 @@ void PtgArray::writeFields(CFRecord& record)
if (record.getGlobalWorkbookInfo()->Version < 0x0800)
record.reserveNunBytes(7); // unused
else
record.reserveNunBytes(16); // unused
record.reserveNunBytes(14); // unused
}
void PtgArray::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref)

View File

@ -99,7 +99,9 @@ void PtgExtraArray::save(CFRecord& record)
}
else
{
record << cols << rows;
cols++;
rows++;
record << rows << cols;
}
for (auto& item : array_)
{

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