haplokuon / netDxf

.net dxf Reader-Writer
MIT License
995 stars 405 forks source link

Annotation leader line overlaps text after the DXF file is loaded, updated and saved. #298

Open kyosukeSakurai opened 3 years ago

kyosukeSakurai commented 3 years ago

Annotation leader line overlaps text after the DXF file is loaded, updated and saved.

image

image

It seems that the update position of the text attachment point is incorrect.

Sample dxf: sample_L2.zip

Sample code:

var dxfDoc = DxfDocument.Load( filename );
foreach( var ldr in dxfDoc.Entities.Leaders)
{
     ldr.update(false)
}
dxfDoc.Save( filename );

I think the following processing is needed to be fixed. Line 599 and 766 on Leader.cs

// Since Hook is decided from mTxt.Position, Annotation lines are created across mText when the attachment point is above and in the center instead of below.
 // Fixed to determine Hook from the bottom of the annotation text. 
         switch (mText.AttachmentPoint)
         {
                case MTextAttachmentPoint.TopRight:
                case MTextAttachmentPoint.TopLeft:
                       position.Y = position.Y - mText.Height;
                       break;
                case MTextAttachmentPoint.MiddleRight:
                       mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
                       mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight;
                        position.Y = position.Y - (mText.Height*0.5);
                        break;
                 case MTextAttachmentPoint.BottomRight:
                 case MTextAttachmentPoint.BottomLeft:
                         break;
          }

// Since Hook is decided from mTxt.Position, Annotation lines are created across mText when the attachment point is above and in the center instead of below.
// Fixed to determine Hook from the bottom of the annotation text.
         switch (mText.AttachmentPoint)
            {
                case MTextAttachmentPoint.TopRight:
                case MTextAttachmentPoint.TopLeft:
                       position.Y = position.Y + mText.Height;
                       break;
                case MTextAttachmentPoint.MiddleRight:
                       mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
                       mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight;
                       position.Y = position.Y + (mText.Height * 0.5);
                       break;
                case MTextAttachmentPoint.BottomRight:
                case MTextAttachmentPoint.BottomLeft:
                       break;
            }