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 2020/09/27 13:31:12 UTC

svn commit: r1882070 - /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java

Author: tilman
Date: Sun Sep 27 13:31:12 2020
New Revision: 1882070

URL: http://svn.apache.org/viewvc?rev=1882070&view=rev
Log:
PDFBOX-4971: parametrize DocumentCreator class, add a raw view for content streams

Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java?rev=1882070&r1=1882069&r2=1882070&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/streampane/StreamPane.java Sun Sep 27 13:31:12 2020
@@ -115,7 +115,8 @@ public class StreamPane implements Actio
     private final JPanel panel;
     private final HexView hexView;
     private final JTabbedPane tabbedPane;
-    private final StreamPaneView view;
+    private final StreamPaneView rawView;
+    private final StreamPaneView niceView;
     private final Stream stream;
     private ToolTipController tTController;
     private PDResources resources;
@@ -146,8 +147,16 @@ public class StreamPane implements Actio
         panel.setPreferredSize(new Dimension(300, 500));
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
-        view = new StreamPaneView();
+        rawView = new StreamPaneView();
         hexView = new HexView();
+        if (isContentStream)
+        {
+            niceView = new StreamPaneView();
+        }
+        else
+        {
+            niceView = null;
+        }
 
         if (stream.isImage())
         {
@@ -163,11 +172,17 @@ public class StreamPane implements Actio
         tabbedPane = new JTabbedPane();
         if (stream.isImage())
         {
-            tabbedPane.add("Image view", view.getStreamPanel());
+            tabbedPane.add("Image view", rawView.getStreamPanel());
+        }
+        else if (isContentStream)
+        {
+            tabbedPane.add("Nice view", niceView.getStreamPanel());
+            tabbedPane.add("Raw view", rawView.getStreamPanel());
+            tabbedPane.add("Hex view", hexView.getPane());
         }
         else
         {
-            tabbedPane.add("Text view", view.getStreamPanel());
+            tabbedPane.add("Text view", rawView.getStreamPanel());
             tabbedPane.add("Hex view", hexView.getPane());
         }
 
@@ -205,12 +220,21 @@ public class StreamPane implements Actio
                 {
                     requestImageShowing();
                     tabbedPane.removeAll();
-                    tabbedPane.add("Image view", view.getStreamPanel());
+                    tabbedPane.add("Image view", rawView.getStreamPanel());
                     return;
                 }
                 tabbedPane.removeAll();
-                tabbedPane.add("Text view", view.getStreamPanel());
-                tabbedPane.add("Hex view", hexView.getPane());
+                if (isContentStream)
+                {
+                    tabbedPane.add("Nice view", rawView.getStreamPanel());
+                    tabbedPane.add("Raw view", niceView.getStreamPanel());
+                    tabbedPane.add("Hex view", hexView.getPane());
+                }
+                else
+                {
+                    tabbedPane.add("Text view", rawView.getStreamPanel());
+                    tabbedPane.add("Hex view", hexView.getPane());
+                }
                 requestStreamText(currentFilter);
             }
             catch (IOException e)
@@ -234,13 +258,17 @@ public class StreamPane implements Actio
                 JOptionPane.showMessageDialog(panel, "image not available (filter missing?)");
                 return;
             }
-            view.showStreamImage(image);
+            rawView.showStreamImage(image);
         }
     }
 
     private void requestStreamText(String command) throws IOException
     {
-        new DocumentCreator(command).execute();
+        new DocumentCreator(rawView, command, false).execute();
+        if (niceView != null)
+        {
+            new DocumentCreator(niceView, command, true).execute();
+        }
         synchronized (stream)
         {
             InputStream is = stream.getStream(command);
@@ -258,13 +286,17 @@ public class StreamPane implements Actio
      */
     private final class DocumentCreator extends SwingWorker<StyledDocument, Integer>
     {
+        private final StreamPaneView targetView;
         private final String filterKey;
+        private final boolean nice;
         private int indent;
         private boolean needIndent;
 
-        private DocumentCreator(String filterKey)
+        private DocumentCreator(StreamPaneView targetView, String filterKey, boolean nice)
         {
+            this.targetView = targetView;
             this.filterKey = filterKey;
+            this.nice = nice;
         }
 
         @Override
@@ -279,14 +311,14 @@ public class StreamPane implements Actio
                     encoding = "UTF-8";
                 }
                 InputStream inputStream = stream.getStream(filterKey);
-                if (isContentStream && Stream.UNFILTERED.equals(filterKey))
+                if (nice && Stream.UNFILTERED.equals(filterKey))
                 {
                     StyledDocument document = getContentStreamDocument(inputStream);
                     if (document != null)
                     {
                         return document;
                     }
-                    return getDocument(stream.getStream(filterKey), encoding);
+                    return getDocument(inputStream, encoding);
                 }
                 return getDocument(inputStream, encoding);
             }
@@ -297,7 +329,7 @@ public class StreamPane implements Actio
         {
             try
             {
-                view.showStreamText(get(), tTController);
+                targetView.showStreamText(get(), tTController);
             }
             catch (InterruptedException e)
             {
@@ -330,6 +362,15 @@ public class StreamPane implements Actio
             if (inputStream != null)
             {
                 String data = getStringOfStream(inputStream, encoding);
+
+                // CR is not displayed in the raw view (see file from PDFBOX-4964),
+                // but LF is displayed, so lets first replace CR LF with LF and then
+                // replace the remaining CRs with LF
+                if (data != null)
+                {
+                    data = data.replace("\r\n", "\n").replace('\r', '\n');
+                }
+
                 try
                 {
                     docu.insertString(0, data, null);