From c83e50d16491ed975029d85bbafdae40b1a1e375 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Sat, 16 Nov 2024 19:32:40 +0300 Subject: [PATCH] fix bug #59349 --- RtfFile/Format/DestinationCommand.cpp | 69 ++++++++++++++++++++++++--- RtfFile/Format/RtfDocument.cpp | 3 +- RtfFile/Format/RtfDocument.h | 2 +- RtfFile/Format/RtfShape.cpp | 18 ++++--- RtfFile/Format/Utils.cpp | 4 ++ RtfFile/Format/Utils.h | 1 + 6 files changed, 82 insertions(+), 15 deletions(-) diff --git a/RtfFile/Format/DestinationCommand.cpp b/RtfFile/Format/DestinationCommand.cpp index ef00f0282ad..4ff675e95fd 100644 --- a/RtfFile/Format/DestinationCommand.cpp +++ b/RtfFile/Format/DestinationCommand.cpp @@ -1718,8 +1718,12 @@ void RtfOldShapeReader::ExitReader( RtfDocument& oDocument, RtfReader& oReader ) } bool RtfOldShapeReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter) { - if ( "do" == sCommand ) + if ("do" == sCommand) + { + m_oShape.m_bLayoutInCell = 0; + m_oShape.m_nZOrderRelative = 1; return true; + } else if ( "doinst" == sCommand ) return true; else if ( "dorslt" == sCommand ) @@ -1754,19 +1758,66 @@ bool RtfOldShapeReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReade else if ( "dolockanchor" == sCommand ) m_oShape.m_bLockAnchor = true; else if ( "dplinehollow" == sCommand ) m_oShape.m_bLine = false; + else if ("dplinecor" == sCommand) + { + if (m_oShape.m_nLineColor == PROP_DEF) m_oShape.m_nLineColor = 0xFFFFFF; + SETBITS(m_oShape.m_nLineColor, 0, 7, parameter); + } + else if ("dplinecog" == sCommand) + { + if (m_oShape.m_nLineColor == PROP_DEF) m_oShape.m_nLineColor = 0xFFFFFF; + SETBITS(m_oShape.m_nLineColor, 8, 15, parameter); + } + else if ("dplinecob" == sCommand) + { + if (m_oShape.m_nLineColor == PROP_DEF) m_oShape.m_nLineColor = 0xFFFFFF; + SETBITS(m_oShape.m_nLineColor, 16, 23, parameter); + } + else if ("dpfillbgcr" == sCommand) + { + if (m_oShape.m_nFillColor == PROP_DEF) m_oShape.m_nFillColor = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor, 0, 7, parameter); + } + else if ("dpfillbgcg" == sCommand) + { + if (m_oShape.m_nFillColor == PROP_DEF) m_oShape.m_nFillColor = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor, 8, 15, parameter); + } + else if ("dpfillbgcb" == sCommand) + { + if (m_oShape.m_nFillColor == PROP_DEF) m_oShape.m_nFillColor = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor, 16, 23, parameter); + } + else if ("dpfillfgcr" == sCommand) + { + if (m_oShape.m_nFillColor2 == PROP_DEF) m_oShape.m_nFillColor2 = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor2, 0, 7, parameter); + } + else if ("dpfillfgcg" == sCommand) + { + if (m_oShape.m_nFillColor2 == PROP_DEF) m_oShape.m_nFillColor2 = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor2, 8, 15, parameter); + } + else if ("dpfillfgcb" == sCommand) + { + if (m_oShape.m_nFillColor2 == PROP_DEF) m_oShape.m_nFillColor2 = 0xFFFFFF; + SETBITS(m_oShape.m_nFillColor2, 16, 23, parameter); + } else if ( hasParameter) { if ( "dpx" == sCommand ) m_oShape.m_nLeft = parameter; - else if ( "dpx" == sCommand ) m_oShape.m_nLeft = parameter; else if ( "dpy" == sCommand ) m_oShape.m_nTop = parameter; - else if ( "dpysize" == sCommand ) m_oShape.m_nBottom = parameter + m_oShape.m_nTop; else if ( "dpxsize" == sCommand ) m_oShape.m_nRight = parameter + m_oShape.m_nLeft; + else if ( "dpysize" == sCommand ) m_oShape.m_nBottom = parameter + m_oShape.m_nTop; else if ( "doz" == sCommand ) m_oShape.m_nZOrder = parameter; else if ( "dofhdr" == sCommand ) m_oShape.m_nHeader = parameter; else if ( "dowr" == sCommand ) m_oShape.m_nWrapType = parameter; else if ( "dowrk" == sCommand ) m_oShape.m_nWrapSideType = parameter; else if ( "dofblwtxt" == sCommand ) m_oShape.m_nZOrderRelative = parameter; - else if ( "dplinew" == sCommand ) m_oShape.m_nLineWidth = parameter; + else if ( "dplinew" == sCommand ) m_oShape.m_nLineWidth = RtfUtility::Pt2Emu(parameter); + else if ( "dplinehollow"== sCommand ) m_oShape.m_bLine = false; + else if ( "dplinedot" == sCommand ) m_oShape.m_nLineDashing = 5; + else if ( "dplinedash" == sCommand ) m_oShape.m_nLineDashing = 6; else if ( "dodhgt" == sCommand ) m_oShape.m_nZOrder = parameter; else if ( "dptxbxmar" == sCommand ) { @@ -1774,8 +1825,14 @@ bool RtfOldShapeReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReade } else if ( "dpfillpat" == sCommand ) { - m_oShape.m_nFillType = parameter; - if (m_oShape.m_nFillType == 0) m_oShape.m_bFilled = false; + switch(parameter) + { + case 0: m_oShape.m_bFilled = false; break; + case 1: m_oShape.m_nFillType = 0; break; //solid + default: + m_oShape.m_nFillType = 2; // pattern + break; + } } } else diff --git a/RtfFile/Format/RtfDocument.cpp b/RtfFile/Format/RtfDocument.cpp index 60e3e53c09e..6e056743d81 100644 --- a/RtfFile/Format/RtfDocument.cpp +++ b/RtfFile/Format/RtfDocument.cpp @@ -77,8 +77,9 @@ std::wstring RtfDocument::RenderToOOX(RenderParameter oRenderParameter) return L""; } -int RtfDocument::GetZIndex() +int RtfDocument::GetZIndex(bool bReverse) { + if (bReverse ) return -(0xFFFF - (m_nZIndexLast++)); return m_nZIndexLast++; } void RtfDocument::SetZIndex(int val) diff --git a/RtfFile/Format/RtfDocument.h b/RtfFile/Format/RtfDocument.h index 86766ac9ce1..58635888644 100644 --- a/RtfFile/Format/RtfDocument.h +++ b/RtfFile/Format/RtfDocument.h @@ -96,7 +96,7 @@ class RtfDocument : public ItemContainer<_section> public: MS_LCID_converter m_lcidConverter; - int GetZIndex(); + int GetZIndex(bool bReverse = false); void SetZIndex(int val); IdGenerator m_oIdGenerator; diff --git a/RtfFile/Format/RtfShape.cpp b/RtfFile/Format/RtfShape.cpp index c5243517a46..198113aef76 100644 --- a/RtfFile/Format/RtfShape.cpp +++ b/RtfFile/Format/RtfShape.cpp @@ -1160,19 +1160,23 @@ std::wstring RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter) sStyle += L"rotation:" + std::to_wstring(m_nRelRotation / 65536) + L";"; int nZIndex = PROP_DEF; - if( PROP_DEF != m_nRelZOrder ) - nZIndex = m_nRelZOrder; - else if( PROP_DEF != m_nZOrder ) - nZIndex = m_nZOrder; + if (PROP_DEF != m_nRelZOrder) + { + if (0 == m_nZOrderRelative) nZIndex = m_nRelZOrder; + else nZIndex = -m_nRelZOrder; + } + else if (PROP_DEF != m_nZOrder) + { + if (0 == m_nZOrderRelative) nZIndex = m_nZOrder; + else nZIndex = -m_nZOrder; + } else if (oRenderParameter.nType != RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2) { - nZIndex = poRtfDocument->GetZIndex(); + nZIndex = poRtfDocument->GetZIndex(0 != m_nZOrderRelative); } if( PROP_DEF != m_nZOrderRelative && PROP_DEF != nZIndex) { - if( 0 == m_nZOrderRelative ) nZIndex = abs(nZIndex); - else nZIndex = -abs(nZIndex); } if (PROP_DEF != nZIndex) sStyle += L"z-index:" + std::to_wstring(nZIndex) + L";"; diff --git a/RtfFile/Format/Utils.cpp b/RtfFile/Format/Utils.cpp index f14ed380288..85f736a3020 100644 --- a/RtfFile/Format/Utils.cpp +++ b/RtfFile/Format/Utils.cpp @@ -300,6 +300,10 @@ float RtfUtility::Emu2Pt(int emu) { return (float)(1.0 * emu / (635 * 20.0)); } +int RtfUtility::Pt2Emu(int pt) +{ + return pt * (635 * 20); +} void RtfUtility::WriteDataToFileBinary(std::wstring& sFilename, BYTE* pbData, size_t nLength) { if( NULL == pbData ) diff --git a/RtfFile/Format/Utils.h b/RtfFile/Format/Utils.h index 687f0df0eba..25fed2b06ca 100644 --- a/RtfFile/Format/Utils.h +++ b/RtfFile/Format/Utils.h @@ -207,6 +207,7 @@ class RtfUtility static int Twips2Emu(int pt); static int Emu2Twips(int pt); static float Emu2Pt(int emu); + static int Pt2Emu(int emu); static void WriteDataToFileBinary(std::wstring& sFilename, BYTE* pbData, size_t nLength); static void WriteDataToFile(std::wstring& sFilename, std::wstring& sData); static void DecodeHexString( std::string sHexText, BYTE *&pData );