poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1848906 [2/3] - in /poi/branches/hemf: ./ src/examples/src/org/apache/poi/xslf/usermodel/ src/examples/src/org/apache/poi/xwpf/usermodel/examples/ src/integrationtest/org/apache/poi/ src/integrationtest/org/apache/poi/stress/ src/java/org/...
Date Fri, 14 Dec 2018 00:44:41 GMT
Modified: poi/branches/hemf/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java Fri Dec 14 00:44:40 2018
@@ -59,6 +59,7 @@ public final class SheetNameFormatter {
      * @param rawSheetName - sheet name
      * @deprecated use <code>appendFormat(StringBuilder out, String rawSheetName)</code> instead
 	 */
+	@Deprecated
 	public static void appendFormat(StringBuffer out, String rawSheetName) {
 		boolean needsQuotes = needsDelimiting(rawSheetName);
 		if(needsQuotes) {
@@ -73,6 +74,7 @@ public final class SheetNameFormatter {
     /**
      * @deprecated use <code>appendFormat(StringBuilder out, String workbookName, String rawSheetName)</code> instead
      */
+    @Deprecated
 	public static void appendFormat(StringBuffer out, String workbookName, String rawSheetName) {
 		boolean needsQuotes = needsDelimiting(workbookName) || needsDelimiting(rawSheetName);
 		if(needsQuotes) {
@@ -123,7 +125,7 @@ public final class SheetNameFormatter {
 		}
 	}
 
-    private static void appendAndEscape(Appendable sb, String rawSheetName) {
+    static void appendAndEscape(Appendable sb, String rawSheetName) {
         int len = rawSheetName.length();
         for(int i=0; i<len; i++) {
             char ch = rawSheetName.charAt(i);
@@ -139,7 +141,12 @@ public final class SheetNameFormatter {
         }
     }
 
-	private static boolean needsDelimiting(String rawSheetName) {
+	/**
+	 * Tell if the given raw sheet name needs screening/delimiting.
+	 * @param rawSheetName the sheet name.
+	 * @return true if the given raw sheet name needs screening/delimiting, false otherwise.
+	 */
+	static boolean needsDelimiting(String rawSheetName) {
 		int len = rawSheetName.length();
 		if(len < 1) {
 			throw new RuntimeException("Zero length string is an invalid sheet name");

Modified: poi/branches/hemf/src/java/org/apache/poi/ss/formula/functions/MatrixFunction.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/ss/formula/functions/MatrixFunction.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/ss/formula/functions/MatrixFunction.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/ss/formula/functions/MatrixFunction.java Fri Dec 14 00:44:40 2018
@@ -63,7 +63,7 @@ public abstract class MatrixFunction imp
                     i = 0;
                     j++;
                 }
-                matrix[j][i++] = aVector;
+                if (j < matrix.length) matrix[j][i++] = aVector;
             }
         }
         

Modified: poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.ptg;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.formula.SheetIdentifier;
 import org.apache.poi.ss.formula.SheetNameFormatter;
+import org.apache.poi.ss.formula.SheetRangeAndWorkbookIndexFormatter;
 import org.apache.poi.ss.formula.SheetRangeIdentifier;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.util.LittleEndianOutput;
@@ -102,16 +103,8 @@ public final class Area3DPxg extends Are
     
     public String toFormulaString() {
         StringBuilder sb = new StringBuilder(64);
-        if (externalWorkbookNumber >= 0) {
-            sb.append('[');
-            sb.append(externalWorkbookNumber);
-            sb.append(']');
-        }
-        SheetNameFormatter.appendFormat(sb, firstSheetName);
-        if (lastSheetName != null) {
-            sb.append(':');
-            SheetNameFormatter.appendFormat(sb, lastSheetName);
-        }
+
+        SheetRangeAndWorkbookIndexFormatter.format(sb, externalWorkbookNumber, firstSheetName, lastSheetName);
         sb.append('!');
         sb.append(formatReferenceAsString());
         return sb.toString();

Modified: poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java Fri Dec 14 00:44:40 2018
@@ -18,7 +18,7 @@
 package org.apache.poi.ss.formula.ptg;
 
 import org.apache.poi.ss.formula.SheetIdentifier;
-import org.apache.poi.ss.formula.SheetNameFormatter;
+import org.apache.poi.ss.formula.SheetRangeAndWorkbookIndexFormatter;
 import org.apache.poi.ss.formula.SheetRangeIdentifier;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.LittleEndianOutput;
@@ -101,18 +101,8 @@ public final class Ref3DPxg extends RefP
 
     public String toFormulaString() {
         StringBuilder sb = new StringBuilder(64);
-        if (externalWorkbookNumber >= 0) {
-            sb.append('[');
-            sb.append(externalWorkbookNumber);
-            sb.append(']');
-        }
-        if (firstSheetName != null) {
-            SheetNameFormatter.appendFormat(sb, firstSheetName);
-        }
-        if (lastSheetName != null) {
-            sb.append(':');
-            SheetNameFormatter.appendFormat(sb, lastSheetName);
-        }
+
+        SheetRangeAndWorkbookIndexFormatter.format(sb, externalWorkbookNumber, firstSheetName, lastSheetName);
         sb.append('!');
         sb.append(formatReferenceAsString());
         return sb.toString();

Modified: poi/branches/hemf/src/java/org/apache/poi/util/RecordFormatException.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/util/RecordFormatException.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/util/RecordFormatException.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/util/RecordFormatException.java Fri Dec 14 00:44:40 2018
@@ -45,8 +45,8 @@ public class RecordFormatException
      * be thrown.  If assertTrue is <code>false</code>, this will throw this
      * exception with the message.
      *
-     * @param assertTrue
-     * @param message
+     * @param assertTrue If false, the exception is thrown, if true, no action is performed
+     * @param message The message to include in the thrown exception
      */
     public static void check(boolean assertTrue, String message) {
         if (! assertTrue) {

Modified: poi/branches/hemf/src/java/org/apache/poi/util/StringUtil.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/util/StringUtil.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/util/StringUtil.java Fri Dec 14 00:44:40 2018
@@ -698,7 +698,7 @@ public class StringUtil {
         final String prefix;
 
         // #61881 - for now we only check the first char
-        if (len > 0 && string[offset] == 0 && string[offset+1] == 0) {
+        if (len > 0 && offset < (string.length - 1) && string[offset] == 0 && string[offset+1] == 0) {
             newOffset = offset+2;
             prefix = "?";
 

Modified: poi/branches/hemf/src/java/org/apache/poi/util/Units.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/java/org/apache/poi/util/Units.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/java/org/apache/poi/util/Units.java (original)
+++ poi/branches/hemf/src/java/org/apache/poi/util/Units.java Fri Dec 14 00:44:40 2018
@@ -127,7 +127,7 @@ public class Units {
         points /= MASTER_DPI;
         return points;
     }
-    
+
     public static int pointsToMaster(double points) {
         points *= MASTER_DPI;
         points /= POINT_DPI;

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java Fri Dec 14 00:44:40 2018
@@ -615,7 +615,7 @@ public class POIXMLDocumentPart {
     protected void read(POIXMLFactory factory, Map<PackagePart, POIXMLDocumentPart> context) throws OpenXML4JException {
         PackagePart pp = getPackagePart();
 
-        if (pp.getContentType().equals(XWPFRelation.TEMPLATE.getContentType())) {
+        if (pp.getContentType().equals(XWPFRelation.GLOSSARY_DOCUMENT.getContentType())) {
             logger.log(POILogger.WARN,
                     "POI does not currently support template.main+xml (glossary) parts.  " +
                     "Skipping this part for now.");

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/extractor/CommandLineTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/extractor/CommandLineTextExtractor.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/extractor/CommandLineTextExtractor.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/extractor/CommandLineTextExtractor.java Fri Dec 14 00:44:40 2018
@@ -22,41 +22,37 @@ import org.apache.poi.extractor.POITextE
 
 /**
  * A command line wrapper around {@link ExtractorFactory}, useful
- *  for when debugging.
+ * for when debugging.
  */
 public class CommandLineTextExtractor {
-   public static final String DIVIDER = "=======================";
-   
-   public static void main(String[] args) throws Exception {
-      if(args.length < 1) {
-         System.err.println("Use:");
-         System.err.println("   CommandLineTextExtractor <filename> [filename] [filename]");
-         System.exit(1);
-      }
-
-       for (String arg : args) {
-           System.out.println(DIVIDER);
-
-           File f = new File(arg);
-           System.out.println(f);
-
-           POITextExtractor extractor =
-                   ExtractorFactory.createExtractor(f);
-           try {
-               POITextExtractor metadataExtractor =
-                       extractor.getMetadataTextExtractor();
-
-               System.out.println("   " + DIVIDER);
-               String metaData = metadataExtractor.getText();
-               System.out.println(metaData);
-               System.out.println("   " + DIVIDER);
-               String text = extractor.getText();
-               System.out.println(text);
-               System.out.println(DIVIDER);
-               System.out.println("Had " + metaData.length() + " characters of metadata and " + text.length() + " characters of text");
-           } finally {
-               extractor.close();
-           }
-       }
-   }
+    public static final String DIVIDER = "=======================";
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 1) {
+            System.err.println("Use:");
+            System.err.println("   CommandLineTextExtractor <filename> [filename] [filename]");
+            System.exit(1);
+        }
+
+        for (String arg : args) {
+            System.out.println(DIVIDER);
+
+            File f = new File(arg);
+            System.out.println(f);
+
+            try (POITextExtractor extractor = ExtractorFactory.createExtractor(f)) {
+                POITextExtractor metadataExtractor =
+                        extractor.getMetadataTextExtractor();
+
+                System.out.println("   " + DIVIDER);
+                String metaData = metadataExtractor.getText();
+                System.out.println(metaData);
+                System.out.println("   " + DIVIDER);
+                String text = extractor.getText();
+                System.out.println(text);
+                System.out.println(DIVIDER);
+                System.out.println("Had " + metaData.length() + " characters of metadata and " + text.length() + " characters of text");
+            }
+        }
+    }
 }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLConstants.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLConstants.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLConstants.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLConstants.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,7 @@ package org.apache.poi.ooxml.util;
 public class POIXMLConstants {
     public static final String FEATURE_LOAD_DTD_GRAMMAR = "http://apache.org/xml/features/nonvalidating/load-dtd-grammar";
     public static final String FEATURE_LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
+    public static final String FEATURE_DISALLOW_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
     public static final String PROPERTY_ENTITY_EXPANSION_LIMIT = "http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit";
     public static final String PROPERTY_SECURITY_MANAGER = "http://apache.org/xml/properties/security-manager";
 }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java Fri Dec 14 00:44:40 2018
@@ -154,8 +154,6 @@ public final class ZipHelper {
                 "The supplied data appears to be a raw XML file. " +
                 "Formats such as Office 2003 XML are not supported");
         default:
-        case OOXML:
-        case UNKNOWN:
             // Don't check for a Zip header, as to maintain backwards
             //  compatibility we need to let them seek over junk at the
             //  start before beginning processing.

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java Fri Dec 14 00:44:40 2018
@@ -38,7 +38,7 @@ public class ZipInputStreamZipEntrySourc
 	
 	/**
 	 * Reads all the entries from the ZipInputStream 
-	 *  into memory, and closes the source stream.
+	 *  into memory, and don't close (since POI 4.0.1) the source stream.
 	 * We'll then eat lots of memory, but be able to
 	 *  work with the entries at-will.
 	 */

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureOutputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureOutputStream.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureOutputStream.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureOutputStream.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,7 @@ package org.apache.poi.poifs.crypt.dsig;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.PrivateKey;
+import java.security.Security;
 import java.security.Signature;
 import java.security.SignatureException;
 
@@ -35,7 +36,12 @@ import org.apache.poi.poifs.crypt.HashAl
     @Override
     public void init() throws GeneralSecurityException {
         final String provider = isMSCapi(key) ? "SunMSCAPI" : "SunRsaSign";
-        signature = Signature.getInstance(algo.ecmaString+"withRSA", provider);
+        if (Security.getProvider(provider) != null) {
+            signature = Signature.getInstance(algo.ecmaString + "withRSA", provider);
+        } else {
+            signature = Signature.getInstance(algo.ecmaString + "withRSA");
+        }
+
         signature.initSign(key);
     }
 

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java Fri Dec 14 00:44:40 2018
@@ -53,6 +53,7 @@ import org.apache.poi.xddf.usermodel.tex
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFTable;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
@@ -81,6 +82,27 @@ import org.openxmlformats.schemas.spread
 
 @Beta
 public abstract class XDDFChart extends POIXMLDocumentPart implements TextContainer {
+    
+    /**
+     * default width of chart in emu
+     */
+    public static final int DEFAULT_WIDTH = 500000;
+
+    /**
+     * default height of chart in emu
+     */
+    public static final int DEFAULT_HEIGHT = 500000;
+    
+    /**
+     * default x-coordinate  of chart in emu
+     */
+    public static final int DEFAULT_X = 10;
+
+    /**
+     * default y-coordinate value of chart in emu
+     */
+    public static final int DEFAULT_Y = 10;
+    
     /**
      * Underlying workbook
      */
@@ -712,11 +734,30 @@ public abstract class XDDFChart extends
         XSSFRow row = this.getRow(sheet, 0);
         XSSFCell cell = this.getCell(row, column);
         cell.setCellValue(title);
-        this.updateSheetTable(sheet.getTables().get(0).getCTTable(), title, column);
+        
+        CTTable ctTable = this.getSheetTable(sheet);
+        
+        this.updateSheetTable(ctTable, title, column);
         return new CellReference(sheet.getSheetName(), 0, column, true, true);
     }
 
     /**
+     * this method will check whether sheet have table
+     * in case table size zero then create new table and add table columns element
+     * @param sheet
+     * @return table object
+     */
+    private CTTable getSheetTable(XSSFSheet sheet) {
+        if(sheet.getTables().size() == 0)
+        {
+            XSSFTable newTable = sheet.createTable(null);
+            newTable.getCTTable().addNewTableColumns();
+            sheet.getTables().add(newTable);
+        }
+        return sheet.getTables().get(0).getCTTable();
+    }
+
+    /**
      * this method update column header of sheet into table
      *
      * @param ctTable
@@ -729,7 +770,8 @@ public abstract class XDDFChart extends
     private void updateSheetTable(CTTable ctTable, String title, int index) {
         CTTableColumns tableColumnList = ctTable.getTableColumns();
         CTTableColumn column = null;
-        for( int i = 0; tableColumnList.getCount() < index; i++) {
+        int columnCount  = tableColumnList.getTableColumnList().size()-1;
+        for( int i = columnCount; i < index; i++) {
             column = tableColumnList.addNewTableColumn();
             column.setId(i);
         }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Fri Dec 14 00:44:40 2018
@@ -302,14 +302,23 @@ public class XMLSlideShow extends POIXML
      * Create a blank chart on the given slide.
      */
     public XSLFChart createChart(XSLFSlide slide) {
+        XSLFChart chart = createChart();
+        slide.addRelation(null, XSLFRelation.CHART, chart);
+        return chart;
+    }
+    
+    /**
+     * This method is used to create template for chart XML.
+     * @return Xslf chart object 
+     * @since POI 4.0.2 
+     */
+    public XSLFChart createChart() {
         int chartIdx = findNextAvailableFileNameIndex(XSLFRelation.CHART, _charts.size() + 1);
         XSLFChart chart = (XSLFChart) createRelationship(XSLFRelation.CHART, XSLFFactory.getInstance(), chartIdx, true).getDocumentPart();
-        slide.addRelation(null, XSLFRelation.CHART, chart);
         chart.setChartIndex(chartIdx);
         _charts.add(chart);
         return chart;
     }
-
     /**
      * Return notes slide for the specified slide or create new if it does not exist yet.
      */
@@ -416,7 +425,7 @@ public class XMLSlideShow extends POIXML
      * Return all the charts in the slideshow
      */
     public List<XSLFChart> getCharts() {
-        return _charts;
+        return Collections.unmodifiableList(_charts);
     }
 
     /**

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java Fri Dec 14 00:44:40 2018
@@ -19,16 +19,28 @@
 
 package org.apache.poi.xslf.usermodel;
 
+import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
+import javax.xml.namespace.QName;
+
 import org.apache.poi.ooxml.POIXMLFactory;
 import org.apache.poi.ooxml.POIXMLRelation;
 import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.util.Beta;
 import org.apache.poi.xddf.usermodel.chart.XDDFChart;
+import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrameNonVisual;
 
 /**
  * Represents a Chart in a .pptx presentation
@@ -36,6 +48,8 @@ import org.openxmlformats.schemas.drawin
 @Beta
 public final class XSLFChart extends XDDFChart {
 
+    private static String CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
+
     /**
      * Construct a PresentationML chart.
      */
@@ -90,4 +104,47 @@ public final class XSLFChart extends XDD
             };
         }
     }
+
+    /**
+     * method to add graphic frame for XSLF chart
+     *
+     * @param shapeId shape id
+     * @param rID relation id
+     * @param anchor size and location of chart
+     * @return graphic frame object
+     * @since POI 4.0.2
+     */
+    static CTGraphicalObjectFrame prototype(int shapeId, String rID, Rectangle2D anchor) {
+        CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance();
+        CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr();
+
+        CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr();
+        cnv.setName("Chart " + shapeId);
+        cnv.setId(shapeId);
+        nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true);
+        nvGr.addNewNvPr();
+
+        CTTransform2D xfrm = frame.addNewXfrm();
+
+        CTPoint2D off = xfrm.addNewOff();
+        off.setX((int)anchor.getX());
+        off.setY((int)anchor.getY());
+
+        CTPositiveSize2D ext = xfrm.addNewExt();
+        ext.setCx((int)anchor.getWidth());
+        ext.setCy((int)anchor.getHeight());
+
+        xfrm.setExt(ext);
+        xfrm.setOff(off);
+
+        CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData();
+        XmlCursor grCur = gr.newCursor();
+        grCur.toNextToken();
+        grCur.beginElement(new QName(CHART_URI, "chart"));
+        grCur.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, rID);
+        grCur.dispose();
+
+        gr.setUri(CHART_URI);
+        return frame;
+    }
 }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java Fri Dec 14 00:44:40 2018
@@ -107,6 +107,19 @@ public class XSLFDrawing {
         return shape;
     }
 
+    /**
+     * This method will add chart into slide's graphic frame
+     *
+     * @param rID relation id of chart
+     * @param rect2D Chart Bounding values
+     * @since POI 4.0.2
+     */
+    public void addChart(String rID, Rectangle2D rect2D) {
+        CTGraphicalObjectFrame sp = _spTree.addNewGraphicFrame();
+        sp.set(XSLFChart.prototype(_sheet.allocateShapeId(), rID, rect2D));
+    }
+
+
     public XSLFObjectShape createOleShape(String pictureRel) {
         CTGraphicalObjectFrame sp = _spTree.addNewGraphicFrame();
         sp.set(XSLFObjectShape.prototype(_sheet.allocateShapeId(), pictureRel));

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java Fri Dec 14 00:44:40 2018
@@ -24,6 +24,12 @@ import java.awt.geom.Path2D;
 import java.awt.geom.PathIterator;
 import java.awt.geom.Rectangle2D;
 
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.poi.ooxml.POIXMLTypeLoader;
+import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.draw.geom.PresetGeometries;
 import org.apache.poi.sl.usermodel.FreeformShape;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.POILogFactory;
@@ -31,6 +37,7 @@ import org.apache.poi.util.POILogger;
 import org.apache.poi.util.Units;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect;
@@ -61,7 +68,7 @@ public class XSLFFreeformShape extends X
     }
 
     @Override
-    public int setPath(final Path2D.Double path) {
+    public int setPath(final Path2D path) {
         final CTPath2D ctPath = CTPath2D.Factory.newInstance();
 
         final Rectangle2D bounds = path.getBounds2D();
@@ -117,6 +124,30 @@ public class XSLFFreeformShape extends X
         return numPoints;
     }
 
+    /**
+     * @return definition of the shape geometry
+     */
+    @Override
+    public CustomGeometry getGeometry() {
+        final XmlObject xo = getShapeProperties();
+        if (!(xo instanceof CTShapeProperties)) {
+            return null;
+        }
+
+        XmlOptions xop = new XmlOptions(POIXMLTypeLoader.DEFAULT_XML_OPTIONS);
+        xop.setSaveOuter();
+
+        XMLStreamReader staxReader = ((CTShapeProperties)xo).getCustGeom().newXMLStreamReader(xop);
+        CustomGeometry custGeo = PresetGeometries.convertCustomGeometry(staxReader);
+        try {
+            staxReader.close();
+        } catch (XMLStreamException e) {
+            LOG.log(POILogger.WARN,
+                    "An error occurred while closing a Custom Geometry XML Stream Reader: " + e.getMessage());
+        }
+
+        return custGeo;
+    }
 
     @Override
     public Path2D.Double getPath() {

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,7 @@ import static org.apache.poi.ooxml.POIXM
 
 import java.awt.Dimension;
 import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -52,6 +53,7 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.Units;
+import org.apache.poi.xddf.usermodel.chart.XDDFChart;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
@@ -306,14 +308,13 @@ implements XSLFShapeContainer, Sheet<XSL
             throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
         }
         RelationPart rp = addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData);
-        
+
         XSLFObjectShape sh = getDrawing().createOleShape(rp.getRelationship().getId());
         CTOleObject oleObj = sh.getCTOleObject();
         Dimension dim = pictureData.getImageDimension();
         oleObj.setImgW(Units.toEMU(dim.getWidth()));
         oleObj.setImgH(Units.toEMU(dim.getHeight()));
-        
-        
+
         getShapes().add(sh);
         sh.setParent(this);
         return sh;
@@ -719,4 +720,28 @@ implements XSLFShapeContainer, Sheet<XSL
         return (ph == null) ? null : new XSLFPlaceholderDetails(ph);
     }
 
+    /**
+     * this method will add chart into slide
+     * with default height, width, x and y
+     * @param chart xslf chart object
+     * @since POI 4.0.2
+     */
+    public void addChart(XSLFChart chart) {
+        Rectangle2D rect2D = new java.awt.Rectangle(XDDFChart.DEFAULT_X, XDDFChart.DEFAULT_Y,
+                XDDFChart.DEFAULT_WIDTH, XDDFChart.DEFAULT_HEIGHT);
+
+        this.addChart(chart, rect2D);
+    }
+
+    /**
+     * this method will add chart into slide
+     * with given height, width, x and y
+     * @param chart xslf chart object
+     * @since POI 4.0.2
+     */
+    public void addChart(XSLFChart chart, Rectangle2D rect2D) {
+        RelationPart rp = addRelation(null, XSLFRelation.CHART, chart);
+        getDrawing().addChart(rp.getRelationship().getId(), rect2D);
+    }
+
 }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java Fri Dec 14 00:44:40 2018
@@ -716,7 +716,6 @@ public abstract class XSLFSimpleShape ex
     }
 
     /**
-     *
      * @return definition of the shape geometry
      */
     @Override

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java Fri Dec 14 00:44:40 2018
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
+import org.apache.commons.compress.archivers.zip.Zip64Mode;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -51,13 +52,7 @@ import org.apache.poi.ss.usermodel.Row.M
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.SheetVisibility;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.Internal;
-import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.Removal;
-import org.apache.poi.util.TempFile;
+import org.apache.poi.util.*;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.usermodel.XSSFChartSheet;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -117,6 +112,8 @@ public class SXSSFWorkbook implements Wo
      */
     private final SharedStringsTable _sharedStringSource;
 
+    private Zip64Mode zip64Mode = Zip64Mode.AsNeeded;
+
     /**
      * Construct a new workbook with default row window size
      */
@@ -250,6 +247,7 @@ public class SXSSFWorkbook implements Wo
             }
         }
     }
+
     /**
      * Construct an empty workbook and specify the window for row access.
      * <p>
@@ -291,6 +289,16 @@ public class SXSSFWorkbook implements Wo
     }
 
     /**
+     * @param zip64Mode {@link Zip64Mode}
+     *
+     * @since 4.0.3
+     */
+    @Beta
+    public void setZip64Mode(Zip64Mode zip64Mode) {
+        this.zip64Mode = zip64Mode;
+    }
+
+    /**
      * Get whether temp files should be compressed.
      *
      * @return whether to compress temp files
@@ -298,6 +306,7 @@ public class SXSSFWorkbook implements Wo
     public boolean isCompressTempFiles() {
         return _compressTmpFiles;
     }
+
     /**
      * Set whether temp files should be compressed.
      * <p>
@@ -377,6 +386,7 @@ public class SXSSFWorkbook implements Wo
 
     protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
         ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out);
+        zos.setUseZip64(zip64Mode);
         try {
             Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
             while (en.hasMoreElements()) {

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java Fri Dec 14 00:44:40 2018
@@ -39,12 +39,12 @@ public class XWPFChart extends XDDFChart
     /**
      * default width of chart in emu
      */
-    public static final int DEFAULT_WIDTH = 500000;
+    public static final int DEFAULT_WIDTH = XDDFChart.DEFAULT_WIDTH;
 
     /**
      * default height of chart in emu
      */
-    public static final int DEFAULT_HEIGHT = 500000;
+    public static final int DEFAULT_HEIGHT = XDDFChart.DEFAULT_HEIGHT;
 
     // lazy initialization
     private Long checksum;

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Fri Dec 14 00:44:40 2018
@@ -58,6 +58,7 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.wp.usermodel.HeaderFooterType;
+import org.apache.poi.xddf.usermodel.chart.XDDFChart;
 import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
@@ -1672,7 +1673,7 @@ public class XWPFDocument extends POIXML
      * @since POI 4.0.0
      */
     public XWPFChart createChart() throws InvalidFormatException, IOException {
-        return createChart(XWPFChart.DEFAULT_WIDTH, XWPFChart.DEFAULT_HEIGHT);
+        return createChart(XDDFChart.DEFAULT_WIDTH, XDDFChart.DEFAULT_HEIGHT);
     }
 
     /**

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java Fri Dec 14 00:44:40 2018
@@ -19,6 +19,7 @@ package org.apache.poi.ooxml;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -89,7 +90,7 @@ public final class TestPOIXMLProperties
         XSSFWorkbook newWorkbook =
                 XSSFTestDataSamples.writeOutAndReadBack(workbook);
         workbook.close();
-        assertTrue(workbook != newWorkbook);
+        assertNotSame(workbook, newWorkbook);
 
 
         POIXMLProperties newProps = newWorkbook.getProperties();
@@ -158,7 +159,7 @@ public final class TestPOIXMLProperties
         p = ctProps.getPropertyArray(3);
         assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid());
         assertEquals("test-4", p.getName());
-        assertEquals(true, p.getBool());
+        assertTrue(p.getBool());
         assertEquals(5, p.getPid());
         
         wb2.close();

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java Fri Dec 14 00:44:40 2018
@@ -60,6 +60,7 @@ import javax.xml.crypto.dsig.Canonicaliz
 import javax.xml.crypto.dsig.dom.DOMSignContext;
 
 import org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo;
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POITestCase;
 import org.apache.poi.ooxml.util.DocumentHelper;
@@ -682,6 +683,8 @@ public class TestSignatureInfo {
                 si.confirmSignature();
                 boolean b = si.verifySignature();
                 assertTrue("Signature not correctly calculated for " + ha, b);
+            } catch (EncryptedDocumentException e) {
+                Assume.assumeTrue(e.getMessage().startsWith("Export Restrictions"));
             } finally {
                 if (pkg != null) {
                     pkg.close();

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java Fri Dec 14 00:44:40 2018
@@ -87,6 +87,10 @@ public class TestNecessaryOOXMLClasses {
         Assert.assertNotNull(ctLblAlgn);
         CTDashStopList ctDashStopList = CTDashStopList.Factory.newInstance();
         Assert.assertNotNull(ctDashStopList);
+        STDispBlanksAs stDashBlanksAs = STDispBlanksAs.Factory.newInstance();
+        Assert.assertNotNull(stDashBlanksAs);
+        CTDispBlanksAs ctDashBlanksAs = CTDispBlanksAs.Factory.newInstance();
+        Assert.assertNotNull(ctDashBlanksAs);
 
         STLblAlgn.Enum e1 = STLblAlgn.Enum.forString("ctr");
         Assert.assertNotNull(e1);
@@ -100,6 +104,8 @@ public class TestNecessaryOOXMLClasses {
         Assert.assertNotNull(e5);
         STMarkerStyle.Enum e6 = STMarkerStyle.Enum.forString("circle");
         Assert.assertNotNull(e6);
+        STDispBlanksAs.Enum e7 = STDispBlanksAs.Enum.forString("span");
+        Assert.assertNotNull(e7);
 
         CTTextBulletTypefaceFollowText ctTextBulletTypefaceFollowText = CTTextBulletTypefaceFollowText.Factory.newInstance();
         Assert.assertNotNull(ctTextBulletTypefaceFollowText);

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xdgf/extractor/TestXDGFVisioExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xdgf/extractor/TestXDGFVisioExtractor.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xdgf/extractor/TestXDGFVisioExtractor.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xdgf/extractor/TestXDGFVisioExtractor.java Fri Dec 14 00:44:40 2018
@@ -42,7 +42,7 @@ public class TestXDGFVisioExtractor {
     }
     
     @After
-    public void closeResoures() throws IOException {
+    public void closeResources() throws IOException {
         if(xml != null) {
             xml.close();
         }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java Fri Dec 14 00:44:40 2018
@@ -47,7 +47,9 @@ public class TestPPTX2PNG {
     private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
     private static final File basedir = null;
     private static final String files =
-        "53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt";
+        "53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, " +
+        "backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
+        "customGeo.pptx, customGeo.ppt";
 
         
     

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,7 @@ import static org.apache.poi.sl.TestComm
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -34,7 +35,7 @@ import org.junit.Test;
  * @author Yegor Kozlov
  */
 public class TestXSLFSlide {
-    
+
     @Test
     public void testReadShapes() throws IOException {
         XMLSlideShow  ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
@@ -101,7 +102,7 @@ public class TestXSLFSlide {
         XSLFTable tbl = (XSLFTable)shapes4.get(0);
         assertEquals(3, tbl.getNumberOfColumns());
         assertEquals(6, tbl.getNumberOfRows());
-        
+
         ppt.close();
     }
 
@@ -116,7 +117,7 @@ public class TestXSLFSlide {
         assertFalse(slide.getFollowMasterGraphics());
         slide.setFollowMasterGraphics(true);
         assertTrue(slide.getFollowMasterGraphics());
-        
+
         ppt.close();
     }
 
@@ -174,7 +175,7 @@ public class TestXSLFSlide {
         XSLFPictureShape sh4 = (XSLFPictureShape)shapes2.get(1);
         XSLFPictureShape srcPic = (XSLFPictureShape)src.getSlides().get(4).getShapes().get(1);
         assertArrayEquals(sh4.getPictureData().getData(), srcPic.getPictureData().getData());
-        
+
         ppt.close();
     }
 
@@ -191,7 +192,23 @@ public class TestXSLFSlide {
             }
         }
         assertEquals(30, ppt.getSlides().size());
-        
+
         ppt.close();
-    }    
-}
\ No newline at end of file
+    }
+
+    @Test
+    public void testCreateChart() throws IOException {
+        XMLSlideShow ppt = new XMLSlideShow();
+        XSLFSlide slide = ppt.createSlide();
+        XSLFChart chart = ppt.createChart();
+        assertNotNull(chart);
+
+        slide.addChart(chart);
+        assertEquals(XSLFRelation.CHART.getContentType(), chart.getPackagePart().getContentType());
+
+        String partName = slide.getRelationPartById("rId2").getDocumentPart().getPackagePart().getPartName().getName();
+        assertEquals(partName, chart.getPackagePart().getPartName().getName());
+
+        ppt.close();
+    }
+}

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java Fri Dec 14 00:44:40 2018
@@ -70,7 +70,7 @@ public class XSSFTestDataSamples {
      * @param wb the workbook to write
      * @param testName a fragment of the filename
      * @return the location where the workbook was saved
-     * @throws IOException
+     * @throws IOException If writing the file fails
      */
     public static <R extends Workbook> File writeOut(R wb, String testName) throws IOException {
         final File file = getOutputFile(testName);
@@ -104,7 +104,9 @@ public class XSSFTestDataSamples {
             file = TempFile.createTempFile(testName, ".xlsx");
         }
         if (file.exists()) {
-            file.delete();
+            if(!file.delete()) {
+                throw new IOException("Could not delete file " + file);
+            }
         }
         return file;
     }
@@ -114,7 +116,7 @@ public class XSSFTestDataSamples {
      *
      * @param wb the workbook to write
      * @return the memory buffer
-     * @throws IOException
+     * @throws IOException If writing the file fails
      */
     public static <R extends Workbook> ByteArrayOutputStream writeOut(R wb) throws IOException {
         ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
@@ -137,7 +139,7 @@ public class XSSFTestDataSamples {
      * to avoid creating a temporary file. However, this may complicate the calling
      * code to avoid having the workbook, BAOS, and BAIS open at the same time.
      *
-     * @param wb
+     * @param wb The workbook to write out, it is closed after the call.
      * @param testName file name to be used to write to a file. This file will be cleaned up by a call to readBack(String)
      * @return workbook location
      * @throws RuntimeException if {@link #TEST_OUTPUT_DIR} System property is not set
@@ -161,18 +163,13 @@ public class XSSFTestDataSamples {
      *
      * @param wb the workbook to write
      * @return the memory buffer
-     * @throws IOException
+     * @throws RuntimeException If writing the file fails
      */
-    public static <R extends Workbook> ByteArrayOutputStream writeOutAndClose(R wb) {
-        try {
-            ByteArrayOutputStream out = writeOut(wb);
-            // Do not close the workbook if there was a problem writing the workbook
-            wb.close();
-            return out;
-        }
-        catch (final IOException e) {
-            throw new RuntimeException(e);
-        }
+    public static <R extends Workbook> ByteArrayOutputStream writeOutAndClose(R wb) throws IOException {
+        ByteArrayOutputStream out = writeOut(wb);
+        // Do not close the workbook if there was a problem writing the workbook
+        wb.close();
+        return out;
     }
 
     /**
@@ -183,12 +180,14 @@ public class XSSFTestDataSamples {
      *
      * @param file the workbook file to read and delete
      * @return the read back workbook
-     * @throws IOException
+     * @throws IOException If reading or deleting the file fails
      */
     public static XSSFWorkbook readBackAndDelete(File file) throws IOException {
         XSSFWorkbook wb = readBack(file);
         // do not delete the file if there's an error--might be helpful for debugging
-        file.delete();
+        if(!file.delete()) {
+            throw new IOException("Could not delete file " + file + " after reading");
+        }
         return wb;
     }
 
@@ -198,16 +197,12 @@ public class XSSFTestDataSamples {
      *
      * @param file the workbook file to read
      * @return the read back workbook
-     * @throws IOException
+     * @throws IOException If reading the file fails
      */
     public static XSSFWorkbook readBack(File file) throws IOException {
-        InputStream in = new FileInputStream(file);
-        try {
+        try (InputStream in = new FileInputStream(file)) {
             return new XSSFWorkbook(in);
         }
-        finally {
-            in.close();
-        }
     }
 
     /**
@@ -216,17 +211,13 @@ public class XSSFTestDataSamples {
      *
      * @param out the output stream to read back from
      * @return the read back workbook
-     * @throws IOException
+     * @throws IOException If reading the file fails
      */
     public static XSSFWorkbook readBack(ByteArrayOutputStream out) throws IOException {
-        InputStream is = new ByteArrayInputStream(out.toByteArray());
-        out.close();
-        try {
+        try (InputStream is = new ByteArrayInputStream(out.toByteArray())) {
+            out.close();
             return new XSSFWorkbook(is);
         }
-        finally {
-            is.close();
-        }
     }
 
     /**

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Fri Dec 14 00:44:40 2018
@@ -452,4 +452,12 @@ public class TestXWPFWordExtractor exten
         //once we add processing for this, we can change this to contains
         assertNotContained(txt, "table rows");
     }
+
+    public void testPartsInTemplate() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60316b.dotx");
+        XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
+        String txt = extractor.getText();
+        assertContains(txt, "header 2");
+        assertContains(txt, "footer 1");
+    }
 }

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java Fri Dec 14 00:44:40 2018
@@ -20,6 +20,8 @@
 
 package org.apache.poi.hslf.record;
 
+import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -143,7 +145,7 @@ public class CurrentUserAtom
 		// See how long it is. If it's under 28 bytes long, we can't
 		//  read it
 		if(_contents.length < 28) {
-		    boolean isPP95 = dir.hasEntry("PP40");
+		    boolean isPP95 = dir.hasEntry(PP95_DOCUMENT);
 		    // PPT95 has 4 byte size, then data
 			if (!isPP95 && _contents.length >= 4) {
 				int size = LittleEndian.getInt(_contents);

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java Fri Dec 14 00:44:40 2018
@@ -17,21 +17,122 @@
 
 package org.apache.poi.hslf.usermodel;
 
+import java.awt.geom.Arc2D;
+import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ddf.AbstractEscherOptRecord;
+import org.apache.poi.ddf.EscherArrayProperty;
 import org.apache.poi.ddf.EscherContainerRecord;
 import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.ddf.EscherProperty;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.sl.draw.binding.CTAdjPoint2D;
+import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
+import org.apache.poi.sl.draw.binding.CTPath2D;
+import org.apache.poi.sl.draw.binding.CTPath2DArcTo;
+import org.apache.poi.sl.draw.binding.CTPath2DCubicBezierTo;
+import org.apache.poi.sl.draw.binding.CTPath2DLineTo;
+import org.apache.poi.sl.draw.binding.CTPath2DList;
+import org.apache.poi.sl.draw.binding.CTPath2DMoveTo;
+import org.apache.poi.sl.draw.binding.ObjectFactory;
+import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.usermodel.AutoShape;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.VerticalAlignment;
 import org.apache.poi.ss.usermodel.ShapeTypes;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
- * Represents an AutoShape.
- * <p>
+ * Represents an AutoShape.<p>
+ *
  * AutoShapes are drawing objects with a particular shape that may be customized through smart resizing and adjustments.
  * See {@link ShapeTypes}
- * </p>
- *
- *  @author Yegor Kozlov
  */
 public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape,HSLFTextParagraph> {
+    private static final POILogger LOG = POILogFactory.getLogger(HSLFAutoShape.class);
+
+    static final byte[] SEGMENTINFO_MOVETO   = new byte[]{0x00, 0x40};
+    static final byte[] SEGMENTINFO_LINETO   = new byte[]{0x00, (byte)0xAC};
+    static final byte[] SEGMENTINFO_ESCAPE   = new byte[]{0x01, 0x00};
+    static final byte[] SEGMENTINFO_ESCAPE2  = new byte[]{0x01, 0x20};
+    static final byte[] SEGMENTINFO_CUBICTO  = new byte[]{0x00, (byte)0xAD};
+    // OpenOffice inserts 0xB3 instead of 0xAD.
+    // protected static final byte[] SEGMENTINFO_CUBICTO2 = new byte[]{0x00, (byte)0xB3};
+    static final byte[] SEGMENTINFO_CLOSE    = new byte[]{0x01, (byte)0x60};
+    static final byte[] SEGMENTINFO_END      = new byte[]{0x00, (byte)0x80};
+
+    private static final BitField PATH_INFO = BitFieldFactory.getInstance(0xE000);
+    private static final BitField ESCAPE_INFO = BitFieldFactory.getInstance(0x1F00);
+
+    enum PathInfo {
+        lineTo(0),curveTo(1),moveTo(2),close(3),end(4),escape(5),clientEscape(6);
+        private final int flag;
+        PathInfo(int flag) {
+            this.flag = flag;
+        }
+        public int getFlag() {
+            return flag;
+        }
+        static PathInfo valueOf(int flag) {
+            for (PathInfo v : values()) {
+                if (v.flag == flag) {
+                    return v;
+                }
+            }
+            return null;
+        }
+    }
+
+    enum EscapeInfo {
+        EXTENSION(0x0000),
+        ANGLE_ELLIPSE_TO(0x0001),
+        ANGLE_ELLIPSE(0x0002),
+        ARC_TO(0x0003),
+        ARC(0x0004),
+        CLOCKWISE_ARC_TO(0x0005),
+        CLOCKWISE_ARC(0x0006),
+        ELLIPTICAL_QUADRANT_X(0x0007),
+        ELLIPTICAL_QUADRANT_Y(0x0008),
+        QUADRATIC_BEZIER(0x0009),
+        NO_FILL(0X000A),
+        NO_LINE(0X000B),
+        AUTO_LINE(0X000C),
+        AUTO_CURVE(0X000D),
+        CORNER_LINE(0X000E),
+        CORNER_CURVE(0X000F),
+        SMOOTH_LINE(0X0010),
+        SMOOTH_CURVE(0X0011),
+        SYMMETRIC_LINE(0X0012),
+        SYMMETRIC_CURVE(0X0013),
+        FREEFORM(0X0014),
+        FILL_COLOR(0X0015),
+        LINE_COLOR(0X0016);
+
+        private final int flag;
+        EscapeInfo(int flag) {
+            this.flag = flag;
+        }
+        public int getFlag() {
+            return flag;
+        }
+        static EscapeInfo valueOf(int flag) {
+            for (EscapeInfo v : values()) {
+                if (v.flag == flag) {
+                    return v;
+                }
+            }
+            return null;
+        }
+    }
 
     protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
         super(escherRecord, parent);
@@ -72,13 +173,11 @@ public class HSLFAutoShape extends HSLFT
     }
 
     /**
-     * Gets adjust value which controls smart resizing of the auto-shape.
+     * Gets adjust value which controls smart resizing of the auto-shape.<p>
      *
-     * <p>
      * The adjustment values are given in shape coordinates:
      * the origin is at the top-left, positive-x is to the right, positive-y is down.
      * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
-     * </p>
      *
      * @param idx the adjust index in the [0, 9] range
      * @return the adjustment value
@@ -90,13 +189,11 @@ public class HSLFAutoShape extends HSLFT
     }
 
     /**
-     * Sets adjust value which controls smart resizing of the auto-shape.
+     * Sets adjust value which controls smart resizing of the auto-shape.<p>
      *
-     * <p>
      * The adjustment values are given in shape coordinates:
      * the origin is at the top-left, positive-x is to the right, positive-y is down.
      * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
-     * </p>
      *
      * @param idx the adjust index in the [0, 9] range
      * @param val the adjustment value
@@ -106,4 +203,278 @@ public class HSLFAutoShape extends HSLFT
 
         setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
     }
+
+    @Override
+    public CustomGeometry getGeometry() {
+        return getGeometry(new Path2D.Double());
+    }
+
+    CustomGeometry getGeometry(Path2D path2D) {
+        final ObjectFactory of = new ObjectFactory();
+        final CTCustomGeometry2D cusGeo = of.createCTCustomGeometry2D();
+        cusGeo.setAvLst(of.createCTGeomGuideList());
+        cusGeo.setGdLst(of.createCTGeomGuideList());
+        cusGeo.setAhLst(of.createCTAdjustHandleList());
+        cusGeo.setCxnLst(of.createCTConnectionSiteList());
+
+        final AbstractEscherOptRecord opt = getEscherOptRecord();
+
+        EscherArrayProperty verticesProp = getShapeProp(opt, EscherProperties.GEOMETRY__VERTICES);
+        EscherArrayProperty segmentsProp = getShapeProp(opt, EscherProperties.GEOMETRY__SEGMENTINFO);
+
+        // return empty path if either GEOMETRY__VERTICES or GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
+
+        //sanity check
+        if(verticesProp == null) {
+            LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES ");
+            return super.getGeometry();
+        }
+        if(segmentsProp == null) {
+            LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO ");
+            return super.getGeometry();
+        }
+
+        final Iterator<byte[]> vertIter = verticesProp.iterator();
+        final Iterator<byte[]> segIter = segmentsProp.iterator();
+        final int[] xyPoints = new int[2];
+        boolean isClosed = false;
+
+        final CTPath2DList pathLst = of.createCTPath2DList();
+        final CTPath2D pathCT = of.createCTPath2D();
+        final List<Object> moveLst = pathCT.getCloseOrMoveToOrLnTo();
+        pathLst.getPath().add(pathCT);
+        cusGeo.setPathLst(pathLst);
+
+        while (segIter.hasNext()) {
+            byte[] segElem = segIter.next();
+            HSLFFreeformShape.PathInfo pi = getPathInfo(segElem);
+            if (pi == null) {
+                continue;
+            }
+            switch (pi) {
+                case escape: {
+                    handleEscapeInfo(pathCT, path2D, segElem, vertIter);
+                    break;
+                }
+                case moveTo:
+                    if (vertIter.hasNext()) {
+                        final CTPath2DMoveTo m = of.createCTPath2DMoveTo();
+                        m.setPt(fillPoint(vertIter.next(), xyPoints));
+                        moveLst.add(m);
+                        path2D.moveTo(xyPoints[0], xyPoints[1]);
+                    }
+                    break;
+                case lineTo:
+                    if (vertIter.hasNext()) {
+                        final CTPath2DLineTo m = of.createCTPath2DLineTo();
+                        m.setPt(fillPoint(vertIter.next(), xyPoints));
+                        moveLst.add(m);
+                        path2D.lineTo(xyPoints[0], xyPoints[1]);
+                    }
+                    break;
+                case curveTo: {
+                    final CTPath2DCubicBezierTo m = of.createCTPath2DCubicBezierTo();
+                    List<CTAdjPoint2D> mLst = m.getPt();
+
+                    int[] pts = new int[6];
+
+                    for (int i=0; vertIter.hasNext() && i<3; i++) {
+                        mLst.add(fillPoint(vertIter.next(), xyPoints));
+                        pts[i*2] = xyPoints[0];
+                        pts[i*2+1] = xyPoints[1];
+                        if (i == 2) {
+                            moveLst.add(m);
+                            path2D.curveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
+                        }
+                    }
+                    break;
+                }
+                case close:
+                    moveLst.add(of.createCTPath2DClose());
+                    path2D.closePath();
+                    isClosed = true;
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        EscherSimpleProperty shapePath = getShapeProp(opt, EscherProperties.GEOMETRY__SHAPEPATH);
+        HSLFFreeformShape.ShapePath sp = HSLFFreeformShape.ShapePath.valueOf(shapePath == null ? 1 : shapePath.getPropertyValue());
+        if ((sp == HSLFFreeformShape.ShapePath.LINES_CLOSED || sp == HSLFFreeformShape.ShapePath.CURVES_CLOSED) && !isClosed) {
+            moveLst.add(of.createCTPath2DClose());
+            path2D.closePath();
+        }
+
+        EscherSimpleProperty geoLeft = getShapeProp(opt, EscherProperties.GEOMETRY__LEFT);
+        EscherSimpleProperty geoRight = getShapeProp(opt, EscherProperties.GEOMETRY__RIGHT);
+        EscherSimpleProperty geoTop = getShapeProp(opt, EscherProperties.GEOMETRY__TOP);
+        EscherSimpleProperty geoBottom = getShapeProp(opt, EscherProperties.GEOMETRY__BOTTOM);
+
+        final Rectangle2D bounds;
+        if (geoLeft != null && geoRight != null && geoTop != null && geoBottom != null) {
+            bounds = new Rectangle2D.Double();
+            bounds.setFrameFromDiagonal(
+                new Point2D.Double(geoLeft.getPropertyValue(), geoTop.getPropertyValue()),
+                new Point2D.Double(geoRight.getPropertyValue(), geoBottom.getPropertyValue())
+            );
+        } else {
+            bounds = path2D.getBounds2D();
+        }
+
+        pathCT.setW((int)Math.rint(bounds.getWidth()));
+        pathCT.setH((int)Math.rint(bounds.getHeight()));
+
+        return new CustomGeometry(cusGeo);
+    }
+
+    private void handleEscapeInfo(CTPath2D pathCT, Path2D path2D, byte[] segElem, Iterator<byte[]> vertIter) {
+        final ObjectFactory of = new ObjectFactory();
+        HSLFFreeformShape.EscapeInfo ei = getEscapeInfo(segElem);
+        switch (ei) {
+            case EXTENSION:
+                break;
+            case ANGLE_ELLIPSE_TO:
+                break;
+            case ANGLE_ELLIPSE:
+                break;
+            case ARC_TO: {
+                // The first two POINT values specify the bounding rectangle of the ellipse.
+                // The second two POINT values specify the radial vectors for the ellipse.
+                // The radial vectors are cast from the center of the bounding rectangle.
+                // The path starts at the POINT where the first radial vector intersects the
+                // bounding rectangle and goes to the POINT where the second radial vector
+                // intersects the bounding rectangle. The drawing direction is always counterclockwise.
+                // If the path has already been started, a line is drawn from the last POINT to
+                // the starting POINT of the arc; otherwise, a new path is started.
+                // The number of arc segments drawn equals the number of segments divided by four.
+
+                int[] r1 = new int[2], r2 = new int[2], start = new int[2], end = new int[2];
+                fillPoint(vertIter.next(), r1);
+                fillPoint(vertIter.next(), r2);
+                fillPoint(vertIter.next(), start);
+                fillPoint(vertIter.next(), end);
+
+                Arc2D arc2D = new Arc2D.Double();
+                Rectangle2D.Double bounds = new Rectangle2D.Double();
+                bounds.setFrameFromDiagonal(xy2p(r1), xy2p(r2));
+                arc2D.setFrame(bounds);
+                arc2D.setAngles(xy2p(start), xy2p(end));
+                path2D.append(arc2D, true);
+
+
+                CTPath2DArcTo arcTo = of.createCTPath2DArcTo();
+                arcTo.setHR(d2s(bounds.getHeight()/2.0));
+                arcTo.setWR(d2s(bounds.getWidth()/2.0));
+
+                arcTo.setStAng(d2s(-arc2D.getAngleStart()*60000.));
+                arcTo.setSwAng(d2s(-arc2D.getAngleExtent()*60000.));
+
+                pathCT.getCloseOrMoveToOrLnTo().add(arcTo);
+
+                break;
+            }
+            case ARC:
+                break;
+            case CLOCKWISE_ARC_TO:
+                break;
+            case CLOCKWISE_ARC:
+                break;
+            case ELLIPTICAL_QUADRANT_X:
+                break;
+            case ELLIPTICAL_QUADRANT_Y:
+                break;
+            case QUADRATIC_BEZIER:
+                break;
+            case NO_FILL:
+                break;
+            case NO_LINE:
+                break;
+            case AUTO_LINE:
+                break;
+            case AUTO_CURVE:
+                break;
+            case CORNER_LINE:
+                break;
+            case CORNER_CURVE:
+                break;
+            case SMOOTH_LINE:
+                break;
+            case SMOOTH_CURVE:
+                break;
+            case SYMMETRIC_LINE:
+                break;
+            case SYMMETRIC_CURVE:
+                break;
+            case FREEFORM:
+                break;
+            case FILL_COLOR:
+                break;
+            case LINE_COLOR:
+                break;
+            default:
+                break;
+        }
+    }
+
+    private static String d2s(double d) {
+        return Integer.toString((int)Math.rint(d));
+    }
+
+    private static Point2D xy2p(int[] xyPoints) {
+        return new Point2D.Double(xyPoints[0],xyPoints[1]);
+    }
+
+    private static HSLFFreeformShape.PathInfo getPathInfo(byte[] elem) {
+        int elemUS = LittleEndian.getUShort(elem, 0);
+        int pathInfo = PATH_INFO.getValue(elemUS);
+        return HSLFFreeformShape.PathInfo.valueOf(pathInfo);
+    }
+
+    private static HSLFFreeformShape.EscapeInfo getEscapeInfo(byte[] elem) {
+        int elemUS = LittleEndian.getUShort(elem, 0);
+        int escInfo = ESCAPE_INFO.getValue(elemUS);
+        return HSLFFreeformShape.EscapeInfo.valueOf(escInfo);
+    }
+
+
+    private static <T extends EscherProperty> T getShapeProp(AbstractEscherOptRecord opt, int propId) {
+        T prop = getEscherProperty(opt, (short)(propId + 0x4000));
+        if (prop == null) {
+            prop = getEscherProperty(opt, propId);
+        }
+        return prop;
+    }
+
+    private CTAdjPoint2D fillPoint(byte[] xyMaster, int[] xyPoints) {
+        if (xyMaster == null || xyPoints == null) {
+            LOG.log(POILogger.WARN, "Master bytes or points not set - ignore point");
+            return null;
+        }
+        if ((xyMaster.length != 4 && xyMaster.length != 8) || xyPoints.length != 2) {
+            LOG.log(POILogger.WARN, "Invalid number of master bytes for a single point - ignore point");
+            return null;
+        }
+
+        int x, y;
+        if (xyMaster.length == 4) {
+            x = LittleEndian.getShort(xyMaster, 0);
+            y = LittleEndian.getShort(xyMaster, 2);
+        } else {
+            x = LittleEndian.getInt(xyMaster, 0);
+            y = LittleEndian.getInt(xyMaster, 4);
+        }
+
+        xyPoints[0] = x;
+        xyPoints[1] = y;
+
+        return toPoint(xyPoints);
+    }
+
+    private static CTAdjPoint2D toPoint(int[] xyPoints) {
+        CTAdjPoint2D pt = new CTAdjPoint2D();
+        pt.setX(Integer.toString(xyPoints[0]));
+        pt.setY(Integer.toString(xyPoints[1]));
+        return pt;
+    }
 }

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java?rev=1848906&r1=1848905&r2=1848906&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java Fri Dec 14 00:44:40 2018
@@ -49,60 +49,61 @@ import org.apache.poi.util.Units;
 /**
  * Represents functionality provided by the 'Fill Effects' dialog in PowerPoint.
  */
+@SuppressWarnings("WeakerAccess")
 public final class HSLFFill {
     private static final POILogger LOG = POILogFactory.getLogger(HSLFFill.class);
 
     /**
      *  Fill with a solid color
      */
-    public static final int FILL_SOLID = 0;
+    static final int FILL_SOLID = 0;
 
     /**
      *  Fill with a pattern (bitmap)
      */
-    public static final int FILL_PATTERN = 1;
+    static final int FILL_PATTERN = 1;
 
     /**
      *  A texture (pattern with its own color map)
      */
-    public static final int FILL_TEXTURE = 2;
+    static final int FILL_TEXTURE = 2;
 
     /**
      *  Center a picture in the shape
      */
-    public static final int FILL_PICTURE = 3;
+    static final int FILL_PICTURE = 3;
 
     /**
      *  Shade from start to end points
      */
-    public static final int FILL_SHADE = 4;
+    static final int FILL_SHADE = 4;
 
     /**
      *  Shade from bounding rectangle to end point
      */
-    public static final int FILL_SHADE_CENTER = 5;
+    static final int FILL_SHADE_CENTER = 5;
 
     /**
      *  Shade from shape outline to end point
      */
-    public static final int FILL_SHADE_SHAPE = 6;
+    static final int FILL_SHADE_SHAPE = 6;
 
     /**
      *  Similar to FILL_SHADE, but the fill angle
      *  is additionally scaled by the aspect ratio of
      *  the shape. If shape is square, it is the same as FILL_SHADE
      */
-    public static final int FILL_SHADE_SCALE = 7;
+    static final int FILL_SHADE_SCALE = 7;
 
     /**
      *  shade to title
      */
-    public static final int FILL_SHADE_TITLE = 8;
+    static final int FILL_SHADE_TITLE = 8;
 
     /**
      *  Use the background fill color/pattern
      */
-    public static final int FILL_BACKGROUND = 9;
+    static final int FILL_BACKGROUND = 9;
 
     /**
      * A bit that specifies whether the RecolorFillAsPicture bit is set.
@@ -214,7 +215,7 @@ public final class HSLFFill {
     private HSLFShape shape;
 
     /**
-     * Construct a <code>Fill</code> object for a shape.
+     * Construct a {@code Fill} object for a shape.
      * Fill information will be read from shape's escher properties.
      *
      * @param shape the shape this background applies to
@@ -279,7 +280,7 @@ public final class HSLFFill {
             
             @Override
             public ColorStyle[] getGradientColors() {
-                ColorStyle cs[];
+                ColorStyle[] cs;
                 if (colorCnt == 0) {
                     cs = new ColorStyle[2];
                     cs[0] = wrapColor(getBackgroundColor());
@@ -288,7 +289,7 @@ public final class HSLFFill {
                     cs = new ColorStyle[colorCnt];
                     int idx = 0;
                     // TODO: handle palette colors and alpha(?) value 
-                    for (byte data[] : ep) {
+                    for (byte[] data : ep) {
                         EscherColorRef ecr = new EscherColorRef(data, 0, 4);
                         cs[idx++] = wrapColor(shape.getColor(ecr));
                     }
@@ -302,13 +303,13 @@ public final class HSLFFill {
             
             @Override
             public float[] getGradientFractions() {
-                float frc[];
+                float[] frc;
                 if (colorCnt == 0) {
                     frc = new float[]{0, 1};
                 } else {
                     frc = new float[colorCnt];
                     int idx = 0;
-                    for (byte data[] : ep) {
+                    for (byte[] data : ep) {
                         double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
                         frc[idx++] = (float)pos;
                     }
@@ -354,7 +355,7 @@ public final class HSLFFill {
 
     /**
      * Returns fill type.
-     * Must be one of the <code>FILL_*</code> constants defined in this class.
+     * Must be one of the {@code FILL_*} constants defined in this class.
      *
      * @return type of fill
      */
@@ -364,9 +365,7 @@ public final class HSLFFill {
         return prop == null ? FILL_SOLID : prop.getPropertyValue();
     }
 
-    /**
-     */
-    protected void afterInsert(HSLFSheet sh){
+    void afterInsert(HSLFSheet sh){
         AbstractEscherOptRecord opt = shape.getEscherOptRecord();
         EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
         if(p != null) {
@@ -379,7 +378,7 @@ public final class HSLFFill {
     }
 
     @SuppressWarnings("resource")
-    protected EscherBSERecord getEscherBSERecord(int idx){
+    EscherBSERecord getEscherBSERecord(int idx){
         HSLFSheet sheet = shape.getSheet();
         if(sheet == null) {
             LOG.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
@@ -399,7 +398,7 @@ public final class HSLFFill {
 
     /**
      * Sets fill type.
-     * Must be one of the <code>FILL_*</code> constants defined in this class.
+     * Must be one of the {@code FILL_*} constants defined in this class.
      *
      * @param type type of the fill
      */
@@ -415,10 +414,10 @@ public final class HSLFFill {
         AbstractEscherOptRecord opt = shape.getEscherOptRecord();
         EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
         int propVal = (p == null) ? 0 : p.getPropertyValue();
-        
+
         return (FILL_USE_FILLED.isSet(propVal) && !FILL_FILLED.isSet(propVal))
             ? null
-            : shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
+            : shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY);
     }
 
     /**
@@ -462,7 +461,7 @@ public final class HSLFFill {
 
         return (FILL_USE_FILLED.isSet(propVal) && !FILL_FILLED.isSet(propVal))
             ? null
-            : shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
+            : shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY);
     }
 
     /**
@@ -480,7 +479,7 @@ public final class HSLFFill {
     }
 
     /**
-     * <code>PictureData</code> object used in a texture, pattern of picture fill.
+     * {@code PictureData} object used in a texture, pattern of picture fill.
      */
     @SuppressWarnings("resource")
     public HSLFPictureData getPictureData(){



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message