Commit 3f905fda authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

DocFormat - bi-direction в параграфах(форматирование)

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@67398 954022d7-b5bf-4e40-9824-e11837661b57
parent c601659c
......@@ -3,7 +3,8 @@
namespace DocFileFormat
{
CharacterPropertiesMapping::CharacterPropertiesMapping( XmlUtils::CXmlWriter* writer, WordDocument* doc, RevisionData* rev, ParagraphPropertyExceptions* currentPapx, bool styleChpx, bool isRunStyleNeeded) : PropertiesMapping( writer ), _isRunStyleNeeded(isRunStyleNeeded), _isOwnRPr(true)
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" ) );
......@@ -13,7 +14,8 @@ namespace DocFileFormat
this->_currentIstd = USHRT_MAX;
}
CharacterPropertiesMapping::CharacterPropertiesMapping( XMLTools::XMLElement<wchar_t>* rPr, WordDocument* doc, RevisionData* rev, ParagraphPropertyExceptions* currentPapx, bool styleChpx, bool isRunStyleNeeded ): PropertiesMapping( NULL ), _isRunStyleNeeded(isRunStyleNeeded), _isOwnRPr(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;
......@@ -81,10 +83,10 @@ namespace DocFileFormat
void CharacterPropertiesMapping::convertSprms( list<SinglePropertyModifier>* sprms, XMLTools::XMLElement<wchar_t>* parent )
{
XMLTools::XMLElement<wchar_t>* rFonts = new XMLTools::XMLElement<wchar_t>( _T( "w:rFonts" ) );
XMLTools::XMLElement<wchar_t>* color = new XMLTools::XMLElement<wchar_t>( _T( "w:color" ) );
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" ) );
XMLTools::XMLElement<wchar_t> * rFonts = new XMLTools::XMLElement<wchar_t> ( _T( "w:rFonts" ) );
XMLTools::XMLElement<wchar_t> * color = new XMLTools::XMLElement<wchar_t> ( _T( "w:color" ) );
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" ) );
// - http://bugzserver/show_bug.cgi?id=13353 TODO :
bool haveStyle = FALSE;
......@@ -109,6 +111,7 @@ namespace DocFileFormat
case 0x085A : // Element flags
appendFlagElement( parent, *iter, _T( "rtl" ), true );
this->_isRTL = true;
break;
case 0x0835 :
......
......@@ -29,6 +29,7 @@ namespace DocFileFormat
void Apply( IVisitable* chpx );
bool CheckIsSymbolFont();
bool _isRTL;
private:
void convertSprms( list<SinglePropertyModifier>* sprms, XMLTools::XMLElement<wchar_t>* parent );
list<CharacterPropertyExceptions*> buildHierarchy( const StyleSheet* styleSheet, unsigned short istdStart );
......
......@@ -38,8 +38,23 @@ namespace DocFileFormat
namespace DocFileFormat
{
// 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 & current of a sections
int DocumentMapping::getCurrentSection(int cp)
{
//if cp is the last char of a section, the next section will start at cp +1
int current = 0;
for (std::vector<int>::iterator iter = m_document->SectionPlex->CharacterPositions.begin() + 1; iter != m_document->SectionPlex->CharacterPositions.end(); ++iter)
{
if (cp < *iter)
{
break;
}
current++;
}
return m_document->SectionPlex->CharacterPositions[current + 1];
}
bool DocumentMapping::isSectionEnd(int cp)
{
bool result = false;
......@@ -133,8 +148,15 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeBegin(_T("w:p"), TRUE);
writeParagraphRsid(papx);
// check for section properties
// ----------- check for section properties
bool isBidi = false;
SectionPropertyExceptions* currentSection = findValidSepx(getCurrentSection(cp));
if (currentSection)
{
isBidi = currentSection->isBidi;
}
//-----------------------------------------------------------
if (sectionEnd)
{
// this is the last paragraph of this section
......@@ -142,7 +164,7 @@ namespace DocFileFormat
if (papx)
{
ParagraphPropertiesMapping oMapping(m_pXmlWriter, m_context, m_document, paraEndChpx, findValidSepx(cpEnd), _sectionNr);
ParagraphPropertiesMapping oMapping(m_pXmlWriter, m_context, m_document, paraEndChpx, isBidi, findValidSepx(cpEnd), _sectionNr);
papx->Convert(&oMapping);
}
......@@ -154,7 +176,7 @@ namespace DocFileFormat
if (papx)
{
ParagraphPropertiesMapping oMapping(m_pXmlWriter, m_context, m_document, paraEndChpx);
ParagraphPropertiesMapping oMapping(m_pXmlWriter, m_context, m_document, paraEndChpx, isBidi);
papx->Convert(&oMapping);
}
}
......
......@@ -44,6 +44,8 @@ namespace DocFileFormat
protected:
/// 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
bool isSectionEnd( int cp );
/// Writes a Paragraph that starts at the given cp and
......
......@@ -121,9 +121,9 @@ namespace Global
static const wchar_t JustificationCode[10][15] =
{
_T( "left" ),
_T( "start" ),
_T( "center" ),
_T( "right" ),
_T( "end" ),
_T( "both" ),
_T( "distribute" ),
_T( "mediumKashida" ),
......
......@@ -22,8 +22,7 @@ namespace DocFileFormat
virtual ~LanguageIdMapping();
void Apply( IVisitable* lid );
private:
wstring getLanguageCode( LanguageId* lid );
static wstring getLanguageCode( LanguageId* lid );
private:
LanguageType _type;
......
......@@ -26,12 +26,24 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeBegin(_T("w:document"), TRUE );
// Namespaces
m_pXmlWriter->WriteAttribute(_T("xmlns:w"), OpenXmlNamespaces::WordprocessingML );
m_pXmlWriter->WriteAttribute(_T("xmlns:v"), OpenXmlNamespaces::VectorML );
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:w"), OpenXmlNamespaces::WordprocessingML );
m_pXmlWriter->WriteAttribute(_T("xmlns:v"), OpenXmlNamespaces::VectorML );
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: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"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wpg"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wpi"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingInk"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wne"), _T("http://schemas.microsoft.com/office/word/2006/wordml"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wps"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingShape"));
//m_pXmlWriter->WriteAttribute(_T("mc:Ignorable"), _T("w14 wp14"));
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeBegin( _T("w:body"), FALSE );
......
......@@ -424,7 +424,8 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE );
// pPr
ParagraphPropertiesMapping oppMapping(m_pXmlWriter, m_context, m_document, NULL);
bool isBidi = false;
ParagraphPropertiesMapping oppMapping(m_pXmlWriter, m_context, m_document, NULL, isBidi);
lvl->grpprlPapx->Convert(&oppMapping);
// rPr
......
......@@ -42,10 +42,8 @@ namespace DocFileFormat
{
HRESULT res = S_OK;
POLE::Stream* ObjectPoolStorage = //docStorage->GetStorage()->stream("ObjectPool");
new POLE::Stream(oleStorage, "ObjectPool");
POLE::Stream* ObjectPoolStorage = new POLE::Stream(oleStorage, "ObjectPool");
//if (oleStorage->enterDirectory("ObjectPool"))
if (ObjectPoolStorage)
{
ObjectId = getOleEntryName( chpx );
......@@ -64,7 +62,8 @@ namespace DocFileFormat
{
processCompObjStream( name + "CompObj" );
}
//oleStorage->leaveDirectory();
processEquationNativeStream( name + "Equation Native" );
}
//oleStorage->leaveDirectory();
delete ObjectPoolStorage;
......@@ -131,6 +130,36 @@ namespace DocFileFormat
{
}
}
void processEquationNativeStream( const string& eqStream )
{
try
{
POLE::Stream* pCompStream = NULL;
HRESULT res = S_OK;
pCompStream = new POLE::Stream(oleStorage, eqStream);
if ( pCompStream )
{
VirtualStreamReader reader( pCompStream );
int sz = reader.GetSize();
unsigned char *Buffer = reader.ReadBytes( sz, true );
if (Buffer)
{
delete []Buffer;
}
delete pCompStream;
}
}
catch (...)
{
}
}
void processCompObjStream( const string& compStream )
{
......@@ -139,10 +168,7 @@ namespace DocFileFormat
POLE::Stream* pCompStream = NULL;
HRESULT res = S_OK;
pCompStream = //oleStorage->stream(compStream);
new POLE::Stream(oleStorage, compStream);
//res = oleStorage->OpenStream( compStream.c_str(), NULL, STGM_SHARE_EXCLUSIVE, NULL, &pCompStream );
pCompStream = new POLE::Stream(oleStorage, compStream);
if ( pCompStream )
{
......@@ -170,9 +196,7 @@ namespace DocFileFormat
POLE::Stream* pOleStream;
HRESULT res = S_OK;
pOleStream = //oleStorage->stream(oleStreamName);
new POLE::Stream(oleStorage, oleStreamName);
//res = oleStorage->OpenStream( oleStream.c_str(), NULL, STGM_SHARE_EXCLUSIVE, NULL, &pOleStream );
pOleStream = new POLE::Stream(oleStorage, oleStreamName);
if ( pOleStream )
{
......
......@@ -4,24 +4,33 @@
namespace DocFileFormat
{
ParagraphPropertiesMapping::ParagraphPropertiesMapping(XmlUtils::CXmlWriter* writer, ConversionContext* context, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isParagraphStyleNeeded) : PropertiesMapping( writer ), m_context(NULL), _pPr(NULL), _framePr(NULL), _sepx(NULL), _paraEndChpx(NULL), _sectionNr(0), m_document(NULL), _isParagraphStyleNeeded(isParagraphStyleNeeded)
ParagraphPropertiesMapping::ParagraphPropertiesMapping(XmlUtils::CXmlWriter* writer, ConversionContext* context, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isBidi, bool isParagraphStyleNeeded)
: PropertiesMapping( writer ), m_context(NULL), _pPr(NULL), _framePr(NULL), _sepx(NULL), _paraEndChpx(NULL), _sectionNr(0),
m_document(NULL), _isParagraphStyleNeeded(isParagraphStyleNeeded)
{
m_document = document;
m_context = context;
m_document = document;
m_context = context;
_pPr = new XMLTools::XMLElement<wchar_t>( _T( "w:pPr" ) );
_framePr = new XMLTools::XMLElement<wchar_t>( _T( "w:framePr" ) );
_paraEndChpx = paraEndChpx;
_pPr = new XMLTools::XMLElement<wchar_t>( _T( "w:pPr" ) );
_framePr = new XMLTools::XMLElement<wchar_t>( _T( "w:framePr" ) );
_paraEndChpx = paraEndChpx;
_isBidi = isBidi;
}
ParagraphPropertiesMapping::ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* context, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, SectionPropertyExceptions* sepx, int sectionNr, bool isParagraphStyleNeeded ): PropertiesMapping( writer ), m_context(NULL), _pPr(NULL), _framePr(NULL), _sepx(NULL), _paraEndChpx(NULL), _sectionNr(0), m_document(NULL), _isParagraphStyleNeeded(isParagraphStyleNeeded)
ParagraphPropertiesMapping::ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* context, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isBidi, SectionPropertyExceptions* sepx, int sectionNr, bool isParagraphStyleNeeded )
: PropertiesMapping( writer ), m_context(NULL), _pPr(NULL), _framePr(NULL), _sepx(NULL), _paraEndChpx(NULL), _sectionNr(0),
m_document(NULL), _isParagraphStyleNeeded(isParagraphStyleNeeded)
{
m_document = document;
m_context = context;
m_document = document;
m_context = context;
_pPr = new XMLTools::XMLElement<wchar_t>( _T( "w:pPr" ) );
_framePr = new XMLTools::XMLElement<wchar_t>( _T( "w:framePr" ) );
_paraEndChpx = paraEndChpx;
_isBidi = isBidi;
_pPr = new XMLTools::XMLElement<wchar_t>( _T( "w:pPr" ) );
_framePr = new XMLTools::XMLElement<wchar_t>( _T( "w:framePr" ) );
_paraEndChpx = paraEndChpx;
_sepx = sepx;
_sectionNr = sectionNr;
}
......@@ -114,6 +123,7 @@ namespace DocFileFormat
case sprmPFBiDi:
{
appendFlagElement( _pPr, *iter, _T( "bidi" ), true );
_isBidi = true;
}
break;
......@@ -256,6 +266,10 @@ namespace DocFileFormat
case sprmPJc:
case sprmPJc80:
{
if (this->_isBidi && (iter->Arguments[0] == 0 || iter->Arguments[0] == 2))
{
iter->Arguments[0] = (iter->Arguments[0] == 0 ? 2 : 0);
}
RELEASEOBJECT( jc );
jc = new XMLTools::XMLElement<wchar_t>( _T( "w:jc" ) );
XMLTools::XMLAttribute<wchar_t> jcVal( _T( "w:val" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::JustificationCode[0][0], 10, 15 ).c_str() );
......
......@@ -15,8 +15,8 @@ namespace DocFileFormat
class ParagraphPropertiesMapping: public PropertiesMapping, public IMapping
{
public:
ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* ctx, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isParagraphStyleNeeded = true );
ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* ctx, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, SectionPropertyExceptions* sepx, int sectionNr, bool isParagraphStyleNeeded = true );
ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* ctx, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isBidi, bool isParagraphStyleNeeded = true );
ParagraphPropertiesMapping( XmlUtils::CXmlWriter* writer, ConversionContext* ctx, WordDocument* document, CharacterPropertyExceptions* paraEndChpx, bool isBidi, SectionPropertyExceptions* sepx, int sectionNr, bool isParagraphStyleNeeded = true );
virtual ~ParagraphPropertiesMapping();
void Apply(IVisitable* visited);
......@@ -31,5 +31,6 @@ namespace DocFileFormat
int _sectionNr;
bool _isParagraphStyleNeeded;
bool _isBidi;
};
}
......@@ -299,7 +299,7 @@ namespace DocFileFormat
if (NULL == m_arrWidth)
m_arrWidth = new short [m_nColumns];
unsigned char nInd = iter->Arguments[0];
unsigned char nInd = iter->Arguments[0];
m_arrWidth[nInd] = FormatUtils::BytesToInt16 (iter->Arguments, 1, iter->argumentsSize);
}
}
......@@ -313,7 +313,7 @@ namespace DocFileFormat
if (NULL == m_arrSpace)
m_arrSpace = new short[m_nColumns];
unsigned char nInd = iter->Arguments[0];
unsigned char nInd = iter->Arguments[0];
m_arrSpace [nInd] = FormatUtils::BytesToInt16 (iter->Arguments, 1, iter->argumentsSize);
}
}
......
......@@ -4,17 +4,28 @@
namespace DocFileFormat
{
class SectionPropertyExceptions: public PropertyExceptions
{
public:
/// Parses the bytes to retrieve a SectionPropertyExceptions
SectionPropertyExceptions( unsigned char* bytes, int size ):
PropertyExceptions( bytes, size )
{
}
class SectionPropertyExceptions: public PropertyExceptions
{
public:
/// Parses the bytes to retrieve a SectionPropertyExceptions
SectionPropertyExceptions( unsigned char* bytes, int size ):
PropertyExceptions( bytes, size ), isBidi(false)
{
for ( list<SinglePropertyModifier>::iterator iter = this->grpprl->begin(); iter != this->grpprl->end(); iter++ )
{
SinglePropertyModifier sprm( *iter );
if( sprm.OpCode == sprmSFBiDi )
{
isBidi = true;
}
}
}
virtual ~SectionPropertyExceptions()
{
}
};
virtual ~SectionPropertyExceptions()
{
}
bool isBidi;
};
}
\ No newline at end of file
......@@ -120,7 +120,8 @@ namespace DocFileFormat
//write paragraph properties
if ( (*iter)->papx != NULL )
{
ParagraphPropertiesMapping* ppMappingnew = new ParagraphPropertiesMapping (m_pXmlWriter, _ctx, m_document, NULL, false);
bool isBidi = false;
ParagraphPropertiesMapping* ppMappingnew = new ParagraphPropertiesMapping (m_pXmlWriter, _ctx, m_document, NULL, isBidi, false);
(*iter)->papx->Convert( ppMappingnew );
RELEASEOBJECT( ppMappingnew );
}
......@@ -222,6 +223,15 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T( "w:rFonts" ) );
LanguageId langid(this->m_document->FIB->m_FibBase.lid);
wstring langcode = LanguageIdMapping::getLanguageCode( &langid );
m_pXmlWriter->WriteNodeBegin( _T( "w:lang" ), TRUE );
m_pXmlWriter->WriteAttribute( _T( "w:val" ), langcode.c_str() );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T( "w:lang" ) );
m_pXmlWriter->WriteNodeEnd( _T( "w:rPr" ) );
m_pXmlWriter->WriteNodeEnd( _T( "w:rPrDefault" ) );
}
......
......@@ -9,6 +9,7 @@
namespace DocFileFormat
{
static int count_vml_objects = 0;
void VMLPictureMapping::appendStyleProperty(std::wstring* b, const std::wstring& propName, const std::wstring& propValue) const
{
if ( b != NULL )
......@@ -31,15 +32,7 @@ namespace DocFileFormat
m_imageData = new XMLTools::XMLElement<wchar_t>( _T( "v:imagedata" ) );
//GUID guid = GUID_NULL;
// wstring guid;
// LPOLESTR guidString = NULL;
// CoCreateGuid (&guid);
// StringFromCLSID (guid, &guidString);
// m_ShapeId = std::wstring(guidString);
// CoTaskMemFree(guidString);
m_ShapeId = std::wstring(L"_x0000_i") + FormatUtils::IntToWideString(1024 + (count_vml_objects++));
}
VMLPictureMapping::~VMLPictureMapping()
......
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