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

(-)src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java (-1 / +6 lines)
Lines 18-23 Link Here
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
import org.apache.poi.hssf.model.InternalSheet;
19
import org.apache.poi.hssf.model.InternalSheet;
20
import org.apache.poi.hssf.model.InternalWorkbook;
20
import org.apache.poi.hssf.model.InternalWorkbook;
21
import org.apache.poi.hssf.record.EscherAggregate;
21
22
22
/**
23
/**
23
 * Helper class for HSSF tests that aren't within the
24
 * Helper class for HSSF tests that aren't within the
Lines 33-37 Link Here
33
	}
34
	}
34
	public static InternalSheet getSheetForTest(HSSFSheet sheet) {
35
	public static InternalSheet getSheetForTest(HSSFSheet sheet) {
35
		return sheet.getSheet();
36
		return sheet.getSheet();
36
	}
37
	}
38
39
    public static HSSFPatriarch createTestPatriarch(HSSFSheet sheet, EscherAggregate agg){
40
        return new HSSFPatriarch(sheet, agg);
41
    }
37
}
42
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (-2 / +20 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.EscherContainerRecord;
21
import org.apache.poi.hssf.record.ObjRecord;
22
20
/**
23
/**
21
 * An abstract shape.
24
 * An abstract shape.
22
 *
25
 *
Lines 40-46 Link Here
40
    public static final int LINESTYLE_NONE = -1;
43
    public static final int LINESTYLE_NONE = -1;
41
44
42
    // TODO - make all these fields private
45
    // TODO - make all these fields private
43
    final HSSFShape parent;  
46
    HSSFShape parent;
44
    HSSFAnchor anchor;
47
    HSSFAnchor anchor;
45
    HSSFPatriarch _patriarch;  
48
    HSSFPatriarch _patriarch;  
46
    private int _lineStyleColor = 0x08000040;
49
    private int _lineStyleColor = 0x08000040;
Lines 49-61 Link Here
49
    private int _lineStyle = LINESTYLE_SOLID;
52
    private int _lineStyle = LINESTYLE_SOLID;
50
    private boolean _noFill = false;
53
    private boolean _noFill = false;
51
54
55
    private EscherContainerRecord spContainer;
56
    private ObjRecord objRecord;
57
58
    public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord){
59
        this.spContainer = spContainer;
60
        this.objRecord = objRecord;
61
    }
52
    /**
62
    /**
53
     * Create a new shape with the specified parent and anchor.
63
     * Create a new shape with the specified parent and anchor.
54
     */
64
     */
55
    HSSFShape( HSSFShape parent, HSSFAnchor anchor )
65
    public HSSFShape( HSSFShape parent, HSSFAnchor anchor )
56
    {
66
    {
57
        this.parent = parent;
67
        this.parent = parent;
58
        this.anchor = anchor;
68
        this.anchor = anchor;
69
    }
70
71
    public EscherContainerRecord getSpContainer() {
72
        return spContainer;
73
    }
74
75
    public ObjRecord getObjRecord() {
76
        return objRecord;
59
    }
77
    }
60
78
61
    /**
79
    /**
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java (+32 lines)
Line 0 Link Here
1
package org.apache.poi.hssf.usermodel;
2
3
import org.apache.poi.ddf.EscherContainerRecord;
4
import org.apache.poi.ddf.EscherRecord;
5
import org.apache.poi.ddf.EscherSpgrRecord;
6
import org.apache.poi.hssf.record.ObjRecord;
7
/**
8
 * @author evgeniy
9
 *         date: 05.06.12
10
 */
