├── src
├── test
│ ├── resources
│ │ └── org
│ │ │ └── verapdf
│ │ │ ├── cos
│ │ │ └── filters
│ │ │ │ ├── lzw
│ │ │ │ └── validDocument.pdf
│ │ │ ├── pd
│ │ │ └── font
│ │ │ │ ├── opentype
│ │ │ │ └── ShortStack-Regular.otf
│ │ │ │ └── truetype
│ │ │ │ ├── SourceCodePro-Bold.ttf
│ │ │ │ └── LiberationSans-Regular.ttf
│ │ │ └── parser
│ │ │ └── xref
│ └── java
│ │ └── org
│ │ └── verapdf
│ │ ├── parser
│ │ └── PDFParserTest.java
│ │ ├── cos
│ │ ├── filters
│ │ │ ├── COSFilterLZWDecodeTest.java
│ │ │ └── COSFilterFlateEncodeTest.java
│ │ └── COSStreamTest.java
│ │ ├── pd
│ │ ├── function
│ │ │ └── PDFunctionTestHelper.java
│ │ └── font
│ │ │ ├── opentype
│ │ │ └── OpenTypeCFFTest.java
│ │ │ └── truetype
│ │ │ └── TrueTypeParserTest.java
│ │ └── io
│ │ └── SeekableInputStreamTest.java
└── main
│ ├── java
│ └── org
│ │ └── verapdf
│ │ ├── as
│ │ ├── warnings
│ │ │ └── StringWarnings.java
│ │ ├── io
│ │ │ ├── ASOutputStream.java
│ │ │ └── ASInputStreamWrapper.java
│ │ ├── filters
│ │ │ ├── IASFilterFactory.java
│ │ │ └── ASOutFilter.java
│ │ └── exceptions
│ │ │ └── StringExceptions.java
│ │ ├── cos
│ │ ├── COSNumber.java
│ │ ├── xref
│ │ │ ├── COSXRefRange.java
│ │ │ ├── COSXRefTable.java
│ │ │ └── COSXRefInfo.java
│ │ ├── COSObjType.java
│ │ ├── visitor
│ │ │ ├── IVisitor.java
│ │ │ ├── ICOSVisitor.java
│ │ │ └── IndirectWriter.java
│ │ ├── COSBody.java
│ │ ├── COSNull.java
│ │ ├── COSBasePair.java
│ │ ├── COSKey.java
│ │ └── COSEmbeddedFileDict.java
│ │ ├── pd
│ │ ├── PDContentStream.java
│ │ ├── PDAppearanceStream.java
│ │ ├── images
│ │ │ └── PDXPostScript.java
│ │ ├── PD3DStream.java
│ │ ├── PDPageContentStream.java
│ │ ├── actions
│ │ │ ├── PDWidgetAdditionalActions.java
│ │ │ ├── PDPageAdditionalActions.java
│ │ │ ├── PDFormFieldActions.java
│ │ │ ├── PDCatalogAdditionalActions.java
│ │ │ ├── PDAnnotationAdditionalActions.java
│ │ │ ├── PDMediaClip.java
│ │ │ └── PDAbstractAdditionalActions.java
│ │ ├── PDResource.java
│ │ ├── colors
│ │ │ ├── PDColorSpace.java
│ │ │ ├── PDDeviceGray.java
│ │ │ ├── PDDeviceCMYK.java
│ │ │ ├── PDCalGray.java
│ │ │ ├── PDDeviceRGB.java
│ │ │ ├── PDSeparation.java
│ │ │ └── PDLab.java
│ │ ├── font
│ │ │ ├── cmap
│ │ │ │ ├── CIDMappable.java
│ │ │ │ ├── SingleCIDMapping.java
│ │ │ │ ├── NotDefInterval.java
│ │ │ │ ├── CMapBaseParser.java
│ │ │ │ ├── IdentityCMap.java
│ │ │ │ ├── CIDInterval.java
│ │ │ │ └── CMapFactory.java
│ │ │ ├── truetype
│ │ │ │ ├── PlatformEncodingPair.java
│ │ │ │ ├── TrueTypeMaxpTable.java
│ │ │ │ ├── TrueTypeTable.java
│ │ │ │ ├── TrueTypeHeadTable.java
│ │ │ │ ├── TrueTypeHmtxTable.java
│ │ │ │ └── TrueTypeHheaTable.java
│ │ │ ├── CIDWArrayRange.java
│ │ │ ├── PDCIDSystemInfo.java
│ │ │ ├── type1
│ │ │ │ └── Type1StringConstants.java
│ │ │ ├── type3
│ │ │ │ └── PDType3CharProc.java
│ │ │ ├── CFFNumber.java
│ │ │ └── cff
│ │ │ │ └── CFFIndex.java
│ │ ├── structure
│ │ │ ├── PDNameSpaceRoleMapping.java
│ │ │ ├── PDOBJRDictionary.java
│ │ │ ├── PDStructTreeNode.java
│ │ │ ├── PDMCRDictionary.java
│ │ │ ├── PDStructTreeRoot.java
│ │ │ └── StructureElementAccessObject.java
│ │ ├── PDOutlineDictionary.java
│ │ ├── annotations
│ │ │ └── PDWidgetAnnotation.java
│ │ ├── encryption
│ │ │ └── PDCryptFilter.java
│ │ ├── PDGroup.java
│ │ ├── form
│ │ │ ├── PDAcroForm.java
│ │ │ └── PDSignatureField.java
│ │ ├── PDNavigationNode.java
│ │ ├── PDHalftone.java
│ │ ├── PDNamesDictionary.java
│ │ ├── PDAppearanceEntry.java
│ │ ├── PDPageTreeNode.java
│ │ ├── patterns
│ │ │ ├── PDShadingPattern.java
│ │ │ ├── PDShading.java
│ │ │ └── PDPattern.java
│ │ └── PDPageTree.java
│ │ ├── exceptions
│ │ ├── LoopedException.java
│ │ ├── VeraPDFParserException.java
│ │ └── InvalidPasswordException.java
│ │ ├── parser
│ │ ├── postscript
│ │ │ ├── PostScriptException.java
│ │ │ ├── PSStackMark.java
│ │ │ ├── PSLiteralObject.java
│ │ │ ├── PSParser.java
│ │ │ └── PSProcedure.java
│ │ ├── BaseParserInputStream.java
│ │ └── NotSeekableCOSParser.java
│ │ ├── tools
│ │ ├── resource
│ │ │ ├── ASFileStreamCloser.java
│ │ │ └── FileResourceHandler.java
│ │ └── IntReference.java
│ │ ├── operator
│ │ ├── InlineImageOperator.java
│ │ └── Operator.java
│ │ └── io
│ │ └── IReader.java
│ └── resources
│ └── font
│ └── stdmetrics
│ └── MustRead.html
├── .gitignore
├── license
└── template
│ └── license.txt
├── .github
└── workflows
│ └── test-pr.yml
└── README.md
/src/test/resources/org/verapdf/cos/filters/lzw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/veraPDF/veraPDF-parser/HEAD/src/test/resources/org/verapdf/cos/filters/lzw
--------------------------------------------------------------------------------
/src/test/resources/org/verapdf/cos/filters/validDocument.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/veraPDF/veraPDF-parser/HEAD/src/test/resources/org/verapdf/cos/filters/validDocument.pdf
--------------------------------------------------------------------------------
/src/test/resources/org/verapdf/pd/font/opentype/ShortStack-Regular.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/veraPDF/veraPDF-parser/HEAD/src/test/resources/org/verapdf/pd/font/opentype/ShortStack-Regular.otf
--------------------------------------------------------------------------------
/src/test/resources/org/verapdf/pd/font/truetype/SourceCodePro-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/veraPDF/veraPDF-parser/HEAD/src/test/resources/org/verapdf/pd/font/truetype/SourceCodePro-Bold.ttf
--------------------------------------------------------------------------------
/src/test/resources/org/verapdf/pd/font/truetype/LiberationSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/veraPDF/veraPDF-parser/HEAD/src/test/resources/org/verapdf/pd/font/truetype/LiberationSans-Regular.ttf
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/warnings/StringWarnings.java:
--------------------------------------------------------------------------------
1 | package org.verapdf.as.warnings;
2 |
3 | public class StringWarnings {
4 | public static final String NOT_ASCII_LETTER = "Text string language escape sequence contains not ASCII letter";
5 | public static final String INVALID_LANGUAGE_ESCAPE_SEQUENCE_LENGTH = "Text string language escape sequence has invalid length";
6 | public static final String NOT_SUPPORTED_UTF16LE_ENCODING = "String object uses encoding UTF16-LE not supported by PDF";
7 | }
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 | **/target/**
14 | /.idea/**
15 | *.iml
16 |
17 | # Ignore Mac DS_Store files
18 | .DS_Store
19 |
20 | # Eclipse artefacts
21 | **/.project
22 | **/.settings
23 | **/.classpath
24 | **/bin
25 |
26 | # Maven artefacts
27 | **/pom.xml.versionsBackup
28 | /target/
29 |
--------------------------------------------------------------------------------
/src/test/resources/org/verapdf/parser/xref:
--------------------------------------------------------------------------------
1 |
2 | 1 20
3 | 0000000000 65535 f
4 | 0000000015 00000 n
5 | 0000000119 00000 n
6 | 0000000176 00000 n
7 | 0000000247 00000 n
8 | 0000001199 00000 n
9 | 0000001360 00000 n
10 | 0000001479 00000 n
11 | 0000001690 00000 n
12 | 0000001842 00000 n
13 | 0000001920 00000 n
14 | 0000001993 00000 n
15 | 0000002207 00000 n
16 | 0000002587 00000 n
17 | 0000002944 00000 n
18 | 0000003025 00000 n
19 | 0000003118 00000 n
20 | 0000003333 00000 n
21 | 0000003416 00000 n
22 | 0000015254 00000 n
23 |
--------------------------------------------------------------------------------
/license/template/license.txt:
--------------------------------------------------------------------------------
1 | This file is part of ${project.name}, a module of the veraPDF project.
2 | Copyright (c) ${project.inceptionYear}-${current.year}, ${owner} <${email}>
3 | All rights reserved.
4 |
5 | ${project.name} is free software: you can redistribute it and/or modify
6 | it under the terms of either:
7 |
8 | The GNU General public license GPLv3+.
9 | You should have received a copy of the GNU General Public License
10 | along with ${project.name} as the LICENSE.GPL file in the root of the source
11 | tree. If not, see http://www.gnu.org/licenses/ or
12 | https://www.gnu.org/licenses/gpl-3.0.en.html.
13 |
14 | The Mozilla Public License MPLv2+.
15 | You should have received a copy of the Mozilla Public License along with
16 | ${project.name} as the LICENSE.MPL file in the root of the source tree.
17 | If a copy of the MPL was not distributed with this file, you can obtain one at
18 | http://mozilla.org/MPL/2.0/.
19 |
--------------------------------------------------------------------------------
/src/main/resources/font/stdmetrics/MustRead.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Core 14 AFM Files - ReadMe
7 |
8 |
9 |
10 | or
11 |
12 |
13 |
14 | This file and the 14 PostScript(R) AFM files it accompanies may be used, copied, and distributed for any purpose and without charge, with or without modification, provided that all copyright notices are retained; that the AFM files are not distributed without this file; that all modifications to this file or any of the AFM files are prominently noted in the modified file(s); and that this paragraph is not modified. Adobe Systems has no responsibility or obligation to support the use of the AFM files. Col
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSNumber.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | /**
24 | * @author Timur Kamalov
25 | */
26 | public abstract class COSNumber extends COSDirect {
27 |
28 | public COSNumber() {
29 | super();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDContentStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public interface PDContentStream {
29 |
30 | COSObject getContents();
31 |
32 | void setContents(final COSObject contents);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDAppearanceStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.cos.COSObject;
24 | import org.verapdf.pd.images.PDXForm;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDAppearanceStream extends PDXForm {
30 |
31 | public PDAppearanceStream(COSObject obj) {
32 | super(obj);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/images/PDXPostScript.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.images;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDXPostScript extends PDXObject {
30 | protected PDXPostScript(COSObject obj) {
31 | super(obj);
32 | }
33 |
34 | @Override
35 | public ASAtom getType() {
36 | return ASAtom.PS;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/io/ASOutputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.as.io;
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public interface ASOutputStream {
29 |
30 | long write(final byte[] buffer) throws IOException;
31 |
32 | long write(final byte[] buffer, int offset, int size) throws IOException;
33 |
34 | long write(ASInputStream stream) throws IOException;
35 |
36 | void close() throws IOException;
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PD3DStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maxim Plushchov
28 | */
29 | public class PD3DStream extends PDObject {
30 |
31 | public PD3DStream(COSObject obj) {
32 | super(obj);
33 | }
34 |
35 | public String getSubtype() {
36 | return getObject().getNameKeyStringValue(ASAtom.SUBTYPE);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/exceptions/LoopedException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.exceptions;
22 |
23 | /**
24 | * @author Maksim Bezrukov
25 | */
26 | public class LoopedException extends RuntimeException {
27 |
28 | public LoopedException() {
29 | }
30 |
31 | public LoopedException(String message) {
32 | super(message);
33 | }
34 |
35 | public LoopedException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 |
39 | public LoopedException(Throwable cause) {
40 | super(cause);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/xref/COSXRefRange.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.xref;
22 |
23 | /**
24 | * @author Timur Kamalov
25 | */
26 | public class COSXRefRange {
27 |
28 | public int start;
29 | public int count;
30 |
31 | public COSXRefRange() {
32 | }
33 |
34 | public COSXRefRange(final int start) {
35 | this(start, 1);
36 | }
37 |
38 | public COSXRefRange(final int start, final int count) {
39 | this.start = start;
40 | this.count = count;
41 | }
42 |
43 | public int next() {
44 | return this.start + this.count;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/exceptions/VeraPDFParserException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.exceptions;
22 |
23 | /**
24 | * @author Irina Mavrina
25 | */
26 | public class VeraPDFParserException extends RuntimeException {
27 |
28 | public VeraPDFParserException() {
29 | }
30 |
31 | public VeraPDFParserException(String message) {
32 | super(message);
33 | }
34 |
35 | public VeraPDFParserException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 |
39 | public VeraPDFParserException(Throwable cause) {
40 | super(cause);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/postscript/PostScriptException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser.postscript;
22 |
23 | /**
24 | * Exception that occurs during PostScript program parsing.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | public class PostScriptException extends Exception {
29 |
30 | public PostScriptException() {
31 | }
32 |
33 | public PostScriptException(String message) {
34 | super(message);
35 | }
36 |
37 | public PostScriptException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDPageContentStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public class PDPageContentStream extends PDObject implements PDContentStream {
29 |
30 | public PDPageContentStream(COSObject contents) {
31 | super(contents);
32 | }
33 |
34 | @Override
35 | public COSObject getContents() {
36 | return super.getObject();
37 | }
38 |
39 | @Override
40 | public void setContents(final COSObject contents) {
41 | super.setObject(contents);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDWidgetAdditionalActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * @author Maxim Plushchov
27 | */
28 | public class PDWidgetAdditionalActions extends PDAnnotationAdditionalActions {
29 |
30 | private static final String WIDGET_ANNOT_PARENT_TYPE = "WidgetAnnot";
31 |
32 | public PDWidgetAdditionalActions(COSObject obj) {
33 | super(obj);
34 | }
35 |
36 | @Override
37 | public String getParentType() {
38 | return WIDGET_ANNOT_PARENT_TYPE;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDResource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * @author Maksim Bezrukov
27 | */
28 | public class PDResource extends PDObject {
29 |
30 | private boolean isInherited = false;
31 |
32 | public PDResource() {
33 | }
34 |
35 | public PDResource(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | public boolean isInherited() {
40 | return isInherited;
41 | }
42 |
43 | public void setInherited(boolean inherited) {
44 | isInherited = inherited;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/postscript/PSStackMark.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser.postscript;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * Object represents operand stack mark. It is used for performing stack
27 | * operators.
28 | *
29 | * @author Sergey Shemyakov
30 | */
31 | public class PSStackMark extends COSObject {
32 |
33 | private static final PSStackMark STACK_MARK_INSTANCE = new PSStackMark();
34 |
35 | private PSStackMark() {
36 | }
37 |
38 | public static PSStackMark getInstance() {
39 | return STACK_MARK_INSTANCE;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/exceptions/InvalidPasswordException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.exceptions;
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * @author Maksim Bezrukov
27 | */
28 | public class InvalidPasswordException extends IOException {
29 |
30 | public InvalidPasswordException() {
31 | }
32 |
33 | public InvalidPasswordException(String message) {
34 | super(message);
35 | }
36 |
37 | public InvalidPasswordException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | public InvalidPasswordException(Throwable cause) {
42 | super(cause);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSObjType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | /**
24 | * @author Timur Kamalov
25 | */
26 | public enum COSObjType {
27 |
28 | COS_UNDEFINED,
29 | COS_NULL,
30 | COS_INTEGER,
31 | COS_REAL,
32 | COS_BOOLEAN,
33 | COS_NAME,
34 | COS_STRING,
35 | COS_DICT,
36 | COS_ARRAY,
37 | COS_STREAM;
38 |
39 | public boolean isNumber() {
40 | return this == COS_INTEGER || this == COS_REAL;
41 | }
42 |
43 | public boolean isBoolean() {
44 | return this == COS_BOOLEAN;
45 | }
46 |
47 | public boolean isDictionaryBased() {
48 | return this == COS_DICT || this == COS_STREAM;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDColorSpace.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.pd.PDResource;
26 |
27 | /**
28 | * @author Maksim Bezrukov
29 | */
30 | public abstract class PDColorSpace extends PDResource {
31 |
32 | protected PDColorSpace() {
33 | }
34 |
35 | protected PDColorSpace(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | public abstract int getNumberOfComponents();
40 |
41 | public abstract ASAtom getType();
42 |
43 | public abstract double[] toRGB(double[] value);
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/CIDMappable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | /**
24 | * Interface represents object that makes mapping of character code into CID.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | interface CIDMappable {
29 |
30 | /**
31 | * Gets CID of given character.
32 | *
33 | * @param character is code of given character.
34 | * @return CID of given character or -1 if no mapping available.
35 | */
36 | int getCID(int character);
37 |
38 | /**
39 | * @return maximal CID that is present in this mapping.
40 | */
41 | int getMaxCID();
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/PDNameSpaceRoleMapping.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.pd.PDObject;
26 |
27 | /**
28 | * @author Sergey Shemyakov
29 | */
30 | public class PDNameSpaceRoleMapping extends PDObject {
31 |
32 | public PDNameSpaceRoleMapping(COSObject obj) {
33 | super(obj);
34 | }
35 |
36 | public StructureType getEquivalentType(ASAtom type) {
37 | if (knownKey(type)) {
38 | return StructureType.createStructureType(getKey(type));
39 | }
40 | return null;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/PDOBJRDictionary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSKey;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDObject;
27 |
28 |
29 | public class PDOBJRDictionary extends PDObject {
30 |
31 | public PDOBJRDictionary(COSObject cosObject) {
32 | super(cosObject);
33 | }
34 |
35 | public COSKey getPageObjectKey() {
36 | COSObject object = getObject().getKey(ASAtom.PG);
37 | return object != null ? object.getKey() : null;
38 | }
39 |
40 | public COSObject getReferencedObject() {
41 | return getObject().getKey(ASAtom.OBJ);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/BaseParserInputStream.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser;
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * @author Maxim Plushchov
27 | */
28 | public interface BaseParserInputStream {
29 |
30 | int read() throws IOException;
31 |
32 | int read(byte[] buffer) throws IOException;
33 |
34 | byte readByte() throws IOException;
35 |
36 | void unread() throws IOException;
37 |
38 | void unread(int i) throws IOException;
39 |
40 | int peek() throws IOException;
41 |
42 | int skip(int size) throws IOException;
43 |
44 | void close() throws IOException;
45 |
46 | boolean isEOF() throws IOException;
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/PlatformEncodingPair.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | /**
24 | * Represents pair of platform and encoding values for cmap table.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | class PlatformEncodingPair {
29 |
30 | private final int platformID;
31 | private final int encodingID;
32 |
33 | PlatformEncodingPair(int platformID, int encodingID) {
34 | this.platformID = platformID;
35 | this.encodingID = encodingID;
36 | }
37 |
38 | int getPlatformID() {
39 | return platformID;
40 | }
41 |
42 | int getEncodingID() {
43 | return encodingID;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/visitor/IVisitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.visitor;
22 |
23 | import org.verapdf.cos.*;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public interface IVisitor {
29 |
30 | void visitFromBoolean(final COSBoolean obj);
31 | void visitFromInteger(final COSInteger obj);
32 | void visitFromReal(final COSReal obj);
33 | void visitFromString(final COSString obj);
34 | void visitFromName(final COSName obj);
35 | void visitFromArray(final COSArray obj);
36 | void visitFromDictionary(final COSDictionary obj);
37 | void visitFromStream(final COSStream obj);
38 | void visitFromNull(final COSNull obj);
39 | void visitFromIndirect(final COSIndirect obj);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/PDStructTreeNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.cos.COSObject;
24 | import org.verapdf.pd.PDObject;
25 | import org.verapdf.tools.TaggedPDFHelper;
26 |
27 | import java.util.List;
28 |
29 | /**
30 | * @author Maksim Bezrukov
31 | */
32 | public class PDStructTreeNode extends PDObject {
33 |
34 | protected PDStructTreeNode(COSObject obj) {
35 | super(obj);
36 | }
37 |
38 | public List getStructChildren() {
39 | return TaggedPDFHelper.getStructNodeStructChildren(getObject());
40 | }
41 |
42 | public List getChildren() {
43 | return TaggedPDFHelper.getStructNodeChildren(getObject());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/SingleCIDMapping.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | /**
24 | * Class represents single character mapping.
25 | * @author Sergey Shemyakov
26 | */
27 | class SingleCIDMapping implements CIDMappable {
28 |
29 | private final int from;
30 | private final int to;
31 |
32 | SingleCIDMapping(int from, int to) {
33 | this.from = from;
34 | this.to = to;
35 | }
36 |
37 | @Override
38 | public int getCID(int character) {
39 | if (character != from) {
40 | return -1;
41 | }
42 | return to;
43 | }
44 |
45 | @Override
46 | public int getMaxCID() {
47 | return to;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/NotDefInterval.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | /**
24 | * Class represents notdef interval. All chars from this interval are mapped
25 | * into one specified notdef value.
26 | *
27 | * @author Sergey Shemyakov
28 | */
29 | class NotDefInterval extends CIDInterval {
30 |
31 | NotDefInterval(int intervalStart, int intervalEnd, int startingCID) {
32 | super(intervalStart, intervalEnd, startingCID);
33 | }
34 |
35 | /**
36 | * {@inheritDoc}
37 | */
38 | @Override
39 | public int getCID(int character) {
40 | if (!contains(character)) {
41 | return -1;
42 | }
43 | return startingCID;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDPageAdditionalActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class PDPageAdditionalActions extends PDAbstractAdditionalActions {
30 |
31 | private static final String PAGE_PARENT_TYPE = "Page";
32 |
33 | private static final ASAtom[] actionNames = {ASAtom.O, ASAtom.C};
34 |
35 | public PDPageAdditionalActions(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | @Override
40 | public ASAtom[] getActionNames() {
41 | return actionNames;
42 | }
43 |
44 | @Override
45 | public String getParentType() {
46 | return PAGE_PARENT_TYPE;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/CMapBaseParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | import org.verapdf.as.io.ASInputStream;
24 | import org.verapdf.parser.BaseParser;
25 | import org.verapdf.parser.NotSeekableBaseParser;
26 |
27 | import java.io.IOException;
28 |
29 | /**
30 | * This class parses CMap files and constructs CMap objects.
31 | *
32 | * @author Sergey Shemyakov
33 | */
34 | public class CMapBaseParser extends NotSeekableBaseParser {
35 |
36 | public CMapBaseParser(ASInputStream stream) throws IOException {
37 | super(stream, true);
38 | }
39 |
40 | @Override
41 | protected boolean isEndOfComment(byte ch) {
42 | return BaseParser.isCR(ch) || BaseParser.isFF(ch);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDFormFieldActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDFormFieldActions extends PDAbstractAdditionalActions {
30 |
31 | private static final String FORM_FIELD_PARENT_TYPE = "FormField";
32 |
33 | private static final ASAtom[] actionNames = {ASAtom.K, ASAtom.F, ASAtom.V, ASAtom.C};
34 |
35 | public PDFormFieldActions(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | @Override
40 | public ASAtom[] getActionNames() {
41 | return actionNames;
42 | }
43 |
44 | @Override
45 | public String getParentType() {
46 | return FORM_FIELD_PARENT_TYPE;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDOutlineDictionary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDOutlineDictionary extends PDObject {
30 |
31 | public PDOutlineDictionary(COSObject obj) {
32 | super(obj);
33 | }
34 |
35 | public PDOutlineItem getFirst() {
36 | return getOutlineItem(ASAtom.FIRST);
37 | }
38 |
39 | public PDOutlineItem getLast() {
40 | return getOutlineItem(ASAtom.LAST);
41 | }
42 |
43 | protected PDOutlineItem getOutlineItem(ASAtom key) {
44 | COSObject first = getKey(key);
45 | if (first != null && first.getType().isDictionaryBased()) {
46 | return new PDOutlineItem(first);
47 | }
48 | return null;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDCatalogAdditionalActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class PDCatalogAdditionalActions extends PDAbstractAdditionalActions {
30 |
31 | private static final String CATALOG_PARENT_TYPE = "Catalog";
32 |
33 | private static final ASAtom[] actionNames = {ASAtom.WC, ASAtom.WS, ASAtom.DS, ASAtom.WP, ASAtom.DP};
34 |
35 | public PDCatalogAdditionalActions(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | @Override
40 | public ASAtom[] getActionNames() {
41 | return actionNames;
42 | }
43 |
44 | @Override
45 | public String getParentType() {
46 | return CATALOG_PARENT_TYPE;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/visitor/ICOSVisitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.visitor;
22 |
23 | import org.verapdf.cos.*;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public interface ICOSVisitor {
29 |
30 | Object visitFromBoolean(final COSBoolean obj);
31 | Object visitFromInteger(final COSInteger obj);
32 | Object visitFromReal(final COSReal obj);
33 | Object visitFromString(final COSString obj);
34 | Object visitFromName(final COSName obj);
35 | Object visitFromArray(final COSArray obj);
36 | Object visitFromDictionary(final COSDictionary obj);
37 | Object visitFromDocument(final COSDocument obj);
38 | Object visitFromStream(final COSStream obj);
39 | Object visitFromNull(final COSNull obj);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/tools/resource/ASFileStreamCloser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.tools.resource;
22 |
23 | import java.io.Closeable;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Class-wrapper around closeable streams that allows only to close streams.
28 | *
29 | * @author Sergey Shemyakov
30 | */
31 | public class ASFileStreamCloser implements Closeable {
32 |
33 | private final Closeable stream;
34 |
35 | /**
36 | * Sets inner stream.
37 | */
38 | public ASFileStreamCloser(Closeable stream) {
39 | this.stream = stream;
40 | }
41 |
42 | @Override
43 | public void close() throws IOException {
44 | if (this.stream != null) {
45 | this.stream.close();
46 | }
47 | }
48 |
49 | Closeable getStream() {
50 | return this.stream;
51 | }
52 | }
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/PDMCRDictionary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSKey;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDObject;
27 |
28 | /**
29 | * @author Maxim Plushchov
30 | */
31 | public class PDMCRDictionary extends PDObject {
32 |
33 | public PDMCRDictionary(COSObject obj) {
34 | super(obj);
35 | }
36 |
37 | public COSKey getPageObjectKey() {
38 | COSObject object = getObject().getKey(ASAtom.PG);
39 | return object != null ? object.getKey() : null;
40 | }
41 |
42 | public COSKey getStreamObjectKey() {
43 | COSObject object = getObject().getKey(ASAtom.STM);
44 | return object != null ? object.getKey() : null;
45 | }
46 |
47 | public Long getMCID() {
48 | return getObject().getIntegerKey(ASAtom.MCID);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/operator/InlineImageOperator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.operator;
22 |
23 | import org.verapdf.as.io.ASInputStream;
24 | import org.verapdf.cos.COSDictionary;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class InlineImageOperator extends Operator {
30 |
31 | private ASInputStream imageData;
32 | private COSDictionary imageParameters;
33 |
34 | public InlineImageOperator(final String operator) {
35 | super(operator);
36 | }
37 |
38 | public ASInputStream getImageData() {
39 | return imageData;
40 | }
41 |
42 | public void setImageData(ASInputStream imageData) {
43 | this.imageData = imageData;
44 | }
45 |
46 | public COSDictionary getImageParameters() {
47 | return imageParameters;
48 | }
49 |
50 | public void setImageParameters(COSDictionary imageParameters) {
51 | this.imageParameters = imageParameters;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDAnnotationAdditionalActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDAnnotationAdditionalActions extends PDAbstractAdditionalActions {
30 |
31 | private static final String ANNOT_PARENT_TYPE = "Annot";
32 |
33 | private static final ASAtom[] actionNames = {ASAtom.E, ASAtom.X, ASAtom.D, ASAtom.U, ASAtom.FOCUS_ABBREVIATION,
34 | ASAtom.BL_FOCUS, ASAtom.PO, ASAtom.PC, ASAtom.PV, ASAtom.PI};
35 |
36 | public PDAnnotationAdditionalActions(COSObject obj) {
37 | super(obj);
38 | }
39 |
40 | @Override
41 | public ASAtom[] getActionNames() {
42 | return actionNames;
43 | }
44 |
45 | @Override
46 | public String getParentType() {
47 | return ANNOT_PARENT_TYPE;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/postscript/PSLiteralObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser.postscript;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | import java.util.Map;
27 | import java.util.Stack;
28 |
29 | /**
30 | * Class for literal PostScript objects. These objects are just pushed to
31 | * operand stack while executed.
32 | *
33 | * @author Sergey Shemyakov
34 | */
35 | public class PSLiteralObject extends PSObject {
36 |
37 | private final COSObject object;
38 |
39 | public PSLiteralObject(COSObject object) {
40 | super(object.get());
41 | this.object = object;
42 | }
43 |
44 | @Override
45 | public void execute(Stack operandStack,
46 | Map userDict) throws PostScriptException {
47 | if (!object.empty()) {
48 | operandStack.push(this.object);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/annotations/PDWidgetAnnotation.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.annotations;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDAnnotation;
27 | import org.verapdf.pd.actions.PDAnnotationAdditionalActions;
28 | import org.verapdf.pd.actions.PDWidgetAdditionalActions;
29 |
30 | /**
31 | * @author Maxim Plushchov
32 | */
33 | public class PDWidgetAnnotation extends PDAnnotation {
34 |
35 | public PDWidgetAnnotation(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | @Override
40 | public PDAnnotationAdditionalActions getAdditionalActions() {
41 | COSObject aa = getKey(ASAtom.AA);
42 | if (aa != null && aa.getType() == COSObjType.COS_DICT) {
43 | return new PDWidgetAdditionalActions(aa);
44 | }
45 | return null;
46 | }
47 |
48 | public String getT() {
49 | return getStringKey(ASAtom.T);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDDeviceGray.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSName;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDDeviceGray extends PDColorSpace {
30 |
31 | public static final PDDeviceGray INSTANCE = new PDDeviceGray(false);
32 | public static final PDDeviceGray INHERITED_INSTANCE = new PDDeviceGray(true);
33 |
34 | private PDDeviceGray(boolean isInherited) {
35 | super(COSName.construct(ASAtom.DEVICEGRAY));
36 | setInherited(isInherited);
37 | }
38 |
39 | @Override
40 | public int getNumberOfComponents() {
41 | return 1;
42 | }
43 |
44 | @Override
45 | public ASAtom getType() {
46 | return ASAtom.DEVICEGRAY;
47 | }
48 |
49 | @Override
50 | public double[] toRGB(double[] value) {
51 | return new double[]{value[0], value[0], value[0]};
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/visitor/IndirectWriter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.visitor;
22 |
23 | import org.verapdf.cos.COSDocument;
24 | import org.verapdf.cos.COSKey;
25 |
26 | import java.io.IOException;
27 | import java.util.HashMap;
28 | import java.util.Map;
29 |
30 | /**
31 | * @author Timur Kamalov
32 | */
33 | public class IndirectWriter extends Writer {
34 |
35 | private final Map renum;
36 |
37 | public IndirectWriter(COSDocument document, String filename, boolean append,
38 | long indirectOffset) throws IOException {
39 | super(document, filename, append, indirectOffset);
40 | this.renum = new HashMap<>();
41 | renum.put(new COSKey(0, 65535), new COSKey(0, 65535));
42 | }
43 |
44 | @Override
45 | protected COSKey getKeyToWrite(final COSKey key) {
46 | if (!this.renum.containsKey(key)) {
47 | this.renum.put(key, new COSKey(this.renum.size(), 0));
48 | }
49 | return this.renum.get(key);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/TrueTypeMaxpTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.verapdf.io.SeekableInputStream;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * @author Sergey Shemyakov
29 | */
30 | class TrueTypeMaxpTable extends TrueTypeTable {
31 |
32 | private int numGlyphs;
33 |
34 | TrueTypeMaxpTable(SeekableInputStream source, long offset) {
35 | super(source, offset);
36 | }
37 |
38 | public TrueTypeMaxpTable(int numGlyphs) {
39 | this.numGlyphs = numGlyphs;
40 | }
41 |
42 | @Override
43 | void readTable() throws IOException {
44 | long startingOffset = this.source.getOffset();
45 | this.source.seek(this.offset);
46 | this.source.skip(4); // version
47 | numGlyphs = this.readUShort();
48 | this.source.seek(startingOffset);
49 | }
50 |
51 | int getNumGlyphs() {
52 | return numGlyphs;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/TrueTypeTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.verapdf.io.SeekableInputStream;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * This is base class for all True Type table parsers.
29 | *
30 | * @author Sergey Shemyakov
31 | */
32 | abstract class TrueTypeTable extends TrueTypeBaseParser {
33 |
34 | protected long offset;
35 |
36 | protected TrueTypeTable(SeekableInputStream source, long offset) {
37 | super(source);
38 | this.offset = offset;
39 | }
40 |
41 | /**
42 | * Empty constructor for inherited classes. Should be used to set Table
43 | * values to default if table is not present in font program.
44 | */
45 | protected TrueTypeTable() {}
46 |
47 | /**
48 | * This method extracts all the data needed from table.
49 | *
50 | * @throws IOException if stream-reading error occurs.
51 | */
52 | abstract void readTable() throws IOException;
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/parser/PDFParserTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser;
22 |
23 | import org.junit.Assert;
24 | import org.junit.Test;
25 |
26 | import org.verapdf.cos.xref.COSXRefEntry;
27 | import org.verapdf.cos.xref.COSXRefSection;
28 | import java.io.IOException;
29 |
30 | /**
31 | * @author Maxim Plushchov
32 | */
33 | public class PDFParserTest {
34 | private final String xrefPath = "src/test/resources/org/verapdf/parser/xref";
35 |
36 | @Test
37 | public void testXrefParsing() {
38 | try {
39 | PDFParser pdfParser = new PDFParser(xrefPath);
40 | COSXRefSection section = new COSXRefSection();
41 | pdfParser.getBaseParser().initializeToken();
42 | pdfParser.parseXrefTable(section);
43 | Assert.assertEquals(COSXRefEntry.FIRST_XREF_ENTRY, section.getEntry(0));
44 | } catch (IOException ex) {
45 | System.out.println("Parsing error: ");
46 | ex.printStackTrace();
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | import java.util.*;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public class COSBody {
29 |
30 | private final Map table;
31 |
32 | public COSBody() {
33 | this.table = new HashMap<>();
34 | }
35 |
36 | public List getAll() {
37 | return new ArrayList<>(table.values());
38 | }
39 |
40 | public COSObject get(final COSKey key) {
41 | COSObject value = this.table.get(key);
42 | return value != null ? value : new COSObject();
43 | }
44 |
45 | public void set(final COSKey key, final COSObject object) {
46 | table.put(key, object);
47 | }
48 |
49 | public COSKey getKeyForObject(COSObject obj) {
50 | if (obj.isIndirect()) {
51 | return obj.getObjectKey();
52 | } else {
53 | for (Map.Entry entry : this.table.entrySet()) {
54 | if (entry.getValue() == obj) {
55 | return entry.getKey();
56 | }
57 | }
58 | return null;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/filters/IASFilterFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.as.filters;
22 |
23 | import org.verapdf.as.io.ASInputStream;
24 | import org.verapdf.as.io.ASOutputStream;
25 | import org.verapdf.cos.COSDictionary;
26 |
27 | import java.io.IOException;
28 |
29 | /**
30 | * Interface for filter factories.
31 | *
32 | * @author Timur Kamalov
33 | */
34 | public interface IASFilterFactory {
35 |
36 | /**
37 | * Gets input filter from given encoded stream with specified decode
38 | * parameters.
39 | *
40 | * @param inputStream is encoded data.
41 | * @param decodeParams is dictionary with parameters for filter.
42 | * @return stream with decoded data.
43 | */
44 | ASInFilter getInFilter(ASInputStream inputStream, COSDictionary decodeParams) throws IOException;
45 |
46 | /**
47 | * Gets output filter with encoded data.
48 | *
49 | * @param outputStream stream to encode.
50 | * @return stream with encoded data.
51 | */
52 | ASOutFilter getOutFilter(ASOutputStream outputStream) throws IOException;
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/encryption/PDCryptFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.encryption;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDObject;
27 |
28 | /**
29 | * Represents crypt filter dictionary on pd level.
30 | *
31 | * @author Sergey Shemyakov
32 | */
33 | public class PDCryptFilter extends PDObject{
34 |
35 | public PDCryptFilter(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | /**
40 | * @return method used by crypt filter: None, V2 or AESV2.
41 | */
42 | public ASAtom getMethod() {
43 | COSObject obj = getKey(ASAtom.CFM);
44 | if (obj != null && obj.getType() == COSObjType.COS_NAME) {
45 | return obj.getName();
46 | }
47 | return ASAtom.NONE;
48 | }
49 |
50 | /**
51 | * @return length of encryption key specified in crypt filter dictionary.
52 | */
53 | public Long getLength() {
54 | return getIntegerKey(ASAtom.LENGTH);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/cos/filters/COSFilterLZWDecodeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.filters;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.cos.COSDictionary;
25 | import org.verapdf.io.SeekableInputStream;
26 |
27 | import java.io.FileInputStream;
28 | import java.io.IOException;
29 |
30 | import static org.junit.Assert.assertEquals;
31 |
32 | /**
33 | * @author Sergey Shemyakov
34 | */
35 | public class COSFilterLZWDecodeTest {
36 |
37 | private final String lzwPath = "src/test/resources/org/verapdf/cos/filters/lzw";
38 |
39 | @Test
40 | public void test() throws IOException {
41 | FileInputStream stream = new FileInputStream(lzwPath);
42 | COSFilterLZWDecode lzwDecode = new COSFilterLZWDecode(SeekableInputStream.getSeekableStream(stream), (COSDictionary) COSDictionary.construct().get());
43 | byte[] buf = new byte[2048];
44 | int read = lzwDecode.read(buf, 2048);
45 | assertEquals(66, buf[0]);
46 | assertEquals(102, read);
47 | assertEquals(46, buf[50]);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/CIDWArrayRange.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font;
22 |
23 | /**
24 | * Represents range of sequential CIDs and width for them. This is used in W
25 | * array in CIDFonts.
26 | *
27 | * @author Sergey Shemyakov
28 | */
29 | public class CIDWArrayRange {
30 | private final double width;
31 | private final int beginCID;
32 | private final int endCID;
33 |
34 | public CIDWArrayRange(int beginCID, int endCID, double width) {
35 | this.width = width;
36 | this.beginCID = beginCID;
37 | this.endCID = endCID;
38 | }
39 |
40 | /**
41 | * Returns true if width for given CID is stored in this CIDWArrayRange.
42 | *
43 | * @param cid is CID to check.
44 | * @return true if width for this CID can be obtained from this
45 | * CIDWArrayRange.
46 | */
47 | public boolean contains(int cid) {
48 | return cid >= beginCID && cid <= endCID;
49 | }
50 |
51 | /**
52 | * @return width for this range.
53 | */
54 | public double getWidth() {
55 | return width;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/PDCIDSystemInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.pd.PDObject;
26 |
27 | /**
28 | * Represents CIDSystemInfo dictionary in CID fonts.
29 | *
30 | * @author Sergey Shemyakov
31 | */
32 | public class PDCIDSystemInfo extends PDObject {
33 |
34 | public PDCIDSystemInfo(COSObject obj) {
35 | super(obj);
36 | }
37 |
38 | /**
39 | * @return a string identifying the issuer of the character collection.
40 | */
41 | public String getRegistry() {
42 | return getStringKey(ASAtom.REGISTRY);
43 | }
44 |
45 | /**
46 | * @return a string that uniquely names the character collection within the
47 | * specified registry.
48 | */
49 | public String getOrdering() {
50 | return getStringKey(ASAtom.ORDERING);
51 | }
52 |
53 | /**
54 | * @return the supplement number of the character collection.
55 | */
56 | public Long getSupplement() {
57 | return getIntegerKey(ASAtom.SUPPLEMENT);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDGroup.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.factory.colors.ColorSpaceFactory;
26 | import org.verapdf.pd.colors.PDColorSpace;
27 |
28 | /**
29 | * @author Maksim Bezrukov
30 | */
31 | public class PDGroup extends PDObject {
32 |
33 | public PDGroup(COSObject obj) {
34 | super(obj);
35 | }
36 |
37 | public ASAtom getSubtype() {
38 | return getObject().getNameKey(ASAtom.S);
39 | }
40 |
41 | public PDColorSpace getColorSpace() {
42 | return ColorSpaceFactory.getColorSpace(getKey(ASAtom.CS));
43 | }
44 |
45 | public PDColorSpace getColorSpace(PDResources resources) {
46 | return ColorSpaceFactory.getColorSpace(getKey(ASAtom.CS), resources);
47 | }
48 |
49 | public boolean isIsolated() {
50 | Boolean value = getObject().getBooleanKey(ASAtom.I);
51 | return value != null ? value.booleanValue() : false;
52 | }
53 |
54 | public boolean isKnockout() {
55 | Boolean value = getObject().getBooleanKey(ASAtom.K);
56 | return value != null ? value.booleanValue() : false;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDMediaClip.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSArray;
25 | import org.verapdf.cos.COSObjType;
26 | import org.verapdf.cos.COSObject;
27 | import org.verapdf.pd.PDObject;
28 |
29 | import java.util.Collections;
30 | import java.util.LinkedList;
31 | import java.util.List;
32 |
33 | /**
34 | * @author Maxim Plushchov
35 | */
36 | public class PDMediaClip extends PDObject {
37 | public PDMediaClip(COSObject obj) {
38 | super(obj);
39 | }
40 |
41 | public String getContentType() {
42 | return getObject().getStringKey(ASAtom.CT);
43 | }
44 |
45 | public List getAlternateDescription() {
46 | COSObject object = getObject().getKey(ASAtom.ALT);
47 | if (object.getType() == COSObjType.COS_ARRAY) {
48 | List list = new LinkedList<>();
49 | for (COSObject elem : (COSArray)object.getDirectBase()) {
50 | if (elem.getType() == COSObjType.COS_STRING) {
51 | list.add(elem.getString());
52 | }
53 | }
54 | return list;
55 | }
56 | return Collections.emptyList();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/exceptions/StringExceptions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.as.exceptions;
22 |
23 | /**
24 | * @author Timur Kamalov
25 | */
26 | public class StringExceptions {
27 |
28 | public static final String UNKNOWN_TYPE_PAGE_TREE_NODE = "unknown type of page tree node";
29 |
30 | //PDFAPI
31 | public static final String CAN_NOT_LOCATE_XREF_TABLE = "can not locate xref table";
32 | public static final String START_XREF_VALIDATION = "startxref validation failed";
33 | public static final String ENCRYPTED_PDF = "encrypted PDF with unknown or wrong password";
34 | public static final String XREF_STM_NOT_SUPPORTED = "xref streams not supported";
35 | public static final String INVALID_PDF_OBJECT = "invalid pdf object";
36 | public static final String INVALID_PDF_ARRAY = "invalid pdf array";
37 | public static final String INVALID_PDF_DICTIONARY = "invalid pdf dictionary";
38 | public static final String INVALID_PDF_STREAM = "invalid pdf stream";
39 |
40 | public static final String DUPLICATE_FACTORY_NAMES = "internal library error";
41 |
42 | public static final String WRITE_ERROR = "Error writing document";
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDDeviceCMYK.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSName;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDDeviceCMYK extends PDColorSpace {
30 |
31 | public static final PDDeviceCMYK INSTANCE = new PDDeviceCMYK(false);
32 | public static final PDDeviceCMYK INHERITED_INSTANCE = new PDDeviceCMYK(true);
33 |
34 | private PDDeviceCMYK(boolean isInherited) {
35 | super(COSName.construct(ASAtom.DEVICECMYK));
36 | setInherited(isInherited);
37 | }
38 |
39 | @Override
40 | public int getNumberOfComponents() {
41 | return 4;
42 | }
43 |
44 | @Override
45 | public ASAtom getType() {
46 | return ASAtom.DEVICECMYK;
47 | }
48 |
49 | @Override
50 | public double[] toRGB(double[] cmyk) {
51 | double[] rgb = new double[3];
52 | rgb[0] = 1.0d - Math.min(1.0, cmyk[0] + cmyk[3]);
53 | rgb[1] = 1.0d - Math.min(1.0, cmyk[1] + cmyk[3]);
54 | rgb[2] = 1.0d - Math.min(1.0, cmyk[2] + cmyk[3]);
55 | return rgb;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/type1/Type1StringConstants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.type1;
22 |
23 | /**
24 | * This class contains all string constants, required in font type1 processing.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | public class Type1StringConstants {
29 | static final String FONT_MATRIX_STRING = "FontMatrix";
30 | static final String ENCODING_STRING = "Encoding";
31 | static final String DUP_STRING = "dup";
32 | static final String DEF_STRING = "def";
33 | static final String READONLY_STRING = "readonly";
34 | static final String EEXEC_STRING = "eexec";
35 | static final String CHAR_STRINGS_STRING = "CharStrings";
36 | static final String LEN_IV_STRING = "lenIV";
37 | static final String CLEARTOMARK_STRING = "cleartomark";
38 | static final String CLOSEFILE = "closefile";
39 | static final String SUBRS = "Subrs";
40 | static final String STANDARD_ENCODING_STRING = "StandardEncoding";
41 | static final String NOACCESS = "noaccess";
42 | static final String WEIGHT = "Weight";
43 | static final String ASCENT = "Ascent";
44 | static final String DESCENT = "Descent";
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/operator/Operator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.operator;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class Operator {
30 |
31 | private static final Map CACHED_OPERATORS = new HashMap<>();
32 |
33 | private final String operator;
34 |
35 | protected Operator(final String operator) {
36 | this.operator = operator;
37 | }
38 |
39 | public static Operator getOperator(final String operator) {
40 | //don't cache image operators due to unique parameters and data
41 | if ("BI".equals(operator) || "ID".equals(operator)) {
42 | return new InlineImageOperator(operator);
43 | } else {
44 | if (CACHED_OPERATORS.containsKey(operator)) {
45 | return CACHED_OPERATORS.get(operator);
46 | } else {
47 | Operator result = new Operator(operator);
48 | CACHED_OPERATORS.put(operator, result);
49 | return result;
50 | }
51 | }
52 | }
53 |
54 | public String getOperator() {
55 | return operator;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "PDFOperator{" + operator + '}';
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/form/PDAcroForm.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.form;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSArray;
25 | import org.verapdf.cos.COSObjType;
26 | import org.verapdf.cos.COSObject;
27 | import org.verapdf.pd.PDObject;
28 |
29 | import java.util.ArrayList;
30 | import java.util.Collections;
31 | import java.util.List;
32 |
33 | /**
34 | * @author Maksim Bezrukov
35 | */
36 | public class PDAcroForm extends PDObject {
37 |
38 | public PDAcroForm(COSObject obj) {
39 | super(obj);
40 | }
41 |
42 | public COSObject getNeedAppearances() {
43 | return getKey(ASAtom.NEED_APPEARANCES);
44 | }
45 |
46 | public List getFields() {
47 | COSObject fields = getKey(ASAtom.FIELDS);
48 | if (fields != null && fields.getType() == COSObjType.COS_ARRAY) {
49 | List res = new ArrayList<>();
50 | for (COSObject obj : (COSArray) fields.getDirectBase()) {
51 | if (obj != null && obj.getType().isDictionaryBased()) {
52 | res.add(PDFormField.createTypedFormField(obj));
53 | }
54 | }
55 | return Collections.unmodifiableList(res);
56 | }
57 | return Collections.emptyList();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSNull.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | import org.verapdf.cos.visitor.ICOSVisitor;
24 | import org.verapdf.cos.visitor.IVisitor;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class COSNull extends COSDirect {
30 |
31 | private static final String NULL_STRING = "null";
32 |
33 | public static final COSNull NULL = new COSNull();
34 |
35 | @Override
36 | public COSObjType getType() {
37 | return COSObjType.COS_NULL;
38 | }
39 |
40 | public static COSObject construct() {
41 | return new COSObject(new COSNull());
42 | }
43 |
44 | @Override
45 | public void accept(final IVisitor visitor) {
46 | visitor.visitFromNull(this);
47 | }
48 |
49 | @Override
50 | public Object accept(final ICOSVisitor visitor) {
51 | return visitor.visitFromNull(this);
52 | }
53 |
54 | @Override
55 | public boolean equals(Object o) {
56 | if (this == o) return true;
57 | return o instanceof COSNull;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return NULL_STRING;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSBasePair.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * @author Sergey Shemyakov
27 | */
28 | public class COSBasePair {
29 | private final COSBase first;
30 | private final COSBase second;
31 |
32 | private COSBasePair(COSBase first, COSBase second) {
33 | this.first = first;
34 | this.second = second;
35 | }
36 |
37 | COSBase getFirst() {
38 | return first;
39 | }
40 |
41 | COSBase getSecond() {
42 | return second;
43 | }
44 |
45 | private boolean contains(COSBase obj) {
46 | return first == obj || second == obj;
47 | }
48 |
49 | static boolean listContainsPair(List list, COSBase obj1, COSBase obj2) {
50 | for (COSBasePair pair : list) {
51 | if (pair.contains(obj1) && pair.contains(obj2)) {
52 | return true;
53 | }
54 | }
55 | return false;
56 | }
57 |
58 | static void addPairToList(List list, COSBase obj1, COSBase obj2) {
59 | if (obj1 instanceof COSArray || obj1 instanceof COSDictionary) {
60 | list.add(new COSBasePair(obj1, obj2));
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/io/IReader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.io;
22 |
23 | import org.verapdf.cos.COSHeader;
24 | import org.verapdf.cos.COSKey;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.cos.COSTrailer;
27 |
28 | import java.io.Closeable;
29 | import java.io.IOException;
30 | import java.util.List;
31 | import java.util.SortedSet;
32 |
33 | /**
34 | * @author Timur Kamalov
35 | */
36 | public interface IReader extends Closeable {
37 |
38 | SeekableInputStream getPDFSource();
39 |
40 | COSHeader getHeader();
41 |
42 | List getKeys();
43 |
44 | COSObject getObject(final COSKey key) throws IOException;
45 |
46 | COSObject getObject(final long offset) throws IOException;
47 |
48 | Long getOffset(final COSKey key);
49 |
50 | long getStartXRef();
51 |
52 | SortedSet getStartXRefs();
53 |
54 | boolean isLinearized();
55 |
56 | COSTrailer getTrailer();
57 |
58 | COSTrailer getFirstTrailer();
59 |
60 | COSTrailer getLastTrailer();
61 |
62 | long getLastTrailerOffset();
63 |
64 | COSObject getLinearizationDictionary();
65 |
66 | COSObject getLastXrefStream();
67 |
68 | boolean isContainsXRefStream();
69 |
70 | List getObjectStreamsList();
71 |
72 | int getGreatestKeyNumberFromXref();
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/TrueTypeHeadTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.verapdf.io.SeekableInputStream;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * This class does parsing of True Type "head" table and extracts all the data
29 | * needed.
30 | *
31 | * @author Sergey Shemyakov
32 | */
33 | class TrueTypeHeadTable extends TrueTypeTable {
34 |
35 | private int unitsPerEm;
36 |
37 | TrueTypeHeadTable(SeekableInputStream source, long offset) {
38 | super(source, offset);
39 | }
40 |
41 | /**
42 | * Sets units per em to default. Should be used if table is not present in
43 | * font program.
44 | */
45 | TrueTypeHeadTable() {
46 | this.unitsPerEm = 2048;
47 | }
48 |
49 | @Override
50 | void readTable() throws IOException {
51 | long startingOffset = this.source.getOffset();
52 | this.source.seek(this.offset);
53 | this.source.skip(18); // 4 table version, 4 fontRevision, 4 checkSumAdjustment, 4 magicNumber, 2 flags
54 | this.unitsPerEm = this.readUShort();
55 | this.source.seek(startingOffset);
56 | }
57 |
58 | int getUnitsPerEm() {
59 | return unitsPerEm;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/form/PDSignatureField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.form;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.*;
25 | import org.verapdf.pd.PDSignature;
26 |
27 | import java.util.Set;
28 |
29 | /**
30 | * Represents signature field.
31 | *
32 | * @author Sergey Shemyakov
33 | */
34 | public class PDSignatureField extends PDFormField {
35 |
36 | protected PDSignatureField(COSObject obj, Set parents) {
37 | super(obj, parents);
38 | }
39 |
40 | /**
41 | * @return digital signature contained in this signature field, or null if
42 | * digital signature can't be obtained.
43 | */
44 | public PDSignature getSignature() {
45 | COSBase directBase = this.getObject().getKey(ASAtom.V).getDirectBase();
46 | if (directBase != null && directBase.getType() == COSObjType.COS_DICT) {
47 | return new PDSignature((COSDictionary) directBase);
48 | }
49 | return null;
50 | }
51 |
52 | /**
53 | * @return COSObject representing indirect reference to digital signature
54 | * contained in this signature field.
55 | */
56 | public COSObject getSignatureReference() {
57 | return this.getObject().getKey(ASAtom.V);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDNavigationNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.actions.PDAction;
27 |
28 | /**
29 | * @author Maksim Bezrukov
30 | */
31 | public class PDNavigationNode extends PDObject {
32 |
33 | public PDNavigationNode(COSObject obj) {
34 | super(obj);
35 | }
36 |
37 | public PDAction getNA() {
38 | return getAction(ASAtom.NA);
39 | }
40 |
41 | public PDAction getPA() {
42 | return getAction(ASAtom.PA);
43 | }
44 |
45 | private PDAction getAction(ASAtom key) {
46 | COSObject object = getKey(key);
47 | if (object != null && object.getType() == COSObjType.COS_DICT) {
48 | return new PDAction(object);
49 | }
50 | return null;
51 | }
52 |
53 | public PDNavigationNode getNext() {
54 | return getNavigationNode(ASAtom.NEXT);
55 | }
56 |
57 | public PDNavigationNode getPrev() {
58 | return getNavigationNode(ASAtom.PREV);
59 | }
60 |
61 | private PDNavigationNode getNavigationNode(ASAtom key) {
62 | COSObject object = getKey(key);
63 | if (object != null && object.getType() == COSObjType.COS_DICT) {
64 | return new PDNavigationNode(object);
65 | }
66 | return null;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDCalGray.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Maksim Bezrukov
28 | */
29 | public class PDCalGray extends PDCIEDictionaryBased {
30 |
31 | public PDCalGray() {
32 | }
33 |
34 | public PDCalGray(COSObject obj) {
35 | super(obj);
36 | }
37 |
38 | @Override
39 | public int getNumberOfComponents() {
40 | return 1;
41 | }
42 |
43 | @Override
44 | public ASAtom getType() {
45 | return ASAtom.CALGRAY;
46 | }
47 |
48 | // See ISO 32000-2:2020, chapter 8.6.5.2
49 | @Override
50 | public double[] toRGB(double[] value) {
51 | double a = value[0];
52 | double gamma = getGamma();
53 | double powAG = Math.pow(a, gamma);
54 | return convXYZtoRGB(wpX * powAG, wpY * powAG, wpZ * powAG);
55 | }
56 |
57 | public Double getGamma() {
58 | return getNumber(this.dictionary.getKey(ASAtom.GAMMA), 1);
59 | }
60 |
61 | private static Double getNumber(COSObject object, double defaultValue) {
62 | if (object != null) {
63 | return object.getReal();
64 | }
65 | return defaultValue;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/TrueTypeHmtxTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.verapdf.io.SeekableInputStream;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * This class does parsing of True Type "hmtx" table and extracts all the data
29 | * needed.
30 | *
31 | * @author Sergey Shemyakov
32 | */
33 | class TrueTypeHmtxTable extends TrueTypeTable {
34 |
35 | private int[] longHorMetrics;
36 | private int numberOfHMetrics;
37 |
38 | TrueTypeHmtxTable(SeekableInputStream source, long offset) {
39 | super(source, offset);
40 | }
41 |
42 | void setNumberOfHMetrics(int numberOfHMetrics) {
43 | this.numberOfHMetrics = numberOfHMetrics;
44 | }
45 |
46 | @Override
47 | void readTable() throws IOException {
48 | long startingOffset = this.source.getOffset();
49 | this.source.seek(this.offset);
50 | longHorMetrics = new int[numberOfHMetrics];
51 | for (int i = 0; i < numberOfHMetrics; ++i) {
52 | longHorMetrics[i] = this.readUFWord();
53 | this.source.skip(2); // lsb
54 | }
55 | this.source.seek(startingOffset);
56 | }
57 |
58 | int[] getLongHorMetrics() {
59 | return longHorMetrics;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/type3/PDType3CharProc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.type3;
22 |
23 | import org.verapdf.cos.COSObjType;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.pd.PDContentStream;
26 | import org.verapdf.pd.PDObject;
27 |
28 | /**
29 | * Class represents content stream that constructs and paints the glyph for
30 | * Type 3 font character.
31 | *
32 | * @author Sergey Shemyakov
33 | */
34 | public class PDType3CharProc extends PDObject implements PDContentStream {
35 |
36 | /**
37 | * Constructor from stream.
38 | *
39 | * @param charStream is COSObject containing charProc content stream.
40 | */
41 | public PDType3CharProc(COSObject charStream) {
42 | super(charStream);
43 | }
44 |
45 | /**
46 | * @return COSStream, containing charProc content stream.
47 | */
48 | @Override
49 | public COSObject getContents() {
50 | return getObject();
51 | }
52 |
53 | /**
54 | * @param contents is COSStream, containing charProc content stream.
55 | */
56 | @Override
57 | public void setContents(COSObject contents) {
58 | if (contents != null && contents.getType() == COSObjType.COS_STREAM) {
59 | setObject(contents);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDHalftone.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.function.PDFunction;
27 |
28 | /**
29 | * @author Maksim Bezrukov
30 | */
31 | public class PDHalftone extends PDObject {
32 |
33 | /**
34 | * Constructing Halftone object from base object
35 | * @param obj base object for halftone. Can be name, dictionary or stream
36 | */
37 | public PDHalftone(COSObject obj) {
38 | super(obj);
39 | }
40 |
41 | public Long getHalftoneType() {
42 | COSObject base = getObject();
43 | if (base.getType() == COSObjType.COS_NAME) {
44 | return null;
45 | }
46 | return base.getIntegerKey(ASAtom.HALFTONE_TYPE);
47 | }
48 |
49 | public String getHalftoneName() {
50 | COSObject base = getObject();
51 | if (base.getType() == COSObjType.COS_NAME) {
52 | return base.getName().getValue();
53 | }
54 | return base.getStringKey(ASAtom.HALFTONE_NAME);
55 | }
56 |
57 | public PDFunction getCustomTransferFunction() {
58 | return PDFunction.createFunction(getObject().getKey(ASAtom.TRANSFER_FUNCTION));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDDeviceRGB.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSName;
25 |
26 | import java.awt.color.ColorSpace;
27 |
28 | /**
29 | * @author Maksim Bezrukov
30 | */
31 | public class PDDeviceRGB extends PDColorSpace {
32 |
33 | public static final PDDeviceRGB INSTANCE = new PDDeviceRGB(false);
34 | public static final PDDeviceRGB INHERITED_INSTANCE = new PDDeviceRGB(true);
35 |
36 | private final ColorSpace colorSpaceRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
37 |
38 | private PDDeviceRGB(boolean isInherited) {
39 | super(COSName.construct(ASAtom.DEVICERGB));
40 | setInherited(isInherited);
41 | }
42 |
43 | @Override
44 | public int getNumberOfComponents() {
45 | return 3;
46 | }
47 |
48 | @Override
49 | public ASAtom getType() {
50 | return ASAtom.DEVICERGB;
51 | }
52 |
53 | @Override
54 | public double[] toRGB(double[] value) {
55 | float[] rgb = new float[value.length];
56 | for (int i = 0; i < value.length; ++i) {
57 | rgb[i] = (float) value[i];
58 | }
59 | rgb = colorSpaceRGB.toRGB(rgb);
60 | return new double[]{rgb[0], rgb[1], rgb[2]};
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDNamesDictionary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 |
27 | /**
28 | * @author Maksim Bezrukov
29 | */
30 | public class PDNamesDictionary extends PDObject {
31 |
32 | private PDNameTreeNode embeddedFiles;
33 | private PDNameTreeNode javaScript;
34 | private PDNameTreeNode dests;
35 |
36 | public PDNamesDictionary(COSObject obj) {
37 | super(obj);
38 | }
39 |
40 | public PDNameTreeNode getEmbeddedFiles() {
41 | if (embeddedFiles == null) {
42 | embeddedFiles = getNameTreeByName(ASAtom.EMBEDDED_FILES);
43 | }
44 | return embeddedFiles;
45 | }
46 |
47 | public PDNameTreeNode getJavaScript() {
48 | if (javaScript == null) {
49 | javaScript = getNameTreeByName(ASAtom.JAVA_SCRIPT);
50 | }
51 | return javaScript;
52 | }
53 |
54 | public PDNameTreeNode getDests() {
55 | if (dests == null) {
56 | dests = getNameTreeByName(ASAtom.DESTS);
57 | }
58 | return dests;
59 | }
60 |
61 | private PDNameTreeNode getNameTreeByName(ASAtom name) {
62 | COSObject base = getKey(name);
63 | if (base != null && base.getType() == COSObjType.COS_DICT) {
64 | return PDNameTreeNode.create(base);
65 | }
66 | return null;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSKey.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | /**
24 | * @author Timur Kamalov
25 | */
26 | public class COSKey {
27 |
28 | private int number;
29 | private int generation;
30 |
31 | public COSKey() {
32 | this(0);
33 | }
34 |
35 | public COSKey(int number) {
36 | this(number, 0);
37 | }
38 |
39 | public COSKey(int number, int generation) {
40 | this.number = number;
41 | this.generation = generation;
42 | }
43 |
44 | public int getNumber() {
45 | return number;
46 | }
47 |
48 | public void setNumber(int number) {
49 | this.number = number;
50 | }
51 |
52 | public int getGeneration() {
53 | return generation;
54 | }
55 |
56 | public void setGeneration(int generation) {
57 | this.generation = generation;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return number + " " + generation + " obj";
63 | }
64 |
65 | @Override
66 | public boolean equals(Object o) {
67 | if (this == o) return true;
68 | if (o == null || getClass() != o.getClass()) return false;
69 |
70 | COSKey cosKey = (COSKey) o;
71 |
72 | if (number != cosKey.number) return false;
73 | return generation == cosKey.generation;
74 |
75 | }
76 |
77 | @Override
78 | public int hashCode() {
79 | int result = number;
80 | result = 31 * result + generation;
81 | return result;
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/xref/COSXRefTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.xref;
22 |
23 | import org.verapdf.cos.COSKey;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * @author Timur Kamalov
30 | */
31 | public class COSXRefTable {
32 |
33 | private List all;
34 | private int maxKeyNumber;
35 |
36 | public COSXRefTable() {
37 | this.all = new ArrayList<>();
38 | maxKeyNumber = 0;
39 | }
40 |
41 | public void set(final List keys) {
42 | this.all = keys;
43 | maxKeyNumber = keys.stream().map(COSKey::getNumber).max(Integer::compare).orElse(0);
44 | }
45 |
46 | private int getGreatestKeyNumberFromXref() {
47 | return maxKeyNumber;
48 | }
49 |
50 | public COSKey next() {
51 | return new COSKey(getGreatestKeyNumberFromXref() + 1);
52 | }
53 |
54 | public void newKey(final COSKey key) {
55 | this.all.add(key);
56 | if (key.getNumber() > maxKeyNumber) {
57 | maxKeyNumber = key.getNumber();
58 | }
59 | }
60 |
61 | public void newKey(final List key) {
62 | this.all.addAll(key);
63 | int newKeysMaxKeyNumber = key.stream().map(COSKey::getNumber).max(Integer::compare).orElse(0);
64 | if (newKeysMaxKeyNumber > maxKeyNumber) {
65 | maxKeyNumber = newKeysMaxKeyNumber;
66 | }
67 | }
68 |
69 | public List getAllKeys() {
70 | return this.all;
71 | }
72 | }
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/pd/function/PDFunctionTestHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.function;
22 |
23 | import org.junit.jupiter.api.extension.ParameterContext;
24 | import org.junit.jupiter.params.converter.ArgumentConversionException;
25 | import org.junit.jupiter.params.converter.ArgumentConverter;
26 | import org.verapdf.cos.*;
27 | import org.verapdf.parser.FunctionParser;
28 | import org.verapdf.parser.postscript.PSOperator;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | class PDFunctionTestHelper {
34 | public static final double EPSILON = 1.0E-7;
35 |
36 | public static class ListOfCOSObjectsConverter implements ArgumentConverter {
37 | @Override
38 | public List convert(Object source, ParameterContext parameterContext) throws ArgumentConversionException {
39 | List params = new ArrayList<>();
40 | String[] parts = ((String) source).split(" ");
41 | for (String item : parts) {
42 | if (FunctionParser.FUNCTION_KEYWORDS.contains(item)) {
43 | params.add(new PSOperator(COSName.construct(item)));
44 | } else {
45 | params.add(COSReal.construct(Double.parseDouble(item)));
46 | }
47 | }
48 | return params;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/io/SeekableInputStreamTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.io;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.as.io.ASMemoryInStream;
25 |
26 | import java.io.ByteArrayInputStream;
27 | import java.io.IOException;
28 | import java.io.InputStream;
29 |
30 | import static org.junit.Assert.assertTrue;
31 |
32 | /**
33 | * Tests correct creation of InternalInputStream and ASMemoryInStream.
34 | *
35 | * @author Sergey Shemyakov
36 | */
37 | public class SeekableInputStreamTest {
38 |
39 | @Test
40 | public void test() throws IOException {
41 | byte[] one = new byte[10];
42 | byte[] two = new byte[10239];
43 | byte[] three = new byte[15000];
44 | InputStream streamOne = new ByteArrayInputStream(one);
45 | InputStream streamTwo = new ByteArrayInputStream(two);
46 | InputStream streamThree = new ByteArrayInputStream(three);
47 | SeekableInputStream ssOne = SeekableInputStream.getSeekableStream(streamOne);
48 | SeekableInputStream ssTwo = SeekableInputStream.getSeekableStream(streamTwo);
49 | SeekableInputStream ssThree = SeekableInputStream.getSeekableStream(streamThree);
50 | assertTrue(ssOne instanceof ASMemoryInStream);
51 | assertTrue(ssTwo instanceof ASMemoryInStream);
52 | assertTrue(ssThree instanceof InternalInputStream);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/pd/font/opentype/OpenTypeCFFTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.opentype;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.as.ASAtom;
25 | import org.verapdf.as.io.ASInputStream;
26 | import org.verapdf.cos.COSName;
27 | import org.verapdf.cos.COSObject;
28 | import org.verapdf.io.InternalInputStream;
29 | import org.verapdf.pd.font.cff.CFFFontProgram;
30 | import org.verapdf.tools.StaticResources;
31 |
32 | import java.io.IOException;
33 |
34 | import static org.junit.Assert.assertFalse;
35 | import static org.junit.Assert.assertTrue;
36 |
37 | /**
38 | * @author Sergey Shemyakov
39 | */
40 | public class OpenTypeCFFTest {
41 |
42 | private final String fontFilePath = "src/test/resources/org/verapdf/pd/font/opentype/ShortStack-Regular.otf";
43 |
44 | @Test
45 | public void test() throws IOException {
46 | StaticResources.clear();
47 | COSObject encoding = COSName.construct(ASAtom.WIN_ANSI_ENCODING);
48 | ASInputStream stream = new InternalInputStream(fontFilePath, 2);
49 | OpenTypeFontProgram font = new OpenTypeFontProgram(stream, true, false, false,
50 | encoding, null, true, null, null);
51 | font.parseFont();
52 | assertTrue(font.getFont() instanceof CFFFontProgram);
53 | assertFalse(((CFFFontProgram) font.getFont()).isCIDFont());
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/NotSeekableCOSParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser;
22 |
23 | import org.verapdf.as.filters.io.ASBufferedInFilter;
24 | import org.verapdf.as.io.ASInputStream;
25 |
26 | import java.io.Closeable;
27 | import java.io.IOException;
28 |
29 | /**
30 | * Parser for COS objects that operates with a buffered stream. The seek()
31 | * operation of stream is not required.
32 | *
33 | * @author Sergey Shemyakov
34 | */
35 | public class NotSeekableCOSParser extends COSParser implements Closeable {
36 |
37 | public NotSeekableCOSParser(ASInputStream stream) throws IOException {
38 | super(new NotSeekableBaseParser(stream));
39 | }
40 |
41 | public NotSeekableCOSParser(ASInputStream stream, boolean isPSParser) throws IOException {
42 | super(new NotSeekableBaseParser(stream, isPSParser));
43 | }
44 |
45 | public NotSeekableCOSParser(NotSeekableBaseParser baseParser) {
46 | super(baseParser);
47 | }
48 |
49 | @Override
50 | public NotSeekableBaseParser getBaseParser() {
51 | return (NotSeekableBaseParser) super.getBaseParser();
52 | }
53 |
54 | @Override
55 | public ASBufferedInFilter getSource() {
56 | return getBaseParser().getSource();
57 | }
58 |
59 | @Override
60 | public void close() throws IOException {
61 | getBaseParser().close();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/cos/COSStreamTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.as.ASAtom;
25 | import org.verapdf.as.io.ASInputStream;
26 | import org.verapdf.as.io.ASMemoryInStream;
27 |
28 | import java.io.IOException;
29 | import java.nio.charset.StandardCharsets;
30 | import java.util.Arrays;
31 |
32 | import static org.junit.Assert.assertEquals;
33 |
34 | /**
35 | * @author Sergey Shemyakov
36 | */
37 | public class COSStreamTest {
38 |
39 | private static final String SAMPLE_DATA = "Just some generic data";
40 |
41 | @Test
42 | public void test() throws IOException {
43 | byte[] asciiHexData = "4a75737420736f6d652067656e657269632064617461".getBytes(StandardCharsets.ISO_8859_1); //"Just some generic data" in hex form
44 | ASInputStream asciiHexStream = new ASMemoryInStream(asciiHexData);
45 | COSObject cosStream = COSStream.construct(asciiHexStream);
46 | cosStream.setKey(ASAtom.FILTER, COSName.construct(ASAtom.ASCII_HEX_DECODE));
47 | ((COSStream) cosStream.get()).setFilters(new COSFilters(COSName.construct(ASAtom.FLATE_DECODE)));
48 | byte[] buf = new byte[100];
49 | int read = cosStream.getData(COSStream.FilterFlags.DECODE).read(buf, 100);
50 | String message = new String(Arrays.copyOf(buf, read), StandardCharsets.ISO_8859_1);
51 | assertEquals(SAMPLE_DATA, message);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDAppearanceEntry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 |
27 | import java.util.Collections;
28 | import java.util.HashMap;
29 | import java.util.Map;
30 |
31 | /**
32 | * @author Maksim Bezrukov
33 | */
34 | public class PDAppearanceEntry extends PDObject {
35 |
36 | public PDAppearanceEntry(COSObject obj) {
37 | super(obj);
38 | }
39 |
40 | public boolean isSubDictionary() {
41 | return getObject().getType() == COSObjType.COS_DICT;
42 | }
43 |
44 | public Map getSubDictionary() {
45 | if (!isSubDictionary()) {
46 | throw new IllegalStateException("Current appearance entry is a stream");
47 | }
48 |
49 | Map res = new HashMap<>();
50 | for (ASAtom key : getObject().getKeySet()) {
51 | COSObject obj = getKey(key);
52 | if (obj.isIndirect()) {
53 | obj = obj.getDirect();
54 | }
55 | if (obj != null && obj.getType() == COSObjType.COS_STREAM) {
56 | res.put(key, new PDAppearanceStream(obj));
57 | }
58 | }
59 | return Collections.unmodifiableMap(res);
60 | }
61 |
62 | public PDAppearanceStream getAppearanceStream() {
63 | if (isSubDictionary()) {
64 | throw new IllegalStateException("Current appearance entry is not a stream");
65 | }
66 | return new PDAppearanceStream(getObject());
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/IdentityCMap.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 |
26 | /**
27 | * Class represents identity CMap.
28 | *
29 | * @author Sergey Shemyakov
30 | */
31 | public class IdentityCMap extends CMap {
32 |
33 | private static final String ADOBE = "Adobe";
34 | private static final String IDENTITY = "Identity";
35 | private static final int DEFAULT_SUPPLEMENT = 0;
36 |
37 | public IdentityCMap(String name) {
38 | this.setName(name);
39 | }
40 |
41 | @Override
42 | public int toCID(int character) {
43 | return character;
44 | }
45 |
46 | @Override
47 | public boolean containsCode(int character) {
48 | return character != 0;
49 | }
50 |
51 | @Override
52 | public int getCodeFromStream(InputStream stream) throws IOException {
53 | int firstByte = stream.read();
54 | int secondByte = stream.read();
55 | return (firstByte << 8) + secondByte;
56 | }
57 |
58 | @Override
59 | public String getRegistry() {
60 | return ADOBE;
61 | }
62 |
63 | @Override
64 | public String getOrdering() {
65 | return IDENTITY;
66 | }
67 |
68 | @Override
69 | public int getSupplement() {
70 | return DEFAULT_SUPPLEMENT;
71 | }
72 |
73 | @Override
74 | public String getUnicode(int code) {
75 | return null;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDPageTreeNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 |
26 | /**
27 | * @author Timur Kamalov
28 | */
29 | public class PDPageTreeNode extends PDObject {
30 |
31 | private PDPageTreeBranch parent;
32 |
33 | public PDPageTreeNode() {
34 | }
35 |
36 | public PDPageTreeNode(final COSObject obj) {
37 | super.setObject(obj);
38 | }
39 |
40 | public PDPageTreeBranch getParent() {
41 | return this.parent;
42 | }
43 |
44 | public void setParent(final PDPageTreeBranch parent) {
45 | this.parent = parent;
46 | if (parent != null) {
47 | super.getObject().setKey(ASAtom.PARENT, parent.getObject());
48 | }
49 | }
50 |
51 | public int getLeafCount() {
52 | return 1;
53 | }
54 |
55 | public PDPageTreeBranch findTerminal(int index) {
56 | if (parent == null) {
57 | return null;
58 | }
59 |
60 | return parent;
61 | }
62 |
63 | public PDPage findTerminalPDPage(int index) {
64 | if (parent == null) {
65 | return null;
66 | }
67 |
68 | index += this.parent.getIndex(this);
69 | return (PDPage) parent.getChild(index);
70 | }
71 |
72 | protected COSObject getInheritableResources() {
73 | COSObject value = getObject().getKey(ASAtom.RESOURCES);
74 | if (value != null && !value.empty()) {
75 | return value;
76 | }
77 |
78 | if (parent != null) {
79 | return parent.getInheritableResources();
80 | }
81 |
82 | return null;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/CFFNumber.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font;
22 |
23 | /**
24 | * Instance of this class can represent int or float. It is used in CFF fonts.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | public class CFFNumber {
29 |
30 | private final long integer;
31 | private final float real;
32 | private final boolean isInteger;
33 |
34 | /**
35 | * Initializes this number with integer.
36 | * @param integer is integer to initialize CFFNumber.
37 | */
38 | public CFFNumber(int integer) {
39 | this.integer = integer;
40 | this.real = integer;
41 | this.isInteger = true;
42 | }
43 |
44 | /**
45 | * Initializes this number with float.
46 | * @param real is float number to initialize CFFNumber.
47 | */
48 | public CFFNumber(float real) {
49 | this.real = real;
50 | this.integer = (long) real;
51 | this.isInteger = false;
52 | }
53 |
54 | /**
55 | * @return true if CFFNumber is initialized with integer.
56 | */
57 | public boolean isInteger() {
58 | return isInteger;
59 | }
60 |
61 | /**
62 | * @return integer if this number is initialized with integer.
63 | */
64 | public long getInteger() {
65 | return integer;
66 | }
67 |
68 | /**
69 | * @return float if this number is initialized with float.
70 | */
71 | public float getReal() {
72 | return real;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/xref/COSXRefInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.xref;
22 |
23 | import org.verapdf.cos.COSObject;
24 | import org.verapdf.cos.COSTrailer;
25 |
26 | /**
27 | * Class represents xref section with trailer.
28 | *
29 | * @author Timur Kamalov
30 | */
31 | public class COSXRefInfo {
32 |
33 | private long startXRef;
34 | private COSXRefSection xref;
35 | private final COSTrailer trailer;
36 |
37 | /**
38 | * Creates empty COSXrefInfo object.
39 | */
40 | public COSXRefInfo() {
41 | this.startXRef = 0;
42 | this.xref = new COSXRefSection();
43 | this.trailer = new COSTrailer();
44 | }
45 |
46 | /**
47 | * @return offset of xref section.
48 | */
49 | public long getStartXRef() {
50 | return this.startXRef;
51 | }
52 |
53 | /**
54 | * Sets offset of xref section.
55 | */
56 | public void setStartXRef(final long startXRef) {
57 | this.startXRef = startXRef;
58 | }
59 |
60 | /**
61 | * @return xref section object.
62 | */
63 | public COSXRefSection getXRefSection() {
64 | return this.xref;
65 | }
66 |
67 | /**
68 | * Sets xref section object.
69 | */
70 | public void setXref(COSXRefSection xref) {
71 | this.xref = xref;
72 | }
73 |
74 | /**
75 | * @return trailer of this section.
76 | */
77 | public COSTrailer getTrailer() {
78 | return this.trailer;
79 | }
80 |
81 | /**
82 | * Sets trailer of this section.
83 | */
84 | public void setTrailer(final COSObject object) {
85 | this.trailer.setObject(object);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/actions/PDAbstractAdditionalActions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.actions;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDObject;
27 |
28 | import java.util.Collections;
29 | import java.util.List;
30 | import java.util.ArrayList;
31 |
32 | /**
33 | * @author Maksim Bezrukov
34 | */
35 | public abstract class PDAbstractAdditionalActions extends PDObject {
36 |
37 | protected PDAbstractAdditionalActions(COSObject obj) {
38 | super(obj);
39 | }
40 |
41 | protected PDAction getAction(ASAtom key) {
42 | COSObject obj = getKey(key);
43 | if (obj != null && obj.getType() == COSObjType.COS_DICT) {
44 | return new PDAction(obj);
45 | }
46 | return null;
47 | }
48 |
49 | public ASAtom[] getActionNames() {
50 | return null;
51 | }
52 |
53 | public List getActions() {
54 | ASAtom[] actionNames = getActionNames();
55 | if (actionNames == null) {
56 | return Collections.emptyList();
57 | }
58 | List actions = new ArrayList<>(actionNames.length);
59 | for (ASAtom name : actionNames) {
60 | PDAction action = getAction(name);
61 | if (name != null) {
62 | actions.add(action);
63 | }
64 | }
65 | return actions;
66 | }
67 |
68 | public abstract String getParentType();
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/patterns/PDShadingPattern.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.patterns;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.pd.PDExtGState;
27 | import org.verapdf.pd.PDResources;
28 | import org.verapdf.tools.TypeConverter;
29 |
30 | /**
31 | * @author Maksim Bezrukov
32 | */
33 | public class PDShadingPattern extends PDPattern {
34 |
35 | private final PDResources resources;
36 |
37 | public PDShadingPattern(COSObject obj, PDResources resources) {
38 | super(obj);
39 | this.resources = resources;
40 | }
41 |
42 | @Override
43 | public int getPatternType() {
44 | return PDPattern.TYPE_SHADING_PATTERN;
45 | }
46 |
47 | public PDShading getShading() {
48 | COSObject obj = getKey(ASAtom.SHADING);
49 | if (obj != null && obj.getType().isDictionaryBased()) {
50 | return new PDShading(obj, this.resources);
51 | } else {
52 | return null;
53 | }
54 | }
55 |
56 | public double[] getMatrix() {
57 | double[] res = TypeConverter.getRealArray(getKey(ASAtom.MATRIX), 6, "Matrix");
58 | return res != null ? res : new double[]{1, 0, 0, 1, 0, 0};
59 | }
60 |
61 | public PDExtGState getExtGState() {
62 | COSObject obj = getKey(ASAtom.EXT_G_STATE);
63 | if (obj.getType() == COSObjType.COS_DICT) {
64 | return new PDExtGState(obj);
65 | }
66 | return null;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cff/CFFIndex.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cff;
22 |
23 | import java.util.Arrays;
24 |
25 | /**
26 | * This class represents CFF data structure INDEX as described in Adobe
27 | * Technical Note #5176: "The Compact Font Format Specification".
28 | *
29 | * @author Sergey Shemyakov
30 | */
31 | public class CFFIndex {
32 |
33 | private final int count;
34 | private final int offsetShift;
35 | private final int[] offsets;
36 | private final byte[] data;
37 |
38 | CFFIndex(int count, int offsetShift, int[] offsets, byte[] data) {
39 | this.count = count;
40 | this.offsetShift = offsetShift;
41 | this.offsets = offsets;
42 | this.data = data;
43 | }
44 |
45 | int size() {
46 | return count;
47 | }
48 |
49 | byte[] get(int n) {
50 | if (n < 0 || n >= count || offsets[n] <= 0 || offsets[n + 1] <= 0) {
51 | throw new ArrayIndexOutOfBoundsException("Can't get object with number "
52 | + n + " from INDEX with " + count + " elements.");
53 | }
54 | return Arrays.copyOfRange(data, offsets[n] - 1, offsets[n + 1] - 1);
55 | }
56 |
57 | int getOffset(int i) {
58 | return offsets[i];
59 | }
60 |
61 | int getOffsetShift() {
62 | return offsetShift;
63 | }
64 |
65 | int getDataLength() {
66 | return this.data.length;
67 | }
68 |
69 | public static CFFIndex getEmptyIndex() {
70 | return new CFFIndex(0, 0, new int[0], new byte[0]);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/postscript/PSParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser.postscript;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.as.io.ASInputStream;
25 | import org.verapdf.cos.COSName;
26 | import org.verapdf.cos.COSObject;
27 | import org.verapdf.parser.NotSeekableBaseParser;
28 | import org.verapdf.parser.NotSeekableCOSParser;
29 | import org.verapdf.pd.function.PSOperatorsConstants;
30 |
31 | import java.io.IOException;
32 | import java.util.HashMap;
33 | import java.util.Map;
34 | import java.util.Stack;
35 |
36 | /**
37 | * PostScript parser that holds operand stack and user dictionary.
38 | *
39 | * @author Sergey Shemyakov
40 | */
41 | public class PSParser extends NotSeekableCOSParser {
42 |
43 | protected final Map userDict = new HashMap<>();
44 | protected final Stack operandStack = new Stack<>();
45 |
46 | public PSParser(ASInputStream fileStream) throws IOException {
47 | super(fileStream, true);
48 | }
49 |
50 | public PSParser(NotSeekableBaseParser baseParser) {
51 | super(baseParser);
52 | }
53 |
54 | public COSObject getObjectFromUserDict(ASAtom key) {
55 | return userDict.get(key);
56 | }
57 |
58 | @Override
59 | protected COSObject getDictionary() {
60 | this.flag = true;
61 | return COSName.construct(PSOperatorsConstants.LEFT_ANGLE_BRACES);
62 | }
63 |
64 | @Override
65 | protected COSObject getCloseDictionary() {
66 | return COSName.construct(PSOperatorsConstants.RIGHT_ANGLE_BRACES);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/PDStructTreeRoot.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.tools.StaticResources;
27 |
28 | import java.util.*;
29 |
30 | /**
31 | * @author Maksim Bezrukov
32 | */
33 | public class PDStructTreeRoot extends PDStructTreeNode {
34 |
35 | private PDNumberTreeNode parentTree;
36 |
37 | public PDStructTreeRoot(COSObject obj) {
38 | super(obj);
39 | StaticResources.setRoleMapHelper(getRoleMap());
40 | }
41 |
42 | public Map getRoleMap() {
43 | COSObject roleMap = getKey(ASAtom.ROLE_MAP);
44 | if (roleMap != null && roleMap.getType() == COSObjType.COS_DICT && roleMap.size() > 0) {
45 | Map res = new HashMap<>();
46 | Set keys = roleMap.getKeySet();
47 | for (ASAtom key : keys) {
48 | ASAtom value = roleMap.getNameKey(key);
49 | if (value != null) {
50 | res.put(key, value);
51 | }
52 | }
53 | return Collections.unmodifiableMap(res);
54 | }
55 | return Collections.emptyMap();
56 | }
57 |
58 | public COSObject getClassMap() {
59 | return getKey(ASAtom.CLASS_MAP);
60 | }
61 |
62 | public PDNumberTreeNode getParentTree() {
63 | if (parentTree == null) {
64 | COSObject parentTreeObject = getKey(ASAtom.PARENT_TREE);
65 | if (parentTreeObject != null && parentTreeObject.getType().isDictionaryBased()) {
66 | parentTree = new PDNumberTreeNode(parentTreeObject);
67 | }
68 | }
69 | return parentTree;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/tools/IntReference.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.tools;
22 |
23 | /**
24 | * Represents int value that can be passed by reference.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | public class IntReference {
29 |
30 | private final int[] num = new int[1];
31 |
32 | /**
33 | * Default constructor that sets integer to 0.
34 | */
35 | public IntReference() {
36 | this(0);
37 | }
38 |
39 | /**
40 | * Constructor that sets integer to given value.
41 | *
42 | * @param num is integer that will be stored.
43 | */
44 | public IntReference(int num) {
45 | this.num[0] = num;
46 | }
47 |
48 | /**
49 | * @return integer that is represented by this reference.
50 | */
51 | public int get() {
52 | return num[0];
53 | }
54 |
55 | /**
56 | * Increments internal integer.
57 | */
58 | public void increment() {
59 | this.num[0]++;
60 | }
61 |
62 | /**
63 | * Decrements internal integer.
64 | */
65 | public void decrement() {
66 | this.num[0]--;
67 | }
68 |
69 | /**
70 | * Sets internal integer to given value.
71 | *
72 | * @param num is value.
73 | */
74 | public void set(int num) {
75 | this.num[0] = num;
76 | }
77 |
78 | /**
79 | * Checks if internal integer equals to another int.
80 | *
81 | * @return true if internal integer equals to passed value.
82 | */
83 | public boolean equals(int num) {
84 | return this.num[0] == num;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDSeparation.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.pd.PDResources;
26 | import org.verapdf.pd.function.PDFunction;
27 |
28 | /**
29 | * @author Maksim Bezrukov
30 | */
31 | public class PDSeparation extends PDSpecialColorSpace {
32 |
33 | public PDSeparation(COSObject obj) {
34 | this(obj, null, false);
35 | }
36 |
37 | public PDSeparation(COSObject obj, PDResources resources, boolean wasDefault) {
38 | super(obj, resources, wasDefault);
39 | }
40 |
41 | public COSObject getColorantName() {
42 | return getObject().at(1);
43 | }
44 |
45 | public PDColorSpace getAlternate() {
46 | return super.getBaseColorSpace();
47 | }
48 |
49 | public COSObject getCosTintTransform() {
50 | return getObject().at(3);
51 | }
52 |
53 | public PDFunction getTintTransform() {
54 | return PDFunction.createFunction(getCosTintTransform());
55 | }
56 |
57 | @Override
58 | COSObject getBaseColorSpaceObject() {
59 | return getObject().at(2);
60 | }
61 |
62 | @Override
63 | public int getNumberOfComponents() {
64 | return 1;
65 | }
66 |
67 | @Override
68 | public ASAtom getType() {
69 | return ASAtom.SEPARATION;
70 | }
71 |
72 | @Override
73 | public double[] toRGB(double[] value) {
74 | double[] altColor = getDoubleArrayResult(value, getTintTransform());
75 | return getAlternate().toRGB(altColor);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/cos/COSEmbeddedFileDict.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos;
22 |
23 | import org.verapdf.as.ASAtom;
24 |
25 | import java.util.ArrayList;
26 | import java.util.Collections;
27 | import java.util.List;
28 |
29 | /**
30 | * Represents embedded file dictionary accessible via EF key in a file
31 | * specification dictionary (see PDF 32000-2008, table 44).
32 | *
33 | * @author Sergey Shemyakov
34 | */
35 | public class COSEmbeddedFileDict {
36 |
37 | private final COSDictionary dictionary;
38 | private static final List DEFINED_FILE_KEYS;
39 |
40 | static {
41 | DEFINED_FILE_KEYS = new ArrayList<>();
42 | DEFINED_FILE_KEYS.add(ASAtom.F);
43 | DEFINED_FILE_KEYS.add(ASAtom.UF);
44 | DEFINED_FILE_KEYS.add(ASAtom.DOS);
45 | DEFINED_FILE_KEYS.add(ASAtom.MAC);
46 | DEFINED_FILE_KEYS.add(ASAtom.UNIX);
47 | }
48 |
49 | public COSEmbeddedFileDict(COSDictionary dictionary) {
50 | this.dictionary = dictionary;
51 | }
52 |
53 | /**
54 | * @return a list of streams for available embedded files.
55 | */
56 | public List getEmbeddedFileStreams() {
57 | List res = new ArrayList<>();
58 | for (ASAtom fileKey : DEFINED_FILE_KEYS) {
59 | COSObject fileStream = dictionary.getKey(fileKey);
60 | if (!fileStream.empty() && fileStream.getType() == COSObjType.COS_STREAM) {
61 | res.add((COSStream) fileStream.getDirectBase());
62 | }
63 | }
64 | return Collections.unmodifiableList(res);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/colors/PDLab.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.colors;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.tools.TypeConverter;
26 |
27 | /**
28 | * @author Maksim Bezrukov
29 | */
30 | public class PDLab extends PDCIEDictionaryBased {
31 |
32 | public PDLab() {
33 | }
34 |
35 | public PDLab(COSObject obj) {
36 | super(obj);
37 | }
38 |
39 | public PDLab(double[] whitepoint) {
40 | fillWhitepointCache(whitepoint);
41 | }
42 |
43 | @Override
44 | public int getNumberOfComponents() {
45 | return 3;
46 | }
47 |
48 | @Override
49 | public ASAtom getType() {
50 | return ASAtom.LAB;
51 | }
52 |
53 | // See ISO 32000-2:2020, chapter 8.6.5.4
54 | @Override
55 | public double[] toRGB(double[] value) {
56 | double lstar = (value[0] + 16d) * (1d / 116d);
57 | double x = wpX * inverse(lstar + value[1] * (1d / 500d));
58 | double y = wpY * inverse(lstar);
59 | double z = wpZ * inverse(lstar - value[2] * (1d / 200d));
60 | return convXYZtoRGB(x, y, z);
61 | }
62 |
63 | public double[] getRange() {
64 | double[] res = TypeConverter.getRealArray(this.dictionary.getKey(ASAtom.RANGE), 4, "Range");
65 | return res != null ? res : new double[]{-100, 100, -100, 100};
66 | }
67 |
68 | private double inverse(double x) {
69 | if (x > 6.0 / 29.0) {
70 | return x * x * x;
71 | } else {
72 | return (108d / 841d) * (x - (4d / 29d));
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/CIDInterval.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | /**
24 | * This class represents continuous interval of CIDs with increasing values.
25 | *
26 | * @author Sergey Shemyakov
27 | */
28 | class CIDInterval implements CIDMappable {
29 |
30 | private final int intervalStart;
31 | private final int intervalEnd;
32 | protected final int startingCID;
33 |
34 | CIDInterval(int intervalStart, int intervalEnd, int startingCID) {
35 | this.intervalStart = intervalStart;
36 | this.intervalEnd = intervalEnd;
37 | this.startingCID = startingCID;
38 | }
39 |
40 | /**
41 | * Method checks if given character belongs to this particular CID interval.
42 | *
43 | * @param character is code of character to be checked.
44 | * @return true if CID for character can be found in this CID interval.
45 | */
46 | public boolean contains(int character) {
47 | return character >= intervalStart && character <= intervalEnd;
48 | }
49 |
50 | /**
51 | * Method returns CID for given character on condition it lies inside this
52 | * interval.
53 | *
54 | * @param character is code of character.
55 | * @return CID of given character.
56 | */
57 | @Override
58 | public int getCID(int character) {
59 | if (!contains(character)) {
60 | return -1;
61 | }
62 | return startingCID + character - intervalStart;
63 | }
64 |
65 | @Override
66 | public int getMaxCID() {
67 | return startingCID + intervalEnd - intervalStart;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/structure/StructureElementAccessObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.structure;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObjType;
25 | import org.verapdf.cos.COSObject;
26 |
27 | /**
28 | * Class contains methods to access structure elements knowing structParents and
29 | * MCID or knowing structParent.
30 | *
31 | * @author Sergey Shemyakov
32 | */
33 | public class StructureElementAccessObject {
34 |
35 | private Long structParent;
36 | private Long structParents;
37 |
38 | public StructureElementAccessObject(COSObject object) {
39 | if (object != null) {
40 | this.structParent = object.getIntegerKey(ASAtom.STRUCT_PARENT);
41 | this.structParents = object.getIntegerKey(ASAtom.STRUCT_PARENTS);
42 | }
43 | }
44 |
45 | public COSObject getStructureElement(PDNumberTreeNode parentTreeRoot, Long mcid) {
46 | if (structParent != null) {
47 | return parentTreeRoot.getObject(structParent);
48 | }
49 | if (mcid != null && mcid > -1 && structParents != null) {
50 | COSObject parents = parentTreeRoot.getObject(structParents);
51 | if (parents != null && !parents.empty() && parents.getType() == COSObjType.COS_ARRAY &&
52 | parents.size() > mcid) {
53 | return parents.at(mcid.intValue());
54 | }
55 | }
56 | return null;
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | int result = structParent != null ? structParent.hashCode() : 0;
62 | result = 31 * result + (structParents != null ? structParents.hashCode() : 0);
63 | return result;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/tools/resource/FileResourceHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.tools.resource;
22 |
23 | import java.io.Closeable;
24 | import java.io.IOException;
25 | import java.util.HashSet;
26 | import java.util.List;
27 | import java.util.Set;
28 |
29 | /**
30 | * Class that handles resource closing.
31 | *
32 | * @author Sergey Shemyakov
33 | */
34 | public class FileResourceHandler implements Closeable {
35 |
36 | private final Set resources;
37 |
38 | public FileResourceHandler() {
39 | this.resources = new HashSet<>();
40 | }
41 |
42 | /**
43 | * Adds resource for closing.
44 | *
45 | * @param obj is a file stream closer to be stored.
46 | */
47 | public void addResource(ASFileStreamCloser obj) {
48 | if (obj != null) {
49 | Closeable resource = obj.getStream();
50 | if (resource != null) {
51 | resources.add(obj);
52 | }
53 | }
54 | }
55 |
56 | /**
57 | * Adds resource for closing.
58 | *
59 | * @param res is a closeable object to be stored.
60 | */
61 | public void addResource(Closeable res) {
62 | if (res != null) {
63 | resources.add(res);
64 | }
65 | }
66 |
67 | /**
68 | * Closes all stored resources.
69 | */
70 | @Override
71 | public void close() throws IOException {
72 | for (Closeable obj : resources) {
73 | obj.close();
74 | }
75 | }
76 |
77 | /**
78 | * Adds all closeable objects from given list to handler.
79 | * @param resources
80 | */
81 | public void addAll(List resources) {
82 | this.resources.addAll(resources);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/patterns/PDShading.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.patterns;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSObject;
25 | import org.verapdf.factory.colors.ColorSpaceFactory;
26 | import org.verapdf.pd.PDResource;
27 | import org.verapdf.pd.PDResources;
28 | import org.verapdf.pd.colors.PDColorSpace;
29 | import org.verapdf.tools.TypeConverter;
30 |
31 | import java.util.logging.Level;
32 | import java.util.logging.Logger;
33 |
34 | /**
35 | * @author Maksim Bezrukov
36 | */
37 | public class PDShading extends PDResource {
38 |
39 | private static final Logger LOGGER = Logger.getLogger(PDShading.class.getCanonicalName());
40 |
41 | private final PDResources resources;
42 |
43 | public PDShading(COSObject obj, PDResources resources) {
44 | super(obj);
45 | this.resources = resources;
46 | }
47 |
48 | public int getShadingType() {
49 | Long type = getObject().getIntegerKey(ASAtom.SHADING_TYPE);
50 | if (type != null) {
51 | return type.intValue();
52 | }
53 | LOGGER.log(Level.FINE, "Shading object do not contain required key ShadingType");
54 | return 0;
55 | }
56 |
57 | public PDColorSpace getColorSpace() {
58 | COSObject obj = getObject().getKey(ASAtom.COLORSPACE);
59 | if (obj != null && !obj.empty()) {
60 | return ColorSpaceFactory.getColorSpace(obj, this.resources, false);
61 | }
62 | LOGGER.log(Level.FINE,"Shading object do not contain required key ColorSpace");
63 | return null;
64 | }
65 |
66 | public double[] getBBox() {
67 | return TypeConverter.getRealArray(getKey(ASAtom.BBOX), 4, "BBox");
68 | }
69 |
70 | public boolean getAntiAlias() {
71 | Boolean antiAlias = getObject().getBooleanKey(ASAtom.ANTI_ALIAS);
72 | return antiAlias == null ? false : antiAlias.booleanValue();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/truetype/TrueTypeHheaTable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.verapdf.io.SeekableInputStream;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * This class does parsing of True Type "hhea" table and extracts all the data
29 | * needed.
30 | *
31 | * @author Sergey Shemyakov
32 | */
33 | class TrueTypeHheaTable extends TrueTypeTable {
34 |
35 | private int numberOfHMetrics;
36 | private int ascender;
37 | private int descender;
38 |
39 | TrueTypeHheaTable(SeekableInputStream source, long offset) {
40 | super(source, offset);
41 | }
42 |
43 | @Override
44 | void readTable() throws IOException {
45 | long startingOffset = this.source.getOffset();
46 | this.source.seek(this.offset);
47 | this.source.skip(4); // version
48 | this.ascender = this.readFWord();
49 | this.descender = this.readFWord();
50 | this.source.skip(2 + // line gap
51 | 2 + // advanceWidthMax
52 | 2 + // minLeftSideBearing
53 | 2 + // minRightSideBearing
54 | 2 + // xMaxExtent
55 | 2 + // caretSlopeRise
56 | 2 + // caretSlopeRun
57 | 10 + // reserved
58 | 2 // metricDataFormat
59 | );
60 | this.numberOfHMetrics = this.readUShort();
61 | this.source.seek(startingOffset);
62 | }
63 |
64 | int getNumberOfHMetrics() {
65 | return numberOfHMetrics;
66 | }
67 |
68 | public int getAscender() {
69 | return ascender;
70 | }
71 |
72 | public int getDescender() {
73 | return descender;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/.github/workflows/test-pr.yml:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of veraPDF Parser, a module of the veraPDF project.
3 | # Copyright (c) 2015-2025, veraPDF Consortium
4 | # All rights reserved.
5 | #
6 | # veraPDF Parser is free software: you can redistribute it and/or modify
7 | # it under the terms of either:
8 | #
9 | # The GNU General public license GPLv3+.
10 | # You should have received a copy of the GNU General Public License
11 | # along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | # tree. If not, see http://www.gnu.org/licenses/ or
13 | # https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | #
15 | # The Mozilla Public License MPLv2+.
16 | # You should have received a copy of the Mozilla Public License along with
17 | # veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | # If a copy of the MPL was not distributed with this file, you can obtain one at
19 | # http://mozilla.org/MPL/2.0/.
20 | #
21 |
22 | name: PR QA
23 |
24 | on:
25 | pull_request:
26 | types: [opened, synchronize, reopened]
27 |
28 | jobs:
29 | build:
30 | name: Checkout and Build
31 | runs-on: ubuntu-latest
32 |
33 | strategy:
34 | fail-fast: false
35 | matrix:
36 | java-version: [8, 11, 17, 21, 25]
37 |
38 | steps:
39 | - uses: actions/checkout@v5
40 | - name: JDK setup
41 | uses: actions/setup-java@v5
42 | continue-on-error: true
43 | with:
44 | java-version: ${{ matrix.java-version }}
45 | distribution: 'temurin'
46 | cache: maven
47 | - name: Build with Maven
48 | run: mvn --batch-mode --update-snapshots verify
49 | - name: Upload coverage report
50 | if: matrix.java-version == 8
51 | uses: actions/upload-artifact@master
52 | with:
53 | name: coverage-report
54 | path: target/site/jacoco/
55 | coverage:
56 | name: Quality Assurance
57 | runs-on: ubuntu-latest
58 | needs: [ build ]
59 |
60 | steps:
61 | - name: Download coverage report
62 | uses: actions/download-artifact@master
63 | with:
64 | name: coverage-report
65 | path: target/site/jacoco/
66 | - name: Codecov coverage reporting
67 | uses: codecov/codecov-action@v2
68 | with:
69 | files: target/site/jacoco/jacoco.xml
70 | fail_ci_if_error: true # optional (default = false)
71 | verbose: true # optional (default = false)
72 | token: ${{ secrets.CODECOV_TOKEN }}
73 | - name: Codacy coverage reporting
74 | uses: codacy/codacy-coverage-reporter-action@v1
75 | with:
76 | project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
77 | coverage-reports: target/site/jacoco/jacoco.xml
78 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/parser/postscript/PSProcedure.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.parser.postscript;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSArray;
25 | import org.verapdf.cos.COSObject;
26 |
27 | import java.util.Map;
28 | import java.util.Stack;
29 |
30 | /**
31 | * Class represents PostScript procedure. Notice that when it is read from
32 | * PostScript program it is pushed to operand stack for later invocation.
33 | *
34 | * @author Sergey Shemyakov
35 | */
36 | public class PSProcedure extends PSObject {
37 |
38 | private final COSArray procedure;
39 |
40 | public PSProcedure(COSArray procedure) {
41 | super(procedure);
42 | this.procedure = procedure;
43 | }
44 |
45 | public void executeProcedure(Stack operandStack,
46 | Map userDict) throws PostScriptException {
47 | for (COSObject obj : procedure) {
48 | PSObject.getPSObject(obj).execute(operandStack, userDict);
49 | }
50 | }
51 |
52 | @Override
53 | public void execute(Stack operandStack,
54 | Map userDict) {
55 | operandStack.push(this);
56 | }
57 |
58 | public Stack modifiedExecuteProcedure(Stack operandStack,
59 | Map userDict) throws PostScriptException {
60 | for (COSObject obj : procedure) {
61 | if (obj != null) {
62 | if (obj instanceof PSOperator) {
63 | ((PSOperator) obj).execute(operandStack, userDict);
64 | } else {
65 | operandStack.push(obj);
66 | }
67 | }
68 | }
69 | return operandStack;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/pd/font/truetype/TrueTypeParserTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.truetype;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.as.ASAtom;
25 | import org.verapdf.cos.COSName;
26 | import org.verapdf.cos.COSObject;
27 | import org.verapdf.io.InternalInputStream;
28 | import org.verapdf.tools.StaticResources;
29 |
30 | import java.io.IOException;
31 |
32 | import static org.junit.Assert.assertEquals;
33 |
34 | /**
35 | * @author Sergey Shemyakov
36 | */
37 | public class TrueTypeParserTest {
38 |
39 | private static final String MONO_FONT_PATH = "src/test/resources/org/verapdf/pd/font/truetype/SourceCodePro-Bold.ttf";
40 | private static final String REGULAR_FONT_PATH = "src/test/resources/org/verapdf/pd/font/truetype/LiberationSans-Regular.ttf";
41 | private static final boolean IS_SYMBOLIC = false;
42 | private static final COSObject ENCODING = COSName.construct(ASAtom.MAC_ROMAN_ENCODING);
43 |
44 | @Test
45 | public void testMonospaced() throws IOException {
46 |
47 | TrueTypeFontProgram font = new TrueTypeFontProgram(new InternalInputStream(MONO_FONT_PATH, 2),
48 | IS_SYMBOLIC, ENCODING, null);
49 | font.parseFont();
50 | assertEquals(600f, font.getWidth("z"), 0.0);
51 | assertEquals(1000f, font.getWidth("yakute"), 0.0);
52 | }
53 |
54 | @Test
55 | public void testRegular() throws IOException {
56 | StaticResources.clear();
57 | TrueTypeFontProgram font = new TrueTypeFontProgram(new InternalInputStream(REGULAR_FONT_PATH, 2),
58 | IS_SYMBOLIC, ENCODING, null);
59 | font.parseFont();
60 | assertEquals(500, (int) font.getWidth("z"));
61 | assertEquals(556, (int) font.getWidth("zero"));
62 | assertEquals(365, (int) font.getWidth("yakute"));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/font/cmap/CMapFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.font.cmap;
22 |
23 | import org.verapdf.as.io.ASInputStream;
24 | import org.verapdf.parser.postscript.PostScriptException;
25 | import org.verapdf.tools.StaticResources;
26 |
27 | import java.io.IOException;
28 | import java.util.logging.Level;
29 | import java.util.logging.Logger;
30 |
31 | /**
32 | * Class controls CMap parsing and caches all CMaps read.
33 | *
34 | * @author Sergey Shemyakov
35 | */
36 | class CMapFactory {
37 | private static final Logger LOGGER = Logger.getLogger(CMapFactory.class.getCanonicalName());
38 |
39 | private CMapFactory() {
40 | // Do nothing here
41 | }
42 |
43 | /**
44 | * Parses CMap from given stream with caching it.
45 | *
46 | * @param name is a string identifier of cMap that is used for caching.
47 | * @param cMapStream is stream with cMap data.
48 | * @return parsed cMap object.
49 | */
50 | static CMap getCMap(String name, ASInputStream cMapStream) {
51 | CMap res;
52 | if (!name.isEmpty()) {
53 | res = StaticResources.getCMap(name);
54 | if (res != null) {
55 | return res;
56 | }
57 | }
58 | try {
59 | CMapParser parser = new CMapParser(cMapStream);
60 | parser.parse();
61 | res = parser.getCMap();
62 | } catch (IOException e) {
63 | LOGGER.log(Level.WARNING, "Can't parse CMap " + name + ", using default", e);
64 | res = new CMap();
65 | } catch (PostScriptException e) {
66 | LOGGER.log(Level.WARNING, "PostScript exception while parsing CMap " + name);
67 | res = new CMap();
68 | }
69 |
70 | StaticResources.cacheCMap(name, res);
71 | return res;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/org/verapdf/cos/filters/COSFilterFlateEncodeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.cos.filters;
22 |
23 | import org.junit.Test;
24 | import org.verapdf.io.InternalInputStream;
25 | import org.verapdf.io.InternalOutputStream;
26 | import org.verapdf.pd.PDDocument;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.util.Arrays;
31 |
32 | /**
33 | * @author Sergey Shemyakov
34 | */
35 | public class COSFilterFlateEncodeTest {
36 |
37 | private static final String FILE_PATH =
38 | "src/test/resources/org/verapdf/cos/filters/validDocument.pdf";
39 |
40 | @Test
41 | public void test() throws IOException {
42 |
43 | byte[] toEncode = getDataToEncode();
44 | File encodedPDF = File.createTempFile("tmp_pdf_file", ".pdf");
45 | encodedPDF.deleteOnExit();
46 | encodePDF(toEncode, encodedPDF);
47 | InternalInputStream inputStream = new InternalInputStream(encodedPDF.getAbsolutePath());
48 | COSFilterFlateDecode decoder = new COSFilterFlateDecode(inputStream);
49 | PDDocument doc = new PDDocument(decoder);
50 | decoder.close();
51 | doc.close();
52 | encodedPDF.delete();
53 | }
54 |
55 | private byte[] getDataToEncode() throws IOException {
56 | byte[] file = new byte[20000];
57 | InternalInputStream stream = new InternalInputStream(FILE_PATH, 2);
58 | int length = stream.read(file, 20000);
59 | stream.close();
60 | return Arrays.copyOf(file, length);
61 | }
62 |
63 | private void encodePDF(byte[] toEncode, File encodedPDF) throws IOException {
64 | InternalOutputStream outputStream = new InternalOutputStream(encodedPDF.getAbsolutePath());
65 | COSFilterFlateEncode filter = new COSFilterFlateEncode(outputStream);
66 | filter.write(toEncode);
67 | filter.close();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | veraPDF-parser
2 | ==============
3 | *Greenfield PDF parser developed for veraPDF*
4 |
5 | [](https://jenkins.openpreservation.org/job/veraPDF/job/1.29/job/parser/ "OPF Jenkins")
6 | [](https://repo1.maven.org/maven2/org/verapdf/parser/ "Maven central")
7 | [](https://codecov.io/gh/veraPDF/veraPDF-parser/ "CodeCov coverage")
8 | [](https://app.codacy.com/gh/veraPDF/veraPDF-parser/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade "Codacy coverage")
9 |
10 | [](https://github.com/veraPDF/veraPDF-library/issues "Open issues on GitHub")
11 | [](https://github.com/veraPDF/veraPDF-library/issues?q=is%3Aissue+is%3Aclosed "Closed issues on GitHub")
12 | [](https://github.com/veraPDF/veraPDF-parser/pulls "Open pull requests on GitHub")
13 | [](https://github.com/veraPDF/veraPDF-parser/pulls?q=is%3Apr+is%3Aclosed "Closed pull requests on GitHub")
14 |
15 | Licensing
16 | ---------
17 | The veraPDF Parser is dual-licensed, see:
18 |
19 | - [GPLv3+](LICENSE.GPL "GNU General Public License, version 3")
20 | - [MPLv2+](LICENSE.MPL "Mozilla Public License, version 2.0")
21 |
22 | Documentation
23 | -------------
24 | See the [veraPDF documentation site](https://docs.verapdf.org/).
25 |
26 | Quick Start
27 | -----------
28 | ### Pre-requisites
29 |
30 | In order to build the parser you'll need:
31 |
32 | * Java 8, 11, 17, 21 or 25, which can be downloaded [from Oracle](https://www.oracle.com/technetwork/java/javase/downloads/index.html), or for Linux users [OpenJDK](http://openjdk.java.net/install/index.html).
33 | * [Maven v3+](https://maven.apache.org/)
34 |
35 | ### Building the veraPDF Parser
36 |
37 | 1. Download the veraPDF-model repository, either: `git clone https://github.com/veraPDF/veraPDF-parser`
38 | or download the [latest tar archive](https://github.com/veraPDF/veraPDF-parser/archive/integration.tar.gz "veraPDF-parser latest GitHub tar archive") or [zip equivalent](https://github.com/veraPDF/veraPDF-parser/archive/integration.zip "veraPDF-parser latest GitHub zip archive") from GitHub.
39 | 2. Move to the downloaded project directory, e.g. `cd veraPDF-parser`
40 | 3. Build and install using Maven: `mvn clean install`
41 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/PDPageTree.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd;
22 |
23 | import org.verapdf.cos.COSObject;
24 |
25 | /**
26 | * @author Timur Kamalov
27 | */
28 | public class PDPageTree {
29 |
30 | private PDPageTreeBranch root;
31 |
32 | public PDPageTree() {
33 | this.root = new PDPageTreeBranch();
34 | }
35 |
36 | public PDPageTree(final COSObject object) {
37 | this.root = new PDPageTreeBranch(object);
38 | }
39 |
40 | public PDPageTreeBranch getRoot() {
41 | return root;
42 | }
43 |
44 | public COSObject getObject() {
45 | return this.root.getObject();
46 | }
47 |
48 | public void setObject(final COSObject object) {
49 | this.root.setObject(object);
50 | }
51 |
52 | public boolean empty() {
53 | return this.root.empty();
54 | }
55 |
56 | public int getPageCount() {
57 | return this.root.getLeafCount();
58 | }
59 |
60 | public PDPage getPage(final int index) {
61 | try {
62 | if (index < this.getPageCount()) {
63 | final PDPage page = this.root.findTerminalPDPage(index);
64 | if (page != null) {
65 | page.pageNumber = index;
66 | page.pagesTotal = index;
67 | }
68 | return page;
69 | } else {
70 | return null;
71 | }
72 | } catch (IndexOutOfBoundsException e) {
73 | throw new IndexOutOfBoundsException("Invalid page tree");
74 | }
75 | }
76 |
77 | public PDPage newPage(final int insertAt) {
78 | final PDPage page = new PDPage(null);
79 | if (this.addPage(page, insertAt)) {
80 | page.pageNumber = (insertAt == -1 ? this.getPageCount() - 1 : insertAt);
81 | }
82 | return page;
83 | }
84 |
85 | public boolean addPage(final PDPage page, final int insertAt) {
86 | final PDPageTreeBranch branch = this.root.findTerminal(insertAt);
87 |
88 | if (branch.insertLeaf(page, insertAt)) {
89 | this.root = this.root.getParent();
90 | return true;
91 | }
92 | return false;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/filters/ASOutFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.as.filters;
22 |
23 | import org.verapdf.as.io.ASInputStream;
24 | import org.verapdf.as.io.ASOutputStream;
25 |
26 | import java.io.IOException;
27 |
28 | /**
29 | * Base class for output filters.
30 | *
31 | * @author Timur Kamalov
32 | */
33 | public abstract class ASOutFilter implements ASOutputStream {
34 |
35 | private ASOutputStream storedOutputStream;
36 |
37 | protected ASOutFilter(final ASOutputStream outStream) {
38 | this.storedOutputStream = outStream;
39 | }
40 |
41 | protected ASOutputStream getStoredOutputStream() {
42 | return this.storedOutputStream;
43 | }
44 |
45 | private ASOutFilter(final ASOutFilter filter) {
46 | close();
47 | }
48 |
49 | /**
50 | * {@inheritDoc}
51 | */
52 | @Override
53 | public long write(final byte[] buffer) throws IOException {
54 | return this.storedOutputStream != null ?
55 | this.storedOutputStream.write(buffer) : 0;
56 | }
57 |
58 | /**
59 | * {@inheritDoc}
60 | */
61 | @Override
62 | public long write(final byte[] buffer, int offset, int size) throws IOException {
63 | return this.storedOutputStream != null ?
64 | this.storedOutputStream.write(buffer, offset, size) : 0;
65 | }
66 |
67 | /**
68 | * {@inheritDoc}
69 | */
70 | @Override
71 | public long write(ASInputStream stream) throws IOException {
72 | return this.storedOutputStream != null ?
73 | this.storedOutputStream.write(stream) : 0;
74 | // byte[] buf = new byte[ASBufferedInFilter.BF_BUFFER_SIZE];
75 | // int read = stream.read(buf, buf.length);
76 | // int res = 0;
77 | // while (read != -1) {
78 | // this.write(buf, 0, read);
79 | // res += read;
80 | // read = stream.read(buf, buf.length);
81 | // }
82 | // return res;
83 | }
84 |
85 | /**
86 | * {@inheritDoc}
87 | */
88 | @Override
89 | public void close() {
90 | this.storedOutputStream = null;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/pd/patterns/PDPattern.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.pd.patterns;
22 |
23 | import org.verapdf.as.ASAtom;
24 | import org.verapdf.cos.COSName;
25 | import org.verapdf.cos.COSObject;
26 | import org.verapdf.factory.colors.ColorSpaceFactory;
27 | import org.verapdf.pd.PDResources;
28 | import org.verapdf.pd.colors.PDColorSpace;
29 |
30 | /**
31 | * @author Maksim Bezrukov
32 | */
33 | public class PDPattern extends PDColorSpace {
34 |
35 | public static final PDPattern INSTANCE = new PDPattern(COSName.construct(ASAtom.PATTERN));
36 |
37 | public static final int TYPE_PATTERN = 0;
38 | public static final int TYPE_TILING_PATTERN = 1;
39 | public static final int TYPE_SHADING_PATTERN = 2;
40 |
41 | private PDColorSpace underlyingColorSpace = null;
42 |
43 | protected PDPattern(COSObject obj) {
44 | super(obj);
45 | }
46 |
47 | private PDPattern(COSObject obj, PDColorSpace underlyingColorSpace) {
48 | super(obj);
49 | this.underlyingColorSpace = underlyingColorSpace;
50 | }
51 |
52 | public static PDPattern createPattern(COSObject underlyingColorSpace, PDResources resources) {
53 | if (underlyingColorSpace == null || underlyingColorSpace.empty()) {
54 | return INSTANCE;
55 | }
56 | return new PDPattern(COSName.construct(ASAtom.PATTERN), ColorSpaceFactory.getColorSpace(underlyingColorSpace, resources));
57 | }
58 |
59 | @Override
60 | public int getNumberOfComponents() {
61 | return -1;
62 | }
63 |
64 | @Override
65 | public ASAtom getType() {
66 | return ASAtom.PATTERN;
67 | }
68 |
69 | @Override
70 | public double[] toRGB(double[] value) {
71 | return null;
72 | }
73 |
74 | public int getPatternType() {
75 | return TYPE_PATTERN;
76 | }
77 |
78 | public PDColorSpace getUnderlyingColorSpace() {
79 | return underlyingColorSpace;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/verapdf/as/io/ASInputStreamWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of veraPDF Parser, a module of the veraPDF project.
3 | * Copyright (c) 2015-2025, veraPDF Consortium
4 | * All rights reserved.
5 | *
6 | * veraPDF Parser is free software: you can redistribute it and/or modify
7 | * it under the terms of either:
8 | *
9 | * The GNU General public license GPLv3+.
10 | * You should have received a copy of the GNU General Public License
11 | * along with veraPDF Parser as the LICENSE.GPL file in the root of the source
12 | * tree. If not, see http://www.gnu.org/licenses/ or
13 | * https://www.gnu.org/licenses/gpl-3.0.en.html.
14 | *
15 | * The Mozilla Public License MPLv2+.
16 | * You should have received a copy of the Mozilla Public License along with
17 | * veraPDF Parser as the LICENSE.MPL file in the root of the source tree.
18 | * If a copy of the MPL was not distributed with this file, you can obtain one at
19 | * http://mozilla.org/MPL/2.0/.
20 | */
21 | package org.verapdf.as.io;
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * Class represents ASInputStream that can be constructed from another
27 | * ASInputStream.
28 | *
29 | * @author Sergey Shemyakov
30 | */
31 | public class ASInputStreamWrapper extends ASInputStream {
32 |
33 | private final ASInputStream stream;
34 |
35 | public ASInputStreamWrapper(ASInputStream stream) {
36 | stream.incrementResourceUsers();
37 | this.stream = stream;
38 | }
39 |
40 | @Override
41 | public int read() throws IOException {
42 | return this.stream.read();
43 | }
44 |
45 | @Override
46 | public int read(byte[] buffer, int size) throws IOException {
47 | return this.stream.read(buffer, size);
48 | }
49 |
50 | @Override
51 | public int read(byte[] b, int off, int len) throws IOException {
52 | return this.stream.read(b, off, len);
53 | }
54 |
55 | @Override
56 | public int skip(int size) throws IOException {
57 | return this.stream.skip(size);
58 | }
59 |
60 | @Override
61 | public void reset() throws IOException {
62 | this.stream.reset();
63 | }
64 |
65 | @Override
66 | public void closeResource() throws IOException {
67 | this.stream.closeResource();
68 | }
69 |
70 | @Override
71 | public void close() throws IOException {
72 | if (!isClosed) {
73 | decrementResourceUsers();
74 | isClosed = true;
75 | if (this.stream.resourceUsers.equals(0)) {
76 | this.stream.close();
77 | }
78 | }
79 | }
80 |
81 | @Override
82 | public void incrementResourceUsers() {
83 | this.stream.incrementResourceUsers();
84 | }
85 |
86 | @Override
87 | public void decrementResourceUsers() {
88 | this.stream.decrementResourceUsers();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------