Commit 3dd4dda2 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormatReader -ole ...

parent 24dc3554
......@@ -667,31 +667,38 @@ namespace DocFileFormat
chpxObj->Convert(rPr);
RELEASEOBJECT(rPr);
}
XMLTools::CStringXmlWriter OleWriter;
VMLPictureMapping oVmlMapper (m_context, &OleWriter, true, _caller);
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->bOlderVersion)
{
OleObject ole ( chpxObj, m_document->GetStorage(), m_document->bOlderVersion);
OleWriter.WriteNodeBegin (_T( "w:object" ), true);
OleWriter.WriteAttribute( _T( "w:dxaOrig" ), FormatUtils::IntToWideString( ( ole.pictureDesciptor.dxaGoal + ole.pictureDesciptor.dxaOrigin ) ).c_str() );
OleWriter.WriteAttribute( _T( "w:dyaOrig" ), FormatUtils::IntToWideString( ( ole.pictureDesciptor.dyaGoal + ole.pictureDesciptor.dyaOrigin ) ).c_str() );
OleWriter.WriteNodeEnd( _T( "" ), true, false );
oleWriter.WriteNodeBegin (_T( "w:object" ), true);
oleWriter.WriteAttribute( _T( "w:dxaOrig" ), FormatUtils::IntToWideString( ( ole.pictureDesciptor.dxaGoal + ole.pictureDesciptor.dxaOrigin ) ).c_str() );
oleWriter.WriteAttribute( _T( "w:dyaOrig" ), FormatUtils::IntToWideString( ( ole.pictureDesciptor.dyaGoal + ole.pictureDesciptor.dyaOrigin ) ).c_str() );
oleWriter.WriteNodeEnd( _T( "" ), true, false );
ole.pictureDesciptor.Convert(&oVmlMapper);
OleObjectMapping oleObjectMapping( &OleWriter, m_context, &ole.pictureDesciptor, _caller, oVmlMapper.GetShapeId() );
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->bOlderVersion);
OleWriter.WriteNodeBegin (_T( "w:object" ), true);
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 );
oleWriter.WriteNodeBegin (_T( "w:object" ), true);
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 );
pic.Convert(&oVmlMapper);
RELEASEOBJECT(chpxs);
......@@ -705,7 +712,7 @@ namespace DocFileFormat
CharacterPropertyExceptions* chpxSep = chpxs->front();
OleObject ole ( chpxSep, m_document->GetStorage(), m_document->bOlderVersion);
OleObjectMapping oleObjectMapping( &OleWriter, m_context, &pic, _caller, oVmlMapper.GetShapeId() );
OleObjectMapping oleObjectMapping( &oleObjectWriter, m_context, &pic, _caller, oVmlMapper.m_shapeId );
if (oVmlMapper.m_isEmbedded)
{
......@@ -714,11 +721,14 @@ namespace DocFileFormat
ole.emeddedData = oVmlMapper.m_embeddedData;
}
ole.Convert( &oleObjectMapping );
_lastOLEObject = oleObjectWriter.GetXmlString();
RELEASEOBJECT( chpxs );
}
}
OleWriter.WriteNodeEnd( _T( "w:object" ) );
oleWriter.WriteString( _lastOLEObject );
oleWriter.WriteNodeEnd( _T( "w:object" ) );
if (!oVmlMapper.m_isEmbedded && oVmlMapper.m_isEquation)
{
......@@ -728,7 +738,7 @@ namespace DocFileFormat
}
else
{
m_pXmlWriter->WriteString(OleWriter.GetXmlString());
m_pXmlWriter->WriteString(oleWriter.GetXmlString());
}
}
......@@ -808,8 +818,6 @@ namespace DocFileFormat
if (pShape)
{
bool bOLE = pShape->isOLE();
VMLShapeMapping oVmlWriter (m_context, m_pXmlWriter, pSpa, &pictDiscr, _caller);
m_pXmlWriter->WriteNodeBegin (L"w:pict");
......@@ -866,7 +874,7 @@ namespace DocFileFormat
if (oVmlMapper.m_isEmbedded)
{
OleObject ole ( chpx, m_document->GetStorage(), m_document->bOlderVersion);
OleObjectMapping oleObjectMapping( &pictWriter, m_context, &oPicture, _caller, oVmlMapper.GetShapeId() );
OleObjectMapping oleObjectMapping( &pictWriter, m_context, &oPicture, _caller, oVmlMapper.m_shapeId );
ole.isEquation = oVmlMapper.m_isEquation;
ole.isEmbedded = oVmlMapper.m_isEmbedded;
......
......@@ -70,68 +70,70 @@ namespace DocFileFormat
public:
DocumentMapping(ConversionContext* context, IMapping* caller);
DocumentMapping(ConversionContext* context, XMLTools::CStringXmlWriter* writer, IMapping* caller);
virtual ~DocumentMapping();
virtual void Apply( IVisitable* visited ) = 0;
//--------------------------------- 4571833.doc
std::wstring m_shapeIdOwner;
std::wstring getOLEObject() { return _lastOLEObject; }
protected:
/// Looks into the section table to find out if this CP is the current of a section
// Looks into the section table to find out if this CP is the current of a section
int getCurrentSection(int cp);
/// Looks into the section table to find out if this CP is the end of a section
// Looks into the section table to find out if this CP is the end of a section
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
// 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 );
/// Writes a Paragraph that starts at the given cpStart and
/// ends at the given 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
// Writes a Paragraph RSID
void writeParagraphRsid( const ParagraphPropertyExceptions* papx );
/// Writes a run with the given characters and CHPX
// 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
// Writes the given text to the document
int writeText( std::vector<wchar_t>* chars, int initialCp, CharacterPropertyExceptions* chpx, bool writeDeletedText );
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 );
/// Searches for bookmarks in the list of characters.
// Searches for bookmarks in the list of characters.
std::vector<int> searchBookmarks( std::vector<wchar_t>* chars, int initialCp );
ParagraphPropertyExceptions* findValidPapx( int fc );
/// Splits a list of characters into several lists
// Splits a list of characters into several lists
std::list<std::vector<wchar_t> >* splitCharList( std::vector<wchar_t>* chars, std::vector<int>* splitIndices );
/// Writes the table starts at the given cp value
// Writes the table starts at the given cp value
int writeTable( int initialCp, unsigned int nestingLevel );
/// Builds a list that contains the width of the several columns of the table.
// Builds a list that contains the width of the several columns of the table.
std::vector<short>* buildTableGrid( int initialCp, unsigned int nestingLevel );
/// Finds the FC of the next row end mark.
// Finds the FC of the next row end mark.
int findRowEndFc( int initialCp, int& rowEndCp, unsigned int nestingLevel );
/// Finds the FC of the next row end mark.
// Finds the FC of the next row end mark.
int findRowEndFc( int initialCp, unsigned int nestingLevel );
/// Writes the table row that starts at the given cp value and ends at the next row end mark
// Writes the table row that starts at the given cp value and ends at the next row end mark
int writeTableRow( int initialCp, std::vector<short>* grid, unsigned int nestingLevel );
/// Writes the table cell that starts at the given cp value and ends at the next cell end mark
// Writes the table cell that starts at the given cp value and ends at the next cell end mark
int writeTableCell( int initialCp, TablePropertyExceptions* tapx, std::vector<short>* grid, int& gridIndex, int cellIndex, unsigned int nestingLevel );
int findCellEndCp( int initialCp, unsigned int nestingLevel );
bool writeBookmarks( int cp );
bool writeBookmarkStart( short id );
bool writeBookmarkEnd( short id );
/// Checks if the CHPX is special
// Checks if the CHPX is special
bool isSpecial( CharacterPropertyExceptions* chpx );
/// Finds the SEPX that is valid for the given CP.
// Finds the SEPX that is valid for the given CP.
SectionPropertyExceptions* findValidSepx( int cp );
/// Searches the given vector for the next FieldEnd character.
// Searches the given vector for the next FieldEnd character.
int searchNextTextMark( std::vector<wchar_t>* chars, int initialCp, wchar_t mark );
private:
Symbol getSymbol ( const CharacterPropertyExceptions* chpx );
Symbol getSymbol ( const CharacterPropertyExceptions* chpx );
//----------------------------------------------------------------------------------------------------------------------
bool m_bInternalXmlWriter;
protected:
WordDocument* m_document;
ConversionContext* m_context;
IMapping* _caller;
ParagraphPropertyExceptions* _lastValidPapx;
......@@ -149,5 +151,6 @@ namespace DocFileFormat
bool _writeWebHidden;
unsigned int _fldCharCounter;
std::wstring _writeAfterRun;
std::wstring _lastOLEObject;
};
}
......@@ -67,7 +67,7 @@ namespace DocFileFormat
virtual ~Shape()
{
RELEASEOBJECT( this->shapeType );
RELEASEOBJECT( shapeType );
}
Shape( IBinaryReader* _reader, unsigned int size, unsigned int typeCode, unsigned int version, unsigned int instance ):
......@@ -107,12 +107,12 @@ namespace DocFileFormat
inline int GetShapeID() const
{
return this->spid;
return spid;
}
inline ShapeType* GetShapeType() const
{
return this->shapeType;
return shapeType;
}
template<class T> bool is() const
......
......@@ -67,7 +67,6 @@ namespace DocFileFormat
}
m_pXmlWriter->WriteNodeBegin( _T( "o:OLEObject" ), TRUE );
//type
if ( ole->bLinked )
{
int relID = m_context->_docx->RegisterExternalOLEObject(_caller, ole->ClipboardFormat, ole->Link);
......@@ -88,22 +87,13 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute( _T( "r:id" ), ( std::wstring( _T( "rId" ) ) + FormatUtils::IntToWideString( relID ) ).c_str() );
m_pXmlWriter->WriteAttribute( _T( "Type" ), _T( "Embed" ) );
//copy the object
copyEmbeddedObject( ole );
}
//ProgID
m_pXmlWriter->WriteAttribute( _T( "ProgID" ), ole->Program.c_str() );
//ShapeId
m_pXmlWriter->WriteAttribute( _T( "ShapeID" ), _shapeId.c_str() );
//DrawAspect
m_pXmlWriter->WriteAttribute( _T( "DrawAspect" ), _T( "Content" ) );
//ObjectID
m_pXmlWriter->WriteAttribute( _T( "ObjectID" ), ole->ObjectId.c_str() );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T( "o:OLEObject" ) );
......@@ -165,20 +155,15 @@ namespace DocFileFormat
}
private:
// Writes the embedded OLE object from the ObjectPool of the binary file to the OpenXml Package.
inline void copyEmbeddedObject( const OleObject* ole )
{
if ( ole != NULL )
{
//!!!TODO: There is issue with some Office OLE Objects. Word can't open *.xls object (Excel.Chart) with set CLSID and
//some Power Point Presentations, and Word Documents. Open Office CAN start this objects!!!
std::wstring clsid;
std::wstring exelChart = _T( "Excel.Chart" );
if ( std::search( ole->Program.begin(), ole->Program.end(), exelChart.begin(), exelChart.end() ) == ole->Program.end() )
{//??
{
clsid = ole->ClassId;
}
OleObjectFileStructure object_descr(OleObjectMapping::GetTargetExt( ole->ClipboardFormat ), ole->ObjectId, clsid);
......
......@@ -50,9 +50,8 @@ namespace DocFileFormat
void SetTextboxStyle(const std::wstring & style);
private:
static int TextboxCount;
static int TextboxCount;
int m_nTBIndex;
double m_dxTextLeft;
......
......@@ -189,7 +189,6 @@ namespace DocFileFormat
return res;
}
//---------------------------------------------------------------
static int count_vml_objects = 0;
void VMLPictureMapping::appendStyleProperty(std::wstring* b, const std::wstring& propName, const std::wstring& propValue) const
{
if ( b != NULL )
......@@ -215,8 +214,6 @@ namespace DocFileFormat
m_isEmbedded = false;
m_imageData = new XMLTools::XMLElement<wchar_t>( _T( "v:imagedata" ) );
m_ShapeId = std::wstring(L"_x0000_i") + FormatUtils::IntToWideString(1024 + (count_vml_objects++));
}
VMLPictureMapping::~VMLPictureMapping()
......@@ -263,7 +260,12 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute( _T( "type" ), std::wstring( _T( "#" ) + VMLShapeTypeMapping::GenerateTypeId(&type)).c_str());
m_pXmlWriter->WriteAttribute( _T( "id" ), m_ShapeId.c_str() );
count_vml_objects++;
if (m_shapeId.empty())
m_shapeId = std::wstring(L"_x0000_s") + FormatUtils::IntToWideString(1024 + count_vml_objects);
m_pXmlWriter->WriteAttribute( _T( "id" ), m_shapeId.c_str() );
if (m_isOlePreview)
{
......@@ -426,11 +428,6 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "v:shape" ) );
}
std::wstring VMLPictureMapping::GetShapeId () const
{
return m_ShapeId;
}
void VMLPictureMapping::writePictureBorder( const std::wstring & name, const BorderCode* brc )
{
if (!brc || name.empty()) return;
......
......@@ -54,8 +54,6 @@ namespace DocFileFormat
VMLPictureMapping( ConversionContext* ctx, XMLTools::CStringXmlWriter* writer, bool olePreview, IMapping* caller, bool isInlinePicture = false );
virtual ~VMLPictureMapping();
virtual void Apply( IVisitable* visited );
std::wstring GetShapeId() const;
private:
/// Writes a border element
void writePictureBorder (const std::wstring & name, const BorderCode* brc);
......@@ -75,12 +73,13 @@ namespace DocFileFormat
bool m_isEmbedded;
std::string m_embeddedData;
std::wstring m_equationXml;
std::wstring m_shapeId;
private:
ConversionContext* m_ctx;
IMapping* m_caller;
int m_nImageId;
std::wstring m_ShapeId;
bool m_isOlePreview;
bool m_isInlinePicture;
......
......@@ -146,8 +146,10 @@ namespace DocFileFormat
std::list<OptionEntry> options = groupShape->ExtractOptions();
ChildAnchor* anchor = groupShape->FirstChildWithType<ChildAnchor>();
m_shapeId = GetShapeID(shape);
m_pXmlWriter->WriteNodeBegin( L"v:group", true );
m_pXmlWriter->WriteAttribute( L"id", GetShapeID(shape).c_str());
m_pXmlWriter->WriteAttribute( L"id", m_shapeId .c_str());
m_pXmlWriter->WriteAttribute( L"style", FormatUtils::XmlEncode(buildStyle(shape, anchor, options, container->Index)).c_str() );
m_pXmlWriter->WriteAttribute( L"coordorigin", ( FormatUtils::IntToWideString(gsr->rcgBounds.topLeftAngle.x) + L"," + FormatUtils::IntToWideString( gsr->rcgBounds.topLeftAngle.y)).c_str() );
m_pXmlWriter->WriteAttribute( L"coordsize", ( FormatUtils::IntToWideString(gsr->rcgBounds.size.cx) + L"," + FormatUtils::IntToWideString(gsr->rcgBounds.size.cy)).c_str() );
......@@ -230,8 +232,14 @@ namespace DocFileFormat
WriteBeginShapeNode (pShape);
sShapeId = GetShapeID(pShape);
m_pXmlWriter->WriteAttribute ( L"id", sShapeId );
m_shapeId = GetShapeID(pShape);
count_vml_objects++;
if (m_shapeId.empty())
m_shapeId = std::wstring(L"_x0000_s") + FormatUtils::IntToWideString(1024 + count_vml_objects);
m_pXmlWriter->WriteAttribute ( L"id", m_shapeId );
if ( !pShape->fBackground )
{
......@@ -1021,14 +1029,21 @@ namespace DocFileFormat
m_context->_doc->Convert(&textboxMapping);
}
}
WriteEndShapeNode(pShape);
// OLE
if (indexOLE >= 0 && pShape->fOleShape)
if (indexOLE >= 0 && pShape->fOleShape) //4571833.doc
{
TextboxMapping textboxMapping(m_context, 0, m_pXmlWriter, m_pCaller);
XMLTools::CStringXmlWriter txtBoxWrapper;
TextboxMapping textboxMapping(m_context, (indexOLE >> 16) - 1, &txtBoxWrapper, m_pCaller);
textboxMapping.m_shapeIdOwner = m_shapeId;
m_context->_doc->Convert(&textboxMapping);
m_pXmlWriter->WriteString(textboxMapping.getOLEObject());
}
WriteEndShapeNode(pShape);
//ShapeType
if (NULL != pShape->GetShapeType() /* && !m_isInlineShape*/) //bullete only???
{
......@@ -1905,7 +1920,6 @@ namespace DocFileFormat
return rectangles;
}
//------------------------------------------------------------------------------------------------------
static int count_vml_objects = 0;
void VMLShapeMapping::ApplyPrimitives(DrawingPrimitives * primitives)
{
......@@ -1992,7 +2006,9 @@ namespace DocFileFormat
TwipsValue w( primitive->dxa );
TwipsValue h( primitive->dya );
std::wstring strId = std::wstring(L"_x0000_s") + FormatUtils::IntToWideString(1024 + (count_vml_objects++));
std::wstring strId = std::wstring(L"_x0000_s") + FormatUtils::IntToWideString(1024 + count_vml_objects);
count_vml_objects++;
//m_pXmlWriter->WriteAttribute ( L"id") , strId.c_str());
m_pXmlWriter->WriteAttribute ( L"o:spid", strId.c_str());
......
......@@ -68,7 +68,8 @@ namespace DocFileFormat
static std::wstring mapHorizontalPosition (PositionHorizontal hPos );
static std::wstring mapHorizontalPositionRelative(int hRel );
bool m_isBullete;
bool m_isBullete;
std::wstring m_shapeId;
private:
void ApplyPrimitives (DrawingPrimitives * primitives );
......
......@@ -37,6 +37,8 @@
namespace DocFileFormat
{
static int count_vml_objects = 0;
class VMLShapeTypeMapping: public PropertiesMapping, public IMapping
{
private:
......
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