Example #1
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "R", "BC", "BG", "CA", "RC", "AC", "TP", "IF" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    result.AddItem(keys[i], obj.Clone());
                }
            }

            string[] xObjects = { "I", "RI", "IX" };
            for (int i = 0; i < xObjects.Length; ++i)
            {
                PDFDictionaryStream stream = dict[xObjects[i]] as PDFDictionaryStream;
                if (stream != null)
                {
                    result.AddItem(xObjects[i], GraphicsTemplate.Copy(stream));
                }
            }

            return(result);
        }
Example #2
0
        private static PDFDictionary copyAppearance(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "N", "R", "D" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj is PDFDictionaryStream)
                {
                    result.AddItem(keys[i], GraphicsTemplate.Copy(obj as PDFDictionaryStream));
                }
                else if (obj is PDFDictionary)
                {
                    PDFDictionary newDict = new PDFDictionary();
                    string[]      keys2   = (obj as PDFDictionary).GetKeys();
                    for (int j = 0; j < keys2.Length; ++j)
                    {
                        PDFDictionaryStream ds = (obj as PDFDictionary)[keys2[j]] as PDFDictionaryStream;
                        if (ds != null)
                        {
                            newDict.AddItem(keys2[j], GraphicsTemplate.Copy(ds));
                        }
                    }

                    result.AddItem(keys[i], newDict);
                }
            }

            return(result);
        }
Example #3
0
        public PDFExponentialFunction()
        {
            m_stream = new PDFDictionaryStream();
            PDFDictionary dict  = m_stream.Dictionary;
            PDFArray      array = new PDFArray();

            m_domain    = new float[2];
            m_domain[0] = 0.0f;
            m_domain[1] = 1.0f;

            m_range = new float[0];

            m_c0    = new float[1];
            m_c0[0] = 0.0f;

            m_c1    = new float[1];
            m_c1[0] = 1.0f;

            m_n = 2.0f;

            dict.AddItem("FunctionType", new PDFNumber((float)PDFFunctionType.Exponential));
            for (int i = 0; i < m_domain.Length; ++i)
            {
                array.AddItem(new PDFNumber(m_domain[i]));
            }
            dict.AddItem("Domain", array);
            array = new PDFArray();
            for (int i = 0; i < m_range.Length; ++i)
            {
                array.AddItem(new PDFNumber(m_range[i]));
            }
            if (array.Count != 0)
            {
                dict.AddItem("Range", array);
            }
            array = new PDFArray();
            for (int i = 0; i < m_c0.Length; ++i)
            {
                array.AddItem(new PDFNumber(m_c0[i]));
            }
            dict.AddItem("C0", array);
            array = new PDFArray();
            for (int i = 0; i < m_c1.Length; ++i)
            {
                array.AddItem(new PDFNumber(m_c1[i]));
            }
            dict.AddItem("C1", array);
            dict.AddItem("N", new PDFNumber(m_n));
        }
Example #4
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary newDict = new PDFDictionary();

            newDict.AddItem("Type", new PDFName("Page"));

            string[] keys = { "LastModified", "Rotate", "Dur", "Metadata", "ID", "PZ", "Tabs", "UserUnit" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    newDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary resources = dict["Resources"] as PDFDictionary;

            if (resources != null)
            {
                newDict.AddItem("Resources", ResourcesBase.Copy(resources));
            }

            string[] boxes = { "MediaBox", "CropBox", "BleedBox", "TrimBox", "ArtBox" };
            for (int i = 0; i < boxes.Length; ++i)
            {
                PDFArray bbox = dict[boxes[i]] as PDFArray;
                if (bbox != null)
                {
                    PDFArray newBbox = new PDFArray();
                    for (int j = 0; j < bbox.Count; ++j)
                    {
                        PDFNumber num = bbox[j] as PDFNumber;
                        newBbox.AddItem(num.Clone());
                    }
                    newDict.AddItem(boxes[i], newBbox);
                }
            }

            PDFDictionary boxColorInfo = dict["BoxColorInfo"] as PDFDictionary;

            if (boxColorInfo != null)
            {
                newDict.AddItem("BoxColorInfo", BoxColorInfoBase.Copy(boxColorInfo));
            }

            IPDFObject contents = dict["Contents"];

            if (contents != null)
            {
                IPDFObject newContents = null;
                if (contents is PDFDictionaryStream)
                {
                    newContents = contents.Clone();
                }
                else if (contents is PDFArray)
                {
                    newContents = new PDFArray();
                    for (int i = 0; i < (contents as PDFArray).Count; ++i)
                    {
                        PDFDictionaryStream contentsItem = (contents as PDFArray)[i] as PDFDictionaryStream;
                        if (contentsItem != null)
                        {
                            (newContents as PDFArray).AddItem(contentsItem.Clone());
                        }
                    }
                }
                newDict.AddItem("Contents", newContents);
            }

            PDFDictionary group = dict["Group"] as PDFDictionary;

            if (group != null)
            {
                newDict.AddItem("Group", GroupBase.Copy(group));
            }

            PDFDictionaryStream thumb = dict["Thumb"] as PDFDictionaryStream;

            if (thumb != null)
            {
                newDict.AddItem("Thumb", thumb);
            }

            PDFDictionary trans = dict["Trans"] as PDFDictionary;

            if (trans != null)
            {
                newDict.AddItem("Trans", TransitionBase.Copy(trans));
            }

            // Parent, B, StructParents - do not
            // Annots, AA - need set after adding page
            // PieceInfo, SeparationInfo, TemplateInstantiated, PresSteps, VP - still unknown

            return(newDict);
        }