Index: abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.cpp =================================================================== RCS file: /cvsroot/abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.cpp,v retrieving revision 1.11 diff -u -r1.11 ie_exp_OpenWriter.cpp --- abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.cpp 26 Mar 2004 11:39:20 -0000 1.11 +++ abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.cpp 3 Sep 2004 10:13:01 -0000 @@ -23,6 +23,7 @@ #include +#include "ut_Language.h" #include "ie_impexp_OpenWriter.h" #include "ie_exp_OpenWriter.h" @@ -93,9 +94,8 @@ gsf_output_write (output, str.byteLength(), reinterpret_cast(str.utf8_str())); } -static void outputCharData (GsfOutput * output, const UT_UCSChar * data, UT_uint32 length) +static void addCharData (UT_UTF8String & sBuf, const UT_UCSChar * data, UT_uint32 length) { - UT_UTF8String sBuf; const UT_UCSChar * pData; UT_ASSERT(sizeof(UT_Byte) == sizeof(char)); @@ -134,10 +134,15 @@ } } } - - writeUTF8String (output, sBuf); } +static void addPropsToString(UT_String & string, UT_PropVector & props) +{ + for (UT_uint32 i = 0; i < props.size(); i++) + { + string += UT_String_sprintf("%s=\"%s\" ", props[i], props[++i]); + } +} /*****************************************************************************/ /*****************************************************************************/ @@ -157,20 +162,42 @@ }; writeToStream(m_pContentStream, preamble, NrElements(preamble)); - UT_GenericVector* tempStylesValuesList = m_pStylesContainer->enumerateSpanStyles(); - UT_GenericVector *tempStylesKeysList = m_pStylesContainer->getSpanStylesKeys(); + + UT_GenericVector *tempStylesValuesList = NULL; + UT_GenericVector *tempStylesKeysList = NULL; + int *styleNum = NULL; + + // span styles + tempStylesValuesList = m_pStylesContainer->enumerateSpanStyles(); + tempStylesKeysList = m_pStylesContainer->getSpanStylesKeys(); for (UT_uint32 i=0; isize(); i++) { - int *styleNum = tempStylesValuesList->getNthItem(i); + styleNum = tempStylesValuesList->getNthItem(i); const UT_String *styleProps = tempStylesKeysList->getNthItem(i); UT_String styleString = UT_String_sprintf("\n", *styleNum, "text", styleProps->c_str()); writeString(m_pContentStream, styleString); UT_DEBUGMSG(("%s", styleString.c_str())); UT_DEBUGMSG(("\"%s\"\n", styleProps->c_str())); } - delete(tempStylesKeysList); - delete(tempStylesValuesList); + FREEP(tempStylesKeysList); + FREEP(tempStylesValuesList); + + // block styles + tempStylesValuesList = m_pStylesContainer->enumerateBlockStyles(); + tempStylesKeysList = m_pStylesContainer->getBlockStylesKeys(); + + for (UT_uint32 i=0; isize(); i++) + { + styleNum = tempStylesValuesList->getNthItem(i); + const UT_String *styleProps = tempStylesKeysList->getNthItem(i); + UT_String styleString = UT_String_sprintf("\n", *styleNum, "paragraph", styleProps->c_str()); + writeString(m_pContentStream, styleString); + UT_DEBUGMSG(("%s", styleString.c_str())); + UT_DEBUGMSG(("\"%s\"\n", styleProps->c_str())); + } + FREEP(tempStylesKeysList); + FREEP(tempStylesValuesList); //m_acc.writeStylePreamble(m_contentStream); @@ -204,34 +231,42 @@ void OO_WriterImpl::insertText(const UT_UCSChar * data, UT_uint32 length) { - outputCharData(m_pContentStream, data, length); + addCharData(m_blockContent, data, length); } void OO_WriterImpl::openBlock() { - UT_UTF8String begP (""); - writeUTF8String (m_pContentStream, begP); } -void OO_WriterImpl::closeBlock() -{ - UT_UTF8String endP ("\n"); - writeUTF8String (m_pContentStream, endP); +void OO_WriterImpl::closeBlock(UT_PropVector & props) +{ + UT_UTF8String begP; + if ((m_pStylesContainer->enumerateBlockStyles())->size()) + begP = UT_UTF8String_sprintf("", + m_pStylesContainer->getBlockStyleNum(props)); + else + begP = ""; + writeUTF8String (m_pContentStream, begP); + + writeUTF8String (m_pContentStream, m_blockContent); + m_blockContent.clear(); + + UT_UTF8String endP ("\n"); + writeUTF8String (m_pContentStream, endP); } void OO_WriterImpl::openSpan(UT_String &props) { UT_UTF8String spanString = UT_UTF8String_sprintf("", - m_pStylesContainer->getStyleNum(props)); - - writeUTF8String(m_pContentStream, spanString); + m_pStylesContainer->getSpanStyleNum(props)); + m_blockContent += spanString; } void OO_WriterImpl::closeSpan() { UT_UTF8String closeSpan = ""; - writeUTF8String(m_pContentStream, closeSpan); + m_blockContent += closeSpan; } void OO_StylesContainer::addSpanStyle(UT_String &key) @@ -253,7 +288,25 @@ } } -const int OO_StylesContainer::getStyleNum(UT_String &key) const +void OO_StylesContainer::addBlockStyle(UT_String &key) +{ + const void *temp; + if (!m_blockStylesHash.pick(key.c_str())) + { + UT_DEBUGMSG(("OO_AccumulatorImpl: block props of this type: %s not yet found, adding style at num: %i\n", key.c_str(), (m_blockStylesHash.size()+1))); + int *val = new int; + char *keyCopy = new char[strlen(key.c_str())+1]; + keyCopy = strcpy(keyCopy, key.c_str()); + *val = (int)m_blockStylesHash.size()+1; + m_blockStylesHash.insert(keyCopy, val); + } + else + { + UT_DEBUGMSG(("OO_AccumulatorImpl: block props of this type: %s already there, forget it\n", key.c_str())); + } +} + +const int OO_StylesContainer::getSpanStyleNum(UT_String &key) const { if (int *val = m_spanStylesHash.pick(key.c_str())) { return *val; @@ -262,23 +315,52 @@ return 0; } +const int OO_StylesContainer::getBlockStyleNum(UT_PropVector &props) const +{ + UT_String key; + addPropsToString(key, props); + + if (int *val = m_blockStylesHash.pick(key.c_str())) { + return *val; + } + else + return 0; +} + UT_GenericVector * OO_StylesContainer::enumerateSpanStyles() const { return m_spanStylesHash.enumerate(); } +UT_GenericVector * OO_StylesContainer::enumerateBlockStyles() const +{ + return m_blockStylesHash.enumerate(); +} UT_GenericVector * OO_StylesContainer::getSpanStylesKeys() const { return m_spanStylesHash.keys(); } +UT_GenericVector * OO_StylesContainer::getBlockStylesKeys() const +{ + return m_blockStylesHash.keys(); +} + + void OO_AccumulatorImpl::openSpan(UT_String &props) { m_pStylesContainer->addSpanStyle(props); +} +void OO_AccumulatorImpl::closeBlock(UT_PropVector &props) +{ + UT_String buffer; + addPropsToString(buffer, props); + m_pStylesContainer->addBlockStyle(buffer); } + OO_Listener::OO_Listener (PD_Document * pDocument, IE_Exp_OpenWriter * pie, OO_ListenerImpl *pListenerImpl) : PL_Listener (), m_pDocument(pDocument), m_pie(pie), m_pListenerImpl(pListenerImpl), m_bInBlock(false), m_bInSpan(false) { @@ -373,7 +455,8 @@ if (!m_bInBlock) return; - m_pListenerImpl->closeBlock(); + m_pListenerImpl->closeBlock(m_blockProps); + m_blockProps.clear(); m_bInBlock = false; } @@ -398,8 +481,23 @@ if (bHaveProp && pAP) { - const XML_Char * szValue; + const XML_Char * szValue = NULL; + // language (and thus direction) are block props + // rather than span props in the sxw file + pAP->getProperty("lang", szValue); + if (szValue) + { + UT_Language language; + UT_LANGUAGE_DIR dir = language.getDirFromCode(szValue); + if (dir == UTLANG_RTL) + { + m_blockProps.addOrReplaceProp("fo:text-align", "end"); + m_blockProps.addOrReplaceProp("style:justify-single-word", "false"); + m_blockProps.addOrReplaceProp("style:writing-mode", "rl-tb"); + } + } + if ((pAP->getProperty("text-position", szValue)) && !UT_strcmp(szValue, "superscript")) { Index: abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.h =================================================================== RCS file: /cvsroot/abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.h,v retrieving revision 1.3 diff -u -r1.3 ie_exp_OpenWriter.h --- abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.h 26 Mar 2004 11:39:20 -0000 1.3 +++ abiword-plugins/wp/impexp/OpenWriter/xp/ie_exp_OpenWriter.h 3 Sep 2004 10:13:02 -0000 @@ -37,6 +37,7 @@ #include "ut_vector.h" #include "ut_stack.h" #include "ut_assert.h" +#include "ut_PropVector.h" #include @@ -78,7 +79,7 @@ virtual ~OO_ListenerImpl() {} virtual void insertText(const UT_UCSChar * data, UT_uint32 length) = 0; virtual void openBlock() = 0; - virtual void closeBlock() = 0; + virtual void closeBlock(UT_PropVector &props) = 0; virtual void openSpan(UT_String &props) = 0; virtual void closeSpan() = 0; }; @@ -111,6 +112,11 @@ bool m_bInBlock; bool m_bInSpan; + // m_blockProps makes it possible to set block props + // from within a span. This is needed for "direction", + // because it's a span prop in Abi but a block prop in sxw. + UT_PropVector m_blockProps; + OO_ListenerImpl * m_pListenerImpl; PD_Document * m_pDocument; IE_Exp_OpenWriter * m_pie; @@ -123,13 +129,19 @@ OO_StylesContainer() {} ~OO_StylesContainer() { m_spanStylesHash.purgeData(); + m_blockStylesHash.purgeData(); } void addSpanStyle(UT_String &key); - const int getStyleNum(UT_String &key) const; + void addBlockStyle(UT_String &key); + const int getSpanStyleNum(UT_String &key) const; + const int getBlockStyleNum(UT_PropVector &key) const; UT_GenericVector * enumerateSpanStyles() const; + UT_GenericVector * enumerateBlockStyles() const; UT_GenericVector * getSpanStylesKeys() const; + UT_GenericVector * getBlockStylesKeys() const; private: UT_GenericStringMap m_spanStylesHash; + UT_GenericStringMap m_blockStylesHash; }; /*! @@ -143,7 +155,7 @@ OO_AccumulatorImpl(OO_StylesContainer *pStylesContainer) : OO_ListenerImpl() { m_pStylesContainer = pStylesContainer; } virtual void insertText(const UT_UCSChar * data, UT_uint32 length) {} virtual void openBlock() {} - virtual void closeBlock() {} + virtual void closeBlock(UT_PropVector &props); virtual void openSpan(UT_String &props); virtual void closeSpan() {} @@ -162,12 +174,14 @@ ~OO_WriterImpl(); virtual void insertText(const UT_UCSChar * data, UT_uint32 length); virtual void openBlock(); - virtual void closeBlock(); + virtual void closeBlock(UT_PropVector &props); virtual void openSpan(UT_String &props); virtual void closeSpan(); private: GsfOutput * m_pContentStream; OO_StylesContainer *m_pStylesContainer; - + // The resulting output for each block is accumulated + // until the block is closed. + UT_UTF8String m_blockContent; };