[Libreoffice-commits] .: 35 commits - writerfilter/Library_rtftok.mk writerfilter/qa writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Fri Aug 12 05:58:21 PDT 2011


 writerfilter/Library_rtftok.mk                     |    1 
 writerfilter/qa/cppunittests/rtftok/testrtftok.cxx |   22 +
 writerfilter/source/dmapper/DomainMapper.cxx       |   60 ++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx  |  159 +++++++----
 writerfilter/source/dmapper/FieldTypes.hxx         |    1 
 writerfilter/source/dmapper/ModelEventListener.cxx |   28 ++
 writerfilter/source/dmapper/PropertyIds.cxx        |    2 
 writerfilter/source/dmapper/PropertyIds.hxx        |    2 
 writerfilter/source/dmapper/PropertyMap.cxx        |   33 +-
 writerfilter/source/rtftok/rtfdocumentimpl.cxx     |  294 ++++++++++++++-------
 writerfilter/source/rtftok/rtfdocumentimpl.hxx     |   44 +--
 writerfilter/source/rtftok/rtfsdrimport.cxx        |   17 -
 writerfilter/source/rtftok/rtfsdrimport.hxx        |    9 
 writerfilter/source/rtftok/rtfskipdestination.cxx  |   66 ++++
 writerfilter/source/rtftok/rtfskipdestination.hxx  |   56 ++++
 writerfilter/source/rtftok/rtftokenizer.cxx        |    7 
 writerfilter/source/rtftok/rtfvalue.cxx            |   30 +-
 writerfilter/source/rtftok/rtfvalue.hxx            |    6 
 18 files changed, 622 insertions(+), 215 deletions(-)

New commits:
commit dd525ec15c237296f1eace5f470db0785a48bfbf
Merge: 64fde7c... bcc2fbe...
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Aug 12 14:57:53 2011 +0200

    Merge remote-tracking branch 'feature/gsoc2011_rtfimport'

diff --cc writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 1ded4ad,bb5ff80..dc487b5
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@@ -973,56 -979,22 +980,58 @@@ util::DateTime lcl_DateStringToDateTime
      sal_Int32 nIndex = 0;
      ::rtl::OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
      ::rtl::OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
 +    int timezonepos = nIndex;
      nIndex = 0;
 -    aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
 -    aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
 -    aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
 +    aDateTime.SetYear( sDate.getToken( 0, '-', nIndex ).toInt32() );
 +    aDateTime.SetMonth( sDate.getToken( 0, '-', nIndex ).toInt32() );
 +    aDateTime.SetDay( sDate.copy( nIndex ).toInt32() );
  
      nIndex = 0;
 -    aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
 -    aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
 -    aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
 +    aDateTime.SetHour( sTime.getToken( 0, ':', nIndex ).toInt32() );
 +    aDateTime.SetMin( sTime.getToken( 0, ':', nIndex ).toInt32() );
 +    aDateTime.SetSec( sTime.copy( nIndex ).toInt32() );
  
 -    return aDateTime;
 +    if( timezonepos >= 0 ) // otherwise consider it local time
 +    {
 +        bool negative = false;
 +        nIndex = timezonepos;
 +        if( nIndex < rDateTime.getLength() && rDateTime[ nIndex ] == '-' )
 +        {
 +            negative = true;
 +            ++nIndex;
 +        }
 +        else if ( nIndex < rDateTime.getLength() && rDateTime[ nIndex ] == '+' )
 +        {
 +            ++nIndex;
 +        }
 +        Time diff( 0, 0, 0 );
 +        if( nIndex < rDateTime.getLength())
 +        {
 +            diff.SetHour( rDateTime.getToken( 0, ':', nIndex ).toInt32());
 +            diff.SetMin( rDateTime.getToken( 0, ':', nIndex ).toInt32());
 +        }
 +        // convert to utc, then to local
 +        if( negative )
 +            aDateTime -= diff;
 +        else
 +            aDateTime += diff;
 +        aDateTime.ConvertToLocalTime();
 +    }
 +    util::DateTime ret;
 +    ret.Year = aDateTime.GetYear();
 +    ret.Month = aDateTime.GetMonth();
 +    ret.Day = aDateTime.GetDay();
 +    ret.Hours = aDateTime.GetHour();
 +    ret.Minutes = aDateTime.GetMin();
 +    ret.Seconds = aDateTime.GetSec();
 +    ret.HundredthSeconds = 0;
 +    return ret;
  }
 +
  void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap )
  {
+     if (m_aTextAppendStack.empty())
+         return;
      uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
      if(xTextAppend.is() && ! getTableManager( ).isIgnore())
      {
commit bcc2fbef8fc9eec7664fc7592fa27e7804a4fc88
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Aug 12 12:32:27 2011 +0200

    fdo#37691: Initial support for the textbox shape
    
    For now, only pictures supported

diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 1c5e27f..212eecd 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -274,7 +274,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
                     OUStringToOString( i->second, RTL_TEXTENCODING_UTF8 ).getStr());
     }
 
-    if (nType == 75) // picture frame
+    if (nType == 75 || nType == 202) // picture frame or text box
     {
         if (bPib)
             m_rImport.resolvePict(false);
commit f40fcd9d109a02e88f53160bb55ffe5e8317d248
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Aug 12 12:19:08 2011 +0200

    support picture at the start of the document

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index ea91f54..d24fded 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -644,6 +644,7 @@ int RTFDocumentImpl::resolvePict(bool bInline)
         aSprms->push_back(make_pair(NS_ooxml::LN_anchor_anchor, pValue));
     }
     writerfilter::Reference<Properties>::Pointer_t const pProperties(new RTFReferenceProperties(aAttributes, aSprms));
+    checkFirstRun();
     Mapper().props(pProperties);
 
     return 0;
commit e0514fd4e88220c0dbbea87feea7a1275dfa2760
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Aug 12 11:40:11 2011 +0200

    Picture frame: we need the destination text outside the pict group
    
    I broke this in 6751324082ca472b9a34caabdd0a1032c27438b9

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 0f94caf..ea91f54 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2527,6 +2527,7 @@ int RTFDocumentImpl::popState()
 
     RTFSprms aSprms;
     RTFSprms aAttributes;
+    OUStringBuffer aDestinationText;
     bool bListEntryEnd = false;
     bool bListLevelEnd = false;
     bool bListOverrideEntryEnd = false;
@@ -2677,6 +2678,7 @@ int RTFDocumentImpl::popState()
     {
         bPopPictureProperties = true;
         aAttributes = m_aStates.top().aCharacterAttributes;
+        aDestinationText = m_aStates.top().aDestinationText;
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_SHAPETEXT)
         m_pCurrentBuffer = 0; // Just disable buffering, don't empty it yet.
@@ -2901,7 +2903,10 @@ int RTFDocumentImpl::popState()
     else if (bFaltEnd)
         m_aStates.top().aTableSprms = aSprms;
     if (bPopPictureProperties)
+    {
         m_aStates.top().aCharacterAttributes = aAttributes;
+        m_aStates.top().aDestinationText = aDestinationText;
+    }
     if (m_pCurrentBuffer == &m_aSuperBuffer)
     {
         if (!m_bHasFootnote)
commit 7a01b7cba3c0f0a5748ed3e085c458cb7ea4796d
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 16:33:12 2011 +0200

    we already have a using directive for these

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 2d9e15f..0f94caf 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2918,7 +2918,7 @@ int RTFDocumentImpl::popState()
     return "RTFDocumentImpl";
 }
 
