示例#1
0
        private IList <IPathShape> AddMoveToShapes(IPathShape pathShape, String[] pathProperties)
        {
            IList <IPathShape> shapes = new List <IPathShape>();
            int argumentCount         = 2;

            String[] shapeCoordinates = GetShapeCoordinates(pathShape, null, JavaUtil.ArraysCopyOfRange(pathProperties
                                                                                                        , 1, 3));
            zOperator = new ClosePath(pathShape.IsRelative());
            zOperator.SetCoordinates(shapeCoordinates, currentPoint);
            pathShape.SetCoordinates(shapeCoordinates, currentPoint);
            currentPoint = pathShape.GetEndingPoint();
            shapes.Add(pathShape);
            IPathShape previousShape = pathShape;

            if (pathProperties.Length > 3)
            {
                for (int index = 3; index < pathProperties.Length; index += argumentCount)
                {
                    if (index + 2 > pathProperties.Length)
                    {
                        break;
                    }
                    pathShape = pathShape.IsRelative() ? SvgPathShapeFactory.CreatePathShape("l") : SvgPathShapeFactory.CreatePathShape
                                    ("L");
                    shapeCoordinates = GetShapeCoordinates(pathShape, previousShape, JavaUtil.ArraysCopyOfRange(pathProperties
                                                                                                                , index, index + 2));
                    pathShape.SetCoordinates(shapeCoordinates, previousShape.GetEndingPoint());
                    shapes.Add(pathShape);
                    previousShape = pathShape;
                }
            }
            return(shapes);
        }
        /// <summary>
        /// Processes an individual pathing operator and all of its arguments, converting into one or more
        /// <see cref="iText.Svg.Renderers.Path.IPathShape"/>
        /// objects.
        /// </summary>
        /// <param name="pathProperties">
        /// The property operator and all arguments as a
        /// <see>String[]</see>
        /// </param>
        /// <param name="previousShape">
        /// The previous shape which can affect the positioning of the current shape. If no previous
        /// shape exists
        /// <see langword="null"/>
        /// is passed.
        /// </param>
        /// <returns>
        /// a
        /// <see cref="System.Collections.IList{E}"/>
        /// of each
        /// <see cref="iText.Svg.Renderers.Path.IPathShape"/>
        /// that should be drawn to represent the operator.
        /// </returns>
        private IList <IPathShape> ProcessPathOperator(String[] pathProperties, IPathShape previousShape)
        {
            IList <IPathShape> shapes = new List <IPathShape>();

            if (pathProperties.Length == 0 || pathProperties[0].Equals(SEPARATOR))
            {
                return(shapes);
            }
            //Implements (absolute) command value only
            //TODO implement relative values e. C(absolute), c(relative)
            IPathShape pathShape = SvgPathShapeFactory.CreatePathShape(pathProperties[0]);

            String[] shapeCoordinates = GetShapeCoordinates(pathShape, previousShape, pathProperties);
            if (pathShape is ClosePath)
            {
                if (previousShape != null)
                {
                    pathShape = zOperator;
                }
                else
                {
                    throw new SvgProcessingException(SvgLogMessageConstant.INVALID_CLOSEPATH_OPERATOR_USE);
                }
            }
            else
            {
                if (pathShape is MoveTo)
                {
                    zOperator = new ClosePath(pathShape.IsRelative());
                    if (shapeCoordinates != null && shapeCoordinates.Length != MOVETOARGUMENTNR)
                    {
                        LOGGER.Warn(MessageFormatUtil.Format(SvgLogMessageConstant.PATH_WRONG_NUMBER_OF_ARGUMENTS, pathProperties[
                                                                 0], shapeCoordinates.Length, MOVETOARGUMENTNR, MOVETOARGUMENTNR));
                    }
                    zOperator.SetCoordinates(shapeCoordinates, currentPoint);
                }
            }
            if (pathShape != null)
            {
                if (shapeCoordinates != null)
                {
                    // Cast will be removed when the method is introduced in the interface
                    pathShape.SetCoordinates(shapeCoordinates, currentPoint);
                }
                currentPoint = pathShape.GetEndingPoint();
                // unsupported operators are ignored.
                shapes.Add(pathShape);
            }
            return(shapes);
        }