View | Details | Raw Unified | Return to bug 53413
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java (-113 / +152 lines)
Lines 18-26 Link Here
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
import org.apache.poi.ddf.EscherClientAnchorRecord;
20
import org.apache.poi.ddf.EscherClientAnchorRecord;
21
import org.apache.poi.ddf.EscherRecord;
21
import org.apache.poi.ss.usermodel.ClientAnchor;
22
import org.apache.poi.ss.usermodel.ClientAnchor;
22
23
23
24
/**
24
/**
25
 * A client anchor is attached to an excel worksheet.  It anchors against a
25
 * A client anchor is attached to an excel worksheet.  It anchors against a
26
 * top-left and buttom-right cell.
26
 * top-left and buttom-right cell.
Lines 28-69 Link Here
28
 * @author Glen Stampoultzis (glens at apache.org)
28
 * @author Glen Stampoultzis (glens at apache.org)
29
 */
29
 */
30
public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
30
public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
31
    short col1;
32
    int row1;
33
    short col2;
34
    int row2;
35
    int anchorType;
36
31
37
    private EscherClientAnchorRecord escherClientAnchorRecord;
32
    private EscherClientAnchorRecord _escherClientAnchor;
38
33
39
    public HSSFClientAnchor(EscherClientAnchorRecord escherClientAnchorRecord) {
34
    public HSSFClientAnchor(EscherClientAnchorRecord escherClientAnchorRecord) {
40
        this.escherClientAnchorRecord = escherClientAnchorRecord;
35
        this._escherClientAnchor = escherClientAnchorRecord;
41
        //TODO set properties or read properties from EscherRecord ?
42
    }
36
    }
43
37
44
    /**
38
    /**
45
     * Creates a new client anchor and defaults all the anchor positions to 0.
39
     * Creates a new client anchor and defaults all the anchor positions to 0.
46
     */
40
     */
47
    public HSSFClientAnchor()
41
    public HSSFClientAnchor() {
48
    {
49
    }
42
    }
50
43
51
    /**
44
    /**
52
     * Creates a new client anchor and sets the top-left and bottom-right
45
     * Creates a new client anchor and sets the top-left and bottom-right
53
     * coordinates of the anchor.
46
     * coordinates of the anchor.
54
     *
47
     *
55
     * @param dx1   the x coordinate within the first cell.
48
     * @param dx1  the x coordinate within the first cell.
56
     * @param dy1   the y coordinate within the first cell.
49
     * @param dy1  the y coordinate within the first cell.
57
     * @param dx2   the x coordinate within the second cell.
50
     * @param dx2  the x coordinate within the second cell.
58
     * @param dy2   the y coordinate within the second cell.
51
     * @param dy2  the y coordinate within the second cell.
59
     * @param col1  the column (0 based) of the first cell.
52
     * @param col1 the column (0 based) of the first cell.
60
     * @param row1  the row (0 based) of the first cell.
53
     * @param row1 the row (0 based) of the first cell.
61
     * @param col2  the column (0 based) of the second cell.
54
     * @param col2 the column (0 based) of the second cell.
62
     * @param row2  the row (0 based) of the second cell.
55
     * @param row2 the row (0 based) of the second cell.
63
     */
56
     */
64
    public HSSFClientAnchor( int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2 )
57
    public HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2) {
65
    {
66
        super( dx1, dy1, dx2, dy2 );
58
        super(dx1, dy1, dx2, dy2);
67
59
68
        checkRange(dx1, 0, 1023, "dx1");
60
        checkRange(dx1, 0, 1023, "dx1");
69
        checkRange(dx2, 0, 1023, "dx2");
61
        checkRange(dx2, 0, 1023, "dx2");
Lines 74-108 Link Here
74
        checkRange(row1, 0, 255 * 256, "row1");
66
        checkRange(row1, 0, 255 * 256, "row1");
75
        checkRange(row2, 0, 255 * 256, "row2");
67
        checkRange(row2, 0, 255 * 256, "row2");
76
68
77
        this.col1 = col1;
69
        setCol1(col1);
78
        this.row1 = row1;
70
        setCol2(col2);
79
        this.col2 = col2;
71
        setRow1(row1);
80
        this.row2 = row2;
72
        setRow2(row2);
81
    }
73
    }
82
74
83
    /**
75
    /**
84
     * Calculates the height of a client anchor in points.
76
     * Calculates the height of a client anchor in points.
85
     *
77
     *
86
     * @param sheet     the sheet the anchor will be attached to
78
     * @param sheet the sheet the anchor will be attached to
87
     * @return          the shape height.
79
     * @return the shape height.
88
     */
80
     */
89
    public float getAnchorHeightInPoints(HSSFSheet sheet )
