mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Compare commits
70 Commits
v5.5.0.138
...
v5.6.0.11
| Author | SHA1 | Date | |
|---|---|---|---|
| ce397b13f6 | |||
| d197c0da15 | |||
| 0e7a8c1af9 | |||
| a52bcb3205 | |||
| b57bf58068 | |||
| 7be6410a13 | |||
| 1ef73f12a4 | |||
| 9706ca50d5 | |||
| 7fba804f17 | |||
| d4f9eecbba | |||
| 245dfe198a | |||
| d49bed47b6 | |||
| b95065fd70 | |||
| 961bde6723 | |||
| 2261de2884 | |||
| 7bc4ab9655 | |||
| 5e6d2f12d5 | |||
| fb7d20c7e0 | |||
| ba518d7c85 | |||
| a045f57430 | |||
| b10274c65d | |||
| c1e4a2ce33 | |||
| ee091e7ca9 | |||
| 3d814e7b40 | |||
| bb65549dc1 | |||
| 5294089fd0 | |||
| 3ec24e5e39 | |||
| dc44dc5e84 | |||
| cf76de8811 | |||
| 86421d8235 | |||
| 5e77e96e5f | |||
| 973b89609d | |||
| a0c0171d12 | |||
| d5c5c4b8cf | |||
| 60904a6df0 | |||
| 72315d1229 | |||
| abb5fd1ec1 | |||
| fd6beb0044 | |||
| 1b6eff5cb7 | |||
| 4fc6511b37 | |||
| 52ff8af2be | |||
| d29475b6fb | |||
| 32e7193212 | |||
| 23fc146eca | |||
| 7fd9e52bc3 | |||
| dd13f9f24c | |||
| 0fe3c3ece5 | |||
| 5d148a6d0d | |||
| d7af2cb41d | |||
| ed5bfb7b27 | |||
| b81e988da5 | |||
| a7c868d3d1 | |||
| bb022c49bd | |||
| 31e8a1cbdd | |||
| a19074993d | |||
| 0a1c718cc0 | |||
| fb5da5e4ff | |||
| 61a157a3c4 | |||
| a7ba4c471e | |||
| 8c18843b58 | |||
| 04d796d760 | |||
| 12c427b11e | |||
| 9415983797 | |||
| e82ea1bc5c | |||
| 49f4bdb933 | |||
| a577378a1e | |||
| 997bf0b887 | |||
| 51c1b7d21a | |||
| 4b0ce196e8 | |||
| 93108c244a |
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,6 +11,8 @@ Common/3dParty/icu/win_32
|
||||
Common/3dParty/icu/linux_64
|
||||
Common/3dParty/icu/linux_32
|
||||
Common/3dParty/icu/mac_64
|
||||
Common/3dParty/icu/ios
|
||||
Common/3dParty/icu/mac-build
|
||||
Common/3dParty/cef/win_64
|
||||
Common/3dParty/cef/win_32
|
||||
Common/3dParty/cef/linux_64
|
||||
|
||||
@ -100,6 +100,7 @@ public:
|
||||
bSectionType = false;
|
||||
bPageNumStart = false;
|
||||
bRtlGutter = false;
|
||||
bGutter = false;
|
||||
}
|
||||
std::wstring Write()
|
||||
{
|
||||
@ -730,10 +731,12 @@ public:
|
||||
{
|
||||
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSize) + L"\"/>");
|
||||
}
|
||||
if(bFontSizeCs)
|
||||
{
|
||||
if(bFontSizeCs)
|
||||
{
|
||||
if(false == bFontSize)
|
||||
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
|
||||
pCStringWriter->WriteString(L"<w:szCs w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
|
||||
}
|
||||
}
|
||||
if(bHighLight)
|
||||
{
|
||||
docRGB& H = HighLight;
|
||||
|
||||
@ -7622,7 +7622,9 @@ void BinaryCommentsTableWriter::WriteComment(CCommentWriteTemp& oComment)
|
||||
}
|
||||
else
|
||||
{
|
||||
nDurableId = XmlUtils::GenerateInt();
|
||||
//numbers greater than 0x7FFFFFFE cause MS Office errors(ST_LongHexNumber by spec)
|
||||
nDurableId = XmlUtils::GenerateInt() & 0x7FFFFFFF;
|
||||
nDurableId = (0x7FFFFFFF != nDurableId) ? nDurableId : nDurableId - 1;
|
||||
}
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_CommentsType::DurableId);
|
||||
m_oBcw.m_oStream.WriteULONG(nDurableId);
|
||||
|
||||
@ -1254,6 +1254,14 @@
|
||||
<File
|
||||
RelativePath="..\src\odf\chart_build_oox.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/bigobj"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
@ -1302,6 +1310,14 @@
|
||||
<File
|
||||
RelativePath="..\src\odf\draw_frame_docx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/bigobj"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
@ -1314,6 +1330,14 @@
|
||||
<File
|
||||
RelativePath="..\src\odf\draw_frame_pptx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/bigobj"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
@ -1326,6 +1350,14 @@
|
||||
<File
|
||||
RelativePath="..\src\odf\draw_frame_xlsx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/bigobj"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
|
||||
@ -350,9 +350,10 @@ namespace PPTX
|
||||
{
|
||||
nvGraphicFramePr.toXmlWriter(pWriter);
|
||||
|
||||
if (xfrm.IsInit() && pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX)
|
||||
if (xfrm.IsInit() && (pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX || pWriter->m_lGroupIndex >= 0))
|
||||
{
|
||||
if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_XLSX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"xdr";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"wpg";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_GRAPHICS) xfrm->m_ns = L"a";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_CHART_DRAWING) xfrm->m_ns = L"cdr";
|
||||
|
||||
|
||||
@ -43,7 +43,12 @@ namespace PPTX
|
||||
{
|
||||
public:
|
||||
WritingElement_AdditionConstructors(TextFont)
|
||||
PPTX_LOGIC_BASE2(TextFont)
|
||||
TextFont()
|
||||
{
|
||||
m_eType = OOX::et_Unknown;
|
||||
}
|
||||
virtual ~TextFont() {}
|
||||
TextFont(const TextFont& oSrc) { *this = oSrc; }
|
||||
|
||||
virtual OOX::EElementType getType () const
|
||||
{
|
||||
|
||||
@ -338,5 +338,13 @@ namespace PPTX
|
||||
return 0; //return 0; - заменить на просмотр настроек по умолчанию
|
||||
}
|
||||
|
||||
void UniColor::SetRGBColor(const BYTE& R, const BYTE& G, const BYTE& B)
|
||||
{
|
||||
Logic::SrgbClr* rgbColor = new Logic::SrgbClr();
|
||||
rgbColor->SetRGB(R, G, B);
|
||||
|
||||
Color.reset(rgbColor);
|
||||
}
|
||||
|
||||
} // namespace Logic
|
||||
} // namespace PPTX
|
||||
|
||||
@ -75,6 +75,8 @@ namespace PPTX
|
||||
return Color->GetRGBColor(_oTheme,_oClrMap, ARGB);
|
||||
return 0;
|
||||
}
|
||||
void SetRGBColor(const BYTE& R, const BYTE& G, const BYTE& B);
|
||||
|
||||
virtual std::wstring toXML() const;
|
||||
|
||||
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
|
||||
|
||||
@ -79,6 +79,7 @@ namespace PPTX
|
||||
node1 = node.ReadNode(_T("a:folHlink"));
|
||||
lColor.GetColorFrom(node1); Scheme.insert(std::pair<std::wstring,Logic::UniColor>(_T("folHlink"), lColor));
|
||||
|
||||
FillWithDefaults();
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
|
||||
@ -233,7 +234,85 @@ namespace PPTX
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void FillWithDefaults()
|
||||
{
|
||||
Logic::UniColor lColor;
|
||||
std::map<std::wstring, Logic::UniColor>::iterator it;
|
||||
it = Scheme.find(L"dk1");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0,0,0);
|
||||
Scheme[L"dk1"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"lt1");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(255,255,255);
|
||||
Scheme[L"lt1"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"dk2");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x1F,0x49, 0x7D);
|
||||
Scheme[L"dk2"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"lt2");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0xEE,0xEC,0xE1);
|
||||
Scheme[L"lt2"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent1");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x4F, 0x81, 0xBD);
|
||||
Scheme[L"accent1"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent2");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0xC0,0x50,0x4D);
|
||||
Scheme[L"accent2"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent3");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x9B,0xBB,0x59);
|
||||
Scheme[L"accent3"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent4");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x80,0x64,0xA2);
|
||||
Scheme[L"accent4"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent5");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x4B,0xAC,0xC6);
|
||||
Scheme[L"accent5"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"accent6");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0xF7,0x96,0x46);
|
||||
Scheme[L"accent6"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"hlink");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x00,0x00,0xFF);
|
||||
Scheme[L"hlink"] = lColor;
|
||||
}
|
||||
it = Scheme.find(L"folHlink");
|
||||
if (Scheme.end() == it || !it->second.is_init())
|
||||
{
|
||||
lColor.SetRGBColor(0x80, 0x00, 0x80);
|
||||
Scheme[L"folHlink"] = lColor;
|
||||
}
|
||||
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
protected:
|
||||
virtual void FillParentPointersForChilds()
|
||||
{
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
#include "./../WrapperWritingElement.h"
|
||||
#include "./../Logic/UniFill.h"
|
||||
#include "./../Logic/Colors/SchemeClr.h"
|
||||
#include "./../Logic/Ln.h"
|
||||
#include "./../Logic/EffectStyle.h"
|
||||
|
||||
@ -84,6 +85,7 @@ namespace PPTX
|
||||
XmlUtils::CXmlNode oNode4 = node.ReadNode(_T("a:bgFillStyleLst"));
|
||||
XmlMacroLoadArray(oNode4, _T("*"), bgFillStyleLst, Logic::UniFill);
|
||||
|
||||
FillWithDefaults();
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
|
||||
@ -251,6 +253,113 @@ namespace PPTX
|
||||
pReader->Seek(_end_rec);
|
||||
}
|
||||
|
||||
void FillWithDefaults()
|
||||
{
|
||||
Logic::SolidFill* pSolidFill = NULL;
|
||||
Logic::SchemeClr* pSchemeClr = NULL;
|
||||
|
||||
// -------------- fill styles -------------------------
|
||||
if (fillStyleLst.size() < 3)
|
||||
{
|
||||
fillStyleLst.clear();
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSchemeClr = new Logic::SchemeClr();
|
||||
pSchemeClr->val.set(L"phClr");
|
||||
pSolidFill->Color.Color.reset(pSchemeClr);
|
||||
fillStyleLst.push_back(Logic::UniFill());
|
||||
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
fillStyleLst.back().Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSolidFill->Color.SetRGBColor(0,0,0);
|
||||
fillStyleLst.push_back(Logic::UniFill());
|
||||
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
fillStyleLst.back().Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSolidFill->Color.SetRGBColor(0,0,0);
|
||||
fillStyleLst.push_back(Logic::UniFill());
|
||||
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
fillStyleLst.back().Fill.reset(pSolidFill);
|
||||
}
|
||||
|
||||
// -------------- back styles -------------------------
|
||||
if (bgFillStyleLst.size() < 3)
|
||||
{
|
||||
bgFillStyleLst.clear();
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSchemeClr = new Logic::SchemeClr();
|
||||
pSchemeClr->val.set(L"phClr");
|
||||
pSolidFill->Color.Color.reset(pSchemeClr);
|
||||
bgFillStyleLst.push_back(Logic::UniFill());
|
||||
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
bgFillStyleLst.back().Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSolidFill->Color.SetRGBColor(0,0,0);
|
||||
bgFillStyleLst.push_back(Logic::UniFill());
|
||||
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
bgFillStyleLst.back().Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSolidFill->Color.SetRGBColor(0,0,0);
|
||||
bgFillStyleLst.push_back(Logic::UniFill());
|
||||
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
|
||||
bgFillStyleLst.back().Fill.reset(pSolidFill);
|
||||
}
|
||||
|
||||
// -------------- line styles -------------------------
|
||||
if (lnStyleLst.size() < 3)
|
||||
{
|
||||
lnStyleLst.clear();
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSchemeClr = new Logic::SchemeClr();
|
||||
pSchemeClr->val.set(L"phClr");
|
||||
pSchemeClr->Modifiers.push_back(Logic::ColorModifier());
|
||||
pSchemeClr->Modifiers.back().name = L"shade";
|
||||
pSchemeClr->Modifiers.back().val = 95000;
|
||||
pSchemeClr->Modifiers.push_back(Logic::ColorModifier());
|
||||
pSchemeClr->Modifiers.back().name = L"satMod";
|
||||
pSchemeClr->Modifiers.back().val = 105000;
|
||||
pSolidFill->Color.Color.reset(pSchemeClr);
|
||||
lnStyleLst.push_back(Logic::Ln());
|
||||
lnStyleLst.back().w = 9525;
|
||||
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
|
||||
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSchemeClr = new Logic::SchemeClr();
|
||||
pSchemeClr->val.set(L"phClr");
|
||||
pSolidFill->Color.Color.reset(pSchemeClr);
|
||||
lnStyleLst.push_back(Logic::Ln());
|
||||
lnStyleLst.back().w = 25400;
|
||||
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
|
||||
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
|
||||
|
||||
pSolidFill = new Logic::SolidFill();
|
||||
pSolidFill->m_namespace = L"a";
|
||||
pSchemeClr = new Logic::SchemeClr();
|
||||
pSchemeClr->val.set(L"phClr");
|
||||
pSolidFill->Color.Color.reset(pSchemeClr);
|
||||
lnStyleLst.push_back(Logic::Ln());
|
||||
lnStyleLst.back().w = 38100;
|
||||
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
|
||||
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
|
||||
}
|
||||
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
public:
|
||||
std::wstring name;
|
||||
std::vector<Logic::UniFill> fillStyleLst;
|
||||
|
||||
@ -52,6 +52,7 @@ namespace PPTX
|
||||
majorFont = node.ReadNode(_T("a:majorFont"));
|
||||
minorFont = node.ReadNode(_T("a:minorFont"));
|
||||
|
||||
FillWithDefaults();
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
virtual std::wstring toXML() const
|
||||
@ -133,6 +134,20 @@ namespace PPTX
|
||||
|
||||
pReader->Seek(_end_rec);
|
||||
}
|
||||
void FillWithDefaults()
|
||||
{
|
||||
if (OOX::et_Unknown == majorFont.latin.m_eType)
|
||||
{
|
||||
majorFont.latin.m_name = _T("a:latin");
|
||||
majorFont.latin.typeface = L"Arial";
|
||||
}
|
||||
if (OOX::et_Unknown == minorFont.latin.m_eType)
|
||||
{
|
||||
minorFont.latin.m_name = _T("a:latin");
|
||||
minorFont.latin.typeface = L"Arial";
|
||||
}
|
||||
FillParentPointersForChilds();
|
||||
}
|
||||
|
||||
std::wstring name;
|
||||
Logic::FontCollection majorFont;
|
||||
|
||||
@ -1726,6 +1726,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
|
||||
else if ( "fldinst" == sCommand )
|
||||
{
|
||||
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
|
||||
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
|
||||
|
||||
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
|
||||
StartSubReader( oFieldInstReader, oDocument, oReader );
|
||||
@ -1740,6 +1741,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
|
||||
else if ( "fldrslt" == sCommand )
|
||||
{
|
||||
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
|
||||
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
|
||||
|
||||
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
|
||||
StartSubReader( oFieldInstReader, oDocument, oReader );
|
||||
@ -2528,6 +2530,11 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
|
||||
}
|
||||
else if ( "cell" == sCommand || "nestcell" == sCommand )
|
||||
{
|
||||
if (oReader.m_oState->m_oParagraphProp.m_bInTable == PROP_DEF && oReader.m_oState->m_oParagraphProp.m_nItap == PROP_DEF)
|
||||
{//пример п 9 п 12.rtf
|
||||
oReader.m_oState->m_oParagraphProp.m_bInTable = 1;
|
||||
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
|
||||
}
|
||||
if (oReader.m_oState->m_oParagraphProp.m_bInTable == 1 && 0 == oReader.m_oState->m_oParagraphProp.m_nItap )//Платежное_поручение.rtf (ели по другому сбойная строка заменяется параграфами
|
||||
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
|
||||
|
||||
@ -2918,7 +2925,15 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
|
||||
// pNewChar->m_eType = RtfCharSpecial::rsc_chatn;
|
||||
// m_oCurParagraph->AddItem( pNewChar );
|
||||
//}
|
||||
else if ( "chftn" == sCommand )
|
||||
else if ( "chpgn" == sCommand ) //todooo - other special
|
||||
{//header & footer
|
||||
RtfCharSpecialPtr pNewChar ( new RtfCharSpecial() );
|
||||
|
||||
pNewChar->m_oProperty = oReader.m_oState->m_oCharProp;
|
||||
pNewChar->m_eType = RtfCharSpecial::rsc_chpgn;
|
||||
m_oCurParagraph->AddItem( pNewChar );
|
||||
}
|
||||
else if ( "chftn" == sCommand )
|
||||
{
|
||||
if ( 1 == oReader.m_nFootnote )
|
||||
{
|
||||
|
||||
@ -86,7 +86,7 @@ public:
|
||||
if( NULL != oParam.poTableStyle )
|
||||
oNewParagraph->m_oProperty.m_nTableStyle = oParam.poTableStyle->m_nID;
|
||||
oNewParagraph->m_oProperty.m_nItap = oParam.oReader->m_nCurItap;
|
||||
oNewParagraph->m_oProperty.m_bInTable = true;
|
||||
oNewParagraph->m_oProperty.m_bInTable = 1;
|
||||
|
||||
oOutputCell.AddItem( oNewParagraph );
|
||||
}break;
|
||||
|
||||
@ -97,8 +97,8 @@ std::wstring RtfFieldInst::RenderToRtf(RenderParameter oRenderParameter)
|
||||
}
|
||||
std::wstring RtfFieldInst::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
|
||||
if (m_pTextItems)
|
||||
return m_pTextItems->RenderToOOX(oRenderParameter);
|
||||
@ -145,8 +145,8 @@ std::wstring RtfField::RenderToRtf(RenderParameter oRenderParameter)
|
||||
|
||||
std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
|
||||
std::wstring sResult;
|
||||
|
||||
@ -168,20 +168,20 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
bInsert = true;
|
||||
|
||||
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
|
||||
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
|
||||
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttm).c_str());
|
||||
|
||||
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
m_pInsert->m_oCharProperty.m_nRevised = PROP_DEF;
|
||||
}
|
||||
if (m_pInsert->m_oCharProperty.m_nDeleted != PROP_DEF)
|
||||
{
|
||||
bDelete = true;
|
||||
|
||||
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
|
||||
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
|
||||
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttmDel).c_str());
|
||||
|
||||
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
m_pInsert->m_oCharProperty.m_nDeleted = PROP_DEF;
|
||||
}
|
||||
//поверяем на наличие гиперссылки
|
||||
@ -224,7 +224,7 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
RenderParameter oNewParametr = oRenderParameter;
|
||||
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
|
||||
|
||||
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
|
||||
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
|
||||
if (!props.empty()) props = L"<w:rPr>" + props + L"</w:rPr>";
|
||||
|
||||
//начинаем Field
|
||||
@ -235,6 +235,8 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sResult += L"</w:r>";
|
||||
//-----------
|
||||
sResult += L"<w:r>";
|
||||
if (!props.empty())
|
||||
sResult += props;
|
||||
|
||||
sResult += L"<w:instrText xml:space=\"preserve\">";
|
||||
|
||||
|
||||
@ -87,8 +87,8 @@ std::wstring RtfParagraph::RenderToRtf(RenderParameter oRenderParameter)
|
||||
|
||||
std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
|
||||
|
||||
std::wstring sResult ;
|
||||
|
||||
@ -134,7 +134,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sResult += L"<w:p";
|
||||
if (oRenderParameter.nType == RENDER_TO_OOX_PARAM_COMMENT)
|
||||
{
|
||||
std::wstring sParaId = XmlUtils::IntToString(++poOOXWriter->m_nextParaId, L"%08X");
|
||||
std::wstring sParaId = XmlUtils::IntToString(++pOOXWriter->m_nextParaId, L"%08X");
|
||||
sResult += L" w14:paraId=\"" + sParaId + L"\" w14:textId=\"" + sParaId + L"\"";
|
||||
}
|
||||
sResult += L"><w:pPr>";
|
||||
@ -145,7 +145,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
if ( PROP_DEF != m_oProperty.m_nTableStyle && m_oProperty.m_bInTable > 0)
|
||||
{
|
||||
RtfStylePtr oCurStyle;
|
||||
if( true == poRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
|
||||
if( true == pRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
|
||||
{
|
||||
RtfParagraphStyle* oCurParaStyle = dynamic_cast<RtfParagraphStyle*>(oCurStyle.get());
|
||||
|
||||
|
||||
@ -261,13 +261,13 @@ std::wstring RtfFont::RenderToOOX(RenderParameter oRenderParameter)
|
||||
break;
|
||||
}
|
||||
sResult += L"<w:rFonts w:ascii=\"";
|
||||
sResult += sFontName;
|
||||
sResult += XmlUtils::EncodeXmlString( sFontName, true );
|
||||
sResult += L"\" w:eastAsia=\"";
|
||||
sResult += sFontName;
|
||||
sResult += XmlUtils::EncodeXmlString( sFontName, true );
|
||||
sResult += L"\" w:hAnsi=\"";
|
||||
sResult += sFontName;
|
||||
sResult += XmlUtils::EncodeXmlString( sFontName, true );
|
||||
sResult += L"\" w:cs=\"";
|
||||
sResult += sFontName;
|
||||
sResult += XmlUtils::EncodeXmlString( sFontName, true );
|
||||
sResult += L"\"";
|
||||
sResult += sHint;
|
||||
sResult += L"/>";
|
||||
@ -2948,8 +2948,14 @@ std::wstring RtfTableProperty::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sDefCellMargins += L"<w:bottom w:w=\"" + std::to_wstring(m_nDefCellMarBottom) + L"\" w:type=\"dxa\"/>";
|
||||
if( PROP_DEF != m_nDefCellMarLeft && 3 == m_eDefCellMarLeftUnit )
|
||||
sDefCellMargins += L"<w:left w:w=\"" + std::to_wstring(m_nDefCellMarLeft) + L"\" w:type=\"dxa\"/>";
|
||||
else
|
||||
sDefCellMargins += L"<w:left w:w=\"0\" w:type=\"dxa\"/>";
|
||||
|
||||
if( PROP_DEF != m_nDefCellMarRight && 3 == m_eDefCellMarRightUnit )
|
||||
sDefCellMargins += L"<w:right w:w=\"" + std::to_wstring(m_nDefCellMarRight) + L"\" w:type=\"dxa\"/>";
|
||||
else
|
||||
sDefCellMargins += L"<w:right w:w=\"0\" w:type=\"dxa\"/>";
|
||||
|
||||
if( PROP_DEF != m_nDefCellMarTop && 3 == m_eDefCellMarTopUnit )
|
||||
sDefCellMargins += L"<w:top w:w=\"" + std::to_wstring(m_nDefCellMarTop) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
@ -3111,7 +3117,7 @@ std::wstring RtfRowProperty::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
switch( m_eWidthEndInvCellUnit )
|
||||
{
|
||||
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"%\"/>"; break;
|
||||
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
|
||||
case mu_Twips: sResult += L"<w:wAfter w:type=\"dxa\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -270,6 +270,7 @@ public:
|
||||
m_byteShade = oColor.m_byteShade;
|
||||
m_byteTint = oColor.m_byteTint;
|
||||
|
||||
m_bAuto = oColor.m_bAuto;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
|
||||
@ -1,50 +1,19 @@
|
||||
INCLUDEPATH += $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/include
|
||||
|
||||
MSVC = vc140
|
||||
|
||||
CORE_BOOST_LIBS = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib
|
||||
|
||||
core_boost_libs {
|
||||
|
||||
core_windows {
|
||||
core_debug {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$MSVC-mt-gd-1_58 -llibboost_filesystem-$$MSVC-mt-gd-1_58
|
||||
}
|
||||
core_release {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$MSVC-mt-1_58 -llibboost_filesystem-$$MSVC-mt-1_58
|
||||
}
|
||||
core_win_64:BOOST_POSTFIX = -vc140-mt-x64-1_72
|
||||
core_win_32:BOOST_POSTFIX = -vc140-mt-x32-1_72
|
||||
core_debug {
|
||||
core_win_64:BOOST_POSTFIX = -vc140-mt-gd-x64-1_72
|
||||
core_win_32:BOOST_POSTFIX = -vc140-mt-gd-x32-1_72
|
||||
}
|
||||
|
||||
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system$$BOOST_POSTFIX -llibboost_filesystem$$BOOST_POSTFIX
|
||||
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex$$BOOST_POSTFIX
|
||||
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time$$BOOST_POSTFIX
|
||||
} else {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
core_boost_regex {
|
||||
|
||||
core_windows {
|
||||
core_debug {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$MSVC-mt-gd-1_58
|
||||
}
|
||||
core_release {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$MSVC-mt-1_58
|
||||
}
|
||||
} else {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -lboost_regex
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
core_boost_date_time {
|
||||
|
||||
core_windows {
|
||||
core_debug {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$MSVC-mt-gd-1_58
|
||||
}
|
||||
core_release {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$MSVC-mt-1_58
|
||||
}
|
||||
} else {
|
||||
LIBS += -L$$CORE_BOOST_LIBS -lboost_date_time
|
||||
}
|
||||
|
||||
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
|
||||
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -lboost_regex
|
||||
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -lboost_date_time
|
||||
}
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
SET outputdir=%SCRIPTPATH%boost_1_58_0\build\%platform%
|
||||
echo "%outputdir%"
|
||||
|
||||
SET TOOLSET=msvc-14.0
|
||||
|
||||
CD "%SCRIPTPATH%\boost_1_58_0"
|
||||
call .\bootstrap.bat
|
||||
|
||||
if exist "stage" (
|
||||
RMDIR "stage" /S /Q
|
||||
)
|
||||
|
||||
md build
|
||||
|
||||
SET folder=build/win_32
|
||||
|
||||
if not exist "%folder%" (
|
||||
echo "x86..."
|
||||
|
||||
md %folder%
|
||||
md %folder%\static
|
||||
md %folder%\static_fpic
|
||||
md %folder%\shared
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=static --with-filesystem --with-system --with-date_time --with-regex --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\static\"
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=static cxxflags=-fPIC --with-filesystem --with-system --with-date_time --with-regex --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\static_fpic\"
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=shared --with-filesystem --with-system --with-date_time --with-regex --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\shared\"
|
||||
)
|
||||
|
||||
SET folder=build/win_64
|
||||
|
||||
|
||||
if not exist "%folder%" (
|
||||
echo "x64..."
|
||||
|
||||
if exist "stage" (
|
||||
RMDIR "stage" /S /Q
|
||||
)
|
||||
|
||||
md %folder%
|
||||
md %folder%\static
|
||||
md %folder%\static_fpic
|
||||
md %folder%\shared
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=static --with-filesystem --with-system --with-date_time --with-regex address-model=64 --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\static\"
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=static cxxflags=-fPIC --with-filesystem --with-system --with-date_time --with-regex address-model=64 --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\static_fpic\"
|
||||
|
||||
.\b2.exe --clean
|
||||
.\bjam.exe link=shared --with-filesystem --with-system --with-date_time --with-regex address-model=64 --toolset=%TOOLSET% || goto :error
|
||||
XCOPY /Y stage\lib\* "%folder%\shared\"
|
||||
)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:error
|
||||
echo "Failed with error #%errorlevel%."
|
||||
exit /b %errorlevel%
|
||||
@ -1,61 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
Darwin*) platform="mac" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
architecture=$(uname -m)
|
||||
arch=""
|
||||
|
||||
case "$architecture" in
|
||||
x86_64*) arch="_64" ;;
|
||||
*) arch="_32" ;;
|
||||
esac
|
||||
|
||||
outputdir="$SCRIPTPATH/boost_1_58_0/build/$platform$arch"
|
||||
echo $outputdir
|
||||
|
||||
cd "$SCRIPTPATH/boost_1_58_0"
|
||||
|
||||
folder="build/$platform$arch"
|
||||
if [ ! -d $folder ]; then
|
||||
./bootstrap.sh --with-libraries=filesystem,system,date_time,regex
|
||||
|
||||
stage="stage"
|
||||
if [ -d $stage ]; then
|
||||
rm -R $stage
|
||||
fi
|
||||
|
||||
mkdir -p "$folder"
|
||||
mkdir -p "$folder/static"
|
||||
mkdir -p "$folder/static_fpic"
|
||||
mkdir -p "$folder/shared"
|
||||
|
||||
./b2 --clean
|
||||
./bjam link=static
|
||||
cp stage/lib/* "$folder/static/"
|
||||
|
||||
./b2 --clean
|
||||
./bjam link=static cxxflags=-fPIC
|
||||
cp stage/lib/* "$folder/static_fpic/"
|
||||
|
||||
./b2 --clean
|
||||
./bjam link=shared
|
||||
cp stage/lib/* "$folder/shared/"
|
||||
fi
|
||||
|
||||
if [[ "$OO_PLATFORM" == *"ios"* ]]
|
||||
then
|
||||
if [ ! -d "$SCRIPTPATH/boost_1_58_0/build/ios" ]; then
|
||||
cd "$SCRIPTPATH"
|
||||
./boost_ios.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
if exist "%SCRIPTPATH%boost_1_58_0.7z" (
|
||||
echo "boost already downloaded"
|
||||
) else (
|
||||
Powershell.exe Invoke-WebRequest -OutFile boost_1_58_0.7z https://downloads.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.7z -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox
|
||||
)
|
||||
|
||||
SET UNSIP_PROGRAMM="C:\Program Files\7-Zip\7z.exe"
|
||||
SET UNSIP_PROGRAMM2="C:\Program Files (x86)\7-Zip\7z.exe"
|
||||
if exist %UNSIP_PROGRAMM2% (
|
||||
SET UNSIP_PROGRAMM=%UNSIP_PROGRAMM2%
|
||||
)
|
||||
|
||||
if exist "%SCRIPTPATH%boost_1_58_0/" (
|
||||
echo "boost already extracted"
|
||||
) else (
|
||||
call %UNSIP_PROGRAMM% x "%SCRIPTPATH%/boost_1_58_0.7z" -o"%SCRIPTPATH%/"
|
||||
)
|
||||
@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
BOOST_URL=https://downloads.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.7z
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
Darwin*) platform="mac" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
if [[ -f "$SCRIPTPATH/boost_1_58_0.7z" ]]
|
||||
then
|
||||
echo "boost already downloaded"
|
||||
else
|
||||
wget $BOOST_URL || curl -O -L $BOOST_URL
|
||||
fi
|
||||
|
||||
if [ -d "$SCRIPTPATH/boost_1_58_0" ]; then
|
||||
echo "boost already extracted"
|
||||
else
|
||||
if [[ "$platform" == *"linux"* ]]
|
||||
then
|
||||
7z x -y "$SCRIPTPATH/boost_1_58_0.7z" -o"$SCRIPTPATH/"
|
||||
else
|
||||
7za x "$SCRIPTPATH/boost_1_58_0.7z" -o"$SCRIPTPATH/"
|
||||
fi
|
||||
fi
|
||||
4
Common/3dParty/cef/.gitignore
vendored
Normal file
4
Common/3dParty/cef/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@ -1 +0,0 @@
|
||||
echo "build: OK!"
|
||||
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "build: OK!"
|
||||
@ -1,62 +0,0 @@
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# download a file
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
function Download-File
|
||||
{
|
||||
param ([string]$url,[string]$file)
|
||||
|
||||
$downloadRequired = $true
|
||||
if (Test-Path $file)
|
||||
{
|
||||
$localModified = (Get-Item $file).CreationTime
|
||||
$webRequest = [System.Net.HttpWebRequest]::Create($url)
|
||||
$webRequest.Method = "HEAD"
|
||||
$webResponse = $webRequest.GetResponse()
|
||||
$remoteLastModified = ($webResponse.LastModified) -as [DateTime]
|
||||
$webResponse.Close()
|
||||
|
||||
if ($remoteLastModified -gt $localModified)
|
||||
{
|
||||
Write-Host "$file is out of date"
|
||||
}
|
||||
else
|
||||
{
|
||||
$downloadRequired = $false
|
||||
}
|
||||
}
|
||||
|
||||
if ($downloadRequired)
|
||||
{
|
||||
$clnt = new-object System.Net.WebClient
|
||||
Write-Host "Downloading from $url to $file"
|
||||
$clnt.DownloadFile($url, $file)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "$file is up to date."
|
||||
}
|
||||
|
||||
return $downloadRequired
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
# unzip a file
|
||||
# ----------------------------------------------------------------------------------------------
|
||||
function RemoveCef
|
||||
{
|
||||
param([string]$outpath)
|
||||
|
||||
if (Test-Path $outpath)
|
||||
{
|
||||
Write-Host "Remove folder $outpath"
|
||||
Remove-Item $outpath -Force -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
$output = Download-File -url $args[0] -file $args[1]
|
||||
if ($output)
|
||||
{
|
||||
RemoveCef -outpath $args[2]
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
@echo off
|
||||
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
setlocal
|
||||
|
||||
SET UNSIP_PROGRAMM="%ProgramFiles%\7-Zip\7z.exe"
|
||||
SET UNSIP_PROGRAMM2="%ProgramFiles(x86)%\7-Zip\7z.exe"
|
||||
if exist %UNSIP_PROGRAMM2% (
|
||||
SET UNSIP_PROGRAMM=%UNSIP_PROGRAMM2%
|
||||
)
|
||||
|
||||
if defined BUILD_PLATFORM (
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:xp=%" (
|
||||
SET "BUILD_PLATFORMS=win_64 win_32 winxp_64 winxp_32"
|
||||
GOTO :found
|
||||
)
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:all=%" (
|
||||
SET "BUILD_PLATFORMS=win_64 win_32"
|
||||
GOTO :found
|
||||
)
|
||||
)
|
||||
|
||||
SET "BUILD_PLATFORMS=win_32"
|
||||
if defined ProgramFiles(x86) (
|
||||
SET "BUILD_PLATFORMS=win_64"
|
||||
GOTO :found
|
||||
)
|
||||
if defined TARGET (
|
||||
SET "BUILD_PLATFORMS=%TARGET%"
|
||||
GOTO :found
|
||||
)
|
||||
|
||||
echo "error"
|
||||
GOTO :end
|
||||
|
||||
:found
|
||||
for %%a in (%BUILD_PLATFORMS%) do (
|
||||
echo "platform: %%a"
|
||||
mkdir "%SCRIPTPATH%%%a"
|
||||
cd "%SCRIPTPATH%%%a"
|
||||
Powershell.exe -executionpolicy remotesigned -file %SCRIPTPATH%download.ps1 http://d2ettrnqo7v976.cloudfront.net/cef/3163/%%a/cef_binary.7z cef_binary.7z cef_binary
|
||||
|
||||
if exist "cef_binary" (
|
||||
echo "cef_binary.7z already extracted"
|
||||
) else (
|
||||
call %UNSIP_PROGRAMM% x "cef_binary.7z"
|
||||
mkdir build
|
||||
xcopy /Y /S cef_binary\Release\* build\
|
||||
xcopy /Y /S cef_binary\Resources\* build\
|
||||
)
|
||||
)
|
||||
|
||||
:end
|
||||
endlocal
|
||||
|
||||
@echo on
|
||||
@ -1,88 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
Darwin*) platform="mac" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
architecture=$(uname -m)
|
||||
arch=""
|
||||
|
||||
case "$architecture" in
|
||||
x86_64*) arch="_64" ;;
|
||||
*) arch="_32" ;;
|
||||
esac
|
||||
|
||||
if [[ -d "$SCRIPTPATH/$platform$arch" ]]
|
||||
then
|
||||
echo
|
||||
else
|
||||
mkdir "$SCRIPTPATH/$platform$arch"
|
||||
fi
|
||||
|
||||
cd "$SCRIPTPATH/$platform$arch"
|
||||
|
||||
if [ -d "build" ]
|
||||
then
|
||||
echo ""
|
||||
else
|
||||
mkdir "build"
|
||||
fi
|
||||
cef_binary=cef_binary
|
||||
cef_arch=$cef_binary.7z
|
||||
cef_version="3163"
|
||||
|
||||
if [[ "$platform" == *"linux"* ]]
|
||||
then
|
||||
cef_version="3202"
|
||||
cef_url=http://d2ettrnqo7v976.cloudfront.net/cef/$cef_version/$platform$arch/$cef_arch
|
||||
else
|
||||
cef_url=http://d2ettrnqo7v976.cloudfront.net/cef/$cef_version/$platform/$cef_arch
|
||||
fi
|
||||
|
||||
if [[ "$platform" == *"linux"* ]]
|
||||
then
|
||||
|
||||
if [[ -f $cef_arch ]]
|
||||
then
|
||||
cef_mod_time=$(date -d"$(curl -sI $cef_url | awk '/Last-Modified/ {print ($3, $4, $5, $6, $7, $8)}')" +"%s")
|
||||
local_mod_time=$(stat -c %Y $cef_arch)
|
||||
if [[ $cef_mod_time -eq $local_mod_time ]]
|
||||
then
|
||||
echo "cef_binary already downloaded"
|
||||
else
|
||||
wget $cef_url -O $cef_arch
|
||||
rm -fr $cef_binary/
|
||||
fi
|
||||
else
|
||||
wget $cef_url
|
||||
rm -fr $cef_binary/
|
||||
fi
|
||||
|
||||
if [ -d $cef_binary ]
|
||||
then
|
||||
echo "cef_binary already extracted"
|
||||
else
|
||||
7z x -y $cef_arch
|
||||
fi
|
||||
|
||||
cp -r -t build/ ./$cef_binary/Release/* ./$cef_binary/Resources/*
|
||||
chmod a+xr build/locales
|
||||
fi
|
||||
|
||||
if [[ "$platform" == *"mac"* ]]
|
||||
then
|
||||
if [ -d "build/Chromium Embedded Framework.framework" ]
|
||||
then
|
||||
echo "cef_binary already extracted"
|
||||
else
|
||||
wget $cef_url || curl -O $cef_url
|
||||
7za x $cef_arch
|
||||
mv "$cef_binary" "build/Chromium Embedded Framework.framework"
|
||||
fi
|
||||
fi
|
||||
@ -1 +0,0 @@
|
||||
echo "build: OK!"
|
||||
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "build: OK!"
|
||||
@ -1,84 +0,0 @@
|
||||
@echo off
|
||||
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
setlocal
|
||||
|
||||
SET ICU_MAJOR_VER=58
|
||||
SET ICU_MINOR_VER=2
|
||||
|
||||
SET VC=%ProgramFiles%\Microsoft Visual Studio 14.0\VC
|
||||
SET VC64=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC
|
||||
if exist %VC64% (
|
||||
SET VC=%VC64%
|
||||
)
|
||||
|
||||
SET UNSIP_PROGRAMM="%ProgramFiles%\7-Zip\7z.exe"
|
||||
SET UNSIP_PROGRAMM2="%ProgramFiles(x86)%\7-Zip\7z.exe"
|
||||
if exist %UNSIP_PROGRAMM2% (
|
||||
SET UNSIP_PROGRAMM=%UNSIP_PROGRAMM2%
|
||||
)
|
||||
|
||||
if defined BUILD_PLATFORM (
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:all=%" (
|
||||
SET "BUILD_PLATFORMS=win_64 win_32"
|
||||
GOTO :found
|
||||
)
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:xp=%" (
|
||||
SET "BUILD_PLATFORMS=win_64 win_32"
|
||||
GOTO :found
|
||||
)
|
||||
)
|
||||
|
||||
SET "BUILD_PLATFORMS=win_32"
|
||||
if defined ProgramFiles(x86) (
|
||||
SET "BUILD_PLATFORMS=win_64"
|
||||
GOTO :found
|
||||
)
|
||||
if defined TARGET (
|
||||
SET "BUILD_PLATFORMS=%TARGET%"
|
||||
GOTO :found
|
||||
)
|
||||
|
||||
echo "error"
|
||||
GOTO :end
|
||||
|
||||
:found
|
||||
for %%a in (%BUILD_PLATFORMS%) do (
|
||||
cd "%SCRIPTPATH%"
|
||||
if not exist "%%a" (
|
||||
md "%%a"
|
||||
)
|
||||
if not exist "%%a\build" (
|
||||
md "%%a\build"
|
||||
)
|
||||
cd "%SCRIPTPATH%%%a"
|
||||
if exist "icu" (
|
||||
echo "icu already exported"
|
||||
) else (
|
||||
svn export https://github.com/unicode-org/icu/tags/release-%ICU_MAJOR_VER%-%ICU_MINOR_VER%/icu4c ./icu
|
||||
)
|
||||
|
||||
if "%%a" == "win_64" (
|
||||
call "%VC%\vcvarsall.bat" x64
|
||||
MSBuild.exe icu\source\allinone\allinone.sln /p:Configuration=Release /p:PlatformToolset=v140 /p:Platform="X64"
|
||||
XCOPY /Y "icu\bin64\icudt%ICU_MAJOR_VER%.dll" "build\"
|
||||
XCOPY /Y "icu\bin64\icuuc%ICU_MAJOR_VER%.dll" "build\"
|
||||
XCOPY /Y "icu\lib64\icudt.lib" "build\"
|
||||
XCOPY /Y "icu\lib64\icuuc.lib" "build\"
|
||||
) else (
|
||||
call "%VC%\vcvarsall.bat" x86
|
||||
MSBuild.exe icu\source\allinone\allinone.sln /p:Configuration=Release /p:PlatformToolset=v140 /p:Platform="Win32"
|
||||
XCOPY /Y "icu\bin\icudt%ICU_MAJOR_VER%.dll" "build\"
|
||||
XCOPY /Y "icu\bin\icuuc%ICU_MAJOR_VER%.dll" "build\"
|
||||
XCOPY /Y "icu\lib\icudt.lib" "build\"
|
||||
XCOPY /Y "icu\lib\icuuc.lib" "build\"
|
||||
)
|
||||
)
|
||||
cd "%SCRIPTPATH%"
|
||||
|
||||
:end
|
||||
endlocal
|
||||
|
||||
@echo on
|
||||
@ -1,91 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
ICU_MAJOR_VER=58
|
||||
ICU_MINOR_VER=2
|
||||
|
||||
SHARED_LIB_VER=$ICU_MAJOR_VER.$ICU_MINOR_VER
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*)
|
||||
platform="linux"
|
||||
BUILD_PLATFORM=Linux
|
||||
SHARED_LIB_EXT=.so.$SHARED_LIB_VER
|
||||
SHARED_LIB_SHORT_EXT=.so.$ICU_MAJOR_VER
|
||||
;;
|
||||
Darwin*)
|
||||
platform="mac"
|
||||
BUILD_PLATFORM=MacOSX
|
||||
SHARED_LIB_EXT=.$SHARED_LIB_VER.dylib
|
||||
SHARED_LIB_SHORT_EXT=.$ICU_MAJOR_VER.dylib
|
||||
;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
|
||||
architecture=$(uname -m)
|
||||
arch=""
|
||||
|
||||
case "$architecture" in
|
||||
x86_64*) arch="_64" ;;
|
||||
*) arch="_32" ;;
|
||||
esac
|
||||
|
||||
if [[ -d "$SCRIPTPATH/$platform$arch" ]]
|
||||
then
|
||||
echo
|
||||
else
|
||||
mkdir "$SCRIPTPATH/$platform$arch"
|
||||
fi
|
||||
|
||||
cd "$SCRIPTPATH/$platform$arch"
|
||||
|
||||
if [ -d "build" ]
|
||||
then
|
||||
echo ""
|
||||
else
|
||||
mkdir "build"
|
||||
fi
|
||||
|
||||
if [ -d "./icu" ]
|
||||
then
|
||||
echo "icu already exported"
|
||||
else
|
||||
svn export https://github.com/unicode-org/icu/tags/release-$ICU_MAJOR_VER-$ICU_MINOR_VER/icu4c ./icu
|
||||
fi
|
||||
|
||||
if [[ "$platform" == *"linux"* ]]
|
||||
then
|
||||
# Workaround for building icu older than 60.0
|
||||
# on systems without xlocale.h (removed from glibc since 2.26)
|
||||
# See https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
|
||||
# See https://bugs.archlinux.org/task/55246
|
||||
sed -i 's/xlocale/locale/' ./icu/source/i18n/digitlst.cpp
|
||||
fi
|
||||
|
||||
if [[ "$platform" == *"mac"* ]]
|
||||
then
|
||||
sed -i -e 's/cmd\, \"%s %s -o %s%s %s %s%s %s %s\"\,/cmd\, \"%s %s -o %s%s %s %s %s %s %s\"\,/' ./icu/source/tools/pkgdata/pkgdata.cpp
|
||||
fi
|
||||
|
||||
cd ./icu/source/
|
||||
|
||||
if [ ! -f "./Makefile" ]
|
||||
then
|
||||
./runConfigureICU $BUILD_PLATFORM
|
||||
fi
|
||||
|
||||
make
|
||||
|
||||
if [ ! -d "$SCRIPTPATH/$platform$arch/usr/local" ]
|
||||
then
|
||||
DESTDIR="$SCRIPTPATH/$platform$arch" make install
|
||||
fi
|
||||
|
||||
cd ../../
|
||||
|
||||
cp "./icu/source/lib/libicudata$SHARED_LIB_EXT" "build/libicudata$SHARED_LIB_SHORT_EXT"
|
||||
cp "./icu/source/lib/libicuuc$SHARED_LIB_EXT" "build/libicuuc$SHARED_LIB_SHORT_EXT"
|
||||
@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
cd "$SCRIPTPATH"/openssl
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
Darwin*) platform="darwin64-x86_64-cc" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
platformLinux=""
|
||||
|
||||
architecture=$(uname -m)
|
||||
arch=""
|
||||
|
||||
if [[ "$platform" == "linux" ]]
|
||||
then
|
||||
case "$architecture" in
|
||||
x86_64*) arch="-64" ;;
|
||||
*) arch="-32" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "$platform$arch"
|
||||
|
||||
if [ ! -f Makefile ]; then
|
||||
#perl ./Configure $platform$arch
|
||||
./config no-shared no-asm
|
||||
fi
|
||||
|
||||
make build_libs
|
||||
486
Common/3dParty/openssl/common/common_openssl.cpp
Normal file
486
Common/3dParty/openssl/common/common_openssl.cpp
Normal file
@ -0,0 +1,486 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./common_openssl.h"
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
namespace NSOpenSSL
|
||||
{
|
||||
unsigned char* openssl_alloc(unsigned int len)
|
||||
{
|
||||
return (unsigned char*)malloc(len);
|
||||
}
|
||||
void openssl_free(unsigned char* data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
// hash
|
||||
unsigned int GetHashSize(const int& alg)
|
||||
{
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
return 20;
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
return 28;
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
return 32;
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
return 48;
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
return 64;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len)
|
||||
{
|
||||
len = GetHashSize(alg);
|
||||
if (0 == len)
|
||||
return NULL;
|
||||
unsigned char* res = openssl_alloc(len);
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
SHA1(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
SHA224(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
SHA256(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
SHA384(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
SHA512(data, (size_t)size, res);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// rsa
|
||||
bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey)
|
||||
{
|
||||
publicKey = NULL;
|
||||
privateKey = NULL;
|
||||
|
||||
RSA* rsa = RSA_new();
|
||||
BIGNUM *exponent = BN_new();
|
||||
|
||||
BN_set_word(exponent, RSA_F4);
|
||||
int result = RSA_generate_multi_prime_key(rsa, 2048, 2, exponent, NULL);
|
||||
if (0 == result)
|
||||
return false;
|
||||
|
||||
if (true)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL))
|
||||
{
|
||||
int key_length = BIO_pending(bio);
|
||||
privateKey = openssl_alloc(key_length + 1);
|
||||
if (key_length != BIO_read(bio, privateKey, key_length))
|
||||
{
|
||||
openssl_free(privateKey);
|
||||
privateKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
privateKey[key_length] = '\0';
|
||||
}
|
||||
}
|
||||
BIO_free_all(bio);
|
||||
}
|
||||
if (true)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (PEM_write_bio_RSA_PUBKEY(bio, rsa))
|
||||
{
|
||||
int key_length = BIO_pending(bio);
|
||||
publicKey = openssl_alloc(key_length + 1);
|
||||
if (key_length != BIO_read(bio, publicKey, key_length))
|
||||
{
|
||||
openssl_free(publicKey);
|
||||
publicKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
publicKey[key_length] = '\0';
|
||||
}
|
||||
}
|
||||
BIO_free_all(bio);
|
||||
}
|
||||
|
||||
BN_free(exponent);
|
||||
RSA_free(rsa);
|
||||
|
||||
return (NULL != publicKey && NULL != privateKey) ? true : false;
|
||||
}
|
||||
|
||||
//#define USE_DEPRECATED
|
||||
bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
|
||||
{
|
||||
BIO* bio = BIO_new_mem_buf(publicKey, (int)strlen((char*)publicKey));
|
||||
|
||||
#ifdef USE_DEPRECATED
|
||||
RSA* rsa = RSA_new();
|
||||
RSA* resrsa = PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, NULL);
|
||||
|
||||
unsigned int key_size = (unsigned int)RSA_size(rsa);
|
||||
data_crypt = openssl_alloc(key_size);
|
||||
|
||||
int res = RSA_public_encrypt((int)size, data, data_crypt, rsa, RSA_NO_PADDING);
|
||||
data_crypt_len = key_size;
|
||||
|
||||
BIO_free(bio);
|
||||
RSA_free(rsa);
|
||||
return (-1 != res) ? true : false;
|
||||
#else
|
||||
EVP_PKEY* publicKeyEngine = NULL;
|
||||
PEM_read_bio_PUBKEY(bio, &publicKeyEngine, 0, NULL);
|
||||
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(publicKeyEngine, NULL);
|
||||
EVP_PKEY_encrypt_init(ctx);
|
||||
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
size_t out_len = 0;
|
||||
EVP_PKEY_encrypt(ctx, NULL, &out_len, data, (size_t)size);
|
||||
|
||||
data_crypt = openssl_alloc((unsigned int)out_len);
|
||||
|
||||
EVP_PKEY_encrypt(ctx, data_crypt, &out_len, data, (size_t)size);
|
||||
data_crypt_len = (unsigned int)out_len;
|
||||
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
EVP_PKEY_free(publicKeyEngine);
|
||||
BIO_free(bio);
|
||||
|
||||
return (out_len > 0) ? true : false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
|
||||
{
|
||||
BIO* bio = BIO_new_mem_buf(privateKey, (int)strlen((char*)privateKey));
|
||||
|
||||
#ifdef USE_DEPRECATED
|
||||
RSA* rsa = RSA_new();
|
||||
PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, NULL);
|
||||
|
||||
unsigned int key_size = (unsigned int)RSA_size(rsa);
|
||||
data_decrypt = openssl_alloc(key_size);
|
||||
|
||||
int res = RSA_private_decrypt((int)size, data, data_decrypt, rsa, RSA_NO_PADDING);
|
||||
data_decrypt_len = key_size;
|
||||
|
||||
BIO_free(bio);
|
||||
RSA_free(rsa);
|
||||
return (-1 != res) ? true : false;
|
||||
#else
|
||||
EVP_PKEY* privateKeyEngine = NULL;
|
||||
PEM_read_bio_PrivateKey(bio, &privateKeyEngine, 0, NULL);
|
||||
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(privateKeyEngine, NULL);
|
||||
EVP_PKEY_decrypt_init(ctx);
|
||||
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
size_t out_len = 0;
|
||||
EVP_PKEY_decrypt(ctx, NULL, &out_len, data, (size_t)size);
|
||||
|
||||
data_decrypt = openssl_alloc((unsigned int)out_len);
|
||||
|
||||
EVP_PKEY_decrypt(ctx, data_decrypt, &out_len, data, (size_t)size);
|
||||
data_decrypt_len = (unsigned int)out_len;
|
||||
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
EVP_PKEY_free(privateKeyEngine);
|
||||
BIO_free(bio);
|
||||
|
||||
return (out_len > 0) ? true : false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out)
|
||||
{
|
||||
unsigned char* out_ptr = NULL;
|
||||
unsigned int out_ptr_len = 0;
|
||||
|
||||
if (!RSA_EncryptPublic(publicKey, (unsigned char*)input.c_str(), (unsigned int)input.length(), out_ptr, out_ptr_len))
|
||||
return false;
|
||||
|
||||
out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_BASE64);
|
||||
openssl_free(out_ptr);
|
||||
return true;
|
||||
}
|
||||
bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out)
|
||||
{
|
||||
unsigned char* input_ptr = NULL;
|
||||
int input_ptr_len = 0;
|
||||
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
|
||||
if (!bBase64)
|
||||
return false;
|
||||
|
||||
unsigned char* out_ptr = NULL;
|
||||
unsigned int out_ptr_len = 0;
|
||||
|
||||
if (!RSA_DecryptPrivate(privateKey, input_ptr, (unsigned int)input_ptr_len, out_ptr, out_ptr_len))
|
||||
{
|
||||
openssl_free(input_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
//out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
|
||||
out = std::string((char*)out_ptr, out_ptr_len);
|
||||
openssl_free(input_ptr);
|
||||
openssl_free(out_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// pbkdf2
|
||||
const EVP_MD* Get_EVP_MD(int nAlg)
|
||||
{
|
||||
switch (nAlg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
{
|
||||
return EVP_sha1();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
{
|
||||
return EVP_sha224();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
{
|
||||
return EVP_sha256();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
{
|
||||
return EVP_sha384();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
{
|
||||
return EVP_sha512();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return EVP_sha1();
|
||||
}
|
||||
unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len)
|
||||
{
|
||||
unsigned char* out = openssl_alloc(key_len);
|
||||
if (0 == PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1000, Get_EVP_MD(hash_alg), key_len, out))
|
||||
{
|
||||
openssl_free(out);
|
||||
out = NULL;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = NULL;
|
||||
if (salt.empty())
|
||||
{
|
||||
unsigned int pass_salt_len = 0;
|
||||
unsigned char* pass_salt = NSOpenSSL::GetHash((unsigned char*)pass.c_str(), (unsigned int)pass.length(), OPENSSL_HASH_ALG_SHA512, pass_salt_len);
|
||||
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), pass_salt, pass_salt_len, OPENSSL_HASH_ALG_SHA256, 32 + 16);
|
||||
openssl_free(pass_salt);
|
||||
}
|
||||
else
|
||||
{
|
||||
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), (const unsigned char*)salt.c_str(), (unsigned int)salt.length(), OPENSSL_HASH_ALG_SHA256, 32 + 16);
|
||||
}
|
||||
return key_iv;
|
||||
}
|
||||
|
||||
// aes
|
||||
int AES_GetKeySize(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return 32;
|
||||
}
|
||||
return 32;
|
||||
}
|
||||
int AES_GetIvSize(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return 16;
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
|
||||
const EVP_CIPHER* _get_cipher_aes(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return EVP_aes_256_cbc();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
|
||||
{
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX_init(ctx);
|
||||
EVP_EncryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
|
||||
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
|
||||
int out_len1 = (int)size + AES_BLOCK_SIZE;
|
||||
int out_len2 = 0;
|
||||
data_crypt = openssl_alloc(out_len1);
|
||||
EVP_EncryptUpdate(ctx, data_crypt, &out_len1, data, (int)size);
|
||||
EVP_EncryptFinal_ex(ctx, data_crypt + out_len1, &out_len2);
|
||||
data_crypt_len = out_len1 + out_len2;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
EVP_cleanup();
|
||||
return true;
|
||||
}
|
||||
bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
|
||||
{
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX_init(ctx);
|
||||
EVP_DecryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
|
||||
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
|
||||
int out_len1 = (int)size;
|
||||
int out_len2 = 0;
|
||||
data_decrypt = openssl_alloc(out_len1);
|
||||
EVP_DecryptUpdate(ctx, data_decrypt, &out_len1, data, (int)size);
|
||||
EVP_DecryptFinal_ex(ctx, data_decrypt + out_len1, &out_len2);
|
||||
data_decrypt_len = out_len1 + out_len2;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
EVP_cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
|
||||
bool bRes = AES_Encrypt_desktop(key_iv, input, output);
|
||||
openssl_free(key_iv);
|
||||
return bRes;
|
||||
}
|
||||
bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
|
||||
bool bRes = AES_Decrypt_desktop(key_iv, input, output);
|
||||
openssl_free(key_iv);
|
||||
return bRes;
|
||||
}
|
||||
bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
|
||||
{
|
||||
unsigned char* data_crypt = NULL;
|
||||
unsigned int data_crypt_len = 0;
|
||||
bool bRes = AES_Encrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, (unsigned char*)input.c_str(), (unsigned int)input.length(), data_crypt, data_crypt_len);
|
||||
|
||||
if (!bRes)
|
||||
return false;
|
||||
|
||||
output = Serialize(data_crypt, data_crypt_len, OPENSSL_SERIALIZE_TYPE_BASE64);
|
||||
openssl_free(data_crypt);
|
||||
return true;
|
||||
}
|
||||
bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
|
||||
{
|
||||
unsigned char* input_ptr = NULL;
|
||||
int input_ptr_len = 0;
|
||||
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
|
||||
if (!bBase64)
|
||||
return false;
|
||||
|
||||
unsigned char* data_decrypt = NULL;
|
||||
unsigned int data_decrypt_len = 0;
|
||||
bool bRes = AES_Decrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, input_ptr, input_ptr_len, data_decrypt, data_decrypt_len);
|
||||
|
||||
if (!bRes)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(input_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
//output = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
|
||||
output = std::string((char*)data_decrypt, data_decrypt_len);
|
||||
RELEASEARRAYOBJECTS(input_ptr);
|
||||
openssl_free(data_decrypt);
|
||||
return true;
|
||||
}
|
||||
|
||||
// serialize
|
||||
std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg)
|
||||
{
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_SERIALIZE_TYPE_ASCII:
|
||||
{
|
||||
return std::string((char*)data, size);
|
||||
}
|
||||
case OPENSSL_SERIALIZE_TYPE_HEX:
|
||||
{
|
||||
std::string res;
|
||||
res.reserve(2 * size + 1);
|
||||
char tmp[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
for (unsigned int i = 0; i < size; ++i)
|
||||
{
|
||||
res.append(1, tmp[data[i] >> 4]);
|
||||
res.append(1, tmp[data[i] & 0x0F]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
case OPENSSL_SERIALIZE_TYPE_BASE64:
|
||||
{
|
||||
char* pDataDst = NULL;
|
||||
int nDataDst = 0;
|
||||
NSFile::CBase64Converter::Encode((BYTE*)data, (int)size, pDataDst, nDataDst, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
std::string sBase64((char*)pDataDst, nDataDst);
|
||||
RELEASEARRAYOBJECTS(pDataDst);
|
||||
return sBase64;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
94
Common/3dParty/openssl/common/common_openssl.h
Normal file
94
Common/3dParty/openssl/common/common_openssl.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMMON_OPENSSL_H
|
||||
#define COMMON_OPENSSL_H
|
||||
|
||||
#define OPENSSL_HASH_ALG_SHA1 0
|
||||
#define OPENSSL_HASH_ALG_INVALID 1
|
||||
#define OPENSSL_HASH_ALG_SHA256 2
|
||||
#define OPENSSL_HASH_ALG_SHA224 3
|
||||
#define OPENSSL_HASH_ALG_SHA384 4
|
||||
#define OPENSSL_HASH_ALG_SHA512 5
|
||||
|
||||
#define OPENSSL_SERIALIZE_TYPE_BASE64 0
|
||||
#define OPENSSL_SERIALIZE_TYPE_HEX 1
|
||||
#define OPENSSL_SERIALIZE_TYPE_ASCII 2
|
||||
|
||||
#define OPENSSL_AES_256_CBC 0
|
||||
|
||||
#include "../../../../DesktopEditor/common/File.h"
|
||||
|
||||
#ifdef COMMON_OPENSSL_BUILDING
|
||||
#define OPENSSL_DECL Q_DECL_EXPORT
|
||||
#else
|
||||
#define OPENSSL_DECL Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
namespace NSOpenSSL
|
||||
{
|
||||
// alloc
|
||||
OPENSSL_DECL unsigned char* openssl_alloc(unsigned int len);
|
||||
OPENSSL_DECL void openssl_free(unsigned char* data);
|
||||
|
||||
// hash
|
||||
OPENSSL_DECL unsigned int GetHashSize(const int& alg);
|
||||
OPENSSL_DECL unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len);
|
||||
|
||||
// rsa
|
||||
OPENSSL_DECL bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey);
|
||||
OPENSSL_DECL bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
OPENSSL_DECL bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len);
|
||||
|
||||
OPENSSL_DECL bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out);
|
||||
OPENSSL_DECL bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out);
|
||||
|
||||
// pbkdf2
|
||||
OPENSSL_DECL unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len);
|
||||
OPENSSL_DECL unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt = "");
|
||||
|
||||
// aes
|
||||
OPENSSL_DECL int AES_GetKeySize(int type);
|
||||
OPENSSL_DECL int AES_GetIvSize(int type);
|
||||
OPENSSL_DECL bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
OPENSSL_DECL bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
|
||||
OPENSSL_DECL bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
|
||||
OPENSSL_DECL bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
|
||||
OPENSSL_DECL bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
|
||||
OPENSSL_DECL bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
|
||||
|
||||
// serialize
|
||||
OPENSSL_DECL std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg);
|
||||
}
|
||||
|
||||
#endif // COMMON_OPENSSL_H
|
||||
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
cd "$SCRIPTPATH"
|
||||
|
||||
if [ ! -d openssl ]; then
|
||||
git clone --depth=1 https://github.com/openssl/openssl.git
|
||||
fi
|
||||
@ -1,17 +1,14 @@
|
||||
core_linux {
|
||||
OPEN_SSL_PLATFORM=$$CORE_BUILDS_PLATFORM_PREFIX
|
||||
build_xp:OPEN_SSL_PLATFORM=$$join(OPEN_SSL_PLATFORM, OPEN_SSL_PLATFORM, "", "_xp")
|
||||
|
||||
INCLUDEPATH += $$PWD/openssl/include
|
||||
INCLUDEPATH += $$PWD/build/$$OPEN_SSL_PLATFORM/include
|
||||
|
||||
LIBS += $$PWD/openssl/libssl.a
|
||||
LIBS += $$PWD/openssl/libcrypto.a
|
||||
|
||||
}
|
||||
|
||||
core_mac {
|
||||
|
||||
INCLUDEPATH += $$PWD/openssl/include
|
||||
|
||||
LIBS += $$PWD/openssl/libssl.a
|
||||
LIBS += $$PWD/openssl/libcrypto.a
|
||||
core_windows:LIBS += -L$$PWD/build/$$OPEN_SSL_PLATFORM/lib -llibcrypto -llibssl
|
||||
!core_windows:LIBS += -L$$PWD/build/$$OPEN_SSL_PLATFORM/lib -lcrypto -lssl
|
||||
|
||||
open_ssl_common {
|
||||
DEFINES += COMMON_OPENSSL_BUILDING
|
||||
|
||||
HEADERS += $$PWD/common/common_openssl.h
|
||||
SOURCES += $$PWD/common/common_openssl.cpp
|
||||
}
|
||||
|
||||
94
Common/3dParty/openssl/test/main.cpp
Normal file
94
Common/3dParty/openssl/test/main.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./../common/common_openssl.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argc;
|
||||
argv;
|
||||
if (true)
|
||||
{
|
||||
std::string sTestHashString = "knoejnrgijwenrgiojwnergjiwnerigjnwerojgnweorigjn";
|
||||
unsigned int data_len = 0;
|
||||
unsigned char* data = NSOpenSSL::GetHash((unsigned char*)sTestHashString.c_str(), (unsigned int)sTestHashString.length(), OPENSSL_HASH_ALG_SHA256, data_len);
|
||||
std::string sResult = NSOpenSSL::Serialize(data, data_len, OPENSSL_SERIALIZE_TYPE_HEX);
|
||||
NSOpenSSL::openssl_free(data);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
unsigned char* publicKey = NULL;
|
||||
unsigned char* privateKey = NULL;
|
||||
bool bRes = NSOpenSSL::RSA_GenerateKeys(publicKey, privateKey);
|
||||
bRes;
|
||||
|
||||
std::string sPublic((char*)publicKey);
|
||||
std::string sPrivate((char*)privateKey);
|
||||
|
||||
NSOpenSSL::openssl_free(publicKey);
|
||||
NSOpenSSL::openssl_free(privateKey);
|
||||
|
||||
std::string sMessage = "Hello world";
|
||||
|
||||
unsigned char* message_crypt = NULL;
|
||||
unsigned int message_crypt_len = 0;
|
||||
bool bEncrypt = NSOpenSSL::RSA_EncryptPublic((unsigned char*)sPublic.c_str(), (unsigned char*)sMessage.c_str(), (unsigned int)sMessage.length(), message_crypt, message_crypt_len);
|
||||
bEncrypt;
|
||||
|
||||
unsigned char* message_decrypt = NULL;
|
||||
unsigned int message_decrypt_len = 0;
|
||||
|
||||
bool bDecrypt = NSOpenSSL::RSA_DecryptPrivate((unsigned char*)sPrivate.c_str(), message_crypt, message_crypt_len, message_decrypt, message_decrypt_len);
|
||||
bDecrypt;
|
||||
|
||||
std::string sMessageOut((char*)message_decrypt, message_decrypt_len);
|
||||
|
||||
NSOpenSSL::openssl_free(message_crypt);
|
||||
NSOpenSSL::openssl_free(message_decrypt);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
std::string password = "{PASSWORD}";
|
||||
std::string message = "{MESSAGE}";
|
||||
std::string message_crypted = "";
|
||||
std::string message_decrypted = "";
|
||||
|
||||
NSOpenSSL::AES_Encrypt_desktop(password, message, message_crypted);
|
||||
NSOpenSSL::AES_Decrypt_desktop(password, message_crypted, message_decrypted);
|
||||
|
||||
message;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
28
Common/3dParty/openssl/test/test.pro
Normal file
28
Common/3dParty/openssl/test/test.pro
Normal file
@ -0,0 +1,28 @@
|
||||
QT -= core
|
||||
QT -= gui
|
||||
|
||||
TARGET = test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../../../core
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
############### destination path ###############
|
||||
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX
|
||||
################################################
|
||||
|
||||
INCLUDEPATH += $$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/include
|
||||
LIBS += -L$$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/lib -llibcrypto
|
||||
|
||||
core_windows:LIBS += -lws2_32 -lAdvapi32 -lCrypt32 -lUser32
|
||||
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
HEADERS += $$PWD_ROOT_DIR/../common/common_openssl.h
|
||||
SOURCES += $$PWD_ROOT_DIR/../common/common_openssl.cpp
|
||||
|
||||
SOURCES += main.cpp
|
||||
@ -1,33 +0,0 @@
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
SET PATH=%SCRIPTPATH%depot_tools;%PATH%
|
||||
SET DEPOT_TOOLS_WIN_TOOLCHAIN=0
|
||||
SET GYP_MSVS_VERSION=2015
|
||||
|
||||
call powershell -File .\fix-static_crt.ps1
|
||||
cd v8
|
||||
|
||||
call gn gen out.gn/win_64/release --args="is_debug=false target_cpu=\"x64\" v8_target_cpu=\"x64\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false"
|
||||
call ninja -C out.gn/win_64/release || goto :error
|
||||
|
||||
call gn gen out.gn/win_64/debug --args="is_debug=true target_cpu=\"x64\" v8_target_cpu=\"x64\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false"
|
||||
call ninja -C out.gn/win_64/debug || goto :error
|
||||
|
||||
call gn gen out.gn/win_32/release --args="is_debug=false target_cpu=\"x86\" v8_target_cpu=\"x86\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false"
|
||||
call ninja -C out.gn/win_32/release || goto :error
|
||||
|
||||
call gn gen out.gn/win_32/debug --args="is_debug=true target_cpu=\"x86\" v8_target_cpu=\"x86\" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false"
|
||||
call ninja -C out.gn/win_32/debug || goto :error
|
||||
|
||||
rem v8_use_snapshot=true v8_use_external_startup_data=true
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:xp=%" (
|
||||
call %~dp0v8_xp\build.bat || goto :error
|
||||
cd %~dp0
|
||||
)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:error
|
||||
echo "Failed with error #%errorlevel%."
|
||||
exit /b %errorlevel%
|
||||
@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PATH=`pwd`/depot_tools:"$PATH"
|
||||
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
Darwin*) platform="mac" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
architecture=$(uname -m)
|
||||
arch=""
|
||||
|
||||
case "$architecture" in
|
||||
x86_64*) arch="_64" ;;
|
||||
*) arch="_32" ;;
|
||||
esac
|
||||
|
||||
cd "$SCRIPTPATH/v8"
|
||||
|
||||
if [[ "$platform$arch" == "linux_64" ]]
|
||||
then
|
||||
gn gen out.gn/linux_64 --args='is_debug=false target_cpu="x64" v8_target_cpu="x64" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false use_sysroot=false'
|
||||
ninja -C out.gn/linux_64
|
||||
fi
|
||||
|
||||
if [[ "$platform$arch" == "linux_32" ]]
|
||||
then
|
||||
gn gen out.gn/linux_32 --args='is_debug=false target_cpu="x86" v8_target_cpu="x86" v8_static_library=true is_component_build=false v8_use_snapshot=false is_clang=false use_sysroot=false'
|
||||
ninja -C out.gn/linux_32
|
||||
fi
|
||||
|
||||
if [[ "$platform" == "mac" ]]
|
||||
then
|
||||
sed -i -e "s/if (mac_sdk_version != mac_sdk_min_build_override/if (false \&\& mac_sdk_version != mac_sdk_min_build_override/g" build/config/mac/mac_sdk.gni
|
||||
# for new macOS!!!
|
||||
#sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
|
||||
gn gen out.gn/mac_64 --args='is_debug=false target_cpu="x64" v8_static_library=true is_component_build=false v8_use_snapshot=false'
|
||||
ninja -C out.gn/mac_64
|
||||
fi
|
||||
@ -1,28 +0,0 @@
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
|
||||
SET DEPOT_TOOLS_WIN_TOOLCHAIN=0
|
||||
SET GYP_MSVS_VERSION=2015
|
||||
|
||||
if exist "depot_tools" (
|
||||
echo "depot_tools already fetched"
|
||||
) else (
|
||||
call git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
|
||||
call powershell -File .\fix-depot_tools.ps1
|
||||
)
|
||||
|
||||
SET PATH=%SCRIPTPATH%depot_tools;%PATH%
|
||||
|
||||
call gclient
|
||||
|
||||
call ./depot_tools/fetch v8
|
||||
cd v8
|
||||
call git checkout -b 6.0 -t branch-heads/6.0
|
||||
cd ../
|
||||
|
||||
call gclient sync --no-history
|
||||
|
||||
if not "%BUILD_PLATFORM%"=="%BUILD_PLATFORM:xp=%" (
|
||||
call v8_xp\fetch.bat
|
||||
cd %~dp0
|
||||
)
|
||||
@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
cd "$SCRIPTPATH"
|
||||
|
||||
if [ ! -d "depot_tools" ]
|
||||
then
|
||||
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
|
||||
fi
|
||||
|
||||
export PATH=`pwd`/depot_tools:"$PATH"
|
||||
gclient
|
||||
|
||||
#detect gcc version
|
||||
currentver="$(gcc -dumpversion)"
|
||||
requiredver="6.0.0"
|
||||
v8_version="6.0"
|
||||
|
||||
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]
|
||||
then
|
||||
v8_version="7.0"
|
||||
fi
|
||||
|
||||
echo "v8 version: $v8_version"
|
||||
|
||||
if [ ! -d "./v8" ]
|
||||
then
|
||||
fetch v8
|
||||
cd v8
|
||||
git checkout -b $v8_version -t branch-heads/$v8_version
|
||||
else
|
||||
cd v8
|
||||
fi
|
||||
|
||||
gclient sync --no-history
|
||||
|
||||
os=$(uname -s)
|
||||
platform=""
|
||||
case "$os" in
|
||||
Linux*) platform="linux" ;;
|
||||
*) exit ;;
|
||||
esac
|
||||
|
||||
cd "$SCRIPTPATH"
|
||||
|
||||
if [[ "$platform" == "linux" ]]
|
||||
then
|
||||
./fetch_linux_correct.sh
|
||||
fi
|
||||
@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
export PATH=`pwd`/depot_tools:"$PATH"
|
||||
|
||||
if [ -d "$SCRIPTPATH/v8/third_party/binutils/Linux_x64/Release" ]; then
|
||||
rm -rf "$SCRIPTPATH/v8/third_party/binutils/Linux_x64/Release"
|
||||
fi
|
||||
if [ -d "$SCRIPTPATH/v8/third_party/binutils/Linux_ia32/Release" ]; then
|
||||
rm -rf "$SCRIPTPATH/v8/third_party/binutils/Linux_ia32/Release"
|
||||
fi
|
||||
|
||||
cd "$SCRIPTPATH/v8"
|
||||
gclient sync --no-history
|
||||
|
||||
if [ -d "$SCRIPTPATH/v8/third_party/binutils/Linux_x64/Release/bin" ]; then
|
||||
cd "$SCRIPTPATH/v8/third_party/binutils/Linux_x64/Release/bin"
|
||||
for file in *
|
||||
do
|
||||
echo $file
|
||||
if [ $file != "ld.gold" ]
|
||||
then
|
||||
mv "$file" "old_${file}"
|
||||
ln -s /usr/bin/"$file" ./"$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -d "$SCRIPTPATH/v8/third_party/binutils/Linux_ia32/Release/bin" ]; then
|
||||
cd "$SCRIPTPATH/v8/third_party/binutils/Linux_ia32/Release/bin"
|
||||
for file in *
|
||||
do
|
||||
echo $file
|
||||
if [ $file != "ld.gold" ]
|
||||
then
|
||||
mv "$file" "old_${file}"
|
||||
ln -s /usr/bin/"$file" ./"$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@ -1,4 +0,0 @@
|
||||
$gclient_path = "depot_tools\gclient.bat"
|
||||
$fetch_path = "depot_tools\fetch.bat"
|
||||
(Get-Content $gclient_path) | ForEach-Object { $_ -replace "^(`"%~dp0python`")", "call $&" } | Set-Content $gclient_path
|
||||
(Get-Content $fetch_path) | ForEach-Object { $_ -replace "^(%~dp0python)", "call $&" } | Set-Content $fetch_path
|
||||
@ -1,2 +0,0 @@
|
||||
$gn_path = "v8\build\config\win\BUILD.gn"
|
||||
(Get-Content $gn_path) | ForEach-Object { $_ -replace ":static_crt", ":dynamic_crt" } | Set-Content $gn_path
|
||||
@ -343,9 +343,7 @@ namespace OOX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
{
|
||||
if ( oReader.IsEmptyNode() )
|
||||
return;
|
||||
@ -411,7 +409,13 @@ namespace OOX
|
||||
else if ( _T("w:sdt") == sName )
|
||||
pItem = new CSdt( oReader );
|
||||
else if ( _T("w:tblGrid") == sName )
|
||||
m_oTblGrid = oReader;
|
||||
{
|
||||
if (false == m_oTblGrid.IsInit())
|
||||
{
|
||||
m_oTblGrid = new CTblGrid();
|
||||
}
|
||||
m_oTblGrid->fromXML(oReader);
|
||||
}
|
||||
else if ( _T("w:tblPr") == sName )
|
||||
{
|
||||
pItem = m_oTableProperties = new CTableProperty( oReader );
|
||||
@ -657,7 +661,11 @@ namespace OOX
|
||||
}
|
||||
else if ( _T("w:trPr") == sName )
|
||||
{
|
||||
pItem = m_pTableRowProperties = new CTableRowProperties( oReader );
|
||||
if (!m_pTableRowProperties)
|
||||
{
|
||||
pItem = m_pTableRowProperties = new CTableRowProperties();
|
||||
}
|
||||
m_pTableRowProperties->fromXML(oReader);
|
||||
}
|
||||
|
||||
if ( pItem )
|
||||
@ -872,7 +880,12 @@ namespace OOX
|
||||
pItem = new CTbl( oReader );
|
||||
else if ( _T("w:tcPr") == sName )
|
||||
{
|
||||
pItem = m_pTableCellProperties = new CTableCellProperties( oReader );
|
||||
if (!m_pTableCellProperties)
|
||||
{
|
||||
pItem = m_pTableCellProperties = new CTableCellProperties();
|
||||
}
|
||||
|
||||
m_pTableCellProperties->fromXML(oReader);
|
||||
}
|
||||
|
||||
if ( pItem )
|
||||
@ -905,9 +918,8 @@ namespace OOX
|
||||
|
||||
return sResult;
|
||||
}
|
||||
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
|
||||
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
|
||||
{
|
||||
// Читаем атрибуты
|
||||
WritingElement_ReadAttributes_Start( oReader )
|
||||
WritingElement_ReadAttributes_ReadSingle( oReader, _T("w:id"), m_sId )
|
||||
WritingElement_ReadAttributes_End( oReader )
|
||||
|
||||
@ -438,15 +438,87 @@ namespace ComplexTypes
|
||||
m_oVertAnchor.Init();
|
||||
m_oVertAnchor->SetValue(SimpleTypes::vanchorMargin);
|
||||
}
|
||||
if(false == m_oTblpX.IsInit() && false == m_oTblpXSpec.IsInit())
|
||||
if(false == m_oTblpXSpec.IsInit())
|
||||
{
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignLeft);
|
||||
if(false == m_oTblpX.IsInit())
|
||||
{
|
||||
m_oTblpX.Init();
|
||||
m_oTblpX->FromTwips(0);
|
||||
}
|
||||
//Several values of sprmTDxaAbs have special meanings as specified by
|
||||
//[ECMA-376] Part 4, Section 2.18.114. These values are specified as
|
||||
//follows.
|
||||
switch(m_oTblpX->ToTwips())
|
||||
{
|
||||
case 0:
|
||||
m_oTblpX.reset(NULL);
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignLeft);
|
||||
break;
|
||||
case -4:
|
||||
m_oTblpX.reset(NULL);
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignCenter);
|
||||
break;
|
||||
case -8:
|
||||
m_oTblpX.reset(NULL);
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignRight);
|
||||
break;
|
||||
case -12:
|
||||
m_oTblpX.reset(NULL);
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignInside);
|
||||
break;
|
||||
case -16:
|
||||
m_oTblpX.reset(NULL);
|
||||
m_oTblpXSpec.Init();
|
||||
m_oTblpXSpec->SetValue(SimpleTypes::xalignOutside);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(false == m_oTblpY.IsInit() && false == m_oTblpYSpec.IsInit())
|
||||
if(false == m_oTblpYSpec.IsInit())
|
||||
{
|
||||
m_oTblpY.Init();
|
||||
m_oTblpY->FromTwips(0);
|
||||
if(false == m_oTblpY.IsInit())
|
||||
{
|
||||
m_oTblpY.Init();
|
||||
m_oTblpY->FromTwips(0);
|
||||
}
|
||||
//The meanings that are provided correspond to
|
||||
//values that are defined in [ECMA-376] Part 4, Section 2.18.115 ST_YAlign
|
||||
//(Vertical Alignment Location).
|
||||
switch(m_oTblpY->ToTwips())
|
||||
{
|
||||
case 0:
|
||||
m_oVertAnchor.Init();
|
||||
m_oVertAnchor->SetValue(SimpleTypes::vanchorText);
|
||||
break;
|
||||
case -4:
|
||||
m_oTblpY.reset(NULL);
|
||||
m_oTblpYSpec.Init();
|
||||
m_oTblpYSpec->SetValue(SimpleTypes::yalignTop);
|
||||
break;
|
||||
case -8:
|
||||
m_oTblpY.reset(NULL);
|
||||
m_oTblpYSpec.Init();
|
||||
m_oTblpYSpec->SetValue(SimpleTypes::yalignCenter);
|
||||
break;
|
||||
case -12:
|
||||
m_oTblpY.reset(NULL);
|
||||
m_oTblpYSpec.Init();
|
||||
m_oTblpYSpec->SetValue(SimpleTypes::yalignBottom);
|
||||
break;
|
||||
case -16:
|
||||
m_oTblpY.reset(NULL);
|
||||
m_oTblpYSpec.Init();
|
||||
m_oTblpYSpec->SetValue(SimpleTypes::yalignInside);
|
||||
break;
|
||||
case -20:
|
||||
m_oTblpY.reset(NULL);
|
||||
m_oTblpYSpec.Init();
|
||||
m_oTblpYSpec->SetValue(SimpleTypes::yalignOutside);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void FromXML(XmlUtils::CXmlNode& oNode)
|
||||
|
||||
@ -231,13 +231,11 @@ namespace XmlUtils
|
||||
|
||||
double d = 0;
|
||||
#if defined (_WIN32) || defined (_WIN64)
|
||||
swscanf_s(string.c_str(), L"%lf", &d);
|
||||
#elif defined(_IOS) || defined(__ANDROID__)
|
||||
swscanf(string.c_str(), L"%lf", &d);
|
||||
swscanf_s(string.c_str(), L"%lf", &d);
|
||||
#else
|
||||
_stscanf(string.c_str(), L"%lf", &d);
|
||||
swscanf(string.c_str(), L"%lf", &d);
|
||||
#endif
|
||||
return d;
|
||||
return d;
|
||||
}
|
||||
AVSINLINE static float GetFloat (const std::wstring& string)
|
||||
{
|
||||
@ -245,13 +243,11 @@ namespace XmlUtils
|
||||
|
||||
float f = 0;
|
||||
#if defined (_WIN32) || defined (_WIN64)
|
||||
swscanf_s(string.c_str(), L"%f", &f);
|
||||
#elif defined(_IOS) || defined(__ANDROID__)
|
||||
swscanf(string.c_str(), L"%f", &f);
|
||||
swscanf_s(string.c_str(), L"%f", &f);
|
||||
#else
|
||||
_stscanf(string.c_str(), L"%f", &f);
|
||||
swscanf(string.c_str(), L"%f", &f);
|
||||
#endif
|
||||
return f;
|
||||
return f;
|
||||
}
|
||||
AVSINLINE static std::wstring BoolToString (const bool & value)
|
||||
{
|
||||
|
||||
@ -2267,6 +2267,8 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\"
|
||||
m_oReadPath = oPath;
|
||||
IFileContainer::Read( oRootPath, oPath );
|
||||
|
||||
return;// todooo option read
|
||||
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
if ( !oReader.FromFile( oPath.GetPath() ) )
|
||||
|
||||
@ -47,6 +47,18 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
std::string wget_url_validate(const std::string& url)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
const char* url_ptr = url.c_str();
|
||||
while ('-' == *url_ptr++) // '\0' => break
|
||||
++pos;
|
||||
if (*url_ptr == '\0')
|
||||
return "";
|
||||
|
||||
return url.substr(pos);
|
||||
}
|
||||
|
||||
int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
|
||||
{
|
||||
int nReturnCode = -1;
|
||||
@ -68,13 +80,15 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
|
||||
|
||||
case 0: // child process
|
||||
{
|
||||
const char* nargs[6];
|
||||
const char* nargs[8];
|
||||
nargs[0] = "/usr/bin/curl";
|
||||
nargs[1] = sUrlA.c_str();
|
||||
nargs[2] = "--output";
|
||||
nargs[3] = sOutputA.c_str();
|
||||
nargs[4] = "--silent";
|
||||
nargs[5] = NULL;
|
||||
nargs[1] = "--url";
|
||||
nargs[2] = sUrlA.c_str();
|
||||
nargs[3] = "--output";
|
||||
nargs[4] = sOutputA.c_str();
|
||||
nargs[5] = "--silent";
|
||||
nargs[6] = "-L";
|
||||
nargs[7] = NULL;
|
||||
|
||||
const char* nenv[3];
|
||||
nenv[0] = "LD_PRELOAD=";
|
||||
@ -97,6 +111,8 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
|
||||
|
||||
if (0 != nReturnCode && NSFile::CFileBinary::Exists(L"/usr/bin/wget"))
|
||||
{
|
||||
std::string sUrlValidateA = wget_url_validate(sUrlA);
|
||||
|
||||
pid_t pid = fork(); // create child process
|
||||
int status;
|
||||
|
||||
@ -109,7 +125,7 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
|
||||
{
|
||||
const char* nargs[6];
|
||||
nargs[0] = "/usr/bin/wget";
|
||||
nargs[1] = sUrlA.c_str();
|
||||
nargs[1] = sUrlValidateA.c_str();
|
||||
nargs[2] = "-O";
|
||||
nargs[3] = sOutputA.c_str();
|
||||
nargs[4] = "-q";
|
||||
|
||||
@ -6,7 +6,7 @@ BUILD_NUMBER = $$(BUILD_NUMBER)
|
||||
!isEmpty(PRODUCT_VERSION){
|
||||
!isEmpty(BUILD_NUMBER){
|
||||
VERSION = $${PRODUCT_VERSION}.$${BUILD_NUMBER}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEFINES += INTVER=$$VERSION
|
||||
@ -17,7 +17,11 @@ isEmpty(PUBLISHER_NAME){
|
||||
}
|
||||
|
||||
win32 {
|
||||
CURRENT_YEAR = $$system("echo %Date:~6,4%")
|
||||
CURRENT_YEAR = $$system(wmic PATH Win32_LocalTime GET ^Year /FORMAT:VALUE | find \"=\")
|
||||
CURRENT_YEAR = $$replace(CURRENT_YEAR, "Year=", "")
|
||||
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\r", "")
|
||||
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\n", "")
|
||||
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\t", "")
|
||||
}
|
||||
|
||||
!win32 {
|
||||
@ -63,6 +67,8 @@ isEqual(QT_MAJOR_VERSION, 5) {
|
||||
}
|
||||
}
|
||||
|
||||
DEFINES += INTERNAL_USE_ARRAY_AS_VECTOR
|
||||
|
||||
ios {
|
||||
CONFIG += core_ios
|
||||
DEFINES += _IOS IOS LINUX _LINUX MAC _MAC _XCODE
|
||||
@ -131,6 +137,7 @@ core_linux {
|
||||
core_mac {
|
||||
DEFINES += LINUX _LINUX MAC _MAC
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
QMAKE_LFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
|
||||
}
|
||||
|
||||
# PREFIXES
|
||||
@ -145,15 +152,17 @@ core_windows {
|
||||
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.02
|
||||
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
|
||||
} else {
|
||||
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.02
|
||||
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.01
|
||||
core_win_64:QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.02
|
||||
core_win_32:QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core_linux {
|
||||
equals(TEMPLATE, app) {
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./:./system
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/system\'"
|
||||
QMAKE_LFLAGS += -Wl,--disable-new-dtags
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,6 +295,12 @@ OBJECTS_DIR = $$PWD_ROOT_DIR/core_build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUI
|
||||
MOC_DIR = $$PWD_ROOT_DIR/core_build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX/moc
|
||||
RCC_DIR = $$PWD_ROOT_DIR/core_build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX/rcc
|
||||
UI_DIR = $$PWD_ROOT_DIR/core_build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX/ui
|
||||
build_xp {
|
||||
OBJECTS_DIR = $$OBJECTS_DIR/xp
|
||||
MOC_DIR = $$MOC_DIR/xp
|
||||
RCC_DIR = $$RCC_DIR/xp
|
||||
UI_DIR = $$UI_DIR/xp
|
||||
}
|
||||
}
|
||||
|
||||
CORE_BUILDS_LIBRARIES_PATH = $$CORE_ROOT_DIR/build/lib/$$CORE_BUILDS_PLATFORM_PREFIX
|
||||
|
||||
@ -392,6 +392,7 @@ namespace NSCommon
|
||||
{
|
||||
NSFonts::IFontManager* pManager = applicationFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pCache = NSFonts::NSFontCache::Create();
|
||||
pCache->SetCacheSize(3);
|
||||
pCache->SetStreams(applicationFonts->GetStreams());
|
||||
pManager->SetOwnerCache(pCache);
|
||||
|
||||
@ -427,6 +428,9 @@ namespace NSCommon
|
||||
pRenderer->put_Width(lWidthPix * 25.4 / dDpi);
|
||||
pRenderer->put_Height(lHeightPix * 25.4 / dDpi);
|
||||
|
||||
bool isUseMapForStreams = false;
|
||||
std::map<std::wstring, bool> mapUsedFiles;
|
||||
|
||||
for (int index = 0; index < nCountFonts; ++index)
|
||||
{
|
||||
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
|
||||
@ -476,6 +480,9 @@ namespace NSCommon
|
||||
|
||||
if (NULL != pInfoCur)
|
||||
{
|
||||
if (isUseMapForStreams)
|
||||
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
|
||||
|
||||
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
|
||||
}
|
||||
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
|
||||
@ -503,6 +510,9 @@ namespace NSCommon
|
||||
|
||||
if (NULL != pInfoCur)
|
||||
{
|
||||
if (isUseMapForStreams)
|
||||
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
|
||||
|
||||
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
|
||||
}
|
||||
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
|
||||
@ -514,6 +524,11 @@ namespace NSCommon
|
||||
pRenderer->put_FontSize(14);
|
||||
|
||||
pRenderer->CommandDrawText(pPair->second.m_sName, 5, 25.4 * (index * lH1_px + lH1_px) / dDpi - 2, 0, 0);
|
||||
|
||||
if (isUseMapForStreams)
|
||||
applicationFonts->GetStreams()->CheckStreams(mapUsedFiles);
|
||||
else
|
||||
applicationFonts->GetStreams()->Clear();
|
||||
}
|
||||
|
||||
std::wstring strThumbnailPath = strFolderThumbnails + L"/fonts_thumbnail";
|
||||
@ -1210,6 +1225,22 @@ std::wstring CorrectDir(const std::wstring& sDir)
|
||||
return sDir.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
std::wstring CorrectValue(const std::wstring& value)
|
||||
{
|
||||
if (value.empty())
|
||||
return L"";
|
||||
|
||||
const wchar_t* data = value.c_str();
|
||||
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = value.length();
|
||||
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
|
||||
return value.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int wmain(int argc, wchar_t** argv)
|
||||
#else
|
||||
@ -1252,6 +1283,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (sKey == L"--use-system")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
if (sValue == L"1" || sValue == L"true")
|
||||
bIsUseSystemFonts = true;
|
||||
}
|
||||
@ -1283,7 +1315,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if (srcPrev != src)
|
||||
{
|
||||
arFontsDirs.push_back(std::wstring(srcPrev, src - srcPrev));
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
src++;
|
||||
srcPrev = src;
|
||||
@ -1294,7 +1326,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (src > srcPrev)
|
||||
{
|
||||
arFontsDirs.push_back(std::wstring(srcPrev, src - srcPrev));
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
}
|
||||
else if (sKey == L"--output-web")
|
||||
|
||||
@ -791,4 +791,42 @@
|
||||
#define ASC_EVENT_TYPE_SPELLCHECK_MESSAGE 22004
|
||||
#define ASC_EVENT_TYPE_SPELLCHECK_TURN_ON 22005
|
||||
|
||||
#define ASC_MENU_EVENT_TYPE_DO_NONPRINTING_DISPLAY 22006
|
||||
|
||||
// Comments
|
||||
#define ASC_MENU_EVENT_TYPE_ADD_COMMENT 23001
|
||||
#define ASC_MENU_EVENT_TYPE_ADD_COMMENTS 23002
|
||||
#define ASC_MENU_EVENT_TYPE_REMOVE_COMMENT 23003
|
||||
#define ASC_MENU_EVENT_TYPE_CHANGE_COMMENTS 23004
|
||||
#define ASC_MENU_EVENT_TYPE_REMOVE_COMMENTS 23005
|
||||
#define ASC_MENU_EVENT_TYPE_CHANGE_COMMENT_DATA 23006
|
||||
#define ASC_MENU_EVENT_TYPE_LOCK_COMMENT 23007
|
||||
#define ASC_MENU_EVENT_TYPE_UNLOCK_COMMENT 23008
|
||||
#define ASC_MENU_EVENT_TYPE_SHOW_COMMENT 23009
|
||||
#define ASC_MENU_EVENT_TYPE_HIDE_COMMENT 23010
|
||||
#define ASC_MENU_EVENT_TYPE_UPDATE_COMMENT_POSITION 23011
|
||||
#define ASC_MENU_EVENT_TYPE_DOCUMENT_PLACE_CHANGED 23012
|
||||
#define ASC_MENU_EVENT_TYPE_DO_SELECT_COMMENT 23101
|
||||
#define ASC_MENU_EVENT_TYPE_DO_SHOW_COMMENT 23102
|
||||
#define ASC_MENU_EVENT_TYPE_DO_SELECT_COMMENTS 23103
|
||||
#define ASC_MENU_EVENT_TYPE_DO_DESELECT_COMMENTS 23104
|
||||
#define ASC_MENU_EVENT_TYPE_DO_ADD_COMMENT 23105
|
||||
#define ASC_MENU_EVENT_TYPE_DO_REMOVE_COMMENT 23106
|
||||
#define ASC_MENU_EVENT_TYPE_DO_REMOVE_ALL_COMMENTS 23107
|
||||
#define ASC_MENU_EVENT_TYPE_DO_CHANGE_COMMENT 23108
|
||||
|
||||
// Track reviews
|
||||
#define ASC_MENU_EVENT_TYPE_SHOW_REVISIONS_CHANGE 24001
|
||||
|
||||
#define ASC_MENU_EVENT_TYPE_DO_SET_TRACK_REVISIONS 24101
|
||||
#define ASC_MENU_EVENT_TYPE_DO_BEGIN_VIEWMODE_IN_REVIEW 24102
|
||||
#define ASC_MENU_EVENT_TYPE_DO_END_VIEWMODE_IN_REVIEW 24103
|
||||
#define ASC_MENU_EVENT_TYPE_DO_ACCEPT_ALL_CHANGES 24104
|
||||
#define ASC_MENU_EVENT_TYPE_DO_REJECT_ALL_CHANGES 24105
|
||||
#define ASC_MENU_EVENT_TYPE_DO_GET_PREV_REVISIONS_CHANGE 24106
|
||||
#define ASC_MENU_EVENT_TYPE_DO_GET_NEXT_REVISIONS_CHANGE 24107
|
||||
#define ASC_MENU_EVENT_TYPE_DO_ACCEPT_CHANGES 24108
|
||||
#define ASC_MENU_EVENT_TYPE_DO_REJECT_CHANGES 24109
|
||||
#define ASC_MENU_EVENT_TYPE_DO_FOLLOW_REVISION_MOVE 24110
|
||||
|
||||
#endif //_BUILD_EDITOR_DEFINES_CROSSPLATFORM_H_
|
||||
|
||||
@ -72,6 +72,21 @@ std::wstring CorrectDir(const std::wstring& sDir)
|
||||
|
||||
return sDir.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
std::wstring CorrectValue(const std::wstring& value)
|
||||
{
|
||||
if (value.empty())
|
||||
return L"";
|
||||
|
||||
const wchar_t* data = value.c_str();
|
||||
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = value.length();
|
||||
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
|
||||
return value.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
@ -308,6 +323,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (sKey == L"--change-sdk")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
if (L"1" == sValue || L"true" == sValue)
|
||||
{
|
||||
bIsNeedCorrectSdkAll = true;
|
||||
@ -315,6 +331,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (sKey == L"--allfonts")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
sAllFonts = sValue;
|
||||
}
|
||||
else if (sKey == L"--params")
|
||||
|
||||
@ -35,7 +35,9 @@
|
||||
#include "Types.h"
|
||||
#include <string.h>
|
||||
|
||||
#if 0 //__APPLE__
|
||||
#ifdef INTERNAL_USE_ARRAY_AS_VECTOR
|
||||
|
||||
// Use std::vector instead this class
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -87,7 +89,7 @@ public:
|
||||
|
||||
for (int i = 0; i < nAllocSize; i++)
|
||||
Add();
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -137,6 +139,11 @@ public:
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
return m_aT.data();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@ -50,11 +50,13 @@
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '\\'
|
||||
#define FILE_SEPARATOR_STR L"\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR_STRA "\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '/'
|
||||
#define FILE_SEPARATOR_STR L"/"
|
||||
#endif
|
||||
#define FILE_SEPARATOR_STRA "/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../../Common/kernel_config.h"
|
||||
|
||||
@ -648,6 +648,8 @@ namespace NSDoctRenderer
|
||||
}
|
||||
void CDocBuilder::SetTmpFolder(const wchar_t* folder)
|
||||
{
|
||||
if (m_pInternal->m_bIsServerSafeVersion)
|
||||
return;
|
||||
m_pInternal->m_sTmpFolder = std::wstring(folder);
|
||||
}
|
||||
void CDocBuilder::CloseFile()
|
||||
@ -907,7 +909,10 @@ namespace NSDoctRenderer
|
||||
else if (sParam == "--cache-scripts")
|
||||
m_pInternal->m_bIsCacheScript = (std::wstring(value) == L"true");
|
||||
else if (sParam == "--save-use-only-names")
|
||||
{
|
||||
m_pInternal->m_bIsServerSafeVersion = true;
|
||||
m_pInternal->m_sFolderForSaveOnlyUseNames = std::wstring(value);
|
||||
}
|
||||
else if (sParam == "--all-fonts-path")
|
||||
{
|
||||
m_pInternal->m_strAllFonts = std::wstring(value);
|
||||
|
||||
@ -186,6 +186,7 @@ namespace NSDoctRenderer
|
||||
|
||||
bool m_bIsCacheScript;
|
||||
|
||||
bool m_bIsServerSafeVersion;
|
||||
std::wstring m_sFolderForSaveOnlyUseNames;
|
||||
|
||||
std::string m_sGlobalVariable;
|
||||
@ -214,6 +215,7 @@ namespace NSDoctRenderer
|
||||
m_bIsGlobalVariableUse = false;
|
||||
|
||||
m_bIsNotUseConfigAllFontsDir = false;
|
||||
m_bIsServerSafeVersion = false;
|
||||
}
|
||||
|
||||
void Init()
|
||||
@ -551,6 +553,10 @@ namespace NSDoctRenderer
|
||||
}
|
||||
#endif
|
||||
|
||||
// не открываем локальные файлы в серверной версии.
|
||||
if (m_bIsServerSafeVersion)
|
||||
return;
|
||||
|
||||
NSFile::CFileBinary::Copy(from, to);
|
||||
}
|
||||
|
||||
|
||||
@ -25,10 +25,6 @@ ADD_DEPENDENCY(graphics, kernel, UnicodeConverter)
|
||||
} else {
|
||||
DEFINES += V8_OS_XP
|
||||
DESTDIR=$$DESTDIR/xp
|
||||
OBJECTS_DIR = $$OBJECTS_DIR/xp
|
||||
MOC_DIR = $$MOC_DIR/xp
|
||||
RCC_DIR = $$RCC_DIR/xp
|
||||
UI_DIR = $$UI_DIR/xp
|
||||
include(../../Common/3dParty/v8/v8_xp/v8.pri)
|
||||
}
|
||||
|
||||
|
||||
@ -778,7 +778,7 @@ int CFontList::GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed)
|
||||
}
|
||||
|
||||
CFontListNamePicker CFontList::m_oPicker;
|
||||
int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, bool bIsUseNamePicker)
|
||||
int CFontList::GetFaceNamePenalty(const std::wstring& sCandName, const std::wstring& sReqName, bool bIsUseNamePicker)
|
||||
{
|
||||
if ( 0 == sReqName.length() )
|
||||
return 0;
|
||||
@ -789,6 +789,9 @@ int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName,
|
||||
if ( sReqName == sCandName )
|
||||
return 0;
|
||||
|
||||
if (CFontListNamePicker::IsEqualsFontsAdvanced(sCandName, sReqName))
|
||||
return 100;
|
||||
|
||||
if ( std::wstring::npos != sReqName.find( sCandName ) || std::wstring::npos != sCandName.find( sReqName ) )
|
||||
{
|
||||
if (m_oPicker.IsLikeFonts(sCandName, sReqName))
|
||||
@ -1010,6 +1013,93 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory,
|
||||
*pLen = (LONG)(pDataMem - pData);
|
||||
}
|
||||
|
||||
class CFontSelectFormatCorrection
|
||||
{
|
||||
private:
|
||||
std::wstring* m_oldName;
|
||||
INT* m_oldBold;
|
||||
INT* m_oldItalic;
|
||||
|
||||
public:
|
||||
CFontSelectFormatCorrection()
|
||||
{
|
||||
m_oldName = NULL;
|
||||
m_oldBold = NULL;
|
||||
m_oldItalic = NULL;
|
||||
}
|
||||
|
||||
static CFontSelectFormatCorrection* CheckCorrection(NSFonts::CFontSelectFormat& oSelect)
|
||||
{
|
||||
// пробуем "подправить" настройки
|
||||
std::wstring sName = *oSelect.wsName;
|
||||
NSFonts::makeLower(sName);
|
||||
|
||||
INT* oldBold = NULL;
|
||||
INT* oldItalic = NULL;
|
||||
|
||||
bool isCorrect = false;
|
||||
if (std::wstring::npos != sName.find(L"bold"))
|
||||
{
|
||||
isCorrect = true;
|
||||
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = sName.find(L"bold", posn)))
|
||||
sName.erase(posn, 4);
|
||||
|
||||
oldBold = oSelect.bBold;
|
||||
if (!oSelect.bBold)
|
||||
oSelect.bBold = new INT(TRUE);
|
||||
}
|
||||
if (std::wstring::npos != sName.find(L"italic") ||
|
||||
std::wstring::npos != sName.find(L"oblique"))
|
||||
{
|
||||
isCorrect = true;
|
||||
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = sName.find(L"italic", posn)))
|
||||
sName.erase(posn, 6);
|
||||
while (std::wstring::npos != (posn = sName.find(L"oblique", posn)))
|
||||
sName.erase(posn, 7);
|
||||
|
||||
oldItalic = oSelect.bItalic;
|
||||
if (!oSelect.bItalic)
|
||||
oSelect.bItalic = new INT(TRUE);
|
||||
}
|
||||
|
||||
if (!isCorrect)
|
||||
return NULL;
|
||||
|
||||
CFontSelectFormatCorrection* pCorrection = new CFontSelectFormatCorrection();
|
||||
pCorrection->m_oldName = oSelect.wsName;
|
||||
oSelect.wsName = new std::wstring(sName);
|
||||
pCorrection->m_oldBold = oldBold;
|
||||
pCorrection->m_oldItalic = oldItalic;
|
||||
|
||||
return pCorrection;
|
||||
}
|
||||
|
||||
void Restore(NSFonts::CFontSelectFormat& oSelect)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.wsName));
|
||||
oSelect.wsName = m_oldName;
|
||||
|
||||
if (m_oldBold != oSelect.bBold)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.bBold));
|
||||
oSelect.bBold = m_oldBold;
|
||||
}
|
||||
if (m_oldItalic != oSelect.bItalic)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.bItalic));
|
||||
oSelect.bItalic = m_oldItalic;
|
||||
}
|
||||
|
||||
m_oldName = NULL;
|
||||
m_oldBold = NULL;
|
||||
m_oldItalic = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect, bool bIsDictionaryUse)
|
||||
{
|
||||
int nFontsCount = m_pList.size();
|
||||
@ -1026,104 +1116,127 @@ NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect,
|
||||
int nMinPenalty = -1; // Минимальный вес
|
||||
|
||||
int nDefPenalty = 2147483647;
|
||||
|
||||
NSFonts::CFontInfo* pInfoMin = NULL;
|
||||
for (std::vector<NSFonts::CFontInfo*>::iterator iter = m_pList.begin(); iter != m_pList.end(); iter++)
|
||||
{
|
||||
int nCurPenalty = 0;
|
||||
NSFonts::CFontInfo* pInfo = *iter;
|
||||
CFontSelectFormatCorrection* pSelectCorrection = NULL;
|
||||
|
||||
if ( NULL != oSelect.pPanose )
|
||||
{
|
||||
nCurPenalty += GetPanosePenalty( pInfo->m_aPanose, oSelect.pPanose );
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
for (std::vector<NSFonts::CFontInfo*>::iterator iter = m_pList.begin(); iter != m_pList.end(); iter++)
|
||||
{
|
||||
int nCurPenalty = 0;
|
||||
NSFonts::CFontInfo* pInfo = *iter;
|
||||
|
||||
ULONG arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
|
||||
|
||||
if (true)
|
||||
{
|
||||
if (NULL != oSelect.ulRange1 &&
|
||||
NULL != oSelect.ulRange2 &&
|
||||
NULL != oSelect.ulRange3 &&
|
||||
NULL != oSelect.ulRange4 &&
|
||||
NULL != oSelect.ulCodeRange1 &&
|
||||
NULL != oSelect.ulCodeRange2)
|
||||
{
|
||||
ULONG arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
|
||||
nCurPenalty += GetSigPenalty( arrCandRanges, arrReqRanges, nCurPenalty >= 1000 ? 50 : 10, 10 );
|
||||
}
|
||||
}
|
||||
if ( NULL != oSelect.pPanose )
|
||||
{
|
||||
nCurPenalty += GetPanosePenalty( pInfo->m_aPanose, oSelect.pPanose );
|
||||
}
|
||||
|
||||
unsigned char unCharset = UNKNOWN_CHARSET;
|
||||
if (NULL != oSelect.unCharset)
|
||||
unCharset = *oSelect.unCharset;
|
||||
ULONG arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
|
||||
|
||||
if ( NULL != oSelect.bFixedWidth )
|
||||
nCurPenalty += GetFixedPitchPenalty( pInfo->m_bIsFixed, *oSelect.bFixedWidth );
|
||||
if (true)
|
||||
{
|
||||
if (NULL != oSelect.ulRange1 &&
|
||||
NULL != oSelect.ulRange2 &&
|
||||
NULL != oSelect.ulRange3 &&
|
||||
NULL != oSelect.ulRange4 &&
|
||||
NULL != oSelect.ulCodeRange1 &&
|
||||
NULL != oSelect.ulCodeRange2)
|
||||
{
|
||||
ULONG arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
|
||||
nCurPenalty += GetSigPenalty( arrCandRanges, arrReqRanges, nCurPenalty >= 1000 ? 50 : 10, 10 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL )
|
||||
{
|
||||
nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true ),
|
||||
GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true ) );
|
||||
}
|
||||
else if ( oSelect.wsName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true );
|
||||
else if ( oSelect.wsAltName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true );
|
||||
unsigned char unCharset = UNKNOWN_CHARSET;
|
||||
if (NULL != oSelect.unCharset)
|
||||
unCharset = *oSelect.unCharset;
|
||||
|
||||
if ( NULL != oSelect.usWidth )
|
||||
nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth );
|
||||
if ( NULL != oSelect.bFixedWidth )
|
||||
nCurPenalty += GetFixedPitchPenalty( pInfo->m_bIsFixed, *oSelect.bFixedWidth );
|
||||
|
||||
if ( NULL != oSelect.usWeight )
|
||||
nCurPenalty += GetWeightPenalty( pInfo->m_usWeigth, *oSelect.usWeight );
|
||||
if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL )
|
||||
{
|
||||
nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true ),
|
||||
GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true ) );
|
||||
}
|
||||
else if ( oSelect.wsName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true );
|
||||
else if ( oSelect.wsAltName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true );
|
||||
|
||||
if ( NULL != oSelect.bBold )
|
||||
nCurPenalty += GetBoldPenalty( pInfo->m_bBold, *oSelect.bBold );
|
||||
if ( NULL != oSelect.usWidth )
|
||||
nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth );
|
||||
|
||||
if ( NULL != oSelect.bItalic )
|
||||
nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, *oSelect.bItalic );
|
||||
if ( NULL != oSelect.usWeight )
|
||||
nCurPenalty += GetWeightPenalty( pInfo->m_usWeigth, *oSelect.usWeight );
|
||||
|
||||
if ( NULL != oSelect.wsFamilyClass )
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.wsFamilyClass );
|
||||
else if (NULL != oSelect.sFamilyClass)
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.sFamilyClass );
|
||||
|
||||
//nCurPenalty += GetFontFormatPenalty( pInfo->m_eFontFormat, fontTrueType );
|
||||
nCurPenalty += GetCharsetPenalty( arrCandRanges, unCharset );
|
||||
//if ( NULL != oSelect.bBold )
|
||||
// nCurPenalty += GetBoldPenalty( pInfo->m_bBold, *oSelect.bBold );
|
||||
//if ( NULL != oSelect.bItalic )
|
||||
// nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, *oSelect.bItalic );
|
||||
|
||||
if ( NULL != oSelect.shAvgCharWidth )
|
||||
nCurPenalty += GetAvgWidthPenalty( pInfo->m_shAvgCharWidth, *oSelect.shAvgCharWidth );
|
||||
// проверяем всегда!!! иначе только по имени может подобраться болд, и появляется зависимость от порядка шрифтов
|
||||
nCurPenalty += GetBoldPenalty( pInfo->m_bBold, (NULL != oSelect.bBold) ? *oSelect.bBold : FALSE );
|
||||
nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, (NULL != oSelect.bItalic) ? *oSelect.bItalic : FALSE );
|
||||
|
||||
if ( NULL != oSelect.shAscent )
|
||||
nCurPenalty += GetAscentPenalty( pInfo->m_shAscent, *oSelect.shAscent );
|
||||
if ( NULL != oSelect.wsFamilyClass )
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.wsFamilyClass );
|
||||
else if (NULL != oSelect.sFamilyClass)
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.sFamilyClass );
|
||||
|
||||
if ( NULL != oSelect.shDescent )
|
||||
nCurPenalty += GetDescentPenalty( pInfo->m_shDescent, *oSelect.shDescent );
|
||||
//nCurPenalty += GetFontFormatPenalty( pInfo->m_eFontFormat, fontTrueType );
|
||||
nCurPenalty += GetCharsetPenalty( arrCandRanges, unCharset );
|
||||
|
||||
if ( NULL != oSelect.shLineGap )
|
||||
nCurPenalty += GetLineGapPenalty( pInfo->m_shLineGap, *oSelect.shLineGap );
|
||||
if ( NULL != oSelect.shAvgCharWidth )
|
||||
nCurPenalty += GetAvgWidthPenalty( pInfo->m_shAvgCharWidth, *oSelect.shAvgCharWidth );
|
||||
|
||||
if ( NULL != oSelect.shXHeight )
|
||||
nCurPenalty += GetXHeightPenalty( pInfo->m_shXHeight, *oSelect.shXHeight );
|
||||
if ( NULL != oSelect.shAscent )
|
||||
nCurPenalty += GetAscentPenalty( pInfo->m_shAscent, *oSelect.shAscent );
|
||||
|
||||
if ( NULL != oSelect.shCapHeight )
|
||||
nCurPenalty += GetCapHeightPenalty( pInfo->m_shCapHeight, *oSelect.shCapHeight );
|
||||
if ( NULL != oSelect.shDescent )
|
||||
nCurPenalty += GetDescentPenalty( pInfo->m_shDescent, *oSelect.shDescent );
|
||||
|
||||
if ( nMinPenalty < 0 )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
else if ( nCurPenalty < nMinPenalty )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
if ( NULL != oSelect.shLineGap )
|
||||
nCurPenalty += GetLineGapPenalty( pInfo->m_shLineGap, *oSelect.shLineGap );
|
||||
|
||||
// Нашелся шрифт, удовлетворяющий всем параметрам, дальше искать нет смысла
|
||||
if ( 0 == nCurPenalty )
|
||||
break;
|
||||
}
|
||||
if ( NULL != oSelect.shXHeight )
|
||||
nCurPenalty += GetXHeightPenalty( pInfo->m_shXHeight, *oSelect.shXHeight );
|
||||
|
||||
if ( NULL != oSelect.shCapHeight )
|
||||
nCurPenalty += GetCapHeightPenalty( pInfo->m_shCapHeight, *oSelect.shCapHeight );
|
||||
|
||||
if ( nMinPenalty < 0 )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
else if ( nCurPenalty < nMinPenalty )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
|
||||
// Нашелся шрифт, удовлетворяющий всем параметрам, дальше искать нет смысла
|
||||
if ( 0 == nCurPenalty )
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == nMinPenalty)
|
||||
break;
|
||||
|
||||
if (NULL == oSelect.wsName || pSelectCorrection)
|
||||
break;
|
||||
|
||||
pSelectCorrection = CFontSelectFormatCorrection::CheckCorrection(oSelect);
|
||||
if (NULL == pSelectCorrection)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pSelectCorrection)
|
||||
{
|
||||
pSelectCorrection->Restore(oSelect);
|
||||
RELEASEOBJECT(pSelectCorrection);
|
||||
}
|
||||
|
||||
return pInfoMin;
|
||||
}
|
||||
|
||||
@ -186,6 +186,17 @@ public:
|
||||
return 1500;
|
||||
}
|
||||
|
||||
return IsEqualsFontsAdvanced(name, req) ? 3000 : 10000;
|
||||
}
|
||||
|
||||
static bool IsEqualsFontsAdvanced(const std::wstring& name, const std::wstring& req)
|
||||
{
|
||||
int lenName = (int)name.length();
|
||||
int lenReq = (int)req.length();
|
||||
|
||||
const wchar_t* pName = name.c_str();
|
||||
const wchar_t* pReq = req.c_str();
|
||||
|
||||
pName = name.c_str();
|
||||
pReq = req.c_str();
|
||||
|
||||
@ -232,7 +243,7 @@ public:
|
||||
delete [] pNameD;
|
||||
delete [] pReqD;
|
||||
|
||||
return bIsEq ? 3000 : 10000;
|
||||
return bIsEq;
|
||||
}
|
||||
};
|
||||
|
||||
@ -273,7 +284,7 @@ private:
|
||||
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
|
||||
int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
|
||||
int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed);
|
||||
int GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, bool bIsUseNamePicker = false);
|
||||
int GetFaceNamePenalty(const std::wstring& sCandName, const std::wstring& sReqName, bool bIsUseNamePicker = false);
|
||||
int GetFamilyUnlikelyPenalty(SHORT nCandFamilyClass, SHORT nReqFamilyClass);
|
||||
int GetFamilyUnlikelyPenalty(int nCandFamilyClass, std::wstring sReqFamilyClass);
|
||||
int GetWidthPenalty(USHORT usCandWidth, USHORT usReqWidth);
|
||||
|
||||
@ -119,6 +119,8 @@ NSFonts::IApplicationFonts* CApplicationFontsWorker::Check()
|
||||
NSDirectory::GetFiles2(*i, strFontsW_Cur, true);
|
||||
}
|
||||
|
||||
std::sort(strFontsW_Cur.begin(), strFontsW_Cur.end());
|
||||
|
||||
bool bIsEqual = true;
|
||||
if (strFonts.size() != strFontsW_Cur.size())
|
||||
bIsEqual = false;
|
||||
|
||||
@ -104,7 +104,19 @@ NSFonts::IFontStream* CApplicationFontStreams::GetStream(const std::wstring &str
|
||||
}
|
||||
void CApplicationFontStreams::CheckStreams(std::map<std::wstring,bool> &mapFiles)
|
||||
{
|
||||
// TODO:
|
||||
std::map<std::wstring, CFontStream*>::iterator iter = m_mapStreams.begin();
|
||||
while (iter != m_mapStreams.end())
|
||||
{
|
||||
CFontStream* pFile = iter->second;
|
||||
|
||||
if (mapFiles.find(iter->first) != mapFiles.end())
|
||||
{
|
||||
iter = m_mapStreams.erase(iter);
|
||||
RELEASEINTERFACE(pFile);
|
||||
}
|
||||
else
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void CApplicationFontStreams::Clear()
|
||||
|
||||
@ -679,7 +679,7 @@ HRESULT CGraphicsRenderer::CommandDrawTextExCHAR(const LONG& c, const LONG& gid,
|
||||
|
||||
HRESULT CGraphicsRenderer::CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
|
||||
{
|
||||
if (NULL != pGids)
|
||||
if (NULL != pGids && 0 != nGidsCount && !(1 == nGidsCount && 0 == *pGids))
|
||||
{
|
||||
m_oFont.StringGID = TRUE;
|
||||
if (c_nHyperlinkType == m_lCurrentCommandType)
|
||||
|
||||
@ -19,14 +19,6 @@ include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
DEFINES -= UNICODE
|
||||
|
||||
core_linux {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
core_mac {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
include/XmlCertificate.h \
|
||||
include/OOXMLSigner.h \
|
||||
@ -51,10 +43,12 @@ HEADERS += \
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lws2_32
|
||||
LIBS += -lUser32
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
!core_windows {
|
||||
|
||||
HEADERS += \
|
||||
src/XmlSigner_openssl.h
|
||||
@ -64,8 +58,6 @@ SOURCES += \
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
|
||||
CONFIG += open_ssl_common
|
||||
include(../../../Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
}
|
||||
build_xp:DESTDIR=$$DESTDIR/xp
|
||||
|
||||
@ -616,7 +616,7 @@ public:
|
||||
|
||||
void RemoveSignature(const std::string& sGuid)
|
||||
{
|
||||
int nCountSignatures = m_arSignatures.size();
|
||||
int nCountSignatures = (int)m_arSignatures.size();
|
||||
if (0 == nCountSignatures)
|
||||
return;
|
||||
|
||||
|
||||
@ -49,17 +49,103 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern char** environ;
|
||||
|
||||
char** linux_environ_get(const std::string& str_library_path = "")
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; environ[i] != NULL; i++)
|
||||
++count;
|
||||
count += 2;
|
||||
|
||||
char** env = new char*[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
env[i] = NULL;
|
||||
|
||||
bool is_ld_library_path = false;
|
||||
for (int i = 0; environ[i] != NULL; i++)
|
||||
{
|
||||
std::string s = environ[i];
|
||||
if (0 == s.find("LD_LIBRARY_PATH"))
|
||||
{
|
||||
s += (":" + str_library_path);
|
||||
is_ld_library_path = true;
|
||||
}
|
||||
env[i] = new char[s.length() + 1];
|
||||
memcpy(env[i], s.c_str(), s.length() * sizeof(char));
|
||||
env[i][s.length()] = '\0';
|
||||
}
|
||||
if (!is_ld_library_path)
|
||||
{
|
||||
int index = count - 2;
|
||||
std::string s = "LD_LIBRARY_PATH=";
|
||||
s += str_library_path;
|
||||
env[index] = new char[s.length() + 1];
|
||||
memcpy(env[index], s.c_str(), s.length() * sizeof(char));
|
||||
env[index][s.length()] = '\0';
|
||||
}
|
||||
return env;
|
||||
}
|
||||
void linux_environ_clear(char** data)
|
||||
{
|
||||
for (int i = 0; data[i] != NULL; i++)
|
||||
delete [] data[i];
|
||||
delete [] data;
|
||||
}
|
||||
void linux_environ_print(char** env)
|
||||
{
|
||||
std::wstring file = NSFile::GetProcessDirectory() + L"/env.log";
|
||||
std::string fileA = U_TO_UTF8(file);
|
||||
for (int i = 0; env[i] != NULL; i++)
|
||||
{
|
||||
FILE* f = fopen(fileA.c_str(), "a+");
|
||||
std::string s = env[i];
|
||||
|
||||
// replace %%
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = s.find("%", posn)))
|
||||
{
|
||||
s.replace(posn, 1, "%%");
|
||||
posn += 2;
|
||||
}
|
||||
|
||||
fprintf(f, s.c_str());
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class CHtmlFile_Private
|
||||
{
|
||||
public:
|
||||
bool m_bIsEpub;
|
||||
std::wstring m_sHtmlFileInternal;
|
||||
|
||||
public:
|
||||
CHtmlFile_Private()
|
||||
{
|
||||
m_bIsEpub = false;
|
||||
m_sHtmlFileInternal = L"";
|
||||
|
||||
std::wstring sProcessPath = NSFile::GetProcessDirectory();
|
||||
std::wstring sPathConfig = sProcessPath + L"/DoctRenderer.config";
|
||||
if (NSFile::CFileBinary::Exists(sPathConfig))
|
||||
{
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlFile(sPathConfig))
|
||||
{
|
||||
std::wstring sPath = oNode.ReadValueString(L"htmlfileinternal");
|
||||
if (!sPath.empty())
|
||||
{
|
||||
if (0 == sPath.find(L"./"))
|
||||
sPath = sProcessPath + sPath.substr(1);
|
||||
m_sHtmlFileInternal = sPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -224,9 +310,9 @@ static void GetScriptsPath(NSStringUtils::CStringBuilder& oBuilder)
|
||||
}
|
||||
}
|
||||
|
||||
int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder, const std::wstring& sPathInternal)
|
||||
int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder)
|
||||
{
|
||||
std::wstring sInternal = sPathInternal;
|
||||
std::wstring sInternal = m_internal->m_sHtmlFileInternal;
|
||||
if (sInternal.empty())
|
||||
sInternal = NSFile::GetProcessDirectory() + L"/HtmlFileInternal/";
|
||||
|
||||
@ -413,10 +499,11 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
|
||||
std::string::size_type posLast = sProgramm.find_last_of('/');
|
||||
std::string sProgrammDir = sProgramm.substr(0, posLast);
|
||||
if (std::string::npos != posLast)
|
||||
sLibraryDir = "LD_LIBRARY_PATH=" + sProgrammDir + ":" + sProgrammDir + "/../";
|
||||
sLibraryDir = sProgrammDir + ":" + sProgrammDir + "/../";
|
||||
|
||||
if (!IsLinuxXVFB())
|
||||
{
|
||||
sLibraryDir = "LD_LIBRARY_PATH=" + sLibraryDir;
|
||||
const char* nargs[2];
|
||||
nargs[0] = sXmlA.c_str();
|
||||
nargs[1] = NULL;
|
||||
@ -442,12 +529,17 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
|
||||
nargs[4] = sXmlA.c_str();
|
||||
nargs[5] = NULL;
|
||||
|
||||
/*
|
||||
const char* nenv[4];
|
||||
nenv[0] = sLibraryDir.c_str();
|
||||
nenv[1] = NULL;//"DISPLAY=:99";
|
||||
nenv[2] = NULL;
|
||||
*/
|
||||
|
||||
execve("/usr/bin/xvfb-run", (char * const *)nargs, (char * const *)nenv);
|
||||
char** env = linux_environ_get(sLibraryDir);
|
||||
//linux_environ_print(env);
|
||||
execve("/usr/bin/xvfb-run", (char * const *)nargs, (char * const *)env);
|
||||
linux_environ_clear(env);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@ -635,7 +727,7 @@ static std::vector<std::wstring> ParseEpub(const std::wstring& sPackagePath, std
|
||||
return arHtmls;
|
||||
}
|
||||
|
||||
int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder, const std::wstring& sPathInternal)
|
||||
int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder)
|
||||
{
|
||||
std::wstring sFolderWithSlash = sFolder;
|
||||
NSStringExt::Replace(sFolderWithSlash, L"\\", L"/");
|
||||
@ -691,7 +783,7 @@ int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo,
|
||||
return 1;
|
||||
|
||||
m_internal->m_bIsEpub = true;
|
||||
int nErr = this->Convert(arHtmls, sDstfolder, sPathInternal);
|
||||
int nErr = this->Convert(arHtmls, sDstfolder);
|
||||
m_internal->m_bIsEpub = false;
|
||||
return nErr;
|
||||
}
|
||||
@ -1399,7 +1491,7 @@ namespace NSMht
|
||||
};
|
||||
}
|
||||
|
||||
int CHtmlFile::ConvertMht(const std::wstring& sFile, const std::wstring& sDstfolder, const std::wstring& sPathInternal)
|
||||
int CHtmlFile::ConvertMht(const std::wstring& sFile, const std::wstring& sDstfolder)
|
||||
{
|
||||
NSMht::CMhtFile oFile;
|
||||
oFile.Parse(sFile);
|
||||
@ -1408,5 +1500,5 @@ int CHtmlFile::ConvertMht(const std::wstring& sFile, const std::wstring& sDstfol
|
||||
|
||||
std::vector<std::wstring> arFiles;
|
||||
arFiles.push_back(sFileMht);
|
||||
return this->Convert(arFiles, sDstfolder, sPathInternal);
|
||||
return this->Convert(arFiles, sDstfolder);
|
||||
}
|
||||
|
||||
@ -56,9 +56,9 @@ public:
|
||||
/// \param sPathInternal - path (subprocesspath = path + HtmlFileInternal.exe) ("" -> GetProcessDirectory()/HtmlFileInternal/HtmlFileInternal.exe)
|
||||
/// \return 1 error, 0 - success
|
||||
|
||||
int Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder, const std::wstring& sPathInternal = L"");
|
||||
int ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder, const std::wstring& sPathInternal = L"");
|
||||
int ConvertMht(const std::wstring& sFile, const std::wstring& sDstfolder, const std::wstring& sPathInternal = L"");
|
||||
int Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder);
|
||||
int ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder);
|
||||
int ConvertMht(const std::wstring& sFile, const std::wstring& sDstfolder);
|
||||
};
|
||||
|
||||
#endif // _HTMLFILE_HTMLFILE_H_
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
#define SVG_INLINE_MAX_SIZE 500000 // 500Kb
|
||||
#define SVG_TO_RASTER_MIN_SIZE 50000000 // 1Mb
|
||||
|
||||
const long c_nClipType2 = 0x0021; // c_nClipType + 1
|
||||
|
||||
namespace NSHtmlRenderer
|
||||
{
|
||||
#define USE_SIMPLE_GRAPHICS_NOSVG
|
||||
@ -1672,7 +1674,8 @@ namespace NSHtmlRenderer
|
||||
}
|
||||
}
|
||||
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType2);
|
||||
m_oClipMetafile.WriteLONG(m_lClipMode);
|
||||
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
|
||||
}
|
||||
|
||||
@ -1726,7 +1729,8 @@ namespace NSHtmlRenderer
|
||||
}
|
||||
}
|
||||
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType2);
|
||||
m_oClipMetafile.WriteLONG(m_lClipMode);
|
||||
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
|
||||
|
||||
return nRet;
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
|
||||
#include "../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
#include "../../DesktopEditor/graphics/pro/Graphics.h"
|
||||
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
|
||||
|
||||
#include "../../PdfReader/PdfReader.h"
|
||||
#include "../../DjVuFile/DjVu.h"
|
||||
@ -77,17 +78,15 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
NSFonts::IApplicationFonts* pFonts = NSFonts::NSApplication::Create();
|
||||
if (true)
|
||||
{
|
||||
pFonts->Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::wstring> arFiles = pFonts->GetSetupFontFiles();
|
||||
NSDirectory::GetFiles2(L"D:\\GIT\\core-fonts", arFiles, true);
|
||||
pFonts->InitializeFromArrayFiles(arFiles);
|
||||
}
|
||||
CApplicationFontsWorker oWorker;
|
||||
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
|
||||
//oWorker.m_arAdditionalFolders.push_back(L"D:\\GIT\\core-fonts");
|
||||
oWorker.m_bIsNeedThumbnails = false;
|
||||
|
||||
if (!NSDirectory::Exists(oWorker.m_sDirectory))
|
||||
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
|
||||
|
||||
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
|
||||
|
||||
#ifdef METAFILE_TEST
|
||||
|
||||
|
||||
@ -53,5 +53,8 @@ linux-g++ | linux-g++-64 | linux-g++-32 {
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
SOURCES += ../src/ASCSVGWriter.cpp
|
||||
SOURCES += \
|
||||
../src/ASCSVGWriter.cpp \
|
||||
../../DesktopEditor/fontengine/ApplicationFontsWorker.cpp
|
||||
|
||||
HEADERS += ../include/ASCSVGWriter.h
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "tchar.h"
|
||||
#include "../source/ECMACryptFile.h"
|
||||
#include "../../Common/OfficeFileFormatChecker.h"
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
|
||||
#if defined(_WIN64)
|
||||
#pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib")
|
||||
@ -25,7 +26,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
ECMACryptFile crypt_file;
|
||||
bool result = false, bDataIntegrity = false;
|
||||
|
||||
std::wstring srcFileName = L"D:\\test\\_crypted\\test-111.docx";
|
||||
std::wstring srcFileName = L"D:\\test\\_bad_86\\crypt_file_test.docx";
|
||||
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
|
||||
std::wstring dstFileName2 = dstFileName + L".oox";
|
||||
|
||||
@ -39,8 +40,17 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//std::wstring dstFileName1 = srcFileName1 + L".oox";
|
||||
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
|
||||
|
||||
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||
result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||
//result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||
|
||||
std::wstring addit_name = L"11111111111111111111111111111";
|
||||
|
||||
std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
|
||||
|
||||
std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
|
||||
|
||||
addit_info += std::string(temp.begin(), temp.end());
|
||||
|
||||
crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
314
OfficeCryptReader/ooxml_crypt/main.cpp
Normal file
314
OfficeCryptReader/ooxml_crypt/main.cpp
Normal file
@ -0,0 +1,314 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./../source/ECMACryptFile.h"
|
||||
#include "./../../DesktopEditor/common/File.h"
|
||||
#include "./../../Common/3dParty/openssl/common/common_openssl.h"
|
||||
#include <iostream>
|
||||
|
||||
// examples:
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --password=111
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata1
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}\ndata1
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata11
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --info=
|
||||
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int wmain(int argc, wchar_t** argv)
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
#endif
|
||||
{
|
||||
if (argc <= 0)
|
||||
return 0;
|
||||
|
||||
std::wstring file_path;
|
||||
std::wstring password;
|
||||
bool is_print_info = false;
|
||||
bool is_decrypt = false;
|
||||
std::string user;
|
||||
std::wstring user_key_file;
|
||||
|
||||
std::vector<std::string> add_records;
|
||||
std::vector<std::string> remove_records;
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring param(argv[i]);
|
||||
#else
|
||||
std::string paramA(argv[i]);
|
||||
std::wstring param = UTF8_TO_U(paramA);
|
||||
#endif
|
||||
|
||||
std::wstring::size_type len = param.length();
|
||||
if (2 > len)
|
||||
continue;
|
||||
|
||||
const wchar_t* param_str = param.c_str();
|
||||
if (param_str[0] != '-' || param_str[1] != '-')
|
||||
continue;
|
||||
|
||||
std::wstring::size_type pos = param.find('=');
|
||||
if (std::wstring::npos == pos)
|
||||
continue;
|
||||
|
||||
std::wstring key = param.substr(2, pos - 2);
|
||||
std::wstring value = param.substr(pos + 1);
|
||||
|
||||
if (key == L"file")
|
||||
{
|
||||
file_path = value;
|
||||
}
|
||||
else if (key == L"add")
|
||||
{
|
||||
if (!value.empty())
|
||||
{
|
||||
if (value.c_str()[value.length() - 1] == '\n')
|
||||
value = value.substr(0, value.length() - 1);
|
||||
|
||||
string_replace(value, L";;;", L"\n");
|
||||
add_records.push_back(U_TO_UTF8(value));
|
||||
}
|
||||
}
|
||||
else if (key == L"remove")
|
||||
{
|
||||
if (!value.empty())
|
||||
{
|
||||
if (value.c_str()[value.length() - 1] == '\n')
|
||||
value = value.substr(0, value.length() - 1);
|
||||
string_replace(value, L";;;", L"\n");
|
||||
remove_records.push_back(U_TO_UTF8(value));
|
||||
}
|
||||
}
|
||||
else if (key == L"password")
|
||||
{
|
||||
password = value;
|
||||
}
|
||||
else if (key == L"info")
|
||||
{
|
||||
is_print_info = true;
|
||||
}
|
||||
else if (key == L"decrypt")
|
||||
{
|
||||
is_decrypt = true;
|
||||
}
|
||||
else if (key == L"user")
|
||||
{
|
||||
user = U_TO_UTF8(value);
|
||||
}
|
||||
else if (key == L"key")
|
||||
{
|
||||
user_key_file = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_path.empty() || !NSFile::CFileBinary::Exists(file_path))
|
||||
{
|
||||
std::cout << "error: file not exist" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.empty())
|
||||
{
|
||||
// encrypt file
|
||||
ECMACryptFile file;
|
||||
bool result = file.EncryptOfficeFile(file_path, file_path, password);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: file is not encrypted" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
ECMACryptFile file;
|
||||
std::string docinfo = file.ReadAdditional(file_path, L"DocumentID");
|
||||
|
||||
if (is_print_info)
|
||||
{
|
||||
std::cout << docinfo << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* doc_info_str = docinfo.c_str();
|
||||
const char* doc_info_str_end = doc_info_str + docinfo.length();
|
||||
|
||||
if (is_decrypt)
|
||||
{
|
||||
std::string encrypted_password = "";
|
||||
|
||||
// находим нужную запись
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
const char* rec_start = doc_info_str;
|
||||
|
||||
// 1) ищем старт записи
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
if (user == std::string(rec_start, doc_info_str - rec_start))
|
||||
{
|
||||
rec_start = doc_info_str;
|
||||
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
encrypted_password = std::string(rec_start, doc_info_str - rec_start);
|
||||
}
|
||||
|
||||
// идем в конец записи
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
if (*doc_info_str++ == '\n')
|
||||
{
|
||||
if (*doc_info_str == '\n')
|
||||
{
|
||||
++doc_info_str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string private_key_content;
|
||||
NSFile::CFileBinary::ReadAllTextUtf8A(user_key_file, private_key_content);
|
||||
|
||||
std::string passwordA;
|
||||
NSOpenSSL::RSA_DecryptPrivate_desktop((unsigned char*)private_key_content.c_str(), encrypted_password, passwordA);
|
||||
std::wstring password = UTF8_TO_U(passwordA);
|
||||
|
||||
// encrypt file
|
||||
ECMACryptFile file;
|
||||
bool bDataIntegrity;
|
||||
bool result = file.DecryptOfficeFile(file_path, file_path, password, bDataIntegrity);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: file is not decrypted" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::string sResult = "";
|
||||
sResult.reserve(1000);
|
||||
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
const char* rec_start = doc_info_str;
|
||||
|
||||
// 1) ищем старт записи
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
std::string::size_type len_first = doc_info_str - rec_start;
|
||||
|
||||
// 2) ищем конец записи
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
if (*doc_info_str++ == '\n')
|
||||
{
|
||||
if (*doc_info_str == '\n')
|
||||
{
|
||||
++doc_info_str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isAdd = true;
|
||||
std::string sRec = std::string(rec_start, (doc_info_str - rec_start - 2));
|
||||
|
||||
// 3) проверяем запись на удаление
|
||||
for (std::vector<std::string>::iterator iter = remove_records.begin(); iter != remove_records.end(); iter++)
|
||||
{
|
||||
if (*iter == std::string(rec_start, len_first))
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
else if (*iter == sRec)
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 4) проверяем запись на удаление
|
||||
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
|
||||
{
|
||||
if (*iter == sRec)
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isAdd)
|
||||
{
|
||||
sResult += sRec;
|
||||
sResult += "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
|
||||
{
|
||||
sResult += *iter;
|
||||
sResult += "\n\n";
|
||||
}
|
||||
|
||||
bool result = file.WriteAdditional(file_path, L"DocumentID", sResult);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: docinfo not writed" << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
OfficeCryptReader/ooxml_crypt/ooxml_crypt.pro
Normal file
56
OfficeCryptReader/ooxml_crypt/ooxml_crypt.pro
Normal file
@ -0,0 +1,56 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
TARGET = ooxml_crypt
|
||||
CORE_ROOT_DIR = $$PWD/../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
|
||||
CONFIG += core_static_link_libstd
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
|
||||
|
||||
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
CONFIG += open_ssl_common
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
DEFINES += CRYPTOPP_DISABLE_ASM
|
||||
DESTDIR = $$CORE_BUILDS_BINARY_PATH
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/../source/ECMACryptFile.h \
|
||||
$$PWD/../source/CryptTransform.h \
|
||||
$$PWD/../source/simple_xml_writer.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/../source/ECMACryptFile.cpp \
|
||||
$$PWD/../source/CryptTransform.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/Common/OfficeFileFormatChecker2.cpp \
|
||||
$$CORE_ROOT_DIR/Common/3dParty/pole/pole.cpp \
|
||||
$$CORE_ROOT_DIR/Common/DocxFormat/Source/Base/unicode_util.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/main.cpp
|
||||
|
||||
core_windows {
|
||||
DEFINES -= UNICODE
|
||||
DEFINES -= _DEBUG
|
||||
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lShell32
|
||||
LIBS += -lGdi32
|
||||
LIBS += -lUser32
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
core_linux {
|
||||
LIBS += -lz -pthread
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./
|
||||
}
|
||||
@ -976,3 +976,56 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ECMACryptFile::ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name)
|
||||
{
|
||||
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
|
||||
if (!pStorage->open(false, false))
|
||||
{
|
||||
delete pStorage;
|
||||
return "";
|
||||
}
|
||||
std::string result;
|
||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name);
|
||||
if ((pStream) && (pStream->size() > 0))
|
||||
{
|
||||
_UINT64 lengthData, size = pStream->size();
|
||||
|
||||
char* data = new char[size];
|
||||
|
||||
lengthData = pStream->read((unsigned char*)data, size);
|
||||
|
||||
result = std::string(data, lengthData);
|
||||
delete []data;
|
||||
delete pStream;
|
||||
}
|
||||
delete pStorage;
|
||||
|
||||
return result;
|
||||
}
|
||||
bool ECMACryptFile::WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info)
|
||||
{
|
||||
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
|
||||
if (!pStorage)return false;
|
||||
|
||||
if (!pStorage->open(true, false))
|
||||
{
|
||||
delete pStorage;
|
||||
return false;
|
||||
}
|
||||
|
||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
||||
|
||||
pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
|
||||
pStream->setSize(addit_info.size());
|
||||
|
||||
pStream->flush();
|
||||
delete pStream;
|
||||
|
||||
pStorage->close();
|
||||
delete pStorage;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,6 +40,9 @@ public:
|
||||
bool DecryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, bool & bDataIntegrity);
|
||||
bool EncryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, const std::wstring &documentID = L"");
|
||||
|
||||
std::string ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name);
|
||||
bool WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info);
|
||||
|
||||
struct _refComponent
|
||||
{
|
||||
int type;
|
||||
@ -50,5 +53,5 @@ public:
|
||||
std::vector<_refComponent> refComponents;
|
||||
std::wstring dataSpaceName;
|
||||
};
|
||||
std::vector<_mapEntry> mapEntries;
|
||||
std::vector<_mapEntry> mapEntries;
|
||||
};
|
||||
|
||||
@ -207,6 +207,75 @@ namespace ZLibZipUtils
|
||||
|
||||
/*========================================================================================================*/
|
||||
|
||||
static std::string normalize_path(const std::string &path)
|
||||
{
|
||||
const char* pData = path.c_str();
|
||||
int nLen = (int) path.length();
|
||||
|
||||
char* pDataNorm = new char[nLen + 1];
|
||||
int* pSlashPoints = new int[nLen + 1];
|
||||
|
||||
int nStart = 0;
|
||||
int nCurrent = 0;
|
||||
int nCurrentSlash = -1;
|
||||
int nCurrentW = 0;
|
||||
bool bIsUp = false;
|
||||
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
if (pData[nCurrent] == FILE_SEPARATOR_CHAR)
|
||||
pDataNorm[nCurrentW++] = pData[nCurrent];
|
||||
#endif
|
||||
while (nCurrent < nLen)
|
||||
{
|
||||
if (pData[nCurrent] == FILE_SEPARATOR_CHAR)
|
||||
{
|
||||
if (nStart < nCurrent)
|
||||
{
|
||||
bIsUp = false;
|
||||
if ((nCurrent - nStart) == 2)
|
||||
{
|
||||
if (pData[nStart] == (char)'.' && pData[nStart + 1] == (char)'.')
|
||||
{
|
||||
if (nCurrentSlash > 0)
|
||||
{
|
||||
--nCurrentSlash;
|
||||
nCurrentW = pSlashPoints[nCurrentSlash];
|
||||
bIsUp = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bIsUp)
|
||||
{
|
||||
pDataNorm[nCurrentW++] = (char) FILE_SEPARATOR_CHAR;
|
||||
++nCurrentSlash;
|
||||
pSlashPoints[nCurrentSlash] = nCurrentW;
|
||||
}
|
||||
}
|
||||
nStart = nCurrent + 1;
|
||||
++nCurrent;
|
||||
continue;
|
||||
}
|
||||
pDataNorm[nCurrentW++] = pData[nCurrent];
|
||||
++nCurrent;
|
||||
}
|
||||
|
||||
pDataNorm[nCurrentW] = (char)'\0';
|
||||
|
||||
std::string result = std::string(pDataNorm, nCurrentW);
|
||||
|
||||
delete []pDataNorm;
|
||||
|
||||
return result;
|
||||
}
|
||||
static void replace_all(std::string& subject, const std::string& search, const std::string& replace)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while ((pos = subject.find(search, pos)) != std::string::npos)
|
||||
{
|
||||
subject.replace(pos, search.length(), replace);
|
||||
pos += replace.length();
|
||||
}
|
||||
}
|
||||
static int do_extract_currentfile( unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password )
|
||||
{
|
||||
char filename_inzipA[256];
|
||||
@ -289,12 +358,39 @@ namespace ZLibZipUtils
|
||||
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||
(filename_withoutpath!=(wchar_t*)filename_inzip))
|
||||
{
|
||||
char* current_directory = getcwd(NULL, 0);
|
||||
if (current_directory)
|
||||
{
|
||||
std::string current_path(current_directory);
|
||||
free(current_directory);
|
||||
|
||||
current_path += FILE_SEPARATOR_STRA;
|
||||
|
||||
replace_all(current_path, "/", FILE_SEPARATOR_STRA);
|
||||
replace_all(current_path, "\\", FILE_SEPARATOR_STRA);
|
||||
|
||||
std::string filename_inzip(filename_inzipA);
|
||||
|
||||
replace_all(filename_inzip, "/", FILE_SEPARATOR_STRA);
|
||||
replace_all(filename_inzip, "\\", FILE_SEPARATOR_STRA);
|
||||
|
||||
std::string norm_path = normalize_path(current_path + filename_inzip);
|
||||
std::string norm_current_path = normalize_path(current_path);
|
||||
|
||||
if (std::string::npos == norm_path.find(norm_current_path))
|
||||
{
|
||||
return UNZ_INTERNALERROR;
|
||||
}
|
||||
}
|
||||
char c=*(filename_withoutpath-1);
|
||||
*(filename_withoutpath-1)='\0';
|
||||
makedir(write_filename);
|
||||
*(filename_withoutpath-1)=c;
|
||||
|
||||
if(oFile.CreateFileW(write_filename))
|
||||
{
|
||||
fout = oFile.GetFileNative();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,7 +448,10 @@ namespace ZLibZipUtils
|
||||
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||
&opt_overwrite,
|
||||
password) != UNZ_OK)
|
||||
break;
|
||||
{
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( progress != NULL )
|
||||
{
|
||||
@ -385,7 +484,7 @@ namespace ZLibZipUtils
|
||||
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
|
||||
}
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
/*========================================================================================================*/
|
||||
@ -541,23 +640,46 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback*
|
||||
std::vector<std::wstring> aCurFiles = NSDirectory::GetFiles(szText);
|
||||
std::vector<std::wstring> aCurDirectories = NSDirectory::GetDirectories(szText);
|
||||
|
||||
if (sorted)
|
||||
{
|
||||
std::sort(aCurFiles.begin(), aCurFiles.end());
|
||||
std::sort(aCurDirectories.begin(), aCurDirectories.end());
|
||||
}
|
||||
for(size_t i = 0; i < aCurDirectories.size(); ++i)
|
||||
for(size_t i = 0; i < aCurDirectories.size(); ++i)
|
||||
{
|
||||
std::wstring sDirName = NSSystemPath::GetFileName(aCurDirectories[i]);
|
||||
StringDeque.push_back( aCurDirectories[i] );
|
||||
zipDeque.push_back( zipDir + sDirName );
|
||||
|
||||
if (sorted)
|
||||
{
|
||||
if (sDirName == L"ppt")
|
||||
{
|
||||
StringDeque.push_front(aCurDirectories[i] );
|
||||
zipDeque.push_front( zipDir + sDirName );
|
||||
}
|
||||
else if(sDirName == L"xl")
|
||||
{
|
||||
StringDeque.push_front( aCurDirectories[i] );
|
||||
zipDeque.push_front( zipDir + sDirName );
|
||||
}
|
||||
else if (sDirName == L"word")
|
||||
{
|
||||
StringDeque.push_front( aCurDirectories[i] );
|
||||
zipDeque.push_front( zipDir + sDirName );
|
||||
}
|
||||
else
|
||||
{
|
||||
StringDeque.push_back( aCurDirectories[i] );
|
||||
zipDeque.push_back( zipDir + sDirName );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StringDeque.push_back( aCurDirectories[i] );
|
||||
zipDeque.push_back( zipDir + sDirName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i < aCurFiles.size(); ++i)
|
||||
{
|
||||
std::wstring cFileName = NSSystemPath::GetFileName(aCurFiles[i]);
|
||||
|
||||
if (std::wstring::npos != cFileName.find(L"mimetype")) // возможно и полное соответствие
|
||||
if (std::wstring::npos != cFileName.find(L"mimetype") ||
|
||||
std::wstring::npos != cFileName.find(L"[Content_Types]")) // возможно и полное соответствие
|
||||
{
|
||||
file = NSSystemPath::Combine(szText, cFileName);
|
||||
zipFileName = zipDir + cFileName;
|
||||
@ -745,9 +867,9 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback*
|
||||
if ( buffer != NULL )
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
err = _wchdir( buffer );
|
||||
int err1 = _wchdir( buffer );
|
||||
#else
|
||||
err = chdir( buffer );
|
||||
int err1 = chdir( buffer );
|
||||
#endif
|
||||
|
||||
free( buffer );
|
||||
|
||||
@ -613,6 +613,7 @@ namespace PdfReader
|
||||
|
||||
std::wstring wsTempFileName = L"";
|
||||
Ref oEmbRef;
|
||||
bool bFontSubstitution = false;
|
||||
// 1. Если шрифт внедренный, тогда скидываем его в темповый файл.
|
||||
// 2. Если шрифт лежит вне пдф, а в самом пдф есть ссылка на него, тогда используем эту ссылку.
|
||||
// 3. В противном случае подбираем шрифт.
|
||||
@ -1018,6 +1019,8 @@ namespace PdfReader
|
||||
{
|
||||
wsFileName = pFontInfo->m_wsFontPath;
|
||||
eFontType = pFont->IsCIDFont() ? fontCIDType2 : fontTrueType;
|
||||
|
||||
bFontSubstitution = true;
|
||||
}
|
||||
else // В крайнем случае, в данном шрифте просто не пишем ничего
|
||||
{
|
||||
@ -1274,12 +1277,11 @@ namespace PdfReader
|
||||
case fontCIDType2OT:
|
||||
{
|
||||
// Создаем карту CID-to-GID
|
||||
// Если у нас есть мап ToUnicode, тогда на основе его читаем из файла гиды по юникодным значениям,
|
||||
// если не нашли, но у нас есть мап CIDtoGID, тогда строим по последнему.
|
||||
|
||||
// Если у нас шрифт был не встроен и подбирался и есть мап ToUnicode, тогда на основе его читаем из файла гиды по юникодным значениям.
|
||||
// Для встроенных шрифтов используем мап CIDtoGID
|
||||
pCodeToGID = NULL;
|
||||
nLen = 0;
|
||||
if (L"" != wsFileName)
|
||||
if (L"" != wsFileName && bFontSubstitution)
|
||||
{
|
||||
CharCodeToUnicode *pCodeToUnicode = NULL;
|
||||
if ((pCodeToUnicode = ((GrCIDFont *)pFont)->GetToUnicode()))
|
||||
@ -1316,7 +1318,7 @@ namespace PdfReader
|
||||
}
|
||||
else
|
||||
{
|
||||
pCodeToGID[nCode] = nCode;
|
||||
pCodeToGID[nCode] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1326,8 +1328,7 @@ namespace PdfReader
|
||||
pCodeToUnicode->Release();
|
||||
}
|
||||
}
|
||||
|
||||
if (!pCodeToGID && ((GrCIDFont *)pFont)->GetCIDToGID())
|
||||
else if (((GrCIDFont *)pFont)->GetCIDToGID())
|
||||
{
|
||||
nLen = ((GrCIDFont *)pFont)->GetCIDToGIDLen();
|
||||
pCodeToGID = (unsigned short *)MemUtilsMallocArray(nLen, sizeof(unsigned short));
|
||||
@ -3262,10 +3263,12 @@ namespace PdfReader
|
||||
Aggplus::CImage oImage;
|
||||
oImage.Create(pBufferPtr, nWidth, nHeight, -4 * nWidth);
|
||||
|
||||
// Пишем данные в pBufferPtr
|
||||
ImageStream *pImageStream = new ImageStream(pStream, nWidth, pColorMap->GetComponentsCount(), pColorMap->GetBitsPerComponent());
|
||||
int nComponentsCount = pColorMap->GetComponentsCount();
|
||||
|
||||
pImageStream->Reset();
|
||||
// Пишем данные в pBufferPtr
|
||||
ImageStream *pImageStream = new ImageStream(pStream, nWidth, nComponentsCount, pColorMap->GetBitsPerComponent());
|
||||
|
||||
pImageStream->Reset();
|
||||
|
||||
unsigned char unAlpha = m_bTransparentGroup ? 255.0 * pGState->GetFillOpacity() : 255;
|
||||
|
||||
@ -3276,12 +3279,29 @@ namespace PdfReader
|
||||
{
|
||||
int nIndex = 4 * (nX + nY * nWidth);
|
||||
pImageStream->GetPixel(unPixel);
|
||||
|
||||
GrRGB oRGB;
|
||||
pColorMap->GetRGB(unPixel, &oRGB);
|
||||
pBufferPtr[nIndex + 0] = ColorToByte(oRGB.b);
|
||||
pBufferPtr[nIndex + 1] = ColorToByte(oRGB.g);
|
||||
pBufferPtr[nIndex + 2] = ColorToByte(oRGB.r);
|
||||
pBufferPtr[nIndex + 3] = unAlpha;
|
||||
|
||||
if (pMaskColors)
|
||||
{
|
||||
bool isMask = true;
|
||||
for (int nCompIndex = 0; nCompIndex < nComponentsCount; ++nCompIndex)
|
||||
{
|
||||
if (pMaskColors[nCompIndex * 2] > unPixel[nCompIndex] || unPixel[nCompIndex] > pMaskColors[nCompIndex * 2 + 1])
|
||||
{
|
||||
isMask = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMask)
|
||||
pBufferPtr[nIndex + 3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -503,7 +503,7 @@ CPdfRenderer::CPdfRenderer(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) :
|
||||
return;
|
||||
}
|
||||
|
||||
m_pDocument->SetCompressionMode(COMP_ALL);
|
||||
m_pDocument->SetCompressionMode(COMP_ALL);
|
||||
|
||||
m_bValid = true;
|
||||
m_dPageHeight = 297;
|
||||
@ -1864,32 +1864,32 @@ void CPdfRenderer::UpdateBrush()
|
||||
double dL, dR, dT, dB;
|
||||
m_oPath.GetBounds(dL, dT, dR, dB);
|
||||
|
||||
double dXStepSpacing = 0, dYStepSpacing = 0;
|
||||
if (c_BrushTextureModeStretch == lTextureMode)
|
||||
{
|
||||
// Чтобы избавиться от погрешностей из-за которых могут возникать полоски, немного увеличим границы пата.
|
||||
dL -= 1;
|
||||
dT -= 1;
|
||||
dB += 1;
|
||||
dR += 1;
|
||||
|
||||
// Растягиваем картинку по размерам пата
|
||||
dW = std::max(10.0, dR - dL);
|
||||
dH = std::max(10.0, dB - dT);
|
||||
dW = std::max(10.0, dR - dL);
|
||||
dH = std::max(10.0, dB - dT);
|
||||
|
||||
// Чтобы избавиться от погрешностей из-за которых могут возникать полоски или обрезание картинки,
|
||||
// удвоим расстрояние между соседними тайлами. Плохого тут нет, т.к. нам нужен всего 1 тайл
|
||||
dXStepSpacing = dW;
|
||||
dYStepSpacing = dH;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Размеры картинки заданы в пикселях. Размеры тайла - это размеры картинки в пунктах.
|
||||
dW = nImageW * 72 / 96;
|
||||
dH = nImageH * 72 / 96;
|
||||
}
|
||||
}
|
||||
|
||||
// Нам нужно, чтобы левый нижний угол границ нашего пата являлся точкой переноса для матрицы преобразования.
|
||||
CMatrix* pMatrix = m_pPage->GetTransform();
|
||||
pMatrix->Apply(dL, dB);
|
||||
pMatrix->Apply(dL, dT);
|
||||
CMatrix oPatternMatrix = *pMatrix;
|
||||
oPatternMatrix.x = dL;
|
||||
oPatternMatrix.y = dB;
|
||||
m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix));
|
||||
oPatternMatrix.y = dT;
|
||||
m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix, imagetilepatterntype_Default, dXStepSpacing, dYStepSpacing));
|
||||
}
|
||||
}
|
||||
else if (c_BrushTypeHatch1 == lBrushType)
|
||||
|
||||
@ -744,9 +744,9 @@ namespace PdfWriter
|
||||
|
||||
return pShading;
|
||||
}
|
||||
CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType)
|
||||
CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType, double dXStepSpacing, double dYStepSpacing)
|
||||
{
|
||||
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, pMatrix, eType);
|
||||
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, pMatrix, eType, dXStepSpacing, dYStepSpacing);
|
||||
}
|
||||
CImageTilePattern*CDocument::CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch)
|
||||
{
|
||||
|
||||
@ -117,7 +117,7 @@ namespace PdfWriter
|
||||
CFont14* CreateFont14(EStandard14Fonts eType);
|
||||
CFontCidTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex);
|
||||
|
||||
CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
|
||||
CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default, double dXStepSpacing = 0, double dYStepSpacing = 0);
|
||||
CImageTilePattern*CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch);
|
||||
CShading* CreateAxialShading(CPage* pPage, double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
|
||||
CShading* CreateRadialShading(CPage* pPage, double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
|
||||
|
||||
@ -44,7 +44,7 @@ namespace PdfWriter
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CImageTilePattern
|
||||
//----------------------------------------------------------------------------------------
|
||||
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType) : CPattern(pXref)
|
||||
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType, double dXStepSpacing, double dYStepSpacing) : CPattern(pXref)
|
||||
{
|
||||
Add("Type", "Pattern");
|
||||
Add("PatternType", 1);
|
||||
@ -84,9 +84,13 @@ namespace PdfWriter
|
||||
|
||||
if (imagetilepatterntype_Default == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, dH));
|
||||
Add("XStep", dW);
|
||||
Add("YStep", dH);
|
||||
if (dXStepSpacing > 0.01 && dYStepSpacing > 0.01)
|
||||
Add("BBox", CArrayObject::CreateBox(-dXStepSpacing / 2, -dYStepSpacing / 2, dW + dXStepSpacing / 2, dH + dYStepSpacing / 2));
|
||||
else
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, dH));
|
||||
|
||||
Add("XStep", dW + dXStepSpacing);
|
||||
Add("YStep", dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteReal(dW);
|
||||
pStream->WriteStr(" 0 0 ");
|
||||
@ -97,8 +101,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseX == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, 2 * dW, dH));
|
||||
Add("XStep", 2 * dW);
|
||||
Add("YStep", dH);
|
||||
Add("XStep", 2 * dW + dXStepSpacing);
|
||||
Add("YStep", dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -119,8 +123,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseY == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, 2 * dH));
|
||||
Add("XStep", dW);
|
||||
Add("YStep", 2 * dH);
|
||||
Add("XStep", dW + dXStepSpacing);
|
||||
Add("YStep", 2 * dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -141,8 +145,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseXY == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, 2 * dW, 2 * dH));
|
||||
Add("XStep", 2 * dW);
|
||||
Add("YStep", 2 * dH);
|
||||
Add("XStep", 2 * dW + dXStepSpacing);
|
||||
Add("YStep", 2 * dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -183,4 +187,4 @@ namespace PdfWriter
|
||||
pStream->WriteStr("/X1 Do\12");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ namespace PdfWriter
|
||||
class CImageTilePattern : public CPattern
|
||||
{
|
||||
public:
|
||||
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
|
||||
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default, double dXStepSpacing = 0, double dYStepSpacing = 0);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _PDF_WRITER_SRC_PATTERN_H
|
||||
#endif // _PDF_WRITER_SRC_PATTERN_H
|
||||
|
||||
@ -15,8 +15,9 @@ include(../Common/base.pri)
|
||||
|
||||
DEFINES += UNICODECONVERTER_USE_DYNAMIC_LIBRARY
|
||||
|
||||
core_linux {
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./
|
||||
core_linux {
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
|
||||
QMAKE_LFLAGS += -Wl,--disable-new-dtags
|
||||
}
|
||||
|
||||
core_ios {
|
||||
|
||||
@ -147,9 +147,7 @@ namespace NExtractTools
|
||||
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO)
|
||||
return mscrypt2oot_bin(sFrom, sTo, sTemp, params);
|
||||
else
|
||||
{
|
||||
//вместо docx другой формат!!
|
||||
}
|
||||
return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
else return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
@ -228,7 +226,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sResultDocxDir, sTo);
|
||||
nRes = dir2zip(sResultDocxDir, sTo, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,7 +557,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
//вместо xlsx другой формат!!
|
||||
return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
}
|
||||
else return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
@ -648,7 +646,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sResultXlsxDir, sTo);
|
||||
nRes = dir2zip(sResultXlsxDir, sTo, true);
|
||||
}
|
||||
}
|
||||
return nRes;
|
||||
@ -938,7 +936,8 @@ namespace NExtractTools
|
||||
{
|
||||
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO)
|
||||
return mscrypt2oot_bin(sFrom, sTo, sTemp, params);
|
||||
//вместо pptx другой формат!!
|
||||
else
|
||||
return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
else return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
@ -1021,7 +1020,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sResultPptxDir, sTo);
|
||||
nRes = dir2zip(sResultPptxDir, sTo, true);
|
||||
}
|
||||
}
|
||||
return nRes;
|
||||
@ -1071,10 +1070,10 @@ namespace NExtractTools
|
||||
return pptt_bin2pptx(sTempPpttFileEditor, sTo, sTemp, bFromChanges, sThemeDir, params);
|
||||
}
|
||||
// zip dir
|
||||
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo)
|
||||
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo, bool bSorted, int method, short level)
|
||||
{
|
||||
COfficeUtils oCOfficeUtils(NULL);
|
||||
return (S_OK == oCOfficeUtils.CompressFileOrDirectory(sFrom, sTo)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
return (S_OK == oCOfficeUtils.CompressFileOrDirectory(sFrom, sTo, bSorted, method, level)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
|
||||
// unzip dir
|
||||
@ -2759,8 +2758,7 @@ namespace NExtractTools
|
||||
arFiles.push_back(sFrom);
|
||||
|
||||
CHtmlFile oHtmlFile;
|
||||
std::wstring sPathInternal = NULL != params.m_sHtmlFileInternalPath ? *params.m_sHtmlFileInternalPath : L"";
|
||||
return 0 == oHtmlFile.Convert(arFiles, sTo, sPathInternal) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
return 0 == oHtmlFile.Convert(arFiles, sTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
//html in container
|
||||
_UINT32 html_zip2doct_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
|
||||
@ -2795,15 +2793,13 @@ namespace NExtractTools
|
||||
{
|
||||
}
|
||||
CHtmlFile oHtmlFile;
|
||||
std::wstring sPathInternal = NULL != params.m_sHtmlFileInternalPath ? *params.m_sHtmlFileInternalPath : L"";
|
||||
return 0 == oHtmlFile.Convert(arFiles, sTo, sPathInternal) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
return 0 == oHtmlFile.Convert(arFiles, sTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
//mht
|
||||
_UINT32 mht2doct_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
|
||||
{
|
||||
CHtmlFile oHtmlFile;
|
||||
std::wstring sPathInternal = NULL != params.m_sHtmlFileInternalPath ? *params.m_sHtmlFileInternalPath : L"";
|
||||
return 0 == oHtmlFile.ConvertMht(sFrom, sTo, sPathInternal) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
return 0 == oHtmlFile.ConvertMht(sFrom, sTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
_UINT32 epub2doct_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
|
||||
{
|
||||
@ -2814,8 +2810,7 @@ namespace NExtractTools
|
||||
{
|
||||
CHtmlFile oHtmlFile;
|
||||
std::wstring sMetaInfo;
|
||||
std::wstring sPathInternal = NULL != params.m_sHtmlFileInternalPath ? *params.m_sHtmlFileInternalPath : L"";
|
||||
nRes = 0 == oHtmlFile.ConvertEpub(sEpubDir, sMetaInfo, sTo, sPathInternal) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
nRes = 0 == oHtmlFile.ConvertEpub(sEpubDir, sMetaInfo, sTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
@ -3174,7 +3169,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
nRes = dir2zip(sFrom, sTo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3406,7 +3401,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
nRes = dir2zip(sFrom, sTo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3653,7 +3648,7 @@ namespace NExtractTools
|
||||
}
|
||||
else
|
||||
{
|
||||
nRes = dir2zip(sFrom, sTo);
|
||||
nRes = dir2zip(sFrom, sTo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ namespace NExtractTools
|
||||
_UINT32 html2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo);
|
||||
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo, bool bSorted = false, int method = 8/*Z_DEFLATED*/, short level = -1);
|
||||
_UINT32 zip2dir (const std::wstring &sFrom, const std::wstring &sTo);
|
||||
|
||||
_UINT32 convertmailmerge (const InputParamsMailMerge& oMailMergeSend,const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bPaid, const std::wstring &sThemeDir, InputParams& params);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -409,7 +409,6 @@ namespace NExtractTools
|
||||
InputParamsMailMerge* m_oMailMergeSend;
|
||||
InputParamsThumbnail* m_oThumbnail;
|
||||
std::wstring* m_sJsonParams;
|
||||
std::wstring* m_sHtmlFileInternalPath;
|
||||
std::wstring* m_sPassword;
|
||||
std::wstring* m_sSavePassword;
|
||||
std::wstring* m_sDocumentID;
|
||||
@ -440,7 +439,6 @@ namespace NExtractTools
|
||||
m_oMailMergeSend = NULL;
|
||||
m_oThumbnail = NULL;
|
||||
m_sJsonParams = NULL;
|
||||
m_sHtmlFileInternalPath = NULL;
|
||||
m_sPassword = NULL;
|
||||
m_sSavePassword = NULL;
|
||||
m_sDocumentID = NULL;
|
||||
@ -470,7 +468,6 @@ namespace NExtractTools
|
||||
RELEASEOBJECT(m_oMailMergeSend);
|
||||
RELEASEOBJECT(m_oThumbnail);
|
||||
RELEASEOBJECT(m_sJsonParams);
|
||||
RELEASEOBJECT(m_sHtmlFileInternalPath);
|
||||
RELEASEOBJECT(m_sPassword);
|
||||
RELEASEOBJECT(m_sSavePassword);
|
||||
RELEASEOBJECT(m_sDocumentID);
|
||||
@ -615,11 +612,6 @@ namespace NExtractTools
|
||||
RELEASEOBJECT(m_sJsonParams);
|
||||
m_sJsonParams = new std::wstring(sValue);
|
||||
}
|
||||
else if(_T("m_sHtmlFileInternalPath") == sName)
|
||||
{
|
||||
RELEASEOBJECT(m_sHtmlFileInternalPath);
|
||||
m_sHtmlFileInternalPath = new std::wstring(sValue);
|
||||
}
|
||||
else if(_T("m_sPassword") == sName)
|
||||
{
|
||||
RELEASEOBJECT(m_sPassword);
|
||||
|
||||
@ -1,478 +1,484 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "CSVReader.h"
|
||||
|
||||
#include <map>
|
||||
#include <locale>
|
||||
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
|
||||
#include "../../Common/OfficeFileErrorDescription.h"
|
||||
#include "../../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../../UnicodeConverter/UnicodeConverter_Encodings.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h"
|
||||
|
||||
namespace CSVReader
|
||||
{
|
||||
const std::wstring ansi_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
std::wstring result;
|
||||
|
||||
std::locale loc("");
|
||||
std::ctype<wchar_t> const &facet = std::use_facet<std::ctype<wchar_t> >(loc);
|
||||
|
||||
result.resize(data_size);
|
||||
|
||||
facet.widen((char*)data, (char*)data + data_size, &result[0]);
|
||||
return result;
|
||||
}
|
||||
const std::wstring utf8_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 2)//utf8 -> utf16
|
||||
{
|
||||
unsigned int nLength = data_size;
|
||||
|
||||
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
|
||||
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
|
||||
|
||||
UTF8 *pStrUtf8 = (UTF8 *) data;
|
||||
|
||||
const UTF8 *pStrUtf8_Conv = pStrUtf8;
|
||||
UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength]
|
||||
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf16;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16Str ((wchar_t *) pStrUtf16);
|
||||
|
||||
delete [] pStrUtf16;
|
||||
return utf16Str;
|
||||
}
|
||||
else //utf8 -> utf32
|
||||
{
|
||||
unsigned int nLength = data_size;
|
||||
|
||||
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
|
||||
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
|
||||
|
||||
UTF8 *pStrUtf8 = (UTF8 *) data;
|
||||
|
||||
const UTF8 *pStrUtf8_Conv = pStrUtf8;
|
||||
UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength]
|
||||
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf32;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf32Str ((wchar_t *) pStrUtf32);
|
||||
|
||||
delete [] pStrUtf32;
|
||||
return utf32Str;
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring utf16_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 2)//utf16 -> utf16
|
||||
{
|
||||
return std::wstring((wchar_t*)data, data_size / 2);
|
||||
}
|
||||
else //utf16 -> utf32
|
||||
{
|
||||
unsigned int nLength = data_size / 2;
|
||||
|
||||
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
|
||||
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
|
||||
|
||||
UTF16 *pStrUtf16 = (UTF16 *) data;
|
||||
|
||||
const UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF32 (&pStrUtf16_Conv, &pStrUtf16[nLength]
|
||||
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf32;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf32Str ((wchar_t *) pStrUtf32);
|
||||
|
||||
delete [] pStrUtf32;
|
||||
return utf32Str;
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring utf32_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 4)//utf32 -> utf32
|
||||
{
|
||||
return std::wstring((wchar_t*)data, data_size / 4);
|
||||
}
|
||||
else //utf32 -> utf16
|
||||
{
|
||||
unsigned int nLength = data_size / 4;
|
||||
|
||||
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
|
||||
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
|
||||
|
||||
UTF32 *pStrUtf32 = (UTF32 *) data;
|
||||
|
||||
const UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF16 (&pStrUtf32_Conv, &pStrUtf32[nLength]
|
||||
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf16;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16Str ((wchar_t *) pStrUtf16);
|
||||
|
||||
delete [] pStrUtf16;
|
||||
return utf16Str;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap)
|
||||
{
|
||||
while(!oDeleteChars.empty())
|
||||
{
|
||||
INT nIndex = oDeleteChars.top() - nStartCell;
|
||||
sText.erase(nIndex, 1);
|
||||
oDeleteChars.pop();
|
||||
}
|
||||
// Пустую не пишем
|
||||
if (0 == sText.length())
|
||||
return;
|
||||
|
||||
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
|
||||
pCell->m_oType.Init();
|
||||
|
||||
WCHAR *pEndPtr;
|
||||
double dValue = wcstod(sText.c_str(), &pEndPtr);
|
||||
if (0 != *pEndPtr)
|
||||
{
|
||||
// Не число
|
||||
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
|
||||
pCell->m_oRichText.Init();
|
||||
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
|
||||
pText->m_sText = sText;
|
||||
pCell->m_oRichText->m_arrItems.push_back(pText);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Число
|
||||
pCell->m_oValue.Init();
|
||||
pCell->m_oValue->m_sText = sText;
|
||||
}
|
||||
|
||||
if (bIsWrap)
|
||||
{
|
||||
// WrapStyle
|
||||
pCell->m_oStyle.Init();
|
||||
pCell->m_oStyle->SetValue(1);
|
||||
}
|
||||
|
||||
pCell->setRowCol(nRow, nCol);
|
||||
oRow.m_arrItems.push_back(pCell);
|
||||
}
|
||||
_UINT32 ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
if (false == oFile.OpenFile(sFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
//-----------------------------------------------------------------------------------
|
||||
// Создадим Workbook
|
||||
oXlsx.CreateWorkbook();
|
||||
// Создадим стили
|
||||
oXlsx.CreateStyles();
|
||||
|
||||
// Добавим стили для wrap-а
|
||||
oXlsx.m_pStyles->m_oCellXfs.Init();
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_oCount.Init();
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_oCount->SetValue(2);
|
||||
|
||||
// Normall default
|
||||
OOX::Spreadsheet::CXfs* pXfs = NULL;
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
|
||||
|
||||
// Wrap style
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
|
||||
pXfs->m_oApplyAlignment.Init();
|
||||
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
|
||||
pXfs->m_oAligment.Init();
|
||||
pXfs->m_oAligment->m_oWrapText.Init();
|
||||
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
|
||||
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
|
||||
|
||||
std::wstring sSheetRId = L"rId1";
|
||||
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet(NULL);
|
||||
pWorksheet->m_oSheetData.Init();
|
||||
|
||||
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
|
||||
|
||||
pSheet->m_oName.Init();
|
||||
pSheet->m_oName->append(L"Sheet1");
|
||||
pSheet->m_oSheetId.Init();
|
||||
pSheet->m_oSheetId->SetValue(1);
|
||||
pSheet->m_oRid.Init();
|
||||
pSheet->m_oRid->SetValue(sSheetRId);
|
||||
|
||||
oXlsx.m_pWorkbook->m_oSheets.Init();
|
||||
oXlsx.m_pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
DWORD nFileSize = 0;
|
||||
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
|
||||
|
||||
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
|
||||
oFile.CloseFile();
|
||||
//skip bom
|
||||
DWORD nInputBufferSize = nFileSize;
|
||||
BYTE* pInputBuffer = pFileData;
|
||||
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
|
||||
{
|
||||
nInputBufferSize -= 3;
|
||||
pInputBuffer += 3;
|
||||
}
|
||||
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
|
||||
{
|
||||
nInputBufferSize -= 2;
|
||||
pInputBuffer += 2;
|
||||
}
|
||||
|
||||
std::wstring sFileDataW;
|
||||
|
||||
if (nCodePage == 1000)
|
||||
{
|
||||
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 46)//utf-8
|
||||
{
|
||||
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 48)//utf-16
|
||||
{
|
||||
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 50) // utf-32
|
||||
{
|
||||
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
size_t nSize = sFileDataW.length();
|
||||
|
||||
if (nSize < 1 && nInputBufferSize > 0)
|
||||
{//для синхронности вывода превью и нормального результата
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
|
||||
nSize = sFileDataW.length();
|
||||
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;
|
||||
}
|
||||
const WCHAR *pTemp = sFileDataW.c_str();
|
||||
|
||||
WCHAR wcDelimiterLeading = L'\0';
|
||||
WCHAR wcDelimiterTrailing = L'\0';
|
||||
int nDelimiterSize = 0;
|
||||
|
||||
if (sDelimiter.length() > 0)
|
||||
{
|
||||
wcDelimiterLeading = sDelimiter[0];
|
||||
nDelimiterSize = 1;
|
||||
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
|
||||
{
|
||||
wcDelimiterTrailing = sDelimiter[1];
|
||||
nDelimiterSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
const WCHAR wcNewLineN = _T('\n');
|
||||
const WCHAR wcNewLineR = _T('\r');
|
||||
const WCHAR wcQuote = _T('"');
|
||||
const WCHAR wcTab = _T('\t');
|
||||
|
||||
bool bIsWrap = false;
|
||||
WCHAR wcCurrent;
|
||||
INT nStartCell = 0;
|
||||
std::stack<INT> oDeleteChars;
|
||||
|
||||
bool bInQuote = false;
|
||||
INT nIndexRow = 0;
|
||||
INT nIndexCol = 0;
|
||||
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(nIndexRow + 1);
|
||||
|
||||
for (size_t nIndex = 0; nIndex < nSize; ++nIndex)
|
||||
{
|
||||
wcCurrent = pTemp[nIndex];
|
||||
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
|
||||
{
|
||||
if (bInQuote)
|
||||
continue;
|
||||
// New Cell
|
||||
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = false;
|
||||
|
||||
nStartCell = nIndex + nDelimiterSize;
|
||||
if (nStartCell == nSize)
|
||||
{
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
pRow = NULL;
|
||||
}
|
||||
}
|
||||
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
|
||||
{
|
||||
if (bInQuote)
|
||||
{
|
||||
// Добавим Wrap
|
||||
bIsWrap = true;
|
||||
continue;
|
||||
}
|
||||
// New line
|
||||
if (nStartCell != nIndex)
|
||||
{
|
||||
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = false;
|
||||
}
|
||||
|
||||
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
|
||||
{
|
||||
// На комбинацию \r\n должен быть только 1 перенос
|
||||
++nIndex;
|
||||
}
|
||||
|
||||
nStartCell = nIndex + 1;
|
||||
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(++nIndexRow + 1);
|
||||
nIndexCol = 0;
|
||||
}
|
||||
else if (wcQuote == wcCurrent)
|
||||
{
|
||||
// Quote
|
||||
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
|
||||
{
|
||||
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
|
||||
bInQuote = !bInQuote;
|
||||
nStartCell = nIndex + 1;
|
||||
}
|
||||
else if ( bInQuote )
|
||||
{
|
||||
// Нужно удалить кавычку ограничитель
|
||||
oDeleteChars.push(nIndex);
|
||||
|
||||
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
|
||||
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
|
||||
++nIndex;
|
||||
else
|
||||
bInQuote = !bInQuote;
|
||||
}
|
||||
}
|
||||
else if (wcTab == wcCurrent)
|
||||
{
|
||||
// delete tab if not delimiter
|
||||
oDeleteChars.push(nIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (nStartCell != nSize)
|
||||
{
|
||||
// New line
|
||||
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(pRow);
|
||||
}
|
||||
oXlsx.m_arWorksheets.push_back(pWorksheet);
|
||||
oXlsx.m_mapWorksheets.insert(std::make_pair(sSheetRId, pWorksheet));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "CSVReader.h"
|
||||
|
||||
#include <map>
|
||||
#include <locale>
|
||||
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
|
||||
#include "../../Common/OfficeFileErrorDescription.h"
|
||||
#include "../../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../../UnicodeConverter/UnicodeConverter_Encodings.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h"
|
||||
|
||||
namespace CSVReader
|
||||
{
|
||||
const std::wstring ansi_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
std::wstring result;
|
||||
|
||||
std::locale loc("");
|
||||
std::ctype<wchar_t> const &facet = std::use_facet<std::ctype<wchar_t> >(loc);
|
||||
|
||||
result.resize(data_size);
|
||||
|
||||
facet.widen((char*)data, (char*)data + data_size, &result[0]);
|
||||
return result;
|
||||
}
|
||||
const std::wstring utf8_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 2)//utf8 -> utf16
|
||||
{
|
||||
unsigned int nLength = data_size;
|
||||
|
||||
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
|
||||
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
|
||||
|
||||
UTF8 *pStrUtf8 = (UTF8 *) data;
|
||||
|
||||
const UTF8 *pStrUtf8_Conv = pStrUtf8;
|
||||
UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength]
|
||||
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf16;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16Str ((wchar_t *) pStrUtf16);
|
||||
|
||||
delete [] pStrUtf16;
|
||||
return utf16Str;
|
||||
}
|
||||
else //utf8 -> utf32
|
||||
{
|
||||
unsigned int nLength = data_size;
|
||||
|
||||
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
|
||||
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
|
||||
|
||||
UTF8 *pStrUtf8 = (UTF8 *) data;
|
||||
|
||||
const UTF8 *pStrUtf8_Conv = pStrUtf8;
|
||||
UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength]
|
||||
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf32;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf32Str ((wchar_t *) pStrUtf32);
|
||||
|
||||
delete [] pStrUtf32;
|
||||
return utf32Str;
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring utf16_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 2)//utf16 -> utf16
|
||||
{
|
||||
return std::wstring((wchar_t*)data, data_size / 2);
|
||||
}
|
||||
else //utf16 -> utf32
|
||||
{
|
||||
unsigned int nLength = data_size / 2;
|
||||
|
||||
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
|
||||
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
|
||||
|
||||
UTF16 *pStrUtf16 = (UTF16 *) data;
|
||||
|
||||
const UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF32 (&pStrUtf16_Conv, &pStrUtf16[nLength]
|
||||
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf32;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf32Str ((wchar_t *) pStrUtf32);
|
||||
|
||||
delete [] pStrUtf32;
|
||||
return utf32Str;
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring utf32_2_unicode(const unsigned char* data, DWORD data_size)
|
||||
{
|
||||
if (sizeof(wchar_t) == 4)//utf32 -> utf32
|
||||
{
|
||||
return std::wstring((wchar_t*)data, data_size / 4);
|
||||
}
|
||||
else //utf32 -> utf16
|
||||
{
|
||||
unsigned int nLength = data_size / 4;
|
||||
|
||||
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
|
||||
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
|
||||
|
||||
UTF32 *pStrUtf32 = (UTF32 *) data;
|
||||
|
||||
const UTF32 *pStrUtf32_Conv = pStrUtf32;
|
||||
UTF16 *pStrUtf16_Conv = pStrUtf16;
|
||||
|
||||
ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF16 (&pStrUtf32_Conv, &pStrUtf32[nLength]
|
||||
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
|
||||
, strictConversion);
|
||||
|
||||
if (conversionOK != eUnicodeConversionResult)
|
||||
{
|
||||
delete [] pStrUtf16;
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16Str ((wchar_t *) pStrUtf16);
|
||||
|
||||
delete [] pStrUtf16;
|
||||
return utf16Str;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap)
|
||||
{
|
||||
while(!oDeleteChars.empty())
|
||||
{
|
||||
INT nIndex = oDeleteChars.top() - nStartCell;
|
||||
sText.erase(nIndex, 1);
|
||||
oDeleteChars.pop();
|
||||
}
|
||||
// Пустую не пишем
|
||||
if (0 == sText.length())
|
||||
return;
|
||||
|
||||
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
|
||||
pCell->m_oType.Init();
|
||||
|
||||
WCHAR *pEndPtr;
|
||||
double dValue = wcstod(sText.c_str(), &pEndPtr);
|
||||
if (0 != *pEndPtr)
|
||||
{
|
||||
// Не число
|
||||
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
|
||||
pCell->m_oRichText.Init();
|
||||
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
|
||||
pText->m_sText = sText;
|
||||
pCell->m_oRichText->m_arrItems.push_back(pText);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Число
|
||||
pCell->m_oValue.Init();
|
||||
pCell->m_oValue->m_sText = sText;
|
||||
}
|
||||
|
||||
if (bIsWrap)
|
||||
{
|
||||
// WrapStyle
|
||||
pCell->m_oStyle.Init();
|
||||
pCell->m_oStyle->SetValue(1);
|
||||
}
|
||||
|
||||
pCell->setRowCol(nRow, nCol);
|
||||
oRow.m_arrItems.push_back(pCell);
|
||||
}
|
||||
_UINT32 ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
if (false == oFile.OpenFile(sFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
|
||||
//-----------------------------------------------------------------------------------
|
||||
// Создадим Workbook
|
||||
oXlsx.CreateWorkbook();
|
||||
// Создадим стили
|
||||
oXlsx.CreateStyles();
|
||||
|
||||
// Добавим стили для wrap-а
|
||||
oXlsx.m_pStyles->m_oCellXfs.Init();
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_oCount.Init();
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_oCount->SetValue(2);
|
||||
|
||||
// Normall default
|
||||
OOX::Spreadsheet::CXfs* pXfs = NULL;
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
|
||||
|
||||
// Wrap style
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
|
||||
pXfs->m_oApplyAlignment.Init();
|
||||
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
|
||||
pXfs->m_oAligment.Init();
|
||||
pXfs->m_oAligment->m_oWrapText.Init();
|
||||
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
|
||||
|
||||
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
|
||||
|
||||
std::wstring sSheetRId = L"rId1";
|
||||
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet(NULL);
|
||||
pWorksheet->m_oSheetData.Init();
|
||||
|
||||
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
|
||||
|
||||
pSheet->m_oName.Init();
|
||||
pSheet->m_oName->append(L"Sheet1");
|
||||
pSheet->m_oSheetId.Init();
|
||||
pSheet->m_oSheetId->SetValue(1);
|
||||
pSheet->m_oRid.Init();
|
||||
pSheet->m_oRid->SetValue(sSheetRId);
|
||||
|
||||
oXlsx.m_pWorkbook->m_oSheets.Init();
|
||||
oXlsx.m_pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
DWORD nFileSize = 0;
|
||||
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
|
||||
|
||||
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
|
||||
oFile.CloseFile();
|
||||
//skip bom
|
||||
DWORD nInputBufferSize = nFileSize;
|
||||
BYTE* pInputBuffer = pFileData;
|
||||
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
|
||||
{
|
||||
nInputBufferSize -= 3;
|
||||
pInputBuffer += 3;
|
||||
}
|
||||
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
|
||||
{
|
||||
nInputBufferSize -= 2;
|
||||
pInputBuffer += 2;
|
||||
}
|
||||
|
||||
std::wstring sFileDataW;
|
||||
|
||||
if (nCodePage == 1000)
|
||||
{
|
||||
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 46)//utf-8
|
||||
{
|
||||
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 48)//utf-16
|
||||
{
|
||||
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else if (nCodePage == 50) // utf-32
|
||||
{
|
||||
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
#else
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
#endif
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
size_t nSize = sFileDataW.length();
|
||||
|
||||
if (nSize < 1 && nInputBufferSize > 0)
|
||||
{//для синхронности вывода превью и нормального результата
|
||||
#ifdef __ANDROID__
|
||||
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
#else
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
#endif
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
|
||||
nSize = sFileDataW.length();
|
||||
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;
|
||||
}
|
||||
const WCHAR *pTemp = sFileDataW.c_str();
|
||||
|
||||
WCHAR wcDelimiterLeading = L'\0';
|
||||
WCHAR wcDelimiterTrailing = L'\0';
|
||||
int nDelimiterSize = 0;
|
||||
|
||||
if (sDelimiter.length() > 0)
|
||||
{
|
||||
wcDelimiterLeading = sDelimiter[0];
|
||||
nDelimiterSize = 1;
|
||||
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
|
||||
{
|
||||
wcDelimiterTrailing = sDelimiter[1];
|
||||
nDelimiterSize = 2;
|
||||
}
|
||||
}
|
||||
|
||||
const WCHAR wcNewLineN = _T('\n');
|
||||
const WCHAR wcNewLineR = _T('\r');
|
||||
const WCHAR wcQuote = _T('"');
|
||||
const WCHAR wcTab = _T('\t');
|
||||
|
||||
bool bIsWrap = false;
|
||||
WCHAR wcCurrent;
|
||||
INT nStartCell = 0;
|
||||
std::stack<INT> oDeleteChars;
|
||||
|
||||
bool bInQuote = false;
|
||||
INT nIndexRow = 0;
|
||||
INT nIndexCol = 0;
|
||||
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(nIndexRow + 1);
|
||||
|
||||
for (size_t nIndex = 0; nIndex < nSize; ++nIndex)
|
||||
{
|
||||
wcCurrent = pTemp[nIndex];
|
||||
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
|
||||
{
|
||||
if (bInQuote)
|
||||
continue;
|
||||
// New Cell
|
||||
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = false;
|
||||
|
||||
nStartCell = nIndex + nDelimiterSize;
|
||||
if (nStartCell == nSize)
|
||||
{
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
pRow = NULL;
|
||||
}
|
||||
}
|
||||
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
|
||||
{
|
||||
if (bInQuote)
|
||||
{
|
||||
// Добавим Wrap
|
||||
bIsWrap = true;
|
||||
continue;
|
||||
}
|
||||
// New line
|
||||
if (nStartCell != nIndex)
|
||||
{
|
||||
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = false;
|
||||
}
|
||||
|
||||
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
|
||||
{
|
||||
// На комбинацию \r\n должен быть только 1 перенос
|
||||
++nIndex;
|
||||
}
|
||||
|
||||
nStartCell = nIndex + 1;
|
||||
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(++nIndexRow + 1);
|
||||
nIndexCol = 0;
|
||||
}
|
||||
else if (wcQuote == wcCurrent)
|
||||
{
|
||||
// Quote
|
||||
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
|
||||
{
|
||||
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
|
||||
bInQuote = !bInQuote;
|
||||
nStartCell = nIndex + 1;
|
||||
}
|
||||
else if ( bInQuote )
|
||||
{
|
||||
// Нужно удалить кавычку ограничитель
|
||||
oDeleteChars.push(nIndex);
|
||||
|
||||
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
|
||||
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
|
||||
++nIndex;
|
||||
else
|
||||
bInQuote = !bInQuote;
|
||||
}
|
||||
}
|
||||
else if (wcTab == wcCurrent)
|
||||
{
|
||||
// delete tab if not delimiter
|
||||
oDeleteChars.push(nIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (nStartCell != nSize)
|
||||
{
|
||||
// New line
|
||||
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(pRow);
|
||||
}
|
||||
oXlsx.m_arWorksheets.push_back(pWorksheet);
|
||||
oXlsx.m_mapWorksheets.insert(std::make_pair(sSheetRId, pWorksheet));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user