Compare commits

..

6 Commits

Author SHA1 Message Date
a17a04298a build linux 2017-05-16 12:39:01 +03:00
f7ba686f0c TestDocsWithChart 2017-05-15 20:21:11 +03:00
c41385e1ae open/save field ffdata 2017-05-15 20:20:26 +03:00
f582a9b690 . 2017-05-15 19:14:50 +03:00
b36c2dbaf9 verify ooxml file. first worked version 2017-05-15 18:14:19 +03:00
10b9e9e5e8 verify ooxml file. developing... 2017-05-15 16:44:50 +03:00
12 changed files with 752 additions and 26 deletions

View File

@ -3801,19 +3801,228 @@ public:
{
int res = c_oSerConstants::ReadOk;
CFldSimple* pFldSimple = static_cast<CFldSimple*>(poResult);
if ( c_oSer_HyperlinkType::Link == type )
if ( c_oSer_FldSimpleType::Instr == type )
pFldSimple->sInstr = m_oBufferedStream.GetString3(length);
else if ( c_oSer_HyperlinkType::Content == type )
else if ( c_oSer_FldSimpleType::Content == type )
{
XmlUtils::CStringWriter* pPrevWriter = m_pCurWriter;
m_pCurWriter = &pFldSimple->writer;
res = Read1(length, &Binary_DocumentTableReader::ReadParagraphContent, this, NULL);
m_pCurWriter = pPrevWriter;
}
else if ( c_oSer_FldSimpleType::FFData == type )
{
OOX::Logic::CFFData oFFData;
res = Read1(length, &Binary_DocumentTableReader::ReadFFData, this, &oFFData);
pFldSimple->writer.WriteString(oFFData.toXML());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadFFData(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
OOX::Logic::CFFData* pFFData = static_cast<OOX::Logic::CFFData*>(poResult);
if ( c_oSerFFData::CalcOnExit == type )
{
pFFData->m_oCalcOnExit.Init();
pFFData->m_oCalcOnExit->m_oVal.FromBool(m_oBufferedStream.GetBool());
}
else if ( c_oSerFFData::CheckBox == type )
{
pFFData->m_oCheckBox.Init();
res = Read1(length, &Binary_DocumentTableReader::ReadFFCheckBox, this, pFFData->m_oCheckBox.GetPointer());
}
else if ( c_oSerFFData::DDList == type )
{
pFFData->m_oDDList.Init();
res = Read1(length, &Binary_DocumentTableReader::ReadDDList, this, pFFData->m_oDDList.GetPointer());
}
else if ( c_oSerFFData::Enabled == type )
{
pFFData->m_oEnabled.Init();
pFFData->m_oEnabled->m_oVal.FromBool(m_oBufferedStream.GetBool());
}
else if ( c_oSerFFData::EntryMacro == type )
{
std::wstring sVal = m_oBufferedStream.GetString3(length);
pFFData->m_oEntryMacro.Init();
pFFData->m_oEntryMacro->m_oVal.Init();
pFFData->m_oEntryMacro->m_oVal->SetValue(sVal);
}
else if ( c_oSerFFData::ExitMacro == type )
{
std::wstring sVal = m_oBufferedStream.GetString3(length);
pFFData->m_oExitMacro.Init();
pFFData->m_oExitMacro->m_oVal.Init();
pFFData->m_oExitMacro->m_oVal->SetValue(sVal);
}
else if ( c_oSerFFData::HelpText == type )
{
pFFData->m_oHelpText.Init();
res = Read1(length, &Binary_DocumentTableReader::ReadFFHelpText, this, pFFData->m_oHelpText.GetPointer());
}
else if ( c_oSerFFData::Label == type )
{
pFFData->m_oLabel.Init();
pFFData->m_oLabel->m_oVal.Init();
pFFData->m_oLabel->m_oVal->SetValue(m_oBufferedStream.GetLong());
}
else if ( c_oSerFFData::Name == type )
{
std::wstring sVal = m_oBufferedStream.GetString3(length);
pFFData->m_oName.Init();
pFFData->m_oName->m_oVal.Init();
pFFData->m_oName->m_oVal->SetValue(sVal);
}
else if ( c_oSerFFData::StatusText == type )
{
pFFData->m_oStatusText.Init();
res = Read1(length, &Binary_DocumentTableReader::ReadFFStatusText, this, pFFData->m_oStatusText.GetPointer());
}
else if ( c_oSerFFData::TabIndex == type )
{
pFFData->m_oTabIndex.Init();
pFFData->m_oTabIndex->m_oVal.Init();
pFFData->m_oTabIndex->m_oVal->SetValue(m_oBufferedStream.GetLong());
}
else if ( c_oSerFFData::TextInput == type )
{
pFFData->m_oTextInput.Init();
res = Read1(length, &Binary_DocumentTableReader::ReadTextInput, this, pFFData->m_oTextInput.GetPointer());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadFFCheckBox(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
OOX::Logic::CFFCheckBox* pFFCheckBox = static_cast<OOX::Logic::CFFCheckBox*>(poResult);
if ( c_oSerFFData::CBChecked == type )
{
pFFCheckBox->m_oChecked.Init();
pFFCheckBox->m_oChecked->m_oVal.FromBool(m_oBufferedStream.GetBool());
}
else if ( c_oSerFFData::CBDefault == type )
{
pFFCheckBox->m_oDefault.Init();
pFFCheckBox->m_oDefault->m_oVal.FromBool(m_oBufferedStream.GetBool());
}
else if ( c_oSerFFData::CBSize == type )
{
pFFCheckBox->m_oSize.Init();
pFFCheckBox->m_oSize->m_oVal.Init();
pFFCheckBox->m_oSize->m_oVal->FromHps(m_oBufferedStream.GetULong());
}
else if ( c_oSerFFData::CBSizeAuto == type )
{
pFFCheckBox->m_oSizeAuto.Init();
pFFCheckBox->m_oSizeAuto->m_oVal.FromBool(m_oBufferedStream.GetBool());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadDDList(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
OOX::Logic::CFFDDList* pDDList = static_cast<OOX::Logic::CFFDDList*>(poResult);
if ( c_oSerFFData::DLDefault == type )
{
pDDList->m_oDefault.Init();
pDDList->m_oDefault->m_oVal.Init();
pDDList->m_oDefault->m_oVal->SetValue(m_oBufferedStream.GetLong());
}
else if ( c_oSerFFData::DLResult == type )
{
pDDList->m_oResult.Init();
pDDList->m_oResult->m_oVal.Init();
pDDList->m_oResult->m_oVal->SetValue(m_oBufferedStream.GetLong());
}
else if ( c_oSerFFData::DLListEntry == type )
{
ComplexTypes::Word::String* pVal = new ComplexTypes::Word::String();
pVal->m_sVal.Init();
pVal->m_sVal->append(m_oBufferedStream.GetString3(length));
pDDList->m_arrListEntry.push_back(pVal);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadFFHelpText(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
ComplexTypes::Word::CFFHelpText* pHelpText = static_cast<ComplexTypes::Word::CFFHelpText*>(poResult);
if ( c_oSerFFData::HTType == type )
{
pHelpText->m_oType.Init();
pHelpText->m_oType->SetValue((SimpleTypes::EInfoTextType)m_oBufferedStream.GetUChar());
}
else if ( c_oSerFFData::HTVal == type )
{
std::wstring sVal = m_oBufferedStream.GetString3(length);
pHelpText->m_oVal.Init();
pHelpText->m_oVal->SetValue(sVal);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadFFStatusText(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
ComplexTypes::Word::CFFStatusText* pStatusText = static_cast<ComplexTypes::Word::CFFStatusText*>(poResult);
if ( c_oSerFFData::HTType == type )
{
pStatusText->m_oType.Init();
pStatusText->m_oType->SetValue((SimpleTypes::EInfoTextType)m_oBufferedStream.GetUChar());
}
else if ( c_oSerFFData::HTVal == type )
{
std::wstring sVal = m_oBufferedStream.GetString3(length);
pStatusText->m_oVal.Init();
pStatusText->m_oVal->SetValue(sVal);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadTextInput(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
OOX::Logic::CFFTextInput* pTextInput = static_cast<OOX::Logic::CFFTextInput*>(poResult);
if ( c_oSerFFData::TIDefault == type )
{
pTextInput->m_oDefault.Init();
pTextInput->m_oDefault->m_sVal.Init();
pTextInput->m_oDefault->m_sVal->append(m_oBufferedStream.GetString3(length));
}
else if ( c_oSerFFData::TIFormat == type )
{
pTextInput->m_oFormat.Init();
pTextInput->m_oFormat->m_sVal.Init();
pTextInput->m_oFormat->m_sVal->append(m_oBufferedStream.GetString3(length));
}
else if ( c_oSerFFData::TIMaxLength == type )
{
pTextInput->m_oMaxLength.Init();
pTextInput->m_oMaxLength->m_oVal.Init();
pTextInput->m_oMaxLength->m_oVal->SetValue(m_oBufferedStream.GetLong());
}
else if ( c_oSerFFData::TIType == type )
{
pTextInput->m_oType.Init();
pTextInput->m_oType->m_oVal.Init();
pTextInput->m_oType->m_oVal->SetValue((SimpleTypes::EFFTextType)m_oBufferedStream.GetUChar());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadHyperlink(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;

View File

@ -912,7 +912,8 @@ extern int g_nCurFormatVersion;
namespace c_oSer_FldSimpleType{ enum c_oSer_FldSimpleType
{
Content = 0,
Instr = 1
Instr = 1,
FFData = 2
};}
namespace c_oSer_ColorThemeType{ enum c_oSer_ColorThemeType
{
@ -1044,6 +1045,34 @@ extern int g_nCurFormatVersion;
Temporary = 34,
MultiLine = 35
};}
namespace c_oSerFFData{enum c_oSerFFData
{
CalcOnExit = 0,
CheckBox = 1,
DDList = 2,
Enabled = 3,
EntryMacro = 4,
ExitMacro = 5,
HelpText = 6,
Label = 7,
Name = 8,
StatusText = 9,
TabIndex = 10,
TextInput = 11,
CBChecked = 12,
CBDefault = 13,
CBSize = 14,
CBSizeAuto = 15,
DLDefault = 16,
DLResult = 17,
DLListEntry = 18,
HTType = 19,
HTVal = 20,
TIDefault = 21,
TIFormat = 22,
TIMaxLength = 23,
TIType = 24,
};}
}
#endif // #ifndef DOCX_BIN_READER_WRITER_DEFINES

View File

@ -3321,11 +3321,208 @@ namespace BinDocxRW
nCurPos = m_oBcw.WriteItemStart(c_oSer_FldSimpleType::Instr);
m_oBcw.m_oStream.WriteStringW3(*pFldSimple->m_sInstr);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
//FFData
if(pFldSimple->m_oFFData.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_FldSimpleType::FFData);
WriteFFData(pFldSimple->m_oFFData.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//Content
nCurPos = m_oBcw.WriteItemStart(c_oSer_FldSimpleType::Content);
WriteParagraphContent(pFldSimple->m_arrItems);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
void WriteFFData(const OOX::Logic::CFFData& oFFData)
{
int nCurPos = 0;
if(oFFData.m_oCalcOnExit.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CalcOnExit);
m_oBcw.m_oStream.WriteBOOL(oFFData.m_oCalcOnExit->m_oVal.ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oCheckBox.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CheckBox);
WriteFFCheckBox(oFFData.m_oCheckBox.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oDDList.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::DDList);
WriteDDList(oFFData.m_oDDList.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oEnabled.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::Enabled);
m_oBcw.m_oStream.WriteBOOL(oFFData.m_oEnabled->m_oVal.ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oEntryMacro.IsInit() && oFFData.m_oEntryMacro->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::EntryMacro);
m_oBcw.m_oStream.WriteStringW3(oFFData.m_oEntryMacro->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oExitMacro.IsInit() && oFFData.m_oExitMacro->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::ExitMacro);
m_oBcw.m_oStream.WriteStringW3(oFFData.m_oExitMacro->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oHelpText.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::HelpText);
WriteFFHelpText(oFFData.m_oHelpText.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oLabel.IsInit() && oFFData.m_oLabel->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::Label);
m_oBcw.m_oStream.WriteLONG(oFFData.m_oLabel->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oName.IsInit() && oFFData.m_oName->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::Name);
m_oBcw.m_oStream.WriteStringW3(oFFData.m_oName->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oStatusText.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::StatusText);
WriteFFStatusText(oFFData.m_oStatusText.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oTabIndex.IsInit() && oFFData.m_oTabIndex->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TabIndex);
m_oBcw.m_oStream.WriteLONG(oFFData.m_oTabIndex->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oFFData.m_oTextInput.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TextInput);
WriteTextInput(oFFData.m_oTextInput.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteFFCheckBox(const OOX::Logic::CFFCheckBox& oCheckBox)
{
int nCurPos = 0;
if(oCheckBox.m_oChecked.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CBChecked);
m_oBcw.m_oStream.WriteBOOL(oCheckBox.m_oChecked->m_oVal.ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oCheckBox.m_oDefault.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CBDefault);
m_oBcw.m_oStream.WriteBOOL(oCheckBox.m_oDefault->m_oVal.ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oCheckBox.m_oSize.IsInit() && oCheckBox.m_oSize->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CBSize);
m_oBcw.m_oStream.WriteULONG(oCheckBox.m_oSize->m_oVal->ToHps());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oCheckBox.m_oSizeAuto.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::CBSizeAuto);
m_oBcw.m_oStream.WriteBOOL(oCheckBox.m_oSizeAuto->m_oVal.ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteDDList(const OOX::Logic::CFFDDList& oDDList)
{
int nCurPos = 0;
if(oDDList.m_oDefault.IsInit() && oDDList.m_oDefault->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::DLDefault);
m_oBcw.m_oStream.WriteLONG(oDDList.m_oDefault->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oDDList.m_oResult.IsInit() && oDDList.m_oResult->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::DLResult);
m_oBcw.m_oStream.WriteLONG(oDDList.m_oResult->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
for(int i = 0 ; i < oDDList.m_arrListEntry.size(); ++i)
{
ComplexTypes::Word::String* pVal = oDDList.m_arrListEntry[i];
if(pVal->m_sVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::DLListEntry);
m_oBcw.m_oStream.WriteStringW3(pVal->m_sVal.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
}
void WriteFFHelpText(const ComplexTypes::Word::CFFHelpText& oHelpText)
{
int nCurPos = 0;
if(oHelpText.m_oType.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::HTType);
m_oBcw.m_oStream.WriteBYTE(oHelpText.m_oType->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oHelpText.m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::HTVal);
m_oBcw.m_oStream.WriteStringW3(oHelpText.m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteFFStatusText(const ComplexTypes::Word::CFFStatusText& oStatusText)
{
int nCurPos = 0;
if(oStatusText.m_oType.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::HTType);
m_oBcw.m_oStream.WriteBYTE(oStatusText.m_oType->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oStatusText.m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::HTVal);
m_oBcw.m_oStream.WriteStringW3(oStatusText.m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteTextInput(const OOX::Logic::CFFTextInput& oTextInput)
{
int nCurPos = 0;
if(oTextInput.m_oDefault.IsInit() && oTextInput.m_oDefault->m_sVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TIDefault);
m_oBcw.m_oStream.WriteStringW3(oTextInput.m_oDefault->m_sVal.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oTextInput.m_oFormat.IsInit() && oTextInput.m_oFormat->m_sVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TIFormat);
m_oBcw.m_oStream.WriteStringW3(oTextInput.m_oFormat->m_sVal.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oTextInput.m_oMaxLength.IsInit() && oTextInput.m_oMaxLength->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TIMaxLength);
m_oBcw.m_oStream.WriteLONG(oTextInput.m_oMaxLength->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(oTextInput.m_oType.IsInit() && oTextInput.m_oType->m_oVal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerFFData::TIType);
m_oBcw.m_oStream.WriteBYTE(oTextInput.m_oType->m_oVal->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteHyperlink(OOX::Logic::CHyperlink* pHyperlink)
{

View File

@ -799,7 +799,7 @@ namespace ComplexTypes
if ( m_oVal.IsInit() )
{
sResult += _T("w:val=\"");
sResult += m_oVal->ToString();
sResult += std::to_wstring(m_oVal->ToHps());
sResult += _T("\" ");
}

View File

@ -3085,6 +3085,11 @@ namespace SimpleTypes
m_dValue = fabs( dValue * 72.0 );
return m_dValue;
}
virtual double FromHps(double dValue)
{
m_dValue = dValue / 2;
return m_dValue;
}
SimpleType_FromString (double)
SimpleType_Operator_Equal (CHpsMeasure)
UniversalMeasure_AdditionalOpearators(CHpsMeasure)

View File

@ -142,6 +142,8 @@ namespace OOX
pItem = new CSmartTag( oItem );
//else if ( _T("w:subDoc") == sName )
// pItem = new CSubDoc( oItem );
else if ( _T("w:ffData") == sName )
m_oFFData = new CFFData( oItem );
if ( pItem )
m_arrItems.push_back( pItem );
@ -232,6 +234,8 @@ namespace OOX
pItem = new CSmartTag( oReader );
//else if ( _T("w:subDoc") == sName )
// pItem = new CSubDoc( oReader );
else if ( _T("w:ffData") == sName )
m_oFFData = new CFFData( oReader );
if ( pItem )
m_arrItems.push_back( pItem );
@ -259,6 +263,11 @@ namespace OOX
sResult += _T(">");
if (m_oFFData.IsInit())
{
sResult += m_oFFData->toXML();
}
for (unsigned int nIndex = 0; nIndex < m_arrItems.size(); nIndex++ )
{
if ( m_arrItems[nIndex] )

View File

@ -38,6 +38,7 @@
#include "../WritingElement.h"
#include "../../Common/SimpleTypes_Word.h"
#include "../../Common/SimpleTypes_Shared.h"
#include "../../DocxFormat/Logic/FldChar.h"
namespace OOX
{
@ -120,6 +121,7 @@ namespace OOX
nullable<std::wstring > m_sInstr;
// Childs
nullable<OOX::Logic::CFFData > m_oFFData;
};
} // namespace Logic

View File

@ -20,6 +20,8 @@ private:
std::string m_sImageValidBase64;
std::string m_sImageInvalidBase64;
std::wstring m_sFolder;
private:
XmlUtils::CXmlNode m_node; // signature file
@ -50,16 +52,23 @@ private:
return *this;
}
CXmlStackNamespaces GetById(const std::string& id)
CXmlStackNamespaces GetById(const std::string& id, const bool& isNameUse = false)
{
return GetByIdRec(*this, id);
return GetByIdRec(*this, id, isNameUse);
}
CXmlStackNamespaces GetByIdRec(CXmlStackNamespaces& stack, const std::string& id)
CXmlStackNamespaces GetByIdRec(CXmlStackNamespaces& stack, const std::string& id, const bool& isNameUse = false)
{
if (stack.m_node.GetAttributeA("Id") == id)
return stack;
if (isNameUse)
{
std::string sName = U_TO_UTF8((stack.m_node.GetName()));
if (sName == id)
return stack;
}
CXmlStackNamespaces ret = stack;
std::vector<std::wstring> _names;
@ -90,7 +99,7 @@ private:
for (int i = 0; i < nCount; i++)
{
oNodes.GetAt(i, ret.m_node);
CXmlStackNamespaces _retRecursion = ret.GetByIdRec(ret, id);
CXmlStackNamespaces _retRecursion = ret.GetByIdRec(ret, id, isNameUse);
if (_retRecursion.m_node.IsValid())
return _retRecursion;
}
@ -108,7 +117,15 @@ private:
std::wstring sXmlFind = L"<" + sName + L" ";
if (0 == sXml.find(sXmlFind))
{
sXml.replace(0, sXmlFind.length(), L"<" + sName + L" " + m_namespaces + L" ");
}
else
{
sXmlFind = L"<" + sName + L">";
if (0 == sXml.find(sXmlFind))
sXml.replace(0, sXmlFind.length(), L"<" + sName + L" " + m_namespaces + L">");
}
}
return U_TO_UTF8(sXml);
@ -152,7 +169,7 @@ public:
public:
void Check()
{
// 1) get cert
// 1) Certificate
XmlUtils::CXmlNode oNodeCert = m_node.ReadNode(L"KeyInfo").ReadNode(L"X509Data").ReadNode(L"X509Certificate");
if (!oNodeCert.IsValid())
{
@ -166,28 +183,212 @@ public:
return;
}
// 2) Objects
// 2) Check files (Manifect)
XmlUtils::CXmlNode nodeManifect = GetObjectById("idPackageObject");
if (!nodeManifect.IsValid())
{
m_valid = OOXML_SIGNATURE_INVALID;
return;
}
XmlUtils::CXmlNodes nodesManifestRefs = nodeManifect.ReadNode(L"Manifest").GetNodes(L"Reference");
int nRefsCount = nodesManifestRefs.GetCount();
for (int i = 0; i < nRefsCount; i++)
{
XmlUtils::CXmlNode tmp;
nodesManifestRefs.GetAt(i, tmp);
m_valid = CheckManifestReference(tmp);
if (OOXML_SIGNATURE_VALID != m_valid)
return;
}
// 3) Images
XmlUtils::CXmlNode nodeImageValid = GetObjectById("idValidSigLnImg");
if (nodeImageValid.IsValid())
m_sImageValidBase64 = U_TO_UTF8(nodeImageValid.GetText());
XmlUtils::CXmlNode nodeImageInvalid = GetObjectById("idInvalidSigLnImg");
if (nodeImageInvalid.IsValid())
m_sImageInvalidBase64 = U_TO_UTF8(nodeImageInvalid.GetText());
// 4) Objects
XmlUtils::CXmlNodes nodesReferences;
m_node.ReadNode(L"SignedInfo").GetNodes(L"Reference", nodesReferences);
nRefsCount = nodesReferences.GetCount();
for (int i = 0; i < nRefsCount; i++)
{
XmlUtils::CXmlNode tmp;
nodesReferences.GetAt(i, tmp);
m_valid = CheckObjectReference(tmp);
if (OOXML_SIGNATURE_VALID != m_valid)
return;
}
// 5) Check signature
CXmlStackNamespaces stack(m_node);
int nCount = nodesReferences.GetCount();
CXmlStackNamespaces stackRes = stack.GetById("SignedInfo", true);
std::string sXml = stackRes.GetXml();
std::string sCanonicalizationMethod = m_node.ReadNode(L"SignedInfo").ReadNode(L"CanonicalizationMethod").GetAttributeA("Algorithm");
std::string sSignatureMethod = m_node.ReadNode(L"SignedInfo").ReadNode(L"SignatureMethod").GetAttributeA("Algorithm");
int nSignatureMethod = ICertificate::GetOOXMLHashAlg(sSignatureMethod);
if (OOXML_HASH_ALG_INVALID == nSignatureMethod)
{
m_valid = OOXML_SIGNATURE_NOTSUPPORTED;
return;
}
IXmlTransform* pCanonicalizationMethodTransform = IXmlTransform::GetFromType(sCanonicalizationMethod);
if (NULL == pCanonicalizationMethodTransform)
{
m_valid = OOXML_SIGNATURE_NOTSUPPORTED;
return;
}
std::string sSignatureCalcValue = pCanonicalizationMethodTransform->Transform(sXml);
RELEASEOBJECT(pCanonicalizationMethodTransform);
std::string sSignatureValue = U_TO_UTF8((m_node.ReadValueString(L"SignatureValue")));
if (!m_cert->Verify(sSignatureCalcValue, sSignatureValue, nSignatureMethod))
m_valid = OOXML_SIGNATURE_INVALID;
}
XmlUtils::CXmlNode GetObjectById(std::string sId)
{
XmlUtils::CXmlNodes oNodes = m_node.GetNodes(L"Object");
int nCount = oNodes.GetCount();
for (int i = 0; i < nCount; i++)
{
XmlUtils::CXmlNode nodeRef;
nodesReferences.GetAt(i, nodeRef);
std::string sId = nodeRef.GetAttributeA("URI");
if (0 == sId.find("#"))
sId = sId.substr(1);
CXmlStackNamespaces _stack = stack.GetById(sId);
std::string sTmp = _stack.GetXml();
XML_UNUSED(sTmp);
XmlUtils::CXmlNode tmp;
oNodes.GetAt(i, tmp);
if (sId == tmp.GetAttributeA("Id"))
return tmp;
}
XmlUtils::CXmlNode ret;
return ret;
}
friend class COOXMLVerifier;
private:
int CheckManifestReference(XmlUtils::CXmlNode& node)
{
std::wstring sFile = node.GetAttribute("URI");
std::wstring::size_type nPos = sFile.find(L"?");
if (nPos == std::wstring::npos)
return OOXML_SIGNATURE_INVALID;
sFile = sFile.substr(0, nPos);
sFile = m_sFolder + sFile;
if (!NSFile::CFileBinary::Exists(sFile))
return OOXML_SIGNATURE_INVALID;
XmlUtils::CXmlNode nodeMethod = node.ReadNode(L"DigestMethod");
if (!nodeMethod.IsValid())
return OOXML_SIGNATURE_INVALID;
int nAlg = ICertificate::GetOOXMLHashAlg(nodeMethod.GetAttributeA("Algorithm"));
if (OOXML_HASH_ALG_INVALID == nAlg)
return OOXML_SIGNATURE_NOTSUPPORTED;
std::string sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
std::string sCalcValue = "";
XmlUtils::CXmlNode nodeTransform = node.ReadNode(L"Transforms");
if (!nodeTransform.IsValid())
{
// simple hash
sCalcValue = m_cert->GetHash(sFile, nAlg);
sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
}
else
{
// XML
CXmlTransforms oTransforms(nodeTransform);
if (!oTransforms.GetValid())
return OOXML_SIGNATURE_NOTSUPPORTED;
std::string sXml;
NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sXml);
sXml = oTransforms.Transform(sXml);
sCalcValue = m_cert->GetHash(sXml, nAlg);
sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
}
if (sCalcValue != sValue)
return OOXML_SIGNATURE_INVALID;
return OOXML_SIGNATURE_VALID;
}
int CheckObjectReference(XmlUtils::CXmlNode& node)
{
std::string sURI = node.GetAttributeA("URI");
if ("" == sURI)
return OOXML_SIGNATURE_INVALID;
if (0 == sURI.find("#"))
sURI = sURI.substr(1);
std::string sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
CXmlTransforms oTransforms;
CXmlTransformC14N* pTransform = new CXmlTransformC14N();
pTransform->CheckC14NTransform("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
oTransforms.AddTransform(pTransform);
#if 0
XmlUtils::CXmlNode nodeTransform = node.ReadNode(L"Transforms");
if (!nodeTransform.IsValid())
{
// simple hash
sCalcValue = m_cert->GetHash(sFile, nAlg);
sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
}
else
{
// XML
CXmlTransforms oTransforms(nodeTransform);
if (!oTransforms.GetValid())
return OOXML_SIGNATURE_NOTSUPPORTED;
std::string sXml;
NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sXml);
sXml = oTransforms.Transform(sXml);
sCalcValue = m_cert->GetHash(sXml, nAlg);
sValue = U_TO_UTF8((node.ReadNodeText(L"DigestValue")));
}
#endif
CXmlStackNamespaces stack(m_node);
CXmlStackNamespaces stackRes = stack.GetById(sURI);
std::string sXml = stackRes.GetXml();
sXml = oTransforms.Transform(sXml);
XmlUtils::CXmlNode nodeMethod = node.ReadNode(L"DigestMethod");
if (!nodeMethod.IsValid())
return OOXML_SIGNATURE_INVALID;
int nAlg = ICertificate::GetOOXMLHashAlg(nodeMethod.GetAttributeA("Algorithm"));
std::string sCalcValue = m_cert->GetHash(sXml, nAlg);
if (sCalcValue != sValue)
return OOXML_SIGNATURE_INVALID;
return OOXML_SIGNATURE_VALID;
}
};
class COOXMLVerifier
@ -229,6 +430,7 @@ public:
COOXMLSignature* pSignature = new COOXMLSignature();
pSignature->m_node = nodeSig;
pSignature->m_sFolder = m_sFolder;
pSignature->Check();
m_arSignatures.push_back(pSignature);

View File

@ -181,6 +181,9 @@ public:
bResult = CryptAcquireCertificatePrivateKey(m_context, 0, NULL, &hCryptProv, &dwKeySpec, NULL);
if (!bResult)
bResult = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
if (!bResult)
return "";
@ -264,14 +267,17 @@ public:
BOOL bResult = CryptAcquireCertificatePrivateKey(m_context, 0, NULL, &hCryptProv, &dwKeySpec, NULL);
if (!bResult)
return FALSE;
bResult = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
if (!bResult)
return false;
bResult = CryptCreateHash(hCryptProv, GetHashId(nAlg), 0, 0, &hHash);
if (!bResult)
{
CryptReleaseContext(hCryptProv, 0);
return FALSE;
return false;
}
BYTE* pDataHash = NULL;

View File

@ -110,8 +110,9 @@ public:
virtual std::string Transform(const std::string& xml)
{
// TODO
return xml;
if (-1 == m_mode)
return xml;
return CXmlCanonicalizator::Execute(xml, m_mode, m_comments);
}
virtual void LoadFromXml(XmlUtils::CXmlNode& node)
@ -148,6 +149,11 @@ protected:
bool m_valid;
public:
CXmlTransforms()
{
m_valid = true;
}
CXmlTransforms(XmlUtils::CXmlNode& node)
{
m_valid = true;
@ -181,6 +187,25 @@ public:
m_transforms.clear();
}
bool GetValid()
{
return m_valid;
}
std::string Transform(const std::string& xml)
{
std::string sResult = xml;
for (std::vector<IXmlTransform*>::iterator i = m_transforms.begin(); i != m_transforms.end(); i++)
{
sResult = (*i)->Transform(sResult);
}
return sResult;
}
void AddTransform(IXmlTransform* transform)
{
m_transforms.push_back(transform);
}
};
#endif //_XML_TRANSFORM_H_

View File

@ -37,7 +37,9 @@ void main(void)
for (std::vector<COOXMLSignature*>::iterator i = oVerifier.m_arSignatures.begin(); i != oVerifier.m_arSignatures.end(); i++)
{
COOXMLSignature* pSign = *i;
int nRes = pSign->GetValid();
XML_UNUSED(pSign);
XML_UNUSED(nRes);
}
XML_UNUSED(nCount);

View File

@ -45,7 +45,8 @@ namespace TestDocsWithChart
{
static void Main(string[] args)
{
getFilesPivot();
getFilesConditional();
//getFilesPivot();
//getFilesAlternateContent();
//getFiles();
//convertFiles();
@ -74,6 +75,45 @@ namespace TestDocsWithChart
}
}
static void getFilesConditional()
{
//string sFindText = "conditionalFormatting";
//string sDirInput = @"\\192.168.3.208\allusers\Files\XLSX";
//string sDirOutput = @"D:\Files\Conditional";
string sFindText = "type=\"expression\"";
string sDirInput = @"D:\Files\Conditional";
string sDirOutput = @"D:\Files\ConditionalFormulaExpression";
String[] allfiles = System.IO.Directory.GetFiles(sDirInput, "*.*", System.IO.SearchOption.AllDirectories);
for (var i = 0; i < allfiles.Length; ++i)
{
string file = allfiles[i];
try
{
ZipArchive zip = ZipFile.OpenRead(file);
string sOutputPath = Path.Combine(sDirOutput, Path.GetFileName(file));
foreach (ZipArchiveEntry entry in zip.Entries)
{
if (entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
{
using (StreamReader reader = new StreamReader(entry.Open(), Encoding.UTF8))
{
string sXml = reader.ReadToEnd();
if (-1 != sXml.IndexOf(sFindText))
{
System.IO.File.Copy(file, sOutputPath, true);
}
}
}
}
}
catch (Exception e)
{
}
}
}
static void getFilesAlternateContent()
{
string sAlternateContent = ":Choice ";