81
    public float getAnchorHeightInPoints(HSSFSheet sheet) {
90
    {
91
        int y1 = getDy1();
82
        int y1 = getDy1();
92
        int y2 = getDy2();
83
        int y2 = getDy2();
93
        int row1 = Math.min( getRow1(), getRow2() );
84
        int row1 = Math.min(getRow1(), getRow2());
94
        int row2 = Math.max( getRow1(), getRow2() );
85
        int row2 = Math.max(getRow1(), getRow2());
95
86
96
        float points = 0;
87
        float points = 0;
97
        if (row1 == row2)
88
        if (row1 == row2) {
98
        {
99
            points = ((y2 - y1) / 256.0f) * getRowHeightInPoints(sheet, row2);
89
            points = ((y2 - y1) / 256.0f) * getRowHeightInPoints(sheet, row2);
100
        }
90
        } else {
101
        else
102
        {
103
            points += ((256.0f - y1) / 256.0f) * getRowHeightInPoints(sheet, row1);
91
            points += ((256.0f - y1) / 256.0f) * getRowHeightInPoints(sheet, row1);
104
            for (int i = row1 + 1; i < row2; i++)
92
            for (int i = row1 + 1; i < row2; i++) {
105
            {
106
                points += getRowHeightInPoints(sheet, i);
93
                points += getRowHeightInPoints(sheet, i);
107
            }
94
            }
108
            points += (y2 / 256.0f) * getRowHeightInPoints(sheet, row2);
95
            points += (y2 / 256.0f) * getRowHeightInPoints(sheet, row2);
Lines 111-118 Link Here
111
        return points;
98
        return points;
112
    }
99
    }
113
100
114
    private float getRowHeightInPoints(HSSFSheet sheet, int rowNum)
101
    private float getRowHeightInPoints(HSSFSheet sheet, int rowNum) {
115
    {
116
        HSSFRow row = sheet.getRow(rowNum);
102
        HSSFRow row = sheet.getRow(rowNum);
117
        if (row == null) {
103
        if (row == null) {
118
            return sheet.getDefaultRowHeightInPoints();
104
            return sheet.getDefaultRowHeightInPoints();
Lines 120-174 Link Here
120
        return row.getHeightInPoints();
106
        return row.getHeightInPoints();
121
    }
107
    }
122
108
123
    public short getCol1()
109
    public short getCol1() {
124
    {
110
        return _escherClientAnchor.getCol1();
125
        return col1;
126
    }
111
    }
127
112
128
    public void setCol1( short col1 )
113
    public void setCol1(short col1) {
129
    {
130
        checkRange(col1, 0, 255, "col1");
114
        checkRange(col1, 0, 255, "col1");
131
        this.col1 = col1;
115
        _escherClientAnchor.setCol1(col1);
132
    }
116
    }
133
    public void setCol1( int col1 ){
117
134
        setCol1((short)col1);
118
    public void setCol1(int col1) {
119
        setCol1((short) col1);
135
    }
120
    }
136
121
137
    public short getCol2()
122
    public short getCol2() {
138
    {
123
        return _escherClientAnchor.getCol2();
139
        return col2;
140
    }
124
    }
141
125
142
    public void setCol2( short col2 )
126
    public void setCol2(short col2) {
143
    {
144
        checkRange(col2, 0, 255, "col2");
127
        checkRange(col2, 0, 255, "col2");
145
        this.col2 = col2;
128
        _escherClientAnchor.setCol2(col2);
146
    }
129
    }
147
130
148
    public void setCol2( int col2 ){
131
    public void setCol2(int col2) {
149
        setCol2((short)col2);
132
        setCol2((short) col2);
150
    }
133
    }
151
134
152
    public int getRow1()
135
    public int getRow1() {
153
    {
136
        return _escherClientAnchor.getRow1();
154
        return row1;
155
    }
137
    }
156
138
157
    public void setRow1( int row1 )
139
    public void setRow1(int row1) {
158
    {
159
        checkRange(row1, 0, 256 * 256, "row1");
140
        checkRange(row1, 0, 256 * 256, "row1");
160
        this.row1 = row1;
141
        _escherClientAnchor.setRow1(Integer.valueOf(row1).shortValue());
161
    }
142
    }
162
143
163
    public int getRow2()
144
    public int getRow2() {
164
    {
145
        return _escherClientAnchor.getRow2();
165
        return row2;
166
    }
146
    }
167
147
168
    public void setRow2( int row2 )
148
    public void setRow2(int row2) {
169
    {
170
        checkRange(row2, 0, 256 * 256, "row2");
149
        checkRange(row2, 0, 256 * 256, "row2");
171
        this.row2 = row2;
150
        _escherClientAnchor.setRow2(Integer.valueOf(row2).shortValue());
172
    }
151
    }
173
152
174
    /**
153
    /**
Lines 179-257 Link Here
179
     * @param y1   the y coordinate within the first cell.
158
     * @param y1   the y coordinate within the first cell.
180
     * @param x2   the x coordinate within the second cell.
159
     * @param x2   the x coordinate within the second cell.
181
     * @param y2   the y coordinate within the second cell.
160
     * @param y2   the y coordinate within the second cell.
182
     * @param col1  the column (0 based) of the first cell.
161
     * @param col1 the column (0 based) of the first cell.
183
     * @param row1  the row (0 based) of the first cell.
162
     * @param row1 the row (0 based) of the first cell.
184
     * @param col2  the column (0 based) of the second cell.
163
     * @param col2 the column (0 based) of the second cell.
185
     * @param row2  the row (0 based) of the second cell.
164
     * @param row2 the row (0 based) of the second cell.
186
     */
165
     */
187
    public void setAnchor( short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2 )
166
    public void setAnchor(short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2) {
188
    {
167
        checkRange(getDx1(), 0, 1023, "dx1");
189
        checkRange(dx1, 0, 1023, "dx1");
168
        checkRange(getDx2(), 0, 1023, "dx2");
190
        checkRange(dx2, 0, 1023, "dx2");
169
        checkRange(getDy1(), 0, 255, "dy1");
191
        checkRange(dy1, 0, 255, "dy1");
170
        checkRange(getDy2(), 0, 255, "dy2");
192
        checkRange(dy2, 0, 255, "dy2");
171
        checkRange(getCol1(), 0, 255, "col1");
193
        checkRange(col1, 0, 255, "col1");
172
        checkRange(getCol2(), 0, 255, "col2");
194
        checkRange(col2, 0, 255, "col2");
173
        checkRange(getRow1(), 0, 255 * 256, "row1");
195
        checkRange(row1, 0, 255 * 256, "row1");
174
        checkRange(getRow2(), 0, 255 * 256, "row2");
196
        checkRange(row2, 0, 255 * 256, "row2");
197
175
198
        this.col1 = col1;
176
        setCol1(col1);
199
        this.row1 = row1;
177
        setRow1(row1);
200
        this.dx1 = x1;
178
        setDx1(x1);
201
        this.dy1 = y1;
179
        setDy1(y1);
202
        this.col2 = col2;
180
        setCol2(col2);
203
        this.row2 = row2;
181
        setRow2(row2);
204
        this.dx2 = x2;
182
        setDx2(x2);
205
        this.dy2 = y2;
183
        setDy2(y2);
206
    }
184
    }
207
185
208
    /**
186
    /**
209
     * @return  true if the anchor goes from right to left.
187
     * @return true if the anchor goes from right to left.
210
     */
188
     */
211
    public boolean isHorizontallyFlipped()
189
    public boolean isHorizontallyFlipped() {
212
    {
190
        if (getCol1() == getCol2()) {
213
        if (col1 == col2) {
191
            return getDx1() > getDx2();
214
            return dx1 > dx2;
215
        }
192
        }
216
        return col1 > col2;
193
        return getCol1() > getCol2();
217
    }
194
    }
218
195
219
    /**
196
    /**
220
     * @return  true if the anchor goes from bottom to top.
197
     * @return true if the anchor goes from bottom to top.
221
     */
198
     */
222
    public boolean isVerticallyFlipped()
199
    public boolean isVerticallyFlipped() {
223
    {
200
        if (getRow1() == getRow2()) {
224
        if (row1 == row2) {
201
            return getDy1() > getDy2();
225
            return dy1 > dy2;
226
        }
202
        }
227
        return row1 > row2;
203
        return getRow1() > getRow2();
228
    }
204
    }
229
205
206
    @Override
207
    public EscherRecord getEscherAnchor() {
208
        return _escherClientAnchor;
209
    }
210
211
    @Override
212
    protected void createEscherAnchor() {
213
        _escherClientAnchor = new EscherClientAnchorRecord();
214
    }
215
230
    /**
216
    /**
231
     * Gets the anchor type
217
     * Gets the anchor type
232
     * <p>
218
     * <p/>
233
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
219
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
234
     */
220
     */
235
    public int getAnchorType()
221
    public int getAnchorType() {
236
    {
222
        return _escherClientAnchor.getFlag();
237
        return anchorType;
238
    }
223
    }
239
224
240
    /**
225
    /**
241
     * Sets the anchor type
226
     * Sets the anchor type
242
     * <p>
227
     * <p/>
243
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
228
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
244
     */
229
     */
245
    public void setAnchorType( int anchorType )
230
    public void setAnchorType(int anchorType) {
246
    {
231
//        if (0 != anchorType && 2 != anchorType && 3 != anchorType){
247
        this.anchorType = anchorType;
232
//            throw new IllegalArgumentException("Anchor type of shape can take only such values: 0, 2, 3");
233
//        }
234
        _escherClientAnchor.setFlag(Integer.valueOf(anchorType).shortValue());
248
    }
235
    }
249
236
250
    private void checkRange( int value, int minRange, int maxRange, String varName )
237
    private void checkRange(int value, int minRange, int maxRange, String varName) {
251
    {
252
        if (value < minRange || value > maxRange)
238
        if (value < minRange || value > maxRange)
253
            throw new IllegalArgumentException(varName + " must be between " + minRange + " and " + maxRange);
239
            throw new IllegalArgumentException(varName + " must be between " + minRange + " and " + maxRange);
254
    }
240
    }
255
241
242
    @Override
243
    public boolean equals(Object obj) {
244
        if (obj == null)
245
            return false;
246
        if (obj == this)
247
            return true;
248
        if (obj.getClass() != getClass())
249
            return false;
250
        HSSFClientAnchor anchor = (HSSFClientAnchor) obj;
256
251
252
        return anchor.getCol1() == getCol1() && anchor.getCol2() == getCol2() && anchor.getDx1() == getDx1()
253
                && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1() && anchor.getDy2() == getDy2()
254
                && anchor.getRow1() == getRow1() && anchor.getRow2() == getRow2() && anchor.getAnchorType() == getAnchorType();
255
    }
256
257
    @Override
258
    public int getDx1() {
259
        return _escherClientAnchor.getDx1();
260
    }
261
262
    @Override
263
    public void setDx1(int dx1) {
264
        _escherClientAnchor.setDx1(Integer.valueOf(dx1).shortValue());
265
    }
266
267
    @Override
268
    public int getDy1() {
269
        return _escherClientAnchor.getDy1();
270
    }
271
272
    @Override
273
    public void setDy1(int dy1) {
274
        _escherClientAnchor.setDy1(Integer.valueOf(dy1).shortValue());
275
    }
276
277
    @Override
278
    public int getDy2() {
279
        return _escherClientAnchor.getDy2();
280
    }
281
282
    @Override
283
    public void setDy2(int dy2) {
284
        _escherClientAnchor.setDy2(Integer.valueOf(dy2).shortValue());
285
    }
286
287
    @Override
288
    public int getDx2() {
289
        return _escherClientAnchor.getDx2();
290
    }
291
292
    @Override
293
    public void setDx2(int dx2) {
294
        _escherClientAnchor.setDx2(Integer.valueOf(dx2).shortValue());
295
    }
257
}
296
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java (-1 / +11 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
import org.apache.poi.ddf.*;
21
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
22
import org.apache.poi.hssf.record.ObjRecord;
23
20
/**
24
/**
21
 * Represents a simple shape such as a line, rectangle or oval.
25
 * Represents a simple shape such as a line, rectangle or oval.
22
 *
26
 *
Lines 51-58 Link Here
51
//    public final static short       OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
55
//    public final static short       OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
52
56
53
    int shapeType = OBJECT_TYPE_LINE;
57
    int shapeType = OBJECT_TYPE_LINE;
58
59
    public HSSFSimpleShape(EscherContainerRecord spContainer, ObjRecord objRecord) {
60
        super(spContainer, objRecord);
61
        CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
62
        setShapeType(cod.getObjectType());
63
    }
54
64
55
    public HSSFSimpleShape( HSSFShape parent, HSSFAnchor anchor )
65
    public HSSFSimpleShape( HSSFShape parent, HSSFAnchor anchor)
56
    {
66
    {
57
        super( parent, anchor );
67
        super( parent, anchor );
58
    }
68
    }
(-)src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java (+160 lines)
Line 0 Link Here
1
package org.apache.poi.hssf.model;
2
3
import junit.framework.TestCase;
4
import org.apache.poi.ddf.*;
5
import org.apache.poi.hssf.HSSFTestDataSamples;
6
import org.apache.poi.hssf.usermodel.*;
7
import org.apache.poi.util.HexDump;
8
9
import java.io.IOException;
10
11
import static junit.framework.Assert.assertEquals;
12
13
/**
14
 * @author Evgeniy Berlog
15
 * date: 12.06.12
16
 */
17
public class TestDrawingShapes extends TestCase{
18
19
    /**
20
     * HSSFShape tree bust be built correctly
21
     * Check file with such records structure:
22
     * -patriarch
23
     * --shape
24
     * --group
25
     * ---group
26
     * ----shape
27
     * ----shape
28
     * ---shape
29
     * ---group
30
     * ----shape
31
     * ----shape
32
     */
33
    public void testDrawingGroups(){
34
        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
35
        HSSFSheet sheet = wb.getSheet("groups");
36
        HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
37
        assertEquals(patriarch.getChildren().size(), 2);
38
        HSSFShapeGroup group = (HSSFShapeGroup) patriarch.getChildren().get(1);
39
        assertEquals(3, group.getChildren().size());
40
        HSSFShapeGroup group1 = (HSSFShapeGroup) group.getChildren().get(0);
41
        assertEquals(2, group1.getChildren().size());
42
        group1 = (HSSFShapeGroup) group.getChildren().get(2);
43
        assertEquals(2, group1.getChildren().size());
44
    }
45
46
    public void testHSSFShapeCompatibility() {
47
        HSSFShape shape = new HSSFSimpleShape(null, new  HSSFClientAnchor());
48
        assertEquals(0x08000040, shape.getLineStyleColor());
49
        assertEquals(0x08000009, shape.getFillColor());
50
        assertEquals(HSSFShape.LINEWIDTH_DEFAULT, shape.getLineWidth());
51
        assertEquals(HSSFShape.LINESTYLE_SOLID, shape.getLineStyle());
52
        assertFalse(shape.isNoFill());
53
54
        AbstractShape sp = AbstractShape.createShape(shape, 1);
55
        EscherContainerRecord spContainer = sp.getSpContainer();
56
        EscherOptRecord opt =
57
                spContainer.getChildById(EscherOptRecord.RECORD_ID);
58
59
        assertEquals(7, opt.getEscherProperties().size());
60
        assertEquals(true,
61
                ((EscherBoolProperty)opt.lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).isTrue());
62
        assertEquals(0x00000004,
63
                ((EscherSimpleProperty)opt.lookup(EscherProperties.GEOMETRY__SHAPEPATH)).getPropertyValue());
64
        assertEquals(0x08000009,
65
                ((EscherSimpleProperty)opt.lookup(EscherProperties.FILL__FILLCOLOR)).getPropertyValue());
66
        assertEquals(true,
67
                ((EscherBoolProperty)opt.lookup(EscherProperties.FILL__NOFILLHITTEST)).isTrue());
68
        assertEquals(0x08000040,
69
                ((EscherSimpleProperty)opt.lookup(EscherProperties.LINESTYLE__COLOR)).getPropertyValue());
70
        assertEquals(true,
71
                ((EscherBoolProperty)opt.lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).isTrue());
72
        assertEquals(true,
73
                ((EscherBoolProperty)opt.lookup(EscherProperties.GROUPSHAPE__PRINT)).isTrue());
74
    }
75
    /**
76
     * create a rectangle, save the workbook, read back and verify that all shape properties are there
77
     */
78
    public void testReadWriteRectangle() throws IOException {
79
80
        HSSFWorkbook wb = new HSSFWorkbook();
81
        HSSFSheet sheet = wb.createSheet();
82
83
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
84
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);
85
        anchor.setAnchorType(2);
86
        assertEquals(anchor.getAnchorType(), 2);
87
88
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
89
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
90
        rectangle.setLineWidth(10000);
91
        rectangle.setFillColor(777);
92
        assertEquals(rectangle.getFillColor(), 777);
93
        assertEquals(10000, rectangle.getLineWidth());
94
        rectangle.setLineStyle(10);
95
        assertEquals(10, rectangle.getLineStyle());
96
        rectangle.setLineStyleColor(1111);
97
        rectangle.setNoFill(true);
98
        assertEquals(rectangle.getLineStyleColor(), 1111);
99
        assertEquals(rectangle.isNoFill(), true);
100
101
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
102
        sheet = wb.getSheetAt(0);
103
        drawing = sheet.getDrawingPatriarch();
104
        assertEquals(1, drawing.getChildren().size());
105
106
        HSSFSimpleShape rectangle2 =
107
                (HSSFSimpleShape)drawing.getChildren().get(0);
108
        assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE,
109
                rectangle2.getShapeType());
110
        assertEquals(10000, rectangle2.getLineWidth());
111
        assertEquals(10, rectangle2.getLineStyle());
112
        assertEquals(anchor, rectangle2.getAnchor());
113
        assertEquals(rectangle2.getLineStyleColor(), 1111);
114
        assertEquals(rectangle2.getFillColor(), 777);
115
        assertEquals(rectangle2.isNoFill(), true);
116
117
        rectangle2.setFillColor(3333);
118
        rectangle2.setLineStyle(9);
119
        rectangle2.setLineStyleColor(4444);
120
        rectangle2.setNoFill(false);
121
        rectangle2.setLineWidth(77);
122
        rectangle2.getAnchor().setDx1(2);
123
        rectangle2.getAnchor().setDx2(3);
124
        rectangle2.getAnchor().setDy1(4);
125
        rectangle2.getAnchor().setDy2(5);
126
127
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
128
        sheet = wb.getSheetAt(0);
129
        drawing = sheet.getDrawingPatriarch();
130
        assertEquals(1, drawing.getChildren().size());
131
        rectangle2 = (HSSFSimpleShape)drawing.getChildren().get(0);
132
        assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType());
133
        assertEquals(77, rectangle2.getLineWidth());
134
        assertEquals(9, rectangle2.getLineStyle());
135
        assertEquals(rectangle2.getLineStyleColor(), 4444);
136
        assertEquals(rectangle2.getFillColor(), 3333);
137
        assertEquals(rectangle2.getAnchor().getDx1(), 2);
138
        assertEquals(rectangle2.getAnchor().getDx2(), 3);
139
        assertEquals(rectangle2.getAnchor().getDy1(), 4);
140
        assertEquals(rectangle2.getAnchor().getDy2(), 5);
141
        assertEquals(rectangle2.isNoFill(), false);
142
    }
143
144
145
    /* assert shape properties when reading shapes from a existing workbook */
146
    public void testReadExistingRectangle() {
147
        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
148
        HSSFSheet sheet = wb.getSheet("rectangles");
149
        HSSFPatriarch drawing = sheet.getDrawingPatriarch();
150
        assertEquals(1, drawing.getChildren().size());
151
152
        for(HSSFShape shape : drawing.getChildren()){
153
            assertEquals(shape.isNoFill(), true);
154
            assertEquals(shape.getLineStyle(), HSSFShape.LINESTYLE_DASHDOTGEL);
155
            assertEquals(shape.getLineStyleColor(), 0x616161);
156
            assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D);
157
            assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT*2);
158
        }
159
    }
