From f10404e30ab2f468147457f0304e0e9fe64eefa3 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Thu, 6 Dec 2018 22:09:47 +0300 Subject: tdf#121110 ww8import Jc80 justify is absolute, not Bidi relative Paragraph justification can be specified either absolutely (in old versions or with eWW8:Jc80) or relatively (with eWW8:Jc). The last processed SPRM wins (I assume). The WW8 format seems to ALWAYS specify Jc80, and that is overwritten by an optional Jc SPRM. I haven't seen Jc be processed before a Jc80 SPRM, but if it does, then the justify would need to be treated as absolute. If for some reason neither of these exist, BiDi will adjust by default only if it is the newer WW8 format. Again, that is an assumption because I haven't seen such a document to test. Change-Id: I966077d743f1d148fe2fb9faba87fbdd8f3507f3 Reviewed-on: https://gerrit.libreoffice.org/63591 Tested-by: Jenkins Reviewed-by: Justin Luth Reviewed-by: Miklos Vajna --- sw/source/filter/ww8/ww8par6.cxx | 77 +++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) (limited to 'sw/source/filter/ww8/ww8par6.cxx') diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 32b822aee523..f743d11cd7cf 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -310,6 +310,59 @@ void SwWW8ImplReader::SetDocumentGrid(SwFrameFormat &rFormat, const wwSection &r rFormat.SetFormatAttr(aGrid); } +void SwWW8ImplReader::SetRelativeJustify( bool bRel ) +{ + if ( m_pCurrentColl && StyleExists(m_nCurrentColl) ) // importing style + m_vColl[m_nCurrentColl].m_nRelativeJustify = bRel ? 1 : 0; + else if ( m_xPlcxMan && m_xPlcxMan->GetPap() ) // importing paragraph + m_xPlcxMan->GetPap()->nRelativeJustify = bRel ? 1 : 0; +} + +bool SwWW8ImplReader::IsRelativeJustify() +{ + bool bRet = m_xWwFib->GetFIBVersion() >= ww::eWW8; + if ( bRet ) + { + // if relativeJustify is undefined (-1), then check the parent style. + if ( m_pCurrentColl && StyleExists(m_nCurrentColl) ) + { + sal_Int16 nRelative = m_vColl[m_nCurrentColl].m_nRelativeJustify; + if ( nRelative < 0 && m_nCurrentColl ) + bRet = IsRelativeJustify( m_vColl[m_nCurrentColl].m_nBase ); + else + bRet = nRelative > 0; + } + else if ( m_xPlcxMan && m_xPlcxMan->GetPap() ) + { + sal_Int16 nRelative = m_xPlcxMan->GetPap()->nRelativeJustify; + if ( nRelative < 0 ) + bRet = IsRelativeJustify( m_nCurrentColl ); + else + bRet = nRelative > 0; + } + } + + return bRet; +} + +bool SwWW8ImplReader::IsRelativeJustify( sal_uInt16 nColl ) +{ + assert( m_xWwFib->GetFIBVersion() >= ww::eWW8 + && "pointless to search styles if relative justify is impossible"); + bool bRet = true; + if ( StyleExists(nColl) ) + { + // if relativeJustify is undefined (-1), then check the parent style. + sal_Int16 nRelative = m_vColl[nColl].m_nRelativeJustify; + if ( nColl == 0 || nRelative >= 0 ) + bRet = nRelative > 0; + else if ( nColl != m_vColl[nColl].m_nBase ) + bRet = IsRelativeJustify( m_vColl[nColl].m_nBase ); + } + + return bRet; +} + void SwWW8ImplReader::Read_ParaBiDi(sal_uInt16, const sal_uInt8* pData, short nLen) { if (nLen < 1) @@ -319,11 +372,17 @@ void SwWW8ImplReader::Read_ParaBiDi(sal_uInt16, const sal_uInt8* pData, short nL SvxFrameDirection eDir = *pData ? SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB; - // Previous adjust or bidi values require changing paraAdjust. - // Only change if ParaBiDi doesn't match previous setting. - const bool bParentRTL = IsRightToLeft(); - if ( (eDir == SvxFrameDirection::Horizontal_RL_TB && !bParentRTL) || - (eDir == SvxFrameDirection::Horizontal_LR_TB && bParentRTL) ) + // In eWW8+, justify can be absolute, or relative to BiDi + bool bBiDiSwap = IsRelativeJustify(); + if ( bBiDiSwap ) + { + // Only change if ParaBiDi doesn't match previous setting. + const bool bParentRTL = IsRightToLeft(); + bBiDiSwap = (eDir == SvxFrameDirection::Horizontal_RL_TB && !bParentRTL) + || (eDir == SvxFrameDirection::Horizontal_LR_TB && bParentRTL); + } + + if ( bBiDiSwap ) { const SvxAdjustItem* pItem = static_cast(GetFormatAttr(RES_PARATR_ADJUST)); if ( !pItem ) @@ -4412,7 +4471,7 @@ void SwWW8ImplReader::Read_IdctHint( sal_uInt16, const sal_uInt8* pData, short n } } -void SwWW8ImplReader::Read_Justify( sal_uInt16, const sal_uInt8* pData, short nLen ) +void SwWW8ImplReader::Read_Justify( sal_uInt16 nId, const sal_uInt8* pData, short nLen ) { if (nLen < 1) { @@ -4446,6 +4505,7 @@ void SwWW8ImplReader::Read_Justify( sal_uInt16, const sal_uInt8* pData, short nL aAdjust.SetLastBlock(SvxAdjust::Block); NewAttr(aAdjust); + SetRelativeJustify( nId != NS_sprm::sprmPJc80 ); } bool SwWW8ImplReader::IsRightToLeft() @@ -4466,7 +4526,7 @@ bool SwWW8ImplReader::IsRightToLeft() return bRTL; } -void SwWW8ImplReader::Read_RTLJustify( sal_uInt16, const sal_uInt8* pData, short nLen ) +void SwWW8ImplReader::Read_RTLJustify( sal_uInt16 nId, const sal_uInt8* pData, short nLen ) { if (nLen < 1) { @@ -4477,7 +4537,7 @@ void SwWW8ImplReader::Read_RTLJustify( sal_uInt16, const sal_uInt8* pData, short //If we are in a ltr paragraph this is the same as normal Justify, //If we are in a rtl paragraph the meaning is reversed. if (!IsRightToLeft()) - Read_Justify(NS_sprm::sprmPJc80 /*dummy*/, pData, nLen); + Read_Justify(nId, pData, nLen); else { SvxAdjust eAdjust(SvxAdjust::Right); @@ -4506,6 +4566,7 @@ void SwWW8ImplReader::Read_RTLJustify( sal_uInt16, const sal_uInt8* pData, short aAdjust.SetLastBlock(SvxAdjust::Block); NewAttr(aAdjust); + SetRelativeJustify( true ); } } -- cgit