Kaydet (Commit) fa15d039 authored tarafından Miklos Vajna's avatar Miklos Vajna

fdo#72031 RTF import: bogus call to getBestTextEncodingFromLocale()

There were two problems here. First, commit
bbe3627e (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 7839633f (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
üst 43a803cc
{\rtf1\ansi\ansicpg1250\deff0\deflang1038{\fonttbl{\f0\fnil\fcharset2 Symbol;}{\f1\fnil\fcharset238 MS Shell Dlg 2;}}\viewkind4\uc1\pard\f0\fs23\'c5\f1\fs17\par}
......@@ -66,7 +66,7 @@ public:
virtual void preTest(const char* filename) SAL_OVERRIDE
{
m_aSavedSettings = Application::GetSettings();
if (OString(filename) == "fdo48023.rtf")
if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf")
{
AllSettings aSettings(m_aSavedSettings);
aSettings.SetLanguageTag(LanguageTag("ru"));
......@@ -82,7 +82,7 @@ public:
virtual void postTest(const char* filename) SAL_OVERRIDE
{
if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo44211.rtf")
if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf" || OString(filename) == "fdo44211.rtf")
Application::SetSettings(m_aSavedSettings);
}
......@@ -2206,6 +2206,11 @@ DECLARE_RTFIMPORT_TEST(testFdo85889mac, "fdo85889-mac.rtf")
CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
}
DECLARE_RTFIMPORT_TEST(testFdo72031, "fdo72031.rtf")
{
OUString aExpected("\xc3\x85", 2, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_EQUAL(aExpected, getRun(getParagraph(1), 1)->getString());
}
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -255,7 +255,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),
......@@ -641,8 +641,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);
......@@ -1163,10 +1169,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)));
......@@ -2907,16 +2913,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:
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment