sw/qa/extras/rtfimport/data/fdo76628.rtf | 10 ++++++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 12 ++++++++++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 19 +++++++++---------- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 10 +++++----- 4 files changed, 36 insertions(+), 15 deletions(-)
New commits: commit 8baff038befe47957967278a7225bc48e0d89889 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Fri Apr 4 10:29:49 2014 +0200 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 diff --git a/sw/qa/extras/rtfimport/data/fdo76628.rtf b/sw/qa/extras/rtfimport/data/fdo76628.rtf new file mode 100644 index 0000000..9429fb8 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo76628.rtf @@ -0,0 +1,10 @@ +{\rtf1\deff0 +{\fonttbl +{\f0\froman\fcharset204\fprq2 Times New Roman;} +{\f18\froman\fcharset0\fprq2 Times New Roman;} +} +{\header \pard\plain \'cf\'ee\'e4\'e3\'ee\'f2\'ee\'e2\'eb\'e5\'ed\'ee +\par } +{\pard\plain \'ce\'c1\'d0\'c0\'c7\'c5\'d6 +\par } +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index cb19476..2a56941 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1619,6 +1619,18 @@ DECLARE_RTFIMPORT_TEST(testDprectAnchor, "dprect-anchor.rtf") CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType")); } +DECLARE_RTFIMPORT_TEST(testFdo76628, "fdo76628.rtf") +{ + OUString aExpected("\xd0\x9e\xd0\x91\xd0\xa0\xd0\x90\xd0\x97\xd0\x95\xd0\xa6", 14, RTL_TEXTENCODING_UTF8); + // Should be 'SAMPLE' in Russian, was garbage. + getParagraph(1, aExpected); + + uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText"); + OUString aExpectedHeader("\xd0\x9f\xd0\xbe\xd0\xb4\xd0\xb3\xd0\xbe\xd1\x82\xd0\xbe\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xbe", 24, RTL_TEXTENCODING_UTF8); + // Should be 'prepared' in Russian, was garbage. + getParagraphOfText(1, xHeaderText, aExpectedHeader); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index cf7b0d6..57b106d 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 d338693..a16334a 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits