Exemplo n.º 1
0
 public static FieldRadioButton Create(PDFDict dict, string partial_name)
 {
     dict["FT"] = Library.CreateName("Btn");
     dict["Ff"] = Library.CreateInteger(((long)32768));
     dict["T"]  = Library.CreateString(partial_name);
     return(new FieldRadioButton(dict));
 }
Exemplo n.º 2
0
        public static LinkDestinationExplicit Create(int page_number)
        {
            PDFArray array1 = Library.CreateArray(2);

            array1[0] = Library.CreateInteger(((long)page_number));
            array1[1] = Library.CreateName("Fit");
            return(Resources.Get(array1, typeof(LinkDestinationExplicit)) as LinkDestinationExplicit);
        }
Exemplo n.º 3
0
        public static FieldRadioButton Create()
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["FT"] = Library.CreateName("Btn");
            dict1["Ff"] = Library.CreateInteger(((long)32768));
            Library.CreateIndirect(dict1);
            return(new FieldRadioButton(dict1));
        }
Exemplo n.º 4
0
        public static FieldText Create()
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["FT"] = Library.CreateName("Tx");
            dict1["Ff"] = Library.CreateInteger(((long)4096));
            Library.CreateIndirect(dict1);
            return(new FieldText(dict1));
        }
Exemplo n.º 5
0
        public static PatternShading Create(Shading sh)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["Type"]        = Library.CreateName("Pattern");
            dict1["PatternType"] = Library.CreateInteger(((long)2));
            dict1["Shading"]     = sh.Direct;
            return(new PatternShading(dict1));
        }
Exemplo n.º 6
0
        public static ShadingType1 Create(ColorSpace cs, Function fn)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["Type"]        = Library.CreateName("Shading");
            dict1["ShadingType"] = Library.CreateInteger(((long)1));
            dict1["ColorSpace"]  = cs.Direct;
            dict1["Function"]    = fn.Direct;
            return(new ShadingType1(dict1));
        }
Exemplo n.º 7
0
        public static MinBitDepth Create(bool indirect, int depth)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["V"] = Library.CreateInteger(((long)depth));
            if (indirect)
            {
                Library.CreateIndirect(dict1);
            }
            return(new MinBitDepth(dict1));
        }
Exemplo n.º 8
0
        public static MediaOffsetFrame Create(bool indirect, int framenum)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["F"] = Library.CreateInteger(((long)framenum));
            if (indirect)
            {
                Library.CreateIndirect(dict1);
            }
            return(new MediaOffsetFrame(dict1));
        }
Exemplo n.º 9
0
        public static FunctionType2 Create(double[] domain, double[] c0, double[] c1, double n)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["FunctionType"] = Library.CreateInteger(((long)2));
            dict1["Domain"]       = Library.CreateArray(false, domain);
            dict1["C0"]           = Library.CreateArray(false, c0);
            dict1["C1"]           = Library.CreateArray(false, c1);
            dict1["N"]            = Library.CreateFixed(n);
            return(new FunctionType2(dict1));
        }
Exemplo n.º 10
0
        public static FunctionType4 Create(double[] domain, double[] range, string expression)
        {
            byte[]    numArray1 = Encoding.ASCII.GetBytes(expression);
            PDFStream stream1   = Library.CreateStream(numArray1, 0, numArray1.Length, false, null);
            PDFDict   dict1     = stream1.Dict;

            dict1["FunctionType"] = Library.CreateInteger(((long)4));
            dict1["Domain"]       = Library.CreateArray(false, domain);
            dict1["Range"]        = Library.CreateArray(false, range);
            return(new FunctionType4(stream1));
        }
Exemplo n.º 11
0
        public static IndexList Create(int[] list)
        {
            int      num1;
            PDFArray array1 = Library.CreateArray(0);

            for (num1 = 0; (num1 < list.Length); num1 += 1)
            {
                array1.Add(Library.CreateInteger(((long)list[num1])));
            }
            return(new IndexList(array1));
        }
