Пример #1
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);
        }
Пример #2
0
        public void PDFBooleanConstructor_Test()
        {
            bool       val    = false;
            PDFBoolean target = new PDFBoolean(val);

            Assert.AreEqual(val, target.Value);
        }
Пример #3
0
        public void Type_Test()
        {
            PDFBoolean    target   = new PDFBoolean(false);
            PDFObjectType expected = PDFObjectTypes.Boolean;
            PDFObjectType actual;

            actual = target.Type;
            Assert.AreEqual(expected, actual);
        }
Пример #4
0
 internal PDFBoolArray(PDFBoolean val) : base(1)
 {
     this.mPDFArr    = null;
     this.mPDFFix    = null;
     this.mParent    = null;
     this.mKeyName   = null;
     this.mAsBoolean = false;
     this.mAsBoolean = true;
     this.mPDFFix    = val;
     this.mArr[0]    = val.Value;
 }
Пример #5
0
        internal EncryptionStandard(PDFDict dict, ISecurityHandler sec)
        {
            this.mEncMetadata = true;
            this.mRev         = -1;
            this.mV           = -1;
            this.mDict        = dict;
            this.mRev         = ((PDFInteger)this.mDict["R"]).Int32Value;
            if (!(this.mDict["Length"] is PDFInteger))
            {
                this.mKeyLength = 40;
            }
            else
            {
                this.mKeyLength = ((PDFInteger)this.mDict["Length"]).Int32Value;
            }
            if (!(this.mDict["V"] is PDFInteger))
            {
                this.mV = 0;
            }
            else
            {
                this.mV = ((PDFInteger)this.mDict["V"]).Int32Value;
            }
            this.mPerm   = BitConverter.ToUInt32(BitConverter.GetBytes(((PDFInteger)this.mDict["P"]).Int32Value), 0);
            this.mOEntry = (this.mDict["O"] as PDFString).Bytes;
            this.mUEntry = (this.mDict["U"] as PDFString).Bytes;
            PDFBoolean flag1 = (this.mDict["EncryptMetadata"] as PDFBoolean);

            if (flag1 != null)
            {
                this.mEncMetadata = flag1.Value;
            }
            this.mDocId         = this.mDict.Doc.Id1;
            this.mOwnerPassword = "";
            if (sec != null)
            {
                if (!this.VerifyUserPassword(""))
                {
                    this.mUserPassword = sec.GetUserPassword();
                }
                else
                {
                    this.mUserPassword = "";
                }
            }
            else
            {
                this.mUserPassword = "";
            }
            if (!this.VerifyUserPassword(this.mUserPassword))
            {
                throw new SecurityException("Wrong PDF Document user password");
            }
        }
Пример #6
0
        public void op_Explicit_Test()
        {
            PDFBoolean value    = new PDFBoolean(false);
            bool       expected = false;
            bool       actual;

            actual = (bool)(value);
            Assert.AreEqual(expected, actual);

            value    = new PDFBoolean(true);
            expected = true;
            actual   = (bool)value;
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void Value_Test()
        {
            bool       expected = true;
            PDFBoolean target   = new PDFBoolean(expected);
            bool       actual;

            actual = target.Value;
            Assert.AreEqual(expected, actual);

            expected = false;
            target   = new PDFBoolean(expected);
            actual   = target.Value;
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void op_Explicit_Test1()
        {
            bool       value    = false;
            PDFBoolean expected = new PDFBoolean(false);
            PDFBoolean actual;

            actual = (PDFBoolean)value;
            Assert.AreEqual(expected, actual);

            expected = new PDFBoolean(true);
            value    = true;
            actual   = (PDFBoolean)value;
            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public void ToString_Test()
        {
            PDFBoolean target   = new PDFBoolean(true);
            string     expected = PDFBoolean.TrueString;

            string actual;

            actual = target.ToString();
            Assert.AreEqual(expected, actual);

            target   = new PDFBoolean(false);
            actual   = target.ToString();
            expected = PDFBoolean.FalseString;
            Assert.AreEqual(expected, actual);
        }
Пример #10
0
        private static bool getEncodedByteAlign(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(false);
            }

            PDFBoolean encodedByteAlign = dict["EncodedByteAlign"] as PDFBoolean;

            if (encodedByteAlign == null)
            {
                return(false);
            }
            return(encodedByteAlign.GetValue());
        }
Пример #11
0
        private static bool getEndOfLine(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(false);
            }

            PDFBoolean endOfLine = dict["EndOfLine"] as PDFBoolean;

            if (endOfLine == null)
            {
                return(false);
            }
            return(endOfLine.GetValue());
        }
Пример #12
0
        private static bool getBlackIs1(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(false);
            }

            PDFBoolean blackIs1 = dict["BlackIs1"] as PDFBoolean;

            if (blackIs1 == null)
            {
                return(false);
            }
            return(blackIs1.GetValue());
        }
Пример #13
0
        private static bool getEndOfBlock(PDFDictionary dict)
        {
            if (dict == null)
            {
                return(true);
            }

            PDFBoolean endOfBlock = dict["EndOfBlock"] as PDFBoolean;

            if (endOfBlock == null)
            {
                return(true);
            }
            return(endOfBlock.GetValue());
        }
Пример #14
0
        public void GetHashCode_Test()
        {
            PDFBoolean one      = new PDFBoolean(true);
            int        expected = one.GetHashCode();

            PDFBoolean two    = new PDFBoolean(true);
            int        actual = two.GetHashCode();

            Assert.AreEqual(expected, actual, "PDFBoolean hash codes for same value were different");

            two    = new PDFBoolean(false);
            actual = two.GetHashCode();

            Assert.AreNotEqual(expected, actual, "PDFBoolean hash codes for different value were the same");
        }
