Animation of the AutoCAD mirror command

AcEdJig uses your code, the effect is as follows:
When the XDir angle of the AcDbText object is between -pi / 2 and pi / 2, the text is not displayed correctly.
virtual Adesk::Boolean subWorldDraw(AcGiWorldDraw* wd)
{
wd->geometry().pushModelTransform(m_mat);
AcDbEntity* pE;
for (int i = 0; i < m_idArray.length(); i++)
{
if (acdbOpenObject(pE, m_idArray[i], AcDb::kForRead) == Acad::eOk)
{
if (pE->isKindOf(AcDbText::desc()))
{
if (!DocVars.Xd_Kernel.pCurDwg->mirrtext())
{
AcGePoint3d ori1;
AcGeVector3d xAxis1, yAxis1, zAxis1;
AcDbText* text = AcDbText::cast(pE);
AcGePoint3d pos(text->position()); // this is the point that will stay fixed
AcGeVector3d zAxis(text->normal());
AcGeVector3d xAxis = zAxis.perpVector().rotateBy(text->rotation(), zAxis);
AcGeVector3d yAxis = zAxis.crossProduct(xAxis);
AcGePoint3dArray box;
XdDbUtils::getEntityBoundaryBox(pE, box);
AcGePoint3d pMid = XdGeUtils::midPoint(box.first(), box[2]);
AcGeMatrix3d mirrMat;
mirrMat.setToAlignCoordSys(
pMid, xAxis, yAxis, zAxis,
pMid, -xAxis, yAxis, zAxis // -xAxis to flip the X direction.
);
wd->geometry().pushModelTransform(mirrMat);
wd->geometry().draw(pE);
}
else {
DocVars.mMirrorResultMatrix = m_mat;
wd->geometry().draw(pE);
}
}
else
{
wd->geometry().draw(pE);
}
pE->close();
}
}
wd->geometry().popModelTransform();
return Adesk::kTrue;
}
