Exemple #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);
        }
Exemple #2
0
        /// <summary>Create a list of bounding rectangles from an 8 x n array of Quadpoints.</summary>
        /// <param name="quadPoints">8xn array of numbers representing 4 points</param>
        /// <returns>a list of bounding rectangles for the passed quadpoints</returns>
        /// <exception cref="iText.Kernel.PdfException">if the passed array's size is not a multiple of 8.</exception>
        public static IList <iText.Kernel.Geom.Rectangle> CreateBoundingRectanglesFromQuadPoint(PdfArray quadPoints
                                                                                                )
        {
            IList <iText.Kernel.Geom.Rectangle> boundingRectangles = new List <iText.Kernel.Geom.Rectangle>();

            if (quadPoints.Size() % 8 != 0)
            {
                throw new PdfException(PdfException.QuadPointArrayLengthIsNotAMultipleOfEight);
            }
            for (int i = 0; i < quadPoints.Size(); i += 8)
            {
                float[]  quadPointEntry   = JavaUtil.ArraysCopyOfRange(quadPoints.ToFloatArray(), i, i + 8);
                PdfArray quadPointEntryFA = new PdfArray(quadPointEntry);
                boundingRectangles.Add(CreateBoundingRectangleFromQuadPoint(quadPointEntryFA));
            }
            return(boundingRectangles);
        }
 /// <summary>
 /// Gets the coordinates that shall be passed to
 /// <see cref="iText.Svg.Renderers.Path.IPathShape.SetCoordinates(System.String[], iText.Kernel.Geom.Point)"/>
 /// for the current shape.
 /// </summary>
 /// <param name="shape">The current shape.</param>
 /// <param name="previousShape">The previous shape which can affect the coordinates of the current shape.</param>
 /// <param name="pathProperties">
 /// The operator and all arguments as a
 /// <see>String[]</see>
 /// </param>
 /// <returns>
 /// a
 /// <see>String[]</see>
 /// of coordinates that shall be passed to
 /// <see cref="iText.Svg.Renderers.Path.IPathShape.SetCoordinates(System.String[], iText.Kernel.Geom.Point)"/>
 /// </returns>
 private String[] GetShapeCoordinates(IPathShape shape, IPathShape previousShape, String[] pathProperties)
 {
     if (shape is ClosePath)
     {
         return(null);
     }
     String[] shapeCoordinates = null;
     String[] operatorArgs     = JavaUtil.ArraysCopyOfRange(pathProperties, 1, pathProperties.Length);
     if (shape is SmoothSCurveTo)
     {
         String[] startingControlPoint = new String[2];
         if (previousShape != null)
         {
             Point previousEndPoint = previousShape.GetEndingPoint();
             //if the previous command was a C or S use its last control point
             if (((previousShape is CurveTo)))
             {
                 Point lastControlPoint = ((CurveTo)previousShape).GetLastControlPoint();
                 float reflectedX       = (float)(2 * previousEndPoint.GetX() - lastControlPoint.GetX());
                 float reflectedY       = (float)(2 * previousEndPoint.GetY() - lastControlPoint.GetY());
                 startingControlPoint[0] = SvgCssUtils.ConvertFloatToString(reflectedX);
                 startingControlPoint[1] = SvgCssUtils.ConvertFloatToString(reflectedY);
             }
             else
             {
                 startingControlPoint[0] = SvgCssUtils.ConvertDoubleToString(previousEndPoint.GetX());
                 startingControlPoint[1] = SvgCssUtils.ConvertDoubleToString(previousEndPoint.GetY());
             }
         }
         else
         {
             // TODO RND-951
             startingControlPoint[0] = pathProperties[1];
             startingControlPoint[1] = pathProperties[2];
         }
         shapeCoordinates = Concatenate(startingControlPoint, operatorArgs);
     }
     if (shapeCoordinates == null)
     {
         shapeCoordinates = operatorArgs;
     }
     return(shapeCoordinates);
 }
