/** * Add a new paragraph run to this shape * * @return created paragraph run */ public XSSFTextParagraph addNewTextParagraph() { CTTextBody txBody = ctShape.getTxBody(); CTTextParagraph p = txBody.addNewP(); XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); _paragraphs.add(paragraph); return paragraph; }
/** * Add a new paragraph run to this shape, set to the provided string * * @return created paragraph run */ public XSSFTextParagraph addNewTextParagraph(String text) { XSSFTextParagraph paragraph = addNewTextParagraph(); paragraph.addNewTextRun().setText(text); return paragraph; }
/** * @return the font to be used on bullet characters within a given paragraph */ public String getBulletFont(){ ParagraphPropertyFetcher<String> fetcher = new ParagraphPropertyFetcher<String>(getLevel()){ public boolean fetch(CTTextParagraphProperties props){ if(props.isSetBuFont()){ setValue(props.getBuFont().getTypeface()); return true; } return false; } }; fetchParagraphProperty(fetcher); return fetcher.getValue(); }
if (p.isBullet() && p.getText().length() > 0) { int level = Math.min(p.getLevel(), MAX_LEVELS - 1); if (p.isBulletAutoNumber()) { i = processAutoNumGroup(i, level, levelCount, out); } else { out.append('\t'); String character = p.getBulletCharacter(); out.append(character.length() > 0 ? character + " " : "- "); out.append(p.getText()); out.append(p.getText());
startAt = p.getBulletAutoNumberStart(); scheme = p.getBulletAutoNumberScheme(); if (levelCount.get(level) == 0) { levelCount.set(level, startAt == 0 ? 1 : startAt); out.append('\t'); if (p.getText().length() > 0) { out.append(getBulletPrefix(scheme, levelCount.get(level))); out.append(p.getText()); if (!(nextp.isBullet() && p.isBulletAutoNumber())) { break; // not an auto-number bullet if (nextp.getLevel() > level) { index = processAutoNumGroup(index + 1, nextp.getLevel(), levelCount, out); continue; // restart the loop given the new index } else if (nextp.getLevel() < level) { break; // changed level nextScheme = nextp.getBulletAutoNumberScheme(); nextStartAt = nextp.getBulletAutoNumberStart(); if (nextp.getText().length() > 0) { out.append(nextp.getText());
@Override public String toString(){ return "[" + getClass() + "]" + getText(); } }
/** * @return font size in points or -1 if font size is not set. */ public double getFontSize(){ double scale = 1; double size = XSSFFont.DEFAULT_FONT_SIZE; // default font size CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit(); if(afit != null) scale = (double)afit.getFontScale() / 100000; CTTextCharacterProperties rPr = getRPr(); if(rPr.isSetSz()){ size = rPr.getSz()*0.01; } return size * scale; }
/** * Set or unset this paragraph as a bullet point * * @param flag whether text in this paragraph has bullets */ public void setBullet(boolean flag) { if(isBullet() == flag) return; CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); if(!flag) { pr.addNewBuNone(); if(pr.isSetBuAutoNum()) pr.unsetBuAutoNum(); if(pr.isSetBuBlip()) pr.unsetBuBlip(); if(pr.isSetBuChar()) pr.unsetBuChar(); if(pr.isSetBuClr()) pr.unsetBuClr(); if(pr.isSetBuClrTx()) pr.unsetBuClrTx(); if(pr.isSetBuFont()) pr.unsetBuFont(); if(pr.isSetBuFontTx()) pr.unsetBuFontTx(); if(pr.isSetBuSzPct()) pr.unsetBuSzPct(); if(pr.isSetBuSzPts()) pr.unsetBuSzPts(); if(pr.isSetBuSzTx()) pr.unsetBuSzTx(); } else { if(pr.isSetBuNone()) pr.unsetBuNone(); if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial"); if(!pr.isSetBuAutoNum()) pr.addNewBuChar().setChar("\u2022"); } }
startAt = p.getBulletAutoNumberStart(); scheme = p.getBulletAutoNumberScheme(); if (levelCount.get(level) == 0) { levelCount.set(level, startAt == 0 ? 1 : startAt); out.append('\t'); if (p.getText().length() > 0) { out.append(getBulletPrefix(scheme, levelCount.get(level))); out.append(p.getText()); if (!(nextp.isBullet() && p.isBulletAutoNumber())) { break; // not an auto-number bullet if (nextp.getLevel() > level) { index = processAutoNumGroup(index + 1, nextp.getLevel(), levelCount, out); continue; // restart the loop given the new index } else if (nextp.getLevel() < level) { break; // changed level nextScheme = nextp.getBulletAutoNumberScheme(); nextStartAt = nextp.getBulletAutoNumberStart(); if (nextp.getText().length() > 0) { out.append(nextp.getText());
if (p.isBullet() && p.getText().length() > 0) { int level = Math.min(p.getLevel(), MAX_LEVELS - 1); if (p.isBulletAutoNumber()) { i = processAutoNumGroup(i, level, levelCount, out); } else { out.append('\t'); String character = p.getBulletCharacter(); out.append(character.length() > 0 ? character + " " : "- "); out.append(p.getText()); out.append(p.getText());
@Override public String toString(){ return "[" + getClass() + "]" + getText(); } }
/** * @return font size in points or -1 if font size is not set. */ public double getFontSize(){ double scale = 1; double size = XSSFFont.DEFAULT_FONT_SIZE; // default font size CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit(); if(afit != null) scale = (double)afit.getFontScale() / 100000; CTTextCharacterProperties rPr = getRPr(); if(rPr.isSetSz()){ size = rPr.getSz()*0.01; } return size * scale; }
/** * Set or unset this paragraph as a bullet point * * @param flag whether text in this paragraph has bullets */ public void setBullet(boolean flag) { if(isBullet() == flag) return; CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); if(!flag) { pr.addNewBuNone(); if(pr.isSetBuAutoNum()) pr.unsetBuAutoNum(); if(pr.isSetBuBlip()) pr.unsetBuBlip(); if(pr.isSetBuChar()) pr.unsetBuChar(); if(pr.isSetBuClr()) pr.unsetBuClr(); if(pr.isSetBuClrTx()) pr.unsetBuClrTx(); if(pr.isSetBuFont()) pr.unsetBuFont(); if(pr.isSetBuFontTx()) pr.unsetBuFontTx(); if(pr.isSetBuSzPct()) pr.unsetBuSzPct(); if(pr.isSetBuSzPts()) pr.unsetBuSzPts(); if(pr.isSetBuSzTx()) pr.unsetBuSzTx(); } else { if(pr.isSetBuNone()) pr.unsetBuNone(); if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial"); if(!pr.isSetBuAutoNum()) pr.addNewBuChar().setChar("\u2022"); } }
/** * @return the character to be used in place of the standard bullet point */ public String getBulletCharacter(){ ParagraphPropertyFetcher<String> fetcher = new ParagraphPropertyFetcher<String>(getLevel()){ public boolean fetch(CTTextParagraphProperties props){ if(props.isSetBuChar()){ setValue(props.getBuChar().getChar()); return true; } return false; } }; fetchParagraphProperty(fetcher); return fetcher.getValue(); }
protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) { this.drawing = drawing; this.ctShape = ctShape; _paragraphs = new ArrayList<>(); // initialize any existing paragraphs - this will be the default body // paragraph in a new shape, // or existing paragraphs that have been loaded from the file CTTextBody body = ctShape.getTxBody(); if (body == null) { _textBody = null; } else { _textBody = new XDDFTextBody(this, body); for (int i = 0; i < body.sizeOfPArray(); i++) { _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape)); } } }
/** * Set a single paragraph of text on the shape. Note this will replace all * existing paragraphs created on the shape. * * @param text * string representing the paragraph text */ public void setText(String text) { clearText(); addNewTextParagraph().addNewTextRun().setText(text); }
/** * * @return the color of bullet characters within a given paragraph. * A <code>null</code> value means to use the text font color. */ public Color getBulletFontColor(){ ParagraphPropertyFetcher<Color> fetcher = new ParagraphPropertyFetcher<Color>(getLevel()){ public boolean fetch(CTTextParagraphProperties props){ if(props.isSetBuClr()){ if(props.getBuClr().isSetSrgbClr()){ CTSRgbColor clr = props.getBuClr().getSrgbClr(); byte[] rgb = clr.getVal(); setValue(new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2])); return true; } } return false; } }; fetchParagraphProperty(fetcher); return fetcher.getValue(); }
XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); _paragraphs.add(paragraph);
/** * Add a new paragraph run to this shape, set to the provided string * * @return created paragraph run */ public XSSFTextParagraph addNewTextParagraph(String text) { XSSFTextParagraph paragraph = addNewTextParagraph(); paragraph.addNewTextRun().setText(text); return paragraph; }
/** * Returns the starting number if this paragraph has automatic numbered bullets, otherwise returns 0 */ public int getBulletAutoNumberStart() { ParagraphPropertyFetcher<Integer> fetcher = new ParagraphPropertyFetcher<Integer>(getLevel()){ public boolean fetch(CTTextParagraphProperties props){ if(props.isSetBuAutoNum() && props.getBuAutoNum().isSetStartAt()) { setValue(props.getBuAutoNum().getStartAt()); return true; } return false; } }; fetchParagraphProperty(fetcher); return fetcher.getValue() == null ? 0 : fetcher.getValue(); }