/** * Set the baseline for both the superscript and subscript fonts. * <p> * The size is specified using a percentage. * Positive values indicate superscript, negative values indicate subscript. * </p> */ @SuppressWarnings("WeakerAccess") public void setBaselineOffset(double baselineOffset){ getRPr(true).setBaseline((int) baselineOffset * 1000); }
@Override public void setBold(boolean bold){ getRPr(true).setB(bold); }
@Override public void setItalic(boolean italic){ getRPr(true).setI(italic); }
@Override public void setUnderlined(boolean underline) { getRPr(true).setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE); }
@Override public void setStrikethrough(boolean strike) { getRPr(true).setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE); }
@Override public void setFontSize(Double fontSize){ CTTextCharacterProperties rPr = getRPr(true); if(fontSize == null) { if (rPr.isSetSz()) { rPr.unsetSz(); } } else { if (fontSize < 1.0) { throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize); } rPr.setSz((int)(100*fontSize)); } }
private CTTextFont getXmlObject(boolean create) { if (create) { return getCTTextFont(getRPr(true), true); } CharacterPropertyFetcher<CTTextFont> visitor = new CharacterPropertyFetcher<CTTextFont>(_p.getIndentLevel()){ @Override public boolean fetch(CTTextCharacterProperties props){ CTTextFont font = getCTTextFont(props, false); if (font == null) { return false; } setValue(font); return true; } }; fetchCharacterProperty(visitor); return visitor.getValue(); }
/** * Set the spacing between characters within a text run. * <p> * The spacing is specified in points. Positive values will cause the text to expand, * negative values to condense. * </p> * * @param spc character spacing in points. */ @SuppressWarnings("WeakerAccess") public void setCharacterSpacing(double spc){ CTTextCharacterProperties rPr = getRPr(true); if(spc == 0.0) { if(rPr.isSetSpc()) { rPr.unsetSpc(); } } else { rPr.setSpc((int)(100*spc)); } }
@Override public XSLFHyperlink getHyperlink(){ CTTextCharacterProperties rPr = getRPr(false); if (rPr == null) { return null; } CTHyperlink hl = rPr.getHlinkClick(); if (hl == null) { return null; } return new XSLFHyperlink(hl, _p.getParentShape().getSheet()); }
@Override public XSLFHyperlink createHyperlink(){ XSLFHyperlink hl = getHyperlink(); if (hl != null) { return hl; } CTTextCharacterProperties rPr = getRPr(true); return new XSLFHyperlink(rPr.addNewHlinkClick(), _p.getParentShape().getSheet()); }
/** * Insert a line break * * @return text run representing this line break ('\n') */ @SuppressWarnings("WeakerAccess") public XSLFTextRun addLineBreak(){ XSLFLineBreak run = new XSLFLineBreak(_p.addNewBr(), this); CTTextCharacterProperties brProps = run.getRPr(true); if(_runs.size() > 0){ // by default line break has the font size of the last text run CTTextCharacterProperties prevRun = _runs.get(_runs.size() - 1).getRPr(true); brProps.set(prevRun); // don't copy hlink properties if (brProps.isSetHlinkClick()) { brProps.unsetHlinkClick(); } if (brProps.isSetHlinkMouseOver()) { brProps.unsetHlinkMouseOver(); } } _runs.add(run); return run; }
private void fetchCharacterProperty(final CharacterPropertyFetcher<?> visitor){ XSLFTextShape shape = _p.getParentShape(); CTTextCharacterProperties rPr = getRPr(false); if (rPr != null && visitor.fetch(rPr)) { return; } if (shape.fetchShapeProperty(visitor)) { return; } if (_p.fetchThemeProperty(visitor)) { return; } _p.fetchMasterProperty(visitor); }
/** * Helper method for appending text and keeping paragraph and character properties. * The character properties are moved to the end paragraph marker */ /* package */ void clearButKeepProperties() { CTTextParagraph thisP = getXmlObject(); for (int i=thisP.sizeOfBrArray(); i>0; i--) { thisP.removeBr(i-1); } for (int i=thisP.sizeOfFldArray(); i>0; i--) { thisP.removeFld(i-1); } if (!_runs.isEmpty()) { int size = _runs.size(); XSLFTextRun lastRun = _runs.get(size-1); CTTextCharacterProperties cpOther = lastRun.getRPr(false); if (cpOther != null) { if (thisP.isSetEndParaRPr()) { thisP.unsetEndParaRPr(); } CTTextCharacterProperties cp = thisP.addNewEndParaRPr(); cp.set(cpOther); } for (int i=size; i>0; i--) { thisP.removeR(i-1); } _runs.clear(); } }
@Override public void setFontColor(PaintStyle color) { if (!(color instanceof SolidPaint)) { LOG.log(POILogger.WARN, "Currently only SolidPaint is supported!"); return; } SolidPaint sp = (SolidPaint)color; Color c = DrawPaint.applyColorTransform(sp.getSolidColor()); CTTextCharacterProperties rPr = getRPr(true); CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill(); XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr()); col.setColor(c); }
CTTextCharacterProperties props = getRPr(false); if (props == null) { return;
/** * @param italic whether this run of text is formatted as italic text */ public void setItalic(boolean italic){ getRPr().setI(italic); }
/** * Specifies whether a run of text will be formatted as strikethrough text. * * @param strike whether a run of text will be formatted as strikethrough text. */ public void setStrikethrough(boolean strike) { getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE); }
/** * Set the baseline for both the superscript and subscript fonts. * <p> * The size is specified using a percentage. * Positive values indicate superscript, negative values indicate subscript. * </p> */ @SuppressWarnings("WeakerAccess") public void setBaselineOffset(double baselineOffset){ getRPr(true).setBaseline((int) baselineOffset * 1000); }
@Override public XSLFHyperlink getHyperlink(){ CTTextCharacterProperties rPr = getRPr(false); if (rPr == null) { return null; } CTHyperlink hl = rPr.getHlinkClick(); if (hl == null) { return null; } return new XSLFHyperlink(hl, _p.getParentShape().getSheet()); }