160
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFRectangle.java (-15 lines)
Lines 1-15 Link Here
1
package org.apache.poi.hssf.usermodel;
2
3
import org.apache.poi.ddf.EscherContainerRecord;
4
import org.apache.poi.hssf.record.ObjRecord;
5
6
/**
7
 * @author Evgeniy Berlog
8
 * @date 08.06.12
9
 */
10
public class HSSFRectangle extends HSSFShape{
11
12
    public HSSFRectangle(EscherContainerRecord spContainer, ObjRecord objRecord) {
13
        super(spContainer, objRecord);
14
    }
15
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java (-19 / +80 lines)
Lines 19-57 Link Here
19
19
20
20
21
import org.apache.poi.ddf.EscherChildAnchorRecord;
21
import org.apache.poi.ddf.EscherChildAnchorRecord;
22
import org.apache.poi.ddf.EscherRecord;
22
23
23
public final class HSSFChildAnchor extends HSSFAnchor {
24
public final class HSSFChildAnchor extends HSSFAnchor {
24
25
25
    private EscherChildAnchorRecord escherChildAnchorRecord;
26
    private EscherChildAnchorRecord _escherChildAnchor;
26
27
27
    public HSSFChildAnchor(EscherChildAnchorRecord escherChildAnchorRecord) {
28
    public HSSFChildAnchor(EscherChildAnchorRecord escherChildAnchorRecord) {
28
        this.escherChildAnchorRecord = escherChildAnchorRecord;
29
        this._escherChildAnchor = escherChildAnchorRecord;
29
    }
30
    }
30
31
31
    public HSSFChildAnchor()
32
    public HSSFChildAnchor() {
32
    {
33
        _escherChildAnchor = new EscherChildAnchorRecord();
33
    }
34
    }
34
35
35
    public HSSFChildAnchor( int dx1, int dy1, int dx2, int dy2 )
36
    public HSSFChildAnchor(int dx1, int dy1, int dx2, int dy2) {
36
    {
37
        super( dx1, dy1, dx2, dy2 );
37
        super(dx1, dy1, dx2, dy2);
38
    }
38
    }
39
39
40
    public void setAnchor(int dx1, int dy1, int dx2, int dy2)
40
    @Override
41
    {
41
    public int getDx1() {
42
        this.dx1 = dx1;
42
        return _escherChildAnchor.getDx1();
43
        this.dy1 = dy1;
44
        this.dx2 = dx2;
45
        this.dy2 = dy2;
46
    }
43
    }
47
44
48
    public boolean isHorizontallyFlipped()
45
    @Override
49
    {
46
    public void setDx1(int dx1) {
50
        return dx1 > dx2;
47
        _escherChildAnchor.setDx1(dx1);
51
    }
48
    }
52
49
53
    public boolean isVerticallyFlipped()
50
    @Override
54
    {
51
    public int getDy1() {
55
        return dy1 > dy2;
52
        return _escherChildAnchor.getDy1();
53
    }
54
55
    @Override
56
    public void setDy1(int dy1) {
57
        _escherChildAnchor.setDy1(dy1);
58
    }
59
60
    @Override
61
    public int getDy2() {
62
        return _escherChildAnchor.getDy2();
63
    }
64
65
    @Override
66
    public void setDy2(int dy2) {
67
        _escherChildAnchor.setDy2(dy2);
68
    }
69
70
    @Override
71
    public int getDx2() {
72
        return _escherChildAnchor.getDx2();
73
    }
74
75
    @Override
76
    public void setDx2(int dx2) {
77
        _escherChildAnchor.setDx2(dx2);
78
    }
79
80
    public void setAnchor(int dx1, int dy1, int dx2, int dy2) {
81
        setDx1(dx1);
82
        setDy1(dy1);
83
        setDx2(dx2);
84
        setDy2(dy2);
85
    }
86
87
    public boolean isHorizontallyFlipped() {
88
        return getDx1() > getDx2();
89
    }
90
91
    public boolean isVerticallyFlipped() {
92
        return getDy1() > getDy2();
93
    }
94
95
    @Override
96
    public EscherRecord getEscherAnchor() {
97
        return _escherChildAnchor;
98
    }
99
100
    @Override
101
    protected void createEscherAnchor() {
102
        _escherChildAnchor = new EscherChildAnchorRecord();
103
    }
104
105
    @Override
106
    public boolean equals(Object obj) {
107
        if (obj == null)
108
            return false;
109
        if (obj == this)
110
            return true;
111
        if (obj.getClass() != getClass())
112
            return false;
113
        HSSFChildAnchor anchor = (HSSFChildAnchor) obj;
114
115
        return anchor.getDx1() == getDx1() && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1()
116
                && anchor.getDy2() == getDy2();
56
    }
117
    }
57
}
118
}
(-)src/java/org/apache/poi/ddf/EscherSimpleProperty.java (+4 lines)
Lines 80-85 Link Here
80
        return propertyValue;
80
        return propertyValue;
81
    }