Exemplo n.º 12
0
 // Properties
 public int this[int index]
 {
     get
     {
         return((base._GetObject(index) as PDFInteger).Int32Value);
     }
     set
     {
         PDFInteger integer1 = Library.CreateInteger(((long)value));
         base._SetObject(index, integer1, integer1.Direct);
     }
 }
Exemplo n.º 13
0
        public static MinScreenSize Create(bool indirect, int width, int height)
        {
            PDFDict  dict1  = Library.CreateDict();
            PDFArray array1 = Library.CreateArray(2);

            array1[0]  = Library.CreateInteger(((long)width));
            array1[1]  = Library.CreateInteger(((long)height));
            dict1["V"] = array1;
            if (indirect)
            {
                Library.CreateIndirect(dict1);
            }
            return(new MinScreenSize(dict1));
        }
Exemplo n.º 14
0
        public static ColorSpaceICCBased Create(Document doc, bool indirect, Stream profile, params string[] encoding)
        {
            PDFArray array2;
            int      num2;
            PDFArray array1 = Library.CreateArray(2);

            array1[0] = PDF.N("ICCBased");
            PDFStream stream1 = Library.CreateStream();

            byte[] numArray1 = new byte[30];
            profile.Position = ((long)0);
            int num1 = profile.Read(numArray1, 0, 30);

            if (num1 == 0)
            {
                throw new Exception("Empty ICC profile");
            }
            string text1 = Utils.BytesToString(numArray1);

            if (text1.IndexOf("GRAY") != -1)
            {
                stream1.Dict["N"] = Library.CreateInteger(((long)1));
            }
            if (text1.IndexOf("RGB") != -1)
            {
                stream1.Dict["N"] = Library.CreateInteger(((long)3));
            }
            if (text1.IndexOf("CMYK") != -1)
            {
                stream1.Dict["N"] = Library.CreateInteger(((long)4));
            }
            if ((encoding != null) && (encoding.Length > 0))
            {
                array2 = Library.CreateArray(encoding.Length);
                stream1.Dict["Filter"] = array2;
                for (num2 = 0; (num2 < encoding.Length); num2 += 1)
                {
                    array2[num2] = PDF.N(encoding[num2]);
                }
            }
            stream1.Encode(profile);
            array1[1] = doc.Indirects.New(stream1);
            ColorSpaceICCBased based1 = (Resources.Get(array1, typeof(ColorSpaceICCBased)) as ColorSpaceICCBased);

            if (indirect)
            {
                doc.Indirects.New(array1);
            }
            return(based1);
        }
Exemplo n.º 15
0
        public static FloatingWindowParams Create(bool indirect, int width, int height)
        {
            PDFDict  dict1  = Library.CreateDict();
            PDFArray array1 = Library.CreateArray(2);

            array1[0]  = Library.CreateInteger(((long)width));
            array1[1]  = Library.CreateInteger(((long)height));
            dict1["D"] = array1;
            if (indirect)
            {
                Library.CreateIndirect(dict1);
            }
            return(new FloatingWindowParams(dict1));
        }
Exemplo n.º 16
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.º 17
0
        public void Add(int value)
        {
            int num1;

            if (this.Count == 0)
            {
                this.mArr.Add(Library.CreateInteger(((long)value)));
                return;
            }
            for (num1 = 0; (num1 < this.Count); num1 += 1)
            {
                if (value < (this.mArr[num1] as PDFInteger).Int32Value)
                {
                    this.mArr.Insert(num1, Library.CreateInteger(((long)value)));
                }
            }
        }
Exemplo n.º 18
0
        internal static PDFIndirect New(Document doc)
        {
            int         num1;
            PDFIndirect indirect1 = doc.Indirects.New();
            PDFDict     dict1     = Library.CreateDict();

            indirect1.Direct   = dict1;
            dict1["Type"]      = Library.CreateName("Page");
            dict1["Resources"] = Library.CreateDict();
            PDFArray array1 = Library.CreateArray(4);

            for (num1 = 0; (num1 < 4); num1 += 1)
            {
                array1[num1] = Library.CreateInteger(((long)0));
            }
            dict1["MediaBox"] = array1;
            return(indirect1);
        }
