Example #1
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side defaultSide
                                  , float borderWidthBefore, float borderWidthAfter)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dash         = width * DASH_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = GetDotsGap(borderLength, initialGap + dash);

            if (adjustedGap > dash)
            {
                adjustedGap -= dash;
            }
            float widthHalf = width / 2;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                y1 += widthHalf;
                y2 += widthHalf;
                break;
            }

            case Border.Side.RIGHT: {
                x1 += widthHalf;
                x2 += widthHalf;
                break;
            }

            case Border.Side.BOTTOM: {
                y1 -= widthHalf;
                y2 -= widthHalf;
                break;
            }

            case Border.Side.LEFT: {
                x1 -= widthHalf;
                x2 -= widthHalf;
                break;
            }
            }
            canvas.SaveState().SetLineWidth(width).SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineDash(dash, adjustedGap, dash + adjustedGap / 2).MoveTo(x1, y1).LineTo(x2, y2).Stroke().RestoreState
                ();
        }
Example #2
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side defaultSide
                                  , float borderWidthBefore, float borderWidthAfter)
        {
            float x3 = 0;
            float y3 = 0;
            float x4 = 0;
            float y4 = 0;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x3 = x2 + borderWidthAfter;
                y3 = y2 + width;
                x4 = x1 - borderWidthBefore;
                y4 = y1 + width;
                break;
            }

            case Border.Side.RIGHT: {
                x3 = x2 + width;
                y3 = y2 - borderWidthAfter;
                x4 = x1 + width;
                y4 = y1 + borderWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x3 = x2 - borderWidthAfter;
                y3 = y2 - width;
                x4 = x1 + borderWidthBefore;
                y4 = y1 - width;
                break;
            }

            case Border.Side.LEFT: {
                x3 = x2 - width;
                y3 = y2 + borderWidthAfter;
                x4 = x1 - width;
                y4 = y1 - borderWidthBefore;
                break;
            }
            }
            canvas.SaveState().SetFillColor(transparentColor.GetColor());
            transparentColor.ApplyFillTransparency(canvas);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill().RestoreState();
        }
Example #3
0
        /// <summary><inheritDoc/></summary>
        protected internal override void SetOuterHalfColor(PdfCanvas canvas, Border.Side side)
        {
            switch (side)
            {
            case Border.Side.TOP:
            case Border.Side.LEFT: {
                canvas.SetFillColor(GetDarkerColor());
                break;
            }

            case Border.Side.BOTTOM:
            case Border.Side.RIGHT: {
                canvas.SetFillColor(GetColor());
                break;
            }
            }
        }
Example #4
0
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderWidthBefore
                                  , float borderWidthAfter)
        {
            float x3 = 0;
            float y3 = 0;
            float x4 = 0;
            float y4 = 0;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x3 = x2 + borderWidthAfter;
                y3 = y2 + width;
                x4 = x1 - borderWidthBefore;
                y4 = y1 + width;
                break;
            }

            case Border.Side.RIGHT: {
                x3 = x2 + width;
                y3 = y2 - borderWidthAfter;
                x4 = x1 + width;
                y4 = y1 + borderWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x3 = x2 - borderWidthAfter;
                y3 = y2 - width;
                x4 = x1 + borderWidthBefore;
                y4 = y1 - width;
                break;
            }

            case Border.Side.LEFT: {
                x3 = x2 - width;
                y3 = y2 + borderWidthAfter;
                x4 = x1 - width;
                y4 = y1 - borderWidthBefore;
                break;
            }
            }
            canvas.SetFillColor(color);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill();
        }
Example #5
0
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderWidthBefore
                                  , float borderWidthAfter)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = GetDotsGap(borderLength, initialGap + width);

            if (adjustedGap > width)
            {
                adjustedGap -= width;
            }
            float widthHalf = width / 2;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                y1 += widthHalf;
                y2 += widthHalf;
                break;
            }

            case Border.Side.RIGHT: {
                x1 += widthHalf;
                x2 += widthHalf;
                break;
            }

            case Border.Side.BOTTOM: {
                y1 -= widthHalf;
                y2 -= widthHalf;
                break;
            }

            case Border.Side.LEFT: {
                x1 -= widthHalf;
                x2 -= widthHalf;
                break;
            }
            }
            canvas.SetLineWidth(width);
            canvas.SetStrokeColor(color);
            canvas.SetLineDash(width, adjustedGap, width + adjustedGap / 2).MoveTo(x1, y1).LineTo(x2, y2).Stroke();
        }
Example #6
0
        /// <summary>Calculate adjusted starting points for discontinuous borders, given two opposing points (A and B) that define the bounding rectangle
        ///     </summary>
        /// <param name="x1">x-coordinate of point A</param>
        /// <param name="y1">y-ordinate of point A</param>
        /// <param name="x2">x-coordinate of point B</param>
        /// <param name="y2">y-ordinate of point B</param>
        /// <param name="defaultSide">default side of the border used to determine the side given by points A and B</param>
        /// <returns>float[] containing the adjusted starting points in the form {x1,y1,x2,y2}</returns>
        protected internal virtual float[] GetStartingPointsForBorderSide(float x1, float y1, float x2, float y2,
                                                                          Border.Side defaultSide)
        {
            float widthHalf = width / 2;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                y1 += widthHalf;
                y2 += widthHalf;
                break;
            }

            case Border.Side.RIGHT: {
                x1 += widthHalf;
                x2 += widthHalf;
                break;
            }

            case Border.Side.BOTTOM: {
                y1 -= widthHalf;
                y2 -= widthHalf;
                break;
            }

            case Border.Side.LEFT: {
                x1 -= widthHalf;
                x2 -= widthHalf;
                break;
            }

            default: {
                break;
            }
            }
            return(new float[] { x1, y1, x2, y2 });
        }
