/** * Get the run properties for the run. * * @param create If true, create the properties, if false, do not. * @return The run properties or null if there are no properties and create is false. */ private CTRPr getRunProperties(boolean create) { CTRPr pr = run.isSetRPr() ? run.getRPr() : null; if (create && pr == null) { pr = run.addNewRPr(); } return pr; }
/** * Get text color. The returned value is a string in the hex form "RRGGBB". */ public String getColor() { String color = null; if (run.isSetRPr()) { CTRPr pr = getRunProperties(false); if (pr != null && pr.isSetColor()) { CTColor clr = pr.getColor(); color = clr.xgetVal().getStringValue(); } } return color; }
/** * 重复样式 * * @param destRun 新建的run * @param srcRun 原始run */ public static void styleRun(XWPFRun destRun, XWPFRun srcRun) { if (null == destRun || null == srcRun) return; CTR ctr = srcRun.getCTR(); if (ctr.isSetRPr() && ctr.getRPr().isSetRStyle()){ String val = ctr.getRPr().getRStyle().getVal(); if (StringUtils.isNotBlank(val)) { CTRPr pr = destRun.getCTR().isSetRPr() ? destRun.getCTR().getRPr() : destRun.getCTR().addNewRPr(); CTString rStyle = pr.isSetRStyle() ? pr.getRStyle() : pr.addNewRStyle(); rStyle.setVal(val); } } if (Boolean.TRUE.equals(srcRun.isBold())) destRun.setBold(srcRun.isBold()); destRun.setColor(srcRun.getColor()); // destRun.setCharacterSpacing(srcRun.getCharacterSpacing()); if (StringUtils.isNotBlank(srcRun.getFontFamily())) destRun.setFontFamily(srcRun.getFontFamily()); int fontSize = srcRun.getFontSize(); if (-1 != fontSize) destRun.setFontSize(fontSize); if (Boolean.TRUE.equals(srcRun.isItalic())) destRun.setItalic(srcRun.isItalic()); if (Boolean.TRUE.equals(srcRun.isStrikeThrough())) destRun.setStrikeThrough(srcRun.isStrikeThrough()); destRun.setUnderline(srcRun.getUnderline()); }
if (StringUtils.isNotBlank(fontFamily)) { run.setFontFamily(fontFamily); CTRPr pr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr(); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); fonts.setAscii(fontFamily);
/** * Get the run properties for the run. * * @param create If true, create the properties, if false, do not. * @return The run properties or null if there are no properties and create is false. */ private CTRPr getRunProperties(boolean create) { CTRPr pr = run.isSetRPr() ? run.getRPr() : null; if (create && pr == null) { pr = run.addNewRPr(); } return pr; }
CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr();
/** * Specifies the font size which shall be applied to all non complex script * characters in the contents of this run when displayed. * <p/> * If this element is not present, the default value is to leave the value * applied at previous level in the style hierarchy. If this element is * never applied in the style hierarchy, then any appropriate font size may * be used for non complex script characters. * </p> * * @param size */ public void setFontSize(int size) { BigInteger bint=new BigInteger(""+size); CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTHpsMeasure ctSize = pr.isSetSz() ? pr.getSz() : pr.addNewSz(); ctSize.setVal(bint.multiply(new BigInteger("2"))); }
/** * Get text color. The returned value is a string in the hex form "RRGGBB". */ public String getColor() { String color = null; if (run.isSetRPr()) { CTRPr pr = run.getRPr(); if (pr.isSetColor()) { CTColor clr = pr.getColor(); color = clr.xgetVal().getStringValue(); } } return color; }
/** * Get text color. The returned value is a string in the hex form "RRGGBB". */ public String getColor() { String color = null; if (run.isSetRPr()) { CTRPr pr = getRunProperties(false); if (pr != null && pr.isSetColor()) { CTColor clr = pr.getColor(); color = clr.xgetVal().getStringValue(); } } return color; }
/** * Set text color. * @param rgbStr - the desired color, in the hex form "RRGGBB". */ public void setColor(String rgbStr) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor(); color.setVal(rgbStr); }
paragraph.insertNewRun(runNum + 1); XWPFRun newRun = paragraph.getRuns().get(runNum + 1); CTRPr rPr = newRun.getCTR().isSetRPr() ? newRun.getCTR().getRPr() : newRun.getCTR().addNewRPr(); rPr.set(run.getCTR().getRPr()); newRun.setText(textForLine);
/** * Specifies the fonts which shall be used to display the text contents of * this run. Specifies a font which shall be used to format all characters * in the ASCII range (0 - 127) within the parent run * * @param fontFamily */ public void setFontFamily(String fontFamily) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); fonts.setAscii(fontFamily); }
/** * This element specifies the amount by which text shall be raised or * lowered for this run in relation to the default baseline of the * surrounding non-positioned text. This allows the text to be repositioned * without altering the font size of the contents. * <p/> * If the val attribute is positive, then the parent run shall be raised * above the baseline of the surrounding text by the specified number of * half-points. If the val attribute is negative, then the parent run shall * be lowered below the baseline of the surrounding text by the specified * number of half-points. * </p> * <p/> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then the text shall not * be raised or lowered relative to the default baseline location for the * contents of this run. * </p> * * @param val */ public void setTextPosition(int val) { BigInteger bint=new BigInteger(""+val); CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTSignedHpsMeasure position = pr.isSetPosition() ? pr.getPosition() : pr.addNewPosition(); position.setVal(bint); }
/** * Whether the bold property shall be applied to all non-complex script * characters in the contents of this run when displayed in a document. * <p> * This formatting property is a toggle property, which specifies that its * behavior differs between its use within a style definition and its use as * direct formatting. When used as part of a style definition, setting this * property shall toggle the current state of that property as specified up * to this point in the hierarchy (i.e. applied to not applied, and vice * versa). Setting it to <code>false</code> (or an equivalent) shall * result in the current setting remaining unchanged. However, when used as * direct formatting, setting this property to true or false shall set the * absolute state of the resulting property. * </p> * <p> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then bold shall not be * applied to non-complex script characters. * </p> * * @param value <code>true</code> if the bold property is applied to * this run */ public void setBold(boolean value) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTOnOff bold = pr.isSetB() ? pr.getB() : pr.addNewB(); bold.setVal(value ? STOnOff.TRUE : STOnOff.FALSE); }
/** * Specifies that the contents of this run shall be displayed with a single * horizontal line through the center of the line. * <p/> * This formatting property is a toggle property, which specifies that its * behavior differs between its use within a style definition and its use as * direct formatting. When used as part of a style definition, setting this * property shall toggle the current state of that property as specified up * to this point in the hierarchy (i.e. applied to not applied, and vice * versa). Setting it to false (or an equivalent) shall result in the * current setting remaining unchanged. However, when used as direct * formatting, setting this property to true or false shall set the absolute * state of the resulting property. * </p> * <p/> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then strikethrough shall * not be applied to the contents of this run. * </p> * * @param value <code>true</code> if the strike property is applied to * this run */ public void setStrike(boolean value) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTOnOff strike = pr.isSetStrike() ? pr.getStrike() : pr.addNewStrike(); strike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE); }
/** * Whether the bold property shall be applied to all non-complex script * characters in the contents of this run when displayed in a document * <p/> * <p/> * This formatting property is a toggle property, which specifies that its * behavior differs between its use within a style definition and its use as * direct formatting. When used as part of a style definition, setting this * property shall toggle the current state of that property as specified up * to this point in the hierarchy (i.e. applied to not applied, and vice * versa). Setting it to <code>false</code> (or an equivalent) shall * result in the current setting remaining unchanged. However, when used as * direct formatting, setting this property to true or false shall set the * absolute state of the resulting property. * </p> * <p/> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then bold shall not be * applied to non-complex script characters. * </p> * * @param value <code>true</code> if the italic property is applied to * this run */ public void setItalic(boolean value) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTOnOff italic = pr.isSetI() ? pr.getI() : pr.addNewI(); italic.setVal(value ? STOnOff.TRUE : STOnOff.FALSE); }
/** * Specifies the alignment which shall be applied to the contents of this * run in relation to the default appearance of the run's text. This allows * the text to be repositioned as subscript or superscript without altering * the font size of the run properties. * <p/> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then the text shall not * be subscript or superscript relative to the default baseline location for * the contents of this run. * </p> * * @param valign * @see VerticalAlign */ public void setSubscript(VerticalAlign valign) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTVerticalAlignRun ctValign = pr.isSetVertAlign() ? pr.getVertAlign() : pr.addNewVertAlign(); ctValign.setVal(STVerticalAlignRun.Enum.forInt(valign.getValue())); }
/** * Specifies that the contents of this run should be displayed along with an * underline appearing directly below the character heigh * <p/> * <p/> * If this element is not present, the default value is to leave the * formatting applied at previous level in the style hierarchy. If this * element is never applied in the style hierarchy, then an underline shall * not be applied to the contents of this run. * </p> * * @param value - * underline type * @see UnderlinePatterns : all possible patterns that could be applied */ public void setUnderline(UnderlinePatterns value) { CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr(); CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU(); underline.setVal(STUnderline.Enum.forInt(value.getValue())); }
CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr();
if (tmpR.getCTR().isSetRPr()) { CTRPr tmpRPr = tmpR.getCTR().getRPr(); if (tmpRPr.isSetRFonts()) { CTFonts tmpFonts = tmpRPr.getRFonts(); CTRPr cellRPr = cellR.getCTR().isSetRPr() ? cellR.getCTR().getRPr() : cellR.getCTR().addNewRPr(); CTFonts cellFonts = cellRPr.isSetRFonts() ? cellRPr.getRFonts() : cellRPr.addNewRFonts(); cellFonts.setAscii(tmpFonts.getAscii());