summaryrefslogtreecommitdiff
path: root/writerfilter/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-11-29 11:43:10 +0100
committerAndras Timar <andras.timar@collabora.com>2014-12-13 16:00:50 +0100
commitd022bc5d27c6cd393358ab9d0ff78886e3d130aa (patch)
tree20e94e18dea638fcc9d999fc7a54aa8677a542eb /writerfilter/source
parente5e64cbb1f687a2f532aa4e4e4e1bb35be210ef6 (diff)
fdo#72031 RTF import: bogus call to getBestTextEncodingFromLocale()
There were two problems here. First, commit bbe3627eece0c3486e7ea11f2f13377aaa3a8fed (rtftok: stop sending sprm:CRgFtc{0,1,2} tokens, 2014-03-05) broke the use-case when the font encoding is 0, but it's present. Before that commit, we parsed the font encoding instantly; after that commit we parse it once we have a font name. If we do that, then we have to have an idea if we have a font encoding. Given that 0 is a valid encoding, use -1 for the "have no encoding" case instead. Second, commit 7839633fb356285652ed96f4bf3f85bcd5b561a4 (fdo#85889 handle pc, pca and mac rtf keywords in writerfilter, 2014-11-24) abused m_nCurrentEncoding, which is meant to be used within the font table only. The problem with this is that this way only the first font will get the encoding, while the spec says it should be used in every context where there is no other explicit encoding. Fix this by setting the default encoding for those 3 control words instead -- and consider the default encoding in getEncoding(). Change-Id: Ia1d71f8ce70f2a53a3770b4840e21362d082e71f (cherry picked from commit fa15d039e3a553da8500c17190d27169a9477cf2) Signed-off-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'writerfilter/source')
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx26
1 files changed, 16 insertions, 10 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 27e0ab227452..b61f5a764074 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -276,7 +276,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
m_bObject(false),
m_aFontTableEntries(),
m_nCurrentFontIndex(0),
- m_nCurrentEncoding(0),
+ m_nCurrentEncoding(-1),
m_nDefaultFontIndex(-1),
m_aStyleTableEntries(),
m_nCurrentStyleIndex(0),
@@ -639,8 +639,14 @@ rtl_TextEncoding RTFDocumentImpl::getEncoding(int nFontIndex)
{
std::map<int, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(nFontIndex);
if (it != m_aFontEncodings.end())
+ // We have a font encoding associated to this font.
return it->second;
- return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale());
+ else if (m_aDefaultState.nCurrentEncoding != rtl_getTextEncodingFromWindowsCharset(0))
+ // We have a default encoding.
+ return m_aDefaultState.nCurrentEncoding;
+ else
+ // Guess based on locale.
+ return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale());
}
else
return m_pSuperstream->getEncoding(nFontIndex);
@@ -1154,10 +1160,10 @@ void RTFDocumentImpl::text(OUString& rString)
case DESTINATION_FONTENTRY:
{
m_aFontNames[m_nCurrentFontIndex] = aName;
- if (m_nCurrentEncoding > 0)
+ if (m_nCurrentEncoding >= 0)
{
m_aFontEncodings[m_nCurrentFontIndex] = m_nCurrentEncoding;
- m_nCurrentEncoding = 0;
+ m_nCurrentEncoding = -1;
}
m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Font_name, RTFValue::Pointer_t(new RTFValue(aName)));
@@ -2831,16 +2837,16 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
m_aStates.top().nCurrentEncoding = RTL_TEXTENCODING_MS_1252;
break;
case RTF_MAC:
- m_nCurrentEncoding = RTL_TEXTENCODING_APPLE_ROMAN;
- m_aStates.top().nCurrentEncoding = m_nCurrentEncoding;
+ m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_APPLE_ROMAN;
+ m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding;
break;
case RTF_PC:
- m_nCurrentEncoding = RTL_TEXTENCODING_IBM_437;
- m_aStates.top().nCurrentEncoding = m_nCurrentEncoding;
+ m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_IBM_437;
+ m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding;
break;
case RTF_PCA:
- m_nCurrentEncoding = RTL_TEXTENCODING_IBM_850;
- m_aStates.top().nCurrentEncoding = m_nCurrentEncoding;
+ m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_IBM_850;
+ m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding;
break;
case RTF_PLAIN:
{