Compare commits

..

23 Commits

Author SHA1 Message Date
9b5f052c97 OdfFormatWriter - fix after testing 2018-10-11 17:57:45 +03:00
2017a8c692 OdfFormat - fix after testing 2018-10-10 19:29:31 +03:00
558c669fb6 Disable truetype fonts convertasion in html viewer 2018-10-10 15:58:26 +03:00
6268e8c3f3 PptxFormat - fix after testing 2018-10-10 11:27:39 +03:00
3c24392e16 PptxFormat - fix after testing 2018-10-09 18:13:57 +03:00
5c1a2f11f9 XlsFormatReader - fix users file (external defined names) 2018-10-09 14:53:04 +03:00
f7a13e04d8 DocxFormat - fix read binary file - bug #39248 2018-10-09 14:02:15 +03:00
c6e47a7bcf DocxFormat - fix bug #39216 2018-10-08 13:08:17 +03:00
62d6581c43 DocFormatReader - fix bug #39236 2018-10-08 11:32:31 +03:00
2d0e5aefa0 Merge pull request #117 from ONLYOFFICE/feature/aspose-math
Feature/aspose math
2018-10-05 17:04:41 +03:00
78a5546d0a PptxFormat - fix binary convert mathType version over 3.0 2018-10-05 12:49:01 +03:00
f55a5418e9 x2t - fix pptx section list 2018-10-04 17:39:32 +03:00
9410862444 [x2t] Fix bin->docx default style falg 2018-10-04 15:08:14 +03:00
f078605031 x2t - select method encrypt files 2018-10-04 13:01:49 +03:00
9105894416 . 2018-10-04 11:32:05 +03:00
1102f7f9b0 OdfFormat - not strong encryption 2018-10-03 20:13:49 +03:00
9aad3d1adb x2t - ooxml - not strong encryption 2018-10-03 20:01:57 +03:00
8d664c2a4f . 2018-10-03 17:22:33 +03:00
cbfa907451 graphics - metafile - fix convert to rastr on linux without set fonts 2018-10-03 15:02:29 +03:00
0712bcfd5c OdfFormatwriter - convert bookmarks 2018-10-02 19:16:14 +03:00
474873531d OdfFormatReader - fix bug #39192 2018-10-02 14:47:38 +03:00
1955dc98df [x2t] Set default value for math nodes with val attribute and COnOff type 2018-09-20 17:38:30 +03:00
158692f824 [x2t] Fix opening docx with track changes and math created by aspose 2018-09-19 16:53:05 +03:00
61 changed files with 1584 additions and 784 deletions

View File

@ -54,6 +54,7 @@
#include "../../DesktopEditor/common/Types.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/DocxFormat/Source/Base/Types_32.h"
#include "../../UnicodeConverter/UnicodeConverter.h"
#include <boost/format.hpp>

View File