81
    }
82
82
83
    public void setPropertyValue(int propertyValue) {
84
        this.propertyValue = propertyValue;
85
    }
86
83
    /**
87
    /**
84
     * Returns true if one escher property is equal to another.
88
     * Returns true if one escher property is equal to another.
85
     */
89
     */
(-)src/java/org/apache/poi/hssf/usermodel/HSSFAnchor.java (-22 / +46 lines)
Lines 18-57 Link Here
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
20
21
import org.apache.poi.ddf.EscherChildAnchorRecord;
22
import org.apache.poi.ddf.EscherClientAnchorRecord;
23
import org.apache.poi.ddf.EscherContainerRecord;
24
import org.apache.poi.ddf.EscherRecord;
25
21
/**
26
/**
22
 * An anchor is what specifics the position of a shape within a client object
27
 * An anchor is what specifics the position of a shape within a client object
23
 * or within another containing shape.
28
 * or within another containing shape.
24
 *
29
 *
25
 * @author Glen Stampoultzis (glens at apache.org)
30
 * @author Glen Stampoultzis (glens at apache.org)
26
 */
31
 */
27
public abstract class HSSFAnchor
32
public abstract class HSSFAnchor {
28
{
29
    int dx1;
30
    int dy1;
31
    int dx2;
32
    int dy2;
33
33
34
    public HSSFAnchor()
34
    public HSSFAnchor() {
35
    {
35
        createEscherAnchor();
36
    }
36
    }
37
37
38
    public HSSFAnchor( int dx1, int dy1, int dx2, int dy2 )
38
    public HSSFAnchor(int dx1, int dy1, int dx2, int dy2) {
39
    {
39
        createEscherAnchor();
40
        this.dx1 = dx1;
40
        setDx1(dx1);
41
        this.dy1 = dy1;
41
        setDy1(dy1);
42
        this.dx2 = dx2;
42
        setDx2(dx2);
43
        this.dy2 = dy2;
43
        setDy2(dy2);
44
    }
44
    }
45
45
46
    public int getDx1(){ return dx1; }
46
    public static HSSFAnchor createAnchorFromEscher(EscherContainerRecord container){
47
    public void setDx1( int dx1 ){ this.dx1 = dx1; }
47
        if (null != container.getChildById(EscherChildAnchorRecord.RECORD_ID)){
48
    public int getDy1(){ return dy1; }
48
            return new HSSFChildAnchor((EscherChildAnchorRecord) container.getChildById(EscherChildAnchorRecord.RECORD_ID));
49
    public void setDy1( int dy1 ){ this.dy1 = dy1; }
49
        } else {
50
    public int getDy2(){ return dy2; }
50
            if (null != container.getChildById(EscherClientAnchorRecord.RECORD_ID)){
51
    public void setDy2( int dy2 ){ this.dy2 = dy2; }
51
                return new HSSFClientAnchor((EscherClientAnchorRecord) container.getChildById(EscherClientAnchorRecord.RECORD_ID));
52
    public int getDx2(){ return dx2; }
52
            }
53
    public void setDx2( int dx2 ){ this.dx2 = dx2; }
53
            return null;
54
//            throw new IllegalArgumentException("continer must have anchor record");
55
        }
56
    }
54
57
58
    public abstract int getDx1();
59
60
    public abstract void setDx1(int dx1);
61
62
    public abstract int getDy1();
63
64
    public abstract void setDy1(int dy1);
65
66
    public abstract int getDy2();
67
68
    public abstract void setDy2(int dy2);
69
70
    public abstract int getDx2();
71
72
    public abstract void setDx2(int dx2);
73
55
    public abstract boolean isHorizontallyFlipped();
74
    public abstract boolean isHorizontallyFlipped();
75
56
    public abstract boolean isVerticallyFlipped();
76
    public abstract boolean isVerticallyFlipped();
77
78
    public abstract EscherRecord getEscherAnchor();
79
80
    protected abstract void createEscherAnchor();
57
}
81
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (-21 / +17 lines)
Lines 41-72 Link Here
41
        implements HSSFShapeContainer
41
        implements HSSFShapeContainer
42
{
42
{
43
    List<HSSFShape> shapes = new ArrayList<HSSFShape>();
43
    List<HSSFShape> shapes = new ArrayList<HSSFShape>();
44
    int x1 = 0;
44
    private EscherSpgrRecord _spgrRecord;
45
    int y1  = 0 ;
46
    int x2 = 1023;
47
    int y2 = 255;
48
45
49
    public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) {
46
    public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) {
50
        super(spgrContainer, objRecord);
47
        super(spgrContainer, objRecord);
51
48
52
        // read internal and external coordinates from spgrContainer
49
        // read internal and external coordinates from spgrContainer
53
        EscherContainerRecord spContainer = spgrContainer.getChildContainers().get(0);
50
        EscherContainerRecord spContainer = spgrContainer.getChildContainers().get(0);
51
        _spgrRecord = (EscherSpgrRecord) spContainer.getChild(0);
54
        for(EscherRecord ch : spContainer.getChildRecords()){
52
        for(EscherRecord ch : spContainer.getChildRecords()){
55
            switch(ch.getRecordId()) {
53
            switch(ch.getRecordId()) {
56
                case EscherSpgrRecord.RECORD_ID:
54
                case EscherSpgrRecord.RECORD_ID:
57
                    EscherSpgrRecord spgr = (EscherSpgrRecord)ch;
58
                    setCoordinates(
59
                            spgr.getRectX1(), spgr.getRectY1(),
60
                            spgr.getRectX2(), spgr.getRectY2()
61
                    );
62
                    break;
55
                    break;
63
                case EscherClientAnchorRecord.RECORD_ID:
56
                case EscherClientAnchorRecord.RECORD_ID:
64
                    this.anchor = EscherAggregate.toClientAnchor((EscherClientAnchorRecord)ch);
57
                    anchor = new HSSFClientAnchor((EscherClientAnchorRecord)ch);
65
                    // TODO anchor = new HSSFClientAnchor((EscherChildAnchorRecord)ch);
66
                    break;
58
                    break;
67
                case EscherChildAnchorRecord.RECORD_ID:
59
                case EscherChildAnchorRecord.RECORD_ID:
68
                    this.anchor = EscherAggregate.toChildAnchor((EscherChildAnchorRecord)ch);
60
                    anchor = new HSSFChildAnchor((EscherChildAnchorRecord)ch);
69
                    // TODO anchor = new HSSFChildAnchor((EscherClientAnchorRecord)ch);
70
                    break;
61
                    break;
71
            }
62
            }
72
        }
63
        }
Lines 76-81 Link Here
76
    public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
67
    public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
77
    {
68
    {
78
        super( parent, anchor );
69
        super( parent, anchor );
70
        _spgrRecord = new EscherSpgrRecord();
71
        _spgrRecord.setRectX1(0);
72
        _spgrRecord.setRectX2(1023);
73
        _spgrRecord.setRectY1(0);
74
        _spgrRecord.setRectY2(255);
79
    }
75
    }
80
76
81
    /**
77
    /**
Lines 171-180 Link Here
171
     */
167
     */
172
    public void setCoordinates( int x1, int y1, int x2, int y2 )
168
    public void setCoordinates( int x1, int y1, int x2, int y2 )
173
    {
169
    {
174
        this.x1 = x1;
170
        _spgrRecord.setRectX1(x1);
175
        this.y1 = y1;
171
        _spgrRecord.setRectX2(x2);
176
        this.x2 = x2;
172
        _spgrRecord.setRectY1(y1);
177
        this.y2 = y2;
173
        _spgrRecord.setRectY2(y2);
178
    }
174
    }
179
175
180
    /**
176
    /**
Lines 182-188 Link Here
182
     */
178
     */
183
    public int getX1()
179
    public int getX1()
184
    {
180
    {
185
        return x1;
181
        return _spgrRecord.getRectX1();
186
    }
182
    }
187
183
188
    /**
184
    /**
Lines 190-196 Link Here
190
     */
186
     */
191
    public int getY1()
187
    public int getY1()
192
    {
188
    {
193
        return y1;
189
        return _spgrRecord.getRectY1();
194
    }
190
    }
195
191
196
    /**
192
    /**
Lines 198-204 Link Here
198
     */
194
     */
199
    public int getX2()
195
    public int getX2()
200
    {
196
    {
201
        return x2;
197
        return _spgrRecord.getRectX2();
202
    }
198
    }
203
199
204
    /**
200
    /**
Lines 206-212 Link Here
206
     */
202
     */
207
    public int getY2()
203
    public int getY2()
208
    {
204
    {
209
        return y2;
205
        return _spgrRecord.getRectY2();
210
    }
206
    }
211
207
212
    /**
208
    /**
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (-65 / +122 lines)
Lines 17-23 Link Here
17
17
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
import org.apache.poi.ddf.EscherContainerRecord;
20
import org.apache.poi.ddf.*;
21
import org.apache.poi.hssf.record.ObjRecord;
21
import org.apache.poi.hssf.record.ObjRecord;
22
22
23
/**
23
/**
Lines 28-33 Link Here
28
public abstract class HSSFShape {
28
public abstract class HSSFShape {
29
    public static final int LINEWIDTH_ONE_PT = 12700;
29
    public static final int LINEWIDTH_ONE_PT = 12700;
30
    public static final int LINEWIDTH_DEFAULT = 9525;
30
    public static final int LINEWIDTH_DEFAULT = 9525;
31
    public static final int LINESTYLE__COLOR_DEFAULT = 0x08000040;
32
    public static final int FILL__FILLCOLOR_DEFAULT = 0x08000009;
31
33
32
    public static final int LINESTYLE_SOLID = 0;              // Solid (continuous) pen
34
    public static final int LINESTYLE_SOLID = 0;              // Solid (continuous) pen
33
    public static final int LINESTYLE_DASHSYS = 1;            // PS_DASH system   dash style
35
    public static final int LINESTYLE_DASHSYS = 1;            // PS_DASH system   dash style
Lines 45-94 Link Here
45
    // TODO - make all these fields private
47
    // TODO - make all these fields private
46
    HSSFShape parent;
48
    HSSFShape parent;
47
    HSSFAnchor anchor;
49
    HSSFAnchor anchor;
48
    HSSFPatriarch _patriarch;  
50
    HSSFPatriarch _patriarch;
49
    private int _lineStyleColor = 0x08000040;
50
    int _fillColor = 0x08000009;
51
    private int _lineWidth = LINEWIDTH_DEFAULT;    // 12700 = 1pt
52
    private int _lineStyle = LINESTYLE_SOLID;
53
    private boolean _noFill = false;
54
51
55
    private EscherContainerRecord spContainer;
52
    protected EscherContainerRecord _escherContainer;
56
    private ObjRecord objRecord;
53
    protected ObjRecord _objRecord;
54
    protected final EscherOptRecord _optRecord;
57
55
58
    public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord){
56
    public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord) {
59
        this.spContainer = spContainer;
57
        this._escherContainer = spContainer;
60
        this.objRecord = objRecord;
58
        this._objRecord = objRecord;
59
        this._optRecord = spContainer.getChildById(EscherOptRecord.RECORD_ID);
60
        this.anchor = HSSFAnchor.createAnchorFromEscher(spContainer);
61
    }
61
    }
62
62
    /**
63
    /**
63
     * Create a new shape with the specified parent and anchor.
64
     * Create a new shape with the specified parent and anchor.
64
     */
65
     */
65
    public HSSFShape( HSSFShape parent, HSSFAnchor anchor )
66
    public HSSFShape(HSSFShape parent, HSSFAnchor anchor) {
66
    {
67
        this.parent = parent;
67
        this.parent = parent;
68
        this.anchor = anchor;
68
        this.anchor = anchor;
69
        this._escherContainer = new EscherContainerRecord();
70
        _optRecord = new EscherOptRecord();
71
        _optRecord.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
72
        _optRecord.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
73
        _optRecord.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
74
        _optRecord.addEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
75
        _optRecord.addEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x0));
69
    }
76
    }
70
77
71
    public EscherContainerRecord getSpContainer() {
78
    public EscherContainerRecord getEscherContainer() {
72
        return spContainer;
79
        return _escherContainer;
73
    }
80
    }
74
81
75
    public ObjRecord getObjRecord() {
82
    public ObjRecord getObjRecord() {
76
        return objRecord;
83
        return _objRecord;
77
    }
84
    }
78
85
79
    /**
86
    /**
80
     * Gets the parent shape.
87
     * Gets the parent shape.
81
     */
88
     */
82
    public HSSFShape getParent()
89
    public HSSFShape getParent() {
83
    {
84
        return parent;
90
        return parent;
85
    }
91
    }
86
92
87
    /**
93
    /**
88
     * @return  the anchor that is used by this shape.
94
     * @return the anchor that is used by this shape.
89
     */
95
     */
90
    public HSSFAnchor getAnchor()
96
    public HSSFAnchor getAnchor() {
91
    {
92
        return anchor;
97
        return anchor;
93
    }
98
    }
94
99
Lines 96-121 Link Here
96
     * Sets a particular anchor.  A top-level shape must have an anchor of
101
     * Sets a particular anchor.  A top-level shape must have an anchor of
97
     * HSSFClientAnchor.  A child anchor must have an anchor of HSSFChildAnchor
102
     * HSSFClientAnchor.  A child anchor must have an anchor of HSSFChildAnchor
98
     *
103
     *
99
     * @param anchor    the anchor to use.
104
     * @param anchor the anchor to use.
100
     * @throws IllegalArgumentException     when the wrong anchor is used for
105
     * @throws IllegalArgumentException when the wrong anchor is used for
101
     *                                      this particular shape.
106
     *                                  this particular shape.
102
     *
103
     * @see HSSFChildAnchor
107
     * @see HSSFChildAnchor
104
     * @see HSSFClientAnchor
108
     * @see HSSFClientAnchor
105
     */
109
     */
106
    public void setAnchor( HSSFAnchor anchor )
110
    public void setAnchor(HSSFAnchor anchor) {
107
    {
111
        if (parent == null) {
108
        if ( parent == null )
109
        {
110
            if ( anchor instanceof HSSFChildAnchor )
112
            if (anchor instanceof HSSFChildAnchor)
111
                throw new IllegalArgumentException( "Must use client anchors for shapes directly attached to sheet." );
113
                throw new IllegalArgumentException("Must use client anchors for shapes directly attached to sheet.");
114
            EscherClientAnchorRecord anch = _escherContainer.getChildById(EscherClientAnchorRecord.RECORD_ID);
115
            if (null != anch) {
116
                _escherContainer.removeChildRecord(anch);
112
        }
117
            }
113
        else
118
        } else {
114
        {
115
            if ( anchor instanceof HSSFClientAnchor )
119
            if (anchor instanceof HSSFClientAnchor)
116
                throw new IllegalArgumentException( "Must use child anchors for shapes attached to groups." );
120
                throw new IllegalArgumentException("Must use child anchors for shapes attached to groups.");
121
            EscherChildAnchorRecord anch = _escherContainer.getChildById(EscherChildAnchorRecord.RECORD_ID);
122
            if (null != anch) {
123
                _escherContainer.removeChildRecord(anch);
117
        }
124
            }
118
125
        }
126
        _escherContainer.addChildRecord(anchor.getEscherAnchor());
119
        this.anchor = anchor;
127
        this.anchor = anchor;
120
    }
128
    }
121
129
Lines 123-214 Link Here
123
     * The color applied to the lines of this shape.
131
     * The color applied to the lines of this shape.
124
     */
132
     */
125
    public int getLineStyleColor() {
133
    public int getLineStyleColor() {
126
        return _lineStyleColor;
134
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.LINESTYLE__COLOR);
135
        return rgbProperty == null ? LINESTYLE__COLOR_DEFAULT : rgbProperty.getRgbColor();
127
    }
136
    }
128
137
129
    /**
138
    /**
130
     * The color applied to the lines of this shape.
139
     * The color applied to the lines of this shape.
131
     */
140
     */
132
    public void setLineStyleColor(int lineStyleColor) {
141
    public void setLineStyleColor(int lineStyleColor) {
133
        _lineStyleColor = lineStyleColor;
142
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.LINESTYLE__COLOR);
143
        if (null == rgbProperty) {
144
            rgbProperty = new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor);
145
            _optRecord.addEscherProperty(rgbProperty);
146
        } else {
147
            rgbProperty.setRgbColor(lineStyleColor);
134
    }
148
        }
149
    }
135
150
136
    /**
151
    /**
137
     * The color applied to the lines of this shape.
152
     * The color applied to the lines of this shape.
138
     */
153
     */
139
    public void setLineStyleColor(int red, int green, int blue) {
154
    public void setLineStyleColor(int red, int green, int blue) {
140
        this._lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
155
        int lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
156
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.LINESTYLE__COLOR);
157
        if (null == rgbProperty) {
158
            rgbProperty = new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor);
159
            _optRecord.addEscherProperty(rgbProperty);
160
        } else {
161
            rgbProperty.setRgbColor(lineStyleColor);
141
    }
162
        }
163
    }
142
164
143
    /**
165
    /**
144
     * The color used to fill this shape.
166
     * The color used to fill this shape.
145
     */
