Exemplo n.º 1
0
        private void SetArraySize(int size)
        {
            PDFArray array1 = (base.Direct as PDFArray);

            while ((size < array1.Count))
            {
                array1.RemoveAt((array1.Count - 1));
            }
            while ((size > array1.Count))
            {
                array1.Add(Library.CreateNull());
            }
        }
Exemplo n.º 2
0
        public static PDFObject CreateObject(bool treatStringAsName, object o)
        {
            if (o == null)
            {
                return(Library.CreateNull());
            }
            Type type1 = o.GetType();

            if (type1.Equals(typeof(double)))
            {
                return(Library.CreateFixed(((double)o)));
            }
            if (type1.Equals(typeof(float)))
            {
                return(Library.CreateFixed(((double)((float)o))));
            }
            if (type1.Equals(typeof(int)))
            {
                return(Library.CreateInteger(((long)((int)o))));
            }
            if (type1.Equals(typeof(uint)))
            {
                return(Library.CreateInteger(((ulong)((uint)o))));
            }
            if (type1.Equals(typeof(string)))
            {
                if (treatStringAsName)
                {
                    return(Library.CreateName(((string)o)));
                }
                return(Library.CreateString(((string)o)));
            }
            if (type1.Equals(typeof(bool)))
            {
                return(Library.CreateBoolean(((bool)o)));
            }
            if (type1.IsArray)
            {
                return(Library.CreateArray(treatStringAsName, o));
            }
            if (type1.GetInterface("System.Collections.IDictionary", false) != null)
            {
                return(Library.CreateDict(treatStringAsName, ((IDictionary)o)));
            }
            if (type1.GetInterface("System.Collections.ICollection", false) != null)
            {
                return(Library.CreateArray(treatStringAsName, o));
            }
            throw new ArgumentException("Invalid item", "o");
        }
Exemplo n.º 3
0
        public static PDFObject DefaultCopyHandler(Document dstDoc, PDFObject src)
        {
            PDFIndirect indirect1;
            PDFStream   stream1;

            if (src == null)
            {
                return(Library.CreateNull());
            }
            if ((src is PDFIndirect))
            {
                indirect1        = dstDoc.Indirects.New();
                indirect1.Direct = ((PDFDirect)Document.DefaultCopyHandler(dstDoc, src.Direct));
                return(indirect1);
            }
            PDFDirect     direct1 = null;
            PDFDirect     direct2 = ((PDFDirect)src);
            PDFObjectType type1   = src.PDFType;

            switch (type1)
            {
            case PDFObjectType.tPDFNull:
            {
                return(Library.CreateNull());
            }

            case PDFObjectType.tPDFInteger:
            {
                return(Library.CreateInteger(((PDFInteger)direct2).Value));
            }

            case PDFObjectType.tPDFFixed:
            {
                return(Library.CreateFixed(((PDFFixed)direct2).Value));
            }

            case PDFObjectType.tPDFBoolean:
            {
                return(Library.CreateBoolean(((PDFBoolean)direct2).Value));
            }

            case PDFObjectType.tPDFName:
            {
                return(Library.CreateName(((PDFName)direct2).Value));
            }

            case PDFObjectType.tPDFString:
            {
                return(Library.CreateString(((PDFString)direct2).Value));
            }

            case PDFObjectType.tPDFDict:
            case PDFObjectType.tPDFArray:
            {
                goto Label_0108;
            }

            case PDFObjectType.tPDFStream:
            {
                stream1 = ((PDFStream)direct2);
                return(Library.CreateStream(stream1.Decrypt(), ((PDFDict)dstDoc.CloneObject(stream1.Dict)), false));
            }
            }
Label_0108:
            return(Library.CreateDirect(src.PDFType));
        }