-com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> RTFDocumentImpl::getModelFactory()
+uno::Reference<lang::XMultiServiceFactory> RTFDocumentImpl::getModelFactory()
 {
     return m_xModelFactory;
 }
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index c85f655..463b605 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -261,10 +261,10 @@ namespace writerfilter {
         {
             public:
                 typedef ::boost::shared_ptr<RTFDocumentImpl> Pointer_t;
-                RTFDocumentImpl(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const& xContext,
-                                com::sun::star::uno::Reference<com::sun::star::io::XInputStream> const& xInputStream,
-                                com::sun::star::uno::Reference<com::sun::star::lang::XComponent> const& xDstDoc,
-                                com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const& xFrame);
+                RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& xContext,
+                                uno::Reference<io::XInputStream> const& xInputStream,
+                                uno::Reference<lang::XComponent> const& xDstDoc,
+                                uno::Reference<frame::XFrame> const& xFrame);
                 virtual ~RTFDocumentImpl();
                 virtual void resolve(Stream & rHandler);
                 virtual std::string getType() const;
@@ -276,7 +276,7 @@ namespace writerfilter {
                 void finishSubstream();
                 void setIgnoreFirst(rtl::OUString& rIgnoreFirst);
                 void seek(sal_uInt32 nPos);
-                com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> getModelFactory();
+                uno::Reference<lang::XMultiServiceFactory> getModelFactory();
                 RTFParserState& getState();
                 /// If the stack of states is empty.
                 bool isEmpty();
@@ -318,12 +318,12 @@ namespace writerfilter {
                 void sectBreak(bool bFinal);
                 void replayBuffer(RTFBuffer_t& rBuffer);
 
-                com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const& m_xContext;
-                com::sun::star::uno::Reference<com::sun::star::io::XInputStream> const& m_xInputStream;
-                com::sun::star::uno::Reference<com::sun::star::lang::XComponent> const& m_xDstDoc;
-                com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const& m_xFrame;
-                com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> m_xModelFactory;
-                com::sun::star::uno::Reference<com::sun::star::document::XDocumentProperties> m_xDocumentProperties;
+                uno::Reference<uno::XComponentContext> const& m_xContext;
+                uno::Reference<io::XInputStream> const& m_xInputStream;
+                uno::Reference<lang::XComponent> const& m_xDstDoc;
+                uno::Reference<frame::XFrame> const& m_xFrame;
+                uno::Reference<lang::XMultiServiceFactory> m_xModelFactory;
+                uno::Reference<document::XDocumentProperties> m_xDocumentProperties;
                 SvStream* m_pInStream;
                 Stream* m_pMapperStream;
                 boost::shared_ptr<RTFSdrImport> m_pSdrImport;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx
index 5bc981c..a0092a2 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -38,18 +38,15 @@ namespace writerfilter {
         class RTFSdrImport
         {
             public:
-                RTFSdrImport(RTFDocumentImpl& rImport,
-                        com::sun::star::uno::Reference<com::sun::star::lang::XComponent> const& xDstDoc);
+                RTFSdrImport(RTFDocumentImpl& rImport, uno::Reference<lang::XComponent> const& xDstDoc);
                 virtual ~RTFSdrImport();
 
                 void resolve(RTFShape& rShape);
             private:
-                void createShape(rtl::OUString aService,
-                        com::sun::star::uno::Reference<drawing::XShape>& xShape,
-                        com::sun::star::uno::Reference<beans::XPropertySet>& xPropertySet);
+                void createShape(rtl::OUString aService, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet);
 
                 RTFDocumentImpl& m_rImport;
-                com::sun::star::uno::Reference<com::sun::star::drawing::XDrawPage> m_xDrawPage;
+                uno::Reference<drawing::XDrawPage> m_xDrawPage;
         };
     } // namespace rtftok
 } // namespace writerfilter
commit 70569eb6d6e0a52b43858293bd989feca8ce22dd
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 16:23:18 2011 +0200

    fix the "last char is missing from footnote when Word produces the rtf" bug

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 97d38a0..2d9e15f 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -264,6 +264,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_bFirstRun(true),
     m_bFirstRow(true),
     m_bNeedPap(false),
+    m_bNeedCr(false),
     m_aListTableSprms(),
     m_aSettingsTableSprms(),
     m_xStorage(),
@@ -333,6 +334,18 @@ bool RTFDocumentImpl::isSubstream()
     return m_bIsSubstream;
 }
 
+void RTFDocumentImpl::finishSubstream()
+{
+    // At the end of a footnote stream, we need to emit a run break when importing from Word.
+    // We can't do so unconditionally, as Writer already writes a \par at the end of the footnote.
+    if (m_bNeedCr)
+    {
+        Mapper().startCharacterGroup();
+        runBreak();
+        Mapper().endCharacterGroup();
+    }
+}
+
 void RTFDocumentImpl::setIgnoreFirst(OUString& rIgnoreFirst)
 {
     m_aIgnoreFirst = rIgnoreFirst;
@@ -390,6 +403,7 @@ void RTFDocumentImpl::runBreak()
 {
     sal_uInt8 sBreak[] = { 0xd };
     Mapper().text(sBreak, 1);
+    m_bNeedCr = false;
 }
 
 void RTFDocumentImpl::tableBreak()
@@ -832,6 +846,7 @@ void RTFDocumentImpl::text(OUString& rString)
         RTFValue::Pointer_t pValue(new RTFValue(rString));
         m_pCurrentBuffer->push_back(make_pair(BUFFER_UTEXT, pValue));
     }
+    m_bNeedCr = true;
     if (!m_pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
         Mapper().endCharacterGroup();
     else if(m_pCurrentBuffer)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 958c8d5..c85f655 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -273,6 +273,7 @@ namespace writerfilter {
                 void setSubstream(bool bIsSubtream);
                 void setAuthor(rtl::OUString& rAuthor);
                 bool isSubstream();
+                void finishSubstream();
                 void setIgnoreFirst(rtl::OUString& rIgnoreFirst);
                 void seek(sal_uInt32 nPos);
                 com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> getModelFactory();
@@ -342,6 +343,8 @@ namespace writerfilter {
                 bool m_bFirstRow;
                 /// If paragraph properties should be emitted on next run.
                 bool m_bNeedPap;
+                /// If we need to emit a CR at the end of substream.
+                bool m_bNeedCr;
                 /// The list table and list override table combined.
                 RTFSprms m_aListTableSprms;
                 /// The settings table.
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index e1e4223..7ddf0fc 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -83,7 +83,10 @@ int RTFTokenizer::resolveParse()
                     if ((ret = m_rImport.popState()))
                         return ret;
                     if (m_rImport.isSubstream() && m_rImport.getGroup() == 0)
+                    {
+                        m_rImport.finishSubstream();
                         return 0;
+                    }
                     break;
                 case '\\':
                     if ((ret = resolveKeyword()))
commit d80ff1025bf1d3b7dcfea51fb8bea6fde6f84c4f
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 16:00:55 2011 +0200

    ignore RTF_FORMSHADE

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4988e42..97d38a0 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1754,6 +1754,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         case RTF_NOLINE:
             lcl_eraseNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_lnNumType, NS_ooxml::LN_CT_LineNumber_distance);
             break;
+        case RTF_FORMSHADE:
+            // Noop, this is the default in Writer.
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit fa73964707dcea6c8b60bf32f765516aed3a26f1
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 15:43:29 2011 +0200

    implement RTF_NOLINE

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 80ade59..4988e42 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -119,6 +119,16 @@ static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Po
     lcl_putNestedAttribute(rSprms, nParent, nId, pValue, bOverwrite, false);
 }
 
+static bool lcl_eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId)
+{
+    RTFValue::Pointer_t pParent = rSprms.find(nParent);
+    if (!pParent.get())
+        // It doesn't even have a parent, we're done!
+        return false;
+    RTFSprms& rAttributes = pParent->getAttributes();
+    return rAttributes.erase(nId);
+}
+
 static RTFSprms& lcl_getLastAttributes(RTFSprms& rSprms, Id nId)
 {
     RTFValue::Pointer_t p = rSprms.find(nId);
@@ -1741,6 +1751,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
                 lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue);
             }
             break;
+        case RTF_NOLINE:
+            lcl_eraseNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_lnNumType, NS_ooxml::LN_CT_LineNumber_distance);
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit bad3177c55725b6238852eb192a25bb3449f7a54
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 15:13:10 2011 +0200

    the rtf exporter uses RTF_ENDDOC to order footnotes to the end of a chapter

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index d2e1bba..74f6963 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3088,7 +3088,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
                 {
                     case NS_ooxml::LN_Value_ST_RestartNumber_continuous: nFootnoteCounting = text::FootnoteNumbering::PER_DOCUMENT; break;
                     case NS_ooxml::LN_Value_ST_RestartNumber_eachPage: nFootnoteCounting = text::FootnoteNumbering::PER_PAGE; break;
-                    case NS_ooxml::LN_Value_ST_RestartNumber_eachSect: // Writer supports chapters only
+                    case NS_ooxml::LN_Value_ST_RestartNumber_eachSect: nFootnoteCounting = text::FootnoteNumbering::PER_CHAPTER; break;
                     default: break;
                 }
                 xFtnEdnSettings->setPropertyValue(
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 0643547..80ade59 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1732,6 +1732,15 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         case RTF_AFTNRESTART:
             // Noop, Writer does not support restarting endnotes at each section.
             break;
+        case RTF_FTNBJ:
+            // Noop, this is the default in Writer.
+            break;
+        case RTF_ENDDOC:
+            {
+                RTFValue::Pointer_t pValue(new RTFValue(NS_ooxml::LN_Value_ST_RestartNumber_eachSect));
+                lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue);
+            }
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit c8f3ce0a24fddc3eac64dbcecee7da3eafebf251
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 14:59:00 2011 +0200

    rtftok: send footnote numbering types

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 07d287a..0643547 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1460,6 +1460,21 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         return 0;
     }
 
+    // Footnote restart type
+    switch (nKeyword)
+    {
+        case RTF_FTNRSTPG: nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachPage; break;
+        case RTF_FTNRESTART: nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachSect; break;
+        case RTF_FTNRSTCONT: nParam = NS_ooxml::LN_Value_ST_RestartNumber_continuous; break;
+        default: break;
+    }
+    if (nParam >= 0)
+    {
+        RTFValue::Pointer_t pValue(new RTFValue(nParam));
+        lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue);
+        return 0;
+    }
+
     // Endnote numbering
     switch (nKeyword)
     {
commit df10654b1ddf6ca0827eed080cdd8d3ba40b9b07
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 13:35:55 2011 +0200

    dmapper: implement footnote numbering types

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 0b778e5..d2e1bba 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -68,6 +68,7 @@
 #include <com/sun/star/style/LineSpacing.hpp>
 #include <com/sun/star/style/LineSpacingMode.hpp>
 #include <com/sun/star/table/BorderLine2.hpp>
+#include <com/sun/star/text/FootnoteNumbering.hpp>
 #include <com/sun/star/text/TextGridMode.hpp>
 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
@@ -3055,6 +3056,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
     // -> so this property can be ignored
     break;
     case NS_ooxml::LN_EG_FtnEdnNumProps_numStart:
+    case NS_ooxml::LN_EG_FtnEdnNumProps_numRestart:
     case NS_ooxml::LN_CT_FtnProps_numFmt:
     case NS_ooxml::LN_CT_EdnProps_numFmt:
     {
@@ -3079,6 +3081,20 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
                     PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_START_AT),
                                                                     uno::makeAny( sal_Int16( nIntValue - 1 )));
             }
