public void DisposeTest()
        {
            StylesDocument target = new StylesDocument();

            target.Dispose();
            //Just make sure it doesn't throw an exception
        }
        public void PDFStylesDocumentConstructorTest1()
        {
            PDFObjectType  type   = (PDFObjectType)"0000";
            StylesDocument target = new StylesDocument(type);

            Assert.AreEqual(type, target.Type);
        }
        private void InitStylesDocument(StylesDocument target)
        {
            StyleDefn defn = new StyleDefn();

            defn.AppliedType  = typeof(Label);
            defn.AppliedClass = "sea";

            defn.Border.Color    = PDFColors.Red;
            defn.Border.Width    = 10;
            defn.Font.FontFamily = (PDFFontSelector)"Helvetica";
            target.Styles.Add(defn);

            StyleDefn defn2 = new StyleDefn();

            defn2.AppliedClass = "sea";

            defn2.Border.Color        = PDFColors.Gray;
            defn2.Columns.ColumnCount = 3;
            target.Styles.Add(defn2);

            StyleDefn defn3 = new StyleDefn();

            defn3.AppliedClass = "other";
            defn3.Border.Width = 20;
            defn3.Stroke.Color = PDFColors.Aqua;
            target.Styles.Add(defn3);
        }
        public void MapPathTest2()
        {
            // web url test

            StylesDocument target = new StylesDocument();

            target.LoadedSource = @"http://www.scryber.co.uk/Documents/PDFs/MyStyles.psfx";
            string source         = @"/Documents/Images/MyImage.png";
            bool   isfile         = false;
            bool   isfileExpected = false;
            string expected       = @"http://www.scryber.co.uk/Documents/Images/MyImage.png";

            string actual;

            actual = target.MapPath(source, out isfile);
            Assert.AreEqual(isfileExpected, isfile);
            Assert.AreEqual(expected, actual);

            target.LoadedSource = @"http://192.1680.1:443/Documents/PDFs/MyStyles.psfx";
            source         = @"/Images/MyImage.png";
            isfile         = false;
            isfileExpected = false;
            expected       = @"http://192.1680.1:443/Images/MyImage.png";

            actual = target.MapPath(source, out isfile);
            Assert.AreEqual(isfileExpected, isfile);
            Assert.AreEqual(expected, actual);
        }
        public void MapPathTest()
        {
            //Relative file path

            StylesDocument target    = new StylesDocument();
            string         path      = @"..\Images\MyImage.png";
            char           separator = System.IO.Path.DirectorySeparatorChar;
            string         root      = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string         expected  = System.IO.Path.Combine(root, "Images", "MyImage.png");
            string         src       = System.IO.Path.Combine(root, "PDFs", "MyStyles.pdfx");

            target.LoadedSource = src;

            string actual;

            actual = target.MapPath(path);
            Assert.AreEqual(expected.ToLower(), actual.ToLower());

            //http url

            path                = @"../Images/MyImage.png";
            expected            = @"http://www.scryber.co.uk/Documents/Images/MyImage.png";
            src                 = @"http://www.scryber.co.uk/Documents/PDFs/MyStyles.psfx";
            target.LoadedSource = src;

            actual = target.MapPath(path);
            Assert.AreEqual(expected.ToLower(), actual.ToLower());

            //http url - same directory

            path                = @"MyImage.png";
            expected            = @"http://www.scryber.co.uk/Documents/PDFs/MyImage.png";
            src                 = @"http://www.scryber.co.uk/Documents/PDFs/MyStyles.psfx";
            target.LoadedSource = src;

            actual = target.MapPath(path);
            Assert.AreEqual(expected.ToLower(), actual.ToLower());



            // image file path not relative

            path                = root + separator + "Images" + separator + "MyImage.png";
            expected            = path;
            src                 = root + "Documents" + separator + "PDFs" + separator + "MyStyles.pdfx";
            target.LoadedSource = src;

            actual = target.MapPath(path);
            Assert.AreEqual(expected.ToLower(), actual.ToLower());

            // image web path not relative

            path                = @"http://www.scryber.co.uk/Images/MyImage.png";
            expected            = @"http://www.scryber.co.uk/Images/MyImage.png";
            src                 = @"http://www.scryber.co.uk/Documents/PDFs/MyStyles.psfx";
            target.LoadedSource = src;

            actual = target.MapPath(path);
            Assert.AreEqual(expected.ToLower(), actual.ToLower());
        }
