private void extractMaster(XHTMLContentHandler xhtml, HSLFMasterSheet master) throws SAXException { if (master == null) { return; } List<HSLFShape> shapes = getShapes(master); if (shapes == null || shapes.isEmpty()) { return; } xhtml.startElement("div", "class", "slide-master-content"); for (HSLFShape shape : shapes) { if (shape != null && ! isPlaceholder(shape)) { if (shape instanceof HSLFTextShape) { HSLFTextShape tsh = (HSLFTextShape) shape; String text = tsh.getText(); if (text != null) { xhtml.element("p", text); } } } } xhtml.endElement("div"); }
private void extractGroupText(XHTMLContentHandler xhtml, ShapeContainer shapeContainer, int depth) throws SAXException { List<HSLFShape> shapes = getShapes(shapeContainer); if (shapes == null) { return; } //Only process items with depth > 0 because they should have been included //already in slide.getTextParagraphs above. //However, cells are considered grouped within the table, so ignore them. //I don't believe that cells can be inside a text box or other //grouped text containing object, so always ignore them. //I also don't believe that a table can be grouped with a table. //If these beliefs are wrong...must fix! List<List<HSLFTextParagraph>> paragraphList = new ArrayList<>(); for (HSLFShape shape : shapes) { if (shape instanceof HSLFGroupShape) { //work recursively, HSLFGroupShape can contain HSLFGroupShape extractGroupText(xhtml, ((HSLFGroupShape)shape), depth+1); } else if (shape instanceof HSLFTextShape && ! (shape instanceof HSLFTableCell) && depth > 0) { paragraphList.add(((HSLFTextShape)shape).getTextParagraphs()); } } textRunsToText(xhtml, paragraphList); }
/** * Create a new TextBox. This constructor is used when a new shape is created. * * @param parent the parent of this Shape. For example, if this text box is a cell * in a table then the parent is Table. */ public HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){ super(null, parent); createSpContainer(parent instanceof HSLFGroupShape); }
@Override public void setVerticalAlignment(VerticalAlignment vAlign) { setAlignment(isHorizontalCentered(), vAlign, getAlignment().baseline); }
@Override public void setHorizontalCentered(Boolean isCentered) { setAlignment(isCentered, getVerticalAlignment(), getAlignment().baseline); }
@Override public Insets2D getInsets() { return new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset()); }
super.afterInsert(sh); storeText(); EscherTextboxWrapper thisTxtbox = getEscherTextboxWrapper(); if(thisTxtbox != null){ getSpContainer().addChildRecord(thisTxtbox.getEscherRecord()); throw new HSLFException(e); boolean isInitialAnchor = getAnchor().equals(new Rectangle2D.Double()); boolean isFilledTxt = !"".equals(getText()); if (isInitialAnchor && isFilledTxt) { resizeToFitText(); htp.setShapeId(getShapeId());
AbstractEscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT); HSLFTextAnchor align = HSLFTextAnchor.TOP; if (prop == null){ int type = getRunType(); HSLFSheet sh = getSheet(); HSLFMasterSheet master = (sh != null) ? sh.getMasterSheet() : null; HSLFTextShape masterShape = (master != null) ? master.getPlaceholderByTextType(type) : null; if (masterShape != null && type != TextHeaderAtom.OTHER_TYPE) { align = masterShape.getAlignment(); } else {
@Override public HSLFTextRun appendText(String text, boolean newParagraph) { // init paragraphs List<HSLFTextParagraph> paras = getTextParagraphs(); HSLFTextRun htr = HSLFTextParagraph.appendText(paras, text, newParagraph); setTextId(getRawText().hashCode()); return htr; }
@Override public Rectangle2D resizeToFitText(Graphics2D graphics) { Rectangle2D anchor = getAnchor(); if(anchor.getWidth() == 0.) { LOG.log(POILogger.WARN, "Width of shape wasn't set. Defaulting to 200px"); anchor.setRect(anchor.getX(), anchor.getY(), 200., anchor.getHeight()); setAnchor(anchor); } double height = getTextHeight(graphics); height += 1; // add a pixel to compensate rounding errors Insets2D insets = getInsets(); anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height+insets.top+insets.bottom); setAnchor(anchor); return anchor; }
@Override public List<HSLFTextParagraph> getTextParagraphs(){ if (!_paragraphs.isEmpty()) { return _paragraphs; } _txtbox = getEscherTextboxWrapper(); if (_txtbox == null) { _txtbox = new EscherTextboxWrapper(); createEmptyParagraph(); } else { List<HSLFTextParagraph> pList = HSLFTextParagraph.findTextParagraphs(_txtbox, getSheet()); if (pList == null) { // there are actually TextBoxRecords without extra data - see #54722 createEmptyParagraph(); } else { _paragraphs = pList; } if (_paragraphs.isEmpty()) { LOG.log(POILogger.WARN, "TextRecord didn't contained any text lines"); } } for (HSLFTextParagraph p : _paragraphs) { p.setParentShape(this); } return _paragraphs; }
private void writeDirtyParagraphs(HSLFShapeContainer container) { for (HSLFShape sh : container.getShapes()) { if (sh instanceof HSLFShapeContainer) { writeDirtyParagraphs((HSLFShapeContainer)sh); } else if (sh instanceof HSLFTextShape) { HSLFTextShape hts = (HSLFTextShape)sh; boolean isDirty = false; for (HSLFTextParagraph p : hts.getTextParagraphs()) { isDirty |= p.isDirty(); } if (isDirty) { hts.storeText(); } } } }
protected EscherTextboxWrapper getEscherTextboxWrapper(){ if(_txtbox != null) { return _txtbox; } EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID); if (textRecord == null) { return null; } HSLFSheet sheet = getSheet(); if (sheet != null) { PPDrawing drawing = sheet.getPPDrawing(); if (drawing != null) { EscherTextboxWrapper wrappers[] = drawing.getTextboxWrappers(); if (wrappers != null) { for (EscherTextboxWrapper w : wrappers) { // check for object identity if (textRecord == w.getEscherRecord()) { _txtbox = w; return _txtbox; } } } } } _txtbox = new EscherTextboxWrapper(textRecord); return _txtbox; }
/** * @return true, if vertical alignment is relative to baseline * this is only used for older versions less equals Office 2003 */ public boolean isAlignToBaseline() { return getAlignment().baseline; }
/** * Return {@link OEPlaceholderAtom}, the atom that describes a placeholder. * * @return {@link OEPlaceholderAtom} or {@code null} if not found */ public OEPlaceholderAtom getPlaceholderAtom(){ return getClientDataRecord(OEPlaceholderAtom.typeID); }
@Override public HSLFTextRun setText(String text) { // init paragraphs List<HSLFTextParagraph> paras = getTextParagraphs(); HSLFTextRun htr = HSLFTextParagraph.setText(paras, text); setTextId(getRawText().hashCode()); return htr; }
@Override public VerticalAlignment getVerticalAlignment() { return getAlignment().vAlign; }
/** * Return {@link RoundTripHFPlaceholder12}, the atom that describes a header/footer placeholder. * Compare the {@link RoundTripHFPlaceholder12#getPlaceholderId()} with * {@link Placeholder#HEADER} or {@link Placeholder#FOOTER}, to find out * what kind of placeholder this is. * * @return {@link RoundTripHFPlaceholder12} or {@code null} if not found * * @since POI 3.14-Beta2 */ public RoundTripHFPlaceholder12 getHFPlaceholderAtom() { // special case for files saved in Office 2007 return getClientDataRecord(RoundTripHFPlaceholder12.typeID); }
private String getPlaceholderText(Placeholder ph, CString cs) { String text; if (_ppt2007) { HSLFSimpleShape ss = _sheet.getPlaceholder(ph); text = (ss instanceof HSLFTextShape) ? ((HSLFTextShape)ss).getText() : null; // default text in master placeholders is not visible if("*".equals(text)) { text = null; } } else { text = (cs == null) ? null : cs.getText(); } return text; }
@Override protected void onAddTextShape(HSLFTextShape shape) { List<HSLFTextParagraph> newParas = shape.getTextParagraphs(); _paragraphs.add(newParas); }