167
     */
146
    public int getFillColor()
168
    public int getFillColor() {
147
    {
169
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.FILL__FILLCOLOR);
148
        return _fillColor;
170
        return rgbProperty == null ? FILL__FILLCOLOR_DEFAULT : rgbProperty.getRgbColor();
149
    }
171
    }
150
172
151
    /**
173
    /**
152
     * The color used to fill this shape.
174
     * The color used to fill this shape.
153
     */
175
     */
154
    public void setFillColor(int fillColor) {
176
    public void setFillColor(int fillColor) {
155
        _fillColor = fillColor;
177
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.FILL__FILLCOLOR);
178
        if (null == rgbProperty) {
179
            rgbProperty = new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor);
180
            _optRecord.addEscherProperty(rgbProperty);
181
        } else {
182
            rgbProperty.setRgbColor(fillColor);
156
    }
183
        }
184
    }
157
185
158
    /**
186
    /**
159
     * The color used to fill this shape.
187
     * The color used to fill this shape.
160
     */
188
     */
161
    public void setFillColor( int red, int green, int blue )
189
    public void setFillColor(int red, int green, int blue) {
162
    {
190
        int fillColor = ((blue) << 16) | ((green) << 8) | red;
163
        this._fillColor = ((blue) << 16) | ((green) << 8) | red;
191
        EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.FILL__FILLCOLOR);
192
        if (null == rgbProperty) {
193
            rgbProperty = new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor);
194
            _optRecord.addEscherProperty(rgbProperty);
195
        } else {
196
            rgbProperty.setRgbColor(fillColor);
164
    }
197
        }
198
    }
165
199
166
    /**
200
    /**
167
     * @return  returns with width of the line in EMUs.  12700 = 1 pt.
201
     * @return returns with width of the line in EMUs.  12700 = 1 pt.
168
     */
202
     */
169
    public int getLineWidth() {
203
    public int getLineWidth() {
170
        return _lineWidth;
204
        EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEWIDTH);
205
        return property.getPropertyValue();
171
    }
206
    }
172
207
173
    /**
208
    /**
174
     * Sets the width of the line.  12700 = 1 pt.
209
     * Sets the width of the line.  12700 = 1 pt.
175
     *
210
     *
176
     * @param lineWidth width in EMU's.  12700EMU's = 1 pt
211
     * @param lineWidth width in EMU's.  12700EMU's = 1 pt
177
     *
178
     * @see HSSFShape#LINEWIDTH_ONE_PT
212
     * @see HSSFShape#LINEWIDTH_ONE_PT
179
     */
213
     */
180
    public void setLineWidth(int lineWidth) {
214
    public void setLineWidth(int lineWidth) {
181
        _lineWidth = lineWidth;
215
        EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEWIDTH);
216
        if (null == property) {
217
            property = new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, lineWidth);
218
            _optRecord.addEscherProperty(property);
219
        } else {
220
            property.setPropertyValue(lineWidth);
182
    }
221
        }
222
    }
183
223
184
    /**
224
    /**
185
     * @return One of the constants in LINESTYLE_*
225
     * @return One of the constants in LINESTYLE_*
186
     */
226
     */
187
    public int getLineStyle() {
227
    public int getLineStyle() {
188
        return _lineStyle;
228
        EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEDASHING);
229
        if (null == property){
230
            return -1;
189
    }
231
        }
232
        return property.getPropertyValue();
233
    }
190
234
191
    /**
235
    /**
192
     * Sets the line style.
236
     * Sets the line style.
193
     *
237
     *
194
     * @param lineStyle     One of the constants in LINESTYLE_*
238
     * @param lineStyle One of the constants in LINESTYLE_*
195
     */
239
     */
196
    public void setLineStyle(int lineStyle) {
240
    public void setLineStyle(int lineStyle) {
197
        _lineStyle = lineStyle;
241
        EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEDASHING);
242
        if (null == property) {
243
            property = new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, lineStyle);
244
            _optRecord.addEscherProperty(property);
245
        } else {
246
            property.setPropertyValue(lineStyle);
198
    }
247
        }
248
    }
199
249
200
    /**
250
    /**
201
     * @return <code>true</code> if this shape is not filled with a color.
251
     * @return <code>true</code> if this shape is not filled with a color.
202
     */
252
     */
203
    public boolean isNoFill() {
253
    public boolean isNoFill() {
204
        return _noFill;
254
        EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
255
        return property.isTrue();
205
    }
256
    }
206
257
207
    /**
258
    /**
208
     * Sets whether this shape is filled or transparent.
259
     * Sets whether this shape is filled or transparent.
209
     */
260
     */
210
    public void setNoFill(boolean noFill) {
261
    public void setNoFill(boolean noFill) {
211
        _noFill = noFill;
262
        EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
263
        if (null == property) {
264
            property = new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? 1 : 0);
265
            _optRecord.addEscherProperty(property);
266
        } else {
267
            property.setPropertyValue(noFill ? 1 : 0);
268
        }
212
    }
269
    }
213
270
214
    /**
271
    /**
(-)src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java (-6 / +8 lines)
Lines 1-22 Link Here
1
package org.apache.poi.hssf.usermodel.drawing;
1
package org.apache.poi.hssf.usermodel.drawing;
2
2
3
import org.apache.poi.hssf.usermodel.HSSFRectangle;
3
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
4
4
5
/**
5
/**
6
 * @author Evgeniy Berlog
6
 * @author Evgeniy Berlog
7
 * date: 08.06.12
7
 * date: 08.06.12
8
 */
8
 */
