public void ValidateName_Test()
        {
            string namevalue = "OkName";

            PDFName.ValidateName(namevalue);
            foreach (Char c in PDFName.InvalidNameChars)
            {
                string invalidvalue = namevalue + c.ToString();
                try
                {
                    PDFName.ValidateName(invalidvalue);
                    Assert.Fail("Invalid name did not raise exception");
                }
                catch (ArgumentException)
                {
                    TestContext.WriteLine("Successfully caught the invalid name");
                }
            }

            try
            {
                PDFName.ValidateName(null);
                Assert.Fail("Invalid null name did not raise exception");
            }
            catch (ArgumentException)
            {
                TestContext.WriteLine("Successfully caught the null invalid name");
            }
        }
Esempio n. 2
0
        protected static PDFName CreatePostScriptFontName(Typeface typeface)
        {
            string     name   = typeface.FontFamily.Source.Replace(" ", "");
            FontStyle  style  = typeface.Style;
            FontWeight weight = typeface.Weight;

            if (style != FontStyles.Normal || weight != FontWeights.Normal)
            {
                string styleString  = (style == FontStyles.Normal) ? "" : style.ToString();
                string weightString = (weight == FontWeights.Normal) ? "" : weight.ToString();
                name = $"{name}-{weightString}{styleString}";
            }

            // Add a random prefix of uppercase letters, like "FRDVGH+", which indicates this font is a subset.
            char[] chars  = new char[7];
            Random random = new Random();

            for (int i = 0; i < 6; i++)
            {
                chars[i] = (char)random.Next('A', 'Z');
            }
            chars[6] = '+';

            return(PDFName.GetEscapedName(new string(chars) + name));
        }
        public void GetHashCode_Test()
        {
            string  name   = "Name";
            PDFName target = new PDFName(name);

            //Hashcode for a PDFName and the hash code for the
            //underlying string should be the same
            int expected = name.GetHashCode();
            int actual;

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

            //Hashcode for 2 PDFNames with the
            //same string should also be the same
            PDFName other = new PDFName(name);

            expected = target.GetHashCode();
            actual   = other.GetHashCode();
            Assert.AreEqual(expected, actual);

            //Different name - different hash code (within reason)
            other    = new PDFName("NotName");
            expected = target.GetHashCode();
            actual   = other.GetHashCode();
            Assert.AreNotEqual(expected, actual);
        }
        public void Equals_Test()
        {
            string  name   = "Name";
            PDFName target = new PDFName(name);

            object obj      = new PDFName(name);
            bool   expected = true;
            bool   actual;

            actual = target.Equals(obj);

            obj      = new PDFName("NewName");
            expected = false;
            actual   = target.Equals(obj);
            Assert.AreEqual(expected, actual);

            obj      = new object();
            expected = false;
            actual   = target.Equals(obj);
            Assert.AreEqual(expected, actual);

            obj      = null;
            expected = false;
            actual   = target.Equals(obj);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 5
0
        public static ZoomMode PDFNameToPDFZoomMode(PDFName name)
        {
            if (name == null)
            {
                return(ZoomMode.FitPage);
            }

            switch (name.GetValue())
            {
            case "FitB":
                return(ZoomMode.FitBounding);

            case "FitBH":
                return(ZoomMode.FitBoundingHorizontal);

            case "FitBV":
                return(ZoomMode.FitBoundingVertical);

            case "FitH":
                return(ZoomMode.FitHorizontal);

            case "Fit":
                return(ZoomMode.FitPage);

            case "FitR":
                return(ZoomMode.FitRectangle);

            case "FitV":
                return(ZoomMode.FitVertical);

            case "XYZ":
                return(ZoomMode.FitXYZ);
            }
            return(ZoomMode.FitPage);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public static PageMode PDFNameToPDFPageMode(PDFName name)
        {
            if (name == null)
            {
                return(PageMode.None);
            }

            string pageMode = name.GetValue();

            switch (pageMode)
            {
            case "UseNone":
                return(PageMode.None);

            case "UseOutlines":
                return(PageMode.Outlines);

            case "UseThumbs":
                return(PageMode.Thumbnail);

            case "FullScreen":
                return(PageMode.FullScreen);

            case "UseOC":
                return(PageMode.OptionalContent);

            case "UseAttachments":
                return(PageMode.Attachment);
            }
            return(PageMode.None);
        }
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            PDFName name = PDFLayoutMarkedContentBegin.GetNameForContentType(this.Begin.ContentType);

            context.Graphics.EndMarkedContent(name);
            return(base.DoOutputToPDF(context, writer));
        }
        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);
        }
