Commit 00f1f40a authored by ElenaSubbotina's avatar ElenaSubbotina

RtfFormat - add office digital signatures

parent 46c05a4c
......@@ -1653,7 +1653,7 @@ bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, st
COMMAND_RTF_INT ( "objw", m_oOle.m_nWidth, sCommand, hasParameter, parameter )
COMMAND_RTF_INT ( "objh", m_oOle.m_nHeight, sCommand, hasParameter, parameter )
COMMAND_RTF_INT ( "objemb", m_oOle.m_eOleType, sCommand, true, RtfOle::ot_emb )
COMMAND_RTF_INT ( "objemb", m_oOle.m_eOleType, sCommand, true, RtfOle::ot_emb )
COMMAND_RTF_INT ( "objlink", m_oOle.m_eOleType, sCommand, true, RtfOle::ot_link )
else if ( "objclass" == sCommand )
......@@ -1760,6 +1760,31 @@ void RtfShapeReader::ShapePropertyReader::ShapePropertyValueReader::PopState( Rt
m_oShape.m_sGtextFont = sValue;
return;
}
else if ( L"wzSigSetupId" == m_sPropName )
{
m_oShape.m_sSigSetupId = sValue;
return;
}
else if ( L"wzSigSetupProvId" == m_sPropName )
{
m_oShape.m_sSigSetupProvId = sValue;
return;
}
else if ( L"wzSigSetupSuggSigner" == m_sPropName )
{
m_oShape.m_sSigSetupSuggSigner = sValue;
return;
}
else if ( L"wzSigSetupSuggSigner2" == m_sPropName )
{
m_oShape.m_sSigSetupSuggSigner2 = sValue;
return;
}
else if ( L"wzSigSetupSuggSignerEmail" == m_sPropName )
{
m_oShape.m_sSigSetupSuggSignerEmail = sValue;
return;
}
//числовые
int nValue = 0;
......@@ -1965,8 +1990,11 @@ void RtfShapeReader::ShapePropertyReader::ShapePropertyValueReader::PopState( Rt
else if ( L"lineEndArrowLength" == m_sPropName ) m_oShape.m_nLineEndArrowLength = nValue;
else if ( L"lineWidth" == m_sPropName ) m_oShape.m_nLineWidth = nValue;
else if ( L"lineDashing" == m_sPropName ) m_oShape.m_nLineDashing = nValue;
else if (L"cxstyle" == m_sPropName ) m_oShape.m_nConnectorStyle = nValue;
else if (L"cxk" == m_sPropName ) m_oShape.m_nConnectionType = nValue;
else if ( L"cxstyle" == m_sPropName ) m_oShape.m_nConnectorStyle = nValue;
else if ( L"cxk" == m_sPropName ) m_oShape.m_nConnectionType = nValue;
//office signature
else if ( L"fIsSignatureLine" == m_sPropName ) m_oShape.m_bIsSignatureLine = nValue;
else if ( L"fSigSetupAllowComments" == m_sPropName ) m_oShape.m_bSigSetupAllowComments = nValue;
else
{
std::wstring name = m_sPropName;
......
......@@ -84,9 +84,8 @@ int OOXGraphicReader::Parse( ReaderParameter oParam , RtfShapePtr & pOutput)
pOutput->m_nShapeType = 75;
OOX::Drawing::CPicture *picture = dynamic_cast<OOX::Drawing::CPicture *>(m_ooxGraphic->m_arrItems[i]);
if (picture)
if (OOXShapeReader::Parse(oParam, pOutput, &picture->m_oBlipFill))
return 1;
OOXShapeReader::Parse(oParam, pOutput, &picture->m_oBlipFill); // тут если false приходит - картинка-потеряшка
return 1;
}
}
}break;
......
......@@ -92,7 +92,7 @@ SimpleTypes::Vml::SptType static PrstTx2ShapeType(SimpleTypes::ETextShapeType ty
}
bool ParseStyle(RtfShapePtr pShape, SimpleTypes::Vml::CCssProperty* prop)
bool ParseVmlStyle(RtfShapePtr pShape, SimpleTypes::Vml::CCssProperty* prop)
{
if (pShape == NULL) return false;
if (prop == NULL) return false;
......@@ -572,11 +572,46 @@ bool OOXShapeReader::ParseVmlChild( ReaderParameter oParam , RtfShapePtr& pOutpu
}
if (text_path->m_oStyle.IsInit())
{
ParseStyles( pOutput, text_path->m_oStyle->m_arrProperties );
ParseVmlStyles( pOutput, text_path->m_oStyle->m_arrProperties );
}
}
}break;
case OOX::et_o_signatureline:
{
OOX::VmlOffice::CSignatureLine *signature = dynamic_cast<OOX::VmlOffice::CSignatureLine*>(m_arrElement->m_arrItems[i]);
if ( signature )
{
if (signature->m_oIsSignatureLine.GetValue() == SimpleTypes::booleanTrue)
pOutput->m_bIsSignatureLine = 1;
if (signature->m_oAllowComments.GetValue() == SimpleTypes::booleanTrue)
pOutput->m_bSigSetupAllowComments = 1;
if (signature->m_oProvId.IsInit())
pOutput->m_sSigSetupProvId = signature->m_oProvId->ToString();
if (signature->m_oId.IsInit())
pOutput->m_sSigSetupId = signature->m_oId->ToString();
if (signature->m_sSuggestedSigner.IsInit())
pOutput->m_sSigSetupSuggSigner = signature->m_sSuggestedSigner.get();
if (signature->m_sSuggestedSigner2.IsInit())
pOutput->m_sSigSetupSuggSigner2 = signature->m_sSuggestedSigner2.get();
if (signature->m_sSuggestedSignerEmail.IsInit())
pOutput->m_sSigSetupSuggSignerEmail = signature->m_sSuggestedSignerEmail.get();
//nullable<std::wstring> m_sAddXml;
//nullable<SimpleTypes::CExt<>> m_oExt;
//SimpleTypes::CTrueFalse<SimpleTypes::booleanTrue> m_oShowSignDate;
//nullable<std::wstring> m_sSigningInstructions;
//SimpleTypes::CTrueFalse<SimpleTypes::booleanFalse> m_oSigningInstructionsSet;
//nullable<std::wstring> m_sSigProvUrl;
}
}break;
default: break;
}
}
......@@ -1309,7 +1344,7 @@ bool OOXShapeReader::ParseVml( ReaderParameter oParam , RtfShapePtr& pOutput)
if ( m_vmlElement->m_oStyle.IsInit())
{
if( false == ParseStyles( pOutput, m_vmlElement->m_oStyle->m_arrProperties ) )
if( false == ParseVmlStyles( pOutput, m_vmlElement->m_oStyle->m_arrProperties ) )
return false;
}
......@@ -1382,7 +1417,7 @@ bool OOXShapeGroupReader::Parse( ReaderParameter oParam , RtfShapePtr& pOutput)
if ( m_vmlGroup->m_oStyle.IsInit())
{
if( false == ParseStyles( pOutput, m_vmlGroup->m_oStyle->m_arrProperties ) )
if( false == ParseVmlStyles( pOutput, m_vmlGroup->m_oStyle->m_arrProperties ) )
return false;
}
......@@ -1635,7 +1670,8 @@ bool OOXShapeReader::WriteDataToPicture( std::wstring sPath, RtfPicture& pOutput
//Выставляем тип картинки
pOutput.eDataType = RtfPicture::GetPictureType( sPath );
//ecли тип не поддерживается rtf конвертируем в png
//ecли тип не поддерживается rtf конвертируем в png
if( RtfPicture::dt_none == pOutput.eDataType )
{
//в туже папку что и исходная картинка
......@@ -1656,68 +1692,82 @@ bool OOXShapeReader::WriteDataToPicture( std::wstring sPath, RtfPicture& pOutput
pOutput.m_bIsCopy = true;//выставляем флаг чтобы потом удалить файл
}
}
else
else if( RtfPicture::dt_apm == pOutput.eDataType )
{
if( RtfPicture::dt_apm == pOutput.eDataType )
{
//убираем заголовок apm (22 byte)
CFile file_inp; //mpa
CFile file_out;//wmf
//убираем заголовок apm (22 byte)
CFile file_inp; //mpa
CFile file_out;//wmf
std::wstring sTargetFile = NSDirectory::CreateTempFileWithUniqueName(ooxPath.GetDirectory(), L"img");
std::wstring sTargetFile = NSDirectory::CreateTempFileWithUniqueName(ooxPath.GetDirectory(), L"img");
int res = file_inp.OpenFile(sPath);
if (res != S_OK) return false;
int res = file_inp.OpenFile(sPath);
if (res != S_OK) return false;
res = file_out.CreateFile(sTargetFile);
if (res != S_OK) return false;
res = file_out.CreateFile(sTargetFile);
if (res != S_OK) return false;
DWORD dwBytesRead = 0;
DWORD dwBytesWrite = 0;
BYTE pBuffer[1024];
DWORD nHeaderLen = 22;
DWORD dwBytesRead = 0;
DWORD dwBytesWrite = 0;
BYTE pBuffer[1024];
DWORD nHeaderLen = 22;
dwBytesRead = file_inp.GetPosition();
file_inp.ReadFile(pBuffer, 1024);
dwBytesRead = file_inp.GetPosition() - dwBytesRead;
while( 0 != dwBytesRead )
dwBytesRead = file_inp.GetPosition();
file_inp.ReadFile(pBuffer, 1024);
dwBytesRead = file_inp.GetPosition() - dwBytesRead;
while( 0 != dwBytesRead )
{
if( nHeaderLen > 0 )
{
if( nHeaderLen > 0 )
if(dwBytesRead > nHeaderLen )
{
if(dwBytesRead > nHeaderLen )
{
file_out.WriteFile(pBuffer + nHeaderLen, dwBytesRead - nHeaderLen);
nHeaderLen = 0;
}
else
nHeaderLen -= dwBytesRead;
file_out.WriteFile(pBuffer + nHeaderLen, dwBytesRead - nHeaderLen);
nHeaderLen = 0;
}
else
file_out.WriteFile( pBuffer, dwBytesRead);
dwBytesRead = file_inp.GetPosition();
file_inp.ReadFile(pBuffer, 1024);
dwBytesRead = file_inp.GetPosition() - dwBytesRead;
nHeaderLen -= dwBytesRead;
}
file_inp.CloseFile();
file_out.CloseFile();
else
file_out.WriteFile( pBuffer, dwBytesRead);
pOutput.eDataType = RtfPicture::dt_wmf;
//Запоминаем имя
pOutput.m_sPicFilename = sTargetFile;
pOutput.m_bIsCopy = true;
dwBytesRead = file_inp.GetPosition();
file_inp.ReadFile(pBuffer, 1024);
dwBytesRead = file_inp.GetPosition() - dwBytesRead;
}
else
file_inp.CloseFile();
file_out.CloseFile();
pOutput.eDataType = RtfPicture::dt_wmf;
//Запоминаем имя
pOutput.m_sPicFilename = sTargetFile;
pOutput.m_bIsCopy = true;
}
else
{
if (pOutput.eDataType == RtfPicture::dt_emf || pOutput.eDataType == RtfPicture::dt_wmf)
{
typedef enum {dt_none, dt_png, dt_jpg, dt_emf, dt_wmf, dt_apm}DataType;
int cxFormats [6] = {0, 4, 3, 10, 10, 10};
MetaFile::CMetaFile meta(NULL);
if (meta.LoadFromFile(sPath.c_str()))
{
double dX, dY, dW, dH;
meta.GetBounds(&dX, &dY, &dW, &dH);
meta.Close();
pOutput.m_nWidthGoal = dW * 15; //pixels to twip
pOutput.m_nHeightGoal = dH * 15; //pixels to twip;
}
//Запоминаем только имя
pOutput.m_sPicFilename = sPath;
pOutput.m_bIsCopy = false; //не удалять
}
else
{//png, jpeg
CBgraFrame image;
if (image.OpenFile(sPath, cxFormats[pOutput.eDataType]) == FALSE ) return false;
if (image.OpenFile(sPath, 0) == FALSE ) return false;
//правильно выставляем размеры
pOutput.m_nWidthGoal = image.get_Width() * 15; //pixels to twip
pOutput.m_nHeightGoal = image.get_Height() * 15; //pixels to twip;
pOutput.m_nWidthGoal = image.get_Width() * 15; //pixels to twip
pOutput.m_nHeightGoal = image.get_Height() * 15; //pixels to twip;
//Запоминаем только имя
pOutput.m_sPicFilename = sPath;
......
......@@ -39,7 +39,7 @@
#include "../../../../Common/DocxFormat/Source/DocxFormat/Logic/Vml.h"
#include "../../../../Common/DocxFormat/Source/DocxFormat/Logic/Shape.h"
bool ParseStyle(RtfShapePtr pShape, SimpleTypes::Vml::CCssProperty* prop);
bool ParseVmlStyle(RtfShapePtr pShape, SimpleTypes::Vml::CCssProperty* prop);
class OOXShapeReader
{
......@@ -88,11 +88,11 @@ private:
OOX::Logic::CShape *m_ooxShape;
bool ParseStyles(RtfShapePtr pShape, std::vector<SimpleTypes::Vml::CCssPropertyPtr> & props)
bool ParseVmlStyles(RtfShapePtr pShape, std::vector<SimpleTypes::Vml::CCssPropertyPtr> & props)
{
for (size_t i=0; i< props.size(); i++)
{
ParseStyle( pShape, props[i].get());
ParseVmlStyle( pShape, props[i].get());
}
return true;
}
......@@ -115,11 +115,11 @@ public:
m_vmlGroup = NULL;
m_ooxGroup = ooxGroup;
}
bool ParseStyles(RtfShapePtr pGroupShape, std::vector<SimpleTypes::Vml::CCssPropertyPtr> & props)
bool ParseVmlStyles(RtfShapePtr pGroupShape, std::vector<SimpleTypes::Vml::CCssPropertyPtr> & props)
{
for (size_t i = 0; i < props.size(); i++)
{
ParseStyle( pGroupShape, props[i].get());
ParseVmlStyle( pGroupShape, props[i].get());
}
return true;
}
......
......@@ -81,13 +81,9 @@ std::wstring RtfPicture::RenderToRtf(RenderParameter oRenderParameter)
std::wstring sResult = L"{\\pict";
//if(-1 != m_nShapeId)
//{
// sResult.AppendFormat(L"{\\*\\picprop\\shplid%d", m_nShapeId);
// sResult += m_oShapeProp.RenderToRtf( oRenderParameter ) + L"}";
//}
//else
// sResult.AppendFormat(L"{\\*\\picprop" + m_oShapeProp.RenderToRtf( oRenderParameter ) + L"}";
if (!dump_shape_properties.empty())
sResult += L"{\\*\\picprop" + dump_shape_properties + L"}";
RENDER_RTF_INT( (int)m_dScaleX, sResult, L"picscalex" )
RENDER_RTF_INT( (int)m_dScaleY, sResult, L"picscaley" )
RENDER_RTF_INT( m_nCropL, sResult, L"piccropl" )
......
......@@ -57,10 +57,12 @@ public:
int m_nCropR;
int m_nCropB;
bool m_bIsCopy; // true - надо удалять m_sPicFilename, false - не надо удалять
std::wstring m_sPicFilename; //всегда содержит имя картинки, тип которой поддерживает rtf
bool m_bIsCopy; // true - надо удалять m_sPicFilename, false - не надо удалять
std::wstring m_sPicFilename; //всегда содержит имя картинки, тип которой поддерживает rtf
std::vector<std::wstring> m_aTempFiles;
std::wstring dump_shape_properties;
RtfPicture()
{
......
......@@ -131,9 +131,9 @@ void RtfShape::SetDefault()
DEFAULT_PROPERTY( m_nRelZOrder )
//Rehydration
m_sMetroBlob = L"";
m_sMetroBlobRels = L"";
m_sMetroBlobData = L"";
m_sMetroBlob.clear();
m_sMetroBlobRels.clear();
m_sMetroBlobData.clear();
//Connectors
DEFAULT_PROPERTY( m_nConnectionType )
DEFAULT_PROPERTY( m_nConnectorStyle )
......@@ -171,6 +171,9 @@ void RtfShape::SetDefault()
DEFAULT_PROPERTY( m_bGtextFStretch )
DEFAULT_PROPERTY( m_bGtextFShrinkFit )
DEFAULT_PROPERTY( m_bGtextFBestFit )
DEFAULT_PROPERTY( m_bIsSignatureLine);
DEFAULT_PROPERTY( m_bSigSetupAllowComments);
m_aTextItems = TextItemContainerPtr();
m_oPicture = RtfPicturePtr();
......@@ -233,7 +236,11 @@ std::wstring RtfShape::RenderToRtf(RenderParameter oRenderParameter)
else
{
sResult += L"{\\*\\shppict";
m_oPicture->dump_shape_properties = RenderToRtfShapeProperty( oRenderParameter );
sResult += m_oPicture->RenderToRtf( oRenderParameter );
sResult += L"}";
sResult += L"{\\nonshppict";
sResult += m_oPicture->GenerateWMF( oRenderParameter );
......@@ -610,7 +617,42 @@ std::wstring RtfShape::RenderToRtfShapeProperty(RenderParameter oRenderParameter
RENDER_RTF_SHAPE_PROP(L"gtextFShrinkFit", sResult, m_bGtextFShrinkFit);
RENDER_RTF_SHAPE_PROP(L"gtextFBestFit", sResult, m_bGtextFBestFit);
}
if ( PROP_DEF != m_bIsSignatureLine)
{
RENDER_RTF_SHAPE_PROP(L"fIsSignatureLine", sResult, m_bIsSignatureLine);
RENDER_RTF_SHAPE_PROP(L"fSigSetupAllowComments", sResult, m_bSigSetupAllowComments);
if( !m_sSigSetupId.empty() )
{
sResult += L"{\\sp{\\sn wzSigSetupId}{\\sv ";
sResult += RtfChar::renderRtfText(m_sSigSetupId, oRenderParameter.poDocument, 0);
sResult += L"}}";
}
if( !m_sSigSetupProvId.empty() )
{
sResult += L"{\\sp{\\sn wzSigSetupProvId}{\\sv ";
sResult += RtfChar::renderRtfText(m_sSigSetupProvId, oRenderParameter.poDocument, 0);
sResult += L"}}";
}
if( !m_sSigSetupSuggSigner.empty() )
{
sResult += L"{\\sp{\\sn wzSigSetupSuggSigner}{\\sv ";
sResult += RtfChar::renderRtfText(m_sSigSetupSuggSigner, oRenderParameter.poDocument, 0);
sResult += L"}}";
}
if( !m_sSigSetupSuggSigner2.empty() )
{
sResult += L"{\\sp{\\sn wzSigSetupSuggSigner2}{\\sv ";
sResult += RtfChar::renderRtfText(m_sSigSetupSuggSigner2, oRenderParameter.poDocument, 0);
sResult += L"}}";
}
if( !m_sSigSetupSuggSignerEmail.empty() )
{
sResult += L"{\\sp{\\sn wzSigSetupSuggSignerEmail}{\\sv ";
sResult += RtfChar::renderRtfText(m_sSigSetupSuggSignerEmail, oRenderParameter.poDocument, 0);
sResult += L"}}";
}
}
return sResult;
}
std::wstring RtfShape::RenderToOOX(RenderParameter oRenderParameter)
......@@ -1346,6 +1388,31 @@ std::wstring RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
sResult += L" string=\"" + XmlUtils::EncodeXmlString(m_sGtextUNICODE) + L"\"";
sResult += L"/>";
}
if ( PROP_DEF != m_bIsSignatureLine)
{
sResult += L"<o:signatureline v:ext=\"edit\"";
if (!m_sSigSetupId.empty())
sResult += L" id=\"" + m_sSigSetupId + L"\"";
if (!m_sSigSetupProvId.empty())
sResult += L" provid=\"" + m_sSigSetupProvId + L"\"";
if (!m_sSigSetupSuggSigner.empty())
sResult += L" o:suggestedsigner=\"" + m_sSigSetupSuggSigner + L"\"";
if (!m_sSigSetupSuggSigner2.empty())
sResult += L" o:suggestedsigner2=\"" + m_sSigSetupSuggSigner2 + L"\"";
if (!m_sSigSetupSuggSignerEmail.empty())
sResult += L" o:suggestedsigneremail=\"" + m_sSigSetupSuggSignerEmail + L"\"";
if (m_bSigSetupAllowComments == 1)
sResult += L" allowcomments=\"t\"";
sResult += L" issignatureline=\"t\"/>";
}
return sResult;
}
std::wstring RtfShape::RenderToOOXEnd(RenderParameter oRenderParameter)
......
......@@ -202,6 +202,14 @@ public:
int m_bGtextFShrinkFit;
int m_bGtextFBestFit;
int m_bIsSignatureLine;
int m_bSigSetupAllowComments;
std::wstring m_sSigSetupId;
std::wstring m_sSigSetupProvId;
std::wstring m_sSigSetupSuggSigner;
std::wstring m_sSigSetupSuggSigner2;
std::wstring m_sSigSetupSuggSignerEmail;
RtfCharProperty m_oCharProperty; // тут могут быть track changes ....
//pWrapPolygonVertices Points of the text wrap polygon.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment