diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-04-04 10:29:49 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-04-04 10:53:27 +0200 |
commit | 8baff038befe47957967278a7225bc48e0d89889 (patch) | |
tree | 8ff19d84a6f61be06c56306579cb51a4b78993b2 /writerfilter | |
parent | Fix -Werror=type-limits and -Werror=sign-compare (diff) | |
download | core-8baff038befe47957967278a7225bc48e0d89889.tar.gz core-8baff038befe47957967278a7225bc48e0d89889.zip |
fdo#76628 RTF import: allow the same font to have multiple encodings
Commit bbe3627eece0c3486e7ea11f2f13377aaa3a8fed (rtftok: stop sending
sprm:CRgFtc{0,1,2} tokens, 2014-03-05) dropped support for case when a
font name is used in multiple entries in the font table, but with
different encodings.
Turns out that this is a valid use-case, so revert back to the old
behavior where the key of the encoding table is the font index, not the
font name.
Change-Id: I048dff58af801d704fd4bc75a6a4dcb0f03bf185
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 19 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 10 |
2 files changed, 14 insertions, 15 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index cf7b0d67d80d..57b106d21364 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -380,6 +380,7 @@ void RTFDocumentImpl::resolveSubstream(sal_Size nPos, Id nId, OUString& rIgnoreF pImpl->setAuthorInitials(m_aAuthorInitials); m_aAuthorInitials = ""; } + pImpl->m_nDefaultFontIndex = m_nDefaultFontIndex; pImpl->seek(nPos); SAL_INFO("writerfilter", "substream start"); Mapper().substream(nId, pImpl); @@ -615,17 +616,17 @@ sal_uInt32 RTFDocumentImpl::getColorTable(sal_uInt32 nIndex) return m_pSuperstream->getColorTable(nIndex); } -rtl_TextEncoding RTFDocumentImpl::getEncoding(const OUString& aFontName) +rtl_TextEncoding RTFDocumentImpl::getEncoding(int nFontIndex) { if (!m_pSuperstream) { - std::map<OUString, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(aFontName); + std::map<int, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(nFontIndex); if (it != m_aFontEncodings.end()) return it->second; return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale()); } else - return m_pSuperstream->getEncoding(aFontName); + return m_pSuperstream->getEncoding(nFontIndex); } OUString RTFDocumentImpl::getFontName(int nIndex) @@ -1086,7 +1087,7 @@ void RTFDocumentImpl::text(OUString& rString) m_aFontNames[m_nCurrentFontIndex] = aName; if (m_nCurrentEncoding > 0) { - m_aFontEncodings[aName] = m_nCurrentEncoding; + m_aFontEncodings[m_nCurrentFontIndex] = m_nCurrentEncoding; m_nCurrentEncoding = 0; } m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Font_name, RTFValue::Pointer_t(new RTFValue(aName))); @@ -2471,9 +2472,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_PLAIN: { m_aStates.top().aCharacterSprms = getDefaultState().aCharacterSprms; - RTFValue::Pointer_t pValue = lcl_getNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); - if (pValue) - m_aStates.top().nCurrentEncoding = getEncoding(pValue->getString()); + m_aStates.top().nCurrentEncoding = getEncoding(getFontIndex(m_nDefaultFontIndex)); m_aStates.top().aCharacterAttributes = getDefaultState().aCharacterAttributes; } break; @@ -3142,10 +3141,10 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) } else { - int nFontIndex = getFontIndex(nParam); - RTFValue::Pointer_t pValue(new RTFValue(getFontName(nFontIndex))); + m_nCurrentFontIndex = getFontIndex(nParam); + RTFValue::Pointer_t pValue(new RTFValue(getFontName(m_nCurrentFontIndex))); lcl_putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, nSprm, pValue); - m_aStates.top().nCurrentEncoding = getEncoding(getFontName(nFontIndex)); + m_aStates.top().nCurrentEncoding = getEncoding(m_nCurrentFontIndex); } break; case RTF_RED: diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index d33869394e77..a16334aabe54 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -357,8 +357,8 @@ namespace writerfilter { OUString getFontName(int nIndex); /// Return the style name of an RTF style index. OUString getStyleName(int nIndex); - /// Return the encoding associated with a font name. - rtl_TextEncoding getEncoding(const OUString& aFontName); + /// Return the encoding associated with a font index. + rtl_TextEncoding getEncoding(int nFontIndex); /// Get the default parser state. RTFParserState& getDefaultState(); oox::GraphicHelper& getGraphicHelper(); @@ -422,8 +422,8 @@ namespace writerfilter { /// Read by RTF_PARD. RTFParserState m_aDefaultState; bool m_bSkipUnknown; - /// Font name <-> encoding map, *not* part of the parser state - std::map<OUString, rtl_TextEncoding> m_aFontEncodings; + /// Font index <-> encoding map, *not* part of the parser state + std::map<int, rtl_TextEncoding> m_aFontEncodings; /// Font index <-> name map. std::map<int, OUString> m_aFontNames; /// Maps the non-continuous font indexes to the continuous dmapper indexes. @@ -516,7 +516,7 @@ namespace writerfilter { int m_nCurrentFontIndex; /// Used only during font table parsing till we don't know the font name. int m_nCurrentEncoding; - /// Used only before font table parsing. + /// Raw default font index, use getFont() on it to get a real one. int m_nDefaultFontIndex; RTFReferenceTable::Entries_t m_aStyleTableEntries; |