use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDPageTree method add.
/**
* Adds the given page to this page tree.
*
* @param page The page to add.
*/
public void add(PDPage page) {
// set parent
COSDictionary node = page.getCOSObject();
node.setItem(COSName.PARENT, root);
// todo: re-balance tree? (or at least group new pages into tree nodes of e.g. 20)
// add to parent's kids
COSArray kids = (COSArray) root.getDictionaryObject(COSName.KIDS);
kids.add(node);
// update ancestor counts
do {
node = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
if (node != null) {
node.setInt(COSName.COUNT, node.getInt(COSName.COUNT) + 1);
}
} while (node != null);
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDResources method add.
/**
* Adds the given resource if it does not already exist.
*/
private COSName add(COSName kind, String prefix, COSObjectable object) {
// return the existing key if the item exists already
COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
if (dict != null && dict.containsValue(object.getCOSObject())) {
return dict.getKeyForValue(object.getCOSObject());
}
// AcroForm default resources of a loaded PDF.
if (dict != null && COSName.FONT.equals(kind)) {
for (Map.Entry<COSName, COSBase> entry : dict.entrySet()) {
if (entry.getValue() instanceof COSObject && object.getCOSObject() == ((COSObject) entry.getValue()).getObject()) {
return entry.getKey();
}
}
}
// add the item with a new key
COSName name = createKey(kind, prefix);
put(kind, name, object);
return name;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDResources method getShading.
/**
* Returns the shading resource with the given name, or null if none exists.
*
* @param name Name of the shading resource.
*
* @return the shading resource of the given name.
*
* @throws IOException if something went wrong.
*/
public PDShading getShading(COSName name) throws IOException {
COSObject indirect = getIndirect(COSName.SHADING, name);
if (cache != null && indirect != null) {
PDShading cached = cache.getShading(indirect);
if (cached != null) {
return cached;
}
}
// get the instance
PDShading shading = null;
COSDictionary dict = (COSDictionary) get(COSName.SHADING, name);
if (dict != null) {
shading = PDShading.create(dict);
}
if (cache != null) {
cache.put(indirect, shading);
}
return shading;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDResources method getPattern.
/**
* Returns the pattern resource with the given name, or null if none exists.
*
* @param name Name of the pattern resource.
*
* @return the pattern resource of the given name.
*
* @throws IOException if something went wrong.
*/
public PDAbstractPattern getPattern(COSName name) throws IOException {
COSObject indirect = getIndirect(COSName.PATTERN, name);
if (cache != null && indirect != null) {
PDAbstractPattern cached = cache.getPattern(indirect);
if (cached != null) {
return cached;
}
}
// get the instance
PDAbstractPattern pattern = null;
COSDictionary dict = (COSDictionary) get(COSName.PATTERN, name);
if (dict != null) {
pattern = PDAbstractPattern.create(dict);
}
if (cache != null) {
cache.put(indirect, pattern);
}
return pattern;
}
use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.
the class PDResources method getExtGState.
/**
* Returns the extended graphics state resource with the given name, or null if none exists.
*
* @param name Name of the graphics state resource.
*
* @return the extended graphics state resource with the given name.
*/
public PDExtendedGraphicsState getExtGState(COSName name) {
COSObject indirect = getIndirect(COSName.EXT_G_STATE, name);
if (cache != null && indirect != null) {
PDExtendedGraphicsState cached = cache.getExtGState(indirect);
if (cached != null) {
return cached;
}
}
// get the instance
PDExtendedGraphicsState extGState = null;
COSDictionary dict = (COSDictionary) get(COSName.EXT_G_STATE, name);
if (dict != null) {
extGState = new PDExtendedGraphicsState(dict);
}
if (cache != null) {
cache.put(indirect, extGState);
}
return extGState;
}
Aggregations