diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-03-29 15:26:28 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-03-29 15:53:55 +0200 |
commit | 6b7942f5ac0498414931a0e7842aa96452b7a04d (patch) | |
tree | 2ab8fa30baa880e497fdaa3a928c776f7accc3a2 | |
parent | b475bc459d0406c9211c7be69973f310949a45a6 (diff) |
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.
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 34 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 8 |
2 files changed, 34 insertions, 8 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 6a1daeaa3089..e63c4512b843 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 54459e74ce85..eb7e27a21fb8 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. |