Exemplo n.º 19
0
        public void AddLinkAnnotation(double left, double bottom, double right, double top, PDFObject uri_action)
        {
            PDFDict dict1 = Library.CreateDict();

            dict1["Type"]    = Library.CreateName("Annot");
            dict1["Subtype"] = Library.CreateName("Link");
            PDFDict dict2 = Library.CreateDict();

            dict2["W"]  = Library.CreateInteger(((long)0));
            dict1["BS"] = dict2;
            PDFArray array1 = Library.CreateArray(0);

            array1.Add(Library.CreateFixed(0f));
            array1.Add(Library.CreateFixed(0f));
            array1.Add(Library.CreateFixed(0f));
            dict1["Border"] = array1;
            PDFArray array2 = Library.CreateArray(0);

            array2.Add(Library.CreateFixed(left));
            array2.Add(Library.CreateFixed(bottom));
            array2.Add(Library.CreateFixed(right));
            array2.Add(Library.CreateFixed(top));
            dict1["Rect"] = array2;
            if (uri_action != null)
            {
                dict1["A"] = uri_action;
            }
            Document    document1 = this.mPage.Dict.Doc;
            PDFIndirect indirect1 = document1.Indirects.New(dict1);
            PDFArray    array3    = null;
            PDFObject   obj1      = this.mPage.Dict["Annots"];

            if ((obj1 != null) && (obj1.PDFType == PDFObjectType.tPDFArray))
            {
                array3 = ((PDFArray)obj1.Direct);
            }
            else
            {
                array3 = Library.CreateArray(0);
                this.mPage.Dict["Annots"] = array3;
            }
            array3.Add(indirect1);
        }
Exemplo n.º 20
0
 // Properties
 public override long this[int index]
 {
     get
     {
         return(this.mArr[index]);
     }
     set
     {
         int        num1;
         PDFArray   array1;
         PDFInteger integer1;
         base[index] = value;
         if (this.mAsFixed)
         {
             if (this.mPDFArr == null)
             {
                 array1       = Library.CreateArray(this.mArr.Length);
                 this.mPDFArr = array1;
                 this.mParent[this.mKeyName] = array1;
                 for (num1 = 0; (num1 < this.mArr.Length); num1 += 1)
                 {
                     this.mPDFArr[num1] = Library.CreateFixed(((double)this.mArr[num1]));
                 }
                 return;
             }
             ((PDFInteger)this.mPDFArr[index]).Value = value;
             return;
         }
         if (index > 0)
         {
             throw new IndexOutOfRangeException();
         }
         if (this.mPDFFix == null)
         {
             integer1     = Library.CreateInteger(value);
             this.mPDFFix = integer1;
             this.mParent[this.mKeyName] = integer1;
             return;
         }
         this.mPDFFix.Value = value;
     }
 }
Exemplo n.º 21
0
        public void Add(OutlineItem item)
        {
            PDFObject obj1;

            if (base.Direct == null)
            {
                obj1 = Library.CreateDict();
                this.mParentDict["Outlines"] = obj1;
                this.mDirect = (obj1 as PDFDirect);
            }
            PDFDict dict1 = item.Dict;
            PDFDict dict2 = (this.Dict["Last"] as PDFDict);

            if (dict2 != null)
            {
                dict2["Next"] = dict1;
                dict1["Prev"] = dict2;
                dict1.Remove("Next");
                this.Dict["Last"] = dict1;
            }
            else
            {
                obj1 = item.Direct;
                this.Dict["Last"]  = obj1;
                this.Dict["First"] = obj1;
                dict1.Remove("Prev");
                dict1.Remove("Next");
            }
            PDFInteger integer1 = (this.Dict["Count"] as PDFInteger);

            if (integer1 == null)
            {
                integer1           = Library.CreateInteger(((long)1));
                this.Dict["Count"] = integer1;
            }
            else
            {
                integer1.Value += ((long)1);
            }
            dict1["Parent"] = this.Dict;
        }
