public void CopyTo_Test()
        {
            PDFDictionary dictionary = new PDFDictionary();
            ICollection <KeyValuePair <PDFName, IFileObject> > target = dictionary;
            PDFName     key   = new PDFName("Item1");
            IFileObject value = new PDFNumber(1);
            KeyValuePair <PDFName, IFileObject> item = new KeyValuePair <PDFName, IFileObject>(key, value); // TODO: Initialize to an appropriate value

            target.Add(item);

            PDFName key2 = new PDFName("Item2");

            item = new KeyValuePair <PDFName, IFileObject>(key2, value);
            target.Add(item);

            KeyValuePair <PDFName, IFileObject>[] array = new KeyValuePair <PDFName, IFileObject> [3];
            int arrayIndex = 1;

            target.CopyTo(array, arrayIndex);

            Assert.IsNotNull(array[1]);
            Assert.IsNotNull(array[2]);

            PDFName     arraykey = array[1].Key;
            IFileObject expected = dictionary[arraykey];
            IFileObject actual   = array[1].Value;

            Assert.AreEqual(expected, actual);

            arraykey = array[2].Key;
            expected = dictionary[arraykey];
            actual   = array[2].Value;
            Assert.AreEqual(expected, actual);
        }
        public void Remove_Test()
        {
            PDFDictionary target = new PDFDictionary();
            PDFName       key    = new PDFName("Item1");
            IFileObject   value  = new PDFNumber(1);

            target.Add(key, value);

            PDFName key2 = new PDFName("Item2");

            target.Add(key2, value);
            Assert.AreEqual(2, target.Count);

            bool expected = true;
            bool actual;

            actual = target.Remove(key);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(1, target.Count);

            expected = false;
            key      = new PDFName("NotFound");
            actual   = target.Remove(key);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(1, target.Count);
        }
        public void TryGetValue_Test()
        {
            PDFDictionary target = new PDFDictionary();
            PDFName       key    = new PDFName("Item1");
            IFileObject   value  = new PDFNumber(1);

            target.Add(key, value);

            PDFName key2 = new PDFName("Item2");

            target.Add(key2, value);

            bool expected = true;
            bool actual;

            IFileObject valueExpected = value;

            actual = target.TryGetValue(key, out value);

            Assert.AreEqual(valueExpected, value);
            Assert.AreEqual(expected, actual);

            expected = false;
            key      = new PDFName("NotFound");
            actual   = target.TryGetValue(key, out value);

            Assert.AreEqual(expected, actual);
            Assert.IsNull(value);
        }
예제 #4
0
        /// <summary>
        /// Only for testing.
        /// </summary>
        internal PDFTrueTypeFont(PDFDictionary fontDictionary) :
            base(fontDictionary)
        {
            FontFamily fontFamily = new FontFamily("Segoe Print");

            this._typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
        }
예제 #5
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);
        }
예제 #6
0
        /// <summary>
        /// Writes the stream of the specified dictionary.
        /// </summary>
        public void WriteStream(PDFDictionary value, bool omitStream)
        {
            StackItem stackItem = _stack[_stack.Count - 1];

            Debug.Assert(stackItem.Object is PDFDictionary);
            Debug.Assert(stackItem.Object.IsIndirect);
            stackItem.HasStream = true;

            WriteRaw(_lastCat == CharCat.NewLine ? ">>\nstream\n" : " >>\nstream\n");

            if (omitStream)
            {
                WriteRaw("  «...stream content omitted...»\n");  // useful for debugging only
            }
            else
            {
                byte[] bytes = value.Stream.Value;
                if (bytes.Length != 0)
                {
                    if (SecurityHandler != null)
                    {
                        bytes = (byte[])bytes.Clone();
                        bytes = SecurityHandler.EncryptBytes(bytes);
                    }
                    Write(bytes);
                    if (_lastCat != CharCat.NewLine)
                    {
                        WriteRaw('\n');
                    }
                }
            }
            WriteRaw("endstream\n");
        }
예제 #7
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);
        }
예제 #8
0
        private bool containsField(string fieldName, PDFArray fields)
        {
            if (fields == null)
            {
                return(false);
            }

            for (int i = 0; i < fields.Count; ++i)
            {
                PDFDictionary dict = fields[i] as PDFDictionary;
                if (dict != null)
                {
                    PDFString name = dict["T"] as PDFString;
                    if (name != null && name.GetValue() == fieldName)
                    {
                        return(true);
                    }

                    PDFArray kids = dict["Kids"] as PDFArray;
                    if (kids != null)
                    {
                        return(containsField(fieldName, kids));
                    }
                }
            }

            return(false);
        }
