├── .classpath
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── LICENSE.txt
├── README.md
├── build.xml
├── pom.xml
├── src
├── com
│ └── sun
│ │ └── pdfview
│ │ ├── BaseWatchable.java
│ │ ├── ByteBufferInputStream.java
│ │ ├── Cache.java
│ │ ├── Configuration.java
│ │ ├── HexDump.java
│ │ ├── Identity8BitCharsetEncoder.java
│ │ ├── ImageInfo.java
│ │ ├── NameTree.java
│ │ ├── OutlineNode.java
│ │ ├── PDFCmd.java
│ │ ├── PDFDebugger.java
│ │ ├── PDFDestination.java
│ │ ├── PDFDocCharsetEncoder.java
│ │ ├── PDFErrorHandler.java
│ │ ├── PDFFile.java
│ │ ├── PDFImage.java
│ │ ├── PDFImageParseException.java
│ │ ├── PDFObject.java
│ │ ├── PDFPage.java
│ │ ├── PDFPaint.java
│ │ ├── PDFParseException.java
│ │ ├── PDFParser.java
│ │ ├── PDFRenderer.java
│ │ ├── PDFShapeCmd.java
│ │ ├── PDFStringUtil.java
│ │ ├── PDFTextFormat.java
│ │ ├── PDFXref.java
│ │ ├── PdfSubByteSampleModel.java
│ │ ├── RefImage.java
│ │ ├── Watchable.java
│ │ ├── action
│ │ ├── GoToAction.java
│ │ ├── GoToEAction.java
│ │ ├── GoToRAction.java
│ │ ├── LaunchAction.java
│ │ ├── PDFAction.java
│ │ ├── PdfObjectParseUtil.java
│ │ └── UriAction.java
│ │ ├── annotation
│ │ ├── AnnotationBorderStyle.java
│ │ ├── AnnotationType.java
│ │ ├── CircleAnnotation.java
│ │ ├── FreetextAnnotation.java
│ │ ├── LinkAnnotation.java
│ │ ├── MarkupAnnotation.java
│ │ ├── PDFAnnotation.java
│ │ ├── SquareAnnotation.java
│ │ ├── StampAnnotation.java
│ │ ├── TextMarkupAnnotation.java
│ │ └── WidgetAnnotation.java
│ │ ├── colorspace
│ │ ├── AltColorSpace.java
│ │ ├── AlternateColorSpace.java
│ │ ├── CMYKColorSpace.java
│ │ ├── CalGrayColor.java
│ │ ├── CalRGBColor.java
│ │ ├── IndexedColor.java
│ │ ├── LabColor.java
│ │ ├── MaskColorSpace.java
│ │ ├── PDFColorSpace.java
│ │ ├── PatternSpace.java
│ │ ├── YCCKColorSpace.java
│ │ └── sGray.icc
│ │ ├── decode
│ │ ├── ASCII85Decode.java
│ │ ├── ASCIIHexDecode.java
│ │ ├── CCITTCodes
│ │ ├── CCITTFaxDecode.java
│ │ ├── CCITTFaxDecoder.java
│ │ ├── DCTDecode.java
│ │ ├── FlateDecode.java
│ │ ├── ImageDataDecoder.java
│ │ ├── JBig2Decode.java
│ │ ├── JPXDecode.java
│ │ ├── LZWDecode.java
│ │ ├── PDFDecoder.java
│ │ ├── PNGPredictor.java
│ │ ├── Predictor.java
│ │ ├── RunLengthDecode.java
│ │ └── TIFFPredictor.java
│ │ ├── decrypt
│ │ ├── CryptFilterDecrypter.java
│ │ ├── EncryptionUnsupportedByPlatformException.java
│ │ ├── EncryptionUnsupportedByProductException.java
│ │ ├── IdentityDecrypter.java
│ │ ├── PDFAuthenticationFailureException.java
│ │ ├── PDFDecrypter.java
│ │ ├── PDFDecrypterFactory.java
│ │ ├── PDFPassword.java
│ │ ├── StandardDecrypter.java
│ │ └── UnsupportedEncryptionException.java
│ │ ├── font
│ │ ├── BuiltinFont.java
│ │ ├── CIDFontType0.java
│ │ ├── CIDFontType2.java
│ │ ├── FlPoint.java
│ │ ├── FontSupport.java
│ │ ├── NativeFont.java
│ │ ├── OutlineFont.java
│ │ ├── PDFFont.java
│ │ ├── PDFFontDescriptor.java
│ │ ├── PDFFontEncoding.java
│ │ ├── PDFGlyph.java
│ │ ├── TTFFont.java
│ │ ├── Type0Font.java
│ │ ├── Type1CFont.java
│ │ ├── Type1Font.java
│ │ ├── Type3Font.java
│ │ ├── cid
│ │ │ ├── PDFCMap.java
│ │ │ └── ToUnicodeMap.java
│ │ ├── res
│ │ │ ├── BaseFonts.properties
│ │ │ ├── d050000l.pfb
│ │ │ ├── n019003l.pfb
│ │ │ ├── n019004l.pfb
│ │ │ ├── n019023l.pfb
│ │ │ ├── n019024l.pfb
│ │ │ ├── n021003l.pfb
│ │ │ ├── n021004l.pfb
│ │ │ ├── n021023l.pfb
│ │ │ ├── n021024l.pfb
│ │ │ ├── n022003l.pfb
│ │ │ ├── n022004l.pfb
│ │ │ ├── n022023l.pfb
│ │ │ ├── n022024l.pfb
│ │ │ └── s050000l.pfb
│ │ └── ttf
│ │ │ ├── AdobeGlyphList.java
│ │ │ ├── CMap.java
│ │ │ ├── CMapFormat0.java
│ │ │ ├── CMapFormat4.java
│ │ │ ├── CMapFormat6.java
│ │ │ ├── CmapTable.java
│ │ │ ├── Glyf.java
│ │ │ ├── GlyfCompound.java
│ │ │ ├── GlyfSimple.java
│ │ │ ├── GlyfTable.java
│ │ │ ├── HeadTable.java
│ │ │ ├── HheaTable.java
│ │ │ ├── HmtxTable.java
│ │ │ ├── LocaTable.java
│ │ │ ├── MaxpTable.java
│ │ │ ├── NameTable.java
│ │ │ ├── PostTable.java
│ │ │ ├── TrueTypeFont.java
│ │ │ ├── TrueTypeTable.java
│ │ │ └── resource
│ │ │ └── glyphlist.txt
│ │ ├── function
│ │ ├── FunctionType0.java
│ │ ├── FunctionType2.java
│ │ ├── FunctionType3.java
│ │ ├── FunctionType4.java
│ │ ├── PDFFunction.java
│ │ └── postscript
│ │ │ ├── PostScriptParser.java
│ │ │ └── operation
│ │ │ ├── Abs.java
│ │ │ ├── Add.java
│ │ │ ├── And.java
│ │ │ ├── Atan.java
│ │ │ ├── Bitshift.java
│ │ │ ├── Ceiling.java
│ │ │ ├── Copy.java
│ │ │ ├── Cvi.java
│ │ │ ├── Cvr.java
│ │ │ ├── Div.java
│ │ │ ├── Dup.java
│ │ │ ├── Eq.java
│ │ │ ├── Exch.java
│ │ │ ├── Exp.java
│ │ │ ├── Expression.java
│ │ │ ├── False.java
│ │ │ ├── Floor.java
│ │ │ ├── Ge.java
│ │ │ ├── Gt.java
│ │ │ ├── Idiv.java
│ │ │ ├── If.java
│ │ │ ├── IfElse.java
│ │ │ ├── Index.java
│ │ │ ├── Le.java
│ │ │ ├── Ln.java
│ │ │ ├── Log.java
│ │ │ ├── Lt.java
│ │ │ ├── Mod.java
│ │ │ ├── Mul.java
│ │ │ ├── Ne.java
│ │ │ ├── Neg.java
│ │ │ ├── Not.java
│ │ │ ├── OperationSet.java
│ │ │ ├── Or.java
│ │ │ ├── Pop.java
│ │ │ ├── PostScriptOperation.java
│ │ │ ├── PushAsNumber.java
│ │ │ ├── Roll.java
│ │ │ ├── Round.java
│ │ │ ├── Sin.java
│ │ │ ├── Sqrt.java
│ │ │ ├── Sub.java
│ │ │ ├── True.java
│ │ │ ├── Truncate.java
│ │ │ └── Xor.java
│ │ └── pattern
│ │ ├── DummyShader.java
│ │ ├── PDFPattern.java
│ │ ├── PDFShader.java
│ │ ├── PatternType1.java
│ │ ├── PatternType2.java
│ │ ├── ShaderType2.java
│ │ └── ShaderType3.java
└── test
│ └── myrenderer
│ ├── MyPdfRenderer.java
│ └── PDFDisplay.java
├── stdclasses
├── ch
│ └── randelshofer
│ │ ├── io
│ │ ├── BoundedRangeInputStream.class
│ │ └── ByteArrayImageInputStream.class
│ │ ├── media
│ │ └── jpeg
│ │ │ ├── Generic_CMYK_Profile.icc
│ │ │ ├── JFIFInputStream$Segment.class
│ │ │ ├── JFIFInputStream.class
│ │ │ └── JPEGImageIO.class
│ │ ├── quaqua
│ │ ├── BasicBrowserUI.class
│ │ ├── BrowserPreviewRenderer.class
│ │ ├── BrowserUI.class
│ │ ├── DefaultBrowserCellRenderer$1.class
│ │ ├── DefaultBrowserCellRenderer$2.class
│ │ ├── DefaultBrowserCellRenderer$3.class
│ │ ├── DefaultBrowserCellRenderer.class
│ │ ├── JBrowser$1.class
│ │ ├── JBrowser$ColumnFocusListener.class
│ │ ├── JBrowser$ColumnKeyListener.class
│ │ ├── JBrowser$ColumnListModel.class
│ │ ├── JBrowser$ColumnMouseListener.class
│ │ ├── JBrowser$ColumnSelectionModel.class
│ │ ├── JBrowser$SelectionModeUpdater.class
│ │ ├── JBrowser$TreeSelectionUpdater.class
│ │ ├── JBrowser.class
│ │ ├── JBrowserViewport$1.class
│ │ ├── JBrowserViewport.class
│ │ ├── images
│ │ │ └── Browser.disclosureIcons.png
│ │ └── util
│ │ │ ├── Images.class
│ │ │ └── SizeConstrainedPanel.class
│ │ └── util
│ │ ├── Applets.class
│ │ └── ArrayUtil.class
└── unpublic
│ └── jbig2.jar
└── test
└── src
└── com
└── sun
└── pdfview
└── function
└── postscript
└── PostScriptOPTest.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /build/
3 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PDFrenderer
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | org.swinglabs
5 | pdf-renderer
6 | jar
7 | PDF Renderer
8 | 1.0.5.1
9 | http://www.swinglabs.org/
10 |
11 |
12 | Lesser General Public License (LGPL)
13 | http://www.gnu.org/copyleft/lesser.html
14 |
15 |
16 | PDF renderer implementation supporting the subset of PDF 1.4 specification.
17 |
18 | 1.6
19 |
20 |
21 | src
22 |
23 |
24 | org.codehaus.mojo
25 | build-helper-maven-plugin
26 | 3.3.0
27 |
28 |
29 | generate-resources
30 |
31 | add-resource
32 |
33 |
34 |
35 |
36 | ${project.basedir}/stdclasses
37 |
38 |
39 | ${project.basedir}/src
40 |
41 | **/*.java
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-compiler-plugin
53 | 3.9.0
54 |
55 | ${java.version}
56 | ${java.version}
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.jpedal
64 | jbig2
65 | 0.0.1
66 | system
67 | ${project.basedir}/stdclasses/unpublic/jbig2.jar
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/ByteBufferInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.nio.ByteBuffer;
24 |
25 | /**
26 | * Exposes a {@link ByteBuffer} as an {@link InputStream}.
27 | *
28 | * @author Luke Kirby
29 | */
30 | public class ByteBufferInputStream extends InputStream {
31 |
32 | /** The underlying byte buffer */
33 | private ByteBuffer buffer;
34 |
35 | /**
36 | * Class constructor
37 | * @param buffer the buffer to present as an input stream, positioned
38 | * at the current read position of the byte buffer
39 | */
40 | public ByteBufferInputStream(ByteBuffer buffer) {
41 | this.buffer = buffer;
42 | }
43 |
44 | @Override
45 | public int read(byte[] b, int off, int len) throws IOException {
46 |
47 | if (b == null) {
48 | throw new NullPointerException();
49 | } else if (off < 0 || len < 0 || len > b.length - off) {
50 | throw new IndexOutOfBoundsException();
51 | } else if (len == 0) {
52 | return 0;
53 | }
54 |
55 | final int remaining = buffer.remaining();
56 | if (remaining == 0) {
57 | return -1;
58 | } else if (remaining < len) {
59 | buffer.get(b, off, remaining);
60 | return remaining;
61 | } else {
62 | buffer.get(b, off, len);
63 | return len;
64 | }
65 | }
66 |
67 | @Override
68 | public long skip(long n) throws IOException {
69 | if (n <= 0) {
70 | return 0;
71 | } else {
72 | final int remaining = buffer.remaining();
73 | if (n < remaining) {
74 | buffer.position(buffer.position() + remaining);
75 | return remaining;
76 | } else {
77 | buffer.position((int) (buffer.position() + n));
78 | return n;
79 | }
80 | }
81 | }
82 |
83 | @Override
84 | public int read() throws IOException {
85 | return buffer.get();
86 | }
87 |
88 | @Override
89 | public int available() throws IOException {
90 | return buffer.remaining();
91 | }
92 |
93 | @Override
94 | public void mark(int readlimit) {
95 | buffer.mark();
96 | }
97 |
98 | @Override
99 | public boolean markSupported() {
100 | return true;
101 | }
102 |
103 | @Override
104 | public void reset() throws IOException {
105 | buffer.reset();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/HexDump.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.io.IOException;
22 | import java.io.RandomAccessFile;
23 |
24 | public class HexDump {
25 |
26 | public static void printData(byte[] data) {
27 | char[] parts = new char[17];
28 | int partsloc = 0;
29 | for (int i = 0; i < data.length; i++) {
30 | int d = (data[i]) & 0xff;
31 | if (d == 0) {
32 | parts[partsloc++] = '.';
33 | } else if (d < 32 || d >= 127) {
34 | parts[partsloc++] = '?';
35 | } else {
36 | parts[partsloc++] = (char) d;
37 | }
38 | if (i % 16 == 0) {
39 | int start = Integer.toHexString(data.length).length();
40 | int end = Integer.toHexString(i).length();
41 |
42 | for (int j = start; j > end; j--) {
43 | System.out.print("0");
44 | }
45 | System.out.print(Integer.toHexString(i) + ": ");
46 | }
47 | if (d < 16) {
48 | System.out.print("0" + Integer.toHexString(d));
49 | } else {
50 | System.out.print(Integer.toHexString(d));
51 | }
52 | if ((i & 15) == 15 || i == data.length - 1) {
53 | System.out.println(" " + new String(parts));
54 | partsloc = 0;
55 | } else if ((i & 7) == 7) {
56 | System.out.print(" ");
57 | parts[partsloc++] = ' ';
58 | } else if ((i & 1) == 1) {
59 | System.out.print(" ");
60 | }
61 | }
62 | System.out.println();
63 | }
64 |
65 | public static void main(String args[]) {
66 | if (args.length != 1) {
67 | System.out.println("Usage: ");
68 | System.out.println(" HexDump ");
69 | System.exit(-1);
70 | }
71 |
72 | try {
73 | RandomAccessFile raf = new RandomAccessFile(args[0], "r");
74 |
75 | int size = (int) raf.length();
76 | byte[] data = new byte[size];
77 |
78 | raf.readFully(data);
79 | printData(data);
80 | } catch (IOException ioe) {
81 | BaseWatchable.getErrorHandler().publishException(ioe);
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/Identity8BitCharsetEncoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview;
21 |
22 | import java.nio.charset.CharsetEncoder;
23 | import java.nio.charset.CoderResult;
24 | import java.nio.CharBuffer;
25 | import java.nio.ByteBuffer;
26 |
27 | /**
28 | * A {@link CharsetEncoder} that attempts to write out the lower 8 bits
29 | * of any character. Characters >= 256 in value are regarded
30 | * as unmappable.
31 | *
32 | * @author Luke Kirby
33 | */
34 | public class Identity8BitCharsetEncoder extends CharsetEncoder {
35 |
36 | public Identity8BitCharsetEncoder() {
37 | super(null, 1, 1);
38 | }
39 |
40 | @Override
41 | protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
42 | while (in.remaining() > 0) {
43 | if (out.remaining() < 1) {
44 | return CoderResult.OVERFLOW;
45 | }
46 | final char c = in.get();
47 | if (c >= 0 && c < 256) {
48 | out.put((byte) c);
49 | } else {
50 | return CoderResult.unmappableForLength(1);
51 | }
52 | }
53 | return CoderResult.UNDERFLOW;
54 | }
55 |
56 | @Override
57 | public boolean isLegalReplacement(byte[] repl) {
58 | // avoid referencing the non-existent character set
59 | return true;
60 | }
61 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/ImageInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.awt.geom.Rectangle2D;
22 | import java.awt.Color;
23 |
24 | public class ImageInfo {
25 |
26 | int width;
27 | int height;
28 | Rectangle2D clip;
29 | Color bgColor;
30 |
31 | public ImageInfo(int width, int height, Rectangle2D clip) {
32 | this(width, height, clip, Color.WHITE);
33 | }
34 |
35 | public ImageInfo(int width, int height, Rectangle2D clip, Color bgColor) {
36 | this.width = width;
37 | this.height = height;
38 | this.clip = clip;
39 | this.bgColor = bgColor;
40 | }
41 |
42 | // a hashcode that uses width, height and clip to generate its number
43 | @Override
44 | public int hashCode() {
45 | int code = (this.width ^ this.height << 16);
46 |
47 | if (this.clip != null) {
48 | code ^= ((int) this.clip.getWidth() | (int) this.clip.getHeight()) << 8;
49 | code ^= ((int) this.clip.getMinX() | (int) this.clip.getMinY());
50 | }
51 |
52 | return code;
53 | }
54 |
55 | // an equals method that compares values
56 | @Override
57 | public boolean equals(Object o) {
58 | if (!(o instanceof ImageInfo)) {
59 | return false;
60 | }
61 |
62 | ImageInfo ii = (ImageInfo) o;
63 |
64 | if (this.width != ii.width || this.height != ii.height) {
65 | return false;
66 | } else if (this.clip != null && ii.clip != null) {
67 | return this.clip.equals(ii.clip);
68 | } else if (this.clip == null && ii.clip == null) {
69 | return true;
70 | } else {
71 | return false;
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/OutlineNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import javax.swing.tree.DefaultMutableTreeNode;
22 |
23 | import com.sun.pdfview.action.PDFAction;
24 |
25 | public class OutlineNode extends DefaultMutableTreeNode {
26 | // the name of this node
27 |
28 | private String title;
29 |
30 | /**
31 | * Create a new outline node
32 | *
33 | * @param title the node's visible name in the tree
34 | */
35 | public OutlineNode(String title) {
36 | this.title = title;
37 | }
38 |
39 | /**
40 | * Get the PDF action associated with this node
41 | */
42 | public PDFAction getAction() {
43 | return (PDFAction) getUserObject();
44 | }
45 |
46 | /**
47 | * Set the PDF action associated with this node
48 | */
49 | public void setAction(PDFAction action) {
50 | setUserObject(action);
51 | }
52 |
53 | /**
54 | * Return the node's visible name in the tree
55 | */
56 | @Override
57 | public String toString() {
58 | return this.title;
59 | }
60 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFCmd.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.awt.geom.Rectangle2D;
22 |
23 | /**
24 | * The abstract superclass of all drawing commands for a PDFPage.
25 | * @author Mike Wessler
26 | */
27 | public abstract class PDFCmd {
28 |
29 | /**
30 | * mark the page or change the graphics state
31 | * @param state the current graphics state; may be modified during
32 | * execution.
33 | * @return the region of the page made dirty by executing this command
34 | * or null if no region was touched. Note this value should be
35 | * in the coordinates of the image touched, not the page.
36 | */
37 | public abstract Rectangle2D execute(PDFRenderer state);
38 |
39 | /**
40 | * a human readable representation of this command
41 | */
42 | @Override
43 | public String toString() {
44 | String name = getClass().getName();
45 | int lastDot = name.lastIndexOf('.');
46 | if (lastDot >= 0) {
47 | return name.substring(lastDot + 1);
48 | } else {
49 | return name;
50 | }
51 | }
52 |
53 | /**
54 | * the details of this command
55 | */
56 | public String getDetails() {
57 | return super.toString();
58 | }
59 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFDocCharsetEncoder.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
2 | * Fortitude Valley, Queensland, Australia
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | package com.sun.pdfview;
20 |
21 | import java.nio.ByteBuffer;
22 | import java.nio.CharBuffer;
23 | import java.nio.charset.CharsetEncoder;
24 | import java.nio.charset.CoderResult;
25 | import java.util.HashMap;
26 | import java.util.Map;
27 |
28 | /**
29 | * Encodes into a PDFDocEncoding representation. Note that only 256 characters
30 | * (if that) are represented in the PDFDocEncoding, so users should be
31 | * prepared to deal with unmappable character exceptions.
32 | *
33 | * @see "PDF Reference version 1.7, Appendix D"
34 | *
35 | * @author Luke Kirby
36 | */
37 | public class PDFDocCharsetEncoder extends CharsetEncoder {
38 |
39 | /**
40 | * Identify whether a particular character preserves the same byte value
41 | * upon encoding in PDFDocEncoding
42 | * @param ch the character
43 | * @return whether the character is identity encoded
44 | */
45 | public static boolean isIdentityEncoding(char ch) {
46 | return ch >= 0 && ch <= 255 && IDENT_PDF_DOC_ENCODING_MAP[ch];
47 |
48 | }
49 |
50 | /**
51 | * For each character that exists in PDFDocEncoding, identifies whether
52 | * the byte value in UTF-16BE is the same as it is in PDFDocEncoding
53 | */
54 | final static boolean[] IDENT_PDF_DOC_ENCODING_MAP = new boolean[256];
55 |
56 | /**
57 | * For non-identity encoded characters, maps from the character to
58 | * the byte value in PDFDocEncoding. If an entry for a non-identity
59 | * coded character is absent from this map, that character is unmappable
60 | * in the PDFDocEncoding.
61 | */
62 | final static Map EXTENDED_TO_PDF_DOC_ENCODING_MAP =
63 | new HashMap();
64 | static
65 | {
66 | for (byte i = 0; i < PDFStringUtil.PDF_DOC_ENCODING_MAP.length; ++i) {
67 | final char c = PDFStringUtil.PDF_DOC_ENCODING_MAP[i];
68 | final boolean identical = (c == i);
69 | IDENT_PDF_DOC_ENCODING_MAP[i] = identical;
70 | if (!identical) {
71 | EXTENDED_TO_PDF_DOC_ENCODING_MAP.put(c, i);
72 | }
73 | }
74 | }
75 |
76 | public PDFDocCharsetEncoder() {
77 | super(null, 1, 1);
78 | }
79 |
80 | @Override
81 | protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
82 | while (in.remaining() > 0) {
83 | if (out.remaining() < 1) {
84 | return CoderResult.OVERFLOW;
85 | }
86 | final char c = in.get();
87 | if (c >= 0 && c < 256 && IDENT_PDF_DOC_ENCODING_MAP[c]) {
88 | out.put((byte) c);
89 | } else {
90 | final Byte mapped = EXTENDED_TO_PDF_DOC_ENCODING_MAP.get(c);
91 | if (mapped != null) {
92 | out.put(mapped);
93 | } else {
94 | return CoderResult.unmappableForLength(1);
95 | }
96 | }
97 | }
98 | return CoderResult.UNDERFLOW;
99 | }
100 |
101 | @Override
102 | public boolean isLegalReplacement(byte[] repl) {
103 | // avoid referencing the non-existent character set
104 | return true;
105 | }
106 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview;
2 |
3 | /**
4 | * Simple class to handle exceptions - as default we just print the stack trace
5 | * but it's possible to inject another behaviour
6 | * @author xond
7 | *
8 | */
9 | public class PDFErrorHandler {
10 |
11 | public void publishException(Throwable e){
12 | e.printStackTrace();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFImageParseException.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * an exception class for recording errors when parsing an PDFImage
7 | * @author Katja Sondermann
8 | */
9 | public class PDFImageParseException extends IOException {
10 | public PDFImageParseException(String msg) {
11 | super(msg);
12 | }
13 |
14 | public PDFImageParseException(String msg, Throwable cause) {
15 | this(msg);
16 | initCause(cause);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFPaint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.awt.Color;
22 | import java.awt.Graphics2D;
23 | import java.awt.Paint;
24 | import java.awt.geom.GeneralPath;
25 | import java.awt.geom.Rectangle2D;
26 |
27 | /**
28 | * PDFPaint is some kind of shader that knows how to fill a path.
29 | * At the moment, only a solid color is implemented, but gradients
30 | * and textures should be possible, too.
31 | * @author Mike Wessler
32 | */
33 | public class PDFPaint {
34 |
35 | private Paint mainPaint;
36 |
37 | /**
38 | * create a new PDFPaint based on a solid color
39 | */
40 | protected PDFPaint(Paint p) {
41 | this.mainPaint = p;
42 | }
43 |
44 | /**
45 | * get the PDFPaint representing a solid color
46 | */
47 | public static PDFPaint getColorPaint(Color c) {
48 | return getPaint(c);
49 | }
50 |
51 | /**
52 | * get the PDFPaint representing a generic paint
53 | */
54 | public static PDFPaint getPaint(Paint p) {
55 | return new PDFPaint(p);
56 | }
57 |
58 | /**
59 | * fill a path with the paint, and record the dirty area.
60 | * @param state the current graphics state
61 | * @param g the graphics into which to draw
62 | * @param s the path to fill
63 | */
64 | public Rectangle2D fill(PDFRenderer state, Graphics2D g,
65 | GeneralPath s) {
66 | g.setPaint(this.mainPaint);
67 | g.fill(s);
68 |
69 | return s.createTransformedShape(g.getTransform()).getBounds2D();
70 | }
71 |
72 | /**
73 | * get the primary color associated with this PDFPaint.
74 | */
75 | public Paint getPaint() {
76 | return this.mainPaint;
77 | }
78 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/PDFParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * an exception class for recording parse errors in the PDF file
25 | * @author Mike Wessler
26 | */
27 | public class PDFParseException extends IOException {
28 |
29 | public PDFParseException(String msg) {
30 | super(msg);
31 | }
32 |
33 | public PDFParseException(String msg, Throwable cause) {
34 | this(msg);
35 | initCause(cause);
36 | }
37 |
38 |
39 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/RefImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | import java.awt.Graphics2D;
22 | import java.awt.image.BufferedImage;
23 |
24 | /**
25 | * A BufferedImage subclass that holds a strong reference to its graphics
26 | * object. This means that the graphics will never go away as long as
27 | * someone holds a reference to this image, and createGraphics() and
28 | * getGraphics() can be called multiple times safely, and will always return
29 | * the same graphics object.
30 | */
31 | public class RefImage extends BufferedImage {
32 |
33 | /** a strong reference to the graphics object */
34 | private Graphics2D g;
35 |
36 | /** Creates a new instance of RefImage */
37 | public RefImage(int width, int height, int type) {
38 | super(width, height, type);
39 | }
40 |
41 | /**
42 | * Create a graphics object only if it is currently null, otherwise
43 | * return the existing graphics object.
44 | */
45 | @Override
46 | public Graphics2D createGraphics() {
47 | if (this.g == null) {
48 | this.g = super.createGraphics();
49 | }
50 |
51 | return this.g;
52 | }
53 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/Watchable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview;
20 |
21 | /**
22 | * An interface for rendering or parsing, which can be stopped and started.
23 | */
24 | public interface Watchable {
25 |
26 | /** the possible statuses */
27 | public static final int UNKNOWN = 0;
28 | public static final int NOT_STARTED = 1;
29 | public static final int PAUSED = 2;
30 | public static final int NEEDS_DATA = 3;
31 | public static final int RUNNING = 4;
32 | public static final int STOPPED = 5;
33 | public static final int COMPLETED = 6;
34 | public static final int ERROR = 7;
35 |
36 | /**
37 | * Get the status of this watchable
38 | *
39 | * @return one of the well-known statuses
40 | */
41 | public int getStatus();
42 |
43 | /**
44 | * Stop this watchable. Stop will cause all processing to cease,
45 | * and the watchable to be destroyed.
46 | */
47 | public void stop();
48 |
49 | /**
50 | * Start this watchable and run until it is finished or stopped.
51 | * Note the watchable may be stopped if go() with a
52 | * different time is called during execution.
53 | */
54 | public void go();
55 |
56 | /**
57 | * Start this watchable and run for the given number of steps or until
58 | * finished or stopped.
59 | *
60 | * @param steps the number of steps to run for
61 | */
62 | public void go(int steps);
63 |
64 | /**
65 | * Start this watchable and run for the given amount of time, or until
66 | * finished or stopped.
67 | *
68 | * @param millis the number of milliseconds to run for
69 | */
70 | public void go(long millis);
71 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/action/GoToAction.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.action;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 | import com.sun.pdfview.PDFDestination;
7 | import com.sun.pdfview.PDFParseException;
8 |
9 | /**
10 | * An action which specifies going to a particular destination
11 | */
12 | public class GoToAction extends PDFAction {
13 | /** the destination to go to */
14 | private PDFDestination dest;
15 |
16 | /**
17 | * Creates a new instance of GoToAction from an object
18 | *
19 | * @param obj the PDFObject with the action information
20 | */
21 | public GoToAction(PDFObject obj, PDFObject root) throws IOException {
22 | super("GoTo");
23 |
24 | // find the destination
25 | PDFObject destObj = obj.getDictRef("D");
26 | if (destObj == null) {
27 | throw new PDFParseException("No destination in GoTo action " + obj);
28 | }
29 |
30 | // parse it
31 | this.dest = PDFDestination.getDestination(destObj, root);
32 | }
33 |
34 | /**
35 | * Create a new GoToAction from a destination
36 | */
37 | public GoToAction(PDFDestination dest) {
38 | super("GoTo");
39 |
40 | this.dest = dest;
41 | }
42 |
43 | /**
44 | * Get the destination this action refers to
45 | */
46 | public PDFDestination getDestination() {
47 | return this.dest;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/action/GoToRAction.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.action;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFDestination;
6 | import com.sun.pdfview.PDFObject;
7 |
8 | /*****************************************************************************
9 | * Action directing to a location within another PDF document
10 | *
11 | * @author Katja Sondermann
12 | * @since 07.07.2009
13 | ****************************************************************************/
14 | public class GoToRAction extends PDFAction {
15 |
16 | /** the destination within the remote PDF file */
17 | private PDFDestination destination;
18 | /** the remote file this action refers to*/
19 | private String file;
20 | /** Should the remote file be opened in a new window? (optional)*/
21 | private boolean newWindow=false;
22 | /**
23 | * Creates a new instance of GoToRAction from an object
24 | * @param obj the PDFObject with the action information
25 | * @throws IOException - in case the action can not be parsed
26 | */
27 | public GoToRAction(PDFObject obj, PDFObject root) throws IOException {
28 | super("GoToR");
29 | // find the destination and parse it
30 | this.destination = PdfObjectParseUtil.parseDestination("D", obj, root, true);
31 |
32 | // find the remote file and parse it
33 | this.file = PdfObjectParseUtil.parseStringFromDict("F", obj, true);
34 |
35 | // find the new window attribute and parse it if available
36 | this.newWindow = PdfObjectParseUtil.parseBooleanFromDict("NewWindow", obj, false);
37 | }
38 |
39 | /*************************************************************************
40 | * Create a new GoToRAction from the given attributes
41 | * @param dest
42 | * @param file
43 | * @param newWindow
44 | ************************************************************************/
45 | public GoToRAction(PDFDestination dest, String file, boolean newWindow){
46 | super("GoToR");
47 | this.file = file;
48 | this.destination = dest;
49 | this.newWindow = newWindow;
50 | }
51 |
52 | /*************************************************************************
53 | * Get the destination this action refers to
54 | * @return PDFDestination
55 | ************************************************************************/
56 | public PDFDestination getDestination() {
57 | return this.destination;
58 | }
59 |
60 | /*************************************************************************
61 | * Get the file this action refers to
62 | * @return PDFDestination
63 | ************************************************************************/
64 | public String getFile() {
65 | return this.file;
66 | }
67 |
68 | /*************************************************************************
69 | * Should the remote file be opened in a new window?
70 | * @return boolean
71 | ************************************************************************/
72 | public boolean isNewWindow() {
73 | return this.newWindow;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/action/PDFAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.action;
21 |
22 | import java.io.IOException;
23 |
24 | import com.sun.pdfview.PDFObject;
25 | import com.sun.pdfview.PDFParseException;
26 |
27 | /**
28 | * The common super-class of all PDF actions.
29 | */
30 | public class PDFAction {
31 | /** the type of this action */
32 | private String type;
33 |
34 | /** the next action or array of actions */
35 | private PDFObject next;
36 |
37 | /** Creates a new instance of PDFAction */
38 | public PDFAction(String type) {
39 | this.type = type;
40 | }
41 |
42 | /**
43 | * Get an action of the appropriate type from a PDFObject
44 | *
45 | * @param obj the PDF object containing the action to parse
46 | * @param root the root of the PDF object tree
47 | */
48 | public static PDFAction getAction(PDFObject obj, PDFObject root)
49 | throws IOException
50 | {
51 | // figure out the action type
52 | PDFObject typeObj = obj.getDictRef("S");
53 | if (typeObj == null) {
54 | throw new PDFParseException("No action type in object: " + obj);
55 | }
56 |
57 | // create the action based on the type
58 | PDFAction action = null;
59 | String type = typeObj.getStringValue();
60 | if (type.equals("GoTo")) {
61 | action = new GoToAction(obj, root);
62 | }else if(type.equals("GoToE")){
63 | action = new GoToEAction(obj, root);
64 | }else if(type.equals("GoToR")){
65 | action = new GoToRAction(obj, root);
66 | }else if(type.equals("URI")){
67 | action = new UriAction(obj, root);
68 | }else if(type.equals("Launch")){
69 | action = new LaunchAction(obj, root);
70 | }
71 | else {
72 | /** [JK FIXME: Implement other action types! ] */
73 | throw new PDFParseException("Unknown Action type: " + type);
74 | }
75 |
76 | // figure out if there is a next action
77 | PDFObject nextObj = obj.getDictRef("Next");
78 | if (nextObj != null) {
79 | action.setNext(nextObj);
80 | }
81 |
82 | // return the action
83 | return action;
84 | }
85 |
86 | /**
87 | * Get the type of this action
88 | */
89 | public String getType() {
90 | return this.type;
91 | }
92 |
93 | /**
94 | * Get the next action or array of actions
95 | */
96 | public PDFObject getNext() {
97 | return this.next;
98 | }
99 |
100 | /**
101 | * Set the next action or array of actions
102 | */
103 | public void setNext(PDFObject next) {
104 | this.next = next;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/action/PdfObjectParseUtil.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.action;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFDestination;
6 | import com.sun.pdfview.PDFObject;
7 | import com.sun.pdfview.PDFParseException;
8 |
9 | /*****************************************************************************
10 | * Utility class for parsing values from a PDFObject
11 | *
12 | * @author Katja Sondermann
13 | * @since 08.07.2009
14 | ****************************************************************************/
15 | public class PdfObjectParseUtil {
16 |
17 | /*************************************************************************
18 | * Parse a String value with the given key from parent object. If it's mandatory
19 | * and not available, an exception will be thrown.
20 | * @param key
21 | * @param parent
22 | * @param mandatory
23 | * @return String - can be null if not mandatory
24 | * @throws IOException - in case of a parsing error
25 | ************************************************************************/
26 | public static String parseStringFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
27 | PDFObject val = parent;
28 | while (val.getType() == PDFObject.DICTIONARY) {
29 | val = val.getDictRef(key);
30 | if(val == null){
31 | if(mandatory){
32 | throw new PDFParseException(key + "value could not be parsed : " + parent.toString());
33 | }
34 | return null;
35 | }
36 | }
37 | return val.getStringValue();
38 | }
39 |
40 | /*************************************************************************
41 | * Parse a Boolean value with the given key from parent object. If it's mandatory
42 | * and not available, an exception will be thrown.
43 | * @param key
44 | * @param parent
45 | * @param mandatory
46 | * @return boolean - false if not available and not mandatory
47 | * @throws IOException
48 | ************************************************************************/
49 | public static boolean parseBooleanFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
50 | PDFObject val = parent.getDictRef(key);
51 | if(val == null){
52 | if(mandatory){
53 | throw new PDFParseException(key + "value could not be parsed : " + parent.toString());
54 | }
55 | return false;
56 | }
57 | return val.getBooleanValue();
58 | }
59 |
60 | /*************************************************************************
61 | * Parse a integer value with the given key from parent object. If it's mandatory
62 | * and not available, an exception will be thrown.
63 | * @param key
64 | * @param parent
65 | * @param mandatory
66 | * @return int - returns "0" in case the value is not a number
67 | * @throws IOException
68 | ************************************************************************/
69 | public static int parseIntegerFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
70 | PDFObject val = parent.getDictRef(key);
71 | if(val == null){
72 | if(mandatory){
73 | throw new PDFParseException(key + "value could not be parsed : " + parent.toString());
74 | }
75 | return 0;
76 | }
77 | return val.getIntValue();
78 | }
79 |
80 | /*************************************************************************
81 | * Parse a destination object
82 | * @param key
83 | * @param parent
84 | * @param root
85 | * @param mandatory
86 | * @return PDFDestination - can be null if not mandatory
87 | * @throws IOException
88 | ************************************************************************/
89 | public static PDFDestination parseDestination(String key, PDFObject parent, PDFObject root, boolean mandatory) throws IOException{
90 | PDFObject destObj = parent.getDictRef(key);
91 | if (destObj == null) {
92 | if(mandatory){
93 | throw new PDFParseException("Error parsing destination " + parent);
94 | }
95 | return null;
96 | }
97 | return PDFDestination.getDestination(destObj, root);
98 |
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/action/UriAction.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.action;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 |
7 | /*****************************************************************************
8 | * URI action, containing a web link
9 | *
10 | * @author Katja Sondermann
11 | * @since 07.07.2009
12 | ****************************************************************************/
13 | public class UriAction extends PDFAction {
14 |
15 | /** The URL this action links to */
16 | private String uri;
17 |
18 | /*************************************************************************
19 | * Constructor, reading the URL from the given action object
20 | * @param type
21 | * @throws IOException - in case the action can not be parsed
22 | ************************************************************************/
23 | public UriAction(PDFObject obj, PDFObject root) throws IOException {
24 | super("URI");
25 | this.uri = PdfObjectParseUtil.parseStringFromDict("URI", obj, true);
26 | }
27 |
28 | /*************************************************************************
29 | * Constructor
30 | * @param type
31 | * @throws IOException
32 | ************************************************************************/
33 | public UriAction(String uri) throws IOException {
34 | super("URI");
35 | this.uri = uri;
36 | }
37 |
38 | /*************************************************************************
39 | * Get the URI this action directs to
40 | * @return String
41 | ************************************************************************/
42 | public String getUri() {
43 | return this.uri;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/AnnotationBorderStyle.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 |
7 | /**
8 | * Annotation border style
9 | * @author Bernd Rosstauscher
10 | */
11 | public class AnnotationBorderStyle {
12 |
13 | public enum BorderStyle {
14 | SOLID("S"),
15 | DASHED("D"),
16 | BEVELED("B"),
17 | INSET("I"),
18 | UNDERLINE("U");
19 |
20 | private String code;
21 |
22 | private BorderStyle(String code) {
23 | this.code = code;
24 | }
25 |
26 | public String getCode() {
27 | return code;
28 | }
29 |
30 | public static BorderStyle fromCode(String code) {
31 | for (BorderStyle bs : BorderStyle.values()) {
32 | if (bs.getCode().equals(code)) {
33 | return bs;
34 | }
35 | }
36 | return SOLID;
37 | }
38 |
39 | }
40 |
41 | private Integer width;
42 | private BorderStyle borderStyle;
43 | private int[] dashArray;
44 |
45 | /**
46 | * Creates a annotation border style
47 | */
48 | public AnnotationBorderStyle() {
49 | super();
50 | }
51 |
52 | /**
53 | * Parse a border style from a BS dictionary.
54 | * @param bs the pdf dictionary to parse.
55 | * @return the border style object.
56 | * @throws IOException
57 | */
58 | public static AnnotationBorderStyle parseFromDictionary(PDFObject bs) throws IOException {
59 | AnnotationBorderStyle result = new AnnotationBorderStyle();
60 | result.width = bs.getDictRefAsInt("W");
61 | result.borderStyle = BorderStyle.fromCode(bs.getDictRefAsString("S"));
62 | result.dashArray = bs.getDictRefAsIntArray("D");
63 | // TODO BE Border effect not supported yet
64 | return result;
65 | }
66 |
67 | /**
68 | * @return the border style enum
69 | */
70 | public BorderStyle getBorderStyle() {
71 | return borderStyle;
72 | }
73 |
74 | /**
75 | * @return the width of the border line
76 | */
77 | public Integer getWidth() {
78 | return width;
79 | }
80 |
81 | /**
82 | * @return specifying the dash for the border line
83 | */
84 | public int[] getDashArray() {
85 | return dashArray;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/AnnotationType.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import com.sun.pdfview.Configuration;
4 |
5 | /**
6 | * @author Bernd Rosstauscher
7 | *
8 | */
9 | public enum AnnotationType{
10 | UNKNOWN("-", 0, PDFAnnotation.class),
11 | LINK("Link", 1, LinkAnnotation.class),
12 | WIDGET("Widget", 2, WidgetAnnotation.class),
13 | STAMP("Stamp", 3, StampAnnotation.class),
14 | FREETEXT("FreeText", 5, FreetextAnnotation.class),
15 | SIGNATURE("Sig", 6, WidgetAnnotation.class),
16 |
17 | // added more annotation types. Most of them only with basic features
18 | // We render them all via the base class MarkupAnnotation
19 |
20 | TEXT("Text", 7, MarkupAnnotation.class),
21 | LINE("Line", 8, MarkupAnnotation.class),
22 | SQUARE("Square", 9, SquareAnnotation.class),
23 | CIRCLE("Circle", 10, CircleAnnotation.class),
24 | POLYGON("Polygon", 11, MarkupAnnotation.class),
25 | POLYLINE("PolyLine", 12, MarkupAnnotation.class),
26 | HIGHLIGHT("Highlight", 13, TextMarkupAnnotation.class),
27 | UNDERLINE("Underline", 14, TextMarkupAnnotation.class),
28 | SQUIGGLY("Squiggly", 15, TextMarkupAnnotation.class),
29 | STRIKEOUT("StrikeOut", 16, TextMarkupAnnotation.class),
30 | CARET("Caret", 17, MarkupAnnotation.class),
31 | INK("Ink", 18, MarkupAnnotation.class),
32 | //POPUP("Popup", 19, MarkupAnnotation.class),
33 | FILEATTACHMENT("FileAttachment", 20, PDFAnnotation.class),
34 | SOUND("Sound", 21, PDFAnnotation.class),
35 | MOVIE("Movie", 22, PDFAnnotation.class),
36 | SCREEN("Screen", 23, PDFAnnotation.class),
37 | PRINTERMARK("PrinterMark", 24, PDFAnnotation.class),
38 | TRAPNET("TrapNet", 25, PDFAnnotation.class),
39 | WATERMARK("Watermark", 26, PDFAnnotation.class),
40 | THREED("3D", 27, PDFAnnotation.class),
41 | REDACT("Redact", 28, MarkupAnnotation.class),
42 | ;
43 |
44 | /**
45 | * @return true if this annotation type should be displayed else false.
46 | */
47 | boolean displayAnnotation() {
48 | switch(this) {
49 | case STAMP: return Configuration.getInstance().isPrintStampAnnotations();
50 | case WIDGET: return Configuration.getInstance().isPrintWidgetAnnotations();
51 | case FREETEXT: return Configuration.getInstance().isPrintFreetextAnnotations();
52 | case LINK: return Configuration.getInstance().isPrintLinkAnnotations();
53 | case SIGNATURE: return Configuration.getInstance().isPrintSignatureFields();
54 | case UNKNOWN: return false;
55 | default: {
56 | // Fallback for all the annotation types that are currently mapped to MarkupAnnotation
57 | return MarkupAnnotation.class.isAssignableFrom(this.className)
58 | && Configuration.getInstance().isPrintFreetextAnnotations();
59 | }
60 | }
61 | }
62 |
63 | private String definition;
64 | private int internalId;
65 | private Class> className;
66 |
67 | private AnnotationType(String definition, int typeId, Class> className) {
68 | this.definition = definition;
69 | this.internalId = typeId;
70 | this.className = className;
71 | }
72 |
73 | /**
74 | * @return the definition
75 | */
76 | public String getDefinition() {
77 | return definition;
78 | }
79 | /**
80 | * @return the internalId
81 | */
82 | public int getInternalId() {
83 | return internalId;
84 | }
85 |
86 | /**
87 | * @return the className
88 | */
89 | public Class> getClassName() {
90 | return className;
91 | }
92 |
93 | /**
94 | * Get annotation type by it's type
95 | * @param definition
96 | * @return
97 | */
98 | public static AnnotationType getByDefinition(String definition) {
99 | for (AnnotationType type : values()) {
100 | if(type.definition.equals(definition)) {
101 | return type;
102 | }
103 | }
104 | return UNKNOWN;
105 | }
106 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/CircleAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 |
7 | /*****************************************************************************
8 | * PDF annotation for a circle
9 | *
10 | * @author Bernd Rosstauscher
11 | ****************************************************************************/
12 | public class CircleAnnotation extends MarkupAnnotation {
13 |
14 | // TODO Not all of this is fully implemented yet.
15 | // But it will work if the visual representation is done via an "Appearance Stream"
16 |
17 | /*************************************************************************
18 | * Constructor
19 | * @param annotObject
20 | * @throws IOException
21 | ************************************************************************/
22 | public CircleAnnotation(PDFObject annotObject) throws IOException {
23 | super(annotObject, AnnotationType.CIRCLE);
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/FreetextAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 |
7 | /*****************************************************************************
8 | * PDF annotation describing a free text
9 | * Currently only supports the XObjects which can be found in the path AP->N
10 | * of the annotation object (same implementation as the stamp annotation)
11 | * @author Katja Sondermann
12 | * @since 28.03.2012
13 | ****************************************************************************/
14 | public class FreetextAnnotation extends MarkupAnnotation {
15 |
16 | /*************************************************************************
17 | * Constructor
18 | * @param annotObject
19 | * @throws IOException
20 | ************************************************************************/
21 | public FreetextAnnotation(PDFObject annotObject) throws IOException {
22 | super(annotObject, AnnotationType.FREETEXT);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/LinkAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFDestination;
6 | import com.sun.pdfview.PDFObject;
7 | import com.sun.pdfview.PDFParseException;
8 | import com.sun.pdfview.action.GoToAction;
9 | import com.sun.pdfview.action.PDFAction;
10 |
11 | /*****************************************************************************
12 | * PDF annotation describing a link to either a location within the current
13 | * document, a location in another PDF file, an application/file to be opened
14 | * or a web site.
15 | * In the PDF structure a link can be a destination ("DEST") or an action ("A").
16 | * Both ways are handled as actions internally, i.e. for getting the links
17 | * destination, you should get the action from this annotation object. It can be
18 | * one of the following actions:
19 | *
GotoAction - for a file internal destination
20 | *
GoToRAction - for a destination in a remote PDF file
21 | *
GoToEAction - for a destination in an embedded PDF file
22 | *
UriAction - for a web link
23 | *
LaunchAction - for launching an application/opening a file
24 | *
25 | * @author Katja Sondermann
26 | * @since 06.07.2009
27 | ****************************************************************************/
28 | public class LinkAnnotation extends PDFAnnotation {
29 |
30 | private PDFAction action = null;
31 |
32 | /*************************************************************************
33 | * Constructor
34 | * @param annotObject
35 | * @throws IOException
36 | ************************************************************************/
37 | public LinkAnnotation(PDFObject annotObject) throws IOException {
38 | super(annotObject, AnnotationType.LINK);
39 | // a link annotation can either have an action (GoTo or URI) or a destination (DEST)
40 | PDFObject actionObj = annotObject.getDictRef("A");
41 | if (actionObj != null) {
42 | this.action = PDFAction.getAction(actionObj, annotObject.getRoot());
43 | } else {
44 | // if a destination is given, create a GoToAction from it
45 | PDFObject dest = annotObject.getDictRef("Dest");
46 | if(dest == null) {
47 | dest = annotObject.getDictRef("DEST");
48 | }
49 | if (dest != null) {
50 | this.action = new GoToAction(PDFDestination.getDestination(dest, annotObject.getRoot()));
51 | } else {
52 | throw new PDFParseException(
53 | "Could not parse link annotation (no Action or Destination found): "
54 | + annotObject.toString());
55 | }
56 | }
57 | }
58 |
59 | /*************************************************************************
60 | * Get the contained PDFAction
61 | * @return PDFAction - can be null in case the contains
62 | * a destination object
63 | ************************************************************************/
64 | public PDFAction getAction() {
65 | return this.action;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/SquareAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 |
7 | /*****************************************************************************
8 | * PDF annotation for a square
9 | *
10 | * @author Bernd Rosstauscher
11 | ****************************************************************************/
12 | public class SquareAnnotation extends MarkupAnnotation {
13 |
14 | // TODO Not all of this is fully implemented yet.
15 | // But it will work if the visual representation is done via an "Appearance Stream"
16 |
17 | /*************************************************************************
18 | * Constructor
19 | * @param annotObject
20 | * @throws IOException
21 | ************************************************************************/
22 | public SquareAnnotation(PDFObject annotObject) throws IOException {
23 | super(annotObject, AnnotationType.SQUARE);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/StampAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import com.sun.pdfview.PDFCmd;
7 | import com.sun.pdfview.PDFObject;
8 |
9 | /*****************************************************************************
10 | * PDF annotation describing a stamp
11 | *
12 | * @author Katja Sondermann
13 | * @since 26.03.2012
14 | ****************************************************************************/
15 | public class StampAnnotation extends MarkupAnnotation {
16 |
17 | private String iconName;
18 | private List iconCommands;
19 |
20 | /*************************************************************************
21 | * Constructor
22 | * @param annotObject
23 | * @throws IOException
24 | ************************************************************************/
25 | public StampAnnotation(PDFObject annotObject) throws IOException {
26 | super(annotObject, AnnotationType.STAMP);
27 | this.iconName = annotObject.getDictRefAsString("Name");
28 |
29 | // No AP so use the icon name
30 | if (iconName != null && annotObject.getDictRef("AP") == null) {
31 | parseIconCommands();
32 | }
33 |
34 | }
35 |
36 | /**
37 | * If the stamp is represented by one of the predefined icons
38 | * this will parse it and create PDFCommands for them.
39 | */
40 | private void parseIconCommands() {
41 | // TODO Add code for the different icon constants.
42 | // fill iconCommands
43 |
44 | // These command names exist.
45 |
46 | // Approved, Experimental, NotApproved, AsIs, Expired ,
47 | // NotForPublicRelease, Confidential, Final, Sold,
48 | // Departmental, ForComment, TopSecret, Draft, ForPublicRelease
49 | }
50 |
51 | /**
52 | * @return the iconName
53 | */
54 | public String getIconName() {
55 | return iconName;
56 | }
57 |
58 | /**
59 | *@return the PDF commands to render this annotation
60 | */
61 | @Override
62 | public List getCurrentCommand() {
63 | List apCommand = super.getCurrentCommand();
64 | if (apCommand != null) {
65 | return apCommand;
66 | }
67 | return this.iconCommands;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/annotation/TextMarkupAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.annotation;
2 |
3 | import java.awt.Rectangle;
4 | import java.awt.geom.AffineTransform;
5 | import java.awt.geom.GeneralPath;
6 | import java.awt.geom.Rectangle2D;
7 | import java.awt.geom.Rectangle2D.Float;
8 | import java.io.IOException;
9 | import java.util.ArrayList;
10 | import java.util.HashMap;
11 | import java.util.List;
12 |
13 | import com.sun.pdfview.PDFCmd;
14 | import com.sun.pdfview.PDFImage;
15 | import com.sun.pdfview.PDFObject;
16 | import com.sun.pdfview.PDFPage;
17 | import com.sun.pdfview.PDFParseException;
18 | import com.sun.pdfview.PDFParser;
19 | import com.sun.pdfview.PDFShapeCmd;
20 |
21 | /*****************************************************************************
22 | * PDF annotation describing a text markup: Highlight, Underline, Squiggle, StrikeOut
23 | *
24 | * @author Bernd Rosstauscher
25 | ****************************************************************************/
26 | public class TextMarkupAnnotation extends MarkupAnnotation {
27 |
28 | private int[] quadPoints;
29 | private List highlightCommands;
30 |
31 | /*************************************************************************
32 | * Constructor
33 | * @param annotObject
34 | * @throws IOException
35 | ************************************************************************/
36 | public TextMarkupAnnotation(PDFObject annotObject, AnnotationType annotationType) throws IOException {
37 | super(annotObject, annotationType);
38 | this.quadPoints = annotObject.getDictRefAsIntArray("QuadPoints");
39 |
40 | // No AP so use the quad points and highlight mode
41 | if (annotObject.getDictRef("AP") == null) {
42 | parseHighlightCommands();
43 | }
44 |
45 | }
46 |
47 | /**
48 | * Parse the highlight commands
49 | */
50 | private void parseHighlightCommands() {
51 | // invalid quad points
52 | if (this.quadPoints == null || this.quadPoints.length % 4 != 0) {
53 | return;
54 | }
55 | highlightCommands = new ArrayList();
56 | highlightCommands.add(PDFPage.createPushCmd());
57 |
58 | //TODO currently we use the same code for: Highlight, Underline, Squiggle, StrikeOut
59 | // We should also set the correct colors and such.
60 |
61 | // Draw a box
62 | for (int i = 0; i < quadPoints.length; i+=4) {
63 | GeneralPath gp = new GeneralPath(new Rectangle(quadPoints[i], quadPoints[i+1], quadPoints[i+2], quadPoints[i+3]));
64 | highlightCommands.add(new PDFShapeCmd(gp, PDFShapeCmd.FILL, true));
65 | }
66 | highlightCommands.add(PDFPage.createPopCmd());
67 | }
68 |
69 | /**
70 | * Gets the highlight painting commands
71 | * Use either Quads or Appearance Stream
72 | */
73 | @Override
74 | public List getCurrentCommand() {
75 | List apCommand = super.getCurrentCommand();
76 | if (apCommand != null) {
77 | return apCommand;
78 | }
79 | return this.highlightCommands;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/AltColorSpace.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.colorspace;
2 |
3 | import java.awt.color.ColorSpace;
4 |
5 | import com.sun.pdfview.function.PDFFunction;
6 |
7 | /*****************************************************************************
8 | * Color Space implementation for handling the PDF AlternateColorSpace.
9 | * A PDF function is applied to colorvalues before converting.
10 | *
11 | * @author Katja Sondermann
12 | * @since 06.01.2011
13 | ****************************************************************************/
14 | public class AltColorSpace extends ColorSpace {
15 |
16 | private PDFFunction fkt;
17 | private ColorSpace origCs;
18 | /**
19 | * Create a new CMYKColorSpace Instance.
20 | */
21 | public AltColorSpace(PDFFunction fkt, ColorSpace origCs) {
22 | super(origCs.getType(), fkt.getNumInputs());
23 | this.fkt = fkt;
24 | this.origCs = origCs;
25 | }
26 |
27 | /**
28 | * Converts from CIEXYZ.
29 | *
30 | * @see java.awt.color.ColorSpace#fromCIEXYZ(float[])
31 | * @see org.scantegrity.lib.CMYKColorSpace#toCIEXYZ
32 | */
33 | @Override
34 | public float[] fromCIEXYZ(float[] p_colorvalue) {
35 | p_colorvalue = this.fkt.calculate(p_colorvalue);
36 | return this.origCs.fromCIEXYZ(p_colorvalue);
37 | }
38 |
39 | /**
40 | * Converts a given RGB.
41 | *
42 | * @param p_rgbvalue - The color to translate
43 | * @return a float[4] of the CMYK values.
44 | * @see java.awt.color.ColorSpace#fromRGB(float[])
45 | */
46 | @Override
47 | public float[] fromRGB(float[] p_rgbvalue) {
48 | p_rgbvalue = this.fkt.calculate(p_rgbvalue);
49 | return this.origCs.fromCIEXYZ(p_rgbvalue);
50 | }
51 |
52 | /**
53 | * Converts to CIEXYZ.
54 | * @see java.awt.color.ColorSpace#toCIEXYZ(float[])
55 | */
56 | @Override
57 | public float[] toCIEXYZ(float[] p_colorvalue) {
58 | float[] colorvalue = this.fkt.calculate(p_colorvalue);
59 | return this.origCs.toCIEXYZ(colorvalue);
60 | }
61 |
62 | /**
63 | * Converts to RGB.
64 | *
65 | * @param p_colorvalue The color in CMYK.
66 | * @see java.awt.color.ColorSpace#toRGB(float[])
67 | */
68 | @Override
69 | public float[] toRGB(float[] p_colorvalue) {
70 | float[] colorvalue = this.fkt.calculate(p_colorvalue);
71 | return this.origCs.toRGB(colorvalue);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/AlternateColorSpace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.awt.color.ColorSpace;
23 |
24 | import com.sun.pdfview.PDFPaint;
25 | import com.sun.pdfview.function.PDFFunction;
26 |
27 | /**
28 | * A color space that uses another color space to return values, and a
29 | * function to map between values in the input and input values to the
30 | * alternate color space
31 | */
32 | public class AlternateColorSpace extends PDFColorSpace {
33 | /** The alternate color space */
34 | private PDFColorSpace alternate;
35 |
36 | /** The function */
37 | private PDFFunction function;
38 |
39 | private AltColorSpace altcolorspace;
40 |
41 | /** Creates a new instance of AlternateColorSpace */
42 | public AlternateColorSpace(PDFColorSpace alternate, PDFFunction function) {
43 | super(null);
44 |
45 | this.alternate = alternate;
46 | this.function = function;
47 | }
48 |
49 | /**
50 | * get the number of components expected in the getPaint command
51 | */
52 | @Override public int getNumComponents() {
53 | if (this.function != null) {
54 | return this.function.getNumInputs();
55 | } else {
56 | return this.alternate.getNumComponents();
57 | }
58 | }
59 |
60 | /**
61 | * get the PDFPaint representing the color described by the
62 | * given color components
63 | * @param components the color components corresponding to the given
64 | * colorspace
65 | * @return a PDFPaint object representing the closest Color to the
66 | * given components.
67 | */
68 | @Override public PDFPaint getPaint(float[] components) {
69 | if (this.function != null) {
70 | // translate values using function
71 | components = this.function.calculate(components);
72 | }
73 |
74 | return this.alternate.getPaint(components);
75 | }
76 |
77 | /**
78 | * get the original Java ColorSpace.
79 | */
80 | @Override public ColorSpace getColorSpace() {
81 | if (altcolorspace == null) altcolorspace = new AltColorSpace(function, alternate.getColorSpace());
82 | return altcolorspace;
83 | //return this.alternate.getColorSpace();
84 | }
85 |
86 | /*************************************************************************
87 | * Get the PDF function
88 | * @return PDFFunction
89 | ************************************************************************/
90 | public PDFFunction getFunktion() {
91 | return this.function;
92 | }
93 |
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/CalGrayColor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.awt.color.ColorSpace;
23 | import java.io.IOException;
24 |
25 | import com.sun.pdfview.PDFObject;
26 |
27 | /**
28 | * A ColorSpace for calibrated gray
29 | * @author Mike Wessler
30 | */
31 | public class CalGrayColor extends ColorSpace {
32 | float white[]= {1f, 1f, 1f};
33 | float black[]= {0, 0, 0};
34 | float gamma= 1;
35 | static ColorSpace cie= ColorSpace.getInstance(ColorSpace.CS_sRGB);
36 |
37 | /**
38 | * Create a new Calibrated Gray color space object, given
39 | * the description in a PDF dictionary.
40 | * @param obj a dictionary that contains an Array of 3 Numbers
41 | * for "WhitePoint" and "BlackPoint", and a Number for "Gamma"
42 | */
43 | public CalGrayColor(PDFObject obj) throws IOException {
44 | // obj is a dictionary that has the following parts:
45 | // WhitePoint [a b c]
46 | // BlackPoint [a b c]
47 | // Gamma a
48 | super(TYPE_GRAY, 1);
49 | PDFObject ary= obj.getDictRef("WhitePoint");
50 | if (ary!=null) {
51 | for(int i=0; i<3; i++) {
52 | this.white[i]= ary.getAt(i).getFloatValue();
53 | }
54 | }
55 | ary= obj.getDictRef("BlackPoint");
56 | if (ary!=null) {
57 | for(int i=0; i<3; i++) {
58 | this.black[i]= ary.getAt(i).getFloatValue();
59 | }
60 | }
61 | PDFObject g= obj.getDictRef("Gamma");
62 | if (g!=null) {
63 | this.gamma= g.getFloatValue();
64 | }
65 | }
66 |
67 | /**
68 | * Create a new calibrated gray color space object, with the
69 | * default values for black point, white point and gamma
70 | */
71 | public CalGrayColor() {
72 | super(TYPE_GRAY, 1);
73 | }
74 |
75 | /**
76 | * get the number of components (1).
77 | */
78 | @Override public int getNumComponents() {
79 | return 1;
80 | }
81 |
82 | /**
83 | * convert from Calibrated Gray to RGB.
84 | * @param comp the gray value (0-1)
85 | * @return the RGB values (0-1)
86 | */
87 | @Override
88 | public float[] toRGB(float comp[]) {
89 | if (comp.length==1) {
90 | float mul= (float)Math.pow(comp[0], this.gamma);
91 | float xyz[] = {
92 | this.white[0]*mul,
93 | 0,
94 | 0};
95 | float rgb[]= cie.fromCIEXYZ(xyz);
96 | return rgb;
97 | } else {
98 | return this.black;
99 | }
100 | }
101 |
102 | /**
103 | * convert from RGB to Calibrated Gray. NOT IMPLEMENTED
104 | */
105 | @Override
106 | public float[] fromRGB(float[] rgbvalue) {
107 | return new float[1];
108 | }
109 |
110 | /**
111 | * convert from CIEXYZ to Calibrated Gray. NOT IMPLEMENTED
112 | */
113 | @Override
114 | public float[] fromCIEXYZ(float[] colorvalue) {
115 | return new float[1];
116 | }
117 |
118 | /**
119 | * get the type of this ColorSpace (TYPE_GRAY)
120 | */
121 | @Override public int getType() {
122 | return TYPE_GRAY;
123 | }
124 |
125 | /**
126 | * convert from Calibrated Gray to CIEXYZ. NOT IMPLEMENTED
127 | */
128 | @Override
129 | public float[] toCIEXYZ(float[] colorvalue) {
130 | return new float[3];
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/LabColor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.awt.color.ColorSpace;
23 | import java.io.IOException;
24 |
25 | import com.sun.pdfview.PDFObject;
26 |
27 | /**
28 | * A ColorSpace for Lab color
29 | * @author Mike Wessler
30 | */
31 | public class LabColor extends ColorSpace {
32 | float white[]= {1f, 1f, 1f};
33 | float black[]= {0, 0, 0};
34 | float range[]= {-100f, 100f, -100f, 100f};
35 | static ColorSpace cie= ColorSpace.getInstance(ColorSpace.CS_sRGB);
36 |
37 | /**
38 | * Create a new Lab color space object, given the description in
39 | * a PDF dictionary.
40 | * @param obj a dictionary that contains an Array of 3 Numbers for
41 | * "WhitePoint" and "BlackPoint", and an array of 4 Numbers for
42 | * "Range".
43 | */
44 | public LabColor(PDFObject obj) throws IOException {
45 | // obj is a dictionary that has the following parts:
46 | // WhitePoint [a b c]
47 | // BlackPoint [a b c]
48 | // Gamma a
49 | super(TYPE_Lab, 3);
50 | PDFObject ary= obj.getDictRef("WhitePoint");
51 | if (ary!=null) {
52 | for(int i=0; i<3; i++) {
53 | this.white[i]= ary.getAt(i).getFloatValue();
54 | }
55 | }
56 | ary= obj.getDictRef("BlackPoint");
57 | if (ary!=null) {
58 | for(int i=0; i<3; i++) {
59 | this.black[i]= ary.getAt(i).getFloatValue();
60 | }
61 | }
62 | ary= obj.getDictRef("Range");
63 | if (ary!=null) {
64 | for (int i=0; i<4; i++) {
65 | this.range[i]= ary.getAt(i).getFloatValue();
66 | }
67 | }
68 | }
69 |
70 | /**
71 | * get the number of components for this color space (3)
72 | */
73 | @Override public int getNumComponents() {
74 | return 3;
75 | }
76 |
77 | /**
78 | * Stage 2 of the conversion algorithm. Pulled out because
79 | * it gets invoked for each component
80 | */
81 | public final float stage2(float s1) {
82 | return (s1>=6f/29f)?s1*s1*s1:108f/841f*(s1-4f/29f);
83 | }
84 |
85 | /**
86 | * convert from Lab to RGB
87 | * @param comp the Lab values (0-1)
88 | * @return the RGB values (0-1)
89 | */
90 | @Override
91 | public float[] toRGB(float comp[]) {
92 | if (comp.length==3) {
93 | float l= (comp[0]+16)/116+comp[1]/500;
94 | float m= (comp[0]+16)/116;
95 | float n= (comp[0]+16)/116-comp[2]/200;
96 | float xyz[]= {
97 | this.white[0]*stage2(l),
98 | this.white[0]*stage2(m),
99 | this.white[0]*stage2(n)};
100 | float rgb[]= cie.fromCIEXYZ(xyz);
101 | return rgb;
102 | } else {
103 | return this.black;
104 | }
105 | }
106 |
107 | /**
108 | * convert from RGB to Lab. NOT IMPLEMENTED
109 | */
110 | @Override
111 | public float[] fromRGB(float[] rgbvalue) {
112 | return new float[3];
113 | }
114 |
115 | /**
116 | * convert from CIEXYZ to Lab. NOT IMPLEMENTED
117 | */
118 | @Override
119 | public float[] fromCIEXYZ(float[] colorvalue) {
120 | return new float[3];
121 | }
122 |
123 | /**
124 | * get the type of this colorspace (TYPE_Lab)
125 | */
126 | @Override public int getType() {
127 | return TYPE_Lab;
128 | }
129 |
130 | /**
131 | * convert from Lab to CIEXYZ. NOT IMPLEMENTED
132 | */
133 | @Override
134 | public float[] toCIEXYZ(float[] colorvalue) {
135 | return new float[3];
136 | }
137 |
138 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/MaskColorSpace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.awt.Color;
23 | import java.awt.color.ColorSpace;
24 |
25 | import com.sun.pdfview.PDFPaint;
26 |
27 | /**
28 | * A color space used to implement masks. For now, the only type of mask
29 | * supported is one where the image pixels specify where to paint, and the
30 | * painting itself is done in a pre-specified PDF Paint.
31 | */
32 | public class MaskColorSpace extends ColorSpace {
33 | /** The paint to paint in. Note this cannot be a pattern or gradient. */
34 | private final PDFPaint paint;
35 |
36 | /** Creates a new instance of PaintColorSpace */
37 | public MaskColorSpace(PDFPaint paint) {
38 | super (TYPE_RGB, 1);
39 |
40 | this.paint = paint;
41 | }
42 |
43 | @Override
44 | public float[] fromCIEXYZ(float[] colorvalue) {
45 | float x = colorvalue[0];
46 | float y = colorvalue[1];
47 | float z = colorvalue[2];
48 |
49 | float[] mask = new float[1];
50 |
51 | if (Math.round(x) > 0 || Math.round(y) > 0 || Math.round(z) > 0) {
52 | mask[0] = 1;
53 | } else {
54 | mask[0] = 0;
55 | }
56 |
57 | return mask;
58 | }
59 |
60 | @Override
61 | public float[] fromRGB(float[] rgbvalue) {
62 | float r = rgbvalue[0];
63 | float g = rgbvalue[1];
64 | float b = rgbvalue[2];
65 |
66 | float[] mask = new float[1];
67 |
68 | if (Math.round(r) > 0 || Math.round(g) > 0 || Math.round(b) > 0) {
69 | mask[0] = 1;
70 | } else {
71 | mask[0] = 0;
72 | }
73 |
74 | return mask;
75 | }
76 |
77 | ColorSpace cie = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
78 | float[] prev1= this.cie.fromRGB(toRGB(new float[] {1.0f}));
79 | float[] prev0= this.cie.fromRGB(toRGB(new float[] {0.0f}));
80 |
81 | @Override
82 | public float[] toCIEXYZ(float[] colorvalue) {
83 | if (colorvalue[0]==1) {
84 | return this.prev1;
85 | } else if (colorvalue[0]==0) {
86 | return this.prev0;
87 | } else {
88 | return this.cie.fromRGB(toRGB(colorvalue));
89 | }
90 | }
91 |
92 | @Override
93 | public float[] toRGB(float[] colorvalue) {
94 | return ((Color) this.paint.getPaint()).getRGBColorComponents(null);
95 | }
96 |
97 | @Override public int getNumComponents() {
98 | return 1;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/PatternSpace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.io.IOException;
23 | import java.util.Map;
24 |
25 | import com.sun.pdfview.PDFObject;
26 | import com.sun.pdfview.PDFPaint;
27 | import com.sun.pdfview.pattern.PDFPattern;
28 |
29 | /**
30 | * A PatternSpace fills with a pattern, the name of which is
31 | * specified in the call to getPaint(). This pattern is
32 | * read from the resources of the current page. The pattern space
33 | * may also have a base color space which the pattern is defined in.
34 | */
35 | public class PatternSpace extends PDFColorSpace {
36 | private PDFColorSpace base;
37 |
38 | public PatternSpace() {
39 | super(null);
40 | }
41 |
42 | /**
43 | * Create a pattern space with the given color space as a base
44 | */
45 | public PatternSpace(PDFColorSpace base) {
46 | super(null);
47 |
48 | this.base = base;
49 | }
50 |
51 | /**
52 | * Get the base color space
53 | */
54 | public PDFColorSpace getBase() {
55 | return this.base;
56 | }
57 |
58 | /**
59 | * Get the number of components we want
60 | */
61 | @Override public int getNumComponents() {
62 | if (this.base == null) {
63 | return 0;
64 | } else {
65 | return this.base.getNumComponents();
66 | }
67 | }
68 |
69 | /**
70 | * get the PDFPaint representing the color described by the
71 | * given color components
72 | * @param components the color components corresponding to the given
73 | * colorspace
74 | * @return a PDFPaint object representing the closest Color to the
75 | * given components.
76 | */
77 | @Override public PDFPaint getPaint(float[] components) {
78 | throw new IllegalArgumentException("Pattern spaces require a pattern " +
79 | "name!");
80 | }
81 |
82 | /**
83 | * Get the paint representing a pattern, optionally with the given
84 | * base paint.
85 | *
86 | * @param patternObj the pattern to render
87 | * @param components the components of the base paint
88 | */
89 | public PDFPaint getPaint(PDFObject patternObj, float[] components,
90 | Map resources)
91 | throws IOException
92 | {
93 | PDFPaint basePaint = null;
94 |
95 | if (getBase() != null) {
96 | basePaint = getBase().getPaint(components);
97 | }
98 |
99 | PDFPattern pattern = (PDFPattern) patternObj.getCache();
100 | if (pattern == null) {
101 | pattern = PDFPattern.getPattern(patternObj, resources);
102 | patternObj.setCache(pattern);
103 | }
104 |
105 | return pattern.getPaint(basePaint);
106 | }
107 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/YCCKColorSpace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.colorspace;
21 |
22 | import java.awt.color.ColorSpace;
23 |
24 | /**
25 | * A ColorSpace for the YCCK color space. This color space converts to CMYK and then
26 | * uses an existing CMYK color space to convert from CMYK to RGB. This allows embedded
27 | * CMYK color profiles to be used with YCCK images. If no CMYK color space is
28 | * provided then by default it uses a CMYKColorSpace. Only toRGB is supported.
29 | *
30 | * @author Ben Day
31 | */
32 | public class YCCKColorSpace extends ColorSpace
33 | {
34 |
35 | private final ColorSpace cmykColorSpace;
36 |
37 | /**
38 | * create a new YCCK color space: a ColorSpace with 4 components
39 | */
40 | public YCCKColorSpace(ColorSpace existingCmykColorSpace)
41 | {
42 | super(TYPE_4CLR, 4);
43 | cmykColorSpace = existingCmykColorSpace;
44 | }
45 |
46 | public YCCKColorSpace()
47 | {
48 | this(new CMYKColorSpace());
49 | }
50 |
51 | /**
52 | * Convert from CIEXYZ to RGB. NOT IMPLEMENTED
53 | */
54 | @Override
55 | public float[] fromCIEXYZ(float[] colorvalue)
56 | {
57 | throw new UnsupportedOperationException("Not yet implemented");
58 | }
59 |
60 | /**
61 | * Convert from RGB to YCCK. NOT IMPLEMENTED
62 | *
63 | * @param rgbvalue the red, green, and blue values (0-1)
64 | * @return the YCCK values (0-1)
65 | */
66 | @Override
67 | public float[] fromRGB(float[] rgbvalue)
68 | {
69 | throw new UnsupportedOperationException("Not yet implemented");
70 | }
71 |
72 | /**
73 | * the number of components
74 | */
75 | @Override
76 | public int getNumComponents()
77 | {
78 | return 4;
79 | }
80 |
81 | /**
82 | * the name of this color space
83 | */
84 | @Override
85 | public String getName(int idx)
86 | {
87 | return "YCCK";
88 | }
89 |
90 | /**
91 | * the type of this color space (TYPE_4CLR)
92 | */
93 | @Override
94 | public int getType()
95 | {
96 | return TYPE_4CLR;
97 | }
98 |
99 | /**
100 | * Convert from YCCK to CIEXYZ. NOT IMPLEMENTED
101 | */
102 | @Override
103 | public float[] toCIEXYZ(float[] colorvalue)
104 | {
105 | return cmykColorSpace.toCIEXYZ(toCmyk(colorvalue));
106 | }
107 |
108 | /**
109 | * Convert from YCCK to RGB.
110 | *
111 | * @param colorvalue the YCCK values (0-1)
112 | * @return the RGB values (0-1)
113 | */
114 | @Override
115 | public float[] toRGB(float[] colorvalue)
116 | {
117 | return cmykColorSpace.toRGB(toCmyk(colorvalue));
118 | }
119 |
120 | private float[] toCmyk(float[] colorvalue) {
121 | float y = colorvalue[0], cb = colorvalue[1], cr = colorvalue[2], k = colorvalue[3];
122 | float[] cmyk = new float[4];
123 | float v;
124 | v = (float) (1.0 - (y + 1.402 * (cr - 0.5)));
125 | cmyk[0] = v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
126 | v = (float) (1.0 - (y - 0.34414 * (cb - 0.5) - 0.71414 * (cr - 0.5)));
127 | cmyk[1] = v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
128 | v = (float) (1.0 - (y + 1.772 * (cb - 0.5)));
129 | cmyk[2] = v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
130 | cmyk[3] = k;
131 | return cmyk;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/colorspace/sGray.icc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/colorspace/sGray.icc
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/ASCIIHexDecode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.decode;
21 |
22 | import com.sun.pdfview.PDFFile;
23 | import com.sun.pdfview.PDFObject;
24 | import com.sun.pdfview.PDFParseException;
25 |
26 | import java.io.ByteArrayOutputStream;
27 | import java.nio.ByteBuffer;
28 |
29 | /**
30 | * decode an array of hex nybbles into a byte array
31 | *
32 | * @author Mike Wessler
33 | */
34 | public class ASCIIHexDecode {
35 | private ByteBuffer buf;
36 |
37 | /**
38 | * initialize the decoder with an array of bytes in ASCIIHex format
39 | */
40 | private ASCIIHexDecode(ByteBuffer buf) {
41 | this.buf = buf;
42 | }
43 |
44 | /**
45 | * get the next character from the input
46 | * @return a number from 0-15, or -1 for the end character
47 | */
48 | private int readHexDigit() throws PDFParseException {
49 | // read until we hit a non-whitespace character or the
50 | // end of the stream
51 | while (this.buf.remaining() > 0) {
52 | int c = this.buf.get();
53 |
54 | // see if we found a useful character
55 | if (!PDFFile.isWhiteSpace((char) c)) {
56 | if (c >= '0' && c <= '9') {
57 | c -= '0';
58 | } else if (c >= 'a' && c <= 'f') {
59 | c -= 'a' - 10;
60 | } else if (c >= 'A' && c <= 'F') {
61 | c -= 'A' - 10;
62 | } else if (c == '>') {
63 | c = -1;
64 | } else {
65 | // unknown character
66 | throw new PDFParseException("Bad character " + c +
67 | "in ASCIIHex decode");
68 | }
69 |
70 | // return the useful character
71 | return c;
72 | }
73 | }
74 |
75 | // end of stream reached
76 | throw new PDFParseException("Short stream in ASCIIHex decode");
77 | }
78 |
79 | /**
80 | * decode the array
81 | * @return the decoded bytes
82 | */
83 | private ByteBuffer decode() throws PDFParseException {
84 | // start at the beginning of the buffer
85 | buf.rewind();
86 |
87 | // allocate the output buffer
88 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
89 |
90 | while (true) {
91 | int first = readHexDigit();
92 | if (first == -1) {
93 | break;
94 | }
95 | int second = readHexDigit();
96 |
97 | if (second == -1) {
98 | baos.write((byte) (first << 4));
99 | break;
100 | } else {
101 | baos.write((byte) ((first << 4) + second));
102 | }
103 | }
104 |
105 | return ByteBuffer.wrap(baos.toByteArray());
106 | }
107 |
108 | /**
109 | * decode an array of bytes in ASCIIHex format.
110 | *
111 | * ASCIIHex format consists of a sequence of Hexidecimal
112 | * digits, with possible whitespace, ending with the
113 | * '>' character.
114 | *
115 | * @param buf the encoded ASCII85 characters in a byte
116 | * buffer
117 | * @param params parameters to the decoder (ignored)
118 | * @return the decoded bytes
119 | */
120 | public static ByteBuffer decode(ByteBuffer buf, PDFObject params)
121 | throws PDFParseException
122 | {
123 | ASCIIHexDecode me = new ASCIIHexDecode(buf);
124 | return me.decode();
125 | }
126 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/CCITTFaxDecode.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.decode;
2 |
3 | import java.io.IOException;
4 | import java.nio.ByteBuffer;
5 |
6 | import com.sun.pdfview.PDFDebugger;
7 | import com.sun.pdfview.PDFObject;
8 |
9 | public class CCITTFaxDecode {
10 |
11 |
12 |
13 | protected static ByteBuffer decode(PDFObject dict, ByteBuffer buf,
14 | PDFObject params) throws IOException {
15 |
16 | byte[] bytes = new byte[buf.remaining()];
17 | buf.get(bytes, 0, bytes.length);
18 | return ByteBuffer.wrap(decode(dict, bytes));
19 | }
20 |
21 |
22 | protected static byte[] decode(PDFObject dict, byte[] source) throws IOException {
23 | int width = 1728;
24 | PDFObject widthDef = dict.getDictRef("Width");
25 | if (widthDef == null) {
26 | widthDef = dict.getDictRef("W");
27 | }
28 | if (widthDef != null) {
29 | width = widthDef.getIntValue();
30 | }
31 | int height = 0;
32 | PDFObject heightDef = dict.getDictRef("Height");
33 | if (heightDef == null) {
34 | heightDef = dict.getDictRef("H");
35 | }
36 | if (heightDef != null) {
37 | height = heightDef.getIntValue();
38 | }
39 |
40 | //
41 | int columns = getOptionFieldInt(dict, "Columns", width);
42 | int rows = getOptionFieldInt(dict, "Rows", height);
43 | int k = getOptionFieldInt(dict, "K", 0);
44 | int size = rows * ((columns + 7) >> 3);
45 | byte[] destination = new byte[size];
46 |
47 | boolean align = getOptionFieldBoolean(dict, "EncodedByteAlign", false);
48 |
49 | CCITTFaxDecoder decoder = new CCITTFaxDecoder(1, columns, rows);
50 | decoder.setAlign(align);
51 | try {
52 | if (k == 0) {
53 | decoder.decodeT41D(destination, source, 0, rows);
54 | } else if (k > 0) {
55 | decoder.decodeT42D(destination, source, 0, rows);
56 | } else if (k < 0) {
57 | decoder.decodeT6(destination, source, 0, rows);
58 | }
59 | }catch (Exception e) {
60 | PDFDebugger.debug("Error decoding CCITTFax image k: "+ k);
61 | // some PDf producer don't correctly assign a k value for the deocde,
62 | // as result we can try one more time using the T6.
63 | //first, reset buffer
64 | destination = new byte[size];
65 | try {
66 | decoder.decodeT6(destination, source, 0, rows);
67 | }catch (Exception e1) {
68 | // do nothing
69 | PDFDebugger.debug("Error decoding CCITTFax image");
70 | }
71 | }
72 | if (!getOptionFieldBoolean(dict, "BlackIs1", false)) {
73 | for (int i = 0; i < destination.length; i++) {
74 | // bitwise not
75 | destination[i] = (byte) ~destination[i];
76 | }
77 | }
78 |
79 | return destination;
80 | }
81 |
82 | public static int getOptionFieldInt(PDFObject dict, String name, int defaultValue) throws IOException {
83 |
84 | PDFObject dictParams = getDecodeParams(dict);
85 |
86 | if (dictParams == null) {
87 | return defaultValue;
88 | }
89 | PDFObject value = dictParams.getDictRef(name);
90 | if (value == null) {
91 | return defaultValue;
92 | }
93 | return value.getIntValue();
94 | }
95 |
96 | public static boolean getOptionFieldBoolean(PDFObject dict, String name, boolean defaultValue) throws IOException {
97 |
98 | PDFObject dictParams = getDecodeParams(dict);
99 |
100 | if (dictParams == null) {
101 | return defaultValue;
102 | }
103 | PDFObject value = dictParams.getDictRef(name);
104 | if (value == null) {
105 | return defaultValue;
106 | }
107 | return value.getBooleanValue();
108 | }
109 |
110 | private static PDFObject getDecodeParams(PDFObject dict) throws IOException {
111 | PDFObject decdParams = dict.getDictRef("DecodeParms");
112 | if (decdParams != null && decdParams.getType() == PDFObject.ARRAY) {
113 | return decdParams.getArray()[0];
114 | }
115 | return decdParams;
116 | }
117 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/FlateDecode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview.decode;
20 |
21 | import java.io.ByteArrayOutputStream;
22 | import java.io.IOException;
23 | import java.nio.ByteBuffer;
24 | import java.util.zip.DataFormatException;
25 | import java.util.zip.Inflater;
26 |
27 | import com.sun.pdfview.PDFObject;
28 | import com.sun.pdfview.PDFParseException;
29 |
30 | /**
31 | * decode a deFlated byte array
32 | * @author Mike Wessler
33 | */
34 | public class FlateDecode {
35 |
36 | /**
37 | * decode a byte buffer in Flate format.
38 | *
39 | * Flate is a built-in Java algorithm. It's part of the java.util.zip
40 | * package.
41 | *
42 | * @param buf the deflated input buffer
43 | * @param params parameters to the decoder (unused)
44 | * @return the decoded (inflated) bytes
45 | */
46 | public static ByteBuffer decode(PDFObject dict, ByteBuffer buf,
47 | PDFObject params) throws IOException {
48 | Inflater inf = new Inflater(false);
49 |
50 | int bufSize = buf.remaining();
51 |
52 | // copy the data, since the array() method is not supported
53 | // on raf-based ByteBuffers
54 | byte[] data = new byte[bufSize];
55 | buf.get(data);
56 |
57 | // set the input to the inflater
58 | inf.setInput(data);
59 |
60 | // output to a byte-array output stream, since we don't
61 | // know how big the output will be
62 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
63 | byte[] decomp = new byte[bufSize];
64 | int read = 0;
65 |
66 | try {
67 | while (!inf.finished()) {
68 | read = inf.inflate(decomp);
69 | if (read <= 0) {
70 | if (inf.needsDictionary()) {
71 | throw new PDFParseException("Don't know how to ask for a dictionary in FlateDecode");
72 | } else {
73 | // just return the data which is already read
74 | break;
75 | }
76 | }
77 | baos.write(decomp, 0, read);
78 | }
79 | } catch (DataFormatException dfe) {
80 | throw new PDFParseException("Data format exception:" + dfe.getMessage());
81 | }
82 |
83 | // return the output as a byte buffer
84 | ByteBuffer outBytes = ByteBuffer.wrap(baos.toByteArray());
85 |
86 | // undo a predictor algorithm, if any was used
87 | if (params != null && params.getDictionary().containsKey("Predictor")) {
88 | Predictor predictor = Predictor.getPredictor(params);
89 | if (predictor != null) {
90 | outBytes = predictor.unpredict(outBytes);
91 | }
92 | }
93 |
94 | return outBytes;
95 | }
96 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/ImageDataDecoder.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.decode;
2 |
3 | import java.awt.Graphics;
4 | import java.awt.image.BufferedImage;
5 | import java.awt.image.DataBufferByte;
6 | import java.awt.image.DataBufferInt;
7 |
8 | /*****************************************************************************
9 | * Decode image data to a usable color space.
10 | *
11 | * @since 25.03.2011
12 | ****************************************************************************/
13 |
14 | public class ImageDataDecoder {
15 |
16 | /*************************************************************************
17 | * @param bimg
18 | * @return
19 | ************************************************************************/
20 |
21 | static byte[] decodeImageData(BufferedImage bimg) {
22 | byte[] output = null;
23 |
24 | int type = bimg.getType();
25 |
26 | if (type == BufferedImage.TYPE_INT_RGB) {
27 | // read back the data
28 | DataBufferInt db = (DataBufferInt) bimg.getData()
29 | .getDataBuffer();
30 | int[] data = db.getData();
31 |
32 | output = new byte[data.length * 3];
33 | for (int i = 0, offset = 0; i < data.length; i++, offset += 3) {
34 | output[offset] = (byte) (data[i] >> 16);
35 | output[offset + 1] = (byte) (data[i] >> 8);
36 | output[offset + 2] = (byte) (data[i]);
37 | }
38 | } else if (type == BufferedImage.TYPE_BYTE_GRAY) {
39 | DataBufferByte db = (DataBufferByte) bimg.getData()
40 | .getDataBuffer();
41 | output = db.getData();
42 | } else if (type == BufferedImage.TYPE_INT_ARGB) {
43 | // read back the data
44 | DataBufferInt db = (DataBufferInt) bimg.getData()
45 | .getDataBuffer();
46 | int[] data = db.getData();
47 |
48 | output = new byte[data.length * 4];
49 | for (int i = 0, offset = 0; i < data.length; i++, offset += 4) {
50 | output[offset] = (byte) (data[i] >> 24);
51 | output[offset + 1] = (byte) (data[i] >> 16);
52 | output[offset + 2] = (byte) (data[i] >> 8);
53 | output[offset + 3] = (byte) (data[i]);
54 | }
55 | } else {
56 | // The raster is in some other format.
57 | // We have to convert it into TYPE_INT_RGB before we can use it.
58 | BufferedImage tmp = new BufferedImage(bimg.getWidth(),
59 | bimg.getHeight(), BufferedImage.TYPE_INT_RGB);
60 | Graphics g = tmp.createGraphics();
61 | g.drawImage(bimg, 0, 0, null);
62 | g.dispose();
63 | // read back the data
64 | DataBufferInt db = (DataBufferInt) tmp.getData()
65 | .getDataBuffer();
66 | int[] data = db.getData();
67 |
68 | output = new byte[data.length * 3];
69 | for (int i = 0, offset = 0; i < data.length; i++, offset += 3) {
70 | output[offset] = (byte) (data[i] >> 16);
71 | output[offset + 1] = (byte) (data[i] >> 8);
72 | output[offset + 2] = (byte) (data[i]);
73 | }
74 | tmp.flush();
75 | }
76 | return output;
77 | }
78 |
79 |
80 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/JBig2Decode.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.decode;
2 |
3 | import java.io.IOException;
4 | import java.nio.ByteBuffer;
5 |
6 | import org.jpedal.jbig2.JBIG2Decoder;
7 | import org.jpedal.jbig2.JBIG2Exception;
8 |
9 | import com.sun.pdfview.PDFObject;
10 |
11 | /*****************************************************************************
12 | * Decoder for jbig2 images within PDFs.
13 | * Copied from
14 | * https://pdf-renderer.dev.java.net/issues/show_bug.cgi?id=67
15 | *
16 | * Problem is also described in:
17 | * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799898
18 | * @since 17.11.2010
19 | ***************************************************************************
20 | */
21 | public class JBig2Decode {
22 | protected static ByteBuffer decode(PDFObject dict, ByteBuffer buf,
23 | PDFObject params) throws IOException {
24 |
25 | byte[] bytes = new byte[buf.remaining()];
26 | buf.get(bytes, 0, bytes.length);
27 |
28 | return ByteBuffer.wrap(decode(dict, bytes));
29 | }
30 |
31 |
32 | protected static byte[] decode(PDFObject dict, byte[] source) throws IOException {
33 | JBIG2Decoder decoder;
34 | decoder = new JBIG2Decoder();
35 | try {
36 | byte[] globals = getOptionFieldBytes(dict, "JBIG2Globals");
37 | if (globals != null) {
38 | decoder.setGlobalData(globals);
39 | }
40 | decoder.decodeJBIG2(source);
41 | } catch (JBIG2Exception ex) {
42 | IOException ioException;
43 |
44 | ioException = new IOException();
45 | ioException.initCause(ex);
46 | throw ioException;
47 | }
48 | return decoder.getPageAsJBIG2Bitmap(0).getData(true);
49 | }
50 |
51 |
52 | public static byte[] getOptionFieldBytes(PDFObject dict, String name) throws IOException {
53 |
54 | PDFObject dictParams = dict.getDictRef("DecodeParms");
55 |
56 | if (dictParams == null) {
57 | return null;
58 | }
59 | PDFObject value = dictParams.getDictRef(name);
60 | if (value == null) {
61 | return null;
62 | }
63 | return value.getStream();
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/JPXDecode.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
2 | * Santa Clara, California 95054, U.S.A. All rights reserved.
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | package com.sun.pdfview.decode;
20 |
21 | import java.awt.image.BufferedImage;
22 | import java.io.ByteArrayInputStream;
23 | import java.io.IOException;
24 | import java.nio.ByteBuffer;
25 | import java.util.Iterator;
26 |
27 | import javax.imageio.ImageIO;
28 | import javax.imageio.ImageReader;
29 | import javax.imageio.stream.MemoryCacheImageInputStream;
30 |
31 | import com.sun.pdfview.PDFObject;
32 | import com.sun.pdfview.PDFParseException;
33 |
34 | /**
35 | * decode a JPX encoded imagestream into a byte array. This class uses Java's
36 | * image_io JPEG2000 reader to do the decoding.
37 | *
38 | * @author Bernd Rosstauscher
39 | */
40 |
41 | public class JPXDecode {
42 |
43 | /*************************************************************************
44 | * @param dict
45 | * @param buf
46 | * @param params
47 | * @return
48 | * @throws PDFParseException
49 | ************************************************************************/
50 |
51 | protected static ByteBuffer decode(PDFObject dict, ByteBuffer buf, PDFObject params) throws PDFParseException {
52 | BufferedImage bimg = loadImageData(buf);
53 | byte[] output = ImageDataDecoder.decodeImageData(bimg);
54 | return ByteBuffer.wrap(output);
55 | }
56 |
57 | /*************************************************************************
58 | * @param buf
59 | * @return
60 | * @throws PDFParseException
61 | * @throws IOException
62 | ************************************************************************/
63 |
64 | private static BufferedImage loadImageData(ByteBuffer buf) throws PDFParseException {
65 | ImageReader reader = null;
66 | try {
67 | byte[] input = new byte[buf.remaining()];
68 | buf.get(input);
69 | Iterator readers = ImageIO.getImageReadersByMIMEType("image/jpeg2000");
70 | if (readers.hasNext() == false) {
71 | throw new PDFParseException("JPXDecode failed. No reader available");
72 | }
73 | reader = readers.next();
74 | reader.setInput(new MemoryCacheImageInputStream(new ByteArrayInputStream(input)));
75 | BufferedImage bimg = reader.read(0);
76 | return bimg;
77 | } catch (IOException e) {
78 | throw new PDFParseException("JPXDecode failed", e);
79 | } finally {
80 | if (reader != null) {
81 | reader.dispose();
82 | }
83 | }
84 |
85 | }
86 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decode/RunLengthDecode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview.decode;
20 |
21 | import java.io.ByteArrayOutputStream;
22 | import java.nio.ByteBuffer;
23 |
24 | import com.sun.pdfview.PDFObject;
25 | import com.sun.pdfview.PDFParseException;
26 |
27 | /**
28 | * decode an array of Run Length encoded bytes into a byte array
29 | *
30 | * @author Mike Wessler
31 | */
32 | public class RunLengthDecode {
33 | /** the end of data in the RunLength encoding. */
34 | private static final int RUN_LENGTH_EOD = 128;
35 |
36 | private ByteBuffer buf;
37 |
38 | /**
39 | * initialize the decoder with an array of bytes in RunLength format
40 | */
41 | private RunLengthDecode(ByteBuffer buf) {
42 | this.buf = buf;
43 | }
44 |
45 | /**
46 | * decode the array
47 | *
48 | * @return the decoded bytes
49 | */
50 | private ByteBuffer decode() {
51 | // start at the beginning of the buffer
52 | this.buf.rewind();
53 |
54 | // allocate the output buffer
55 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
56 | int dupAmount;
57 | byte[] buffer = new byte[128];
58 | while ((dupAmount = this.buf.get()&0xFF) != RUN_LENGTH_EOD) {
59 | if (dupAmount >= 0 && dupAmount <= 127) {
60 | int amountToCopy = dupAmount + 1;
61 | this.buf.get(buffer, 0, amountToCopy);
62 | baos.write(buffer, 0, amountToCopy);
63 | } else {
64 | byte dupByte = this.buf.get();
65 | for (int i = 0; i < 257 - dupAmount; i++) {
66 | baos.write(dupByte);
67 | }
68 | }
69 | }
70 | return ByteBuffer.wrap(baos.toByteArray());
71 | }
72 |
73 | /**
74 | * decode an array of bytes in RunLength format.
75 | *
76 | * RunLength format consists of a sequence of a byte-oriented format based
77 | * on run length. There are a series of "runs", where a run is a length byte
78 | * followed by 1 to 128 bytes of data. If the length is 0-127, the following
79 | * length+1 (1 to 128) bytes are to be copied. If the length is 129 through
80 | * 255, the following single byte is copied 257-length (2 to 128) times. A
81 | * length value of 128 means and End of Data (EOD).
82 | *
83 | * @param buf
84 | * the RUnLEngth encoded bytes in a byte buffer
85 | *
86 | * @param params
87 | * parameters to the decoder (ignored)
88 | * @return the decoded bytes
89 | */
90 | public static ByteBuffer decode(ByteBuffer buf, PDFObject params) throws PDFParseException {
91 | RunLengthDecode me = new RunLengthDecode(buf);
92 | return me.decode();
93 | }
94 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decrypt/EncryptionUnsupportedByPlatformException.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
2 | * Fortitude Valley, Queensland, Australia
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | package com.sun.pdfview.decrypt;
20 |
21 | /**
22 | * Identifies that the specified encryption mechanism, though supported by the
23 | * product, is not supported by the platform that it is running on; i.e., that
24 | * either the JCE does not support a required cipher or that its policy is
25 | * such that a key of a given length can not be used.
26 | *
27 | * @author Luke Kirby
28 | */
29 | public class EncryptionUnsupportedByPlatformException
30 | extends UnsupportedEncryptionException {
31 |
32 | public EncryptionUnsupportedByPlatformException(String message) {
33 | super(message);
34 | }
35 |
36 | public EncryptionUnsupportedByPlatformException(String message, Throwable cause) {
37 | super(message, cause);
38 | }
39 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decrypt/EncryptionUnsupportedByProductException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.decrypt;
21 |
22 | /**
23 | * Identifies that the specified encryption mechanism is not
24 | * supported by this product, that is, PDFRenderer, as opposed to
25 | * a {@link EncryptionUnsupportedByPlatformException limitation in
26 | * the platform}.
27 | *
28 | * @author Luke Kirby
29 | */
30 | public class EncryptionUnsupportedByProductException
31 | extends UnsupportedEncryptionException {
32 |
33 | public EncryptionUnsupportedByProductException(String message) {
34 | super(message);
35 | }
36 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decrypt/IdentityDecrypter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.decrypt;
21 |
22 | import java.nio.ByteBuffer;
23 |
24 | import com.sun.pdfview.PDFObject;
25 | import com.sun.pdfview.PDFParseException;
26 |
27 | /**
28 | * Performs identity decryption; that is, inputs aren't encrypted and
29 | * are returned right back.
30 | *
31 | * @Author Luke Kirby
32 | */
33 | public class IdentityDecrypter implements PDFDecrypter {
34 |
35 | private static IdentityDecrypter INSTANCE = new IdentityDecrypter();
36 |
37 | @Override
38 | public ByteBuffer decryptBuffer(String cryptFilterName,
39 | PDFObject streamObj, ByteBuffer streamBuf)
40 | throws PDFParseException {
41 |
42 | if (cryptFilterName != null) {
43 | throw new PDFParseException("This Encryption version does not support Crypt filters");
44 | }
45 |
46 | return streamBuf;
47 | }
48 |
49 | @Override
50 | public String decryptString(int objNum, int objGen, String inputBasicString) {
51 | return inputBasicString;
52 | }
53 |
54 | public static IdentityDecrypter getInstance() {
55 | return INSTANCE;
56 | }
57 |
58 | @Override
59 | public boolean isEncryptionPresent() {
60 | return false;
61 | }
62 |
63 | @Override
64 | public boolean isEncryptionPresent(String cryptFilterName) {
65 | return false;
66 | }
67 |
68 | @Override
69 | public boolean isOwnerAuthorised() {
70 | return false;
71 | }
72 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decrypt/PDFAuthenticationFailureException.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
2 | * Fortitude Valley, Queensland, Australia
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | package com.sun.pdfview.decrypt;
20 |
21 | import com.sun.pdfview.PDFParseException;
22 |
23 | /**
24 | * Identifies that the supplied password was incorrect or non-existent
25 | * and required.
26 | * @author Luke Kirby
27 | */
28 | // TODO - consider having this not extend PDFParseException so that
29 | // it will be handled more explicitly?
30 | public class PDFAuthenticationFailureException extends PDFParseException {
31 | public PDFAuthenticationFailureException(String message) {
32 | super(message);
33 | }
34 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/decrypt/UnsupportedEncryptionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Pirion Systems Pty Ltd, 139 Warry St,
3 | * Fortitude Valley, Queensland, Australia
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.decrypt;
21 |
22 | /**
23 | * Identifies that the specified encryption mechanism is not
24 | * supported by this product or platform.
25 | *
26 | * @see EncryptionUnsupportedByPlatformException
27 | * @see EncryptionUnsupportedByProductException
28 | * @author Luke Kirby
29 | */
30 | public abstract class UnsupportedEncryptionException extends Exception {
31 |
32 | protected UnsupportedEncryptionException(String message) {
33 | super(message);
34 | }
35 |
36 | protected UnsupportedEncryptionException(String message, Throwable cause) {
37 | super(message, cause);
38 | }
39 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/CIDFontType0.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.font;
2 |
3 | import java.io.IOException;
4 |
5 | import com.sun.pdfview.PDFObject;
6 | import com.sun.pdfview.font.cid.PDFCMap;
7 | import com.sun.pdfview.font.ttf.AdobeGlyphList;
8 |
9 | /*****************************************************************************
10 | * At the moment this is not fully supported to parse CID based fonts
11 | * As a hack we try to use a built in font as substitution and use a
12 | * toUnicode map to translate the characters if available.
13 | *
14 | *
15 | * @version $Id: CIDFontType0.java,v 1.1 2011-08-03 15:48:56 bros Exp $
16 | * @author Bernd Rosstauscher
17 | * @since 03.08.2011
18 | ****************************************************************************/
19 |
20 | public class CIDFontType0 extends BuiltinFont {
21 |
22 | private PDFCMap glyphLookupMap;
23 |
24 | /*************************************************************************
25 | * Constructor
26 | * @param baseFont
27 | * @param fontObj
28 | * @param descriptor
29 | * @throws IOException
30 | ************************************************************************/
31 |
32 | public CIDFontType0(String baseFont, PDFObject fontObj,
33 | PDFFontDescriptor descriptor) throws IOException {
34 | super(baseFont, fontObj, descriptor);
35 | }
36 |
37 | /*************************************************************************
38 | * @param fontObj
39 | * @throws IOException
40 | ************************************************************************/
41 |
42 | public void parseToUnicodeMap(PDFObject fontObj) throws IOException {
43 | PDFObject toUnicode = fontObj.getDictRef("ToUnicode");
44 | if (toUnicode != null) {
45 | PDFCMap cmap = PDFCMap.getCMap(toUnicode);
46 | this.glyphLookupMap = cmap;
47 | }
48 | }
49 |
50 | /**
51 | * Get a character from the first font in the descendant fonts array
52 | */
53 | @Override
54 | protected PDFGlyph getGlyph(char src, String name) {
55 | //TODO BROS 03.08.2011 Hack for unsupported Type0 CID based fonts
56 | // If we have a toUnicodeMap then try to use that one when mapping to our build in font.
57 | // See "9.10 Extraction of Text Content" in the PDF spec.
58 | if (this.glyphLookupMap != null) {
59 | src = this.glyphLookupMap.map(src);
60 | //The preferred method of getting the glyph should be by name.
61 | if (name == null && src != 160){//unless it NBSP
62 | //so, try to find the name by the char
63 | name = AdobeGlyphList.getGlyphName(src);
64 | }
65 | }
66 | return super.getGlyph(src, name);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/FlPoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.font;
21 |
22 | /**
23 | * A floating-point Point, with public fields. Also contains a flag
24 | * for "open" to indicate that the path this point is a member of has
25 | * or hasn't been closed.
26 | *
27 | * @author Mike Wessler
28 | */
29 | public class FlPoint {
30 | /** x coordinate of the point */
31 | public float x= 0;
32 |
33 | /** y coordinate of the point */
34 | public float y= 0;
35 |
36 | /**
37 | * whether the path this point is a part of is open or closed.
38 | * used in Type1CFont.java.
39 | */
40 | public boolean open= false;
41 |
42 | /** reset the values to (0,0) and closed */
43 | public final void reset() {
44 | this.x= 0;
45 | this.y= 0;
46 | this.open= false;
47 | }
48 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/PDFGlyph.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview.font;
20 |
21 | import java.awt.geom.AffineTransform;
22 | import java.awt.geom.GeneralPath;
23 | import java.awt.geom.Point2D;
24 |
25 | import com.sun.pdfview.PDFPage;
26 | import com.sun.pdfview.PDFShapeCmd;
27 |
28 | /**
29 | * A single glyph in a stream of PDF text, which knows how to write itself
30 | * onto a PDF command stream
31 | */
32 | public class PDFGlyph {
33 | /** the character code of this glyph */
34 | private final char src;
35 | /** the name of this glyph */
36 | private final String name;
37 | /** the advance from this glyph */
38 | private final Point2D advance;
39 | /** the shape represented by this glyph (for all fonts but type 3) */
40 | private GeneralPath shape;
41 | /** the PDFPage storing this glyph's commands (for type 3 fonts) */
42 | private PDFPage page;
43 |
44 | /** Creates a new instance of PDFGlyph based on a shape */
45 | public PDFGlyph(char src, String name, GeneralPath shape, Point2D.Float advance) {
46 | this.shape = shape;
47 | this.advance = advance;
48 | this.src = src;
49 | this.name = name;
50 | }
51 |
52 | /** Creates a new instance of PDFGlyph based on a page */
53 | public PDFGlyph(char src, String name, PDFPage page, Point2D advance) {
54 | this.page = page;
55 | this.advance = advance;
56 | this.src = src;
57 | this.name = name;
58 | }
59 |
60 | /** Get the character code of this glyph */
61 | public char getChar() {
62 | return this.src;
63 | }
64 |
65 | /** Get the name of this glyph */
66 | public String getName() {
67 | return this.name;
68 | }
69 |
70 | /** Get the shape of this glyph */
71 | public GeneralPath getShape() {
72 | return this.shape;
73 | }
74 |
75 | /** Get the PDFPage for a type3 font glyph */
76 | public PDFPage getPage() {
77 | return this.page;
78 | }
79 |
80 | /** Add commands for this glyph to a page */
81 | public Point2D addCommands(PDFPage cmds, AffineTransform transform, int mode) {
82 | if (this.shape != null) {
83 | GeneralPath outline = (GeneralPath) this.shape.createTransformedShape(transform);
84 | cmds.addCommand(new PDFShapeCmd(outline, mode, false));
85 | } else if (this.page != null) {
86 | cmds.addCommands(this.page, transform);
87 | }
88 | return this.advance;
89 | }
90 |
91 | public Point2D getAdvance() {
92 | return advance;
93 | }
94 |
95 | @Override
96 | public String toString() {
97 | StringBuffer str = new StringBuffer();
98 | str.append(this.name);
99 | return str.toString();
100 | }
101 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/Type0Font.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.font;
21 |
22 | import java.io.IOException;
23 |
24 | import com.sun.pdfview.PDFObject;
25 |
26 | /**
27 | * Type 0 fonts are composite fonts with a CMAP to map between
28 | * source character codes and destination fonts/codes
29 | *
30 | * @author Jonathan Kaplan
31 | */
32 | public class Type0Font extends PDFFont {
33 |
34 | /**
35 | * The decendant fonts, indexed by font number from the CMAP
36 | */
37 | PDFFont[] fonts;
38 |
39 | /** Creates a new instance of Type0Font */
40 | public Type0Font(String baseFont, PDFObject fontObj,
41 | PDFFontDescriptor descriptor) throws IOException {
42 | super (baseFont, descriptor);
43 |
44 | PDFObject[] descendantFonts = fontObj.getDictRef("DescendantFonts").getArray();
45 |
46 | this.fonts = new PDFFont[descendantFonts.length];
47 |
48 | for (int i = 0; i < descendantFonts.length; i++) {
49 | PDFFont descFont = PDFFont.getFont(descendantFonts[i], null);
50 | if (descFont instanceof CIDFontType0) {
51 | ((CIDFontType0)descFont).parseToUnicodeMap(fontObj);
52 | }
53 | this.fonts[i] = descFont;
54 | }
55 | }
56 |
57 | /**
58 | * Get a descendant font of this font by fontId
59 | */
60 | public PDFFont getDescendantFont(int fontID) {
61 | return this.fonts[fontID];
62 | }
63 |
64 | /**
65 | * Get a character from the first font in the descendant fonts array
66 | */
67 | @Override
68 | protected PDFGlyph getGlyph(char src, String name) {
69 | return (getDescendantFont(0).getGlyph(src, name));
70 | }
71 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/cid/PDFCMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 | package com.sun.pdfview.font.cid;
20 |
21 | import java.io.IOException;
22 | import java.util.HashMap;
23 |
24 | import com.sun.pdfview.PDFDebugger;
25 | import com.sun.pdfview.PDFObject;
26 |
27 | /**
28 | * A CMap maps from a character in a composite font to a font/glyph number
29 | * pair in a CID font.
30 | *
31 | * @author jkaplan
32 | */
33 | public abstract class PDFCMap {
34 | /**
35 | * A cache of known CMaps by name
36 | */
37 | private static HashMap cache;
38 |
39 | /** Creates a new instance of CMap */
40 | protected PDFCMap() {}
41 |
42 | /**
43 | * Get a CMap, given a PDF object containing one of the following:
44 | * a string name of a known CMap
45 | * a stream containing a CMap definition
46 | */
47 | public static PDFCMap getCMap(PDFObject map) throws IOException {
48 | if (map.getType() == PDFObject.NAME) {
49 | return getCMap(map.getStringValue());
50 | } else if (map.getType() == PDFObject.STREAM) {
51 | return parseCMap(map);
52 | } else {
53 | throw new IOException("CMap type not Name or Stream!");
54 | }
55 | }
56 |
57 | /**
58 | * Get a CMap, given a string name
59 | */
60 | public static PDFCMap getCMap(String mapName) throws IOException {
61 | if (cache == null) {
62 | populateCache();
63 | }
64 |
65 | if (!cache.containsKey(mapName)) {
66 | //throw new IOException("Unknown CMap: " + mapName);
67 | PDFDebugger.debug("Unknown CMap: '" + mapName + "' procced with 'Identity-H'");
68 | return cache.get("Identity-H");
69 | }
70 |
71 | return cache.get(mapName);
72 | }
73 |
74 | /**
75 | * Populate the cache with well-known types
76 | */
77 | protected static void populateCache() {
78 | cache = new HashMap();
79 |
80 | // add the Identity-H map
81 | cache.put("Identity-H", new PDFCMap() {
82 | @Override
83 | public char map(char src) {
84 | return src;
85 | }
86 | });
87 | }
88 |
89 | /**
90 | * Parse a CMap from a CMap stream
91 | */
92 | protected static PDFCMap parseCMap(PDFObject map) throws IOException {
93 | return new ToUnicodeMap(map);
94 | }
95 |
96 | /**
97 | * Map a given source character to a destination character
98 | */
99 | public abstract char map(char src);
100 |
101 | /**
102 | * Get the font number assoicated with a given source character
103 | */
104 | public int getFontID(char src) {
105 | return 0;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/BaseFonts.properties:
--------------------------------------------------------------------------------
1 | # Sample ResourceBundle properties file
2 |
3 | Courier.file=n022003l.pfb
4 |
5 | Courier.length=96263
6 |
7 | Courier-Bold.file=n022004l.pfb
8 |
9 | Courier-Bold.length=120373
10 |
11 | Courier-BoldOblique.file=n022024l.pfb
12 |
13 | Courier-BoldOblique.length=114228
14 |
15 | Courier-Oblique.file=n022023l.pfb
16 |
17 | Courier-Oblique.length=101133
18 |
19 | Helvetica.file=n019003l.pfb
20 |
21 | Helvetica.length=68590
22 |
23 | Helvetica-Bold.file=n019004l.pfb
24 |
25 | Helvetica-Bold.length=72400
26 |
27 | Helvetica-BoldOblique.file=n019024l.pfb
28 |
29 | Helvetica-BoldOblique.length=73879
30 |
31 | Helvetica-Oblique.file=n019023l.pfb
32 |
33 | Helvetica-Oblique.length=71719
34 |
35 | Times-Roman.file=n021003l.pfb
36 |
37 | Times-Roman.length=113206
38 |
39 | Times-Bold.file=n021004l.pfb
40 |
41 | Times-Bold.length=108822
42 |
43 | Times-BoldItalic.file=n021024l.pfb
44 |
45 | Times-BoldItalic.length=96211
46 |
47 | Times-Italic.file=n021023l.pfb
48 |
49 | Times-Italic.length=108217
50 |
51 | Symbol.file=s050000l.pfb
52 |
53 | Symbol.length=32213
54 |
55 | ZapfDingbats.file=d050000l.pfb
56 |
57 | ZapfDingbats.length=45955
58 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/d050000l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/d050000l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n019003l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n019003l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n019004l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n019004l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n019023l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n019023l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n019024l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n019024l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n021003l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n021003l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n021004l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n021004l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n021023l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n021023l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n021024l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n021024l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n022003l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n022003l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n022004l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n022004l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n022023l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n022023l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/n022024l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/n022024l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/res/s050000l.pfb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/res/s050000l.pfb
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/ttf/LocaTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
3 | * Santa Clara, California 95054, U.S.A. All rights reserved.
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public
16 | * License along with this library; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | package com.sun.pdfview.font.ttf;
21 |
22 | import java.nio.ByteBuffer;
23 |
24 | /**
25 | * Model the TrueType Loca table
26 | */
27 | public class LocaTable extends TrueTypeTable {
28 | /** if true, the table stores glyphs in long format */
29 | private boolean isLong;
30 |
31 | /** the offsets themselves */
32 | private int offsets[];
33 |
34 | /** Creates a new instance of HmtxTable */
35 | protected LocaTable(TrueTypeFont ttf) {
36 | super (TrueTypeTable.LOCA_TABLE);
37 |
38 | MaxpTable maxp = (MaxpTable) ttf.getTable("maxp");
39 | int numGlyphs = maxp.getNumGlyphs();
40 |
41 | HeadTable head = (HeadTable) ttf.getTable("head");
42 | short format = head.getIndexToLocFormat();
43 | this.isLong = (format == 1);
44 |
45 | this.offsets = new int[numGlyphs + 1];
46 | }
47 |
48 | /**
49 | * get the offset, in bytes, of a given glyph from the start of
50 | * the glyph table
51 | */
52 | public int getOffset(int glyphID) {
53 | return this.offsets[glyphID];
54 | }
55 |
56 | /**
57 | * get the size, in bytes, of the given glyph
58 | */
59 | public int getSize(int glyphID) {
60 | return this.offsets[glyphID + 1] - this.offsets[glyphID];
61 | }
62 |
63 | /**
64 | * Return true if the glyphs arte in long (int) format, or
65 | * false if they are in short (short) format
66 | */
67 | public boolean isLongFormat() {
68 | return this.isLong;
69 | }
70 |
71 |
72 | /** get the data in this map as a ByteBuffer */
73 | @Override
74 | public ByteBuffer getData() {
75 | int size = getLength();
76 |
77 | ByteBuffer buf = ByteBuffer.allocate(size);
78 |
79 | // write the offsets
80 | for (int i = 0; i < this.offsets.length; i++) {
81 | if (isLongFormat()) {
82 | buf.putInt(this.offsets[i]);
83 | } else {
84 | buf.putShort((short) (this.offsets[i] / 2));
85 | }
86 | }
87 |
88 | // reset the start pointer
89 | buf.flip();
90 |
91 | return buf;
92 | }
93 |
94 | /** Initialize this structure from a ByteBuffer */
95 | @Override
96 | public void setData(ByteBuffer data) {
97 | for (int i = 0; i < this.offsets.length; i++) {
98 | if (isLongFormat()) {
99 | this.offsets[i] = data.getInt();
100 | } else {
101 | this.offsets[i] = 2 * ( 0xFFFF & data.getShort());
102 | }
103 | }
104 | }
105 |
106 | /**
107 | * Get the length of this table
108 | */
109 | @Override
110 | public int getLength() {
111 | if (isLongFormat()) {
112 | return this.offsets.length * 4;
113 | } else {
114 | return this.offsets.length * 2;
115 | }
116 | }
117 | }
--------------------------------------------------------------------------------
/src/com/sun/pdfview/font/ttf/resource/glyphlist.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/src/com/sun/pdfview/font/ttf/resource/glyphlist.txt
--------------------------------------------------------------------------------
/src/com/sun/pdfview/function/postscript/PostScriptParser.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.function.postscript;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 | import java.util.StringTokenizer;
6 |
7 | /*****************************************************************************
8 | * Very simple post script parser / tokenizer
9 | *
10 | * @author Bernd Rosstauscher
11 | * @since 22.10.2010
12 | ****************************************************************************/
13 |
14 | public class PostScriptParser {
15 |
16 | /*************************************************************************
17 | * Constructor
18 | ************************************************************************/
19 |
20 | public PostScriptParser() {
21 | super();
22 | }
23 |
24 | /*************************************************************************
25 | * Parses the given script and returns a list of tokens.
26 | * @param scriptContent to parse.
27 | * @return the list of tokens.
28 | ************************************************************************/
29 |
30 | public List parse(String scriptContent) {
31 | List tokens = new LinkedList();
32 | StringTokenizer tok = new StringTokenizer(scriptContent, " \t\n\r");
33 | while (tok.hasMoreTokens()) {
34 | String t = tok.nextToken();
35 | t = filterBlockStart(t);
36 | t = filterBlockEnd(t);
37 | if (t.length() > 0) {
38 | tokens.add(t.trim());
39 | }
40 | }
41 | return tokens;
42 | }
43 |
44 | /*************************************************************************
45 | * @param t
46 | * @return
47 | ************************************************************************/
48 | private String filterBlockEnd(String t) {
49 | if (t.endsWith("}")) {
50 | t = t.substring(0, t.length()-1);
51 | }
52 | return t;
53 | }
54 |
55 | /*************************************************************************
56 | * @param t
57 | * @return
58 | ************************************************************************/
59 | private String filterBlockStart(String t) {
60 | if (t.startsWith("{")) {
61 | t = t.substring(1);
62 | }
63 | return t;
64 | }
65 |
66 |
67 |
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/src/com/sun/pdfview/function/postscript/operation/Abs.java:
--------------------------------------------------------------------------------
1 | package com.sun.pdfview.function.postscript.operation;
2 |
3 | import java.util.Stack;
4 |
5 | final class Abs implements PostScriptOperation {
6 | @Override
7 | /**
8 | * num1absnum2
9 | *
10 | * The type of the result is the same as the type of num1,
11 | * unless num1 is the smallest (most negative) integer,
12 | * in which case the result is a real number.