Skip to content
Commits on Source (3)
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
......@@ -175,28 +178,126 @@
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
EXTERNAL COMPONENTS
SAMBox includes a number of components with separate copyright notices
and license terms. Your use of these components is subject to the terms and
conditions of the following licenses.
Contributions made to the original PDFBox and FontBox projects:
Copyright (c) 2002-2007, www.pdfbox.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of pdfbox; nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Adobe Font Metrics (AFM) for PDF Core 14 Fonts
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.
CMaps for PDF Fonts (http://opensource.adobe.com/wiki/display/cmap/Downloads)
Copyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
OSXAdapter
Version: 2.0
Disclaimer: IMPORTANT: This Apple software is supplied to you by
Apple Inc. ("Apple") in consideration of your agreement to the
following terms, and your use, installation, modification or
redistribution of this Apple software constitutes acceptance of these
terms. If you do not agree with these terms, please do not use,
install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc.
may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
libsambox-java (1.1.46-1) unstable; urgency=medium
* New upstream version 1.1.46.
-- Markus Koschany <apo@debian.org> Sat, 22 Dec 2018 12:22:05 +0100
libsambox-java (1.1.41-1) unstable; urgency=medium
* New upstream version 1.1.41.
......
......@@ -5,7 +5,7 @@
<artifactId>sambox</artifactId>
<packaging>jar</packaging>
<name>sambox</name>
<version>1.1.41</version>
<version>1.1.46</version>
<description>An Apache PDFBox fork intended to be used as PDF processor for Sejda and PDFsam related projects</description>
<url>http://www.sejda.org</url>
......@@ -33,7 +33,7 @@
<connection>scm:git:git@github.com:torakiki/sambox.git</connection>
<developerConnection>scm:git:git@github.com:torakiki/sambox.git</developerConnection>
<url>scm:git:git@github.com:torakiki/sambox.git</url>
<tag>v1.1.41</tag>
<tag>v1.1.46</tag>
</scm>
<developers>
......@@ -214,6 +214,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.sejda.sambox</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -233,7 +240,8 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx768m -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider</argLine>
<argLine>-Xmx768m
-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider</argLine>
<excludes>
<exclude>org/sejda/sambox/rendering/TestPDFToImage.java</exclude>
</excludes>
......@@ -241,7 +249,8 @@
<reuseForks>false</reuseForks>
</configuration>
</plugin>
<!-- PDFBOX-3974: download test files from JIRA and keep them in repository cache -->
<!-- PDFBOX-3974: download test files from JIRA and keep them in repository
cache -->
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
......@@ -406,18 +415,18 @@
</configuration>
</execution>
<execution>
<id>PDFBOX-4184</id>
<id>PDFBOX-4184-2</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://www.crh.noaa.gov/Image/gjt/images/ImageGallery/Uncompahgre_small.jpg</url>
<!-- file is also 032163.jpg
from http://downloads.digitalcorpora.org/corpora/files/govdocs1/zipfiles/032.zip -->
<url>https://issues.apache.org/jira/secure/attachment/12929821/16bit.png</url>
<!-- originally from https://github.com/danfickle/openhtmltopdf/issues/173
see "blurred" image link https://user-images.githubusercontent.com/29379074/36145630-f304cd0e-10d7-11e8-942c-66eb8040be70.png -->
<outputDirectory>${project.build.directory}/imgs</outputDirectory>
<outputFileName>PDFBOX-4184-032163.jpg</outputFileName>
<sha512>35241c979d3808ca9d2641b5ec5e40637132b313f75070faca8b8f6d00ddce394070414236db3993f1092fe3bc16995750d528b6d803a7851423c14c308ccdde</sha512>
<outputFileName>PDFBOX-4184-16bit.png</outputFileName>
<sha512>45f148913590ea1a94c3ac17080969b74e579fe51967a5bf535caa3f7104ea81ee222b99deb8ee528b0a53640f97d87cf668633a1bdd61a62092246df1807471</sha512>
</configuration>
</execution>
</executions>
......@@ -439,7 +448,7 @@
<dependency>
<groupId>org.sejda</groupId>
<artifactId>sejda-io</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
......@@ -449,7 +458,7 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
<version>2.0.11</version>
<version>2.0.12</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
......@@ -472,7 +481,7 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
......
......@@ -454,7 +454,8 @@ public class COSArray extends COSBase implements List<COSBase>
float[] retval = new float[size()];
for (int i = 0; i < size(); i++)
{
retval[i] = ((COSNumber) getObject(i)).floatValue();
retval[i] = ofNullable(getObject(i, COSNumber.class)).map(COSNumber::floatValue)
.orElse(0f);
}
return retval;
}
......
......@@ -133,6 +133,26 @@ public class COSDictionary extends COSBase
return retval;
}
/**
*
* @param firstKey
* @param secondKey
* @param clazz
* @return
* @see #getDictionaryObject(COSName, COSName)
*/
public <T extends COSBase> T getDictionaryObject(COSName firstKey, COSName secondKey,
Class<T> clazz)
{
return ofNullable(getDictionaryObject(firstKey, clazz)).orElseGet(() -> {
if (nonNull(secondKey))
{
return getDictionaryObject(secondKey, clazz);
}
return null;
});
}
/**
* Get an object from this dictionary. If the object is a reference then it will dereference it. If the object is
* COSNull then null will be returned.
......@@ -1163,9 +1183,9 @@ public class COSDictionary extends COSBase
}
/**
* This is a special case of getItem that takes multiple keys, it will handle the situation
* where multiple keys could get the same value, ie if either CS or ColorSpace is used to get
* the colorspace. This will get an object from this dictionary.
* This is a special case of getItem that takes multiple keys, it will handle the situation where multiple keys
* could get the same value, ie if either CS or ColorSpace is used to get the colorspace. This will get an object
* from this dictionary.
*
* @param firstKey The first key to try.
* @param secondKey The second key to try.
......
......@@ -49,7 +49,7 @@ public abstract class Filter
* used to compress /Flate streams. The default value is -1 which is {@link Deflater#DEFAULT_COMPRESSION}. To set
* maximum compression, use {@code System.setProperty(Filter.SYSPROP_DEFLATELEVEL, "9");}
*/
public static final String SYSPROP_DEFLATELEVEL = "org.apache.pdfbox.filter.deflatelevel";
public static final String SYSPROP_DEFLATELEVEL = "org.sejda.sambox.filter.deflatelevel";
protected Filter()
{
......@@ -149,4 +149,21 @@ public abstract class Filter
return reader;
}
/**
* @return the ZIP compression level configured for PDFBox
*/
public static int getCompressionLevel()
{
int compressionLevel = Deflater.DEFAULT_COMPRESSION;
try
{
compressionLevel = Integer
.parseInt(System.getProperty(Filter.SYSPROP_DEFLATELEVEL, "-1"));
}
catch (NumberFormatException ex)
{
LOG.warn(ex.getMessage(), ex);
}
return Math.max(-1, Math.min(Deflater.BEST_COMPRESSION, compressionLevel));
}
}
......@@ -117,17 +117,7 @@ final class FlateFilter extends Filter
public void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
throws IOException
{
int compressionLevel = Deflater.DEFAULT_COMPRESSION;
try
{
compressionLevel = Integer
.parseInt(System.getProperty(Filter.SYSPROP_DEFLATELEVEL, "-1"));
}
catch (NumberFormatException ex)
{
LOG.warn(ex.getMessage(), ex);
}
compressionLevel = Math.max(-1, Math.min(Deflater.BEST_COMPRESSION, compressionLevel));
int compressionLevel = getCompressionLevel();
Deflater deflater = new Deflater(compressionLevel);
try (DeflaterOutputStream out = new DeflaterOutputStream(encoded, deflater))
{
......
......@@ -20,7 +20,7 @@ import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferUShort;
import java.awt.image.WritableRaster;
import java.awt.image.Raster;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -55,7 +55,7 @@ public final class JPXFilter extends Filter
result.getParameters().addAll(parameters);
BufferedImage image = readJPX(encoded, result);
WritableRaster raster = image.getRaster();
Raster raster = image.getRaster();
switch (raster.getDataBuffer().getDataType())
{
case DataBuffer.TYPE_BYTE:
......
......@@ -36,9 +36,11 @@ import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.fontbox.ttf.TrueTypeFont;
import org.sejda.io.CountingWritableByteChannel;
import org.sejda.io.SeekableSources;
import org.sejda.sambox.cos.COSArray;
......@@ -106,7 +108,7 @@ public class PDDocument implements Closeable
private PDDocumentCatalog documentCatalog;
private SecurityHandler securityHandler;
private boolean open = true;
private OnClose onClose;
private OnClose onClose = () -> LOG.debug("Closing document");
private ResourceCache resourceCache = new DefaultResourceCache();
// fonts to subset before saving
......@@ -285,6 +287,18 @@ public class PDDocument implements Closeable
return new PDEncryption();
}
/**
* For internal PDFBox use when creating PDF documents: register a TrueTypeFont to make sure it is closed when the
* PDDocument is closed to avoid memory leaks. Users don't have to call this method, it is done by the appropriate
* PDFont classes.
*
* @param ttf
*/
public void registerTrueTypeFontForClosing(TrueTypeFont ttf)
{
onClose.andThen(() -> IOUtils.closeQuietly(ttf));
}
/**
* @return the list of fonts which will be subset before the document is saved.
*/
......@@ -398,7 +412,7 @@ public class PDDocument implements Closeable
public void setOnCloseAction(OnClose onClose)
{
requireOpen();
this.onClose = onClose;
this.onClose = onClose.andThen(this.onClose);
}
private void requireOpen() throws IllegalStateException
......@@ -606,11 +620,8 @@ public class PDDocument implements Closeable
*/
@Override
public void close() throws IOException
{
if (onClose != null)
{
onClose.onClose();
}
this.resourceCache.clear();
this.open = false;
}
......@@ -629,6 +640,15 @@ public class PDDocument implements Closeable
* @param onClose
*/
void onClose() throws IOException;
default OnClose andThen(OnClose after)
{
Objects.requireNonNull(after);
return () -> {
onClose();
after.onClose();
};
}
}
/**
......@@ -640,7 +660,8 @@ public class PDDocument implements Closeable
}
// bridge to pdfbox style api, used in tests
public static PDDocument load(File file) throws IOException {
public static PDDocument load(File file) throws IOException
{
return PDFParser.parse(SeekableSources.seekableSourceFrom(file));
}
......
......@@ -118,7 +118,8 @@ public class PDPageTree implements COSObjectable, Iterable<PDPage>
return value;
}
COSDictionary parent = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
COSDictionary parent = node.getDictionaryObject(COSName.PARENT, COSName.P,
COSDictionary.class);
if (parent != null)
{
return getInheritableAttribute(parent, key);
......@@ -303,7 +304,9 @@ public class PDPageTree implements COSObjectable, Iterable<PDPage>
{
if (pageNum < 0)
{
throw new PageNotFoundException("Index out of bounds: " + pageNum + " in " + getSourcePath(), pageNum, getSourcePath());
throw new PageNotFoundException(
"Index out of bounds: " + pageNum + " in " + getSourcePath(), pageNum,
getSourcePath());
}
if (isPageTreeNode(node))
......@@ -338,22 +341,25 @@ public class PDPageTree implements COSObjectable, Iterable<PDPage>
}
throw new PageNotFoundException(
"Unable to find page " + pageNum + " in " + getSourcePath(), pageNum, getSourcePath());
"Unable to find page " + pageNum + " in " + getSourcePath(), pageNum,
getSourcePath());
}
throw new PageNotFoundException(
"Index out of bounds: " + pageNum + " in " + getSourcePath(), pageNum, getSourcePath());
"Index out of bounds: " + pageNum + " in " + getSourcePath(), pageNum,
getSourcePath());
}
if (encountered == pageNum)
{
return node;
}
throw new PageNotFoundException("Unable to find page " + pageNum + " in " + getSourcePath(), pageNum, getSourcePath());
throw new PageNotFoundException("Unable to find page " + pageNum + " in " + getSourcePath(),
pageNum, getSourcePath());
}
private String getSourcePath() {
return ofNullable(getCOSObject().id())
.map(i -> i.ownerIdentifier).orElse("Unknown");
private String getSourcePath()
{
return ofNullable(getCOSObject().id()).map(i -> i.ownerIdentifier).orElse("Unknown");
}
/**
......@@ -462,14 +468,15 @@ public class PDPageTree implements COSObjectable, Iterable<PDPage>
private void remove(COSDictionary node)
{
// remove from parent's kids
COSDictionary parent = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
COSDictionary parent = node.getDictionaryObject(COSName.PARENT, COSName.P,
COSDictionary.class);
COSArray kids = parent.getDictionaryObject(COSName.KIDS, COSArray.class);
if (kids.removeObject(node))
{
// update ancestor counts
do
{
node = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
node = node.getDictionaryObject(COSName.PARENT, COSName.P, COSDictionary.class);
if (node != null)
{
node.setInt(COSName.COUNT, node.getInt(COSName.COUNT) - 1);
......
......@@ -34,6 +34,7 @@ public class PDFunctionType3 extends PDFunction
private COSArray encode = null;
private COSArray bounds = null;
private PDFunction[] functionsArray = null;
private float[] boundsValues = null;
/**
* Constructor.
......@@ -60,7 +61,8 @@ public class PDFunctionType3 extends PDFunction
@Override
public float[] eval(float[] input) throws IOException
{
//This function is known as a "stitching" function. Based on the input, it decides which child function to call.
// This function is known as a "stitching" function. Based on the input, it decides which child function to
// call.
// All functions in the array are 1-value-input functions
// See PDF Reference section 3.9.3.
PDFunction function = null;
......@@ -84,11 +86,15 @@ public class PDFunctionType3 extends PDFunction
// This doesn't make sense but it may happen ...
function = functionsArray[0];
PDRange encRange = getEncodeForParameter(0);
x = interpolate(x, domain.getMin(), domain.getMax(), encRange.getMin(), encRange.getMax());
x = interpolate(x, domain.getMin(), domain.getMax(), encRange.getMin(),
encRange.getMax());
}
else
{
float[] boundsValues = getBounds().toFloatArray();
if (boundsValues == null)
{
boundsValues = getBounds().toFloatArray();
}
int boundsSize = boundsValues.length;
// create a combined array containing the domain and the bounds values
// domain.min, bounds[0], bounds[1], ...., bounds[boundsSize-1], domain.max
......@@ -100,12 +106,13 @@ public class PDFunctionType3 extends PDFunction
// find the partition
for (int i = 0; i < partitionValuesSize - 1; i++)
{
if ( x >= partitionValues[i] &&
(x < partitionValues[i+1] || (i == partitionValuesSize - 2 && x == partitionValues[i+1])))
if (x >= partitionValues[i] && (x < partitionValues[i + 1]
|| (i == partitionValuesSize - 2 && x == partitionValues[i + 1])))
{
function = functionsArray[i];
PDRange encRange = getEncodeForParameter(i);
x = interpolate(x, partitionValues[i], partitionValues[i+1], encRange.getMin(), encRange.getMax());
x = interpolate(x, partitionValues[i], partitionValues[i + 1],
encRange.getMin(), encRange.getMax());
break;
}
}
......
......@@ -55,7 +55,6 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
*/
public static final String OWNER_CSS_2_00 = "CSS-2.00";
/**
* Default constructor.
*/
......@@ -74,10 +73,8 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
super(dictionary);
}
/**
* Gets the list numbering (ListNumbering). The default value is
* {@link PDListAttributeObject#LIST_NUMBERING_NONE}.
* Gets the list numbering (ListNumbering). The default value is {@link PDListAttributeObject#LIST_NUMBERING_NONE}.
*
* @return the list numbering
*/
......@@ -88,8 +85,7 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Sets the list numbering (ListNumbering). The value shall be one of the
* following:
* Sets the list numbering (ListNumbering). The value shall be one of the following:
* <ul>
* <li>{@link PDListAttributeObject#LIST_NUMBERING_NONE},</li>
* <li>{@link PDListAttributeObject#LIST_NUMBERING_DISC},</li>
......@@ -110,8 +106,8 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Gets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan). The default value is 1.
* Gets the number of rows in the enclosing table that shall be spanned by the cell (RowSpan). The default value is
* 1.
*
* @return the row span
*/
......@@ -121,8 +117,7 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Sets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan).
* Sets the number of rows in the enclosing table that shall be spanned by the cell (RowSpan).
*
* @param rowSpan the row span
*/
......@@ -132,8 +127,8 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Gets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan). The default value is 1.
* Gets the number of columns in the enclosing table that shall be spanned by the cell (ColSpan). The default value
* is 1.
*
* @return the column span
*/
......@@ -143,8 +138,7 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Sets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan).
* Sets the number of columns in the enclosing table that shall be spanned by the cell (ColSpan).
*
* @param colSpan the column span
*/
......@@ -154,10 +148,9 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Gets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
* Gets the headers (Headers). An array of byte strings, where each string shall be the element identifier (see the
* {@link org.sejda.sambox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()})
* for a TH structure element that shall be used as a header associated with this cell.
*
* @return the headers.
*/
......@@ -167,10 +160,9 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Sets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
* Sets the headers (Headers). An array of byte strings, where each string shall be the element identifier (see the
* {@link org.sejda.sambox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()})
* for a TH structure element that shall be used as a header associated with this cell.
*
* @param headers the headers
*/
......@@ -180,9 +172,8 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Gets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it.
* Gets the scope (Scope). It shall reflect whether the header cell applies to the rest of the cells in the row that
* contains it, the column that contains it, or both the row and the column that contain it.
*
* @return the scope
*/
......@@ -192,10 +183,9 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
}
/**
* Sets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it. The value
* shall be one of the following:
* Sets the scope (Scope). It shall reflect whether the header cell applies to the rest of the cells in the row that
* contains it, the column that contains it, or both the row and the column that contain it. The value shall be one
* of the following:
* <ul>
* <li>{@link PDTableAttributeObject#SCOPE_ROW},</li>
* <li>{@link PDTableAttributeObject#SCOPE_COLUMN}, or</li>
......@@ -229,7 +219,6 @@ public class PDExportFormatAttributeObject extends PDLayoutAttributeObject
this.setString(PDTableAttributeObject.SUMMARY, summary);
}
@Override
public String toString()
{
......
......@@ -50,7 +50,6 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
*/
public static final String SCOPE_ROW = "Row";
/**
* Default constructor.
*/
......@@ -69,10 +68,9 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
super(dictionary);
}
/**
* Gets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan). The default value is 1.
* Gets the number of rows in the enclosing table that shall be spanned by the cell (RowSpan). The default value is
* 1.
*
* @return the row span
*/
......@@ -82,8 +80,7 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Sets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan).
* Sets the number of rows in the enclosing table that shall be spanned by the cell (RowSpan).
*
* @param rowSpan the row span
*/
......@@ -93,8 +90,8 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Gets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan). The default value is 1.
* Gets the number of columns in the enclosing table that shall be spanned by the cell (ColSpan). The default value
* is 1.
*
* @return the column span
*/
......@@ -104,8 +101,7 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Sets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan).
* Sets the number of columns in the enclosing table that shall be spanned by the cell (ColSpan).
*
* @param colSpan the column span
*/
......@@ -115,10 +111,9 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Gets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
* Gets the headers (Headers). An array of byte strings, where each string shall be the element identifier (see the
* {@link org.sejda.sambox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()})
* for a TH structure element that shall be used as a header associated with this cell.
*
* @return the headers.
*/
......@@ -128,10 +123,9 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Sets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
* Sets the headers (Headers). An array of byte strings, where each string shall be the element identifier (see the
* {@link org.sejda.sambox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()})
* for a TH structure element that shall be used as a header associated with this cell.
*
* @param headers the headers
*/
......@@ -141,9 +135,8 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Gets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it.
* Gets the scope (Scope). It shall reflect whether the header cell applies to the rest of the cells in the row that
* contains it, the column that contains it, or both the row and the column that contain it.
*
* @return the scope
*/
......@@ -153,10 +146,9 @@ public class PDTableAttributeObject extends PDStandardAttributeObject
}
/**
* Sets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it. The value
* shall be one of the following:
* Sets the scope (Scope). It shall reflect whether the header cell applies to the rest of the cells in the row that
* contains it, the column that contains it, or both the row and the column that contain it. The value shall be one
* of the following:
* <ul>
* <li>{@link #SCOPE_ROW},</li>
* <li>{@link #SCOPE_COLUMN}, or</li>
......
......@@ -18,8 +18,8 @@
package org.sejda.sambox.pdmodel.encryption;
/**
* This class represents the access permissions to a document.
* These permissions are specified in the PDF format specifications, they include:
* This class represents the access permissions to a document. These permissions are specified in the PDF format
* specifications, they include:
* <ul>
* <li>print the document</li>
* <li>modify the content of the document</li>
......@@ -31,15 +31,15 @@ package org.sejda.sambox.pdmodel.encryption;
* <li>print in degraded quality</li>
* </ul>
*
* This class can be used to protect a document by assigning access permissions to recipients.
* In this case, it must be used with a specific ProtectionPolicy.
* This class can be used to protect a document by assigning access permissions to recipients. In this case, it must be
* used with a specific ProtectionPolicy.
*
*
* When a document is decrypted, it has a currentAccessPermission property which is the access permissions
* granted to the user who decrypted the document.
* When a document is decrypted, it has a currentAccessPermission property which is the access permissions granted to
* the user who decrypted the document.
*
* @see ProtectionPolicy
* @see org.apache.pdfbox.pdmodel.PDDocument#getCurrentAccessPermission()
* @see org.sejda.sambox.pdmodel.PDDocument#getCurrentAccessPermission()
*
* @author Ben Litchfield
* @author Benoit Guillon
......@@ -64,8 +64,7 @@ public class AccessPermission
private boolean readOnly = false;
/**
* Create a new access permission object.
* By default, all permissions are granted.
* Create a new access permission object. By default, all permissions are granted.
*/
public AccessPermission()
{
......@@ -73,8 +72,7 @@ public class AccessPermission
}
/**
* Create a new access permission object from a byte array.
* Bytes are ordered most significant byte first.
* Create a new access permission object from a byte array. Bytes are ordered most significant byte first.
*
* @param b the bytes as defined in PDF specs
*/
......@@ -122,26 +120,16 @@ public class AccessPermission
return (bytes & (1 << (bit - 1))) != 0;
}
/**
* This will tell if the access permission corresponds to owner
* access permission (no restriction).
* This will tell if the access permission corresponds to owner access permission (no restriction).
*
* @return true if the access permission does not restrict the use of the document
*/
public boolean isOwnerPermission()
{
return (this.canAssembleDocument()
&& this.canExtractContent()
&& this.canExtractForAccessibility()
&& this.canFillInForm()
&& this.canModify()
&& this.canModifyAnnotations()
&& this.canPrint()
&& this.canPrintDegraded()
);
return (this.canAssembleDocument() && this.canExtractContent()
&& this.canExtractForAccessibility() && this.canFillInForm() && this.canModify()
&& this.canModifyAnnotations() && this.canPrint() && this.canPrintDegraded());
}
/**
......@@ -165,10 +153,9 @@ public class AccessPermission
}
/**
* This returns an integer representing the access permissions.
* This integer can be used for public key encryption. This format
* is not documented in the PDF specifications but is necessary for compatibility
* with Adobe Acrobat and Adobe Reader.
* This returns an integer representing the access permissions. This integer can be used for public key encryption.
* This format is not documented in the PDF specifications but is necessary for compatibility with Adobe Acrobat and
* Adobe Reader.
*
* @return the integer representing access permissions
*/
......@@ -186,9 +173,8 @@ public class AccessPermission
}
/**
* The returns an integer representing the access permissions.
* This integer can be used for standard PDF encryption as specified
* in the PDF specifications.
* The returns an integer representing the access permissions. This integer can be used for standard PDF encryption
* as specified in the PDF specifications.
*
* @return the integer representing the access permissions
*/
......@@ -250,8 +236,7 @@ public class AccessPermission
/**
* This will tell if the user can extract text and images from the PDF document.
*
* @return true If supplied with the user password they are allowed to extract content
* from the PDF document
* @return true If supplied with the user password they are allowed to extract content from the PDF document
*/
public boolean canExtractContent()
{
......@@ -263,8 +248,7 @@ public class AccessPermission
* <p>
* This method will have no effect if the object is in read only mode
*
* @param allowExtraction A boolean determining if the user can extract content
* from the document.
* @param allowExtraction A boolean determining if the user can extract content from the document.
*/
public void setCanExtractContent(boolean allowExtraction)
{
......@@ -275,10 +259,9 @@ public class AccessPermission
}
/**
* This will tell if the user can add or modify text annotations and fill in interactive forms
* fields and, if {@link #canModify() canModify()} returns true, create or modify interactive
* form fields (including signature fields). Note that if
* {@link #canFillInForm() canFillInForm()} returns true, it is still possible to fill in
* This will tell if the user can add or modify text annotations and fill in interactive forms fields and, if
* {@link #canModify() canModify()} returns true, create or modify interactive form fields (including signature
* fields). Note that if {@link #canFillInForm() canFillInForm()} returns true, it is still possible to fill in
* interactive forms (including signature fields) even if this method here returns false.
*
* @return true If supplied with the user password they are allowed to modify annotations.
......@@ -289,10 +272,9 @@ public class AccessPermission
}
/**
* Set if the user can add or modify text annotations and fill in interactive forms fields and,
* (including signature fields). Note that if {@link #canFillInForm() canFillInForm()} returns
* true, it is still possible to fill in interactive forms (including signature fields) even the
* parameter here is false.
* Set if the user can add or modify text annotations and fill in interactive forms fields and, (including signature
* fields). Note that if {@link #canFillInForm() canFillInForm()} returns true, it is still possible to fill in
* interactive forms (including signature fields) even the parameter here is false.
* <p>
* This method will have no effect if the object is in read only mode.
*
......@@ -307,8 +289,8 @@ public class AccessPermission
}
/**
* This will tell if the user can fill in interactive form fields (including signature fields)
* even if {@link #canModifyAnnotations() canModifyAnnotations()} returns false.
* This will tell if the user can fill in interactive form fields (including signature fields) even if
* {@link #canModifyAnnotations() canModifyAnnotations()} returns false.
*
* @return true If supplied with the user password they are allowed to fill in form fields.
*/
......@@ -319,9 +301,9 @@ public class AccessPermission
/**
* Set if the user can fill in interactive form fields (including signature fields) even if
* {@link #canModifyAnnotations() canModifyAnnotations()} returns false. Therefore, if you want
* to prevent a user from filling in interactive form fields, you need to call
* {@link #setCanModifyAnnotations(boolean) setCanModifyAnnotations(false)} as well.
* {@link #canModifyAnnotations() canModifyAnnotations()} returns false. Therefore, if you want to prevent a user
* from filling in interactive form fields, you need to call {@link #setCanModifyAnnotations(boolean)
* setCanModifyAnnotations(false)} as well.
* <p>
* This method will have no effect if the object is in read only mode.
*
......@@ -336,11 +318,9 @@ public class AccessPermission
}
/**
* This will tell if the user can extract text and images from the PDF document
* for accessibility purposes.
* This will tell if the user can extract text and images from the PDF document for accessibility purposes.
*
* @return true If supplied with the user password they are allowed to extract content
* from the PDF document
* @return true If supplied with the user password they are allowed to extract content from the PDF document
*/
public boolean canExtractForAccessibility()
{
......@@ -352,8 +332,7 @@ public class AccessPermission
* <p>
* This method will have no effect if the object is in read only mode.
*
* @param allowExtraction A boolean determining if the user can extract content
* from the document.
* @param allowExtraction A boolean determining if the user can extract content from the document.
*/
public void setCanExtractForAccessibility(boolean allowExtraction)
{
......@@ -366,8 +345,7 @@ public class AccessPermission
/**
* This will tell if the user can insert/rotate/delete pages.
*
* @return true If supplied with the user password they are allowed to extract content
* from the PDF document
* @return true If supplied with the user password they are allowed to extract content from the PDF document
*/
public boolean canAssembleDocument()
{
......@@ -392,8 +370,7 @@ public class AccessPermission
/**
* This will tell if the user can print the document in a degraded format.
*
* @return true If supplied with the user password they are allowed to print the
* document in a degraded format.
* @return true If supplied with the user password they are allowed to print the document in a degraded format.
*/
public boolean canPrintDegraded()
{
......@@ -416,10 +393,9 @@ public class AccessPermission
}
/**
* Locks the access permission read only (ie, the setters will have no effects).
* After that, the object cannot be unlocked.
* This method is used for the currentAccessPermssion of a document to avoid
* users to change access permission.
* Locks the access permission read only (ie, the setters will have no effects). After that, the object cannot be
* unlocked. This method is used for the currentAccessPermssion of a document to avoid users to change access
* permission.
*/
public void setReadOnly()
{
......
......@@ -71,21 +71,17 @@ public final class PublicKeySecurityHandler extends SecurityHandler
/**
* Prepares everything to decrypt the document.
*
* @param encryption encryption dictionary, can be retrieved via
* {@link PDDocument#getEncryption()}
* @param documentIDArray document id which is returned via
* {@link org.apache.pdfbox.cos.COSDocument#getDocumentID()} (not used by
* this handler)
* @param encryption encryption dictionary, can be retrieved via {@link PDDocument#getEncryption()}
* @param documentIDArray document id which is returned via {@link org.sejda.sambox.cos.COSDocument#getDocumentID()}
* (not used by this handler)
* @param decryptionMaterial Information used to decrypt the document.
*
* @throws IOException If there is an error accessing data. If verbose mode
* is enabled, the exception message will provide more details why the
* match wasn't successful.
* @throws IOException If there is an error accessing data. If verbose mode is enabled, the exception message will
* provide more details why the match wasn't successful.
*/
@Override
public void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray,
DecryptionMaterial decryptionMaterial)
throws IOException
DecryptionMaterial decryptionMaterial) throws IOException
{
if (!(decryptionMaterial instanceof PublicKeyDecryptionMaterial))
{
......@@ -139,7 +135,8 @@ public final class PublicKeySecurityHandler extends SecurityHandler
{
foundRecipient = true;
PrivateKey privateKey = (PrivateKey) material.getPrivateKey();
envelopedData = ri.getContent(new JceKeyTransEnvelopedRecipient(privateKey));
envelopedData = ri
.getContent(new JceKeyTransEnvelopedRecipient(privateKey));
break;
}
j++;
......@@ -150,7 +147,8 @@ public final class PublicKeySecurityHandler extends SecurityHandler
extraInfo.append(": ");
if (rid instanceof KeyTransRecipientId)
{
appendCertInfo(extraInfo, (KeyTransRecipientId) rid, certificate, materialCert);
appendCertInfo(extraInfo, (KeyTransRecipientId) rid, certificate,
materialCert);
}
}
}
......@@ -159,8 +157,8 @@ public final class PublicKeySecurityHandler extends SecurityHandler
}
if (!foundRecipient || envelopedData == null)
{
throw new IOException("The certificate matches none of " + i
+ " recipient entries" + extraInfo.toString());
throw new IOException("The certificate matches none of " + i + " recipient entries"
+ extraInfo.toString());
}
if (envelopedData.length != 24)
{
......
......@@ -109,8 +109,7 @@ public abstract class SecurityHandler
* Prepares everything to decrypt the document.
*
* @param encryption encryption dictionary, can be retrieved via {@link PDDocument#getEncryption()}
* @param documentIDArray document id which is returned via
* {@link org.apache.pdfbox.cos.COSDocument#getDocumentID()}
* @param documentIDArray document id which is returned via {@link org.sejda.sambox.cos.COSDocument#getDocumentID()}
* @param decryptionMaterial Information used to decrypt the document.
*
* @throws IOException If there is an error accessing data.
......
......@@ -16,6 +16,8 @@
*/
package org.sejda.sambox.pdmodel.font;
import static java.util.Optional.ofNullable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
......@@ -542,6 +544,14 @@ final class FontMapperImpl implements FontMapper
PDPanoseClassification panose = fontDescriptor.getPanose().getPanose();
if (panose.getFamilyKind() == info.getPanose().getFamilyKind())
{
if (panose.getFamilyKind() == 0
&& (info.getPostScriptName().toLowerCase().contains("barcode")
|| info.getPostScriptName().startsWith("Code"))
&& !probablyBarcodeFont(fontDescriptor))
{
// PDFBOX-4268: ignore barcode font if we aren't searching for one.
continue;
}
// serifs
if (panose.getSerifStyle() == info.getPanose().getSerifStyle())
{
......@@ -606,6 +616,14 @@ final class FontMapperImpl implements FontMapper
return queue;
}
private static boolean probablyBarcodeFont(PDFontDescriptor fontDescriptor)
{
String ff = ofNullable(fontDescriptor.getFontFamily()).orElse("");
String fn = ofNullable(fontDescriptor.getFontName()).orElse("");
return ff.startsWith("Code") || ff.toLowerCase().contains("barcode")
|| fn.startsWith("Code") || fn.toLowerCase().contains("barcode");
}
/**
* Returns true if the character set described by CIDSystemInfo is present in the given font. Only applies to
* Adobe-GB1, Adobe-CNS1, Adobe-Japan1, Adobe-Korea1, as per the PDF spec.
......
......@@ -495,7 +495,8 @@ public abstract class PDFont implements COSObjectable, PDFontLike, Subsettable
if (toUnicodeCMap != null)
{
if (toUnicodeCMap.getName() != null && toUnicodeCMap.getName().startsWith("Identity-")
&& dict.getDictionaryObject(COSName.TO_UNICODE) instanceof COSName)
&& (dict.getDictionaryObject(COSName.TO_UNICODE) instanceof COSName
|| !toUnicodeCMap.hasUnicodeMappings()))
{
// handle the undocumented case of using Identity-H/V as a ToUnicode CMap, this
// isn't actually valid as the Identity-x CMaps are code->CID maps, not
......
......@@ -198,11 +198,17 @@ public class PDType0Font extends PDFont implements PDVectorFont
}
/**
* Private. Creates a new TrueType font for embedding.
*
* @param document
* @param ttf
* @param embedSubset
* @param closeTTF whether to close the ttf parameter after embedding. Must be true when the ttf parameter was
* created in the load() method, false when the ttf parameter was passed to the load() method.
* @param vertical
* @throws IOException
*/
private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset,
boolean closeOnSubset, boolean vertical)
throws IOException
boolean closeTTF, boolean vertical) throws IOException
{
if (vertical)
{
......@@ -212,11 +218,12 @@ public class PDType0Font extends PDFont implements PDVectorFont
descendantFont = embedder.getCIDFont();
readEncoding();
fetchCMapUCS2();
if (closeOnSubset)
if (closeTTF)
{
if (embedSubset)
{
this.ttf = ttf;
document.registerTrueTypeFontForClosing(ttf);
}
else
{
......
......@@ -442,7 +442,7 @@ public class PDType1Font extends PDSimpleFont
Map<String, Integer> inverted = encoding.getNameToCodeMap();
int code = inverted.get(name);
bytes = new byte[] { (byte) code };
codeToBytesMap.put(code, bytes);
codeToBytesMap.put(unicode, bytes);
return bytes;
}
......