Example #7
0
        /// <summary><inheritDoc/></summary>
        public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2)
        {
            float thirdOfWidth = width / 3;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                y1 -= thirdOfWidth;
                y2  = y1;
                break;
            }

            case Border.Side.RIGHT: {
                x1 -= thirdOfWidth;
                x2 -= thirdOfWidth;
                y1 += thirdOfWidth;
                y2 -= thirdOfWidth;
                break;
            }

            case Border.Side.BOTTOM: {
                break;
            }

            case Border.Side.LEFT: {
                break;
            }
            }
            canvas.SaveState().SetLineWidth(thirdOfWidth).SetStrokeColor(color).MoveTo(x1, y1).LineTo(x2, y2).Stroke()
            .RestoreState();
            switch (borderSide)
            {
            case Border.Side.TOP: {
                //                x1 -= 2*thirdOfWidth;
                y2 += 2 * thirdOfWidth;
                y1 += 2 * thirdOfWidth;
                break;
            }

            case Border.Side.RIGHT: {
                x2 += 2 * thirdOfWidth;
                x1 += 2 * thirdOfWidth;
                //                y1 -= 2*thirdOfWidth;
                break;
            }

            case Border.Side.BOTTOM: {
                x2 -= 2 * thirdOfWidth;
                y2 -= 2 * thirdOfWidth;
                x1 += 2 * thirdOfWidth;
                y1 -= 2 * thirdOfWidth;
                break;
            }

            case Border.Side.LEFT: {
                y2 += 2 * thirdOfWidth;
                x1 -= 2 * thirdOfWidth;
                y1 -= 2 * thirdOfWidth;
                break;
            }
            }
            canvas.SaveState().SetLineWidth(thirdOfWidth).SetStrokeColor(color).MoveTo(x1, y1).LineTo(x2, y2).Stroke()
            .RestoreState();
        }
Example #8
0
        /// <summary><inheritDoc/></summary>
        public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side
                                            defaultSide)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dash         = width * DASH_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = base.GetDotsGap(borderLength, initialGap + dash);

            if (adjustedGap > dash)
            {
                adjustedGap -= dash;
            }
            canvas.SaveState().SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineDash(dash, adjustedGap, dash + adjustedGap / 2).SetLineWidth(width).MoveTo(x1, y1).LineTo(x2
                                                                                                                    , y2).Stroke().RestoreState();
        }
Example #9
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float horizontalRadius1
                                  , float verticalRadius1, float horizontalRadius2, float verticalRadius2, Border.Side defaultSide, float
                                  borderWidthBefore, float borderWidthAfter)
        {
            float x3 = 0;
            float y3 = 0;
            float x4 = 0;
            float y4 = 0;
            float innerRadiusBefore;
            float innerRadiusFirst;
            float innerRadiusSecond;
            float innerRadiusAfter;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x3 = x2 + borderWidthAfter;
                y3 = y2 + width;
                x4 = x1 - borderWidthBefore;
                y4 = y1 + width;
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                if (innerRadiusBefore > innerRadiusFirst)
                {
                    x1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x4, y1 - innerRadiusFirst
                                                                                                     ), new Point(x1 + innerRadiusBefore, y1 - innerRadiusFirst)).GetX();
                    y1 -= innerRadiusFirst;
                }
                else
                {
                    if (0 != innerRadiusBefore && 0 != innerRadiusFirst)
                    {
                        y1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1 + innerRadiusBefore, y1
                                                                                                         ), new Point(x1 + innerRadiusBefore, y1 - innerRadiusFirst)).GetY();
                        x1 += innerRadiusBefore;
                    }
                }
                if (innerRadiusAfter > innerRadiusSecond)
                {
                    x2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2, y2 - innerRadiusSecond
                                                                                                     ), new Point(x2 - innerRadiusAfter, y2 - innerRadiusSecond)).GetX();
                    y2 -= innerRadiusSecond;
                }
                else
                {
                    if (0 != innerRadiusAfter && 0 != innerRadiusSecond)
                    {
                        y2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2 - innerRadiusAfter, y2
                                                                                                         ), new Point(x2 - innerRadiusAfter, y2 - innerRadiusSecond)).GetY();
                        x2 -= innerRadiusAfter;
                    }
                }
                break;
            }

            case Border.Side.RIGHT: {
                x3 = x2 + width;
                y3 = y2 - borderWidthAfter;
                x4 = x1 + width;
                y4 = y1 + borderWidthBefore;
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                if (innerRadiusFirst > innerRadiusBefore)
                {
                    x1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1, y1 - innerRadiusBefore
                                                                                                     ), new Point(x1 - innerRadiusFirst, y1 - innerRadiusBefore)).GetX();
                    y1 -= innerRadiusBefore;
                }
                else
                {
                    if (0 != innerRadiusBefore && 0 != innerRadiusFirst)
                    {
                        y1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1 - innerRadiusFirst, y1
                                                                                                         ), new Point(x1 - innerRadiusFirst, y1 - innerRadiusBefore)).GetY();
                        x1 -= innerRadiusFirst;
                    }
                }
                if (innerRadiusAfter > innerRadiusSecond)
                {
                    y2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2 - innerRadiusSecond, y2
                                                                                                     ), new Point(x2 - innerRadiusSecond, y2 + innerRadiusAfter)).GetY();
                    x2 -= innerRadiusSecond;
                }
                else
                {
                    if (0 != innerRadiusAfter && 0 != innerRadiusSecond)
                    {
                        x2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2, y2 + innerRadiusAfter
                                                                                                         ), new Point(x2 - innerRadiusSecond, y2 + innerRadiusAfter)).GetX();
                        y2 += innerRadiusAfter;
                    }
                }
                break;
            }

            case Border.Side.BOTTOM: {
                x3 = x2 - borderWidthAfter;
                y3 = y2 - width;
                x4 = x1 + borderWidthBefore;
                y4 = y1 - width;
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                if (innerRadiusFirst > innerRadiusBefore)
                {
                    y1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1 - innerRadiusBefore, y1
                                                                                                     ), new Point(x1 - innerRadiusBefore, y1 + innerRadiusFirst)).GetY();
                    x1 -= innerRadiusBefore;
                }
                else
                {
                    if (0 != innerRadiusBefore && 0 != innerRadiusFirst)
                    {
                        x1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1, y1 + innerRadiusFirst
                                                                                                         ), new Point(x1 - innerRadiusBefore, y1 + innerRadiusFirst)).GetX();
                        y1 += innerRadiusFirst;
                    }
                }
                if (innerRadiusAfter > innerRadiusSecond)
                {
                    x2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2, y2 + innerRadiusSecond
                                                                                                     ), new Point(x2 + innerRadiusAfter, y2 + innerRadiusSecond)).GetX();
                    y2 += innerRadiusSecond;
                }
                else
                {
                    if (0 != innerRadiusAfter && 0 != innerRadiusSecond)
                    {
                        y2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2 + innerRadiusAfter, y2
                                                                                                         ), new Point(x2 + innerRadiusAfter, y2 + innerRadiusSecond)).GetY();
                        x2 += innerRadiusAfter;
                    }
                }
                break;
            }

            case Border.Side.LEFT: {
                x3 = x2 - width;
                y3 = y2 + borderWidthAfter;
                x4 = x1 - width;
                y4 = y1 - borderWidthBefore;
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                if (innerRadiusFirst > innerRadiusBefore)
                {
                    x1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1, y1 + innerRadiusBefore
                                                                                                     ), new Point(x1 + innerRadiusFirst, y1 + innerRadiusBefore)).GetX();
                    y1 += innerRadiusBefore;
                }
                else
                {
                    if (0 != innerRadiusBefore && 0 != innerRadiusFirst)
                    {
                        y1 = (float)GetIntersectionPoint(new Point(x1, y1), new Point(x4, y4), new Point(x1 + innerRadiusFirst, y1
                                                                                                         ), new Point(x1 + innerRadiusFirst, y1 + innerRadiusBefore)).GetY();
                        x1 += innerRadiusFirst;
                    }
                }
                if (innerRadiusAfter > innerRadiusSecond)
                {
                    y2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2 + innerRadiusSecond, y2
                                                                                                     ), new Point(x2 + innerRadiusSecond, y2 - innerRadiusAfter)).GetY();
                    x2 += innerRadiusSecond;
                }
                else
                {
                    if (0 != innerRadiusAfter && 0 != innerRadiusSecond)
                    {
                        x2 = (float)GetIntersectionPoint(new Point(x2, y2), new Point(x3, y3), new Point(x2, y2 - innerRadiusAfter
                                                                                                         ), new Point(x2 + innerRadiusSecond, y2 - innerRadiusAfter)).GetX();
                        y2 -= innerRadiusAfter;
                    }
                }
                break;
            }
            }
            canvas.SaveState().SetFillColor(transparentColor.GetColor());
            transparentColor.ApplyFillTransparency(canvas);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill().RestoreState();
        }
