////////////////////////////////////////////////////////////////////
        // Draw Happy Face
        ////////////////////////////////////////////////////////////////////

        private void DrawHappyFace
        (
            PdfContents Contents
        )
        {
            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the happy face
            Contents.Translate(4.25, 7.5);

            // change nonstroking (fill) color to yellow
            Contents.SetColorNonStroking(Color.Yellow);

            // draw happy face yellow oval
            Contents.DrawOval(-1.5, -1.0, 3.0, 2.0, PaintOp.Fill);

            // set line width to 0.2" this is the black circle around the eye
            Contents.SetLineWidth(0.2);

            // eye color is white with black outline circle
            Contents.SetColorNonStroking(Color.White);
            Contents.SetColorStroking(Color.Black);

            // draw eyes
            Contents.DrawOval(-0.75, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);
            Contents.DrawOval(0.25, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);

            // mouth color is black
            Contents.SetColorNonStroking(Color.Black);

            // draw mouth by creating a path made of one line and one Bezier curve
            Contents.MoveTo(-0.6, -0.4);
            Contents.LineTo(0.6, -0.4);
            Contents.DrawBezier(0.0, -0.8, 0, -0.8, -0.6, -0.4);

            // fill the path with black color
            Contents.SetPaintOp(PaintOp.Fill);

            // restore graphics sate
            Contents.RestoreGraphicsState();
            return;
        }
Exemplo n.º 2
0
        private void BuildPath
        (
            PdfContents Contents,
            PaintOp PaintOperator
        )
        {
            // every figure is a separated subpath and contains some segments
            foreach (SysMedia.PathFigure SubPath in MediaPath.Figures)
            {
                // get start of sub-path point
                PointD CurPoint   = PathToDrawing(SubPath.StartPoint);
                PointD StartPoint = CurPoint;
                Contents.MoveTo(CurPoint);

                // process all points of one sub-path
                foreach (SysMedia.PathSegment Seg in SubPath.Segments)
                {
                    // line segment
                    if (Seg.GetType() == typeof(SysMedia.LineSegment))
                    {
                        CurPoint = PathToDrawing(((SysMedia.LineSegment)Seg).Point);
                        Contents.LineTo(CurPoint);
                    }

                    // polygon
                    else if (Seg.GetType() == typeof(SysMedia.PolyLineSegment))
                    {
                        SysMedia.PolyLineSegment LineSegArray = (SysMedia.PolyLineSegment)Seg;
                        foreach (SysWin.Point PolyPoint in LineSegArray.Points)
                        {
                            CurPoint = PathToDrawing(PolyPoint);
                            Contents.LineTo(CurPoint);
                        }
                    }

                    // cubic bezier segment
                    else if (Seg.GetType() == typeof(SysMedia.BezierSegment))
                    {
                        SysMedia.BezierSegment BezierSeg = (SysMedia.BezierSegment)Seg;
                        CurPoint = PathToDrawing(BezierSeg.Point3);
                        Contents.DrawBezier(PathToDrawing(BezierSeg.Point1), PathToDrawing(BezierSeg.Point2), CurPoint);
                    }

                    // cubic bezier multi segments
                    else if (Seg.GetType() == typeof(SysMedia.PolyBezierSegment))
                    {
                        SysMedia.PolyBezierSegment BezierSegArray = (SysMedia.PolyBezierSegment)Seg;
                        int Count = BezierSegArray.Points.Count;
                        for (int Index = 0; Index < Count; Index += 3)
                        {
                            CurPoint = PathToDrawing(BezierSegArray.Points[Index + 2]);
                            Contents.DrawBezier(PathToDrawing(BezierSegArray.Points[Index]), PathToDrawing(BezierSegArray.Points[Index + 1]), CurPoint);
                        }
                    }

                    // quadratic bezier segment
                    else if (Seg.GetType() == typeof(SysMedia.QuadraticBezierSegment))
                    {
                        SysMedia.QuadraticBezierSegment BezierSeg = (SysMedia.QuadraticBezierSegment)Seg;
                        PointD NextPoint = PathToDrawing(BezierSeg.Point2);
                        Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSeg.Point1), NextPoint), BezierPointOne.Ignore);
                        CurPoint = NextPoint;
                    }

                    // quadratic bezier multi segments
                    else if (Seg.GetType() == typeof(SysMedia.PolyQuadraticBezierSegment))
                    {
                        SysMedia.PolyQuadraticBezierSegment BezierSegArray = (SysMedia.PolyQuadraticBezierSegment)Seg;
                        int Count = BezierSegArray.Points.Count;
                        for (int Index = 0; Index < Count; Index += 2)
                        {
                            PointD NextPoint = PathToDrawing(BezierSegArray.Points[Index + 1]);
                            Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSegArray.Points[Index]), NextPoint), BezierPointOne.Ignore);
                            CurPoint = NextPoint;
                        }
                    }

                    // draw arc
                    else if (Seg.GetType() == typeof(SysMedia.ArcSegment))
                    {
                        SysMedia.ArcSegment Arc = (SysMedia.ArcSegment)Seg;
                        PointD  NextPoint       = PathToDrawing(Arc.Point);
                        ArcType ArcType;
                        if (Arc.SweepDirection == (PathYAxis == YAxisDirection.Down ? SysMedia.SweepDirection.Counterclockwise : SysMedia.SweepDirection.Clockwise))
                        {
                            ArcType = Arc.IsLargeArc ? ArcType.LargeCounterClockWise : ArcType.SmallCounterClockWise;
                        }
                        else
                        {
                            ArcType = Arc.IsLargeArc ? ArcType.LargeClockWise : ArcType.SmallClockWise;
                        }
                        Contents.DrawArc(CurPoint, NextPoint, SizeToDrawing(Arc.Size), Arc.RotationAngle, ArcType, BezierPointOne.Ignore);
                        CurPoint = NextPoint;
                    }

                    // should no happen
                    else
                    {
                        throw new ApplicationException("Windows Media path: unknown path segment.");
                    }
                }

                // for stroke set paint operator for each sub-path
                if (SubPath.IsClosed)
                {
                    Contents.SetPaintOp(PaintOp.CloseSubPath);
                }
            }

            // paint operator
            Contents.SetPaintOp(PaintOperator);
            return;
        }