Пример #1
0
        public void TestEasyAccessToStyles()
        {
            XWPFDocument doc    = XWPFTestDataSamples.OpenSampleDocument("SampleDoc.docx");
            XWPFStyles   styles = doc.GetStyles();

            Assert.IsNotNull(styles);

            // Has 3 paragraphs on page one, a break, and 3 on page 2
            Assert.AreEqual(7, doc.Paragraphs.Count);

            // Check the first three have no run styles, just default paragraph style
            for (int i = 0; i < 3; i++)
            {
                XWPFParagraph p = doc.Paragraphs[(i)];
                Assert.AreEqual(null, p.Style);
                Assert.AreEqual(null, p.StyleID);
                Assert.AreEqual(1, p.Runs.Count);

                XWPFRun r = p.Runs[(0)];
                Assert.AreEqual(null, r.GetColor());
                Assert.AreEqual(null, r.FontFamily);
                Assert.AreEqual(null, r.FontName);
                Assert.AreEqual(-1, r.FontSize);
            }

            // On page two, has explicit styles, but on Runs not on
            //  the paragraph itself
            for (int i = 4; i < 7; i++)
            {
                XWPFParagraph p = doc.Paragraphs[(i)];
                Assert.AreEqual(null, p.Style);
                Assert.AreEqual(null, p.StyleID);
                Assert.AreEqual(1, p.Runs.Count);

                XWPFRun r = p.Runs[(0)];
                Assert.AreEqual("Arial Black", r.FontFamily);
                Assert.AreEqual("Arial Black", r.FontName);
                Assert.AreEqual(16, r.FontSize);
                Assert.AreEqual("548DD4", r.GetColor());
            }

            // Check the document styles
            // Should have a style defined for each type
            Assert.AreEqual(4, styles.NumberOfStyles);
            Assert.IsNotNull(styles.GetStyle("Normal"));
            Assert.IsNotNull(styles.GetStyle("DefaultParagraphFont"));
            Assert.IsNotNull(styles.GetStyle("TableNormal"));
            Assert.IsNotNull(styles.GetStyle("NoList"));

            // We can't do much yet with latent styles
            Assert.AreEqual(137, styles.LatentStyles.NumberOfStyles);

            // Check the default styles
            Assert.IsNotNull(styles.DefaultRunStyle);
            Assert.IsNotNull(styles.DefaultParagraphStyle);

            Assert.AreEqual(11, styles.DefaultRunStyle.FontSize);
            Assert.AreEqual(200, styles.DefaultParagraphStyle.SpacingAfter);
        }
Пример #2
0
        public void Test52449()
        {
            XWPFDocument doc    = XWPFTestDataSamples.OpenSampleDocument("52449.docx");
            XWPFStyles   styles = doc.GetStyles();

            Assert.IsNotNull(styles);

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(doc);

            styles = docIn.GetStyles();
            Assert.IsNotNull(styles);
        }
Пример #3
0
        public void TestLanguages()
        {
            XWPFDocument docOut = new XWPFDocument();
            XWPFStyles   styles = docOut.CreateStyles();

            styles.SetEastAsia("Chinese");

            styles.SetSpellingLanguage("English");

            CT_Fonts def = new CT_Fonts();

            styles.SetDefaultFonts(def);
        }
Пример #4
0
        public void TestSetStyles_Bug57254()
        {
            XWPFDocument docOut = new XWPFDocument();
            XWPFStyles   styles = docOut.CreateStyles();

            CT_Styles ctStyles   = new CT_Styles();
            String    strStyleId = "headline1";
            CT_Style  ctStyle    = ctStyles.AddNewStyle();

            ctStyle.styleId = (/*setter*/ strStyleId);
            styles.SetStyles(ctStyles);

            Assert.IsTrue(styles.StyleExist(strStyleId));

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            styles = docIn.GetStyles();
            Assert.IsTrue(styles.StyleExist(strStyleId));
        }
Пример #5
0
        public void TestAddStylesToDocument()
        {
            XWPFDocument docOut = new XWPFDocument();
            XWPFStyles   styles = docOut.CreateStyles();

            String   strStyleId = "headline1";
            CT_Style ctStyle    = new CT_Style();

            ctStyle.styleId = (strStyleId);
            XWPFStyle s = new XWPFStyle(ctStyle);

            styles.AddStyle(s);

            Assert.IsTrue(styles.StyleExist(strStyleId));

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            styles = docIn.GetStyles();
            Assert.IsTrue(styles.StyleExist(strStyleId));
        }
Пример #6
0
        public void TestGetUsedStyles()
        {
            XWPFDocument     sampleDoc         = XWPFTestDataSamples.OpenSampleDocument("Styles.docx");
            List <XWPFStyle> testUsedStyleList = new List <XWPFStyle>();
            XWPFStyles       styles            = sampleDoc.GetStyles();
            XWPFStyle        style             = styles.GetStyle("berschrift1");

            testUsedStyleList.Add(style);
            testUsedStyleList.Add(styles.GetStyle("Standard"));
            testUsedStyleList.Add(styles.GetStyle("berschrift1Zchn"));
            testUsedStyleList.Add(styles.GetStyle("Absatz-Standardschriftart"));
            style.HasSameName(style);

            List <XWPFStyle> usedStyleList = styles.GetUsedStyleList(style);

            //Assert.AreEqual(usedStyleList, testUsedStyleList);
            Assert.AreEqual(usedStyleList.Count, testUsedStyleList.Count);
            for (int i = 0; i < usedStyleList.Count; i++)
            {
                Assert.AreEqual(usedStyleList[i], testUsedStyleList[i]);
            }
        }
Пример #7
0
        /**
         * constructor
         * @param style
         * @param styles
         */

        public XWPFStyle(CT_Style style, XWPFStyles styles)
        {
            this.ctStyle = style;
            this.styles  = styles;
        }
Пример #8
0
 public XWPFLatentStyles(CT_LatentStyles latentStyles, XWPFStyles styles)
 {
     this.latentStyles = latentStyles;
     this.styles       = styles;
 }