public COSName getDisplayMode() { COSArray definition = cosGetArray(); if (definition.size() < 2) { return null; } return definition.get(1).asName(); }
/** * This method scans the document for all WidgetAnnotation objects. * * <p>This is done because some writer do not create a correct list of all PDAcroFormField objects * in the AcroForm. In the case that the list of children is empty, we go and search ourselves for * candidates... * * @param doc The document to reconstruct. */ protected COSArray reconstruct(PDDocument doc) { COSArray result = COSArray.create(); if (doc == null) { return result; } PDPageTree pageTree = doc.getPageTree(); if (pageTree == null) { return result; } boolean signatureExists = false; for (PDPage page = pageTree.getFirstPage(); page != null; page = page.getNextPage()) { List annotations = page.getAnnotations(); if (annotations == null) { continue; } for (Iterator it = annotations.iterator(); it.hasNext(); ) { PDAnnotation annot = (PDAnnotation) it.next(); if (annot.isWidgetAnnotation()) { COSDictionary cosAnnot = annot.cosGetDict(); result.basicAddSilent(cosAnnot); cosAnnot.basicRemoveSilent(PDAcroFormField.DK_Parent); signatureExists |= cosAnnot.get(PDAcroFormField.DK_FT).equals(PDAcroFormField.CN_FT_Sig); } } } if (signatureExists) { int flags = getFieldInt(PDAcroForm.DK_SigFlags, 0); flags |= AcroFormSigFlags.Bit_AppendOnly | AcroFormSigFlags.Bit_SignatureExists; cosGetDict().basicPutSilent(PDAcroForm.DK_SigFlags, COSInteger.create(flags)); } return result; }
protected void do_endbfrange(CSOperation operation) { Iterator it = operation.getOperands(); while (it.hasNext()) { COSString start = (COSString) it.next(); COSString end = (COSString) it.next(); COSObject destination = (COSObject) it.next(); CMapRangeMap map; if (destination instanceof COSString) { byte[] destBytes = ((COSString) destination).byteValue(); if (destBytes.length > 2) { // this is special to /ToUnicode maps map = new CMapBFRangeStringMap( start.byteValue(), end.byteValue(), ((COSString) destination).byteValue()); } else { map = new CMapBFRangeCodeMap( start.byteValue(), end.byteValue(), ((COSString) destination).byteValue()); } } else { COSArray array = destination.asArray(); if (array.get(0) instanceof COSString) { // this is special to /ToUnicode maps map = new CMapBFRangeStringArrayMap( start.byteValue(), end.byteValue(), (COSArray) destination); } else { map = new CMapBFRangeNameArrayMap( start.byteValue(), end.byteValue(), (COSArray) destination); } } addMap(map); } }
public void setPage(PDPage page) { COSArray definition = cosGetArray(); if (definition.size() == 0) { definition.add(page.cosGetObject()); } else { definition.set(0, page.cosGetObject()); } }
public void setParameters(float[] parameters) { COSArray definition = cosGetArray(); while (definition.size() < (2 + parameters.length)) { definition.add(COSNull.NULL); } for (int i = 2; i < (2 + parameters.length); i++) { definition.set(i, COSFixed.create(parameters[i])); } }
/* * (non-Javadoc) * * @see de.intarsys.pdf.pd.PDAcroFormNode#invalidateCaches() */ @Override public void invalidateCaches() { super.invalidateCaches(); COSArray cosFields = cosGetField(DK_Fields).asArray(); if (cosFields != null) { cosFields.removeObjectListener(this); } cachedFields = null; }
private void cosAddField(COSDictionary field) { COSArray cosFields = cosGetField(DK_Fields).asArray(); if (cosFields == null) { cosFields = COSArray.create(); cosFields.beIndirect(); cosSetField(DK_Fields, cosFields); } cosFields.add(field); }
/* * (non-Javadoc) * * @see de.intarsys.pdf.pd.PDAcroFormNode#removeField(de.intarsys.pdf.pd.PDAcroFormField) */ @Override public boolean removeField(PDAcroFormField field) { getFields().remove(field); COSArray cosFields = cosGetField(DK_Fields).asArray(); if (cosFields == null) { return false; } boolean removed = cosFields.remove(field.cosGetDict()); getSigFlags().setSignatureExists(isSignatureExists()); return removed; }
/** * The destination page. ATTENTION: it is common have dangling destinations to invalid (null) * pages around! * * @return The destination page. Be sure to handle null return values. */ public PDPage getPage(PDDocument doc) { COSArray definition = cosGetArray(); COSObject page = definition.get(0); if (page.asNumber() != null) { int pageIndex = page.asNumber().intValue(); return doc.getPageTree().getPageAt(pageIndex); } if (page.asDictionary() != null) { return (PDPage) PDPageNode.META.createFromCos(page.asDictionary()); } return null; }
public void setDashArray(int[] newDashArray) { if ((newDashArray == null) || ((newDashArray.length == 1) && (newDashArray[0] == 3))) { cosRemoveField(DK_D); return; } COSArray a = COSArray.create(newDashArray.length); cosSetField(DK_D, a); // overwrite existing array for (int i = 0; i < newDashArray.length; i++) { a.add(COSInteger.create(newDashArray[i])); } }
protected void checkFields() { // be careful not to propagate any changes -> deadlock prone synchronized (this) { if (fieldsChecked) { return; } fieldsChecked = true; // reconstruct form fields if there is an empty fields array COSArray fields = cosGetField(DK_Fields).asArray(); if ((fields != null) && (fields.size() == 0)) { COSArray cosFields = reconstruct(getDoc()); cosGetDict().basicPutSilent(DK_Fields, cosFields); } } }
public float[] getParameters() { COSArray definition = cosGetArray(); int size = definition.size() - 2; if (size < 0) { return new float[0]; } float[] result = new float[size]; for (int i = 0; i < size; i++) { COSNumber param = definition.get(i + 2).asNumber(); if (param == null) { result[i] = 0; } else { result[i] = param.floatValue(); } } return result; }
public int[] getDashArray() { COSArray array = cosGetField(DK_D).asArray(); if (array != null) { int[] result = new int[array.size()]; for (int i = 0; i < array.size(); i++) { COSInteger value = array.get(i).asInteger(); if (value != null) { result[i] = value.intValue(); } else { // TODO 3 wrong default, maybe restrict result[i] = 0; } } return result; } return new int[] {3}; // default }
/** * Fill an array of glyph widths from the definition prepared by the font dictionary. The widths * in the font are declared in the range from the first supported code point to the last code * point. The code point selects a glyph out of the font depending on the encoding by the font, * the corresponding entry in the width array defines its width. * * @param result The array to hold the correct widths. * @param array The COSArray defining the widths. * @return The array of widths for the defined range of chars in the font */ protected int[] createDeclaredWidths(int[] result, COSArray array) { int i = getFirstChar(); for (Iterator it = array.iterator(); it.hasNext(); ) { COSNumber width = ((COSObject) it.next()).asNumber(); if (width != null) { result[i] = width.intValue(); } i++; } return result; }
public void setDisplayMode(COSName mode) { COSArray definition = cosGetArray(); if (definition.size() == 0) { definition.add(COSNull.NULL); definition.add(mode); } else if (definition.size() == 1) { definition.add(mode); } else { definition.set(1, mode); } }