@ -484,6 +484,266 @@ namespace DocFileFormat
return result_cp;
}
void DocumentMapping::writeField(const std::wstring& sFieldString, int cpFieldStart, int cpFieldEnd)
{
_fieldLevels.push_back(fieldLevels());
std::vector<std::wstring> arField;
boost::algorithm::split(arField, sFieldString, boost::algorithm::is_any_of(L"\\"), boost::algorithm::token_compress_on);
std::wstring f;
std::wstring EMBED ( L"EMBED" );
std::wstring embed ( L"embed" );
std::wstring LINK ( L"LINK" );
std::wstring FORM ( L"FORM" );
std::wstring Excel ( L"Excel" );
std::wstring Word ( L"Word" );
std::wstring opendocument(L"opendocument" );
std::wstring Equation ( L"Equation" );
std::wstring MERGEFORMAT( L"MERGEFORMAT" );
std::wstring QUOTE ( L"QUOTE" );
std::wstring chart ( L"Chart" );
std::wstring PBrush ( L"PBrush" );
std::wstring TOC ( L"TOC" );
std::wstring HYPERLINK ( L"HYPERLINK" );
std::wstring PAGEREF ( L"PAGEREF" );
std::wstring PAGE ( L"PAGE" );
std::wstring SHAPE ( L"SHAPE" );
if (arField.empty() == false)
f = arField[0];
else
f = sFieldString;
bool bChart = search( f.begin(), f.end(), chart.begin(), chart.end()) != f.end();
bool bEMBED = search( f.begin(), f.end(), EMBED.begin(), EMBED.end()) != f.end() ||
search( f.begin(), f.end(), embed.begin(), embed.end()) != f.end();
bool bLINK = search( f.begin(), f.end(), LINK.begin(), LINK.end()) != f.end();
bool bOpendocument = search( f.begin(), f.end(), opendocument.begin(), opendocument.end()) != f.end();
bool bFORM = search( f.begin(), f.end(), FORM.begin(), FORM.end()) != f.end();
bool bMERGEFORMAT = search( f.begin(), f.end(), MERGEFORMAT.begin(), MERGEFORMAT.end()) != f.end();
bool bExcel = search( f.begin(), f.end(), Excel.begin(), Excel.end()) != f.end();
bool bWord = search( f.begin(), f.end(), Word.begin(), Word.end()) != f.end();
bool bHYPERLINK = search( f.begin(), f.end(), HYPERLINK.begin(), HYPERLINK.end()) != f.end();
bool bQUOTE = search( f.begin(), f.end(), QUOTE.begin(), QUOTE.end()) != f.end();
bool bEquation = search( f.begin(), f.end(), Equation.begin(), Equation.end()) != f.end();
bool bPAGE = search( f.begin(), f.end(), PAGE.begin(), PAGE.end()) != f.end();
bool bTOC = search( f.begin(), f.end(), TOC.begin(), TOC.end()) != f.end();
bool bSHAPE = search( f.begin(), f.end(), SHAPE.begin(), SHAPE.end()) != f.end();
bool bPAGEREF = false;
if (bHYPERLINK && arField.size() > 1)
{
std::wstring f1 = arField[1];
bPAGEREF = search( f1.begin(), f1.end(), PAGEREF.begin(), PAGEREF.end()) != f1.end();
}
if (bTOC)
_bContentWrite = true;
if ( bFORM )
{
std::wstring FORMTEXT ( L" FORMTEXT" );
std::wstring FORMCHECKBOX ( L" FORMCHECKBOX" );
std::wstring FORMDROPDOWN ( L" FORMDROPDOWN" );
m_pXmlWriter->WriteNodeBegin( L"w:fldChar" , true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType" , L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true, false );
bool bFORMTEXT = search( f.begin(), f.end(), FORMTEXT.begin(), FORMTEXT.end()) != f.end();
bool bFORMCHECKBOX = search( f.begin(), f.end(), FORMCHECKBOX.begin(), FORMCHECKBOX.end()) != f.end();
bool bFORMDROPDOWN = search( f.begin(), f.end(), FORMDROPDOWN.begin(), FORMDROPDOWN.end()) != f.end();
if (bFORMTEXT || bFORMCHECKBOX || bFORMDROPDOWN)
{
int cpPic = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::Picture );
if (cpPic < cpFieldEnd)
{
int fcPic = m_document->FindFileCharPos( cpPic );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions(fcPic, fcPic + 1);
if (chpxs)
{
CharacterPropertyExceptions* chpxSep = chpxs->front();
FormFieldData ffdata (2, chpxSep, m_document->DataStream, false);
FormFieldDataMapping data_mapping(m_pXmlWriter, m_context, _caller);
ffdata.Convert(&data_mapping);
RELEASEOBJECT( chpxs );
}
}
}
m_pXmlWriter->WriteNodeEnd( L"w:fldChar" );
_fieldLevels.back().bBegin = true;
}
else if ( ( bMERGEFORMAT || bExcel || bWord || bOpendocument )
&&
( ( bEMBED || bLINK ) && bChart) )
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true, false );
int cpPic = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::Picture );
m_pXmlWriter->WriteNodeEnd( L"w:fldChar" );
_fieldLevels.back().bBegin = true;
}
else if (bHYPERLINK && bPAGEREF)
{
int cpFieldSep2 = cpFieldStart, cpFieldSep1 = cpFieldStart;
std::vector<std::wstring> toc;
if (arField.size() > 1)
f = arField[1];
if ( _bContentWrite )
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true );
_fieldLevels.back().bBegin = true;
}
else
{
for (size_t i = 1; i < arField.size(); i++)
{
std::wstring f1 = arField[1];
int d = (int)f1.find(PAGEREF);
if (d > 0)
{
_writeWebHidden = true;
std::wstring _writeTocLink =f1.substr(d + 9);
d = (int)_writeTocLink.find(L" ");
_writeTocLink = _writeTocLink.substr(0, d);
_writeAfterRun = std::wstring (L"<w:hyperlink w:anchor = \"");
_writeAfterRun += _writeTocLink;
_writeAfterRun += std::wstring (L"\" w:history=\"1\">");
break;
//cp = cpFieldSep1;
}
//cpFieldSep1 = cpFieldSep2;
}
_skipRuns = 5; //with separator
}
}
else if ( bEMBED || (bLINK && !bHYPERLINK)|| bQUOTE)
{
int cpPic = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::Picture);
int cpFieldSep = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::FieldSeparator);
if (cpPic < cpFieldEnd)
{
int fcPic = m_document->FindFileCharPos( cpPic );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions(fcPic, fcPic + 1);
CharacterPropertyExceptions* chpxObj = chpxs->front();
RevisionData oData = RevisionData(chpxObj);
CharacterPropertiesMapping* rPr = new CharacterPropertiesMapping(m_pXmlWriter, m_document, &oData, _lastValidPapx, false);
if(rPr)
{
chpxObj->Convert(rPr);
RELEASEOBJECT(rPr);
}
XMLTools::CStringXmlWriter oleWriter;
XMLTools::CStringXmlWriter oleObjectWriter;
VMLPictureMapping oVmlMapper (m_context, &oleWriter, true, _caller);
if (!m_shapeIdOwner.empty()) //4571833.doc
oVmlMapper.m_shapeId = m_shapeIdOwner;
if (m_document->nWordVersion > 0)
{
OleObject ole ( chpxObj, m_document);
oleWriter.WriteNodeBegin (L"w:object", true);
oleWriter.WriteAttribute( L"w:dxaOrig", FormatUtils::IntToWideString( ( ole.pictureDesciptor.dxaGoal + ole.pictureDesciptor.dxaOrigin ) ));
oleWriter.WriteAttribute( L"w:dyaOrig", FormatUtils::IntToWideString( ( ole.pictureDesciptor.dyaGoal + ole.pictureDesciptor.dyaOrigin ) ));
oleWriter.WriteNodeEnd( L"", true, false );
ole.pictureDesciptor.Convert(&oVmlMapper);
OleObjectMapping oleObjectMapping( &oleObjectWriter, m_context, &ole.pictureDesciptor, _caller, oVmlMapper.m_shapeId);
ole.Convert( &oleObjectMapping );
_lastOLEObject = oleObjectWriter.GetXmlString();
}
else
{
PictureDescriptor pic(chpxObj, m_document->DataStream, 0x7fffffff, m_document->nWordVersion);
oleWriter.WriteNodeBegin (L"w:object", true);
oleWriter.WriteAttribute( L"w:dxaOrig", FormatUtils::IntToWideString( ( pic.dxaGoal + pic.dxaOrigin ) ) );
oleWriter.WriteAttribute( L"w:dyaOrig", FormatUtils::IntToWideString( ( pic.dyaGoal + pic.dyaOrigin ) ) );
oleWriter.WriteNodeEnd( L"", true, false );
pic.Convert(&oVmlMapper);
RELEASEOBJECT(chpxs);
if ( cpFieldSep < cpFieldEnd && m_document->m_PieceTable)
{
int fcFieldSep = m_document->m_PieceTable->FileCharacterPositions->operator []( cpFieldSep );
int fcFieldSep1 = m_document->FindFileCharPos( cpFieldSep );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions( fcFieldSep, ( fcFieldSep + 1 ) );
CharacterPropertyExceptions* chpxSep = chpxs->front();
OleObject ole ( chpxSep, m_document);
OleObjectMapping oleObjectMapping( &oleObjectWriter, m_context, &pic, _caller, oVmlMapper.m_shapeId );
if (oVmlMapper.m_isEmbedded)
{
ole.isEquation = oVmlMapper.m_isEquation;
ole.isEmbedded = oVmlMapper.m_isEmbedded;
ole.emeddedData = oVmlMapper.m_embeddedData;
}
ole.Convert( &oleObjectMapping );
_lastOLEObject = oleObjectWriter.GetXmlString();
RELEASEOBJECT( chpxs );
}
}
oleWriter.WriteString( _lastOLEObject );
oleWriter.WriteNodeEnd( L"w:object" );
if (!oVmlMapper.m_isEmbedded && oVmlMapper.m_isEquation)
{
//нельзя в Run писать oMath
//m_pXmlWriter->WriteString(oVmlMapper.m_equationXml);
_writeAfterRun = oVmlMapper.m_equationXml;
}
else
{
m_pXmlWriter->WriteString(oleWriter.GetXmlString());
}
}
_skipRuns = 3;
_embeddedObject = true;
}
else
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true );
_fieldLevels.back().bBegin = true;
}
}
// Writes the given text to the document
int DocumentMapping::writeText(std::vector<wchar_t>* chars, int initialCp, CharacterPropertyExceptions* chpx, bool writeDeletedText)
{
@ -576,289 +836,15 @@ namespace DocFileFormat
}
else if (TextMark::FieldBeginMark == code)
{
_fieldLevels.push_back(fieldLevels());
int cpFieldStart = initialCp + i;
int cpFieldEnd = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::FieldEndMark );
std::wstring f, sFieldString;
std::wstring sFieldString;
if (cpFieldEnd < (int)m_document->Text->size())
sFieldString = std::wstring( ( m_document->Text->begin() + cpFieldStart ), ( m_document->Text->begin() + cpFieldEnd + 1 ) );
std::vector<std::wstring> arField;
boost::algorithm::split(arField, sFieldString, boost::algorithm::is_any_of(L"\\"), boost::algorithm::token_compress_on);
std::wstring EMBED ( L"EMBED" );
std::wstring embed ( L"embed" );
std::wstring LINK ( L"LINK" );
std::wstring FORM ( L"FORM" );
std::wstring Excel ( L"Excel" );
std::wstring Word ( L"Word" );
std::wstring opendocument(L"opendocument" );
std::wstring Equation ( L"Equation" );
std::wstring MERGEFORMAT( L"MERGEFORMAT" );
std::wstring QUOTE ( L"QUOTE" );
std::wstring chart ( L"Chart" );
std::wstring PBrush ( L"PBrush" );
std::wstring TOC ( L"TOC" );
std::wstring HYPERLINK ( L"HYPERLINK" );
std::wstring PAGEREF ( L"PAGEREF" );
std::wstring PAGE ( L"PAGE" );
std::wstring SHAPE ( L"SHAPE" );
writeField(sFieldString, cpFieldStart, cpFieldEnd);
if (arField.empty() == false)
f = arField[0];
else
f = sFieldString;
bool bChart = search( f.begin(), f.end(), chart.begin(), chart.end()) != f.end();
bool bEMBED = search( f.begin(), f.end(), EMBED.begin(), EMBED.end()) != f.end() ||
search( f.begin(), f.end(), embed.begin(), embed.end()) != f.end();
bool bLINK = search( f.begin(), f.end(), LINK.begin(), LINK.end()) != f.end();
bool bOpendocument = search( f.begin(), f.end(), opendocument.begin(), opendocument.end()) != f.end();
bool bFORM = search( f.begin(), f.end(), FORM.begin(), FORM.end()) != f.end();
bool bMERGEFORMAT = search( f.begin(), f.end(), MERGEFORMAT.begin(), MERGEFORMAT.end()) != f.end();
bool bExcel = search( f.begin(), f.end(), Excel.begin(), Excel.end()) != f.end();
bool bWord = search( f.begin(), f.end(), Word.begin(), Word.end()) != f.end();
bool bHYPERLINK = search( f.begin(), f.end(), HYPERLINK.begin(), HYPERLINK.end()) != f.end();
bool bQUOTE = search( f.begin(), f.end(), QUOTE.begin(), QUOTE.end()) != f.end();
bool bEquation = search( f.begin(), f.end(), Equation.begin(), Equation.end()) != f.end();
bool bPAGE = search( f.begin(), f.end(), PAGE.begin(), PAGE.end()) != f.end();
bool bTOC = search( f.begin(), f.end(), TOC.begin(), TOC.end()) != f.end();
bool bSHAPE = search( f.begin(), f.end(), SHAPE.begin(), SHAPE.end()) != f.end();
bool bPAGEREF = false;
if (bHYPERLINK && arField.size() > 1)
{
std::wstring f1 = arField[1];
bPAGEREF = search( f1.begin(), f1.end(), PAGEREF.begin(), PAGEREF.end()) != f1.end();
}
if (bTOC)
_bContentWrite = true;
if ( bFORM )
{
std::wstring FORMTEXT ( L" FORMTEXT" );
std::wstring FORMCHECKBOX ( L" FORMCHECKBOX" );
std::wstring FORMDROPDOWN ( L" FORMDROPDOWN" );
m_pXmlWriter->WriteNodeBegin( L"w:fldChar" , true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType" , L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true, false );
bool bFORMTEXT = search( f.begin(), f.end(), FORMTEXT.begin(), FORMTEXT.end()) != f.end();
bool bFORMCHECKBOX = search( f.begin(), f.end(), FORMCHECKBOX.begin(), FORMCHECKBOX.end()) != f.end();
bool bFORMDROPDOWN = search( f.begin(), f.end(), FORMDROPDOWN.begin(), FORMDROPDOWN.end()) != f.end();
if (bFORMTEXT || bFORMCHECKBOX || bFORMDROPDOWN)
{
int cpPic = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::Picture );
if (cpPic < cpFieldEnd)
{
int fcPic = m_document->FindFileCharPos( cpPic );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions(fcPic, fcPic + 1);
if (chpxs)
{
CharacterPropertyExceptions* chpxSep = chpxs->front();
FormFieldData ffdata (2, chpxSep, m_document->DataStream, false);
FormFieldDataMapping data_mapping(m_pXmlWriter, m_context, _caller);
ffdata.Convert(&data_mapping);
RELEASEOBJECT( chpxs );
}
}
}
m_pXmlWriter->WriteNodeEnd( L"w:fldChar" );
_fieldLevels.back().bBegin = true;
}
else if ( ( bMERGEFORMAT || bExcel || bWord || bOpendocument )
&&
( ( bEMBED || bLINK ) && bChart) )
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true, false );
int cpPic = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::Picture );
m_pXmlWriter->WriteNodeEnd( L"w:fldChar" );
_fieldLevels.back().bBegin = true;
}
else if (bHYPERLINK && bPAGEREF)
{
int cpFieldSep2 = cpFieldStart, cpFieldSep1 = cpFieldStart;
std::vector<std::wstring> toc;
if (arField.size() > 1)
f = arField[1];
if ( _bContentWrite )
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true );
_fieldLevels.back().bBegin = true;
}
else
{
for (size_t i = 1; i < arField.size(); i++)
{
std::wstring f1 = arField[1];
int d = (int)f1.find(PAGEREF);
if (d > 0)
{
_writeWebHidden = true;
std::wstring _writeTocLink =f1.substr(d + 9);
d = (int)_writeTocLink.find(L" ");
_writeTocLink = _writeTocLink.substr(0, d);
_writeAfterRun = std::wstring (L"<w:hyperlink w:anchor = \"");
_writeAfterRun += _writeTocLink;
_writeAfterRun += std::wstring (L"\" w:history=\"1\">");
break;
//cp = cpFieldSep1;
}
//cpFieldSep1 = cpFieldSep2;
}
_skipRuns = 5; //with separator
}
}
//else if ( bHYPERLINK )
//{//todooo - выделение гиперссылки отдельно
// std::vector<std::wstring> arRefs;
// boost::algorithm::split(arRefs, f, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on);
//
// std::wstring sLink = arRefs[2];
// m_pXmlWriter->WriteNodeBegin( L"w:hyperlink", true );
// int relID = m_context->_docx->RegisterHyperlink(_caller, sLink);
// m_pXmlWriter->WriteAttribute( L"r:id", L"rId"+ FormatUtils::IntToWideString( relID ) );
// m_pXmlWriter->WriteAttribute( L"w:history", 1 );
// m_pXmlWriter->WriteNodeEnd( L"", true, false );
// if (arRefs.size() > 2)
// {
// writeTextElement(arRefs[3].substr(1, arRefs[3].length() - 2), textType);
// }
// m_pXmlWriter->WriteNodeEnd( L"w:hyperlink", false, true );
// _skipRuns = 1;
//}
else if ( bEMBED || (bLINK && !bHYPERLINK)|| bQUOTE)
{
int cpPic = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::Picture);
int cpFieldSep = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::FieldSeparator);
if (cpPic < cpFieldEnd)
{
int fcPic = m_document->FindFileCharPos( cpPic );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions(fcPic, fcPic + 1);
CharacterPropertyExceptions* chpxObj = chpxs->front();
RevisionData oData = RevisionData(chpxObj);
CharacterPropertiesMapping* rPr = new CharacterPropertiesMapping(m_pXmlWriter, m_document, &oData, _lastValidPapx, false);
if(rPr)
{
chpxObj->Convert(rPr);
RELEASEOBJECT(rPr);
}
XMLTools::CStringXmlWriter oleWriter;
XMLTools::CStringXmlWriter oleObjectWriter;
VMLPictureMapping oVmlMapper (m_context, &oleWriter, true, _caller);
if (!m_shapeIdOwner.empty()) //4571833.doc
oVmlMapper.m_shapeId = m_shapeIdOwner;
if (m_document->nWordVersion > 0)
{
OleObject ole ( chpxObj, m_document);
oleWriter.WriteNodeBegin (L"w:object", true);
oleWriter.WriteAttribute( L"w:dxaOrig", FormatUtils::IntToWideString( ( ole.pictureDesciptor.dxaGoal + ole.pictureDesciptor.dxaOrigin ) ));
oleWriter.WriteAttribute( L"w:dyaOrig", FormatUtils::IntToWideString( ( ole.pictureDesciptor.dyaGoal + ole.pictureDesciptor.dyaOrigin ) ));
oleWriter.WriteNodeEnd( L"", true, false );
ole.pictureDesciptor.Convert(&oVmlMapper);
OleObjectMapping oleObjectMapping( &oleObjectWriter, m_context, &ole.pictureDesciptor, _caller, oVmlMapper.m_shapeId);
ole.Convert( &oleObjectMapping );
_lastOLEObject = oleObjectWriter.GetXmlString();
}
else
{
PictureDescriptor pic(chpxObj, m_document->DataStream, 0x7fffffff, m_document->nWordVersion);
oleWriter.WriteNodeBegin (L"w:object", true);
oleWriter.WriteAttribute( L"w:dxaOrig", FormatUtils::IntToWideString( ( pic.dxaGoal + pic.dxaOrigin ) ) );
oleWriter.WriteAttribute( L"w:dyaOrig", FormatUtils::IntToWideString( ( pic.dyaGoal + pic.dyaOrigin ) ) );
oleWriter.WriteNodeEnd( L"", true, false );
pic.Convert(&oVmlMapper);
RELEASEOBJECT(chpxs);
if ( cpFieldSep < cpFieldEnd && m_document->m_PieceTable)
{
int fcFieldSep = m_document->m_PieceTable->FileCharacterPositions->operator []( cpFieldSep );
int fcFieldSep1 = m_document->FindFileCharPos( cpFieldSep );
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions( fcFieldSep, ( fcFieldSep + 1 ) );
CharacterPropertyExceptions* chpxSep = chpxs->front();
OleObject ole ( chpxSep, m_document);
OleObjectMapping oleObjectMapping( &oleObjectWriter, m_context, &pic, _caller, oVmlMapper.m_shapeId );
if (oVmlMapper.m_isEmbedded)
{
ole.isEquation = oVmlMapper.m_isEquation;
ole.isEmbedded = oVmlMapper.m_isEmbedded;
ole.emeddedData = oVmlMapper.m_embeddedData;
}
ole.Convert( &oleObjectMapping );
_lastOLEObject = oleObjectWriter.GetXmlString();
RELEASEOBJECT( chpxs );
}
}
oleWriter.WriteString( _lastOLEObject );
oleWriter.WriteNodeEnd( L"w:object" );
if (!oVmlMapper.m_isEmbedded && oVmlMapper.m_isEquation)
{
//нельзя в Run писать oMath
//m_pXmlWriter->WriteString(oVmlMapper.m_equationXml);
_writeAfterRun = oVmlMapper.m_equationXml;
}
else
{
m_pXmlWriter->WriteString(oleWriter.GetXmlString());
}
}
_skipRuns = 3;
_embeddedObject = true;
}
else
{
m_pXmlWriter->WriteNodeBegin( L"w:fldChar", true );
m_pXmlWriter->WriteAttribute( L"w:fldCharType", L"begin" );
m_pXmlWriter->WriteNodeEnd( L"", true );
_fieldLevels.back().bBegin = true;
}
}
else if (TextMark::FieldSeparator == code)
{
@ -1078,7 +1064,19 @@ namespace DocFileFormat
cp++;
}
if (std::wstring::npos != text.find(L"EMBED"))
{//если есть мааркер конца поля и маркер замещающей картинки и нету маркера начала
//О реорганизации территориальных органов ПФР с 01.11.2018.doc
int cpFieldStart = initialCp;
int cpPic = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::Picture);
int cpFieldEnd = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::FieldEndMark );
if (cpFieldStart < cpPic && cpPic < cpFieldEnd)
{
writeField(text, cpFieldStart, cpFieldEnd);
text.clear();
}
}
if (!text.empty())
{
//bool preserve_space = (text.find(L"\x20")) != text.npos) ? true : false;

View File

@ -85,21 +85,17 @@ namespace DocFileFormat
int getCurrentSection (int cp);
//---------------------------------
bool isSectionEnd ( int cp );
// Writes a Paragraph that starts at the given cp and
// ends at the next paragraph end mark or section end mark
int writeParagraph( int cp, int cpEnd );
// Writes a Paragraph that starts at the given cpStart and
// ends at the given cpEnd
int writeParagraph( int initialCp, int cpEnd, bool sectionEnd, bool lastBad = false );
// Writes a Paragraph RSID
void writeParagraphRsid( const ParagraphPropertyExceptions* papx );
// Writes a run with the given characters and CHPX
int writeRun( std::vector<wchar_t>* chars, CharacterPropertyExceptions* chpx, int initialCp );
// Writes the given text to the document
int writeText ( std::vector<wchar_t>* chars, int initialCp, CharacterPropertyExceptions* chpx, bool writeDeletedText );
int writeText ( std::vector<wchar_t>* chars, int initialCp, CharacterPropertyExceptions* chpx, bool writeDeletedText );
void writeParagraphRsid ( const ParagraphPropertyExceptions* papx );
void writeTextElement ( const std::wstring& text, const std::wstring& textType );
void writeTextStart ( const std::wstring& textType, bool preserve_space);
void writeTextEnd ( const std::wstring& textType );
void writeField (const std::wstring& sFieldString, int cpFieldStart, int cpFieldEnd);
std::vector<int> searchBookmarks( std::vector<wchar_t>* chars, int initialCp );
std::vector<int> searchAnnot(std::vector<wchar_t>* chars, int initialCp);

View File

@ -110,7 +110,7 @@ namespace DocFileFormat
typedef struct FibWord2
{
unsigned int Spare = 0;
unsigned char rgwSpare0[3];
unsigned short rgwSpare0[3];
unsigned int fcPlcMcr = 0;
unsigned int lcbPlcMcr = 0;
@ -1312,10 +1312,10 @@ namespace DocFileFormat
flag16 = reader.ReadUInt16(); //10
m_FibBase.fDot = (flag16 & 0x0001) >> 2;
m_FibBase.fGlsy = (flag16 & 0x0002) >> 1;
m_FibBase.fComplex = (flag16 & 0x0004) >> 2;
m_FibBase.fHasPic = (flag16 & 0x0008) >> 3;
m_FibBase.fDot = ((flag16 & 0x0001) >> 2) != 0;
m_FibBase.fGlsy = ((flag16 & 0x0002) >> 1) != 0;
m_FibBase.fComplex = ((flag16 & 0x0004) >> 2) != 0;
m_FibBase.fHasPic = ((flag16 & 0x0008) >> 3) != 0;
m_FibBase.cQuickSaves = (WORD)(((int)flag16 & 0x00F0) >> 4);
m_FibBase.fEncrypted = FormatUtils::BitmaskToBool((int)flag16, 0x0100);
m_FibBase.fWhichTblStm = FormatUtils::BitmaskToBool((int)flag16, 0x0200);

View File

@ -78,7 +78,14 @@ public:
return rdUShort;
}
void WriteUInt16(unsigned short val)
{
if (m_Data)
{
((unsigned short *)(m_Data + m_Position))[0] = val;
m_Position += sizeof(unsigned short);
}
}
virtual short ReadInt16()
{
short rdShort = 0;
@ -104,7 +111,14 @@ public:
return rdInt;
}
void WriteInt32(_INT32 val)
{
if (m_Data)
{
((_INT32 *)(m_Data + m_Position))[0] = val;
m_Position += sizeof(_INT32);
}
}
virtual unsigned int ReadUInt32()
{
int rdUInt = 0;
@ -117,7 +131,22 @@ public:
return rdUInt;
}
void WriteByte(unsigned char val)
{
if (m_Data)
{
m_Data[m_Position] = val;
m_Position += 1;
}
}
void WriteUInt32(_UINT32 val)
{
if (m_Data)
{
((_UINT32 *)(m_Data + m_Position))[0] = val;
m_Position += sizeof(_UINT32);
}
}
virtual unsigned char ReadByte()
{
unsigned char rdByte = 0;
@ -159,6 +188,14 @@ public:
return pBytes;
}
void WriteBytes(unsigned char* pData, int size)
{
if (m_Data)
{
memcpy(m_Data + m_Position, pData, size);
m_Position += size;
}
}
virtual unsigned long GetPosition() const
{
@ -172,7 +209,7 @@ public:
virtual int Seek (int offset, int origin = 0/*STREAM_SEEK_SET*/)
{
if ( (m_Data != NULL) && (offset > 0) && ((unsigned int)offset < m_Size) )
if ( (m_Data != NULL) && (offset >= 0) && ((unsigned int)offset < m_Size) )
return m_Position = offset;
return 0;

View File

@ -97,7 +97,7 @@ namespace DocFileFormat
ShapeContainer* shape = static_cast<ShapeContainer*>(groupChild);
if (shape)
{
shape->m_nIndex = i;
shape->m_nIndex = (int)i;
if (shape->m_bBackground)
{
m_pBackgroud = shape;

View File

@ -60,8 +60,8 @@ namespace DocFileFormat
for ( size_t i = 0; i < this->Children.size(); ++i )
{
ClientAnchor *clientAnchor = dynamic_cast<ClientAnchor*>( this->Children[i] );
if ( (clientAnchor) && (clientAnchor->value == 0x80000000))
m_bSkip = true;
//if ( (clientAnchor) && (clientAnchor->value == 0x80000000))
// m_bSkip = true; //О реорганизации территориальных органов ПФР с 01.11.2018.doc
Shape* sh = dynamic_cast<Shape*>( this->Children[i] );
if (sh)

View File

@ -100,94 +100,87 @@ public:
RELEASEOBJECT(m_oRPr)
}
};
#ifndef READ1_DEF
#define READ1_DEF(stLen, res, fReadFunction, arg) {\
long read1defCurPos = 0;\
#define READ1_DEF(stLen, res, fReadFunction, arg) {\
long read1defCurPos = 0;\
while(read1defCurPos < (long)stLen)\
{\
BYTE read1defType = m_oBufferedStream.GetUChar();\
long read1defLength = m_oBufferedStream.GetLong();\
res = fReadFunction(read1defType, read1defLength, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
BYTE read1defType = m_oBufferedStream.GetUChar();\
long read1defLength = m_oBufferedStream.GetLong();\
res = fReadFunction(read1defType, read1defLength, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read1defLength);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read1defCurPos += read1defLength + 5;\
m_oBufferedStream.GetPointer(read1defLength);\
res = c_oSerConstants::ReadOk;\
}\
}
#endif
#ifndef READ2_DEF
#define READ2_DEF(stLen, res, fReadFunction, arg) {\
long read2defCurPos = 0;\
else if(res != c_oSerConstants::ReadOk)\
break;\
read1defCurPos += read1defLength + 5;\
}\
}
#define READ2_DEF(stLen, res, fReadFunction, arg) {\
long read2defCurPos = 0;\
while(read2defCurPos < (long)stLen)\
{\
BYTE read2defType = m_oBufferedStream.GetUChar();\
long read2defLenType = m_oBufferedStream.GetUChar();\
int read2defCurPosShift = 2;\
int read2defRealLen;\
switch(read2defLenType)\
{\
BYTE read2defType = m_oBufferedStream.GetUChar();\
long read2defLenType = m_oBufferedStream.GetUChar();\
int read2defCurPosShift = 2;\
int read2defRealLen;\
switch(read2defLenType)\
{\
case c_oSerPropLenType::Null: read2defRealLen = 0;break;\
case c_oSerPropLenType::Byte: read2defRealLen = 1;break;\
case c_oSerPropLenType::Short: read2defRealLen = 2;break;\
case c_oSerPropLenType::Three: read2defRealLen = 3;break;\
case c_oSerPropLenType::Long:\
case c_oSerPropLenType::Double: read2defRealLen = 4;break;\
case c_oSerPropLenType::Variable:\
read2defRealLen = m_oBufferedStream.GetLong();\
read2defCurPosShift += 4;\
break;\
case c_oSerPropLenType::Double64: read2defRealLen = 8;break;\
case c_oSerPropLenType::Long64: read2defRealLen = 8;break;\
default:res = c_oSerConstants::ErrorUnknown;break;\
}\
if(res == c_oSerConstants::ReadOk)\
res = fReadFunction(read2defType, read2defRealLen, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read2defRealLen);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read2defCurPos += read2defRealLen + read2defCurPosShift;\
case c_oSerPropLenType::Null: read2defRealLen = 0;break;\
case c_oSerPropLenType::Byte: read2defRealLen = 1;break;\
case c_oSerPropLenType::Short: read2defRealLen = 2;break;\
case c_oSerPropLenType::Three: read2defRealLen = 3;break;\
case c_oSerPropLenType::Long:\
case c_oSerPropLenType::Double: read2defRealLen = 4;break;\
case c_oSerPropLenType::Variable:\
read2defRealLen = m_oBufferedStream.GetLong();\
read2defCurPosShift += 4;\
break;\
case c_oSerPropLenType::Double64: read2defRealLen = 8;break;\
case c_oSerPropLenType::Long64: read2defRealLen = 8;break;\
default:res = c_oSerConstants::ErrorUnknown;break;\
}\
}
#endif
#ifndef READ_TABLE_DEF
#define READ_TABLE_DEF(res, fReadFunction, arg) {\
res = m_oBufferedStream.Peek(4) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;\
if(res == c_oSerConstants::ReadOk)\
res = fReadFunction(read2defType, read2defRealLen, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read2defRealLen);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read2defCurPos += read2defRealLen + read2defCurPosShift;\
}\
}
#define READ_TABLE_DEF(res, fReadFunction, arg) {\
res = m_oBufferedStream.Peek(4) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;\
if (c_oSerConstants::ReadOk == res) {\
long readtabledefLen = m_oBufferedStream.GetLong();\
res = m_oBufferedStream.Peek(readtabledefLen) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;\
if (c_oSerConstants::ReadOk == res) {\
long readtabledefLen = m_oBufferedStream.GetLong();\
res = m_oBufferedStream.Peek(readtabledefLen) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;\
if (c_oSerConstants::ReadOk == res) {\
READ1_DEF(readtabledefLen, res, fReadFunction, arg);\
}\
READ1_DEF(readtabledefLen, res, fReadFunction, arg);\
}\
}
#endif
#ifndef READ1_TRACKREV
#define READ1_TRACKREV(type, length, poResult) \
if(c_oSerProp_RevisionType::Author == type)\
{\
poResult->Author = m_oBufferedStream.GetString3(length);\
}\
else if(c_oSerProp_RevisionType::Date == type)\
{\
poResult->Date = m_oBufferedStream.GetString3(length);\
}\
else if(c_oSerProp_RevisionType::Id == type)\
{\
poResult->Id = new long(m_oBufferedStream.GetLong());\
}\
else if(c_oSerProp_RevisionType::UserId == type)\
{\
poResult->UserId = m_oBufferedStream.GetString3(length);\
}
#endif
}\
}
#define READ1_TRACKREV(type, length, poResult) \
if(c_oSerProp_RevisionType::Author == type)\
{\
poResult->Author = m_oBufferedStream.GetString3(length);\
}\
else if(c_oSerProp_RevisionType::Date == type)\
{\
poResult->Date = m_oBufferedStream.GetString3(length);\
}\
else if(c_oSerProp_RevisionType::Id == type)\
{\
poResult->Id = new long(m_oBufferedStream.GetLong());\
}\
else if(c_oSerProp_RevisionType::UserId == type)\
{\
poResult->UserId = m_oBufferedStream.GetString3(length);\
}
void InnerColorToOOX(rPr& oRPr, ComplexTypes::Word::CColor& oColor);
class Binary_CommonReader
@ -2838,7 +2831,8 @@ public:
}
else if(c_oSer_sts::Style_Default == type)
{
odocStyle->bDefault = (0 != m_oBufferedStream.GetUChar());
odocStyle->bDefault = true;
odocStyle->Default = m_oBufferedStream.GetBool();
}
else if(c_oSer_sts::Style_BasedOn == type)
{
@ -3976,6 +3970,12 @@ public:
READ1_DEF(length, res, this->ReadMathArg, poResult);
m_oDocumentWriter.m_oContent.WriteString(std::wstring(_T("</m:oMath>")));
}
else if ( c_oSerParType::MRun == type )
{
GetRunStringWriter().WriteString(std::wstring(_T("<m:r>")));
READ1_DEF(length, res, this->ReadMathMRun, poResult);
GetRunStringWriter().WriteString(std::wstring(_T("</m:r>")));
}
else if ( c_oSerParType::Hyperlink == type )
{
CHyperlink oHyperlink;
@ -4598,6 +4598,12 @@ public:
READ1_DEF(length, res, this->ReadMathDelimiter, poResult);
GetRunStringWriter().WriteString(std::wstring(_T("</m:d>")));
}
else if ( c_oSer_OMathContentType::Del == type )
{
TrackRevision oTrackRevision;
READ1_DEF(length, res, this->ReadDelIns, &oTrackRevision);
oTrackRevision.Write(&GetRunStringWriter(), _T("w:del"));
}
else if ( c_oSer_OMathContentType::EqArr == type )
{
GetRunStringWriter().WriteString(std::wstring(_T("<m:eqArr>")));
@ -4622,6 +4628,12 @@ public:
READ1_DEF(length, res, this->ReadMathGroupChr, poResult);
GetRunStringWriter().WriteString(std::wstring(_T("</m:groupChr>")));
}
else if ( c_oSer_OMathContentType::Ins == type )
{
TrackRevision oTrackRevision;
READ1_DEF(length, res, this->ReadDelIns, &oTrackRevision);
oTrackRevision.Write(&GetRunStringWriter(), _T("w:ins"));
}
else if ( c_oSer_OMathContentType::LimLow == type )
{
GetRunStringWriter().WriteString(std::wstring(_T("<m:limLow>")));

View File

@ -499,8 +499,8 @@ extern int g_nCurFormatVersion;
MoveToRangeEnd = 21,
JsaProject = 22,
BookmarkStart = 23,
BookmarkEnd = 24
BookmarkEnd = 24,
MRun = 25
};}
namespace c_oSerDocTableType{enum c_oSerDocTableType
{

View File

@ -3505,6 +3505,14 @@ namespace BinDocxRW
m_oBcw.WriteItemEnd(nCurPos);
break;
}
case OOX::et_m_r:
{
OOX::Logic::CMRun* pMRun = static_cast<OOX::Logic::CMRun*>(item);
nCurPos = m_oBcw.WriteItemStart(c_oSerParType::MRun);
WriteMathRunContent(pMRun);
m_oBcw.WriteItemEnd(nCurPos);
break;
}
default:
break;
}
@ -4114,6 +4122,14 @@ namespace BinDocxRW
m_oBcw.WriteItemEnd(nCurPos);
break;
}
case OOX::et_w_del:
{
OOX::Logic::CDel* pDel = static_cast<OOX::Logic::CDel*>(item);
nCurPos = m_oBcw.WriteItemStart(c_oSer_OMathContentType::Del);
WriteDel(*pDel);
m_oBcw.WriteItemEnd(nCurPos);
break;
}
case OOX::et_m_eqArr:
{
OOX::Logic::CEqArr* pEqArr = static_cast<OOX::Logic::CEqArr*>(item);
@ -4166,6 +4182,14 @@ namespace BinDocxRW
m_oBcw.WriteItemEnd(nCurPos);
break;
}
case OOX::et_w_ins:
{
OOX::Logic::CIns* pIns = static_cast<OOX::Logic::CIns*>(item);
nCurPos = m_oBcw.WriteItemStart(c_oSer_OMathContentType::Ins);
WriteIns(*pIns);
m_oBcw.WriteItemEnd(nCurPos);
break;
}
case OOX::et_m_limLow:
{
OOX::Logic::CLimLow* pLimLow = static_cast<OOX::Logic::CLimLow*>(item);

View File

@ -465,6 +465,10 @@ std::wstring oox2odf_converter::Impl::convert_formula(const std::wstring & expr)
boost::wregex(L"(?!([a-zA-Z]+\\d*\\())(([a-zA-Z]+\\!)?\\$?[a-zA-Z]*\\$?\\d*(\\:\\$?[a-zA-Z]*\\$?\\d*){0,1})"),
&oox2odf_converter::Impl::replace_arguments, boost::match_default | boost::format_all);
//SUBTOTAL(109,Expense31[Amount])
XmlUtils::replace_all( res, L"[", L"KVADRATIN");
XmlUtils::replace_all( res, L"]", L"KVADRATOUT");
if (res1 == res)
{
XmlUtils::replace_all( res1, L"KAVYCHKA", L"\""); //IMCONJUGATE_emb.xlsx

View File

@ -838,12 +838,20 @@ void common_draw_docx_convert(oox::docx_conversion_context & Context, union_comm
}
if (!drawing->isInline)
{
drawing->relativeHeight = L"2";
drawing->behindDoc = L"0";
if (((drawing->styleWrap && drawing->styleWrap->get_type() == style_wrap::RunThrough) ||
!drawing->styleWrap) && styleRunThrough && styleRunThrough->get_type() == run_through::Background)
{
drawing->behindDoc = L"1";
if (!drawing->styleWrap)
drawing->styleWrap = style_wrap(style_wrap::RunThrough);
}
if (!drawing->styleWrap)
drawing->styleWrap = style_wrap(style_wrap::Parallel);//у опен офис и мс разные дефолты
drawing->relativeHeight = L"2";
drawing->behindDoc = L"0";
_CP_OPT(int) zIndex = attlists_.shape_with_text_and_styles_.common_shape_draw_attlist_.draw_z_index_;
if (zIndex)//порядок отрисовки объектов
@ -853,13 +861,6 @@ void common_draw_docx_convert(oox::docx_conversion_context & Context, union_comm
else
drawing->relativeHeight = std::to_wstring( 2 + *zIndex );
}
if (drawing->styleWrap && drawing->styleWrap->get_type() == style_wrap::RunThrough
&& styleRunThrough && styleRunThrough->get_type() == run_through::Background)
{
drawing-> behindDoc = L"1";
}
drawing->margin_rect[0] = GetMargin(graphicProperties, sideLeft);
drawing->margin_rect[1] = GetMargin(graphicProperties, sideTop);
drawing->margin_rect[2] = GetMargin(graphicProperties, sideRight);

View File

@ -103,6 +103,7 @@ void draw_shape::common_docx_convert(oox::docx_conversion_context & Context)
{
std::wstring href = fill.bitmap->xlink_href_;
fill.bitmap->rId = Context.get_mediaitems().add_or_find(href, oox::typeImage, fill.bitmap->isInternal, href);
fill.bitmap->name_space = L"w14";
}
std::wstringstream strm_fill, strm_ln;

View File

@ -110,7 +110,7 @@ public:
virtual void docx_convert(oox::docx_conversion_context & Context);
virtual void xlsx_convert(oox::xlsx_conversion_context & Context);
virtual void pptx_convert(oox::pptx_conversion_context & Context) ;
virtual void pptx_convert(oox::pptx_conversion_context & Context);
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const;

View File

@ -381,11 +381,12 @@ void table_table_cell::add_child_element( xml::sax * Reader, const std::wstring
void table_table_cell::add_text(const std::wstring & Text)
{
}
bool table_table_cell::empty()
bool table_table_cell::empty(bool bWithStyle)
{
if (!content_.elements_.empty()) return false;
if (attlist_.table_formula_) return false;
if (attlist_.table_style_name_) return false;
if (bWithStyle && attlist_.table_style_name_) return false;
if (attlist_extra_.table_number_columns_spanned_ > 1) return false;
if (attlist_extra_.table_number_rows_spanned_ > 1) return false;
@ -454,7 +455,7 @@ bool table_table_row::empty()
return false;
}
bool table_table_row::empty_content_cells()
bool table_table_row::empty_content_cells(bool bWithCellStyle)
{
bool res = true;
@ -467,7 +468,7 @@ bool table_table_row::empty_content_cells()
res = false;
break;
}
if (cell && cell->empty() == false)
if (cell && cell->empty(bWithCellStyle) == false)
{
res = false;
break;

View File

@ -362,7 +362,7 @@ private:
public:
bool empty();
bool empty_content_cells();
bool empty_content_cells(bool bWithCellStyle = true);
table_table_row_attlist attlist_;
office_element_ptr_array content_; // table-table-cell or table-covered-table-cell
@ -411,7 +411,7 @@ private:
public:
bool last_cell_;
bool empty();
bool empty(bool bWithStyle = true);
table_table_cell_attlist attlist_;
table_table_cell_attlist_extra attlist_extra_;

View File

@ -84,7 +84,7 @@ void table_table_row::xlsx_convert(oox::xlsx_conversion_context & Context)
Context.get_table_context().state()->add_empty_row(attlist_.table_number_rows_repeated_);
return;
}
if (attlist_.table_number_rows_repeated_ > 0x0f00 && empty_content_cells() || bEndTable)//0xf000 - conv_KDZO3J3xLIbZ5fC0HR0__xlsx.ods
if (attlist_.table_number_rows_repeated_ > 0x0f00 && empty_content_cells(false) || bEndTable)//0xf000 - conv_KDZO3J3xLIbZ5fC0HR0__xlsx.ods
{
Context.get_table_context().state()->set_end_table();
Context.get_table_context().state()->add_empty_row(attlist_.table_number_rows_repeated_);

View File

@ -96,7 +96,7 @@ HRESULT convert_single(std::wstring srcFileName)
Oox2Odf::Converter converter(srcTempPath, type, L"C:\\Windows\\Fonts", NULL);
std::wstring sPassword = L"";//password";
std::wstring sPassword;// = L"password";
converter.convert();
converter.write(dstTempPath, srcTempPath, sPassword, L"hiuh56f56tfy7g");

View File

@ -230,10 +230,11 @@ std::wstring odf_chart_context::Impl::convert_formula(std::wstring oox_formula)
else
{
//open office dont support defined names in chart formula
// 7501214.xlsx - частичное заполнение local-table
int col = -1, row = -1;
utils::parsing_ref( refs[0], col, row);
if (col < 0 && row < 0)
if (col < 0 && row < 0 && (odf_context_->type != SpreadsheetDocument))
{
local_table_enabled_ = true;
//find defined name ????
@ -1587,7 +1588,9 @@ void odf_chart_context::set_cash(std::wstring format, std::vector<std::wstring>
int col1 = -1, col2 = -1, row1 = -1, row2 = -1;
if (refs.size() < 1) return;
if (refs.size() < 1) return;
if (refs[0].empty()) return;
utils::parsing_ref( refs[0], col1, row1);
if (refs.size() > 1)
@ -1694,7 +1697,7 @@ int odf_chart_context::Impl::create_local_table_rows(int curr_row, ods_table_sta
add = false;
if (cells[i].row > curr_row + 1 && !header)
if (cells[i].row > curr_row + 1/* && !header*/)
{
office_element_ptr row_elm;

View File

@ -346,7 +346,7 @@ void odf_drawing_context::set_background_state(bool Val)
void odf_drawing_context::check_anchor()
{
return;
if ((impl_->is_footer_ || impl_->is_header_ || impl_->is_background_) && (impl_->anchor_settings_.run_through_) && (impl_->anchor_settings_.run_through_->get_type() == run_through::Background))
if ((/*impl_->is_footer_ || impl_->is_header_ ||*/ impl_->is_background_) && (impl_->anchor_settings_.run_through_) && (impl_->anchor_settings_.run_through_->get_type() == run_through::Background))
{
set_anchor(anchor_type::Char);
//подозрительно на подложку страницы
@ -1317,7 +1317,7 @@ void odf_drawing_context::set_no_fill()
switch(impl_->current_drawing_part_)
{
case Area:
if ((impl_->is_footer_ || impl_->is_header_ || impl_->is_background_) &&
if ((/*impl_->is_footer_ || impl_->is_header_ ||*/ impl_->is_background_) &&
(impl_->current_graphic_properties->common_draw_fill_attlist_.draw_fill_) &&
(impl_->current_graphic_properties->common_draw_fill_attlist_.draw_fill_->get_type() == draw_fill::bitmap))
{
@ -1367,7 +1367,7 @@ void odf_drawing_context::set_solid_fill(std::wstring hexColor)
//impl_->current_graphic_properties->common_background_color_attlist_.fo_background_color_ = color(hexColor); - default transparent
//последнее нужно - что если будут вводить текст - под текстом будет цвет фона (или он поменяется в полях текста)
if ((impl_->is_footer_ || impl_->is_header_ || impl_->is_background_) &&
if ((/*impl_->is_footer_ || impl_->is_header_ ||*/ impl_->is_background_) &&
(impl_->current_graphic_properties->common_draw_fill_attlist_.draw_fill_) &&
(impl_->current_graphic_properties->common_draw_fill_attlist_.draw_fill_->get_type() == draw_fill::bitmap))
{
@ -2391,7 +2391,7 @@ void odf_drawing_context::set_textarea_padding(_CP_OPT(double) & left, _CP_OPT(d
//------------------------------------------------------------------------------------------------------------------
void odf_drawing_context::start_image(std::wstring odf_path)
{
if (impl_->is_footer_ || impl_->is_header_ || impl_->is_background_)
if (/*impl_->is_footer_ || impl_->is_header_ ||*/ impl_->is_background_)//AstraIntlCaseStudyFinal0.docx
{
start_shape(142/*SimpleTypes::shapetypeRect*/);
start_bitmap_style();
@ -2514,7 +2514,10 @@ void odf_drawing_context::set_text_box_min_size(bool val)
if (impl_->current_graphic_properties)
{
impl_->current_graphic_properties->draw_auto_grow_height_ = true;
impl_->current_graphic_properties->draw_auto_grow_width_ = true;
//impl_->current_graphic_properties->draw_auto_grow_width_ = true; //Example_2.xlsx
impl_->current_graphic_properties->draw_fit_to_size_ = false;
impl_->current_graphic_properties->style_shrink_to_fit_ = false;
}
if (impl_->current_drawing_state_.elements_.empty()) return;
@ -2675,7 +2678,7 @@ void odf_drawing_context::set_text_box_parent_style(std::wstring style_name)
void odf_drawing_context::end_image()
{
if (impl_->is_footer_ || impl_->is_header_ || impl_->is_background_)
if (/*impl_->is_footer_ || impl_->is_header_ ||*/ impl_->is_background_)
{
end_bitmap_style();
end_shape();

View File

@ -80,11 +80,20 @@ std::wstring convert_date(const std::wstring & oox_date)
boost::gregorian::date date_ = boost::gregorian::date(1900, 1, 1) + boost::gregorian::date_duration(iDate-2);
////to for example, "1899-12-31T05:37:46.66569
std::wstring date_str = boost::lexical_cast<std::wstring>(date_.year())
std::wstring date_str;
try
{
date_str = boost::lexical_cast<std::wstring>(date_.year())
+ L"-" +
(date_.month() < 10 ? L"0": L"") + boost::lexical_cast<std::wstring>(date_.month().as_number())
+ L"-" +
(date_.day() < 10 ? L"0": L"") + boost::lexical_cast<std::wstring>(date_.day());
}
catch(...)
{
date_str = oox_date;
}
return date_str;
}
@ -471,21 +480,21 @@ void ods_table_state::set_row_default_cell_style(std::wstring & style_name)
office_element_ptr & ods_table_state::current_row_element()
{
if (rows_.size()>0)
if (false == rows_.empty())
return rows_.back().elm;
else
throw;
}
office_element_ptr & ods_table_state::current_cell_element()
{
if (cells_size_ >0)
if (cells_size_ > 0)
return cells_.back().elm;
else
throw;
}
ods_hyperlink_state & ods_table_state::current_hyperlink()
{
if ((cells_size_ >0 && hyperlinks_.size()>0) && (cells_.back().hyperlink_idx>=0) )
if ((cells_size_ >0 && !hyperlinks_.empty()) && (cells_.back().hyperlink_idx >= 0) )
{
return hyperlinks_[cells_.back().hyperlink_idx];
}

View File

@ -530,7 +530,42 @@ void odt_conversion_context::end_index_field()
text_context()->end_element();
text_context()->end_element();
}
void odt_conversion_context::start_bookmark (int id, const std::wstring& name)
{
office_element_ptr bookmark_elm;
create_element(L"text", L"bookmark-start", bookmark_elm, this);
text_bookmark_start* bookmark = dynamic_cast<text_bookmark_start*>(bookmark_elm.get());
if (bookmark)
{
bookmark->text_name_ = name;
std::map<int, std::wstring>::iterator pFind = mapBookmarks.find(id);
if (pFind == mapBookmarks.end())
{
mapBookmarks.insert(std::make_pair(id, name));
}
text_context()->start_element(bookmark_elm);
text_context()->end_element();
}
}
void odt_conversion_context::end_bookmark (int id)
{
std::map<int, std::wstring>::iterator pFind = mapBookmarks.find(id);
if (pFind == mapBookmarks.end()) return;
office_element_ptr bookmark_elm;
create_element(L"text", L"bookmark-end", bookmark_elm, this);
text_bookmark_end* bookmark = dynamic_cast<text_bookmark_end*>(bookmark_elm.get());
if (bookmark)
{
bookmark->text_name_ = pFind->second;
text_context()->start_element(bookmark_elm);
text_context()->end_element();
}
}
void odt_conversion_context::start_hyperlink(std::wstring ref)
{
office_element_ptr hyperlink_elm;
@ -623,6 +658,7 @@ std::map<std::wstring, std::wstring> odt_conversion_context::parse_instr_options
void odt_conversion_context::add_field_instr(const std::wstring &instr)
{
if (current_fields.empty()) return;
current_fields.back().instrText += instr;
}
void odt_conversion_context::set_field_instr()
@ -789,7 +825,7 @@ void odt_conversion_context::set_field_instr()
}
void odt_conversion_context::start_field(bool in_span)
{
if (false == current_fields.empty() && current_fields.back().status == 0)
if (false == current_fields.empty() && current_fields.back().status == 0 && current_fields.back().instrText.empty() )
return; //start_field из sdt
_field_state field;

View File

@ -89,6 +89,9 @@ public:
void start_hyperlink (std::wstring ref);
void end_hyperlink ();
void start_bookmark (int id, const std::wstring& name);
void end_bookmark (int id);
void start_sequence ();
void end_sequence ();
@ -203,6 +206,7 @@ private:
std::vector<odt_section_state> sections_;
std::map<std::wstring, int> mapSequenceDecls;
std::map<int, std::wstring> mapBookmarks;
void add_to_root();

View File

@ -125,6 +125,7 @@ void graphic_format_properties::serialize(std::wostream & _Wostream ,const wchar
CP_XML_ATTR_OPT(L"draw:fit-to-size", draw_fit_to_size_);
CP_XML_ATTR_OPT(L"draw:fit-to-contour", draw_fit_to_contour_);
CP_XML_ATTR_OPT(L"draw:ole-draw-aspect", draw_ole_draw_aspect_);
CP_XML_ATTR_OPT(L"style:shrink-to-fit", style_shrink_to_fit_);
CP_XML_ATTR_OPT(L"draw:stroke", draw_stroke_);
CP_XML_ATTR_OPT(L"draw:stroke-dash", draw_stroke_dash_);

View File

@ -93,6 +93,7 @@ public:
_CP_OPT(odf_types::Bool) draw_auto_grow_height_;
_CP_OPT(odf_types::Bool) draw_auto_grow_width_;
_CP_OPT(odf_types::Bool) style_shrink_to_fit_;
_CP_OPT(odf_types::Bool) draw_fit_to_size_;
_CP_OPT(odf_types::Bool) draw_fit_to_contour_;
_CP_OPT(std::wstring) draw_wrap_influence_on_position_;

View File

@ -688,8 +688,8 @@ void OoxConverter::convert(PPTX::Logic::SpPr *oox_spPr, PPTX::Logic::ShapeStyle*
bool bLine = odf_context()->drawing_context()->isLineShape();
if (custGeom && !custGeom->cxnLst.empty())
bLine = true;
//if (custGeom && !custGeom->cxnLst.empty())
// bLine = true;
odf_context()->drawing_context()->start_area_properties();
{
@ -2293,7 +2293,7 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
if (index < 1000)
{
index -= 1;
if ((index >= 0) || (index < (int)theme->themeElements.fmtScheme.fillStyleLst.size()))
if (index >= 0 && index < (int)theme->themeElements.fmtScheme.fillStyleLst.size())
{
fill = &theme->themeElements.fmtScheme.fillStyleLst[index];
}
@ -2301,7 +2301,7 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
else if (index > 1000)
{
index -= 1001;
if ((index >= 0) || (index < (int)theme->themeElements.fmtScheme.bgFillStyleLst.size()))
if (index >= 0 && index < (int)theme->themeElements.fmtScheme.bgFillStyleLst.size())
{
fill = &theme->themeElements.fmtScheme.bgFillStyleLst[index];
}
@ -2312,15 +2312,15 @@ void OoxConverter::convert(PPTX::Logic::StyleRef *style_ref, int type)
else if (type == 2)
{
index -= 1;
if (index >= 0 || index < (int)theme->themeElements.fmtScheme.lnStyleLst.size())
if (index >= 0 && index < (int)theme->themeElements.fmtScheme.lnStyleLst.size())
{
convert(&theme->themeElements.fmtScheme.lnStyleLst[index], nARGB);
}
}
else if (type == 3)
else if (type == 3)
{
index -= 1;
if ((index >= 0) || (index < (int)theme->themeElements.fmtScheme.effectStyleLst.size()))
if (index >= 0 && index < (int)theme->themeElements.fmtScheme.effectStyleLst.size())
{
convert(&theme->themeElements.fmtScheme.effectStyleLst[index]);
}

View File

@ -483,9 +483,17 @@ void OoxConverter::convert(OOX::Vml::CFill *vml_fill)
odf_context()->drawing_context()->set_gradient_start(*sRgbColor1, no_set);
if (sRgbColor2)
odf_context()->drawing_context()->set_gradient_end(*sRgbColor2, no_set);
else
odf_context()->drawing_context()->set_gradient_end(L"#ffffff", no_set);
if (vml_fill->m_oAngle.IsInit())
{
odf_context()->drawing_context()->set_gradient_angle(vml_fill->m_oAngle->GetValue() + 90);
}
if (vml_fill->m_oFocusPosition.IsInit())
{
odf_context()->drawing_context()->set_gradient_center(vml_fill->m_oFocusPosition->GetX(), vml_fill->m_oFocusPosition->GetY());
}
odf_context()->drawing_context()->end_gradient_style();
}break;
@ -952,9 +960,9 @@ void OoxConverter::convert(OOX::Vml::CVmlCommonElements *vml_common)
delete oRgbColor;
}
}
for (std::vector<OOX::WritingElement*>::iterator it = vml_common->m_arrItems.begin(); it != vml_common->m_arrItems.end(); ++it)
for (size_t i = 0; i < vml_common->m_arrItems.size(); ++i)
{
convert(*it);
convert(vml_common->m_arrItems[i]);
}
if (vml_common->m_oFilled.IsInit() && vml_common->m_oFilled->GetValue() == SimpleTypes::booleanFalse)

View File

@ -65,6 +65,7 @@
#include "../../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Sparkline.h"
#include "../../../OfficeCryptReader/source/CryptTransform.h"
#include "../../../DesktopEditor/common/Directory.h"
#include "../../../DesktopEditor/common/SystemUtils.h"
#define PROGRESSEVENT_ID 0
@ -203,28 +204,37 @@ bool OoxConverter::encrypt_file (const std::wstring &password, const std::wstrin
{
CRYPT::ODFEncryptor encryptor;
CRYPT::_odfCryptData cryptData;
//-----------------------
//aes
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA256;
cryptData.start_hashSize = 32;
cryptData.spinCount = 100000;
cryptData.keySize = 32;
std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvMethodEncrypt);
cryptData.checksum_size = 1024;
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256;
if (sApplication == L"Weak")
{
//-----------------------
//blowfish
//cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish_CFB;
//cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA1;
//cryptData.start_hashSize = 20;
cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish_CFB;
cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA1;
cryptData.start_hashSize = 20;
//cryptData.spinCount = 1024;
//cryptData.keySize = 16;
cryptData.spinCount = 1024;
cryptData.keySize = 7;//16;
//cryptData.checksum_size = 1024;
//cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
cryptData.checksum_size = 1024;
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
}
else
{
//-----------------------
//aes
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA256;
cryptData.start_hashSize = 32;
cryptData.spinCount = 100000;
cryptData.keySize = 32;
cryptData.checksum_size = 1024;
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256;
}
//-----------------------
NSFile::CFileBinary file;

View File

@ -1205,7 +1205,8 @@ void OoxConverter::convert(OOX::Spreadsheet::CT_NumDataSource* val)
}
else if (val->m_numRef)
{
if (val->m_numRef->m_f)odf_context()->chart_context()->set_series_value_formula(*val->m_numRef->m_f);
if (val->m_numRef->m_f)
odf_context()->chart_context()->set_series_value_formula(*val->m_numRef->m_f);
convert(val->m_numRef->m_numCache, false, false);
}

View File

@ -288,6 +288,14 @@ void DocxConverter::convert(OOX::WritingElement *oox_unknown)
{
convert(dynamic_cast<OOX::Logic::CFldSimple*>(oox_unknown));
}break;
case OOX::et_w_bookmarkStart:
{
convert(dynamic_cast<OOX::Logic::CBookmarkStart*>(oox_unknown));
}break;
case OOX::et_w_bookmarkEnd:
{
convert(dynamic_cast<OOX::Logic::CBookmarkEnd*>(oox_unknown));
}break;
case OOX::et_w_r:
{
convert(dynamic_cast<OOX::Logic::CRun*>(oox_unknown));
@ -389,12 +397,6 @@ void DocxConverter::convert(OOX::WritingElement *oox_unknown)
{
convert(dynamic_cast<OOX::Logic::CTc*>(oox_unknown));
}break;
case OOX::et_w_bookmarkStart:
{
}break;
case OOX::et_w_bookmarkEnd:
{
}break;
default:
{
OoxConverter::convert(oox_unknown);
@ -799,6 +801,23 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
odt_context->end_change(id_change_properties, 3); //todooo change int type to enum
}
void DocxConverter::convert(OOX::Logic::CBookmarkStart *oox_bookmark_start)
{
if (!oox_bookmark_start) return;
if (oox_bookmark_start->m_sName.IsInit() == false) return;
if (oox_bookmark_start->m_oId.IsInit() == false) return;
odt_context->start_bookmark(oox_bookmark_start->m_oId->GetValue(), *oox_bookmark_start->m_sName);
}
void DocxConverter::convert(OOX::Logic::CBookmarkEnd *oox_bookmark_end)
{
if (!oox_bookmark_end) return;
if (oox_bookmark_end->m_oId.IsInit() == false) return;
odt_context->end_bookmark(oox_bookmark_end->m_oId->GetValue());
}
void DocxConverter::convert(OOX::Logic::CPTab *oox_ptab)
{
@ -858,7 +877,7 @@ void DocxConverter::convert(OOX::Logic::CPTab *oox_ptab)
odt_context->text_context()->add_tab(ref);
}
void DocxConverter::convert(OOX::Logic::CSym *oox_sym)
void DocxConverter::convert(OOX::Logic::CSym *oox_sym)
{
if (oox_sym == NULL) return;
if (oox_sym->m_oChar.IsInit() == false) return;
@ -2981,6 +3000,11 @@ void DocxConverter::convert(OOX::Drawing::CAnchor *oox_anchor)
odt_context->drawing_context()->set_wrap_style(odf_types::style_wrap::Parallel);
wrap_set = true;
}
else if (oox_anchor->m_oWrapNone.IsInit())
{
odt_context->drawing_context()->set_wrap_style(odf_types::style_wrap::None);
wrap_set = true;
}
else if (oox_anchor->m_oAllowOverlap.IsInit())
{
odt_context->drawing_context()->set_overlap(oox_anchor->m_oAllowOverlap->ToBool());
@ -4344,13 +4368,22 @@ bool DocxConverter::convert(OOX::Logic::CTableProperty *oox_table_pr, odf_writer
}
else if (oox_table_pr->m_oTblLayout.IsInit() && oox_table_pr->m_oTblLayout->m_oType.IsInit())
{
table_properties->table_format_properties_.common_horizontal_margin_attlist_.fo_margin_left_ = odf_types::length(0,odf_types::length::cm);
table_properties->table_format_properties_.common_horizontal_margin_attlist_.fo_margin_left_ = odf_types::length(0, odf_types::length::cm);
table_properties->table_format_properties_.table_align_ = odf_types::table_align(odf_types::table_align::Left);
}
//if(oox_table_pr->m_oJc.IsInit() && oox_table_pr->m_oJc->m_oVal.IsInit())
//{
//}
if(oox_table_pr->m_oJc.IsInit() && oox_table_pr->m_oJc->m_oVal.IsInit())
{
switch(oox_table_pr->m_oJc->m_oVal->GetValue())
{
case 0: table_properties->table_format_properties_.table_align_ = odf_types::table_align(odf_types::table_align::Center); break;
case 2:
case 3: table_properties->table_format_properties_.table_align_ = odf_types::table_align(odf_types::table_align::Left); break;
case 1:
case 4: table_properties->table_format_properties_.table_align_ = odf_types::table_align(odf_types::table_align::Right); break;
default: break;
}
}
//nullable<ComplexTypes::Word::COnOff2<SimpleTypes::onoffTrue> > m_oBidiVisual;
//nullable<ComplexTypes::Word::CShading > m_oShade;
//nullable<ComplexTypes::Word::std::wstring_ > m_oTblCaption;

View File

@ -97,6 +97,8 @@ namespace OOX
class CSdtContent;
class CBackground;
class CLockedCanvas;
class CBookmarkStart;
class CBookmarkEnd;
}
namespace Numbering
@ -199,6 +201,8 @@ namespace Oox2Odf
void convert(OOX::Logic::CSym *oox_sym);
void convert(OOX::Logic::CSmartTag *oox_tag);
void convert(OOX::Logic::CPTab *oox_ptab);
void convert(OOX::Logic::CBookmarkStart *oox_bookmark_start);
void convert(OOX::Logic::CBookmarkEnd *oox_bookmark_end);
int convert(ComplexTypes::Word::CTrackChange *oox_change, int type);
void convert(OOX::Logic::CIns *oox_ins);

View File

@ -1115,10 +1115,10 @@ void XlsxConverter::convert(OOX::Spreadsheet::CSheetViews *oox_sheet_views)
std::wstring ref(selection->m_oActiveCell.get());
odf_writer::utils::parsing_ref (ref, ActiveCellX, ActiveCellY);
if (ActiveCellX >= 0 && ActiveCellY >= 0)
if (ActiveCellX > 0 && ActiveCellY > 0)
{
ods_context->settings_context()->add_property(L"CursorPositionX", L"int", std::to_wstring(ActiveCellX));
ods_context->settings_context()->add_property(L"CursorPositionY", L"int", std::to_wstring(ActiveCellY));
ods_context->settings_context()->add_property(L"CursorPositionX", L"int", std::to_wstring(ActiveCellX - 1));
ods_context->settings_context()->add_property(L"CursorPositionY", L"int", std::to_wstring(ActiveCellY - 1));
}
}
if (selection->m_oSqref.IsInit())
@ -1983,16 +1983,37 @@ void XlsxConverter::convert(OOX::Spreadsheet::CCellAnchor *oox_anchor)
if (!oox_anchor) return;
//////////////////
if (oox_anchor->m_oFrom.IsInit() || oox_anchor->m_oTo.IsInit())
if (oox_anchor->m_oFrom.IsInit() || oox_anchor->m_oTo.IsInit() ||
oox_anchor->m_oPos.IsInit() || oox_anchor->m_oExt.IsInit())
{
oox_table_position from={}, to={};
convert(oox_anchor->m_oFrom.GetPointer(), &from);
convert(oox_anchor->m_oTo.GetPointer(), &to);
double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
double x1=0, y1=0, x2=0, y2=0;
ods_context->current_table().convert_position(from, x1, y1);
ods_context->current_table().convert_position(to, x2, y2);
if (oox_anchor->m_oFrom.IsInit())
{
convert(oox_anchor->m_oFrom.GetPointer(), &from);
ods_context->current_table().convert_position(from, x1, y1);
}
else if (oox_anchor->m_oPos.IsInit())
{
if (oox_anchor->m_oPos->m_oX.IsInit())
x1 = oox_anchor->m_oPos->m_oX->GetValue();
if (oox_anchor->m_oPos->m_oY.IsInit())
y1 = oox_anchor->m_oPos->m_oY->GetValue();
}
if (oox_anchor->m_oTo.IsInit())
{
convert(oox_anchor->m_oTo.GetPointer(), &to);
ods_context->current_table().convert_position(to, x2, y2);
}
else if (oox_anchor->m_oExt.IsInit())
{
if (oox_anchor->m_oExt->m_oCx.IsInit())
x2 = x1 + oox_anchor->m_oExt->m_oCx->GetValue();
if (oox_anchor->m_oExt->m_oCy.IsInit())
y2 = y1 + oox_anchor->m_oExt->m_oCy->GetValue();
}
ods_context->drawing_context()->set_drawings_rect(x1, y1, x2 - x1, y2 - y1);
}

View File

@ -235,7 +235,7 @@ namespace NSBinPptxRW
nCountSlides = m_oReader.GetLong();
}
if (0 == nCountThemes || 0 == nCountMasters || 0 == nCountLayouts/* || 0 == nCountSlides*/) //rev 60054 - презентация без слайдов
if (/*0 == nCountThemes || */0 == nCountMasters || 0 == nCountLayouts/* || 0 == nCountSlides*/) //rev 60054 - презентация без слайдов
{
return;
}
@ -353,7 +353,11 @@ namespace NSBinPptxRW
}
for (LONG i = 0; i < nCountMasters; ++i)
{
arThemesSave[m_arSlideMasters_Theme[i].m_lThemeIndex] = true;
int ind = m_arSlideMasters_Theme[i].m_lThemeIndex;
if (ind < arThemesSave.size())
{
arThemesSave[ind] = true;
}
}
for (size_t i = 0; i < m_arNotesMasters_Theme.size(); i++)
@ -365,7 +369,7 @@ namespace NSBinPptxRW
}
}
LONG lCurrectTheme = 0;
for (LONG i = 0; i < nCountMasters; ++i)
for (LONG i = 0; i < nCountMasters && i < arThemesSave.size(); ++i)
{
if (!arThemesSave[i])
continue;
@ -373,7 +377,7 @@ namespace NSBinPptxRW
++lCurrectTheme;
}
// теперь нужно перебить ссылки
for (LONG i = 0; i < nCountMasters; ++i)
for (LONG i = 0; i < nCountMasters && i < arThemesDst.size(); ++i)
{
m_arSlideMasters_Theme[i].m_lThemeIndex = arThemesDst[i];
}

View File

@ -752,7 +752,11 @@ namespace PPTX
olePic.Init();
olePic->blipFill.blip.Init();
olePic->blipFill.stretch.Init();
olePic->blipFill.stretch->fillRect.Init();
olePic->blipFill.srcRect.Init();
olePic->blipFill.blip->oleFilepathImage = NSDirectory::CreateTempFileWithUniqueName(sTempDirectory, L"img");

View File

@ -304,6 +304,9 @@ namespace PPTX
{
LONG _embed_data_size = pReader->GetLong();
LONG _end_embed_data = pReader->GetPos() + _embed_data_size + 4;
if (_embed_data_size < 1)
break;
//------------------------------------------------------------------
std::wstring sDstEmbedded = pReader->m_pRels->m_pManager->GetDstMedia();
int nPos = (int)sDstEmbedded.rfind(wchar_t('m'));
@ -327,7 +330,22 @@ namespace PPTX
{
pReader->Seek(pReader->GetPos() - 4); //roll back to size record
std::wstring sXmlContent;
pReader->m_pMainDocument->getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent);
if (pReader->m_pMainDocument)
{
pReader->m_pMainDocument->getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent);
}
else
{
BinDocxRW::CDocxSerializer oDocxSerializer;
NSBinPptxRW::CDrawingConverter oDrawingConverter;
oDrawingConverter.SetMainDocument(&oDocxSerializer);
//oDocxSerializer.m_pParamsWriter = new BinDocxRW::ParamsWriter(oDrawingConverter.m_pBinaryWriter, &oFontProcessor, &oDrawingConverter, NULL);
oDocxSerializer.m_pCurFileWriter = new Writers::FileWriter(L"", L"", false, 111, false, &oDrawingConverter, L"");
oDocxSerializer.getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent);
}
if (!sXmlContent.empty())
{
@ -1479,7 +1497,11 @@ namespace PPTX
if(oleObject->m_oId.IsInit())
{
if (blipFill.blip.IsInit() == false)
{
blipFill.blip.Init();
blipFill.stretch.Init();
blipFill.stretch->fillRect.Init();
}
blipFill.blip->oleRid = oleObject->m_oId->get();
}
XmlMacroReadAttributeBase(node, L"spid", oleObject->m_sShapeId);

View File

@ -74,6 +74,7 @@ namespace PPTX
pWriter->EndAttributes();
pWriter->StartNode(L"p14:sldIdLst");
pWriter->EndAttributes();
pWriter->WriteArray2(arSldIdLst);
pWriter->EndNode(L"p14:sldIdLst");

View File

@ -51,15 +51,34 @@ BiffStructurePtr ExtPtgArea3D::clone()
void ExtPtgArea3D::load(CFRecord& record)
{
global_info = record.getGlobalWorkbookInfo();
record >> iTabs >> area;
}
void ExtPtgArea3D::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref)
{
Log::info("ExtPtgArea3D record is not implemented.");
std::wstring strRange;
std::wstring range_ref = area.toString();
ptg_stack.push(L"#REF!");
if(-1 == iTabs.itabFirst)
{
strRange = L"#REF";
}
else if (iTabs.itabFirst < global_info->external_sheets_info.size())
{
strRange = XMLSTUFF::name2sheet_name(global_info->external_sheets_info[iTabs.itabFirst], L"");
if (iTabs.itabFirst != iTabs.itabLast && iTabs.itabLast < global_info->external_sheets_info.size() )
{
strRange += XMLSTUFF::name2sheet_name(global_info->external_sheets_info[iTabs.itabLast], L"");
}
}
if (!strRange.empty()) strRange += L"!";
ptg_stack.push(strRange + range_ref);
}

View File

@ -53,7 +53,9 @@ public:
ExtSheetPair iTabs;
RgceAreaRel area;
const CellRef& cell_base_ref;
const CellRef &cell_base_ref;
GlobalWorkbookInfoPtr global_info;
};
} // namespace XLS

View File

@ -52,8 +52,6 @@ void ExtPtgAreaErr3D::load(CFRecord& record)
void ExtPtgAreaErr3D::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref)
{
Log::info("ExtPtgAreaErr3D record is not implemented.");
ptg_stack.push(L"#REF!");
}

View File

@ -51,15 +51,37 @@ BiffStructurePtr ExtPtgRef3D::clone()
void ExtPtgRef3D::load(CFRecord& record)
{
global_info = record.getGlobalWorkbookInfo();
record >> iTabs >> loc;
}
void ExtPtgRef3D::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref )
{
Log::info("ExtPtgRef3D record is not implemented.");
ptg_stack.push(L"#REF!");
std::wstring cell_ref = loc.toString();
std::wstring strRange;
if(-1 == iTabs.itabFirst)
{
strRange = L"#REF";
}
else if (iTabs.itabFirst < global_info->external_sheets_info.size())
{
strRange = XMLSTUFF::name2sheet_name(global_info->external_sheets_info[iTabs.itabFirst], L"");
if (iTabs.itabFirst != iTabs.itabLast && iTabs.itabLast < global_info->external_sheets_info.size() )
{
strRange += XMLSTUFF::name2sheet_name(global_info->external_sheets_info[iTabs.itabLast], L"");
}
}
else
{
return;
}
if (!strRange.empty()) strRange += L"!";
ptg_stack.push(strRange + cell_ref);
}

View File

@ -48,12 +48,13 @@ public:
virtual void load(CFRecord& record);
virtual void assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref = false);
ExtSheetPair iTabs;
RgceLocRel loc;
const CellRef& cell_base_ref;
GlobalWorkbookInfoPtr global_info;
};
} // namespace XLS

View File

@ -46,6 +46,12 @@ public:
std::vector<BaseObjectPtr> m_arCRN;
};
struct _def_name
{
std::wstring fmla;
int sheetId;
};
SUPBOOK();
~SUPBOOK();
@ -65,12 +71,14 @@ public:
GlobalWorkbookInfoPtr global_info;
std::vector<std::wstring> arNames;
bool IsExternal();
std::wstring sExternPathLink;
int nExternIndex;
std::map<std::wstring, _def_name> mapNamesExt;
std::vector<std::wstring> arNames;
private:
int serialize_book(std::wostream & strm);
int serialize_dde(std::wostream & strm);

View File

@ -110,13 +110,13 @@ const bool SUPBOOK::loadContent(BinProcessor& proc)
ExternDocName* docName = dynamic_cast<ExternDocName*>(extern_name.body.get());
if(docName)
{
if (docName->ixals > 0 && !supbook.rgst.empty())
if (docName->ixals > 0 && docName->ixals < supbook.rgst.size())
{
name = supbook.rgst[docName->ixals];
name = supbook.rgst[docName->ixals - 1];
}
else
{
name = docName->nameDefinition.getAssembledFormula();
//name = docName->nameDefinition.getAssembledFormula(); //in update !!
if (name.empty())
{
name = docName->extName.value();
@ -229,19 +229,25 @@ int SUPBOOK::serialize_book(std::wostream & strm)
{
CP_XML_NODE(L"sheetNames")
{
for (size_t i = 0; i < m_arXCT.size(); i++)
for (size_t i = 0; i < book->rgst.size(); i++)
{
CP_XML_NODE(L"sheetName")
{
std::wstring sheet;
XCT * name = dynamic_cast<XCT*>(m_arXCT[i].m_XCT.get());
if ((name) && (name->itab_exist))
sheet = book->rgst[name->itab];
else
sheet = L"Sheet " + std::to_wstring(i + 1);
CP_XML_ATTR(L"val", sheet);
CP_XML_ATTR(L"val", book->rgst[i]);
}
}
for (size_t i = 0; i < m_arXCT.size(); i++)
{
XCT * name = dynamic_cast<XCT*>(m_arXCT[i].m_XCT.get());
if ((name) && (name->itab_exist))
{
}
else
{
CP_XML_NODE(L"sheetName")
{
CP_XML_ATTR(L"val", L"Sheet " + std::to_wstring(i + 1));
}
}
}
}
@ -249,11 +255,20 @@ int SUPBOOK::serialize_book(std::wostream & strm)
{
CP_XML_NODE(L"definedNames")
{
for (size_t d = 0; d < arNames.size(); d++)
for (size_t j = 0; j < arNames.size(); j++)
{
CP_XML_NODE(L"definedName")
{
CP_XML_ATTR(L"name", arNames[d]);
CP_XML_ATTR(L"name", arNames[j]);
std::map<std::wstring, _def_name>::iterator pFind = mapNamesExt.find(arNames[j]);
if (pFind != mapNamesExt.end())
{
CP_XML_ATTR(L"refersTo", pFind->second.fmla);
if (pFind->second.sheetId > 0)
CP_XML_ATTR(L"sheetId", pFind->second.sheetId);
}
}
}
}
@ -267,8 +282,9 @@ int SUPBOOK::serialize_book(std::wostream & strm)
CP_XML_NODE(L"sheetData")
{
CP_XML_ATTR(L"sheetId", i);
int current_row = -1;
CP_XML_ATTR(L"sheetId", name->itab);
int current_row = -1;
for (size_t j = 0; j < m_arXCT[i].m_arCRN.size(); j++)
{
CRN * cell = dynamic_cast<CRN*>(m_arXCT[i].m_arCRN[j].get());

View File

@ -153,6 +153,7 @@ public:
double defaultRowHeight = 14.4;
};
std::vector<_sheet_info> sheets_info;
std::vector<std::wstring> external_sheets_info; //current
std::pair<float, float> defaultDigitFontSize;
NSFonts::IApplicationFonts* applicationFonts;

View File

@ -98,6 +98,12 @@
#include "Biff_records/DXF.h"
#include "Biff_records/SupBook.h"
#include "Biff_records/NameCmt.h"
#include "Biff_records/SupBook.h"
#include "Biff_records/ExternName.h"
#include "Biff_records/ExternSheet.h"
#include "Biff_records/Continue.h"
//#include "Biff_records/XCT.h"
//#include "Biff_records/CRN.h"
#include "Biff_structures/ODRAW/OfficeArtDgContainer.h"
@ -575,6 +581,7 @@ const bool GlobalsSubstream::loadContent(BinProcessor& proc)
LoadHFPicture();
UpdateXti();
UpdateDefineNames();
UpdateExternalDefineNames();
return true;
}
@ -663,7 +670,7 @@ void GlobalsSubstream::UpdateXti()
{
strRange = L"#REF";
}
else
else if (xti->itabFirst < global_info_->sheets_info.size())
{
strRange = XMLSTUFF::name2sheet_name(global_info_->sheets_info[xti->itabFirst].name, L"");
if (xti->itabFirst != xti->itabLast)
@ -678,6 +685,14 @@ void GlobalsSubstream::UpdateXti()
val_1.link = XMLSTUFF::xti_indexes2sheet_name(xti->itabFirst, xti->itabLast, info->rgst, val_1.link);
}
}
else if (xti->itabFirst == -1)
{
//sheet not found
}
else if (xti->itabFirst == -2)
{
//Workbook-level
}
global_info_->arXti_External.push_back(val_1);
}
@ -748,6 +763,48 @@ void GlobalsSubstream::UpdateDefineNames()
global_info_->arDefineNames.push_back(name);// для имен функций - todooo ... не все функции корректны !! БДИ !!
}
}
void GlobalsSubstream::UpdateExternalDefineNames()
{
for (size_t s = 0; s < m_arSUPBOOK.size(); s++)
{
SUPBOOK* SUPBOOK_ = dynamic_cast<SUPBOOK*>(m_arSUPBOOK[s].get());
if (!SUPBOOK_) continue;
SupBook *supbook = dynamic_cast<SupBook*>(SUPBOOK_->m_SupBook.get());
if (!supbook) continue;
global_info_->external_sheets_info.clear();
for (size_t i = 0; i < supbook->rgst.size(); i++)
{
global_info_->external_sheets_info.push_back(supbook->rgst[i]);
}
for (size_t i = 0; i < SUPBOOK_->m_arExternName.size(); i++)
{
ExternName *externName = dynamic_cast<ExternName*>(SUPBOOK_->m_arExternName[i].get());
if (!externName) continue;
ExternDocName* docName = dynamic_cast<ExternDocName*>(externName->body.get());
if(docName)
{
if (docName->ixals > 0 && docName->ixals < supbook->rgst.size())
{
}
else
{
SUPBOOK::_def_name def_name;
def_name.fmla = docName->nameDefinition.getAssembledFormula();
if (false == def_name.fmla.empty())
{
SUPBOOK_->mapNamesExt.insert(std::make_pair(docName->extName.value(), def_name));
}
}
}
}
}
}
int GlobalsSubstream::serialize_protection(std::wostream & _stream)
{
if (!m_PROTECTION) return 0;

View File

@ -94,6 +94,7 @@ private:
void LoadHFPicture();
void UpdateXti();
void UpdateDefineNames();
void UpdateExternalDefineNames();
};
} // namespace XLS

View File

@ -693,7 +693,7 @@ namespace ComplexTypes
if ( m_sVal.IsInit() )
{
sResult += _T("w:val=\"");
sResult += m_sVal.get2();
sResult += XmlUtils::EncodeXmlString(m_sVal.get2(), false);
sResult += _T("\" ");
}
@ -704,7 +704,7 @@ namespace ComplexTypes
std::wstring sResult;
if ( m_sVal.IsInit() )
sResult += m_sVal.get();
sResult += XmlUtils::EncodeXmlString(m_sVal.get(), false);
return sResult;
}

View File

@ -4106,10 +4106,16 @@ namespace SimpleTypes
void ReadValue_Rotation(std::wstring& sValue)
{
m_oValue.dValue = sValue.empty() ? 0 : _wtof(sValue.c_str() );
m_oValue.dValue = sValue.empty() ? 0 : _wtof(sValue.c_str() );
if (sValue.find(_T("fd")) != -1)
m_oValue.dValue /= 6000;
if (sValue.find(_T("fd")) != std::wstring::npos)
{
m_oValue.dValue /= 6000.;
}
else if (sValue.find(_T("f")) == sValue.length() - 1)
{
m_oValue.dValue /= 65536.;
}
}
void ReadValue_Double(std::wstring& sValue)

View File

@ -89,6 +89,7 @@ namespace OOX
m_mTable.insert( std::make_pair( _T("docm"), _T("application/vnd.ms-word.document.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("docx"), _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document")));
m_mTable.insert( std::make_pair( _T("vml"), _T("application/vnd.openxmlformats-officedocument.vmlDrawing")));
m_mTable.insert( std::make_pair( _T("vsd"), _T("application/vnd.visio")));
}
const std::wstring operator[] (const std::wstring& sExtension) const
{

View File

@ -314,6 +314,8 @@ namespace OOX
pItem = new COMath( oReader );
else if ( _T("m:oMathPara") == sName )
pItem = new COMathPara( oReader );
else if ( _T("m:r") == sName )
pItem = new CMRun( oReader );
else if ( _T("w:permEnd") == sName )
pItem = new CPermEnd( oReader );
else if ( _T("w:permStart") == sName )
@ -410,6 +412,8 @@ namespace OOX
pItem = new COMath( oReader );
else if ( _T("m:oMathPara") == sName )
pItem = new COMathPara( oReader );
else if ( _T("m:r") == sName )
pItem = new CMRun( oReader );
else if ( _T("w:permEnd") == sName )
pItem = new CPermEnd( oReader );
else if ( _T("w:permStart") == sName )

View File

@ -315,6 +315,20 @@ namespace OOX
nullable<TMathBottomType> m_val;
};
template<class TMathBottomType, class NodeType>
inline void CMathBottomNodesExFromXML(CMathBottomNodes<TMathBottomType>& v, NodeType& oNode)
{
v.fromXML( oNode );
v.sNodeName = v.GetMathNodeName(v.getType());
}
template<class NodeType>
inline void CMathBottomNodesExFromXML(CMathBottomNodes<SimpleTypes::COnOff<>>& v, NodeType& oNode)
{
v.m_val.Init();
v.m_val->FromBool(true);
v.fromXML( oNode );
v.sNodeName = v.GetMathNodeName(v.getType());
}
template <typename TMathBottomType, EElementType EnumType = OOX::et_Unknown>
class CMathBottomNodesEx : public CMathBottomNodes<TMathBottomType>
@ -322,13 +336,11 @@ namespace OOX
public:
CMathBottomNodesEx(XmlUtils::CXmlNode& oNode)
{
CMathBottomNodes<TMathBottomType>::fromXML( oNode );
CMathBottomNodes<TMathBottomType>::sNodeName = CMathBottomNodes<TMathBottomType>::GetMathNodeName(getType());
CMathBottomNodesExFromXML(*this, oNode);
}
CMathBottomNodesEx(XmlUtils::CXmlLiteReader& oReader)
{
CMathBottomNodes<TMathBottomType>::fromXML( oReader );
CMathBottomNodes<TMathBottomType>::sNodeName = CMathBottomNodes<TMathBottomType>::GetMathNodeName(getType());
CMathBottomNodesExFromXML(*this, oReader);
}
virtual EElementType getType() const
{

View File

@ -41,6 +41,8 @@ namespace NSSystemUtils
static const wchar_t* gc_EnvApplicationNameDefault = L"ONLYOFFICE";
static const wchar_t* gc_EnvCompanyName = L"COMPANY_NAME";
static const wchar_t* gc_EnvCompanyNameDefault = L"Ascensio System SIA Copyright (c) 2018";
static const wchar_t* gc_EnvMethodEncrypt = L"METHOD_CRYPT";
static const wchar_t* gc_EnvMethodEncryptDefault = L"Strong";
KERNEL_DECL std::wstring GetEnvVariable(const std::wstring& strName);
}

View File

@ -60,9 +60,12 @@ core_windows {
LIB_GRAPHICS_PRI_PATH = $$PWD/../..
FREETYPE_VERSION=2.5.2
INCLUDEPATH += \
$$LIB_GRAPHICS_PRI_PATH/agg-2.4/include \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/include \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/include \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/include/freetype \
$$LIB_GRAPHICS_PRI_PATH/cximage/jasper/include \
$$LIB_GRAPHICS_PRI_PATH/cximage/jpeg \
$$LIB_GRAPHICS_PRI_PATH/cximage/png \
@ -134,45 +137,46 @@ SOURCES += \
SOURCES += $$PWD/graphics_pri.cpp
SOURCES += $$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftbbox.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftgxval.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftlcdfil.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftmm.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftotval.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftpatent.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftpfr.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftsynth.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/fttype1.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftwinfnt.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftxf86.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/pcf/pcf.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/pfr/pfr.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/psaux/psaux.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/pshinter/pshinter.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/psnames/psmodule.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/raster/raster.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/sfnt/sfnt.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/truetype/truetype.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/type1/type1.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/cid/type1cid.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/type42/type42.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/winfonts/winfnt.c \
SOURCES += \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftbbox.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftgxval.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftlcdfil.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftmm.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftotval.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftpatent.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftpfr.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftsynth.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/fttype1.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftwinfnt.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftxf86.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/pcf/pcf.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/pfr/pfr.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/psaux/psaux.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/pshinter/pshinter.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/psnames/psmodule.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/raster/raster.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/sfnt/sfnt.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/truetype/truetype.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/type1/type1.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/cid/type1cid.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/type42/type42.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/winfonts/winfnt.c \
\
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/autofit/autofit.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/bdf/bdf.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/cff/cff.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftbase.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftbitmap.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/cache/ftcache.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftfstype.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftgasp.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftglyph.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/gzip/ftgzip.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftinit.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/lzw/ftlzw.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftstroke.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/base/ftsystem.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-2.5.2/src/smooth/smooth.c
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/autofit/autofit.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/bdf/bdf.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/cff/cff.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftbase.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftbitmap.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/cache/ftcache.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftfstype.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftgasp.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftglyph.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/gzip/ftgzip.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftinit.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/lzw/ftlzw.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftstroke.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/base/ftsystem.c \
$$LIB_GRAPHICS_PRI_PATH/freetype-$$FREETYPE_VERSION/src/smooth/smooth.c
SOURCES += \
$$LIB_GRAPHICS_PRI_PATH/cximage/jasper/base/jas_cm.c \

View File

@ -188,10 +188,17 @@ namespace MetaFile
{
pFontManager->LoadFontByName(wsFaceName, dFontHeight, lStyle, 72, 72);
pFontManager->SetCharSpacing(dFontCharSpace * 72 / 25.4);
double dMmToPt = 25.4 / 72;
double dFHeight = dFontHeight * pFontManager->m_pFont->GetHeight() / pFontManager->m_pFont->m_lUnits_Per_Em * dMmToPt;
double dFDescent = dFontHeight * pFontManager->m_pFont->GetDescender() / pFontManager->m_pFont->m_lUnits_Per_Em * dMmToPt;
double dFAscent = dFHeight - std::abs(dFDescent);
double dMmToPt = 25.4 / 72;
double dFHeight = dFontHeight;
double dFDescent = dFontHeight;
if (pFontManager->m_pFont)
{
dFHeight *= pFontManager->m_pFont->GetHeight() / pFontManager->m_pFont->m_lUnits_Per_Em * dMmToPt;
dFDescent *= pFontManager->m_pFont->GetDescender() / pFontManager->m_pFont->m_lUnits_Per_Em * dMmToPt;
}
double dFAscent = dFHeight - std::abs(dFDescent);
if (NULL != pDx && unCharsCount > 1)
{

View File

@ -1143,6 +1143,8 @@ namespace NSHtmlRenderer
int symbolsCount = 0;
oCur.GenerateArray(symbols, symbolsCount);
// есть проблема с композитными глифами (буква ё). пока отключу конвертацию
lFontConverterFlag = 0;
oFontConverter.ToOTF(oCur.m_strFontPath, strTempFont, (unsigned int*)symbols, symbolsCount, sName, lFontConverterFlag); // TRUETYPE only
RELEASEARRAYOBJECTS(symbols);

View File

@ -21,6 +21,10 @@
int _tmain(int argc, _TCHAR* argv[])
{
std::wstring password = L"password";
ECMACryptFile crypt_file;
bool result = false, bDataIntegrity = false;
std::wstring srcFileName = L"D:\\test\\_crypted\\test-111.docx";
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
std::wstring dstFileName2 = dstFileName + L".oox";
@ -31,21 +35,12 @@ int _tmain(int argc, _TCHAR* argv[])
//std::wstring srcFileName = L"D:\\test\\_crypted\\test.docx";
//std::wstring dstFileName3 = srcFileName + L"-mycrypt1.docx";
std::wstring password = L"574446f1-6aa0-860a-0296-787a87a214bb";
ECMACryptFile crypt_file;
bool result = false, bDataIntegrity = false;
//result = crypt_file.DecryptOfficeFile(srcFileName, dstFileName, password, bDataIntegrity);
//result = crypt_file.EncryptOfficeFile(dstFileName, dstFileName2, password);
//std::wstring srcFileName1 = L"D:\\test\\_crypted\\test-111.docx-ms.docx";
//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);
COfficeFileFormatChecker fileChecker;
std::wstring sDocumentID = fileChecker.getDocumentID(L"d:/test/_pdf/Test3-pdfa-my.pdf");
return 0;
}

View File

@ -36,6 +36,7 @@
#include "../../Common/3dParty/cryptopp/modes.h"
#include "../../Common/3dParty/cryptopp/aes.h"
#include "../../Common/3dParty/cryptopp/des.h"
#include "../../Common/3dParty/cryptopp/sha.h"
#include "../../Common/3dParty/cryptopp/md5.h"
#include "../../Common/3dParty/cryptopp/rsa.h"
@ -62,6 +63,8 @@ static const unsigned char encrKeyValueBlockKey[8] = { 0x14, 0x6e, 0x0b, 0xe
static const unsigned char encrDataIntegritySaltBlockKey[8] = { 0x5f, 0xb2, 0xad, 0x01, 0x0c, 0xb9, 0xe1, 0xf6 };
static const unsigned char encrDataIntegrityHmacValueBlockKey[8] = { 0xa0, 0x67, 0x7f, 0x02, 0xb2, 0x2c, 0x84, 0x33 };
#define PADDING_SIZE 16
using namespace CryptoPP;
class _buf
@ -280,6 +283,9 @@ _buf HashAppend(_buf & hashBuf, _buf & block, CRYPT_METHOD::_hashAlgorithm algo
_buf GenerateAgileKey(_buf & salt, _buf & password, _buf & blockKey, int hashSize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm)
{
//if (hashSize < 8)
// blockKey = 8;
_buf pHashBuf = HashAppend(salt, password, algorithm);
for (int i = 0; i < spin; i++)
@ -308,7 +314,7 @@ _buf GenerateOdfKey(_buf & pSalt, _buf & pPassword, int keySize, int spin, CRYPT
return _buf(pKey.ptr, pKey.size);
}
_buf GenerateHashKey(_buf & salt, _buf & password, int hashSize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm, int block_index = 0)
_buf GenerateHashKey(_buf & salt, _buf & password, int hashSize, int keySize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm, int block_index = 0)
{
_buf block ((unsigned char*)&block_index, 4, false);
@ -350,8 +356,15 @@ _buf GenerateHashKey(_buf & salt, _buf & password, int hashSize, int spin, CRYPT
memcpy(pHashBuf3.ptr + 0, pHashBuf1.ptr, hashSize);
memcpy(pHashBuf3.ptr + hashSize, pHashBuf2.ptr, hashSize);
CorrectHashSize(pHashBuf3, keySize, 0);
if (keySize == 5)
CorrectHashSize(pHashBuf3, 16, 0); //40-bit crypt key !!!
return _buf(pHashBuf3.ptr, pHashBuf3.size);
}
ARC4::Decryption rc4Decryption; // todooo -> in impl
ARC4::Encryption rc4Encryption;
bool EncryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYPT_METHOD::_cipherAlgorithm algorithm,
StreamTransformationFilter::BlockPaddingScheme padding = StreamTransformationFilter::PKCS_PADDING)
@ -362,10 +375,11 @@ bool EncryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
}
else if (algorithm == CRYPT_METHOD::RC4)
{
data_out.ptr = new unsigned char[data_inp.size];
data_out.size = data_inp.size;
if (!data_out.ptr)
{
data_out = _buf(data_inp.size);
}
ARC4::Encryption rc4Encryption(key.ptr, key.size);
rc4Encryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
@ -374,6 +388,44 @@ bool EncryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
CFB_Mode<Blowfish>::Encryption encryption(key.ptr, key.size, iv.ptr);
encryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
else if (algorithm == CRYPT_METHOD::DES_CBC)
{
if (!iv.ptr)
{
iv = _buf(16, true);
}
DES::Encryption desEncryption(key.ptr, key.size == 7 ? 8 : key.size);
StreamTransformation *modeEncryption = new CipherModeFinalTemplate_ExternalCipher<CBC_Encryption>(desEncryption, iv.ptr );
if (!data_out.ptr)
{
data_out = _buf(data_inp.size);
}
StreamTransformationFilter stfEncryption(*modeEncryption, new ArraySink( data_out.ptr, data_out.size), padding);
stfEncryption.Put( data_inp.ptr, data_inp.size );
stfEncryption.MessageEnd();
delete modeEncryption;
}
else if (algorithm == CRYPT_METHOD::DES_ECB)
{
if (!iv.ptr)
{
iv = _buf(16, true);
}
DES::Encryption desEncryption(key.ptr, key.size == 7 ? 8 : key.size);
StreamTransformation *modeEncryption = new CipherModeFinalTemplate_ExternalCipher<ECB_OneWay>(desEncryption, iv.ptr );
if (!data_out.ptr)
{
data_out = _buf(data_inp.size);
}
StreamTransformationFilter stfEncryption(*modeEncryption, new ArraySink( data_out.ptr, data_out.size), padding);
stfEncryption.Put( data_inp.ptr, data_inp.size );
stfEncryption.MessageEnd();
delete modeEncryption;
}
else //AES
{
StreamTransformation *modeEncryption = NULL;
@ -413,8 +465,6 @@ bool EncryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
return true;
}
ARC4::Decryption rc4Decryption; // todooo -> in impl
bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYPT_METHOD::_cipherAlgorithm algorithm,
StreamTransformationFilter::BlockPaddingScheme padding = StreamTransformationFilter::NO_PADDING)
{
@ -436,6 +486,36 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRY
CFB_Mode<Blowfish>::Decryption decryption(key.ptr, key.size, iv.ptr);
decryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
else if (algorithm == CRYPT_METHOD::DES_CBC)
{
if (!iv.ptr)
{
iv = _buf(16, true);
}
DES::Decryption desDecryption(key.ptr, key.size == 7 ? 8 : key.size);
StreamTransformation *modeDecryption = new CipherModeFinalTemplate_ExternalCipher<CBC_Decryption>(desDecryption, iv.ptr );
StreamTransformationFilter stfDecryptor(*modeDecryption, new ArraySink( data_out.ptr, data_out.size), padding);
stfDecryptor.Put( data_inp.ptr, data_inp.size );
stfDecryptor.MessageEnd();
delete modeDecryption;
}
else if (algorithm == CRYPT_METHOD::DES_ECB)
{
if (!iv.ptr)
{
iv = _buf(16, true);
}
DES::Decryption desDecryption(key.ptr, key.size == 7 ? 8 : key.size);
StreamTransformation *modeDecryption = new CipherModeFinalTemplate_ExternalCipher<ECB_OneWay>(desDecryption, iv.ptr );
StreamTransformationFilter stfDecryptor(*modeDecryption, new ArraySink( data_out.ptr, data_out.size), padding);
stfDecryptor.Put( data_inp.ptr, data_inp.size );
stfDecryptor.MessageEnd();
delete modeDecryption;
}
else //AES
{
StreamTransformation *modeDecryption = NULL;
@ -504,13 +584,20 @@ bool ECMADecryptor::SetPassword(std::wstring _password)
_buf verifierInputKey = GenerateAgileKey( pSalt, pPassword, pInputBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
_buf verifierHashKey = GenerateAgileKey( pSalt, pPassword, pValueBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(verifierInputKey.ptr, verifierInputKey.size);
}
//--------------------------------------------
_buf decryptedVerifierHashInputBytes;
DecryptCipher(verifierInputKey, pSalt, pEncVerInput, decryptedVerifierHashInputBytes, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf hashBuf = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
//--------------------------------------------
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(verifierHashKey.ptr, verifierHashKey.size);
}
_buf decryptedVerifierHashBytes;
DecryptCipher(verifierHashKey, pSalt, pEncVerValue, decryptedVerifierHashBytes, cryptData.cipherAlgorithm);
//--------------------------------------------
@ -518,10 +605,7 @@ bool ECMADecryptor::SetPassword(std::wstring _password)
}
else
{
_buf verifierKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.spinCount, cryptData.hashAlgorithm);
CorrectHashSize(verifierKey, cryptData.keySize, 0);
if (cryptData.keySize == 5)
CorrectHashSize(verifierKey, 16, 0); //40-bit crypt key !!!
_buf verifierKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
@ -538,7 +622,7 @@ bool ECMADecryptor::SetPassword(std::wstring _password)
_buf decryptedVerifierHashBytes;
DecryptCipher(verifierKey, pSalt, pEncVerValue, decryptedVerifierHashBytes, cryptData.cipherAlgorithm);
bVerify = (decryptedVerifierHashBytes==hashBuf);
bVerify = (decryptedVerifierHashBytes == hashBuf);
}
return bVerify;
}
@ -587,11 +671,8 @@ void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long
_buf pPassword (password);
_buf pSalt (cryptData.saltValue);
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.spinCount, cryptData.hashAlgorithm, block_index);
CorrectHashSize(hashKey, cryptData.keySize, 0);
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm, block_index);
if (cryptData.keySize == 5) CorrectHashSize(hashKey, 16, 0); //40-bit crypt key !!!
rc4Decryption.SetKey(hashKey.ptr, hashKey.size);
}
@ -681,6 +762,10 @@ void ECMADecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*&
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(agileKey.ptr, agileKey.size);
}
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
@ -688,6 +773,10 @@ void ECMADecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*&
int i = start_iv_block, sz = 4096, pos = 0;//aes block size = 4096
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(pDecryptedKey.ptr, pDecryptedKey.size);
}
while (pos < size)
{
if (pos + sz > size)
@ -708,14 +797,10 @@ void ECMADecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*&
}
else
{
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.spinCount, cryptData.hashAlgorithm, start_iv_block);
CorrectHashSize(hashKey, cryptData.keySize, 0);
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm, start_iv_block);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
if (cryptData.keySize == 5)
CorrectHashSize(hashKey, 16, 0); //40-bit crypt key !!!
{
rc4Decryption.SetKey(hashKey.ptr, hashKey.size);
}
@ -759,40 +844,85 @@ void ECMAEncryptor::SetPassword(std::wstring _password)
//---------
_buf pPassword (password);
_buf empty (NULL, 0, false);
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pInputBlockKey ((unsigned char*)encrVerifierHashInputBlockKey, 8);
_buf pValueBlockKey ((unsigned char*)encrVerifierHashValueBlockKey, 8);
_buf pSalt (seed_salt.data(), seed_salt.size());
_buf pDataSalt (seed_datasalt.data(), seed_datasalt.size());
_buf pDecryptedKey (seed_key.data(), seed_key.size());
//------------------------------------------------------------------------------------------------
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.bAgile == true)
{
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pInputBlockKey ((unsigned char*)encrVerifierHashInputBlockKey, 8);
_buf pValueBlockKey ((unsigned char*)encrVerifierHashValueBlockKey, 8);
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pKeyValue;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pKeyValue, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashInputBytes(seed_verify.data(), seed_verify.size());
_buf verifierInputKey = GenerateAgileKey( pSalt, pPassword, pInputBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
_buf pEncVerInput;
EncryptCipher( verifierInputKey, pSalt, decryptedVerifierHashInputBytes, pEncVerInput, cryptData.cipherAlgorithm);
//--------------------------------------------
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(agileKey.ptr, agileKey.size);
}
_buf pKeyValue;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pKeyValue, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashInputBytes(seed_verify.data(), seed_verify.size());
_buf verifierInputKey = GenerateAgileKey( pSalt, pPassword, pInputBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(verifierInputKey.ptr, verifierInputKey.size);
}
_buf pEncVerInput;
EncryptCipher( verifierInputKey, pSalt, decryptedVerifierHashInputBytes, pEncVerInput, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashBytes = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
_buf verifierHashKey = GenerateAgileKey(pSalt, pPassword, pValueBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pEncVerValue;
EncryptCipher( verifierHashKey, pSalt, decryptedVerifierHashBytes, pEncVerValue, cryptData.cipherAlgorithm);
_buf decryptedVerifierHashBytes = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
_buf verifierHashKey = GenerateAgileKey(pSalt, pPassword, pValueBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(verifierHashKey.ptr, verifierHashKey.size);
}
else if (decryptedVerifierHashBytes.size % PADDING_SIZE != 0)
{
CorrectHashSize(decryptedVerifierHashBytes, (decryptedVerifierHashBytes.size / PADDING_SIZE + 1) * PADDING_SIZE, 0);
}
_buf pEncVerValue;
EncryptCipher( verifierHashKey, pSalt, decryptedVerifierHashBytes, pEncVerValue, cryptData.cipherAlgorithm);
cryptData.saltValue = std::string((char*)pSalt.ptr, pSalt.size);
cryptData.dataSaltValue = std::string((char*)pDataSalt.ptr, pDataSalt.size);
cryptData.encryptedKeyValue = std::string((char*)pKeyValue.ptr, pKeyValue.size);
cryptData.encryptedVerifierInput = std::string((char*)pEncVerInput.ptr, pEncVerInput.size);
cryptData.encryptedVerifierValue = std::string((char*)pEncVerValue.ptr, pEncVerValue.size);
cryptData.saltValue = std::string((char*)pSalt.ptr, pSalt.size);
cryptData.dataSaltValue = std::string((char*)pDataSalt.ptr, pDataSalt.size);
cryptData.encryptedKeyValue = std::string((char*)pKeyValue.ptr, pKeyValue.size);
cryptData.encryptedVerifierInput = std::string((char*)pEncVerInput.ptr, pEncVerInput.size);
cryptData.encryptedVerifierValue = std::string((char*)pEncVerValue.ptr, pEncVerValue.size);
}
else
{
_buf verifierKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(verifierKey.ptr, verifierKey.size);
}
_buf decryptedVerInput(seed_verify.data(), seed_verify.size());
_buf pEncVerInput;
EncryptCipher( verifierKey, pSalt, decryptedVerInput, pEncVerInput, cryptData.cipherAlgorithm);
_buf hashBuf = HashAppend(decryptedVerInput, empty, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm != CRYPT_METHOD::RC4 && hashBuf.size % PADDING_SIZE != 0)
{
CorrectHashSize(hashBuf, (hashBuf.size / PADDING_SIZE + 1) * PADDING_SIZE, 0);
}
_buf pEncVerValue;
EncryptCipher( verifierKey, pSalt, hashBuf, pEncVerValue, cryptData.cipherAlgorithm);
cryptData.saltValue = std::string((char*)pSalt.ptr, pSalt.size);
cryptData.encryptedVerifierInput = std::string((char*)pEncVerInput.ptr, pEncVerInput.size);
cryptData.encryptedVerifierValue = std::string((char*)pEncVerValue.ptr, pEncVerValue.size);
}
}
void ECMAEncryptor::SetCryptData(_ecmaCryptData & data)
@ -823,6 +953,11 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
//----
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(agileKey.ptr, agileKey.size);
}
_buf secretKey;
DecryptCipher( agileKey, pSalt, pKeyValue, secretKey, cryptData.cipherAlgorithm);
@ -844,16 +979,28 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
std::string sData((char*)data, size);
_buf hmac = Hmac(pSaltHmac, cryptData.hashAlgorithm, sData);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Encryption.SetKey(secretKey.ptr, secretKey.size);
}
if (pSaltHmac.size % PADDING_SIZE != 0)
{
CorrectHashSize(pSaltHmac, (pSaltHmac.size / PADDING_SIZE + 1) * PADDING_SIZE, 0);
}
_buf pEncHmacKey;
EncryptCipher(secretKey, iv1, pSaltHmac, pEncHmacKey, cryptData.cipherAlgorithm);
if (hmac.size % PADDING_SIZE != 0)
{
CorrectHashSize(hmac, (hmac.size / PADDING_SIZE + 1) * PADDING_SIZE, 0);
}
_buf pEncHmacValue;
EncryptCipher(secretKey, iv2, hmac, pEncHmacValue, cryptData.cipherAlgorithm);
cryptData.encryptedHmacKey = std::string((char*)pEncHmacKey.ptr, pEncHmacKey.size);
cryptData.encryptedHmacValue = std::string((char*)pEncHmacValue.ptr, pEncHmacValue.size);
}
#define PADDING_SIZE 16 // 8
int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*& data_out_ptr)
{
data_out_ptr = NULL;
@ -863,7 +1010,8 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
_buf empty (NULL, 0, false);
int size_out = size;
if (size_out % PADDING_SIZE != 0)
if (cryptData.cipherAlgorithm != CRYPT_METHOD::RC4 && size_out % PADDING_SIZE != 0)
size_out = (size_out / PADDING_SIZE + 1) * PADDING_SIZE;
data_out_ptr = new unsigned char[size_out + PADDING_SIZE]; // real size + padding + size for realsize
@ -873,63 +1021,90 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
unsigned char* data_inp = data_inp_ptr;
unsigned char* data_out = data_out_ptr + 8;
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pDataSalt (cryptData.dataSaltValue);
_buf pKeyValue (cryptData.encryptedKeyValue);
//------------------------------------------------------------------------------------------------
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
//-------------------------------------------------------------------------------------------------
_buf iv(cryptData.blockSize, true);
int i = 0, sz = 4096, enc_size = 0;
while (enc_size < size)
{
if (enc_size + sz > size)
{
sz = size - enc_size;
}
if (cryptData.bAgile)
{
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pDataSalt (cryptData.dataSaltValue);
_buf pKeyValue (cryptData.encryptedKeyValue);
_buf pIndex((unsigned char*)&i, 4);
iv = HashAppend(pDataSalt, pIndex, cryptData.hashAlgorithm);
//------------------------------------------------------------------------------------------------
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
CorrectHashSize(iv, cryptData.blockSize, 0x36);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(agileKey.ptr, agileKey.size);
}
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
if (sz < 4096)
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
_buf pInp(4096);
memcpy(pInp.ptr, data_inp, sz );
pInp.size = sz;
_buf pOut(4096);
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
if (sz % PADDING_SIZE != 0)
sz = (sz / PADDING_SIZE + 1) * PADDING_SIZE;
memcpy(data_out, pOut.ptr, sz);
rc4Encryption.SetKey(pDecryptedKey.ptr, agileKey.size);
}
else
//-------------------------------------------------------------------------------------------------
_buf iv(cryptData.blockSize, true);
int i = 0, sz = 4096, enc_size = 0;
while (enc_size < size)
{
_buf pInp(data_inp, sz, false);
_buf pOut(data_out, sz, false);
if (enc_size + sz > size)
{
sz = size - enc_size;
}
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
}
data_inp += sz;
data_out += sz;
_buf pIndex((unsigned char*)&i, 4);
iv = HashAppend(pDataSalt, pIndex, cryptData.hashAlgorithm);
enc_size += sz; i++;
CorrectHashSize(iv, cryptData.blockSize, 0x36);
if (sz < 4096)
{
_buf pInp(4096);
memcpy(pInp.ptr, data_inp, sz );
pInp.size = sz;
_buf pOut(4096);
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
if (sz % PADDING_SIZE != 0)
sz = (sz / PADDING_SIZE + 1) * PADDING_SIZE;
memcpy(data_out, pOut.ptr, sz);
}
else
{
_buf pInp(data_inp, sz, false);
_buf pOut(data_out, sz, false);
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
}
data_inp += sz;
data_out += sz;
enc_size += sz; i++;
}
return enc_size + 8;
}
else
{
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
rc4Decryption.SetKey(hashKey.ptr, hashKey.size);
rc4Encryption.SetKey(hashKey.ptr, hashKey.size);
}
_buf pInp(data_inp, size, false);
_buf pOut(data_out, size_out, false);
return enc_size + 8;
EncryptCipher(hashKey, empty, pInp, pOut, cryptData.cipherAlgorithm/*, StreamTransformationFilter::ZEROS_PADDING*/);
return size_out + 8;
}
}
//-----------------------------------------------------------------------------------------------------------
ODFDecryptor::ODFDecryptor()

View File

@ -55,7 +55,9 @@ namespace CRYPT_METHOD
AES_CBC,
AES_CFB,
AES_ECB,
Blowfish_CFB
Blowfish_CFB,
DES_CBC,
DES_ECB
};
}
namespace CRYPT