+            else if( NS_ooxml::LN_EG_FtnEdnNumProps_numRestart == nSprmId && xFtnEdnSettings.is())
+            {
+                sal_Int16 nFootnoteCounting = 0;
+                switch (nIntValue)
+                {
+                    case NS_ooxml::LN_Value_ST_RestartNumber_continuous: nFootnoteCounting = text::FootnoteNumbering::PER_DOCUMENT; break;
+                    case NS_ooxml::LN_Value_ST_RestartNumber_eachPage: nFootnoteCounting = text::FootnoteNumbering::PER_PAGE; break;
+                    case NS_ooxml::LN_Value_ST_RestartNumber_eachSect: // Writer supports chapters only
+                    default: break;
+                }
+                xFtnEdnSettings->setPropertyValue(
+                        PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_FOOTNOTE_COUNTING ),
+                        uno::makeAny( nFootnoteCounting ));
+            }
             else if (xFtnEdnSettings.is())
             {
                 sal_Int16 nNumType = ConversionHelper::ConvertNumberingType( nIntValue );
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index 9957ec1..d87d171 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -205,6 +205,7 @@ const rtl::OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
             case PROP_FOOTER_TEXT          :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterText")); break;
             case PROP_FOOTER_IS_SHARED     :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterIsShared")); break;
             case PROP_FOOTER_IS_ON         :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")); break;
+            case PROP_FOOTNOTE_COUNTING    :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")); break;
             case PROP_WIDTH                :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Width")); break;
             case PROP_HEIGHT               :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Height")); break;
             case PROP_SEPARATOR_LINE_IS_ON :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")); break;
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index 057751b..81afa29 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -143,6 +143,7 @@ enum PropertyIds
         ,PROP_FOOTER_IS_SHARED
         ,PROP_FOOTER_TEXT
         ,PROP_FOOTER_TEXT_LEFT
+        ,PROP_FOOTNOTE_COUNTING
         ,PROP_FORMAT
         ,PROP_FULL_NAME
         ,PROP_GAMMA
commit 308df0b438a7318374bf4cee069ef9a134f91e1b
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 12:20:42 2011 +0200

    skip RTF_AFTNRSTCONT and RTF_AFTNRESTART

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c477a1e..07d287a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1711,6 +1711,12 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         case RTF_AENDNOTES:
             // Noop, Writer does not support having endnotes at the end of section.
             break;
+        case RTF_AFTNRSTCONT:
+            // Noop, this is the default in Writer.
+            break;
+        case RTF_AFTNRESTART:
+            // Noop, Writer does not support restarting endnotes at each section.
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit 4ace48121084a3225ab204203684a9bf0567ddef
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 11:09:09 2011 +0200

    implement footnote numbering types

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 070af20..c477a1e 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1442,6 +1442,24 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         return 0;
     }
 
+    // Footnote numbering
+    switch (nKeyword)
+    {
+        case RTF_FTNNAR: nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal; break;
+        case RTF_FTNNALC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter; break;
+        case RTF_FTNNAUC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter; break;
+        case RTF_FTNNRLC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman; break;
+        case RTF_FTNNRUC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman; break;
+        case RTF_FTNNCHI: nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago; break;
+        default: break;
+    }
+    if (nParam >= 0)
+    {
+        RTFValue::Pointer_t pValue(new RTFValue(nParam));
+        lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_CT_FtnProps_numFmt, pValue);
+        return 0;
+    }
+
     // Endnote numbering
     switch (nKeyword)
     {
commit 5a38c231cc31f1fb7d7173898bf910a503285572
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 10:22:41 2011 +0200

    implement RTF_FTNSTART

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 5f19480..0b778e5 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3064,7 +3064,8 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
             if( m_pImpl->IsInFootnoteProperties() )
             {
                 uno::Reference< text::XFootnotesSupplier> xFootnotesSupplier( m_pImpl->GetTextDocument(), uno::UNO_QUERY );
-                xFtnEdnSettings = xFootnotesSupplier->getFootnoteSettings();
+                if (xFootnotesSupplier.is())
+                    xFtnEdnSettings = xFootnotesSupplier->getFootnoteSettings();
             }
             else
             {
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 8a5ae8c..070af20 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2250,6 +2250,9 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         case RTF_VERN:
             // Ignore this for now, later the RTF writer version could be used to add hacks for older buggy writers.
             break;
+        case RTF_FTNSTART:
+            lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
+            break;
         case RTF_AFTNSTART:
             lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
             break;
commit 8d4a0dbc11027f263f5b5c58bd277eef37c42f1c
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 10:14:27 2011 +0200

    it's enough to set these as a default sprm

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 456fe38..8a5ae8c 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1456,7 +1456,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     if (nParam >= 0)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
-        lcl_putNestedSprm(m_aSettingsTableSprms, NS_ooxml::LN_CT_Settings_endnotePr, NS_ooxml::LN_CT_EdnProps_numFmt, pValue);
         lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_CT_EdnProps_numFmt, pValue);
         return 0;
     }
@@ -2252,7 +2251,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
             // Ignore this for now, later the RTF writer version could be used to add hacks for older buggy writers.
             break;
         case RTF_AFTNSTART:
-            lcl_putNestedSprm(m_aSettingsTableSprms, NS_ooxml::LN_CT_Settings_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
             lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
             break;
         default:
commit da8f7be84f07857b7c3a0b01dd388741f547a505
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Thu Aug 11 10:10:26 2011 +0200

    implement RTF_AFTNSTART

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 919cf12..456fe38 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2251,6 +2251,10 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         case RTF_VERN:
             // Ignore this for now, later the RTF writer version could be used to add hacks for older buggy writers.
             break;
+        case RTF_AFTNSTART:
+            lcl_putNestedSprm(m_aSettingsTableSprms, NS_ooxml::LN_CT_Settings_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
+            lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue);
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle value '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit d7d9d3a74400889fc8dc7222a86160f9375b1253
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 20:14:02 2011 +0200

    implement endnote numbering types

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index f3c679c..5f19480 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3069,15 +3069,16 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
             else
             {
                 uno::Reference< text::XEndnotesSupplier> xEndnotesSupplier( m_pImpl->GetTextDocument(), uno::UNO_QUERY );
-                xFtnEdnSettings = xEndnotesSupplier->getEndnoteSettings();
+                if (xEndnotesSupplier.is())
+                    xFtnEdnSettings = xEndnotesSupplier->getEndnoteSettings();
             }
-            if( NS_ooxml::LN_EG_FtnEdnNumProps_numStart == nSprmId )
+            if( NS_ooxml::LN_EG_FtnEdnNumProps_numStart == nSprmId && xFtnEdnSettings.is())
             {
                 xFtnEdnSettings->setPropertyValue(
                     PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_START_AT),
                                                                     uno::makeAny( sal_Int16( nIntValue - 1 )));
             }
-            else
+            else if (xFtnEdnSettings.is())
             {
                 sal_Int16 nNumType = ConversionHelper::ConvertNumberingType( nIntValue );
                 xFtnEdnSettings->setPropertyValue(
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4f988b2..919cf12 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1442,6 +1442,25 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         return 0;
     }
 
+    // Endnote numbering
+    switch (nKeyword)
+    {
+        case RTF_AFTNNAR: nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal; break;
+        case RTF_AFTNNALC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter; break;
+        case RTF_AFTNNAUC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter; break;
+        case RTF_AFTNNRLC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman; break;
+        case RTF_AFTNNRUC: nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman; break;
+        case RTF_AFTNNCHI: nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago; break;
+        default: break;
+    }
+    if (nParam >= 0)
+    {
+        RTFValue::Pointer_t pValue(new RTFValue(nParam));
+        lcl_putNestedSprm(m_aSettingsTableSprms, NS_ooxml::LN_CT_Settings_endnotePr, NS_ooxml::LN_CT_EdnProps_numFmt, pValue);
+        lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_CT_EdnProps_numFmt, pValue);
+        return 0;
+    }
+
     // Trivial paragraph flags
     switch (nKeyword)
     {
commit 53b709286c270945d3093b83b5f55f996bd1dce2
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 19:12:03 2011 +0200

    skip RTF_AENDDOC and RTF_AENDNOTES

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 95b9772..4f988b2 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1669,6 +1669,12 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
                         NS_ooxml::LN_EG_SectPrContents_lnNumType, NS_ooxml::LN_CT_LineNumber_restart, pValue);
             }
             break;
+        case RTF_AENDDOC:
+            // Noop, this is the default in Writer.
+            break;
+        case RTF_AENDNOTES:
+            // Noop, Writer does not support having endnotes at the end of section.
+            break;
         default:
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
commit 7c9156d9c5e6f4ea2af9131382c67810165da8fb
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 18:43:08 2011 +0200

    implement the RTF_FALT destination

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index eb841c9..95b9772 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -748,6 +748,7 @@ void RTFDocumentImpl::text(OUString& rString)
         case DESTINATION_OBJDATA:
         case DESTINATION_ANNOTATIONDATE:
         case DESTINATION_ANNOTATIONAUTHOR:
+        case DESTINATION_FALT:
             m_aStates.top().aDestinationText.append(rString);
             break;
         case DESTINATION_EQINSTRUCTION:
@@ -1132,6 +1133,9 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
         case RTF_ATNAUTHOR:
             m_aStates.top().nDestinationState = DESTINATION_ANNOTATIONAUTHOR;
             break;
+        case RTF_FALT:
+            m_aStates.top().nDestinationState = DESTINATION_FALT;
+            break;
         case RTF_LISTTEXT:
             // Should be ignored by any reader that understands Word 97 through Word 2007 numbering.
         case RTF_NONESTTABLES:
@@ -2341,6 +2345,7 @@ int RTFDocumentImpl::pushState()
     else
         aState = m_aStates.top();
     m_aStates.push(aState);
+    m_aStates.top().aDestinationText.setLength(0);
 
     m_nGroup++;
 
@@ -2420,6 +2425,7 @@ int RTFDocumentImpl::popState()
     RTFShape aShape;
     bool bPopShapeProperties = false;
     bool bPopPictureProperties = false;
+    bool bFaltEnd = false;
 
     if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE)
     {
@@ -2725,6 +2731,14 @@ int RTFDocumentImpl::popState()
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_ANNOTATIONAUTHOR)
         m_aAuthor = m_aStates.top().aDestinationText.makeStringAndClear();