Exemplo n.º 6
0
        protected override void Commit()
        {
            if (ctStyles == null)
            {
                throw new InvalidOperationException("Unable to write out styles that were never read in!");
            }

            /*XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
             * xmlOptions.SaveSyntheticDocumentElement=(new QName(CTStyles.type.Name.NamespaceURI, "styles"));
             * Dictionary<String,String> map = new Dictionary<String,String>();
             * map.Put("http://schemas.Openxmlformats.org/officeDocument/2006/relationships", "r");
             * map.Put("http://schemas.Openxmlformats.org/wordProcessingml/2006/main", "w");
             * xmlOptions.SaveSuggestedPrefixes=(map);*/
            PackagePart             part       = GetPackagePart();
            Stream                  out1       = part.GetOutputStream();
            StylesDocument          doc        = new StylesDocument(ctStyles);
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[] {
                new XmlQualifiedName("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"),
                new XmlQualifiedName("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
                new XmlQualifiedName("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"),
                new XmlQualifiedName("v", "urn:schemas-microsoft-com:vml"),
                new XmlQualifiedName("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"),
                new XmlQualifiedName("w10", "urn:schemas-microsoft-com:office:word"),
                new XmlQualifiedName("wne", "http://schemas.microsoft.com/office/word/2006/wordml"),
                new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")
            });

            doc.Save(out1, namespaces);
            out1.Close();
        }
        public void IDTest()
        {
            StylesDocument target   = new StylesDocument();
            string         expected = "MyStylesDocument";
            string         actual;

            target.ID = expected;
            actual    = target.ID;
            Assert.AreEqual(expected, actual);
        }
        public void LoadedSourceTest()
        {
            StylesDocument target   = new StylesDocument();
            string         expected = @"C:\Documents\PDFs\MyStyles.psfx";
            string         actual;

            target.LoadedSource = expected;
            actual = target.LoadedSource;
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
 protected override void Commit()
 {
   if (this.ctStyles == null)
     throw new InvalidOperationException("Unable to write out styles that were never read in!");
   Stream outputStream = this.GetPackagePart().GetOutputStream();
   StylesDocument stylesDocument = new StylesDocument(this.ctStyles);
   XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[8]{ new XmlQualifiedName("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"), new XmlQualifiedName("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"), new XmlQualifiedName("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"), new XmlQualifiedName("v", "urn:schemas-microsoft-com:vml"), new XmlQualifiedName("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"), new XmlQualifiedName("w10", "urn:schemas-microsoft-com:office:word"), new XmlQualifiedName("wne", "http://schemas.microsoft.com/office/word/2006/wordml"), new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main") });
   stylesDocument.Save(outputStream, namespaces);
   outputStream.Close();
 }
        public void MergeIntoTest()
        {
            string         classname = "sea";
            StylesDocument target    = new StylesDocument();

            // same class, same type = applied
            StyleDefn defn = new StyleDefn();

            defn.AppliedType  = typeof(Label);
            defn.AppliedClass = classname;

            defn.Border.Color    = PDFColors.Red;
            defn.Border.Width    = 10;
            defn.Font.FontFamily = (PDFFontSelector)"Helvetica";
            target.Styles.Add(defn);

            // same class no type = applied (lower priority)
            StyleDefn defn2 = new StyleDefn();

            defn2.AppliedClass = classname;

            defn2.Border.Color        = PDFColors.Gray;
            defn2.Columns.ColumnCount = 3;
            target.Styles.Add(defn2);

            // different class = not applied
            StyleDefn defn3 = new StyleDefn();

            defn3.AppliedClass = "other";
            defn3.Border.Width = 20;
            defn3.Stroke.Color = PDFColors.Aqua;
            target.Styles.Add(defn3);

            //same class but different type = not applied
            StyleDefn defn4 = new StyleDefn();

            defn4.AppliedClass    = classname;
            defn4.AppliedType     = typeof(Image);
            defn4.Font.FontFamily = (PDFFontSelector)"Symbol";
            target.Styles.Add(defn4);



            Style actual = new Style();
            Label lbl    = new Label();

            lbl.StyleClass = classname;
            target.MergeInto(actual, lbl, ComponentState.Normal);
            actual.Flatten();

            Assert.AreEqual(PDFColors.Red, actual.Border.Color); //from defn (higher priority than defn2)
            Assert.AreEqual((PDFUnit)10, actual.Border.Width);   // from defn
            Assert.AreEqual(3, actual.Columns.ColumnCount);      //from defn2
            Assert.AreEqual((PDFFontSelector)"Helvetica", actual.Font.FontFamily);
        }
        public void ParentTest()
        {
            StylesDocument target   = new StylesDocument();
            Document       expected = new Document();

            expected.Styles.Add(target);
            target.Parent = expected;

            IPDFComponent actual = target.Parent;

            Assert.AreEqual(expected, actual);
        }
        public void DocumentTest()
        {
            StylesDocument target = new StylesDocument();
            Document       root   = new Document();

            root.Styles.Add(target);

            IPDFDocument actual;

            actual = target.Document;
            Assert.AreEqual(root, actual);
        }
Exemplo n.º 13
0
 public XWPFStyles CreateStyles()
 {
     if (this.styles == null)
     {
         StylesDocument stylesDocument = new StylesDocument();
         XWPFRelation   styles         = XWPFRelation.STYLES;
         int            relationIndex  = this.GetRelationIndex(styles);
         XWPFStyles     relationship   = (XWPFStyles)this.CreateRelationship((POIXMLRelation)styles, (POIXMLFactory)XWPFFactory.GetInstance(), relationIndex);
         relationship.SetStyles(stylesDocument.Styles);
         this.styles = relationship;
     }
     return(this.styles);
 }
        public void InitTest()
        {
            StylesDocument target  = new StylesDocument(); // TODO: Initialize to an appropriate value
            PDFInitContext context = new PDFInitContext(new PDFItemCollection(null),
                                                        new Logging.DoNothingTraceLog(TraceRecordLevel.Off), new PDFPerformanceMonitor(true), null);

            target.Initialized += target_Initialized;

            isInitialized = false;
            target.Init(context);
            //Set to true by the event handler
            Assert.IsTrue(isInitialized);
        }
Exemplo n.º 15
0
 internal override void OnDocumentRead()
 {
   try
   {
     this.ctStyles = StylesDocument.Parse(this.GetPackagePart().GetInputStream()).Styles;
     this.latentStyles = new XWPFLatentStyles(this.ctStyles.latentStyles, this);
   }
   catch (XmlException ex)
   {
     throw new POIXMLException("Unable to read styles", (Exception) ex);
   }
   foreach (CT_Style style in (IEnumerable<CT_Style>) this.ctStyles.GetStyleList())
     this.listStyle.Add(new XWPFStyle(style, this));
 }
        public void StylesTest()
        {
            StylesDocument  target   = new StylesDocument();
            StyleCollection expected = target.Styles;

            Assert.IsNotNull(expected, "Styles collection is not initialized");
            Assert.AreEqual(target, expected.Owner, "Check the owner is set");

            expected      = new StyleCollection();
            target.Styles = expected;

            StyleCollection actual = target.Styles;

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(actual.Owner, target, "Check the owner is reset");
        }
Exemplo n.º 17
0
        /**
         * Read document
         */

        internal override void OnDocumentRead()
        {
            StylesDocument stylesDoc;

            try
            {
                XmlDocument doc = ConvertStreamToXml(GetPackagePart().GetInputStream());
                stylesDoc = StylesDocument.Parse(doc, NamespaceManager);
                SetStyles(stylesDoc.Styles);
                latentStyles = new XWPFLatentStyles(ctStyles.latentStyles, this);
            }
            catch (XmlException e)
            {
                throw new POIXMLException("Unable to read styles", e);
            }
        }
Exemplo n.º 18
0
 public CT_Styles GetStyle()
 {
     PackagePart[] relatedByType;
     try
     {
         relatedByType = this.GetRelatedByType(XWPFRelation.STYLES.Relation);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException("get Style document part exception", ex);
     }
     if (relatedByType.Length != 1)
     {
         throw new InvalidOperationException("Expecting one Styles document part, but found " + (object)relatedByType.Length);
     }
     return(StylesDocument.Parse(relatedByType[0].GetInputStream()).Styles);
 }
        public void OwnerTest()
        {
            Document doc = new Document();

            doc.ID = "First Document";

            //doc.Styles should be initialized with the document as it's owner
            StyleCollection col = doc.Styles;

            Assert.AreEqual(doc, col.Owner);

            //A non IPDFComponent entry - make sure there are not cast exceptions
            Style unowned = new Style();

            col.Add(unowned);

            //An IPDFComponent entry - so should have it's parent value set
            StylesDocument styleDoc = new StylesDocument();

            col.Add(styleDoc);

            //parent should automatically be set on the styleDoc from the parent.
            Assert.AreEqual(doc, styleDoc.Parent);

            //Changing the owner should pass through
            Document other = new Document();

            other.ID  = "Other Document";
            col.Owner = other;
            Assert.AreEqual(other, styleDoc.Parent);

            //removing the time should not set the owner.
            col.Remove(styleDoc);
            Assert.IsNull(styleDoc.Parent);

            //multiple hierarchy
            StylesDocument inner = new StylesDocument();

            styleDoc.Styles.Add(inner);
            doc.Styles.Add(styleDoc);
            Assert.AreEqual(inner.Parent, styleDoc);
            Assert.AreEqual(other, styleDoc.Parent);
        }
Exemplo n.º 20
0
        /**
         * Read document
         */

        internal override void OnDocumentRead()
        {
            StylesDocument stylesDoc;

            try
            {
                Stream is1 = GetPackagePart().GetInputStream();
                stylesDoc    = StylesDocument.Parse(is1);
                ctStyles     = stylesDoc.Styles;
                latentStyles = new XWPFLatentStyles(ctStyles.latentStyles, this);
            }
            catch (XmlException e)
            {
                throw new POIXMLException("Unable to read styles", e);
            }
            // Build up all the style objects
            foreach (CT_Style style in ctStyles.GetStyleList())
            {
                listStyle.Add(new XWPFStyle(style, this));
            }
        }
Exemplo n.º 21
0
        protected internal override void Commit()
        {
            if (ctStyles == null)
            {
                throw new InvalidOperationException("Unable to write out styles that were never read in!");
            }

            /*XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
             * xmlOptions.SaveSyntheticDocumentElement=(new QName(CTStyles.type.Name.NamespaceURI, "styles"));
             * Dictionary<String,String> map = new Dictionary<String,String>();
             * map.Put("http://schemas.Openxmlformats.org/officeDocument/2006/relationships", "r");
             * map.Put("http://schemas.Openxmlformats.org/wordProcessingml/2006/main", "w");
             * xmlOptions.SaveSuggestedPrefixes=(map);*/
            PackagePart part = GetPackagePart();

            using (Stream out1 = part.GetOutputStream())
            {
                StylesDocument doc = new StylesDocument(ctStyles);
                doc.Save(out1);
            }
        }
        public void PDFStylesDocumentConstructorTest()
        {
            StylesDocument target = new StylesDocument();

            Assert.IsNotNull(target);
        }