diff --git a/src/java/org/apache/poi/hpsf/ClassIDPredefined.java b/src/java/org/apache/poi/hpsf/ClassIDPredefined.java index 1974c3164d..9e1c5a4a28 100644 --- a/src/java/org/apache/poi/hpsf/ClassIDPredefined.java +++ b/src/java/org/apache/poi/hpsf/ClassIDPredefined.java @@ -92,7 +92,13 @@ public enum ClassIDPredefined { /** URL Moniker **/ URL_MONIKER ("{79EAC9E0-BAF9-11CE-8C82-00AA004BA90B}", null, null), /** File Moniker **/ - FILE_MONIKER ("{00000303-0000-0000-C000-000000000046}", null, null) + FILE_MONIKER ("{00000303-0000-0000-C000-000000000046}", null, null), + /** Document summary information first property section **/ + DOC_SUMMARY ("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}", null, null), + /** Document summary information user defined properties section **/ + USER_PROPERTIES ("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", null, null), + /** Summary information property section **/ + SUMMARY_PROPERTIES ("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", null, null); ; diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index cb945a36ed..07c09a7579 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -17,9 +17,11 @@ package org.apache.poi.hpsf; +import static org.apache.poi.hpsf.ClassIDPredefined.DOC_SUMMARY; +import static org.apache.poi.hpsf.ClassIDPredefined.USER_PROPERTIES; + import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -32,6 +34,7 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap; * * @see SummaryInformation */ +@SuppressWarnings("unused") public class DocumentSummaryInformation extends PropertySet { /** @@ -44,15 +47,10 @@ public class DocumentSummaryInformation extends PropertySet { /** * The DocumentSummaryInformation's first and second sections' format ID. */ - private static final ClassID DOC_SUMMARY_INFORMATION = - new ClassID("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"); - private static final ClassID USER_DEFINED_PROPERTIES = - new ClassID("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); - public static final ClassID[] FORMAT_ID = { - DOC_SUMMARY_INFORMATION, USER_DEFINED_PROPERTIES + DOC_SUMMARY.getClassID(), USER_PROPERTIES.getClassID() }; - + @Override public PropertyIDMap getPropertySetIDMap() { return PropertyIDMap.getDocumentSummaryInformationProperties(); @@ -63,10 +61,10 @@ public class DocumentSummaryInformation extends PropertySet { * Creates an empty {@link DocumentSummaryInformation}. */ public DocumentSummaryInformation() { - getFirstSection().setFormatID(DOC_SUMMARY_INFORMATION); + getFirstSection().setFormatID(DOC_SUMMARY.getClassID()); } - + /** * Creates a {@link DocumentSummaryInformation} from a given * {@link PropertySet}. @@ -97,20 +95,16 @@ public class DocumentSummaryInformation extends PropertySet { * * @param stream Holds the data making out the property set * stream. - * @throws MarkUnsupportedException - * if the stream does not support the {@link InputStream#markSupported} method. * @throws IOException * if the {@link InputStream} cannot be accessed as needed. * @exception NoPropertySetStreamException * if the input stream does not contain a property set. - * @exception UnsupportedEncodingException - * if a character encoding is not supported. */ public DocumentSummaryInformation(final InputStream stream) - throws NoPropertySetStreamException, MarkUnsupportedException, IOException, UnsupportedEncodingException { + throws NoPropertySetStreamException, IOException { super(stream); } - + /** * Returns the category (or {@code null}). * @@ -531,10 +525,10 @@ public class DocumentSummaryInformation extends PropertySet { public void removeLinksDirty() { remove1stProperty(PropertyIDMap.PID_LINKSDIRTY); } - - + + /** - * Returns the character count including whitespace, or 0 if the + * Returns the character count including whitespace, or 0 if the * {@link DocumentSummaryInformation} does not contain this char count. *

This is the whitespace-including version of {@link SummaryInformation#getCharCount()} * @@ -546,42 +540,42 @@ public class DocumentSummaryInformation extends PropertySet { /** * Sets the character count including whitespace - * + * * @param count The character count to set. */ public void setCharCountWithSpaces(int count) { set1stProperty(PropertyIDMap.PID_CCHWITHSPACES, count); } - + /** * Removes the character count */ public void removeCharCountWithSpaces() { remove1stProperty(PropertyIDMap.PID_CCHWITHSPACES); } - - + + /** - * Get if the User Defined Property Set has been updated outside of the + * Get if the User Defined Property Set has been updated outside of the * Application.

* If it has (true), the hyperlinks should be updated on document load. - * + * * @return true, if the hyperlinks should be updated on document load */ public boolean getHyperlinksChanged() { return getPropertyBooleanValue(PropertyIDMap.PID_HYPERLINKSCHANGED); } - + /** - * Set the flag for if the User Defined Property Set has been updated outside + * Set the flag for if the User Defined Property Set has been updated outside * of the Application. - * + * * @param changed true, if the User Defined Property Set has been updated */ public void setHyperlinksChanged(boolean changed) { set1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED, changed); } - + /** * Removes the flag for if the User Defined Property Set has been updated * outside of the Application. @@ -590,30 +584,30 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED); } - + /** * Gets the version of the Application which wrote the * Property set, stored with the two high order bytes having the major * version number, and the two low order bytes the minor version number.

* This will be 0 if no version is set. - * + * * @return the Application version */ public int getApplicationVersion() { return getPropertyIntValue(PropertyIDMap.PID_VERSION); } - + /** * Sets the Application version, which must be a 4 byte int with - * the two high order bytes having the major version number, and the + * the two high order bytes having the major version number, and the * two low order bytes the minor version number. - * + * * @param version the Application version */ public void setApplicationVersion(int version) { set1stProperty(PropertyIDMap.PID_VERSION, version); } - + /** * Removes the Application Version */ @@ -621,31 +615,28 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_VERSION); } - + /** - * Returns the VBA digital signature for the VBA project + * Returns the VBA digital signature for the VBA project * embedded in the document (or {@code null}). - * + * * @return the VBA digital signature */ public byte[] getVBADigitalSignature() { Object value = getProperty(PropertyIDMap.PID_DIGSIG); - if (value != null && value instanceof byte[]) { - return (byte[])value; - } - return null; + return (value instanceof byte[]) ? (byte[])value : null; } - + /** - * Sets the VBA digital signature for the VBA project + * Sets the VBA digital signature for the VBA project * embedded in the document. - * + * * @param signature VBA Digital Signature for the project */ public void setVBADigitalSignature(byte[] signature) { set1stProperty(PropertyIDMap.PID_DIGSIG, signature); } - + /** * Removes the VBA Digital Signature */ @@ -653,25 +644,25 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_DIGSIG); } - + /** * Gets the content type of the file (or {@code null}). - * + * * @return the content type of the file */ public String getContentType() { return getPropertyStringValue(PropertyIDMap.PID_CONTENTTYPE); } - + /** * Sets the content type of the file - * + * * @param type the content type of the file */ public void setContentType(String type) { set1stProperty(PropertyIDMap.PID_CONTENTTYPE, type); } - + /** * Removes the content type of the file */ @@ -679,25 +670,25 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_CONTENTTYPE); } - + /** * Gets the content status of the file (or {@code null}). - * + * * @return the content status of the file */ public String getContentStatus() { return getPropertyStringValue(PropertyIDMap.PID_CONTENTSTATUS); } - + /** * Sets the content status of the file - * + * * @param status the content status of the file */ public void setContentStatus(String status) { set1stProperty(PropertyIDMap.PID_CONTENTSTATUS, status); } - + /** * Removes the content status of the file */ @@ -705,25 +696,25 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_CONTENTSTATUS); } - + /** * Gets the document language, which is normally unset and empty (or {@code null}). - * + * * @return the document language */ public String getLanguage() { return getPropertyStringValue(PropertyIDMap.PID_LANGUAGE); } - + /** * Set the document language - * + * * @param language the document language */ public void setLanguage(String language) { set1stProperty(PropertyIDMap.PID_LANGUAGE, language); } - + /** * Removes the document language */ @@ -731,26 +722,26 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_LANGUAGE); } - + /** * Gets the document version as a string, which is normally unset and empty * (or {@code null}). - * + * * @return the document verion */ public String getDocumentVersion() { return getPropertyStringValue(PropertyIDMap.PID_DOCVERSION); } - + /** * Sets the document version string - * + * * @param version the document version string */ public void setDocumentVersion(String version) { set1stProperty(PropertyIDMap.PID_DOCVERSION, version); } - + /** * Removes the document version string */ @@ -758,7 +749,7 @@ public class DocumentSummaryInformation extends PropertySet { remove1stProperty(PropertyIDMap.PID_DOCVERSION); } - + /** * Gets the custom properties. * @@ -824,7 +815,7 @@ public class DocumentSummaryInformation extends PropertySet { private void ensureSection2() { if (getSectionCount() < 2) { Section s2 = new Section(); - s2.setFormatID(USER_DEFINED_PROPERTIES); + s2.setFormatID(USER_PROPERTIES.getClassID()); addSection(s2); } } @@ -846,7 +837,7 @@ public class DocumentSummaryInformation extends PropertySet { } } } - + /** * Throws an {@link UnsupportedOperationException} with a message text * telling which functionality is not yet implemented. diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index 70c0a1bf16..fe98e4121e 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -62,7 +62,7 @@ import org.apache.poi.util.Removal; * #getSections} to retrieve the {@link Section}s, then call {@link * Section#getProperties} for each {@link Section} to get hold of the * {@link Property} arrays.

- * + * * Since the vast majority of {@link PropertySet}s contains only a single * {@link Section}, the convenience method {@link #getProperties} returns * the properties of a {@link PropertySet}'s {@link Section} (throwing a @@ -108,7 +108,7 @@ public class PropertySet { ClassID.LENGTH + /* Class ID */ LittleEndianConsts.INT_SIZE; /* Section count */ - + /** * Specifies this {@link PropertySet}'s byte order. See the * HPFS documentation for details! @@ -120,7 +120,7 @@ public class PropertySet { * documentation for details! */ private int format; - + /** * Specifies the version of the operating system that created this * {@link PropertySet}. See the HPFS documentation for details! @@ -138,7 +138,7 @@ public class PropertySet { */ private final List

