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

(-)src/scratchpad/src/org/apache/poi/hslf/model/Shape.java (-1 / +3 lines)
Lines 342-348 Link Here
342
     * @param sh - owning shape
342
     * @param sh - owning shape
343
     */
343
     */
344
    protected void afterInsert(Sheet sh){
344
    protected void afterInsert(Sheet sh){
345
345
        if(_fill != null) {
346
            _fill.afterInsert(sh);
347
        }
346
    }
348
    }
347
349
348
    /**
350
    /**
(-)src/scratchpad/src/org/apache/poi/hslf/model/Fill.java (+37 lines)
Lines 23-28 Link Here
23
import org.apache.poi.hslf.usermodel.SlideShow;
23
import org.apache.poi.hslf.usermodel.SlideShow;
24
import org.apache.poi.util.POILogger;
24
import org.apache.poi.util.POILogger;
25
import org.apache.poi.util.POILogFactory;
25
import org.apache.poi.util.POILogFactory;
26
import java.util.List;
26
27
27
import java.awt.*;
28
import java.awt.*;
28
29
Lines 117-122 Link Here
117
    }
118
    }
118
119
119
    /**
120
    /**
121
     */
122
    protected void afterInsert(Sheet sh){
123
        EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
124
        EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
125
        if(p != null) {
126
            int idx = p.getPropertyValue();
127
            EscherBSERecord bse = getEscherBSERecord(idx);
128
            bse.setRef(bse.getRef() + 1);
129
        }
130
    }
131
132
    protected EscherBSERecord getEscherBSERecord(int idx){
133
        Sheet sheet = shape.getSheet();
134
        if(sheet == null) {
135
            logger.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
136
            return null;
137
        }
138
        SlideShow ppt = sheet.getSlideShow();
139
        Document doc = ppt.getDocumentRecord();
140
        EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
141
        EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
142
        if(bstore == null) {
143
            logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
144
            return null;
145
        }
146
        List lst = bstore.getChildRecords();
147
        return (EscherBSERecord)lst.get(idx-1);
148
    }
149
150
    /**
120
     * Sets fill type.
151
     * Sets fill type.
121
     * Must be one of the <code>FILL_*</code> constants defined in this class.
152
     * Must be one of the <code>FILL_*</code> constants defined in this class.
122
     *
153
     *
Lines 233-238 Link Here
233
    public void setPictureData(int idx){
264
    public void setPictureData(int idx){
234
        EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
265
        EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
235
        Shape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx);
266
        Shape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx);
267
        if( idx != 0 ) {
268
            if( shape.getSheet() != null ) {
269
                EscherBSERecord bse = getEscherBSERecord(idx);
270
                bse.setRef(bse.getRef() + 1);
271
            }
272
        }
236
    }
273
    }
237
274
238
}
275
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java (+24 lines)
Lines 21-31 Link Here
21
21
22
import java.io.*;
22
import java.io.*;
23
import java.awt.*;
23
import java.awt.*;
24
import java.util.List;
24
25
26
import org.apache.poi.ddf.*;
27
import org.apache.poi.hslf.record.Document;
25
import org.apache.poi.hslf.usermodel.SlideShow;
28
import org.apache.poi.hslf.usermodel.SlideShow;
26
import org.apache.poi.hslf.HSLFSlideShow;
29
import org.apache.poi.hslf.HSLFSlideShow;
27
import org.apache.poi.POIDataSamples;
30
import org.apache.poi.POIDataSamples;
28
31
32
29
/**
33
/**
30
 * Test <code>Fill</code> object.
34
 * Test <code>Fill</code> object.
31
 *
35
 *
Lines 163-168 Link Here
163
167
164
        fill = slides[0].getBackground().getFill();
168
        fill = slides[0].getBackground().getFill();
165
        assertEquals(Fill.FILL_PICTURE, fill.getFillType());
169
        assertEquals(Fill.FILL_PICTURE, fill.getFillType());
170
        assertEquals(3, getFillPictureRefCount(slides[0].getBackground(), fill));
166
        shape = slides[0].getShapes()[0];
171
        shape = slides[0].getShapes()[0];
167
        assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
172
        assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
168
173
Lines 173-180 Link Here
173
178
174
        fill = slides[2].getBackground().getFill();
179
        fill = slides[2].getBackground().getFill();
175
        assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
180
        assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
181
        assertEquals(3, getFillPictureRefCount(slides[2].getBackground(), fill));
176
        shape = slides[2].getShapes()[0];
182
        shape = slides[2].getShapes()[0];
177
        assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
183
        assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
184
        assertEquals(1, getFillPictureRefCount(shape, fill));
178
185
179
        fill = slides[3].getBackground().getFill();
186
        fill = slides[3].getBackground().getFill();
180
        assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
187
        assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
Lines 183-186 Link Here
183
190
184
    }
191
    }
185
192
193
    private int getFillPictureRefCount(Shape shape, Fill fill) {
194
        EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
195
        EscherSimpleProperty p = (EscherSimpleProperty)Shape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
196
        if(p != null) {
197
            int idx = p.getPropertyValue();
198
199
            Sheet sheet = shape.getSheet();
200
            SlideShow ppt = sheet.getSlideShow();
201
            Document doc = ppt.getDocumentRecord();
202
            EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
203
            EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
204
            List lst = bstore.getChildRecords();
205
            return ((EscherBSERecord)lst.get(idx-1)).getRef();
206
        }
207
        return 0;
208
    }
209
186
}
210
}

Return to bug 46288