void DRIText::subViewportDraw(AcGiViewportDraw * mode)
{
assertReadEnabled();
AcGePoint3d orgn;
AcGeVector3d xa, ya, za;
AcGeMatrix3d transform;
mode->viewport().getEyeToWorldTransform(transform);
transform.getCoordSystem(orgn, xa, ya, za);
double lLimit, uLimit;
double rot = rotation();
double vpRot = atan2(xa.y, xa.x);
//Counterclockwise rotation
if (vpRot < 0) vpRot *= -1;
else vpRot = 2.0 * PI - vpRot;
lLimit = (PI * 0.5) - vpRot;
uLimit = (1.5 * PI) - vpRot;
if (lLimit < 0) lLimit += 2.0 * PI;
if (uLimit <= 0) uLimit += 2.0 * PI;
bool toRotate = false;
//General case, quadrant I and IV
if ((vpRot < (PI * 0.5)) || (vpRot >= (1.5 * PI)))
{
if (rot > lLimit && rot < uLimit) toRotate = true;
}
//General case, quadrant II and III
else if ((vpRot >= (PI * 0.5)) && (vpRot < (1.5 * PI)))
{
if (rot < uLimit || rot > lLimit) toRotate = true;
}
if (toRotate)
{
AcGeVector3d dir{ AcGeVector3d(cos(rot),sin(rot),0.0) }; dir.normalize();
AcGeVector3d dirPerp{ AcGeVector3d(cos(rot + PI * 0.5),sin(rot + PI * 0.5),0.0) }; dirPerp.normalize();
AcString text = textString();
AcGiTextStyle style;
fromAcDbTextStyle(style, this->textStyle());
style.loadStyleRec();
AcGePoint2d extents = style.extents(textString(), Adesk::kFalse, text.length(), Adesk::kTrue);
mode->geometry().text(position() + dir * extents.x + dirPerp * extents.y,
AcGeVector3d::kZAxis, dir * -1, height(), 1.0, 0.0, text);
}
else AcDbText::subViewportDraw(mode);
}