Problems extrancting text
Posted: 09 Oct 2007, 11:00
Hello,
I have some problems extracting texts:
I used a modified version of the example from extended version of CAD Import .NET -> Import example to extract texts and attdefs in order to create text objects in an application we use and the problem is that this code does not extract the properties correctly for all types of text.
This code works for dxf files created with Corel but does not work with dxf files created by Autocad because in Autocad the height of the text is read much higher than it is in reality (although the position, the length and the angle seem ok).
Also the method we used to extract the font type only works for Corel files and doesn't work for Autocad files.
I have some problems extracting texts:
I used a modified version of the example from extended version of CAD Import .NET -> Import example to extract texts and attdefs in order to create text objects in an application we use and the problem is that this code does not extract the properties correctly for all types of text.
This code works for dxf files created with Corel but does not work with dxf files created by Autocad because in Autocad the height of the text is read much higher than it is in reality (although the position, the length and the angle seem ok).
Also the method we used to extract the font type only works for Corel files and doesn't work for Autocad files.
Code: Select all
CADConst.DoScale2D(ref cadParams);
DPoint dptStart = sender.StartPoint; //sender is CADText
dptStart.Y += sender.Height * 1.3; //we don't know the meaning of this line - it was taken from your example
PointF ptStart = TransformPoint(cadParams.matrix.PtXMat(dptStart)); //Right now TransformPoint is actually FCADImage.GetPoint()
PointF ptUpLeft = TransformPoint(new DPoint(sender.Box.left, sender.Box.top, sender.Box.z1));
PointF ptDownRight = TransformPoint(new DPoint(sender.Box.right, sender.Box.bottom, sender.Box.z2));
float width = Math.Abs(ptDownRight.X - ptUpLeft.X);
float height = Math.Abs(ptDownRight.Y - ptUpLeft.Y); //this is ok for Corel files but is always too big for Autocad files
string txt = sender.Text;
if (txt.Length > 0 && width > 0 && height > 0)
{
RectangleF rectBounds = new RectangleF((float)Math.Abs(ptStart.X), (float)Math.Abs(ptStart.Y), (float)Math.Abs(width), (float)Math.Abs(height));
SDiagram.TextNode text = new Syncfusion.Windows.Forms.Diagram.TextNode(txt, rectBounds);
text.PinPoint = ptStart;
text.PinPointOffset = new SizeF(0,0);
text.RotationAngle = -(sender.Rotation + cadParams.angle);
text.FontStyle.Size = height;
text.LineStyle.LineColor = Color.Transparent;
text.NoClip = false;
try
{
string fontName = cadParams.insert.EntName.Substring(3,cadParams.insert.EntName.IndexOf(";") - 3); //this method works only for Corel files
text.FontStyle.Family = fontName;
}
catch
{
}
}