Exemplo n.º 22
0
        public bool EmbedFontFile(Stream fontStream)
        {
            PDFArray array1;
            PDFDict  dict1;
            PDFDict  dict2;

            Altsoft.FTMB.Font font1 = Altsoft.FTMB.Font.OpenFont(fontStream);
            if ((font1 == null) || !font1.GetType().Equals(typeof(TrueTypeFont)))
            {
                return(false);
            }
            if (((font1.EmbeddingRights & 782) == 0) || ((font1.EmbeddingRights & 8) != 0))
            {
                array1 = (this.Dict["DescendantFonts"] as PDFArray);
                if (array1 == null)
                {
                    return(false);
                }
                dict1 = (array1[0] as PDFDict);
                if (dict1 == null)
                {
                    return(false);
                }
                dict1 = (dict1["FontDescriptor"] as PDFDict);
                if (dict1 == null)
                {
                    return(false);
                }
                font1.FontStream.Position = ((long)0);
                dict2              = Library.CreateDict();
                dict2["Filter"]    = Library.CreateName("FlateDecode");
                dict2["Length1"]   = Library.CreateInteger(font1.FontStream.Length);
                dict1["FontFile2"] = base.Direct.Doc.Indirects.New(Library.CreateStream(font1.FontStream, dict2));
                return(true);
            }
            return(false);
        }
Exemplo n.º 23
0
 public static FieldText Create(PDFDict dict)
 {
     dict["FT"] = Library.CreateName("Tx");
     dict["Ff"] = Library.CreateInteger(((long)4096));
     return(new FieldText(dict));
 }
