Commit 506680d3 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

DocFormatReader - конвертация embedded математических формул формата OOX

parent 4e193650
......@@ -571,22 +571,15 @@ namespace DocFileFormat
RevisionData oData = RevisionData(chpxPic);
/// <w:rPr>
CharacterPropertiesMapping* rPr = new CharacterPropertiesMapping(m_pXmlWriter, m_document, &oData, _lastValidPapx, false);
if(rPr)
{
chpxPic->Convert(rPr);
RELEASEOBJECT(rPr);
}
m_pXmlWriter->WriteNodeBegin (_T( "w:object" ), TRUE);
XmlUtils::CXmlWriter OleWriter;
OleWriter.WriteNodeBegin (_T( "w:object" ), TRUE);
//append the origin attributes
m_pXmlWriter->WriteAttribute( _T( "w:dxaOrig" ), FormatUtils::IntToWideString( ( pic.dxaGoal + pic.dxaOrigin ) ).c_str() );
m_pXmlWriter->WriteAttribute( _T( "w:dyaOrig" ), FormatUtils::IntToWideString( ( pic.dyaGoal + pic.dyaOrigin ) ).c_str() );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
OleWriter.WriteAttribute( _T( "w:dxaOrig" ), FormatUtils::IntToWideString( ( pic.dxaGoal + pic.dxaOrigin ) ).c_str() );
OleWriter.WriteAttribute( _T( "w:dyaOrig" ), FormatUtils::IntToWideString( ( pic.dyaGoal + pic.dyaOrigin ) ).c_str() );
OleWriter.WriteNodeEnd( _T( "" ), TRUE, FALSE );
VMLPictureMapping oVmlMapper (m_context, m_pXmlWriter, true, _caller);
VMLPictureMapping oVmlMapper (m_context, &OleWriter, true, _caller);
pic.Convert(&oVmlMapper);
RELEASEOBJECT(chpxs);
......@@ -597,9 +590,9 @@ namespace DocFileFormat
CharacterPropertyExceptions* chpxSep = chpxs->front();
OleObject ole ( chpxSep, m_document->GetStorage() );
OleObjectMapping oleObjectMapping( m_pXmlWriter, m_context, &pic, _caller, oVmlMapper.GetShapeId() );
OleObjectMapping oleObjectMapping( &OleWriter, m_context, &pic, _caller, oVmlMapper.GetShapeId() );
if (oVmlMapper.m_isEquation || oVmlMapper.m_isEmbedded)
if (oVmlMapper.m_isEmbedded)
{
ole.isEquation = oVmlMapper.m_isEquation;
ole.isEmbedded = oVmlMapper.m_isEmbedded;
......@@ -610,7 +603,22 @@ namespace DocFileFormat
RELEASEOBJECT( chpxs );
}
m_pXmlWriter->WriteNodeEnd( _T( "w:object" ) );
OleWriter.WriteNodeEnd( _T( "w:object" ) );
if (!oVmlMapper.m_isEmbedded && oVmlMapper.m_isEquation)
{
m_pXmlWriter->WriteString(oVmlMapper.m_equationXml.c_str());
}
else
{
CharacterPropertiesMapping* rPr = new CharacterPropertiesMapping(m_pXmlWriter, m_document, &oData, _lastValidPapx, false);
if(rPr)
{
chpxPic->Convert(rPr);
RELEASEOBJECT(rPr);
}
m_pXmlWriter->WriteString(OleWriter.GetXmlString());
}
}
if (search(f.begin(), f.end(), embed.begin(), embed.end()) != f.end() )
......@@ -713,7 +721,7 @@ namespace DocFileFormat
VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller);
oPicture.Convert (&oVmlMapper);
if (oVmlMapper.m_isEquation || oVmlMapper.m_isEmbedded)
if (oVmlMapper.m_isEmbedded)
{
OleObject ole ( chpx, m_document->GetStorage() );
OleObjectMapping oleObjectMapping( m_pXmlWriter, m_context, &oPicture, _caller, oVmlMapper.GetShapeId() );
......
......@@ -31,10 +31,10 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute(_T("xmlns:o"), OpenXmlNamespaces::Office );
m_pXmlWriter->WriteAttribute(_T("xmlns:w10"), OpenXmlNamespaces::OfficeWord );
m_pXmlWriter->WriteAttribute(_T("xmlns:r"), OpenXmlNamespaces::Relationships );
m_pXmlWriter->WriteAttribute(_T("xmlns:m"), _T("http://schemas.openxmlformats.org/officeDocument/2006/math"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wpc"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:mc"), _T("http://schemas.openxmlformats.org/markup-compatibility/2006"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:m"), _T("http://schemas.openxmlformats.org/officeDocument/2006/math"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wp14"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wp"), _T("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:w14"), _T("http://schemas.microsoft.com/office/word/2010/wordml"));
......
......@@ -23,10 +23,10 @@ namespace DocFileFormat
if ( ole != NULL )
{
if (ole->isEquation || ole->isEmbedded)
if (ole->isEmbedded)
{
if (ole->isEquation) ole->ClipboardFormat = L"Equation";
if (ole->isEmbedded) ole->ClipboardFormat = L"MSWordDocx";
else ole->ClipboardFormat = L"MSWordDocx";
ole->Program = L"Word.Document";
}
......@@ -46,7 +46,8 @@ namespace DocFileFormat
else
{
int relID = -1;
if (ole->isEquation || ole->isEmbedded)
if (ole->isEmbedded)
relID = m_context->_docx->RegisterPackage(_caller, ole->ClipboardFormat);
else
relID = m_context->_docx->RegisterOLEObject(_caller, ole->ClipboardFormat);
......
......@@ -5,10 +5,65 @@
#include "OfficeDrawing/GeometryTextBooleanProperties.h"
#include "../../DesktopEditor/common/String.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Document.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Document.h"
namespace DocFileFormat
{
bool ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString)
{
newXmlString.clear();
std::wstring sTempXmlFile = FileSystem::Directory::CreateTempFileWithUniqueName(
FileSystem::Directory::GetTempPathW(), L"emb");
sTempXmlFile += L".xml";
NSFile::CFileBinary file;
file.CreateFileW(sTempXmlFile);
file.WriteFile((BYTE*)xmlString.c_str(), xmlString.size());
file.CloseFile();
OOX::CPath path(sTempXmlFile.c_str());
OOX::CDocument docEmbedded(path, path);
bool res = false;
for (int i = 0 ; i < docEmbedded.m_arrItems.size(); i++)
{
if (docEmbedded.m_arrItems[i]->getType() == OOX::et_w_p)
{
OOX::Logic::CParagraph *paragraph = dynamic_cast<OOX::Logic::CParagraph *>(docEmbedded.m_arrItems[i]);
for (int j = 0; (paragraph) && (j < paragraph->m_arrItems.size()); j++)
{
if (paragraph->m_arrItems[j]->getType() == OOX::et_m_oMath)
{
res = true;
newXmlString = paragraph->m_arrItems[j]->toXML().GetBuffer();
break;
}
else if (paragraph->m_arrItems[j]->getType() == OOX::et_m_oMathPara)
{
OOX::Logic::COMathPara *mathPara = dynamic_cast<OOX::Logic::COMathPara *>(paragraph->m_arrItems[j]);
for (int k = 0; (mathPara) && (k < mathPara->m_arrItems.size()); k++)
{
if (mathPara->m_arrItems[k]->getType() == OOX::et_m_oMath)
{
res = true;
newXmlString = mathPara->m_arrItems[k]->toXML().GetBuffer();
break;
}
}
}
if (res) break;
}
if (res) break;
}
}
return res;
}
//---------------------------------------------------------------
static int count_vml_objects = 0;
void VMLPictureMapping::appendStyleProperty(std::wstring* b, const std::wstring& propName, const std::wstring& propValue) const
{
......@@ -42,10 +97,7 @@ namespace DocFileFormat
{
RELEASEOBJECT(m_imageData);
}
}
namespace DocFileFormat
{
void VMLPictureMapping::Apply( IVisitable* visited )
{
PictureDescriptor* pict = static_cast<PictureDescriptor*>(visited);
......@@ -97,7 +149,14 @@ namespace DocFileFormat
case wzEquationXML:
{
m_isEquation = true;
m_isEmbedded = true;
m_embeddedData = std::string((char*)iter->opComplex, iter->op);
if (ParseEmbeddedEquation( m_embeddedData, m_equationXml))
{
m_isEmbedded = false;
}
}break;
case metroBlob:
{
......
......@@ -13,6 +13,8 @@
namespace DocFileFormat
{
bool ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString );
class VMLPictureMapping: public PropertiesMapping, public IMapping
{
public:
......@@ -39,6 +41,7 @@ namespace DocFileFormat
bool m_isEquation;
bool m_isEmbedded;
std::string m_embeddedData;
std::wstring m_equationXml;
private:
ConversionContext* m_ctx;
......
......@@ -378,6 +378,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp"
>
</File>
</Files>
<Globals>
</Globals>
......
......@@ -636,6 +636,18 @@
RelativePath=".\ASCOfficeDocFile.cpp"
>
</File>
<File
RelativePath="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\stdafx.cpp"
>
......
......@@ -4,6 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 9.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASCOfficeDocFile", "ASCOfficeDocFile2005.vcproj", "{DA13D6D4-39B5-49DB-B5D7-D1AFDBB7C320}"
ProjectSection(ProjectDependencies) = postProject
{C5371405-338F-4B70-83BD-2A5CDF64F383} = {C5371405-338F-4B70-83BD-2A5CDF64F383}
{21663823-DE45-479B-91D0-B4FEF4916EF0} = {21663823-DE45-479B-91D0-B4FEF4916EF0}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocFormatLib", "..\DocFormatLib\Win32\DocFormatLib.vcproj", "{C5371405-338F-4B70-83BD-2A5CDF64F383}"
......@@ -24,6 +25,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml2", "..\..\Common\DocxFormat\Source\XML\libxml2\win_build\libxml2.vcproj", "{21663823-DE45-479B-91D0-B4FEF4916EF0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocxFormat", "..\..\Common\DocxFormat\Projects\DocxFormat2005.vcproj", "{A100103A-353E-45E8-A9B8-90B87CC5C0B0}"
ProjectSection(ProjectDependencies) = postProject
{21663823-DE45-479B-91D0-B4FEF4916EF0} = {21663823-DE45-479B-91D0-B4FEF4916EF0}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocFormatTest", "..\DocFormatTest\DocFormatTest.vcproj", "{0F49D5D1-A8D3-4F97-8BC1-E2F65BB00C10}"
ProjectSection(ProjectDependencies) = postProject
......
......@@ -3026,7 +3026,14 @@ namespace SimpleTypes
{
CString sResult;
sResult.Format( _T("%fpt"), m_dValue);
if (m_bUnit)
{
sResult.Format( _T("%fpt"), m_dValue);
}
else
{
sResult.Format( _T("%d"), (int)(m_dValue * 2));
}
return sResult;
}
......
......@@ -14,15 +14,17 @@ namespace OOX
public:
CMathArgNodes()
{
eType = et_Unknown;
eType = et_Unknown;
}
CMathArgNodes(XmlUtils::CXmlNode &oNode)
{
fromXML( oNode );
sNodeName = GetMathNodeName(getType());
}
CMathArgNodes(XmlUtils::CXmlLiteReader& oReader)
{
fromXML( oReader );
sNodeName = GetMathNodeName(getType());
}
virtual ~CMathArgNodes()
{
......@@ -51,6 +53,8 @@ namespace OOX
virtual CString toXML() const
{
if (sNodeName.IsEmpty()) return L"";
CString sResult = _T("<") + sNodeName + _T(">");
for ( unsigned int nIndex = 0; nIndex < m_arrItems.size(); nIndex++ )
......@@ -61,7 +65,7 @@ namespace OOX
}
}
sResult = _T("</") + sNodeName + _T(">");
sResult += _T("</") + sNodeName + _T(">");
return sResult;
}
......@@ -71,14 +75,46 @@ namespace OOX
return eType;
}
private:
EElementType eType;
CString sNodeName;
EElementType eType;
public:
CString sNodeName;
CString GetMathNodeName(const EElementType & enumType) const
{//todooo - MathBottomNodes
switch(enumType)
{
case OOX::et_m_deg: return L"m:deg";
case OOX::et_m_den: return L"m:den";
case OOX::et_m_e: return L"m:e";
case OOX::et_m_fName: return L"m:fName";
case OOX::et_m_lim: return L"m:lim";
case OOX::et_m_num: return L"m:num";
case OOX::et_m_oMath: return L"m:oMath";
case OOX::et_m_sub: return L"m:sub";
case OOX::et_m_sup: return L"m:sup";
}
return L"";
}
// Childs
};
template <EElementType EnumType = OOX::et_Unknown>
class CMathArgNodesEx : public CMathArgNodes
{
public:
CMathArgNodesEx(XmlUtils::CXmlNode& oNode)
{
fromXML( oNode );
}
CMathArgNodesEx(XmlUtils::CXmlLiteReader& oReader)
{
fromXML( oReader );
}
virtual EElementType getType() const
{
return EnumType;
}
};
}//namespace Logic
}//namespace OOX
\ No newline at end of file
......@@ -179,6 +179,8 @@ namespace OOX
}
virtual CString toXML() const
{
if (sNodeName.IsEmpty()) return L"";
CString sResult = _T("<") + sNodeName + _T(" m:val=\"");
sResult += m_val->ToString();
sResult += _T("\" />");
......@@ -191,7 +193,6 @@ namespace OOX
}
private:
EElementType eType;
CString sNodeName;
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
......@@ -200,8 +201,79 @@ namespace OOX
WritingElement_ReadAttributes_ReadSingle( oReader, _T("m:val"), m_val )
WritingElement_ReadAttributes_End( oReader )
}
public:
CString sNodeName;
CString GetMathNodeName(const EElementType & enumType) const
{//todooo - MathArgNodes
switch(enumType)
{
case OOX::et_m_deg: return L"m:deg";
case OOX::et_m_aln: return L"m:aln";
case OOX::et_m_alnScr: return L"m:alnScr";
case OOX::et_m_argSz: return L"m:argSz";
case OOX::et_m_baseJc: return L"m:baseJc";
case OOX::et_m_begChr: return L"m:begChr";
case OOX::et_m_brkBin: return L"m:brkBin";
case OOX::et_m_brkBinSub: return L"m:brkBinSub";
case OOX::et_m_cGp: return L"m:cGp";
case OOX::et_m_cGpRule: return L"m:cGpRule";
case OOX::et_m_chr: return L"m:chr";
case OOX::et_m_count: return L"m:count";
case OOX::et_m_cSp: return L"m:cSp";
case OOX::et_m_defJc: return L"m:defJc";
case OOX::et_m_degHide: return L"m:degHide";
case OOX::et_m_diff: return L"m:diff";
case OOX::et_m_dispDef: return L"m:dispDef";
case OOX::et_m_endChr: return L"m:endChr";
case OOX::et_m_grow: return L"m:grow";
case OOX::et_m_hideBot: return L"m:hideBot";
case OOX::et_m_hideLeft: return L"m:hideLeft";
case OOX::et_m_hideRight: return L"m:hideRight";
case OOX::et_m_hideTop: return L"m:hideTop";
case OOX::et_m_interSp: return L"m:interSp";
case OOX::et_m_intLim: return L"m:intLim";
case OOX::et_m_intraSp: return L"m:intraSp";
case OOX::et_m_jc: return L"m:jc";
case OOX::et_m_limLoc: return L"m:limLoc";
case OOX::et_m_lit: return L"m:lit";
case OOX::et_m_lMargin: return L"m:lMargin";
case OOX::et_m_maxDist: return L"m:maxDist";
case OOX::et_m_mcJc: return L"m:mcJc";
case OOX::et_m_naryLim: return L"m:naryLim";
case OOX::et_m_noBreak: return L"m:noBreak";
case OOX::et_m_nor: return L"m:nor";
case OOX::et_m_objDist: return L"m:objDist";
case OOX::et_m_opEmu: return L"m:opEmu";
case OOX::et_m_plcHide: return L"m:plcHide";
case OOX::et_m_pos: return L"m:pos";
case OOX::et_m_postSp: return L"m:postSp";
case OOX::et_m_preSp: return L"m:preSp";
case OOX::et_m_rMargin: return L"m:rMargin";
case OOX::et_m_rSp: return L"m:rSp";
case OOX::et_m_rSpRule: return L"m:rSpRule";
case OOX::et_m_scr: return L"m:scr";
case OOX::et_m_sepChr: return L"m:sepChr";
case OOX::et_m_show: return L"m:show";
case OOX::et_m_shp: return L"m:shp";
case OOX::et_m_smallFrac: return L"m:smallFrac";
case OOX::et_m_strikeBLTR: return L"m:strikeBLTR";
case OOX::et_m_strikeH: return L"m:strikeH";
case OOX::et_m_strikeTLBR: return L"m:strikeTLBR";
case OOX::et_m_strikeV: return L"m:strikeV";
case OOX::et_m_sty: return L"m:sty";
case OOX::et_m_subHide: return L"m:subHide";
case OOX::et_m_supHide: return L"m:supHide";
case OOX::et_m_transp: return L"m:transp";
case OOX::et_m_type: return L"m:type";
case OOX::et_m_vertJc: return L"m:vertJc";
case OOX::et_m_wrapIndent: return L"m:wrapIndent";
case OOX::et_m_wrapRight: return L"m:wrapRight";
case OOX::et_m_zeroAsc: return L"m:zeroAsc";
case OOX::et_m_zeroDesc: return L"m:zeroDesc";
case OOX::et_m_zeroWid: return L"m:zeroWid";
}
return L"";
}
nullable<TMathBottomType> m_val;
};
......@@ -213,10 +285,12 @@ namespace OOX
CMathBottomNodesEx(XmlUtils::CXmlNode& oNode)
{
fromXML( oNode );
sNodeName = GetMathNodeName(getType());
}
CMathBottomNodesEx(XmlUtils::CXmlLiteReader& oReader)
{
fromXML( oReader );
sNodeName = GetMathNodeName(getType());
}
virtual EElementType getType() const
{
......
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