[Libreoffice-commits] .: 2 commits - writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Thu Mar 29 06:53:27 PDT 2012


 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   35 ++++++++++++++++++++-----
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    8 +++++
 2 files changed, 35 insertions(+), 8 deletions(-)

New commits:
commit 6b7942f5ac0498414931a0e7842aa96452b7a04d
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Thu Mar 29 15:26:28 2012 +0200

    fdo#45394 fix RTF import of custom fonts in substreams
    
    Substreams (headers, footers, etc.) are parsed separately, so their font
    table is empty by default. Fix handling of custom fonts (and thus
    encodings) there by passing a pointer to the superstream.

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 6a1daea..e63c451 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -261,6 +261,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_pCurrentBuffer(0),
     m_bHasFootnote(false),
     m_bIsSubstream(false),
+    m_pSuperstream(0),
     m_nHeaderFooterPositions(),
     m_nGroupStartPos(0),
     m_aBookmarks(),
@@ -317,6 +318,11 @@ void RTFDocumentImpl::setSubstream(bool bIsSubtream)
     m_bIsSubstream = bIsSubtream;
 }
 
+void RTFDocumentImpl::setSuperstream(RTFDocumentImpl *pSuperstream)
+{
+    m_pSuperstream = pSuperstream;
+}
+
 void RTFDocumentImpl::setAuthor(rtl::OUString& rAuthor)
 {
     m_aAuthor = rAuthor;
@@ -356,6 +362,7 @@ void RTFDocumentImpl::resolveSubstream(sal_uInt32 nPos, Id nId, OUString& rIgnor
     // Seek to header position, parse, then seek back.
     RTFDocumentImpl::Pointer_t pImpl(new RTFDocumentImpl(m_xContext, m_xInputStream, m_xDstDoc, m_xFrame, m_xStatusIndicator));
     pImpl->setSubstream(true);
+    pImpl->setSuperstream(this);
     pImpl->setIgnoreFirst(rIgnoreFirst);
     if (!m_aAuthor.isEmpty())
     {
@@ -516,11 +523,24 @@ sal_uInt32 RTFDocumentImpl::getColorTable(sal_uInt32 nIndex)
     return 0;
 }
 
-sal_uInt32 RTFDocumentImpl::getEncodingTable(sal_uInt32 nFontIndex)
+rtl_TextEncoding RTFDocumentImpl::getEncoding(sal_uInt32 nFontIndex)
 {
-    if (nFontIndex < m_aFontEncodings.size())
-        return m_aFontEncodings[nFontIndex];
-    return 0;
+    if (!m_pSuperstream)
+    {
+        if (nFontIndex < m_aFontEncodings.size())
+            return m_aFontEncodings[nFontIndex];
+        return 0;
+    }
+    else
+        return m_pSuperstream->getEncoding(nFontIndex);
+}
+
+int RTFDocumentImpl::getFontIndex(int nIndex)
+{
+    if (!m_pSuperstream)
+        return std::find(m_aFontIndexes.begin(), m_aFontIndexes.end(), nIndex) - m_aFontIndexes.begin();
+    else
+        return m_pSuperstream->getFontIndex(nIndex);
 }
 
 void RTFDocumentImpl::resolve(Stream & rMapper)
@@ -2168,14 +2188,14 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
             if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE || m_aStates.top().nDestinationState == DESTINATION_FONTENTRY)
             {
                 m_aFontIndexes.push_back(nParam);
-                m_nCurrentFontIndex = std::find(m_aFontIndexes.begin(), m_aFontIndexes.end(), nParam) - m_aFontIndexes.begin();
+                m_nCurrentFontIndex = getFontIndex(nParam);
             }
             else
             {
-                int nFontIndex = std::find(m_aFontIndexes.begin(), m_aFontIndexes.end(), nParam) - m_aFontIndexes.begin();
+                int nFontIndex = getFontIndex(nParam);
                 RTFValue::Pointer_t pValue(new RTFValue(nFontIndex));
                 m_aStates.top().aCharacterSprms->push_back(make_pair(NS_sprm::LN_CRgFtc0, pValue));
-                m_aStates.top().nCurrentEncoding = getEncodingTable(nFontIndex);
+                m_aStates.top().nCurrentEncoding = getEncoding(nFontIndex);
             }
             break;
         case RTF_RED:
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 54459e7..eb7e27a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -330,6 +330,7 @@ namespace writerfilter {
 
                 Stream& Mapper();
                 void setSubstream(bool bIsSubtream);
+                void setSuperstream(RTFDocumentImpl *pSuperstream);
                 void setAuthor(rtl::OUString& rAuthor);
                 bool isSubstream() const;
                 void finishSubstream();
@@ -364,11 +365,14 @@ namespace writerfilter {
                 bool getFirstRun();
                 /// If we need to add a dummy paragraph before a section break.
                 void setNeedPar(bool bNeedPar);
+                /// Return the dmapper index of an RTF index for fonts.
+                int getFontIndex(int nIndex);
+                /// Return the encoding associated with a dmapper font index.
+                rtl_TextEncoding getEncoding(sal_uInt32 nFontIndex);
 
             private:
                 SvStream& Strm();
                 sal_uInt32 getColorTable(sal_uInt32 nIndex);
-                sal_uInt32 getEncodingTable(sal_uInt32 nFontIndex);
                 RTFSprms mergeSprms();
                 RTFSprms mergeAttributes();
                 void resetSprms();
@@ -434,6 +438,8 @@ namespace writerfilter {
                 bool m_bHasFootnote;
                 /// If this is a substream.
                 bool m_bIsSubstream;
+                /// Superstream of this substream.
+                RTFDocumentImpl *m_pSuperstream;
                 std::queue< std::pair<Id, sal_uInt32> > m_nHeaderFooterPositions;
                 sal_uInt32 m_nGroupStartPos;
                 /// Ignore the first occurrence of this text.
commit b475bc459d0406c9211c7be69973f310949a45a6
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Thu Mar 29 12:54:07 2012 +0200

    fdo#45394 fix RTF import of tables with empty first row
    
    Additionally the table should be at the start of the document to trigger
    this bug.

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4254c49..6a1daea 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1392,6 +1392,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
         case RTF_CELL:
         case RTF_NESTCELL:
             {
+                checkFirstRun();
                 if (m_bNeedPap)
                 {
                     // There were no runs in the cell, so we need to send paragraph and character properties here.


More information about the Libreoffice-commits mailing list