Exemplo n.º 24
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.º 25
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.º 26
0
        public Page Insert(int nr, PDFObject page)
        {
            PDFDict     dict1;
            PDFArray    array1;
            int         num1;
            PDFDict     dict2;
            PDFDict     dict3;
            PDFDict     dict4;
            PDFIndirect indirect1;
            PDFArray    array2;
            int         num2;
            int         num3;
            PDFDict     dict5;
            int         num4;
            PDFDict     dict6;
            PDFArray    array3;
            PDFDict     dict7;
            PDFArray    array4;
            int         num5;
            Page        page1;
            Page        page2;
            PDFDict     dict8;
            PDFObject   obj1;

            try
            {
                if (nr > this.Count)
                {
                    throw new ArgumentOutOfRangeException("nr", nr, "New page number should be less or equal to page count");
                }
                if (this.mPagesDict == null)
                {
                    dict8                   = Library.CreateDict();
                    this.mPagesDict         = dict8;
                    this.mDoc.Root["Pages"] = Library.CreateIndirect(dict8);
                }
                dict1  = null;
                array1 = null;
                num1   = 0;
                if (this.Count == 0)
                {
                    dict1  = this.mPagesDict;
                    array1 = ((PDFArray)dict1["Kids"]);
                    if (array1 == null)
                    {
                        obj1          = Library.CreateArray(0);
                        dict1["Kids"] = obj1;
                        array1        = ((PDFArray)obj1);
                    }
                    dict1["Count"] = PDF.O(0);
                }
                else
                {
                    dict2  = this[((nr > 0) ? (nr - 1) : 0)].Dict;
                    dict1  = ((PDFDict)dict2["Parent"]);
                    array1 = ((PDFArray)dict1["Kids"]);
                    if (nr > 0)
                    {
                        num1 = 0;
                        while ((num1 < array1.Count))
                        {
                            if (array1[num1].Indirect.Id == dict2.Indirect.Id)
                            {
                                break;
                            }
                            num1 += 1;
                        }
                        if (num1 == array1.Count)
                        {
                            throw new PDFException(string.Format("Invalid page tree - invalid parent pointer in page {0}", nr));
                        }
                        num1 += 1;
                    }
                    else
                    {
                        num1 = 0;
                    }
                }
                array1.Insert(num1, page);
                ((PDFDict)page.Direct)["Parent"] = dict1.Indirect;
                for (dict3 = dict1; (dict3 != null); dict3 = ((PDFDict)dict3["Parent"]))
                {
                    PDFInteger integer1 = ((PDFInteger)dict3["Count"]);
                    ((PDFInteger)dict3["Count"]).Value = (integer1.Value + ((long)1));
                }
                while ((array1.Count > PagesCollection.MaxKids))
                {
                    dict4         = Library.CreateDict();
                    indirect1     = this.mDoc.Indirects.New(dict4);
                    dict4["Type"] = Library.CreateName("Pages");
                    obj1          = Library.CreateArray(0);
                    dict4["Kids"] = obj1;
                    array2        = ((PDFArray)obj1);
                    num2          = ((PDFNumeric)dict1["Count"]).Int32Value;
                    num3          = 0;
                    while ((array1.Count > (PagesCollection.MaxKids / 2)))
                    {
                        dict5 = ((PDFDict)array1[(PagesCollection.MaxKids / 2)]);
                        array1.RemoveAt((PagesCollection.MaxKids / 2));
                        dict5["Parent"] = dict4.Indirect;
                        num4            = 0;
                        if (((PDFName)dict5["Type"]).Value.Equals("Pages"))
                        {
                            num4 = ((PDFNumeric)dict5["Count"]).Int32Value;
                        }
                        else
                        {
                            num4 = 1;
                        }
                        num2 -= num4;
                        num3 += num4;
                        array2.Add(dict5.Indirect);
                    }
                    ((PDFInteger)dict1["Count"]).Value = ((long)num2);
                    dict4["Count"] = Library.CreateInteger(((long)num3));
                    if (dict1["Parent"] == null)
                    {
                        dict6 = Library.CreateDict();
                        this.mDoc.Indirects.New(dict6);
                        dict6["Type"]  = Library.CreateName("Pages");
                        dict6["Count"] = Library.CreateInteger(((long)(num3 + num2)));
                        obj1           = Library.CreateArray(0);
                        dict6["Kids"]  = obj1;
                        array3         = ((PDFArray)obj1);
                        array3.Add(dict1.Indirect);
                        array3.Add(dict4.Indirect);
                        dict1["Parent"]         = dict6.Indirect;
                        dict4["Parent"]         = dict6.Indirect;
                        this.mDoc.Root["Pages"] = dict6.Indirect;
                        dict1 = dict6;
                    }
                    else
                    {
                        dict4["Parent"] = dict1["Parent"].Indirect;
                        dict7           = ((PDFDict)dict1["Parent"]);
                        array4          = ((PDFArray)dict7["Kids"]);
                        num5            = 0;
                        while ((num5 < array4.Count))
                        {
                            if (array4[num5].Indirect.Id == dict1.Indirect.Id)
                            {
                                break;
                            }
                            num5 += 1;
                        }
                        if (num5 == array4.Count)
                        {
                            throw new PDFException("Invalid page tree - invalid parent pointer");
                        }
                        array4.Insert((num5 + 1), indirect1);
                        dict1 = dict7;
                    }
                    array1 = ((PDFArray)dict1["Kids"]);
                }
                page1 = (Resources.Get(page, typeof(Page)) as Page);
                this.mPagesColl.Insert(nr, page);
                return(page1);
            }
            catch (InvalidCastException)
            {
                throw new PDFSyntaxException("Invalid PDF page tree");
            }
            return(page2);
        }
