org.docx4j.wml.Style Java Examples
The following examples show how to use
org.docx4j.wml.Style.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PStyle11PtInTableOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testTblStyle_AllSilent() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); // // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified! // // So we need to delete that! // wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults(); // Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults"); // dd.getRPr().setSz(null); // dd.getRPr().setSzCs(null); ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #2
Source File: ChangingTheStyleSheet.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * This method alters the default style sheet that is part of each document. * * To do this, we first retrieve the style sheet from the package and then * get the Styles object from it. From this object, we get the list of actual * styles and iterate over them. * We check against all styles we want to alter and apply the alterations if * applicable. * * @param wordMLPackage */ public static void alterStyleSheet() { StyleDefinitionsPart styleDefinitionsPart = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart(); Styles styles = styleDefinitionsPart.getJaxbElement(); List<Style> stylesList = styles.getStyle(); for (Style style : stylesList) { if (style.getStyleId().equals("Normal")) { alterNormalStyle(style); } else if (style.getStyleId().equals("Heading2")) { alterHeading2Style(style); } else if (style.getStyleId().equals("Heading1") || style.getStyleId().equals("Heading3") || style.getStyleId().equals("Title") || style.getStyleId().equals("Subtitle")) { getRunPropertiesAndRemoveThemeInfo(style); } } }
Example #3
Source File: PStyle12PtInTableGridOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 6 votes |
/** * table says 40, Normal says nothing. * don't override table style * @throws Exception */ @Test public void testTblStyle_AllSilent() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); // // NB PropertyResolver puts 10pt in DocDefaults, if nothing is specified! setSetting(wordMLPackage, OVERRIDE); // resulting text in table is 40pt wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); this.assertSz(s, 40); }
Example #4
Source File: PStyle12PtInTableNormalOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 6 votes |
@Test public void testTblStyle_AllSilent() throws Exception { // Result is to use the implicit 10pt WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); // NB PropertyResolver puts 10pt in DocDefaults, if nothing is specified! ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); this.assertSz(s, 20); // Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==20); }
Example #5
Source File: PStyle11PtInTableOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test @Ignore public void testTblStyle_BasedOnNormal() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==22); }
Example #6
Source File: PStyle11PtInTableOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOn_Normal12() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #7
Source File: PStyle11PtInTableOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOnNormal() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #8
Source File: PStyle11PtInTableOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_AllSilent() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); // // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified! // // So we need to delete that! // wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults(); // Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults"); // dd.getRPr().setSz(null); // dd.getRPr().setSzCs(null); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); //Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==40); if (s==null) { log.warn("missing style " + getStyleName()); Assert.fail("missing style " + getStyleName()); } else { this.assertSz(s, 40); } }
Example #9
Source File: PStyle12PtInTableGridOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOn_Normal12() throws Exception { // A style basedOn Normal is ignored where the font size comes from Normal WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #10
Source File: PStyle12PtInTableGridOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOnNormal() throws Exception { // A style basedOn Normal is honoured, provided it (not Normal) contributes the font size WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==24); }
Example #11
Source File: PStyle11PtInTableOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test @Ignore public void testTblStyle_BasedOn_Normal11() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==22); }
Example #12
Source File: PStyle12PtInTableNormalOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOnNormal() throws Exception { // A style basedOn Normal is honoured, provided it (not Normal) contributes the font size WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableNormal-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #13
Source File: PStyleTableAbstract.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
protected Style getStyle(WordprocessingMLPackage wordMLPackage, String stylename) throws Docx4JException { for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if (stylename.equals(s.getStyleId())) { return s; } } return null; }
Example #14
Source File: PStyle12PtInTableNormalOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOnNormal() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableNormal-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #15
Source File: PStyleTableAbstract.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
protected void assertSz(Style s, int expectedResult) { if (s.getRPr()!=null && s.getRPr().getSz()!=null && s.getRPr().getSz().getVal()!=null) { int actualResult = s.getRPr().getSz().getVal().intValue(); Assert.assertTrue(actualResult==expectedResult); } else if (s.getRPr()!=null && s.getRPr().getSz()==null) { log.warn("null Sz: " + XmlUtils.marshaltoString(s)); Assert.fail("null Sz"); } }
Example #16
Source File: PStyle12PtInTableGridOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOn_Normal12() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT); }
Example #17
Source File: PStyle12PtInTableGridOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void testTblStyle_BasedOnNormal() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableGrid-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==24); }
Example #18
Source File: PStyle12PtInTableGridOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
/** * table says 40, p says nothing * should override, but nothing explicit, so we don't * * @throws Exception */ @Test public void testTblStyle_AllSilent() throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); // // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified! // // So we need to delete that! // wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults(); // Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults"); // dd.getRPr().setSz(null); // dd.getRPr().setSzCs(null); setSetting(wordMLPackage, OVERRIDE); // table style should get overridden wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); this.assertSz(s, 40); // nothing explicit to override with, so use table val }
Example #19
Source File: ChangingTheStyleSheet.java From docx4j-template with Apache License 2.0 | 5 votes |
private static RPr getRunPropertiesAndRemoveThemeInfo(Style style) { // We only want to change some settings, so we get the existing run // properties from the style. RPr rpr = style.getRPr(); removeThemeFontInformation(rpr); return rpr; }
Example #20
Source File: ChangingTheStyleSheet.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * For this style, we get the existing run properties from the style and * remove the theme font information from them. Then we also remove the bold * styling, change the font size (half-points) and add an underline. */ private static void alterHeading2Style(Style style) { RPr rpr = getRunPropertiesAndRemoveThemeInfo(style); removeBoldStyle(rpr); changeFontSize(rpr, 24); addUnderline(rpr); }
Example #21
Source File: ChangingTheStyleSheet.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * First we create a run properties object as we want to remove nearly all of * the existing styling. Then we change the font and font size and set the * run properties on the given style. As in previous examples, the font size * is defined to be in half-point size. */ private static void alterNormalStyle(Style style) { // we want to change (or remove) almost all the run properties of the // normal style, so we create a new one. RPr rpr = new RPr(); changeFontToArial(rpr); changeFontSize(rpr, 20); style.setRPr(rpr); }
Example #22
Source File: PStyle12PtInTableNormalOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@Test public void testTblStyle_BasedOn_Normal12() throws Exception { // Compat setting says Paragraph style overrides table style WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableNormal-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); this.assertSz(ours, EXPECTED_RESULT); }
Example #23
Source File: PStyle12PtInTableNormalOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@Test public void testTblStyle_BasedOn_Normal12() throws Exception { // A style basedOn Normal is ignored where the font size comes from Normal WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) ); // Use our style! List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true); PPr ppr = Context.getWmlObjectFactory().createPPr(); ((P)xpathResults.get(0)).setPPr(ppr); PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle(); ps.setVal("testStyle"); ppr.setPStyle(ps); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); ParagraphStylesInTableFix.process(wordMLPackage); // // Revert style and save: // ppr.setPStyle(ps); // doesn't work - wrong ref! // wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); Style ours = null; for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) { if ("testStyle-TableNormal-BR".equals(s.getStyleId())) { ours = s; break; } } // Style s = getStyle(wordMLPackage, STYLE_NAME); assertSz(ours, EXPECTED_RESULT); }
Example #24
Source File: PStyle12PtInTableNormalOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@Test public void testTblStyle_AllSilent() throws Exception { // Result is to use the implicit 10pt WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styles_no_font_sz) ); setSetting(wordMLPackage, OVERRIDE); wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); // TODO make this change in other AllSilent tests // // NB PropertyResolver puts 10pt in DocDefaults, if nothing is specified! ParagraphStylesInTableFix.process(wordMLPackage); Style s = getStyle(wordMLPackage, getStyleName()); this.assertSz(s, 20); }
Example #25
Source File: PStyleTableAbstract.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
protected WordprocessingMLPackage test(String documentXml, String styleXml, int expectedResult) throws Exception { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().setContents( (Document)XmlUtils.unmarshalString(documentXml) ); wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents( (Styles)XmlUtils.unmarshalString(styleXml) ); setSetting(wordMLPackage, OVERRIDE); if (OVERRIDE) { log.info("table style should get overridden by Normal"); } else { log.info("table style should NOT get overridden by Normal"); } /* Where Normal is basedOn our DocDefaults style, * Word *does* override the table style! * * It doesn't if there is just a normal DocDefaults element * which sets the font size. And that is what we should be testing here. * * So save the docx * * Note that createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified, * so we save the docx here before that method has run. * * TODO 2016 01 18 revisit this, since createVirtualStylesForDocDefaults has gone now * (its only in StyleTree) */ wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx")); // this.saveDocx(wordMLPackage, null); ParagraphStylesInTableFix.process(wordMLPackage); // // Now remove the style, and save the docx, to check in Word // Style s = getStyle(wordMLPackage, STYLE_NAME); // wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle().remove(s); // // getStyle(wordMLPackage, STYLE_NAME).setBasedOn(null); // // this.saveDocx(wordMLPackage, null); Style s = getStyle(wordMLPackage, getStyleName()); if (s==null) { log.warn("missing style " + getStyleName()); Assert.fail("missing style " + getStyleName()); } else { assertSz(s, expectedResult); } return wordMLPackage; }
Example #26
Source File: PStyleTableAbstract.java From docx4j-export-FO with Apache License 2.0 | 3 votes |
protected void assertSzNull(Style s) { if (s.getRPr()==null) { } else if (s.getRPr()!=null) { Assert.assertNull(s.getRPr().getSz()); } }