Example #10
0
 /// <summary><inheritDoc/></summary>
 public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side
                                     defaultSide)
 {
     canvas.SaveState().SetStrokeColor(transparentColor.GetColor());
     transparentColor.ApplyStrokeTransparency(canvas);
     canvas.SetLineWidth(width).MoveTo(x1, y1).LineTo(x2, y2).Stroke().RestoreState();
 }
Example #11
0
        /// <summary><inheritDoc/></summary>
        public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side
                                            defaultSide)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = GetDotsGap(borderLength, initialGap);
            bool   isHorizontal = false;

            if (Math.Abs(y2 - y1) < 0.0005f)
            {
                isHorizontal = true;
            }
            if (isHorizontal)
            {
                x2 -= width;
            }
            canvas.SaveState();
            canvas.SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineWidth(width);
            canvas.SetLineCapStyle(PdfCanvasConstants.LineCapStyle.ROUND);
            canvas.SetLineDash(0, adjustedGap, adjustedGap / 2).MoveTo(x1, y1).LineTo(x2, y2).Stroke();
            canvas.RestoreState();
        }
Example #12
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float horizontalRadius1
                                  , float verticalRadius1, float horizontalRadius2, float verticalRadius2, Border.Side defaultSide, float
                                  borderWidthBefore, float borderWidthAfter)
        {
            float  curv         = 0.447f;
            float  initialGap   = width * GAP_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = GetDotsGap(borderLength, initialGap);
            // Points (x0, y0) and (x3, y3) are used to produce Bezier curve
            float x0 = x1;
            float y0 = y1;
            float x3 = x2;
            float y3 = y2;
            float innerRadiusBefore;
            float innerRadiusFirst;
            float innerRadiusSecond;
            float innerRadiusAfter;
            float widthHalf = width / 2;

            canvas.SaveState().SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineWidth(width).SetLineCapStyle(PdfCanvasConstants.LineCapStyle.ROUND).SetLineDash(0, adjustedGap
                                                                                                          , adjustedGap / 2);
            Point clipPoint1;
            Point clipPoint2;
            Point clipPoint;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                x0        -= borderWidthBefore / 2;
                y0        -= innerRadiusFirst;
                x3        += borderWidthAfter / 2;
                y3        -= innerRadiusSecond;
                clipPoint1 = GetIntersectionPoint(new Point(x1 - borderWidthBefore, y1 + width), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0 + 10, y0));
                clipPoint2 = GetIntersectionPoint(new Point(x2 + borderWidthAfter, y2 + width), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3 - 10, y3));
                if (clipPoint1.x > clipPoint2.x)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 - borderWidthBefore, y1 + width), clipPoint1, clipPoint2, new
                                                     Point(x2 + borderWidthAfter, y2 + width));
                    canvas.MoveTo(x1 - borderWidthBefore, y1 + width).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 + borderWidthAfter
                                                                                                              , y2 + width).LineTo(x1 - borderWidthBefore, y1 + width);
                }
                else
                {
                    canvas.MoveTo(x1 - borderWidthBefore, y1 + width).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 + borderWidthAfter, y2 + width).LineTo(x1 - borderWidthBefore, y1 + width);
                }
                canvas.Clip().NewPath();
                x1 += innerRadiusBefore;
                y1 += widthHalf;
                x2 -= innerRadiusAfter;
                y2 += widthHalf;
                canvas.MoveTo(x0, y0).CurveTo(x0, y0 + innerRadiusFirst * curv, x1 - innerRadiusBefore * curv, y1, x1, y1)
                .LineTo(x2, y2).CurveTo(x2 + innerRadiusAfter * curv, y2, x3, y3 + innerRadiusSecond * curv, x3, y3);
                break;
            }

            case Border.Side.RIGHT: {
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                x0        -= innerRadiusFirst;
                y0        += borderWidthBefore / 2;
                x3        -= innerRadiusSecond;
                y3        -= borderWidthAfter;
                clipPoint1 = GetIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0, y0 - 10));
                clipPoint2 = GetIntersectionPoint(new Point(x2 + width, y2 - borderWidthAfter), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3, y3 - 10));
                if (clipPoint1.y < clipPoint2.y)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), clipPoint1, clipPoint2, new
                                                     Point(x2 + width, y2 - borderWidthAfter));
                    canvas.MoveTo(x1 + width, y1 + borderWidthBefore).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 + width, y2 -
                                                                                                              borderWidthAfter).LineTo(x1 + width, y1 + borderWidthBefore).Clip().NewPath();
                }
                else
                {
                    canvas.MoveTo(x1 + width, y1 + borderWidthBefore).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 + width, y2 - borderWidthAfter).LineTo(x1 + width, y1 + borderWidthBefore).Clip
                        ().NewPath();
                }
                canvas.Clip().NewPath();
                x1 += widthHalf;
                y1 -= innerRadiusBefore;
                x2 += widthHalf;
                y2 += innerRadiusAfter;
                canvas.MoveTo(x0, y0).CurveTo(x0 + innerRadiusFirst * curv, y0, x1, y1 + innerRadiusBefore * curv, x1, y1)
                .LineTo(x2, y2).CurveTo(x2, y2 - innerRadiusAfter * curv, x3 + innerRadiusSecond * curv, y3, x3, y3);
                break;
            }

            case Border.Side.BOTTOM: {
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                x0        += borderWidthBefore / 2;
                y0        += innerRadiusFirst;
                x3        -= borderWidthAfter / 2;
                y3        += innerRadiusSecond;
                clipPoint1 = GetIntersectionPoint(new Point(x1 + borderWidthBefore, y1 - width), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0 - 10, y0));
                clipPoint2 = GetIntersectionPoint(new Point(x2 - borderWidthAfter, y2 - width), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3 + 10, y3));
                if (clipPoint1.x < clipPoint2.x)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 + borderWidthBefore, y1 - width), clipPoint1, clipPoint2, new
                                                     Point(x2 - borderWidthAfter, y2 - width));
                    canvas.MoveTo(x1 + borderWidthBefore, y1 - width).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 - borderWidthAfter
                                                                                                              , y2 - width).LineTo(x1 + borderWidthBefore, y1 - width);
                }
                else
                {
                    canvas.MoveTo(x1 + borderWidthBefore, y1 - width).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 - borderWidthAfter, y2 - width).LineTo(x1 + borderWidthBefore, y1 - width);
                }
                canvas.Clip().NewPath();
                x1 -= innerRadiusBefore;
                y1 -= widthHalf;
                x2 += innerRadiusAfter;
                y2 -= widthHalf;
                canvas.MoveTo(x0, y0).CurveTo(x0, y0 - innerRadiusFirst * curv, x1 + innerRadiusBefore * curv, y1, x1, y1)
                .LineTo(x2, y2).CurveTo(x2 - innerRadiusAfter * curv, y2, x3, y3 - innerRadiusSecond * curv, x3, y3);
                break;
            }

            case Border.Side.LEFT: {
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                x0        += innerRadiusFirst;
                y0        -= borderWidthBefore / 2;
                x3        += innerRadiusSecond;
                y3        += borderWidthAfter;
                clipPoint1 = GetIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0, y0 + 10));
                clipPoint2 = GetIntersectionPoint(new Point(x2 - width, y2 + borderWidthAfter), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3, y3 + 10));
                if (clipPoint1.y > clipPoint2.y)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), clipPoint1, clipPoint2, new
                                                     Point(x2 - width, y2 + borderWidthAfter));
                    canvas.MoveTo(x1 - width, y1 - borderWidthBefore).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 - width, y2 +
                                                                                                              borderWidthAfter).LineTo(x1 - width, y1 - borderWidthBefore);
                }
                else
                {
                    canvas.MoveTo(x1 - width, y1 - borderWidthBefore).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 - width, y2 + borderWidthAfter).LineTo(x1 - width, y1 - borderWidthBefore);
                }
                canvas.Clip().NewPath();
                x1 -= widthHalf;
                y1 += innerRadiusBefore;
                x2 -= widthHalf;
                y2 -= innerRadiusAfter;
                canvas.MoveTo(x0, y0).CurveTo(x0 - innerRadiusFirst * curv, y0, x1, y1 - innerRadiusBefore * curv, x1, y1)
                .LineTo(x2, y2).CurveTo(x2, y2 + innerRadiusAfter * curv, x3 - innerRadiusSecond * curv, y3, x3, y3);
                break;
            }
            }
            canvas.Stroke().RestoreState();
        }
