diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java index 48acd57e57..6e08df7b3c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java @@ -135,6 +135,9 @@ public class TextRun throw new IllegalArgumentException("Supplied RichTextRun wasn't from this TextRun"); } + // Ensure a StyleTextPropAtom is present, adding if required + ensureStyleAtomPresent(); + // Update the text length for its Paragraph and Character stylings LinkedList pStyles = _styleAtom.getParagraphStyles(); LinkedList cStyles = _styleAtom.getCharacterStyles(); @@ -191,6 +194,27 @@ public class TextRun _rtRuns[0] = new RichTextRun(this,0,s.length()); } + /** + * Ensure a StyleTextPropAtom is present for this run, + * by adding if required + */ + private synchronized void ensureStyleAtomPresent() { + if(_styleAtom != null) { + // All there + return; + } + + // Create a new one + _styleAtom = new StyleTextPropAtom(0); + + // Use the TextHeader atom to get at the parent + RecordContainer runAtomsParent = _headerAtom.getParentRecord(); + + // Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom + Record addAfter = _byteAtom; + if(_byteAtom == null) { addAfter = _charAtom; } + runAtomsParent.addChildAfter(_styleAtom, addAfter); + } // Accesser methods follow diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java index 3f2674bf8a..74495d03b4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java @@ -37,7 +37,6 @@ import java.io.ByteArrayOutputStream; public class DummyPositionSensitiveRecordWithChildren extends PositionDependentRecordContainer { - private Record[] _children; private byte[] _header; private long _type; @@ -60,11 +59,6 @@ public class DummyPositionSensitiveRecordWithChildren extends PositionDependentR */ public long getRecordType() { return _type; } - /** - * Return any children - */ - public Record[] getChildRecords() { return _children; } - /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java index 5a30fae6f4..eb7478fde5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java @@ -33,7 +33,6 @@ import java.io.ByteArrayOutputStream; public class DummyRecordWithChildren extends RecordContainer { - private Record[] _children; private byte[] _header; private long _type; @@ -55,11 +54,6 @@ public class DummyRecordWithChildren extends RecordContainer */ public long getRecordType() { return _type; } - /** - * Return any children - */ - public Record[] getChildRecords() { return _children; } - /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java index 04d388d255..c07291f21e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java @@ -37,7 +37,6 @@ import java.io.ByteArrayOutputStream; public class EscherTextboxWrapper extends RecordContainer { private EscherTextboxRecord _escherRecord; - private Record[] _children; private long _type; /** @@ -63,11 +62,6 @@ public class EscherTextboxWrapper extends RecordContainer */ public long getRecordType() { return _type; } - /** - * Return any children - */ - public Record[] getChildRecords() { return _children; } - /** * Stores the data for the child records back into the Escher layer. * Doesn't actually do the writing out, that's left to the Escher diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java index 97866de1f6..c6ee18e53e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java @@ -30,7 +30,6 @@ import java.util.*; public class FontCollection extends RecordContainer { private List fonts; - private Record[] _children; private byte[] _header; protected FontCollection(byte[] source, int start, int len) { @@ -48,14 +47,13 @@ public class FontCollection extends RecordContainer { } + /** + * Return the type, which is 2005 + */ public long getRecordType() { return RecordTypes.FontCollection.typeID; } - public Record[] getChildRecords() { - return _children; - } - /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java index 3e7c9e7e21..f7506d83b6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java @@ -32,7 +32,6 @@ import java.io.ByteArrayOutputStream; public class Notes extends PositionDependentRecordContainer { - private Record[] _children; private byte[] _header; private static long _type = 1008l; @@ -80,11 +79,6 @@ public class Notes extends PositionDependentRecordContainer */ public long getRecordType() { return _type; } - /** - * Return any children - */ - public Record[] getChildRecords() { return _children; } - /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java index 275e87441e..b3d9dee3fb 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java @@ -34,6 +34,13 @@ import java.io.ByteArrayOutputStream; public abstract class RecordContainer extends Record { + protected Record[] _children; + + /** + * Return any children + */ + public Record[] getChildRecords() { return _children; } + /** * We're not an atom */ @@ -49,6 +56,34 @@ public abstract class RecordContainer extends Record r[r.length-1] = newChild; return r; } + + /** + * Adds the given Child Record after the supplied record + * @param newChild + * @param after + */ + public synchronized void addChildAfter(Record newChild, Record after) { + boolean added = false; + Record[] newChildren = new Record[_children.length+1]; + for(int i=0; i<_children.length; i++) { + int newPos = i; + if(added) { newPos++; } + + newChildren[newPos] = _children[i]; + if(_children[i].equals(after)) { + // Found one to add after + added = true; + newPos++; + newChildren[newPos] = newChild; + } + } + + if(added) { + _children = newChildren; + } else { + throw new IllegalArgumentException("Asked to add a new child after another record, but that record wasn't one of our children!"); + } + } /** * Write out our header, and our children. diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java index 2f29b0e4dd..9717a58c2e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java @@ -32,7 +32,6 @@ import java.io.ByteArrayOutputStream; public class Slide extends PositionDependentRecordContainer { - private Record[] _children; private byte[] _header; private static long _type = 1006l; @@ -80,11 +79,6 @@ public class Slide extends PositionDependentRecordContainer */ public long getRecordType() { return _type; } - /** - * Return any children - */ - public Record[] getChildRecords() { return _children; } - /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index c8ed475517..ca1f88ff24 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -49,7 +49,6 @@ import java.util.Vector; // For now, pretend to be an atom public class SlideListWithText extends RecordContainer { - private Record[] _children; private byte[] _header; private static long _type = 4080; @@ -109,11 +108,6 @@ public class SlideListWithText extends RecordContainer */ public long getRecordType() { return _type; } - /** - * We're pretending to be an atom, so return null - */ - public Record[] getChildRecords() { return _children; } - /** * Write the contents of the record back, so it can be written * to disk