]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2839: Links to pdf files with no scheme should open in pdf viewer
authorSimon Steiner <ssteiner@apache.org>
Wed, 19 Jan 2022 09:53:53 +0000 (09:53 +0000)
committerSimon Steiner <ssteiner@apache.org>
Wed, 19 Jan 2022 09:53:53 +0000 (09:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1897193 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java

index 57f8a17a95c0544c92d94b4882d36782f5b601e6..f0456a53f5b74e58ea4e126ab86311ce9c1dd24f 100644 (file)
@@ -589,6 +589,9 @@ public class PDFFactory {
             if (filename == null) {
                 filename = uri.getSchemeSpecificPart();
             }
+            if (scheme == null && filename.toLowerCase().endsWith(".pdf")) {
+                scheme = "file";
+            }
             if (scheme == null) {
                 return new PDFUri(uri.toASCIIString());
             } else if (scheme.equalsIgnoreCase("embedded-file")) {
index b4c6a52391c701f6d5bd01fdf5800ed3162ef62e..988a146686602aac7ee280bd82b96ba683052503 100644 (file)
@@ -123,12 +123,12 @@ public class PDFLinkTestCase {
             {"/foo/bar 2.pdf", quote("<< /Type /Filespec /F (/foo/bar 2.pdf)")},
 
             // PDF, Relative paths
-            {"foobar.pdf", quote("<< /URI (foobar.pdf)")}, //34
-            {"foo bar.pdf", quote("<< /URI (foo%20bar.pdf)")},
-            {"./foobar.pdf", quote("<< /URI (./foobar.pdf)")},
-            {"./foo bar.pdf", quote("<< /URI (./foo%20bar.pdf)")},
-            {"../foobar.pdf", quote("<< /URI (../foobar.pdf)")},
-            {"../foo bar.pdf", quote("<< /URI (../foo%20bar.pdf)")},
+            {"foobar.pdf", quote("<< /Type /Filespec /F (foobar.pdf)")}, //34
+            {"foo bar.pdf", quote("<< /Type /Filespec /F (foo bar.pdf)")},
+            {"./foobar.pdf", quote("<< /Type /Filespec /F (./foobar.pdf)")},
+            {"./foo bar.pdf", quote("<< /Type /Filespec /F (./foo bar.pdf)")},
+            {"../foobar.pdf", quote("<< /Type /Filespec /F (../foobar.pdf)")},
+            {"../foo bar.pdf", quote("<< /Type /Filespec /F (../foo bar.pdf)")},
 
             // PDF, Windows network paths
             {"\\\\foo\\bar.pdf", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)")}, //40
@@ -165,12 +165,18 @@ public class PDFLinkTestCase {
                     + quote("/D [ 2 /XYZ null null null ]")},
 
             // PDF with fragments, Relative paths
-            {"foobar.pdf#dest=aa", quote("<< /URI (foobar.pdf#dest=aa)")}, //55
-            {"foo bar.pdf#page=2", quote("<< /URI (foo%20bar.pdf#page=2)")},
-            {"./foobar.pdf#dest=aa", quote("<< /URI (./foobar.pdf#dest=aa)")},
-            {"./foo bar.pdf#page=2", quote("<< /URI (./foo%20bar.pdf#page=2)")},
-            {"../foobar.pdf#dest=aa", quote("<< /URI (../foobar.pdf#dest=aa)")},
-            {"../foo bar.pdf#page=2", quote("<< /URI (../foo%20bar.pdf#page=2)")},
+            {"foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (foobar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+                    + quote("/D (aa)")}, //55
+            {"foo bar.pdf#page=2", quote("<< /Type /Filespec /F (foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+                    + quote("/D [ 2 /XYZ null null null ]")},
+            {"./foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (./foobar.pdf)") + ".*" + quote("/S /GoToR")
+                    + ".*" + quote("/D (aa)")},
+            {"./foo bar.pdf#page=2", quote("<< /Type /Filespec /F (./foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+                    + quote("/D [ 2 /XYZ null null null ]")},
+            {"../foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (../foobar.pdf)") + ".*" + quote("/S /GoToR")
+                    + ".*" + quote("/D (aa)")},
+            {"../foo bar.pdf#page=2", quote("<< /Type /Filespec /F (../foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+                    + quote("/D [ 2 /XYZ null null null ]")},
 
             // PDF with fragments, Windows network paths
             {"\\\\foo\\bar.pdf#dest=aa", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)") + ".*"
@@ -393,7 +399,7 @@ public class PDFLinkTestCase {
             {"file:examples.html", quote("<< /Type /Filespec /F (examples.html)")},
 
             // parenthesis
-            {"simple_report_(version2.pdf", quote("<< /URI (simple_report_\\(version2.pdf)")}
+            {"simple_report_(version2.pdf", quote("<< /Type /Filespec /F (simple_report_\\(version2.pdf)")}
         });
     }
 
@@ -415,6 +421,6 @@ public class PDFLinkTestCase {
 
         Pattern r = Pattern.compile(expected);
         Matcher m = r.matcher(outString);
-        Assert.assertTrue(m.find());
+        Assert.assertTrue(target + " " + outString, m.find());
     }
 }