我需要在DXF文件中写一些文本。我使用.NET Framework 4.5.2,C#,库netDxf。但是DXF指定类型MText对我不利。 我需要使用几何图元在DXF中编写文本。好的,我为此编写了一些代码:
FormattedText fText = new FormattedText(
"50",
CultureInfo.GetCultureInfo("ru-RU"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
12.0,
Brushes.Black);
List<Vector2> points = new List<Vector2>();
List<Vector2> points2 = new List<Vector2>();
Geometry geometry = fText.BuildGeometry(new Point());
PathGeometry path = PathGeometry.CreateFromGeometry(geometry);
int k = 1;
foreach(var pf in path.Figures)
{
foreach(var ps in pf.Segments)
{
if (ps is PolyLineSegment)
{
PolyLineSegment seg = ps as PolyLineSegment;
for (int i = 0; i < seg.Points.Count; ++i)
{
if(k == 1)
points.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
else
points2.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
}
}
else if (ps is PolyBezierSegment)
{
PolyBezierSegment seg = ps as PolyBezierSegment;
for (int i = 0; i < seg.Points.Count; i += 3)
{
if (k == 1)
points.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
else
points2.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
}
}
else if (ps is LineSegment)
{
LineSegment seg = ps as LineSegment;
if(k == 1)
points.Add(new Vector2(seg.Point.X, seg.Point.Y));
else
points2.Add(new Vector2(seg.Point.X, seg.Point.Y));
}
else if (ps is BezierSegment)
{
BezierSegment seg = ps as BezierSegment;
if (k == 1)
{
points.Add(new Vector2(seg.Point1.X, seg.Point1.Y));
points.Add(new Vector2(seg.Point2.X, seg.Point2.Y));
points.Add(new Vector2(seg.Point3.X, seg.Point3.Y));
}
else
{
points2.Add(new Vector2(seg.Point1.X, seg.Point1.Y));
points2.Add(new Vector2(seg.Point2.X, seg.Point2.Y));
points2.Add(new Vector2(seg.Point3.X, seg.Point3.Y));
}
}
else if (ps is QuadraticBezierSegment)
{
QuadraticBezierSegment seg = ps as QuadraticBezierSegment;
if (k == 1)
{
points.Add(new Vector2(seg.Point1.X, seg.Point1.Y));
points.Add(new Vector2(seg.Point2.X, seg.Point2.Y));
}
else
{
points2.Add(new Vector2(seg.Point1.X, seg.Point1.Y));
points2.Add(new Vector2(seg.Point2.X, seg.Point2.Y));
}
}
else if (ps is PolyQuadraticBezierSegment)
{
PolyQuadraticBezierSegment seg = ps as PolyQuadraticBezierSegment;
for (int i = 0; i < seg.Points.Count; i += 2)
{
if (k == 1)
points.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
else
points2.Add(new Vector2(seg.Points[i].X, seg.Points[i].Y));
}
}
else
{
Console.WriteLine("ERROR");
}
}
k += 1;
}
DxfDocument dxf = new DxfDocument();
netDxf.Entities.LwPolyline lw = new netDxf.Entities.LwPolyline(points, true);
netDxf.Entities.LwPolyline lw2 = new netDxf.Entities.LwPolyline(points2, true);
dxf.AddEntity(lw);
dxf.AddEntity(lw2);
dxf.Save("test.dxf");
Console.WriteLine(k);
但是result对我不利。
倒置数字(我尝试绘制50个数字)
数字0并未画到最后
我该如何解决?还有其他方法吗?