public static XObjectImage Create(Document doc, Bitmap img, params string[] encoding) { int num3; int num4; int num5; Color color1; int num6; PDFArray array1; int num7; int num8; PDFStream stream1 = Library.CreateStream(); PDFDict dict1 = stream1.Dict; dict1["Width"] = PDF.O(img.Width); dict1["Height"] = PDF.O(img.Height); dict1["Subtype"] = PDF.N("Image"); dict1["Type"] = PDF.N("XObject"); byte[] numArray1 = null; BitArrayAccessor accessor1 = null; int num1 = 0; int num2 = 0; if (doc == null) { doc = Library.Resources.Doc; } XObjectImage image1 = ((XObjectImage)doc.Resources[doc.Indirects.New(stream1), typeof(XObjectImage)]); image1.ColorSpace = ColorSpaceDeviceRGB.Create(); numArray1 = new byte[((3 * img.Width) * img.Height)]; num1 = 8; num2 = (3 * img.Width); dict1["BitsPerComponent"] = PDF.O(8); for (num3 = 0; (num3 < img.Height); num3 += 1) { num4 = 0; accessor1 = new BitArrayAccessor(numArray1, ((num3 * num2) * 8), num1, false); for (num5 = 0; (num5 < img.Width); num5 += 1) { color1 = img.GetPixel(num5, num3); num6 = 0; while ((num6 < 3)) { num8 = num6; switch (num8) { case 0: { int num9 = num4; num4 = (num9 + 1); accessor1[num4] = ((long)((ulong)color1.R)); goto Label_0180; } case 1: { int num10 = num4; num4 = (num10 + 1); accessor1[num4] = ((long)((ulong)color1.G)); goto Label_0180; } case 2: { goto Label_016B; } } goto Label_0180; Label_016B: int num11 = num4; num4 = (num11 + 1); accessor1[num4] = ((long)((ulong)color1.B)); Label_0180: num6 += 1; } } } MemoryStream stream2 = new MemoryStream(numArray1); if (encoding.Length > 0) { array1 = Library.CreateArray(encoding.Length); stream1.Dict["Filter"] = array1; for (num7 = 0; (num7 < encoding.Length); num7 += 1) { array1[num7] = PDF.N(encoding[num7]); } } stream1.Encode(stream2); return(image1); }
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!"); }
// Methods public ObjectCollection(PDFDirect direct) : base(direct, false) { this.mArr = Library.CreateArray(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)); }
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); }
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"); }
public static PDFArray CreateArray() { return(Library.CreateArray(0)); }
public static AnnotationWidgetCollection Create() { return(new AnnotationWidgetCollection(Library.CreateArray(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"); }