Commit 08399f16 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

DocFormatReader - конвертация объекта автосодержание

parent ed5e68c9
......@@ -6,23 +6,25 @@ namespace DocFileFormat
CharacterPropertiesMapping::CharacterPropertiesMapping( XmlUtils::CXmlWriter* writer, WordDocument* doc, RevisionData* rev, ParagraphPropertyExceptions* currentPapx, bool styleChpx, bool isRunStyleNeeded)
: PropertiesMapping( writer ), _isRunStyleNeeded(isRunStyleNeeded), _isOwnRPr(true), _isRTL(false)
{
this->_doc = doc;
this->_rPr = new XMLTools::XMLElement<wchar_t>( _T( "w:rPr" ) );
this->_revisionData = rev;
this->_currentPapx = currentPapx;
this->_styleChpx = styleChpx;
this->_currentIstd = USHRT_MAX;
_doc = doc;
_rPr = new XMLTools::XMLElement<wchar_t>( _T( "w:rPr" ) );
_revisionData = rev;
_currentPapx = currentPapx;
_styleChpx = styleChpx;
_currentIstd = USHRT_MAX;
_webHidden = false;
}
CharacterPropertiesMapping::CharacterPropertiesMapping( XMLTools::XMLElement<wchar_t>* rPr, WordDocument* doc, RevisionData* rev, ParagraphPropertyExceptions* currentPapx, bool styleChpx, bool isRunStyleNeeded )
: PropertiesMapping( NULL ), _isRunStyleNeeded(isRunStyleNeeded), _isOwnRPr(false), _isRTL(false)
{
this->_doc = doc;
this->_rPr = rPr;
this->_revisionData = rev;
this->_currentPapx = currentPapx;
this->_styleChpx = styleChpx;
this->_currentIstd = USHRT_MAX;
_doc = doc;
_rPr = rPr;
_revisionData = rev;
_currentPapx = currentPapx;
_styleChpx = styleChpx;
_currentIstd = USHRT_MAX;
_webHidden = false;
}
CharacterPropertiesMapping::~CharacterPropertiesMapping()
......@@ -89,6 +91,12 @@ namespace DocFileFormat
XMLTools::XMLAttribute<wchar_t> * colorVal = new XMLTools::XMLAttribute<wchar_t>( _T( "w:val" ) );
XMLTools::XMLElement<wchar_t> * lang = new XMLTools::XMLElement<wchar_t> ( _T( "w:lang" ) );
if (_webHidden)
{
XMLTools::XMLElement<wchar_t> * webHidden = new XMLTools::XMLElement<wchar_t> ( _T( "w:webHidden" ) );
parent->AppendChild( *webHidden );
RELEASEOBJECT( webHidden );
}
std::list<SinglePropertyModifier>::iterator end = sprms->end();
for (std::list<SinglePropertyModifier>::iterator iter = sprms->begin(); iter != end; ++iter)
{
......@@ -96,7 +104,7 @@ namespace DocFileFormat
{
case 0x4A30 : // style id
{
if (_isRunStyleNeeded)
if (_isRunStyleNeeded && !_webHidden)
{
_currentIstd = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize );
if (_currentIstd < this->_doc->Styles->Styles->size())
......
......@@ -29,6 +29,7 @@ namespace DocFileFormat
void Apply( IVisitable* chpx );
bool CheckIsSymbolFont();
bool _webHidden;
bool _isRTL;
private:
void convertSprms( list<SinglePropertyModifier>* sprms, XMLTools::XMLElement<wchar_t>* parent );
......@@ -42,6 +43,7 @@ namespace DocFileFormat
virtual void appendFlagElement( XMLTools::XMLElement<wchar_t>* node, const SinglePropertyModifier& sprm, const wchar_t* elementName, bool unique );
private:
XmlUtils::CXmlWriter pRunPr;
WordDocument* _doc;
XMLTools::XMLElement<wchar_t>* _rPr;
......@@ -49,7 +51,6 @@ namespace DocFileFormat
RevisionData* _revisionData;
bool _styleChpx;
XmlUtils::CXmlWriter pRunPr;
ParagraphPropertyExceptions* _currentPapx;
list<CharacterPropertyExceptions*> _hierarchy;
......
......@@ -17,6 +17,8 @@ namespace DocFileFormat
m_context = context;
m_bInternalXmlWriter = false;
_writeWebHidden = false;
_writeInstrText = false;
_isSectionPageBreak = 0;
}
......@@ -361,6 +363,8 @@ namespace DocFileFormat
CharacterPropertiesMapping* rPr = new CharacterPropertiesMapping(m_pXmlWriter, m_document, &rev, _lastValidPapx, false);
if (rPr)
{
rPr->_webHidden = _writeWebHidden;
chpx->Convert(rPr);
RELEASEOBJECT(rPr);
}
......@@ -412,31 +416,6 @@ namespace DocFileFormat
std::wstring textType = _T( "t" );
std::wstring text;
#ifdef _DEBUG
if (0)
if (chars)
{
//ATLTRACE (L"Run :");
for (size_t i = 0; i < chars->size(); ++i)
{
//ATLTRACE (L"0x%x ", chars->operator [](i));
}
//ATLTRACE (L"\n");
for ( list<SinglePropertyModifier>::iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); ++iter)
{
//if (sprmCPicLocation==iter->OpCode)
// ATLTRACE (L"SPRM : sprmCPicLocation, %d\n", FormatUtils::BytesToInt32(iter->Arguments, 0, iter->argumentsSize));
//else if (sprmCFSpec == iter->OpCode)
// ATLTRACE (L"SPRM : sprmCFSpec, %d\n", FormatUtils::BytesToInt32(iter->Arguments, 0, iter->argumentsSize));
//else if (sprmCRsidText == iter->OpCode)
// ATLTRACE (L"SPRM : sprmCRsidText, %d\n", FormatUtils::BytesToInt32(iter->Arguments, 0, iter->argumentsSize));
//else
// ATLTRACE (L"SPRM : %d, %d\n", iter->OpCode, FormatUtils::BytesToInt32(iter->Arguments, 0, iter->argumentsSize));
}
//ATLTRACE (L"\n");
}
#endif
if (writeDeletedText)
{
textType = std::wstring(_T("delText"));
......@@ -519,6 +498,10 @@ namespace DocFileFormat
std::wstring quote ( _T( " QUOTE" ) );
std::wstring chart ( _T( "Chart" ) );
std::wstring PBrush ( _T( " PBrush" ) );
std::wstring TOC ( _T( " TOC" ) );
std::wstring HYPERLINK ( _T( " HYPERLINK" ) );
std::wstring PAGEREF ( _T( " PAGEREF" ) );
if ( search( f.begin(), f.end(), form.begin(), form.end() ) != f.end() )
{
......@@ -539,9 +522,9 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "w:fldChar" ) );
this->_writeInstrText = true;
_writeInstrText = true;
this->_fldCharCounter++;
_fldCharCounter++;
}
else if (( search( f.begin(), f.end(), mergeformat.begin(), mergeformat.end()) != f.end()) ||
(( search( f.begin(), f.end(), excel.begin(), excel.end()) != f.end() ||
......@@ -559,9 +542,60 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "w:fldChar" ) );
this->_writeInstrText = true;
_writeInstrText = true;
_fldCharCounter++;
}
else if ( search( f.begin(), f.end(), HYPERLINK.begin(), HYPERLINK.end()) != f.end() &&
search( f.begin(), f.end(), PAGEREF.begin(), PAGEREF.end()) != f.end())
{
int cpFieldSep2 = cpFieldStart, cpFieldSep1 = cpFieldStart;
std::vector<std::wstring> toc;
if (search( f.begin(), f.end(), TOC.begin(), TOC.end()) != f.end())
{
m_pXmlWriter->WriteNodeBegin( _T( "w:fldChar" ), TRUE );
m_pXmlWriter->WriteAttribute( _T( "w:fldCharType" ), _T( "begin" ) );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
_writeInstrText = true;
_fldCharCounter++;
}
else
{
while ( cpFieldSep2 < cpFieldEnd)
{
cpFieldSep2 = searchNextTextMark(m_document->Text, cpFieldSep1 + 1, TextMark::FieldSeparator);
std::wstring f1( ( m_document->Text->begin() + cpFieldSep1 ), ( m_document->Text->begin() + cpFieldSep2 + 1 ) );
toc.push_back(f1);
if (search( f1.begin(), f1.end(), PAGEREF.begin(), PAGEREF.end()) != f1.end())
{
int d = f1.find(PAGEREF);
_writeWebHidden = true;
std::wstring _writeTocLink =f1.substr(d + 9);
d = _writeTocLink.find(_T(" "));
_writeTocLink = _writeTocLink.substr(0, d);
_writeAfterRun = std::wstring (_T("<w:hyperlink w:anchor = \""));
_writeAfterRun += _writeTocLink;
_writeAfterRun += std::wstring (_T("\" w:history=\"1\">"));
//if (_writeInstrText == true)
//{
// m_pXmlWriter->WriteNodeBegin( _T( "w:fldChar" ), TRUE );
// m_pXmlWriter->WriteAttribute( _T( "w:fldCharType" ), _T( "separate" ) );
// m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
//}
_writeInstrText = false;
this->_fldCharCounter++;
//cp = cpFieldSep1;
}
cpFieldSep1 = cpFieldSep2;
}
_skipRuns = 5;
}
}
else if ( search( f.begin(), f.end(), embed.begin(), embed.end()) != f.end()
|| search( f.begin(), f.end(), link.begin(), link.end() ) != f.end()
......@@ -634,9 +668,9 @@ namespace DocFileFormat
}
if (search(f.begin(), f.end(), embed.begin(), embed.end()) != f.end() )
this->_skipRuns = 3;
_skipRuns = 3;
else
this->_skipRuns = 5;
_skipRuns = 5;
}
else
{
......@@ -644,9 +678,8 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute( _T( "w:fldCharType" ), _T( "begin" ) );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
this->_writeInstrText = true;
this->_fldCharCounter++;
_writeInstrText = true;
_fldCharCounter++;
}
}
else if (TextMark::FieldSeparator == c)
......@@ -668,12 +701,17 @@ namespace DocFileFormat
m_pXmlWriter->WriteString( elem.GetXMLString().c_str() );
this->_fldCharCounter--;
_fldCharCounter--;
}
if (_writeWebHidden)
{
_writeAfterRun = std::wstring (_T("</w:hyperlink>"));
}
_writeWebHidden = false;
if ( this->_fldCharCounter == 0 )
if ( _fldCharCounter == 0 )
{
this->_writeInstrText = false;
_writeInstrText = false;
}
}
else if ((TextMark::Symbol == c) && fSpec)
......@@ -784,7 +822,7 @@ namespace DocFileFormat
if (typeid(*this) != typeid(CommentsMapping))
{
m_pXmlWriter->WriteNodeBegin( _T( "w:commentReference" ), TRUE );
m_pXmlWriter->WriteAttribute( _T( "w:id" ), FormatUtils::IntToWideString( this->_commentNr ).c_str() );
m_pXmlWriter->WriteAttribute( _T( "w:id" ), FormatUtils::IntToWideString( _commentNr ).c_str() );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
}
else
......@@ -793,7 +831,7 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
}
this->_commentNr++;
_commentNr++;
}
else if (!FormatUtils::IsControlSymbol(c) && ((int)c != 0xFFFF))
{
......@@ -812,11 +850,6 @@ namespace DocFileFormat
m_pXmlWriter->WriteString(text.c_str());
writeTextEnd(textType);
#ifdef _DEBUG
//OutputDebugStringW ( text.c_str() );
//OutputDebugStringW ( _T("\n") );
#endif
}
}
......@@ -824,9 +857,11 @@ namespace DocFileFormat
{
if ( !text.empty() )
{
//bool preserve_space = (text.find(_T("\x20")) != text.npos) ? true : false;
bool preserve_space = true;//(text.find(_T("\x20")) != text.npos) ? true : false;
if (textType == _T("instrText"))
preserve_space = false;
writeTextStart( textType, true /*preserve_space*/ );
writeTextStart( textType, preserve_space );
m_pXmlWriter->WriteString( text.c_str() );
......
......@@ -99,9 +99,11 @@ namespace DocFileFormat
WordDocument* m_document;
ConversionContext* m_context;
IMapping* _caller;
ParagraphPropertyExceptions* _lastValidPapx;
SectionPropertyExceptions* _lastValidSepx;
int _skipRuns;
int _sectionNr;
int _footnoteNr;
......@@ -109,8 +111,8 @@ namespace DocFileFormat
int _commentNr;
int _isSectionPageBreak; //0 - not set, 1 -page break, 2 - continues
bool _writeInstrText;
bool _writeWebHidden;
unsigned int _fldCharCounter;
IMapping* _caller;
std::wstring _writeAfterRun;
};
}
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