HPS - ComputeTextExtent example

Below is sample code on how to calculate text size to draw a box around it. Please note that text’s ascender/descender are not included in calculation.

HPS also have pre-define background you can use as well.
[Text — HOOPS Visualize HPS 2023 SP2 U2 Documentation](https://Pre-defined backround)

Sample code using hps_mfc_sandbox:

void CHPSView::OnUserCode3()
{
	// TODO: Add your command handler code here


    GetCanvas().GetFrontView().GetSegmentKey().GetCameraControl()
        .SetPosition(Point(0, 0, 5))
        .SetTarget(Point(0, 0, 0))
        .SetUpVector(Vector(0, 1, 0))
        .SetField(2.5f, 2.5f)
        .SetProjection(Camera::Projection::Orthographic);
    GetCanvas().GetFrontView().FitWorld().UpdateWithNotifier().Wait();
}

void CHPSView::OnUserCode4()
{
	// TODO: Add your command handler code here

    Point textPosition(-0.75f, 0.0f, 0.0f);
    TextKey text = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().InsertText(textPosition, "Testing");
    text.SetFont("roman").SetAlignment(Text::Alignment::Center).SetTransform(Text::Transform::NonTransformable);



    float xFrac;
    float yFrac;
	SprocketPath myPath(GetCanvas());
    myPath.GetKeyPath().ComputeTextExtent("Testing", xFrac, yFrac);

    Point textWindowPosition;
	myPath.GetKeyPath().ConvertCoordinate(Coordinate::Space::Object, textPosition, Coordinate::Space::Window, textWindowPosition);

    PointArray textWindowExtentPoints(5);
    textWindowExtentPoints[0] = textWindowPosition + Vector(-xFrac, -yFrac, 0);
    textWindowExtentPoints[1] = textWindowPosition + Vector(xFrac, -yFrac, 0);
    textWindowExtentPoints[2] = textWindowPosition + Vector(xFrac, yFrac, 0);
    textWindowExtentPoints[3] = textWindowPosition + Vector(-xFrac, yFrac, 0);
    textWindowExtentPoints[4] = textWindowExtentPoints[0];

    PointArray textObjectExtentPoints(5);
	myPath.GetKeyPath().ConvertCoordinate(
        Coordinate::Space::Window, textWindowExtentPoints, Coordinate::Space::Object, textObjectExtentPoints);

	GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().Subsegment("text_bound").Flush();
    GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().Subsegment("text_bound").InsertLine(textObjectExtentPoints);

	GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().GetVisibilityControl().SetLines(true);


    GetCanvas().GetFrontView().UpdateWithNotifier().Wait();

}

Screenshot: