pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1685649 - in /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools: PDFDebugger.java pdfdebugger/colorpane/CSArrayBased.java pdfdebugger/pagepane/ pdfdebugger/pagepane/PagePane.java
Date Mon, 15 Jun 2015 18:11:01 GMT
Author: tilman
Date: Mon Jun 15 18:11:00 2015
New Revision: 1685649

URL: http://svn.apache.org/r1685649
Log:
PDFBOX-2530: dereference COSObject after url select, as done by Khyrul Bashar in GSoC2015;
display "other" colorspace names in right pane; display page number in right pane

Added:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java
  (with props)
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java
  (with props)
Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java?rev=1685649&r1=1685648&r2=1685649&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java Mon Jun 15 18:11:00
2015
@@ -60,9 +60,13 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.IOException;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSDeviceN;
 import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSIndexed;
+import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSArrayBased;
 import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSSeparation;
+import org.apache.pdfbox.tools.pdfdebugger.pagepane.PagePane;
 import org.apache.pdfbox.tools.util.FileOpenSaveDialog;
 import org.apache.pdfbox.tools.pdfdebugger.ui.Tree;
 import org.apache.pdfbox.tools.pdfdebugger.treestatus.TreeStatus;
@@ -85,6 +89,9 @@ public class PDFDebugger extends javax.s
     private static final Set<COSName> SPECIALCOLORSPACES =
             new HashSet(Arrays.asList(COSName.INDEXED, COSName.SEPARATION, COSName.DEVICEN));
 