Example #13
0
 protected internal abstract void SetOuterHalfColor(PdfCanvas canvas, Border.Side side);
Example #14
0
        /// <summary>
        /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
        /// drawing direction.
        /// </summary>
        /// <remarks>
        /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
        /// drawing direction. Borders are drawn in this order: top, right, bottom, left.
        /// <para />
        /// Given points specify the line which lies on the border of the content area,
        /// therefore the border itself should be drawn to the left from the drawing direction.
        /// <para />
        /// <c>borderWidthBefore</c> and <c>borderWidthAfter</c> parameters are used to
        /// define the widths of the borders that are before and after the current border, e.g. for
        /// the bottom border, <c>borderWidthBefore</c> specifies width of the right border and
        /// <c>borderWidthAfter</c> - width of the left border. Those width are used to handle areas
        /// of border joins.
        /// <para />
        /// <c>horizontalRadius1</c>, <c>verticalRadius1</c>, <c>horizontalRadius2</c>
        /// and <c>verticalRadius2</c> are used to draw rounded borders.
        /// </remarks>
        /// <param name="canvas">PdfCanvas to be written to</param>
        /// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
        /// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
        /// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
        /// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
        /// <param name="horizontalRadius1">defines the horizontal radius of the border's first corner</param>
        /// <param name="verticalRadius1">defines the vertical radius of the border's first corner</param>
        /// <param name="horizontalRadius2">defines the horizontal radius of the border's second corner</param>
        /// <param name="verticalRadius2">defines the vertical radius of the border's second corner</param>
        /// <param name="defaultSide">
        /// the
        /// <see cref="Side"/>
        /// , that we will fallback to, if it cannot be determined by border coordinates
        /// </param>
        /// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
        /// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
        public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float horizontalRadius1
                                 , float verticalRadius1, float horizontalRadius2, float verticalRadius2, Border.Side defaultSide, float
                                 borderWidthBefore, float borderWidthAfter)
        {
            ILog logger = LogManager.GetLogger(typeof(iText.Layout.Borders.Border));

            logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.METHOD_IS_NOT_IMPLEMENTED_BY_DEFAULT_OTHER_METHOD_WILL_BE_USED
                                                 , "Border#draw(PdfCanvas, float, float, float, float, float, float, float, float, Side, float, float",
                                                 "Border#draw(PdfCanvas, float, float, float, float, Side, float, float)"));
            Draw(canvas, x1, y1, x2, y2, defaultSide, borderWidthBefore, borderWidthAfter);
        }
