text = toInternalString(text); assert(!paragraphs.isEmpty() && !paragraphs.get(0).getTextRuns().isEmpty()); HSLFTextRun htr = htp.getTextRuns().get(htp.getTextRuns().size() - 1); boolean lastParaEmpty = lastRunEmpty && (htp.getTextRuns().size() == 1); TextPropCollection tpc = htp.getParagraphStyle(); HSLFTextParagraph prevHtp = htp; htp = new HSLFTextParagraph(htp._headerAtom, htp._byteAtom, htp._charAtom, paragraphs); htp.getParagraphStyle().copy(tpc); htp.setParentShape(prevHtp.getParentShape()); htp.setShapeId(prevHtp.getShapeId()); htp.supplySheet(prevHtp.getSheet()); paragraphs.add(htp); htr = new HSLFTextRun(htp); htr.getCharacterStyle().copy(tpc); htp.addTextRun(htr); storeText(paragraphs);
boolean nextBullet = htp.isBullet(); List<HSLFTextRun> textRuns = htp.getTextRuns(); String firstLine = removePBreak(textRuns.get(0).getRawText()); boolean showBullet = (isBullet && (textRuns.size() > 1 || !"".equals(firstLine)));
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (HSLFTextRun r : getTextRuns()) { sb.append(r.getRawText()); } return toExternalString(sb.toString(), getRunType()); }
public static String getText(List<HSLFTextParagraph> paragraphs) { assert (!paragraphs.isEmpty()); String rawText = getRawText(paragraphs); return toExternalString(rawText, paragraphs.get(0).getRunType()); }
@Override public void setBulletStyle(Object... styles) { if (styles.length == 0) { setBullet(false); } else { setBullet(true); for (Object ostyle : styles) { if (ostyle instanceof Number) { setBulletSize(((Number)ostyle).doubleValue()); } else if (ostyle instanceof Color) { setBulletColor((Color)ostyle); } else if (ostyle instanceof Character) { setBulletChar((Character)ostyle); } else if (ostyle instanceof String) { setBulletFont((String)ostyle); } else if (ostyle instanceof AutoNumberingScheme) { throw new HSLFException("setting bullet auto-numberin scheme for HSLF not supported ... yet"); } } } }
private static String collectText(List<List<HSLFTextParagraph>> paragraphs, String title) { return paragraphs.stream() .flatMap(Collection::stream) .flatMap(paragraph -> paragraph.getTextRuns().stream()) .map(HSLFTextRun::getRawText) .filter(rawText -> !title.equals(rawText)) .collect(Collectors.joining()); } }
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slide = ppt.createSlide(); HSLFTextBox shape = new HSLFTextBox(); HSLFTextParagraph rt = shape.getTextParagraphs().get(0); rt.getTextRuns().get(0).setFontSize(42d); rt.setBullet(true); rt.setIndent(0d); //bullet offset rt.setLeftMargin(50d); //text offset (should be greater than bullet offset) rt.setBulletChar('\u263A'); //bullet character shape.setText( "January\r" + "February\r" + "March\r" + "April"); slide.addShape(shape); shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide slide.addShape(shape); try (FileOutputStream out = new FileOutputStream("bullets.ppt")) { ppt.write(out); } } } }
final String rawText = toInternalString(getRawText(paragraphs)); TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom; StyleTextPropAtom styleAtom = findStyleAtomPresent(headerAtom, rawText.length()); ptpc = para.getParagraphStyle(); ptpc.updateTextSize(0); if (!ptpc.equals(lastPTPC)) { lastPTPC.copy(ptpc); for (HSLFTextRun tr : para.getTextRuns()) { rtpc = tr.getCharacterStyle(); rtpc.updateTextSize(0); for (Record r : paragraphs.get(0).getRecords()) { if (r instanceof TextSpecInfoAtom) { ((TextSpecInfoAtom) r).setParentSize(rawText.length() + 1);
for (HSLFTextParagraph htp : _paragraphs) { int runsLen = 0; for (HSLFTextRun htr : htp.getTextRuns()) { runsLen += htr.getLength(); charStyle = sta.addCharacterTextPropCollection(htr.getLength()); htp.setParagraphStyle(paraStyle); HSLFTextParagraph htp = new HSLFTextParagraph(tha, tba, tca, _paragraphs); htp.setParagraphStyle(paraStyle); htp.setParentShape(this); _paragraphs.add(htp); htr.setCharacterStyle(charStyle); htr.setText(text); htp.addTextRun(htr);
/** * Sets (overwrites) the current text. * Uses the properties of the first paragraph / textrun * * @param text the text string used by this object. */ public static HSLFTextRun setText(List<HSLFTextParagraph> paragraphs, String text) { // check paragraphs assert(!paragraphs.isEmpty() && !paragraphs.get(0).getTextRuns().isEmpty()); Iterator<HSLFTextParagraph> paraIter = paragraphs.iterator(); HSLFTextParagraph htp = paraIter.next(); // keep first assert (htp != null); while (paraIter.hasNext()) { paraIter.next(); paraIter.remove(); } Iterator<HSLFTextRun> runIter = htp.getTextRuns().iterator(); if (runIter.hasNext()) { HSLFTextRun htr = runIter.next(); htr.setText(""); while (runIter.hasNext()) { runIter.next(); runIter.remove(); } } else { HSLFTextRun trun = new HSLFTextRun(htp); htp.addTextRun(trun); } return appendText(paragraphs, text, false); }
for (int j = 0; j < txt2[i].length; j++) { HSLFTableCell cell = table2.getCell(i, j); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0); rt.setFontSize(10d); rt.setFontFamily("Arial"); cell.setHorizontalCentered(true); } else { rt.getTextParagraph().setBullet(true); rt.setFontSize(12d); rt.getTextParagraph().setTextAlign(TextAlign.LEFT); cell.setHorizontalCentered(false);
MasterTextPropAtom indents = null; for (Record r : getRecords(records, recordIdx, null)) { long rt = r.getRecordType(); if (RecordTypes.TextHeaderAtom.typeID == rt) { StyleTextPropAtom styles = findStyleAtomPresent(header, rawText.length()); HSLFTextParagraph tpara = new HSLFTextParagraph(header, tbytes, tchars, paragraphs); paragraphs.add(tpara); tpara._ruler = ruler; tpara.getParagraphStyle().updateTextSize(para.length()); tpara.addTextRun(trun); trun.setText(para); applyCharacterStyles(paragraphs, styles.getCharacterStyles()); applyParagraphStyles(paragraphs, styles.getParagraphStyles()); if (indents != null) { applyParagraphIndents(paragraphs, indents.getIndents());
for (HSLFTextParagraph textPara : textLevel1) { final ParserField parserField; switch (textPara.getRunType()) { case TextHeaderAtom.TITLE_TYPE: case TextHeaderAtom.CENTER_TITLE_TYPE: for (HSLFTextRun textRun : textPara.getTextRuns()) { sb.append(textRun.getRawText()); sb.append(' ');
protected static void applyParagraphIndents(List<HSLFTextParagraph> paragraphs, List<IndentProp> paraStyles) { int paraIdx = 0; for (IndentProp p : paraStyles) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) { return; } HSLFTextParagraph para = paragraphs.get(paraIdx); int len = 0; for (HSLFTextRun trun : para.getTextRuns()) { len += trun.getLength(); } para.setIndentLevel(p.getIndentLevel()); ccPara += len + 1; } } }
protected static void applyParagraphStyles(List<HSLFTextParagraph> paragraphs, List<TextPropCollection> paraStyles) { int paraIdx = 0; for (TextPropCollection p : paraStyles) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { if (paraIdx >= paragraphs.size()) { return; } HSLFTextParagraph htp = paragraphs.get(paraIdx); TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph); pCopy.copy(p); htp.setParagraphStyle(pCopy); int len = 0; for (HSLFTextRun trun : htp.getTextRuns()) { len += trun.getLength(); } if (paraIdx == paragraphs.size()-1) { len++; } pCopy.updateTextSize(len); ccPara += len; } } }
final HSLFSheet sheet = getSheet(); final int txtype = getRunType(); final HSLFMasterSheet master; if (sheet instanceof HSLFMasterSheet) { TextPropCollection masterProps = master.getPropCollection(txtype, getIndentLevel(), pn, isChar); if (masterProps != null) { T prop = masterProps.findByName(pn); if (isValidProp(prop)) { return prop;
@Override public BulletStyle getBulletStyle() { if (!isBullet() && getAutoNumberingScheme() == null) { return null;
private <T extends TextProp> T getMasterProp(final String name) { final int txtype = parentParagraph.getRunType(); final HSLFSheet sheet = parentParagraph.getSheet(); if (sheet == null) { logger.log(POILogger.ERROR, "Sheet is not available"); return null; } final HSLFMasterSheet master = sheet.getMasterSheet(); if (master == null) { logger.log(POILogger.WARN, "MasterSheet is not available"); return null; } final TextPropCollection col = master.getPropCollection(txtype, parentParagraph.getIndentLevel(), name, true); return (col == null) ? null : col.findByName(name); }
private void setPropValInner(final TextPropCollection props, final String name, Consumer<? extends TextProp> handler) { final boolean isChar = props.getTextPropType() == TextPropType.character; final TextPropCollection pc; if (_sheet instanceof HSLFMasterSheet) { pc = ((HSLFMasterSheet)_sheet).getPropCollection(getRunType(), getIndentLevel(), "*", isChar); if (pc == null) { throw new HSLFException("Master text property collection can't be determined."); } } else { pc = props; } if (handler == null) { pc.removeByName(name); } else { // Fetch / Add the TextProp handler.accept(pc.addWithName(name)); } setDirty(); }
/** * Returns the type of the text, from the TextHeaderAtom. * Possible values can be seen from TextHeaderAtom * @see org.apache.poi.hslf.record.TextHeaderAtom */ public int getRunType() { getEscherTextboxWrapper(); if (_txtbox == null) { return -1; } List<HSLFTextParagraph> paras = HSLFTextParagraph.findTextParagraphs(_txtbox, getSheet()); return (paras.isEmpty()) ? -1 : paras.get(0).getRunType(); }