View File

@ -37,6 +37,7 @@
#include "../../Common/DocxFormat/Source/Base/Types_32.h"
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/common/SystemUtils.h"
#include "../../DesktopEditor/xml/include/xmlutils.h"
#include "../../ASCOfficeDocFile/DocDocxConverter/MemoryStream.h"
@ -46,7 +47,8 @@
using namespace CRYPT;
#define GETBIT(from, num) ((from & (1 << num)) != 0)
#define GETBIT(from, num) ((from & (1 << num)) != 0)
#define SETBIT(to, num, setorclear) {setorclear ? to |= (1 << num) : to &= ~(1 << num);}
#define WritingElement_ReadAttributes_Start(Reader) \
if ( Reader.GetAttributesCount() <= 0 )\
@ -288,15 +290,26 @@ bool ReadXmlEncryptionInfo(const std::string & xml_string, _ecmaCryptData & cryp
if (keyData.cipherAlgorithm == "AES")
{
if (keyData.cipherChaining == "ChainingModeCBC") cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
//if (keyData.cipherChaining == "ChainingModeCBC") cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
if (keyData.cipherChaining == "ChainingModeCFB") cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CFB;
}
if (keyData.hashAlgorithm == "SHA1") cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
if (keyData.hashAlgorithm == "SHA224") cryptData.hashAlgorithm = CRYPT_METHOD::SHA224;
if (keyData.hashAlgorithm == "SHA256") cryptData.hashAlgorithm = CRYPT_METHOD::SHA256;
if (keyData.hashAlgorithm == "SHA384") cryptData.hashAlgorithm = CRYPT_METHOD::SHA384;
if (keyData.hashAlgorithm == "SHA512") cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
else if (keyData.cipherAlgorithm == "RC4")
{
cryptData.cipherAlgorithm = CRYPT_METHOD::RC4;
}
else if (keyData.cipherAlgorithm == "DES")
{
cryptData.cipherAlgorithm = CRYPT_METHOD::DES_CBC;
//if (keyData.cipherChaining == "ChainingModeCBC") cryptData.cipherAlgorithm = CRYPT_METHOD::DES_CBC;
if (keyData.cipherChaining == "ChainingModeECB") cryptData.cipherAlgorithm = CRYPT_METHOD::DES_ECB;
}
if (keyData.hashAlgorithm == "SHA1") cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
else if (keyData.hashAlgorithm == "SHA224") cryptData.hashAlgorithm = CRYPT_METHOD::SHA224;
else if (keyData.hashAlgorithm == "SHA256") cryptData.hashAlgorithm = CRYPT_METHOD::SHA256;
else if (keyData.hashAlgorithm == "SHA384") cryptData.hashAlgorithm = CRYPT_METHOD::SHA384;
else if (keyData.hashAlgorithm == "SHA512") cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
else if (keyData.hashAlgorithm == "MD5") cryptData.hashAlgorithm = CRYPT_METHOD::MD5;
return true;
}
@ -315,12 +328,33 @@ bool WriteXmlEncryptionInfo(const _ecmaCryptData & cryptData, std::string & xml_
keyData.keyBits = std::to_string(cryptData.keySize * 8);
keyData.saltValue = EncodeBase64(cryptData.dataSaltValue);
keyData.cipherAlgorithm = "AES";
if (keyData.cipherAlgorithm == "AES")
switch(cryptData.cipherAlgorithm)
{
if (cryptData.cipherAlgorithm == CRYPT_METHOD::AES_CBC) keyData.cipherChaining = "ChainingModeCBC";
if (cryptData.cipherAlgorithm == CRYPT_METHOD::AES_CFB) keyData.cipherChaining = "ChainingModeCFB";
case CRYPT_METHOD::RC4:
keyData.cipherAlgorithm = "RC4";
break;
case CRYPT_METHOD::AES_CBC:
keyData.cipherAlgorithm = "AES";
keyData.cipherChaining = "ChainingModeCBC";
break;
case CRYPT_METHOD::AES_ECB:
keyData.cipherAlgorithm = "AES";
keyData.cipherChaining = "ChainingModeECB";
break;
case CRYPT_METHOD::AES_CFB:
keyData.cipherAlgorithm = "AES";
keyData.cipherChaining = "ChainingModeCFB";
break;
case CRYPT_METHOD::DES_CBC:
keyData.cipherAlgorithm = "DES";
keyData.cipherChaining = "ChainingModeCBC";
break;
case CRYPT_METHOD::DES_ECB:
keyData.cipherAlgorithm = "DES";
keyData.cipherChaining = "ChainingModeECB";
break;
break;
}
switch(cryptData.hashAlgorithm)
@ -330,6 +364,7 @@ bool WriteXmlEncryptionInfo(const _ecmaCryptData & cryptData, std::string & xml_
case CRYPT_METHOD::SHA256: keyData.hashAlgorithm = "SHA256"; break;
case CRYPT_METHOD::SHA384: keyData.hashAlgorithm = "SHA384"; break;
case CRYPT_METHOD::SHA512: keyData.hashAlgorithm = "SHA512"; break;
case CRYPT_METHOD::MD5: keyData.hashAlgorithm = "MD5"; break;
}
std::vector<_keyEncryptor> keyEncryptors;
@ -360,7 +395,12 @@ bool WriteXmlEncryptionInfo(const _ecmaCryptData & cryptData, std::string & xml_
CP_XML_ATTR("keyBits", keyData.keyBits);
CP_XML_ATTR("hashSize", keyData.hashSize);
CP_XML_ATTR("cipherAlgorithm", keyData.cipherAlgorithm);
CP_XML_ATTR("cipherChaining", keyData.cipherChaining);
if (false == keyData.cipherChaining.empty())
{
CP_XML_ATTR("cipherChaining", keyData.cipherChaining);
}
CP_XML_ATTR("hashAlgorithm", keyData.hashAlgorithm);
CP_XML_ATTR("saltValue", keyData.saltValue);
}
@ -400,7 +440,105 @@ bool WriteXmlEncryptionInfo(const _ecmaCryptData & cryptData, std::string & xml_
return true;
}
bool WriteStandartEncryptionInfo(unsigned char* data, int &size, _ecmaCryptData & cryptData)
{
if (!data || size < 1) return false;
MemoryStream mem_stream(data, size, false);
_UINT32 SizeHeader = 0, Flags = 0, SizeExtra = 0, AlgID = 0, AlgIDHash = 0, KeySize = 0, ProviderType = 0, Reserved1 = 0, Reserved2 = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
SETBIT(Flags, 2, fCryptoAPI);
SETBIT(Flags, 3, fDocProps);
SETBIT(Flags, 4, fExternal);
SETBIT(Flags, 5, fAES);
mem_stream.WriteUInt32(SizeHeader);
KeySize = (cryptData.keySize == 5) ? 0 : cryptData.keySize * 8;
std::string provider;// to utf16
switch(cryptData.cipherAlgorithm)
{
case CRYPT_METHOD::RC4:
{
ProviderType = 0x0001;
AlgID = 0x6801;
}break;
case CRYPT_METHOD::DES_ECB:
case CRYPT_METHOD::DES_CBC:
{
ProviderType = 0;//0x0018;
AlgID = 0x6601;
}break;
case CRYPT_METHOD::AES_ECB:
case CRYPT_METHOD::AES_CBC:
{
ProviderType = 0x0018;
switch(KeySize)
{
case 128: AlgID = 0x660E; break;
case 192: AlgID = 0x660F; break;
case 256: AlgID = 0x6610; break;
}
break;
}break;
}
//ProviderType = 0x0018;
switch(ProviderType)
{
case 0x0001: provider = "Microsoft Strong Cryptographic Provider"; break;
case 0x0018: provider = "Microsoft Enhanced RSA and AES Cryptographic Provider"; break;
}
switch(cryptData.hashAlgorithm)
{
case CRYPT_METHOD::MD5: AlgIDHash = 0x8003; break;
case CRYPT_METHOD::SHA1: AlgIDHash = 0x8004; break;
case CRYPT_METHOD::SHA256: AlgIDHash = 0x8004; break;
case CRYPT_METHOD::SHA384: AlgIDHash = 0x800D; break;
case CRYPT_METHOD::SHA512: AlgIDHash = 0x800E; break;
}
mem_stream.WriteUInt32(Flags);
mem_stream.WriteUInt32(SizeExtra);
mem_stream.WriteUInt32(AlgID);
mem_stream.WriteUInt32(AlgIDHash);
mem_stream.WriteUInt32(KeySize);
mem_stream.WriteUInt32(ProviderType);
mem_stream.WriteUInt32(Reserved1);
mem_stream.WriteUInt32(Reserved2);
for (size_t i = 0; i < provider.length(); ++i)
{
mem_stream.WriteByte((unsigned char)provider[i]);
mem_stream.WriteByte((unsigned char)0);
}
mem_stream.WriteByte((unsigned char)0); //null terminate
mem_stream.WriteByte((unsigned char)0);
SizeHeader = mem_stream.GetPosition() - 4;
//EncryptionVerifier
mem_stream.WriteUInt32((_UINT32)cryptData.saltSize);
mem_stream.WriteBytes((unsigned char*)cryptData.saltValue.c_str(), cryptData.saltSize);
mem_stream.WriteBytes((unsigned char*)cryptData.encryptedVerifierInput.c_str(), 0x10);
mem_stream.WriteUInt32((_UINT32)cryptData.hashSize);
//int szEncryptedVerifierHash = (ProviderType == 0x0001) ? 0x14 : 0x20; //RC4 | AES(DES) .. md5?
mem_stream.WriteBytes((unsigned char*)cryptData.encryptedVerifierValue.c_str(), cryptData.encryptedVerifierValue.length()/*szEncryptedVerifierHash*/);
size = mem_stream.GetPosition();
mem_stream.Seek(0);
mem_stream.WriteUInt32(SizeHeader);
return true;
}
bool ReadStandartEncryptionInfo(unsigned char* data, int size, _ecmaCryptData & cryptData)
{
if (!data || size < 1) return false;
@ -445,21 +583,41 @@ bool ReadStandartEncryptionInfo(unsigned char* data, int size, _ecmaCryptData &
cryptData.hashSize = mem_stream.ReadUInt32();
int szEncryptedVerifierHash = (ProviderType == 0x0001) ? 0x14 : 0x20;
cryptData.encryptedVerifierValue = std::string((char*)data + mem_stream.GetPosition(), szEncryptedVerifierHash);
unsigned long szEncryptedVerifierHash = (ProviderType == 0x0001) ? 0x14 : 0x20; // RC4 | AES(DES)
unsigned long szEncryptedVerifierHashMax = mem_stream.GetSize() - mem_stream.GetPosition();
cryptData.encryptedVerifierValue = std::string((char*)data + mem_stream.GetPosition(), (std::max)(szEncryptedVerifierHash, szEncryptedVerifierHashMax));
mem_stream.ReadBytes(szEncryptedVerifierHash, false);
pos = mem_stream.GetPosition();
//------------------------------------------------------------------------------------------
cryptData.hashAlgorithm = CRYPT_METHOD::SHA1; //by AlgIDHash -> 0x0000 || 0x8004
cryptData.spinCount = 50000;
switch(AlgIDHash)
{
case 0x8003:
cryptData.hashAlgorithm = CRYPT_METHOD::MD5; break;
case 0x0000:
case 0x8004:
cryptData.hashAlgorithm = CRYPT_METHOD::SHA1; break;
case 0x800C:
cryptData.hashAlgorithm = CRYPT_METHOD::SHA256; break;
case 0x800D:
cryptData.hashAlgorithm = CRYPT_METHOD::SHA384; break;
case 0x800E:
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512; break;
}
cryptData.spinCount = 50000;
switch(AlgID)
{
case 0x6801:
cryptData.cipherAlgorithm = CRYPT_METHOD::RC4;
cryptData.keySize = KeySize / 8;
if (KeySize == 0) cryptData.keySize = 5; //40 bit
else cryptData.keySize = KeySize / 8;
break;
case 0x6601:
cryptData.cipherAlgorithm = CRYPT_METHOD::DES_ECB;
cryptData.keySize = 8;
break;
case 0x660E:
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
@ -488,12 +646,69 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s
{
_ecmaCryptData cryptData;
cryptData.bAgile = true;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
cryptData.keySize = 0x20;
cryptData.hashSize = 0x40;
cryptData.blockSize = 0x10;
cryptData.saltSize = 0x10;
std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvMethodEncrypt);
if (sApplication == L"Weak")
{
cryptData.bAgile = false;
cryptData.cipherAlgorithm = CRYPT_METHOD::DES_ECB;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
cryptData.keySize = 0x08;
cryptData.hashSize = 0x14;
cryptData.blockSize = 0x10;
cryptData.saltSize = 0x10;
cryptData.spinCount = 50000;
}
else
{
cryptData.bAgile = true;
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
cryptData.keySize = 0x20;
cryptData.hashSize = 0x40;
cryptData.blockSize = 0x10;
cryptData.saltSize = 0x10;
cryptData.spinCount = 100000;
}
//cryptData.bAgile = true;
//cryptData.cipherAlgorithm = CRYPT_METHOD::DES_CBC;
////cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
////cryptData.keySize = 0x08;
////cryptData.hashSize = 0x40;
////cryptData.blockSize = 0x10;
////cryptData.saltSize = 0x10;
//cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
//cryptData.keySize = 0x08;
//cryptData.hashSize = 0x14;
//cryptData.blockSize = 0x10;
//cryptData.saltSize = 0x10;
//cryptData.bAgile = false;
//cryptData.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
//cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
//cryptData.keySize = 0x10;
//cryptData.hashSize = 0x14;
//cryptData.blockSize = 0x10;
//cryptData.saltSize = 0x10;
//cryptData.spinCount = 50000;
//cryptData.bAgile = false;
//cryptData.cipherAlgorithm = CRYPT_METHOD::RC4;
//cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
//cryptData.keySize = 7;
//cryptData.hashSize = 0x14;
//cryptData.blockSize = 0x10;
//cryptData.saltSize = 0x10;
//cryptData.spinCount = 50000;
//cryptData.bAgile = false;
//cryptData.cipherAlgorithm = CRYPT_METHOD::DES_ECB;
//cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
//cryptData.keySize = 0x08;
//cryptData.hashSize = 0x14;
//cryptData.blockSize = 0x10;
//cryptData.saltSize = 0x10;
//cryptData.spinCount = 50000;
ECMAEncryptor cryptor;
@ -539,22 +754,53 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s
cryptor.GetCryptData(cryptData);
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
if (cryptData.bAgile)
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile standart
_UINT32 nEncryptionInfoFlags = 64;
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
pStream->write((unsigned char*)strXml.c_str(), strXml.length());
pStream->flush();
delete pStream;
}
else
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0002; // standart
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
_UINT32 nEncryptionInfoFlags = 64;
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
pStream->write((unsigned char*)strXml.c_str(), strXml.length());
pStream->flush();
delete pStream;
//-------------------------------------------------------------------
_UINT32 nEncryptionInfoFlags = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
SETBIT(nEncryptionInfoFlags, 2, fCryptoAPI);
SETBIT(nEncryptionInfoFlags, 3, fDocProps);
SETBIT(nEncryptionInfoFlags, 4, fExternal);
SETBIT(nEncryptionInfoFlags, 5, fAES);
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
int nEncryptionInfoSize = 4096;
unsigned char* byteEncryptionInfo = new unsigned char[nEncryptionInfoSize];
WriteStandartEncryptionInfo(byteEncryptionInfo, nEncryptionInfoSize, cryptData);
pStream->write(byteEncryptionInfo, nEncryptionInfoSize);
delete []byteEncryptionInfo;
pStream->flush();
delete pStream;
}
//-------------------------------------------------------------------
pStream = new POLE::Stream(pStorage, L"EncryptedPackage", true, lengthData);
pStream->write(data_out, lengthData);
@ -651,10 +897,10 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s
else
{
cryptData.bAgile = false;
bool fCryptoAPI = GETBIT(nEncryptionInfoFlags, 1);
bool fDocProps = GETBIT(nEncryptionInfoFlags, 2);
bool fExternal = GETBIT(nEncryptionInfoFlags, 3);
bool fAES = GETBIT(nEncryptionInfoFlags, 4);
bool fCryptoAPI = GETBIT(nEncryptionInfoFlags, 2);
bool fDocProps = GETBIT(nEncryptionInfoFlags, 3);
bool fExternal = GETBIT(nEncryptionInfoFlags, 4);
bool fAES = GETBIT(nEncryptionInfoFlags, 5);
if ((VersionInfoMajor == 0x0003 || VersionInfoMajor == 0x0004) && VersionInfoMinor == 0x0003) //extensible info
{
@ -676,28 +922,6 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s
delete pStorage;
return false;
}
//------------------------------------------------------------------------------------------------------------
//pStream = new POLE::Stream(pStorage, "DataSpaces/DataSpaceMap");
//if (pStream)
//{
// delete pStream;
// pStorage->deleteByName("DataSpaces");
// //_UINT32 size = 0;
// //_UINT32 count = 0;
// //
// //pStream->read((unsigned char*)&size, 4);
// //pStream->read((unsigned char*)&count, 4);
// //for (int i = 0 ; i < count; i++)
// //{
// // _mapEntry m;
// // ReadMapEntry(pStream, m);
// // mapEntries.push_back(m);
// //}
// //delete pStream;
//}
//------------------------------------------------------------------------------------------------------------
ECMADecryptor decryptor;

View File

@ -364,6 +364,14 @@
RelativePath="..\..\..\XlsxSerializerCom\Writer\BinaryCommonReader.h"
>
</File>
<File
RelativePath="..\..\..\XlsxSerializerCom\Writer\BinaryReader.h"
>
</File>
<File
RelativePath="..\..\..\XlsxSerializerCom\Common\BinReaderWriterDefines.h"
>
</File>
<File
RelativePath="..\..\..\XlsxSerializerCom\Reader\CSVReader.cpp"
>
@ -627,14 +635,6 @@
<Filter
Name="Common"
>
<File
RelativePath="..\..\..\XlsxSerializerCom\Writer\BinaryReader.h"
>
</File>
<File
RelativePath="..\..\..\XlsxSerializerCom\Common\BinReaderWriterDefines.h"
>
</File>
<File
RelativePath="..\..\..\XlsxSerializerCom\Reader\ChartFromToBinary.cpp"
>

View File

@ -37,7 +37,7 @@
namespace BinXlsxRW {
#define READ_TABLE_DEF(res, fReadFunction, arg) {\
#define READ_TABLE_DEF(res, fReadFunction, arg) {\
res = m_oBufferedStream.Peek(4) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;\
if (c_oSerConstants::ReadOk == res) {\
long readtabledefLen = m_oBufferedStream.GetLong();\
@ -47,65 +47,66 @@ namespace BinXlsxRW {
}\
}\
}
#define READ1_DEF(stLen, res, fReadFunction, arg) {\
long read1defCurPos = 0;\
long read1defstart_pos = m_oBufferedStream.GetPos();\
while(read1defCurPos < (long)stLen)\
{\
BYTE read1defType = m_oBufferedStream.GetUChar();\
ULONG read1defLength = m_oBufferedStream.GetULong();\
if (read1defLength + read1defCurPos > (ULONG)stLen)\
{\
m_oBufferedStream.Seek(read1defstart_pos + stLen);\
res = c_oSerConstants::ReadOk;\
break;\
}\
res = fReadFunction(read1defType, read1defLength, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read1defLength);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read1defCurPos += read1defLength + 5;\
}\
}
#define READ2_DEF(stLen, res, fReadFunction, arg) {\
long read2defCurPos = 0;\
while(read2defCurPos < stLen)\
#define READ1_DEF(stLen, res, fReadFunction, arg) {\
long read1defCurPos = 0;\
long read1defstart_pos = m_oBufferedStream.GetPos();\
while(read1defCurPos < (long)stLen)\
{\
BYTE read1defType = m_oBufferedStream.GetUChar();\
ULONG read1defLength = m_oBufferedStream.GetULong();\
if (read1defLength + read1defCurPos > (ULONG)stLen)\
{\
BYTE read2defType = m_oBufferedStream.GetUChar();\
long read2defLenType = m_oBufferedStream.GetUChar();\
int read2defCurPosShift = 2;\
int read2defRealLen;\
switch(read2defLenType)\
{\
case c_oSerPropLenType::Null: read2defRealLen = 0;break;\
case c_oSerPropLenType::Byte: read2defRealLen = 1;break;\
case c_oSerPropLenType::Short: read2defRealLen = 2;break;\
case c_oSerPropLenType::Three: read2defRealLen = 3;break;\
case c_oSerPropLenType::Long: read2defRealLen = 4;break;\
case c_oSerPropLenType::Double: read2defRealLen = 8;break;\
case c_oSerPropLenType::Variable:\
read2defRealLen = m_oBufferedStream.GetLong();\
read2defCurPosShift += 4;\
break;\
default:res = c_oSerConstants::ErrorUnknown;break;\
}\
if(res == c_oSerConstants::ReadOk)\
res = fReadFunction(read2defType, read2defRealLen, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read2defRealLen);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read2defCurPos += read2defRealLen + read2defCurPosShift;\
m_oBufferedStream.Seek(read1defstart_pos + stLen);\
res = c_oSerConstants::ReadOk;\
break;\
}\
}
res = fReadFunction(read1defType, read1defLength, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read1defLength);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read1defCurPos += read1defLength + 5;\
}\
}
#define READ2_DEF(stLen, res, fReadFunction, arg) {\
long read2defCurPos = 0;\
while(read2defCurPos < stLen)\
{\
BYTE read2defType = m_oBufferedStream.GetUChar();\
long read2defLenType = m_oBufferedStream.GetUChar();\
int read2defCurPosShift = 2;\
int read2defRealLen;\
switch(read2defLenType)\
{\
case c_oSerPropLenType::Null: read2defRealLen = 0;break;\
case c_oSerPropLenType::Byte: read2defRealLen = 1;break;\
case c_oSerPropLenType::Short: read2defRealLen = 2;break;\
case c_oSerPropLenType::Three: read2defRealLen = 3;break;\
case c_oSerPropLenType::Long: read2defRealLen = 4;break;\
case c_oSerPropLenType::Double: read2defRealLen = 8;break;\
case c_oSerPropLenType::Variable:\
read2defRealLen = m_oBufferedStream.GetLong();\
read2defCurPosShift += 4;\
break;\
default:res = c_oSerConstants::ErrorUnknown;break;\
}\
if(res == c_oSerConstants::ReadOk)\
res = fReadFunction(read2defType, read2defRealLen, arg);\
if(res == c_oSerConstants::ReadUnknown)\
{\
m_oBufferedStream.GetPointer(read2defRealLen);\
res = c_oSerConstants::ReadOk;\
}\
else if(res != c_oSerConstants::ReadOk)\
break;\
read2defCurPos += read2defRealLen + read2defCurPosShift;\
}\
}
class Binary_CommonReader
{