Return-Path: Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: (qmail 53370 invoked from network); 18 Aug 2009 02:42:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Aug 2009 02:42:14 -0000 Received: (qmail 66820 invoked by uid 500); 18 Aug 2009 02:42:33 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 66780 invoked by uid 500); 18 Aug 2009 02:42:33 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 66771 invoked by uid 99); 18 Aug 2009 02:42:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Aug 2009 02:42:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Aug 2009 02:42:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 445E8238898B; Tue, 18 Aug 2009 02:42:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r805262 [4/6] - in /poi/trunk/src: java/org/apache/poi/hssf/dev/ java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/record/formula/ java/org/apache/poi/hssf/record/formula/atp/ java/org/apache/poi/hssf... Date: Tue, 18 Aug 2009 02:41:50 -0000 To: commits@poi.apache.org From: josh@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090818024201.445E8238898B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Tue Aug 18 02:41:45 2009 @@ -38,220 +38,212 @@ import org.apache.poi.hslf.model.Slide; import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; -import org.apache.poi.util.ArrayUtil; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; /** * This class is a friendly wrapper on top of the more scary HSLFSlideShow. * - * TODO: - * - figure out how to match notes to their correct sheet - * (will involve understanding DocSlideList and DocNotesList) - * - handle Slide creation cleaner + * TODO: - figure out how to match notes to their correct sheet (will involve + * understanding DocSlideList and DocNotesList) - handle Slide creation cleaner * * @author Nick Burch * @author Yegor kozlov */ public final class SlideShow { - // What we're based on - private HSLFSlideShow _hslfSlideShow; + // What we're based on + private HSLFSlideShow _hslfSlideShow; - // Low level contents, as taken from HSLFSlideShow - private Record[] _records; + // Low level contents, as taken from HSLFSlideShow + private Record[] _records; - // Pointers to the most recent versions of the core records - // (Document, Notes, Slide etc) - private Record[] _mostRecentCoreRecords; - // Lookup between the PersitPtr "sheet" IDs, and the position - // in the mostRecentCoreRecords array - private Hashtable _sheetIdToCoreRecordsLookup; - - // Records that are interesting - private Document _documentRecord; - - // Friendly objects for people to deal with - private SlideMaster[] _masters; - private TitleMaster[] _titleMasters; - private Slide[] _slides; - private Notes[] _notes; - private FontCollection _fonts; - - // For logging - private POILogger logger = POILogFactory.getLogger(this.getClass()); - - - /* =============================================================== - * Setup Code - * =============================================================== - */ - - - /** - * Constructs a Powerpoint document from the underlying - * HSLFSlideShow object. Finds the model stuff from this - * - * @param hslfSlideShow the HSLFSlideShow to base on - */ - public SlideShow(HSLFSlideShow hslfSlideShow) { + // Pointers to the most recent versions of the core records + // (Document, Notes, Slide etc) + private Record[] _mostRecentCoreRecords; + // Lookup between the PersitPtr "sheet" IDs, and the position + // in the mostRecentCoreRecords array + private Hashtable _sheetIdToCoreRecordsLookup; + + // Records that are interesting + private Document _documentRecord; + + // Friendly objects for people to deal with + private SlideMaster[] _masters; + private TitleMaster[] _titleMasters; + private Slide[] _slides; + private Notes[] _notes; + private FontCollection _fonts; + + // For logging + private POILogger logger = POILogFactory.getLogger(this.getClass()); + + + /* =============================================================== + * Setup Code + * =============================================================== + */ + + + /** + * Constructs a Powerpoint document from the underlying + * HSLFSlideShow object. Finds the model stuff from this + * + * @param hslfSlideShow the HSLFSlideShow to base on + */ + public SlideShow(HSLFSlideShow hslfSlideShow) { // Get useful things from our base slideshow - _hslfSlideShow = hslfSlideShow; - _records = _hslfSlideShow.getRecords(); + _hslfSlideShow = hslfSlideShow; + _records = _hslfSlideShow.getRecords(); - // Handle Parent-aware Reocrds - for(int i=0; i<_records.length; i++) { - handleParentAwareRecords(_records[i]); - } - - // Find the versions of the core records we'll want to use - findMostRecentCoreRecords(); - - // Build up the model level Slides and Notes - buildSlidesAndNotes(); - } - - /** - * Constructs a new, empty, Powerpoint document. - */ - public SlideShow() { - this(HSLFSlideShow.create()); - } - - /** - * Constructs a Powerpoint document from an input stream. - */ - public SlideShow(InputStream inputStream) throws IOException { - this(new HSLFSlideShow(inputStream)); - } - - /** - * Find the records that are parent-aware, and tell them - * who their parent is - */ - private void handleParentAwareRecords(Record baseRecord) { - // Only need to do something if this is a container record - if(baseRecord instanceof RecordContainer) { - RecordContainer br = (RecordContainer)baseRecord; - Record[] childRecords = br.getChildRecords(); - - // Loop over child records, looking for interesting ones - for(int i=0; i _slides.length || newSlideNumber > _slides.length) { - throw new IllegalArgumentException("Old and new slide numbers must not exceed the number of slides (" + _slides.length + ")"); + if (oldSlideNumber > _slides.length || newSlideNumber > _slides.length) { + throw new IllegalArgumentException( + "Old and new slide numbers must not exceed the number of slides (" + + _slides.length + ")"); + } + + // The order of slides is defined by the order of slide atom sets in the + // SlideListWithText container. + SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); + SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); + + SlideAtomsSet tmp = sas[oldSlideNumber - 1]; + sas[oldSlideNumber - 1] = sas[newSlideNumber - 1]; + sas[newSlideNumber - 1] = tmp; + + ArrayList lst = new ArrayList(); + for (int i = 0; i < sas.length; i++) { + lst.add(sas[i].getSlidePersistAtom()); + Record[] r = sas[i].getSlideRecords(); + for (int j = 0; j < r.length; j++) { + lst.add(r[j]); + } + _slides[i].setSlideNumber(i + 1); + } + Record[] r = (Record[]) lst.toArray(new Record[lst.size()]); + slwt.setChildRecord(r); + } + + /** + * Removes the slide at the given index (0-based). + *

+ * Shifts any subsequent slides to the left (subtracts one from their slide + * numbers). + *

+ * + * @param index + * the index of the slide to remove (0-based) + * @return the slide that was removed from the slide show. + */ + public Slide removeSlide(int index) { + int lastSlideIdx = _slides.length - 1; + if (index < 0 || index > lastSlideIdx) { + throw new IllegalArgumentException("Slide index (" + index + ") is out of range (0.." + + lastSlideIdx + ")"); + } + + SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); + SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); + + Slide removedSlide = null; + ArrayList records = new ArrayList(); + ArrayList sa = new ArrayList(); + ArrayList sl = new ArrayList(); + + ArrayList nt = new ArrayList(); + for (Notes notes : getNotes()) + nt.add(notes); + + for (int i = 0, num = 0; i < _slides.length; i++) { + if (i != index) { + sl.add(_slides[i]); + sa.add(sas[i]); + _slides[i].setSlideNumber(num++); + records.add(sas[i].getSlidePersistAtom()); + records.addAll(Arrays.asList(sas[i].getSlideRecords())); + } else { + removedSlide = _slides[i]; + nt.remove(_slides[i].getNotesSheet()); + } + } + if (sa.size() == 0) { + _documentRecord.removeSlideListWithText(slwt); + } else { + slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()])); + slwt.setChildRecord(records.toArray(new Record[records.size()])); } + _slides = sl.toArray(new Slide[sl.size()]); - // The order of slides is defined by the order of slide atom sets in the SlideListWithText container. - SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); - SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); - - SlideAtomsSet tmp = sas[oldSlideNumber-1]; - sas[oldSlideNumber-1] = sas[newSlideNumber-1]; - sas[newSlideNumber-1] = tmp; - - ArrayList lst = new ArrayList(); - for (int i = 0; i < sas.length; i++) { - lst.add(sas[i].getSlidePersistAtom()); - Record[] r = sas[i].getSlideRecords(); - for (int j = 0; j < r.length; j++) { - lst.add(r[j]); - } - _slides[i].setSlideNumber(i+1); - } - Record[] r = (Record[])lst.toArray(new Record[lst.size()]); - slwt.setChildRecord(r); - } - - /** - * Removes the slide at the given index (0-based). - *