9
public enum HSSFShapeType {
9
public enum HSSFShapeType {
10
    NOT_PRIMITIVE(0x0, null),
10
    NOT_PRIMITIVE((short)0x0, null, (short)0),
11
    RECTANGLE(0x1, HSSFRectangle.class),
11
    RECTANGLE((short)0x1, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_RECTANGLE),
12
    ROUND_RECTANGLE(0x2, null);
12
    ROUND_RECTANGLE((short)0x2, null, null);
13
13
14
    private Short type;
14
    private Short type;
15
    private Class shape;
15
    private Class shape;
16
    private Short objectId;
16
17
17
    HSSFShapeType(Integer type, Class shape) {
18
    private HSSFShapeType(Short type, Class shape, Short objectId) {
18
        this.type = type.shortValue();
19
        this.type = type;
19
        this.shape = shape;
20
        this.shape = shape;
21
        this.objectId = objectId;
20
    }
22
    }
21
23
22
    public Short getType() {
24
    public Short getType() {
(-)src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java (+209 lines)
Line 0 Link Here
1
package org.apache.poi.hssf.model;
2
3
import junit.framework.TestCase;
4
import org.apache.poi.ddf.EscherChildAnchorRecord;
5
import org.apache.poi.ddf.EscherClientAnchorRecord;
6
import org.apache.poi.ddf.EscherContainerRecord;
7
import org.apache.poi.hssf.usermodel.*;
8
9
/**
10
 * @author Evgeniy Berlog
11
 * @date 12.06.12
12
 */
13
public class TestHSSFAnchor extends TestCase {
14
15
    public void testCreateClientAnchorFromContainer(){
16
        EscherContainerRecord container = new EscherContainerRecord();
17
        EscherClientAnchorRecord escher = new EscherClientAnchorRecord();
18
        escher.setFlag((short) 3);
19
        escher.setCol1((short)11);
20
        escher.setCol2((short)12);
21
        escher.setRow1((short)13);
22
        escher.setRow2((short) 14);
23
        escher.setDx1((short) 15);
24
        escher.setDx2((short) 16);
25
        escher.setDy1((short) 17);
26
        escher.setDy2((short) 18);
27
        container.addChildRecord(escher);
28
29
        HSSFClientAnchor anchor = (HSSFClientAnchor) HSSFAnchor.createAnchorFromEscher(container);
30
        assertEquals(anchor.getCol1(), 11);
31
        assertEquals(escher.getCol1(), 11);
32
        assertEquals(anchor.getCol2(), 12);
33
        assertEquals(escher.getCol2(), 12);
34
        assertEquals(anchor.getRow1(), 13);
35
        assertEquals(escher.getRow1(), 13);
36
        assertEquals(anchor.getRow2(), 14);
37
        assertEquals(escher.getRow2(), 14);
38
        assertEquals(anchor.getDx1(), 15);
39
        assertEquals(escher.getDx1(), 15);
40
        assertEquals(anchor.getDx2(), 16);
41
        assertEquals(escher.getDx2(), 16);
42
        assertEquals(anchor.getDy1(), 17);
43
        assertEquals(escher.getDy1(), 17);
44
        assertEquals(anchor.getDy2(), 18);
45
        assertEquals(escher.getDy2(), 18);
46
    }
47
48
    public void testCreateChildAnchorFromContainer(){
49
        EscherContainerRecord container = new EscherContainerRecord();
50
        EscherChildAnchorRecord escher = new EscherChildAnchorRecord();
51
        escher.setDx1((short) 15);
52
        escher.setDx2((short) 16);
53
        escher.setDy1((short) 17);
54
        escher.setDy2((short) 18);
55
        container.addChildRecord(escher);
56
57
        HSSFChildAnchor anchor = (HSSFChildAnchor) HSSFAnchor.createAnchorFromEscher(container);
58
        assertEquals(anchor.getDx1(), 15);
59
        assertEquals(escher.getDx1(), 15);
60
        assertEquals(anchor.getDx2(), 16);
61
        assertEquals(escher.getDx2(), 16);
62
        assertEquals(anchor.getDy1(), 17);
63
        assertEquals(escher.getDy1(), 17);
64
        assertEquals(anchor.getDy2(), 18);
65
        assertEquals(escher.getDy2(), 18);
66
    }
67
68
    public void testShapeEscherMustHaveAnchorRecord(){
69
        HSSFWorkbook wb = new HSSFWorkbook();
70
        HSSFSheet sheet = wb.createSheet();
71
72
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
73
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);
74
        anchor.setAnchorType(2);
75
76
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
77
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
78
79
        rectangle.setAnchor(anchor);
80
81
        assertNotNull(anchor.getEscherAnchor());
82
        assertNotNull(rectangle.getEscherContainer());
83
        assertTrue(anchor.getEscherAnchor().equals(rectangle.getEscherContainer().getChildById(EscherClientAnchorRecord.RECORD_ID)));
84
    }
85
86
    public void testClientAnchorFromEscher(){
87
        EscherClientAnchorRecord escher = new EscherClientAnchorRecord();
88
        escher.setCol1((short)11);
89
        escher.setCol2((short)12);
90
        escher.setRow1((short)13);
91
        escher.setRow2((short) 14);
92
        escher.setDx1((short) 15);
93
        escher.setDx2((short) 16);
94
        escher.setDy1((short) 17);
95
        escher.setDy2((short) 18);
96
97
        HSSFClientAnchor anchor = new HSSFClientAnchor(escher);
98
        assertEquals(anchor.getCol1(), 11);
99
        assertEquals(escher.getCol1(), 11);
100
        assertEquals(anchor.getCol2(), 12);
101
        assertEquals(escher.getCol2(), 12);
102
        assertEquals(anchor.getRow1(), 13);
103
        assertEquals(escher.getRow1(), 13);
104
        assertEquals(anchor.getRow2(), 14);
105
        assertEquals(escher.getRow2(), 14);
106
        assertEquals(anchor.getDx1(), 15);
107
        assertEquals(escher.getDx1(), 15);
108
        assertEquals(anchor.getDx2(), 16);
109
        assertEquals(escher.getDx2(), 16);
110
        assertEquals(anchor.getDy1(), 17);
111
        assertEquals(escher.getDy1(), 17);
112
        assertEquals(anchor.getDy2(), 18);
113
        assertEquals(escher.getDy2(), 18);
114
    }
115
116
    public void testClientAnchorFromScratch(){
117
        HSSFClientAnchor anchor = new HSSFClientAnchor();
118
        EscherClientAnchorRecord escher = (EscherClientAnchorRecord) anchor.getEscherAnchor();
119
        anchor.setAnchor((short)11, 12, 13, 14, (short)15, 16, 17, 18);
120
121
        assertEquals(anchor.getCol1(), 11);
122
        assertEquals(escher.getCol1(), 11);
123
        assertEquals(anchor.getCol2(), 15);
124
        assertEquals(escher.getCol2(), 15);
125
        assertEquals(anchor.getRow1(), 12);
126
        assertEquals(escher.getRow1(), 12);
127
        assertEquals(anchor.getRow2(), 16);
128
        assertEquals(escher.getRow2(), 16);
129
        assertEquals(anchor.getDx1(), 13);
130
        assertEquals(escher.getDx1(), 13);
131
        assertEquals(anchor.getDx2(), 17);
132
        assertEquals(escher.getDx2(), 17);
133
        assertEquals(anchor.getDy1(), 14);
134
        assertEquals(escher.getDy1(), 14);
135
        assertEquals(anchor.getDy2(), 18);
136
        assertEquals(escher.getDy2(), 18);
137
138
        anchor.setCol1(111);
139
        assertEquals(anchor.getCol1(), 111);
140
        assertEquals(escher.getCol1(), 111);
141
        anchor.setCol2(112);
142
        assertEquals(anchor.getCol2(), 112);
143
        assertEquals(escher.getCol2(), 112);
144
        anchor.setRow1(113);
145
        assertEquals(anchor.getRow1(), 113);
146
        assertEquals(escher.getRow1(), 113);
147
        anchor.setRow2(114);
148
        assertEquals(anchor.getRow2(), 114);
149
        assertEquals(escher.getRow2(), 114);
150
        anchor.setDx1(115);
151
        assertEquals(anchor.getDx1(), 115);
152
        assertEquals(escher.getDx1(), 115);
153
        anchor.setDx2(116);
154
        assertEquals(anchor.getDx2(), 116);
155
        assertEquals(escher.getDx2(), 116);
156
        anchor.setDy1(117);
157
        assertEquals(anchor.getDy1(), 117);
158
        assertEquals(escher.getDy1(), 117);
159
        anchor.setDy2(118);
160
        assertEquals(anchor.getDy2(), 118);
161
        assertEquals(escher.getDy2(), 118);
162
    }
163
164
    public void testChildAnchorFromEscher(){
165
        EscherChildAnchorRecord escher = new EscherChildAnchorRecord();
166
        escher.setDx1((short) 15);
167
        escher.setDx2((short) 16);
168
        escher.setDy1((short) 17);
169
        escher.setDy2((short) 18);
170
171
        HSSFChildAnchor anchor = new HSSFChildAnchor(escher);
172
        assertEquals(anchor.getDx1(), 15);
173
        assertEquals(escher.getDx1(), 15);
174
        assertEquals(anchor.getDx2(), 16);
175
        assertEquals(escher.getDx2(), 16);
176
        assertEquals(anchor.getDy1(), 17);
177
        assertEquals(escher.getDy1(), 17);
178
        assertEquals(anchor.getDy2(), 18);
179
        assertEquals(escher.getDy2(), 18);
180
    }
181
182
    public void testChildAnchorFromScratch(){
183
        HSSFChildAnchor anchor = new HSSFChildAnchor();
184
        EscherChildAnchorRecord escher = (EscherChildAnchorRecord) anchor.getEscherAnchor();
185
        anchor.setAnchor(11, 12, 13, 14);
186
187
        assertEquals(anchor.getDx1(), 11);
188
        assertEquals(escher.getDx1(), 11);
189
        assertEquals(anchor.getDx2(), 13);
190
        assertEquals(escher.getDx2(), 13);
191
        assertEquals(anchor.getDy1(), 12);
192
        assertEquals(escher.getDy1(), 12);
193
        assertEquals(anchor.getDy2(), 14);
194
        assertEquals(escher.getDy2(), 14);
195
196
        anchor.setDx1(115);
197
        assertEquals(anchor.getDx1(), 115);
198
        assertEquals(escher.getDx1(), 115);
199
        anchor.setDx2(116);
200
        assertEquals(anchor.getDx2(), 116);
201
        assertEquals(escher.getDx2(), 116);
202
        anchor.setDy1(117);
203
        assertEquals(anchor.getDy1(), 117);
204
        assertEquals(escher.getDy1(), 117);
205
        anchor.setDy2(118);
206
        assertEquals(anchor.getDy2(), 118);
207
        assertEquals(escher.getDy2(), 118);
208
    }
209
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (-1 / +1 lines)
Lines 57-63 Link Here
57
        setShapeType(OBJECT_TYPE_COMMENT);
57
        setShapeType(OBJECT_TYPE_COMMENT);
58
58
59
        //default color for comments
59
        //default color for comments
60
        _fillColor = 0x08000050;
60
        setFillColor(0x08000050);
61
61
62
        //by default comments are hidden
62
        //by default comments are hidden
63
        _visible = false;
63
        _visible = false;
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (-8 / +8 lines)
Lines 145-152 Link Here
145
        float w = 0;
145
        float w = 0;
146
146
147
        //space in the leftmost cell
147
        //space in the leftmost cell
148
        w += getColumnWidthInPixels(anchor.col1)*(1 - (float)anchor.dx1/1024);
148
        w += getColumnWidthInPixels(anchor.getCol1())*(1 - (float)anchor.getDx1()/1024);
149
        short col2 = (short)(anchor.col1 + 1);
149
        short col2 = (short)(anchor.getCol1() + 1);
150
        int dx2 = 0;
150
        int dx2 = 0;
151
151
152
        while(w < scaledWidth){
152
        while(w < scaledWidth){
Lines 160-171 Link Here
160
            double delta = w - scaledWidth;
160
            double delta = w - scaledWidth;
161
            dx2 = (int)((cw-delta)/cw*1024);
161
            dx2 = (int)((cw-delta)/cw*1024);
162
        }
162
        }
163
        anchor.col2 = col2;
163
        anchor.setCol2(col2);
164
        anchor.dx2 = dx2;
164
        anchor.setDx2(dx2);
165
165
166
        float h = 0;
166
        float h = 0;
167
        h += (1 - (float)anchor.dy1/256)* getRowHeightInPixels(anchor.row1);
167
        h += (1 - (float)anchor.getDy1()/256)* getRowHeightInPixels(anchor.getRow1());
168
        int row2 = anchor.row1 + 1;
168
        int row2 = anchor.getRow1() + 1;
169
        int dy2 = 0;
169
        int dy2 = 0;
170
170
171
        while(h < scaledHeight){
171
        while(h < scaledHeight){
Lines 177-184 Link Here
177
            double delta = h - scaledHeight;
177
            double delta = h - scaledHeight;
178
            dy2 = (int)((ch-delta)/ch*256);
178
            dy2 = (int)((ch-delta)/ch*256);
179
        }
179
        }
180
        anchor.row2 = row2;
180
        anchor.setRow2(row2);
181
        anchor.dy2 = dy2;
181
        anchor.setDy2(dy2);
182
182
183
        return anchor;
183
        return anchor;
184
    }
184
    }
(-)src/java/org/apache/poi/ddf/EscherRGBProperty.java (+4 lines)
Lines 38-43 Link Here
38
        return propertyValue;
38
        return propertyValue;
39
    }
39
    }