Exemplo n.º 4
0
        public PDFObject ReadNextObject()
        {
            int       num1;
            PDFArray  array1;
            PDFObject obj1;
            bool      flag1;
            int       num2;
            int       num3;
            int       num4;
            PDFObject obj3;
            PDFObject obj4;
            PDFObject obj5;
            TokenType type1 = base.GetNextToken();

            switch (type1)
            {
            case ((TokenType)0):
            {
                goto Label_00DC;
            }

            case ((TokenType)1):
            {
                if (this.m_sName == "null")
                {
                    return(Library.CreateNull());
                }
                goto Label_009E;
            }

            case ((TokenType)2):
            case ((TokenType)11):
            {
                goto Label_006E;
            }

            case ((TokenType)3):
            {
                goto Label_0230;
            }

            case ((TokenType)4):
            {
                if (this.m_iDictCounter == 0)
                {
                    throw new PDFParserException("Invalid end of dict found!");
                }
                this.m_iDictCounter -= 1;
                return(Library.CreateDict());
            }

            case ((TokenType)5):
            {
                this.m_iArrCounter += 1;
                num1   = this.m_iArrCounter;
                array1 = Library.CreateArray(0);
                flag1  = true;
                do
                {
                    obj1 = this.ReadNextObject();
                    if (num1 != this.m_iArrCounter)
                    {
                        flag1 = false;
                    }
                    else if (obj1.PDFType == PDFObjectType.tPDFName)
                    {
                        num2 = array1.Count;
                        if (((((PDFName)obj1).Value == "R") || (((PDFName)obj1).Value == "r")) && (((num2 >= 2) && (array1[(num2 - 1)].PDFType == PDFObjectType.tPDFInteger)) && (array1[(num2 - 2)].PDFType == PDFObjectType.tPDFInteger)))
                        {
                            num3 = ((PDFInteger)array1[(num2 - 2)]).Int32Value;
                            num4 = ((PDFInteger)array1[(num2 - 1)]).Int32Value;
                            array1.Add(this.m_doc.CreateIndirectObject(num3, num4));
                            array1.RemoveAt((num2 - 1));
                            array1.RemoveAt((num2 - 2));
                        }
                        else
                        {
                            array1.Add(obj1);
                        }
                    }
                    else
                    {
                        array1.Add(obj1);
                    }
                }while (flag1);
                return(array1);
            }

            case ((TokenType)6):
            {
                if (this.m_iArrCounter == 0)
                {
                    throw new PDFParserException("Invalid end of array found!");
                }
                this.m_iArrCounter -= 1;
                return(Library.CreateArray(0));
            }

            case ((TokenType)7):
            {
                goto Label_00E8;
            }

            case ((TokenType)8):
            {
                goto Label_007A;
            }

            case ((TokenType)9):
            {
                goto Label_036E;
            }

            case ((TokenType)10):
            {
                goto Label_0053;
            }

            case ((TokenType)12):
            {
                goto Label_0048;
            }
            }
            goto Label_0379;
Label_0048:
            throw new PDFParserException("Invalid token encountered");
Label_0053:
            if (this.SkipComments)
            {
                return(this.ReadNextObject());
            }
            return(Library.CreateString(this.m_sName));

Label_006E:
            return(Library.CreateString(this.m_sName));

Label_007A:
            return(Library.CreateFixed(this.m_dReal));

Label_009E:
            if (this.m_sName == "false")
            {
                return(Library.CreateBoolean(false));
            }
            if (this.m_sName == "true")
            {
                return(Library.CreateBoolean(true));
            }
            return(Library.CreateName(this.m_sName));

Label_00DC:
            return(Library.CreateName(this.m_sName));

Label_00E8:
            return(Library.CreateInteger(this.m_iInteger));

Label_0230:
            this.m_iDictCounter += 1;
            PDFDict   dict1 = Library.CreateDict();
            bool      flag2 = true;
            PDFObject obj2  = this.ReadNextObject();

Label_0250:
            if (obj2.PDFType == PDFObjectType.tPDFDict)
            {
                flag2 = false;
            }
            else
            {
                if (obj2.PDFType != PDFObjectType.tPDFName)
                {
                    throw new PDFParserException("Invalid key entry found!");
                }
                obj3 = this.ReadNextObject();
                obj4 = this.ReadNextObject();
                if ((obj4.PDFType == PDFObjectType.tPDFInteger) && (obj3.PDFType == PDFObjectType.tPDFInteger))
                {
                    obj5 = this.ReadNextObject();
                    if ((obj5.PDFType == PDFObjectType.tPDFName) && ((((PDFName)obj5).Value == "R") || (((PDFName)obj5).Value == "r")))
                    {
                        dict1[((PDFName)obj2)] = this.m_doc.CreateIndirectObject(((PDFInteger)obj3).Int32Value, ((PDFInteger)obj4).Int32Value);
                        obj2 = this.ReadNextObject();
                        goto Label_033D;
                    }
                    throw new PDFParserException("Invalid dict entry!");
                }
                dict1[((PDFName)obj2)] = obj3;
                obj2 = obj4;
            }
Label_033D:
            if (flag2)
            {
                goto Label_0250;
            }
            return(dict1);

Label_036E:
            throw new PDFParserException("Unexpected end of file found!");
Label_0379:
            throw new PDFParserException("Fatal ERROR!");
        }