Example #15
0
 /// <summary>
 /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
 /// drawing direction.
 /// </summary>
 /// <remarks>
 /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
 /// drawing direction. Borders are drawn in this order: top, right, bottom, left.
 /// <para />
 /// Given points specify the line which lies on the border of the content area,
 /// therefore the border itself should be drawn to the left from the drawing direction.
 /// <para />
 /// <c>borderWidthBefore</c> and <c>borderWidthAfter</c> parameters are used to
 /// define the widths of the borders that are before and after the current border, e.g. for
 /// the bottom border, <c>borderWidthBefore</c> specifies width of the right border and
 /// <c>borderWidthAfter</c> - width of the left border. Those width are used to handle areas
 /// of border joins.
 /// </remarks>
 /// <param name="canvas">PdfCanvas to be written to</param>
 /// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="defaultSide">
 /// the
 /// <see cref="Side"/>
 /// , that we will fallback to, if it cannot be determined by border coordinates
 /// </param>
 /// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
 /// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
 public abstract void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side defaultSide
                           , float borderWidthBefore, float borderWidthAfter);
Example #16
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderWidthBefore
                                  , float borderWidthAfter)
        {
            float x3                 = 0;
            float y3                 = 0;
            float x4                 = 0;
            float y4                 = 0;
            float thirdOfWidth       = width / 3;
            float thirdOfWidthBefore = borderWidthBefore / 3;
            float thirdOfWidthAfter  = borderWidthAfter / 3;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x3 = x2 + thirdOfWidthAfter;
                y3 = y2 + thirdOfWidth;
                x4 = x1 - thirdOfWidthBefore;
                y4 = y1 + thirdOfWidth;
                break;
            }

            case Border.Side.RIGHT: {
                x3 = x2 + thirdOfWidth;
                y3 = y2 - thirdOfWidthAfter;
                x4 = x1 + thirdOfWidth;
                y4 = y1 + thirdOfWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x3 = x2 - thirdOfWidthAfter;
                y3 = y2 - thirdOfWidth;
                x4 = x1 + thirdOfWidthBefore;
                y4 = y1 - thirdOfWidth;
                break;
            }

            case Border.Side.LEFT: {
                x3 = x2 - thirdOfWidth;
                y3 = y2 + thirdOfWidthAfter;
                x4 = x1 - thirdOfWidth;
                y4 = y1 - thirdOfWidthBefore;
                break;
            }
            }
            canvas.SetFillColor(color);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill();
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x2 += 2 * thirdOfWidthAfter;
                y2 += 2 * thirdOfWidth;
                x3 += 2 * thirdOfWidthAfter;
                y3 += 2 * thirdOfWidth;
                x4 -= 2 * thirdOfWidthBefore;
                y4 += 2 * thirdOfWidth;
                x1 -= 2 * thirdOfWidthBefore;
                y1 += 2 * thirdOfWidth;
                break;
            }

            case Border.Side.RIGHT: {
                x2 += 2 * thirdOfWidth;
                y2 -= 2 * thirdOfWidthAfter;
                x3 += 2 * thirdOfWidth;
                y3 -= 2 * thirdOfWidthAfter;
                x4 += 2 * thirdOfWidth;
                y4 += 2 * thirdOfWidthBefore;
                x1 += 2 * thirdOfWidth;
                y1 += 2 * thirdOfWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x2 -= 2 * thirdOfWidthAfter;
                y2 -= 2 * thirdOfWidth;
                x3 -= 2 * thirdOfWidthAfter;
                y3 -= 2 * thirdOfWidth;
                x4 += 2 * thirdOfWidthBefore;
                y4 -= 2 * thirdOfWidth;
                x1 += 2 * thirdOfWidthBefore;
                y1 -= 2 * thirdOfWidth;
                break;
            }

            case Border.Side.LEFT: {
                x2 -= 2 * thirdOfWidth;
                y2 += 2 * thirdOfWidthAfter;
                x3 -= 2 * thirdOfWidth;
                y3 += 2 * thirdOfWidthAfter;
                x4 -= 2 * thirdOfWidth;
                y4 -= 2 * thirdOfWidthBefore;
                x1 -= 2 * thirdOfWidth;
                y1 -= 2 * thirdOfWidthBefore;
                break;
            }
            }
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill();
        }
