You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/10/08 12:46:37 UTC

svn commit: r1904457 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Author: tilman
Date: Sat Oct  8 12:46:37 2022
New Revision: 1904457

URL: http://svn.apache.org/viewvc?rev=1904457&view=rev
Log:
PDFBOX-5523: check for input, improve javadoc, improve field names

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java?rev=1904457&r1=1904456&r2=1904457&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java Sat Oct  8 12:46:37 2022
@@ -69,8 +69,8 @@ public class Overlay implements Closeabl
     private LayoutPage oddPageOverlayPage;
     private LayoutPage evenPageOverlayPage;
 
-    private final Set<PDDocument> openDocuments = new HashSet<>();
-    private Map<Integer, LayoutPage> specificPageOverlayPage = new HashMap<>();
+    private final Set<PDDocument> openDocumentsSet = new HashSet<>();
+    private Map<Integer, LayoutPage> specificPageOverlayLayoutPageMap = new HashMap<>();
 
     private Position position = Position.BACKGROUND;
 
@@ -114,10 +114,6 @@ public class Overlay implements Closeabl
      */
     public PDDocument overlay(Map<Integer, String> specificPageOverlayMap) throws IOException
     {
-        if (inputPDFDocument == null)
-        {
-            throw new IllegalArgumentException("No input document");
-        }
         Map<String, LayoutPage> layouts = new HashMap<>();
         String path;
         loadPDFs();
@@ -130,9 +126,9 @@ public class Overlay implements Closeabl
                 PDDocument doc = loadPDF(path);
                 layoutPage = getLayoutPage(doc);
                 layouts.put(path, layoutPage);
-                openDocuments.add(doc);
+                openDocumentsSet.add(doc);
             }
-            specificPageOverlayPage.put(e.getKey(), layoutPage);
+            specificPageOverlayLayoutPageMap.put(e.getKey(), layoutPage);
         }
         processPages(inputPDFDocument);
         return inputPDFDocument;
@@ -142,7 +138,7 @@ public class Overlay implements Closeabl
      * This will add overlays documents to a document. If you created the overlay documents with
      * subsetted fonts, you need to save them first so that the subsetting gets done.
      *
-     * @param specificPageOverlayDocuments Optional map of overlay documents for specific pages. The
+     * @param specificPageOverlayDocumentMap Optional map of overlay documents for specific pages. The
      * page numbers are 1-based. The map must be empty (but not null) if no specific mappings are
      * used.
      *
@@ -152,15 +148,15 @@ public class Overlay implements Closeabl
      *
      * @throws IOException if something went wrong
      */
-    public PDDocument overlayDocuments(Map<Integer, PDDocument> specificPageOverlayDocuments) throws IOException
+    public PDDocument overlayDocuments(Map<Integer, PDDocument> specificPageOverlayDocumentMap) throws IOException
     {
         loadPDFs();
-        for (Map.Entry<Integer, PDDocument> e : specificPageOverlayDocuments.entrySet())
+        for (Map.Entry<Integer, PDDocument> e : specificPageOverlayDocumentMap.entrySet())
         {
             PDDocument doc = e.getValue();
             if (doc != null)
             {
-                specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
+                specificPageOverlayLayoutPageMap.put(e.getKey(), getLayoutPage(doc));
             }
         }
         processPages(inputPDFDocument);
@@ -199,16 +195,20 @@ public class Overlay implements Closeabl
         {
             evenPageOverlay.close();
         }
-        for (PDDocument doc : openDocuments)
+        for (PDDocument doc : openDocumentsSet)
         {
             doc.close();
         }
-        openDocuments.clear();
-        specificPageOverlayPage.clear();
+        openDocumentsSet.clear();
+        specificPageOverlayLayoutPageMap.clear();
     }
 
     private void loadPDFs() throws IOException
     {
+        if (inputPDFDocument == null)
+        {
+            throw new IllegalArgumentException("No input document");
+        }
         // input PDF
         if (inputFileName != null)
         {
@@ -266,9 +266,9 @@ public class Overlay implements Closeabl
         }
         if (allPagesOverlay != null)
         {
-            specificPageOverlayPage = getLayoutPages(allPagesOverlay);
+            specificPageOverlayLayoutPageMap = getLayoutPages(allPagesOverlay);
             useAllOverlayPages = true;
-            numberOfOverlayPages = specificPageOverlayPage.size();
+            numberOfOverlayPages = specificPageOverlayLayoutPageMap.size();
         }
     }
     
@@ -467,9 +467,9 @@ public class Overlay implements Closeabl
     private LayoutPage getLayoutPage(int pageNumber, int numberOfPages)
     {
         LayoutPage layoutPage = null;
-        if (!useAllOverlayPages && specificPageOverlayPage.containsKey(pageNumber))
+        if (!useAllOverlayPages && specificPageOverlayLayoutPageMap.containsKey(pageNumber))
         {
-            layoutPage = specificPageOverlayPage.get(pageNumber);
+            layoutPage = specificPageOverlayLayoutPageMap.get(pageNumber);
         }
         else if ((pageNumber == 1) && (firstPageOverlayPage != null))
         {
@@ -494,7 +494,7 @@ public class Overlay implements Closeabl
         else if (useAllOverlayPages)
         {
             int usePageNum = (pageNumber -1 ) % numberOfOverlayPages;
-            layoutPage = specificPageOverlayPage.get(usePageNum);
+            layoutPage = specificPageOverlayLayoutPageMap.get(usePageNum);
         }
         return layoutPage;
     }