From 33aefc7d578965a2a9366d4366c2e1f8dd2e5875 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 3 Jun 2014 20:18:59 +0200 Subject: RTF import: fix handling of \loch \hich \dbch \ltrch \rtlch The logic is not immediately obvious from the RTF spec; let's do what the editengine RTF import does, but without the unnecessary complexity. (cherry picked from commit 36246aa9fb57c9fe4e546c91a8274d8828b1424e) Conflicts: writerfilter/source/rtftok/rtfdocumentimpl.cxx writerfilter/source/rtftok/rtfdocumentimpl.hxx Change-Id: I60e69130e6e5aed1f5d237f64b1656c3141e402a Reviewed-on: https://gerrit.libreoffice.org/9634 Reviewed-by: Miklos Vajna Tested-by: Miklos Vajna --- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 23 ++++++++++++++++++----- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index f1ac1d102cc9..920b19f8108d 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2626,8 +2626,10 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) break; case RTF_LTRCH: // dmapper does not support this. + m_aStates.top().isRightToLeft = false; break; case RTF_RTLCH: + m_aStates.top().isRightToLeft = true; if (m_aDefaultState.nCurrentEncoding == RTL_TEXTENCODING_MS_1255) m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding; break; @@ -3187,11 +3189,20 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) { case RTF_F: case RTF_AF: - if (nKeyword == RTF_F) - nSprm = NS_sprm::LN_CRgFtc0; + if (m_aStates.top().isRightToLeft + || m_aStates.top().eRunType == RTFParserState::HICH) + { + nSprm = NS_sprm::LN_CRgFtc2; + } + else if (m_aStates.top().eRunType == RTFParserState::DBCH) + { + nSprm = NS_sprm::LN_CRgFtc1; + } else - nSprm = (m_aStates.top().eRunType == RTFParserState::HICH - ? NS_sprm::LN_CRgFtc1 : NS_sprm::LN_CRgFtc2); + { + assert(m_aStates.top().eRunType == RTFParserState::LOCH); + nSprm = NS_sprm::LN_CRgFtc0; + } if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE || m_aStates.top().nDestinationState == DESTINATION_FONTENTRY) { m_aFontIndexes.push_back(nParam); @@ -3215,7 +3226,8 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) int nFontIndex = getFontIndex(nParam); RTFValue::Pointer_t pValue(new RTFValue(nFontIndex)); m_aStates.top().aCharacterSprms.set(nSprm, pValue); - m_aStates.top().nCurrentEncoding = getEncoding(nFontIndex); + if (nKeyword == RTF_F) + m_aStates.top().nCurrentEncoding = getEncoding(nFontIndex); } break; case RTF_RED: @@ -5198,6 +5210,7 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl) aDrawingObject(), aFrame(this), eRunType(LOCH), + isRightToLeft(false), nYear(0), nMonth(0), nDay(0), diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index a6e44067ea30..07571d27c069 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -255,6 +255,8 @@ namespace writerfilter { /// CJK or CTL? enum { LOCH, HICH, DBCH } eRunType; + /// ltrch or rtlch + bool isRightToLeft; // Info group. int nYear; -- cgit