Example #17
0
        /// <summary>Perform drawing operations to draw discontinuous borders.</summary>
        /// <remarks>
        /// Perform drawing operations to draw discontinuous borders. Used by
        /// <see cref="DashedBorder"/>
        /// ,
        /// <see cref="DottedBorder"/>
        /// and
        /// <see cref="RoundDotsBorder"/>.
        /// </remarks>
        /// <param name="canvas">canvas to draw on</param>
        /// <param name="boundingRectangle">rectangle representing the bounding box of the drawing operations</param>
        /// <param name="horizontalRadii">the horizontal radius of the border's two corners</param>
        /// <param name="verticalRadii">the vertical radius of the border's two corners</param>
        /// <param name="defaultSide">
        /// the
        /// <see cref="Side"/>
        /// , that we will fallback to, if it cannot be determined by border coordinates
        /// </param>
        /// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
        /// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
        protected internal virtual void DrawDiscontinuousBorders(PdfCanvas canvas, Rectangle boundingRectangle, float
                                                                 [] horizontalRadii, float[] verticalRadii, Border.Side defaultSide, float borderWidthBefore, float borderWidthAfter
                                                                 )
        {
            float x1 = boundingRectangle.GetX();
            float y1 = boundingRectangle.GetY();
            float x2 = boundingRectangle.GetRight();
            float y2 = boundingRectangle.GetTop();
            float horizontalRadius1 = horizontalRadii[0];
            float horizontalRadius2 = horizontalRadii[1];
            float verticalRadius1   = verticalRadii[0];
            float verticalRadius2   = verticalRadii[1];
            // Points (x0, y0) and (x3, y3) are used to produce Bezier curve
            float x0 = boundingRectangle.GetX();
            float y0 = boundingRectangle.GetY();
            float x3 = boundingRectangle.GetRight();
            float y3 = boundingRectangle.GetTop();
            float innerRadiusBefore;
            float innerRadiusFirst;
            float innerRadiusSecond;
            float innerRadiusAfter;
            float widthHalf = width / 2;
            Point clipPoint1;
            Point clipPoint2;
            Point clipPoint;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, defaultSide);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                x0        -= borderWidthBefore / 2;
                y0        -= innerRadiusFirst;
                x3        += borderWidthAfter / 2;
                y3        -= innerRadiusSecond;
                clipPoint1 = GetIntersectionPoint(new Point(x1 - borderWidthBefore, y1 + width), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0 + 10, y0));
                clipPoint2 = GetIntersectionPoint(new Point(x2 + borderWidthAfter, y2 + width), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3 - 10, y3));
                if (clipPoint1.x > clipPoint2.x)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 - borderWidthBefore, y1 + width), clipPoint1, clipPoint2, new
                                                     Point(x2 + borderWidthAfter, y2 + width));
                    canvas.MoveTo(x1 - borderWidthBefore, y1 + width).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 + borderWidthAfter
                                                                                                              , y2 + width).LineTo(x1 - borderWidthBefore, y1 + width);
                }
                else
                {
                    canvas.MoveTo(x1 - borderWidthBefore, y1 + width).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 + borderWidthAfter, y2 + width).LineTo(x1 - borderWidthBefore, y1 + width);
                }
                canvas.Clip().EndPath();
                x1 += innerRadiusBefore;
                y1 += widthHalf;
                x2 -= innerRadiusAfter;
                y2 += widthHalf;
                canvas.MoveTo(x0, y0).CurveTo(x0, y0 + innerRadiusFirst * CURV, x1 - innerRadiusBefore * CURV, y1, x1, y1)
                .LineTo(x2, y2).CurveTo(x2 + innerRadiusAfter * CURV, y2, x3, y3 + innerRadiusSecond * CURV, x3, y3);
                break;
            }

            case Border.Side.RIGHT: {
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                x0        -= innerRadiusFirst;
                y0        += borderWidthBefore / 2;
                x3        -= innerRadiusSecond;
                y3        -= borderWidthAfter / 2;
                clipPoint1 = GetIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0, y0 - 10));
                clipPoint2 = GetIntersectionPoint(new Point(x2 + width, y2 - borderWidthAfter), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3, y3 - 10));
                if (clipPoint1.y < clipPoint2.y)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), clipPoint1, clipPoint2, new
                                                     Point(x2 + width, y2 - borderWidthAfter));
                    canvas.MoveTo(x1 + width, y1 + borderWidthBefore).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 + width, y2 -
                                                                                                              borderWidthAfter).LineTo(x1 + width, y1 + borderWidthBefore).Clip().EndPath();
                }
                else
                {
                    canvas.MoveTo(x1 + width, y1 + borderWidthBefore).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 + width, y2 - borderWidthAfter).LineTo(x1 + width, y1 + borderWidthBefore).Clip
                        ().EndPath();
                }
                canvas.Clip().EndPath();
                x1 += widthHalf;
                y1 -= innerRadiusBefore;
                x2 += widthHalf;
                y2 += innerRadiusAfter;
                canvas.MoveTo(x0, y0).CurveTo(x0 + innerRadiusFirst * CURV, y0, x1, y1 + innerRadiusBefore * CURV, x1, y1)
                .LineTo(x2, y2).CurveTo(x2, y2 - innerRadiusAfter * CURV, x3 + innerRadiusSecond * CURV, y3, x3, y3);
                break;
            }

            case Border.Side.BOTTOM: {
                innerRadiusBefore = Math.Max(0, horizontalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, verticalRadius1 - width);
                innerRadiusSecond = Math.Max(0, verticalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, horizontalRadius2 - borderWidthAfter);
                x0        += borderWidthBefore / 2;
                y0        += innerRadiusFirst;
                x3        -= borderWidthAfter / 2;
                y3        += innerRadiusSecond;
                clipPoint1 = GetIntersectionPoint(new Point(x1 + borderWidthBefore, y1 - width), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0 - 10, y0));
                clipPoint2 = GetIntersectionPoint(new Point(x2 - borderWidthAfter, y2 - width), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3 + 10, y3));
                if (clipPoint1.x < clipPoint2.x)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 + borderWidthBefore, y1 - width), clipPoint1, clipPoint2, new
                                                     Point(x2 - borderWidthAfter, y2 - width));
                    canvas.MoveTo(x1 + borderWidthBefore, y1 - width).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 - borderWidthAfter
                                                                                                              , y2 - width).LineTo(x1 + borderWidthBefore, y1 - width);
                }
                else
                {
                    canvas.MoveTo(x1 + borderWidthBefore, y1 - width).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 - borderWidthAfter, y2 - width).LineTo(x1 + borderWidthBefore, y1 - width);
                }
                canvas.Clip().EndPath();
                x1 -= innerRadiusBefore;
                y1 -= widthHalf;
                x2 += innerRadiusAfter;
                y2 -= widthHalf;
                canvas.MoveTo(x0, y0).CurveTo(x0, y0 - innerRadiusFirst * CURV, x1 + innerRadiusBefore * CURV, y1, x1, y1)
                .LineTo(x2, y2).CurveTo(x2 - innerRadiusAfter * CURV, y2, x3, y3 - innerRadiusSecond * CURV, x3, y3);
                break;
            }

            case Border.Side.LEFT: {
                innerRadiusBefore = Math.Max(0, verticalRadius1 - borderWidthBefore);
                innerRadiusFirst  = Math.Max(0, horizontalRadius1 - width);
                innerRadiusSecond = Math.Max(0, horizontalRadius2 - width);
                innerRadiusAfter  = Math.Max(0, verticalRadius2 - borderWidthAfter);
                x0        += innerRadiusFirst;
                y0        -= borderWidthBefore / 2;
                x3        += innerRadiusSecond;
                y3        += borderWidthAfter / 2;
                clipPoint1 = GetIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), new Point(x1, y1), new Point
                                                      (x0, y0), new Point(x0, y0 + 10));
                clipPoint2 = GetIntersectionPoint(new Point(x2 - width, y2 + borderWidthAfter), new Point(x2, y2), new Point
                                                      (x3, y3), new Point(x3, y3 + 10));
                if (clipPoint1.y > clipPoint2.y)
                {
                    clipPoint = GetIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), clipPoint1, clipPoint2, new
                                                     Point(x2 - width, y2 + borderWidthAfter));
                    canvas.MoveTo(x1 - width, y1 - borderWidthBefore).LineTo(clipPoint.x, clipPoint.y).LineTo(x2 - width, y2 +
                                                                                                              borderWidthAfter).LineTo(x1 - width, y1 - borderWidthBefore);
                }
                else
                {
                    canvas.MoveTo(x1 - width, y1 - borderWidthBefore).LineTo(clipPoint1.x, clipPoint1.y).LineTo(clipPoint2.x,
                                                                                                                clipPoint2.y).LineTo(x2 - width, y2 + borderWidthAfter).LineTo(x1 - width, y1 - borderWidthBefore);
                }
                canvas.Clip().EndPath();
                x1 -= widthHalf;
                y1 += innerRadiusBefore;
                x2 -= widthHalf;
                y2 -= innerRadiusAfter;
                canvas.MoveTo(x0, y0).CurveTo(x0 - innerRadiusFirst * CURV, y0, x1, y1 - innerRadiusBefore * CURV, x1, y1)
                .LineTo(x2, y2).CurveTo(x2, y2 + innerRadiusAfter * CURV, x3 - innerRadiusSecond * CURV, y3, x3, y3);
                break;
            }

            default: {
                break;
            }
            }
            canvas.Stroke().RestoreState();
        }