+    else if (m_aStates.top().nDestinationState == DESTINATION_FALT)
+    {
+        OUString aStr(m_aStates.top().aDestinationText.makeStringAndClear());
+        RTFValue::Pointer_t pValue(new RTFValue(aStr));
+        m_aStates.top().aTableSprms->push_back(make_pair(NS_ooxml::LN_CT_Font_altName, pValue));
+        aSprms = m_aStates.top().aTableSprms;
+        bFaltEnd = true;
+    }
 
     // See if we need to end a track change
     RTFValue::Pointer_t pTrackchange = m_aStates.top().aCharacterSprms.find(NS_ooxml::LN_trackchange);
@@ -2775,6 +2789,8 @@ int RTFDocumentImpl::popState()
         m_aStates.top().aShape = aShape;
         m_aStates.top().aCharacterAttributes = aAttributes;
     }
+    else if (bFaltEnd)
+        m_aStates.top().aTableSprms = aSprms;
     if (bPopPictureProperties)
         m_aStates.top().aCharacterAttributes = aAttributes;
     if (m_pCurrentBuffer == &m_aSuperBuffer)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 411bfe2..958c8d5 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -111,7 +111,8 @@ namespace writerfilter {
             DESTINATION_OBJDATA,
             DESTINATION_RESULT,
             DESTINATION_ANNOTATIONDATE,
-            DESTINATION_ANNOTATIONAUTHOR
+            DESTINATION_ANNOTATIONAUTHOR,
+            DESTINATION_FALT
         };
 
         enum RTFBorderState
commit 6751324082ca472b9a34caabdd0a1032c27438b9
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 18:35:54 2011 +0200

    Move destination text to RTFParserState
    
    For example a font name may be interrupted by an RTF_FALT destination
    anytime.

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 1844726..eb841c9 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -495,7 +495,7 @@ int RTFDocumentImpl::resolvePict(bool bInline)
     int b = 0, count = 2;
 
     // Feed the destination text to a stream.