Esempio n. 10
0
        static string[] get_button_info(PDFDict field)
        {
            string    svalue;
            string    sdefault_value;
            PDFObject entry;

            entry = field.Get("V");
            if (entry is PDFName)
            {
                PDFName field_value_name = (PDFName)entry;
                svalue = "Value: " + field_value_name.Value;
            }
            else
            {
                svalue = "";
            }

            entry = field.Get("DV");
            if (entry is PDFName)
            {
                PDFName field_defvalue_name = (PDFName)entry;
                sdefault_value = "Default Value: " + field_defvalue_name.Value;
            }
            else
            {
                sdefault_value = "";
            }

            return(new string[] { svalue, sdefault_value });
        }
        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 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);
        }
Esempio n. 13
0
        public static PageNumberingStyle PDFNameToPDFPageNumberingStyle(PDFName name)
        {
            if (name == null)
            {
                return(PageNumberingStyle.None);
            }
            switch (name.GetValue())
            {
            case "D":
                return(PageNumberingStyle.DecimalArabic);

            case "R":
                return(PageNumberingStyle.UppercaseRoman);

            case "r":
                return(PageNumberingStyle.LowercaseRoman);

            case "A":
                return(PageNumberingStyle.UppercaseLetters);

            case "a":
                return(PageNumberingStyle.LowercaseLetters);
            }
            return(PageNumberingStyle.None);
        }
Esempio n. 14
0
        public static PageLayout PDFNameToPDFPageLayout(PDFName name)
        {
            if (name == null)
            {
                return(PageLayout.SinglePage);
            }

            switch (name.GetValue())
            {
            case "SinglePage":
                return(PageLayout.SinglePage);

            case "OneColumn":
                return(PageLayout.OneColumn);

            case "TwoColumnLeft":
                return(PageLayout.TwoColumnLeft);

            case "TwoColumnRight":
                return(PageLayout.TwoColumnRight);

            case "TwoPageLeft":
                return(PageLayout.TwoPageLeft);

            case "TwoPageRight":
                return(PageLayout.TwoPageRight);
            }
            return(PageLayout.SinglePage);
        }
Esempio n. 15
0
 private Stream ApplyEncodeFilter(Stream str, PDFName filter, PDFDict encodeParams)
 {
     if (filter.Value == "ASCIIHexDecode")
     {
         return(new ASCIIHexEncoder(str));
     }
     if (filter.Value == "ASCII85Decode")
     {
         return(new ASCII85Encoder(str));
     }
     if (filter.Value == "LZWDecode")
     {
         return(new LZW_Encoder(str, encodeParams));
     }
     if (filter.Value == "FlateDecode")
     {
         return(new Flate_Encoder(str, encodeParams));
     }
     if (filter.Value == "RunLengthDecode")
     {
         return(new RLE_Encoder(str));
     }
     if (filter.Value == "CCITTFaxDecode")
     {
         return(new CCITT_Encoder(str, encodeParams));
     }
     if (filter.Value == "DCTDecode")
     {
         return(new DCT_Encoder(str, encodeParams));
     }
     throw new PDFException(string.Format("Unknown filter: {0:S}", filter.Value));
 }
Esempio n. 16
0
        public void PaintXObject(PDFName name)
        {
            if (null == name || string.IsNullOrEmpty(name.Value))
            {
                throw new ArgumentNullException("The value of name cannot be null");
            }

            this.Writer.WriteOpCodeS(PDFOpCode.XobjPaint, name);
        }
Esempio n. 17
0
        public void Value_Test()
        {
            string  name   = "Name";
            PDFName target = new PDFName(name);
            string  actual;

            actual = target.Value;

            Assert.AreEqual(name, actual);
        }
Esempio n. 18
0
        public PDFStream GetGlyphStream(PDFName key)
        {
            PDFDict dict1 = (this.Dict["CharProcs"] as PDFDict);

            if (dict1 == null)
            {
                throw new ArgumentException("Invalid CharProcs in Type3 font");
            }
            return(dict1[key, 1] as PDFStream);
        }
Esempio n. 19
0
        public override bool Equals(object obj)
        {
            PDFName name1 = (obj as PDFName);

            if (name1 == null)
            {
                return(false);
            }
            return(this.Value.Equals(name1.Value));
        }
