├── .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 | * num1 abs num2

    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.

    13 | * 14 | * errors: stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.abs((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Add.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Add implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 num2 add sum

    9 | * 10 | * If both operands are integers and the result is 11 | * within integer range, the result is an integer; 12 | * otherwise, the result is a real number.

    13 | * 14 | * errors: stackunderflow, typecheck, undefinedresult 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push((Double)environment.pop() + (Double)environment.pop()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/And.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class And implements PostScriptOperation { 6 | @Override 7 | /** 8 | * bool1|int1 bool2|int2 and bool3|int3

    9 | * 10 | * returns the logical conjunction of the operands 11 | * if they are boolean. If the operands are integers, 12 | * and returns the bitwise "and" of their binary 13 | * representations.

    14 | * 15 | * errors: stackunderflow, typecheck 16 | */ 17 | public void eval(Stack environment) { 18 | environment.push((Long)environment.pop() & (Long)environment.pop()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Atan.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Atan implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num den atan angle

    10 | * 11 | * returns the angle (in degress between 12 | * 0 and 360) whose tangent is num divided by den. 13 | * Either num or den may be 0, but not both. The signs 14 | * of num and den determine the quadrant in which the 15 | * result will lie: positive num yeilds a result in the 16 | * positive y plane, while a positive den yeilds a result in 17 | * the positive x plane. The result is a real number.

    18 | * 19 | * errors: stackunderflow, typecheck, undefinedresult 20 | */ 21 | public void eval(Stack environment) { 22 | double den = (Double)environment.pop(); 23 | double num = (Double)environment.pop(); 24 | if (den == 0.0) { 25 | environment.push(90.0); 26 | } else { 27 | environment.push(Math.toDegrees(Math.atan(num / den))); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Bitshift.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Bitshift implements PostScriptOperation { 6 | @Override 7 | /** 8 | * int1 shift bitshift int2

    9 | * 10 | * shifts the binary representation of int1 left by 11 | * shift bits and returns the result. Bits shifted out 12 | * are lost; bits shifted in are 0. If shift is negative, 13 | * a right shift by –shift bits is performed. 14 | * This PostScriptOperation produces an arithmetically correct 15 | * result only for positive values of int1. 16 | * Both int1 and shift must be integers.

    17 | * 18 | * errors: stackunderflow, typecheck 19 | */ 20 | public void eval(Stack environment) { 21 | long shift = (Long)environment.pop(); 22 | long int1 = (Long)environment.pop(); 23 | environment.push(int1 << shift); 24 | } 25 | } -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Ceiling.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Ceiling implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 ceiling num2

    9 | * 10 | * returns the least integer value greater than or equal 11 | * to num1. The type of the result is the same as the type 12 | * of the operand.

    13 | * 14 | * errors: stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.ceil((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Copy.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | final class Copy implements PostScriptOperation { 5 | @Override 6 | /** 7 | * any1 ... anyn n copy any1 ... anyn any1 ... anyn 8 | * array1 array2 copy subarray2
    9 | * string1 string2 copy substring2

    10 | * 11 | * performs two entirely different functions, depending on the 12 | * type of the topmost operand. 13 | * In the first form, where the top element on the operand 14 | * stack is a nonnegative integer n, copy pops n from the 15 | * stack and duplicates the top n elements on the stack 16 | * as shown above. This form of copy operates only on the 17 | * objects themselves, not on the values of composite objects.

    18 | * 19 | * Examples
    20 | * (a) (b) (c) 2 copy Þ (a) (b) (c) (b) (c)
    21 | * (a) (b) (c) 0 copy Þ (a) (b) (c)

    22 | * 23 | * In the other forms, copy copies all the elements of the 24 | * first composite object into the second. The composite 25 | * object operands must be of the same type, except that 26 | * a packed array can be copied into an array (and only into 27 | * an array—copy cannot copy into packed arrays, because 28 | * they are read-only). This form of copy copies the value of 29 | * a composite object. This is quite different from dup and 30 | * other operators that copy only the objects themselves 31 | * (see Section 3.3.1, "Simple and Composite Objects"). 32 | * However, copy performs only one level of copying. 33 | * It does not apply recursively to elements that are 34 | * themselves composite objects; instead, the values 35 | * of those elements become shared. In the case of arrays or 36 | * strings, the length of the second object must be at least as 37 | * great as the first; copy returns the initial subarray or 38 | * substring of the second operand into which the elements 39 | * were copied. Any remaining elements of array2 or 40 | * string2 are unaffected.

    41 | * 42 | * Example:
    43 | * /a1 [1 2 3] def
    44 | * a1 dup length array copy Þ [1 2 3]

    45 | * 46 | * errors: invalidaccess, rangecheck, stackoverflow, 47 | * stackunderflow, typecheck 48 | */ 49 | public void eval(Stack environment) { 50 | Number count = (Number) environment.pop(); 51 | // ???? 52 | Object[] buffer = new Object[count.intValue()]; 53 | for (int i = 0; i < buffer.length; i++) { 54 | buffer[i] = environment.pop(); 55 | } 56 | for (int i = 0; i < buffer.length; i++) { 57 | environment.push(buffer[buffer.length-i-1]); 58 | } 59 | for (int i = 0; i < buffer.length; i++) { 60 | environment.push(buffer[buffer.length-i-1]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Cvi.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | final class Cvi implements PostScriptOperation { 5 | @Override 6 | /** 7 | * num cvi int or string cvi int

    8 | * 9 | * takes an integer, real, or string and produces an 10 | * integer result. If the operand is an integer, cvi 11 | * simply returns it. If the operand is a real number, 12 | * it truncates any fractional part (that is, rounds 13 | * it toward 0) and converts it to an integer. 14 | * If the operand is a string, cvi invokes the equivalent 15 | * of the token operator to interpret the characters 16 | * of the string as a number according to the PostScript 17 | * syntax rules. If that number is a real number, cvi converts 18 | * it to an integer. 19 | * A rangecheck error occurs if a real number is too 20 | * large to convert to an integer.

    21 | * 22 | * errors: invalidaccess, rangecheck, stackunderflow, 23 | * syntaxError, typecheck, 24 | */ 25 | public void eval(Stack environment) { 26 | environment.push(environment.pop()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Cvr.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Cvr implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num cvr real or string cvr real

    9 | * 10 | * (convert to real) takes an integer, real, or string 11 | * object and produces a real result. If the operand 12 | * is an integer, cvr converts it to a real number. 13 | * If the operand is a real number, cvr simply returns it. 14 | * If the operand is a string, cvr invokes the equivalent 15 | * of the token operator to interpret the characters of 16 | * the string as a number according to the PostScript 17 | * syntax rules. If that number is an integer, cvr converts 18 | * it to a real number.

    19 | * 20 | * errors: invalidaccess, limitcheck, stackunderflow, 21 | * syntaxerror, typecheck, undefinedresult 22 | */ 23 | public void eval(Stack environment) { 24 | // YOUR CODE IN THIS SPACE 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Div.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Div implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 num2 div quotient

    9 | * 10 | * divides num1 by num2, producing a result that is 11 | * always a real number even if both operands are integers. 12 | * Use idiv instead if the operands are integers and an 13 | * integer result is desired.

    14 | * 15 | * errors: stackunderflow, typecheck, undefinedresult 16 | */ 17 | public void eval(Stack environment) { 18 | double num2 = (Double)environment.pop(); 19 | double num1 = (Double)environment.pop(); 20 | environment.push(num1 / num2); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Dup.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Dup implements PostScriptOperation { 6 | @Override 7 | /** 8 | * any dup any any

    9 | * 10 | * duplicates the top element on the operand stack. 11 | * dup copies only the object; the value of a composite 12 | * object is not copied but is shared. 13 | * See Section 3.3, "Data Types and Objects."

    14 | * 15 | * errors: stackoverflow, stackunderflow 16 | */ 17 | public void eval(Stack environment) { 18 | Object obj = environment.pop(); 19 | environment.push(obj); 20 | environment.push(obj); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Eq.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Eq implements PostScriptOperation { 7 | @Override 8 | /** 9 | * any1 any2 eq bool

    10 | * 11 | * pops two objects from the operand stack and pushes\ 12 | * true if they are equal, or false if not. 13 | * The definition of equality depends on the types of 14 | * the objects being compared. 15 | * Simple objects are equal if their types and values 16 | * are the same. Strings are equal if their lengths and 17 | * individual elements are equal. 18 | * Other composite objects 19 | * (arrays and dictionaries) are equal only if they share 20 | * the same value. Separate values are considered unequal, 21 | * even if all the components of those values are the 22 | * same. 23 | * This operator performs some type conversions. 24 | * Integers and real numbers can be compared freely: 25 | * an integer and a real number representing the same 26 | * mathematical value are considered equal by eq. 27 | * Strings and names can likewise be compared freely: 28 | * a name defined by some sequence of characters is equal 29 | * to a string whose elements are the same sequence of 30 | * characters. 31 | * The literal/executable and access attributes of 32 | * objects are not considered in comparisons 33 | * between objects.

    34 | * 35 | * errors: invalidaccess, stackunderflow 36 | */ 37 | public void eval(Stack environment) { 38 | environment.push(environment.pop().equals(environment.pop())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Exch.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Exch implements PostScriptOperation { 6 | @Override 7 | public void eval(Stack environment) { // any1 any2 exch any2 any1 - exchange top of stack 8 | Object any1 = environment.pop(); 9 | Object any2 = environment.pop(); 10 | environment.push(any1); 11 | environment.push(any2); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Exp.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Exp implements PostScriptOperation { 6 | @Override 7 | /** 8 | * base exponent exp real

    9 | * 10 | * raises base to the exponent power. The operands may be 11 | * either integers or real numbers. If the exponent has a 12 | * fractional part, the result is meaningful only if the 13 | * base is nonnegative. The result is always a real number.

    14 | * 15 | * errors: stackunderflow, typecheck, undefinedresult 16 | */ 17 | public void eval(Stack environment) { 18 | double exponent = (Double)environment.pop(); 19 | double base = (Double)environment.pop(); 20 | environment.push(Math.pow(exponent, base)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Expression.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.LinkedList; 4 | 5 | 6 | 7 | public class Expression extends LinkedList { 8 | 9 | @Override 10 | public boolean equals(Object obj) { 11 | if (obj instanceof Expression) { 12 | // actually validate the list contents are the same expressions 13 | return true; 14 | } 15 | return false; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/False.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class False implements PostScriptOperation { 7 | @Override 8 | /** 9 | * false false

    10 | * 11 | * pushes a boolean object whose value is false on the 12 | * operand stack. false is not an operator; it is a name in 13 | * systemdict associated with the boolean value false.

    14 | * 15 | * errors: stackoverflow 16 | */ 17 | public void eval(Stack environment) { 18 | environment.push(false); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Floor.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Floor implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 floor num2

    9 | * 10 | * returns the greatest integer value less than or equal 11 | * to num1. The type of the result is the same as the type 12 | * of the operand.

    13 | * 14 | * errors: stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.floor((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Ge.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Ge implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 num2 ge bool

    10 | * 11 | * pops two objects from the operand stack and pushes true 12 | * if the first operand is greater than or equal to the second, 13 | * or false otherwise. If both operands are numbers, 14 | * ge compares their mathematical values. If both operands 15 | * are strings, ge compares them element by element, treating 16 | * the elements as integers in the range 0 to 255, to determine 17 | * whether the first string is lexically greater than or equal 18 | * to the second. If the operands are of other types or one 19 | * is a string and the other is a number, a typecheck 20 | * error occurs.

    21 | * 22 | * errors: invalidaccess, stackunderflow, typecheck 23 | */ 24 | public void eval(Stack environment) { 25 | double num2 = (Double)environment.pop(); 26 | double num1 = (Double)environment.pop(); 27 | environment.push(num1 >= num2); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Gt.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Gt implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 num2 gt bool

    10 | * 11 | * pops two objects from the operand stack and pushes true 12 | * if the first operand is greater than the second, or 13 | * false otherwise. If both operands are numbers, gt compares 14 | * their mathematical values. If both operands are strings, 15 | * gt compares them element by element, treating the elements 16 | * as integers in the range 0 to 255, to determine whether 17 | * the first string is lexically greater than the second. 18 | * If the operands are of other types or one is a string 19 | * and the other is a number, a typecheck error occurs.

    20 | * 21 | * errors: invalidaccess, stackunderflow, typecheck 22 | */ 23 | public void eval(Stack environment) { 24 | double num2 = (Double)environment.pop(); 25 | double num1 = (Double)environment.pop(); 26 | environment.push(num1 > num2); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Idiv.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Idiv implements PostScriptOperation { 6 | @Override 7 | /** 8 | * int1 int2 idiv quotient

    9 | * 10 | * divides int1 by int2 and returns the integer part 11 | * of the quotient, with any fractional part discarded. 12 | * Both operands of idiv must be integers and the result 13 | * is an integer.

    14 | * 15 | * stackunderflow, typecheck, undefinedresult 16 | */ 17 | public void eval(Stack environment) { 18 | long int2 = (Long)environment.pop(); 19 | long int1 = (Long)environment.pop(); 20 | environment.push(int1 / int2); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/If.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class If implements PostScriptOperation { 7 | @Override 8 | /** 9 | * bool {proc} if -

    10 | * 11 | * removes both operands from the stack, then executes proc 12 | * if bool is true. The if operator pushes no results of 13 | * its own on the operand stack, but proc may do so (see 14 | * Section 3.5, "Execution").

    15 | * 16 | * Examples

    17 | * 3 4 lt {(3 is less than 4)} if

    18 | * 19 | * errors: stackunderflow, typecheck 20 | */ 21 | public void eval(Stack environment) { 22 | if ((Boolean)environment.pop()) { 23 | environment.push(environment.pop()); 24 | } else { 25 | environment.pop(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/IfElse.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class IfElse implements PostScriptOperation { 6 | @Override 7 | /** 8 | * bool {expr1} {expr2} ifelse -

    9 | * 10 | * removes all three operands from the stack, then 11 | * executes proc1 if bool is true or proc2 if bool is false. 12 | * The ifelse operator pushes no results of its own on the 13 | * operand stack, but the procedure it executes may do so 14 | * (see Section 3.5, "Execution").

    15 | * 16 | * Examples

    17 | * 4 3 lt {(TruePart)} {(FalsePart)} ifelse
    18 | * results in FalsePart, since 4 is not less than 3

    19 | * 20 | * errors: stackunderflow, typecheck 21 | */ 22 | public void eval(Stack environment) { 23 | // execute expr1 if bool is true, expr2 if false 24 | if ((Boolean)environment.pop()) { 25 | // expression.push(popExpression()); 26 | environment.pop(); 27 | } else { 28 | environment.pop(); 29 | // expression.push(popExpression()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Index.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Index implements PostScriptOperation { 6 | @Override 7 | public void eval(Stack environment) { // anyn ... any0 n index anyn ... any0 anyn 8 | long n = Math.round((Double)environment.pop()); 9 | environment.push(environment.get((int)(environment.size() - n - 1))); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Le.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Le implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 num2 le bool

    9 | * 10 | * pops two objects from the operand stack and pushes true 11 | * if the first operand is less than or equal to the second, 12 | * or false otherwise. If both operands are numbers, le 13 | * compares their mathematical values. If both operands are 14 | * strings, le compares them element by element, treating 15 | * the elements as integers in the range 0 to 255, 16 | * to determine whether the first string is lexically less 17 | * than or equal to the second. If the operands are of other 18 | * types or one is a string and the other is a number, a 19 | * typecheck error occurs.

    20 | * 21 | * errors: invalidaccess, stackunderflow, typecheck 22 | */ 23 | public void eval(Stack environment) { 24 | double num2 = (Double)environment.pop(); 25 | double num1 = (Double)environment.pop(); 26 | environment.push(num1 <= num2); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Ln.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Ln implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num ln real

    10 | * 11 | * returns the natural logarithm (base e) of num. 12 | * The result is a real number.

    13 | * 14 | * errors: rangecheck, stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.log((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Log.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Log implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num log real

    10 | * 11 | * returns the common logarithm (base 10) of num. 12 | * The result is a real number.

    13 | * 14 | * errors: rangecheck, stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.log10((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Lt.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Lt implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 num2 lt bool

    9 | * 10 | * pops two objects from the operand stack and pushes true 11 | * if the first operand is less than the second, or false 12 | * otherwise. If both operands are numbers, lt compares 13 | * their mathematical values. If both operands are strings, 14 | * lt compares them element by element, treating the elements 15 | * as integers in the range 0 to 255, to determine whether 16 | * the first string is lexically less than the second. 17 | * If the operands are of other types or one is a string 18 | * and the other is a number, a typecheck error occurs.

    19 | * 20 | * errors: invalidaccess, stackunderflow, typecheck 21 | */ 22 | public void eval(Stack environment) { 23 | double num2 = (Double)environment.pop(); 24 | double num1 = (Double)environment.pop(); 25 | environment.push(num1 < num2); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Mod.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Mod implements PostScriptOperation { 7 | @Override 8 | /** 9 | * int1 int2 mod remainder

    10 | * 11 | * returns the remainder that results from 12 | * dividing int1 by int2. The sign of the result 13 | * is the same as the sign of the dividend int1. 14 | * Both operands must be integers and the result 15 | * is an integer.

    16 | * 17 | * errors: stackunderflow, typecheck, undefinedresult 18 | */ 19 | public void eval(Stack environment) { 20 | long int2 = (Long)environment.pop(); 21 | long int1 = (Long)environment.pop(); 22 | environment.push(int1 % int2); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Mul.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Mul implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 num2 mul product

    10 | * 11 | * returns the product of num1 and num2. 12 | * If both operands are integers and the result 13 | * is within integer range, the result is an integer; 14 | * otherwise, the result is a real number.

    15 | * 16 | * errors: stackunderflow, typecheck, undefinedresult 17 | */ 18 | public void eval(Stack environment) { 19 | environment.push((Double)environment.pop() * (Double)environment.pop()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Ne.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Ne implements PostScriptOperation { 7 | @Override 8 | /** 9 | * any1 any2 ne bool

    10 | * 11 | * pops two objects from the operand stack and pushes false 12 | * if they are equal, or true if not. What it means for objects 13 | * to be equal is presented in the description of the 14 | * eq operator.

    15 | * 16 | * errors: invalidaccess, stackunderflow 17 | */ 18 | public void eval(Stack environment) { 19 | environment.push(!environment.pop().equals(environment.pop())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Neg.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Neg implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 neg num2

    10 | * 11 | * returns the negative of num1. The type of the result 12 | * is the same as the type of num1 unless num1 is the 13 | * smallest (most negative) integer, in which case the 14 | * result is a real number.

    15 | * 16 | * errors: stackunderflow, typecheck 17 | */ 18 | public void eval(Stack environment) { 19 | environment.push(-(Double)environment.pop()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Not.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Not implements PostScriptOperation { 7 | @Override 8 | /** 9 | * bool1|int1 not bool2|int2

    10 | * 11 | * returns the logical negation of the operand if it is 12 | * boolean. If the operand is an integer, not returns the 13 | * bitwise complement (ones complement) of its binary 14 | * representation.

    15 | * 16 | * errors: stackunderflow, typecheck 17 | */ 18 | public void eval(Stack environment) { 19 | environment.push(~(Long)environment.pop()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Or.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Or implements PostScriptOperation { 7 | @Override 8 | /** 9 | * bool1|int1 bool2|int2 or bool3|int3

    10 | * 11 | * returns the logical disjunction of the operands if they 12 | * are boolean. If the operands are integers, or returns 13 | * the bitwise "inclusive or" of their binary representations.

    14 | * 15 | * errors: stackunderflow, typecheck 16 | */ 17 | public void eval(Stack environment) { 18 | environment.push((Long)environment.pop() | (Long)environment.pop()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Pop.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Pop implements PostScriptOperation { 7 | @Override 8 | public void eval(Stack environment) { // discard top element 9 | environment.pop(); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/PostScriptOperation.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | public interface PostScriptOperation { 6 | 7 | /** 8 | * evaluate the function, popping the stack as needed and pushing results. 9 | */ 10 | public void eval(Stack environment); 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/PushAsNumber.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | 7 | final class PushAsNumber implements PostScriptOperation { 8 | 9 | private String token; 10 | 11 | /************************************************************************* 12 | * Constructor 13 | * @param numberToken 14 | ************************************************************************/ 15 | 16 | public PushAsNumber(String numberToken) { 17 | super(); 18 | this.token = numberToken; 19 | } 20 | 21 | /************************************************************************* 22 | * eval 23 | * @see com.sun.pdfview.function.postscript.operation.PostScriptOperation#eval(java.util.Stack) 24 | ************************************************************************/ 25 | @Override 26 | public void eval(Stack environment) { 27 | try { 28 | double number = Double.parseDouble(this.token); 29 | environment.push(number); 30 | } catch (NumberFormatException e) { 31 | throw new IllegalArgumentException("PS token is not supported "+this.token); 32 | } } 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Roll.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Roll implements PostScriptOperation { 6 | 7 | public static int popAsInteger(Stack st) { 8 | Object e = st.pop(); 9 | if (e instanceof Double) { 10 | double doubleVal = (Double) e; 11 | return (int) doubleVal; 12 | } else { 13 | // error 14 | return 0; 15 | } 16 | } 17 | 18 | @Override 19 | public void eval(Stack environment) { 20 | // anyn-1 ... any0 n j roll any(j-1)mod n ... anyn-1 ... any 21 | // Roll n elements up j times 22 | int j = popAsInteger(environment); 23 | int n = popAsInteger(environment); 24 | Object[] temp = new Object[n]; 25 | 26 | if (environment.size() < n) { 27 | // error, cause by non-standard PS cmd, do nothing for compatibility 28 | return; 29 | } 30 | 31 | if (j >= 0) { 32 | j %= n; 33 | } else { 34 | j = -j % n; 35 | if (j != 0) 36 | j = n - j; 37 | } 38 | for (int i = 0; i < n; ++i) { 39 | temp[i] = environment.pop(); 40 | } 41 | 42 | for (int i = j - 1; i > -1; --i) { 43 | environment.push(temp[i]); 44 | } 45 | for (int i = n - 1; i > j - 1; --i) { 46 | environment.push(temp[i]); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Round.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Round implements PostScriptOperation { 6 | @Override 7 | /** 8 | * num1 round num2

    9 | * 10 | * returns the integer value nearest to num1. 11 | * If num1 is equally close to its two nearest 12 | * integers, round returns the greater of the two. 13 | * The type of the result is the same as 14 | * the type of the operand.

    15 | * 16 | * errors: stackunderflow, typecheck 17 | */ 18 | public void eval(Stack environment) { 19 | environment.push(Math.round((Double)environment.pop())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Sin.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Sin implements PostScriptOperation { 7 | @Override 8 | /** 9 | * angle sin real

    10 | * 11 | * returns the sine of angle, which is interpreted as an 12 | * angle in degrees. The result is a real number.

    13 | * 14 | * errors: stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | double radians = Math.toRadians((Double)environment.pop()); 18 | environment.push(Math.toDegrees(Math.sin(radians))); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Sqrt.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Sqrt implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num sqrt real

    10 | * 11 | * returns the square root of num, which must be a 12 | * nonnegative number. The result is a real number.

    13 | * 14 | * errors: rangecheck, stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push(Math.sqrt((Double)environment.pop())); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Sub.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Sub implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 num2 sub difference

    10 | * 11 | * returns the result of subtracting num2 from num1. 12 | * If both operands are integers and the result is within 13 | * integer range, the result is an integer; otherwise, 14 | * the result is a real number.

    15 | * 16 | * errors: stackunderflow, typecheck, undefinedresult 17 | */ 18 | public void eval(Stack environment) { 19 | double num2 = (Double)environment.pop(); 20 | double num1 = (Double)environment.pop(); 21 | environment.push(num1 - num2); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/True.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class True implements PostScriptOperation { 7 | @Override 8 | /** 9 | * true true

    10 | * 11 | * pushes a boolean object whose value is true on the operand 12 | * stack. true is not an operator; it is a name in systemdict 13 | * associated with the boolean value true.

    14 | * 15 | * errors: stackoverflow 16 | */ 17 | public void eval(Stack environment) { 18 | environment.push(true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Truncate.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | final class Truncate implements PostScriptOperation { 7 | @Override 8 | /** 9 | * num1 truncate num2

    10 | * 11 | * truncates num1 toward 0 by removing its fractional part. 12 | * The type of the result is the same as the type of the 13 | * operand.

    14 | * 15 | * errors: stackunderflow, typecheck 16 | */ 17 | public void eval(Stack environment) { 18 | double num1 = (Double)environment.pop(); 19 | environment.push((((long) num1) - num1)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/function/postscript/operation/Xor.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript.operation; 2 | 3 | import java.util.Stack; 4 | 5 | final class Xor implements PostScriptOperation { 6 | @Override 7 | /** 8 | * bool1|int1 bool2|int2 xor bool3|int3

    9 | * 10 | * returns the logical "exclusive or" of the operands if they 11 | * are boolean. If the operands are integers, xor returns the 12 | * bitwise "exclusive or" of their binary representations.

    13 | * 14 | * errors: stackunderflow, typecheck 15 | */ 16 | public void eval(Stack environment) { 17 | environment.push((Long)environment.pop() ^ (Long)environment.pop()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/pattern/DummyShader.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.pattern; 2 | 3 | import java.awt.Color; 4 | import java.io.IOException; 5 | 6 | import com.sun.pdfview.PDFObject; 7 | import com.sun.pdfview.PDFPaint; 8 | 9 | public class DummyShader extends PDFShader { 10 | 11 | protected DummyShader(int type) { 12 | super(type); 13 | } 14 | 15 | @Override 16 | public void parse(PDFObject shareObj) throws IOException { 17 | 18 | } 19 | 20 | @Override 21 | public PDFPaint getPaint() { 22 | return PDFPaint.getPaint(Color.PINK); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/sun/pdfview/pattern/PDFPattern.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.pattern; 21 | 22 | 23 | import java.awt.geom.AffineTransform; 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | import com.sun.pdfview.PDFObject; 28 | import com.sun.pdfview.PDFPaint; 29 | import com.sun.pdfview.PDFParseException; 30 | 31 | /** 32 | * The abstract superclass of all PDF Pattern types 33 | * 34 | */ 35 | public abstract class PDFPattern { 36 | 37 | /** the pattern type (1 or 2) */ 38 | private int type; 39 | 40 | /** the matrix to transform from pattern space to PDF space */ 41 | private AffineTransform xform; 42 | 43 | /** Creates a new instance of PDFPattern */ 44 | protected PDFPattern(int type) 45 | { 46 | this.type = type; 47 | } 48 | 49 | /** 50 | * Read a pattern from the given pattern stream 51 | */ 52 | public static PDFPattern getPattern(PDFObject patternObj, Map resources) 53 | throws IOException 54 | { 55 | // see if the pattern is already cached 56 | PDFPattern pattern = (PDFPattern) patternObj.getCache(); 57 | if (pattern != null) { 58 | return pattern; 59 | } 60 | 61 | // get the pattern type 62 | int type = patternObj.getDictRef("PatternType").getIntValue(); 63 | 64 | // read the pattern transform matrix 65 | PDFObject matrix = patternObj.getDictRef("Matrix"); 66 | AffineTransform xform = null; 67 | if (matrix == null) { 68 | xform = new AffineTransform(); 69 | } else { 70 | float elts[]= new float[6]; 71 | for (int i = 0; i < elts.length; i++) { 72 | elts[i] = matrix.getAt(i).getFloatValue(); 73 | } 74 | 75 | xform = new AffineTransform(elts); 76 | } 77 | 78 | switch (type) { 79 | case 1: 80 | pattern = new PatternType1(); 81 | break; 82 | case 2: 83 | pattern = new PatternType2(); 84 | break; 85 | default: 86 | throw new PDFParseException("Unknown pattern type " + type); 87 | } 88 | 89 | // set the transform 90 | pattern.setTransform(xform); 91 | 92 | // parse the pattern-specific data 93 | pattern.parse(patternObj, resources); 94 | 95 | // set the cache 96 | patternObj.setCache(pattern); 97 | 98 | return pattern; 99 | } 100 | 101 | /** 102 | * Get the type of this pattern 103 | */ 104 | public int getPatternType() { 105 | return this.type; 106 | } 107 | 108 | /** 109 | * Get the transform associated with this pattern 110 | */ 111 | public AffineTransform getTransform() { 112 | return this.xform; 113 | } 114 | 115 | /** 116 | * Set the transform associated with this pattern 117 | */ 118 | protected void setTransform(AffineTransform xform) { 119 | this.xform = xform; 120 | } 121 | 122 | /** 123 | * Parse the pattern-specific information from the pdf object 124 | * 125 | * @param patternObj the pdfobject with data for this pattern 126 | */ 127 | protected abstract void parse(PDFObject patternObj, Map resources) 128 | throws IOException; 129 | 130 | /** 131 | * Returns paint that represents the selected pattern 132 | * 133 | * @param basePaint the background paint color, or null for none 134 | */ 135 | public abstract PDFPaint getPaint(PDFPaint basePaint); 136 | } -------------------------------------------------------------------------------- /src/com/sun/pdfview/pattern/PatternType2.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.pattern; 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 | 28 | /** 29 | * A type 1 (tiling) pattern 30 | */ 31 | public class PatternType2 extends PDFPattern { 32 | 33 | /** the shader */ 34 | private PDFShader shader; 35 | 36 | /** Creates a new instance of PatternType1 */ 37 | public PatternType2() { 38 | super(2); 39 | } 40 | 41 | /** 42 | * Parse the pattern from the PDFObject 43 | * 44 | * Note the resources passed in are ignored... 45 | */ 46 | @Override 47 | protected void parse(PDFObject patternObj, Map rsrc) throws IOException 48 | { 49 | this.shader = PDFShader.getShader(patternObj.getDictRef("Shading"), rsrc); 50 | } 51 | 52 | /** 53 | * Create a PDFPaint from this pattern and set of components. 54 | * This creates a buffered image of this pattern using 55 | * the given paint, then uses that image to create the correct 56 | * TexturePaint to use in the PDFPaint. 57 | * 58 | * @param basePaint the base paint to use, or null if not needed 59 | */ 60 | @Override 61 | public PDFPaint getPaint(PDFPaint basePaint) { 62 | return shader.getPaint(); 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/myrenderer/MyPdfRenderer.java: -------------------------------------------------------------------------------- 1 | package test.myrenderer; 2 | 3 | import javax.swing.JFrame; 4 | 5 | public class MyPdfRenderer { 6 | 7 | public static String fileName = "D:/25-002.pdf"; // set file path of file to test hee 8 | public static int pageIndex = 1; // the page to be displayed 9 | 10 | public static void main(String[] args) { 11 | JFrame myFrame = new JFrame("PDFRenderer"); 12 | PDFDisplay pdfDisplay = new PDFDisplay(fileName, pageIndex); 13 | myFrame.add(pdfDisplay); 14 | myFrame.setSize(700, 1000); 15 | myFrame.setVisible(true); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/myrenderer/PDFDisplay.java: -------------------------------------------------------------------------------- 1 | package test.myrenderer; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.Graphics2D; 6 | import java.awt.Rectangle; 7 | import java.awt.print.PageFormat; 8 | import java.awt.print.Paper; 9 | import java.io.BufferedInputStream; 10 | import java.io.ByteArrayOutputStream; 11 | import java.io.FileInputStream; 12 | import java.nio.ByteBuffer; 13 | 14 | import javax.swing.JComponent; 15 | 16 | import com.sun.pdfview.PDFFile; 17 | import com.sun.pdfview.PDFPage; 18 | import com.sun.pdfview.PDFRenderer; 19 | 20 | public class PDFDisplay extends JComponent { 21 | private static final long serialVersionUID = 1L; 22 | // byte array containing the PDF file content 23 | private byte[] bytes = null; 24 | private String fileName; 25 | private int pageIndex; 26 | 27 | public PDFDisplay(String fileName, int pageIndex) { 28 | super(); 29 | this.fileName = fileName; 30 | this.pageIndex = pageIndex; 31 | readFile(); 32 | } 33 | 34 | private void readFile() { 35 | try(BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fileName));){ 36 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 37 | int b; 38 | while ((b = inputStream.read()) != -1) { 39 | outputStream.write(b); 40 | } 41 | this.bytes = outputStream.toByteArray(); 42 | }catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | @Override 48 | public void paintComponent(Graphics g) { 49 | try { 50 | PDFFile pdfFile = new PDFFile(ByteBuffer.wrap(this.bytes)); 51 | PDFPage page = pdfFile.getPage(this.pageIndex); 52 | Paper paper = new Paper(); 53 | int formatOrientation = page.getAspectRatio() > 1 ? PageFormat.LANDSCAPE 54 | : PageFormat.PORTRAIT; 55 | if(formatOrientation == PageFormat.LANDSCAPE) { 56 | paper.setSize(page.getHeight(), page.getWidth()); 57 | }else { 58 | paper.setSize(page.getWidth(), page.getHeight()); 59 | } 60 | PageFormat pageFormat = new PageFormat(); 61 | pageFormat.setPaper(paper); 62 | pageFormat.setOrientation(formatOrientation); 63 | 64 | Graphics2D g2d = (Graphics2D)g.create(); 65 | Rectangle imgbounds = new Rectangle(0, 0, (int)pageFormat.getWidth(), 66 | (int)pageFormat.getHeight()); 67 | PDFRenderer renderer = new PDFRenderer(page, g2d, imgbounds, null, Color.WHITE); 68 | try { 69 | page.waitForFinish(); 70 | } 71 | catch (InterruptedException e) { 72 | // some exception handling 73 | } 74 | renderer.run(); 75 | }catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/io/BoundedRangeInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/io/BoundedRangeInputStream.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/io/ByteArrayImageInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/io/ByteArrayImageInputStream.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/media/jpeg/Generic_CMYK_Profile.icc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/media/jpeg/Generic_CMYK_Profile.icc -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/media/jpeg/JFIFInputStream$Segment.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/media/jpeg/JFIFInputStream$Segment.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/media/jpeg/JFIFInputStream.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/media/jpeg/JFIFInputStream.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/media/jpeg/JPEGImageIO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/media/jpeg/JPEGImageIO.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/BasicBrowserUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/BasicBrowserUI.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/BrowserPreviewRenderer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/BrowserPreviewRenderer.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/BrowserUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/BrowserUI.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$1.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$2.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer$3.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/DefaultBrowserCellRenderer.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$1.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnFocusListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnFocusListener.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnKeyListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnKeyListener.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnListModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnListModel.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnMouseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnMouseListener.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnSelectionModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$ColumnSelectionModel.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$SelectionModeUpdater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$SelectionModeUpdater.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser$TreeSelectionUpdater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser$TreeSelectionUpdater.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowser.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowserViewport$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowserViewport$1.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/JBrowserViewport.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/JBrowserViewport.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/images/Browser.disclosureIcons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/images/Browser.disclosureIcons.png -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/util/Images.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/util/Images.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/quaqua/util/SizeConstrainedPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/quaqua/util/SizeConstrainedPanel.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/util/Applets.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/util/Applets.class -------------------------------------------------------------------------------- /stdclasses/ch/randelshofer/util/ArrayUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/ch/randelshofer/util/ArrayUtil.class -------------------------------------------------------------------------------- /stdclasses/unpublic/jbig2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/katjas/PDFrenderer/dfa74e498eeb1d3a623a70bfb8e0a4c8638ae538/stdclasses/unpublic/jbig2.jar -------------------------------------------------------------------------------- /test/src/com/sun/pdfview/function/postscript/PostScriptOPTest.java: -------------------------------------------------------------------------------- 1 | package com.sun.pdfview.function.postscript; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Iterator; 6 | import java.util.List; 7 | import java.util.Stack; 8 | 9 | import org.junit.Test; 10 | 11 | import com.sun.pdfview.function.postscript.operation.OperationSet; 12 | import com.sun.pdfview.function.postscript.operation.PostScriptOperation; 13 | 14 | public class PostScriptOPTest { 15 | 16 | public static Stack parse(String text) { 17 | Stack stack = new Stack(); 18 | PostScriptParser p = new PostScriptParser(); 19 | List tokens = p.parse(text); 20 | for (Iterator iterator = tokens.iterator(); iterator.hasNext(); ) { 21 | String token = iterator.next(); 22 | PostScriptOperation op = OperationSet.getInstance().getOperation(token); 23 | op.eval(stack); 24 | } 25 | return stack; 26 | } 27 | 28 | 29 | @Test 30 | public void testRoll() { 31 | Stack stack = parse("1 2 3 4 5 5 -2 roll"); 32 | assertEquals(2, ((Number)stack.pop()).intValue()); 33 | assertEquals(1, ((Number)stack.pop()).intValue()); 34 | assertEquals(5, ((Number)stack.pop()).intValue()); 35 | assertEquals(4, ((Number)stack.pop()).intValue()); 36 | assertEquals(3, ((Number)stack.pop()).intValue()); 37 | assertTrue(stack.isEmpty()); 38 | 39 | stack = parse("1 2 3 4 5 5 2 roll"); 40 | assertEquals(3, ((Number)stack.pop()).intValue()); 41 | assertEquals(2, ((Number)stack.pop()).intValue()); 42 | assertEquals(1, ((Number)stack.pop()).intValue()); 43 | assertEquals(5, ((Number)stack.pop()).intValue()); 44 | assertEquals(4, ((Number)stack.pop()).intValue()); 45 | assertTrue(stack.isEmpty()); 46 | 47 | stack = parse("1 2 3 4 5 5 7 roll"); 48 | assertEquals(3, ((Number)stack.pop()).intValue()); 49 | assertEquals(2, ((Number)stack.pop()).intValue()); 50 | assertEquals(1, ((Number)stack.pop()).intValue()); 51 | assertEquals(5, ((Number)stack.pop()).intValue()); 52 | assertEquals(4, ((Number)stack.pop()).intValue()); 53 | assertTrue(stack.isEmpty()); 54 | 55 | stack = parse("1 2 3 4 5 5 0 roll"); 56 | assertEquals(5, ((Number)stack.pop()).intValue()); 57 | assertEquals(4, ((Number)stack.pop()).intValue()); 58 | assertEquals(3, ((Number)stack.pop()).intValue()); 59 | assertEquals(2, ((Number)stack.pop()).intValue()); 60 | assertEquals(1, ((Number)stack.pop()).intValue()); 61 | assertTrue(stack.isEmpty()); 62 | } 63 | 64 | @Test 65 | public void testIndex() { 66 | Stack stack = parse("1 0 index"); 67 | assertEquals(1, ((Number)stack.pop()).intValue()); 68 | assertEquals(1, ((Number)stack.pop()).intValue()); 69 | assertTrue(stack.isEmpty()); 70 | 71 | stack = parse("1 2 3 1 index"); 72 | assertEquals(2, ((Number)stack.pop()).intValue()); 73 | assertEquals(3, ((Number)stack.pop()).intValue()); 74 | } 75 | 76 | @Test 77 | public void testExch() { 78 | Stack stack = parse("1 0 exch"); 79 | assertEquals(1, ((Number)stack.pop()).intValue()); 80 | assertEquals(0, ((Number)stack.pop()).intValue()); 81 | assertTrue(stack.isEmpty()); 82 | 83 | stack = parse("1 3.1 0 exch"); 84 | assertEquals(3.1, ((Number)stack.pop()).doubleValue(), 1e-16); 85 | assertEquals(0, ((Number)stack.pop()).intValue()); 86 | assertEquals(1, ((Number)stack.pop()).intValue()); 87 | assertTrue(stack.isEmpty()); 88 | } 89 | 90 | @Test 91 | public void testSub() { 92 | Stack stack = parse("1 2 sub"); 93 | assertEquals(-1, ((Number)stack.pop()).intValue()); 94 | assertTrue(stack.isEmpty()); 95 | 96 | stack = parse("6.3 2 sub"); 97 | assertEquals(4.3, ((Number)stack.pop()).doubleValue(), 1e-16); 98 | assertTrue(stack.isEmpty()); 99 | } 100 | 101 | @Test 102 | public void testDup() { 103 | Stack stack = parse("1 2 dup"); 104 | assertEquals(2, ((Number)stack.pop()).intValue()); 105 | assertEquals(2, ((Number)stack.pop()).intValue()); 106 | assertEquals(1, ((Number)stack.pop()).intValue()); 107 | assertTrue(stack.isEmpty()); 108 | } 109 | 110 | } 111 | --------------------------------------------------------------------------------