-    OString aStr = OUStringToOString(m_aDestinationText.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
+    OString aStr = OUStringToOString(m_aStates.top().aDestinationText.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
     const char *str = aStr.getStr();
     for (int i = 0; i < aStr.getLength(); ++i)
     {
@@ -692,7 +692,7 @@ void RTFDocumentImpl::text(OUString& rString)
                     rString = rString.copy(0, rString.getLength() - 1);
                     bEnd = true;
                 }
-                m_aDestinationText.append(rString);
+                m_aStates.top().aDestinationText.append(rString);
                 if (bEnd)
                 {
                     switch (m_aStates.top().nDestinationState)
@@ -700,7 +700,7 @@ void RTFDocumentImpl::text(OUString& rString)
                         case DESTINATION_FONTTABLE:
                         case DESTINATION_FONTENTRY:
                             {
-                                RTFValue::Pointer_t pValue(new RTFValue(m_aDestinationText.makeStringAndClear()));
+                                RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
                                 m_aStates.top().aTableAttributes->push_back(make_pair(NS_rtf::LN_XSZFFN, pValue));
 
                                 writerfilter::Reference<Properties>::Pointer_t const pProp(
@@ -712,7 +712,7 @@ void RTFDocumentImpl::text(OUString& rString)
                         case DESTINATION_STYLESHEET:
                         case DESTINATION_STYLEENTRY:
                             {
-                                RTFValue::Pointer_t pValue(new RTFValue(m_aDestinationText.makeStringAndClear()));
+                                RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
                                 m_aStates.top().aTableAttributes->push_back(make_pair(NS_rtf::LN_XSTZNAME1, pValue));
 
                                 writerfilter::Reference<Properties>::Pointer_t const pProp(
@@ -723,7 +723,7 @@ void RTFDocumentImpl::text(OUString& rString)
                             break;
                         case DESTINATION_REVISIONTABLE:
                         case DESTINATION_REVISIONENTRY:
-                            m_aAuthors[m_aAuthors.size()] = m_aDestinationText.makeStringAndClear();
+                            m_aAuthors[m_aAuthors.size()] = m_aStates.top().aDestinationText.makeStringAndClear();
                             break;
                         default: break;
                     }
@@ -748,7 +748,7 @@ void RTFDocumentImpl::text(OUString& rString)
         case DESTINATION_OBJDATA:
         case DESTINATION_ANNOTATIONDATE:
         case DESTINATION_ANNOTATIONAUTHOR:
-            m_aDestinationText.append(rString);
+            m_aStates.top().aDestinationText.append(rString);
             break;
         case DESTINATION_EQINSTRUCTION:
             if (rString.copy(0, 2).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("do"))
@@ -786,7 +786,7 @@ void RTFDocumentImpl::text(OUString& rString)
     // Don't return earlier, a bookmark start has to be in a paragraph group.
     if (m_aStates.top().nDestinationState == DESTINATION_BOOKMARKSTART)
     {
-        m_aDestinationText.append(rString);
+        m_aStates.top().aDestinationText.append(rString);
         return;
     }
 
@@ -2496,7 +2496,7 @@ int RTFDocumentImpl::popState()
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_LEVELTEXT)
     {
-        OUString aStr = m_aDestinationText.makeStringAndClear();
+        OUString aStr = m_aStates.top().aDestinationText.makeStringAndClear();
 
         // The first character is the length of the string (the rest should be ignored).
         sal_Int32 nLength(aStr.toChar());
@@ -2536,9 +2536,9 @@ int RTFDocumentImpl::popState()
         aShape = m_aStates.top().aShape;
         aAttributes = m_aStates.top().aCharacterAttributes;
         if (m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTYNAME)
-            aShape.aProperties.push_back(make_pair(m_aDestinationText.makeStringAndClear(), OUString()));
+            aShape.aProperties.push_back(make_pair(m_aStates.top().aDestinationText.makeStringAndClear(), OUString()));
         else if (m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTYVALUE && aShape.aProperties.size())
-            aShape.aProperties.back().second = m_aDestinationText.makeStringAndClear();
+            aShape.aProperties.back().second = m_aStates.top().aDestinationText.makeStringAndClear();
         bPopShapeProperties = true;
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_PICPROP
@@ -2549,13 +2549,13 @@ int RTFDocumentImpl::popState()
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_BOOKMARKSTART)
     {
-        OUString aStr = m_aDestinationText.makeStringAndClear();
+        OUString aStr = m_aStates.top().aDestinationText.makeStringAndClear();
         int nPos = m_aBookmarks.size();
         m_aBookmarks[aStr] = nPos;
         Mapper().props(lcl_getBookmarkProperties(nPos, aStr));
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_BOOKMARKEND)
-        Mapper().props(lcl_getBookmarkProperties(m_aBookmarks[m_aDestinationText.makeStringAndClear()]));
+        Mapper().props(lcl_getBookmarkProperties(m_aBookmarks[m_aStates.top().aDestinationText.makeStringAndClear()]));
     else if (m_aStates.top().nDestinationState == DESTINATION_PICT)
         resolvePict(true);
     else if (m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTYVALUEPICT)
@@ -2567,17 +2567,17 @@ int RTFDocumentImpl::popState()
         m_pCurrentBuffer = 0; // Just disable buffering, don't empty it yet.
     else if (m_aStates.top().nDestinationState == DESTINATION_FORMFIELDNAME)
     {
-        RTFValue::Pointer_t pValue(new RTFValue(m_aDestinationText.makeStringAndClear()));
+        RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
         m_aFormfieldSprms->push_back(make_pair(NS_ooxml::LN_CT_FFData_name, pValue));
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_FORMFIELDLIST)
     {
-        RTFValue::Pointer_t pValue(new RTFValue(m_aDestinationText.makeStringAndClear()));
+        RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
         m_aFormfieldSprms->push_back(make_pair(NS_ooxml::LN_CT_FFDDList_listEntry, pValue));
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_DATAFIELD)
     {
-        OString aStr = OUStringToOString(m_aDestinationText.makeStringAndClear(), m_aStates.top().nCurrentEncoding);
+        OString aStr = OUStringToOString(m_aStates.top().aDestinationText.makeStringAndClear(), m_aStates.top().nCurrentEncoding);
         // decode hex dump
         OStringBuffer aBuf;
         const char *str = aStr.getStr();
@@ -2626,9 +2626,9 @@ int RTFDocumentImpl::popState()
     else if (m_aStates.top().nDestinationState == DESTINATION_PRINTTIME && m_xDocumentProperties.is())
         m_xDocumentProperties->setPrintDate(lcl_getDateTime(m_aStates));
     else if (m_aStates.top().nDestinationState == DESTINATION_AUTHOR && m_xDocumentProperties.is())
-        m_xDocumentProperties->setAuthor(m_aDestinationText.makeStringAndClear());
+        m_xDocumentProperties->setAuthor(m_aStates.top().aDestinationText.makeStringAndClear());
     else if (m_aStates.top().nDestinationState == DESTINATION_COMMENT && m_xDocumentProperties.is())
-        m_xDocumentProperties->setGenerator(m_aDestinationText.makeStringAndClear());
+        m_xDocumentProperties->setGenerator(m_aStates.top().aDestinationText.makeStringAndClear());
     else if (m_aStates.top().nDestinationState == DESTINATION_OPERATOR
             || m_aStates.top().nDestinationState == DESTINATION_COMPANY)
     {
@@ -2638,7 +2638,7 @@ int RTFDocumentImpl::popState()
         {
             uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = m_xDocumentProperties->getUserDefinedProperties();
             xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVEABLE,
-                    uno::makeAny(m_aDestinationText.makeStringAndClear()));
+                    uno::makeAny(m_aStates.top().aDestinationText.makeStringAndClear()));
         }
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_OBJDATA)
@@ -2647,7 +2647,7 @@ int RTFDocumentImpl::popState()
         int b = 0, count = 2;
 
         // Feed the destination text to a stream.
-        OString aStr = OUStringToOString(m_aDestinationText.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
+        OString aStr = OUStringToOString(m_aStates.top().aDestinationText.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
         const char *str = aStr.getStr();
         for (int i = 0; i < aStr.getLength(); ++i)
         {
@@ -2715,7 +2715,7 @@ int RTFDocumentImpl::popState()
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_ANNOTATIONDATE)
     {
-        OUString aStr(OStringToOUString(lcl_DTTM22OString(m_aDestinationText.makeStringAndClear().toInt32()),
+        OUString aStr(OStringToOUString(lcl_DTTM22OString(m_aStates.top().aDestinationText.makeStringAndClear().toInt32()),
                     m_aStates.top().nCurrentEncoding));
         RTFValue::Pointer_t pValue(new RTFValue(aStr));
         RTFSprms aAnnAttributes;
@@ -2724,7 +2724,7 @@ int RTFDocumentImpl::popState()
         Mapper().props(pProperties);
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_ANNOTATIONAUTHOR)
-        m_aAuthor = m_aDestinationText.makeStringAndClear();
+        m_aAuthor = m_aStates.top().aDestinationText.makeStringAndClear();
 
     // See if we need to end a track change
     RTFValue::Pointer_t pTrackchange = m_aStates.top().aCharacterSprms.find(NS_ooxml::LN_trackchange);
@@ -2815,8 +2815,8 @@ bool RTFDocumentImpl::isEmpty()
 
 void RTFDocumentImpl::setDestinationText(OUString& rString)
 {
-    m_aDestinationText.setLength(0);
-    m_aDestinationText.append(rString);
+    m_aStates.top().aDestinationText.setLength(0);
+    m_aStates.top().aDestinationText.append(rString);
 }
 
 void RTFDocumentImpl::replayShapetext()
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index da48316..411bfe2 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -246,6 +246,9 @@ namespace writerfilter {
                 int nDay;
                 int nHour;
                 int nMinute;
+
+                /// Text from special destinations.
+                rtl::OUStringBuffer aDestinationText;
         };
 
         class RTFTokenizer;
@@ -368,8 +371,6 @@ namespace writerfilter {
                 std::map<int, rtl::OUString> m_aAuthors;
                 /// Annotation author of the next annotation.
                 rtl::OUString m_aAuthor;
-                /// Text from special destinations.
-                rtl::OUStringBuffer m_aDestinationText;
 
                 RTFSprms m_aFormfieldSprms;
                 RTFSprms m_aFormfieldAttributes;
commit 3721e245b424ea1645174fb9321c0216204ad9b7
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 17:02:47 2011 +0200

    RTFDocumentImpl: avoid raw pointers

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 1210b37..1844726 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -273,7 +273,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_aObjectSprms(),
     m_aObjectAttributes(),
     m_bObject(false),
-    m_pObjectData(0),
     m_aFontTableEntries(),
     m_nCurrentFontIndex(0),
     m_aStyleTableEntries(),
@@ -291,14 +290,12 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
 
     m_pGraphicHelper = new oox::GraphicHelper(m_xContext, xFrame, m_xStorage);
 
-    m_pTokenizer = new RTFTokenizer(*this, m_pInStream);
-    m_pSdrImport = new RTFSdrImport(*this, m_xDstDoc);
+    m_pTokenizer.reset(new RTFTokenizer(*this, m_pInStream));
+    m_pSdrImport.reset(new RTFSdrImport(*this, m_xDstDoc));
 }
 
 RTFDocumentImpl::~RTFDocumentImpl()
 {
-    delete m_pTokenizer;
-    delete m_pSdrImport;
 }
 
 SvStream& RTFDocumentImpl::Strm()
@@ -2646,7 +2643,7 @@ int RTFDocumentImpl::popState()
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_OBJDATA)
     {
-        m_pObjectData = new SvMemoryStream();
+        m_pObjectData.reset(new SvMemoryStream());
         int b = 0, count = 2;
 
         // Feed the destination text to a stream.
@@ -2689,7 +2686,7 @@ int RTFDocumentImpl::popState()
             *m_pObjectData >> nData; // NativeDataSize
         }
 
-        uno::Reference<io::XInputStream> xInputStream(new utl::OInputStreamWrapper(m_pObjectData));
+        uno::Reference<io::XInputStream> xInputStream(new utl::OInputStreamWrapper(m_pObjectData.get()));
         RTFValue::Pointer_t pStreamValue(new RTFValue(xInputStream));
 
         RTFSprms aOLEAttributes;
@@ -2714,11 +2711,6 @@ int RTFDocumentImpl::popState()
         Mapper().endShape();
         m_aObjectAttributes->clear();
         m_aObjectSprms->clear();
-        if (m_pObjectData)
-        {
-            delete m_pObjectData;
-            m_pObjectData = 0;
-        }
         m_bObject = false;
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_ANNOTATIONDATE)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index f5506cd..da48316 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -321,8 +321,8 @@ namespace writerfilter {
                 com::sun::star::uno::Reference<com::sun::star::document::XDocumentProperties> m_xDocumentProperties;
                 SvStream* m_pInStream;
                 Stream* m_pMapperStream;
-                RTFSdrImport* m_pSdrImport;
-                RTFTokenizer* m_pTokenizer;
+                boost::shared_ptr<RTFSdrImport> m_pSdrImport;
+                boost::shared_ptr<RTFTokenizer> m_pTokenizer;
                 /// Same as m_aStates.size(), except that this can be negative for invalid input.
                 int m_nGroup;
                 std::stack<RTFParserState> m_aStates;
@@ -379,8 +379,8 @@ namespace writerfilter {
                 RTFSprms m_aObjectAttributes;
                 /// If we are in an object group.
                 bool m_bObject;
-                /// Contents of the objdata group, stored here so we can delete it when we leave the object group.
-                SvStream* m_pObjectData;
+                /// Contents of the objdata group.
+                boost::shared_ptr<SvStream> m_pObjectData;
 
                 RTFReferenceTable::Entries_t m_aFontTableEntries;
                 int m_nCurrentFontIndex;
commit 41430f10267643eefb7163682b30b12c4ff24911
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 16:40:39 2011 +0200

    RTFValue: avoid raw pointers

diff --git a/writerfilter/source/rtftok/rtfvalue.cxx b/writerfilter/source/rtftok/rtfvalue.cxx
index 961f6d7..0469adc 100644
--- a/writerfilter/source/rtftok/rtfvalue.cxx
+++ b/writerfilter/source/rtftok/rtfvalue.cxx
@@ -45,8 +45,8 @@ RTFValue::RTFValue(int nValue, rtl::OUString sValue, RTFSprms rAttributes,
     m_rStream(rStream),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms(rAttributes);
-    m_pSprms = new RTFSprms(rSprms);
+    m_pAttributes.reset(new RTFSprms(rAttributes));
+    m_pSprms.reset(new RTFSprms(rSprms));
 }
 
 RTFValue::RTFValue(int nValue)
@@ -56,8 +56,8 @@ RTFValue::RTFValue(int nValue)
     m_rStream(),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms();
-    m_pSprms = new RTFSprms();
+    m_pAttributes.reset(new RTFSprms());
+    m_pSprms.reset(new RTFSprms());
 }
 
 RTFValue::RTFValue(OUString sValue, bool bForce)
@@ -67,8 +67,8 @@ RTFValue::RTFValue(OUString sValue, bool bForce)
     m_rStream(),
     m_bForceString(bForce)
 {
-    m_pAttributes = new RTFSprms();
-    m_pSprms = new RTFSprms();
+    m_pAttributes.reset(new RTFSprms());
+    m_pSprms.reset(new RTFSprms());
 }
 
 RTFValue::RTFValue(RTFSprms rAttributes)
@@ -78,8 +78,8 @@ RTFValue::RTFValue(RTFSprms rAttributes)
     m_rStream(),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms(rAttributes);
-    m_pSprms = new RTFSprms();
+    m_pAttributes.reset(new RTFSprms(rAttributes));
+    m_pSprms.reset(new RTFSprms());
 }
 
 RTFValue::RTFValue(RTFSprms rAttributes, RTFSprms rSprms)
@@ -89,8 +89,8 @@ RTFValue::RTFValue(RTFSprms rAttributes, RTFSprms rSprms)
     m_rStream(),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms(rAttributes);
-    m_pSprms = new RTFSprms(rSprms);
+    m_pAttributes.reset(new RTFSprms(rAttributes));
+    m_pSprms.reset(new RTFSprms(rSprms));
 }
 
 RTFValue::RTFValue(uno::Reference<drawing::XShape> rShape)
@@ -100,8 +100,8 @@ RTFValue::RTFValue(uno::Reference<drawing::XShape> rShape)
     m_rStream(),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms();
-    m_pSprms = new RTFSprms();
+    m_pAttributes.reset(new RTFSprms());
+    m_pSprms.reset(new RTFSprms());
 }
 
 RTFValue::RTFValue(uno::Reference<io::XInputStream> rStream)
@@ -111,14 +111,12 @@ RTFValue::RTFValue(uno::Reference<io::XInputStream> rStream)
     m_rStream(rStream),
     m_bForceString(false)
 {
-    m_pAttributes = new RTFSprms();
-    m_pSprms = new RTFSprms();
+    m_pAttributes.reset(new RTFSprms());
+    m_pSprms.reset(new RTFSprms());
 }
 
 RTFValue::~RTFValue()
 {
-    delete m_pAttributes;
-    delete m_pSprms;
 }
 
 int RTFValue::getInt() const
diff --git a/writerfilter/source/rtftok/rtfvalue.hxx b/writerfilter/source/rtftok/rtfvalue.hxx
index db9005f..b83340e 100644
--- a/writerfilter/source/rtftok/rtfvalue.hxx
+++ b/writerfilter/source/rtftok/rtfvalue.hxx
@@ -42,7 +42,7 @@ namespace writerfilter {
             : public Value
         {
             public:
-                typedef ::boost::shared_ptr<RTFValue> Pointer_t;
+                typedef boost::shared_ptr<RTFValue> Pointer_t;
                 RTFValue(int nValue, rtl::OUString sValue, RTFSprms rAttributes, RTFSprms rSprms, uno::Reference<drawing::XShape> rShape,
                         uno::Reference<io::XInputStream> rStream);
                 RTFValue(int nValue);
@@ -66,8 +66,8 @@ namespace writerfilter {
             private:
                 int m_nValue;
                 rtl::OUString m_sValue;
-                RTFSprms* m_pAttributes;
-                RTFSprms* m_pSprms;
+                boost::shared_ptr<RTFSprms> m_pAttributes;
+                boost::shared_ptr<RTFSprms> m_pSprms;
                 uno::Reference<drawing::XShape> m_rShape;
                 uno::Reference<io::XInputStream> m_rStream;
                 bool m_bForceString;
commit e20a75a4f3b991f78d67bc333b23d2a9fa9c1470
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 13:33:00 2011 +0200

    dmapper: implement PAGEREF field

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index e9663be..f3c679c 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -70,6 +70,7 @@
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <com/sun/star/text/TextGridMode.hpp>
 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
+#include <com/sun/star/text/XTextFieldsSupplier.hpp>
 #include <com/sun/star/text/WritingMode.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
 #include <com/sun/star/text/XFootnote.hpp>
@@ -166,6 +167,17 @@ DomainMapper::~DomainMapper()
             uno::Reference< container::XIndexAccess > xIndexes = xIndexesSupplier->getDocumentIndexes();
             nIndexes = xIndexes->getCount();
         }
+        // If we have page references, those need updating as well, similar to the indexes.
+        uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(m_pImpl->GetTextDocument(), uno::UNO_QUERY);
+        if(xTextFieldsSupplier.is())
+        {
+            uno::Reference<container::XEnumeration> xEnumeration = xTextFieldsSupplier->getTextFields()->createEnumeration();
+            while(xEnumeration->hasMoreElements())
+            {
+                ++nIndexes;
+                xEnumeration->nextElement();
+            }
+        }
         if( nIndexes )
         {
             //index update has to wait until first view is created
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 491ef0b..bb5ff80 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1900,6 +1900,7 @@ if(!bFilled)
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXT")),          "DatabaseNextSet",          "", FIELD_NEXT         },
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXTIF")),        "DatabaseNextSet",          "", FIELD_NEXTIF       },
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PAGE")),          "PageNumber",               "", FIELD_PAGE         },
+            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PAGEREF")),       "GetReference",             "", FIELD_PAGEREF      },
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REF")),           "GetReference",             "", FIELD_REF          },
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REVNUM")),        "DocInfo.Revision",         "", FIELD_REVNUM       },
             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SAVEDATE")),      "DocInfo.Change",           "", FIELD_SAVEDATE     },
@@ -2706,16 +2707,19 @@ void DomainMapper_Impl::CloseFieldCommand()
                         }
 
                     break;
+                    case FIELD_PAGEREF:
                     case FIELD_REF:
                     {
-                        ::rtl::OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" REF") );
+                        bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
+                        ::rtl::OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(),
+                                (bPageRef ? sizeof(" PAGEREF") : sizeof(" REF")));
                         xFieldProperties->setPropertyValue(
                             rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
                             uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
                         xFieldProperties->setPropertyValue(
                             rPropNameSupplier.GetName(PROP_SOURCE_NAME),
                             uno::makeAny( sBookmark) );
-                        sal_Int16 nFieldPart = text::ReferenceFieldPart::TEXT;
+                        sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT);
                         ::rtl::OUString sValue;
                         if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
                         {
diff --git a/writerfilter/source/dmapper/FieldTypes.hxx b/writerfilter/source/dmapper/FieldTypes.hxx
index a16c808..bb765f5 100644
--- a/writerfilter/source/dmapper/FieldTypes.hxx
+++ b/writerfilter/source/dmapper/FieldTypes.hxx
@@ -171,6 +171,7 @@ enum FieldId
      see lcl_ParseNumberingType
      */
     ,FIELD_PAGE
+    ,FIELD_PAGEREF
     /* REF targetbkm \f \* MERGEFORMAT ->
         imports a ShowVariable (bookmarkname)?
         \h hyerlink to paragraph
diff --git a/writerfilter/source/dmapper/ModelEventListener.cxx b/writerfilter/source/dmapper/ModelEventListener.cxx
index c151c50..e86aa01 100644
--- a/writerfilter/source/dmapper/ModelEventListener.cxx
+++ b/writerfilter/source/dmapper/ModelEventListener.cxx
@@ -26,9 +26,15 @@
  *
  ************************************************************************/
 #include <ModelEventListener.hxx>
+#include <PropertyIds.hxx>
 #include <com/sun/star/document/XEventBroadcaster.hpp>
 #include <com/sun/star/text/XDocumentIndex.hpp>
 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
+#include <com/sun/star/text/XTextFieldsSupplier.hpp>
+#include <com/sun/star/util/XRefreshable.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/text/ReferenceFieldPart.hpp>
+#include <com/sun/star/text/ReferenceFieldSource.hpp>
 
 namespace writerfilter {
 namespace dmapper {
@@ -54,6 +60,8 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) thro
     {
         try
         {
+            PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
+
             uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( rEvent.Source, uno::UNO_QUERY );
             //remove listener
             uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
@@ -67,6 +75,26 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) thro
                 uno::Reference< text::XDocumentIndex> xIndex( xIndexes->getByIndex( nIndex ), uno::UNO_QUERY );
                 xIndex->update();
             }
+
+            // If we have PAGEREF fields, update fields as well.
+            uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY);
+            uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY);
+            sal_Int32 nIndex = 0;
+            while(xEnumeration->hasMoreElements())
+            {
+                uno::Reference<beans::XPropertySet> xPropertySet(xEnumeration->nextElement(), uno::UNO_QUERY);
+                sal_Int16 nSource;
+                xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE)) >>= nSource;
+                sal_Int16 nPart;
+                xPropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_PART)) >>= nPart;
+                if (nSource == text::ReferenceFieldSource::BOOKMARK && nPart == text::ReferenceFieldPart::PAGE)
+                    ++nIndex;
+            }
+            if (nIndex)
+            {
+                uno::Reference<util::XRefreshable> xRefreshable(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY);
+                xRefreshable->refresh();
+            }
         }
         catch( const uno::Exception& rEx )
         {
commit ed7b24e4d563dc80be4409d717009a05c9be099a
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Wed Aug 10 11:44:04 2011 +0200

    Fix page numbers
    
    I broke that in commit 5338fee30bef0eeeedb768220713641b3d1536fe

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4c983d1..491ef0b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2941,7 +2941,7 @@ void DomainMapper_Impl::PopFieldContext()
         //insert the field, TC or TOC
         uno::Reference< text::XTextAppend >  xTextAppend;
         if (!m_aTextAppendStack.empty())
-            m_aTextAppendStack.top().xTextAppend;
+            xTextAppend = m_aTextAppendStack.top().xTextAppend;
         if(xTextAppend.is())
         {
             try
commit e7253c562ef2fb52ff2d2f8da4595aaf87264ecd
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 23:43:55 2011 +0200

    use RTFSkipDestination instead of skipDestination()

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 84cafa5..1210b37 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -53,6 +53,7 @@
 #include <rtfvalue.hxx>
 #include <rtfsprm.hxx>
 #include <rtfreferenceproperties.hxx>
+#include <rtfskipdestination.hxx>
 
 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
 
@@ -875,7 +876,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer)
 
 int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
 {
-    bool bParsed = true;
+    RTFSkipDestination aSkip(*this);
     switch (nKeyword)
     {
         case RTF_RTF:
@@ -1146,17 +1147,16 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
 #endif
             // Make sure we skip destinations (even without \*) till we don't handle them
             m_aStates.top().nDestinationState = DESTINATION_SKIP;
-            bParsed = false;
+            aSkip.setParsed(false);
             break;
     }
 
-    skipDestination(bParsed);
     return 0;
 }
 
 int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 {
-    bool bParsed = true;
+    RTFSkipDestination aSkip(*this);
     sal_uInt8 cCh = 0;
 
     // Trivial symbols
@@ -1180,7 +1180,6 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
     {
         OUString aStr(OStringToOUString(OString(cCh), RTL_TEXTENCODING_MS_1252));
         text(aStr);
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1188,7 +1187,8 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
     {
         case RTF_IGNORE:
             m_bSkipUnknown = true;
-            return 0; // don't reset m_bSkipUnknown after this keyword
+            aSkip.setReset(false);
+            return 0;
             break;
         case RTF_PAR:
             {
@@ -1316,16 +1316,15 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle symbol '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
 #endif
-            bParsed = false;
+            aSkip.setParsed(false);
             break;
     }
-    skipDestination(bParsed);
     return 0;
 }
 
 int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
 {
-    bool bParsed = true;
+    RTFSkipDestination aSkip(*this);
     int nParam = -1;
 
     // Indentation
@@ -1342,7 +1341,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aParagraphSprms->push_back(make_pair(NS_sprm::LN_PJc, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1361,7 +1359,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aParagraphSprms->push_back(make_pair(NS_sprm::LN_PWAlignFont, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1377,7 +1374,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aTabAttributes->push_back(make_pair(NS_ooxml::LN_CT_TabStop_val, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1396,7 +1392,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aTabAttributes->push_back(make_pair(NS_ooxml::LN_CT_TabStop_leader, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1426,7 +1421,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         lcl_putBorderProperty(m_aStates, NS_rtf::LN_BRCTYPE, pValue);
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1444,7 +1438,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aSectionSprms->push_back(make_pair(NS_sprm::LN_SBkc, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1462,7 +1455,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         RTFValue::Pointer_t pValue(new RTFValue(1));
         m_aStates.top().aParagraphSprms.erase(NS_sprm::LN_PFInTable);
         m_aStates.top().aParagraphSprms->push_back(make_pair(nParam, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1680,16 +1672,15 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
 #endif
-            bParsed = false;
+            aSkip.setParsed(false);
             break;
     }
-    skipDestination(bParsed);
     return 0;
 }
 
 int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
 {
-    bool bParsed = true;
+    RTFSkipDestination aSkip(*this);
     int nSprm = 0;
     RTFValue::Pointer_t pIntValue(new RTFValue(nParam));
     // Trivial table sprms.
@@ -1704,7 +1695,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     if (nSprm > 0)
     {
         m_aStates.top().aTableSprms->push_back(make_pair(nSprm, pIntValue));
-        skipDestination(bParsed);
         return 0;
     }
     // Trivial character sprms.
@@ -1724,7 +1714,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     if (nSprm > 0)
     {
         m_aStates.top().aCharacterSprms->push_back(make_pair(nSprm, pIntValue));
-        skipDestination(bParsed);
         return 0;
     }
     // Trivial paragraph sprms.
@@ -1743,7 +1732,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     if (nSprm > 0)
     {
         m_aStates.top().aParagraphSprms->push_back(make_pair(nSprm, pIntValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1757,7 +1745,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     if (nSprm > 0)
     {
         m_aStates.top().aTableAttributes->push_back(make_pair(nSprm, pIntValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1772,7 +1759,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     {
         RTFValue::Pointer_t pValue(new RTFValue(nParam));
         m_aStates.top().aCharacterAttributes->push_back(make_pair(nSprm, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -1787,10 +1773,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         default: break;
     }
     if (nSprm > 0)
-    {
-        skipDestination(bParsed);
         return 0;
-    }
 
     // Then check for the more complex ones.
     switch (nKeyword)
@@ -2246,16 +2229,15 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle value '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
 #endif
-            bParsed = false;
+            aSkip.setParsed(false);
             break;
     }
-    skipDestination(bParsed);
     return 0;
 }
 
 int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam)
 {
-    bool bParsed = true;
+    RTFSkipDestination aSkip(*this);
     int nSprm = -1;
     RTFValue::Pointer_t pBoolValue(new RTFValue(!bParam || nParam != 0));
 
@@ -2285,7 +2267,6 @@ int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam
     {
         RTFValue::Pointer_t pValue(new RTFValue((!bParam || nParam != 0) ? nSprm : 0));
         m_aStates.top().aCharacterSprms->push_back(make_pair(NS_sprm::LN_CKul, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -2303,7 +2284,6 @@ int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam
     {
         RTFValue::Pointer_t pValue(new RTFValue((!bParam || nParam != 0) ? nSprm : 0));
         m_aStates.top().aCharacterSprms->push_back(make_pair(NS_sprm::LN_CKcd, pValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -2327,7 +2307,6 @@ int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam
     if (nSprm >= 0)
     {
         m_aStates.top().aCharacterSprms->push_back(make_pair(nSprm, pBoolValue));
-        skipDestination(bParsed);
         return 0;
     }
 
@@ -2348,26 +2327,12 @@ int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam
 #if OSL_DEBUG_LEVEL > 1
             OSL_TRACE("%s: TODO handle toggle '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword));
 #endif
-            bParsed = false;
+            aSkip.setParsed(false);
             break;
     }
-    skipDestination(bParsed);
     return 0;
 }
 
-void RTFDocumentImpl::skipDestination(bool bParsed)
-{
-    if (m_bSkipUnknown)
-    {
-        if (!bParsed)
-        {
-            OSL_TRACE("%s: skipping destination", OSL_THIS_FUNC);
-            m_aStates.top().nDestinationState = DESTINATION_SKIP;
-        }
-        m_bSkipUnknown = false;
-    }
-}
-
 int RTFDocumentImpl::pushState()
 {
     //OSL_TRACE("%s before push: %d", OSL_THIS_FUNC, m_nGroup);
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 8b0f25a..f5506cd 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -277,7 +277,6 @@ namespace writerfilter {
                 bool isEmpty();
                 int getGroup();
                 void setDestinationText(rtl::OUString& rString);
-                void skipDestination(bool bParsed);
                 /// Resolve a picture: If not inline, then anchored.
                 int resolvePict(bool bInline);
                 void runBreak();
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index 847dd24..e1e4223 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -28,6 +28,7 @@
 #include <tools/stream.hxx>
 
 #include <rtftokenizer.hxx>
+#include <rtfskipdestination.hxx>
 
 using rtl::OString;
 using rtl::OStringBuffer;
@@ -227,7 +228,8 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
     if (i == nRTFControlWords)
     {
         OSL_TRACE("%s: unknown keyword '\\%s'", OSL_THIS_FUNC, rKeyword.getStr());
-        m_rImport.skipDestination(false);
+        RTFSkipDestination aSkip(m_rImport);
+        aSkip.setParsed(false);
         return 0;
     }
 
commit 825c6e71904f6af5f4c01d087a65a20acf25e0c2
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 23:41:44 2011 +0200

    Add a new RTFSkipDestination class
    
    The idea is that calling skipDestination() all the time before return is
    boring: better to just place an RTFSkipDestination and its destructor
    will do its job when it goes out of scope.

diff --git a/writerfilter/Library_rtftok.mk b/writerfilter/Library_rtftok.mk
index d5d536d..e53f7a8 100644
--- a/writerfilter/Library_rtftok.mk
+++ b/writerfilter/Library_rtftok.mk
@@ -65,6 +65,7 @@ $(eval $(call gb_Library_add_exception_objects,rtftok,\
 	writerfilter/source/rtftok/rtfdocumentimpl \
 	writerfilter/source/rtftok/rtfsdrimport \
 	writerfilter/source/rtftok/rtftokenizer \
+	writerfilter/source/rtftok/rtfskipdestination \
 	writerfilter/source/rtftok/rtfcontrolwords \
 	writerfilter/source/rtftok/rtfcharsets \
 	writerfilter/source/rtftok/rtfreferenceproperties \
diff --git a/writerfilter/source/rtftok/rtfskipdestination.cxx b/writerfilter/source/rtftok/rtfskipdestination.cxx
new file mode 100644
index 0000000..9ad1d1d
--- /dev/null
+++ b/writerfilter/source/rtftok/rtfskipdestination.cxx
@@ -0,0 +1,66 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       Miklos Vajna <vmiklos at frugalware.org>
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <rtfskipdestination.hxx>
+
+namespace writerfilter {
+namespace rtftok {
+
+RTFSkipDestination::RTFSkipDestination(RTFDocumentImpl& rImport)
+    : m_rImport(rImport),
+    m_bParsed(true),
+    m_bReset(true)
+{
+}
+
+RTFSkipDestination::~RTFSkipDestination()
+{
+    if (m_rImport.getSkipUnknown() && m_bReset)
+    {
+        if (!m_bParsed)
+        {
+            OSL_TRACE("%s: skipping destination", OSL_THIS_FUNC);
+            m_rImport.getState().nDestinationState = DESTINATION_SKIP;
+        }
+        m_rImport.setSkipUnknown(false);
+    }
+}
+
+void RTFSkipDestination::setParsed(bool bParsed)
+{
+    m_bParsed = bParsed;
+}
+
+void RTFSkipDestination::setReset(bool bReset)
+{
+    m_bReset = bReset;
+}
+
+} // namespace rtftok
+} // namespace writerfilter
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfskipdestination.hxx b/writerfilter/source/rtftok/rtfskipdestination.hxx
new file mode 100644
index 0000000..31f0164
--- /dev/null
+++ b/writerfilter/source/rtftok/rtfskipdestination.hxx
@@ -0,0 +1,56 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       Miklos Vajna <vmiklos at frugalware.org>
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef _RTFSKIPDESTINATION_HXX_
+#define _RTFSKIPDESTINATION_HXX_
+
+#include <rtfdocumentimpl.hxx>
+
+class SvStream;
+
+namespace writerfilter {
+    namespace rtftok {
+        /// Skips a destination after a not parsed control word if it was prefixed with \*
+        class RTFSkipDestination
+        {
+            public:
+                RTFSkipDestination(RTFDocumentImpl& rImport);
+                virtual ~RTFSkipDestination();
+                void setParsed(bool bParsed);
+                void setReset(bool bReset);
+            private:
+                RTFDocumentImpl& m_rImport;
+                bool m_bParsed;
+                /// If false, the destructor is a noop, required by the \* symbol itself.
+                bool m_bReset;
+        };
+    } // namespace rtftok
+} // namespace writerfilter
+
+#endif // _RTFSKIPDESTINATION_HXX_
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 197fe11da21d2ef63b1124495d862d1d6980a9d5
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 23:24:17 2011 +0200

    RTFDocumentImpl: add set/get methods for SkipUnknown

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 3458849..84cafa5 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2867,6 +2867,16 @@ void RTFDocumentImpl::replayShapetext()
     replayBuffer(m_aShapetextBuffer);
 }
 
+bool RTFDocumentImpl::getSkipUnknown()
+{
+    return m_bSkipUnknown;
+}
+
+void RTFDocumentImpl::setSkipUnknown(bool bSkipUnknown)
+{
+    m_bSkipUnknown = bSkipUnknown;
+}
+
 RTFParserState::RTFParserState()
     : nInternalState(INTERNAL_NORMAL),
     nDestinationState(DESTINATION_NORMAL),
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index dec202b..8b0f25a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -282,6 +282,8 @@ namespace writerfilter {
                 int resolvePict(bool bInline);
                 void runBreak();
                 void replayShapetext();
+                bool getSkipUnknown();
+                void setSkipUnknown(bool bSkipUnknown);
 
                 // These callbacks are invoked by the tokenizer.
                 int resolveChars(char ch);
commit 98158723b279537f8221ef13565d87dae4cc6ba2
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 18:49:31 2011 +0200

    implement font alignment paragraph sprms

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4012d2b..3458849 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1346,6 +1346,25 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
         return 0;
     }
 
+    // Font Alignment
+    switch (nKeyword)
+    {
+        case RTF_FAFIXED:
+        case RTF_FAAUTO: nParam = NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_auto; break;
+        case RTF_FAHANG: nParam = NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_top; break;
+        case RTF_FACENTER: nParam = NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_center; break;
+        case RTF_FAROMAN: nParam = NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_baseline; break;
+        case RTF_FAVAR: nParam = NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_bottom; break;
+        default: break;
+    }
+    if (nParam >= 0)
+    {
+        RTFValue::Pointer_t pValue(new RTFValue(nParam));
+        m_aStates.top().aParagraphSprms->push_back(make_pair(NS_sprm::LN_PWAlignFont, pValue));
+        skipDestination(bParsed);
+        return 0;
+    }
+
     // Tab kind.
     switch (nKeyword)
     {
commit 9d4f6c02b1946dce75748559a4af36b95f5c4e01
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 17:26:28 2011 +0200

    dmapper: paragraph vertical alignment support

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index ba8f970..e9663be 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1768,6 +1768,28 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
     case NS_sprm::LN_PFAutoSpaceDN:
         break;  // sprmPFAutoSpaceDN
     case NS_sprm::LN_PWAlignFont:
+        {
+            sal_Int16 nAlignment = 0;
+            switch (nIntValue)
+            {
+                case NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_top:
+                    nAlignment = 2;
+                    break;
+                case NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_center:
+                    nAlignment = 3;
+                    break;
+                case NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_baseline:
+                    nAlignment = 1;
+                    break;
+                case NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_bottom:
+                    nAlignment = 4;
+                    break;
+                case NS_ooxml::LN_Value_wordprocessingml_ST_TextAlignment_auto:
+                default:
+                    break;
+            }
+            rContext->Insert( PROP_PARA_VERT_ALIGNMENT, true, uno::makeAny( nAlignment) );
+        }
         break;  // sprmPWAlignFont
     case NS_sprm::LN_PFrameTextFlow:
         break;  // sprmPFrameTextFlow
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index 5373c00..9957ec1 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -116,6 +116,7 @@ const rtl::OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
 
             case PROP_PARA_STYLE_NAME:      sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")); break;
             case PROP_PARA_ADJUST:     sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaAdjust")); break;
+            case PROP_PARA_VERT_ALIGNMENT: sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaVertAlignment")); break;
             case PROP_PARA_LAST_LINE_ADJUST:     sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaLastLineAdjust")); break;
             case PROP_PARA_RIGHT_MARGIN     :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaRightMargin")); break;
             case PROP_PARA_LEFT_MARGIN      :    sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaLeftMargin")); break;
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index 6ddd1d8..057751b 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -225,6 +225,7 @@ enum PropertyIds
         ,PROP_PARA_STYLE_NAME
         ,PROP_PARA_TAB_STOPS
         ,PROP_PARA_TOP_MARGIN
+        ,PROP_PARA_VERT_ALIGNMENT
         ,PROP_PARA_WIDOWS
         ,PROP_PARENT_NUMBERING
         ,PROP_POSITION_AND_SPACE_MODE
commit 57a189d7f9e92cac405c838932f19f6f195866ba
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 16:18:56 2011 +0200

    DomainMapper_Impl::AddBookmark: missing empty stack check

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 2703be6..4c983d1 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3017,6 +3017,8 @@ void DomainMapper_Impl::PopFieldContext()
 
 void DomainMapper_Impl::AddBookmark( const ::rtl::OUString& rBookmarkName, const ::rtl::OUString& rId )
 {
+    if (m_aTextAppendStack.empty())
+        return;
     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId );
     //is the bookmark name already registered?
commit ea31506b0dfdc5249a522863cfb395c37531ce97
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 16:16:24 2011 +0200

    fix shape import for the unit test

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index eec5135..4012d2b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -527,10 +527,9 @@ int RTFDocumentImpl::resolvePict(bool bInline)
     // Wrap it in an XShape.
     uno::Reference<drawing::XShape> xShape;
     OUString aService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicObjectShape"));
-    xShape.set(m_xModelFactory->createInstance(aService), uno::UNO_QUERY);
-    OSL_ASSERT(xShape.is());
+    if (m_xModelFactory.is())
+        xShape.set(m_xModelFactory->createInstance(aService), uno::UNO_QUERY);
     uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
-    OSL_ASSERT(xPropertySet.is());
     if (m_bObject)
     {
         // Set bitmap
@@ -558,7 +557,8 @@ int RTFDocumentImpl::resolvePict(bool bInline)
         m_aObjectAttributes->push_back(make_pair(NS_ooxml::LN_shape, pShapeValue));
         return 0;
     }
-    xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), uno::Any(aGraphicUrl));
+    if (xPropertySet.is())
+        xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), uno::Any(aGraphicUrl));
 
     // Send it to the dmapper.
     RTFSprms aSprms;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index f83280d..1c5e27f 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -111,7 +111,8 @@ void RTFSdrImport::resolve(RTFShape& rShape)
 
             // Defaults
             aAny <<= (sal_uInt32)0xffffff; // White in Word, kind of blue in Writer.
-            xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")), aAny);
+            if (xPropertySet.is())
+                xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")), aAny);
         }
         else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("wzName")))
         {
@@ -128,21 +129,21 @@ void RTFSdrImport::resolve(RTFShape& rShape)
             m_rImport.setDestinationText(i->second);
             bPib = true;
         }
-        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("fillColor")))
+        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("fillColor")) && xPropertySet.is())
         {
             aAny <<= lcl_BGRToRGB(i->second.toInt32());
             xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")), aAny);
         }
         else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("fillBackColor")))
             ; // Ignore: complementer of fillColor
-        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("lineColor")))
+        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("lineColor")) && xPropertySet.is())
         {
             aAny <<= lcl_BGRToRGB(i->second.toInt32());
             xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LineColor")), aAny);
         }
         else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("lineBackColor")))
             ; // Ignore: complementer of lineColor
-        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("txflTextFlow")))
+        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("txflTextFlow")) && xPropertySet.is())
         {
             if (i->second.toInt32() == 1)
             {
@@ -150,7 +151,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
                 xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("TextWritingMode")), aAny);
             }
         }
-        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("fLine")))
+        else if (i->first.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("fLine")) && xPropertySet.is())
         {
             if (i->second.toInt32() == 0)
             {
@@ -282,7 +283,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
 
     if (m_xDrawPage.is())
         m_xDrawPage->add(xShape);
-    if (bCustom)
+    if (bCustom && xShape.is())
     {
         uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
         xDefaulter->createCustomShapeDefaults(OUString::valueOf(sal_Int32(nType)));
@@ -312,7 +313,7 @@ void RTFSdrImport::resolve(RTFShape& rShape)
     beans::PropertyValue* pGeomValues = aGeomPropSeq.getArray();
     for (std::vector<beans::PropertyValue>::iterator i = aGeomPropVec.begin(); i != aGeomPropVec.end(); ++i)
         *pGeomValues++ = *i;
-    if (aGeomPropSeq.getLength())
+    if (aGeomPropSeq.getLength() && xPropertySet.is())
         xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CustomShapeGeometry")), uno::Any(aGeomPropSeq));
 
     // Set position and size
commit 5338fee30bef0eeeedb768220713641b3d1536fe
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Mon Aug 8 16:14:00 2011 +0200

    dmapper: more null pointer checks for the unit test

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 65f3481..2703be6 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -287,6 +287,8 @@ void DomainMapper_Impl::SetDocumentSettingsProperty( const ::rtl::OUString& rPro
 
 void DomainMapper_Impl::RemoveLastParagraph( )
 {
+    if (m_aTextAppendStack.empty())
+        return;
     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     if (!xTextAppend.is())
         return;
@@ -322,9 +324,12 @@ void    DomainMapper_Impl::PushProperties(ContextType eId)
         // beginning with the second section group a section has to be inserted
         // into the document
         SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() );
-         uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
-         if(xTextAppend.is())
-             pSectionContext_->SetStart( xTextAppend->getEnd() );
+        if (!m_aTextAppendStack.empty())
+        {
+            uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
+            if (xTextAppend.is())
+                pSectionContext_->SetStart( xTextAppend->getEnd() );
+        }
     }
     m_aPropertyStacks[eId].push( pInsert );
     m_aContextStack.push(eId);
@@ -699,7 +704,9 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
 
     ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
     TextAppendContext& rAppendContext = m_aTextAppendStack.top();
-    uno::Reference< text::XTextAppend >  xTextAppend = rAppendContext.xTextAppend;
+    uno::Reference< text::XTextAppend >  xTextAppend;
+    if (!m_aTextAppendStack.empty())
+        xTextAppend = rAppendContext.xTextAppend;
     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
 
 #ifdef DEBUG_DOMAINMAPPER
@@ -986,6 +993,8 @@ util::DateTime lcl_DateStringToDateTime( const ::rtl::OUString& rDateTime )
 }
 void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap )
 {
+    if (m_aTextAppendStack.empty())
+        return;
     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     if(xTextAppend.is() && ! getTableManager( ).isIgnore())
     {
@@ -1087,6 +1096,8 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
                                     uno::Reference< text::XTextRange >& xBefore )
 {
     uno::Reference< beans::XPropertySet > xRet;
+    if (m_aTextAppendStack.empty())
+        return xRet;
     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     if(xTextAppend.is())
     {
@@ -1127,6 +1138,8 @@ void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType)
                 GetPageStyles(),
                 m_xTextFactory,

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list