Exemple #4
0
        /// <exception cref="Org.BouncyCastle.Security.SecurityUtilityException"/>
        private byte[] ComputeHash(byte[] password, byte[] salt, int saltOffset, int saltLen, byte[] userKey)
        {
            IDigest mdSha256 = DigestUtilities.GetDigest("SHA-256");

            mdSha256.Update(password);
            mdSha256.Update(salt, saltOffset, saltLen);
            if (userKey != null)
            {
                mdSha256.Update(userKey);
            }
            byte[] k = mdSha256.Digest();
            if (isPdf2)
            {
                // See 7.6.4.3.3 "Algorithm 2.B"
                IDigest mdSha384          = DigestUtilities.GetDigest("SHA-384");
                IDigest mdSha512          = DigestUtilities.GetDigest("SHA-512");
                int     userKeyLen        = userKey != null ? userKey.Length : 0;
                int     passAndUserKeyLen = password.Length + userKeyLen;
                // k1 repetition length
                int k1RepLen;
                int roundNum = 0;
                while (true)
                {
                    // a)
                    k1RepLen = passAndUserKeyLen + k.Length;
                    byte[] k1 = new byte[k1RepLen * 64];
                    Array.Copy(password, 0, k1, 0, password.Length);
                    Array.Copy(k, 0, k1, password.Length, k.Length);
                    if (userKey != null)
                    {
                        Array.Copy(userKey, 0, k1, password.Length + k.Length, userKeyLen);
                    }
                    for (int i = 1; i < 64; ++i)
                    {
                        Array.Copy(k1, 0, k1, k1RepLen * i, k1RepLen);
                    }
                    // b)
                    AESCipherCBCnoPad cipher = new AESCipherCBCnoPad(true, JavaUtil.ArraysCopyOf(k, 16), JavaUtil.ArraysCopyOfRange
                                                                         (k, 16, 32));
                    byte[] e = cipher.ProcessBlock(k1, 0, k1.Length);
                    // c)
                    IDigest    md        = null;
                    BigInteger i_1       = new BigInteger(1, JavaUtil.ArraysCopyOf(e, 16));
                    int        remainder = i_1.Remainder(BigInteger.ValueOf(3)).IntValue;
                    switch (remainder)
                    {
                    case 0: {
                        md = mdSha256;
                        break;
                    }

                    case 1: {
                        md = mdSha384;
                        break;
                    }

                    case 2: {
                        md = mdSha512;
                        break;
                    }
                    }
                    // d)
                    k = md.Digest(e);
                    ++roundNum;
                    if (roundNum > 63)
                    {
                        // e)
                        int condVal = e[e.Length - 1] & 0xFF;
                        // interpreting last byte as unsigned integer
                        if (condVal <= roundNum - 32)
                        {
                            break;
                        }
                    }
                }
                k = k.Length == 32 ? k : JavaUtil.ArraysCopyOf(k, 32);
            }
            return(k);
        }
Exemple #5
0
        /// <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 || String.IsNullOrEmpty(pathProperties[0]) || SvgPathShapeFactory.GetArgumentCount
                    (pathProperties[0]) < 0)
            {
                return(shapes);
            }
            int argumentCount = SvgPathShapeFactory.GetArgumentCount(pathProperties[0]);

            if (argumentCount == 0)
            {
                // closePath operator
                if (previousShape == null)
                {
                    throw new SvgProcessingException(SvgLogMessageConstant.INVALID_CLOSEPATH_OPERATOR_USE);
                }
                shapes.Add(zOperator);
                currentPoint = zOperator.GetEndingPoint();
                return(shapes);
            }
            for (int index = 1; index < pathProperties.Length; index += argumentCount)
            {
                if (index + argumentCount > pathProperties.Length)
                {
                    break;
                }
                IPathShape pathShape = SvgPathShapeFactory.CreatePathShape(pathProperties[0]);
                if (pathShape is MoveTo)
                {
                    shapes.AddAll(AddMoveToShapes(pathShape, pathProperties));
                    return(shapes);
                }
                String[] shapeCoordinates = GetShapeCoordinates(pathShape, previousShape, JavaUtil.ArraysCopyOfRange(pathProperties
                                                                                                                     , index, index + argumentCount));
                if (pathShape != null)
                {
                    if (shapeCoordinates != null)
                    {
                        pathShape.SetCoordinates(shapeCoordinates, currentPoint);
                    }
                    currentPoint = pathShape.GetEndingPoint();
                    // unsupported operators are ignored.
                    shapes.Add(pathShape);
                }
                previousShape = pathShape;
            }
            return(shapes);
        }
 private byte[] SubArray(byte[] array, int beg, int end)
 {
     return(JavaUtil.ArraysCopyOfRange(array, beg, end + 1));
 }
 private static byte[] ReadImageType(byte[] bytes)
 {
     return(JavaUtil.ArraysCopyOfRange(bytes, 0, 8));
 }