Exemplo n.º 27
0
        public static Altsoft.PDFO.Font EmbedFont(Document doc, Stream fontstream, string encoding, bool embedFontFile, bool isVertical)
        {
            int      num2;
            PDFArray array2;
            int      num10;

            Altsoft.FTMB.Font font1 = Altsoft.FTMB.Font.OpenFont(fontstream);
            if ((font1.FontType != FontType.TrueTypeFontT) || (encoding != "Unicode"))
            {
                return(null);
            }
            TrueTypeFont font2 = (font1 as TrueTypeFont);
            double       num1  = ((double)font2.UnitsPerEm);
            PDFDict      dict1 = Library.CreateDict();

            dict1["Type"]     = Library.CreateName("Font");
            dict1["Subtype"]  = Library.CreateName("CIDFontType2");
            dict1["BaseFont"] = Library.CreateName(font2.FontName);
            PDFDict dict2 = Library.CreateDict();

            dict2["Registry"]      = Library.CreateString("Adobe");
            dict2["Ordering"]      = Library.CreateString("Identity");
            dict2["Supplement"]    = Library.CreateInteger(((long)0));
            dict1["CIDSystemInfo"] = dict2;
            TTEncoding encoding1 = null;

            for (num2 = 0; ((num2 < font2.Encodings.Count) && (encoding1 == null)); num2 += 1)
            {
                encoding1 = ((TTEncoding)font2.Encodings[num2]);
                if ((encoding1.platformID != 3) || ((encoding1.specificID != 1) && (encoding1.specificID != 0)))
                {
                    encoding1 = null;
                }
            }
            if (encoding1 == null)
            {
                return(null);
            }
            dict1["DW"] = Library.CreateInteger(((long)((((double)font2.GetWidth(encoding1.GetGID(0))) * 1000f) / num1)));
            int      num3   = 0;
            int      num4   = encoding1.GetLastCharCode(ref num3);
            int      num5   = encoding1.GetFirstCharCode(ref num3);
            PDFArray array1 = Library.CreateArray(0);

            if (num5 != 0)
            {
                array1.Add(Library.CreateInteger(((long)0)));
                array2 = Library.CreateArray(0);
                array2.Add(Library.CreateInteger(((long)((((double)font2.GetWidth(0, 3, 1)) * 1000f) / num1))));
                array1.Add(array2);
            }
            array1.Add(Library.CreateInteger(((long)num5)));
            array2 = Library.CreateArray(0);
            array2.Add(Library.CreateInteger(((long)((((double)font2.GetWidth(num3)) * 1000f) / num1))));
            int num6 = num5;

            while ((num5 != num4))
            {
                num5 = encoding1.GetNextCharCode(num5, ref num3);
                if (num5 != (num6 + 1))
                {
                    array1.Add(array2);
                    array1.Add(Library.CreateInteger(((long)num5)));
                    array2 = Library.CreateArray(0);
                }
                num6 = num5;
                array2.Add(Library.CreateInteger(((long)((((double)font2.GetWidth(num3)) * 1000f) / num1))));
            }
            array1.Add(array2);
            dict1["W"] = array1;
            Stream stream1 = new MemoryStream();
            int    num7    = encoding1.GetFirstCharCode(ref num3);
            int    num8    = 0;

            while ((num8 < num7))
            {
                stream1.WriteByte(0);
                stream1.WriteByte(0);
                num8 += 1;
            }
            stream1.WriteByte(((byte)(num3 / 256)));
            stream1.WriteByte(((byte)(num3 % 256)));
            num8 += 1;
            int num9 = encoding1.GetLastCharCode(ref num3);

            do
            {
                num7 = encoding1.GetNextCharCode(num7, ref num3);
                while ((num8 < num7))
                {
                    stream1.WriteByte(0);
                    stream1.WriteByte(0);
                    num8 += 1;
                }
                stream1.WriteByte(((byte)(num3 / 256)));
                stream1.WriteByte(((byte)(num3 % 256)));
                num8 += 1;
            }while ((num7 != num9));
            stream1.Position = ((long)0);
            PDFDict dict3 = Library.CreateDict();

            dict3["Filter"] = Library.CreateName("FlateDecode");
            PDFStream stream2 = Library.CreateStream(stream1, dict3);

            dict1["CIDToGIDMap"] = doc.Indirects.New(stream2);
            PDFDict dict4 = Library.CreateDict();

            dict4["Type"]     = Library.CreateName("FontDescriptor");
            dict4["FontName"] = Library.CreateName(font2.FontName);
            dict4["Flags"]    = Library.CreateInteger(((long)4));
            PDFArray array3 = Library.CreateArray(4);

            for (num10 = 0; (num10 < 4); num10 += 1)
            {
                array3[num10] = Library.CreateInteger(((long)font2.FontBBox[num10]));
            }
            dict4["FontBBox"]    = array3;
            dict4["ItalicAngle"] = Library.CreateFixed(font2.ItalicAngle);
            dict4["Ascent"]      = Library.CreateInteger(((long)font2.FontBBox[3]));
            dict4["Descent"]     = Library.CreateInteger(((long)font2.FontBBox[1]));
            dict4["CapHeight"]   = Library.CreateInteger(((long)font2.FontBBox[3]));
            dict4["StemV"]       = Library.CreateInteger(((long)0));
            if (((font2.EmbeddingRights == 0) || ((font2.EmbeddingRights & 8) != 0)) && embedFontFile)
            {
                font2.FontStream.Position = ((long)0);
                dict3              = Library.CreateDict();
                dict3["Filter"]    = Library.CreateName("FlateDecode");
                dict3["Length1"]   = Library.CreateInteger(font2.FontStream.Length);
                dict4["FontFile2"] = doc.Indirects.New(Library.CreateStream(font2.FontStream, dict3));
            }
            dict1["FontDescriptor"] = doc.Indirects.New(dict4);
            PDFDict dict5 = Library.CreateDict();

            dict5["Type"]     = Library.CreateName("Font");
            dict5["Subtype"]  = Library.CreateName("Type0");
            dict5["BaseFont"] = Library.CreateName(font2.FontName);
            if (!isVertical)
            {
                dict5["Encoding"] = Library.CreateName("Identity-H");
            }
            else
            {
                dict5["Encoding"] = Library.CreateName("Identity-V");
            }
            PDFArray array4 = Library.CreateArray(1);

            array4[0] = doc.Indirects.New(dict1);
            dict5["DescendantFonts"] = array4;
            return(new FontType0(dict5));
        }
