continue;
}
if (rb instanceof EscherAggregate){
+ /**
+ * this record will be removed after reading actual data from EscherAggregate
+ */
rb = new DrawingRecord();
}
Record rec = (Record) ((Record) rb).clone();
recordData = in.readRemainder();
}
+ @Deprecated
public void processContinueRecord(byte[] record) {
//don't merge continue record with the drawing record, it must be serialized separately
contd = record;
return sid;
}
+ @Deprecated
public byte[] getData() {
-// if (continueData.size() != 0) {
-// byte[] newBuffer = new byte[recordData.length + continueData.size()];
-// System.arraycopy(recordData, 0, newBuffer, 0, recordData.length);
-// System.arraycopy(continueData.toByteArray(), 0, newBuffer, recordData.length, continueData.size());
-// return newBuffer;
-// }
return recordData;
}
recordData = thedata;
}
+ /**
+ * Cloning of drawing records must be executed through HSSFPatriarch, because all id's must be changed
+ * @return cloned drawing records
+ */
public Object clone() {
DrawingRecord rec = new DrawingRecord();
rec.recordData = recordData.clone();
public static final short ST_TEXTBOX = (short) 202;
public static final short ST_NIL = (short) 0x0FFF;
- protected HSSFPatriarch patriarch;
-
/**
* if we want to get the same byte array if we open existing file and serialize it we should save
* note records in right order. This list contains ids of NoteRecords in such order as we read from existing file
return result.toString();
}
+ /**
+ * Calculates the xml representation of this record. This is
+ * simply a dump of all the records.
+ */
public String toXml(String tab) {
StringBuilder builder = new StringBuilder();
builder.append(tab).append("<").append(getRecordName()).append(">\n");
/**
* Collapses the drawing records into an aggregate.
- * read Drawing and Continue records into single byte array, create Escher tree from byte array, create map <EscherRecord, Record>
+ * read Drawing, Obj, TxtObj, Note and Continue records into single byte array,
+ * create Escher tree from byte array, create map <EscherRecord, Record>
+ *
*/
public static EscherAggregate createAggregate(List records, int locFirstDrawingRecord, DrawingManager2 drawingManager) {
// Keep track of any shape records created so we can match them back to the object id's.
byte[] drawingData = new byte[endOffset - startOffset + 1];
System.arraycopy(buffer, startOffset, drawingData, 0, drawingData.length);
- pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i);
+ pos += writeDataIntoDrawingRecord(drawingData, writtenEscherBytes, pos, data, i);
writtenEscherBytes += drawingData.length;
if (i == shapes.size() - 1 && endOffset < buffer.length - 1) {
drawingData = new byte[buffer.length - endOffset - 1];
System.arraycopy(buffer, endOffset + 1, drawingData, 0, drawingData.length);
- pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i);
+ pos += writeDataIntoDrawingRecord(drawingData, writtenEscherBytes, pos, data, i);
}
}
if ((pos - offset) < buffer.length - 1) {
byte[] drawingData = new byte[buffer.length - (pos - offset)];
System.arraycopy(buffer, (pos - offset), drawingData, 0, drawingData.length);
- pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i);
+ pos += writeDataIntoDrawingRecord(drawingData, writtenEscherBytes, pos, data, i);
}
// write records that need to be serialized after all drawing group records
return bytesWritten;
}
- private int writeDataIntoDrawingRecord(int temp, byte[] drawingData, int writtenEscherBytes, int pos, byte[] data, int i) {
+ /**
+ * @param drawingData - escher records saved into single byte array
+ * @param writtenEscherBytes - count of bytes already saved into drawing records (we should know it to decide create
+ * drawing or continue record)
+ * @param pos current position of data array
+ * @param data - array of bytes where drawing records must be serialized
+ * @param i - number of shape, saved into data array
+ * @return offset of data array after serialization
+ */
+ private int writeDataIntoDrawingRecord(byte[] drawingData, int writtenEscherBytes, int pos, byte[] data, int i) {
+ int temp = 0;
//First record in drawing layer MUST be DrawingRecord
if (writtenEscherBytes + drawingData.length > RecordInputStream.MAX_RECORD_DATA_SIZE && i != 1) {
for (int j = 0; j < drawingData.length; j += RecordInputStream.MAX_RECORD_DATA_SIZE) {
return size;
}
+ /**
+ * @return record size, including header size of obj, text, note, drawing, continue records
+ */
public int getRecordSize() {
// To determine size of aggregate record we have to know size of each DrawingRecord because if DrawingRecord
// is split into several continue records we have to add header size to total EscherAggregate size
shapeToObj.remove(rec);
}
- public void clear() {
- clearEscherRecords();
- shapeToObj.clear();
-// lastShapeId = 1024;
- }
-
protected String getRecordName() {
return "ESCHERAGGREGATE";
}
}
/**
- * Returns the mapping of {@link EscherClientDataRecord} and {@link EscherTextboxRecord}
+ * @return unmodifiable copy of the mapping of {@link EscherClientDataRecord} and {@link EscherTextboxRecord}
* to their {@link TextObjectRecord} or {@link ObjRecord} .
* <p/>
* We need to access it outside of EscherAggregate when building shapes
- *
- * @return
*/
public Map<EscherRecord, Record> getShapeToObjMapping() {
return Collections.unmodifiableMap(shapeToObj);
}
/**
- * @return tails records. We need to access them when building shapes.
+ * @return unmodifiable copy of tail records. We need to access them when building shapes.
* Every HSSFComment shape has a link to a NoteRecord from the tailRec collection.
*/
public Map<Integer, NoteRecord> getTailRecords() {
return tailRec;
}
+ /**
+ * @param obj - ObjRecord with id == NoteRecord.id
+ * @return null if note record is not found else returns note record with id == obj.id
+ */
public NoteRecord getNoteRecordByObj(ObjRecord obj) {
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) obj.getSubRecords().get(0);
return tailRec.get(cod.getObjectId());
}
+ /**
+ * Add tail record to existing map
+ * @param note to be added
+ */
public void addTailRecord(NoteRecord note) {
tailRec.put(note.getShapeId(), note);
}
+ /**
+ * Remove tail record from the existing map
+ * @param note to be removed
+ */
public void removeTailRecord(NoteRecord note) {
tailRec.remove(note.getShapeId());
}
}
}
+ /**
+ * @return x coordinate of the left up corner
+ */
public abstract int getDx1();
+ /**
+ * @param dx1 x coordinate of the left up corner
+ */
public abstract void setDx1(int dx1);
+ /**
+ * @return y coordinate of the left up corner
+ */
public abstract int getDy1();
+ /**
+ * @param dy1 y coordinate of the left up corner
+ */
public abstract void setDy1(int dy1);
+ /**
+ * @return y coordinate of the right down corner
+ */
public abstract int getDy2();
+ /**
+ * @param dy2 y coordinate of the right down corner
+ */
public abstract void setDy2(int dy2);
+ /**
+ * @return x coordinate of the right down corner
+ */
public abstract int getDx2();
+ /**
+ * @param dx2 x coordinate of the right down corner
+ */
public abstract void setDx2(int dx2);
+ /**
+ * @return whether this shape is horizontally flipped
+ */
public abstract boolean isHorizontallyFlipped();
+ /**
+ * @return whether this shape is vertically flipped
+ */
public abstract boolean isVerticallyFlipped();
- public abstract EscherRecord getEscherAnchor();
+ protected abstract EscherRecord getEscherAnchor();
protected abstract void createEscherAnchor();
}
private EscherChildAnchorRecord _escherChildAnchor;
+ /**
+ * create anchor from existing file
+ * @param escherChildAnchorRecord
+ */
public HSSFChildAnchor(EscherChildAnchorRecord escherChildAnchorRecord) {
this._escherChildAnchor = escherChildAnchorRecord;
}
_escherChildAnchor = new EscherChildAnchorRecord();
}
+ /**
+ * create anchor from scratch
+ * @param dx1 x coordinate of the left up corner
+ * @param dy1 y coordinate of the left up corner
+ * @param dx2 x coordinate of the right down corner
+ * @param dy2 y coordinate of the right down corner
+ */
public HSSFChildAnchor(int dx1, int dy1, int dx2, int dy2) {
super(Math.min(dx1, dx2), Math.min(dy1, dy2), Math.max(dx1, dx2), Math.max(dy1, dy2));
if (dx1 > dx2){
_escherChildAnchor.setDx2(dx2);
}
+ /**
+ * @param dx1 x coordinate of the left up corner
+ * @param dy1 y coordinate of the left up corner
+ * @param dx2 x coordinate of the right down corner
+ * @param dy2 y coordinate of the right down corner
+ */
public void setAnchor(int dx1, int dy1, int dx2, int dy2) {
setDx1(Math.min(dx1, dx2));
setDy1(Math.min(dy1, dy2));
setDy2(Math.max(dy1, dy2));
}
+
public boolean isHorizontallyFlipped() {
return _isHorizontallyFlipped;
}
+
public boolean isVerticallyFlipped() {
return _isVerticallyFlipped;
}
@Override
- public EscherRecord getEscherAnchor() {
+ protected EscherRecord getEscherAnchor() {
return _escherChildAnchor;
}
return row.getHeightInPoints();
}
+ /**
+ * @return the column(0 based) of the first cell.
+ */
public short getCol1() {
return _escherClientAnchor.getCol1();
}
+ /**
+ * @param col1 the column(0 based) of the first cell.
+ */
public void setCol1(short col1) {
checkRange(col1, 0, 255, "col1");
_escherClientAnchor.setCol1(col1);
}
+ /**
+ * @param col1 0-based column of the first cell.
+ */
public void setCol1(int col1) {
setCol1((short) col1);
}
+ /**
+ * @return the column(0 based) of the first cell.
+ */
public short getCol2() {
return _escherClientAnchor.getCol2();
}
+ /**
+ * @param col2 the column(0 based) of the second cell.
+ */
public void setCol2(short col2) {
checkRange(col2, 0, 255, "col2");
_escherClientAnchor.setCol2(col2);
}
+ /**
+ * @param col2 the column(0 based) of the second cell.
+ */
public void setCol2(int col2) {
setCol2((short) col2);
}
+ /**
+ * @return the row(0 based) of the first cell.
+ */
public int getRow1() {
return _escherClientAnchor.getRow1();
}
+ /**
+ * @param row1 0-based row of the first cell.
+ */
public void setRow1(int row1) {
checkRange(row1, 0, 256 * 256, "row1");
_escherClientAnchor.setRow1(Integer.valueOf(row1).shortValue());
}
+ /**
+ * @return the row(0 based) of the second cell.
+ */
public int getRow2() {
return _escherClientAnchor.getRow2();
}
+ /**
+ * @return the row(0 based) of the second cell.
+ */
public void setRow2(int row2) {
checkRange(row2, 0, 256 * 256, "row2");
_escherClientAnchor.setRow2(Integer.valueOf(row2).shortValue());
setDy2(y2);
}
- /**
- * @return true if the anchor goes from right to left.
- */
public boolean isHorizontallyFlipped() {
return _isHorizontallyFlipped;
}
- /**
- * @return true if the anchor goes from bottom to top.
- */
public boolean isVerticallyFlipped() {
return _isVerticallyFlipped;
}
@Override
- public EscherRecord getEscherAnchor() {
+ protected EscherRecord getEscherAnchor() {
return _escherClientAnchor;
}
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
*/
public void setAnchorType(int anchorType) {
-// if (0 != anchorType && 2 != anchorType && 3 != anchorType){
-// throw new IllegalArgumentException("Anchor type of shape can take only such values: 0, 2, 3");
-// }
_escherClientAnchor.setFlag(Integer.valueOf(anchorType).shortValue());
}
public HSSFCombobox(HSSFShape parent, HSSFAnchor anchor) {\r
super(parent, anchor);\r
super.setShapeType(OBJECT_TYPE_COMBO_BOX);\r
+ CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);\r
+ cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_COMBO_BOX);\r
}\r
\r
@Override\r
//by default comments are hidden
setVisible(false);
setAuthor("");
+ CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
+ cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT);
}
protected HSSFComment(NoteRecord note, TextObjectRecord txo) {
buildShapeTree();
}
+ /**
+ * used to clone patriarch
+ *
+ * create patriarch from existing one
+ * @param patriarch - copy all the shapes from this patriarch to new one
+ * @param sheet where must be located new patriarch
+ * @return new patriarch with copies of all shapes from the existing patriarch
+ */
static HSSFPatriarch createPatriarch(HSSFPatriarch patriarch, HSSFSheet sheet){
HSSFPatriarch newPatriarch = new HSSFPatriarch(sheet, new EscherAggregate());
newPatriarch.afterCreate();
-
for (HSSFShape shape: patriarch.getChildren()){
HSSFShape newShape;
if (shape instanceof HSSFShapeGroup){
newPatriarch.onCreate(newShape);
newPatriarch.addShape(newShape);
}
-
return newPatriarch;
}
- /**
- * remove first level shapes
- *
- * @param shape to be removed
- */
public boolean removeShape(HSSFShape shape) {
boolean isRemoved = _mainSpgrContainer.removeChildRecord(shape.getEscherContainer());
if (isRemoved){
return shape;
}
+ /**
+ *
+ * @param anchor the client anchor describes how this picture is
+ * attached to the sheet.
+ * @param pictureIndex the index of the picture in the workbook collection
+ * of pictures.
+ *
+ * @return newly created shape
+ */
public HSSFPicture createPicture(ClientAnchor anchor, int pictureIndex) {
return createPicture((HSSFClientAnchor) anchor, pictureIndex);
}
/**
* Total count of all children and their children's children.
+ * @return count of shapes including shapes inside shape groups
*/
public int countOfAllChildren() {
int count = _shapes.size();
_spgrRecord.setRectX2(x2);
}
+ /**
+ * remove all shapes inside patriarch
+ */
public void clear() {
ArrayList <HSSFShape> copy = new ArrayList<HSSFShape>(_shapes);
for (HSSFShape shape: copy){
}
}
+ /**
+ * @return new unique shapeId
+ */
int newShapeId() {
DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager();
EscherDgRecord dg =
return false;
}
- /**
- * The top left x coordinate of this group.
- */
public int getX1() {
return _spgrRecord.getRectX1();
}
- /**
- * The top left y coordinate of this group.
- */
public int getY1() {
return _spgrRecord.getRectY1();
}
- /**
- * The bottom right x coordinate of this group.
- */
public int getX2() {
return _spgrRecord.getRectX2();
}
- /**
- * The bottom right y coordinate of this group.
- */
public int getY2() {
return _spgrRecord.getRectY2();
}
import java.io.UnsupportedEncodingException;
import org.apache.poi.ddf.*;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.ss.usermodel.Picture;
{
super( parent, anchor );
super.setShapeType(OBJECT_TYPE_PICTURE);
+ CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
+ cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE);
}
public int getPictureIndex()
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
}
+ /**
+ * @return array of x coordinates
+ */
public int[] getXPoints() {
EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
if (null == verticesProp){
return array;
}
+ /**
+ * @return array of y coordinates
+ */
public int[] getYPoints() {
EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
if (null == verticesProp){
return array;
}
+ /**
+ * @param xPoints - array of x coordinates
+ * @param yPoints - array of y coordinates
+ */
public void setPoints(int[] xPoints, int[] yPoints) {
if (xPoints.length != yPoints.length){
System.out.println("xPoint.length must be equal to yPoints.length");
/**
* Defines the width and height of the points in the polygon
- *
* @param width
* @param height
*/
setPropertyValue(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, height));
}
+ /**
+ * @return shape width
+ */
public int getDrawAreaWidth() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.GEOMETRY__RIGHT);
return property == null ? 100: property.getPropertyValue();
}
+ /**
+ * @return shape height
+ */
public int getDrawAreaHeight() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.GEOMETRY__BOTTOM);
return property == null ? 100: property.getPropertyValue();
public final static int NO_FILLHITTEST_TRUE = 0x00110000;
public final static int NO_FILLHITTEST_FALSE = 0x00010000;
+ /**
+ * creates shapes from existing file
+ * @param spContainer
+ * @param objRecord
+ */
public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord) {
this._escherContainer = spContainer;
this._objRecord = objRecord;
protected abstract void afterRemove(HSSFPatriarch patriarch);
+ /**
+ * @param shapeId - global shapeId which must be set to EscherSpRecord
+ */
void setShapeId(int shapeId){
EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setShapeId(shapeId);
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0);
cod.setObjectId((short) (shapeId%1024));
}
-
+
+ /**
+ * @return global shapeId(from EscherSpRecord)
+ */
int getShapeId(){
return ((EscherSpRecord)_escherContainer.getChildById(EscherSpRecord.RECORD_ID)).getShapeId();
}
}
/**
- * Sets whether this shape is filled or transparent.
+ * @param noFill sets whether this shape is filled or transparent.
*/
public void setNoFill(boolean noFill) {
setPropertyValue(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? NO_FILLHITTEST_TRUE : NO_FILLHITTEST_FALSE));
protected void setPropertyValue(EscherProperty property){
_optRecord.setEscherProperty(property);
}
-
+
+ /**
+ * @param value specifies whether this shape is vertically flipped.
+ */
public void setFlipVertical(boolean value){
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
if (value){
}
}
+ /**
+ * @param value specifies whether this shape is horizontally flipped.
+ */
public void setFlipHorizontal(boolean value){
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
if (value){
sp.setFlags(sp.getFlags() & (Integer.MAX_VALUE - EscherSpRecord.FLAG_FLIPHORIZ));
}
}
-
+
+ /**
+ * @return whether this shape is vertically flipped.
+ */
public boolean isFlipVertical(){
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
return (sp.getFlags() & EscherSpRecord.FLAG_FLIPVERT) != 0;
}
+ /**
+ * @return whether this shape is horizontally flipped.
+ */
public boolean isFlipHorizontal(){
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
return (sp.getFlags() & EscherSpRecord.FLAG_FLIPHORIZ) != 0;
}
-
+
+ /**
+ * @return the rotation, in degrees, that is applied to a shape.
+ */
public int getRotationDegree(){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TRANSFORM__ROTATION);
}
}
+ /**
+ * specifies the rotation, in degrees, that is applied to a shape.
+ * Positive values specify rotation in the clockwise direction.
+ * Negative values specify rotation in the counterclockwise direction.
+ * Rotation occurs around the center of the shape.
+ * The default value for this property is 0x00000000
+ * @param value
+ */
public void setRotationDegree(short value){
setPropertyValue(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION , (value << 16)));
}
void setCoordinates( int x1, int y1, int x2, int y2 );
void clear();
-
+
+ /**
+ *@return The top left x coordinate of this group.
+ */
public int getX1();
+ /**
+ *@return The top left y coordinate of this group.
+ */
public int getY1();
+ /**
+ *@return The bottom right x coordinate of this group.
+ */
public int getX2();
+ /**
+ * @return The bottom right y coordinate of this group.
+ */
public int getY2();
+ /**
+ * remove first level shapes
+ * @param shape to be removed
+ * @return true if shape is removed else return false
+ */
public boolean removeShape(HSSFShape shape);
}
\r
import org.apache.poi.ddf.*;\r
import org.apache.poi.hssf.record.*;\r
-import org.apache.poi.hssf.usermodel.drawing.HSSFShapeType;\r
import org.apache.poi.poifs.filesystem.DirectoryNode;\r
\r
-import java.lang.reflect.Constructor;\r
-import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
*/\r
public class HSSFShapeFactory {\r
\r
- private static final Map<Short, HSSFShapeType> shapeTypeToClass = new HashMap<Short, HSSFShapeType>(HSSFShapeType.values().length);\r
- private static final ReflectionConstructorShapeCreator shapeCreator = new ReflectionConstructorShapeCreator(shapeTypeToClass);\r
-\r
- static {\r
- for (HSSFShapeType type : HSSFShapeType.values()) {\r
- shapeTypeToClass.put(type.getType(), type);\r
- }\r
- }\r
-\r
- private static class ReflectionConstructorShapeCreator {\r
-\r
- private final Map<Short, HSSFShapeType> shapeTypeToClass;\r
-\r
- private ReflectionConstructorShapeCreator(Map<Short, HSSFShapeType> shapeTypeToClass) {\r
- this.shapeTypeToClass = shapeTypeToClass;\r
- }\r
-\r
- public HSSFShape createNewShape(Short type, EscherContainerRecord spContainer, ObjRecord objRecord) {\r
- if (!shapeTypeToClass.containsKey(type)) {\r
- return new HSSFUnknownShape(spContainer, objRecord);\r
- }\r
- Class clazz = shapeTypeToClass.get(type).getShape();\r
- if (null == clazz) {\r
- //System.out.println("No class attached to shape type: "+type);\r
- return new HSSFUnknownShape(spContainer, objRecord);\r
- }\r
- try {\r
- Constructor constructor = clazz.getConstructor(new Class[]{EscherContainerRecord.class, ObjRecord.class});\r
- return (HSSFShape) constructor.newInstance(spContainer, objRecord);\r
- } catch (NoSuchMethodException e) {\r
- throw new IllegalStateException(clazz.getName() + " doesn't have required for shapes constructor");\r
- } catch (Exception e) {\r
- throw new IllegalStateException("Couldn't create new instance of " + clazz.getName());\r
- }\r
- }\r
- }\r
+ private final static short OBJECT_TYPE_LINE = 1;\r
+ private final static short OBJECT_TYPE_RECTANGLE = 2;\r
+ private final static short OBJECT_TYPE_OVAL = 3;\r
+ private final static short OBJECT_TYPE_ARC = 4;\r
+ private final static short OBJECT_TYPE_PICTURE = 8;\r
\r
+ /**\r
+ * build shape tree from escher container\r
+ * @param container root escher container from which escher records must be taken\r
+ * @param agg - EscherAggregate\r
+ * @param out - shape container to which shapes must be added\r
+ * @param root - node to create HSSFObjectData shapes\r
+ */\r
public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out, DirectoryNode root) {\r
if (container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {\r
ObjRecord obj = null;\r
// skip the first child record, it is group descriptor\r
for (int i = 0; i < children.size(); i++) {\r
EscherContainerRecord spContainer = children.get(i);\r
- if (i == 0) {\r
- EscherSpgrRecord spgr = (EscherSpgrRecord) spContainer.getChildById(EscherSpgrRecord.RECORD_ID);\r
- } else {\r
+ if (i != 0) {\r
createShapeTree(spContainer, agg, group, root);\r
}\r
}\r
out.addShape(group);\r
} else if (container.getRecordId() == EscherContainerRecord.SP_CONTAINER) {\r
Map<EscherRecord, Record> shapeToObj = agg.getShapeToObjMapping();\r
- EscherSpRecord spRecord = null;\r
ObjRecord objRecord = null;\r
TextObjectRecord txtRecord = null;\r
\r
for (EscherRecord record : container.getChildRecords()) {\r
switch (record.getRecordId()) {\r
- case EscherSpRecord.RECORD_ID:\r
- spRecord = (EscherSpRecord) record;\r
- break;\r
case EscherClientDataRecord.RECORD_ID:\r
objRecord = (ObjRecord) shapeToObj.get(record);\r
break;\r
return;\r
}\r
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);\r
- HSSFShape shape = null;\r
+ HSSFShape shape;\r
switch (cmo.getObjectType()) {\r
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:\r
shape = new HSSFPicture(container, objRecord);\r
throw new IllegalStateException("Use method cloneShape(HSSFPatriarch patriarch)");
}
- public HSSFShape cloneShape(HSSFPatriarch patriarch) {
+ protected HSSFShape cloneShape(HSSFPatriarch patriarch) {
EscherContainerRecord spgrContainer = new EscherContainerRecord();
spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
spgrContainer.setOptions((short) 0x000F);
import org.apache.poi.ddf.*;
import org.apache.poi.hssf.record.*;
-import org.apache.poi.hssf.usermodel.drawing.HSSFShapeType;
+import org.apache.poi.hssf.usermodel.drawing.ShapeTypes;
import org.apache.poi.ss.usermodel.RichTextString;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Represents a simple shape such as a line, rectangle or oval.
*
// The commented out ones haven't been tested yet or aren't supported
// by HSSFSimpleShape.
- public final static short OBJECT_TYPE_LINE = 1;
- public final static short OBJECT_TYPE_RECTANGLE = 2;
- public final static short OBJECT_TYPE_OVAL = 3;
- public final static short OBJECT_TYPE_ARC = 4;
-// public final static short OBJECT_TYPE_CHART = 5;
+ public final static short OBJECT_TYPE_LINE = ShapeTypes.Line;
+ public final static short OBJECT_TYPE_RECTANGLE = ShapeTypes.Rectangle;
+ public final static short OBJECT_TYPE_OVAL = ShapeTypes.Ellipse;
+ public final static short OBJECT_TYPE_ARC = ShapeTypes.Arc;
+ // public final static short OBJECT_TYPE_CHART = 5;
// public final static short OBJECT_TYPE_TEXT = 6;
// public final static short OBJECT_TYPE_BUTTON = 7;
- public final static short OBJECT_TYPE_PICTURE = 8;
+ public final static short OBJECT_TYPE_PICTURE = ShapeTypes.PictureFrame;
+
// public final static short OBJECT_TYPE_POLYGON = 9;
// public final static short OBJECT_TYPE_CHECKBOX = 11;
// public final static short OBJECT_TYPE_OPTION_BUTTON = 12;
// public final static short OBJECT_TYPE_SCROLL_BAR = 17;
// public final static short OBJECT_TYPE_LIST_BOX = 18;
// public final static short OBJECT_TYPE_GROUP_BOX = 19;
- public final static short OBJECT_TYPE_COMBO_BOX = 20;
- public final static short OBJECT_TYPE_COMMENT = 25;
+ public final static short OBJECT_TYPE_COMBO_BOX = ShapeTypes.HostControl;
+ public final static short OBJECT_TYPE_COMMENT = ShapeTypes.TextBox;
public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
public final static int WRAP_SQUARE = 0;
public final static int WRAP_BY_POINTS = 1;
public final static int WRAP_NONE = 2;
- private static final Map <Short, Short> objTypeToShapeType = new HashMap<Short, Short>();
-
private TextObjectRecord _textObjectRecord;
- static {
- objTypeToShapeType.put(OBJECT_TYPE_RECTANGLE, HSSFShapeType.RECTANGLE.getType());
- objTypeToShapeType.put(OBJECT_TYPE_PICTURE, HSSFShapeType.PICTURE.getType());
- objTypeToShapeType.put(OBJECT_TYPE_LINE, HSSFShapeType.LINE.getType());
- objTypeToShapeType.put(OBJECT_TYPE_OVAL, HSSFShapeType.OVAL.getType());
- objTypeToShapeType.put(OBJECT_TYPE_ARC, HSSFShapeType.ARC.getType());
- }
-
public HSSFSimpleShape(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord) {
super(spContainer, objRecord);
this._textObjectRecord = textObjectRecord;
* @see #OBJECT_TYPE_COMMENT
*/
public int getShapeType() {
- CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
- return cod.getObjectType();
- }
-
- /**
- * Sets the shape types.
- *
- * @param shapeType One of the OBJECT_TYPE_* constants.
- *
- * @see #OBJECT_TYPE_LINE
- * @see #OBJECT_TYPE_OVAL
- * @see #OBJECT_TYPE_RECTANGLE
- */
- public void setShapeType( int shapeType ){
- CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
- cod.setObjectType((short) shapeType);
EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
- if (null == objTypeToShapeType.get((short)shapeType)){
- System.out.println("Unknown shape type: "+shapeType);
- return;
- }
- spRecord.setShapeType(objTypeToShapeType.get((short) shapeType));
+ return spRecord.getShapeType();
}
public int getWrapText(){
/**
* @see org.apache.poi.hssf.usermodel.drawing.ShapeTypes
- * @param value
+ * @param value - shapeType
*/
- public void setAdditionalShapeType(short value){
+ public void setShapeType(int value){
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
cod.setObjectType(OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING);
EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
- spRecord.setShapeType(value);
+ spRecord.setShapeType((short) value);
}
}
+++ /dev/null
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.apache.poi.hssf.usermodel;\r
-\r
-import org.apache.poi.ddf.EscherContainerRecord;\r
-import org.apache.poi.ddf.EscherRecord;\r
-import org.apache.poi.hssf.record.ObjRecord;\r
-\r
-/**\r
- * @author Evgeniy Berlog\r
- * date: 05.06.12\r
- */\r
-public class HSSFUnknownShape extends HSSFShape {\r
-\r
- public HSSFUnknownShape(EscherRecord spContainer, ObjRecord objRecord) {\r
- super((EscherContainerRecord) spContainer, objRecord);\r
- }\r
-\r
- @Override\r
- protected EscherContainerRecord createSpContainer() {\r
- return null;\r
- }\r
-\r
- @Override\r
- protected ObjRecord createObjRecord() {\r
- return null;\r
- }\r
-\r
- @Override\r
- protected void afterRemove(HSSFPatriarch patriarch) {\r
- }\r
-\r
- @Override\r
- void afterInsert(HSSFPatriarch patriarch) {\r
- }\r
-\r
- @Override\r
- protected HSSFShape cloneShape() {\r
- return null;\r
- }\r
-}\r
assertEquals(agg.getShapeToObjMapping().size(), 2);\r
}\r
\r
- public void testComboboxRecords(){\r
- HSSFWorkbook wb = new HSSFWorkbook();\r
- HSSFSheet sheet = wb.createSheet();\r
- HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
-\r
- HSSFCombobox combobox = new HSSFCombobox(null, new HSSFClientAnchor());\r
- HSSFTestHelper.setShapeId(combobox, 1024);\r
- ComboboxShape comboboxShape = new ComboboxShape(combobox, 1024);\r
-\r
- assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), HSSFTestHelper.getEscherContainer(combobox).serialize()));\r
- assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), HSSFTestHelper.getObjRecord(combobox).serialize()));\r
- }\r
-\r
public void testRemoveShapes(){\r
HSSFWorkbook wb = new HSSFWorkbook();\r
HSSFSheet sheet = wb.createSheet();\r
\r
rectangle.setAnchor(anchor);\r
\r
- assertNotNull(anchor.getEscherAnchor());\r
+ assertNotNull(HSSFTestHelper.getEscherAnchor(anchor));\r
assertNotNull(HSSFTestHelper.getEscherContainer(rectangle));\r
- assertTrue(anchor.getEscherAnchor().equals(HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherClientAnchorRecord.RECORD_ID)));\r
+ assertTrue(HSSFTestHelper.getEscherAnchor(anchor).equals(HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherClientAnchorRecord.RECORD_ID)));\r
}\r
\r
public void testClientAnchorFromEscher(){\r
\r
public void testClientAnchorFromScratch(){\r
HSSFClientAnchor anchor = new HSSFClientAnchor();\r
- EscherClientAnchorRecord escher = (EscherClientAnchorRecord) anchor.getEscherAnchor();\r
+ EscherClientAnchorRecord escher = (EscherClientAnchorRecord) HSSFTestHelper.getEscherAnchor(anchor);\r
anchor.setAnchor((short)11, 12, 13, 14, (short)15, 16, 17, 18);\r
\r
assertEquals(anchor.getCol1(), 11);\r
\r
public void testChildAnchorFromScratch(){\r
HSSFChildAnchor anchor = new HSSFChildAnchor();\r
- EscherChildAnchorRecord escher = (EscherChildAnchorRecord) anchor.getEscherAnchor();\r
+ EscherChildAnchorRecord escher = (EscherChildAnchorRecord) HSSFTestHelper.getEscherAnchor(anchor);\r
anchor.setAnchor(11, 12, 13, 14);\r
\r
assertEquals(anchor.getDx1(), 11);\r
public static ObjRecord getObjRecord(HSSFShape shape){
return shape.getObjRecord();
}
+
+ public static EscherRecord getEscherAnchor(HSSFAnchor anchor){
+ return anchor.getEscherAnchor();
+ }
}
expected = obj.serialize();\r
actual = objShape.serialize();\r
\r
- assertEquals(expected.length, actual.length);\r
- assertTrue(Arrays.equals(expected, actual));\r
-\r
TextObjectRecord tor = comment.getTextObjectRecord();\r
TextObjectRecord torShape = commentShape.getTextObjectRecord();\r
\r
expected = obj.serialize();\r
actual = objShape.serialize();\r
\r
- assertEquals(expected.length, actual.length);\r
- assertTrue(Arrays.equals(expected, actual));\r
-\r
TextObjectRecord tor = textbox.getTextObjectRecord();\r
TextObjectRecord torShape = textboxShape.getTextObjectRecord();\r
\r