You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/05/21 20:15:01 UTC
svn commit: r777204 [5/21] - in /poi/trunk/src/scratchpad:
examples/src/org/apache/poi/hslf/examples/
examples/src/org/apache/poi/hwpf/ src/org/apache/poi/hdf/event/
src/org/apache/poi/hdf/extractor/ src/org/apache/poi/hdf/extractor/data/
src/org/apach...
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java Thu May 21 18:12:22 2009
@@ -58,10 +58,10 @@
boolean escher = false;
int ndx=0;
- for (; ndx<args.length; ndx++) {
+ for (; ndx<args.length; ndx++) {
if (!args[ndx].substring(0,1).equals("-"))
break;
-
+
if (args[ndx].equals("-escher")) {
escher = true;
} else if (args[ndx].equals("-verbose")) {
@@ -71,20 +71,20 @@
return;
}
}
-
+
// parsed any options, expect exactly one remaining arg (filename)
if (ndx != args.length-1) {
printUsage();
return;
}
-
+
filename = args[ndx];
SlideShowRecordDumper foo = new SlideShowRecordDumper(filename, verbose, escher);
foo.printDump();
}
-
+
public static void printUsage() {
System.err.println("Usage: SlideShowRecordDumper [-escher] [-verbose] <filename>");
System.err.println("Valid Options:");
@@ -94,7 +94,7 @@
/**
- * Constructs a Powerpoint dump from fileName. Parses the document
+ * Constructs a Powerpoint dump from fileName. Parses the document
* and dumps out the contents
*
* @param fileName The name of the file to read.
@@ -139,7 +139,7 @@
public int getDiskLen(Record r) throws IOException {
if (r == null) return 0;
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
@@ -148,13 +148,13 @@
public String getPrintableRecordContents(Record r) throws IOException {
if (r==null) return "<<null>>";
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
}
-
+
public String printEscherRecord( EscherRecord er ) {
String nl = System.getProperty( "line.separator" );
StringBuffer buf = new StringBuffer();
@@ -163,41 +163,41 @@
buf.append(printEscherContainerRecord( (EscherContainerRecord)er ));
} else if (er instanceof EscherTextboxRecord) {
buf.append("EscherTextboxRecord:" + nl);
-
+
EscherTextboxWrapper etw = new EscherTextboxWrapper((EscherTextboxRecord)er);
Record children[] = etw.getChildRecords();
for (int j=0; j<children.length; j++) {
if (children[j] instanceof StyleTextPropAtom) {
-
+
// need preceding Text[Chars|Bytes]Atom to initialize the data structure
- if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
+ if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
children[j-1] instanceof TextBytesAtom)) {
-
- int size = (children[j-1] instanceof TextCharsAtom) ?
- ((TextCharsAtom)children[j-1]).getText().length() :
+
+ int size = (children[j-1] instanceof TextCharsAtom) ?
+ ((TextCharsAtom)children[j-1]).getText().length() :
((TextBytesAtom)children[j-1]).getText().length();
-
+
StyleTextPropAtom tsp = (StyleTextPropAtom)children[j];
tsp.setParentTextSize(size);
-
+
} else {
buf.append("Error! Couldn't find preceding TextAtom for style\n");
}
-
+
buf.append(children[j].toString() + nl );
- } else {
+ } else {
buf.append(children[j].toString() + nl );
}
}
} else {
buf.append( er.toString() );
- }
+ }
return buf.toString();
}
-
+
public String printEscherContainerRecord( EscherContainerRecord ecr ) {
String indent = "";
-
+
String nl = System.getProperty( "line.separator" );
StringBuffer children = new StringBuffer();
@@ -211,13 +211,13 @@
EscherRecord record = iterator.next();
children.append(newIndent + "Child " + count + ":" + nl);
-
+
children.append( printEscherRecord(record) );
count++;
}
- return
+ return
indent + ecr.getClass().getName() + " (" + ecr.getRecordName() + "):" + nl +
indent + " isContainer: " + ecr.isContainerRecord() + nl +
indent + " options: 0x" + HexDump.toHex( ecr.getOptions() ) + nl +
@@ -242,7 +242,7 @@
// Figure out how big it is
int len = getDiskLen(r);
-
+
// Grab the type as hex
String hexType = makeHex((int)r.getRecordType(),4);
String rHexType = reverseHex(hexType);
@@ -273,9 +273,9 @@
EscherRecord er = factory.createRecord(b, 0);
er.fillFields(b, 0, factory);
-
+
System.out.println( printEscherRecord( er ) );
-
+
} else if(optVerbose && r.getChildRecords() == null) {
String recData = getPrintableRecordContents(r);
System.out.println(ind + recData );
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,8 +15,6 @@
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
@@ -33,7 +30,7 @@
* Uses record level code to locate StyleTextPropAtom entries.
* Having found them, it shows the contents
*/
-public class TextStyleListing {
+public final class TextStyleListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
@@ -84,7 +81,7 @@
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
showTextProps(tpc);
}
-
+
LinkedList charStyles = stpa.getCharacterStyles();
System.out.println("Contains " + charStyles.size() + " character styles:");
for(int i=0; i<charStyles.size(); i++) {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,8 +15,6 @@
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
@@ -37,7 +34,7 @@
* persistence related atoms. Tries to match them together, to help
* illuminate quite what all the offsets mean
*/
-public class UserEditAndPersistListing {
+public final class UserEditAndPersistListing {
private static byte[] fileContents;
public static void main(String[] args) throws Exception {
@@ -122,7 +119,7 @@
CurrentUserAtom cua = ss.getCurrentUserAtom();
System.out.println("Checking Current User Atom");
System.out.println(" Thinks the CurrentEditOffset is " + cua.getCurrentEditOffset());
-
+
System.out.println("");
}
@@ -133,7 +130,7 @@
long rlen = LittleEndian.getUInt(fileContents, pos+4);
Record r = Record.createRecordForType(type,fileContents,pos,(int)rlen+8);
-
+
return r;
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,8 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.exceptions;
@@ -27,7 +24,7 @@
* @author Nick Burch
*/
-public class CorruptPowerPointFileException extends IllegalStateException
+public final class CorruptPowerPointFileException extends IllegalStateException
{
public CorruptPowerPointFileException(String s) {
super(s);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java Thu May 21 18:12:22 2009
@@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.exceptions;
import org.apache.poi.EncryptedDocumentException;
@@ -22,7 +23,7 @@
* This exception is thrown when we try to open a PowerPoint file, and
* discover that it is encrypted
*/
-public class EncryptedPowerPointFileException extends EncryptedDocumentException
+public final class EncryptedPowerPointFileException extends EncryptedDocumentException
{
public EncryptedPowerPointFileException(String s) {
super(s);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/HSLFException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/HSLFException.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/HSLFException.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/HSLFException.java Thu May 21 18:12:22 2009
@@ -1,43 +1,42 @@
-
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.exceptions;
-
-/**
- * A generic exception that can be thrown by HSLF classes
- *
- * @author Yegor Kozlov
- */
-public class HSLFException extends RuntimeException {
-
- public HSLFException() {
- super();
- }
-
- public HSLFException(String message) {
- super(message);
- }
-
- public HSLFException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public HSLFException(Throwable cause) {
- super(cause);
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.exceptions;
+
+/**
+ * A generic exception that can be thrown by HSLF classes
+ *
+ * @author Yegor Kozlov
+ */
+public final class HSLFException extends RuntimeException {
+
+ public HSLFException() {
+ super();
+ }
+
+ public HSLFException(String message) {
+ super(message);
+ }
+
+ public HSLFException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public HSLFException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/InvalidRecordFormatException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/InvalidRecordFormatException.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/InvalidRecordFormatException.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/InvalidRecordFormatException.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,8 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.exceptions;
@@ -27,7 +24,7 @@
* @author Nick Burch
*/
-public class InvalidRecordFormatException extends Exception
+public final class InvalidRecordFormatException extends Exception
{
public InvalidRecordFormatException(String s) {
super(s);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.extractor;
import org.apache.poi.hslf.usermodel.SlideShow;
@@ -30,7 +30,7 @@
*
* @author Yegor Kozlov
*/
-public class ImageExtractor {
+public final class ImageExtractor {
public static void main(String args[]) throws IOException {
if (args.length < 1) {
System.err.println("Usage:");
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java Thu May 21 18:12:22 2009
@@ -43,7 +43,7 @@
private HSLFSlideShow _hslfshow;
private SlideShow _show;
private Slide[] _slides;
-
+
private boolean slidesByDefault = true;
private boolean notesByDefault = false;
private boolean commentsByDefault = false;
@@ -135,7 +135,7 @@
}
/**
- * Fetches all the slide text from the slideshow,
+ * Fetches all the slide text from the slideshow,
* but not the notes, unless you've called
* setSlidesByDefault() and setNotesByDefault()
* to change this
@@ -162,18 +162,18 @@
return getText(getSlideText, getNoteText, commentsByDefault);
}
public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText) {
- StringBuffer ret = new StringBuffer();
+ StringBuffer ret = new StringBuffer();
if(getSlideText) {
for(int i=0; i<_slides.length; i++) {
Slide slide = _slides[i];
-
+
// Slide header, if set
HeadersFooters hf = slide.getHeadersFooters();
if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
ret.append(hf.getHeaderText() + "\n");
}
-
+
// Slide text
TextRun[] runs = slide.getTextRuns();
for(int j=0; j<runs.length; j++) {
@@ -186,20 +186,20 @@
}
}
}
-
+
// Slide footer, if set
if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
}
-
+
// Comments, if requested and present
if(getCommentText) {
Comment[] comments = slide.getComments();
for(int j=0; j<comments.length; j++) {
ret.append(
- comments[j].getAuthor() +
+ comments[j].getAuthor() +
" - " +
- comments[j].getText() +
+ comments[j].getText() +
"\n"
);
}
@@ -216,14 +216,14 @@
// but ensure no duplicates
HashSet seenNotes = new HashSet();
HeadersFooters hf = _show.getNotesHeadersFooters();
-
+
for(int i=0; i<_slides.length; i++) {
Notes notes = _slides[i].getNotesSheet();
if(notes == null) { continue; }
Integer id = new Integer(notes._getSheetNumber());
if(seenNotes.contains(id)) { continue; }
seenNotes.add(id);
-
+
// Repeat the Notes header, if set
if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
ret.append(hf.getHeaderText() + "\n");
@@ -241,7 +241,7 @@
}
}
}
-
+
// Repeat the notes footer, if set
if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
@@ -251,4 +251,4 @@
return ret.toString();
}
-}
\ No newline at end of file
+}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,8 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.extractor;
@@ -42,12 +39,12 @@
* This class will get all the text from a Powerpoint Document, including
* all the bits you didn't want, and in a somewhat random order, but will
* do it very fast.
- * The class ignores most of the hslf classes, and doesn't use
+ * The class ignores most of the hslf classes, and doesn't use
* HSLFSlideShow. Instead, it just does a very basic scan through the
* file, grabbing all the text records as it goes. It then returns the
* text, either as a single string, or as a vector of all the individual
* strings.
- * Because of how it works, it will return a lot of "crud" text that you
+ * Because of how it works, it will return a lot of "crud" text that you
* probably didn't want! It will return text from master slides. It will
* return duplicate text, and some mangled text (powerpoint files often
* have duplicate copies of slide text in them). You don't get any idea
@@ -59,7 +56,7 @@
* @author Nick Burch
*/
-public class QuickButCruddyTextExtractor
+public final class QuickButCruddyTextExtractor
{
private POIFSFileSystem fs;
private InputStream is;
@@ -193,12 +190,12 @@
TextCharsAtom tca = (TextCharsAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
trun = new TextRun((TextHeaderAtom)null,tca,(StyleTextPropAtom)null);
}
-
+
// CString (doesn't go via a TextRun)
if(type == RecordTypes.CString.typeID) {
CString cs = (CString)Record.createRecordForType(type, pptContents, startPos, len+8);
String text = cs.getText();
-
+
// Ignore the ones we know to be rubbish
if(text.equals("___PPT10")) {
} else if(text.equals("Default Design")) {
@@ -211,10 +208,10 @@
if(trun != null) {
textV.add(trun.getText());
}
-
+
// Wind on by the atom length, and check we're not at the end
int newPos = (startPos + 8 + len);
- if(newPos > (pptContents.length - 8)) {
+ if(newPos > (pptContents.length - 8)) {
newPos = -1;
}
return newPos;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java Thu May 21 18:12:22 2009
@@ -1,169 +1,168 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.record.*;
-import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.util.LittleEndian;
-
-import java.io.ByteArrayOutputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Iterator;
-
-/**
- * Represents an ActiveX control in a PowerPoint document.
- *
- * TODO: finish
- * @author Yegor Kozlov
- */
-public final class ActiveXShape extends Picture {
- public static final int DEFAULT_ACTIVEX_THUMBNAIL = -1;
-
- /**
- * Create a new <code>Picture</code>
- *
- * @param pictureIdx the index of the picture
- */
- public ActiveXShape(int movieIdx, int pictureIdx){
- super(pictureIdx, null);
- setActiveXIndex(movieIdx);
- }
-
- /**
- * Create a <code>Picture</code> object
- *
- * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
- * this picture in the <code>Slide</code>
- * @param parent the parent shape of this picture
- */
- protected ActiveXShape(EscherContainerRecord escherRecord, Shape parent){
- super(escherRecord, parent);
- }
-
- /**
- * Create a new Placeholder and initialize internal structures
- *
- * @return the created <code>EscherContainerRecord</code> which holds shape data
- */
- protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
- _escherContainer = super.createSpContainer(idx, isChild);
-
- EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
- spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE | EscherSpRecord.FLAG_OLESHAPE);
-
- setShapeType(ShapeTypes.HostControl);
- setEscherProperty(EscherProperties.BLIP__PICTUREID, idx);
- setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
- setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);
- setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
- setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, -1);
-
- EscherClientDataRecord cldata = new EscherClientDataRecord();
- cldata.setOptions((short)0xF);
- _escherContainer.addChildRecord(cldata); // TODO unit test to prove getChildRecords().add is wrong
-
- OEShapeAtom oe = new OEShapeAtom();
-
- //convert hslf into ddf
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- oe.writeOut(out);
- } catch(Exception e){
- throw new HSLFException(e);
- }
- cldata.setRemainingData(out.toByteArray());
-
- return _escherContainer;
- }
-
- /**
- * Assign a control to this shape
- *
- * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)
- * @param idx the index of the movie
- */
- public void setActiveXIndex(int idx){
- EscherContainerRecord spContainer = getSpContainer();
- for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
- EscherRecord obj = it.next();
- if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
- EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;
- byte[] recdata = clientRecord.getRemainingData();
- LittleEndian.putInt(recdata, 8, idx);
- }
- }
- }
-
- public int getControlIndex(){
- int idx = -1;
- OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
- if(oe != null) idx = oe.getOptions();
- return idx;
- }
-
- /**
- * Set a property of this ActiveX control
- * @param key
- * @param value
- */
- public void setProperty(String key, String value){
-
- }
-
- /**
- * Document-level container that specifies information about an ActiveX control
- *
- * @return container that specifies information about an ActiveX control
- */
- public ExControl getExControl(){
- int idx = getControlIndex();
- ExControl ctrl = null;
- Document doc = getSheet().getSlideShow().getDocumentRecord();
- ExObjList lst = (ExObjList)doc.findFirstOfType(RecordTypes.ExObjList.typeID);
- if(lst != null){
- Record[] ch = lst.getChildRecords();
- for (int i = 0; i < ch.length; i++) {
- if(ch[i] instanceof ExControl){
- ExControl c = (ExControl)ch[i];
- if(c.getExOleObjAtom().getObjID() == idx){
- ctrl = c;
- break;
- }
- }
- }
- }
- return ctrl;
- }
-
- protected void afterInsert(Sheet sheet){
- ExControl ctrl = getExControl();
- ctrl.getExControlAtom().setSlideId(sheet._getSheetNumber());
-
- try {
- String name = ctrl.getProgId() + "-" + getControlIndex();
- byte[] data = (name + '\u0000').getBytes("UTF-16LE");
- EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
- opt.addEscherProperty(prop);
- } catch (UnsupportedEncodingException e){
- throw new HSLFException(e);
- }
-
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.util.LittleEndian;
+
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+/**
+ * Represents an ActiveX control in a PowerPoint document.
+ *
+ * TODO: finish
+ * @author Yegor Kozlov
+ */
+public final class ActiveXShape extends Picture {
+ public static final int DEFAULT_ACTIVEX_THUMBNAIL = -1;
+
+ /**
+ * Create a new <code>Picture</code>
+ *
+ * @param pictureIdx the index of the picture
+ */
+ public ActiveXShape(int movieIdx, int pictureIdx){
+ super(pictureIdx, null);
+ setActiveXIndex(movieIdx);
+ }
+
+ /**
+ * Create a <code>Picture</code> object
+ *
+ * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
+ * this picture in the <code>Slide</code>
+ * @param parent the parent shape of this picture
+ */
+ protected ActiveXShape(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Create a new Placeholder and initialize internal structures
+ *
+ * @return the created <code>EscherContainerRecord</code> which holds shape data
+ */
+ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
+ _escherContainer = super.createSpContainer(idx, isChild);
+
+ EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+ spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE | EscherSpRecord.FLAG_OLESHAPE);
+
+ setShapeType(ShapeTypes.HostControl);
+ setEscherProperty(EscherProperties.BLIP__PICTUREID, idx);
+ setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+ setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);
+ setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
+ setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, -1);
+
+ EscherClientDataRecord cldata = new EscherClientDataRecord();
+ cldata.setOptions((short)0xF);
+ _escherContainer.addChildRecord(cldata); // TODO unit test to prove getChildRecords().add is wrong
+
+ OEShapeAtom oe = new OEShapeAtom();
+
+ //convert hslf into ddf
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ oe.writeOut(out);
+ } catch(Exception e){
+ throw new HSLFException(e);
+ }
+ cldata.setRemainingData(out.toByteArray());
+
+ return _escherContainer;
+ }
+
+ /**
+ * Assign a control to this shape
+ *
+ * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)
+ * @param idx the index of the movie
+ */
+ public void setActiveXIndex(int idx){
+ EscherContainerRecord spContainer = getSpContainer();
+ for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
+ EscherRecord obj = it.next();
+ if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
+ EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;
+ byte[] recdata = clientRecord.getRemainingData();
+ LittleEndian.putInt(recdata, 8, idx);
+ }
+ }
+ }
+
+ public int getControlIndex(){
+ int idx = -1;
+ OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
+ if(oe != null) idx = oe.getOptions();
+ return idx;
+ }
+
+ /**
+ * Set a property of this ActiveX control
+ * @param key
+ * @param value
+ */
+ public void setProperty(String key, String value){
+
+ }
+
+ /**
+ * Document-level container that specifies information about an ActiveX control
+ *
+ * @return container that specifies information about an ActiveX control
+ */
+ public ExControl getExControl(){
+ int idx = getControlIndex();
+ ExControl ctrl = null;
+ Document doc = getSheet().getSlideShow().getDocumentRecord();
+ ExObjList lst = (ExObjList)doc.findFirstOfType(RecordTypes.ExObjList.typeID);
+ if(lst != null){
+ Record[] ch = lst.getChildRecords();
+ for (int i = 0; i < ch.length; i++) {
+ if(ch[i] instanceof ExControl){
+ ExControl c = (ExControl)ch[i];
+ if(c.getExOleObjAtom().getObjID() == idx){
+ ctrl = c;
+ break;
+ }
+ }
+ }
+ }
+ return ctrl;
+ }
+
+ protected void afterInsert(Sheet sheet){
+ ExControl ctrl = getExControl();
+ ctrl.getExControlAtom().setSlideId(sheet._getSheetNumber());
+
+ try {
+ String name = ctrl.getProgId() + "-" + getControlIndex();
+ byte[] data = (name + '\u0000').getBytes("UTF-16LE");
+ EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ opt.addEscherProperty(prop);
+ } catch (UnsupportedEncodingException e){
+ throw new HSLFException(e);
+ }
+ }
+}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java Thu May 21 18:12:22 2009
@@ -1,380 +1,381 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.EscherProperties;
-
-import java.awt.geom.*;
-
-/**
- * Stores definition of auto-shapes.
- * See the Office Drawing 97-2007 Binary Format Specification for details.
- *
- * TODO: follow the spec and define all the auto-shapes
- *
- * @author Yegor Kozlov
- */
-public class AutoShapes {
- protected static ShapeOutline[] shapes;
-
-
- /**
- * Return shape outline by shape type
- * @param type shape type see {@link ShapeTypes}
- *
- * @return the shape outline
- */
- public static ShapeOutline getShapeOutline(int type){
- ShapeOutline outline = shapes[type];
- return outline;
- }
-
- /**
- * Auto-shapes are defined in the [0,21600] coordinate system.
- * We need to transform it into normal slide coordinates
- *
- */
- public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){
- AffineTransform at = new AffineTransform();
- at.translate(anchor.getX(), anchor.getY());
- at.scale(
- 1.0f/21600*anchor.getWidth(),
- 1.0f/21600*anchor.getHeight()
- );
- return at.createTransformedShape(outline);
- }
-
- static {
- shapes = new ShapeOutline[255];
-
- shapes[ShapeTypes.Rectangle] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);
- return path;
- }
- };
-
- shapes[ShapeTypes.RoundRectangle] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
- RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);
- return path;
- }
- };
-
- shapes[ShapeTypes.Ellipse] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);
- return path;
- }
- };
-
- shapes[ShapeTypes.Diamond] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- GeneralPath path = new GeneralPath();
- path.moveTo(10800, 0);
- path.lineTo(21600, 10800);
- path.lineTo(10800, 21600);
- path.lineTo(0, 10800);
- path.closePath();
- return path;
- }
- };
-
- //m@0,l,21600r21600
- shapes[ShapeTypes.IsocelesTriangle] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(0, 21600);
- path.lineTo(21600, 21600);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.RightTriangle] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- GeneralPath path = new GeneralPath();
- path.moveTo(0, 0);
- path.lineTo(21600, 21600);
- path.lineTo(0, 21600);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Parallelogram] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(21600, 0);
- path.lineTo(21600 - adjval, 21600);
- path.lineTo(0, 21600);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Trapezoid] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(0, 0);
- path.lineTo(adjval, 21600);
- path.lineTo(21600 - adjval, 21600);
- path.lineTo(21600, 0);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Hexagon] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(21600 - adjval, 0);
- path.lineTo(21600, 10800);
- path.lineTo(21600 - adjval, 21600);
- path.lineTo(adjval, 21600);
- path.lineTo(0, 10800);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Octagon] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(21600 - adjval, 0);
- path.lineTo(21600, adjval);
- path.lineTo(21600, 21600-adjval);
- path.lineTo(21600-adjval, 21600);
- path.lineTo(adjval, 21600);
- path.lineTo(0, 21600-adjval);
- path.lineTo(0, adjval);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Plus] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(21600 - adjval, 0);
- path.lineTo(21600 - adjval, adjval);
- path.lineTo(21600, adjval);
- path.lineTo(21600, 21600-adjval);
- path.lineTo(21600-adjval, 21600-adjval);
- path.lineTo(21600-adjval, 21600);
- path.lineTo(adjval, 21600);
- path.lineTo(adjval, 21600-adjval);
- path.lineTo(0, 21600-adjval);
- path.lineTo(0, adjval);
- path.lineTo(adjval, adjval);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Pentagon] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
-
- GeneralPath path = new GeneralPath();
- path.moveTo(10800, 0);
- path.lineTo(21600, 8259);
- path.lineTo(21600 - 4200, 21600);
- path.lineTo(4200, 21600);
- path.lineTo(0, 8259);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.DownArrow] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m0@0 l@1@0 @1,0 @2,0 @2@0,21600@0,10800,21600xe
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
- GeneralPath path = new GeneralPath();
- path.moveTo(0, adjval);
- path.lineTo(adjval2, adjval);
- path.lineTo(adjval2, 0);
- path.lineTo(21600-adjval2, 0);
- path.lineTo(21600-adjval2, adjval);
- path.lineTo(21600, adjval);
- path.lineTo(10800, 21600);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.UpArrow] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m0@0 l@1@0 @1,21600@2,21600@2@0,21600@0,10800,xe
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
- GeneralPath path = new GeneralPath();
- path.moveTo(0, adjval);
- path.lineTo(adjval2, adjval);
- path.lineTo(adjval2, 21600);
- path.lineTo(21600-adjval2, 21600);
- path.lineTo(21600-adjval2, adjval);
- path.lineTo(21600, adjval);
- path.lineTo(10800, 0);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Arrow] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m@0, l@0@1 ,0@1,0@2@0@2@0,21600,21600,10800xe
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(adjval, adjval2);
- path.lineTo(0, adjval2);
- path.lineTo(0, 21600-adjval2);
- path.lineTo(adjval, 21600-adjval2);
- path.lineTo(adjval, 21600);
- path.lineTo(21600, 10800);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.LeftArrow] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m@0, l@0@1,21600@1,21600@2@0@2@0,21600,,10800xe
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
- GeneralPath path = new GeneralPath();
- path.moveTo(adjval, 0);
- path.lineTo(adjval, adjval2);
- path.lineTo(21600, adjval2);
- path.lineTo(21600, 21600-adjval2);
- path.lineTo(adjval, 21600-adjval2);
- path.lineTo(adjval, 21600);
- path.lineTo(0, 10800);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.Can] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
-
- GeneralPath path = new GeneralPath();
-
- path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);
- path.moveTo(0, adjval/2);
-
- path.lineTo(0, 21600 - adjval/2);
- path.closePath();
-
- path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);
- path.moveTo(21600, 21600 - adjval/2);
-
- path.lineTo(21600, adjval/2);
- path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);
- path.moveTo(0, adjval/2);
- path.closePath();
- return path;
- }
- };
-
- shapes[ShapeTypes.LeftBrace] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(21600, 0);
-
- path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
- path.moveTo(10800, adjval);
-
- path.lineTo(10800, adjval2 - adjval);
-
- path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
- path.moveTo(0, adjval2);
-
- path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
- path.moveTo(10800, adjval2 + adjval);
-
- path.lineTo(10800, 21600 - adjval);
-
- path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
-
- return path;
- }
- };
-
- shapes[ShapeTypes.RightBrace] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- //m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
-
- GeneralPath path = new GeneralPath();
- path.moveTo(0, 0);
-
- path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
- path.moveTo(10800, adjval);
-
- path.lineTo(10800, adjval2 - adjval);
-
- path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
- path.moveTo(21600, adjval2);
-
- path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
- path.moveTo(10800, adjval2 + adjval);
-
- path.lineTo(10800, 21600 - adjval);
-
- path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
-
- return path;
- }
- };
-
- shapes[ShapeTypes.StraightConnector1] = new ShapeOutline(){
- public java.awt.Shape getOutline(Shape shape){
- return new Line2D.Float(0, 0, 21600, 21600);
- }
- };
-
-
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.EscherProperties;
+
+import java.awt.geom.*;
+
+/**
+ * Stores definition of auto-shapes.
+ * See the Office Drawing 97-2007 Binary Format Specification for details.
+ *
+ * TODO: follow the spec and define all the auto-shapes
+ *
+ * @author Yegor Kozlov
+ */
+public final class AutoShapes {
+ protected static ShapeOutline[] shapes;
+
+
+ /**
+ * Return shape outline by shape type
+ * @param type shape type see {@link ShapeTypes}
+ *
+ * @return the shape outline
+ */
+ public static ShapeOutline getShapeOutline(int type){
+ ShapeOutline outline = shapes[type];
+ return outline;
+ }
+
+ /**
+ * Auto-shapes are defined in the [0,21600] coordinate system.
+ * We need to transform it into normal slide coordinates
+ *
+ */
+ public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){
+ AffineTransform at = new AffineTransform();
+ at.translate(anchor.getX(), anchor.getY());
+ at.scale(
+ 1.0f/21600*anchor.getWidth(),
+ 1.0f/21600*anchor.getHeight()
+ );
+ return at.createTransformedShape(outline);
+ }
+
+ static {
+ shapes = new ShapeOutline[255];
+
+ shapes[ShapeTypes.Rectangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RoundRectangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Ellipse] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Diamond] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ GeneralPath path = new GeneralPath();
+ path.moveTo(10800, 0);
+ path.lineTo(21600, 10800);
+ path.lineTo(10800, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ //m@0,l,21600r21600
+ shapes[ShapeTypes.IsocelesTriangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(0, 21600);
+ path.lineTo(21600, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RightTriangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+ path.lineTo(21600, 21600);
+ path.lineTo(0, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Parallelogram] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600, 0);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(0, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Trapezoid] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+ path.lineTo(adjval, 21600);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(21600, 0);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Hexagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600, 10800);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Octagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600, adjval);
+ path.lineTo(21600, 21600-adjval);
+ path.lineTo(21600-adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 21600-adjval);
+ path.lineTo(0, adjval);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Plus] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600 - adjval, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(21600, 21600-adjval);
+ path.lineTo(21600-adjval, 21600-adjval);
+ path.lineTo(21600-adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(adjval, 21600-adjval);
+ path.lineTo(0, 21600-adjval);
+ path.lineTo(0, adjval);
+ path.lineTo(adjval, adjval);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Pentagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(10800, 0);
+ path.lineTo(21600, 8259);
+ path.lineTo(21600 - 4200, 21600);
+ path.lineTo(4200, 21600);
+ path.lineTo(0, 8259);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.DownArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m0@0 l@1@0 @1,0 @2,0 @2@0,21600@0,10800,21600xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, adjval);
+ path.lineTo(adjval2, adjval);
+ path.lineTo(adjval2, 0);
+ path.lineTo(21600-adjval2, 0);
+ path.lineTo(21600-adjval2, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(10800, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.UpArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m0@0 l@1@0 @1,21600@2,21600@2@0,21600@0,10800,xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, adjval);
+ path.lineTo(adjval2, adjval);
+ path.lineTo(adjval2, 21600);
+ path.lineTo(21600-adjval2, 21600);
+ path.lineTo(21600-adjval2, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(10800, 0);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Arrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m@0, l@0@1 ,0@1,0@2@0@2@0,21600,21600,10800xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(adjval, adjval2);
+ path.lineTo(0, adjval2);
+ path.lineTo(0, 21600-adjval2);
+ path.lineTo(adjval, 21600-adjval2);
+ path.lineTo(adjval, 21600);
+ path.lineTo(21600, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.LeftArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m@0, l@0@1,21600@1,21600@2@0@2@0,21600,,10800xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(adjval, adjval2);
+ path.lineTo(21600, adjval2);
+ path.lineTo(21600, 21600-adjval2);
+ path.lineTo(adjval, 21600-adjval2);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Can] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);
+ path.moveTo(0, adjval/2);
+
+ path.lineTo(0, 21600 - adjval/2);
+ path.closePath();
+
+ path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);
+ path.moveTo(21600, 21600 - adjval/2);
+
+ path.lineTo(21600, adjval/2);
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);
+ path.moveTo(0, adjval/2);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.LeftBrace] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(21600, 0);
+
+ path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval);
+
+ path.lineTo(10800, adjval2 - adjval);
+
+ path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
+ path.moveTo(0, adjval2);
+
+ path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval2 + adjval);
+
+ path.lineTo(10800, 21600 - adjval);
+
+ path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
+
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RightBrace] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+
+ path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval);
+
+ path.lineTo(10800, adjval2 - adjval);
+
+ path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
+ path.moveTo(21600, adjval2);
+
+ path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval2 + adjval);
+
+ path.lineTo(10800, 21600 - adjval);
+
+ path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
+
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.StraightConnector1] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ return new Line2D.Float(0, 0, 21600, 21600);
+ }
+ };
+
+
+ }
+}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Background.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Background.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Background.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Background.java Thu May 21 18:12:22 2009
@@ -29,10 +29,10 @@
/**
* Background shape
- *
+ *
* @author Yegor Kozlov
*/
-public class Background extends Shape {
+public final class Background extends Shape {
protected Background(EscherContainerRecord escherRecord, Shape parent) {
super(escherRecord, parent);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java Thu May 21 18:12:22 2009
@@ -20,7 +20,7 @@
import org.apache.poi.hslf.record.Comment2000;
/**
- *
+ *
* @author Nick Burch
*/
public final class Comment {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java?rev=777204&r1=777203&r2=777204&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java Thu May 21 18:12:22 2009
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -32,7 +31,7 @@
*
* @author Yegor Kozlov
*/
-public class Fill {
+public final class Fill {
// For logging
protected POILogger logger = POILogFactory.getLogger(this.getClass());
@@ -229,7 +228,7 @@
/**
* Assign picture used to fill the underlying shape.
*
- * @param idx 0-based index of the picture added to this ppt by <code>SlideShow.addPicture</code> method.
+ * @param idx 0-based index of the picture added to this ppt by <code>SlideShow.addPicture</code> method.
*/
public void setPictureData(int idx){
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org