예제 #9
0
        private void addRadioButton(Field field)
        {
            PDFDictionary dict = findRadioButtonGroup(field.Name);

            if (dict == null)
            {
                dict = createRadioButtonGroup(field.Name);
            }

            PDFArray kids = dict["Kids"] as PDFArray;

            if (kids == null)
            {
                kids = new PDFArray();
                dict.AddItem("Kids", kids);
            }

            if (field is RadioButton && (field as RadioButton).Checked == true)
            {
                dict.AddItem("V", new PDFName((field as RadioButton).ExportValue));
                dict.AddItem("DV", new PDFName((field as RadioButton).ExportValue));
            }

            kids.AddItem(field.Dictionary);
            field.Dictionary.AddItem("Parent", dict);
            field.Dictionary.RemoveItem("T");
        }
예제 #10
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary newDict = new PDFDictionary();

            PDFBoolean k = dict["K"] as PDFBoolean;

            if (k != null)
            {
                newDict.AddItem("K", k.Clone());
            }

            PDFBoolean i = dict["I"] as PDFBoolean;

            if (i != null)
            {
                newDict.AddItem("I", i.Clone());
            }

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

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

            IPDFObject cs = dict["CS"];

            if (cs != null)
            {
                newDict.AddItem("CS", cs.Clone());
            }

            return(newDict);
        }
예제 #11
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary newDict = new PDFDictionary();

            string[] keys = { "Type", "Subtype", "Rect", "Contents", "NM", "M", "F", "Border", "C", "AS" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    newDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary ap = dict["AP"] as PDFDictionary;

            if (ap != null)
            {
                newDict.AddItem("AP", copyAppearance(ap));
            }

            // P, StructParent - do not
            // OS - still unknown

            return(newDict);
        }
        public void PDFDictionaryConstructor_Test()
        {
            PDFDictionary target   = new PDFDictionary();
            int           expected = 0;
            int           actual   = target.Count;

            Assert.AreEqual(expected, actual);
        }
        public void IsReadOnly_Test()
        {
            PDFDictionary target   = new PDFDictionary();
            bool          expected = false;
            bool          actual;

            actual = target.IsReadOnly;
            Assert.AreEqual(expected, actual);
        }
        public void Type_Test()
        {
            PDFDictionary target   = new PDFDictionary();
            PDFObjectType expected = PDFObjectTypes.Dictionary;

            PDFObjectType actual;

            actual = target.Type;
            Assert.AreEqual(expected, actual);
        }
예제 #15
0
        internal Catalog(PDFDictionary dict)
        {
            if (dict == null)
            {
                throw new InvalidDocumentException();
            }

            _dictionary        = dict;
            _documentEssential = new DocumentEssential(this);
        }
예제 #16
0
 public CCITTFaxParameters(PDFDictionary dict)
 {
     _k                      = getK(dict);
     _endOfLine              = getEndOfLine(dict);
     _encodedByteAlign       = getEncodedByteAlign(dict);
     _columns                = getColumns(dict);
     _rows                   = getRows(dict);
     _endOfBlock             = getEndOfBlock(dict);
     _blackIs1               = getBlackIs1(dict);
     _damagedRowsBeforeError = getDamagedRowsBeforeError(dict);
 }
예제 #17
0
        private void loadAdditionalAction(string name)
        {
            PDFDictionary aa = _dictionary["AA"] as PDFDictionary;

            if (aa != null)
            {
                PDFDictionary dict = aa[name] as PDFDictionary;
                if (dict != null)
                {
                    setActionValue(new JavaScriptAction(dict, _documentEssential), name);
                }
            }
        }
예제 #18
0
        private void loadNames()
        {
            PDFDictionary names = _dictionary["Names"] as PDFDictionary;

            if (names == null)
            {
                _names = new Names();
            }
            else
            {
                _names = new Names(names);
            }
        }
예제 #19
0
        private void loadAcroForm()
        {
            PDFDictionary acroForm = _dictionary["AcroForm"] as PDFDictionary;

            if (acroForm == null)
            {
                _acroForm = new AcroForm();
                _dictionary.AddItem("AcroForm", _acroForm.GetDictionary());
            }
            else
            {
                _acroForm = new AcroForm(acroForm);
            }
        }
예제 #20
0
        private void loadPageLabels()
        {
            PDFDictionary pageLabelsRoot = _dictionary["PageLabels"] as PDFDictionary;

            if (pageLabelsRoot != null)
            {
                _pageLabels = new PageLabelsCollection(pageLabelsRoot);
            }
            else
            {
                _pageLabels = new PageLabelsCollection();
                _dictionary.AddItem("PageLabels", _pageLabels.GetDictionary());
            }
        }
예제 #21
0
        private void loadViewerPreferences()
        {
            PDFDictionary viewerPreferences = _dictionary["ViewerPreferences"] as PDFDictionary;

            if (viewerPreferences != null)
            {
                _viewerPreferences = new ViewerPreferences(viewerPreferences);
            }
            else
            {
                _viewerPreferences = new ViewerPreferences();
                _dictionary.AddItem("ViewerPreferences", _viewerPreferences.GetDictionary());
            }
        }
