org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts Java Examples
The following examples show how to use
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts.
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: StyleUtils.java From poi-tl with Apache License 2.0 | 4 votes |
/** * 设置run的样式 * * @param run * @param style */ public static void styleRun(XWPFRun run, Style style) { if (null == run || null == style) return; String color = style.getColor(); String fontFamily = style.getFontFamily(); int fontSize = style.getFontSize(); Boolean bold = style.isBold(); Boolean italic = style.isItalic(); Boolean strike = style.isStrike(); Boolean underLine = style.isUnderLine(); Enum highlightColor = style.getHighlightColor(); int twips = style.getCharacterSpacing(); String vertAlign = style.getVertAlign(); CTRPr pr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr(); if (StringUtils.isNotBlank(color)) { // run.setColor(color); // issue 326 CTColor ctColor = pr.isSetColor() ? pr.getColor() : pr.addNewColor(); ctColor.setVal(color); if (ctColor.isSetThemeColor()) ctColor.unsetThemeColor(); } if (0 != fontSize) run.setFontSize(fontSize); if (StringUtils.isNotBlank(fontFamily)) { run.setFontFamily(fontFamily); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); fonts.setAscii(fontFamily); fonts.setHAnsi(fontFamily); fonts.setCs(fontFamily); fonts.setEastAsia(fontFamily); } if (null != highlightColor) { CTHighlight highlight = pr.isSetHighlight() ? pr.getHighlight() : pr.addNewHighlight(); STHighlightColor hColor = highlight.xgetVal(); if (hColor == null) { hColor = STHighlightColor.Factory.newInstance(); } STHighlightColor.Enum val = STHighlightColor.Enum.forString(highlightColor.toString()); if (val != null) { hColor.setStringValue(val.toString()); highlight.xsetVal(hColor); } } if (null != bold) run.setBold(bold); if (null != italic) run.setItalic(italic); if (null != strike) run.setStrikeThrough(strike); if (Boolean.TRUE.equals(underLine)) { run.setUnderline(UnderlinePatterns.SINGLE); } // in twentieths of a point if (0 != twips) run.setCharacterSpacing(20*twips); if (StringUtils.isNotBlank(vertAlign)) { run.setVerticalAlignment(vertAlign); } }
Example #2
Source File: StyleUtils.java From poi-tl with Apache License 2.0 | 4 votes |
/** * 设置w:rPr的样式 * * @param pr * @param fmtStyle */ public static void styleRpr(CTParaRPr pr, Style fmtStyle) { if (null == pr || null == fmtStyle) return; if (StringUtils.isNotBlank(fmtStyle.getColor())) { CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor(); color.setVal(fmtStyle.getColor()); } if (null != fmtStyle.isItalic()) { CTOnOff italic = pr.isSetI() ? pr.getI() : pr.addNewI(); italic.setVal(fmtStyle.isItalic() ? STOnOff.TRUE : STOnOff.FALSE); } if (null != fmtStyle.isBold()) { CTOnOff bold = pr.isSetB() ? pr.getB() : pr.addNewB(); bold.setVal(fmtStyle.isBold() ? STOnOff.TRUE : STOnOff.FALSE); } if (0 != fmtStyle.getFontSize()) { BigInteger bint = new BigInteger("" + fmtStyle.getFontSize()); CTHpsMeasure ctSize = pr.isSetSz() ? pr.getSz() : pr.addNewSz(); ctSize.setVal(bint.multiply(new BigInteger("2"))); } if (null != fmtStyle.isStrike()) { CTOnOff strike = pr.isSetStrike() ? pr.getStrike() : pr.addNewStrike(); strike.setVal(fmtStyle.isStrike() ? STOnOff.TRUE : STOnOff.FALSE); } if (StringUtils.isNotBlank(fmtStyle.getFontFamily())) { CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); String fontFamily = fmtStyle.getFontFamily(); fonts.setAscii(fontFamily); if (!fonts.isSetHAnsi()) { fonts.setHAnsi(fontFamily); } if (!fonts.isSetCs()) { fonts.setCs(fontFamily); } if (!fonts.isSetEastAsia()) { fonts.setEastAsia(fontFamily); } } }