Exemplo n.º 1
0
        public static PDFArray PDFColorToPDFArray(DeviceColor value)
        {
            PDFArray color = new PDFArray();

            switch (value.Colorspace.N)
            {
            case 1:
                color.AddItem(new PDFNumber((value as ColorGray).G * 1.0f / 255));
                break;

            case 3:
                color.AddItem(new PDFNumber((value as ColorRGB).R * 1.0f / 255));
                color.AddItem(new PDFNumber((value as ColorRGB).G * 1.0f / 255));
                color.AddItem(new PDFNumber((value as ColorRGB).B * 1.0f / 255));
                break;

            case 4:
                color.AddItem(new PDFNumber((value as ColorCMYK).C * 1.0f / 255));
                color.AddItem(new PDFNumber((value as ColorCMYK).M * 1.0f / 255));
                color.AddItem(new PDFNumber((value as ColorCMYK).Y * 1.0f / 255));
                color.AddItem(new PDFNumber((value as ColorCMYK).K * 1.0f / 255));
                break;
            }
            return(color);
        }
Exemplo n.º 2
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "Type", "Subtype", "R", "CYX", "O" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    result.AddItem(keys[i], obj.Clone());
                }
            }

            string[] numberFormat = { "X", "Y", "D", "A", "T", "S" };
            for (int i = 0; i < numberFormat.Length; ++i)
            {
                PDFArray arr = dict[numberFormat[i]] as PDFArray;
                if (arr != null)
                {
                    PDFArray newArr = new PDFArray();
                    for (int j = 0; j < arr.Count; ++i)
                    {
                        PDFDictionary d = arr[i] as PDFDictionary;
                        if (d != null)
                        {
                            newArr.AddItem(NumberFormat.Copy(d));
                        }
                    }
                    result.AddItem(numberFormat[i], newArr);
                }
            }

            return(result);
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary newDict = new PDFDictionary();

            string[] arrays = { "C", "D" };
            for (int i = 0; i < arrays.Length; ++i)
            {
                PDFArray arr = dict[arrays[i]] as PDFArray;
                if (arr != null)
                {
                    PDFArray newArr = new PDFArray();
                    for (int j = 0; j < arr.Count; ++j)
                    {
                        PDFNumber num = arr[j] as PDFNumber;
                        newArr.AddItem(num.Clone());
                    }
                    newDict.AddItem(arrays[i], newArr);
                }
            }

            PDFNumber w = dict["W"] as PDFNumber;

            if (w != null)
            {
                newDict.AddItem("W", w.Clone());
            }

            PDFName s = dict["S"] as PDFName;

            if (s != null)
            {
                newDict.AddItem("S", s.Clone());
            }

            return(newDict);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 private void setDefault()
 {
     _array.Clear();
     _array.AddItem(new PDFName(LineEndingStyle.None.ToString()));
     _array.AddItem(new PDFName(LineEndingStyle.None.ToString()));
 }
Exemplo n.º 7
0
 public EndingStyles(LineEndingStyle begin, LineEndingStyle end)
 {
     _array = new PDFArray();
     _array.AddItem(new PDFName(begin.ToString()));
     _array.AddItem(new PDFName(end.ToString()));
 }
Exemplo n.º 8
0
 public EndingStyles()
 {
     _array = new PDFArray();
     _array.AddItem(new PDFName(LineEndingStyle.None.ToString()));
     _array.AddItem(new PDFName(LineEndingStyle.None.ToString()));
 }