11
public class HSSFShapeFactory {
12
13
    public static HSSFShape createShape(EscherRecord container, ObjRecord objRecord){
14
        if (0 == container.getChildRecords().size()){
15
            throw new IllegalArgumentException("Couldn't create shape from empty escher container");
16
        }
17
        if (container.getChild(0) instanceof EscherSpgrRecord){
18
            return new HSSFShapeGroup((EscherContainerRecord) container, objRecord);
19
        }
20
21
        //TODO implement cases for all shapes
22
        return new HSSFUnknownShape(container, objRecord);
23
    }
24
25
    public static HSSFShapeGroup createShapeGroup(){
26
        return null;
27
    }
28
29
    public static HSSFShapeGroup createSimpleShape(EscherRecord container, ObjRecord objRecord){
30
        return null;
31
    }
32
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (-1 / +2 lines)
Lines 1739-1749 Link Here
1739
1739
1740
        _patriarch = new HSSFPatriarch(this, agg);
1740
        _patriarch = new HSSFPatriarch(this, agg);
1741
        agg.setPatriarch(_patriarch);
1741
        agg.setPatriarch(_patriarch);
1742
        EscherAggregate.createShapeTree(EscherAggregate.getMainSpgrContainer(agg), agg.getPatriarch(), agg);
1742
1743
1743
        // Have it process the records into high level objects
1744
        // Have it process the records into high level objects
1744
        //  as best it can do (this step may eat anything
1745
        //  as best it can do (this step may eat anything
1745
        //  that isn't supported, you were warned...)
1746
        //  that isn't supported, you were warned...)
1746
        agg.convertRecordsToUserModel();
1747
//        agg.convertRecordsToUserModel();
1747
1748
1748
        // Return what we could cope with
1749
        // Return what we could cope with
1749
        return _patriarch;
1750
        return _patriarch;
(-)src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java (+16 lines)
Line 0 Link Here
1
package org.apache.poi.hssf.usermodel;
2
3
import org.apache.poi.ddf.EscherContainerRecord;
4
import org.apache.poi.ddf.EscherRecord;
5
import org.apache.poi.hssf.record.ObjRecord;
6
7
/**
8
 * @author Evgeniy Berlog
9
 * date: 05.06.12
10
 */
11
public class HSSFUnknownShape extends HSSFShape {
12
13
    public HSSFUnknownShape(EscherRecord spContainer, ObjRecord objRecord) {
14
        super((EscherContainerRecord) spContainer, objRecord);
15
    }
16
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (+6 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.EscherContainerRecord;
21
import org.apache.poi.hssf.record.ObjRecord;
22
20
import java.util.ArrayList;
23
import java.util.ArrayList;
21
import java.util.List;
24
import java.util.List;
22
import java.util.Iterator;
25
import java.util.Iterator;
Lines 37-42 Link Here
37
    int x2 = 1023;
40
    int x2 = 1023;
38
    int y2 = 255;
41
    int y2 = 255;
39
42
43
    public HSSFShapeGroup(EscherContainerRecord spContainer, ObjRecord objRecord) {
44
        super(spContainer, objRecord);
45
    }
40
46
41
    public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
47
    public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
42
    {
48
    {
(-)src/java/org/apache/poi/hssf/record/EscherAggregate.java (-17 / +39 lines)
Lines 43-58 Link Here
43
import org.apache.poi.hssf.model.ConvertAnchor;
43
import org.apache.poi.hssf.model.ConvertAnchor;
44
import org.apache.poi.hssf.model.DrawingManager2;
44
import org.apache.poi.hssf.model.DrawingManager2;
45
import org.apache.poi.hssf.model.TextboxShape;
45
import org.apache.poi.hssf.model.TextboxShape;
46
import org.apache.poi.hssf.usermodel.HSSFAnchor;
46
import org.apache.poi.hssf.usermodel.*;
47
import org.apache.poi.hssf.usermodel.HSSFChildAnchor;
47
import org.apache.poi.hssf.usermodel.HSSFShapeFactory;
48
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
49
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
50
import org.apache.poi.hssf.usermodel.HSSFPicture;
51
import org.apache.poi.hssf.usermodel.HSSFShape;
52
import org.apache.poi.hssf.usermodel.HSSFShapeContainer;
53
import org.apache.poi.hssf.usermodel.HSSFShapeGroup;
54
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
55
import org.apache.poi.hssf.usermodel.HSSFTextbox;
56
import org.apache.poi.util.POILogFactory;
48
import org.apache.poi.util.POILogFactory;
57
import org.apache.poi.util.POILogger;
49
import org.apache.poi.util.POILogger;
58
50
Lines 413-419 Link Here
413
        }
405
        }
414
406
415
        // Decode the shapes
407
        // Decode the shapes
416
        //		agg.escherRecords = new ArrayList();
408
        // agg.escherRecords = new ArrayList();
417
        int pos = 0;
409
        int pos = 0;
418
        while (pos < buffer.size()) {
410
        while (pos < buffer.size()) {
419
            EscherRecord r = recordFactory.createRecord(buffer.toByteArray(), pos);
411
            EscherRecord r = recordFactory.createRecord(buffer.toByteArray(), pos);
Lines 453-462 Link Here
453
        records.subList(locFirstDrawingRecord, locLastDrawingRecord).clear();
445
        records.subList(locFirstDrawingRecord, locLastDrawingRecord).clear();
454
        records.add(locFirstDrawingRecord, agg);
446
        records.add(locFirstDrawingRecord, agg);
455
447
456
457
        return agg;
448
        return agg;
458
    }
449
    }
459
450
451
    public static EscherContainerRecord getMainSpgrContainer(EscherAggregate agg){
452
        EscherContainerRecord topContainer = agg.getEscherContainer();
453
        return topContainer.getChildContainers().get(0);
454
    }
455
456
    public static void createShapeTree(EscherContainerRecord container, HSSFShapeContainer shapeGroup, EscherAggregate agg){
457
        for (EscherRecord record: container.getChildRecords()){
458
            if (record instanceof EscherContainerRecord){
459
                if (EscherContainerRecord.SP_CONTAINER == record.getRecordId()){
460
                    if (record.getChild(0) instanceof EscherSpgrRecord){
461
                        //TODO set properties for HSSFDrawingPatriarch
462
                        continue;
463
                    }
464
                    shapeGroup.addShape(HSSFShapeFactory.createShape(record, (ObjRecord) agg.shapeToObj.get(container.getChildById(EscherClientDataRecord.RECORD_ID))));
465
                    continue;
466
                }
467
                if (EscherContainerRecord.SPGR_CONTAINER == record.getRecordId()){
468
                    EscherContainerRecord spContainer = (EscherContainerRecord) container.getChild(0);
469
                    HSSFShapeGroup group = (HSSFShapeGroup) HSSFShapeFactory.createShape(spContainer, (ObjRecord) agg.shapeToObj.get(spContainer.getChildById(EscherClientDataRecord.RECORD_ID)));
470
                    shapeGroup.addShape(group);
471
                    createShapeTree((EscherContainerRecord)record, group, agg);
472
                }
473
            }
474
        }
475
    }
476
460
    /**
477
    /**
461
     * Serializes this aggregate to a byte array.  Since this is an aggregate
478
     * Serializes this aggregate to a byte array.  Since this is an aggregate
462
     * record it will effectively serialize the aggregated records.
479
     * record it will effectively serialize the aggregated records.
Lines 466-472 Link Here
466
     * @return The number of bytes serialized.
483
     * @return The number of bytes serialized.
467
     */
484
     */
468
    public int serialize(int offset, byte[] data) {
485
    public int serialize(int offset, byte[] data) {
469
        convertUserModelToRecords();
486
//        convertUserModelToRecords();
470
487
471
        // Determine buffer size
488
        // Determine buffer size
472
        List records = getEscherRecords();
489
        List records = getEscherRecords();
Lines 486-492 Link Here
486
503
487
                public void afterRecordSerialize(int offset, short recordId, int size, EscherRecord record) {
504
                public void afterRecordSerialize(int offset, short recordId, int size, EscherRecord record) {
488
                    if (recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID) {
505
                    if (recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID) {
489
                        spEndingOffsets.add(Integer.valueOf(offset));
506
                        spEndingOffsets.add(offset);
490
                        shapes.add(record);
507
                        shapes.add(record);
491
                    }
508
                    }
492
                }
509
                }
Lines 501-512 Link Here
501
        pos = offset;
518
        pos = offset;
502
        int writtenEscherBytes = 0;
519
        int writtenEscherBytes = 0;
503
        for (int i = 1; i < shapes.size(); i++) {
520
        for (int i = 1; i < shapes.size(); i++) {
504
            int endOffset = ((Integer) spEndingOffsets.get(i)).intValue() - 1;
521
            int endOffset;
522
            if (i == shapes.size()-1){
523
                endOffset = buffer.length - 1;
524
            } else {
525
                endOffset = (Integer) spEndingOffsets.get(i) - 1;
526
            }
505
            int startOffset;
527
            int startOffset;
506
            if (i == 1)
528
            if (i == 1)
507
                startOffset = 0;
529
                startOffset = 0;
508
            else
530
            else
509
                startOffset = ((Integer) spEndingOffsets.get(i - 1)).intValue();
531
                startOffset = (Integer) spEndingOffsets.get(i - 1);
510
532
511
533
512
            byte[] drawingData = new byte[endOffset - startOffset + 1];
534
            byte[] drawingData = new byte[endOffset - startOffset + 1];
Lines 570-576 Link Here
570
592
571
    public int getRecordSize() {
593
    public int getRecordSize() {
572
        // TODO - convert this to RecordAggregate
594
        // TODO - convert this to RecordAggregate
573
        convertUserModelToRecords();
595
//        convertUserModelToRecords();
574
        // To determine size of aggregate record we have to know size of each DrawingRecord because if DrawingRecord
596
        // To determine size of aggregate record we have to know size of each DrawingRecord because if DrawingRecord
575
        // is split into several continue records we have to add header size to total EscherAggregate size
597
        // is split into several continue records we have to add header size to total EscherAggregate size
576
        int continueRecordsHeadersSize = 0;
598
        int continueRecordsHeadersSize = 0;
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java (+6 lines)
Lines 31-34 Link Here
31
     */
31
     */
32
    List getChildren();
32
    List getChildren();
33
33
34
    /**
35
     * add shape to the list of child records
36
     * @param shape
37
     */
38
    public void addShape(HSSFShape shape);
39
34
}
40
}

Return to bug 53372