How to modify the position of text to fit different Scale of Model?

How can I modify the position of the text in Detail View to adapt to different Scale of Model, Attachment 1 Scale Value is 1/1, Attachment 2 Scale Value is 1/100. it can be clearly seen that my customized red Dimension in Attachment 1 is displayed correctly, but my customized red Dimension in Attachment 2 is displayed incorrectly.

You can clearly see that the text is overlapping, the black Dimension on the right is the system’s Linear Dimension, and it has no problem displaying it at whatever scale it is at, and I want my custom Dimension to be able to adapt to different scales like the system’s Dimension.I would like my customized Dimension to be able to adapt to the unscalable scaling size, can this be achieved in Rhinoceros 7?
Here is my drawing code:

// Retrieve the first point
Point3d point1;
using (var gp = new GetPoint())
{
gp.SetCommandPrompt(“Select the annotation point”);
if (gp.Get() != GetResult.Point)
return gp.CommandResult();
point1 = gp.Point();
}

// Retrieve the second point, and dynamically draw a line from the first point to the current point
Point3d point2;
using (var gp = new GetPoint())
{
gp.SetCommandPrompt(“Select the direction for coordinate annotation”);
gp.DynamicDraw +=
(sender, e) => e.Display.DrawLine(point1, e.CurrentPoint, System.Drawing.Color.Black);
gp.Get();
if (gp.CommandResult() != Result.Success)
return gp.CommandResult();
point2 = gp.Point();
}

double pt3Offset = 35;

// Determine the third point based on the position of the second point
Point3d point3;
if (point2.X < point1.X)
{
// If the second point is to the left of the first point
point3 = point2 + new Point3d(-pt3Offset, 0, 0);
}
else
{
// If the second point is to the right of the first point
point3 = point2 + new Point3d(pt3Offset, 0, 0);
}

// Create the annotation style
string text = string.Format(“X={0}\nY={1}”, point1.X.ToString(“F3”), point1.Y.ToString(“F3”));
DimensionStyle style = new DimensionStyle
{
LeaderArrowType = DimensionStyle.ArrowType.LongerTriangle,
TextHeight = DefaultTextHeight,
DimensionScale = dimensionScale,
};
int index = doc.DimStyles.Add(style, true);
DimensionStyle dsInDoc = doc.DimStyles[index];

// Create and add the Leader
Plane plane = Plane.WorldXY;
Point3d points = { point1, point2, point3 };
var attrib = doc.CreateDefaultAttributes();
attrib.LayerIndex = layerIndex;
Leader leader = Leader.Create(string.Empty, plane, dsInDoc, points);

// Determine the position of the text
double textWidth = 1; // Assumed text width
Point3d textPoint1 = new Point3d(point3.X + textWidth, point3.Y + style.TextHeight, 0); // X text position
Point3d textPoint2 = new Point3d(point3.X + textWidth, point3.Y - style.TextHeight, 0); // Y text position

// Create text entities
TextEntity textEntity1 = new TextEntity
{
Plane = new Plane(textPoint1, Vector3d.XAxis, Vector3d.YAxis),
PlainText = $“X={point1.X.ToString(“F3”)}”,
TextHeight = DefaultTextHeight,
DimensionScale = dimensionScale,
Justification = TextJustification.MiddleRight
};
TextEntity textEntity2 = new TextEntity
{
Plane = new Plane(textPoint2, Vector3d.XAxis, Vector3d.YAxis),
PlainText = “Y={point1.Y.ToString(“F3”)}”,
TextHeight = DefaultTextHeight,
DimensionScale = dimensionScale,
Justification = TextJustification.MiddleRight
};

// Add objects to the document and record their IDs
Guid leaderId = doc.Objects.AddLeader(leader, attrib);
Guid textEntity1Id = doc.Objects.AddText(textEntity1, attrib);
Guid textEntity2Id = doc.Objects.AddText(textEntity2, attrib);

// Create a group and add these object IDs
int groupIndex = doc.Groups.Add(new List { leaderId, textEntity1Id, textEntity2Id });
// Refresh the view
doc.Views.Redraw();