protected virtual void AddShape(ShapeDetails shape, StringBuilder sb)
        {
            sb.Append(@"
        draw([");
            for (var i = 0; i < shape.Lines.Count; i++)
            {
                if (i != 0)
                {
                    sb.Append(",");
                }
                sb.Append("[");
                var points = shape.Lines[i].AllPoints.ToArray();
                for (var j = 0; j < points.Length; j++)
                {
                    if (j != 0)
                    {
                        sb.Append(",");
                    }
                    var p = points[j];
                    sb.Append(p.X).Append(",").Append(p.Y);
                }
                sb.Append("]");
            }

            sb.Append("],").Append((int)shape.ShapeOperation).Append(",");
            AppendColor(shape.StrokeColor, sb);
            sb.Append(",");
            AppendColor(shape.FillColor, sb);
            sb.Append(",").Append(shape.LineWidth)
            .Append(",'").Append(shape.EvenOddRule?"evenodd":"nonzero").Append("',").Append("null").Append(");");
        }
        private void AddShape(ShapeDetails shape, StringBuilder sb)
        {
            if (shape.ShapeOperation == ShapeOperation.None)
            {
                return;
            }
            ShapePoint lastEnd = null;

            sb.Append(@"
        <path d=""");
            foreach (var line in shape.Lines)
            {
                if (!line.Start.Equals(lastEnd))
                {
                    sb.Append("M");
                    AddPoint(line.Start, sb);
                }

                if (line.CurveControlPoint1 == null)
                {
                    sb.Append(" L");
                }
                else
                {
                    if (line.CurveControlPoint2 != null)
                    {
                        sb.Append(" C");
                        AddPoint(line.CurveControlPoint1, sb);
                        sb.Append(",");
                        AddPoint(line.CurveControlPoint2, sb);
                        sb.Append(",");
                    }
                    else
                    {
                        sb.Append(" Q");
                        AddPoint(line.CurveControlPoint1, sb);
                        sb.Append(",");
                    }
                }

                AddPoint(line.End, sb);
                lastEnd = line.End;
            }

            sb.Append("\" stroke-width=\"").Append(shape.LineWidth)
            .Append("\" fill=\"");
            AppendColor(shape.ShapeOperation == ShapeOperation.Stroke?null:shape.FillColor, sb);
            if (shape.EvenOddRule)
            {
                sb.Append("\" fill-rule=\"evenodd");
            }
            sb.Append("\" stroke=\"");
            AppendColor(shape.ShapeOperation == ShapeOperation.Fill?null:shape.StrokeColor, sb);
            sb.Append("\"/>");
        }
示例#3
0
        public virtual void ParsePath(PathRenderInfo data)
        {
            var shapeOperation = (ShapeOperation)data.GetOperation();

            if (shapeOperation == ShapeOperation.None)
            {
                return;
            }
            bool evenOddRule = data.GetRule() == PdfCanvasConstants.FillingRule.EVEN_ODD;
            var  fillColor   = ColorManager.Instance.GetColor(data.GetFillColor(), data.GetGraphicsState().GetFillOpacity());

            if (shapeOperation != ShapeOperation.Stroke && (fillColor == null || fillColor == Color.Black))
            {
                return;
            }

            var strokeColor = ColorManager.Instance.GetColor(data.GetStrokeColor(), data.GetGraphicsState().GetStrokeOpacity());
            var lineWidth   = data.GetLineWidth();
            var lineCap     = data.GetLineCapStyle();
            var ctm         = data.GetCtm();
            var lines       = ConvertLines(data.GetPath(), ctm).ToArray();

            if (lines.Length == 0)
            {
                return;
            }


            var shapeDetails = new ShapeDetails
            {
                ShapeOperation = shapeOperation,
                StrokeColor    = strokeColor,
                FillColor      = fillColor,
                LineWidth      = lineWidth,
                EvenOddRule    = evenOddRule,
                Lines          = lines
            };

            if (Log.DebugSupported)
            {
                Log.Debug($"shape: {shapeDetails}");
            }
            shapes.Add(shapeDetails);
        }