Author: tilman Date: Thu Oct 29 20:26:18 2015 New Revision: 1711357 URL: http://svn.apache.org/viewvc?rev=1711357&view=rev Log: PDFBOX-3070: avoid endless recursion for DefaultRGB color space, as suggested by Evgeniy Muravitskiy
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java?rev=1711357&r1=1711356&r2=1711357&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java Thu Oct 29 20:26:18 2015 @@ -134,10 +134,26 @@ public final class PDResources implement * Returns the color space resource with the given name, or null if none exists. * * @param name Name of the color space resource. - * @throws java.io.IOException if something went wrong. + * @return a new color space. + * @throws IOException if something went wrong. */ public PDColorSpace getColorSpace(COSName name) throws IOException { + return getColorSpace(name, false); + } + + /** + * Returns the color space resource with the given name, or null if none exists. This method is + * for PDFBox internal use only, others should use {@link getColorSpace(COSName)}. + * + * @param name Name of the color space resource. + * @param wasDefault if current color space was used by a default color space. This parameter is + * to + * @return a new color space. + * @throws IOException if something went wrong. + */ + public PDColorSpace getColorSpace(COSName name, boolean wasDefault) throws IOException + { COSObject indirect = getIndirect(COSName.COLORSPACE, name); if (cache != null && indirect != null) { @@ -153,11 +169,11 @@ public final class PDResources implement COSBase object = get(COSName.COLORSPACE, name); if (object != null) { - colorSpace = PDColorSpace.create(object, this); + colorSpace = PDColorSpace.create(object, this, wasDefault); } else { - colorSpace = PDColorSpace.create(name, this); + colorSpace = PDColorSpace.create(name, this, wasDefault); } // we can't cache PDPattern, because it holds page resources, see PDFBOX-2370 Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=1711357&r1=1711356&r2=1711357&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java Thu Oct 29 20:26:18 2015 @@ -66,6 +66,26 @@ public abstract class PDColorSpace imple PDResources resources) throws IOException { + return create(colorSpace, resources, false); + } + + /** + * Creates a color space given a name or array. Abbreviated device color names are not supported + * here, please replace them first. This method is for PDFBox internal use only, others should + * use {@link create(COSBase, PDResources)}. + * + * @param colorSpace the color space COS object + * @param resources the current resources. + * @param wasDefault if current color space was used by a default color space. + * @return a new color space. + * @throws MissingResourceException if the color space is missing in the resources dictionary + * @throws IOException if the color space is unknown or cannot be created. + */ + public static PDColorSpace create(COSBase colorSpace, + PDResources resources, + boolean wasDefault) + throws IOException + { if (colorSpace instanceof COSObject) { return create(((COSObject) colorSpace).getObject(), resources); @@ -94,9 +114,9 @@ public abstract class PDColorSpace imple defaultName = COSName.DEFAULT_GRAY; } - if (resources.hasColorSpace(defaultName)) + if (resources.hasColorSpace(defaultName) && !wasDefault) { - return resources.getColorSpace(defaultName); + return resources.getColorSpace(defaultName, true); } } @@ -181,7 +201,7 @@ public abstract class PDColorSpace imple name == COSName.DEVICEGRAY) { // not allowed in an array, but we sometimes encounter these regardless - return create(name, resources); + return create(name, resources, wasDefault); } else {