summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorSerge Krot <Serge.Krot@cib.de>2019-05-30 15:33:29 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-06-18 11:38:53 +0200
commit3c1f6fc029ab8ff9129f2316a3d7c81bc7b69125 (patch)
tree16b33e39a9d43fd8c822f173507e83376d4ce8cb /writerfilter
parent1170001897078dd0bdafb2c00da8657e3660267c (diff)
tdf#125719 sw: rtf: refactor associated character properties
1. \rtlch, \ltrch should be placed before their properties. 2. Do not mix associated and normal character properties in output. 3. Do not output empty "\rtlch \ltrch", "\ltrch \rtlch" pairs. 4. Handle associated character properties runs instead of handling separately their parts without order of them. Change-Id: Ibbf7365d04708682a5f1eb664a579c60a47465d2 Reviewed-on: https://gerrit.libreoffice.org/72578 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> (cherry picked from commit fd95fb975b754d71d3750e85431a4e596a40e659) Reviewed-on: https://gerrit.libreoffice.org/73868 Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/rtftok/rtfdispatchflag.cxx17
-rw-r--r--writerfilter/source/rtftok/rtfdispatchvalue.cxx77
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx49
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.hxx11
4 files changed, 106 insertions, 48 deletions
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx
index 46592a24105b..3ea7872d52a1 100644
--- a/writerfilter/source/rtftok/rtfdispatchflag.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx
@@ -473,8 +473,7 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
m_aStates.top().setCurrentEncoding(getEncoding(getFontIndex(m_nDefaultFontIndex)));
m_aStates.top().getCharacterAttributes() = getDefaultState().getCharacterAttributes();
m_aStates.top().setCurrentCharacterStyleIndex(-1);
- m_aStates.top().setIsRightToLeft(false);
- m_aStates.top().setRunType(RTFParserState::RunType::LOCH);
+ m_aStates.top().setRunType(RTFParserState::RunType::NONE);
}
break;
case RTF_PARD:
@@ -565,6 +564,7 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
case RTF_RTLSECT:
{
auto pValue = new RTFValue(nKeyword == RTF_LTRSECT ? 0 : 1);
+ m_aStates.top().setRunType(RTFParserState::RunType::NONE);
m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_EG_SectPrContents_textDirection,
pValue);
}
@@ -573,20 +573,29 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
case RTF_RTLPAR:
{
auto pValue = new RTFValue(nKeyword == RTF_LTRPAR ? 0 : 1);
+ m_aStates.top().setRunType(RTFParserState::RunType::NONE);
m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_bidi, pValue);
}
break;
case RTF_LTRROW:
case RTF_RTLROW:
+ m_aStates.top().setRunType(RTFParserState::RunType::NONE);
m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblPrBase_bidiVisual,
new RTFValue(int(nKeyword == RTF_RTLROW)));
break;
case RTF_LTRCH:
// dmapper does not support this.
- m_aStates.top().setIsRightToLeft(false);
+ if (m_aStates.top().getRunType() == RTFParserState::RunType::RTLCH_LTRCH_1)
+ m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_2);
+ else
+ m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_1);
break;
case RTF_RTLCH:
- m_aStates.top().setIsRightToLeft(true);
+ if (m_aStates.top().getRunType() == RTFParserState::RunType::LTRCH_RTLCH_1)
+ m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_2);
+ else
+ m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_1);
+
if (m_aDefaultState.getCurrentEncoding() == RTL_TEXTENCODING_MS_1255)
m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding());
break;
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index e12a57f1d2a9..fa6bcc46f024 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -164,10 +164,22 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
{
case RTF_FS:
case RTF_AFS:
- nSprm = (m_aStates.top().getIsRightToLeft()
- || m_aStates.top().getRunType() == RTFParserState::RunType::HICH)
- ? NS_ooxml::LN_EG_RPrBase_szCs
- : NS_ooxml::LN_EG_RPrBase_sz;
+ switch (m_aStates.top().getRunType())
+ {
+ case RTFParserState::RunType::HICH:
+ case RTFParserState::RunType::RTLCH_LTRCH_1:
+ case RTFParserState::RunType::LTRCH_RTLCH_2:
+ case RTFParserState::RunType::DBCH:
+ nSprm = NS_ooxml::LN_EG_RPrBase_szCs;
+ break;
+ case RTFParserState::RunType::NONE:
+ case RTFParserState::RunType::LOCH:
+ case RTFParserState::RunType::LTRCH_RTLCH_1:
+ case RTFParserState::RunType::RTLCH_LTRCH_2:
+ default:
+ nSprm = NS_ooxml::LN_EG_RPrBase_sz;
+ break;
+ }
break;
case RTF_EXPNDTW:
nSprm = NS_ooxml::LN_EG_RPrBase_spacing;
@@ -191,19 +203,23 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
{
case RTF_LANG:
case RTF_ALANG:
- if (m_aStates.top().getIsRightToLeft()
- || m_aStates.top().getRunType() == RTFParserState::RunType::HICH)
- {
- nSprm = NS_ooxml::LN_CT_Language_bidi;
- }
- else if (m_aStates.top().getRunType() == RTFParserState::RunType::DBCH)
+ switch (m_aStates.top().getRunType())
{
- nSprm = NS_ooxml::LN_CT_Language_eastAsia;
- }
- else
- {
- assert(m_aStates.top().getRunType() == RTFParserState::RunType::LOCH);
- nSprm = NS_ooxml::LN_CT_Language_val;
+ case RTFParserState::RunType::HICH:
+ case RTFParserState::RunType::RTLCH_LTRCH_1:
+ case RTFParserState::RunType::LTRCH_RTLCH_2:
+ nSprm = NS_ooxml::LN_CT_Language_bidi;
+ break;
+ case RTFParserState::RunType::DBCH:
+ nSprm = NS_ooxml::LN_CT_Language_eastAsia;
+ break;
+ case RTFParserState::RunType::NONE:
+ case RTFParserState::RunType::LOCH:
+ case RTFParserState::RunType::LTRCH_RTLCH_1:
+ case RTFParserState::RunType::RTLCH_LTRCH_2:
+ default:
+ nSprm = NS_ooxml::LN_CT_Language_val;
+ break;
}
break;
case RTF_LANGFE: // this one is always CJK apparently
@@ -336,20 +352,25 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
{
case RTF_F:
case RTF_AF:
- if (m_aStates.top().getIsRightToLeft()
- || m_aStates.top().getRunType() == RTFParserState::RunType::HICH)
- {
- nSprm = NS_ooxml::LN_CT_Fonts_cs;
- }
- else if (m_aStates.top().getRunType() == RTFParserState::RunType::DBCH)
+ switch (m_aStates.top().getRunType())
{
- nSprm = NS_ooxml::LN_CT_Fonts_eastAsia;
- }
- else
- {
- assert(m_aStates.top().getRunType() == RTFParserState::RunType::LOCH);
- nSprm = NS_ooxml::LN_CT_Fonts_ascii;
+ case RTFParserState::RunType::HICH:
+ case RTFParserState::RunType::RTLCH_LTRCH_1:
+ case RTFParserState::RunType::LTRCH_RTLCH_2:
+ nSprm = NS_ooxml::LN_CT_Fonts_cs;
+ break;
+ case RTFParserState::RunType::DBCH:
+ nSprm = NS_ooxml::LN_CT_Fonts_eastAsia;
+ break;
+ case RTFParserState::RunType::NONE:
+ case RTFParserState::RunType::LOCH:
+ case RTFParserState::RunType::LTRCH_RTLCH_1:
+ case RTFParserState::RunType::RTLCH_LTRCH_2:
+ default:
+ nSprm = NS_ooxml::LN_CT_Fonts_ascii;
+ break;
}
+
if (m_aStates.top().getDestination() == Destination::FONTTABLE
|| m_aStates.top().getDestination() == Destination::FONTENTRY)
{
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index b6d8290283cc..43463dabc152 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1850,17 +1850,41 @@ RTFError RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int n
{
case RTF_B:
case RTF_AB:
- nSprm = (m_aStates.top().getIsRightToLeft()
- || m_aStates.top().getRunType() == RTFParserState::RunType::HICH)
- ? NS_ooxml::LN_EG_RPrBase_bCs
- : NS_ooxml::LN_EG_RPrBase_b;
+ switch (m_aStates.top().getRunType())
+ {
+ case RTFParserState::RunType::HICH:
+ case RTFParserState::RunType::RTLCH_LTRCH_1:
+ case RTFParserState::RunType::LTRCH_RTLCH_2:
+ case RTFParserState::RunType::DBCH:
+ nSprm = NS_ooxml::LN_EG_RPrBase_bCs;
+ break;
+ case RTFParserState::RunType::NONE:
+ case RTFParserState::RunType::LOCH:
+ case RTFParserState::RunType::LTRCH_RTLCH_1:
+ case RTFParserState::RunType::RTLCH_LTRCH_2:
+ default:
+ nSprm = NS_ooxml::LN_EG_RPrBase_b;
+ break;
+ }
break;
case RTF_I:
case RTF_AI:
- nSprm = (m_aStates.top().getIsRightToLeft()
- || m_aStates.top().getRunType() == RTFParserState::RunType::HICH)
- ? NS_ooxml::LN_EG_RPrBase_iCs
- : NS_ooxml::LN_EG_RPrBase_i;
+ switch (m_aStates.top().getRunType())
+ {
+ case RTFParserState::RunType::HICH:
+ case RTFParserState::RunType::RTLCH_LTRCH_1:
+ case RTFParserState::RunType::LTRCH_RTLCH_2:
+ case RTFParserState::RunType::DBCH:
+ nSprm = NS_ooxml::LN_EG_RPrBase_iCs;
+ break;
+ case RTFParserState::RunType::NONE:
+ case RTFParserState::RunType::LOCH:
+ case RTFParserState::RunType::LTRCH_RTLCH_1:
+ case RTFParserState::RunType::RTLCH_LTRCH_2:
+ default:
+ nSprm = NS_ooxml::LN_EG_RPrBase_i;
+ break;
+ }
break;
case RTF_OUTL:
nSprm = NS_ooxml::LN_EG_RPrBase_outline;
@@ -1950,7 +1974,11 @@ RTFError RTFDocumentImpl::pushState()
else
{
// fdo#85812 group resets run type of _current_ and new state (but not RTL)
- m_aStates.top().setRunType(RTFParserState::RunType::LOCH);
+ if (m_aStates.top().getRunType() != RTFParserState::RunType::LTRCH_RTLCH_2
+ && m_aStates.top().getRunType() != RTFParserState::RunType::RTLCH_LTRCH_2)
+ {
+ m_aStates.top().setRunType(RTFParserState::RunType::NONE);
+ }
if (m_aStates.top().getDestination() == Destination::MR)
lcl_DestinationToMath(m_aStates.top().getCurrentDestinationText(), m_aMathBuffer,
@@ -3567,8 +3595,7 @@ RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl)
, m_nListLevelNum(0)
, m_bLevelNumbersValid(true)
, m_aFrame(this)
- , m_eRunType(RunType::LOCH)
- , m_bIsRightToLeft(false)
+ , m_eRunType(RunType::NONE)
, m_nYear(0)
, m_nMonth(0)
, m_nDay(0)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 24739f682206..f7a263c2bc11 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -401,9 +401,14 @@ public:
/// Maps to OOXML's ascii, cs or eastAsia.
enum class RunType
{
+ NONE,
LOCH,
HICH,
- DBCH
+ DBCH,
+ LTRCH_RTLCH_1,
+ LTRCH_RTLCH_2,
+ RTLCH_LTRCH_1,
+ RTLCH_LTRCH_2
};
explicit RTFParserState(RTFDocumentImpl* pDocumentImpl);
@@ -475,8 +480,6 @@ public:
sal_uInt16 getMonth() const { return m_nMonth; }
void setYear(sal_uInt16 nYear) { m_nYear = nYear; }
sal_uInt16 getYear() const { return m_nYear; }
- void setIsRightToLeft(bool bIsRightToLeft) { m_bIsRightToLeft = bIsRightToLeft; }
- bool getIsRightToLeft() const { return m_bIsRightToLeft; }
void setRunType(RunType eRunType) { m_eRunType = eRunType; }
RunType getRunType() const { return m_eRunType; }
RTFFrame& getFrame() { return m_aFrame; }
@@ -578,8 +581,6 @@ private:
RTFFrame m_aFrame;
RunType m_eRunType;
- /// ltrch or rtlch
- bool m_bIsRightToLeft;
// Info group.
sal_Int16 m_nYear;