public void QuadraticCurveTo(PDFPoint end, PDFPoint handle)
        {
            PathQuadraticCurve arc = new PathQuadraticCurve()
            {
                EndPoint = end, ControlPoint = handle
            };

            CurrentPath.Add(arc);
            IncludeInBounds(end);
            IncludeInBounds(handle);
            Cursor     = end;
            LastHandle = handle;
        }
        public void QuadraticCurveFor(PDFPoint endDelta, PDFPoint handleDelta)
        {
            PDFPoint           end    = ConvertDeltaToActual(endDelta);
            PDFPoint           handle = ConvertDeltaToActual(handleDelta);
            PathQuadraticCurve arc    = new PathQuadraticCurve()
            {
                EndPoint = end, ControlPoint = handle
            };

            CurrentPath.Add(arc);
            IncludeInBounds(end);
            IncludeInBounds(handle);
            Cursor     = end;
            LastHandle = handle;
        }
Ejemplo n.º 3
0
        internal static IEnumerable <PathBezierCurveData> GetBezierCurvesForQuadratic(PDFPoint start, PathQuadraticCurve quad)
        {
            PathBezierCurveData[] all = new PathBezierCurveData[1];

            try
            {
                double x1 = start.X.PointsValue + (quad.ControlPoint.X.PointsValue - start.X.PointsValue) * 2 / 3;
                double y1 = start.Y.PointsValue + (quad.ControlPoint.Y.PointsValue - start.Y.PointsValue) * 2 / 3;

                PDFPoint startHandle = new PDFPoint(x1, y1);

                double x2 = quad.ControlPoint.X.PointsValue + (quad.EndPoint.X.PointsValue - quad.ControlPoint.X.PointsValue) / 3;
                double y2 = quad.ControlPoint.Y.PointsValue + (quad.EndPoint.Y.PointsValue - quad.ControlPoint.Y.PointsValue) / 3;

                PDFPoint endHandle = new PDFPoint(x2, y2);

                PathBezierCurveData one = new PathBezierCurveData(quad.EndPoint, startHandle, endHandle, true, true);
                all[0] = one;
            }
            catch (Exception ex)
            {
                throw new PDFException(Errors.CouldNotBuildPathFromQuadratic, ex);
            }

            return(all);
        }
Ejemplo n.º 4
0
        private void RenderPathOp(PathData data, PDFPoint location, ref PDFPoint cursor)
        {
            switch (data.Type)
            {
            case PathDataType.Move:
                PathMoveData move = (PathMoveData)data;
                cursor = move.MoveTo;
                this.RenderMoveTo(move.MoveTo.X + location.X, move.MoveTo.Y + location.Y);
                break;

            case PathDataType.Line:
                PathLineData line = (PathLineData)data;
                cursor = line.LineTo;
                this.RenderLineTo(line.LineTo.X + location.X, line.LineTo.Y + location.Y);
                break;

            case PathDataType.Rect:
                PathRectData rect = (PathRectData)data;
                cursor = rect.Rect.Location;
                this.RenderRectangle(rect.Rect.X + location.X, rect.Rect.Y + location.Y, rect.Rect.Width, rect.Rect.Height);
                break;

            case PathDataType.SubPath:
                PathSubPathData sub = (PathSubPathData)data;
                this.RenderPathData(location, sub.InnerPath, ref cursor);
                break;

            case PathDataType.Bezier:
                PathBezierCurveData bez = (PathBezierCurveData)data;
                cursor = bez.EndPoint;
                if (bez.HasStartHandle && bez.HasEndHandle)
                {
                    this.RenderBezierCurveTo(bez.EndPoint.X + location.X, bez.EndPoint.Y + location.Y,
                                             bez.StartHandle.X + location.X, bez.StartHandle.Y + location.Y,
                                             bez.EndHandle.X + location.X, bez.EndHandle.Y + location.Y);
                }
                else if (bez.HasStartHandle)
                {
                    this.RenderBezierCurveToWithStartHandleOnly(bez.EndPoint.X + location.X, bez.EndPoint.Y + location.Y,
                                                                bez.StartHandle.X + location.X, bez.StartHandle.Y + location.Y);
                }
                else if (bez.HasEndHandle)
                {
                    this.RenderBezierCurveToWithEndHandleOnly(bez.EndPoint.X + location.X, bez.EndPoint.Y + location.Y,
                                                              bez.EndHandle.X + location.X, bez.EndHandle.Y + location.Y);
                }
                else
                {
                    this.RenderLineTo(bez.Points[2].X, bez.Points[2].Y);
                }

                break;

            case PathDataType.Arc:
                IEnumerable <PathBezierCurveData> segments;
                PathArcData arc = (PathArcData)data;
                segments = PathDataHelper.GetBezierCurvesForArc(cursor, arc);
                foreach (PathBezierCurveData segment in segments)
                {
                    this.RenderBezierCurveTo(segment.EndPoint.X + location.X,
                                             segment.EndPoint.Y + location.Y,
                                             segment.StartHandle.X + location.X,
                                             segment.StartHandle.Y + location.Y,
                                             segment.EndHandle.X + location.X,
                                             segment.EndHandle.Y + location.Y);
                }
                cursor = arc.EndPoint;
                break;

            case PathDataType.Quadratic:
                IEnumerable <PathBezierCurveData> quadSegments;
                PathQuadraticCurve quad = (PathQuadraticCurve)data;
                quadSegments = PathDataHelper.GetBezierCurvesForQuadratic(cursor, quad);
                foreach (PathBezierCurveData quadSeg in quadSegments)
                {
                    this.RenderBezierCurveTo(quadSeg.EndPoint.X + location.X, quadSeg.EndPoint.Y + location.Y,
                                             quadSeg.StartHandle.X + location.X, quadSeg.StartHandle.Y + location.Y,
                                             quadSeg.EndHandle.X + location.X, quadSeg.EndHandle.Y + location.Y);
                }
                cursor = quad.EndPoint;
                break;

            case PathDataType.Close:
                this.RenderClosePathOp();
                cursor = PDFPoint.Empty;
                break;

            default:
                throw new ArgumentOutOfRangeException("data.Type");
            }
        }