You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/24 23:47:58 UTC
svn commit: r1692593 [12/17] - in /poi:
site/src/documentation/content/xdocs/ trunk/
trunk/src/examples/src/org/apache/poi/hslf/examples/
trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/
trunk/src/examples/src/org/apache/poi/xslf/usermode...
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java Fri Jul 24 21:47:55 2015
@@ -93,8 +93,6 @@ public final class SlideListWithText ext
}
int clen = endPos - i - 1;
- boolean emptySet = false;
- if(clen == 0) { emptySet = true; }
// Create a SlideAtomsSets, not caring if they're empty
//if(emptySet) { continue; }
@@ -149,7 +147,7 @@ public final class SlideListWithText ext
}
public void setInstance(int inst){
- LittleEndian.putShort(_header, (short)((inst << 4) | 0xF));
+ LittleEndian.putShort(_header, 0, (short)((inst << 4) | 0xF));
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java Fri Jul 24 21:47:55 2015
@@ -83,7 +83,7 @@ public final class StyleTextProp9Atom ex
break;
}
}
- this.autoNumberSchemes = (TextPFException9[]) schemes.toArray(new TextPFException9[schemes.size()]);
+ this.autoNumberSchemes = schemes.toArray(new TextPFException9[schemes.size()]);
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Fri Jul 24 21:47:55 2015
@@ -17,19 +17,13 @@
package org.apache.poi.hslf.record;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.LinkedList;
-
-import org.apache.poi.hslf.model.textproperties.AlignmentTextProp;
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.TextProp;
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.hslf.model.textproperties.*;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType;
+import org.apache.poi.util.*;
/**
* A StyleTextPropAtom (type 4001). Holds basic character properties
@@ -51,7 +45,7 @@ import org.apache.poi.util.POILogger;
public final class StyleTextPropAtom extends RecordAtom
{
private byte[] _header;
- private static long _type = 4001l;
+ private static final long _type = RecordTypes.StyleTextPropAtom.typeID;
private byte[] reserved;
private byte[] rawContents; // Holds the contents between write-outs
@@ -68,26 +62,26 @@ public final class StyleTextPropAtom ext
* Characters the paragraph covers, and also contains the TextProps
* that actually define the styling of the paragraph.
*/
- private LinkedList<TextPropCollection> paragraphStyles;
- public LinkedList<TextPropCollection> getParagraphStyles() { return paragraphStyles; }
+ private List<TextPropCollection> paragraphStyles;
+ public List<TextPropCollection> getParagraphStyles() { return paragraphStyles; }
/**
* Updates the link list of TextPropCollections which make up the
* paragraph stylings
*/
- public void setParagraphStyles(LinkedList<TextPropCollection> ps) { paragraphStyles = ps; }
+ public void setParagraphStyles(List<TextPropCollection> ps) { paragraphStyles = ps; }
/**
* The list of all the different character stylings we code for.
* Each entry is a TextPropCollection, which tells you how many
* Characters the character styling covers, and also contains the
* TextProps that actually define the styling of the characters.
*/
- private LinkedList<TextPropCollection> charStyles;
- public LinkedList<TextPropCollection> getCharacterStyles() { return charStyles; }
+ private List<TextPropCollection> charStyles;
+ public List<TextPropCollection> getCharacterStyles() { return charStyles; }
/**
* Updates the link list of TextPropCollections which make up the
* character stylings
*/
- public void setCharacterStyles(LinkedList<TextPropCollection> cs) { charStyles = cs; }
+ public void setCharacterStyles(List<TextPropCollection> cs) { charStyles = cs; }
/**
* Returns how many characters the paragraph's
@@ -109,7 +103,7 @@ public final class StyleTextPropAtom ext
public int getCharacterTextLengthCovered() {
return getCharactersCovered(charStyles);
}
- private int getCharactersCovered(LinkedList<TextPropCollection> styles) {
+ private int getCharactersCovered(List<TextPropCollection> styles) {
int length = 0;
for(TextPropCollection tpc : styles) {
length += tpc.getCharactersCovered();
@@ -117,58 +111,6 @@ public final class StyleTextPropAtom ext
return length;
}
- /** All the different kinds of paragraph properties we might handle */
- public static final TextProp[] paragraphTextPropTypes = new TextProp[] {
- new TextProp(0, 0x1, "hasBullet"),
- new TextProp(0, 0x2, "hasBulletFont"),
- new TextProp(0, 0x4, "hasBulletColor"),
- new TextProp(0, 0x8, "hasBulletSize"),
- new ParagraphFlagsTextProp(),
- new TextProp(2, 0x80, "bullet.char"),
- new TextProp(2, 0x10, "bullet.font"),
- new TextProp(2, 0x40, "bullet.size"),
- new TextProp(4, 0x20, "bullet.color"),
- new AlignmentTextProp(),
- new TextProp(2, 0x100, "text.offset"),
- new TextProp(2, 0x400, "bullet.offset"),
- new TextProp(2, 0x1000, "linespacing"),
- new TextProp(2, 0x2000, "spacebefore"),
- new TextProp(2, 0x4000, "spaceafter"),
- new TextProp(2, 0x8000, "defaultTabSize"),
- new TextProp(2, 0x100000, "tabStops"),
- new TextProp(2, 0x10000, "fontAlign"),
- new TextProp(2, 0xA0000, "wrapFlags"),
- new TextProp(2, 0x200000, "textDirection")
- };
- /** All the different kinds of character properties we might handle */
- public static final TextProp[] characterTextPropTypes = new TextProp[] {
- new TextProp(0, 0x1, "bold"),
- new TextProp(0, 0x2, "italic"),
- new TextProp(0, 0x4, "underline"),
- new TextProp(0, 0x8, "unused1"),
- new TextProp(0, 0x10, "shadow"),
- new TextProp(0, 0x20, "fehint"),
- new TextProp(0, 0x40, "unused2"),
- new TextProp(0, 0x80, "kumi"),
- new TextProp(0, 0x100, "unused3"),
- new TextProp(0, 0x200, "emboss"),
- new TextProp(0, 0x400, "nibble1"),
- new TextProp(0, 0x800, "nibble2"),
- new TextProp(0, 0x1000, "nibble3"),
- new TextProp(0, 0x2000, "nibble4"),
- new TextProp(0, 0x4000, "unused4"),
- new TextProp(0, 0x8000, "unused5"),
- new CharFlagsTextProp(),
- new TextProp(2, 0x10000, "font.index"),
- new TextProp(0, 0x100000, "pp10ext"),
- new TextProp(2, 0x200000, "asian.font.index"),
- new TextProp(2, 0x400000, "ansi.font.index"),
- new TextProp(2, 0x800000, "symbol.font.index"),
- new TextProp(2, 0x20000, "font.size"),
- new TextProp(4, 0x40000, "font.color"),
- new TextProp(2, 0x80000, "superscript")
- };
-
/* *************** record code follows ********************** */
/**
@@ -193,9 +135,9 @@ public final class StyleTextPropAtom ext
System.arraycopy(source,start+8,rawContents,0,rawContents.length);
reserved = new byte[0];
- // Set empty linked lists, ready for when they call setParentTextSize
- paragraphStyles = new LinkedList<TextPropCollection>();
- charStyles = new LinkedList<TextPropCollection>();
+ // Set empty lists, ready for when they call setParentTextSize
+ paragraphStyles = new ArrayList<TextPropCollection>();
+ charStyles = new ArrayList<TextPropCollection>();
}
@@ -213,19 +155,20 @@ public final class StyleTextPropAtom ext
LittleEndian.putInt(_header,4,10);
// Set empty paragraph and character styles
- paragraphStyles = new LinkedList<TextPropCollection>();
- charStyles = new LinkedList<TextPropCollection>();
+ paragraphStyles = new ArrayList<TextPropCollection>();
+ charStyles = new ArrayList<TextPropCollection>();
- TextPropCollection defaultParagraphTextProps =
- new TextPropCollection(parentTextSize, (short)0);
- paragraphStyles.add(defaultParagraphTextProps);
-
- TextPropCollection defaultCharacterTextProps =
- new TextPropCollection(parentTextSize);
- charStyles.add(defaultCharacterTextProps);
+ addParagraphTextPropCollection(parentTextSize);
+ addCharacterTextPropCollection(parentTextSize);
// Set us as now initialised
initialised = true;
+
+ try {
+ updateRawContents();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
@@ -244,10 +187,6 @@ public final class StyleTextPropAtom ext
// on the properties
updateRawContents();
- // Now ensure that the header size is correct
- int newSize = rawContents.length + reserved.length;
- LittleEndian.putInt(_header,4,newSize);
-
// Write out the (new) header
out.write(_header);
@@ -264,9 +203,14 @@ public final class StyleTextPropAtom ext
* contains, so we can go ahead and initialise ourselves.
*/
public void setParentTextSize(int size) {
+ if (initialised) return;
+
int pos = 0;
int textHandled = 0;
+ paragraphStyles.clear();
+ charStyles.clear();
+
// While we have text in need of paragraph stylings, go ahead and
// grok the contents as paragraph formatting data
int prsize = size;
@@ -285,9 +229,9 @@ public final class StyleTextPropAtom ext
pos += 4;
// Now make sense of those properties
- TextPropCollection thisCollection = new TextPropCollection(textLen, indent);
- int plSize = thisCollection.buildTextPropList(
- paraFlags, paragraphTextPropTypes, rawContents, pos);
+ TextPropCollection thisCollection = new TextPropCollection(textLen, TextPropType.paragraph);
+ thisCollection.setIndentLevel(indent);
+ int plSize = thisCollection.buildTextPropList(paraFlags, rawContents, pos);
pos += plSize;
// Save this properties set
@@ -313,18 +257,14 @@ public final class StyleTextPropAtom ext
textHandled += textLen;
pos += 4;
- // There is no 2 byte value
- short no_val = -1;
-
// Grab the 4 byte value that tells us what properties follow
int charFlags = LittleEndian.getInt(rawContents,pos);
pos += 4;
// Now make sense of those properties
// (Assuming we actually have some)
- TextPropCollection thisCollection = new TextPropCollection(textLen, no_val);
- int chSize = thisCollection.buildTextPropList(
- charFlags, characterTextPropTypes, rawContents, pos);
+ TextPropCollection thisCollection = new TextPropCollection(textLen, TextPropType.character);
+ int chSize = thisCollection.buildTextPropList(charFlags, rawContents, pos);
pos += chSize;
// Save this properties set
@@ -362,42 +302,47 @@ public final class StyleTextPropAtom ext
* Updates the cache of the raw contents. Serialised the styles out.
*/
private void updateRawContents() throws IOException {
- if(!initialised) {
- // We haven't groked the styles since creation, so just stick
- // with what we found
- return;
- }
+ if (initialised) {
+ // Only update the style bytes, if the styles have been potentially
+ // changed
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- // First up, we need to serialise the paragraph properties
- for(int i=0; i<paragraphStyles.size(); i++) {
- TextPropCollection tpc = paragraphStyles.get(i);
- tpc.writeOut(baos);
- }
-
- // Now, we do the character ones
- for(int i=0; i<charStyles.size(); i++) {
- TextPropCollection tpc = charStyles.get(i);
- tpc.writeOut(baos);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // First up, we need to serialise the paragraph properties
+ for(TextPropCollection tpc : paragraphStyles) {
+ tpc.writeOut(baos);
+ }
+
+ // Now, we do the character ones
+ for(TextPropCollection tpc : charStyles) {
+ tpc.writeOut(baos);
+ }
+
+ rawContents = baos.toByteArray();
}
-
- rawContents = baos.toByteArray();
+
+ // Now ensure that the header size is correct
+ int newSize = rawContents.length + reserved.length;
+ LittleEndian.putInt(_header,4,newSize);
}
- public void setRawContents(byte[] bytes) {
- rawContents = bytes;
+ /**
+ * Clear styles, so new collections can be added
+ */
+ public void clearStyles() {
+ paragraphStyles.clear();
+ charStyles.clear();
reserved = new byte[0];
- initialised = false;
+ initialised = true;
}
-
+
/**
* Create a new Paragraph TextPropCollection, and add it to the list
* @param charactersCovered The number of characters this TextPropCollection will cover
* @return the new TextPropCollection, which will then be in the list
*/
public TextPropCollection addParagraphTextPropCollection(int charactersCovered) {
- TextPropCollection tpc = new TextPropCollection(charactersCovered, (short)0);
+ TextPropCollection tpc = new TextPropCollection(charactersCovered, TextPropType.paragraph);
paragraphStyles.add(tpc);
return tpc;
}
@@ -407,7 +352,7 @@ public final class StyleTextPropAtom ext
* @return the new TextPropCollection, which will then be in the list
*/
public TextPropCollection addCharacterTextPropCollection(int charactersCovered) {
- TextPropCollection tpc = new TextPropCollection(charactersCovered);
+ TextPropCollection tpc = new TextPropCollection(charactersCovered, TextPropType.character);
charStyles.add(tpc);
return tpc;
}
@@ -429,51 +374,25 @@ public final class StyleTextPropAtom ext
} else {
out.append("Paragraph properties\n");
-
for(TextPropCollection pr : getParagraphStyles()) {
- out.append(" chars covered: " + pr.getCharactersCovered());
- out.append(" special mask flags: 0x" + HexDump.toHex(pr.getSpecialMask()) + "\n");
- for(TextProp p : pr.getTextPropList()) {
- out.append(" " + p.getName() + " = " + p.getValue() );
- out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
- }
-
- out.append(" para bytes that would be written: \n");
-
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- pr.writeOut(baos);
- byte[] b = baos.toByteArray();
- out.append(HexDump.dump(b, 0, 0));
- } catch (Exception e ) {
- e.printStackTrace();
- }
+ out.append(pr);
}
out.append("Character properties\n");
for(TextPropCollection pr : getCharacterStyles()) {
- out.append(" chars covered: " + pr.getCharactersCovered() );
- out.append(" special mask flags: 0x" + HexDump.toHex(pr.getSpecialMask()) + "\n");
- for(TextProp p : pr.getTextPropList()) {
- out.append(" " + p.getName() + " = " + p.getValue() );
- out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
- }
-
- out.append(" char bytes that would be written: \n");
-
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- pr.writeOut(baos);
- byte[] b = baos.toByteArray();
- out.append(HexDump.dump(b, 0, 0));
- } catch (Exception e ) {
- e.printStackTrace();
- }
+ out.append(pr);
}
+
+ out.append("Reserved bytes\n");
+ out.append( HexDump.dump(reserved, 0, 0) );
}
out.append(" original byte stream \n");
- out.append( HexDump.dump(rawContents, 0, 0) );
+
+ byte buf[] = new byte[rawContents.length+reserved.length];
+ System.arraycopy(rawContents, 0, buf, 0, rawContents.length);
+ System.arraycopy(reserved, 0, buf, rawContents.length, reserved.length);
+ out.append( HexDump.dump(buf, 0, 0) );
return out.toString();
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java Fri Jul 24 21:47:55 2015
@@ -35,7 +35,7 @@ import java.io.OutputStream;
public final class TextBytesAtom extends RecordAtom
{
private byte[] _header;
- private static long _type = 4008l;
+ private static long _type = RecordTypes.TextBytesAtom.typeID;
/** The bytes that make up the text */
private byte[] _text;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java Fri Jul 24 21:47:55 2015
@@ -33,7 +33,7 @@ import java.io.OutputStream;
public final class TextCharsAtom extends RecordAtom
{
private byte[] _header;
- private static long _type = 4000l;
+ private static long _type = RecordTypes.TextCharsAtom.typeID;
/** The bytes that make up the text */
private byte[] _text;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java Fri Jul 24 21:47:55 2015
@@ -32,7 +32,7 @@ import java.io.OutputStream;
public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecord
{
private byte[] _header;
- private static long _type = 3999l;
+ private static long _type = RecordTypes.TextHeaderAtom.typeID;
private RecordContainer parentRecord;
public static final int TITLE_TYPE = 0;
@@ -46,9 +46,21 @@ public final class TextHeaderAtom extend
/** The kind of text it is */
private int textType;
+ /** position in the owning SlideListWithText */
+ private int index = -1;
public int getTextType() { return textType; }
public void setTextType(int type) { textType = type; }
+
+ /**
+ * @return 0-based index of the text run in the SLWT container
+ */
+ public int getIndex() { return index; }
+
+ /**
+ * @param id 0-based index of the text run in the SLWT container
+ */
+ public void setIndex(int index) { this.index = index; }
public RecordContainer getParentRecord() { return parentRecord; }
public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java Fri Jul 24 21:47:55 2015
@@ -17,11 +17,12 @@
package org.apache.poi.hslf.record;
-import org.apache.poi.util.LittleEndian;
-
-import java.io.OutputStream;
-import java.io.IOException;
+import java.io.*;
import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
/**
* The special info runs contained in this text.
@@ -30,6 +31,8 @@ import java.util.ArrayList;
* @author Yegor Kozlov
*/
public final class TextSpecInfoAtom extends RecordAtom {
+ private static final long _type = RecordTypes.TextSpecInfoAtom.typeID;
+
/**
* Record header.
*/
@@ -41,6 +44,15 @@ public final class TextSpecInfoAtom exte
private byte[] _data;
/**
+ * Constructs an empty atom, with a default run of size 1
+ */
+ public TextSpecInfoAtom() {
+ _header = new byte[8];
+ LittleEndian.putUInt(_header, 4, _type);
+ reset(1);
+ }
+
+ /**
* Constructs the link related atom record from its
* source data.
*
@@ -48,7 +60,7 @@ public final class TextSpecInfoAtom exte
* @param start the start offset into the byte array.
* @param len the length of the slice in the byte array.
*/
- protected TextSpecInfoAtom(byte[] source, int start, int len) {
+ public TextSpecInfoAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
@@ -62,7 +74,7 @@ public final class TextSpecInfoAtom exte
* Gets the record type.
* @return the record type.
*/
- public long getRecordType() { return RecordTypes.TextSpecInfoAtom.typeID; }
+ public long getRecordType() { return _type; }
/**
* Write the contents of the record back, so it can be written
@@ -90,111 +102,67 @@ public final class TextSpecInfoAtom exte
* @param size the site of parent text
*/
public void reset(int size){
- _data = new byte[10];
- // 01 00 00 00
- LittleEndian.putInt(_data, 0, size);
- // 01 00 00 00
- LittleEndian.putInt(_data, 4, 1); //mask
- // 00 00
- LittleEndian.putShort(_data, 8, (short)0); //langId
+ TextSpecInfoRun sir = new TextSpecInfoRun(size);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ sir.writeOut(bos);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ _data = bos.toByteArray();
// Update the size (header bytes 5-8)
LittleEndian.putInt(_header, 4, _data.length);
}
/**
+ * Adapts the size by enlarging the last {@link TextSpecInfoRun}
+ * or chopping the runs to the given length
+ *
+ * @param size
+ */
+ public void setParentSize(int size) {
+ assert(size > 0);
+ int covered = 0;
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ TextSpecInfoRun runs[] = getTextSpecInfoRuns();
+ assert(runs.length > 0);
+ for (int i=0; i<runs.length && covered < size; i++) {
+ TextSpecInfoRun run = runs[i];
+ if (covered + run.getLength() > size || i == runs.length-1) {
+ run.setLength(size-covered);
+ }
+ covered += run.getLength();
+ try {
+ run.writeOut(bos);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ _data = bos.toByteArray();
+
+ // Update the size (header bytes 5-8)
+ LittleEndian.putInt(_header, 4, _data.length);
+ }
+
+ /**
* Get the number of characters covered by this records
*
* @return the number of characters covered by this records
*/
public int getCharactersCovered(){
int covered = 0;
- TextSpecInfoRun[] runs = getTextSpecInfoRuns();
- for (int i = 0; i < runs.length; i++) covered += runs[i].len;
+ for (TextSpecInfoRun r : getTextSpecInfoRuns()) covered += r.length;
return covered;
}
public TextSpecInfoRun[] getTextSpecInfoRuns(){
- ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
- int pos = 0;
- int[] bits = {1, 0, 2};
- while(pos < _data.length) {
- TextSpecInfoRun run = new TextSpecInfoRun();
- run.len = LittleEndian.getInt(_data, pos); pos += 4;
- run.mask = LittleEndian.getInt(_data, pos); pos += 4;
- for (int i = 0; i < bits.length; i++) {
- if((run.mask & 1 << bits[i]) != 0){
- switch (bits[i]){
- case 0:
- run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;
- break;
- case 1:
- run.langId = LittleEndian.getShort(_data, pos); pos += 2;
- break;
- case 2:
- run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;
- break;
- }
- }
- }
- lst.add(run);
+ LittleEndianByteArrayInputStream bis = new LittleEndianByteArrayInputStream(_data);
+ List<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
+ while (bis.available() > 0) {
+ lst.add(new TextSpecInfoRun(bis));
}
return lst.toArray(new TextSpecInfoRun[lst.size()]);
}
- public static class TextSpecInfoRun {
- //Length of special info run.
- protected int len;
-
- //Special info mask of this run;
- protected int mask;
-
- // info fields as indicated by the mask.
- // -1 means the bit is not set
- protected short spellInfo = -1;
- protected short langId = -1;
- protected short altLangId = -1;
-
- /**
- * Spelling status of this text. See Spell Info table below.
- *
- * <p>Spell Info Types:</p>
- * <li>0 Unchecked
- * <li>1 Previously incorrect, needs rechecking
- * <li>2 Correct
- * <li>3 Incorrect
- *
- * @return Spelling status of this text
- */
- public short getSpellInfo(){
- return spellInfo;
- }
-
- /**
- * Windows LANGID for this text.
- *
- * @return Windows LANGID for this text.
- */
- public short getLangId(){
- return spellInfo;
- }
-
- /**
- * Alternate Windows LANGID of this text;
- * must be a valid non-East Asian LANGID if the text has an East Asian language,
- * otherwise may be an East Asian LANGID or language neutral (zero).
- *
- * @return Alternate Windows LANGID of this text
- */
- public short getAltLangId(){
- return altLangId;
- }
-
- /**
- * @return Length of special info run.
- */
- public int length(){
- return len;
- }
- }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java Fri Jul 24 21:47:55 2015
@@ -19,11 +19,11 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType;
import org.apache.poi.util.LittleEndian;
/**
@@ -52,8 +52,8 @@ public final class TxMasterStyleAtom ext
private static long _type = 4003;
private byte[] _data;
- private TextPropCollection[] prstyles;
- private TextPropCollection[] chstyles;
+ private List<TextPropCollection> paragraphStyles;
+ private List<TextPropCollection> charStyles;
protected TxMasterStyleAtom(byte[] source, int start, int len) {
_header = new byte[8];
@@ -98,8 +98,8 @@ public final class TxMasterStyleAtom ext
*
* @return character styles defined in this record
*/
- public TextPropCollection[] getCharacterStyles(){
- return chstyles;
+ public List<TextPropCollection> getCharacterStyles(){
+ return charStyles;
}
/**
@@ -107,8 +107,8 @@ public final class TxMasterStyleAtom ext
*
* @return paragraph styles defined in this record
*/
- public TextPropCollection[] getParagraphStyles(){
- return prstyles;
+ public List<TextPropCollection> getParagraphStyles(){
+ return paragraphStyles;
}
/**
@@ -137,28 +137,31 @@ public final class TxMasterStyleAtom ext
short levels = LittleEndian.getShort(_data, 0);
pos += LittleEndian.SHORT_SIZE;
- prstyles = new TextPropCollection[levels];
- chstyles = new TextPropCollection[levels];
+ paragraphStyles = new ArrayList<TextPropCollection>(levels);
+ charStyles = new ArrayList<TextPropCollection>(levels);
for(short j = 0; j < levels; j++) {
-
+ TextPropCollection prprops = new TextPropCollection(0, TextPropType.paragraph); // getParagraphProps(type, j)
if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
// Fetch the 2 byte value, that is safe to ignore for some types of text
- short val = LittleEndian.getShort(_data, pos);
+ short indentLevel = LittleEndian.getShort(_data, pos);
+ prprops.setIndentLevel(indentLevel);
pos += LittleEndian.SHORT_SIZE;
+ } else {
+ prprops.setIndentLevel((short)-1);
}
head = LittleEndian.getInt(_data, pos);
pos += LittleEndian.INT_SIZE;
- TextPropCollection prprops = new TextPropCollection(0);
- pos += prprops.buildTextPropList( head, getParagraphProps(type, j), _data, pos);
- prstyles[j] = prprops;
+
+ pos += prprops.buildTextPropList( head, _data, pos);
+ paragraphStyles.add(prprops);
head = LittleEndian.getInt(_data, pos);
pos += LittleEndian.INT_SIZE;
- TextPropCollection chprops = new TextPropCollection(0);
- pos += chprops.buildTextPropList( head, getCharacterProps(type, j), _data, pos);
- chstyles[j] = chprops;
+ TextPropCollection chprops = new TextPropCollection(0, TextPropType.character); // getCharacterProps(type, j)
+ pos += chprops.buildTextPropList( head, _data, pos);
+ charStyles.add(chprops);
}
}
@@ -169,30 +172,12 @@ public final class TxMasterStyleAtom ext
* Depending on the level and type, it may be our special
* ones, or the standard StyleTextPropAtom ones
*/
- protected TextProp[] getParagraphProps(int type, int level){
- if (level != 0 || type >= MAX_INDENT){
- return StyleTextPropAtom.paragraphTextPropTypes;
- }
- return new TextProp[] {
- new ParagraphFlagsTextProp(),
- new TextProp(2, 0x80, "bullet.char"),
- new TextProp(2, 0x10, "bullet.font"),
- new TextProp(2, 0x40, "bullet.size"),
- new TextProp(4, 0x20, "bullet.color"),
- new TextProp(2, 0xD00, "alignment"),
- new TextProp(2, 0x1000, "linespacing"),
- new TextProp(2, 0x2000, "spacebefore"),
- new TextProp(2, 0x4000, "spaceafter"),
- new TextProp(2, 0x8000, "text.offset"),
- new TextProp(2, 0x10000, "bullet.offset"),
- new TextProp(2, 0x20000, "defaulttab"),
- new TextProp(2, 0x40000, "para_unknown_2"),
- new TextProp(2, 0x80000, "para_unknown_3"),
- new TextProp(2, 0x100000, "para_unknown_4"),
- new TextProp(2, 0x200000, "para_unknown_5")
- };
-
- }
+// protected TextProp[] getParagraphProps(int type, int level){
+// return StyleTextPropAtom.paragraphTextPropTypes;
+// return (level != 0 || type >= MAX_INDENT)
+// ? StyleTextPropAtom.paragraphTextPropTypes
+// : paragraphSpecialPropTypes;
+// }
/**
* Character properties for the specified text type and
@@ -200,19 +185,10 @@ public final class TxMasterStyleAtom ext
* Depending on the level and type, it may be our special
* ones, or the standard StyleTextPropAtom ones
*/
- protected TextProp[] getCharacterProps(int type, int level){
- if (level != 0 || type >= MAX_INDENT){
- return StyleTextPropAtom.characterTextPropTypes;
- }
- return new TextProp[] {
- new CharFlagsTextProp(),
- new TextProp(2, 0x10000, "font.index"),
- new TextProp(2, 0x20000, "char_unknown_1"),
- new TextProp(4, 0x40000, "char_unknown_2"),
- new TextProp(2, 0x80000, "font.size"),
- new TextProp(2, 0x100000, "char_unknown_3"),
- new TextProp(4, 0x200000, "font.color"),
- new TextProp(2, 0x800000, "char_unknown_4")
- };
- }
+// protected TextProp[] getCharacterProps(int type, int level){
+// return StyleTextPropAtom.characterTextPropTypes;
+// return (level != 0 || type >= MAX_INDENT)
+// ? StyleTextPropAtom.characterTextPropTypes
+// : characterSpecialPropTypes;
+// }
}
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java Fri Jul 24 21:47:55 2015
@@ -31,10 +31,12 @@ import org.apache.poi.ddf.EscherContaine
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.sl.usermodel.FreeformShape;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
/**
* A "Freeform" shape.
@@ -45,7 +47,7 @@ import org.apache.poi.util.POILogger;
* </p>
* @author Yegor Kozlov
*/
-public final class HSLFFreeformShape extends HSLFAutoShape {
+public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFTextParagraph> {
public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40};
public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC};
@@ -86,19 +88,15 @@ public final class HSLFFreeformShape ext
this(null);
}
- /**
- * Set the shape path
- *
- * @param path
- */
- public void setPath(GeneralPath path)
- {
+ @Override
+ public int setPath(GeneralPath path) {
Rectangle2D bounds = path.getBounds2D();
PathIterator it = path.getPathIterator(new AffineTransform());
List<byte[]> segInfo = new ArrayList<byte[]>();
List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
boolean isClosed = false;
+ int numPoints = 0;
while (!it.isDone()) {
double[] vals = new double[6];
int type = it.currentSegment(vals);
@@ -106,11 +104,13 @@ public final class HSLFFreeformShape ext
case PathIterator.SEG_MOVETO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
segInfo.add(SEGMENTINFO_MOVETO);
+ numPoints++;
break;
case PathIterator.SEG_LINETO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(SEGMENTINFO_ESCAPE);
+ numPoints++;
break;
case PathIterator.SEG_CUBICTO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
@@ -118,6 +118,7 @@ public final class HSLFFreeformShape ext
pntInfo.add(new Point2D.Double(vals[4], vals[5]));
segInfo.add(SEGMENTINFO_CUBICTO);
segInfo.add(SEGMENTINFO_ESCAPE2);
+ numPoints++;
break;
case PathIterator.SEG_QUADTO:
//TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
@@ -130,6 +131,7 @@ public final class HSLFFreeformShape ext
segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(SEGMENTINFO_CLOSE);
isClosed = true;
+ numPoints++;
break;
}
@@ -148,8 +150,8 @@ public final class HSLFFreeformShape ext
for (int i = 0; i < pntInfo.size(); i++) {
Point2D.Double pnt = pntInfo.get(i);
byte[] data = new byte[4];
- LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI));
- LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI));
+ LittleEndian.putShort(data, 0, (short)Units.pointsToMaster(pnt.getX() - bounds.getX()));
+ LittleEndian.putShort(data, 2, (short)Units.pointsToMaster(pnt.getY() - bounds.getY()));
verticesProp.setElement(i, data);
}
opt.addEscherProperty(verticesProp);
@@ -164,20 +166,18 @@ public final class HSLFFreeformShape ext
}
opt.addEscherProperty(segmentsProp);
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)(bounds.getWidth()*MASTER_DPI/POINT_DPI)));
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)(bounds.getHeight()*MASTER_DPI/POINT_DPI)));
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(bounds.getWidth())));
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bounds.getHeight())));
opt.sortProperties();
setAnchor(bounds);
+
+ return numPoints;
}
- /**
- * Gets the freeform path
- *
- * @return the freeform path
- */
- public GeneralPath getPath(){
+ @Override
+ public GeneralPath getPath(){
EscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
@@ -187,17 +187,19 @@ public final class HSLFFreeformShape ext
EscherArrayProperty segmentsProp = getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000));
if(segmentsProp == null) segmentsProp = getEscherProperty(opt, EscherProperties.GEOMETRY__SEGMENTINFO);
+ // return empty path if either GEOMETRY__VERTICES or GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
+ GeneralPath path = new GeneralPath();
+
//sanity check
if(verticesProp == null) {
logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES ");
- return null;
+ return path;
}
if(segmentsProp == null) {
logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO ");
- return null;
+ return path;
}
- GeneralPath path = new GeneralPath();
int numPoints = verticesProp.getNumberOfElementsInArray();
int numSegments = segmentsProp.getNumberOfElementsInArray();
for (int i = 0, j = 0; i < numSegments && j < numPoints; i++) {
@@ -206,9 +208,7 @@ public final class HSLFFreeformShape ext
byte[] p = verticesProp.getElement(j++);
short x = LittleEndian.getShort(p, 0);
short y = LittleEndian.getShort(p, 2);
- path.moveTo(
- ((float)x*POINT_DPI/MASTER_DPI),
- ((float)y*POINT_DPI/MASTER_DPI));
+ path.moveTo(Units.masterToPoints(x), Units.masterToPoints(y));
} else if (Arrays.equals(elem, SEGMENTINFO_CUBICTO) || Arrays.equals(elem, SEGMENTINFO_CUBICTO2)){
i++;
byte[] p1 = verticesProp.getElement(j++);
@@ -221,9 +221,9 @@ public final class HSLFFreeformShape ext
short x3 = LittleEndian.getShort(p3, 0);
short y3 = LittleEndian.getShort(p3, 2);
path.curveTo(
- ((float)x1*POINT_DPI/MASTER_DPI), ((float)y1*POINT_DPI/MASTER_DPI),
- ((float)x2*POINT_DPI/MASTER_DPI), ((float)y2*POINT_DPI/MASTER_DPI),
- ((float)x3*POINT_DPI/MASTER_DPI), ((float)y3*POINT_DPI/MASTER_DPI));
+ Units.masterToPoints(x1), Units.masterToPoints(y1),
+ Units.masterToPoints(x2), Units.masterToPoints(y2),
+ Units.masterToPoints(x3), Units.masterToPoints(y3));
} else if (Arrays.equals(elem, SEGMENTINFO_LINETO)){
i++;
@@ -233,24 +233,14 @@ public final class HSLFFreeformShape ext
byte[] p = verticesProp.getElement(j++);
short x = LittleEndian.getShort(p, 0);
short y = LittleEndian.getShort(p, 2);
- path.lineTo(
- ((float)x*POINT_DPI/MASTER_DPI), ((float)y*POINT_DPI/MASTER_DPI));
+ path.lineTo(Units.masterToPoints(x), Units.masterToPoints(y));
}
} else if (Arrays.equals(pnext, SEGMENTINFO_CLOSE)){
path.closePath();
}
}
}
- return path;
- }
-
- public java.awt.Shape getOutline(){
- GeneralPath path = getPath();
- if(path == null) {
- // return empty path if either GEOMETRY__VERTICES or GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
- return new GeneralPath();
- }
-
+
Rectangle2D anchor = getAnchor2D();
Rectangle2D bounds = path.getBounds2D();
AffineTransform at = new AffineTransform();
@@ -259,6 +249,6 @@ public final class HSLFFreeformShape ext
anchor.getWidth()/bounds.getWidth(),
anchor.getHeight()/bounds.getHeight()
);
- return at.createTransformedShape(path);
+ return new GeneralPath(at.createTransformedShape(path));
}
}
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java Fri Jul 24 21:47:55 2015
@@ -24,6 +24,7 @@ import org.apache.poi.ddf.*;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
/**
* Represents a group of shapes.
@@ -73,27 +74,27 @@ public class HSLFGroupShape extends HSLF
LittleEndian.putInt(header, 4, 8);
clientAnchor.fillFields(header, 0, null);
- clientAnchor.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
- clientAnchor.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
- clientAnchor.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
- clientAnchor.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));
+ clientAnchor.setFlag((short)Units.pointsToMaster(anchor.y));
+ clientAnchor.setCol1((short)Units.pointsToMaster(anchor.x));
+ clientAnchor.setDx1((short)Units.pointsToMaster(anchor.width + anchor.x));
+ clientAnchor.setRow1((short)Units.pointsToMaster(anchor.height + anchor.y));
EscherSpgrRecord spgr = getEscherChild(EscherSpgrRecord.RECORD_ID);
- spgr.setRectX1(anchor.x*MASTER_DPI/POINT_DPI);
- spgr.setRectY1(anchor.y*MASTER_DPI/POINT_DPI);
- spgr.setRectX2((anchor.x + anchor.width)*MASTER_DPI/POINT_DPI);
- spgr.setRectY2((anchor.y + anchor.height)*MASTER_DPI/POINT_DPI);
+ spgr.setRectX1(Units.pointsToMaster(anchor.x));
+ spgr.setRectY1(Units.pointsToMaster(anchor.y));
+ spgr.setRectX2(Units.pointsToMaster(anchor.x + anchor.width));
+ spgr.setRectY2(Units.pointsToMaster(anchor.y + anchor.height));
}
@Override
public void setInteriorAnchor(Rectangle2D anchor){
EscherSpgrRecord spgr = getEscherChild(EscherSpgrRecord.RECORD_ID);
- int x1 = (int)Math.round(anchor.getX()*MASTER_DPI/POINT_DPI);
- int y1 = (int)Math.round(anchor.getY()*MASTER_DPI/POINT_DPI);
- int x2 = (int)Math.round((anchor.getX() + anchor.getWidth())*MASTER_DPI/POINT_DPI);
- int y2 = (int)Math.round((anchor.getY() + anchor.getHeight())*MASTER_DPI/POINT_DPI);
+ int x1 = Units.pointsToMaster(anchor.getX());
+ int y1 = Units.pointsToMaster(anchor.getY());
+ int x2 = Units.pointsToMaster(anchor.getX() + anchor.getWidth());
+ int y2 = Units.pointsToMaster(anchor.getY() + anchor.getHeight());
spgr.setRectX1(x1);
spgr.setRectY1(y1);
@@ -105,11 +106,11 @@ public class HSLFGroupShape extends HSLF
@Override
public Rectangle2D getInteriorAnchor(){
EscherSpgrRecord rec = getEscherChild(EscherSpgrRecord.RECORD_ID);
- double x = rec.getRectX1()*POINT_DPI/MASTER_DPI;
- double y = rec.getRectY1()*POINT_DPI/MASTER_DPI;
- double width = (rec.getRectX2()-rec.getRectX1())*POINT_DPI/MASTER_DPI;
- double height = (rec.getRectY2()-rec.getRectY1())*POINT_DPI/MASTER_DPI;
- return new Rectangle2D.Double(x,y,width,height);
+ double x1 = Units.masterToPoints(rec.getRectX1());
+ double y1 = Units.masterToPoints(rec.getRectY1());
+ double x2 = Units.masterToPoints(rec.getRectX2());
+ double y2 = Units.masterToPoints(rec.getRectY2());
+ return new Rectangle2D.Double(x1,y1,x2-x1,y2-y1);
}
/**
@@ -185,22 +186,26 @@ public class HSLFGroupShape extends HSLF
*/
public Rectangle2D getAnchor2D(){
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
- Rectangle2D anchor;
+ int x1,y1,x2,y2;
if(clientAnchor == null){
logger.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
- double x = rec.getDx1()*POINT_DPI/MASTER_DPI;
- double y = rec.getDy1()*POINT_DPI/MASTER_DPI;
- double width = (rec.getDx2()-rec.getDx1())*POINT_DPI/MASTER_DPI;
- double height = (rec.getDy2()-rec.getDy1())*POINT_DPI/MASTER_DPI;
- anchor = new Rectangle2D.Double(x,y,width,height);
+ x1 = rec.getDx1();
+ y1 = rec.getDy1();
+ x2 = rec.getDx2();
+ y2 = rec.getDy2();
} else {
- double x = clientAnchor.getCol1()*POINT_DPI/MASTER_DPI;
- double y = clientAnchor.getFlag()*POINT_DPI/MASTER_DPI;
- double width = (clientAnchor.getDx1() - clientAnchor.getCol1())*POINT_DPI/MASTER_DPI ;
- double height = (clientAnchor.getRow1() - clientAnchor.getFlag())*POINT_DPI/MASTER_DPI;
- anchor = new Rectangle2D.Double(x,y,width,height);
+ x1 = clientAnchor.getCol1();
+ y1 = clientAnchor.getFlag();
+ x2 = clientAnchor.getDx1();
+ y2 = clientAnchor.getRow1();
}
+ Rectangle2D anchor= new Rectangle2D.Double(
+ (x1 == -1 ? -1 : Units.masterToPoints(x1)),
+ (y1 == -1 ? -1 : Units.masterToPoints(y1)),
+ (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
+ (y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
+ );
return anchor;
}
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java Fri Jul 24 21:47:55 2015
@@ -18,6 +18,7 @@
package org.apache.poi.hslf.usermodel;
import java.awt.Insets;
+import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -25,11 +26,22 @@ import java.util.List;
import javax.imageio.ImageIO;
-import org.apache.poi.ddf.*;
+import org.apache.poi.ddf.EscherBSERecord;
+import org.apache.poi.ddf.EscherComplexProperty;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.blip.Bitmap;
import org.apache.poi.hslf.record.Document;
-import org.apache.poi.sl.usermodel.*;
-import org.apache.poi.util.*;
+import org.apache.poi.sl.usermodel.PictureShape;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
+import org.apache.poi.util.Units;
/**
@@ -153,14 +165,14 @@ public class HSLFPictureShape extends HS
if(img != null) {
// Valid image, set anchor from it
- setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*POINT_DPI/PIXEL_DPI, img.getHeight()*POINT_DPI/PIXEL_DPI));
+ setAnchor(new Rectangle2D.Double(0, 0, Units.pixelToPoints(img.getWidth()), Units.pixelToPoints(img.getHeight())));
} else {
// Invalid image, go with the default metafile size
- setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
+ setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
}
} else {
//default size of a metafile picture is 200x200
- setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
+ setAnchor(new Rectangle2D.Double(50, 50, 200, 200));
}
}
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java Fri Jul 24 21:47:55 2015
@@ -50,31 +50,6 @@ public abstract class HSLFShape implemen
protected POILogger logger = POILogFactory.getLogger(this.getClass());
/**
- * In Escher absolute distances are specified in
- * English Metric Units (EMUs), occasionally referred to as A units;
- * there are 360000 EMUs per centimeter, 914400 EMUs per inch, 12700 EMUs per point.
- */
- public static final int EMU_PER_INCH = 914400;
- public static final int EMU_PER_POINT = 12700;
- public static final int EMU_PER_CENTIMETER = 360000;
-
- /**
- * Master DPI (576 pixels per inch).
- * Used by the reference coordinate system in PowerPoint.
- */
- public static final int MASTER_DPI = 576;
-
- /**
- * Pixels DPI (96 pixels per inch)
- */
- public static final int PIXEL_DPI = 96;
-
- /**
- * Points DPI (72 pixels per inch)
- */
- public static final int POINT_DPI = 72;
-
- /**
* Either EscherSpContainer or EscheSpgrContainer record
* which holds information about this shape.
*/
@@ -165,31 +140,31 @@ public abstract class HSLFShape implemen
public Rectangle2D getAnchor2D(){
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
- int x,y,w,h;
+ int x1,y1,x2,y2;
EscherChildAnchorRecord childRec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
boolean useChildRec = ((flags & EscherSpRecord.FLAG_CHILD) != 0);
if (useChildRec && childRec != null){
- x = childRec.getDx1();
- y = childRec.getDy1();
- w = childRec.getDx2()-childRec.getDx1();
- h = childRec.getDy2()-childRec.getDy1();
+ x1 = childRec.getDx1();
+ y1 = childRec.getDy1();
+ x2 = childRec.getDx2();
+ y2 = childRec.getDy2();
} else {
if (useChildRec) {
logger.log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found");
}
EscherClientAnchorRecord clientRec = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
- x = clientRec.getFlag();
- y = clientRec.getCol1();
- w = clientRec.getDx1()-clientRec.getFlag();
- h = clientRec.getRow1()-clientRec.getCol1();
+ x1 = clientRec.getCol1();
+ y1 = clientRec.getFlag();
+ x2 = clientRec.getDx1();
+ y2 = clientRec.getRow1();
}
// TODO: find out where this -1 value comes from at #57820 (link to ms docs?)
- Rectangle2D anchor = new Rectangle2D.Float(
- (float)(x == -1 ? -1 : Units.masterToPoints(x)),
- (float)(y == -1 ? -1 : Units.masterToPoints(y)),
- (float)(w == -1 ? -1 : Units.masterToPoints(w)),
- (float)(h == -1 ? -1 : Units.masterToPoints(h))
+ Rectangle2D anchor = new Rectangle2D.Double(
+ (x1 == -1 ? -1 : Units.masterToPoints(x1)),
+ (y1 == -1 ? -1 : Units.masterToPoints(y1)),
+ (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
+ (y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
);
return anchor;
@@ -216,8 +191,8 @@ public abstract class HSLFShape implemen
rec.setDy2(h);
} else {
EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(EscherClientAnchorRecord.RECORD_ID);
- rec.setFlag((short)x);
- rec.setCol1((short)y);
+ rec.setCol1((short)x);
+ rec.setFlag((short)y);
rec.setDx1((short)w);
rec.setRow1((short)h);
}
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Fri Jul 24 21:47:55 2015
@@ -67,6 +67,7 @@ import org.apache.poi.poifs.filesystem.P
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
/**
* This class is a friendly wrapper on top of the more scary HSLFSlideShow.
@@ -529,8 +530,8 @@ public final class HSLFSlideShow impleme
*/
public Dimension getPageSize() {
DocumentAtom docatom = _documentRecord.getDocumentAtom();
- int pgx = (int) docatom.getSlideSizeX() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
- int pgy = (int) docatom.getSlideSizeY() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
+ int pgx = (int)Units.masterToPoints((int)docatom.getSlideSizeX());
+ int pgy = (int)Units.masterToPoints((int)docatom.getSlideSizeY());
return new Dimension(pgx, pgy);
}
@@ -542,8 +543,8 @@ public final class HSLFSlideShow impleme
*/
public void setPageSize(Dimension pgsize) {
DocumentAtom docatom = _documentRecord.getDocumentAtom();
- docatom.setSlideSizeX(pgsize.width * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
- docatom.setSlideSizeY(pgsize.height * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
+ docatom.setSlideSizeX(Units.pointsToMaster(pgsize.width));
+ docatom.setSlideSizeY(Units.pointsToMaster(pgsize.height));
}
/**
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java Fri Jul 24 21:47:55 2015
@@ -17,16 +17,25 @@
package org.apache.poi.hslf.usermodel;
-import org.apache.poi.ddf.*;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ddf.EscherArrayProperty;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherTextboxRecord;
import org.apache.poi.hslf.model.Line;
-import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.util.LittleEndian;
-
-import java.util.*;
-import java.util.List;
-import java.awt.*;
+import org.apache.poi.util.Units;
/**
* Represents a table in a PowerPoint presentation
@@ -127,7 +136,7 @@ public final class HSLFTable extends HSL
EscherArrayProperty p = opt.lookup(0x3A0);
for (int i = 0; i < cells.length; i++) {
HSLFTableCell cell = cells[i][0];
- int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI;
+ int rowHeight = Units.pointsToMaster(cell.getAnchor().height);
byte[] val = new byte[4];
LittleEndian.putInt(val, 0, rowHeight);
p.setElement(i, val);
Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java (from r1691849, poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java&p1=poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java&r1=1691849&r2=1692593&rev=1692593&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java Fri Jul 24 21:47:55 2015
@@ -32,6 +32,7 @@ import org.apache.poi.sl.draw.DrawFactor
import org.apache.poi.sl.draw.DrawTextShape;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
/**
* A common superclass of all shapes that can hold text.
@@ -377,10 +378,7 @@ public abstract class HSLFTextShape exte
* @return the botom margin
*/
public double getBottomInset(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
- int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return val/EMU_PER_POINT;
+ return getInset(EscherProperties.TEXT__TEXTBOTTOM, .05);
}
/**
@@ -390,7 +388,7 @@ public abstract class HSLFTextShape exte
* @param margin the bottom margin
*/
public void setBottomInset(double margin){
- setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));
+ setInset(EscherProperties.TEXT__TEXTBOTTOM, margin);
}
/**
@@ -402,10 +400,7 @@ public abstract class HSLFTextShape exte
* @return the left margin
*/
public double getLeftInset(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
- int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return val/EMU_PER_POINT;
+ return getInset(EscherProperties.TEXT__TEXTLEFT, .1);
}
/**
@@ -415,7 +410,7 @@ public abstract class HSLFTextShape exte
* @param margin the left margin
*/
public void setLeftInset(double margin){
- setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));
+ setInset(EscherProperties.TEXT__TEXTLEFT, margin);
}
/**
@@ -427,10 +422,7 @@ public abstract class HSLFTextShape exte
* @return the right margin
*/
public double getRightInset(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
- int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return val/EMU_PER_POINT;
+ return getInset(EscherProperties.TEXT__TEXTRIGHT, .1);
}
/**
@@ -440,7 +432,7 @@ public abstract class HSLFTextShape exte
* @param margin the right margin
*/
public void setRightInset(double margin){
- setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));
+ setInset(EscherProperties.TEXT__TEXTRIGHT, margin);
}
/**
@@ -451,10 +443,7 @@ public abstract class HSLFTextShape exte
* @return the top margin
*/
public double getTopInset(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
- int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return val/EMU_PER_POINT;
+ return getInset(EscherProperties.TEXT__TEXTTOP, .05);
}
/**
@@ -464,9 +453,32 @@ public abstract class HSLFTextShape exte
* @param margin the top margin
*/
public void setTopInset(double margin){
- setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));
+ setInset(EscherProperties.TEXT__TEXTTOP, margin);
+ }
+
+ /**
+ * Returns the distance (in points) between the edge of the text frame
+ * and the edge of the inscribed rectangle of the shape that contains the text.
+ * Default value is 1/20 inch.
+ *
+ * @param propId the id of the inset edge
+ * @return the inset in points
+ */
+ private double getInset(short propId, double defaultInch) {
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, propId);
+ int val = prop == null ? (int)(Units.toEMU(Units.POINT_DPI)*defaultInch) : prop.getPropertyValue();
+ return Units.toPoints(val);
}
+ /**
+ * @param propId the id of the inset edge
+ * @param margin the inset in points
+ */
+ private void setInset(short propId, double margin){
+ setEscherProperty(propId, Units.toEMU(margin));
+ }
+
@Override
public boolean getWordWrap(){
int ww = getWordWrapEx();
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java Fri Jul 24 21:47:55 2015
@@ -22,9 +22,10 @@ package org.apache.poi;
import junit.framework.TestCase;
+
import java.io.*;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.*;
@@ -47,7 +48,7 @@ public final class TestPOIDocumentScratc
* a Word Document for our testing
*/
public void setUp() throws Exception {
- doc = new HSLFSlideShow(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
+ doc = new HSLFSlideShowImpl(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
doc2 = HWPFTestDataSamples.openSampleFile("test2.doc");
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java Fri Jul 24 21:47:55 2015
@@ -24,7 +24,8 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
public class HSLFTestDataSamples {
@@ -45,12 +46,12 @@ public class HSLFTestDataSamples {
* from a <tt>ByteArrayInputStream</tt>.<p/>
* Useful for verifying that the serialisation round trip
*/
- public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
+ public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new HSLFSlideShow(bais);
+ return new HSLFSlideShowImpl(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -61,12 +62,12 @@ public class HSLFTestDataSamples {
* from a <tt>ByteArrayInputStream</tt>.<p/>
* Useful for verifying that the serialisation round trip
*/
- public static SlideShow writeOutAndReadBack(SlideShow original) {
+ public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new SlideShow(bais);
+ return new HSLFSlideShow(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java Fri Jul 24 21:47:55 2015
@@ -21,6 +21,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
@@ -32,28 +33,28 @@ public final class TestEncryptedFile ext
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
public void testLoadNonEncrypted() throws Exception {
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertNotNull(hss);
}
public void testLoadEncrypted() throws Exception {
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java Fri Jul 24 21:47:55 2015
@@ -25,7 +25,8 @@ import java.io.FileNotFoundException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -37,9 +38,9 @@ import org.apache.poi.poifs.filesystem.P
*/
public final class TestReWrite extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow hssA;
- private HSLFSlideShow hssB;
- private HSLFSlideShow hssC;
+ private HSLFSlideShowImpl hssA;
+ private HSLFSlideShowImpl hssB;
+ private HSLFSlideShowImpl hssC;
// POIFS primed on the test data
private POIFSFileSystem pfsA;
private POIFSFileSystem pfsB;
@@ -50,20 +51,20 @@ public final class TestReWrite extends T
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- hssA = new HSLFSlideShow(pfsA);
+ hssA = new HSLFSlideShowImpl(pfsA);
pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
- hssB = new HSLFSlideShow(pfsB);
+ hssB = new HSLFSlideShowImpl(pfsB);
pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
- hssC = new HSLFSlideShow(pfsC);
+ hssC = new HSLFSlideShowImpl(pfsC);
}
public void testWritesOutTheSame() throws Exception {
assertWritesOutTheSame(hssA, pfsA);
assertWritesOutTheSame(hssB, pfsB);
}
- public void assertWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
+ public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
// Write out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss.write(baos);
@@ -129,9 +130,9 @@ public final class TestReWrite extends T
// We need to identify and fix that first
//assertSlideShowWritesOutTheSame(hssB, pfsB);
}
- public void assertSlideShowWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
+ public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
// Create a slideshow covering it
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
ss.getSlides();
ss.getNotes();
@@ -163,7 +164,7 @@ public final class TestReWrite extends T
}
public void test48593() throws Exception {
- SlideShow slideShow = new SlideShow();
+ HSLFSlideShow slideShow = new HSLFSlideShow();
slideShow.createSlide();
slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
slideShow.createSlide();
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java Fri Jul 24 21:47:55 2015
@@ -19,9 +19,12 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
+
import java.io.*;
import java.util.*;
+
import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
@@ -33,14 +36,14 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestReWriteSanity extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow ss;
+ private HSLFSlideShowImpl ss;
// POIFS primed on the test data
private POIFSFileSystem pfs;
public TestReWriteSanity() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new HSLFSlideShow(pfs);
+ ss = new HSLFSlideShowImpl(pfs);
}
public void testUserEditAtomsRight() throws Exception {
@@ -52,7 +55,7 @@ public final class TestReWriteSanity ext
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// Create a new one from that
- HSLFSlideShow wss = new HSLFSlideShow(bais);
+ HSLFSlideShowImpl wss = new HSLFSlideShowImpl(bais);
// Find the location of the PersistPtrIncrementalBlocks and
// UserEditAtoms
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java Fri Jul 24 21:47:55 2015
@@ -19,7 +19,9 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
@@ -30,11 +32,11 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestRecordCounts extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow ss;
+ private HSLFSlideShowImpl ss;
public TestRecordCounts() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- ss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
}
public void testSheetsCount() {
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Fri Jul 24 21:47:55 2015
@@ -23,9 +23,9 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.OLEShape;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -140,7 +140,7 @@ public final class TestExtractor extends
POIFSFileSystem fs = new POIFSFileSystem(
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
);
- HSLFSlideShow ss;
+ HSLFSlideShowImpl ss;
DirectoryNode dirA = (DirectoryNode)
fs.getRoot().getEntry("MBD0000A3B6");
@@ -151,14 +151,14 @@ public final class TestExtractor extends
assertNotNull(dirB.getEntry("PowerPoint Document"));
// Check the first file
- ss = new HSLFSlideShow(dirA);
+ ss = new HSLFSlideShowImpl(dirA);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n",
ppe.getText(true, false)
);
// And the second
- ss = new HSLFSlideShow(dirB);
+ ss = new HSLFSlideShowImpl(dirB);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
ppe.getText(true, false)
@@ -186,7 +186,7 @@ public final class TestExtractor extends
num_doc++;
} else if ("Presentation".equals(name)) {
num_ppt++;
- SlideShow ppt = new SlideShow(data);
+ HSLFSlideShow ppt = new HSLFSlideShow(data);
}
}
assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
@@ -241,8 +241,8 @@ public final class TestExtractor extends
String text;
// With a header on the notes
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Header.ppt"));
- SlideShow ss = new SlideShow(hslf);
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("45537_Header.ppt"));
+ HSLFSlideShow ss = new HSLFSlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText());
@@ -259,8 +259,8 @@ public final class TestExtractor extends
// And with a footer, also on notes
- hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Footer.ppt"));
- ss = new SlideShow(hslf);
+ hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("45537_Footer.ppt"));
+ ss = new HSLFSlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText());
@@ -281,7 +281,7 @@ public final class TestExtractor extends
String masterTitleText = "This is the Master Title";
String masterRandomText = "This text comes from the Master Slide";
String masterFooterText = "Footer from the master slide";
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
@@ -309,7 +309,7 @@ public final class TestExtractor extends
// Now with another file only containing master text
// Will always show up
String masterText = "Footer from the master slide";
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
@@ -322,7 +322,7 @@ public final class TestExtractor extends
* Bug #54880 Chinese text not extracted properly
*/
public void testChineseText() throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("54880_chinese.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
ppe = new PowerPointExtractor(hslf);
String text = ppe.getText();
@@ -360,7 +360,7 @@ public final class TestExtractor extends
// Open via a HWPFDocument
for(DirectoryNode dir : files) {
- HSLFSlideShow slideshow = new HSLFSlideShow(dir);
+ HSLFSlideShowImpl slideshow = new HSLFSlideShowImpl(dir);
PowerPointExtractor extractor = new PowerPointExtractor(slideshow);
assertEquals(expectText, extractor.getText());
}
@@ -369,20 +369,20 @@ public final class TestExtractor extends
}
public void testTable() throws Exception{
- ppe = new PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
- String text = ppe.getText();
- String target = "TH Cell 1\tTH Cell 2\tTH Cell 3\tTH Cell 4\n"+
- "Row 1, Cell 1\tRow 1, Cell 2\tRow 1, Cell 3\tRow 1, Cell 4\n"+
- "Row 2, Cell 1\tRow 2, Cell 2\tRow 2, Cell 3\tRow 2, Cell 4\n"+
- "Row 3, Cell 1\tRow 3, Cell 2\tRow 3, Cell 3\tRow 3, Cell 4\n"+
- "Row 4, Cell 1\tRow 4, Cell 2\tRow 4, Cell 3\tRow 4, Cell 4\n"+
- "Row 5, Cell 1\tRow 5, Cell 2\tRow 5, Cell 3\tRow 5, Cell 4\n";
- assertTrue(text.contains(target));
+// ppe = new PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
+// String text = ppe.getText();
+// String target = "TH Cell 1\tTH Cell 2\tTH Cell 3\tTH Cell 4\n"+
+// "Row 1, Cell 1\tRow 1, Cell 2\tRow 1, Cell 3\tRow 1, Cell 4\n"+
+// "Row 2, Cell 1\tRow 2, Cell 2\tRow 2, Cell 3\tRow 2, Cell 4\n"+
+// "Row 3, Cell 1\tRow 3, Cell 2\tRow 3, Cell 3\tRow 3, Cell 4\n"+
+// "Row 4, Cell 1\tRow 4, Cell 2\tRow 4, Cell 3\tRow 4, Cell 4\n"+
+// "Row 5, Cell 1\tRow 5, Cell 2\tRow 5, Cell 3\tRow 5, Cell 4\n";
+// assertTrue(text.contains(target));
ppe = new PowerPointExtractor(slTests.openResourceAsStream("54722.ppt"));
- text = ppe.getText();
+ String text = ppe.getText();
- target = "this\tText\tis\twithin\ta\n"+
+ String target = "this\tText\tis\twithin\ta\n"+
"table\t1\t2\t3\t4";
assertTrue(text.contains(target));
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java Fri Jul 24 21:47:55 2015
@@ -29,13 +29,11 @@ import org.junit.runners.Suite;
TestFreeform.class,
TestHeadersFooters.class,
TestHyperlink.class,
- TestImagePainter.class,
TestLine.class,
TestMovieShape.class,
TestOleEmbedding.class,
TestPPFont.class,
TestPPGraphics2D.class,
- TestPicture.class,
TestSetBoldItalic.class,
TestShapes.class,
TestSheet.class,
@@ -43,9 +41,7 @@ import org.junit.runners.Suite;
TestSlideMaster.class,
TestSlides.class,
TestTable.class,
- TestTextRun.class,
- TestTextRunReWrite.class,
- TestTextShape.class
+ TestTextRunReWrite.class
})
public class AllHSLFModelTests {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org