/** * Add a new Shape to this Slide * * @param shape - the Shape to add */ public void addShape(Shape shape) { PPDrawing ppdrawing = getPPDrawing(); EscherContainerRecord dgContainer = (EscherContainerRecord) ppdrawing.getEscherRecords()[0]; EscherContainerRecord spgr = (EscherContainerRecord) Shape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER); spgr.addChildRecord(shape.getSpContainer()); shape.setSheet(this); shape.setShapeId(allocateShapeId()); shape.afterInsert(this); }
/** * For a given PPDrawing, grab all the TextRuns */ public static TextRun[] findTextRuns(PPDrawing ppdrawing) { final List<TextRun> runsV = new ArrayList<TextRun>(); EscherTextboxWrapper[] wrappers = ppdrawing.getTextboxWrappers(); for (int i = 0; i < wrappers.length; i++) { int s1 = runsV.size(); // propagate parents to parent-aware records RecordContainer.handleParentAwareRecords(wrappers[i]); findTextRuns(wrappers[i].getChildRecords(), runsV); int s2 = runsV.size(); if (s2 != s1){ TextRun t = runsV.get(runsV.size()-1); t.setShapeId(wrappers[i].getShapeId()); } } return runsV.toArray(new TextRun[runsV.size()]); }
/** * Background for this slide. */ public Background getBackground() { if(getFollowMasterBackground()) { return getMasterSheet().getBackground(); } return super.getBackground(); }
/** * When a textbox is added to a sheet we need to tell upper-level * <code>PPDrawing</code> about it. * * @param sh the sheet we are adding to */ protected void afterInsert(Sheet sh){ super.afterInsert(sh); EscherTextboxWrapper _txtbox = getEscherTextboxWrapper(); if(_txtbox != null){ PPDrawing ppdrawing = sh.getPPDrawing(); ppdrawing.addTextboxWrapper(_txtbox); // Ensure the escher layer knows about the added records try { _txtbox.writeOut(null); } catch (IOException e){ throw new HSLFException(e); } if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText(); } if(_txtrun != null) { _txtrun.setShapeId(getShapeId()); sh.onAddTextShape(this); } }
/** * @return font color as RGB value * @see java.awt.Color */ public Color getFontColor() { int rgb = getCharTextPropVal("font.color"); int cidx = rgb >> 24; if (rgb % 0x1000000 == 0){ ColorSchemeAtom ca = parentRun.getSheet().getColorScheme(); if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx); } Color tmp = new Color(rgb, true); return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed()); }
/** * Fetch the value of the given Character related TextProp. * Returns -1 if that TextProp isn't present. * If the TextProp isn't present, the value from the appropriate * Master Sheet will apply. */ private int getCharTextPropVal(String propName) { TextProp prop = null; if (characterStyle != null){ prop = characterStyle.findByName(propName); } if (prop == null){ Sheet sheet = parentRun.getSheet(); int txtype = parentRun.getRunType(); MasterSheet master = sheet.getMasterSheet(); if (master != null) prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true); } return prop == null ? -1 : prop.getValue(); } /**
PPDrawing ppdrawing = getPPDrawing();
private String getPlaceholderText(int placeholderId, CString cs){ String text = null; if(_ppt2007){ Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0]; TextShape placeholder = master.getPlaceholder(placeholderId); if(placeholder != null) text = placeholder.getText(); //default text in master placeholders is not visible if("*".equals(text)) text = null; } else { text = cs == null ? null : cs.getText(); } return text; }
/** * Return placeholder by text type * * @param type type of text, See {@link org.apache.poi.hslf.record.TextHeaderAtom} * @return <code>TextShape</code> or <code>null</code> */ public TextShape getPlaceholderByTextType(int type){ Shape[] shape = getShapes(); for (int i = 0; i < shape.length; i++) { if(shape[i] instanceof TextShape){ TextShape tx = (TextShape)shape[i]; TextRun run = tx.getTextRun(); if(run != null && run.getRunType() == type){ return tx; } } } return null; }
/** * Return programmable tag associated with this sheet, e.g. <code>___PPT12</code>. * * @return programmable tag associated with this sheet. */ public String getProgrammableTag(){ String tag = null; RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType( RecordTypes.ProgTags.typeID ); if(progTags != null) { RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType( RecordTypes.ProgBinaryTag.typeID ); if(progBinaryTag != null) { CString binaryTag = (CString) progBinaryTag.findFirstOfType( RecordTypes.CString.typeID ); if(binaryTag != null) tag = binaryTag.getText(); } } return tag; }
/** * Add a shape to this group. * * @param shape - the Shape to add */ public void addShape(Shape shape){ _escherContainer.addChildRecord(shape.getSpContainer()); Sheet sheet = getSheet(); shape.setSheet(sheet); shape.setShapeId(sheet.allocateShapeId()); shape.afterInsert(sheet); }
protected void afterInsert(Sheet sheet){ ExControl ctrl = getExControl(); ctrl.getExControlAtom().setSlideId(sheet._getSheetNumber()); try { String name = ctrl.getProgId() + "-" + getControlIndex(); byte[] data = (name + '\u0000').getBytes("UTF-16LE"); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data); EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); opt.addEscherProperty(prop); } catch (UnsupportedEncodingException e){ throw new HSLFException(e); } } }
/** * Returns the bullet color */ public Color getBulletColor() { int rgb = getParaTextPropVal("bullet.color"); if(rgb == -1) return getFontColor(); int cidx = rgb >> 24; if (rgb % 0x1000000 == 0){ ColorSchemeAtom ca = parentRun.getSheet().getColorScheme(); if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx); } Color tmp = new Color(rgb, true); return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed()); }
private boolean getFlag(boolean isCharacter, int index) { TextPropCollection props; String propname; if (isCharacter){ props = characterStyle; propname = CharFlagsTextProp.NAME; } else { props = paragraphStyle; propname = ParagraphFlagsTextProp.NAME; } BitMaskTextProp prop = null; if (props != null){ prop = (BitMaskTextProp)props.findByName(propname); } if (prop == null){ Sheet sheet = parentRun.getSheet(); if(sheet != null){ int txtype = parentRun.getRunType(); MasterSheet master = sheet.getMasterSheet(); if (master != null){ prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter); } } else { logger.log(POILogger.WARN, "MasterSheet is not available"); } } return prop == null ? false : prop.getSubValue(index); }
/** * Returns the background shape for this sheet. * * @return the background shape for this sheet. */ public Background getBackground() { if (_background == null) { PPDrawing ppdrawing = getPPDrawing(); EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0]; EscherContainerRecord spContainer = null; for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) { EscherRecord rec = it.next(); if (rec.getRecordId() == EscherContainerRecord.SP_CONTAINER) { spContainer = (EscherContainerRecord) rec; break; } } _background = new Background(spContainer, null); _background.setSheet(this); } return _background; }
private boolean isVisible(int flag, int placeholderId){ boolean visible; if(_ppt2007){ Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0]; TextShape placeholder = master.getPlaceholder(placeholderId); visible = placeholder != null && placeholder.getText() != null; } else { visible = _container.getHeadersFootersAtom().getFlag(flag); } return visible; }
/** * Search text placeholer by its type * * @param type type of placeholder to search. See {@link org.apache.poi.hslf.record.OEPlaceholderAtom} * @return <code>TextShape</code> or <code>null</code> */ public TextShape getPlaceholder(int type){ Shape[] shape = getShapes(); for (int i = 0; i < shape.length; i++) { if(shape[i] instanceof TextShape){ TextShape tx = (TextShape)shape[i]; int placeholderId = 0; OEPlaceholderAtom oep = tx.getPlaceholderAtom(); if(oep != null) { placeholderId = oep.getPlaceholderId(); } else { //special case for files saved in Office 2007 RoundTripHFPlaceholder12 hldr = (RoundTripHFPlaceholder12)tx.getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID); if(hldr != null) placeholderId = hldr.getPlaceholderId(); } if(placeholderId == type){ return tx; } } } return null; }
Color toRGB(int val){ int a = (val >> 24) & 0xFF; int b = (val >> 16) & 0xFF; int g = (val >> 8) & 0xFF; int r = (val >> 0) & 0xFF; if(a == 0xFE){ // Color is an sRGB value specified by red, green, and blue fields. } else if (a == 0xFF){ // Color is undefined. } else { // index in the color scheme ColorSchemeAtom ca = getSheet().getColorScheme(); int schemeColor = ca.getColor(a); r = (schemeColor >> 0) & 0xFF; g = (schemeColor >> 8) & 0xFF; b = (schemeColor >> 16) & 0xFF; } return new Color(r, g, b); }
/** * Fetch the value of the given Paragraph related TextProp. * Returns -1 if that TextProp isn't present. * If the TextProp isn't present, the value from the appropriate * Master Sheet will apply. */ private int getParaTextPropVal(String propName) { TextProp prop = null; boolean hardAttribute = false; if (paragraphStyle != null){ prop = paragraphStyle.findByName(propName); BitMaskTextProp maskProp = (BitMaskTextProp)paragraphStyle.findByName(ParagraphFlagsTextProp.NAME); hardAttribute = maskProp != null && maskProp.getValue() == 0; } if (prop == null && !hardAttribute){ Sheet sheet = parentRun.getSheet(); int txtype = parentRun.getRunType(); MasterSheet master = sheet.getMasterSheet(); if (master != null) prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false); } return prop == null ? -1 : prop.getValue(); }
/** * Removes the specified shape from this sheet. * * @param shape shape to be removed from this sheet, if present. * @return <tt>true</tt> if the shape was deleted. */ public boolean removeShape(Shape shape) { PPDrawing ppdrawing = getPPDrawing(); EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0]; EscherContainerRecord spgr = null; for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) { EscherRecord rec = it.next(); if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) { spgr = (EscherContainerRecord) rec; break; } } if(spgr == null) { return false; } List<EscherRecord> lst = spgr.getChildRecords(); boolean result = lst.remove(shape.getSpContainer()); spgr.setChildRecords(lst); return result; }