Fixed conversion of geometric shapes in HWP

This commit is contained in:
Kirill Polyakov
2025-09-29 17:00:06 +03:00
parent 4734d58ba6
commit aa4b0c8844
9 changed files with 161 additions and 63 deletions

View File

@ -15,6 +15,8 @@
#include "../Paragraph/CtrlShapeArc.h"
#include "../Paragraph/CtrlShapePolygon.h"
#include "../Paragraph/CtrlShapeCurve.h"
#include "../Paragraph/CtrlShapeLine.h"
#include "../Paragraph/CtrlShapeRect.h"
#include "../HWPElements/HWPRecordParaShape.h"
#include "../HWPElements/HWPRecordCharShape.h"
@ -332,7 +334,7 @@ void CConverter2OOXML::WriteCharacter(const CCtrlCharacter* pCharacter, short sh
}
}
void CConverter2OOXML::WriteShape(const CCtrlGeneralShape* pShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState)
void CConverter2OOXML::WriteShape(const CCtrlGeneralShape* pShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState, const CCtrlContainer *pContainer)
{
if (nullptr == pShape || oState.m_bInTextBox)
return;
@ -346,7 +348,7 @@ void CConverter2OOXML::WriteShape(const CCtrlGeneralShape* pShape, short shParaS
case EShapeType::Polygon:
case EShapeType::Curve:
{
WriteGeometryShape(pShape, shParaShapeID, shParaStyleID, oBuilder, oState);
WriteGeometryShape(pShape, shParaShapeID, shParaStyleID, oBuilder, oState, pContainer);
break;
}
case EShapeType::Pic:
@ -1002,7 +1004,7 @@ VECTOR<TPoint> ArcToBezier(const TPoint& oStart, const TPoint& oEnd, const TPoin
return {oStart, oControl1, oControl2, oEnd};
}
void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState)
void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState, const CCtrlContainer* pContainer)
{
if (nullptr == pGeneralShape)
return;
@ -1027,7 +1029,7 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
oBuilder.WriteString(L"<mc:AlternateContent><mc:Choice Requires=\"wps\">");
OpenDrawingNode(pGeneralShape, oBuilder);
OpenDrawingNode((nullptr != pContainer) ? pContainer : pGeneralShape, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">");
@ -1041,9 +1043,20 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
case EShapeObjectType::Arc:
{
const CCtrlShapeArc *pShapeArc = (const CCtrlShapeArc*)pGeneralShape;
VECTOR<TPoint> arBezierPoints{ArcToBezier({Transform::HWPUINT2OOXML(pShapeArc->GetFirstPoint() .m_nX), Transform::HWPUINT2OOXML(pShapeArc->GetFirstPoint() .m_nY)},
{Transform::HWPUINT2OOXML(pShapeArc->GetSecondPoint().m_nX), Transform::HWPUINT2OOXML(pShapeArc->GetSecondPoint().m_nY)},
{Transform::HWPUINT2OOXML(pShapeArc->GetCenterPoint().m_nX), Transform::HWPUINT2OOXML(pShapeArc->GetCenterPoint().m_nY)})};
TPoint oStartPoint {pShapeArc->GetFirstPoint()},
oEndPoint {pShapeArc->GetSecondPoint()},
oCenterPoint{pShapeArc->GetCenterPoint()};
const TMatrix oMatrix{pGeneralShape->GetFinalMatrix()};
oMatrix.ApplyToPoint(oStartPoint .m_nX, oStartPoint .m_nY);
oMatrix.ApplyToPoint(oEndPoint .m_nX, oEndPoint .m_nY);
oMatrix.ApplyToPoint(oCenterPoint.m_nX, oCenterPoint.m_nY);
VECTOR<TPoint> arBezierPoints{ArcToBezier({Transform::HWPUINT2OOXML(oStartPoint .m_nX), Transform::HWPUINT2OOXML(oStartPoint .m_nY)},
{Transform::HWPUINT2OOXML(oEndPoint .m_nX), Transform::HWPUINT2OOXML(oEndPoint .m_nY)},
{Transform::HWPUINT2OOXML(oCenterPoint.m_nX), Transform::HWPUINT2OOXML(oCenterPoint.m_nY)})};
oBuilder.WriteString(L"<a:custGeom><a:pathLst><a:path>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(arBezierPoints[0].m_nX) + L"\" y=\"" + std::to_wstring(arBezierPoints[0].m_nY) + L"\"/></a:moveTo>");
@ -1065,13 +1078,55 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
}
case EShapeObjectType::Line:
{
oBuilder.WriteString(L"<a:prstGeom prst=\"line\"><a:avLst/></a:prstGeom>");
const CCtrlShapeLine *pShapeLine = (const CCtrlShapeLine*)pGeneralShape;
TPoint oStartPoint{pShapeLine->GetStartX(), pShapeLine->GetStartY()},
oEndPoint {pShapeLine->GetEndX(), pShapeLine->GetEndY() };
const TMatrix oMatrix{pGeneralShape->GetFinalMatrix()};
oMatrix.ApplyToPoint(oStartPoint .m_nX, oStartPoint .m_nY);
oMatrix.ApplyToPoint(oEndPoint .m_nX, oEndPoint .m_nY);
oBuilder.WriteString(L"<a:custGeom><a:pathLst><a:path>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(oStartPoint.m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(oStartPoint.m_nY)) + L"\"/></a:moveTo>");
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(oEndPoint.m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(oEndPoint.m_nY)) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"</a:path></a:pathLst></a:custGeom>");
// oBuilder.WriteString(L"<a:prstGeom prst=\"line\"><a:avLst/></a:prstGeom>");
break;
}
case EShapeObjectType::Rectangle:
{
oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom>");
const CCtrlShapeRect* pShapeRect = (const CCtrlShapeRect*)pGeneralShape;
TPoint arPoints[4];
pShapeRect->GetPoints(arPoints);
const TMatrix oMatrix{pGeneralShape->GetFinalMatrix()};
for (TPoint& oPoint : arPoints)
{
oMatrix.ApplyToPoint(oPoint.m_nX, oPoint.m_nY);
oPoint.m_nX = Transform::HWPUINT2OOXML(oPoint.m_nX);
oPoint.m_nY = Transform::HWPUINT2OOXML(oPoint.m_nY);
}
oBuilder.WriteString(L"<a:custGeom><a:pathLst><a:path>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(arPoints[0].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[0].m_nY) + L"\"/></a:moveTo>");
for (unsigned short ushIndex = 1; ushIndex < 4; ++ushIndex)
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(arPoints[ushIndex].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex].m_nY) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(arPoints[0].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[0].m_nY) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"</a:path></a:pathLst></a:custGeom>");
// oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom>");
break;
}
case EShapeObjectType::Polygon:
@ -1081,11 +1136,21 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
if (2 > arPoints.size())
break;
const TMatrix oMatrix{pGeneralShape->GetFinalMatrix()};
for (TPoint& oPoint : arPoints)
{
oMatrix.ApplyToPoint(oPoint.m_nX, oPoint.m_nY);
oPoint.m_nX = Transform::HWPUINT2OOXML(oPoint.m_nX);
oPoint.m_nY = Transform::HWPUINT2OOXML(oPoint.m_nY);
}
oBuilder.WriteString(L"<a:custGeom><a:pathLst><a:path>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[0].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[0].m_nY)) + L"\"/></a:moveTo>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(arPoints[0].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[0].m_nY) + L"\"/></a:moveTo>");
for (unsigned short ushIndex = 1; ushIndex < arPoints.size(); ++ushIndex)
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex].m_nY)) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(arPoints[ushIndex].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex].m_nY) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"</a:path></a:pathLst></a:custGeom>");
break;
@ -1097,23 +1162,34 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
if (2 > arPoints.size())
break;
const TMatrix oMatrix{pGeneralShape->GetFinalMatrix()};
for (TPoint& oPoint : arPoints)
{
oPoint.m_nX = Transform::HWPUINT2OOXML(oPoint.m_nX);
oPoint.m_nY = Transform::HWPUINT2OOXML(oPoint.m_nY);
oMatrix.ApplyToPoint(oPoint.m_nX, oPoint.m_nY);
}
VECTOR<HWP_BYTE> arSegmentType{((const CCtrlShapeCurve*)pGeneralShape)->GetSegmentsType()};
oBuilder.WriteString(L"<a:custGeom><a:pathLst><a:path>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[0].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[0].m_nY)) + L"\"/></a:moveTo>");
oBuilder.WriteString(L"<a:moveTo><a:pt x=\"" + std::to_wstring(arPoints[0].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[0].m_nY) + L"\"/></a:moveTo>");
for (unsigned short ushIndex = 0; ushIndex < arSegmentType.size(); ++ushIndex)
{
if (0x01 == arSegmentType[ushIndex])
{
oBuilder.WriteString(L"<a:cubicBezTo>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 1].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 1].m_nY)) + L"\"/>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 2].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 2].m_nY)) + L"\"/>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 3].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 3].m_nY)) + L"\"/>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(arPoints[ushIndex + 1].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex + 1].m_nY) + L"\"/>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(arPoints[ushIndex + 2].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex + 2].m_nY) + L"\"/>");
oBuilder.WriteString(L"<a:pt x=\"" + std::to_wstring(arPoints[ushIndex + 3].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex + 3].m_nY) + L"\"/>");
oBuilder.WriteString(L"</a:cubicBezTo>");
ushIndex += 2;
}
else
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 1].m_nX)) + L"\" y=\"" + std::to_wstring(Transform::HWPUINT2OOXML(arPoints[ushIndex + 1].m_nY)) + L"\"/></a:lnTo>");
oBuilder.WriteString(L"<a:lnTo><a:pt x=\"" + std::to_wstring(arPoints[ushIndex + 1].m_nX) + L"\" y=\"" + std::to_wstring(arPoints[ushIndex + 1].m_nY) + L"\"/></a:lnTo>");
}
oBuilder.WriteString(L"</a:path></a:pathLst></a:custGeom>");
@ -1235,7 +1311,7 @@ void CConverter2OOXML::WriteOleShape(const CCtrlShapeOle* pOleShape, short shPar
void CConverter2OOXML::WriteContainer(const CCtrlContainer* pContainer, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState)
{
for (const CCtrlGeneralShape* pGeneralShape : pContainer->GetShapes())
WriteShape(pGeneralShape, shParaShapeID, shParaStyleID, oBuilder, oState);
WriteShape(pGeneralShape, shParaShapeID, shParaStyleID, oBuilder, oState, pContainer);
}
void CConverter2OOXML::WriteSectionSettings(TConversionState& oState)
@ -1343,9 +1419,7 @@ void CConverter2OOXML::WritePicture(const CCtrlShapePic* pCtrlPic, short shParaS
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
int nWidth{pCtrlPic->GetImageRectWidth()}, nHeight{pCtrlPic->GetIMageRectHeight()};
OpenDrawingNode(pCtrlPic, oBuilder, &nWidth, &nHeight);
OpenDrawingNode(pCtrlPic, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
@ -1361,7 +1435,7 @@ void CConverter2OOXML::WritePicture(const CCtrlShapePic* pCtrlPic, short shParaS
if (pCtrlPic->VertFlip())
oBuilder.WriteString(L" flipV=\"1\"");
oBuilder.WriteString(L"><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(nWidth) + L"\" cy=\"" + std::to_wstring(nHeight) + L"\"/></a:xfrm>");
oBuilder.WriteString(L"><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(pCtrlPic->GetFinalWidth()) + L"\" cy=\"" + std::to_wstring(pCtrlPic->GetFinalHeight()) + L"\"/></a:xfrm>");
oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/>");
WriteBorderSettings(pCtrlPic, oBuilder);
oBuilder.WriteString(L"</pic:spPr></pic:pic></a:graphicData></a:graphic>");
@ -1539,7 +1613,7 @@ void CConverter2OOXML::WriteTextBorderStyle(short shBorderFillId, NSStringUtils:
WriteBorder(pBorderFill->GetLeftBorder(), L"bdr", oBuilder);
}
void CConverter2OOXML::OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder, int* pWidth, int* pHeight)
void CConverter2OOXML::OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder)
{
if (nullptr == pCtrlShape)
return;
@ -1554,7 +1628,7 @@ void CConverter2OOXML::OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStri
L"\" distR=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetRightOutMargin() / 10)) +
L"\">");
WriteShapeExtent(pCtrlShape, oBuilder, pWidth, pHeight);
WriteShapeExtent(pCtrlShape, oBuilder);
}
else
{
@ -1567,7 +1641,7 @@ void CConverter2OOXML::OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStri
L"\" simplePos=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">");
WriteShapePosition(pCtrlShape, oBuilder);
WriteShapeExtent(pCtrlShape, oBuilder, pWidth, pHeight);
WriteShapeExtent(pCtrlShape, oBuilder);
WriteShapeWrapMode(pCtrlShape, oBuilder);
}
@ -1631,25 +1705,14 @@ void CConverter2OOXML::WriteShapePosition(const CCtrlCommon* pCtrlShape, NSStrin
oBuilder.WriteString(L"<wp:simplePos x=\"0\" y=\"0\"/>");
oBuilder.WriteString(L"<wp:positionH relativeFrom=\"");
const int nHorzOffset = pCtrlShape->GetHorzOffset();
const int nVertOffset = pCtrlShape->GetVertOffset();
if (0 == pCtrlShape->GetHorzOffset())
{
oBuilder.WriteString(L"margin\">");
oBuilder.WriteString(L"<wp:align>left</wp:align>");
}
else
{
oBuilder.WriteString(GetHRelativeFrom(pCtrlShape->GetHorzRelTo()) + L"\">");
oBuilder.WriteString(L"<wp:posOffset>" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetHorzOffset())) + L"</wp:posOffset>");
}
oBuilder.WriteString(L"</wp:positionH>");
oBuilder.WriteString(L"<wp:positionV relativeFrom=\"" + GetVRelativeFrom(pCtrlShape->GetVertRelTo()) + L"\"><wp:posOffset>" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetVertOffset())) + L"</wp:posOffset></wp:positionV>");
oBuilder.WriteString(L"<wp:positionH relativeFrom=\"" + GetHRelativeFrom(pCtrlShape->GetHorzRelTo()) + L"\"><wp:posOffset>" + std::to_wstring(Transform::HWPUINT2OOXML(nHorzOffset)) + L"</wp:posOffset></wp:positionH>");
oBuilder.WriteString(L"<wp:positionV relativeFrom=\"" + GetVRelativeFrom(pCtrlShape->GetVertRelTo()) + L"\"><wp:posOffset>" + std::to_wstring(Transform::HWPUINT2OOXML(nVertOffset)) + L"</wp:posOffset></wp:positionV>");
}
void CConverter2OOXML::WriteShapeExtent(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder, int* pWidth, int* pHeight)
void CConverter2OOXML::WriteShapeExtent(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder)
{
if (nullptr == pCtrlShape)
return;
@ -1657,12 +1720,6 @@ void CConverter2OOXML::WriteShapeExtent(const CCtrlObjElement* pCtrlShape, NSStr
const int nFinalWidth = std::abs(pCtrlShape->GetFinalWidth());
const int nFinalHeight = std::abs(pCtrlShape->GetFinalHeight());
if (nullptr != pWidth)
*pWidth = Transform::HWPUINT2OOXML(nFinalWidth);
if (nullptr != pHeight)
*pHeight = Transform::HWPUINT2OOXML(nFinalHeight);
oBuilder.WriteString(L"<wp:extent cx=\"" + std::to_wstring(Transform::HWPUINT2OOXML(nFinalWidth)) + L"\" cy=\"" + std::to_wstring(Transform::HWPUINT2OOXML(nFinalHeight)) + L"\"/>");
oBuilder.WriteString(L"<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>");
}

View File

@ -99,7 +99,7 @@ class CConverter2OOXML
void WriteCellProperties(short shBorderFillID, NSStringUtils::CStringBuilder& oBuilder);
void WriteBorder(const TBorder& oBorder, const HWP_STRING& sBorderName, NSStringUtils::CStringBuilder& oBuilder);
void WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState, const CCtrlContainer *pContainer = nullptr);
void WriteEqEditShape(const CCtrlEqEdit* pEqEditShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void WriteOleShape(const CCtrlShapeOle* pOleShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
@ -115,11 +115,11 @@ class CConverter2OOXML
void WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState, const CRunnerStyle& sExternStyles = CRunnerStyle());
void WriteTextBorderStyle(short shBorderFillId, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder, int* pWidth = nullptr, int *pHeight = nullptr);
void OpenDrawingNode(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void CloseDrawingNode(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void WriteShapePosition(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void WriteShapeExtent(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder, int* pWidth = nullptr, int *pHeight = nullptr);
void WriteShapeExtent(const CCtrlObjElement* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void WriteShapeWrapMode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void WriteShapeProperty(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
@ -134,7 +134,7 @@ class CConverter2OOXML
void WriteAutoNumber(const CCtrlAutoNumber* pAutoNumber, short shParaShapeID, short shParaStyleID, short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void WriteCharacter(const CCtrlCharacter* pCharacter, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void WriteShape(const CCtrlGeneralShape* pShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);
void WriteShape(const CCtrlGeneralShape* pShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState, const CCtrlContainer* pContainer = nullptr);
void WriteNote(const CCtrlNote* pNote, short shParaShapeID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);

View File

@ -52,6 +52,8 @@ CCtrlContainer::CCtrlContainer(const HWP_STRING& sCtrlID, CXMLReader& oReader, E
m_arShapes.push_back(new CCtrlShapePic(L"cip$", oReader, eType));
else if (GetNodeName(ENode::Ole, eType) == sNodeName)
m_arShapes.push_back(new CCtrlShapeOle(L"elo$", oReader, eType));
else
CCtrlGeneralShape::ParseChildren(oReader, eType);
}
END_WHILE

View File

@ -329,18 +329,15 @@ void TMatrix::Multiply(const TMatrix& oMatrix)
const double dM21 = m_dM21 * oMatrix.m_dM11 + m_dM22 * oMatrix.m_dM21;
const double dM22 = m_dM21 * oMatrix.m_dM12 + m_dM22 * oMatrix.m_dM22;
const double dDx = m_dDX * oMatrix.m_dM11 + m_dDY * oMatrix.m_dM21 + oMatrix.m_dDX;
const double dDy = m_dDX * oMatrix.m_dM12 + m_dDY * oMatrix.m_dM22 + oMatrix.m_dDY;
m_dM11 = dM11;
m_dM12 = dM12;
m_dM21 = dM21;
m_dM22 = dM22;
m_dDX = dDx;
m_dDY = dDy;
m_dDX += oMatrix.m_dDX;
m_dDY += oMatrix.m_dDY;
}
void TMatrix::ApplyToPoint(double& dX, double& dY)
void TMatrix::ApplyToPoint(double& dX, double& dY) const
{
const double _dX = dX;
const double _dY = dY;
@ -349,7 +346,16 @@ void TMatrix::ApplyToPoint(double& dX, double& dY)
dY = _dX * m_dM12 + _dY * m_dM22 + m_dDY;
}
void TMatrix::ApplyToSize(double& dW, double& dH)
void HWP::TMatrix::ApplyToPoint(int& nX, int& nY) const
{
const double _dX = nX;
const double _dY = nY;
nX = (int)(_dX * m_dM11 + _dY * m_dM21 + m_dDX);
nY = (int)(_dX * m_dM12 + _dY * m_dM22 + m_dDY);
}
void TMatrix::ApplyToSize(double& dW, double& dH) const
{
const double _dW = dW;
const double _dH = dH;

View File

@ -18,8 +18,9 @@ struct TMatrix
TMatrix(double dM11, double dM12, double dM21, double dM22, double dDX, double dDY);
void Multiply(const TMatrix& oMatrix);
void ApplyToPoint(double& dX, double& dY);
void ApplyToSize(double& dW, double& dH);
void ApplyToPoint(double& dX, double& dY) const;
void ApplyToPoint(int& nX, int &nY) const;
void ApplyToSize(double& dW, double& dH) const;
};
class CCtrlObjElement : public CCtrlCommon

View File

@ -89,6 +89,26 @@ EShapeType CCtrlShapeLine::GetShapeType() const
return EShapeType::Line;
}
int HWP::CCtrlShapeLine::GetStartX() const
{
return m_nStartX;
}
int HWP::CCtrlShapeLine::GetStartY() const
{
return m_nStartY;
}
int HWP::CCtrlShapeLine::GetEndX() const
{
return m_nEndX;
}
int HWP::CCtrlShapeLine::GetEndY() const
{
return m_nEndY;
}
void CCtrlShapeLine::ParseElement(CCtrlShapeLine& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();

View File

@ -24,6 +24,11 @@ public:
EShapeType GetShapeType() const override;
int GetStartX() const;
int GetStartY() const;
int GetEndX() const;
int GetEndY() const;
static void ParseElement(CCtrlShapeLine& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
static void ParseCtrl(CCtrlShapeLine& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
};

View File

@ -69,19 +69,19 @@ void CCtrlShapeRect::ReadFromHWPML(CXMLReader &oReader)
else if ("X0" == sAttributeName)
m_arPoints[0].m_nX = oReader.GetInt();
else if ("Y0" == sAttributeName)
m_arPoints[0].m_nX = oReader.GetInt();
m_arPoints[0].m_nY = oReader.GetInt();
else if ("X1" == sAttributeName)
m_arPoints[1].m_nX = oReader.GetInt();
else if ("Y1" == sAttributeName)
m_arPoints[1].m_nX = oReader.GetInt();
m_arPoints[1].m_nY = oReader.GetInt();
else if ("X2" == sAttributeName)
m_arPoints[2].m_nX = oReader.GetInt();
else if ("Y2" == sAttributeName)
m_arPoints[2].m_nX = oReader.GetInt();
m_arPoints[2].m_nY = oReader.GetInt();
else if ("X3" == sAttributeName)
m_arPoints[3].m_nX = oReader.GetInt();
else if ("Y3" == sAttributeName)
m_arPoints[3].m_nX = oReader.GetInt();
m_arPoints[3].m_nY = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
@ -95,6 +95,11 @@ EShapeType CCtrlShapeRect::GetShapeType() const
return EShapeType::Rect;
}
void CCtrlShapeRect::GetPoints(TPoint (&arPoints)[4]) const
{
memcpy(arPoints, m_arPoints, sizeof(TPoint) * 4);
}
int CCtrlShapeRect::ParseElement(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();

View File

@ -22,6 +22,8 @@ public:
EShapeType GetShapeType() const override;
void GetPoints(TPoint (&arPoints)[4]) const;
static int ParseElement(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
static int ParseCtrl(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
static int ParseListHeaderAppend(CCtrlShapeRect& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);