40
40
41
    public void setRgbColor(int color){
42
        this.propertyValue = color;
43
    }
44
41
    public byte getRed()
45
    public byte getRed()
42
    {
46
    {
43
        return (byte) ( propertyValue & 0xFF );
47
        return (byte) ( propertyValue & 0xFF );
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java (-30 / +6 lines)
Lines 39-63 Link Here
39
import java.util.Map;
39
import java.util.Map;
40
40
41
/**
41
/**
42
 * @author evgeniy
42
 * @author Evgeniy Berlog
43
 * date: 05.06.12
43
 * date: 05.06.12
44
 */
44
 */
45
public class HSSFShapeFactory {
45
public class HSSFShapeFactory {
46
46
47
    private static final Map<Short, Class> shapeTypeToClass = new HashMap<Short, Class>(HSSFShapeType.values().length);
47
    private static final Map<Short, HSSFShapeType> shapeTypeToClass = new HashMap<Short, HSSFShapeType>(HSSFShapeType.values().length);
48
    private static final ReflectionConstructorShapeCreator shapeCreator = new ReflectionConstructorShapeCreator(shapeTypeToClass);
48
    private static final ReflectionConstructorShapeCreator shapeCreator = new ReflectionConstructorShapeCreator(shapeTypeToClass);
49
49
50
    static {
50
    static {
51
        for (HSSFShapeType type: HSSFShapeType.values()){
51
        for (HSSFShapeType type: HSSFShapeType.values()){
52
            shapeTypeToClass.put(type.getType(), type.getShape());
52
            shapeTypeToClass.put(type.getType(), type);
53
        }
53
        }
54
    }
54
    }
55
55
56
    private static class ReflectionConstructorShapeCreator {
56
    private static class ReflectionConstructorShapeCreator {
57
57
58
        private final Map<Short, Class> shapeTypeToClass;
58
        private final Map<Short, HSSFShapeType> shapeTypeToClass;
59
59
60
        private ReflectionConstructorShapeCreator(Map<Short, Class> shapeTypeToClass) {
60
        private ReflectionConstructorShapeCreator(Map<Short, HSSFShapeType> shapeTypeToClass) {
61
            this.shapeTypeToClass = shapeTypeToClass;
61
            this.shapeTypeToClass = shapeTypeToClass;
62
        }
62
        }
63
63
Lines 65-71 Link Here
65
            if (!shapeTypeToClass.containsKey(type)){
65
            if (!shapeTypeToClass.containsKey(type)){
66
                return new HSSFUnknownShape(spContainer, objRecord);
66
                return new HSSFUnknownShape(spContainer, objRecord);
67
            }
67
            }
68
            Class clazz = shapeTypeToClass.get(type);
68
            Class clazz = shapeTypeToClass.get(type).getShape();
69
            if (null == clazz){
69
            if (null == clazz){
70
                //System.out.println("No class attached to shape type: "+type);
70
                //System.out.println("No class attached to shape type: "+type);
71
                return new HSSFUnknownShape(spContainer, objRecord);
71
                return new HSSFUnknownShape(spContainer, objRecord);
Lines 81-106 Link Here
81
        }
81
        }
82
    }
82
    }
83
83
84
    public static HSSFShape createShape(EscherRecord container, ObjRecord objRecord){
85
        if (0 == container.getChildRecords().size()){
86
            throw new IllegalArgumentException("Couldn't create shape from empty escher container");
87
        }
88
        if (container.getChild(0) instanceof EscherSpgrRecord){
89
            return new HSSFShapeGroup((EscherContainerRecord) container, objRecord);
90
        }
91
92
        //TODO implement cases for all shapes
93
        return new HSSFUnknownShape(container, objRecord);
94
    }
95
96
    public static HSSFShapeGroup createShapeGroup(){
97
        return null;
98
    }
99
100
    public static HSSFShapeGroup createSimpleShape(EscherRecord container, ObjRecord objRecord){
101
        return null;
102
    }
103
104
    public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out){
84
    public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out){
105
        if(container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
85
        if(container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
106
            HSSFShapeGroup group = new HSSFShapeGroup(container,
86
            HSSFShapeGroup group = new HSSFShapeGroup(container,
Lines 111-120 Link Here
111
                EscherContainerRecord spContainer = children.get(i);
91
                EscherContainerRecord spContainer = children.get(i);
112
                if(i == 0){
92
                if(i == 0){
113
                    EscherSpgrRecord spgr = (EscherSpgrRecord)spContainer.getChildById(EscherSpgrRecord.RECORD_ID);
93
                    EscherSpgrRecord spgr = (EscherSpgrRecord)spContainer.getChildById(EscherSpgrRecord.RECORD_ID);
114
                    group.setCoordinates(
115
                            spgr.getRectX1(), spgr.getRectY1(),
116
                            spgr.getRectX2(), spgr.getRectY2()
117
                    );
118
                } else {
94
                } else {
119
                    createShapeTree(spContainer, agg, group);
95
                    createShapeTree(spContainer, agg, group);
120
                }
96
                }
(-)src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java (-1 / +8 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 38-43 Link Here
38
    public static final short RECORD_ID = (short) 0xF010;
37
    public static final short RECORD_ID = (short) 0xF010;
39
    public static final String RECORD_DESCRIPTION = "MsofbtClientAnchor";
38
    public static final String RECORD_DESCRIPTION = "MsofbtClientAnchor";
40
39
40
    /**
41
     * bit[0] -  fMove (1 bit): A bit that specifies whether the shape will be kept intact when the cells are moved.
42
     * bit[1] - fSize (1 bit): A bit that specifies whether the shape will be kept intact when the cells are resized. If fMove is 1, the value MUST be 1.
43
     * bit[2-4] - reserved, MUST be 0 and MUST be ignored
44
     * bit[5-15]- Undefined and MUST be ignored.
45
     *
46
     * it can take values: 0, 2, 3
47
     */
41
    private short field_1_flag;
48
    private short field_1_flag;
42
    private short field_2_col1;
49
    private short field_2_col1;
43
    private short field_3_dx1;
50
    private short field_3_dx1;

Return to bug 53413