sections = new ArrayList<>(); - + /** * Constructs a {@code PropertySet} instance. Its * primary task is to initialize the field with their proper values. @@ -190,7 +190,7 @@ public class PropertySet { if (!isPropertySetStream(stream)) { throw new NoPropertySetStreamException(); } - + final byte[] buffer = IOUtils.toByteArray(stream); init(buffer, 0, buffer.length); } @@ -208,7 +208,7 @@ public class PropertySet { * @param length The length of the stream data. * @throws NoPropertySetStreamException if the byte array is not a * property set stream. - * + * * @exception UnsupportedEncodingException if the codepage is not supported. */ public PropertySet(final byte[] stream, final int offset, final int length) @@ -227,14 +227,14 @@ public class PropertySet { * complete byte array contents is the stream data. * @throws NoPropertySetStreamException if the byte array is not a * property set stream. - * + * * @exception UnsupportedEncodingException if the codepage is not supported. */ public PropertySet(final byte[] stream) throws NoPropertySetStreamException, UnsupportedEncodingException { this(stream, 0, stream.length); } - + /** * Constructs a {@code PropertySet} by doing a deep copy of * an existing {@code PropertySet}. All nested elements, i.e. @@ -253,7 +253,7 @@ public class PropertySet { } } - + /** * @return The property set stream's low-level "byte order" field. It is always {@code 0xFFFE}. */ @@ -321,7 +321,7 @@ public class PropertySet { public void setClassID(ClassID classID) { this.classID = classID; } - + /** * @return The number of {@link Section}s in the property set. */ @@ -348,24 +348,24 @@ public class PropertySet { public void addSection(final Section section) { sections.add(section); } - + /** * Removes all sections from this property set. */ public void clearSections() { sections.clear(); } - + /** * The id to name mapping of the properties in this set. - * + * * @return the id to name mapping of the properties in this set or {@code null} if not applicable */ public PropertyIDMap getPropertySetIDMap() { return null; } - + /** * Checks whether an {@link InputStream} is in the Horrible * Property Set Format. @@ -427,11 +427,9 @@ public class PropertySet { return false; } final long osVersion = leis.readUInt(); - byte[] clsBuf = new byte[ClassID.LENGTH]; - leis.readFully(clsBuf); - - final ClassID classID = new ClassID(clsBuf, 0); - + if (leis.skip(ClassID.LENGTH) != ClassID.LENGTH) { + return false; + } final long sectionCount = leis.readUInt(); return (sectionCount >= 0); } catch (RuntimeException e) { @@ -482,7 +480,7 @@ public class PropertySet { * consists of a format ID telling what the section contains * and an offset telling how many bytes from the start of the * stream the section begins. - * + * * Most property sets have only one section. The Document * Summary Information stream has 2. Everything else is a rare * exception and is no longer fostered by Microsoft. @@ -608,9 +606,9 @@ public class PropertySet { /** * Fetches the property with the given ID, then does its * best to return it as a String - * + * * @param propertyId the property id - * + * * @return The property as a String, or null if unavailable */ String getPropertyStringValue(final int propertyId) { @@ -620,9 +618,9 @@ public class PropertySet { /** * Return the string representation of a property value - * + * * @param propertyValue the property value - * + * * @return The property value as a String, or null if unavailable */ public static String getPropertyStringValue(final Object propertyValue) { @@ -633,7 +631,7 @@ public class PropertySet { if (propertyValue instanceof String) { return (String)propertyValue; } - + // Do our best with some edge cases if (propertyValue instanceof byte[]) { byte[] b = (byte[])propertyValue; @@ -666,7 +664,7 @@ public class PropertySet { * represents a Summary Information, else {@code false}. */ public boolean isSummaryInformation() { - return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), SummaryInformation.FORMAT_ID); + return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), SummaryInformation.FORMAT_ID); } /** @@ -676,9 +674,9 @@ public class PropertySet { * represents a Document Summary Information, else {@code false}. */ public boolean isDocumentSummaryInformation() { - return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), DocumentSummaryInformation.FORMAT_ID); + return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), DocumentSummaryInformation.FORMAT_ID); } - + /* package */ static boolean matchesSummary(ClassID actual, ClassID... expected) { for (ClassID sum : expected) { if (sum.equals(actual) || sum.equalsInverted(actual)) { @@ -816,7 +814,7 @@ public class PropertySet { * to the specified parameter, else {@code false}. * * @param o the object to compare this {@code PropertySet} with - * + * * @return {@code true} if the objects are equal, {@code false} * if not */ @@ -888,7 +886,7 @@ public class PropertySet { b.append(']'); return b.toString(); } - + void remove1stProperty(long id) { getFirstSection().removeProperty(id); @@ -897,20 +895,20 @@ public class PropertySet { void set1stProperty(long id, String value) { getFirstSection().setProperty((int)id, value); } - + void set1stProperty(long id, int value) { getFirstSection().setProperty((int)id, value); } - + void set1stProperty(long id, boolean value) { getFirstSection().setProperty((int)id, value); } - + @SuppressWarnings("SameParameterValue") void set1stProperty(long id, byte[] value) { getFirstSection().setProperty((int)id, value); } - + private static void putClassId(final ByteArrayOutputStream out, final ClassID n) { byte[] b = new byte[16]; n.write(b, 0); diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java index bab1963b1c..4c85b8fda8 100644 --- a/src/java/org/apache/poi/hpsf/SummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java @@ -17,6 +17,8 @@ package org.apache.poi.hpsf; +import static org.apache.poi.hpsf.ClassIDPredefined.SUMMARY_PROPERTIES; + import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; @@ -40,8 +42,7 @@ public final class SummaryInformation extends PropertySet { /** * The SummaryInformation's section's format ID. */ - public static final ClassID FORMAT_ID = - new ClassID("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"); + public static final ClassID FORMAT_ID = SUMMARY_PROPERTIES.getClassID(); @Override public PropertyIDMap getPropertySetIDMap() { @@ -54,7 +55,7 @@ public final class SummaryInformation extends PropertySet { public SummaryInformation() { getFirstSection().setFormatID(FORMAT_ID); } - + /** * Creates a {@link SummaryInformation} from a given {@link * PropertySet}. @@ -98,7 +99,7 @@ public final class SummaryInformation extends PropertySet { super(stream); } - + /** * @return The title or {@code null} */ @@ -315,7 +316,7 @@ public final class SummaryInformation extends PropertySet { /** - * Returns the revision number (or {@code null}). + * Returns the revision number (or {@code null}). * * @return The revision number or {@code null} */ @@ -582,7 +583,7 @@ public final class SummaryInformation extends PropertySet { * change!

* * To process this data, you may wish to make use of the - * {@link Thumbnail} class. The raw data is generally + * {@link Thumbnail} class. The raw data is generally * an image in WMF or Clipboard (BMP?) format * * @return The thumbnail or {@code null} diff --git a/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java index adba13d520..66d39ad702 100644 --- a/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java +++ b/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java @@ -104,7 +104,7 @@ public class EmbeddedExtractor implements Iterable { extractAll(patriarch, embeddings); return embeddings; } - + protected void extractAll(ShapeContainer parent, List embeddings) throws IOException { for (Shape shape : parent) { EmbeddedData data = null; @@ -124,7 +124,7 @@ public class EmbeddedExtractor implements Iterable { } else if (shape instanceof ShapeContainer) { extractAll((ShapeContainer)shape, embeddings); } - + if (data == null) { continue; } @@ -132,7 +132,7 @@ public class EmbeddedExtractor implements Iterable { data.setShape(shape); String filename = data.getFilename(); String extension = (filename == null || filename.lastIndexOf('.') == -1) ? ".bin" : filename.substring(filename.lastIndexOf('.')); - + // try to find an alternative name if (filename == null || filename.isEmpty() || filename.startsWith("MBD") || filename.startsWith("Root Entry")) { filename = shape.getShapeName(); @@ -146,11 +146,11 @@ public class EmbeddedExtractor implements Iterable { } filename = filename.trim(); data.setFilename(filename); - + embeddings.add(data); } } - + public boolean canExtract(DirectoryNode source) { return false; @@ -175,7 +175,7 @@ public class EmbeddedExtractor implements Iterable { protected EmbeddedData extract(Picture source) throws IOException { return null; } - + public static class Ole10Extractor extends EmbeddedExtractor { @Override public boolean canExtract(DirectoryNode dn) { @@ -196,11 +196,10 @@ public class EmbeddedExtractor implements Iterable { } static class PdfExtractor extends EmbeddedExtractor { - static ClassID PdfClassID = new ClassID("{B801CA65-A1FC-11D0-85AD-444553540000}"); @Override public boolean canExtract(DirectoryNode dn) { ClassID clsId = dn.getStorageClsid(); - return (PdfClassID.equals(clsId) || dn.hasEntry("CONTENTS")); + return (ClassIDPredefined.PDF.equals(clsId) || dn.hasEntry("CONTENTS")); } @Override @@ -211,7 +210,7 @@ public class EmbeddedExtractor implements Iterable { return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF); } } - + @Override public boolean canExtract(Picture source) { PictureData pd = source.getPictureData(); @@ -239,12 +238,12 @@ public class EmbeddedExtractor implements Iterable { if (idxStart == -1) { return null; } - + int idxEnd = indexOf(pictureBytes, idxStart, "%%EOF".getBytes(LocaleUtil.CHARSET_1252)); if (idxEnd == -1) { return null; } - + int pictureBytesLen = idxEnd-idxStart+6; byte[] pdfBytes = IOUtils.safelyAllocate(pictureBytesLen, MAX_RECORD_LENGTH); System.arraycopy(pictureBytes, idxStart, pdfBytes, 0, pictureBytesLen); @@ -254,7 +253,7 @@ public class EmbeddedExtractor implements Iterable { } return new EmbeddedData(filename, pdfBytes, CONTENT_TYPE_PDF); } - + } @@ -271,12 +270,12 @@ public class EmbeddedExtractor implements Iterable { String contentType = null; String ext = null; - + if (clsId != null) { contentType = clsId.getContentType(); ext = clsId.getFileExtension(); } - + if (contentType == null || ext == null) { contentType = "application/zip"; ext = ".zip"; @@ -285,7 +284,7 @@ public class EmbeddedExtractor implements Iterable { DocumentInputStream dis = dn.createDocumentInputStream("package"); byte[] data = IOUtils.toByteArray(dis); dis.close(); - + return new EmbeddedData(dn.getName()+ext, data, contentType); } } @@ -295,7 +294,7 @@ public class EmbeddedExtractor implements Iterable { public boolean canExtract(DirectoryNode dn) { return canExtractExcel(dn) || canExtractWord(dn); } - + protected boolean canExtractExcel(DirectoryNode dn) { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); return (ClassIDPredefined.EXCEL_V7 == clsId @@ -309,7 +308,7 @@ public class EmbeddedExtractor implements Iterable { || ClassIDPredefined.WORD_V8 == clsId || dn.hasEntry("WordDocument")); } - + @Override public EmbeddedData extract(DirectoryNode dn) throws IOException { EmbeddedData ed = super.extract(dn); @@ -320,7 +319,7 @@ public class EmbeddedExtractor implements Iterable { ed.setFilename(dn.getName() + ".doc"); ed.setContentType(CONTENT_TYPE_DOC); } - + return ed; } } @@ -338,7 +337,7 @@ public class EmbeddedExtractor implements Iterable { return ed; } } - + protected static void copyNodes(DirectoryNode src, DirectoryNode dest) throws IOException { for (Entry e : src) { if (e instanceof DirectoryNode) { @@ -353,8 +352,8 @@ public class EmbeddedExtractor implements Iterable { } } } - - + + /** * Knuth-Morris-Pratt Algorithm for Pattern Matching @@ -401,5 +400,5 @@ public class EmbeddedExtractor implements Iterable { return failure; } - + } diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java index ebe819155f..d323f86106 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfWindowing.java @@ -262,8 +262,11 @@ public class HwmfWindowing { public void draw(HwmfGraphics ctx) { final HwmfDrawProperties prop = ctx.getProperties(); Rectangle2D old = prop.getWindow(); - double oldW = (old == null ? 0 : old.getWidth()); - double oldH = (old == null ? 0 : old.getHeight()); + double oldW = 0, oldH = 0; + if (old != null) { + oldW = old.getWidth(); + oldH = old.getHeight(); + } if (oldW != size.getWidth() || oldH != size.getHeight()) { prop.setWindowExt(size.getWidth(), size.getHeight()); ctx.updateWindowMapMode(); @@ -521,7 +524,7 @@ public class HwmfWindowing { public void draw(HwmfGraphics ctx) { ctx.setClip(normalizeBounds(bounds), HwmfRegionMode.RGN_DIFF, false); } - + @Override public String toString() { return GenericRecordJsonWriter.marshal(this); @@ -561,7 +564,7 @@ public class HwmfWindowing { public void draw(HwmfGraphics ctx) { ctx.setClip(bounds, HwmfRegionMode.RGN_AND, false); } - + @Override public String toString() { return GenericRecordJsonWriter.marshal(this); @@ -736,7 +739,7 @@ public class HwmfWindowing { // lower-right corner of the rectangle. double bottom = leis.readShort(); bounds.setRect(left, top, right-left, bottom-top); - + int size = 9*LittleEndianConsts.SHORT_SIZE+LittleEndianConsts.INT_SIZE; scanObjects = new WmfScanObject[scanCount]; @@ -751,7 +754,7 @@ public class HwmfWindowing { public void draw(HwmfGraphics ctx) { ctx.addObjectTableEntry(this); } - + @Override public void applyObject(HwmfGraphics ctx) { Rectangle2D lastRect = null; @@ -768,7 +771,7 @@ public class HwmfWindowing { count++; } } - + Shape region = null; if (count > 0) { region = (count == 1) ? lastRect : scanLines;