More fixes to allow EscherContainerRecord to exclusively maintain 'child records' field. (due to r745976 / r746018)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@746085 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8a77c05b99
commit
8dcd0c8c58
@ -2023,7 +2023,7 @@ public final class Workbook implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EscherDggRecord dgg = null;
|
EscherDggRecord dgg = null;
|
||||||
for(Iterator it = cr.getChildRecords().iterator(); it.hasNext();) {
|
for(Iterator<EscherRecord> it = cr.getChildIterator(); it.hasNext();) {
|
||||||
Object er = it.next();
|
Object er = it.next();
|
||||||
if(er instanceof EscherDggRecord) {
|
if(er instanceof EscherDggRecord) {
|
||||||
dgg = (EscherDggRecord)er;
|
dgg = (EscherDggRecord)er;
|
||||||
@ -2150,7 +2150,9 @@ public final class Workbook implements Model {
|
|||||||
{
|
{
|
||||||
bstoreContainer = new EscherContainerRecord();
|
bstoreContainer = new EscherContainerRecord();
|
||||||
bstoreContainer.setRecordId( EscherContainerRecord.BSTORE_CONTAINER );
|
bstoreContainer.setRecordId( EscherContainerRecord.BSTORE_CONTAINER );
|
||||||
dggContainer.getChildRecords().add( 1, bstoreContainer );
|
List<EscherRecord> childRecords = dggContainer.getChildRecords();
|
||||||
|
childRecords.add(1, bstoreContainer);
|
||||||
|
dggContainer.setChildRecords(childRecords);
|
||||||
}
|
}
|
||||||
bstoreContainer.setOptions( (short) ( (escherBSERecords.size() << 4) | 0xF ) );
|
bstoreContainer.setOptions( (short) ( (escherBSERecords.size() << 4) | 0xF ) );
|
||||||
|
|
||||||
@ -2285,18 +2287,18 @@ public final class Workbook implements Model {
|
|||||||
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
|
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
|
||||||
|
|
||||||
EscherDgRecord dg = null;
|
EscherDgRecord dg = null;
|
||||||
for(Iterator it = escherContainer.getChildRecords().iterator(); it.hasNext();) {
|
for(Iterator<EscherRecord> it = escherContainer.getChildIterator(); it.hasNext();) {
|
||||||
Object er = it.next();
|
EscherRecord er = it.next();
|
||||||
if(er instanceof EscherDgRecord) {
|
if(er instanceof EscherDgRecord) {
|
||||||
dg = (EscherDgRecord)er;
|
dg = (EscherDgRecord)er;
|
||||||
//update id of the drawing in the cloned sheet
|
//update id of the drawing in the cloned sheet
|
||||||
dg.setOptions( (short) ( dgId << 4 ) );
|
dg.setOptions( (short) ( dgId << 4 ) );
|
||||||
} else if (er instanceof EscherContainerRecord){
|
} else if (er instanceof EscherContainerRecord){
|
||||||
//recursively find shape records and re-generate shapeId
|
//recursively find shape records and re-generate shapeId
|
||||||
ArrayList spRecords = new ArrayList();
|
List<EscherRecord> spRecords = new ArrayList<EscherRecord>();
|
||||||
EscherContainerRecord cp = (EscherContainerRecord)er;
|
EscherContainerRecord cp = (EscherContainerRecord)er;
|
||||||
cp.getRecordsById(EscherSpRecord.RECORD_ID, spRecords);
|
cp.getRecordsById(EscherSpRecord.RECORD_ID, spRecords);
|
||||||
for(Iterator spIt = spRecords.iterator(); spIt.hasNext();) {
|
for(Iterator<EscherRecord> spIt = spRecords.iterator(); spIt.hasNext();) {
|
||||||
EscherSpRecord sp = (EscherSpRecord)spIt.next();
|
EscherSpRecord sp = (EscherSpRecord)spIt.next();
|
||||||
int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
|
int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
|
||||||
//allocateShapeId increments the number of shapes. roll back to the previous value
|
//allocateShapeId increments the number of shapes. roll back to the previous value
|
||||||
|
@ -196,21 +196,20 @@ public abstract class AbstractEscherHolderRecord extends Record {
|
|||||||
public EscherRecord findFirstWithId(short id) {
|
public EscherRecord findFirstWithId(short id) {
|
||||||
return findFirstWithId(id, getEscherRecords());
|
return findFirstWithId(id, getEscherRecords());
|
||||||
}
|
}
|
||||||
private EscherRecord findFirstWithId(short id, List records) {
|
private EscherRecord findFirstWithId(short id, List<EscherRecord> records) {
|
||||||
// Check at our level
|
// Check at our level
|
||||||
for(Iterator it = records.iterator(); it.hasNext();) {
|
for(Iterator<EscherRecord> it = records.iterator(); it.hasNext();) {
|
||||||
EscherRecord r = (EscherRecord)it.next();
|
EscherRecord r = it.next();
|
||||||
if(r.getRecordId() == id) {
|
if(r.getRecordId() == id) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then check our children in turn
|
// Then check our children in turn
|
||||||
for(Iterator it = records.iterator(); it.hasNext();) {
|
for(Iterator<EscherRecord> it = records.iterator(); it.hasNext();) {
|
||||||
EscherRecord r = (EscherRecord)it.next();
|
EscherRecord r = it.next();
|
||||||
if(r.isContainerRecord()) {
|
if(r.isContainerRecord()) {
|
||||||
EscherRecord found =
|
EscherRecord found = findFirstWithId(id, r.getChildRecords());
|
||||||
findFirstWithId(id, r.getChildRecords());
|
|
||||||
if(found != null) {
|
if(found != null) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -201,22 +201,20 @@ public final class SlideShowRecordDumper {
|
|||||||
String nl = System.getProperty( "line.separator" );
|
String nl = System.getProperty( "line.separator" );
|
||||||
|
|
||||||
StringBuffer children = new StringBuffer();
|
StringBuffer children = new StringBuffer();
|
||||||
if ( ecr.getChildRecords().size() > 0 )
|
int count = 0;
|
||||||
|
for ( Iterator<EscherRecord> iterator = ecr.getChildIterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
children.append( " children: " + nl );
|
if (count < 1) {
|
||||||
|
children.append( " children: " + nl );
|
||||||
int count = 0;
|
|
||||||
for ( Iterator iterator = ecr.getChildRecords().iterator(); iterator.hasNext(); )
|
|
||||||
{
|
|
||||||
String newIndent = " ";
|
|
||||||
|
|
||||||
EscherRecord record = (EscherRecord) iterator.next();
|
|
||||||
children.append(newIndent + "Child " + count + ":" + nl);
|
|
||||||
|
|
||||||
children.append( printEscherRecord(record) );
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
String newIndent = " ";
|
||||||
|
|
||||||
|
EscherRecord record = iterator.next();
|
||||||
|
children.append(newIndent + "Child " + count + ":" + nl);
|
||||||
|
|
||||||
|
children.append( printEscherRecord(record) );
|
||||||
|
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -76,7 +76,7 @@ public final class ActiveXShape extends Picture {
|
|||||||
|
|
||||||
EscherClientDataRecord cldata = new EscherClientDataRecord();
|
EscherClientDataRecord cldata = new EscherClientDataRecord();
|
||||||
cldata.setOptions((short)0xF);
|
cldata.setOptions((short)0xF);
|
||||||
_escherContainer.getChildRecords().add(cldata);
|
_escherContainer.addChildRecord(cldata); // TODO unit test to prove getChildRecords().add is wrong
|
||||||
|
|
||||||
OEShapeAtom oe = new OEShapeAtom();
|
OEShapeAtom oe = new OEShapeAtom();
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public final class ActiveXShape extends Picture {
|
|||||||
*/
|
*/
|
||||||
public void setActiveXIndex(int idx){
|
public void setActiveXIndex(int idx){
|
||||||
EscherContainerRecord spContainer = getSpContainer();
|
EscherContainerRecord spContainer = getSpContainer();
|
||||||
for (Iterator<EscherRecord> it = spContainer.getChildRecords().iterator(); it.hasNext();) {
|
for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
|
||||||
EscherRecord obj = it.next();
|
EscherRecord obj = it.next();
|
||||||
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
|
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
|
||||||
EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;
|
EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;
|
||||||
|
@ -177,11 +177,10 @@ public class Hyperlink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EscherContainerRecord spContainer = shape.getSpContainer();
|
EscherContainerRecord spContainer = shape.getSpContainer();
|
||||||
List spchild = spContainer.getChildRecords();
|
for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext(); ) {
|
||||||
for (Iterator it = spchild.iterator(); it.hasNext(); ) {
|
EscherRecord obj = it.next();
|
||||||
EscherRecord obj = (EscherRecord)it.next();
|
|
||||||
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID){
|
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID){
|
||||||
byte[] data = ((EscherContainerRecord)obj).serialize();
|
byte[] data = obj.serialize();
|
||||||
Record[] records = Record.findChildRecords(data, 8, data.length-8);
|
Record[] records = Record.findChildRecords(data, 8, data.length-8);
|
||||||
if(records != null) find(records, exobj, lst);
|
if(records != null) find(records, exobj, lst);
|
||||||
}
|
}
|
||||||
|
@ -86,13 +86,7 @@ public class Placeholder extends TextBox {
|
|||||||
cldata.setRemainingData(out.toByteArray());
|
cldata.setRemainingData(out.toByteArray());
|
||||||
|
|
||||||
//append placeholder container before EscherTextboxRecord
|
//append placeholder container before EscherTextboxRecord
|
||||||
List lst = _escherContainer.getChildRecords();
|
_escherContainer.addChildBefore(cldata, EscherTextboxRecord.RECORD_ID);
|
||||||
for (int i = 0; i < lst.size(); i++) {
|
|
||||||
EscherRecord rec = (EscherRecord)lst.get(i);
|
|
||||||
if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
|
|
||||||
lst.add(i++, cldata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _escherContainer;
|
return _escherContainer;
|
||||||
}
|
}
|
||||||
|
@ -246,9 +246,9 @@ public abstract class Shape {
|
|||||||
* @return escher record or <code>null</code> if not found.
|
* @return escher record or <code>null</code> if not found.
|
||||||
*/
|
*/
|
||||||
public static EscherRecord getEscherChild(EscherContainerRecord owner, int recordId){
|
public static EscherRecord getEscherChild(EscherContainerRecord owner, int recordId){
|
||||||
for ( Iterator iterator = owner.getChildRecords().iterator(); iterator.hasNext(); )
|
for ( Iterator<EscherRecord> iterator = owner.getChildIterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
EscherRecord escherRecord = (EscherRecord) iterator.next();
|
EscherRecord escherRecord = iterator.next();
|
||||||
if (escherRecord.getRecordId() == recordId)
|
if (escherRecord.getRecordId() == recordId)
|
||||||
return escherRecord;
|
return escherRecord;
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,8 @@ public class ShapeFactory {
|
|||||||
|
|
||||||
protected static Record getClientDataRecord(EscherContainerRecord spContainer, int recordType) {
|
protected static Record getClientDataRecord(EscherContainerRecord spContainer, int recordType) {
|
||||||
Record oep = null;
|
Record oep = null;
|
||||||
for (Iterator it = spContainer.getChildRecords().iterator(); it.hasNext();) {
|
for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
|
||||||
EscherRecord obj = (EscherRecord) it.next();
|
EscherRecord obj = it.next();
|
||||||
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
|
if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
|
||||||
byte[] data = obj.serialize();
|
byte[] data = obj.serialize();
|
||||||
Record[] records = Record.findChildRecords(data, 8, data.length - 8);
|
Record[] records = Record.findChildRecords(data, 8, data.length - 8);
|
||||||
|
@ -14,18 +14,24 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.ddf.EscherChildAnchorRecord;
|
||||||
|
import org.apache.poi.ddf.EscherClientAnchorRecord;
|
||||||
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
|
import org.apache.poi.ddf.EscherRecord;
|
||||||
|
import org.apache.poi.ddf.EscherSpRecord;
|
||||||
|
import org.apache.poi.ddf.EscherSpgrRecord;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a group of shapes.
|
* Represents a group of shapes.
|
||||||
@ -57,14 +63,17 @@ public class ShapeGroup extends Shape{
|
|||||||
* @return the shapes contained in this group container
|
* @return the shapes contained in this group container
|
||||||
*/
|
*/
|
||||||
public Shape[] getShapes() {
|
public Shape[] getShapes() {
|
||||||
// Out escher container record should contain serveral
|
// Out escher container record should contain several
|
||||||
// SpContainers, the first of which is the group shape itself
|
// SpContainers, the first of which is the group shape itself
|
||||||
List lst = _escherContainer.getChildRecords();
|
Iterator<EscherRecord> iter = _escherContainer.getChildIterator();
|
||||||
|
|
||||||
ArrayList shapeList = new ArrayList();
|
|
||||||
// Don't include the first SpContainer, it is always NotPrimitive
|
// Don't include the first SpContainer, it is always NotPrimitive
|
||||||
for (int i = 1; i < lst.size(); i++){
|
if (iter.hasNext()) {
|
||||||
EscherRecord r = (EscherRecord)lst.get(i);
|
iter.next();
|
||||||
|
}
|
||||||
|
List<Shape> shapeList = new ArrayList<Shape>();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
EscherRecord r = iter.next();
|
||||||
if(r instanceof EscherContainerRecord) {
|
if(r instanceof EscherContainerRecord) {
|
||||||
// Create the Shape for it
|
// Create the Shape for it
|
||||||
EscherContainerRecord container = (EscherContainerRecord)r;
|
EscherContainerRecord container = (EscherContainerRecord)r;
|
||||||
@ -79,7 +88,7 @@ public class ShapeGroup extends Shape{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Put the shapes into an array, and return
|
// Put the shapes into an array, and return
|
||||||
Shape[] shapes = (Shape[])shapeList.toArray(new Shape[shapeList.size()]);
|
Shape[] shapes = shapeList.toArray(new Shape[shapeList.size()]);
|
||||||
return shapes;
|
return shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +100,7 @@ public class ShapeGroup extends Shape{
|
|||||||
*/
|
*/
|
||||||
public void setAnchor(java.awt.Rectangle anchor){
|
public void setAnchor(java.awt.Rectangle anchor){
|
||||||
|
|
||||||
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
|
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
||||||
|
|
||||||
EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
|
EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
|
||||||
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
|
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
|
||||||
@ -122,7 +131,7 @@ public class ShapeGroup extends Shape{
|
|||||||
* @param anchor the coordinate space of this group
|
* @param anchor the coordinate space of this group
|
||||||
*/
|
*/
|
||||||
public void setCoordinates(Rectangle2D anchor){
|
public void setCoordinates(Rectangle2D anchor){
|
||||||
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
|
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
||||||
EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
|
EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
|
||||||
|
|
||||||
int x1 = (int)Math.round(anchor.getX()*MASTER_DPI/POINT_DPI);
|
int x1 = (int)Math.round(anchor.getX()*MASTER_DPI/POINT_DPI);
|
||||||
@ -144,7 +153,7 @@ public class ShapeGroup extends Shape{
|
|||||||
* @return the coordinate space of this group
|
* @return the coordinate space of this group
|
||||||
*/
|
*/
|
||||||
public Rectangle2D getCoordinates(){
|
public Rectangle2D getCoordinates(){
|
||||||
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
|
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
||||||
EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
|
EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);
|
||||||
|
|
||||||
Rectangle2D.Float anchor = new Rectangle2D.Float();
|
Rectangle2D.Float anchor = new Rectangle2D.Float();
|
||||||
@ -228,7 +237,7 @@ public class ShapeGroup extends Shape{
|
|||||||
* @return the anchor of this shape group
|
* @return the anchor of this shape group
|
||||||
*/
|
*/
|
||||||
public Rectangle2D getAnchor2D(){
|
public Rectangle2D getAnchor2D(){
|
||||||
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChildRecords().get(0);
|
EscherContainerRecord spContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
||||||
EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
|
EscherClientAnchorRecord clientAnchor = (EscherClientAnchorRecord)getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
|
||||||
Rectangle2D.Float anchor = new Rectangle2D.Float();
|
Rectangle2D.Float anchor = new Rectangle2D.Float();
|
||||||
if(clientAnchor == null){
|
if(clientAnchor == null){
|
||||||
|
@ -211,26 +211,32 @@ public abstract class Sheet {
|
|||||||
|
|
||||||
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
||||||
EscherContainerRecord spgr = null;
|
EscherContainerRecord spgr = null;
|
||||||
List ch = dg.getChildRecords();
|
|
||||||
|
|
||||||
for (Iterator it = ch.iterator(); it.hasNext();) {
|
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
|
||||||
EscherRecord rec = (EscherRecord) it.next();
|
EscherRecord rec = it.next();
|
||||||
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
||||||
spgr = (EscherContainerRecord) rec;
|
spgr = (EscherContainerRecord) rec;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ch = spgr.getChildRecords();
|
if (spgr == null) {
|
||||||
|
throw new IllegalStateException("spgr not found");
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList shapes = new ArrayList();
|
List<Shape> shapes = new ArrayList<Shape>();
|
||||||
for (int i = 1; i < ch.size(); i++) {
|
Iterator<EscherRecord> it = spgr.getChildIterator();
|
||||||
EscherContainerRecord sp = (EscherContainerRecord) ch.get(i);
|
if (it.hasNext()) {
|
||||||
|
// skip first item
|
||||||
|
it.next();
|
||||||
|
}
|
||||||
|
for (; it.hasNext();) {
|
||||||
|
EscherContainerRecord sp = (EscherContainerRecord) it.next();
|
||||||
Shape sh = ShapeFactory.createShape(sp, null);
|
Shape sh = ShapeFactory.createShape(sp, null);
|
||||||
sh.setSheet(this);
|
sh.setSheet(this);
|
||||||
shapes.add(sh);
|
shapes.add(sh);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Shape[]) shapes.toArray(new Shape[shapes.size()]);
|
return shapes.toArray(new Shape[shapes.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,17 +307,21 @@ public abstract class Sheet {
|
|||||||
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
||||||
EscherContainerRecord spgr = null;
|
EscherContainerRecord spgr = null;
|
||||||
|
|
||||||
for (Iterator it = dg.getChildRecords().iterator(); it.hasNext();) {
|
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
|
||||||
EscherRecord rec = (EscherRecord) it.next();
|
EscherRecord rec = it.next();
|
||||||
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
|
||||||
spgr = (EscherContainerRecord) rec;
|
spgr = (EscherContainerRecord) rec;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(spgr == null) return false;
|
if(spgr == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
List lst = spgr.getChildRecords();
|
List<EscherRecord> lst = spgr.getChildRecords();
|
||||||
return lst.remove(shape.getSpContainer());
|
boolean result = lst.remove(shape.getSpContainer());
|
||||||
|
spgr.setChildRecords(lst);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -344,10 +354,9 @@ public abstract class Sheet {
|
|||||||
|
|
||||||
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
|
||||||
EscherContainerRecord spContainer = null;
|
EscherContainerRecord spContainer = null;
|
||||||
List ch = dg.getChildRecords();
|
|
||||||
|
|
||||||
for (Iterator it = ch.iterator(); it.hasNext();) {
|
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
|
||||||
EscherRecord rec = (EscherRecord) it.next();
|
EscherRecord rec = it.next();
|
||||||
if (rec.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
|
if (rec.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
|
||||||
spContainer = (EscherContainerRecord) rec;
|
spContainer = (EscherContainerRecord) rec;
|
||||||
break;
|
break;
|
||||||
|
@ -17,20 +17,21 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import java.awt.Color;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import java.awt.Graphics2D;
|
||||||
import org.apache.poi.hslf.record.ColorSchemeAtom;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
|
||||||
import org.apache.poi.hslf.record.InteractiveInfo;
|
|
||||||
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.ddf.EscherSpRecord;
|
||||||
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
|
import org.apache.poi.hslf.record.ColorSchemeAtom;
|
||||||
|
import org.apache.poi.hslf.record.InteractiveInfo;
|
||||||
|
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
||||||
|
import org.apache.poi.hslf.record.Record;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract simple (non-group) shape.
|
* An abstract simple (non-group) shape.
|
||||||
* This is the parent class for all primitive shapes like Line, Rectangle, etc.
|
* This is the parent class for all primitive shapes like Line, Rectangle, etc.
|
||||||
@ -256,8 +257,8 @@ public class SimpleShape extends Shape {
|
|||||||
Rectangle2D clientAnchor = top.getAnchor2D();
|
Rectangle2D clientAnchor = top.getAnchor2D();
|
||||||
Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();
|
Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();
|
||||||
|
|
||||||
double scalex = (double)spgrAnchor.getWidth()/clientAnchor.getWidth();
|
double scalex = spgrAnchor.getWidth()/clientAnchor.getWidth();
|
||||||
double scaley = (double)spgrAnchor.getHeight()/clientAnchor.getHeight();
|
double scaley = spgrAnchor.getHeight()/clientAnchor.getHeight();
|
||||||
|
|
||||||
double x = clientAnchor.getX() + (anchor.getX() - spgrAnchor.getX())/scalex;
|
double x = clientAnchor.getX() + (anchor.getX() - spgrAnchor.getX())/scalex;
|
||||||
double y = clientAnchor.getY() + (anchor.getY() - spgrAnchor.getY())/scaley;
|
double y = clientAnchor.getY() + (anchor.getY() - spgrAnchor.getY())/scaley;
|
||||||
@ -353,7 +354,7 @@ public class SimpleShape extends Shape {
|
|||||||
|
|
||||||
EscherClientDataRecord cldata = new EscherClientDataRecord();
|
EscherClientDataRecord cldata = new EscherClientDataRecord();
|
||||||
cldata.setOptions((short)0xF);
|
cldata.setOptions((short)0xF);
|
||||||
getSpContainer().getChildRecords().add(cldata);
|
getSpContainer().addChildRecord(cldata); // TODO - junit to prove getChildRecords().add is wrong
|
||||||
|
|
||||||
InteractiveInfo info = new InteractiveInfo();
|
InteractiveInfo info = new InteractiveInfo();
|
||||||
InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
|
InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
|
||||||
|
@ -152,7 +152,7 @@ public class Slide extends Sheet
|
|||||||
EscherSpRecord spr = null;
|
EscherSpRecord spr = null;
|
||||||
switch(c.getRecordId()){
|
switch(c.getRecordId()){
|
||||||
case EscherContainerRecord.SPGR_CONTAINER:
|
case EscherContainerRecord.SPGR_CONTAINER:
|
||||||
EscherContainerRecord dc = (EscherContainerRecord)c.getChildRecords().get(0);
|
EscherContainerRecord dc = (EscherContainerRecord)c.getChild(0);
|
||||||
spr = dc.getChildById(EscherSpRecord.RECORD_ID);
|
spr = dc.getChildById(EscherSpRecord.RECORD_ID);
|
||||||
break;
|
break;
|
||||||
case EscherContainerRecord.SP_CONTAINER:
|
case EscherContainerRecord.SP_CONTAINER:
|
||||||
|
@ -73,7 +73,6 @@ public class Table extends ShapeGroup {
|
|||||||
setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
|
setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
|
||||||
|
|
||||||
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
||||||
List lst = spCont.getChildRecords();
|
|
||||||
EscherOptRecord opt = new EscherOptRecord();
|
EscherOptRecord opt = new EscherOptRecord();
|
||||||
opt.setRecordId((short)0xF122);
|
opt.setRecordId((short)0xF122);
|
||||||
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
|
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
|
||||||
@ -82,8 +81,9 @@ public class Table extends ShapeGroup {
|
|||||||
p.setNumberOfElementsInArray(numrows);
|
p.setNumberOfElementsInArray(numrows);
|
||||||
p.setNumberOfElementsInMemory(numrows);
|
p.setNumberOfElementsInMemory(numrows);
|
||||||
opt.addEscherProperty(p);
|
opt.addEscherProperty(p);
|
||||||
|
List<EscherRecord> lst = spCont.getChildRecords();
|
||||||
lst.add(lst.size()-1, opt);
|
lst.add(lst.size()-1, opt);
|
||||||
|
spCont.setChildRecords(lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +118,7 @@ public class Table extends ShapeGroup {
|
|||||||
super.afterInsert(sh);
|
super.afterInsert(sh);
|
||||||
|
|
||||||
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
||||||
List lst = spCont.getChildRecords();
|
List<EscherRecord> lst = spCont.getChildRecords();
|
||||||
EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
|
EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
|
||||||
EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1);
|
EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1);
|
||||||
for (int i = 0; i < cells.length; i++) {
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
@ -175,11 +175,9 @@ public class PPDrawing extends RecordAtom
|
|||||||
} else {
|
} else {
|
||||||
// If it has children, walk them
|
// If it has children, walk them
|
||||||
if(toSearch[i].isContainerRecord()) {
|
if(toSearch[i].isContainerRecord()) {
|
||||||
List childrenL = toSearch[i].getChildRecords();
|
List<EscherRecord> childrenL = toSearch[i].getChildRecords();
|
||||||
EscherRecord[] children = new EscherRecord[childrenL.size()];
|
EscherRecord[] children = new EscherRecord[childrenL.size()];
|
||||||
for(int j=0; j< children.length; j++) {
|
childrenL.toArray(children);
|
||||||
children[j] = (EscherRecord)childrenL.get(j);
|
|
||||||
}
|
|
||||||
findEscherTextboxRecord(children,found);
|
findEscherTextboxRecord(children,found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,8 +307,8 @@ public class PPDrawing extends RecordAtom
|
|||||||
public EscherDgRecord getEscherDgRecord(){
|
public EscherDgRecord getEscherDgRecord(){
|
||||||
if(dg == null){
|
if(dg == null){
|
||||||
EscherContainerRecord dgContainer = (EscherContainerRecord)childRecords[0];
|
EscherContainerRecord dgContainer = (EscherContainerRecord)childRecords[0];
|
||||||
for(Iterator it = dgContainer.getChildRecords().iterator(); it.hasNext();){
|
for(Iterator<EscherRecord> it = dgContainer.getChildIterator(); it.hasNext();){
|
||||||
EscherRecord r = (EscherRecord) it.next();
|
EscherRecord r = it.next();
|
||||||
if(r instanceof EscherDgRecord){
|
if(r instanceof EscherDgRecord){
|
||||||
dg = (EscherDgRecord)r;
|
dg = (EscherDgRecord)r;
|
||||||
break;
|
break;
|
||||||
|
@ -71,15 +71,14 @@ public class PPDrawingGroup extends RecordAtom {
|
|||||||
|
|
||||||
public void writeOut(OutputStream out) throws IOException {
|
public void writeOut(OutputStream out) throws IOException {
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
List child = dggContainer.getChildRecords();
|
Iterator<EscherRecord> iter = dggContainer.getChildIterator();
|
||||||
for (int i = 0; i < child.size(); i++) {
|
while (iter.hasNext()) {
|
||||||
EscherRecord r = (EscherRecord)child.get(i);
|
EscherRecord r = iter.next();
|
||||||
if (r.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER){
|
if (r.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER){
|
||||||
EscherContainerRecord bstore = (EscherContainerRecord)r;
|
EscherContainerRecord bstore = (EscherContainerRecord)r;
|
||||||
|
|
||||||
ByteArrayOutputStream b2 = new ByteArrayOutputStream();
|
ByteArrayOutputStream b2 = new ByteArrayOutputStream();
|
||||||
List blip = bstore.getChildRecords();
|
for (Iterator<EscherRecord> it= bstore.getChildIterator(); it.hasNext();) {
|
||||||
for (Iterator it=blip.iterator(); it.hasNext();) {
|
|
||||||
EscherBSERecord bse = (EscherBSERecord)it.next();
|
EscherBSERecord bse = (EscherBSERecord)it.next();
|
||||||
byte[] b = new byte[36+8];
|
byte[] b = new byte[36+8];
|
||||||
bse.serialize(0, b);
|
bse.serialize(0, b);
|
||||||
@ -121,8 +120,8 @@ public class PPDrawingGroup extends RecordAtom {
|
|||||||
|
|
||||||
public EscherDggRecord getEscherDggRecord(){
|
public EscherDggRecord getEscherDggRecord(){
|
||||||
if(dgg == null){
|
if(dgg == null){
|
||||||
for(Iterator it = dggContainer.getChildRecords().iterator(); it.hasNext();){
|
for(Iterator<EscherRecord> it = dggContainer.getChildIterator(); it.hasNext();){
|
||||||
EscherRecord r = (EscherRecord) it.next();
|
EscherRecord r = it.next();
|
||||||
if(r instanceof EscherDggRecord){
|
if(r instanceof EscherDggRecord){
|
||||||
dgg = (EscherDggRecord)r;
|
dgg = (EscherDggRecord)r;
|
||||||
break;
|
break;
|
||||||
|
@ -746,19 +746,11 @@ public final class SlideShow {
|
|||||||
bstore = new EscherContainerRecord();
|
bstore = new EscherContainerRecord();
|
||||||
bstore.setRecordId( EscherContainerRecord.BSTORE_CONTAINER);
|
bstore.setRecordId( EscherContainerRecord.BSTORE_CONTAINER);
|
||||||
|
|
||||||
List child = dggContainer.getChildRecords();
|
dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
|
||||||
for ( int i = 0; i < child.size(); i++ ) {
|
|
||||||
EscherRecord rec = (EscherRecord)child.get(i);
|
|
||||||
if (rec.getRecordId() == EscherOptRecord.RECORD_ID){
|
|
||||||
child.add(i, bstore);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dggContainer.setChildRecords(child);
|
|
||||||
} else {
|
} else {
|
||||||
List lst = bstore.getChildRecords();
|
Iterator<EscherRecord> iter = bstore.getChildIterator();
|
||||||
for ( int i = 0; i < lst.size(); i++ ) {
|
for (int i = 0; iter.hasNext(); i++) {
|
||||||
EscherBSERecord bse = (EscherBSERecord) lst.get(i);
|
EscherBSERecord bse = (EscherBSERecord) iter.next();
|
||||||
if (Arrays.equals(bse.getUid(), uid)){
|
if (Arrays.equals(bse.getUid(), uid)){
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ public class TestEscherBlipRecord extends TestCase
|
|||||||
|
|
||||||
EscherContainerRecord record = new EscherContainerRecord();
|
EscherContainerRecord record = new EscherContainerRecord();
|
||||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChildRecords().get(1);
|
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChildRecords().get(0);
|
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(0);
|
||||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeWin32());
|
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeWin32());
|
||||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeMacOS());
|
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeMacOS());
|
||||||
assertTrue(Arrays.equals(new byte[]{
|
assertTrue(Arrays.equals(new byte[]{
|
||||||
@ -89,8 +89,8 @@ public class TestEscherBlipRecord extends TestCase
|
|||||||
|
|
||||||
EscherContainerRecord record = new EscherContainerRecord();
|
EscherContainerRecord record = new EscherContainerRecord();
|
||||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChildRecords().get(1);
|
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChildRecords().get(1);
|
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(1);
|
||||||
//System.out.println(bse1);
|
//System.out.println(bse1);
|
||||||
assertEquals(EscherBSERecord.BT_WMF, bse1.getBlipTypeWin32());
|
assertEquals(EscherBSERecord.BT_WMF, bse1.getBlipTypeWin32());
|
||||||
assertEquals(EscherBSERecord.BT_PICT, bse1.getBlipTypeMacOS());
|
assertEquals(EscherBSERecord.BT_PICT, bse1.getBlipTypeMacOS());
|
||||||
|
@ -34,15 +34,11 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class TestEscherAggregate extends TestCase
|
public final class TestEscherAggregate extends TestCase {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Tests that the create aggregate method correctly rejoins escher records together.
|
* Tests that the create aggregate method correctly rejoins escher records together.
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public void testCreateAggregate() throws Exception
|
public void testCreateAggregate() {
|
||||||
{
|
|
||||||
String msoDrawingRecord1 =
|
String msoDrawingRecord1 =
|
||||||
"0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
|
"0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
|
||||||
"03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" +
|
"03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" +
|
||||||
@ -76,7 +72,7 @@ public class TestEscherAggregate extends TestCase
|
|||||||
|
|
||||||
ObjRecord r2 = new ObjRecord();
|
ObjRecord r2 = new ObjRecord();
|
||||||
|
|
||||||
List records = new ArrayList();
|
List<Record> records = new ArrayList<Record>();
|
||||||
records.add( d1 );
|
records.add( d1 );
|
||||||
records.add( r1 );
|
records.add( r1 );
|
||||||
records.add( d2 );
|
records.add( d2 );
|
||||||
@ -92,8 +88,7 @@ public class TestEscherAggregate extends TestCase
|
|||||||
// System.out.println( "aggregate = " + aggregate );
|
// System.out.println( "aggregate = " + aggregate );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSerialize() throws Exception
|
public void testSerialize() {
|
||||||
{
|
|
||||||
|
|
||||||
EscherContainerRecord container1 = new EscherContainerRecord();
|
EscherContainerRecord container1 = new EscherContainerRecord();
|
||||||
EscherContainerRecord spContainer1 = new EscherContainerRecord();
|
EscherContainerRecord spContainer1 = new EscherContainerRecord();
|
||||||
@ -127,8 +122,8 @@ public class TestEscherAggregate extends TestCase
|
|||||||
|
|
||||||
EscherAggregate aggregate = new EscherAggregate(null);
|
EscherAggregate aggregate = new EscherAggregate(null);
|
||||||
aggregate.addEscherRecord( container1 );
|
aggregate.addEscherRecord( container1 );
|
||||||
aggregate.assoicateShapeToObjRecord( d2, new ObjRecord() );
|
aggregate.associateShapeToObjRecord( d2, new ObjRecord() );
|
||||||
aggregate.assoicateShapeToObjRecord( d3, new ObjRecord() );
|
aggregate.associateShapeToObjRecord( d3, new ObjRecord() );
|
||||||
|
|
||||||
byte[] data = new byte[112];
|
byte[] data = new byte[112];
|
||||||
int bytesWritten = aggregate.serialize( 0, data );
|
int bytesWritten = aggregate.serialize( 0, data );
|
||||||
@ -136,5 +131,4 @@ public class TestEscherAggregate extends TestCase
|
|||||||
assertEquals( "[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00]",
|
assertEquals( "[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00]",
|
||||||
HexDump.toHex( data ) );
|
HexDump.toHex( data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user