You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"While changing the text value, OLDSTRING = 'TITLE1' and NEWSTRING = 'HELLO WORLD', we are experiencing an issue where the alignment point of the old data is assigned after the changes. The geometric text alignment point is not updated according to the new string's insertion point."
Please find the below sample code, and we are facing difficulties finding the alignment calculation for different font styles.
public static float MeasureTextWidth(string text, string fontName, float fontSize, float widthFactor)
{
// Create a System.Drawing.Font object based on the given font and size
using (System.Drawing.Font font = new System.Drawing.Font(fontName, fontSize))
using (Graphics g = Graphics.FromImage(new Bitmap(1, 1)))
{
// Set anti-aliasing for smoother text rendering
g.TextRenderingHint = TextRenderingHint.AntiAlias;
// Measure the width of the string
SizeF textSize = g.MeasureString(text, font);
// Apply the width factor for scaling
return textSize.Width * widthFactor;
}
}
// OLDSTRING = TITLE1, NEWSTRING = HELLO WORLD
clonedEntity1.Value = NEWSTRING;
var insertionPoint = clonedEntity1.AlignmentPoint;
var height = clonedEntity1.Height;
var widthFactor = clonedEntity1.WidthFactor;
var fontName = clonedEntity1.Style?.Name ?? "Arial";
// Measure text width
// double textWidth = MeasureTextWidth(clonedEntity1.Value, fontName, (float)height) * widthFactor;
// Measure text size using System.Drawing
double textWidth = MeasureTextWidth(clonedEntity1.Value, clonedEntity1.Style?.Name ?? "Arial", (float)clonedEntity1.Height, (float)clonedEntity1.WidthFactor);
// Calculate center alignment
var maxPoint = new netDxf.Vector2(insertionPoint.X - (textWidth / 2), insertionPoint.Y);
// Adjust alignment based on font
double adjustment = clonedEntity1.Style.Name switch
{
"ROMANS" => 1.45,
"ARIAL" => 0.0485,
"ISOCP" => 0.35800,
_ => 0
};
// Set AlignmentPoint (NOT InsertPoint)
clonedEntity1.InsertPoint = new XYZ(maxPoint.X + adjustment, clonedEntity1.InsertPoint.Y, 0);
clonedEntity1.HorizontalAlignment = TextHorizontalAlignment.Center;
clonedEntity1.VerticalAlignment = TextVerticalAlignmentType.Middle;
The text was updated successfully, but these errors were encountered:
"While changing the text value, OLDSTRING = 'TITLE1' and NEWSTRING = 'HELLO WORLD', we are experiencing an issue where the alignment point of the old data is assigned after the changes. The geometric text alignment point is not updated according to the new string's insertion point."
Please find the below sample code, and we are facing difficulties finding the alignment calculation for different font styles.
public static float MeasureTextWidth(string text, string fontName, float fontSize, float widthFactor)
{
// Create a System.Drawing.Font object based on the given font and size
using (System.Drawing.Font font = new System.Drawing.Font(fontName, fontSize))
using (Graphics g = Graphics.FromImage(new Bitmap(1, 1)))
{
// Set anti-aliasing for smoother text rendering
g.TextRenderingHint = TextRenderingHint.AntiAlias;
}
// OLDSTRING = TITLE1, NEWSTRING = HELLO WORLD
clonedEntity1.Value = NEWSTRING;
var insertionPoint = clonedEntity1.AlignmentPoint;
var height = clonedEntity1.Height;
var widthFactor = clonedEntity1.WidthFactor;
var fontName = clonedEntity1.Style?.Name ?? "Arial";
// Measure text width
// double textWidth = MeasureTextWidth(clonedEntity1.Value, fontName, (float)height) * widthFactor;
// Measure text size using System.Drawing
double textWidth = MeasureTextWidth(clonedEntity1.Value, clonedEntity1.Style?.Name ?? "Arial", (float)clonedEntity1.Height, (float)clonedEntity1.WidthFactor);
// Calculate center alignment
var maxPoint = new netDxf.Vector2(insertionPoint.X - (textWidth / 2), insertionPoint.Y);
// Adjust alignment based on font
double adjustment = clonedEntity1.Style.Name switch
{
"ROMANS" => 1.45,
"ARIAL" => 0.0485,
"ISOCP" => 0.35800,
_ => 0
};
// Set AlignmentPoint (NOT InsertPoint)
clonedEntity1.InsertPoint = new XYZ(maxPoint.X + adjustment, clonedEntity1.InsertPoint.Y, 0);
clonedEntity1.HorizontalAlignment = TextHorizontalAlignment.Center;
clonedEntity1.VerticalAlignment = TextVerticalAlignmentType.Middle;
The text was updated successfully, but these errors were encountered: