Пример #1
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            //	/CIDInit		/ProcSet findresource begin 12
            //
            //  /CIDSystemInfo
            //		/Registry   A string identifying the issuer of the character collection.
            //					For information about assigning a registry identifier, contact the Adobe
            //					Solutions Network or consult the ASN Web site (see the Bibliography).
            //		/Ordering	A string that uniquely names the character collection within the specified registry.
            //		/Supplement	The supplement number of the character collection. An original character collection
            //					has a supplement number of  0. Whenever additional CIDs are assigned in a character
            //					collection, the supplement number shall be increased. Supplements shall not alter
            //					the ordering of existing CIDs in the character collection. This value shall not be
            //					used in determining compatibility between character collections.
            StringBuilder sb = new StringBuilder();

            sb.Append(@"/CIDInit/ProcSet findresource begin 12 dict begin begincmap/CIDSystemInfo <</Registry (QWERT)/Ordering (ASDFG)/Supplement 0>> def /CMapName /QWERT def/CMapType 2 def 1 begincodespacerange
<00> <FF>
endcodespacerange" + "\n");

            sb.Append(font.hashChar.Count + " beginbfchar\n");
            foreach (int i in font.hashChar)
            {
                sb.Append("<" + font.GetGlyphId(i).ToString("X2") + "> <" + i.ToString("X4") + ">\n");
            }

            sb.Append("endbfchar\nendcmap\nCMapName currentdict /CMap defineresource pop\nend end\n");

            indirectObject.SetChild(new DictionaryObject(sb.ToString()));
        }
Пример #2
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("FontDescriptor") },
                { "StemV", new IntegerObject(font.StemV) },
                { "Flags", new IntegerObject((int)font.Flags) },
                { "FontName", new NameObject(font.Name) },
                { "FontBBox", new ArrayObject(new List <PdfObject> {
                        new IntegerObject(font.boundingBox[0]),
                        new IntegerObject(font.boundingBox[1]),
                        new IntegerObject(font.boundingBox[2]),
                        new IntegerObject(font.boundingBox[3])
                    }) },
                { "ItalicAngle", new IntegerObject(font.ItalicAngle) },
                { "Ascent", new IntegerObject(font.Ascendent) },
                { "Descent", new IntegerObject(font.Descendent) },
                { "CapHeight", new IntegerObject(font.CapHeight) },
            };

            if (font.Leading > 0)
            {
                entries.Add("Leading", new IntegerObject(font.Leading));
            }

            if (font.IsEmbedded)
            {
                var fontContent = new DocumentFontContent(font.FontByteArray);
                entries.Add("FontFile2", fontContent.IndirectReferenceObject(pdfObjects));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #3
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var widths = new List <PdfObject>();

            for (int i = FirstChar; i < LastChar + 1; i++)
            {
                if (!hashChar.Contains(i))
                {
                    widths.Add(new IntegerObject(0));
                }
                else if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var entries = new Dictionary <string, PdfObject> {
                { "Encoding", new NameObject("WinAnsiEncoding") },
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(FirstChar) },
                { "LastChar", new IntegerObject(LastChar) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #4
0
 internal void AddObject(IndirectObject id)
 {
     objects.Add(id);
     if (id.Number > lastNumber)
     {
         lastNumber = id.Number + 1;
     }
 }
Пример #5
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Length", new IntegerObject(font.Length) },
                { "Length1", new IntegerObject(font.Length) }
            };

            indirectObject.SetChild(new DictionaryObject(entries, font));
        }
Пример #6
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var resourceEntries = new Dictionary <string, PdfObject>();

            if (fonts.Count > 0)
            {
                var dicFonts = new Dictionary <string, PdfObject>();

                foreach (var font in fonts)
                {
                    dicFonts.Add(font.Value, font.Key.IndirectReferenceObject(pdfObjects));
                }

                resourceEntries.Add("Font", new DictionaryObject(dicFonts));
            }

            if (images.Count > 0)
            {
                var dicImages = new Dictionary <string, PdfObject>();

                foreach (var img in images)
                {
                    dicImages.Add(img.Value, img.Key.IndirectReferenceObject(pdfObjects));
                }

                resourceEntries.Add("XObject", new DictionaryObject(dicImages));
            }

            if (procsets.Count > 0)
            {
                List <PdfObject> lstObjects = new List <PdfObject>();
                foreach (var procSet in procsets)
                {
                    lstObjects.Add(new NameObject(procSet));
                }
                resourceEntries.Add("ProcSet", new ArrayObject(lstObjects));
            }

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Page") },
                { "Parent", parent.IndirectReferenceObject(pdfObjects) },
                { "Contents", contents.IndirectReferenceObject(pdfObjects) }
            };

            if (resourceEntries.Count > 0)
            {
                entries.Add("Resources", new DictionaryObject(resourceEntries));
            }

            if (MediaBox != null)
            {
                entries.Add("MediaBox", new ArrayObject(MediaBox.ToArrayObject()));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #7
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("Type1") },
                { "BaseFont", new NameObject(this.Name) },
                { "Encoding", new NameObject("WinAnsiEncoding") }
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #8
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var dic = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Catalog") },
                { "Pages", pageTree.IndirectReferenceObject(pdfObjects) }
            };

            if (Outlines != null)
            {
                dic.Add("Outlines", outlines.IndirectReferenceObject(pdfObjects));
            }

            indirectObject.SetChild(new DictionaryObject(dic));
        }
Пример #9
0
        /// <summary>
        /// From an object reference, I want to know the type of this object
        /// For example: 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
        /// It will return "Catalog"
        /// If the obj referenced is not a dictionary, for example
        /// 1 0 obj [ 1 2 3 ] endobj
        /// type will be null
        /// </summary>
        public string GetType(IndirectObject obj)
        {
            var dic = obj.Child <DictionaryObject>(0);

            if (dic == null)
            {
                return(null);
            }
            if (dic.Dictionary.ContainsKey("Type"))
            {
                return(GetObject <NameObject>(dic.Dictionary["Type"]).Value);
            }
            return(null);
        }
Пример #10
0
        internal IndirectObject CreateIndirectObject(Guid guid)
        {
            if (guidToIndirect.ContainsKey(guid))
            {
                return(guidToIndirect[guid]);
            }

            var indirect = new IndirectObject(++lastNumber);

            objects.Add(indirect);
            guidToIndirect.Add(guid, indirect);

            return(indirect);
        }
Пример #11
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("XObject") },
                { "Subtype", new NameObject("Image") },
                { "Length", new IntegerObject(image.Length) },
                { "Width", new IntegerObject(this.Width) },
                { "Height", new IntegerObject(this.Height) },
                { "BitsPerComponent", new IntegerObject(this.BitsPerComponent) },
                { "ColorSpace", (this.Components == 3 ? new NameObject("DeviceRGB") : new NameObject("DeviceGray")) }
            };

            indirectObject.SetChild(new DictionaryObject(entries, image));
        }
Пример #12
0
        /// <summary>
        /// From an indirect object -1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj-,
        /// construct a Document -DocumentCatalog in the example-
        /// </summary>
        public T GetDocument <T>(IndirectObject obj) where T : DocumentTree
        {
            if (cache.ContainsKey(obj))
            {
                return(cache[obj] as T);
            }

            var a = (T)Activator.CreateInstance(typeof(T));

            cache.Add(obj, a);

            a.Load(this, obj.childs[0]);

            return(a);
        }
Пример #13
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject>()
            {
                { "Count", new IntegerObject(Count) }
            };

            if (Parent == null)
            {
                entries.Add("Type", new NameObject("Outlines"));
            }
            if (Parent != null)
            {
                entries.Add("Parent", Parent.IndirectReferenceObject(pdfObjects));
                entries.Add("Dest", new ArrayObject(new List <PdfObject>()
                {
                    Page.IndirectReferenceObject(pdfObjects),
                    new NameObject("XYZ"),
                    GetRealOrNullObject(X),
                    GetRealOrNullObject(Y),
                    GetRealOrNullObject(Zoom)
                }));
            }
            if (First != null)
            {
                entries.Add("First", First.IndirectReferenceObject(pdfObjects));
            }
            if (Last != null)
            {
                entries.Add("Last", Last.IndirectReferenceObject(pdfObjects));
            }
            if (Prev != null)
            {
                entries.Add("Prev", Prev.IndirectReferenceObject(pdfObjects));
            }
            if (Next != null)
            {
                entries.Add("Next", Next.IndirectReferenceObject(pdfObjects));
            }
            if (Title != null)
            {
                entries.Add("Title", new StringObject(Title));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #14
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            List <PdfObject> kids = new List <PdfObject>();

            kids.AddRange(pageTreeSons.Select(p => p.IndirectReferenceObject(pdfObjects)));
            kids.AddRange(pageSons.Select(p => p.IndirectReferenceObject(pdfObjects)));

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Pages") },
                { "Kids", new ArrayObject(kids) },
                { "Count", new IntegerObject(kids.Count) },
            };

            if (MediaBox != null)
            {
                entries.Add("MediaBox", new ArrayObject(MediaBox.ToArrayObject()));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #15
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            // a good guide: http://www.4real.gr/technical-documents-ttf-subset.html
            SubsetTTFFont = Subset(TTFFont);

            File.WriteAllBytes("file.ttf", SubsetTTFFont);

            var widths = new List <PdfObject>();

            widths.Add(new IntegerObject(this.Width));
            foreach (int i in hashChar)
            {
                if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var descriptor = new DocumentTtfDescriptorFont(this);
            var cmap       = new DocumentCmapFont(this);

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(0) },
                { "LastChar", new IntegerObject(hashChar.Count) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
                { "ToUnicode", cmap.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Пример #16
0
 internal T GetObject <T>(IndirectObject obj) where T : PdfObject
 => obj.childs[0] as T;
Пример #17
0
 public virtual void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects) { }
Пример #18
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            string text = string.Join(" ", pageOperators);

            indirectObject.SetChild(new DictionaryObject(text));
        }