+    private static final Set<COSName> OTHERCOLORSPACES =
+            new HashSet(Arrays.asList(COSName.ICCBASED, COSName.PATTERN, COSName.CALGRAY,
COSName.CALRGB, COSName.LAB));
+
     private static final String PASSWORD = "-password";
 
     /**
@@ -278,11 +285,16 @@ public class PDFDebugger extends javax.s
             try
             {
                 Object selectedNode = path.getLastPathComponent();
-                if (isSpecialColorSpace(selectedNode))
+                if (isSpecialColorSpace(selectedNode) || isOtherColorSpace(selectedNode))
                 {
                     showColorPane(selectedNode);
                     return;
                 }
+                if (isPage(selectedNode))
+                {
+                    showPage(selectedNode);
+                    return;
+                }
                 if (!jSplitPane1.getRightComponent().equals(jScrollPane2))
                 {
                     jSplitPane1.setRightComponent(jScrollPane2);
@@ -314,6 +326,11 @@ public class PDFDebugger extends javax.s
         {
             selectedNode = ((ArrayEntry) selectedNode).getValue();
         }
+        
+        if (selectedNode instanceof COSObject)
+        {
+            selectedNode = ((COSObject)selectedNode).getObject();
+        }
 
         if (selectedNode instanceof COSArray)
         {
@@ -327,6 +344,62 @@ public class PDFDebugger extends javax.s
         return false;
     }
 
+    private boolean isOtherColorSpace(Object selectedNode)
+    {
+        if (selectedNode instanceof MapEntry)
+        {
+            selectedNode = ((MapEntry) selectedNode).getValue();
+        }
+        else if (selectedNode instanceof ArrayEntry)
+        {
+            selectedNode = ((ArrayEntry) selectedNode).getValue();
+        }
+
+        if (selectedNode instanceof COSObject)
+        {
+            selectedNode = ((COSObject) selectedNode).getObject();
+        }
+
+        if (selectedNode instanceof COSArray)
+        {
+            COSBase arrayEntry = ((COSArray)selectedNode).get(0);
+            if (arrayEntry instanceof COSName)
+            {
+                COSName name = (COSName) arrayEntry;
+                return OTHERCOLORSPACES.contains(name);
+            }
+        }
+        return false;
+    }
+
+    private boolean isPage(Object selectedNode)
+    {
+        if (selectedNode instanceof MapEntry)
+        {
+            selectedNode = ((MapEntry) selectedNode).getValue();
+        }
+        else if (selectedNode instanceof ArrayEntry)
+        {
+            selectedNode = ((ArrayEntry) selectedNode).getValue();
+        }
+
+        if (selectedNode instanceof COSObject)
+        {
+            selectedNode = ((COSObject) selectedNode).getObject();
+        }
+
+        if (selectedNode instanceof COSDictionary)
+        {
+            COSDictionary dict = (COSDictionary) selectedNode;
+            COSBase typeItem = dict.getItem(COSName.TYPE);
+            if (COSName.PAGE.equals(typeItem))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Show a Panel describing the special color spaces in more detail and interactive way.
      * For now only Separation Color space is shown.
@@ -342,6 +415,11 @@ public class PDFDebugger extends javax.s
         {
             csNode = ((ArrayEntry) csNode).getValue();
         }
+        
+        if (csNode instanceof COSObject)
+        {
+            csNode = ((COSObject)csNode).getObject();
+        }
 
         if (csNode instanceof COSArray)
         {
@@ -362,6 +440,37 @@ public class PDFDebugger extends javax.s
                 {
                     jSplitPane1.setRightComponent(new CSIndexed(array).getPanel());
                 }
+                else if (OTHERCOLORSPACES.contains(csName))
+                {
+                    jSplitPane1.setRightComponent(new CSArrayBased(array).getPanel());
+                }
+            }
+        }
+    }
+
+    private void showPage(Object selectedNode)
+    {
+        if (selectedNode instanceof MapEntry)
+        {
+            selectedNode = ((MapEntry) selectedNode).getValue();
+        }
+        else if (selectedNode instanceof ArrayEntry)
+        {
+            selectedNode = ((ArrayEntry) selectedNode).getValue();
+        }
+     
+        if (selectedNode instanceof COSArray)
+        {
+            selectedNode = ((COSObject) selectedNode).getObject();
+        }
+        
+        if (selectedNode instanceof COSDictionary)
+        {
+            COSDictionary page = (COSDictionary) selectedNode;
+            COSBase typeItem = page.getItem(COSName.TYPE);
+            if (COSName.PAGE.equals(typeItem))
+            {
+                jSplitPane1.setRightComponent(new PagePane(page).getPanel());
             }
         }
     }

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java?rev=1685649&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java
Mon Jun 15 18:11:00 2015
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.tools.pdfdebugger.colorpane;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.io.IOException;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
+
+/**
+ *
+ * @author Tilman Hausherr
+ *
+ * Simple pane to show a title and detail on the color spaces that have no visual "magic".
+ */
+public class CSArrayBased
+{
+    private JPanel panel;
+    private PDColorSpace colorSpace = null;
+    private int numberOfComponents = 0;
+    private String errmsg = "";
+
+    public CSArrayBased(COSArray array)
+    {
+        try
+        {
+            colorSpace = PDColorSpace.create(array);
+            if (!(colorSpace instanceof PDPattern))
+            {
+                numberOfComponents = colorSpace.getNumberOfComponents();
+            }
+        }
+        catch (IOException ex)
+        {
+            errmsg = ex.getMessage();
+        }
+        initUI();
+    }
+
+    private void initUI()
+    {
+        panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+        panel.setPreferredSize(new Dimension(300, 500));
+
+        if (colorSpace == null)
+        {
+            JLabel error = new JLabel(errmsg);
+            error.setAlignmentX(Component.CENTER_ALIGNMENT);
+            error.setFont(new Font(Font.MONOSPACED, Font.BOLD, 15));
+            panel.add(error);
+            return;
+        }
+        
+        JLabel colorSpaceLabel = new JLabel(colorSpace.getName() + " colorspace");
+        colorSpaceLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+        colorSpaceLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 30));
+        panel.add(colorSpaceLabel);
+
+        if (numberOfComponents > 0)
+        {
+            JLabel colorCountLabel = new JLabel("Component Count: " + numberOfComponents);
+            colorCountLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+            colorCountLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
+            panel.add(colorCountLabel);
+        }
+    }
+
+    /**
+     * return the main panel that hold all the UI elements.
+     *
+     * @return JPanel instance
+     */
+    public Component getPanel()
+    {
+        return panel;
+    }
+
+}

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSArrayBased.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java?rev=1685649&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java
Mon Jun 15 18:11:00 2015
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.tools.pdfdebugger.pagepane;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageTree;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class PagePane
+{
+    private JPanel panel;
+    private int pageIndex = -1;
+
+    public PagePane(COSDictionary page)
+    {
+        COSBase parent = page;
+        
+        // copied from PDPageDestination.retrievePageNumber()
+        //TODO should this become a utility method of PDPageTree?
+        while (((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P) !=
null)
+        {
+            parent = ((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P);
+        }
+        // now parent is the pages node
+        PDPageTree pages = new PDPageTree((COSDictionary) parent);
+        pageIndex = pages.indexOf(new PDPage(page));
+
+        initUI();
+    }
+
+    private void initUI()
+    {
+        panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+        panel.setPreferredSize(new Dimension(300, 500));
+
+        String pageLabelText = pageIndex < 0 ? "Page number not found" : "Page " + (pageIndex
+ 1);
+        
+        JLabel pageLabel = new JLabel(pageLabelText);
+        pageLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
+        pageLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 30));
+        panel.add(pageLabel);
+    }
+
+    /**
+     * return the main panel that hold all the UI elements.
+     *
+     * @return JPanel instance
+     */
+    public Component getPanel()
+    {
+        return panel;
+    }
+
+}

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/pagepane/PagePane.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message