Ejemplo n.º 1
0
        private PDFDict SetItem(PDFDict curr, int index, PDFObject value)
        {
            bool       flag1;
            int        num1;
            PDFInteger integer1;
            PDFArray   array3;
            int        num2;
            PDFArray   array4;
            PDFDict    dict1;
            PDFArray   array5;
            PDFArray   array6;
            int        num3;
            PDFDict    dict2;
            PDFArray   array7;
            PDFInteger integer2;
            PDFInteger integer3;
            PDFDict    dict3;
            PDFArray   array8;
            PDFObject  obj1;
            PDFArray   array1 = (curr["Nums"] as PDFArray);
            PDFArray   array2 = (curr["Kids"] as PDFArray);

            if (array1 != null)
            {
                if ((array1.Count % 2) != 0)
                {
                    throw new InvalidOperationException("Attempt to manipulate invalid name tree");
                }
                flag1 = true;
                for (num1 = 0; (num1 < (array1.Count / 2)); num1 += 1)
                {
                    integer1 = (array1[(2 * num1)] as PDFInteger);
                    if (integer1 == null)
                    {
                        throw new InvalidOperationException("Attempt to manipulate invalid name tree");
                    }
                    if (integer1.Value == ((long)index))
                    {
                        array1[((2 * num1) + 1)] = value;
                        return(null);
                    }
                    if (integer1.Value > ((long)index))
                    {
                        array1.Insert((2 * num1), value);
                        array1.Insert((2 * num1), PDF.O(index));
                        flag1 = false;
                        break;
                    }
                }
                if (flag1)
                {
                    array1.Add(PDF.O(index));
                    array1.Add(value);
                    array3 = (curr["Limits"] as PDFArray);
                    if (array3 != null)
                    {
                        ((PDFInteger)array3[1]).Value = ((long)index);
                    }
                }
                if ((array1.Count / 2) > this.mMaxKids)
                {
                    num2   = (array1.Count / 2);
                    array4 = Library.CreateArray(0);
                    dict1  = Library.CreateDict();
                    Library.CreateIndirect(dict1);
                    while ((array1.Count > num2))
                    {
                        array4.Insert(0, array1.RemoveAt((array1.Count - 1)));
                        array4.Insert(0, array1.RemoveAt((array1.Count - 1)));
                    }
                    array5          = Library.CreateArray(1);
                    array5[0]       = array1[0];
                    array5[1]       = array1[(array1.Count - 2)];
                    curr["Limits"]  = array5;
                    dict1["Nums"]   = array4;
                    array6          = Library.CreateArray(0);
                    array6[0]       = array4[0];
                    array6[1]       = array4[(array4.Count - 2)];
                    dict1["Limits"] = array6;
                    return(dict1);
                }
                return(null);
            }
            if (array2 != null)
            {
                for (num3 = 0; (num3 < array2.Count); num3 += 1)
                {
                    dict2 = (array2[num3] as PDFDict);
                    if (dict2 == null)
                    {
                        throw new InvalidOperationException("Attempt to manipulate invalid name tree");
                    }
                    array7 = (dict2["Limits"] as PDFArray);
                    if (array7.Count != 2)
                    {
                        throw new InvalidOperationException("Attempt to manipulate invalid name tree");
                    }
                    integer2 = (array7[0] as PDFInteger);
                    integer3 = (array7[1] as PDFInteger);
                    if ((integer2 == null) || (integer3 == null))
                    {
                        throw new InvalidOperationException("Attempt to manipulate invalid name tree");
                    }
                    if (((((long)index) < integer2.Value) || (((long)index) < integer3.Value)) || ((num3 + 1) == array2.Count))
                    {
                        dict3 = this.SetItem(dict2, index, value);
                        if (((long)index) < integer2.Value)
                        {
                            array7[0] = PDF.O(index);
                        }
                        if (dict3 != null)
                        {
                            return(this.SplitNode(curr, num3, dict3));
                        }
                        return(null);
                    }
                }
            }
            else
            {
                array1       = Library.CreateArray(2);
                curr["Nums"] = array1;
                array8       = Library.CreateArray(2);
                obj1         = PDF.O(index);
                array1[0]    = obj1;
                obj1         = obj1;
                array8[1]    = obj1;
                array8[0]    = obj1;
                array1[1]    = value;
            }
            return(null);
        }