本文整理汇总了Java中org.docx4j.wml.Style类的典型用法代码示例。如果您正苦于以下问题:Java Style类的具体用法?Java Style怎么用?Java Style使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Style类属于org.docx4j.wml包,在下文中一共展示了Style类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTblStyle_AllSilent
import org.docx4j.wml.Style; //导入依赖的package包/类
@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, STYLE_NAME);
this.assertSz(s, 20);
// Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==20);
}
示例2: testTblStyle_AllSilent
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* 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, STYLE_NAME);
this.assertSz(s, 40); // nothing explicit to override with, so use table val
}
示例3: testTblStyle_BasedOnNormal
import org.docx4j.wml.Style; //导入依赖的package包/类
@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);
}
示例4: testTblStyle_BasedOnNormal
import org.docx4j.wml.Style; //导入依赖的package包/类
@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);
}
示例5: extractTextFromParagraph
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* Extract text from the paragraph and append it to the provided {@link StringBuilder}.
*
* @param stringBuilder
* The {@link StringBuilder} to append text to.
* @param formattingData
* Formatting data map to update with ranges of paragraph that are formatted.
* @param paragraph
* The docx4j paragraph object
* @param paragraphProperties
* The docx4j paragraph properties
* @param styleMap
* The extracted styles from the main document
* @param mainDoc
* The main document object
*/
private void extractTextFromParagraph(final StringBuilder stringBuilder, final Map<FormattingType, Set<TextRange>> formattingData,
final P paragraph, final PPr paragraphProperties, final Map<String, Style> styleMap, final MainDocumentPart mainDoc) {
for (final Object paragraphChild : paragraph.getContent()) {
if (paragraphChild instanceof R) {
final R run = (R) paragraphChild;
for (final Object runChild : run.getContent()) {
if (runChild instanceof JAXBElement && ((JAXBElement<?>) runChild).getDeclaredType() == Text.class) {
final String childText = ((Text) ((JAXBElement<?>) runChild).getValue()).getValue();
final TextRange childRange = new TextRange(stringBuilder.length(), stringBuilder.length() + childText.length());
stringBuilder.append(childText);
extractFormattingData(run, childRange, formattingData, paragraphProperties, styleMap, mainDoc);
}
}
}
}
}
示例6: extractFormattingData
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* Updates the provided formatting data map based on the provided data about the text run.
*
* @param run
* The provided text run
* @param childRange
* The text range this run covers
* @param formattingData
* The formatting data map to update
* @param paragraphProperties
* The docx4j paragraph properties object
* @param styleMap
* The extracted styles of the main document.
* @param mainDoc
* The main document object
*/
private void extractFormattingData(final R run, final TextRange childRange, final Map<FormattingType, Set<TextRange>> formattingData,
final PPr paragraphProperties, final Map<String, Style> styleMap, final MainDocumentPart mainDoc) {
final RPr runProperties = run.getRPr();
final BooleanDefaultTrue isBold = getRunProperty(runProperties, paragraphProperties, RPr::getB, styleMap, mainDoc);
final BooleanDefaultTrue isItalics = getRunProperty(runProperties, paragraphProperties, RPr::getI, styleMap, mainDoc);
final U underlining = getRunProperty(runProperties, paragraphProperties, RPr::getU, styleMap, mainDoc);
if (isBold != null && isBold.isVal()) {
formattingData.get(FormattingType.BOLD).add(childRange);
}
if (isItalics != null && isItalics.isVal()) {
formattingData.get(FormattingType.ITALICS).add(childRange);
}
if (underlining != null && underlining.getVal() != UnderlineEnumeration.NONE) {
formattingData.get(FormattingType.UNDERLINE).add(childRange);
}
}
示例7: generateStyles
import org.docx4j.wml.Style; //导入依赖的package包/类
private List<Style> generateStyles() {
final List<Style> styles = new ArrayList<>();
styles.add(createParagraphStyle(TITLE_STYLE, paragraphProperties(headingSpacing(), lowerBorder(), centerAligned(), joinNext()),
runProperties(SERIF_FONT_NAME, 28, notBold())));
styles.add(createParagraphStyle(HEADING1_STYLE, paragraphProperties(headingSpacing(), lowerBorder(), leftAligned(), joinNext()),
runProperties(SERIF_FONT_NAME, 22, notBold())));
styles.add(createParagraphStyle(HEADING2_STYLE, paragraphProperties(headingSpacing(), noBorder(), leftAligned(), joinNext()),
runProperties(SANS_SERIF_FONT_NAME, 15, bold())));
styles.add(createParagraphStyle(TEXT_STYLE, paragraphProperties(bodySpacing(), noBorder(), leftAligned(), noJoinNext()),
runProperties(SANS_SERIF_FONT_NAME, 12, notBold())));
styles.add(createParagraphStyle(KEY_VALUE_STYLE, paragraphProperties(noSpacing(), noBorder(), leftAligned(), noJoinNext()),
runProperties(SANS_SERIF_FONT_NAME, 12, notBold())));
styles.add(createCharacterStyle(KEY_CHARACTER_STYLE, runProperties(SANS_SERIF_FONT_NAME, 12, bold())));
return styles;
}
示例8: addNumberingToStyle
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* Adds numbering to the style
* @param style
* @param numId the id of numbering definition instance
* @param ilvl the level
*/
static void addNumberingToStyle(Style style, BigInteger numId, BigInteger ilvl) {
ObjectFactory factory = Context.getWmlObjectFactory();
//Create and add <w:pPr> to style
PPr ppr = factory.createPPr();
style.setPPr(ppr);
//Create and add <w:numPr>
NumPr numPr = factory.createPPrBaseNumPr();
ppr.setNumPr(numPr);
// The <w:ilvl> element
Ilvl ilvlElement = factory.createPPrBaseNumPrIlvl();
numPr.setIlvl(ilvlElement);
ilvlElement.setVal(ilvl);
// The <w:numId> element
NumId numIdElement = factory.createPPrBaseNumPrNumId();
numPr.setNumId(numIdElement);
numIdElement.setVal(numId);
}
示例9: setStyleMLA
import org.docx4j.wml.Style; //导入依赖的package包/类
void setStyleMLA(Style style, boolean justify) {
ObjectFactory factory = Context.getWmlObjectFactory();
PPr paragraphProperties = factory.createPPr();
Jc justification = factory.createJc();
if (justify)
justification.setVal(JcEnumeration.BOTH);
else
justification.setVal(JcEnumeration.CENTER);
paragraphProperties.setJc(justification);
Spacing sp = factory.createPPrBaseSpacing();
sp.setAfter(BigInteger.ZERO);
sp.setBefore(BigInteger.ZERO);
sp.setLine(BigInteger.valueOf(482));
sp.setLineRule(STLineSpacingRule.AUTO);
paragraphProperties.setSpacing(sp);
style.setPPr(paragraphProperties);
RPr rpr = new RPr();
changeFont(rpr, "Times New Roman");
style.setRPr(rpr);
}
示例10: alterStyleSheet
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* 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);
}
}
}
示例11: alterNormalStyle
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* 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);
}
示例12: alterHeading2Style
import org.docx4j.wml.Style; //导入依赖的package包/类
/**
* 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);
}
示例13: getRunPropertiesAndRemoveThemeInfo
import org.docx4j.wml.Style; //导入依赖的package包/类
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;
}
示例14: testTblStyle_BasedOn_Normal12
import org.docx4j.wml.Style; //导入依赖的package包/类
@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);
}
示例15: assertSz
import org.docx4j.wml.Style; //导入依赖的package包/类
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");
}
}