Esempio n. 20
0
        public void Type_Test()
        {
            string        name   = "Name";
            PDFName       target = new PDFName(name);
            PDFObjectType actual;

            actual = target.Type;
            PDFObjectType expected = PDFObjectTypes.Name;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 21
0
        public static TextAnnotationIcon PDFNameToPDFTextAnnotationIcon(PDFName name)
        {
            if (name == null)
            {
                return(TextAnnotationIcon.Note);
            }

            switch (name.GetValue())
            {
            case "Circle":
                return(TextAnnotationIcon.Circle);

            case "Comment":
                return(TextAnnotationIcon.Comment);

            case "Cross":
                return(TextAnnotationIcon.Cross);

            case "Help":
                return(TextAnnotationIcon.Help);

            case "Insert":
                return(TextAnnotationIcon.Insert);

            case "Key":
                return(TextAnnotationIcon.Key);

            case "NewParagraph":
                return(TextAnnotationIcon.NewParagraph);

            case "Paragraph":
                return(TextAnnotationIcon.Paragraph);

            case "RightArrow":
                return(TextAnnotationIcon.RightArrow);

            case "RightPointer":
                return(TextAnnotationIcon.RightPointer);

            case "Star":
                return(TextAnnotationIcon.Star);

            case "UpArrow":
                return(TextAnnotationIcon.UpArrow);

            case "UpLeftArrow":
                return(TextAnnotationIcon.UpLeftArrow);

            case "Check":
                return(TextAnnotationIcon.Check);
            }

            return(TextAnnotationIcon.Note);
        }
Esempio n. 22
0
 internal PDFNameArray(PDFName val) : base(1)
 {
     this.mPDFArr  = null;
     this.mPDFFix  = null;
     this.mParent  = null;
     this.mKeyName = null;
     this.mAsName  = false;
     this.mAsName  = true;
     this.mPDFFix  = val;
     this.mArr[0]  = val.Value;
 }
Esempio n. 23
0
        public void op_Explicit_Test()
        {
            string  name     = "NewName";
            PDFName expected = new PDFName(name);
            PDFName actual;

            actual = ((PDFName)(name));
            Assert.AreEqual(expected, actual);

            actual = (PDFName)"OtherName";
            Assert.AreNotEqual(expected, actual);
        }
Esempio n. 24
0
 // Properties
 public string this[int index]
 {
     get
     {
         return((base._GetObject(index) as PDFName).Value);
     }
     set
     {
         PDFName name1 = Library.CreateName(value);
         base._SetObject(index, name1, name1.Direct);
     }
 }
Esempio n. 25
0
 public static BorderEffect PDFNameToPDFBorderEffect(PDFName name)
 {
     if (name == null)
     {
         return(BorderEffect.None);
     }
     if (name.GetValue() == "C")
     {
         return(BorderEffect.Cloudy);
     }
     return(BorderEffect.None);
 }
Esempio n. 26
0
 public PDFObject this[PDFName key, bool getDirect]
 {
     get
     {
         PDFObject obj1 = ((PDFObject)this.mHash[key]);
         if ((obj1 != null) && getDirect)
         {
             obj1 = obj1.Direct;
         }
         return(obj1);
     }
 }
Esempio n. 27
0
 public static Direction PDFNameToPDFDirection(PDFName name)
 {
     if (name == null)
     {
         return(Direction.LeftToRight);
     }
     if (name.GetValue() == "R2L")
     {
         return(Direction.RightToLeft);
     }
     return(Direction.LeftToRight);
 }
Esempio n. 28
0
 public static CaretSymbol PDFNameToPDFCaretSymbol(PDFName name)
 {
     if (name == null)
     {
         return(CaretSymbol.None);
     }
     if (name.GetValue() == "P")
     {
         return(CaretSymbol.Paragraph);
     }
     return(CaretSymbol.None);
 }
Esempio n. 29
0
        public void op_Explicit_Test1()
        {
            string  expected = "NewName";
            PDFName name     = new PDFName(expected);
            string  actual;

            actual = ((string)(name));
            Assert.AreEqual(expected, actual);

            name   = new PDFName("OtherName");
            actual = (string)name;
            Assert.AreNotEqual(expected, actual);
        }
Esempio n. 30
0
        public static IEncryption Factory(PDFDict encryptDict, ISecurityHandler sec)
        {
            PDFName name1 = (encryptDict["Filter"] as PDFName);

            if (name1 == null)
            {
                return(null);
            }
            if (name1.Value != "Adobe.PubSec")
            {
                return(null);
            }
            return(new EncryptionPKCS(encryptDict, sec));
        }