Пример #15
0
        public void Equals_Test1()
        {
            PDFBoolean one      = new PDFBoolean(true);
            PDFBoolean two      = new PDFBoolean(true);
            bool       expected = true;
            bool       actual;

            actual = PDFBoolean.Equals(one, two);
            Assert.AreEqual(expected, actual, "PDFBooleans did not compare as equal");

            actual = Object.Equals(one, two);
            Assert.AreEqual(expected, actual, "PDFBooleans as objects did not compare as equal");

            two      = new PDFBoolean(false);
            expected = false;
            actual   = PDFBoolean.Equals(one, two);
            Assert.AreEqual(expected, actual, "PDFBooleans compared falsely as equal");

            actual = Object.Equals(one, two);
            Assert.AreEqual(expected, actual, "PDFBooleans as objects did not compare as equal");
        }
Пример #16
0
        public void Equals_Test()
        {
            PDFBoolean target = new PDFBoolean(true);
            object     obj    = new PDFBoolean(true);

            bool expected = true;
            bool actual;

            actual = target.Equals(obj);
            Assert.AreEqual(expected, actual, "PDFBooleans did not compare as equal");

            obj      = new PDFBoolean(false);
            expected = false;
            actual   = target.Equals(obj);
            Assert.AreEqual(expected, actual, "PDFBooleans compared falsely as equal");

            obj      = new object();
            expected = false;
            actual   = target.Equals(obj);
            Assert.AreEqual(expected, actual, "PDFBoolean and Object compared falsely as equal");
        }
Пример #17
0
        public void op_Inequality_Test()
        {
            PDFBoolean one      = new PDFBoolean(true);
            PDFBoolean two      = new PDFBoolean(false);
            bool       expected = true;
            bool       actual;

            actual = (one != two);
            Assert.AreEqual(expected, actual);

            one      = new PDFBoolean(true);
            two      = new PDFBoolean(true);
            expected = false;
            actual   = (one != two);
            Assert.AreEqual(expected, actual);

            one      = new PDFBoolean(false);
            two      = new PDFBoolean(false);
            expected = false;
            actual   = (one != two);
            Assert.AreEqual(expected, actual);
        }
Пример #18
0
        static void DisplayRootDictionary(PDFDict formsRoot)
        {
            PDFObject entry;
            bool      bNeedAppearances   = false;
            int       nSigFlags          = 0;
            bool      bCalcOrder         = false;
            bool      bDefaultResource   = false;
            bool      bDefaultAppearance = false;
            bool      bXFAForms          = false;
            int       QuadMode           = -1;
            string    sQuadMode          = "unkown";

            entry = formsRoot.Get("NeedAppearances");
            if (entry is PDFBoolean)
            {
                PDFBoolean needAppearances = (PDFBoolean)entry;
                bNeedAppearances = needAppearances.Value;
            }

            Console.WriteLine("NeedAppearances: " + (bNeedAppearances ? "True" : "False"));

            entry = formsRoot.Get("SigFlags");
            if (entry is PDFInteger)
            {
                PDFInteger sigFlags = (PDFInteger)entry;
                nSigFlags = sigFlags.Value;
            }

            if (nSigFlags == 0)
            {
                Console.WriteLine("Document has no signatures.");
            }
            else
            {
                if ((nSigFlags & 1) == 1)
                {
                    Console.WriteLine("Document has signatures.");
                }
                if ((nSigFlags & 2) == 2)
                {
                    Console.WriteLine("Signatures: Document may append only.");
                }
            }

            entry = formsRoot.Get("CO");
            if (entry is PDFDict)
            {
                bCalcOrder = true;
            }
            Console.WriteLine(String.Format("Calculation Order Dictionary is {0}present.", (bCalcOrder?"":"not ")));

            entry = formsRoot.Get("DR");
            if (entry is PDFDict)
            {
                bDefaultResource = true;
            }
            Console.WriteLine(String.Format("Default Resource Dictionary is {0}present.", (bDefaultResource? "" : "not ")));

            entry = formsRoot.Get("DA");
            if (entry is PDFString)
            {
                bDefaultAppearance = true;
            }
            Console.WriteLine(String.Format("Default Appearance String is {0}present.", (bDefaultAppearance ? "" : "not ")));

            entry = formsRoot.Get("Q");
            if (entry is PDFInteger)
            {
                PDFInteger quad_entry = (PDFInteger)entry;
                QuadMode = quad_entry.Value;
            }
            switch (QuadMode)
            {
            case -1: sQuadMode = "not present"; break;

            case 0: sQuadMode = "Left"; break;

            case 1: sQuadMode = "Centered"; break;

            case 2: sQuadMode = "Right"; break;
            }
            Console.WriteLine(String.Format("Default Quad Mode is {0}.", sQuadMode));

            entry = formsRoot.Get("XFA");
            if (entry is PDFString)
            {
                bXFAForms = true;
            }
            Console.WriteLine(String.Format("XFA Forms are {0}present.", (bXFAForms ? "" : "not ")));
            Console.WriteLine("");
        }
Пример #19
0
 public void WriteBoolean(PDFBoolean val)
 {
     this.WriteBoolean(val.Value);
 }
Пример #20
0
 /// <summary>
 /// Writes the specified value to the PDF stream.
 /// </summary>
 public void Write(PDFBoolean value)
 {
     WriteSeparator(CharCat.Character);
     WriteRaw(value.Value ? "true" : "false");
     _lastCat = CharCat.Character;
 }