Exemplo n.º 5
0
        public static PDFDirect CreateDirect(PDFObjectType type)
        {
            PDFObjectType type1 = type;

            switch (type1)
            {
            case PDFObjectType.tPDFNull:
            {
                goto Label_0060;
            }

            case PDFObjectType.tPDFInteger:
            {
                goto Label_004D;
            }

            case PDFObjectType.tPDFFixed:
            {
                goto Label_003E;
            }

            case PDFObjectType.tPDFBoolean:
            {
                goto Label_0031;
            }

            case PDFObjectType.tPDFName:
            {
                goto Label_0055;
            }

            case PDFObjectType.tPDFString:
            {
                goto Label_0066;
            }

            case PDFObjectType.tPDFDict:
            {
                goto Label_0038;
            }

            case PDFObjectType.tPDFArray:
            {
                goto Label_002A;
            }
            }
            goto Label_0071;
Label_002A:
            return(Library.CreateArray(0));

Label_0031:
            return(Library.CreateBoolean(false));

Label_0038:
            return(Library.CreateDict());

Label_003E:
            return(Library.CreateFixed(0f));

Label_004D:
            return(Library.CreateInteger(((long)0)));

Label_0055:
            return(Library.CreateName(""));

Label_0060:
            return(Library.CreateNull());

Label_0066:
            return(Library.CreateString(""));

Label_0071:
            throw new ArgumentOutOfRangeException("type", type, "Invalid direct type");
        }
Exemplo n.º 6
0
        protected internal virtual PDFDirect CopyHandlerDirect(PDFDirect src, CopyHandlerDelegate ch)
        {
            PDFObject obj1;
            PDFArray  array1;
            PDFArray  array2;
            int       num1;
            PDFDict   dict1;
            PDFDict   dict2;
            PDFStream stream1;
            PDFStream stream2;

            if (ch != null)
            {
                obj1 = ch.Invoke(this.dstDoc, src);
                if ((obj1 is PDFDirect))
                {
                    src = ((PDFDirect)obj1);
                }
                else
                {
                    throw new PDFException("Can\'t convert direct into indirect");
                }
            }
            PDFObjectType type1 = src.PDFType;

            switch (type1)
            {
            case PDFObjectType.tPDFNull:
            {
                goto Label_0155;
            }

            case PDFObjectType.tPDFInteger:
            {
                goto Label_0133;
            }

            case PDFObjectType.tPDFFixed:
            {
                goto Label_0122;
            }

            case PDFObjectType.tPDFBoolean:
            {
                goto Label_00A2;
            }

            case PDFObjectType.tPDFName:
            {
                goto Label_0144;
            }

            case PDFObjectType.tPDFString:
            {
                goto Label_01E7;
            }

            case PDFObjectType.tPDFDict:
            {
                dict1 = (src as PDFDict);
                dict2 = Library.CreateDict();
                foreach (PDFName name1 in dict1.Keys)
                {
                    dict2[name1.Value] = this.CopyHandler(dict1[name1, 0], ch);
                }
                return(dict2);
            }

            case PDFObjectType.tPDFArray:
            {
                array1 = (src as PDFArray);
                array2 = Library.CreateArray(array1.Count);
                num1   = 0;
                goto Label_0097;
            }

            case PDFObjectType.tPDFStream:
            {
                stream1 = (src as PDFStream);
                stream2 = Library.CreateStream();
                foreach (PDFName name2 in stream1.Dict.Keys)
                {
                    stream2.Dict[name2.Value] = this.CopyHandler(stream1.Dict[name2, 0], ch);
                }
                stream2.SetRawStream(stream1.Decrypt());
                return(stream2);
            }
            }
            goto Label_01F8;
Label_007D:
            array2[num1] = this.CopyHandler(array1[num1, 0], ch);
            num1        += 1;
Label_0097:
            if (num1 < array1.Count)
            {
                goto Label_007D;
            }
            return(array2);

Label_00A2:
            return(Library.CreateBoolean((src as PDFBoolean).Value));

Label_0122:
            return(Library.CreateFixed((src as PDFFixed).Value));

Label_0133:
            return(Library.CreateInteger((src as PDFInteger).Value));

Label_0144:
            return(Library.CreateName((src as PDFName).Value));

Label_0155:
            return(Library.CreateNull());

Label_01E7:
            return(Library.CreateString((src as PDFString).Value));

Label_01F8:
            throw new Exception("Invalid object type");
        }