Skip to content

Commit 6e8a7a6

Browse files
committed
PDFBOX-6008: pass document resource cache to softmask
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1925690 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2007db2 commit 6e8a7a6

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public PDExtendedGraphicsState getExtGState(COSName name)
269269
COSBase base = get(COSName.EXT_G_STATE, name);
270270
if (base instanceof COSDictionary)
271271
{
272-
extGState = new PDExtendedGraphicsState((COSDictionary) base);
272+
extGState = new PDExtendedGraphicsState((COSDictionary) base, getResourceCache());
273273
}
274274

275275
if (cache != null && indirect != null)

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.pdfbox.cos.COSFloat;
2525
import org.apache.pdfbox.cos.COSName;
2626
import org.apache.pdfbox.cos.COSNumber;
27+
import org.apache.pdfbox.pdmodel.ResourceCache;
2728
import org.apache.pdfbox.pdmodel.common.COSObjectable;
2829
import org.apache.pdfbox.pdmodel.graphics.PDFontSetting;
2930
import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern;
@@ -37,6 +38,7 @@
3738
public class PDExtendedGraphicsState implements COSObjectable
3839
{
3940
private final COSDictionary dict;
41+
private final ResourceCache cache;
4042

4143
/**
4244
* Default constructor, creates blank graphics state.
@@ -45,6 +47,7 @@ public PDExtendedGraphicsState()
4547
{
4648
dict = new COSDictionary();
4749
dict.setItem(COSName.TYPE, COSName.EXT_G_STATE);
50+
cache = null;
4851
}
4952

5053
/**
@@ -53,8 +56,20 @@ public PDExtendedGraphicsState()
5356
* @param dictionary The existing graphics state.
5457
*/
5558
public PDExtendedGraphicsState(COSDictionary dictionary)
59+
{
60+
this(dictionary, null);
61+
}
62+
63+
/**
64+
* Create a graphics state from an existing dictionary.
65+
*
66+
* @param dictionary The existing graphics state.
67+
* @param resourceCache Resource cache, may be null.
68+
*/
69+
public PDExtendedGraphicsState(COSDictionary dictionary, ResourceCache resourceCache)
5670
{
5771
dict = dictionary;
72+
cache = resourceCache;
5873
}
5974

6075
/**
@@ -587,7 +602,7 @@ public void setBlendMode(BlendMode bm)
587602
public PDSoftMask getSoftMask()
588603
{
589604
COSBase smask = dict.getDictionaryObject(COSName.SMASK);
590-
return smask == null ? null : PDSoftMask.create(smask);
605+
return smask == null ? null : PDSoftMask.create(smask, cache);
591606
}
592607

593608
/**

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDSoftMask.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.pdfbox.cos.COSBase;
2525
import org.apache.pdfbox.cos.COSDictionary;
2626
import org.apache.pdfbox.cos.COSName;
27+
import org.apache.pdfbox.pdmodel.PDResources;
28+
import org.apache.pdfbox.pdmodel.ResourceCache;
2729
import org.apache.pdfbox.pdmodel.common.COSObjectable;
2830
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
2931
import org.apache.pdfbox.pdmodel.graphics.PDXObject;
@@ -45,6 +47,19 @@ public final class PDSoftMask implements COSObjectable
4547
* @return the newly created instance of PDSoftMask
4648
*/
4749
public static PDSoftMask create(COSBase dictionary)
50+
{
51+
return create(dictionary, null);
52+
}
53+
54+
/**
55+
* Creates a new soft mask.
56+
*
57+
* @param dictionary SMask
58+
* @param resourceCache Resource cache, may be null.
59+
*
60+
* @return the newly created instance of PDSoftMask
61+
*/
62+
public static PDSoftMask create(COSBase dictionary, ResourceCache resourceCache)
4863
{
4964
if (dictionary instanceof COSName)
5065
{
@@ -60,7 +75,7 @@ public static PDSoftMask create(COSBase dictionary)
6075
}
6176
else if (dictionary instanceof COSDictionary)
6277
{
63-
return new PDSoftMask((COSDictionary) dictionary);
78+
return new PDSoftMask((COSDictionary) dictionary, resourceCache);
6479
}
6580
else
6681
{
@@ -72,6 +87,7 @@ else if (dictionary instanceof COSDictionary)
7287
private static final Logger LOG = LogManager.getLogger(PDSoftMask.class);
7388

7489
private final COSDictionary dictionary;
90+
private final ResourceCache resourceCache;
7591
private COSName subType = null;
7692
private PDTransparencyGroup group = null;
7793
private COSArray backdropColor = null;
@@ -88,8 +104,20 @@ else if (dictionary instanceof COSDictionary)
88104
* @param dictionary The soft mask dictionary.
89105
*/
90106
public PDSoftMask(COSDictionary dictionary)
107+
{
108+
this(dictionary, null);
109+
}
110+
111+
/**
112+
* Creates a new soft mask.
113+
*
114+
* @param dictionary The soft mask dictionary.
115+
* @param resourceCache Resource cache, may be null.
116+
*/
117+
public PDSoftMask(COSDictionary dictionary, ResourceCache resourceCache)
91118
{
92119
this.dictionary = dictionary;
120+
this.resourceCache = resourceCache;
93121
}
94122

95123
@Override
@@ -125,7 +153,8 @@ public PDTransparencyGroup getGroup() throws IOException
125153
COSBase cosGroup = getCOSObject().getDictionaryObject(COSName.G);
126154
if (cosGroup != null)
127155
{
128-
PDXObject x = PDXObject.createXObject(cosGroup, null);
156+
PDResources resources = new PDResources(new COSDictionary(), resourceCache);
157+
PDXObject x = PDXObject.createXObject(cosGroup, resources);
129158
if (x instanceof PDTransparencyGroup)
130159
{
131160
group = (PDTransparencyGroup) x;

0 commit comments

Comments
 (0)