Example #18
0
        /// <summary>
        /// Returns the
        /// <see cref="Side">side</see>
        /// corresponded to the line between two points.
        /// </summary>
        /// <remarks>
        /// Returns the
        /// <see cref="Side">side</see>
        /// corresponded to the line between two points.
        /// Notice that we consider the rectangle traversal to be clockwise.
        /// In case side couldn't be detected we will fallback to default side
        /// </remarks>
        /// <param name="x1">the abscissa of the left-bottom point</param>
        /// <param name="y1">the ordinate of the left-bottom point</param>
        /// <param name="x2">the abscissa of the right-top point</param>
        /// <param name="y2">the ordinate of the right-top point</param>
        /// <param name="defaultSide">the default side of border</param>
        /// <returns>
        /// the corresponded
        /// <see cref="Side">side</see>
        /// </returns>
        protected internal virtual Border.Side GetBorderSide(float x1, float y1, float x2, float y2, Border.Side defaultSide
                                                             )
        {
            bool isLeft  = false;
            bool isRight = false;

            if (Math.Abs(y2 - y1) > 0.0005f)
            {
                isLeft  = y2 - y1 > 0;
                isRight = y2 - y1 < 0;
            }
            bool isTop    = false;
            bool isBottom = false;

            if (Math.Abs(x2 - x1) > 0.0005f)
            {
                isTop    = x2 - x1 > 0;
                isBottom = x2 - x1 < 0;
            }
            if (isTop)
            {
                return(isLeft ? Border.Side.LEFT : Border.Side.TOP);
            }
            else
            {
                if (isRight)
                {
                    return(Border.Side.RIGHT);
                }
                else
                {
                    if (isBottom)
                    {
                        return(Border.Side.BOTTOM);
                    }
                    else
                    {
                        if (isLeft)
                        {
                            return(Border.Side.LEFT);
                        }
                    }
                }
            }
            return(defaultSide);
        }