Exemplo n.º 28
0
 public static FieldChoice Create(PDFDict dict)
 {
     dict["FT"] = Library.CreateName("Ch");
     dict["Ff"] = Library.CreateInteger(((long)262144));
     return(new FieldChoice(dict));
 }
Exemplo n.º 29
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.º 30
0
        public void Insert(int index, OutlineItem item)
        {
            PDFDict    dict2;
            PDFInteger integer1;
            PDFDict    dict3;
            PDFInteger integer2;
            PDFObject  obj1;

            if (base.Direct == null)
            {
                obj1 = Library.CreateDict();
                this.mParentDict["Outlines"] = obj1;
                this.mDirect = (obj1 as PDFDirect);
            }
            PDFDict dict1 = item.Dict;

            if (index == 0)
            {
                dict2 = (this.Dict["First"] as PDFDict);
                if (dict2 != null)
                {
                    dict2["Prev"] = dict1;
                    dict1["Next"] = dict2;
                    dict1.Remove("Prev");
                    this.Dict["First"] = dict1;
                }
                else
                {
                    obj1 = item.Direct;
                    this.Dict["Last"]  = obj1;
                    this.Dict["First"] = obj1;
                    dict1.Remove("Prev");
                    dict1.Remove("Next");
                }
                integer1 = (this.Dict["Count"] as PDFInteger);
                if (integer1 == null)
                {
                    integer1           = Library.CreateInteger(((long)1));
                    this.Dict["Count"] = integer1;
                }
                else
                {
                    integer1.Value += ((long)1);
                }
            }
            else if (index == this.Count)
            {
                this.Add(item);
            }
            else
            {
                dict3 = this.At(index);
                if (dict3 == null)
                {
                    throw new IndexOutOfRangeException("OutlineItem index out of range");
                }
                dict1["Prev"] = dict3["Prev"];
                dict1["Next"] = dict3;
                (dict3["Prev"] as PDFDict)["Next"] = dict1;
                integer2 = (this.Dict["Count"] as PDFInteger);
                if (integer2 == null)
                {
                    integer2           = Library.CreateInteger(((long)1));
                    this.Dict["Count"] = integer2;
                }
                else
                {
                    integer2.Value += ((long)1);
                }
            }
            dict1["Parent"] = this.Dict;
        }