public final class PDResources extends java.lang.Object implements COSObjectable
Modifier and Type | Field and Description |
---|---|
private ResourceCache |
cache |
private java.util.Map<COSName,java.lang.ref.SoftReference<PDFont>> |
directFontCache |
private COSDictionary |
resources |
Constructor and Description |
---|
PDResources()
Constructor for embedding.
|
PDResources(COSDictionary resourceDictionary)
Constructor for reading.
|
PDResources(COSDictionary resourceDictionary,
ResourceCache resourceCache)
Constructor for reading.
|
Modifier and Type | Method and Description |
---|---|
private COSName |
add(COSName kind,
java.lang.String prefix,
COSObjectable object)
Adds the given resource if it does not already exist.
|
COSName |
add(PDAbstractPattern pattern)
Adds the given pattern to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDColorSpace colorSpace)
Adds the given color space to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDExtendedGraphicsState extGState)
Adds the given extended graphics state to the resources of the current page and returns the
name for the new resources.
|
COSName |
add(PDFont font)
Adds the given font to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDFormXObject form)
Adds the given form to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDImageXObject image)
Adds the given image to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDPropertyList properties)
Adds the given property list to the resources of the current page and returns the name for
the new resources.
|
COSName |
add(PDShading shading)
Adds the given shading to the resources of the current page and returns the name for the
new resources.
|
COSName |
add(PDXObject xobject,
java.lang.String prefix)
Adds the given XObject to the resources of the current page and returns the name for the
new resources.
|
private COSName |
createKey(COSName kind,
java.lang.String prefix)
Returns a unique key for a new resource.
|
private COSBase |
get(COSName kind,
COSName name)
Returns the resource with the given name and kind, or null.
|
PDColorSpace |
getColorSpace(COSName name)
Returns the color space resource with the given name, or null if none exists.
|
PDColorSpace |
getColorSpace(COSName name,
boolean wasDefault)
Returns the color space resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getColorSpaceNames()
Returns the names of the color space resources, if any.
|
COSDictionary |
getCOSObject()
Returns the underlying dictionary.
|
PDExtendedGraphicsState |
getExtGState(COSName name)
Returns the extended graphics state resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getExtGStateNames()
Returns the names of the extended graphics state resources, if any.
|
PDFont |
getFont(COSName name)
Returns the font resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getFontNames()
Returns the names of the font resources, if any.
|
private COSObject |
getIndirect(COSName kind,
COSName name)
Returns the resource with the given name and kind as an indirect object, or null.
|
private java.lang.Iterable<COSName> |
getNames(COSName kind)
Returns the resource names of the given kind.
|
PDAbstractPattern |
getPattern(COSName name)
Returns the pattern resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getPatternNames()
Returns the names of the pattern resources, if any.
|
PDPropertyList |
getProperties(COSName name)
Returns the property list resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getPropertiesNames()
Returns the names of the property list resources, if any.
|
ResourceCache |
getResourceCache()
Returns the resource cache associated with the Resources, or null if there is none.
|
PDShading |
getShading(COSName name)
Returns the shading resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getShadingNames()
Returns the names of the shading resources, if any.
|
PDXObject |
getXObject(COSName name)
Returns the XObject resource with the given name, or null if none exists.
|
java.lang.Iterable<COSName> |
getXObjectNames()
Returns the names of the XObject resources, if any.
|
boolean |
hasColorSpace(COSName name)
Returns true if the given color space name exists in these resources.
|
private boolean |
isAllowedCache(PDXObject xobject) |
boolean |
isImageXObject(COSName name)
Tells whether the XObject resource with the given name is an image.
|
private void |
put(COSName kind,
COSName name,
COSObjectable object)
Sets the value of a given named resource.
|
void |
put(COSName name,
PDAbstractPattern pattern)
Sets the pattern resource with the given name.
|
void |
put(COSName name,
PDColorSpace colorSpace)
Sets the color space resource with the given name.
|
void |
put(COSName name,
PDExtendedGraphicsState extGState)
Sets the extended graphics state resource with the given name.
|
void |
put(COSName name,
PDFont font)
Sets the font resource with the given name.
|
void |
put(COSName name,
PDPropertyList properties)
Sets the property list resource with the given name.
|
void |
put(COSName name,
PDShading shading)
Sets the shading resource with the given name.
|
void |
put(COSName name,
PDXObject xobject)
Sets the XObject resource with the given name.
|
private final COSDictionary resources
private final ResourceCache cache
public PDResources()
public PDResources(COSDictionary resourceDictionary)
resourceDictionary
- The cos dictionary for this resource.public PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache)
resourceDictionary
- The cos dictionary for this resource.resourceCache
- The document's resource cache, may be null.public COSDictionary getCOSObject()
getCOSObject
in interface COSObjectable
public PDFont getFont(COSName name) throws java.io.IOException
name
- Name of the font resource.java.io.IOException
- if something went wrong.public PDColorSpace getColorSpace(COSName name) throws java.io.IOException
name
- Name of the color space resource.java.io.IOException
- if something went wrong.public PDColorSpace getColorSpace(COSName name, boolean wasDefault) throws java.io.IOException
getColorSpace(COSName)
.name
- Name of the color space resource.wasDefault
- if current color space was used by a default color space. This parameter is
tojava.io.IOException
- if something went wrong.public boolean hasColorSpace(COSName name)
name
- Name of the color space resource.public PDExtendedGraphicsState getExtGState(COSName name)
name
- Name of the graphics state resource.public PDShading getShading(COSName name) throws java.io.IOException
name
- Name of the shading resource.java.io.IOException
- if something went wrong.public PDAbstractPattern getPattern(COSName name) throws java.io.IOException
name
- Name of the pattern resource.java.io.IOException
- if something went wrong.public PDPropertyList getProperties(COSName name)
name
- Name of the property list resource.public boolean isImageXObject(COSName name)
name
- Name of the XObject resource.public PDXObject getXObject(COSName name) throws java.io.IOException
name
- Name of the XObject resource.java.io.IOException
- if something went wrong.private boolean isAllowedCache(PDXObject xobject)
private COSObject getIndirect(COSName kind, COSName name)
private COSBase get(COSName kind, COSName name)
public java.lang.Iterable<COSName> getColorSpaceNames()
public java.lang.Iterable<COSName> getXObjectNames()
public java.lang.Iterable<COSName> getFontNames()
public java.lang.Iterable<COSName> getPropertiesNames()
public java.lang.Iterable<COSName> getShadingNames()
public java.lang.Iterable<COSName> getPatternNames()
public java.lang.Iterable<COSName> getExtGStateNames()
private java.lang.Iterable<COSName> getNames(COSName kind)
public COSName add(PDFont font)
font
- the font to addpublic COSName add(PDColorSpace colorSpace)
colorSpace
- the color space to addpublic COSName add(PDExtendedGraphicsState extGState)
extGState
- the extended graphics state to addpublic COSName add(PDShading shading)
shading
- the shading to addpublic COSName add(PDAbstractPattern pattern)
pattern
- the pattern to addpublic COSName add(PDPropertyList properties)
properties
- the property list to addpublic COSName add(PDImageXObject image)
image
- the image to addpublic COSName add(PDFormXObject form)
form
- the form to addpublic COSName add(PDXObject xobject, java.lang.String prefix)
xobject
- the XObject to addprefix
- the prefix to be used when creating the resource nameprivate COSName add(COSName kind, java.lang.String prefix, COSObjectable object)
private COSName createKey(COSName kind, java.lang.String prefix)
private void put(COSName kind, COSName name, COSObjectable object)
public void put(COSName name, PDFont font)
name
- the name of the resourcefont
- the font to be addedpublic void put(COSName name, PDColorSpace colorSpace)
name
- the name of the resourcecolorSpace
- the color space to be addedpublic void put(COSName name, PDExtendedGraphicsState extGState)
name
- the name of the resourceextGState
- the extended graphics state to be addedpublic void put(COSName name, PDShading shading)
name
- the name of the resourceshading
- the shading to be addedpublic void put(COSName name, PDAbstractPattern pattern)
name
- the name of the resourcepattern
- the pattern to be addedpublic void put(COSName name, PDPropertyList properties)
name
- the name of the resourceproperties
- the property list to be addedpublic void put(COSName name, PDXObject xobject)
name
- the name of the resourcexobject
- the XObject to be addedpublic ResourceCache getResourceCache()