Example #19
0
 /// <summary>Draws the border of a cell.</summary>
 /// <param name="canvas">PdfCanvas to be written to</param>
 /// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="defaultSide">
 /// the
 /// <see cref="Side"/>
 /// , that we will fallback to, if it cannot be determined by border coordinates
 /// </param>
 public abstract void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side
                                     defaultSide);
Example #20
0
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float horizontalRadius1
                                  , float verticalRadius1, float horizontalRadius2, float verticalRadius2, Border.Side defaultSide, float
                                  borderWidthBefore, float borderWidthAfter)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dash         = width * DASH_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = base.GetDotsGap(borderLength, initialGap + dash);

            if (adjustedGap > dash)
            {
                adjustedGap -= dash;
            }
            canvas.SaveState().SetLineWidth(width).SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineDash(dash, adjustedGap, dash + adjustedGap / 2);
            Rectangle boundingRectangle = new Rectangle(x1, y1, x2 - x1, y2 - y1);

            float[] horizontalRadii = new float[] { horizontalRadius1, horizontalRadius2 };
            float[] verticalRadii   = new float[] { verticalRadius1, verticalRadius2 };
            DrawDiscontinuousBorders(canvas, boundingRectangle, horizontalRadii, verticalRadii, defaultSide, borderWidthBefore
                                     , borderWidthAfter);
        }
Example #21
0
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderWidthBefore
                                  , float borderWidthAfter)
        {
            float x3                = 0;
            float y3                = 0;
            float x4                = 0;
            float y4                = 0;
            float widthHalf         = width / 2;
            float halfOfWidthBefore = borderWidthBefore / 2;
            float halfOfWidthAfter  = borderWidthAfter / 2;

            Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x3 = x2 + halfOfWidthAfter;
                y3 = y2 + widthHalf;
                x4 = x1 - halfOfWidthBefore;
                y4 = y1 + widthHalf;
                break;
            }

            case Border.Side.RIGHT: {
                x3 = x2 + widthHalf;
                y3 = y2 - halfOfWidthAfter;
                x4 = x1 + widthHalf;
                y4 = y1 + halfOfWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x3 = x2 - halfOfWidthAfter;
                y3 = y2 - widthHalf;
                x4 = x1 + halfOfWidthBefore;
                y4 = y1 - widthHalf;
                break;
            }

            case Border.Side.LEFT: {
                x3 = x2 - widthHalf;
                y3 = y2 + halfOfWidthAfter;
                x4 = x1 - widthHalf;
                y4 = y1 - halfOfWidthBefore;
                break;
            }
            }
            SetInnerHalfColor(canvas, borderSide);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill();
            switch (borderSide)
            {
            case Border.Side.TOP: {
                x2 += borderWidthAfter;
                y2 += width;
                x1 -= borderWidthBefore;
                y1 += width;
                break;
            }

            case Border.Side.RIGHT: {
                x2 += width;
                y2 -= borderWidthAfter;
                x1 += width;
                y1 += borderWidthBefore;
                break;
            }

            case Border.Side.BOTTOM: {
                x2 -= borderWidthAfter;
                y2 -= width;
                x1 += borderWidthBefore;
                y1 -= width;
                break;
            }

            case Border.Side.LEFT: {
                x2 -= width;
                y2 += borderWidthAfter;
                x1 -= width;
                y1 -= borderWidthBefore;
                break;
            }
            }
            SetOuterHalfColor(canvas, borderSide);
            canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill();
        }
Example #22
0
        /// <summary><inheritDoc/></summary>
        public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Border.Side defaultSide
                                  , float borderWidthBefore, float borderWidthAfter)
        {
            float  initialGap   = width * GAP_MODIFIER;
            float  dash         = width * DASH_MODIFIER;
            float  dx           = x2 - x1;
            float  dy           = y2 - y1;
            double borderLength = Math.Sqrt(dx * dx + dy * dy);
            float  adjustedGap  = base.GetDotsGap(borderLength, initialGap + dash);

            if (adjustedGap > dash)
            {
                adjustedGap -= dash;
            }
            float[] startingPoints = GetStartingPointsForBorderSide(x1, y1, x2, y2, defaultSide);
            x1 = startingPoints[0];
            y1 = startingPoints[1];
            x2 = startingPoints[2];
            y2 = startingPoints[3];
            canvas.SaveState().SetLineWidth(width).SetStrokeColor(transparentColor.GetColor());
            transparentColor.ApplyStrokeTransparency(canvas);
            canvas.SetLineDash(dash, adjustedGap, dash + adjustedGap / 2).MoveTo(x1, y1).LineTo(x2, y2).Stroke().RestoreState
                ();
        }
Example #23
0
 /// <summary>
 /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
 /// drawing direction.
 /// </summary>
 /// <remarks>
 /// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
 /// drawing direction. Borders are drawn in this order: top, right, bottom, left.
 /// <para />
 /// Given points specify the line which lies on the border of the content area,
 /// therefore the border itself should be drawn to the left from the drawing direction.
 /// <para />
 /// <c>borderWidthBefore</c> and <c>borderWidthAfter</c> parameters are used to
 /// define the widths of the borders that are before and after the current border, e.g. for
 /// the bottom border, <c>borderWidthBefore</c> specifies width of the right border and
 /// <c>borderWidthAfter</c> - width of the left border. Those width are used to handle areas
 /// of border joins.
 /// <para />
 /// <c>borderRadius</c> is used to draw rounded borders.
 /// </remarks>
 /// <param name="canvas">PdfCanvas to be written to</param>
 /// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
 /// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
 /// <param name="borderRadius">defines the radius of the element's corners</param>
 /// <param name="defaultSide">
 /// the
 /// <see cref="Side"/>
 /// , that we will fallback to, if it cannot be determined by border coordinates
 /// </param>
 /// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
 /// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
 public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
                          defaultSide, float borderWidthBefore, float borderWidthAfter)
 {
     Draw(canvas, x1, y1, x2, y2, borderRadius, borderRadius, borderRadius, borderRadius, defaultSide, borderWidthBefore
          , borderWidthAfter);
 }