Shifts any subsequent slides to the left (subtracts one from their slide numbers).

- * - * @param index the index of the slide to remove (0-based) - * @return the slide that was removed from the slide show. - */ - public Slide removeSlide(int index) { - int lastSlideIdx = _slides.length - 1; - if(index < 0 || index > lastSlideIdx) { - throw new IllegalArgumentException("Slide index (" - + index +") is out of range (0.." + lastSlideIdx + ")"); - } - - SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); - SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); - - Slide removedSlide = null; - ArrayList records = new ArrayList(); - ArrayList sa = new ArrayList(); - ArrayList sl = new ArrayList(); - - ArrayList nt = new ArrayList(); - for(Notes notes : getNotes()) nt.add(notes); - - for (int i = 0, num = 0; i < _slides.length; i++){ - if(i != index) { - sl.add(_slides[i]); - sa.add(sas[i]); - _slides[i].setSlideNumber(num++); - records.add(sas[i].getSlidePersistAtom()); - records.addAll(Arrays.asList(sas[i].getSlideRecords())); - } else { - removedSlide = _slides[i]; - nt.remove(_slides[i].getNotesSheet()); - } - } - if(sa.size() == 0){ - _documentRecord.removeSlideListWithText(slwt); - } else { - slwt.setSlideAtomsSets( sa.toArray(new SlideAtomsSet[sa.size()]) ); - slwt.setChildRecord(records.toArray(new Record[records.size()])); - } - _slides = sl.toArray(new Slide[sl.size()]); - - //if the removed slide had notes - remove references to them too - - if(removedSlide != null){ - int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID(); - if(notesId != 0){ - SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText(); - records = new ArrayList(); - ArrayList na = new ArrayList(); - for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()){ - if(ns.getSlidePersistAtom().getSlideIdentifier() != notesId) { - na.add(ns); - records.add(ns.getSlidePersistAtom()); - if(ns.getSlideRecords() != null) records.addAll(Arrays.asList(ns.getSlideRecords())); - } - } - if(na.size() == 0){ - _documentRecord.removeSlideListWithText(nslwt); - } else { - nslwt.setSlideAtomsSets( na.toArray(new SlideAtomsSet[na.size()]) ); - nslwt.setChildRecord(records.toArray(new Record[records.size()])); - } - - } - } - _notes = nt.toArray(new Notes[nt.size()]); + // if the removed slide had notes - remove references to them too - return removedSlide; - } + if (removedSlide != null) { + int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID(); + if (notesId != 0) { + SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText(); + records = new ArrayList(); + ArrayList na = new ArrayList(); + for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) { + if (ns.getSlidePersistAtom().getSlideIdentifier() != notesId) { + na.add(ns); + records.add(ns.getSlidePersistAtom()); + if (ns.getSlideRecords() != null) + records.addAll(Arrays.asList(ns.getSlideRecords())); + } + } + if (na.size() == 0) { + _documentRecord.removeSlideListWithText(nslwt); + } else { + nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()])); + nslwt.setChildRecord(records.toArray(new Record[records.size()])); + } - /* =============================================================== - * Addition Code + } + } + _notes = nt.toArray(new Notes[nt.size()]); + + return removedSlide; + } + + /* + * =============================================================== + * Addition Code * =============================================================== */ - /** * Create a blank Slide. * - * @return the created Slide + * @return the created Slide */ - public Slide createSlide() { - SlideListWithText slist = null; + public Slide createSlide() { + SlideListWithText slist = null; - // We need to add the records to the SLWT that deals - // with Slides. - // Add it, if it doesn't exist - slist = _documentRecord.getSlideSlideListWithText(); - if(slist == null) { - // Need to add a new one - slist = new SlideListWithText(); - slist.setInstance(SlideListWithText.SLIDES); - _documentRecord.addSlideListWithText(slist); - } - - // Grab the SlidePersistAtom with the highest Slide Number. - // (Will stay as null if no SlidePersistAtom exists yet in - // the slide, or only master slide's ones do) - SlidePersistAtom prev = null; + // We need to add the records to the SLWT that deals + // with Slides. + // Add it, if it doesn't exist + slist = _documentRecord.getSlideSlideListWithText(); + if (slist == null) { + // Need to add a new one + slist = new SlideListWithText(); + slist.setInstance(SlideListWithText.SLIDES); + _documentRecord.addSlideListWithText(slist); + } + + // Grab the SlidePersistAtom with the highest Slide Number. + // (Will stay as null if no SlidePersistAtom exists yet in + // the slide, or only master slide's ones do) + SlidePersistAtom prev = null; SlideAtomsSet[] sas = slist.getSlideAtomsSets(); - for(int j=0; jPicture class. - * @return the index to this picture (1 based). - */ - public int addPicture(byte[] data, int format) throws IOException { - byte[] uid = PictureData.getChecksum(data); - - EscherContainerRecord bstore; - - EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer(); - bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); - if (bstore == null){ - bstore = new EscherContainerRecord(); - bstore.setRecordId( EscherContainerRecord.BSTORE_CONTAINER); - - dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID); - } else { - Iterator iter = bstore.getChildIterator(); - for (int i = 0; iter.hasNext(); i++) { - EscherBSERecord bse = (EscherBSERecord) iter.next(); - if (Arrays.equals(bse.getUid(), uid)){ - return i + 1; - } - } - } - - PictureData pict = PictureData.create(format); - pict.setData(data); - - int offset = _hslfSlideShow.addPicture(pict); - - EscherBSERecord bse = new EscherBSERecord(); - bse.setRecordId(EscherBSERecord.RECORD_ID); - bse.setOptions( (short) ( 0x0002 | ( format << 4 ) ) ); - bse.setSize(pict.getRawData().length + 8); - bse.setUid(uid); - - bse.setBlipTypeMacOS((byte)format); - bse.setBlipTypeWin32((byte)format); - - if (format == Picture.EMF) bse.setBlipTypeMacOS((byte)Picture.PICT); - else if (format == Picture.WMF) bse.setBlipTypeMacOS((byte)Picture.PICT); - else if (format == Picture.PICT) bse.setBlipTypeWin32((byte)Picture.WMF); - - bse.setRef(0); - bse.setOffset(offset); - bse.setRemainingData( new byte[0] ); - - bstore.addChildRecord(bse); - int count = bstore.getChildRecords().size(); - bstore.setOptions((short)( (count << 4) | 0xF )); - - return count; - } - - /** - * Adds a picture to this presentation and returns the associated index. - * - * @param pict the file containing the image to add - * @param format the format of the picture. One of constans defined in the Picture class. - * @return the index to this picture (1 based). - */ - public int addPicture(File pict, int format) throws IOException { - int length = (int)pict.length(); - byte[] data = new byte[length]; - try { - FileInputStream is = new FileInputStream(pict); - is.read(data); - is.close(); - } catch (IOException e){ - throw new HSLFException(e); - } - return addPicture(data, format); - } - - /** - * Add a font in this presentation - * - * @param font the font to add - * @return 0-based index of the font - */ - public int addFont(PPFont font) { - FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); - int idx = fonts.getFontIndex(font.getFontName()); - if(idx == -1){ - idx = fonts.addFont(font.getFontName(), font.getCharSet(), font.getFontFlags(), font.getFontType(), font.getPitchAndFamily()); - } - return idx; - } - - /** - * Get a font by index - * - * @param idx 0-based index of the font - * @return of an instance of PPFont or null if not found - */ - public PPFont getFont(int idx) { - PPFont font = null; - FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); - Record[] ch = fonts.getChildRecords(); - for (int i = 0; i < ch.length; i++) { - if(ch[i] instanceof FontEntityAtom) { - FontEntityAtom atom = (FontEntityAtom)ch[i]; - if(atom.getFontIndex() == idx){ - font = new PPFont(atom); - break; - } - } - } - return font; - } - - /** - * get the number of fonts in the presentation - * - * @return number of fonts - */ - public int getNumberOfFonts() { - return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts(); - } - - /** - * Return Header / Footer settings for slides - * - * @return Header / Footer settings for slides - */ - public HeadersFooters getSlideHeadersFooters(){ - //detect if this ppt was saved in Office2007 - String tag = getSlidesMasters()[0].getProgrammableTag(); - boolean ppt2007 = "___PPT12".equals(tag); - - HeadersFootersContainer hdd = null; - Record[] ch = _documentRecord.getChildRecords(); - for (int i = 0; i < ch.length; i++) { - if(ch[i] instanceof HeadersFootersContainer && - ((HeadersFootersContainer)ch[i]).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer){ - hdd = (HeadersFootersContainer)ch[i]; - break; - } - } - boolean newRecord = false; - if(hdd == null) { - hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer); - newRecord = true; - } - return new HeadersFooters(hdd, this, newRecord, ppt2007); - } - - /** - * Return Header / Footer settings for notes - * - * @return Header / Footer settings for notes - */ - public HeadersFooters getNotesHeadersFooters(){ - //detect if this ppt was saved in Office2007 - String tag = getSlidesMasters()[0].getProgrammableTag(); - boolean ppt2007 = "___PPT12".equals(tag); - - HeadersFootersContainer hdd = null; - Record[] ch = _documentRecord.getChildRecords(); - for (int i = 0; i < ch.length; i++) { - if(ch[i] instanceof HeadersFootersContainer && - ((HeadersFootersContainer)ch[i]).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer){ - hdd = (HeadersFootersContainer)ch[i]; - break; - } - } - boolean newRecord = false; - if(hdd == null) { - hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer); - newRecord = true; - } - if(ppt2007 && _notes.length > 0){ - return new HeadersFooters(hdd, _notes[0], newRecord, ppt2007); - } else { - return new HeadersFooters(hdd, this, newRecord, ppt2007); - } - } - - /** - * Add a movie in this presentation - * - * @param path the path or url to the movie - * @return 0-based index of the movie - */ - public int addMovie(String path, int type) { - ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); - if(lst == null){ - lst = new ExObjList(); - _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); - } - - ExObjListAtom objAtom = lst.getExObjListAtom(); - //increment the object ID seed - int objectId = (int)objAtom.getObjectIDSeed() + 1; - objAtom.setObjectIDSeed(objectId); - ExMCIMovie mci; - switch (type){ - case MovieShape.MOVIE_MPEG: - mci = new ExMCIMovie(); - break; - case MovieShape.MOVIE_AVI: - mci = new ExAviMovie(); - break; - default: - throw new IllegalArgumentException("Unsupported Movie: " + type); - } - - lst.appendChildRecord(mci); - ExVideoContainer exVideo = mci.getExVideo(); - exVideo.getExMediaAtom().setObjectId(objectId); - exVideo.getExMediaAtom().setMask(0xE80000); - exVideo.getPathAtom().setText(path); - return objectId; - } - - /** - * Add a control in this presentation - * - * @param name name of the control, e.g. "Shockwave Flash Object" - * @param progId OLE Programmatic Identifier, e.g. "ShockwaveFlash.ShockwaveFlash.9" - * @return 0-based index of the control - */ - public int addControl(String name, String progId) { - ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); - if (lst == null) { - lst = new ExObjList(); - _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); - } - ExObjListAtom objAtom = lst.getExObjListAtom(); - //increment the object ID seed - int objectId = (int) objAtom.getObjectIDSeed() + 1; - objAtom.setObjectIDSeed(objectId); - ExControl ctrl = new ExControl(); - ExOleObjAtom oleObj = ctrl.getExOleObjAtom(); - oleObj.setObjID(objectId); - oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE); - oleObj.setType(ExOleObjAtom.TYPE_CONTROL); - oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT); - - ctrl.setProgId(progId); - ctrl.setMenuName(name); - ctrl.setClipboardName(name); - lst.addChildAfter(ctrl, objAtom); - - return objectId; - } - - /** - * Add a hyperlink to this presentation - * - * @return 0-based index of the hyperlink - */ - public int addHyperlink(Hyperlink link) { - ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); - if (lst == null) { - lst = new ExObjList(); - _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); - } - ExObjListAtom objAtom = lst.getExObjListAtom(); - //increment the object ID seed - int objectId = (int) objAtom.getObjectIDSeed() + 1; - objAtom.setObjectIDSeed(objectId); - - ExHyperlink ctrl = new ExHyperlink(); - ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom(); - obj.setNumber(objectId); - ctrl.setLinkURL(link.getAddress()); - ctrl.setLinkTitle(link.getTitle()); - lst.addChildAfter(ctrl, objAtom); - link.setId(objectId); + slide.setMasterSheet(_masters[0]); + // All done and added + return slide; + } + + /** + * Adds a picture to this presentation and returns the associated index. + * + * @param data + * picture data + * @param format + * the format of the picture. One of constans defined in the + * Picture class. + * @return the index to this picture (1 based). + */ + public int addPicture(byte[] data, int format) throws IOException { + byte[] uid = PictureData.getChecksum(data); + + EscherContainerRecord bstore; + + EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer(); + bstore = (EscherContainerRecord) Shape.getEscherChild(dggContainer, + EscherContainerRecord.BSTORE_CONTAINER); + if (bstore == null) { + bstore = new EscherContainerRecord(); + bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER); + + dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID); + } else { + Iterator iter = bstore.getChildIterator(); + for (int i = 0; iter.hasNext(); i++) { + EscherBSERecord bse = (EscherBSERecord) iter.next(); + if (Arrays.equals(bse.getUid(), uid)) { + return i + 1; + } + } + } + + PictureData pict = PictureData.create(format); + pict.setData(data); + + int offset = _hslfSlideShow.addPicture(pict); + + EscherBSERecord bse = new EscherBSERecord(); + bse.setRecordId(EscherBSERecord.RECORD_ID); + bse.setOptions((short) (0x0002 | (format << 4))); + bse.setSize(pict.getRawData().length + 8); + bse.setUid(uid); + + bse.setBlipTypeMacOS((byte) format); + bse.setBlipTypeWin32((byte) format); + + if (format == Picture.EMF) + bse.setBlipTypeMacOS((byte) Picture.PICT); + else if (format == Picture.WMF) + bse.setBlipTypeMacOS((byte) Picture.PICT); + else if (format == Picture.PICT) + bse.setBlipTypeWin32((byte) Picture.WMF); + + bse.setRef(0); + bse.setOffset(offset); + bse.setRemainingData(new byte[0]); + + bstore.addChildRecord(bse); + int count = bstore.getChildRecords().size(); + bstore.setOptions((short) ((count << 4) | 0xF)); + + return count; + } + + /** + * Adds a picture to this presentation and returns the associated index. + * + * @param pict + * the file containing the image to add + * @param format + * the format of the picture. One of constans defined in the + * Picture class. + * @return the index to this picture (1 based). + */ + public int addPicture(File pict, int format) throws IOException { + int length = (int) pict.length(); + byte[] data = new byte[length]; + try { + FileInputStream is = new FileInputStream(pict); + is.read(data); + is.close(); + } catch (IOException e) { + throw new HSLFException(e); + } + return addPicture(data, format); + } + + /** + * Add a font in this presentation + * + * @param font + * the font to add + * @return 0-based index of the font + */ + public int addFont(PPFont font) { + FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); + int idx = fonts.getFontIndex(font.getFontName()); + if (idx == -1) { + idx = fonts.addFont(font.getFontName(), font.getCharSet(), font.getFontFlags(), font + .getFontType(), font.getPitchAndFamily()); + } + return idx; + } + + /** + * Get a font by index + * + * @param idx + * 0-based index of the font + * @return of an instance of PPFont or null if not + * found + */ + public PPFont getFont(int idx) { + PPFont font = null; + FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); + Record[] ch = fonts.getChildRecords(); + for (int i = 0; i < ch.length; i++) { + if (ch[i] instanceof FontEntityAtom) { + FontEntityAtom atom = (FontEntityAtom) ch[i]; + if (atom.getFontIndex() == idx) { + font = new PPFont(atom); + break; + } + } + } + return font; + } + + /** + * get the number of fonts in the presentation + * + * @return number of fonts + */ + public int getNumberOfFonts() { + return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts(); + } + + /** + * Return Header / Footer settings for slides + * + * @return Header / Footer settings for slides + */ + public HeadersFooters getSlideHeadersFooters() { + // detect if this ppt was saved in Office2007 + String tag = getSlidesMasters()[0].getProgrammableTag(); + boolean ppt2007 = "___PPT12".equals(tag); + + HeadersFootersContainer hdd = null; + Record[] ch = _documentRecord.getChildRecords(); + for (int i = 0; i < ch.length; i++) { + if (ch[i] instanceof HeadersFootersContainer + && ((HeadersFootersContainer) ch[i]).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) { + hdd = (HeadersFootersContainer) ch[i]; + break; + } + } + boolean newRecord = false; + if (hdd == null) { + hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer); + newRecord = true; + } + return new HeadersFooters(hdd, this, newRecord, ppt2007); + } + + /** + * Return Header / Footer settings for notes + * + * @return Header / Footer settings for notes + */ + public HeadersFooters getNotesHeadersFooters() { + // detect if this ppt was saved in Office2007 + String tag = getSlidesMasters()[0].getProgrammableTag(); + boolean ppt2007 = "___PPT12".equals(tag); + + HeadersFootersContainer hdd = null; + Record[] ch = _documentRecord.getChildRecords(); + for (int i = 0; i < ch.length; i++) { + if (ch[i] instanceof HeadersFootersContainer + && ((HeadersFootersContainer) ch[i]).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) { + hdd = (HeadersFootersContainer) ch[i]; + break; + } + } + boolean newRecord = false; + if (hdd == null) { + hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer); + newRecord = true; + } + if (ppt2007 && _notes.length > 0) { + return new HeadersFooters(hdd, _notes[0], newRecord, ppt2007); + } else { + return new HeadersFooters(hdd, this, newRecord, ppt2007); + } + } - return objectId; - } + /** + * Add a movie in this presentation + * + * @param path + * the path or url to the movie + * @return 0-based index of the movie + */ + public int addMovie(String path, int type) { + ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); + if (lst == null) { + lst = new ExObjList(); + _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); + } + + ExObjListAtom objAtom = lst.getExObjListAtom(); + // increment the object ID seed + int objectId = (int) objAtom.getObjectIDSeed() + 1; + objAtom.setObjectIDSeed(objectId); + ExMCIMovie mci; + switch (type) { + case MovieShape.MOVIE_MPEG: + mci = new ExMCIMovie(); + break; + case MovieShape.MOVIE_AVI: + mci = new ExAviMovie(); + break; + default: + throw new IllegalArgumentException("Unsupported Movie: " + type); + } + + lst.appendChildRecord(mci); + ExVideoContainer exVideo = mci.getExVideo(); + exVideo.getExMediaAtom().setObjectId(objectId); + exVideo.getExMediaAtom().setMask(0xE80000); + exVideo.getPathAtom().setText(path); + return objectId; + } + + /** + * Add a control in this presentation + * + * @param name + * name of the control, e.g. "Shockwave Flash Object" + * @param progId + * OLE Programmatic Identifier, e.g. + * "ShockwaveFlash.ShockwaveFlash.9" + * @return 0-based index of the control + */ + public int addControl(String name, String progId) { + ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); + if (lst == null) { + lst = new ExObjList(); + _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); + } + ExObjListAtom objAtom = lst.getExObjListAtom(); + // increment the object ID seed + int objectId = (int) objAtom.getObjectIDSeed() + 1; + objAtom.setObjectIDSeed(objectId); + ExControl ctrl = new ExControl(); + ExOleObjAtom oleObj = ctrl.getExOleObjAtom(); + oleObj.setObjID(objectId); + oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE); + oleObj.setType(ExOleObjAtom.TYPE_CONTROL); + oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT); + + ctrl.setProgId(progId); + ctrl.setMenuName(name); + ctrl.setClipboardName(name); + lst.addChildAfter(ctrl, objAtom); + + return objectId; + } + + /** + * Add a hyperlink to this presentation + * + * @return 0-based index of the hyperlink + */ + public int addHyperlink(Hyperlink link) { + ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); + if (lst == null) { + lst = new ExObjList(); + _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); + } + ExObjListAtom objAtom = lst.getExObjListAtom(); + // increment the object ID seed + int objectId = (int) objAtom.getObjectIDSeed() + 1; + objAtom.setObjectIDSeed(objectId); + + ExHyperlink ctrl = new ExHyperlink(); + ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom(); + obj.setNumber(objectId); + ctrl.setLinkURL(link.getAddress()); + ctrl.setLinkTitle(link.getTitle()); + lst.addChildAfter(ctrl, objAtom); + link.setId(objectId); + + return objectId; + } } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java Tue Aug 18 02:41:45 2009 @@ -17,7 +17,6 @@ package org.apache.poi.hwpf.model; -import org.apache.poi.util.LittleEndian; import org.apache.poi.hwpf.model.types.DOPAbstractType; /** @@ -25,13 +24,10 @@ * * @author Ryan Ackley */ +public final class DocumentProperties extends DOPAbstractType { -public final class DocumentProperties extends DOPAbstractType -{ - - public DocumentProperties(byte[] tableStream, int offset) - { - super.fillFields(tableStream, offset); - } + public DocumentProperties(byte[] tableStream, int offset) { + super.fillFields(tableStream, offset); + } } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java Tue Aug 18 02:41:45 2009 @@ -17,7 +17,6 @@ package org.apache.poi.hwpf.model; -import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.LittleEndian; import java.util.ArrayList; @@ -40,8 +39,7 @@ * * @author Ryan Ackley */ -public final class PAPFormattedDiskPage extends FormattedDiskPage -{ +public final class PAPFormattedDiskPage extends FormattedDiskPage { private static final int BX_SIZE = 13; private static final int FC_SIZE = 4; Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java Tue Aug 18 02:41:45 2009 @@ -17,7 +17,6 @@ package org.apache.poi.hwpf.model; -import java.util.*; import java.io.IOException; import org.apache.poi.util.LittleEndian; @@ -35,9 +34,7 @@ * * @author Ryan Ackley */ - -public final class StyleSheet implements HDFType -{ +public final class StyleSheet implements HDFType { public static final int NIL_STYLE = 4095; private static final int PAP_TYPE = 1; Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Tue Aug 18 02:41:45 2009 @@ -17,254 +17,229 @@ package org.apache.poi.hwpf.model; - import org.apache.poi.hwpf.model.io.HWPFOutputStream; import org.apache.poi.poifs.common.POIFSConstants; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; /** - * The piece table for matching up character positions - * to bits of text. - * This mostly works in bytes, but the TextPieces - * themselves work in characters. This does the icky - * convertion. + * The piece table for matching up character positions to bits of text. This + * mostly works in bytes, but the TextPieces themselves work in characters. This + * does the icky convertion. + * * @author Ryan Ackley */ -public final class TextPieceTable implements CharIndexTranslator -{ - protected ArrayList _textPieces = new ArrayList(); - //int _multiple; - int _cpMin; - - public TextPieceTable() { - } - - public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, - int size, int fcMin) - throws UnsupportedEncodingException - { - // get our plex of PieceDescriptors - PlexOfCps pieceTable = new PlexOfCps(tableStream, offset, size, PieceDescriptor.getSizeInBytes()); - - int length = pieceTable.length(); - PieceDescriptor[] pieces = new PieceDescriptor[length]; - - // iterate through piece descriptors raw bytes and create - // PieceDescriptor objects - for (int x = 0; x < length; x++) - { - GenericPropertyNode node = pieceTable.getProperty(x); - pieces[x] = new PieceDescriptor(node.getBytes(), 0); - } - - - // Figure out the cp of the earliest text piece - // Note that text pieces don't have to be stored in order! - _cpMin = pieces[0].getFilePosition() - fcMin; - for (int x = 0; x < pieces.length; x++) { - int start = pieces[x].getFilePosition() - fcMin; - if(start < _cpMin) { - _cpMin = start; - } - } - - - // using the PieceDescriptors, build our list of TextPieces. - for (int x = 0; x < pieces.length; x++) - { - int start = pieces[x].getFilePosition(); - PropertyNode node = pieceTable.getProperty(x); - - // Grab the start and end, which are in characters - int nodeStartChars = node.getStart(); - int nodeEndChars = node.getEnd(); - - // What's the relationship between bytes and characters? - boolean unicode = pieces[x].isUnicode(); - int multiple = 1; - if (unicode) { - multiple = 2; - } - - // Figure out the length, in bytes and chars - int textSizeChars = (nodeEndChars - nodeStartChars); - int textSizeBytes = textSizeChars * multiple; - - // Grab the data that makes up the piece - byte[] buf = new byte[textSizeBytes]; - System.arraycopy(documentStream, start, buf, 0, textSizeBytes); - - // And now build the piece - _textPieces.add(new TextPiece(nodeStartChars, nodeEndChars, buf, pieces[x], node.getStart())); - } - - // In the interest of our sanity, now sort the text pieces - // into order, if they're not already - TextPiece[] tp = (TextPiece[]) - _textPieces.toArray(new TextPiece[_textPieces.size()]); - Arrays.sort(tp); - for(int i=0; i= cp) { - return tp.isUnicode(); - } - // Otherwise keep track for the last one - lastWas = tp.isUnicode(); - } - - // If they ask off the end, just go with the last one... - return lastWas; - } - - public boolean isUnicodeAtByteOffset(int bytePos) { - boolean lastWas = false; - - - Iterator it = _textPieces.iterator(); - while(it.hasNext()) { - TextPiece tp = (TextPiece)it.next(); - int curByte = tp.getPieceDescriptor().getFilePosition(); - int pieceEnd = curByte + tp.bytesLength(); - - // If the text piece covers the character, all good - if(curByte <= bytePos && pieceEnd > bytePos) { - return tp.isUnicode(); - } - // Otherwise keep track for the last one - lastWas = tp.isUnicode(); - // Move along - curByte = pieceEnd; - } - - // If they ask off the end, just go with the last one... - return lastWas; - } - - public byte[] writeTo(HWPFOutputStream docStream) - throws IOException - { - - PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes()); - //int fcMin = docStream.getOffset(); - - int size = _textPieces.size(); - for (int x = 0; x < size; x++) - { - TextPiece next = (TextPiece)_textPieces.get(x); - PieceDescriptor pd = next.getPieceDescriptor(); - - int offset = docStream.getOffset(); - int mod = (offset % POIFSConstants.BIG_BLOCK_SIZE); - if (mod != 0) - { - mod = POIFSConstants.BIG_BLOCK_SIZE - mod; - byte[] buf = new byte[mod]; - docStream.write(buf); - } - - - // set the text piece position to the current docStream offset. - pd.setFilePosition(docStream.getOffset()); - - // write the text to the docstream and save the piece descriptor to the - // plex which will be written later to the tableStream. - docStream.write(next.getRawBytes()); - - // The TextPiece is already in characters, which - // makes our life much easier - int nodeStart = next.getStart(); - int nodeEnd = next.getEnd(); - textPlex.addProperty(new GenericPropertyNode(nodeStart, nodeEnd, - pd.toByteArray())); - } - - return textPlex.toByteArray(); - - } - - /** - * Adjust all the text piece after inserting - * some text into one of them - * @param listIndex The TextPiece that had characters inserted into - * @param length The number of characters inserted - */ - public int adjustForInsert(int listIndex, int length) { - int size = _textPieces.size(); - - TextPiece tp = (TextPiece)_textPieces.get(listIndex); - - // Update with the new end - tp.setEnd(tp.getEnd() + length); - - // Now change all subsequent ones - for (int x = listIndex + 1; x < size; x++) - { - tp = (TextPiece)_textPieces.get(x); - tp.setStart(tp.getStart() + length); - tp.setEnd(tp.getEnd() + length); - } - - // All done - return length; - } - - - public boolean equals(Object o) - { - TextPieceTable tpt = (TextPieceTable)o; - - int size = tpt._textPieces.size(); - if (size == _textPieces.size()) - { - for (int x = 0; x < size; x++) - { - if (!tpt._textPieces.get(x).equals(_textPieces.get(x))) - { - return false; - } - } - return true; - } - return false; - } - /* (non-Javadoc) - * @see org.apache.poi.hwpf.model.CharIndexTranslator#getLengthInChars(int) +public final class TextPieceTable implements CharIndexTranslator { + protected ArrayList _textPieces = new ArrayList(); + // int _multiple; + int _cpMin; + + public TextPieceTable() { + } + + public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin) { + // get our plex of PieceDescriptors + PlexOfCps pieceTable = new PlexOfCps(tableStream, offset, size, PieceDescriptor + .getSizeInBytes()); + + int length = pieceTable.length(); + PieceDescriptor[] pieces = new PieceDescriptor[length]; + + // iterate through piece descriptors raw bytes and create + // PieceDescriptor objects + for (int x = 0; x < length; x++) { + GenericPropertyNode node = pieceTable.getProperty(x); + pieces[x] = new PieceDescriptor(node.getBytes(), 0); + } + + // Figure out the cp of the earliest text piece + // Note that text pieces don't have to be stored in order! + _cpMin = pieces[0].getFilePosition() - fcMin; + for (int x = 0; x < pieces.length; x++) { + int start = pieces[x].getFilePosition() - fcMin; + if (start < _cpMin) { + _cpMin = start; + } + } + + // using the PieceDescriptors, build our list of TextPieces. + for (int x = 0; x < pieces.length; x++) { + int start = pieces[x].getFilePosition(); + PropertyNode node = pieceTable.getProperty(x); + + // Grab the start and end, which are in characters + int nodeStartChars = node.getStart(); + int nodeEndChars = node.getEnd(); + + // What's the relationship between bytes and characters? + boolean unicode = pieces[x].isUnicode(); + int multiple = 1; + if (unicode) { + multiple = 2; + } + + // Figure out the length, in bytes and chars + int textSizeChars = (nodeEndChars - nodeStartChars); + int textSizeBytes = textSizeChars * multiple; + + // Grab the data that makes up the piece + byte[] buf = new byte[textSizeBytes]; + System.arraycopy(documentStream, start, buf, 0, textSizeBytes); + + // And now build the piece + _textPieces.add(new TextPiece(nodeStartChars, nodeEndChars, buf, pieces[x], node + .getStart())); + } + + // In the interest of our sanity, now sort the text pieces + // into order, if they're not already + TextPiece[] tp = (TextPiece[]) _textPieces.toArray(new TextPiece[_textPieces.size()]); + Arrays.sort(tp); + for (int i = 0; i < tp.length; i++) { + _textPieces.set(i, tp[i]); + } + } + + public int getCpMin() { + return _cpMin; + } + + public List getTextPieces() { + return _textPieces; + } + + /** + * Is the text at the given Character offset unicode, or plain old ascii? In + * a very evil fashion, you have to actually know this to make sense of + * character and paragraph properties :( + * + * @param cp + * The character offset to check about + */ + public boolean isUnicodeAtCharOffset(int cp) { + boolean lastWas = false; + + Iterator it = _textPieces.iterator(); + while (it.hasNext()) { + TextPiece tp = (TextPiece) it.next(); + // If the text piece covers the character, all good + if (tp.getStart() <= cp && tp.getEnd() >= cp) { + return tp.isUnicode(); + } + // Otherwise keep track for the last one + lastWas = tp.isUnicode(); + } + + // If they ask off the end, just go with the last one... + return lastWas; + } + + public boolean isUnicodeAtByteOffset(int bytePos) { + boolean lastWas = false; + + Iterator it = _textPieces.iterator(); + while (it.hasNext()) { + TextPiece tp = (TextPiece) it.next(); + int curByte = tp.getPieceDescriptor().getFilePosition(); + int pieceEnd = curByte + tp.bytesLength(); + + // If the text piece covers the character, all good + if (curByte <= bytePos && pieceEnd > bytePos) { + return tp.isUnicode(); + } + // Otherwise keep track for the last one + lastWas = tp.isUnicode(); + // Move along + curByte = pieceEnd; + } + + // If they ask off the end, just go with the last one... + return lastWas; + } + + public byte[] writeTo(HWPFOutputStream docStream) throws IOException { + + PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes()); + // int fcMin = docStream.getOffset(); + + int size = _textPieces.size(); + for (int x = 0; x < size; x++) { + TextPiece next = (TextPiece) _textPieces.get(x); + PieceDescriptor pd = next.getPieceDescriptor(); + + int offset = docStream.getOffset(); + int mod = (offset % POIFSConstants.BIG_BLOCK_SIZE); + if (mod != 0) { + mod = POIFSConstants.BIG_BLOCK_SIZE - mod; + byte[] buf = new byte[mod]; + docStream.write(buf); + } + + // set the text piece position to the current docStream offset. + pd.setFilePosition(docStream.getOffset()); + + // write the text to the docstream and save the piece descriptor to + // the + // plex which will be written later to the tableStream. + docStream.write(next.getRawBytes()); + + // The TextPiece is already in characters, which + // makes our life much easier + int nodeStart = next.getStart(); + int nodeEnd = next.getEnd(); + textPlex.addProperty(new GenericPropertyNode(nodeStart, nodeEnd, pd.toByteArray())); + } + + return textPlex.toByteArray(); + + } + + /** + * Adjust all the text piece after inserting some text into one of them + * + * @param listIndex + * The TextPiece that had characters inserted into + * @param length + * The number of characters inserted */ + public int adjustForInsert(int listIndex, int length) { + int size = _textPieces.size(); + + TextPiece tp = (TextPiece) _textPieces.get(listIndex); + + // Update with the new end + tp.setEnd(tp.getEnd() + length); + + // Now change all subsequent ones + for (int x = listIndex + 1; x < size; x++) { + tp = (TextPiece) _textPieces.get(x); + tp.setStart(tp.getStart() + length); + tp.setEnd(tp.getEnd() + length); + } + + // All done + return length; + } + + public boolean equals(Object o) { + TextPieceTable tpt = (TextPieceTable) o; + + int size = tpt._textPieces.size(); + if (size == _textPieces.size()) { + for (int x = 0; x < size; x++) { + if (!tpt._textPieces.get(x).equals(_textPieces.get(x))) { + return false; + } + } + return true; + } + return false; + } + public int getCharIndex(int bytePos) { int charCount = 0; @@ -272,15 +247,14 @@ while (it.hasNext()) { TextPiece tp = (TextPiece) it.next(); int pieceStart = tp.getPieceDescriptor().getFilePosition(); - if(pieceStart >= bytePos) { + if (pieceStart >= bytePos) { break; } - + int bytesLength = tp.bytesLength(); int pieceEnd = pieceStart + bytesLength; - int toAdd = bytePos > pieceEnd ? bytesLength : bytesLength - - (pieceEnd - bytePos); + int toAdd = bytePos > pieceEnd ? bytesLength : bytesLength - (pieceEnd - bytePos); if (tp.isUnicode()) { charCount += toAdd / 2; @@ -291,5 +265,5 @@ return charCount; } - + } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java Tue Aug 18 02:41:45 2009 @@ -19,13 +19,12 @@ +import org.apache.poi.hdf.model.hdftypes.HDFType; +import org.apache.poi.hwpf.usermodel.BorderCode; +import org.apache.poi.hwpf.usermodel.DateAndTime; +import org.apache.poi.hwpf.usermodel.ShadingDescriptor; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.StringUtil; -import org.apache.poi.util.HexDump; -import org.apache.poi.hdf.model.hdftypes.HDFType; -import org.apache.poi.hwpf.usermodel.*; /** * Character Properties. Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java?rev=805262&r1=805261&r2=805262&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java Tue Aug 18 02:41:45 2009 @@ -18,25 +18,19 @@ package org.apache.poi.hwpf.model.types; - +import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.StringUtil; -import org.apache.poi.util.HexDump; -import org.apache.poi.hdf.model.hdftypes.HDFType; -import org.apache.poi.hwpf.usermodel.*; /** * Document Properties. * NOTE: This source is automatically generated please do not modify this file. Either subclass or * remove the record in src/records/definitions. - + * * @author S. Ryan Ackley */ -public abstract class DOPAbstractType - implements HDFType -{ +public abstract class DOPAbstractType implements HDFType { protected byte field_1_formatFlags; private static BitField fFacingPages = BitFieldFactory.getInstance(0x01); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org