ASF Bugzilla – Attachment 17887 Details for
Bug 38954
patch: new functionality which allows working with shapes in HSLF
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch with changes
ppt_shapes.patch (text/plain), 20.29 KB, created by
Yegor Kozlov
on 2006-03-13 17:10:50 UTC
(
hide
)
Description:
patch with changes
Filename:
MIME Type:
Creator:
Yegor Kozlov
Created:
2006-03-13 17:10:50 UTC
Size:
20.29 KB
patch
obsolete
>Index: src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (working copy) >@@ -20,22 +20,18 @@ > package org.apache.poi.hslf.usermodel; > > import java.util.*; >+import java.util.List; > import java.io.*; >+import java.awt.*; > > import org.apache.poi.util.LittleEndian; > > import org.apache.poi.hslf.*; > import org.apache.poi.hslf.model.*; >-import org.apache.poi.hslf.record.FontCollection; >-import org.apache.poi.hslf.record.ParentAwareRecord; >-import org.apache.poi.hslf.record.Record; >-import org.apache.poi.hslf.record.RecordContainer; >-import org.apache.poi.hslf.record.RecordTypes; >-import org.apache.poi.hslf.record.SlideAtom; >-import org.apache.poi.hslf.record.SlideListWithText; >+import org.apache.poi.hslf.model.Notes; >+import org.apache.poi.hslf.model.Slide; > import org.apache.poi.hslf.record.SlideListWithText.*; >-import org.apache.poi.hslf.record.PersistPtrHolder; >-import org.apache.poi.hslf.record.PositionDependentRecord; >+import org.apache.poi.hslf.record.*; > import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; > > /** >@@ -93,8 +89,7 @@ > // Build up the model level Slides and Notes > buildSlidesAndNotes(); > } >- >- >+ > /** > * Find the records that are parent-aware, and tell them > * who their parent is >@@ -398,4 +393,102 @@ > public Picture[] getPictures() throws IOException { > return _hslfSlideShow.getPictures(); > } >+ >+ /** >+ * Create a blank <code>Slide</code>. >+ * >+ * @return the created <code>Slide</code> >+ * @throws IOException >+ */ >+ public Slide createSlide() throws IOException { >+ RecordContainer doc = null; //find document record >+ for (int i = 0; i < _mostRecentCoreRecords.length; i++) { >+ Record record = _records[i]; >+ if (record.getRecordType() == RecordTypes.Document.typeID){ >+ doc = (RecordContainer)record; >+ break; >+ } >+ } >+ >+ RecordContainer slist=null; >+ Record[] rec = doc.getChildRecords(); >+ int num = 0; >+ for (int i = 0; i < rec.length; i++) { >+ Record record = rec[i]; >+ if (record.getRecordType() == RecordTypes.SlideListWithText.typeID){ >+ if (num > 0){ >+ slist = (RecordContainer)record; >+ } >+ num++; >+ } >+ } >+ if (num == 1){ >+ slist = new SlideListWithText(); >+ rec = doc.getChildRecords(); >+ for (int i = 0; i < rec.length-1; i++) { >+ Record record = rec[i+1]; >+ if (record.getRecordType() == RecordTypes.EndDocument.typeID){ >+ >+ doc.addChildAfter(slist, rec[i]); >+ } >+ } >+ } >+ rec = slist.getChildRecords(); >+ >+ //add SlidePersistAtom >+ SlidePersistAtom prev = rec.length == 0 ? null : (SlidePersistAtom)rec[rec.length - 1]; >+ SlidePersistAtom sp = new SlidePersistAtom(); >+ >+ //refernce is the 1-based index of the slide container in the document root. >+ //it always starts with 3 (1 is Document, 2 is MainMaster, 3 is the first slide) >+ sp.setRefID(prev == null ? 3 : (prev.getRefID() + 1)); >+ //first slideId is always 256 >+ sp.setSlideIdentifier(prev == null ? 256 : (prev.getSlideIdentifier() + 1)); >+ >+ Record[] r = slist.appendChildRecord(sp, >+ slist.getChildRecords() == null ? new Record[]{} : slist.getChildRecords()); >+ slist.setChildRecords(r); >+ Slide slide = new Slide(); >+ >+ int offset = 0; >+ List lst = new ArrayList(); >+ for (int i = 0; i < _records.length; i++) { >+ Record record = _records[i]; >+ lst.add(record); >+ ByteArrayOutputStream out = new ByteArrayOutputStream(); >+ record.writeOut(out); >+ >+ if (_records[i].getRecordType() == RecordTypes.PersistPtrIncrementalBlock.typeID){ >+ lst.add(i, slide.getSlideRecord()); >+ >+ slide.getSlideRecord().setLastOnDiskOffset(offset); >+ PersistPtrHolder ptr = (PersistPtrHolder)_records[i]; >+ int id = sp.getRefID(); >+ ptr.getSlideDataLocationsLookup().put(new Integer(id), new Integer((i+1)*4)); >+ ptr.getSlideLocationsLookup().put(new Integer(id), new Integer(offset)); >+ ptr.addSlideLookup(id, offset); >+ >+ } >+ offset += out.size() ; >+ } >+ _records = (Record[])lst.toArray(new Record[lst.size()]); >+ _hslfSlideShow.setRecords(_records); >+ >+ UserEditAtom usr = (UserEditAtom)_records[_records.length-1]; >+ usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW); >+ return slide; >+ } >+ >+ public Dimension getPageSize(){ >+ RecordContainer doc = null; //find document record >+ for (int i = 0; i < _mostRecentCoreRecords.length; i++) { >+ Record record = _records[i]; >+ if (record.getRecordType() == RecordTypes.Document.typeID){ >+ doc = (RecordContainer)record; >+ break; >+ } >+ } >+ DocumentAtom docatom = (DocumentAtom)doc.getChildRecords()[0]; >+ return new Dimension((int)docatom.getSlideSizeX(), (int)docatom.getSlideSizeY()); >+ } > } >Index: src/scratchpad/src/org/apache/poi/hslf/model/Slide.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (working copy) >@@ -23,7 +23,7 @@ > > import org.apache.poi.hslf.record.*; > import org.apache.poi.hslf.record.SlideListWithText.*; >-import org.apache.poi.util.LittleEndian; >+import org.apache.poi.ddf.*; > > /** > * This class represents a slide in a PowerPoint Document. It allows >@@ -43,6 +43,10 @@ > private TextRun[] _otherRuns; // Any from the PPDrawing, shouldn't really be any though > private Notes _notes; // usermodel needs to set this > >+ public Slide(){ >+ _slide = new org.apache.poi.hslf.record.Slide(); >+ } >+ > /** > * Constructs a Slide from the Slide record, and the SlideAtomsSet > * containing the text. >@@ -129,4 +133,54 @@ > * Returns the Notes Sheet for this slide, or null if there isn't one > */ > public Notes getNotesSheet() { return _notes; } >-} >+ >+ /** >+ * Returns all shapes contained in this Slide >+ * >+ * @return all shapes contained in this Slide >+ */ >+ public Shape[] getShapes() { >+ PPDrawing ppdrawing = _slide.getPPDrawing(); >+ >+ EscherContainerRecord dg = (EscherContainerRecord)ppdrawing.getEscherRecords()[0]; >+ EscherContainerRecord spgr = null; >+ List ch = dg.getChildRecords(); >+ >+ for (Iterator it = ch.iterator(); it.hasNext();) { >+ EscherRecord rec = (EscherRecord)it.next(); >+ if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){ >+ spgr = (EscherContainerRecord)rec; >+ break; >+ } >+ } >+ ch = spgr.getChildRecords(); >+ >+ ArrayList shapes = new ArrayList(); >+ for (int i=1;i<ch.size();i++) { >+ EscherContainerRecord sp = (EscherContainerRecord)ch.get(i); >+ shapes.add(ShapeFactory.createShape(sp, null)); >+ } >+ return (Shape[])shapes.toArray(new Shape[shapes.size()]); >+ } >+ >+ /** >+ * Add a new Shape to this Slide >+ * >+ * @param shape - the Shape to add >+ */ >+ public void addShape(Shape shape){ >+ >+ PPDrawing ppdrawing = _slide.getPPDrawing(); >+ >+ EscherContainerRecord dgContainer = (EscherContainerRecord)ppdrawing.getEscherRecords()[0]; >+ EscherContainerRecord spgr = (EscherContainerRecord)Shape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER); >+ spgr.addChildRecord(shape.getShapeRecord()); >+ >+ EscherDgRecord dg = (EscherDgRecord)Shape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID); >+ dg.setNumShapes(dg.getNumShapes()+1); >+ } >+ >+ protected void create(){ >+ _slide = new org.apache.poi.hslf.record.Slide(); >+ } >+} >Index: src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java (working copy) >@@ -56,6 +56,7 @@ > // Somewhat user facing getters > public int getLastViewedSlideID() { return lastViewedSlideID; } > public short getLastViewType() { return lastViewType; } >+ public void setLastViewType(short type) { lastViewType=type; } > > // Scary internal getters > public int getLastUserEditAtomOffset() { return lastUserEditAtomOffset; } >Index: src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java (working copy) >@@ -78,6 +78,10 @@ > return _slideLocations; > } > >+ public Hashtable getSlideDataLocationsLookup() { >+ return _slideOffsetDataLocation; >+ } >+ > /** > * Adds a new slide, notes or similar, to be looked up by this. > * For now, won't look for the most optimal on disk representation. >@@ -104,6 +108,11 @@ > > // Update the atom header > LittleEndian.putInt(_header,4,newPtrData.length); >+ >+ //update info (first 4 bytes in ptr data) >+ int info = (slideID << 20 | 1); >+ LittleEndian.putInt(_ptrData, 0, info); >+ > } > > /** >@@ -178,7 +187,7 @@ > Integer oldPos = (Integer)_slideLocations.get(id); > Integer newPos = (Integer)oldToNewReferencesLookup.get(oldPos); > >- if(newPos == null) { >+ if(newPos == null) { > throw new RuntimeException("Couldn't find the new location of the \"slide\" that used to be at " + oldPos); > } > >Index: src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java (working copy) >@@ -66,8 +66,25 @@ > > > /* *************** record code follows ********************** */ >+ public SlideAtom(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 2); >+ LittleEndian.putUShort(_header, 2, (int)_type); >+ LittleEndian.putInt(_header, 4, 24); > >- /** >+ byte[] ssdate = new byte[12]; >+ layoutAtom = new SSlideLayoutAtom(ssdate); >+ layoutAtom.setGeometryType(SSlideLayoutAtom.BLANK_SLIDE); >+ >+ followMasterObjects = true; >+ followMasterScheme = true; >+ followMasterBackground = true; >+ masterID = -2147483648; >+ notesID = 0; >+ reserved = new byte[2]; >+ } >+ >+ /** > * For the Slide Atom > */ > protected SlideAtom(byte[] source, int start, int len) { >@@ -180,6 +197,7 @@ > > /** Retrieve the geometry type */ > public int getGeometryType() { return geometry; } >+ public void setGeometryType(int geom) { geometry = geom; } > > /** > * Create a new Embeded SSlideLayoutAtom, from 12 bytes of data >Index: src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java (working copy) >@@ -91,7 +91,24 @@ > { accentAndFollowingHyperlinkColourRGB = rgb; } > > /* *************** record code follows ********************** */ >+ public ColorSchemeAtom(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 16); >+ LittleEndian.putUShort(_header, 2, (int)_type); >+ LittleEndian.putInt(_header, 4, 32); > >+ // Grab the rgb values >+ backgroundColourRGB = 16777215; >+ textAndLinesColourRGB = 0; >+ shadowsColourRGB = 8421504; >+ titleTextColourRGB = 0; >+ fillsColourRGB = 10079232; >+ accentColourRGB = 13382451; >+ accentAndHyperlinkColourRGB = 16764108; >+ accentAndFollowingHyperlinkColourRGB = 11711154; >+ >+ } >+ > /** > * For the Colour Scheme (ColorSchem) Atom > */ >Index: src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java (working copy) >@@ -21,6 +21,7 @@ > import org.apache.poi.util.LittleEndian; > > import org.apache.poi.ddf.*; >+import org.apache.poi.hslf.model.ShapeTypes; > > import java.io.IOException; > import java.io.OutputStream; >@@ -62,8 +63,17 @@ > > > /* ******************** record stuff follows ********************** */ >+ public PPDrawing(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 15); >+ LittleEndian.putUShort(_header, 2, (int)RecordTypes.PPDrawing.typeID); >+ LittleEndian.putInt(_header, 4, 0); > >- /** >+ textboxWrappers = new EscherTextboxWrapper[]{}; >+ create(); >+ } >+ >+ /** > * Sets everything up, groks the escher etc > */ > protected PPDrawing(byte[] source, int start, int len) { >@@ -188,4 +198,57 @@ > // Finally, write out the children > out.write(b); > } >+ >+ protected void create(){ >+ EscherContainerRecord dgContainer = new EscherContainerRecord(); >+ dgContainer.setRecordId( EscherContainerRecord.DG_CONTAINER ); >+ dgContainer.setOptions((short)15); >+ >+ EscherDgRecord dg = new EscherDgRecord(); >+ dg.setOptions((short)16); >+ dg.setNumShapes(1); >+ dgContainer.addChildRecord(dg); >+ >+ EscherContainerRecord spgrContainer = new EscherContainerRecord(); >+ spgrContainer.setOptions((short)15); >+ spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER); >+ EscherContainerRecord spContainer = new EscherContainerRecord(); >+ spContainer.setOptions((short)15); >+ spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER); >+ EscherSpgrRecord spgr = new EscherSpgrRecord(); >+ spgr.setOptions((short)1); >+ spContainer.addChildRecord(spgr); >+ EscherSpRecord sp = new EscherSpRecord(); >+ sp.setOptions((short)((ShapeTypes.NotPrimitive << 4) + 2)); >+ sp.setFlags(EscherSpRecord.FLAG_PATRIARCH | EscherSpRecord.FLAG_GROUP); >+ spContainer.addChildRecord(sp); >+ spgrContainer.addChildRecord(spContainer); >+ dgContainer.addChildRecord(spgrContainer); >+ >+ spContainer = new EscherContainerRecord(); >+ spContainer.setOptions((short)15); >+ spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER); >+ sp = new EscherSpRecord(); >+ sp.setOptions((short)((ShapeTypes.Rectangle << 4) + 2)); >+ sp.setFlags(EscherSpRecord.FLAG_BACKGROUND | EscherSpRecord.FLAG_HASSHAPETYPE); >+ spContainer.addChildRecord(sp); >+ >+ EscherOptRecord opt = new EscherOptRecord(); >+ opt.setRecordId(EscherOptRecord.RECORD_ID); >+ opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 134217728)); >+ opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLBACKCOLOR, 134217733)); >+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__RECTRIGHT, 10064750)); >+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__RECTBOTTOM, 7778750)); >+ opt.addEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1179666)); >+ opt.addEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524288)); >+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHAPE__BLACKANDWHITESETTINGS, 9)); >+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHAPE__BACKGROUNDSHAPE, 65537)); >+ spContainer.addChildRecord(opt); >+ >+ dgContainer.addChildRecord(spContainer); >+ >+ childRecords = new EscherRecord[]{ >+ dgContainer >+ }; >+ } > } >Index: src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java (working copy) >@@ -54,7 +54,16 @@ > > private SlideAtomsSet[] slideAtomsSets; > >- /** >+ public SlideListWithText(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 15); >+ LittleEndian.putUShort(_header, 2, (int)_type); >+ LittleEndian.putInt(_header, 4, 0); >+ >+ _children = new Record[]{}; >+ } >+ >+ /** > * Create a new holder for slide records > */ > protected SlideListWithText(byte[] source, int start, int len) { >Index: src/scratchpad/src/org/apache/poi/hslf/record/Slide.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/Slide.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/Slide.java (working copy) >@@ -23,6 +23,7 @@ > import java.io.OutputStream; > import java.io.ByteArrayOutputStream; > >+ > /** > * Master container for Slides. There is one of these for every slide, > * and they have certain specific children >@@ -50,8 +51,26 @@ > */ > public PPDrawing getPPDrawing() { return ppDrawing; } > >+ public Slide(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 15); >+ LittleEndian.putUShort(_header, 2, (int)_type); >+ LittleEndian.putInt(_header, 4, 0); > >- /** >+ slideAtom = new SlideAtom(); >+ >+ ppDrawing = new PPDrawing(); >+ >+ ColorSchemeAtom colorAtom = new ColorSchemeAtom(); >+ >+ _children = new Record[]{ >+ slideAtom, >+ ppDrawing, >+ colorAtom >+ }; >+ } >+ >+ /** > * Set things up, and find our more interesting children > */ > protected Slide(byte[] source, int start, int len) { >Index: src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java (working copy) >@@ -41,7 +41,9 @@ > */ > public Record[] getChildRecords() { return _children; } > >- /** >+ public void setChildRecords(Record[] rec) { _children = rec; } >+ >+ /** > * We're not an atom > */ > public boolean isAnAtom() { return false; } >Index: src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java (working copy) >@@ -51,7 +51,17 @@ > > /* *************** record code follows ********************** */ > >- /** >+ public SlidePersistAtom(){ >+ _header = new byte[8]; >+ LittleEndian.putUShort(_header, 0, 0); >+ LittleEndian.putUShort(_header, 2, (int)_type); >+ LittleEndian.putInt(_header, 4, 20); >+ >+ hasShapesOtherThanPlaceholders = true; >+ reservedFields = new byte[4]; >+ } >+ >+ /** > * For the SlidePersist Atom > */ > protected SlidePersistAtom(byte[] source, int start, int len) { >@@ -111,4 +121,14 @@ > writeLittleEndian(slideIdentifier,out); > out.write(reservedFields); > } >+ >+ public void setRefID(int id) { >+ refID = id; >+ } >+ >+ public void setSlideIdentifier(int id) { >+ slideIdentifier = id; >+ } >+ >+ > } >Index: src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (revision 385585) >+++ src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (working copy) >@@ -368,4 +368,8 @@ > > return (Picture[])p.toArray(new Picture[p.size()]); > } >+ >+ public void setRecords(Record[] rec){ >+ _records = rec; >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 38954
:
17884
|
17885
|
17886
| 17887