summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-02-13 18:42:56 +0100
committerMiklos Vajna <vmiklos@suse.cz>2012-02-13 18:44:48 +0100
commitd7baacd81bbcfaa35b7fbf9981fa3fa7c9fb1cb4 (patch)
tree7ad515c8d8b50bff432d8f7fb99442089b0700c4
parent8963cc01f5267f3afc4e4a4ff5a65a67520f447b (diff)
fdo#45543 fix RTF import of ms932-encoded characters
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx27
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx6
2 files changed, 25 insertions, 8 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index bd02037edcff..4c3994765d0a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -297,7 +297,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
m_bWasInFrame(false),
m_bIsInFrame(false),
m_bHasPage(false),
- m_aUnicodeBuffer()
+ m_aUnicodeBuffer(),
+ m_aHexBuffer()
{
OSL_ASSERT(xInputStream.is());
m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
@@ -727,6 +728,9 @@ int RTFDocumentImpl::resolvePict(bool bInline)
int RTFDocumentImpl::resolveChars(char ch)
{
+ if (m_aStates.top().nInternalState != INTERNAL_HEX)
+ checkUnicode(false, true);
+
OStringBuffer aBuf;
bool bUnicodeChecked = false;
@@ -738,7 +742,7 @@ int RTFDocumentImpl::resolveChars(char ch)
{
if (!bUnicodeChecked)
{
- checkUnicode();
+ checkUnicode(true, false);
bUnicodeChecked = true;
}
aBuf.append(ch);
@@ -753,6 +757,13 @@ int RTFDocumentImpl::resolveChars(char ch)
}
if (m_aStates.top().nInternalState != INTERNAL_HEX && !Strm().IsEof())
Strm().SeekRel(-1);
+
+ if (m_aStates.top().nInternalState == INTERNAL_HEX)
+ {
+ m_aHexBuffer.append(ch);
+ return 0;
+ }
+
if (m_aStates.top().nDestinationState == DESTINATION_SKIP)
return 0;
OString aStr = aBuf.makeStringAndClear();
@@ -1980,8 +1991,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
{
- if (nKeyword != RTF_U)
- checkUnicode();
+ checkUnicode(nKeyword != RTF_U, true);
RTFSkipDestination aSkip(*this);
int nSprm = 0;
RTFValue::Pointer_t pIntValue(new RTFValue(nParam));
@@ -3290,13 +3300,18 @@ void RTFDocumentImpl::setSkipUnknown(bool bSkipUnknown)
m_bSkipUnknown = bSkipUnknown;
}
-void RTFDocumentImpl::checkUnicode()
+void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
{
- if (m_aUnicodeBuffer.getLength() > 0)
+ if (bUnicode && m_aUnicodeBuffer.getLength() > 0)
{
OUString aString = m_aUnicodeBuffer.makeStringAndClear();
text(aString);
}
+ if (bHex && m_aHexBuffer.getLength() > 0)
+ {
+ OUString aString = OStringToOUString(m_aHexBuffer.makeStringAndClear(), m_aStates.top().nCurrentEncoding);
+ text(aString);
+ }
}
RTFParserState::RTFParserState()
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 90ecc98bd4ee..62429739bb6e 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -352,8 +352,8 @@ namespace writerfilter {
void replayBuffer(RTFBuffer_t& rBuffer);
/// If we got tokens indicating we're in a frame.
bool inFrame();
- /// If we have some unicode characters to send.
- void checkUnicode();
+ /// If we have some unicode or hex characters to send.
+ void checkUnicode(bool bUnicode = true, bool bHex = true);
uno::Reference<uno::XComponentContext> const& m_xContext;
uno::Reference<io::XInputStream> const& m_xInputStream;
@@ -442,6 +442,8 @@ namespace writerfilter {
bool m_bHasPage;
// Unicode characters are collected here so we don't have to send them one by one.
rtl::OUStringBuffer m_aUnicodeBuffer;
+ /// Same for hex characters.
+ rtl::OStringBuffer m_aHexBuffer;
};
} // namespace rtftok
} // namespace writerfilter