summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-04-21 11:25:18 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-04-21 11:57:19 +0200
commitf8bda240a09b4ece1c3401874b3cc8f325dbcedb (patch)
tree3d59ce78a08694416a48d6005b916a09a923e8ca
parent2abba84aa7c639011956721a4922653130dd09a6 (diff)
fdo#48023 fix RTF import of Russian characters without an encoding specified
lcl_GetDefaultTextEncodingForRTF() in editeng did the same.
-rw-r--r--sw/qa/extras/rtftok/data/fdo48023.rtf8
-rw-r--r--sw/qa/extras/rtftok/rtftok.cxx25
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx15
3 files changed, 47 insertions, 1 deletions
diff --git a/sw/qa/extras/rtftok/data/fdo48023.rtf b/sw/qa/extras/rtftok/data/fdo48023.rtf
new file mode 100644
index 000000000000..6d6a0d9b551e
--- /dev/null
+++ b/sw/qa/extras/rtftok/data/fdo48023.rtf
@@ -0,0 +1,8 @@
+{\rtf
+{\fonttbl
+{\f1 Arial;}
+}
+\pard
+\f1 Программист
+\par
+}
diff --git a/sw/qa/extras/rtftok/rtftok.cxx b/sw/qa/extras/rtftok/rtftok.cxx
index fa1321f25ef0..6870f0202e86 100644
--- a/sw/qa/extras/rtftok/rtftok.cxx
+++ b/sw/qa/extras/rtftok/rtftok.cxx
@@ -82,6 +82,7 @@ public:
void testFdo44176();
void testFdo39053();
void testFdo48356();
+ void testFdo48023();
CPPUNIT_TEST_SUITE(RtfModelTest);
#if !defined(MACOSX) && !defined(WNT)
@@ -106,6 +107,7 @@ public:
CPPUNIT_TEST(testFdo44176);
CPPUNIT_TEST(testFdo39053);
CPPUNIT_TEST(testFdo48356);
+ CPPUNIT_TEST(testFdo48023);
#endif
CPPUNIT_TEST_SUITE_END();
@@ -574,6 +576,29 @@ void RtfModelTest::testFdo48356()
CPPUNIT_ASSERT_EQUAL(1, i);
}
+void RtfModelTest::testFdo48023()
+{
+ lang::Locale aLocale;
+ aLocale.Language = "ru";
+ AllSettings aSettings(Application::GetSettings());
+ AllSettings aSavedSettings(aSettings);
+ aSettings.SetLocale(aLocale);
+ Application::SetSettings(aSettings);
+ load("fdo48023.rtf");
+ Application::SetSettings(aSavedSettings);
+
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xRangeEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xRangeEnum = xRangeEnumAccess->createEnumeration();
+ uno::Reference<text::XTextRange> xTextRange(xRangeEnum->nextElement(), uno::UNO_QUERY);
+
+ // Implicit encoding detection based on locale was missing
+ OUString aExpected("Программист", 22, RTL_TEXTENCODING_UTF8);
+ CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(RtfModelTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 2527cefd0042..2b304819523a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -513,13 +513,26 @@ sal_uInt32 RTFDocumentImpl::getColorTable(sal_uInt32 nIndex)
return 0;
}
+rtl_TextEncoding lcl_getDefaultTextEncoding()
+{
+
+ const OUString& rLanguage = Application::GetSettings().GetLocale().Language;
+
+ if (rLanguage == "ru" || rLanguage == "uk")
+ return RTL_TEXTENCODING_MS_1251;
+ if (rLanguage == "tr")
+ return RTL_TEXTENCODING_MS_1254;
+ else
+ return RTL_TEXTENCODING_MS_1252;
+}
+
rtl_TextEncoding RTFDocumentImpl::getEncoding(sal_uInt32 nFontIndex)
{
if (!m_pSuperstream)
{
if (nFontIndex < m_aFontEncodings.size())
return m_aFontEncodings[nFontIndex];
- return 0;
+ return lcl_getDefaultTextEncoding();
}
else
return m_pSuperstream->getEncoding(nFontIndex);