[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 2 commits - writerfilter/source

Michael Stahl mst at kemper.freedesktop.org
Tue Apr 10 04:07:30 PDT 2012


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

New commits:
commit 606dd9f18806ad3f659041e395eed870139699d2
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.
    (cherry picked from commit 6b7942f5ac0498414931a0e7842aa96452b7a04d)
    
    Signed-off-by: Michael Stahl <mstahl at redhat.com>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4597d63..a117ec6 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -286,6 +286,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(),
@@ -341,6 +342,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;
@@ -380,6 +386,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.getLength())
     {
@@ -542,11 +549,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 9626063..461b88e 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 a19a526648175e5c7091ea08293e62cc756b4d0c
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.
    (cherry picked from commit b475bc459d0406c9211c7be69973f310949a45a6)
    
    Signed-off-by: Michael Stahl <mstahl at redhat.com>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 2d82e28..4597d63 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1414,6 +1414,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