示例#1
0
        private static IEnumerable <IPdfPathItem> ConvertPolyline(DxfLwPolyline lwPolyline, DxfLayer layer,
                                                                  Matrix4 affine, Matrix4 scale)
        {
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(lwPolyline, layer),
                strokeWidth: GetStrokeWidth(lwPolyline, layer));
            IList <DxfLwPolylineVertex> vertices = lwPolyline.Vertices;
            int n = vertices.Count;
            DxfLwPolylineVertex vertex = vertices[0];

            for (int i = 1; i < n; i++)
            {
                DxfLwPolylineVertex next = vertices[i];
                yield return(ConvertPolylineSegment(vertex, next, affine, scale, pdfStreamState));

                vertex = next;
            }
            if (lwPolyline.IsClosed)
            {
                var next = vertices[0];
                var p1   = affine.Transform(new Vector(vertex.X, vertex.Y, 0))
                           .ToPdfPoint(PdfMeasurementType.Point);
                var p2 = affine.Transform(new Vector(next.X, next.Y, 0))
                         .ToPdfPoint(PdfMeasurementType.Point);
                yield return(new PdfLine(p1, p2, pdfStreamState));
            }
        }
示例#2
0
        private static IEnumerable <IPdfPathItem> ConvertLine(DxfLine line, DxfLayer layer, Matrix4 affine)
        {
            var p1             = affine.Transform(line.P1).ToPdfPoint(PdfMeasurementType.Point);
            var p2             = affine.Transform(line.P2).ToPdfPoint(PdfMeasurementType.Point);
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(line, layer),
                strokeWidth: GetStrokeWidth(line, layer));

            yield return(new PdfLine(p1, p2, pdfStreamState));
        }
示例#3
0
        private static IPdfPathItem ConvertPolylineSegment(DxfLwPolylineVertex vertex, DxfLwPolylineVertex next, Matrix4 affine,
                                                           Matrix4 scale, PdfStreamState pdfStreamState)
        {
            var p1 = affine.Transform(new Vector(vertex.X, vertex.Y, 0))
                     .ToPdfPoint(PdfMeasurementType.Point);
            var p2 = affine.Transform(new Vector(next.X, next.Y, 0))
                     .ToPdfPoint(PdfMeasurementType.Point);

            if (vertex.Bulge.Equals(0.0))
            {
                return(new PdfLine(p1, p2, pdfStreamState));
            }

            double dx     = next.X - vertex.X;
            double dy     = next.Y - vertex.Y;
            double length = Math.Sqrt(dx * dx + dy * dy);

            if (length <= 1e-10)
            {
                // segment is very short, avoid numerical problems
                return(new PdfLine(p1, p2, pdfStreamState));
            }

            double alpha  = 4.0 * Math.Atan(vertex.Bulge);
            double radius = length / (2.0 * Math.Abs(Math.Sin(alpha * 0.5)));

            double bulgeFactor = Math.Sign(vertex.Bulge) * Math.Cos(alpha * 0.5) * radius;
            double normalX     = -(dy / length) * bulgeFactor;
            double normalY     = +(dx / length) * bulgeFactor;

            // calculate center (dxf coordinate system), start and end angle
            double cx = (vertex.X + next.X) / 2 + normalX;
            double cy = (vertex.Y + next.Y) / 2 + normalY;
            double startAngle;
            double endAngle;

            if (vertex.Bulge > 0) // counter-clockwise
            {
                startAngle = Math.Atan2(vertex.Y - cy, vertex.X - cx);
                endAngle   = Math.Atan2(next.Y - cy, next.X - cx);
            }
            else // clockwise: flip start and end angle
            {
                startAngle = Math.Atan2(next.Y - cy, next.X - cx);
                endAngle   = Math.Atan2(vertex.Y - cy, vertex.X - cx);
            }

            // transform to PDF coordinate system
            var          center    = affine.Transform(new Vector(cx, cy, 0)).ToPdfPoint(PdfMeasurementType.Point);
            var          pdfRadius = scale.Transform(new Vector(radius, radius, radius)).ToPdfPoint(PdfMeasurementType.Point);
            const double rotation  = 0;

            return(new PdfEllipse(center, pdfRadius.X, pdfRadius.Y, rotation,
                                  startAngle, endAngle, pdfStreamState));
        }
示例#4
0
        private static IEnumerable <IPdfPathItem> ConvertCircle(DxfCircle circle, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(circle, layer),
                strokeWidth: GetStrokeWidth(circle, layer));
            // a circle becomes an ellipse, unless aspect ratio is kept.
            var center = affine.Transform(circle.Center).ToPdfPoint(PdfMeasurementType.Point);
            var radius = scale.Transform(new Vector(circle.Radius, circle.Radius, circle.Radius))
                         .ToPdfPoint(PdfMeasurementType.Point);

            yield return(new PdfEllipse(center, radius.X, radius.Y, state: pdfStreamState));
        }
示例#5
0
        private static IEnumerable <IPdfPathItem> ConvertArc(DxfArc arc, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(arc, layer),
                strokeWidth: GetStrokeWidth(arc, layer));
            var center = affine.Transform(arc.Center).ToPdfPoint(PdfMeasurementType.Point);
            var radius = scale.Transform(new Vector(arc.Radius, arc.Radius, arc.Radius))
                         .ToPdfPoint(PdfMeasurementType.Point);
            const double rotation      = 0;
            double       startAngleRad = arc.StartAngle * Math.PI / 180;
            double       endAngleRad   = arc.EndAngle * Math.PI / 180;

            yield return(new PdfEllipse(center, radius.X, radius.Y, rotation, startAngleRad, endAngleRad,
                                        pdfStreamState));
        }
示例#6
0
        private static PdfText ConvertText(DxfText text, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            // TODO horizontal and vertical justification (manual calculation for PDF, measure text?)
            // TODO Thickness, Rotation, TextStyleName, SecondAlignmentPoint
            // TODO IsTextUpsideDown, IsTextBackwards
            // TODO RelativeXScaleFactor
            // TODO TextHeight unit? Same as other scale?
            // TODO TextStyleName probably maps to something meaningfull (bold, italic, etc?)
            PdfMeasurement fontSize = scale.Transform(new Vector(0, text.TextHeight, 0))
                                      .ToPdfPoint(PdfMeasurementType.Point).Y;
            PdfPoint location       = affine.Transform(text.Location).ToPdfPoint(PdfMeasurementType.Point);
            var      pdfStreamState = new PdfStreamState(GetPdfColor(text, layer));

            return(new PdfText(text.Value, Font, fontSize, location, pdfStreamState));
        }
示例#7
0
        private static IEnumerable <IPdfPathItem> ConvertPoint(DxfModelPoint point, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            var p         = affine.Transform(point.Location).ToPdfPoint(PdfMeasurementType.Point);
            var thickness = scale.Transform(new Vector(point.Thickness, 0, 0)).ToPdfPoint(PdfMeasurementType.Point).X;

            if (thickness.RawValue < 1)
            {
                thickness = PdfMeasurement.Points(1);
            }
            // TODO fill circle? For now fake it via stroke thickness.
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(point, layer),
                strokeWidth: thickness);

            yield return(new PdfCircle(p, thickness / 2, pdfStreamState));
        }
示例#8
0
 public PdfSetState(PdfStreamState state)
 {
     State = state;
 }
示例#9
0
 public PdfArc(PdfPoint center, PdfMeasurement radius, double startAngle, double endAngle, PdfStreamState state = default(PdfStreamState))
     : base(center, radius, radius, startAngle: startAngle, endAngle: endAngle, state: state)
 {
 }