예제 #22
0
        private void loadOutlines()
        {
            PDFDictionary outlinesRoot = _dictionary["Outlines"] as PDFDictionary;

            if (outlinesRoot != null)
            {
                _outlines = new OutlinesCollection(outlinesRoot, _documentEssential);
            }
            else
            {
                _outlines = new OutlinesCollection(_documentEssential);
                _dictionary.AddItem("Outlines", _outlines.GetDictionary());
            }
        }
예제 #23
0
        private PDFDictionary createRadioButtonGroup(string name)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("FT", new PDFName("Btn"));
            dict.AddItem("Ff", new PDFNumber(49152));
            dict.AddItem("V", new PDFName("Off"));
            dict.AddItem("DV", new PDFName("Off"));
            dict.AddItem("Kids", new PDFArray());
            dict.AddItem("T", new PDFString(name));

            (_dictionary["Fields"] as PDFArray).AddItem(dict);
            return(dict);
        }
예제 #24
0
        private void loadPages()
        {
            PDFDictionary pages = _dictionary["Pages"] as PDFDictionary;

            if (pages != null)
            {
                _pages = new PageCollection(pages, _documentEssential);
            }
            else
            {
                _pages = new PageCollection(_documentEssential);
                _dictionary.AddItem("Pages", _pages.GetDictionary());
            }
        }
예제 #25
0
        private void loadResources()
        {
            PDFDictionary resources = _dictionary["DR"] as PDFDictionary;

            if (resources != null)
            {
                _resources = new Resources(resources, false);
            }
            else
            {
                _resources = new Resources(false);
                _dictionary.AddItem("DR", _resources.Dictionary);
            }
        }
예제 #26
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));
        }
예제 #27
0
        /// <summary>
        /// Recursively converts the page tree into a flat array.
        /// </summary>
        PDFDictionary[] GetKids(PDFReference iref, PDFPage.InheritedValues values, PDFDictionary parent)
        {
            // TODO: inherit inheritable keys...
            PDFDictionary kid = (PDFDictionary)iref.Value;

#if true
            string type = kid.Elements.GetName(Keys.Type);
            if (type == "/Page")
            {
                PDFPage.InheritValues(kid, values);
                return(new PDFDictionary[] { kid });
            }

            if (String.IsNullOrEmpty(type))
            {
                // Type is required. If type is missing, assume it is "/Page" and hope it will work.
                // TODO Implement a "Strict" mode in PDFSharp and don't do this in "Strict" mode.
                PDFPage.InheritValues(kid, values);
                return(new PDFDictionary[] { kid });
            }
#else
            if (kid.Elements.GetName(Keys.Type) == "/Page")
            {
                PDFPage.InheritValues(kid, values);
                return(new PDFDictionary[] { kid });
            }
#endif

            Debug.Assert(kid.Elements.GetName(Keys.Type) == "/Pages");
            PDFPage.InheritValues(kid, ref values);
            List <PDFDictionary> list = new List <PDFDictionary>();
            PDFArray             kids = kid.Elements["/Kids"] as PDFArray;

            if (kids == null)
            {
                if (kid.Elements["/Kids"] is PDFReference xref3)
                {
                    kids = xref3.Value as PDFArray;
                }
            }

            foreach (PDFReference xref2 in kids)
            {
                list.AddRange(GetKids(xref2, values, kid));
            }
            int count = list.Count;
            Debug.Assert(count == kid.Elements.GetInteger("/Count"));
            return(list.ToArray());
        }
예제 #28
0
        /// <summary>
        /// Adds a new page to the PDF and creates the needed PDF objects.
        /// </summary>
        public void AddPage()
        {
            currentContentStream = CreateContentStream(PDFStream.Filter.None);
            pageContentStreams.Add(currentContentStream);

            currentPageDictionary = CreateIndirectDictionary();
            currentPageDictionary.Put("Type", new PDFName("Page"));
            currentPageDictionary.Put("Parent", pagesDictionary);
            currentPageDictionary.Put("Contents", currentContentStream);
            currentPageDictionary.Put("MediaBox", mediaBox);
            currentPageDictionary.Put("Resources", _commonResources);

            pageDictionaries.Add(currentPageDictionary);
            pageKidsArray.Array.Add(currentPageDictionary);
        }
예제 #29
0
        private static int getColumns(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(1);
            }

            PDFNumber columns = dict["Columns"] as PDFNumber;

            if (columns == null)
            {
                return(1);
            }
            return((int)columns.GetValue());
        }
예제 #30
0
        private static int getBitsPerComponent(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(8);
            }

            PDFNumber bitsPerComponent = dict["BitsPerComponent"] as PDFNumber;

            if (bitsPerComponent == null)
            {
                return(8);
            }
            return((int)bitsPerComponent.GetValue());
        }