proj_name
stringclasses 131
values | relative_path
stringlengths 30
228
| class_name
stringlengths 1
68
| func_name
stringlengths 1
48
| masked_class
stringlengths 78
9.82k
| func_body
stringlengths 46
9.61k
| len_input
int64 29
2.01k
| len_output
int64 14
1.94k
| total
int64 55
2.05k
| relevant_context
stringlengths 0
38.4k
|
|---|---|---|---|---|---|---|---|---|---|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentInformation.java
|
PDDocumentInformation
|
setTrapped
|
class PDDocumentInformation implements COSObjectable
{
private final COSDictionary info;
/**
* Default Constructor.
*/
public PDDocumentInformation()
{
info = new COSDictionary();
}
/**
* Constructor that is used for a preexisting dictionary.
*
* @param dic The underlying dictionary.
*/
public PDDocumentInformation( COSDictionary dic )
{
info = dic;
}
/**
* This will get the underlying dictionary that this object wraps.
*
* @return The underlying info dictionary.
*/
@Override
public COSDictionary getCOSObject()
{
return info;
}
/**
* Return the properties String value.
* <p>
* Allows to retrieve the
* low level date for validation purposes.
* </p>
*
* @param propertyKey the dictionaries key
* @return the properties value
*/
public Object getPropertyStringValue(String propertyKey)
{
return info.getString(propertyKey);
}
/**
* This will get the title of the document. This will return null if no title exists.
*
* @return The title of the document.
*/
public String getTitle()
{
return info.getString( COSName.TITLE );
}
/**
* This will set the title of the document.
*
* @param title The new title for the document.
*/
public void setTitle( String title )
{
info.setString( COSName.TITLE, title );
}
/**
* This will get the author of the document. This will return null if no author exists.
*
* @return The author of the document.
*/
public String getAuthor()
{
return info.getString( COSName.AUTHOR );
}
/**
* This will set the author of the document.
*
* @param author The new author for the document.
*/
public void setAuthor( String author )
{
info.setString( COSName.AUTHOR, author );
}
/**
* This will get the subject of the document. This will return null if no subject exists.
*
* @return The subject of the document.
*/
public String getSubject()
{
return info.getString( COSName.SUBJECT );
}
/**
* This will set the subject of the document.
*
* @param subject The new subject for the document.
*/
public void setSubject( String subject )
{
info.setString( COSName.SUBJECT, subject );
}
/**
* This will get the keywords of the document. This will return null if no keywords exists.
*
* @return The keywords of the document.
*/
public String getKeywords()
{
return info.getString( COSName.KEYWORDS );
}
/**
* This will set the keywords of the document.
*
* @param keywords The new keywords for the document.
*/
public void setKeywords( String keywords )
{
info.setString( COSName.KEYWORDS, keywords );
}
/**
* This will get the creator of the document. This will return null if no creator exists.
*
* @return The creator of the document.
*/
public String getCreator()
{
return info.getString( COSName.CREATOR );
}
/**
* This will set the creator of the document.
*
* @param creator The new creator for the document.
*/
public void setCreator( String creator )
{
info.setString( COSName.CREATOR, creator );
}
/**
* This will get the producer of the document. This will return null if no producer exists.
*
* @return The producer of the document.
*/
public String getProducer()
{
return info.getString( COSName.PRODUCER );
}
/**
* This will set the producer of the document.
*
* @param producer The new producer for the document.
*/
public void setProducer( String producer )
{
info.setString( COSName.PRODUCER, producer );
}
/**
* This will get the creation date of the document. This will return null if no creation date exists.
*
* @return The creation date of the document.
*/
public Calendar getCreationDate()
{
return info.getDate( COSName.CREATION_DATE );
}
/**
* This will set the creation date of the document.
*
* @param date The new creation date for the document.
*/
public void setCreationDate( Calendar date )
{
info.setDate( COSName.CREATION_DATE, date );
}
/**
* This will get the modification date of the document. This will return null if no modification date exists.
*
* @return The modification date of the document.
*/
public Calendar getModificationDate()
{
return info.getDate( COSName.MOD_DATE );
}
/**
* This will set the modification date of the document.
*
* @param date The new modification date for the document.
*/
public void setModificationDate( Calendar date )
{
info.setDate( COSName.MOD_DATE, date );
}
/**
* This will get the trapped value for the document.
* This will return null if one is not found.
*
* @return The trapped value for the document.
*/
public String getTrapped()
{
return info.getNameAsString( COSName.TRAPPED );
}
/**
* This will get the keys of all metadata information fields for the document.
*
* @return all metadata key strings.
* @since Apache PDFBox 1.3.0
*/
public Set<String> getMetadataKeys()
{
Set<String> keys = new TreeSet<>();
for (COSName key : info.keySet())
{
keys.add(key.getName());
}
return keys;
}
/**
* This will get the value of a custom metadata information field for the document.
* This will return null if one is not found.
*
* @param fieldName Name of custom metadata field from pdf document.
*
* @return String Value of metadata field
*/
public String getCustomMetadataValue(String fieldName)
{
return info.getString( fieldName );
}
/**
* Set the custom metadata value.
*
* @param fieldName The name of the custom metadata field.
* @param fieldValue The value to the custom metadata field.
*/
public void setCustomMetadataValue( String fieldName, String fieldValue )
{
info.setString( fieldName, fieldValue );
}
/**
* This will set the trapped of the document. This will be
* 'True', 'False', or 'Unknown'.
*
* @param value The new trapped value for the document.
*
* @throws IllegalArgumentException if the parameter is invalid.
*/
public void setTrapped( String value )
{<FILL_FUNCTION_BODY>}
}
|
if( value != null &&
!value.equals( "True" ) &&
!value.equals( "False" ) &&
!value.equals( "Unknown" ) )
{
throw new IllegalArgumentException( "Valid values for trapped are " +
"'True', 'False', or 'Unknown'" );
}
info.setName( COSName.TRAPPED, value );
| 1,912
| 101
| 2,013
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java
|
PDDocumentNameDestinationDictionary
|
getDestination
|
class PDDocumentNameDestinationDictionary implements COSObjectable
{
private final COSDictionary nameDictionary;
/**
* Constructor.
*
* @param dict The dictionary of names and corresponding destinations.
*/
public PDDocumentNameDestinationDictionary(COSDictionary dict)
{
this.nameDictionary = dict;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos dictionary for this object.
*/
@Override
public COSDictionary getCOSObject()
{
return nameDictionary;
}
/**
* Returns the destination corresponding to the parameter.
*
* @param name The destination name.
* @return The destination for that name, or null if there isn't any.
*
* @throws IOException if something goes wrong when creating the destination object.
*/
public PDDestination getDestination(String name) throws IOException
{<FILL_FUNCTION_BODY>}
}
|
COSBase item = nameDictionary.getDictionaryObject(name);
// "The value of this entry shall be a dictionary in which each key is a destination name
// and the corresponding value is either an array defining the destination (...)
// or a dictionary with a D entry whose value is such an array."
if (item instanceof COSArray)
{
return PDDestination.create(item);
}
else if (item instanceof COSDictionary)
{
COSDictionary dict = (COSDictionary) item;
if (dict.containsKey(COSName.D))
{
return PDDestination.create(dict.getDictionaryObject(COSName.D));
}
}
return null;
| 257
| 183
| 440
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java
|
PDDocumentNameDictionary
|
getDests
|
class PDDocumentNameDictionary implements COSObjectable
{
private final COSDictionary nameDictionary;
private final PDDocumentCatalog catalog;
/**
* Constructor.
*
* @param cat The document catalog that this dictionary is part of.
*/
public PDDocumentNameDictionary( PDDocumentCatalog cat )
{
COSDictionary names = cat.getCOSObject().getCOSDictionary(COSName.NAMES);
if (names == null)
{
names = new COSDictionary();
cat.getCOSObject().setItem(COSName.NAMES, names);
}
nameDictionary = names;
catalog = cat;
}
/**
* Constructor.
*
* @param cat The document that this dictionary is part of.
* @param names The names dictionary.
*/
public PDDocumentNameDictionary( PDDocumentCatalog cat, COSDictionary names )
{
catalog = cat;
nameDictionary = names;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos dictionary for this object.
*/
@Override
public COSDictionary getCOSObject()
{
return nameDictionary;
}
/**
* Get the destination named tree node. The values in this name tree will be
* PDPageDestination objects.
*
* @return The destination name tree node.
*/
public PDDestinationNameTreeNode getDests()
{<FILL_FUNCTION_BODY>}
/**
* Set the named destinations that are associated with this document.
*
* @param dests The destination names.
*/
public void setDests( PDDestinationNameTreeNode dests )
{
nameDictionary.setItem( COSName.DESTS, dests );
//The dests can either be in the document catalog or in the
//names dictionary, PDFBox will just maintain the one in the
//names dictionary for now unless there is a reason to do
//something else.
//clear the potentially out of date Dests reference.
catalog.getCOSObject().setItem( COSName.DESTS, (COSObjectable)null);
}
/**
* Get the embedded files named tree node. The values in this name tree will
* be PDComplexFileSpecification objects.
*
* @return The embedded files name tree node.
*/
public PDEmbeddedFilesNameTreeNode getEmbeddedFiles()
{
COSDictionary dic = nameDictionary.getCOSDictionary(COSName.EMBEDDED_FILES);
return dic != null ? new PDEmbeddedFilesNameTreeNode(dic) : null;
}
/**
* Set the named embedded files that are associated with this document.
*
* @param ef The new embedded files
*/
public void setEmbeddedFiles( PDEmbeddedFilesNameTreeNode ef )
{
nameDictionary.setItem( COSName.EMBEDDED_FILES, ef );
}
/**
* Get the document level JavaScript name tree. When the document is opened, all the JavaScript
* actions in it shall be executed, defining JavaScript functions for use by other scripts in
* the document.
*
* @return The document level JavaScript name tree.
*/
public PDJavascriptNameTreeNode getJavaScript()
{
COSDictionary dic = nameDictionary.getCOSDictionary(COSName.JAVA_SCRIPT);
return dic != null ? new PDJavascriptNameTreeNode(dic) : null;
}
/**
* Set the named javascript entries that are associated with this document.
*
* @param js The new Javascript entries.
*/
public void setJavascript( PDJavascriptNameTreeNode js )
{
nameDictionary.setItem( COSName.JAVA_SCRIPT, js );
}
}
|
COSDictionary dic = nameDictionary.getCOSDictionary(COSName.DESTS);
//The document catalog also contains the Dests entry sometimes
//so check there as well.
if( dic == null )
{
dic = catalog.getCOSObject().getCOSDictionary(COSName.DESTS);
}
return dic != null ? new PDDestinationNameTreeNode(dic) : null;
| 1,002
| 108
| 1,110
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
|
PDJavascriptNameTreeNode
|
convertCOSToPD
|
class PDJavascriptNameTreeNode extends PDNameTreeNode<PDActionJavaScript>
{
/**
* Constructor.
*/
public PDJavascriptNameTreeNode()
{
super();
}
/**
* Constructor.
*
* @param dic The COS dictionary.
*/
public PDJavascriptNameTreeNode( COSDictionary dic )
{
super(dic);
}
@Override
protected PDActionJavaScript convertCOSToPD( COSBase base ) throws IOException
{<FILL_FUNCTION_BODY>}
@Override
protected PDNameTreeNode<PDActionJavaScript> createChildNode( COSDictionary dic )
{
return new PDJavascriptNameTreeNode(dic);
}
}
|
if (!(base instanceof COSDictionary))
{
throw new IOException( "Error creating Javascript object, expected a COSDictionary and not " + base);
}
return (PDActionJavaScript)PDActionFactory.createAction((COSDictionary) base);
| 206
| 67
| 273
|
<methods>public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public List<PDNameTreeNode<org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript>> getKids() ,public java.lang.String getLowerLimit() ,public Map<java.lang.String,org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript> getNames() throws java.io.IOException,public PDNameTreeNode<org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript> getParent() ,public java.lang.String getUpperLimit() ,public org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript getValue(java.lang.String) throws java.io.IOException,public boolean isRootNode() ,public void setKids(List<? extends PDNameTreeNode<org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript>>) ,public void setNames(Map<java.lang.String,org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript>) ,public void setParent(PDNameTreeNode<org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript>) <variables>private static final Logger LOG,private final non-sealed org.apache.pdfbox.cos.COSDictionary node,private PDNameTreeNode<org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript> parent
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSDictionaryMap.java
|
COSDictionaryMap
|
remove
|
class COSDictionaryMap<K,V> implements Map<K,V>
{
private final COSDictionary map;
private final Map<K,V> actuals;
/**
* Constructor for this map.
*
* @param actualsMap The map with standard java objects as values.
* @param dicMap The map with COSBase objects as values.
*/
public COSDictionaryMap( Map<K,V> actualsMap, COSDictionary dicMap )
{
actuals = actualsMap;
map = dicMap;
}
/**
* {@inheritDoc}
*/
@Override
public int size()
{
return map.size();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEmpty()
{
return size() == 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsKey(Object key)
{
return actuals.containsKey( key );
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsValue(Object value)
{
return actuals.containsValue( value );
}
/**
* {@inheritDoc}
*/
@Override
public V get(Object key)
{
return actuals.get( key );
}
/**
* {@inheritDoc}
*/
@Override
public V put(K key, V value)
{
COSObjectable object = (COSObjectable)value;
map.setItem( COSName.getPDFName( (String)key ), object.getCOSObject() );
return actuals.put( key, value );
}
/**
* {@inheritDoc}
*/
@Override
public V remove(Object key)
{<FILL_FUNCTION_BODY>}
/**
* {@inheritDoc}
*/
@Override
public void putAll(Map<? extends K, ? extends V> t)
{
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* {@inheritDoc}
*/
@Override
public void clear()
{
map.clear();
actuals.clear();
}
/**
* {@inheritDoc}
*/
@Override
public Set<K> keySet()
{
return actuals.keySet();
}
/**
* {@inheritDoc}
*/
@Override
public Collection<V> values()
{
return actuals.values();
}
/**
* {@inheritDoc}
*/
@Override
public Set<Map.Entry<K, V>> entrySet()
{
return Collections.unmodifiableSet(actuals.entrySet());
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o)
{
boolean retval = false;
if( o instanceof COSDictionaryMap )
{
COSDictionaryMap<K, V> other = (COSDictionaryMap<K, V>) o;
retval = other.map.equals( this.map );
}
return retval;
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{
return actuals.toString();
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
return map.hashCode();
}
/**
* This will take a map<java.lang.String,org.apache.pdfbox.pdmodel.COSObjectable>
* and convert it into a COSDictionary.
*
* @param someMap A map containing COSObjectables
*
* @return A proper COSDictionary
*/
public static COSDictionary convert(Map<String, ?> someMap)
{
COSDictionary dic = new COSDictionary();
someMap.forEach((name, objectable) ->
{
COSObjectable object = (COSObjectable) objectable;
dic.setItem(COSName.getPDFName(name), object.getCOSObject());
});
return dic;
}
/**
* This will take a COS dictionary and convert it into COSDictionaryMap. All cos
* objects will be converted to their primitive form.
*
* @param map The COS mappings.
* @return A standard java map.
* @throws IOException If there is an error during the conversion.
*/
public static COSDictionaryMap<String, Object> convertBasicTypesToMap( COSDictionary map ) throws IOException
{
COSDictionaryMap<String, Object> retval = null;
if( map != null )
{
Map<String, Object> actualMap = new HashMap<>();
for( COSName key : map.keySet() )
{
COSBase cosObj = map.getDictionaryObject( key );
Object actualObject = null;
if( cosObj instanceof COSString )
{
actualObject = ((COSString)cosObj).getString();
}
else if( cosObj instanceof COSInteger )
{
actualObject = ((COSInteger)cosObj).intValue();
}
else if( cosObj instanceof COSName )
{
actualObject = ((COSName)cosObj).getName();
}
else if( cosObj instanceof COSFloat )
{
actualObject = ((COSFloat)cosObj).floatValue();
}
else if( cosObj instanceof COSBoolean )
{
actualObject = ((COSBoolean)cosObj).getValue() ? Boolean.TRUE : Boolean.FALSE;
}
else
{
throw new IOException( "Error:unknown type of object to convert:" + cosObj );
}
actualMap.put( key.getName(), actualObject );
}
retval = new COSDictionaryMap<>( actualMap, map );
}
return retval;
}
}
|
map.removeItem( COSName.getPDFName( (String)key ) );
return actuals.remove( key );
| 1,543
| 34
| 1,577
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDDictionaryWrapper.java
|
PDDictionaryWrapper
|
equals
|
class PDDictionaryWrapper implements COSObjectable
{
private final COSDictionary dictionary;
/**
* Default constructor
*/
public PDDictionaryWrapper()
{
this.dictionary = new COSDictionary();
}
/**
* Creates a new instance with a given COS dictionary.
*
* @param dictionary the dictionary
*/
public PDDictionaryWrapper(COSDictionary dictionary)
{
this.dictionary = dictionary;
}
/**
* {@inheritDoc}
*/
@Override
public COSDictionary getCOSObject()
{
return this.dictionary;
}
@Override
public boolean equals(Object obj)
{<FILL_FUNCTION_BODY>}
@Override
public int hashCode()
{
return this.dictionary.hashCode();
}
}
|
if (this == obj)
{
return true;
}
if (obj instanceof PDDictionaryWrapper)
{
return this.dictionary.equals(((PDDictionaryWrapper) obj).dictionary);
}
return false;
| 227
| 65
| 292
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDPageLabelRange.java
|
PDPageLabelRange
|
setStart
|
class PDPageLabelRange implements COSObjectable
{
private final COSDictionary root;
// Page label dictionary (PDF32000-1:2008 Section 12.4.2, Table 159)
private static final COSName KEY_START = COSName.ST;
private static final COSName KEY_PREFIX = COSName.P;
private static final COSName KEY_STYLE = COSName.S;
// Style entry values (PDF32000-1:2008 Section 12.4.2, Table 159)
/**
* Decimal page numbering style (1, 2, 3, ...).
*/
public static final String STYLE_DECIMAL = "D";
/**
* Roman numbers (upper case) numbering style (I, II, III, IV, ...).
*/
public static final String STYLE_ROMAN_UPPER = "R";
/**
* Roman numbers (lower case) numbering style (i, ii, iii, iv, ...).
*/
public static final String STYLE_ROMAN_LOWER = "r";
/**
* Letter (upper case) numbering style (A, B, ..., Z, AA, BB, ..., ZZ, AAA,
* ...).
*/
public static final String STYLE_LETTERS_UPPER = "A";
/**
* Letter (lower case) numbering style (a, b, ..., z, aa, bb, ..., zz, aaa,
* ...).
*/
public static final String STYLE_LETTERS_LOWER = "a";
/**
* Creates a new empty page label range object.
*/
public PDPageLabelRange()
{
this(new COSDictionary());
}
/**
* Creates a new page label range object from the given dictionary.
*
* @param dict
* the base dictionary for the new object.
*/
public PDPageLabelRange(COSDictionary dict)
{
root = dict;
}
/**
* Returns the underlying dictionary.
*
* @return the underlying dictionary.
*/
@Override
public COSDictionary getCOSObject()
{
return root;
}
/**
* Returns the numbering style for this page range.
*
* @return one of the STYLE_* constants
*/
public String getStyle()
{
return root.getNameAsString(KEY_STYLE);
}
/**
* Sets the numbering style for this page range.
*
* @param style
* one of the STYLE_* constants or {@code null} if no page
* numbering is desired.
*/
public void setStyle(String style)
{
if (style != null)
{
root.setName(KEY_STYLE, style);
}
else
{
root.removeItem(KEY_STYLE);
}
}
/**
* Returns the start value for page numbering in this page range.
*
* @return a positive integer the start value for numbering.
*/
public int getStart()
{
return root.getInt(KEY_START, 1);
}
/**
* Sets the start value for page numbering in this page range.
*
* @param start
* a positive integer representing the start value.
* @throws IllegalArgumentException
* if {@code start} is not a positive integer
*/
public void setStart(int start)
{<FILL_FUNCTION_BODY>}
/**
* Returns the page label prefix for this page range.
*
* @return the page label prefix for this page range, or {@code null} if no
* prefix has been defined.
*/
public String getPrefix()
{
return root.getString(KEY_PREFIX);
}
/**
* Sets the page label prefix for this page range.
*
* @param prefix
* the page label prefix for this page range, or {@code null} to
* unset the prefix.
*/
public void setPrefix(String prefix)
{
if (prefix != null)
{
root.setString(KEY_PREFIX, prefix);
}
else
{
root.removeItem(KEY_PREFIX);
}
}
}
|
if (start <= 0)
{
throw new IllegalArgumentException(
"The page numbering start value must be a positive integer");
}
root.setInt(KEY_START, start);
| 1,154
| 52
| 1,206
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRange.java
|
PDRange
|
toString
|
class PDRange implements COSObjectable
{
private final COSArray rangeArray;
private int startingIndex;
/**
* Constructor with an initial range of 0..1.
*/
public PDRange()
{
rangeArray = new COSArray();
rangeArray.add(COSFloat.ZERO);
rangeArray.add(COSFloat.ONE);
startingIndex = 0;
}
/**
* Constructor assumes a starting index of 0.
*
* @param range The array that describes the range.
*/
public PDRange( COSArray range )
{
rangeArray = range;
}
/**
* Constructor with an index into an array. Because some arrays specify
* multiple ranges ie [ 0,1, 0,2, 2,3 ] It is convenient for this
* class to take an index into an array. So if you want this range to
* represent 0,2 in the above example then you would say <code>new PDRange( array, 1 )</code>.
*
* @param range The array that describes the index
* @param index The range index into the array for the start of the range.
*/
public PDRange( COSArray range, int index )
{
rangeArray = range;
startingIndex = index;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSBase getCOSObject()
{
return rangeArray;
}
/**
* This will get the underlying array value.
*
* @return The cos object that this object wraps.
*/
public COSArray getCOSArray()
{
return rangeArray;
}
/**
* This will get the minimum value of the range.
*
* @return The min value.
*/
public float getMin()
{
COSNumber min = (COSNumber)rangeArray.getObject( startingIndex*2 );
return min.floatValue();
}
/**
* This will set the minimum value for the range.
*
* @param min The new minimum for the range.
*/
public void setMin( float min )
{
rangeArray.set( startingIndex*2, new COSFloat( min ) );
}
/**
* This will get the maximum value of the range.
*
* @return The max value.
*/
public float getMax()
{
COSNumber max = (COSNumber)rangeArray.getObject( startingIndex*2+1 );
return max.floatValue();
}
/**
* This will set the maximum value for the range.
*
* @param max The new maximum for the range.
*/
public void setMax( float max )
{
rangeArray.set( startingIndex*2+1, new COSFloat( max ) );
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return "PDRange{" + getMin() + ", " + getMax() + '}';
| 812
| 26
| 838
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDEmbeddedFile.java
|
PDEmbeddedFile
|
setMacSubtype
|
class PDEmbeddedFile extends PDStream
{
/**
* {@inheritDoc}
*/
public PDEmbeddedFile( PDDocument document )
{
super( document );
getCOSObject().setItem(COSName.TYPE, COSName.EMBEDDED_FILE);
}
/**
* {@inheritDoc}
*/
public PDEmbeddedFile( COSStream str )
{
super(str);
}
/**
* {@inheritDoc}
*/
public PDEmbeddedFile( PDDocument doc, InputStream str ) throws IOException
{
super(doc, str);
getCOSObject().setItem(COSName.TYPE, COSName.EMBEDDED_FILE);
}
/**
* {@inheritDoc}
* @param filter Filter to apply to the stream.
*
* @throws IOException {@inheritDoc}
*/
public PDEmbeddedFile(PDDocument doc, InputStream input, COSName filter) throws IOException
{
super(doc, input, filter);
getCOSObject().setItem(COSName.TYPE, COSName.EMBEDDED_FILE);
}
/**
* Set the subtype for this embedded file. This should be a mime type value. Optional.
*
* @param mimeType The mimeType for the file.
*/
public void setSubtype( String mimeType )
{
getCOSObject().setName(COSName.SUBTYPE, mimeType);
}
/**
* Get the subtype(mimetype) for the embedded file.
*
* @return The type of embedded file.
*/
public String getSubtype()
{
return getCOSObject().getNameAsString(COSName.SUBTYPE );
}
/**
* Get the size of the embedded file.
*
* @return The size of the embedded file.
*/
public int getSize()
{
return getCOSObject().getEmbeddedInt(COSName.PARAMS, COSName.SIZE);
}
/**
* Set the size of the embedded file.
*
* @param size The size of the embedded file.
*/
public void setSize( int size )
{
getCOSObject().setEmbeddedInt(COSName.PARAMS, COSName.SIZE, size);
}
/**
* Get the creation date of the embedded file.
*
* @return The Creation date.
* @throws IOException If there is an error while constructing the date.
*/
public Calendar getCreationDate() throws IOException
{
return getCOSObject().getEmbeddedDate(COSName.PARAMS, COSName.CREATION_DATE);
}
/**
* Set the creation date.
*
* @param creation The new creation date.
*/
public void setCreationDate( Calendar creation )
{
getCOSObject().setEmbeddedDate(COSName.PARAMS, COSName.CREATION_DATE, creation);
}
/**
* Get the mod date of the embedded file.
*
* @return The mod date.
* @throws IOException If there is an error while constructing the date.
*/
public Calendar getModDate() throws IOException
{
return getCOSObject().getEmbeddedDate(COSName.PARAMS, COSName.MOD_DATE);
}
/**
* Set the mod date.
*
* @param mod The new creation mod.
*/
public void setModDate( Calendar mod )
{
getCOSObject().setEmbeddedDate(COSName.PARAMS, COSName.MOD_DATE, mod);
}
/**
* Get the check sum of the embedded file.
*
* @return The check sum of the file.
*/
public String getCheckSum()
{
return getCOSObject().getEmbeddedString(COSName.PARAMS, COSName.CHECK_SUM);
}
/**
* Set the check sum.
*
* @param checksum The checksum of the file.
*/
public void setCheckSum( String checksum )
{
getCOSObject().setEmbeddedString(COSName.PARAMS, COSName.CHECK_SUM, checksum);
}
/**
* Get the mac subtype.
*
* @return The mac subtype.
*/
public String getMacSubtype()
{
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
return params != null ? params.getEmbeddedString(COSName.MAC, COSName.SUBTYPE) : null;
}
/**
* Set the mac subtype.
*
* @param macSubtype The mac subtype.
*/
public void setMacSubtype( String macSubtype )
{<FILL_FUNCTION_BODY>}
/**
* Get the mac Creator.
*
* @return The mac Creator.
*/
public String getMacCreator()
{
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
return params != null ? params.getEmbeddedString(COSName.MAC, COSName.CREATOR) : null;
}
/**
* Set the mac Creator.
*
* @param macCreator The mac Creator.
*/
public void setMacCreator( String macCreator )
{
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
if( params == null && macCreator != null )
{
params = new COSDictionary();
getCOSObject().setItem( COSName.PARAMS, params );
}
if( params != null )
{
params.setEmbeddedString(COSName.MAC, COSName.CREATOR, macCreator);
}
}
/**
* Get the mac ResFork.
*
* @return The mac ResFork.
*/
public String getMacResFork()
{
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
return params != null ? params.getEmbeddedString(COSName.MAC, COSName.RES_FORK) : null;
}
/**
* Set the mac ResFork.
*
* @param macResFork The mac ResFork.
*/
public void setMacResFork( String macResFork )
{
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
if( params == null && macResFork != null )
{
params = new COSDictionary();
getCOSObject().setItem( COSName.PARAMS, params );
}
if( params != null )
{
params.setEmbeddedString(COSName.MAC, COSName.RES_FORK, macResFork);
}
}
}
|
COSDictionary params = getCOSObject().getCOSDictionary(COSName.PARAMS);
if( params == null && macSubtype != null )
{
params = new COSDictionary();
getCOSObject().setItem( COSName.PARAMS, params );
}
if( params != null )
{
params.setEmbeddedString(COSName.MAC, COSName.SUBTYPE, macSubtype);
}
| 1,855
| 119
| 1,974
|
<methods>public void <init>(org.apache.pdfbox.pdmodel.PDDocument) ,public void <init>(org.apache.pdfbox.cos.COSDocument) ,public void <init>(org.apache.pdfbox.cos.COSStream) ,public void <init>(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream) throws java.io.IOException,public void <init>(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream, org.apache.pdfbox.cos.COSName) throws java.io.IOException,public void <init>(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream, org.apache.pdfbox.cos.COSArray) throws java.io.IOException,public org.apache.pdfbox.cos.COSInputStream createInputStream() throws java.io.IOException,public org.apache.pdfbox.cos.COSInputStream createInputStream(org.apache.pdfbox.filter.DecodeOptions) throws java.io.IOException,public java.io.InputStream createInputStream(List<java.lang.String>) throws java.io.IOException,public java.io.OutputStream createOutputStream() throws java.io.IOException,public java.io.OutputStream createOutputStream(org.apache.pdfbox.cos.COSName) throws java.io.IOException,public org.apache.pdfbox.cos.COSStream getCOSObject() ,public List<java.lang.Object> getDecodeParms() throws java.io.IOException,public int getDecodedStreamLength() ,public org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification getFile() throws java.io.IOException,public List<java.lang.Object> getFileDecodeParams() throws java.io.IOException,public List<java.lang.String> getFileFilters() ,public List<org.apache.pdfbox.cos.COSName> getFilters() ,public int getLength() ,public org.apache.pdfbox.pdmodel.common.PDMetadata getMetadata() ,public void setDecodeParms(List<?>) ,public void setDecodedStreamLength(int) ,public void setFile(org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification) ,public void setFileDecodeParams(List<?>) ,public void setFileFilters(List<java.lang.String>) ,public void setFilters(List<org.apache.pdfbox.cos.COSName>) ,public void setMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) ,public byte[] toByteArray() throws java.io.IOException<variables>private static final Logger LOG,private final non-sealed org.apache.pdfbox.cos.COSStream stream
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDFileSpecification.java
|
PDFileSpecification
|
createFS
|
class PDFileSpecification implements COSObjectable
{
/**
* A file specification can either be a COSString or a COSDictionary. This
* will create the file specification either way.
*
* @param base The cos object that describes the fs.
*
* @return The file specification for the COSBase object.
*
* @throws IOException If there is an error creating the file spec.
*/
public static PDFileSpecification createFS( COSBase base ) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* This will get the file name.
*
* @return The file name.
*/
public abstract String getFile();
/**
* This will set the file name.
*
* @param file The name of the file.
*/
public abstract void setFile( String file );
}
|
PDFileSpecification retval = null;
if( base == null )
{
//then simply return null
}
else if( base instanceof COSString )
{
retval = new PDSimpleFileSpecification( (COSString)base );
}
else if( base instanceof COSDictionary )
{
retval = new PDComplexFileSpecification( (COSDictionary)base );
}
else
{
throw new IOException( "Error: Unknown file specification " + base );
}
return retval;
| 223
| 142
| 365
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
|
Rinterpol
|
getSamples
|
class Rinterpol
{
// coordinate that is to be interpolated
private final float[] in;
// coordinate of the "ceil" point
private final int[] inPrev;
// coordinate of the "floor" point
private final int[] inNext;
private final int numberOfInputValues;
private final int numberOfOutputValues = getNumberOfOutputParameters();
/**
* Constructor.
*
* @param input the input coordinates
* @param inputPrev coordinate of the "ceil" point
* @param inputNext coordinate of the "floor" point
*
*/
Rinterpol(float[] input, int[] inputPrev, int[] inputNext)
{
in = input;
inPrev = inputPrev;
inNext = inputNext;
numberOfInputValues = input.length;
}
/**
* Calculate the interpolation.
*
* @return interpolated result sample
*/
float[] rinterpolate()
{
return rinterpol(new int[numberOfInputValues], 0);
}
/**
* Do a linear interpolation if the two coordinates can be known, or
* call itself recursively twice.
*
* @param coord coord partially set coordinate (not set from step
* upwards); gets fully filled in the last call ("leaf"), where it is
* used to get the correct sample
* @param step between 0 (first call) and dimension - 1
* @return interpolated result sample
*/
private float[] rinterpol(int[] coord, int step)
{
float[] resultSample = new float[numberOfOutputValues];
if (step == in.length - 1)
{
// leaf
if (inPrev[step] == inNext[step])
{
coord[step] = inPrev[step];
int[] tmpSample = getSamples()[calcSampleIndex(coord)];
for (int i = 0; i < numberOfOutputValues; ++i)
{
resultSample[i] = tmpSample[i];
}
return resultSample;
}
coord[step] = inPrev[step];
int[] sample1 = getSamples()[calcSampleIndex(coord)];
coord[step] = inNext[step];
int[] sample2 = getSamples()[calcSampleIndex(coord)];
for (int i = 0; i < numberOfOutputValues; ++i)
{
resultSample[i] = interpolate(in[step], inPrev[step], inNext[step], sample1[i], sample2[i]);
}
return resultSample;
}
else
{
// branch
if (inPrev[step] == inNext[step])
{
coord[step] = inPrev[step];
return rinterpol(coord, step + 1);
}
coord[step] = inPrev[step];
float[] sample1 = rinterpol(coord, step + 1);
coord[step] = inNext[step];
float[] sample2 = rinterpol(coord, step + 1);
for (int i = 0; i < numberOfOutputValues; ++i)
{
resultSample[i] = interpolate(in[step], inPrev[step], inNext[step], sample1[i], sample2[i]);
}
return resultSample;
}
}
/**
* calculate array index (structure described in p.171 PDF spec 1.7) in multiple dimensions.
*
* @param vector with coordinates
* @return index in flat array
*/
private int calcSampleIndex(int[] vector)
{
// inspiration: http://stackoverflow.com/a/12113479/535646
// but used in reverse
float[] sizeValues = getSize().toFloatArray();
int index = 0;
int sizeProduct = 1;
int dimension = vector.length;
for (int i = dimension - 2; i >= 0; --i)
{
sizeProduct *= sizeValues[i];
}
for (int i = dimension - 1; i >= 0; --i)
{
index += sizeProduct * vector[i];
if (i - 1 >= 0)
{
sizeProduct /= sizeValues[i - 1];
}
}
return index;
}
/**
* Get all sample values of this function.
*
* @return an array with all samples.
*/
private int[][] getSamples()
{<FILL_FUNCTION_BODY>}
}
|
if (samples == null)
{
int arraySize = 1;
int nIn = getNumberOfInputParameters();
int nOut = getNumberOfOutputParameters();
COSArray sizes = getSize();
for (int i = 0; i < nIn; i++)
{
arraySize *= sizes.getInt(i);
}
samples = new int[arraySize][nOut];
int bitsPerSample = getBitsPerSample();
int index = 0;
try (InputStream is = getPDStream().createInputStream())
{
// PDF spec 1.7 p.171:
// Each sample value is represented as a sequence of BitsPerSample bits.
// Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
try (ImageInputStream mciis = new MemoryCacheImageInputStream(is))
{
for (int i = 0; i < arraySize; i++)
{
for (int k = 0; k < nOut; k++)
{
// TODO will this cast work properly for 32 bitsPerSample or should we use long[]?
samples[index][k] = (int) mciis.readBits(bitsPerSample);
}
index++;
}
}
}
catch (IOException exception)
{
LOG.error("IOException while reading the sample values of this function.", exception);
}
}
return samples;
| 1,161
| 362
| 1,523
|
<methods>public void <init>(org.apache.pdfbox.cos.COSBase) ,public static org.apache.pdfbox.pdmodel.common.function.PDFunction create(org.apache.pdfbox.cos.COSBase) throws java.io.IOException,public abstract float[] eval(float[]) throws java.io.IOException,public final org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.pdmodel.common.PDRange getDomainForInput(int) ,public abstract int getFunctionType() ,public int getNumberOfInputParameters() ,public int getNumberOfOutputParameters() ,public org.apache.pdfbox.pdmodel.common.PDRange getRangeForOutput(int) ,public void setDomainValues(org.apache.pdfbox.cos.COSArray) ,public void setRangeValues(org.apache.pdfbox.cos.COSArray) ,public java.lang.String toString() <variables>private org.apache.pdfbox.cos.COSArray domain,private org.apache.pdfbox.cos.COSDictionary functionDictionary,private org.apache.pdfbox.pdmodel.common.PDStream functionStream,private int numberOfInputValues,private int numberOfOutputValues,private org.apache.pdfbox.cos.COSArray range
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java
|
PDFunctionType2
|
toString
|
class PDFunctionType2 extends PDFunction
{
/**
* The C0 values of the exponential function.
*/
private final COSArray c0;
/**
* The C1 values of the exponential function.
*/
private final COSArray c1;
/**
* The exponent value of the exponential function.
*/
private final float exponent;
/**
* Constructor.
*
* @param function The function.
*/
public PDFunctionType2(COSBase function)
{
super(function);
c0 = Objects.requireNonNullElseGet(getCOSObject().getCOSArray(COSName.C0), COSArray::new);
if (c0.isEmpty())
{
c0.add(COSFloat.ZERO);
}
c1 = Objects.requireNonNullElseGet(getCOSObject().getCOSArray(COSName.C1), COSArray::new);
if (c1.isEmpty())
{
c1.add(COSFloat.ONE);
}
exponent = getCOSObject().getFloat(COSName.N);
}
/**
* {@inheritDoc}
*/
@Override
public int getFunctionType()
{
return 2;
}
/**
* Performs exponential interpolation
*
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException
{
// exponential interpolation
float xToN = (float) Math.pow(input[0], exponent); // x^exponent
float[] result = new float[Math.min(c0.size(), c1.size())];
for (int j = 0; j < result.length; j++)
{
float c0j = ((COSNumber) c0.get(j)).floatValue();
float c1j = ((COSNumber) c1.get(j)).floatValue();
result[j] = c0j + xToN * (c1j - c0j);
}
return clipToRange(result);
}
/**
* Returns the C0 values of the function, 0 if empty.
*
* @return a COSArray with the C0 values
*/
public COSArray getC0()
{
return c0;
}
/**
* Returns the C1 values of the function, 1 if empty.
*
* @return a COSArray with the C1 values
*/
public COSArray getC1()
{
return c1;
}
/**
* Returns the exponent of the function.
*
* @return the float value of the exponent
*/
public float getN()
{
return exponent;
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return "FunctionType2{"
+ "C0: " + getC0() + " "
+ "C1: " + getC1() + " "
+ "N: " + getN() + "}";
| 759
| 58
| 817
|
<methods>public void <init>(org.apache.pdfbox.cos.COSBase) ,public static org.apache.pdfbox.pdmodel.common.function.PDFunction create(org.apache.pdfbox.cos.COSBase) throws java.io.IOException,public abstract float[] eval(float[]) throws java.io.IOException,public final org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.pdmodel.common.PDRange getDomainForInput(int) ,public abstract int getFunctionType() ,public int getNumberOfInputParameters() ,public int getNumberOfOutputParameters() ,public org.apache.pdfbox.pdmodel.common.PDRange getRangeForOutput(int) ,public void setDomainValues(org.apache.pdfbox.cos.COSArray) ,public void setRangeValues(org.apache.pdfbox.cos.COSArray) ,public java.lang.String toString() <variables>private org.apache.pdfbox.cos.COSArray domain,private org.apache.pdfbox.cos.COSDictionary functionDictionary,private org.apache.pdfbox.pdmodel.common.PDStream functionStream,private int numberOfInputValues,private int numberOfOutputValues,private org.apache.pdfbox.cos.COSArray range
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType4.java
|
PDFunctionType4
|
eval
|
class PDFunctionType4 extends PDFunction
{
private static final Operators OPERATORS = new Operators();
private final InstructionSequence instructions;
/**
* Constructor.
*
* @param functionStream The function stream.
* @throws IOException if an I/O error occurs while reading the function
*/
public PDFunctionType4(COSBase functionStream) throws IOException
{
super( functionStream );
byte[] bytes = getPDStream().toByteArray();
String string = new String(bytes, StandardCharsets.ISO_8859_1);
this.instructions = InstructionSequenceBuilder.parse(string);
}
/**
* {@inheritDoc}
*/
@Override
public int getFunctionType()
{
return 4;
}
/**
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException
{<FILL_FUNCTION_BODY>}
}
|
//Setup the input values
ExecutionContext context = new ExecutionContext(OPERATORS);
for (int i = 0; i < input.length; i++)
{
PDRange domain = getDomainForInput(i);
float value = clipToRange(input[i], domain.getMin(), domain.getMax());
context.getStack().push(value);
}
//Execute the type 4 function.
instructions.execute(context);
//Extract the output values
int numberOfOutputValues = getNumberOfOutputParameters();
int numberOfActualOutputValues = context.getStack().size();
if (numberOfActualOutputValues < numberOfOutputValues)
{
throw new IllegalStateException("The type 4 function returned "
+ numberOfActualOutputValues
+ " values but the Range entry indicates that "
+ numberOfOutputValues + " values be returned.");
}
float[] outputValues = new float[numberOfOutputValues];
for (int i = numberOfOutputValues - 1; i >= 0; i--)
{
PDRange range = getRangeForOutput(i);
outputValues[i] = context.popReal();
outputValues[i] = clipToRange(outputValues[i], range.getMin(), range.getMax());
}
//Return the resulting array
return outputValues;
| 252
| 337
| 589
|
<methods>public void <init>(org.apache.pdfbox.cos.COSBase) ,public static org.apache.pdfbox.pdmodel.common.function.PDFunction create(org.apache.pdfbox.cos.COSBase) throws java.io.IOException,public abstract float[] eval(float[]) throws java.io.IOException,public final org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.pdmodel.common.PDRange getDomainForInput(int) ,public abstract int getFunctionType() ,public int getNumberOfInputParameters() ,public int getNumberOfOutputParameters() ,public org.apache.pdfbox.pdmodel.common.PDRange getRangeForOutput(int) ,public void setDomainValues(org.apache.pdfbox.cos.COSArray) ,public void setRangeValues(org.apache.pdfbox.cos.COSArray) ,public java.lang.String toString() <variables>private org.apache.pdfbox.cos.COSArray domain,private org.apache.pdfbox.cos.COSDictionary functionDictionary,private org.apache.pdfbox.pdmodel.common.PDStream functionStream,private int numberOfInputValues,private int numberOfOutputValues,private org.apache.pdfbox.cos.COSArray range
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionTypeIdentity.java
|
PDFunctionTypeIdentity
|
getFunctionType
|
class PDFunctionTypeIdentity extends PDFunction
{
public PDFunctionTypeIdentity(COSBase function)
{
super(null);
//TODO passing null is not good because getCOSObject() can result in an NPE in the base class
}
@Override
public int getFunctionType()
{<FILL_FUNCTION_BODY>}
@Override
public float[] eval(float[] input) throws IOException
{
return input;
}
@Override
protected COSArray getRangeValues()
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{
return "FunctionTypeIdentity";
}
}
|
// shouldn't be called
throw new UnsupportedOperationException();
//TODO this is a violation of the interface segregation principle
| 189
| 36
| 225
|
<methods>public void <init>(org.apache.pdfbox.cos.COSBase) ,public static org.apache.pdfbox.pdmodel.common.function.PDFunction create(org.apache.pdfbox.cos.COSBase) throws java.io.IOException,public abstract float[] eval(float[]) throws java.io.IOException,public final org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.pdmodel.common.PDRange getDomainForInput(int) ,public abstract int getFunctionType() ,public int getNumberOfInputParameters() ,public int getNumberOfOutputParameters() ,public org.apache.pdfbox.pdmodel.common.PDRange getRangeForOutput(int) ,public void setDomainValues(org.apache.pdfbox.cos.COSArray) ,public void setRangeValues(org.apache.pdfbox.cos.COSArray) ,public java.lang.String toString() <variables>private org.apache.pdfbox.cos.COSArray domain,private org.apache.pdfbox.cos.COSDictionary functionDictionary,private org.apache.pdfbox.pdmodel.common.PDStream functionStream,private int numberOfInputValues,private int numberOfOutputValues,private org.apache.pdfbox.cos.COSArray range
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/ArithmeticOperators.java
|
Round
|
execute
|
class Round implements Operator
{
@Override
public void execute(ExecutionContext context)
{<FILL_FUNCTION_BODY>}
}
|
Number num = context.popNumber();
if (num instanceof Integer)
{
context.getStack().push(num.intValue());
}
else
{
context.getStack().push((float)Math.round(num.doubleValue()));
}
| 42
| 70
| 112
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/BitwiseOperators.java
|
Not
|
execute
|
class Not implements Operator
{
@Override
public void execute(ExecutionContext context)
{<FILL_FUNCTION_BODY>}
}
|
Stack<Object> stack = context.getStack();
Object op1 = stack.pop();
if (op1 instanceof Boolean)
{
boolean bool1 = (Boolean)op1;
boolean result = !bool1;
stack.push(result);
}
else if (op1 instanceof Integer)
{
int int1 = (Integer)op1;
int result = -int1;
stack.push(result);
}
else
{
throw new ClassCastException("Operand must be bool or int");
}
| 42
| 140
| 182
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/ConditionalOperators.java
|
IfElse
|
execute
|
class IfElse implements Operator
{
@Override
public void execute(ExecutionContext context)
{<FILL_FUNCTION_BODY>}
}
|
Stack<Object> stack = context.getStack();
InstructionSequence proc2 = (InstructionSequence)stack.pop();
InstructionSequence proc1 = (InstructionSequence)stack.pop();
Boolean condition = (Boolean)stack.pop();
if (condition)
{
proc1.execute(context);
}
else
{
proc2.execute(context);
}
| 44
| 101
| 145
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/InstructionSequence.java
|
InstructionSequence
|
execute
|
class InstructionSequence
{
private final List<Object> instructions = new java.util.ArrayList<>();
/**
* Add a name (ex. an operator)
* @param name the name
*/
public void addName(String name)
{
this.instructions.add(name);
}
/**
* Adds an int value.
* @param value the value
*/
public void addInteger(int value)
{
this.instructions.add(value);
}
/**
* Adds a real value.
* @param value the value
*/
public void addReal(float value)
{
this.instructions.add(value);
}
/**
* Adds a bool value.
* @param value the value
*/
public void addBoolean(boolean value)
{
this.instructions.add(value);
}
/**
* Adds a proc (sub-sequence of instructions).
* @param child the child proc
*/
public void addProc(InstructionSequence child)
{
this.instructions.add(child);
}
/**
* Executes the instruction sequence.
* @param context the execution context
*/
public void execute(ExecutionContext context)
{<FILL_FUNCTION_BODY>}
}
|
Stack<Object> stack = context.getStack();
for (Object o : instructions)
{
if (o instanceof String)
{
String name = (String)o;
Operator cmd = context.getOperators().getOperator(name);
if (cmd != null)
{
cmd.execute(context);
}
else
{
throw new UnsupportedOperationException("Unknown operator or name: " + name);
}
}
else
{
stack.push(o);
}
}
//Handles top-level procs that simply need to be executed
while (!stack.isEmpty() && stack.peek() instanceof InstructionSequence)
{
InstructionSequence nested = (InstructionSequence)stack.pop();
nested.execute(context);
}
| 346
| 205
| 551
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/InstructionSequenceBuilder.java
|
InstructionSequenceBuilder
|
token
|
class InstructionSequenceBuilder extends Parser.AbstractSyntaxHandler
{
private static final Predicate<String> MATCHES_INTEGER = Pattern.compile("[\\+\\-]?\\d+").asMatchPredicate();
private static final Predicate<String> MATCHES_REAL = Pattern.compile("[\\-]?\\d*\\.\\d*([Ee]\\-?\\d+)?").asMatchPredicate();
private final InstructionSequence mainSequence = new InstructionSequence();
private final Stack<InstructionSequence> seqStack = new Stack<>();
private InstructionSequenceBuilder()
{
this.seqStack.push(this.mainSequence);
}
/**
* Returns the instruction sequence that has been build from the syntactic elements.
* @return the instruction sequence
*/
public InstructionSequence getInstructionSequence()
{
return this.mainSequence;
}
/**
* Parses the given text into an instruction sequence representing a Type 4 function
* that can be executed.
* @param text the Type 4 function text
* @return the instruction sequence
*/
public static InstructionSequence parse(CharSequence text)
{
InstructionSequenceBuilder builder = new InstructionSequenceBuilder();
Parser.parse(text, builder);
return builder.getInstructionSequence();
}
private InstructionSequence getCurrentSequence()
{
return this.seqStack.peek();
}
/** {@inheritDoc} */
@Override
public void token(CharSequence text)
{
String token = text.toString();
token(token);
}
private void token(String token)
{<FILL_FUNCTION_BODY>}
/**
* Parses a value of type "int".
* @param token the token to be parsed
* @return the parsed value
*/
public static int parseInt(String token)
{
return Integer.parseInt(token);
}
/**
* Parses a value of type "real".
* @param token the token to be parsed
* @return the parsed value
*/
public static float parseReal(String token)
{
return Float.parseFloat(token);
}
}
|
if ("{".equals(token))
{
InstructionSequence child = new InstructionSequence();
getCurrentSequence().addProc(child);
this.seqStack.push(child);
}
else if ("}".equals(token))
{
this.seqStack.pop();
}
else
{
if (MATCHES_INTEGER.test(token))
{
getCurrentSequence().addInteger(parseInt(token));
return;
}
if (MATCHES_REAL.test(token))
{
getCurrentSequence().addReal(parseReal(token));
return;
}
//TODO Maybe implement radix numbers, such as 8#1777 or 16#FFFE
getCurrentSequence().addName(token);
}
| 567
| 209
| 776
|
<methods>public non-sealed void <init>() ,public void comment(java.lang.CharSequence) ,public void newLine(java.lang.CharSequence) ,public void whitespace(java.lang.CharSequence) <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/Parser.java
|
Tokenizer
|
scanToken
|
class Tokenizer
{
private static final char NUL = '\u0000'; //NUL
private static final char EOT = '\u0004'; //END OF TRANSMISSION
private static final char TAB = '\u0009'; //TAB CHARACTER
private static final char FF = '\u000C'; //FORM FEED
private static final char CR = '\r'; //CARRIAGE RETURN
private static final char LF = '\n'; //LINE FEED
private static final char SPACE = '\u0020'; //SPACE
private final CharSequence input;
private int index;
private final SyntaxHandler handler;
private State state = State.WHITESPACE;
private final StringBuilder buffer = new StringBuilder();
private Tokenizer(CharSequence text, SyntaxHandler syntaxHandler)
{
this.input = text;
this.handler = syntaxHandler;
}
private boolean hasMore()
{
return index < input.length();
}
private char currentChar()
{
return input.charAt(index);
}
private char nextChar()
{
index++;
if (!hasMore())
{
return EOT;
}
else
{
return currentChar();
}
}
private char peek()
{
if (index < input.length() - 1)
{
return input.charAt(index + 1);
}
else
{
return EOT;
}
}
private State nextState()
{
char ch = currentChar();
switch (ch)
{
case CR:
case LF:
case FF: //FF
state = State.NEWLINE;
break;
case NUL:
case TAB:
case SPACE:
state = State.WHITESPACE;
break;
case '%':
state = State.COMMENT;
break;
default:
state = State.TOKEN;
}
return state;
}
private void tokenize()
{
while (hasMore())
{
buffer.setLength(0);
nextState();
switch (state)
{
case NEWLINE:
scanNewLine();
break;
case WHITESPACE:
scanWhitespace();
break;
case COMMENT:
scanComment();
break;
default:
scanToken();
}
}
}
private void scanNewLine()
{
assert state == State.NEWLINE;
char ch = currentChar();
buffer.append(ch);
if (ch == CR && peek() == LF)
{
//CRLF is treated as one newline
buffer.append(nextChar());
}
handler.newLine(buffer);
nextChar();
}
private void scanWhitespace()
{
assert state == State.WHITESPACE;
buffer.append(currentChar());
loop:
while (hasMore())
{
char ch = nextChar();
switch (ch)
{
case NUL:
case TAB:
case SPACE:
buffer.append(ch);
break;
default:
break loop;
}
}
handler.whitespace(buffer);
}
private void scanComment()
{
assert state == State.COMMENT;
buffer.append(currentChar());
loop:
while (hasMore())
{
char ch = nextChar();
switch (ch)
{
case CR:
case LF:
case FF:
break loop;
default:
buffer.append(ch);
}
}
//EOF reached
handler.comment(buffer);
}
private void scanToken()
{<FILL_FUNCTION_BODY>}
}
|
assert state == State.TOKEN;
char ch = currentChar();
buffer.append(ch);
switch (ch)
{
case '{':
case '}':
handler.token(buffer);
nextChar();
return;
default:
//continue
}
loop:
while (hasMore())
{
ch = nextChar();
switch (ch)
{
case NUL:
case TAB:
case SPACE:
case CR:
case LF:
case FF:
case EOT:
case '{':
case '}':
break loop;
default:
buffer.append(ch);
}
}
//EOF reached
handler.token(buffer);
| 1,013
| 199
| 1,212
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/RelationalOperators.java
|
Eq
|
isEqual
|
class Eq implements Operator
{
@Override
public void execute(ExecutionContext context)
{
Stack<Object> stack = context.getStack();
Object op2 = stack.pop();
Object op1 = stack.pop();
boolean result = isEqual(op1, op2);
stack.push(result);
}
protected boolean isEqual(Object op1, Object op2)
{<FILL_FUNCTION_BODY>}
}
|
boolean result;
if (op1 instanceof Number && op2 instanceof Number)
{
Number num1 = (Number)op1;
Number num2 = (Number)op2;
result = Float.compare(num1.floatValue(),num2.floatValue()) == 0;
}
else
{
result = op1.equals(op2);
}
return result;
| 119
| 102
| 221
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/type4/StackOperators.java
|
Index
|
execute
|
class Index implements Operator
{
@Override
public void execute(ExecutionContext context)
{<FILL_FUNCTION_BODY>}
}
|
Stack<Object> stack = context.getStack();
int n = ((Number)stack.pop()).intValue();
if (n < 0)
{
throw new IllegalArgumentException("rangecheck: " + n);
}
int size = stack.size();
stack.push(stack.get(size - n - 1));
| 42
| 85
| 127
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java
|
PDAttributeObject
|
isValueChanged
|
class PDAttributeObject extends PDDictionaryWrapper
{
/**
* Default constructor.
*/
public PDAttributeObject()
{
}
/**
* Creates a new attribute object with a given dictionary.
*
* @param dictionary the dictionary
*/
public PDAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Creates an attribute object.
*
* @param dictionary the dictionary
* @return the attribute object
*/
public static PDAttributeObject create(COSDictionary dictionary)
{
String owner = dictionary.getNameAsString(COSName.O);
if (owner != null)
{
switch (owner)
{
case PDUserAttributeObject.OWNER_USER_PROPERTIES:
return new PDUserAttributeObject(dictionary);
case PDListAttributeObject.OWNER_LIST:
return new PDListAttributeObject(dictionary);
case PDPrintFieldAttributeObject.OWNER_PRINT_FIELD:
return new PDPrintFieldAttributeObject(dictionary);
case PDTableAttributeObject.OWNER_TABLE:
return new PDTableAttributeObject(dictionary);
case PDLayoutAttributeObject.OWNER_LAYOUT:
return new PDLayoutAttributeObject(dictionary);
case PDExportFormatAttributeObject.OWNER_XML_1_00:
case PDExportFormatAttributeObject.OWNER_HTML_3_20:
case PDExportFormatAttributeObject.OWNER_HTML_4_01:
case PDExportFormatAttributeObject.OWNER_OEB_1_00:
case PDExportFormatAttributeObject.OWNER_RTF_1_05:
case PDExportFormatAttributeObject.OWNER_CSS_1_00:
case PDExportFormatAttributeObject.OWNER_CSS_2_00:
return new PDExportFormatAttributeObject(dictionary);
default:
break;
}
}
return new PDDefaultAttributeObject(dictionary);
}
private PDStructureElement structureElement;
/**
* Gets the structure element.
*
* @return the structure element
*/
private PDStructureElement getStructureElement()
{
return this.structureElement;
}
/**
* Sets the structure element.
*
* @param structureElement the structure element
*/
protected void setStructureElement(PDStructureElement structureElement)
{
this.structureElement = structureElement;
}
/**
* Returns the owner of the attributes.
*
* @return the owner of the attributes
*/
public String getOwner()
{
return this.getCOSObject().getNameAsString(COSName.O);
}
/**
* Sets the owner of the attributes.
*
* @param owner the owner of the attributes
*/
protected void setOwner(String owner)
{
this.getCOSObject().setName(COSName.O, owner);
}
/**
* Detects whether there are no properties in the attribute object.
*
* @return <code>true</code> if the attribute object is empty,
* <code>false</code> otherwise
*/
public boolean isEmpty()
{
// only entry is the owner?
return (this.getCOSObject().size() == 1) && (this.getOwner() != null);
}
/**
* Notifies the attribute object change listeners if the attribute is changed.
*
* @param oldBase old value
* @param newBase new value
*/
protected void potentiallyNotifyChanged(COSBase oldBase, COSBase newBase)
{
if (this.isValueChanged(oldBase, newBase))
{
this.notifyChanged();
}
}
/**
* Is the value changed?
*
* @param oldValue old value
* @param newValue new value
* @return <code>true</code> if the value is changed, <code>false</code>
* otherwise
*/
private boolean isValueChanged(COSBase oldValue, COSBase newValue)
{<FILL_FUNCTION_BODY>}
/**
* Notifies the attribute object change listeners about a change in this
* attribute object.
*/
protected void notifyChanged()
{
if (this.getStructureElement() != null)
{
this.getStructureElement().attributeChanged(this);
}
}
@Override
public String toString()
{
return "O=" + this.getOwner();
}
/**
* Creates a String representation of an Object array.
*
* @param array the Object array
* @return the String representation
*/
protected static String arrayToString(Object[] array)
{
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < array.length; i++)
{
if (i > 0)
{
sb.append(", ");
}
sb.append(array[i]);
}
return sb.append(']').toString();
}
/**
* Creates a String representation of a float array.
*
* @param array the float array
* @return the String representation
*/
protected static String arrayToString(float[] array)
{
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < array.length; i++)
{
if (i > 0)
{
sb.append(", ");
}
sb.append(array[i]);
}
return sb.append(']').toString();
}
}
|
if (oldValue == null)
{
return newValue != null;
}
return !oldValue.equals(newValue);
| 1,483
| 39
| 1,522
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public boolean equals(java.lang.Object) ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public int hashCode() <variables>private final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDDefaultAttributeObject.java
|
PDDefaultAttributeObject
|
toString
|
class PDDefaultAttributeObject extends PDAttributeObject
{
/**
* Default constructor.
*/
public PDDefaultAttributeObject()
{
}
/**
* Creates a default attribute object with a given dictionary.
*
* @param dictionary the dictionary
*/
public PDDefaultAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Gets the attribute names.
*
* @return the attribute names
*/
public List<String> getAttributeNames()
{
List<String> attrNames = new ArrayList<>();
this.getCOSObject().keySet().stream()
.filter(key -> !COSName.O.equals(key))
.map(COSName::getName)
.forEach(attrNames::add);
return attrNames;
}
/**
* Gets the attribute value for a given name.
*
* @param attrName the given attribute name
* @return the attribute value for a given name
*/
public COSBase getAttributeValue(String attrName)
{
return this.getCOSObject().getDictionaryObject(attrName);
}
/**
* Gets the attribute value for a given name.
*
* @param attrName the given attribute name
* @param defaultValue the default value
* @return the attribute value for a given name
*/
protected COSBase getAttributeValue(String attrName, COSBase defaultValue)
{
COSBase value = this.getCOSObject().getDictionaryObject(attrName);
if (value == null)
{
return defaultValue;
}
return value;
}
/**
* Sets an attribute.
*
* @param attrName the attribute name
* @param attrValue the attribute value
*/
public void setAttribute(String attrName, COSBase attrValue)
{
COSBase old = this.getAttributeValue(attrName);
this.getCOSObject().setItem(COSName.getPDFName(attrName), attrValue);
this.potentiallyNotifyChanged(old, attrValue);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder().append(super.toString())
.append(", attributes={");
Iterator<String> it = this.getAttributeNames().iterator();
while (it.hasNext())
{
String name = it.next();
sb.append(name).append('=').append(this.getAttributeValue(name));
if (it.hasNext())
{
sb.append(", ");
}
}
return sb.append('}').toString();
| 579
| 126
| 705
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public static org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDAttributeObject create(org.apache.pdfbox.cos.COSDictionary) ,public java.lang.String getOwner() ,public boolean isEmpty() ,public java.lang.String toString() <variables>private org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement structureElement
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java
|
PDObjectReference
|
getReferencedObject
|
class PDObjectReference implements COSObjectable
{
/**
* Log instance.
*/
private static final Logger LOG = LogManager.getLogger(PDObjectReference.class);
/**
* TYPE of this object.
*/
public static final String TYPE = "OBJR";
private final COSDictionary dictionary;
/**
* Default Constructor.
*
*/
public PDObjectReference()
{
this.dictionary = new COSDictionary();
this.dictionary.setName(COSName.TYPE, TYPE);
}
/**
* Constructor for an existing object reference.
*
* @param theDictionary The existing dictionary.
*/
public PDObjectReference(COSDictionary theDictionary)
{
dictionary = theDictionary;
}
/**
* Returns the underlying dictionary.
*
* @return the dictionary
*/
@Override
public COSDictionary getCOSObject()
{
return this.dictionary;
}
/**
* Gets a higher-level object for the referenced object.
* Currently this method may return a {@link PDAnnotation},
* a {@link PDXObject} or <code>null</code>.
*
* @return a higher-level object for the referenced object
*/
public COSObjectable getReferencedObject()
{<FILL_FUNCTION_BODY>}
/**
* Sets the referenced annotation.
*
* @param annotation the referenced annotation
*/
public void setReferencedObject(PDAnnotation annotation)
{
this.getCOSObject().setItem(COSName.OBJ, annotation);
}
/**
* Sets the referenced XObject.
*
* @param xobject the referenced XObject
*/
public void setReferencedObject(PDXObject xobject)
{
this.getCOSObject().setItem(COSName.OBJ, xobject);
}
}
|
COSDictionary objDictionary = getCOSObject().getCOSDictionary(COSName.OBJ);
if (objDictionary == null)
{
return null;
}
try
{
if (objDictionary instanceof COSStream)
{
PDXObject xobject = PDXObject.createXObject(objDictionary, null); // <-- TODO: valid?
if (xobject != null)
{
return xobject;
}
}
PDAnnotation annotation = PDAnnotation.createAnnotation(objDictionary);
/*
* COSName.TYPE is optional, so if annotation is of type unknown and
* COSName.TYPE is not COSName.ANNOT it still may be an annotation.
* TODO shall we return the annotation object instead of null?
* what else can be the target of the object reference?
*/
if (!(annotation instanceof PDAnnotationUnknown)
|| COSName.ANNOT.equals(objDictionary.getCOSName(COSName.TYPE)))
{
return annotation;
}
}
catch (IOException exception)
{
LOG.debug("Couldn't get the referenced object - returning null instead", exception);
// this can only happen if the target is an XObject.
}
return null;
| 584
| 358
| 942
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
|
PDStructureTreeRoot
|
getClassMap
|
class PDStructureTreeRoot extends PDStructureNode
{
/**
* Log instance.
*/
private static final Logger LOG = LogManager.getLogger(PDStructureTreeRoot.class);
private static final String TYPE = "StructTreeRoot";
/**
* Default Constructor.
*
*/
public PDStructureTreeRoot()
{
super(TYPE);
}
/**
* Constructor for an existing structure element.
*
* @param dic The existing dictionary.
*/
public PDStructureTreeRoot(COSDictionary dic)
{
super(dic);
}
/**
* Returns the K entry. This can be a dictionary representing a structure element, or an array
* of them.
*
* @return the K entry.
*/
public COSBase getK()
{
return this.getCOSObject().getDictionaryObject(COSName.K);
}
/**
* Sets the K entry.
*
* @param k the K value
*/
public void setK(COSBase k)
{
this.getCOSObject().setItem(COSName.K, k);
}
/**
* Returns the ID tree.
*
* @return the ID tree
*/
public PDNameTreeNode<PDStructureElement> getIDTree()
{
COSDictionary idTree = getCOSObject().getCOSDictionary(COSName.ID_TREE);
return idTree != null ? new PDStructureElementNameTreeNode(idTree) : null;
}
/**
* Sets the ID tree.
*
* @param idTree the ID tree
*/
public void setIDTree(PDNameTreeNode<PDStructureElement> idTree)
{
this.getCOSObject().setItem(COSName.ID_TREE, idTree);
}
/**
* Returns the parent tree.
*
* @return the parent tree
*/
public PDNumberTreeNode getParentTree()
{
COSDictionary parentTree = getCOSObject().getCOSDictionary(COSName.PARENT_TREE);
return parentTree != null ? new PDNumberTreeNode(parentTree, PDParentTreeValue.class) : null;
}
/**
* Sets the parent tree.
*
* @param parentTree the parent tree
*/
public void setParentTree(PDNumberTreeNode parentTree)
{
this.getCOSObject().setItem(COSName.PARENT_TREE, parentTree);
}
/**
* Returns the next key in the parent tree.
*
* @return the next key in the parent tree
*/
public int getParentTreeNextKey()
{
return this.getCOSObject().getInt(COSName.PARENT_TREE_NEXT_KEY);
}
/**
* Sets the next key in the parent tree.
*
* @param parentTreeNextkey the next key in the parent tree.
*/
public void setParentTreeNextKey(int parentTreeNextkey)
{
this.getCOSObject().setInt(COSName.PARENT_TREE_NEXT_KEY, parentTreeNextkey);
}
/**
* Returns the role map.
*
* @return the role map
*/
public Map<String, Object> getRoleMap()
{
COSDictionary rm = getCOSObject().getCOSDictionary(COSName.ROLE_MAP);
if (rm != null)
{
try
{
return COSDictionaryMap.convertBasicTypesToMap(rm);
}
catch (IOException e)
{
LOG.error(e,e);
}
}
return new HashMap<>();
}
/**
* Sets the role map.
*
* @param roleMap the role map
*/
public void setRoleMap(Map<String, String> roleMap)
{
COSDictionary rmDic = new COSDictionary();
roleMap.forEach(rmDic::setName);
this.getCOSObject().setItem(COSName.ROLE_MAP, rmDic);
}
/**
* Sets the ClassMap.
*
* @return the ClassMap, never null. The elements are either {@link PDAttributeObject} or lists
* of it.
*/
public Map<String, Object> getClassMap()
{<FILL_FUNCTION_BODY>}
/**
* Sets the ClassMap.
*
* @param classMap null, or a map whose elements are either {@link PDAttributeObject} or lists
* of it.
*/
public void setClassMap(Map<String, Object> classMap)
{
if (classMap == null || classMap.isEmpty())
{
this.getCOSObject().removeItem(COSName.CLASS_MAP);
return;
}
COSDictionary classMapDictionary = new COSDictionary();
classMap.forEach((name, object) ->
{
if (object instanceof PDAttributeObject)
{
classMapDictionary.setItem(name, ((PDAttributeObject) object).getCOSObject());
}
else if (object instanceof List)
{
classMapDictionary.setItem(name, new COSArray((List<PDAttributeObject>) object));
}
});
this.getCOSObject().setItem(COSName.CLASS_MAP, classMapDictionary);
}
}
|
Map<String, Object> classMap = new HashMap<>();
COSDictionary classMapDictionary = this.getCOSObject().getCOSDictionary(COSName.CLASS_MAP);
if (classMapDictionary == null)
{
return classMap;
}
classMapDictionary.forEach((name, base) ->
{
if (base instanceof COSObject)
{
base = ((COSObject) base).getObject();
}
if (base instanceof COSDictionary)
{
classMap.put(name.getName(), PDAttributeObject.create((COSDictionary) base));
}
else if (base instanceof COSArray)
{
COSArray array = (COSArray) base;
List<PDAttributeObject> list = new ArrayList<>();
for (int i = 0; i < array.size(); ++i)
{
COSBase base2 = array.getObject(i);
if (base2 instanceof COSDictionary)
{
list.add(PDAttributeObject.create((COSDictionary) base2));
}
}
classMap.put(name.getName(), list);
}
});
return classMap;
| 1,429
| 299
| 1,728
|
<methods>public void appendKid(org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement) ,public static org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureNode create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public List<java.lang.Object> getKids() ,public java.lang.String getType() ,public void insertBefore(org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement, java.lang.Object) ,public boolean removeKid(org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement) ,public void setKids(List<java.lang.Object>) <variables>private final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserAttributeObject.java
|
PDUserAttributeObject
|
removeUserProperty
|
class PDUserAttributeObject extends PDAttributeObject
{
/**
* Attribute owner for user properties
*/
public static final String OWNER_USER_PROPERTIES = "UserProperties";
/**
* Default constructor
*/
public PDUserAttributeObject()
{
this.setOwner(OWNER_USER_PROPERTIES);
}
/**
* Constructor
*
* @param dictionary the dictionary
*/
public PDUserAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Returns the user properties.
*
* @return the user properties
*/
public List<PDUserProperty> getOwnerUserProperties()
{
COSArray p = getCOSObject().getCOSArray(COSName.P);
List<PDUserProperty> properties = new ArrayList<>(p.size());
for (int i = 0; i < p.size(); i++)
{
properties.add(
new PDUserProperty((COSDictionary) p.getObject(i), this));
}
return properties;
}
/**
* Sets the user properties.
*
* @param userProperties the user properties
*/
public void setUserProperties(List<PDUserProperty> userProperties)
{
COSArray p = new COSArray(userProperties);
this.getCOSObject().setItem(COSName.P, p);
}
/**
* Adds a user property.
*
* @param userProperty the user property
*/
public void addUserProperty(PDUserProperty userProperty)
{
COSArray p = getCOSObject().getCOSArray(COSName.P);
p.add(userProperty);
this.notifyChanged();
}
/**
* Removes a user property.
*
* @param userProperty the user property
*/
public void removeUserProperty(PDUserProperty userProperty)
{<FILL_FUNCTION_BODY>}
/**
* Notify a possible change of user properties.
*
* @param userProperty the user property which might have be changed
*/
public void userPropertyChanged(PDUserProperty userProperty)
{
}
@Override
public String toString()
{
return super.toString() + ", userProperties=" + this.getOwnerUserProperties();
}
}
|
if (userProperty == null)
{
return;
}
COSArray p = getCOSObject().getCOSArray(COSName.P);
if (p.remove(userProperty.getCOSObject()))
{
this.notifyChanged();
}
| 627
| 74
| 701
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public static org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDAttributeObject create(org.apache.pdfbox.cos.COSDictionary) ,public java.lang.String getOwner() ,public boolean isEmpty() ,public java.lang.String toString() <variables>private org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement structureElement
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java
|
PDUserProperty
|
toString
|
class PDUserProperty extends PDDictionaryWrapper
{
private final PDUserAttributeObject userAttributeObject;
/**
* Creates a new user property.
*
* @param userAttributeObject the user attribute object
*/
public PDUserProperty(PDUserAttributeObject userAttributeObject)
{
this.userAttributeObject = userAttributeObject;
}
/**
* Creates a user property with a given dictionary.
*
* @param dictionary the dictionary
* @param userAttributeObject the user attribute object
*/
public PDUserProperty(COSDictionary dictionary,
PDUserAttributeObject userAttributeObject)
{
super(dictionary);
this.userAttributeObject = userAttributeObject;
}
/**
* Returns the property name.
*
* @return the property name
*/
public String getName()
{
return this.getCOSObject().getNameAsString(COSName.N);
}
/**
* Sets the property name.
*
* @param name the property name
*/
public void setName(String name)
{
this.potentiallyNotifyChanged(this.getName(), name);
this.getCOSObject().setName(COSName.N, name);
}
/**
* Returns the property value.
*
* @return the property value
*/
public COSBase getValue()
{
return this.getCOSObject().getDictionaryObject(COSName.V);
}
/**
* Sets the property value.
*
* @param value the property value
*/
public void setValue(COSBase value)
{
this.potentiallyNotifyChanged(this.getValue(), value);
this.getCOSObject().setItem(COSName.V, value);
}
/**
* Returns the string for the property value.
*
* @return the string for the property value
*/
public String getFormattedValue()
{
return this.getCOSObject().getString(COSName.F);
}
/**
* Sets the string for the property value.
*
* @param formattedValue the string for the property value
*/
public void setFormattedValue(String formattedValue)
{
this.potentiallyNotifyChanged(this.getFormattedValue(), formattedValue);
this.getCOSObject().setString(COSName.F, formattedValue);
}
/**
* Shall the property be hidden?
*
* @return <code>true</code> if the property shall be hidden,
* <code>false</code> otherwise
*/
public boolean isHidden()
{
return this.getCOSObject().getBoolean(COSName.H, false);
}
/**
* Specifies whether the property shall be hidden.
*
* @param hidden <code>true</code> if the property shall be hidden,
* <code>false</code> otherwise
*/
public void setHidden(boolean hidden)
{
this.potentiallyNotifyChanged(this.isHidden(), hidden);
this.getCOSObject().setBoolean(COSName.H, hidden);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
/**
* Notifies the user attribute object if the user property is changed.
*
* @param oldEntry old entry
* @param newEntry new entry
*/
private void potentiallyNotifyChanged(Object oldEntry, Object newEntry)
{
if (this.isEntryChanged(oldEntry, newEntry))
{
this.userAttributeObject.userPropertyChanged(this);
}
}
/**
* Is the value changed?
*
* @param oldEntry old entry
* @param newEntry new entry
* @return <code>true</code> if the entry is changed, <code>false</code>
* otherwise
*/
private boolean isEntryChanged(Object oldEntry, Object newEntry)
{
if (oldEntry == null)
{
return newEntry != null;
}
return !oldEntry.equals(newEntry);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ ((userAttributeObject == null) ? 0 : userAttributeObject.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!super.equals(obj))
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
PDUserProperty other = (PDUserProperty) obj;
if (userAttributeObject == null)
{
if (other.userAttributeObject != null)
{
return false;
}
}
else if (!userAttributeObject.equals(other.userAttributeObject))
{
return false;
}
return true;
}
}
|
return "Name=" + this.getName() +
", Value=" + this.getValue() +
", FormattedValue=" + this.getFormattedValue() +
", Hidden=" + this.isHidden();
| 1,337
| 59
| 1,396
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public boolean equals(java.lang.Object) ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public int hashCode() <variables>private final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/Revisions.java
|
Revisions
|
setRevisionNumber
|
class Revisions<T>
{
private List<T> objects;
private List<Integer> revisionNumbers;
/**
* Constructor.
*/
public Revisions()
{
}
private List<T> getObjects()
{
if (this.objects == null)
{
this.objects = new ArrayList<>();
}
return this.objects;
}
private List<Integer> getRevisionNumbers()
{
if (this.revisionNumbers == null)
{
this.revisionNumbers = new ArrayList<>();
}
return this.revisionNumbers;
}
/**
* Returns the object at the specified position.
*
* @param index the position
* @return the object
* @throws IndexOutOfBoundsException if the index is out of range
*/
public T getObject(int index)
{
return this.getObjects().get(index);
}
/**
* Returns the revision number at the specified position.
*
* @param index the position
* @return the revision number
* @throws IndexOutOfBoundsException if the index is out of range
*/
public int getRevisionNumber(int index)
{
return this.getRevisionNumbers().get(index);
}
/**
* Adds an object with a specified revision number.
*
* @param object the object
* @param revisionNumber the revision number
*/
public void addObject(T object, int revisionNumber)
{
this.getObjects().add(object);
this.getRevisionNumbers().add(revisionNumber);
}
/**
* Sets the revision number of a specified object.
*
* @param object the object
* @param revisionNumber the revision number
*/
protected void setRevisionNumber(T object, int revisionNumber)
{<FILL_FUNCTION_BODY>}
/**
* Returns the size.
*
* @return the size
*/
public int size()
{
return this.getObjects().size();
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < this.getObjects().size(); i++)
{
if (i > 0)
{
sb.append("; ");
}
sb.append("object=").append(this.getObjects().get(i))
.append(", revisionNumber=").append(this.getRevisionNumber(i));
}
return sb.toString();
}
}
|
int index = this.getObjects().indexOf(object);
if (index > -1)
{
this.getRevisionNumbers().set(index, revisionNumber);
}
| 686
| 49
| 735
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDMarkedContent.java
|
PDMarkedContent
|
toString
|
class PDMarkedContent
{
/**
* Creates a marked-content sequence.
*
* @param tag the tag
* @param properties the properties
* @return the marked-content sequence
*/
public static PDMarkedContent create(COSName tag, COSDictionary properties)
{
if (COSName.ARTIFACT.equals(tag))
{
return new PDArtifactMarkedContent(properties);
}
return new PDMarkedContent(tag, properties);
}
private final String tag;
private final COSDictionary properties;
private final List<Object> contents;
/**
* Creates a new marked content object.
*
* @param tag the tag
* @param properties the properties
*/
public PDMarkedContent(COSName tag, COSDictionary properties)
{
this.tag = tag == null ? null : tag.getName();
this.properties = properties;
this.contents = new ArrayList<>();
}
/**
* Gets the tag.
*
* @return the tag
*/
public String getTag()
{
return this.tag;
}
/**
* Gets the properties.
*
* @return the properties
*/
public COSDictionary getProperties()
{
return this.properties;
}
/**
* Gets the marked-content identifier.
*
* @return the marked-content identifier, or -1 if it doesn't exist.
*/
public int getMCID()
{
return this.getProperties() == null ? -1 :
this.getProperties().getInt(COSName.MCID);
}
/**
* Gets the language (Lang).
*
* @return the language
*/
public String getLanguage()
{
return this.getProperties() == null ? null :
this.getProperties().getNameAsString(COSName.LANG);
}
/**
* Gets the actual text (ActualText).
*
* @return the actual text
*/
public String getActualText()
{
return this.getProperties() == null ? null :
this.getProperties().getString(COSName.ACTUAL_TEXT);
}
/**
* Gets the alternate description (Alt).
*
* @return the alternate description
*/
public String getAlternateDescription()
{
return this.getProperties() == null ? null :
this.getProperties().getString(COSName.ALT);
}
/**
* Gets the expanded form (E).
*
* @return the expanded form
*/
public String getExpandedForm()
{
return this.getProperties() == null ? null :
this.getProperties().getString(COSName.E);
}
/**
* Gets the contents of the marked content sequence. Can be
* <ul>
* <li>{@link TextPosition},</li>
* <li>{@link PDMarkedContent}, or</li>
* <li>{@link PDXObject}.</li>
* </ul>
*
* @return the contents of the marked content sequence
*/
public List<Object> getContents()
{
return this.contents;
}
/**
* Adds a text position to the contents.
*
* @param text the text position
*/
public void addText(TextPosition text)
{
this.getContents().add(text);
}
/**
* Adds a marked content to the contents.
*
* @param markedContent the marked content
*/
public void addMarkedContent(PDMarkedContent markedContent)
{
this.getContents().add(markedContent);
}
/**
* Adds an XObject to the contents.
*
* @param xobject the XObject
*/
public void addXObject(PDXObject xobject)
{
this.getContents().add(xobject);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return "tag=" + this.tag +
", properties=" + this.properties +
", contents=" + this.contents;
| 1,249
| 41
| 1,290
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/markedcontent/PDPropertyList.java
|
PDPropertyList
|
create
|
class PDPropertyList implements COSObjectable
{
protected final COSDictionary dict;
/**
* Creates a property list from the given dictionary.
*
* @param dict COS dictionary
* @return a new instance of a PDPropertyList using the given dictionary
*/
public static PDPropertyList create(COSDictionary dict)
{<FILL_FUNCTION_BODY>}
/**
* Constructor for subclasses.
*/
protected PDPropertyList()
{
this.dict = new COSDictionary();
}
/**
* Constructor for subclasses.
*
* @param dict the dictionary to be used to create an instance of PDPropertyList
*/
protected PDPropertyList(COSDictionary dict)
{
this.dict = dict;
}
@Override
public COSDictionary getCOSObject()
{
return dict;
}
}
|
COSBase item = dict.getItem(COSName.TYPE);
if (COSName.OCG.equals(item))
{
return new PDOptionalContentGroup(dict);
}
else if (COSName.OCMD.equals(item))
{
return new PDOptionalContentMembershipDictionary(dict);
}
else
{
// todo: more types
return new PDPropertyList(dict);
}
| 240
| 120
| 360
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/prepress/PDBoxStyle.java
|
PDBoxStyle
|
setLineDashPattern
|
class PDBoxStyle implements COSObjectable
{
/**
* Style for guideline.
*/
public static final String GUIDELINE_STYLE_SOLID = "S";
/**
* Style for guideline.
*/
public static final String GUIDELINE_STYLE_DASHED = "D";
private final COSDictionary dictionary;
/**
* Default Constructor.
*
*/
public PDBoxStyle()
{
dictionary = new COSDictionary();
}
/**
* Constructor for an existing BoxStyle element.
*
* @param dic The existing dictionary.
*/
public PDBoxStyle( COSDictionary dic )
{
dictionary = dic;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSDictionary getCOSObject()
{
return dictionary;
}
/**
* Get the RGB color to be used for the guidelines. This is guaranteed to
* not return null. The default color is [0,0,0].
*
*@return The guideline color.
*/
public PDColor getGuidelineColor()
{
COSArray colorValues = dictionary.getCOSArray(COSName.C);
if( colorValues == null )
{
colorValues = new COSArray(List.of(
COSInteger.ZERO,
COSInteger.ZERO,
COSInteger.ZERO
));
dictionary.setItem(COSName.C, colorValues);
}
return new PDColor(colorValues.toFloatArray(), PDDeviceRGB.INSTANCE);
}
/**
* Set the color space instance for this box style. This must be a
* PDDeviceRGB!
*
* @param color The new colorspace value.
*/
public void setGuideLineColor( PDColor color )
{
COSArray values = null;
if( color != null )
{
values = color.toCOSArray();
}
dictionary.setItem(COSName.C, values);
}
/**
* Get the width of the of the guideline in default user space units.
* The default is 1.
*
* @return The width of the guideline.
*/
public float getGuidelineWidth()
{
return dictionary.getFloat(COSName.W, 1);
}
/**
* Set the guideline width.
*
* @param width The width in default user space units.
*/
public void setGuidelineWidth( float width )
{
dictionary.setFloat(COSName.W, width);
}
/**
* Get the style for the guideline. The default is "S" for solid.
*
* @return The guideline style.
* @see PDBoxStyle#GUIDELINE_STYLE_DASHED
* @see PDBoxStyle#GUIDELINE_STYLE_SOLID
*/
public String getGuidelineStyle()
{
return dictionary.getNameAsString(COSName.S, GUIDELINE_STYLE_SOLID);
}
/**
* Set the style for the box.
*
* @param style The style for the box line.
* @see PDBoxStyle#GUIDELINE_STYLE_DASHED
* @see PDBoxStyle#GUIDELINE_STYLE_SOLID
*/
public void setGuidelineStyle( String style )
{
dictionary.setName(COSName.S, style);
}
/**
* Get the line dash pattern for this box style. This is guaranteed to not
* return null. The default is [3],0.
*
* @return The line dash pattern.
*/
public PDLineDashPattern getLineDashPattern()
{
COSArray d = dictionary.getCOSArray(COSName.D);
if( d == null )
{
d = new COSArray(List.of(COSInteger.THREE));
dictionary.setItem(COSName.D, d);
}
COSArray lineArray = new COSArray(Arrays.asList(d));
//dash phase is not specified and assumed to be zero.
return new PDLineDashPattern(lineArray, 0);
}
/**
* Set the line dash pattern associated with this box style.
*
* @param dashArray The patter for this box style.
*/
public void setLineDashPattern( COSArray dashArray )
{<FILL_FUNCTION_BODY>}
}
|
COSArray array = null;
if( dashArray != null )
{
array = dashArray;
}
dictionary.setItem(COSName.D, array);
| 1,233
| 50
| 1,283
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/taggedpdf/PDArtifactMarkedContent.java
|
PDArtifactMarkedContent
|
isAttached
|
class PDArtifactMarkedContent extends PDMarkedContent
{
public PDArtifactMarkedContent(COSDictionary properties)
{
super(COSName.ARTIFACT, properties);
}
/**
* Gets the type (Type).
*
* @return the type
*/
public String getType()
{
return this.getProperties().getNameAsString(COSName.TYPE);
}
/**
* Gets the artifact's bounding box (BBox).
*
* @return the artifact's bounding box
*/
public PDRectangle getBBox()
{
COSArray a = getProperties().getCOSArray(COSName.BBOX);
return a != null ? new PDRectangle(a) : null;
}
/**
* Is the artifact attached to the top edge?
*
* @return <code>true</code> if the artifact is attached to the top edge,
* <code>false</code> otherwise
*/
public boolean isTopAttached()
{
return this.isAttached("Top");
}
/**
* Is the artifact attached to the bottom edge?
*
* @return <code>true</code> if the artifact is attached to the bottom edge,
* <code>false</code> otherwise
*/
public boolean isBottomAttached()
{
return this.isAttached("Bottom");
}
/**
* Is the artifact attached to the left edge?
*
* @return <code>true</code> if the artifact is attached to the left edge,
* <code>false</code> otherwise
*/
public boolean isLeftAttached()
{
return this.isAttached("Left");
}
/**
* Is the artifact attached to the right edge?
*
* @return <code>true</code> if the artifact is attached to the right edge,
* <code>false</code> otherwise
*/
public boolean isRightAttached()
{
return this.isAttached("Right");
}
/**
* Gets the subtype (Subtype).
*
* @return the subtype
*/
public String getSubtype()
{
return this.getProperties().getNameAsString(COSName.SUBTYPE);
}
/**
* Is the artifact attached to the given edge?
*
* @param edge the edge
* @return <code>true</code> if the artifact is attached to the given edge,
* <code>false</code> otherwise
*/
private boolean isAttached(String edge)
{<FILL_FUNCTION_BODY>}
}
|
COSArray a = getProperties().getCOSArray(COSName.ATTACHED);
if (a != null)
{
for (int i = 0; i < a.size(); i++)
{
if (edge.equals(a.getName(i)))
{
return true;
}
}
}
return false;
| 706
| 96
| 802
|
<methods>public void <init>(org.apache.pdfbox.cos.COSName, org.apache.pdfbox.cos.COSDictionary) ,public void addMarkedContent(org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent) ,public void addText(org.apache.pdfbox.text.TextPosition) ,public void addXObject(org.apache.pdfbox.pdmodel.graphics.PDXObject) ,public static org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent create(org.apache.pdfbox.cos.COSName, org.apache.pdfbox.cos.COSDictionary) ,public java.lang.String getActualText() ,public java.lang.String getAlternateDescription() ,public List<java.lang.Object> getContents() ,public java.lang.String getExpandedForm() ,public java.lang.String getLanguage() ,public int getMCID() ,public org.apache.pdfbox.cos.COSDictionary getProperties() ,public java.lang.String getTag() ,public java.lang.String toString() <variables>private final non-sealed List<java.lang.Object> contents,private final non-sealed org.apache.pdfbox.cos.COSDictionary properties,private final non-sealed java.lang.String tag
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/taggedpdf/PDFourColours.java
|
PDFourColours
|
setColourByIndex
|
class PDFourColours implements COSObjectable
{
private final COSArray array;
public PDFourColours()
{
this.array = new COSArray(List.of(
COSNull.NULL,
COSNull.NULL,
COSNull.NULL,
COSNull.NULL
));
}
public PDFourColours(COSArray array)
{
this.array = array;
// ensure that array has 4 items
if (this.array.size() < 4)
{
for (int i = (this.array.size() - 1); i < 4; i++)
{
this.array.add(COSNull.NULL);
}
}
}
/**
* Gets the colour for the before edge.
*
* @return the colour for the before edge
*/
public PDGamma getBeforeColour()
{
return this.getColourByIndex(0);
}
/**
* Sets the colour for the before edge.
*
* @param colour the colour for the before edge
*/
public void setBeforeColour(PDGamma colour)
{
this.setColourByIndex(0, colour);
}
/**
* Gets the colour for the after edge.
*
* @return the colour for the after edge
*/
public PDGamma getAfterColour()
{
return this.getColourByIndex(1);
}
/**
* Sets the colour for the after edge.
*
* @param colour the colour for the after edge
*/
public void setAfterColour(PDGamma colour)
{
this.setColourByIndex(1, colour);
}
/**
* Gets the colour for the start edge.
*
* @return the colour for the start edge
*/
public PDGamma getStartColour()
{
return this.getColourByIndex(2);
}
/**
* Sets the colour for the start edge.
*
* @param colour the colour for the start edge
*/
public void setStartColour(PDGamma colour)
{
this.setColourByIndex(2, colour);
}
/**
* Gets the colour for the end edge.
*
* @return the colour for the end edge
*/
public PDGamma getEndColour()
{
return this.getColourByIndex(3);
}
/**
* Sets the colour for the end edge.
*
* @param colour the colour for the end edge
*/
public void setEndColour(PDGamma colour)
{
this.setColourByIndex(3, colour);
}
/**
* {@inheritDoc}
*/
@Override
public COSBase getCOSObject()
{
return this.array;
}
/**
* Gets the colour by edge index.
*
* @param index edge index
* @return the colour
*/
private PDGamma getColourByIndex(int index)
{
PDGamma retval = null;
COSBase item = this.array.getObject(index);
if (item instanceof COSArray)
{
retval = new PDGamma((COSArray) item);
}
return retval;
}
/**
* Sets the colour by edge index.
*
* @param index the edge index
* @param colour the colour
*/
private void setColourByIndex(int index, PDGamma colour)
{<FILL_FUNCTION_BODY>}
}
|
COSBase base;
if (colour == null)
{
base = COSNull.NULL;
}
else
{
base = colour.getCOSArray();
}
this.array.set(index, base);
| 950
| 67
| 1,017
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/taggedpdf/PDListAttributeObject.java
|
PDListAttributeObject
|
toString
|
class PDListAttributeObject extends PDStandardAttributeObject
{
/**
* standard attribute owner: List
*/
public static final String OWNER_LIST = "List";
protected static final String LIST_NUMBERING = "ListNumbering";
/**
* ListNumbering: Circle: Open circular bullet
*/
public static final String LIST_NUMBERING_CIRCLE = "Circle";
/**
* ListNumbering: Decimal: Decimal arabic numerals (1–9, 10–99, …)
*/
public static final String LIST_NUMBERING_DECIMAL = "Decimal";
/**
* ListNumbering: Disc: Solid circular bullet
*/
public static final String LIST_NUMBERING_DISC = "Disc";
/**
* ListNumbering: LowerAlpha: Lowercase letters (a, b, c, …)
*/
public static final String LIST_NUMBERING_LOWER_ALPHA = "LowerAlpha";
/**
* ListNumbering: LowerRoman: Lowercase roman numerals (i, ii, iii, iv, …)
*/
public static final String LIST_NUMBERING_LOWER_ROMAN = "LowerRoman";
/**
* ListNumbering: None: No autonumbering; Lbl elements (if present) contain arbitrary text
* not subject to any numbering scheme
*/
public static final String LIST_NUMBERING_NONE = "None";
/**
* ListNumbering: Square: Solid square bullet
*/
public static final String LIST_NUMBERING_SQUARE = "Square";
/**
* ListNumbering: UpperAlpha: Uppercase letters (A, B, C, …)
*/
public static final String LIST_NUMBERING_UPPER_ALPHA = "UpperAlpha";
/**
* ListNumbering: UpperRoman: Uppercase roman numerals (I, II, III, IV, …)
*/
public static final String LIST_NUMBERING_UPPER_ROMAN = "UpperRoman";
/**
* Default constructor.
*/
public PDListAttributeObject()
{
this.setOwner(OWNER_LIST);
}
/**
* Creates a new List attribute object with a given dictionary.
*
* @param dictionary the dictionary
*/
public PDListAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Gets the list numbering (ListNumbering). The default value is
* {@link #LIST_NUMBERING_NONE}.
*
* @return the list numbering
*/
public String getListNumbering()
{
return this.getName(LIST_NUMBERING, LIST_NUMBERING_NONE);
}
/**
* Sets the list numbering (ListNumbering). The value shall be one of the
* following:
* <ul>
* <li>{@link #LIST_NUMBERING_NONE},</li>
* <li>{@link #LIST_NUMBERING_DISC},</li>
* <li>{@link #LIST_NUMBERING_CIRCLE},</li>
* <li>{@link #LIST_NUMBERING_SQUARE},</li>
* <li>{@link #LIST_NUMBERING_DECIMAL},</li>
* <li>{@link #LIST_NUMBERING_UPPER_ROMAN},</li>
* <li>{@link #LIST_NUMBERING_LOWER_ROMAN},</li>
* <li>{@link #LIST_NUMBERING_UPPER_ALPHA},</li>
* <li>{@link #LIST_NUMBERING_LOWER_ALPHA}.</li>
* </ul>
*
* @param listNumbering the list numbering
*/
public void setListNumbering(String listNumbering)
{
this.setName(LIST_NUMBERING, listNumbering);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder().append(super.toString());
if (this.isSpecified(LIST_NUMBERING))
{
sb.append(", ListNumbering=").append(this.getListNumbering());
}
return sb.toString();
| 1,078
| 69
| 1,147
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public boolean isSpecified(java.lang.String) <variables>protected static final float UNSPECIFIED
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/taggedpdf/PDPrintFieldAttributeObject.java
|
PDPrintFieldAttributeObject
|
toString
|
class PDPrintFieldAttributeObject extends PDStandardAttributeObject
{
/**
* standard attribute owner: PrintField
*/
public static final String OWNER_PRINT_FIELD = "PrintField";
private static final String ROLE = "Role";
private static final String CHECKED = "checked";
private static final String DESC = "Desc";
/**
* role: rb: Radio button
*/
public static final String ROLE_RB = "rb";
/**
* role: cb: Check box
*/
public static final String ROLE_CB = "cb";
/**
* role: pb: Push button
*/
public static final String ROLE_PB = "pb";
/**
* role: tv: Text-value field
*/
public static final String ROLE_TV = "tv";
/**
* checked state: on
*/
public static final String CHECKED_STATE_ON = "on";
/**
* checked state: off
*/
public static final String CHECKED_STATE_OFF = "off";
/**
* checked state: neutral
*/
public static final String CHECKED_STATE_NEUTRAL = "neutral";
/**
* Default constructor.
*/
public PDPrintFieldAttributeObject()
{
this.setOwner(OWNER_PRINT_FIELD);
}
/**
* Creates a new PrintField attribute object with a given dictionary.
*
* @param dictionary the dictionary
*/
public PDPrintFieldAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Gets the role.
*
* @return the role
*/
public String getRole()
{
return this.getName(ROLE);
}
/**
* Sets the role. The value of Role shall be one of the following:
* <ul>
* <li>{@link #ROLE_RB},</li>
* <li>{@link #ROLE_CB},</li>
* <li>{@link #ROLE_PB},</li>
* <li>{@link #ROLE_TV}.</li>
* </ul>
*
* @param role the role
*/
public void setRole(String role)
{
this.setName(ROLE, role);
}
/**
* Gets the checked state. The default value is {@link #CHECKED_STATE_OFF}.
*
* @return the checked state
*/
public String getCheckedState()
{
return this.getName(CHECKED, CHECKED_STATE_OFF);
}
/**
* Sets the checked state. The value shall be one of:
* <ul>
* <li>{@link #CHECKED_STATE_ON},</li>
* <li>{@link #CHECKED_STATE_OFF} (default), or</li>
* <li>{@link #CHECKED_STATE_NEUTRAL}.</li>
* </ul>
*
* @param checkedState the checked state
*/
public void setCheckedState(String checkedState)
{
this.setName(CHECKED, checkedState);
}
/**
* Gets the alternate name of the field (Desc).
*
* @return the alternate name of the field
*/
public String getAlternateName()
{
return this.getString(DESC);
}
/**
* Sets the alternate name of the field (Desc).
*
* @param alternateName the alternate name of the field
*/
public void setAlternateName(String alternateName)
{
this.setString(DESC, alternateName);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder().append(super.toString());
if (this.isSpecified(ROLE))
{
sb.append(", Role=").append(this.getRole());
}
if (this.isSpecified(CHECKED))
{
sb.append(", Checked=").append(this.getCheckedState());
}
if (this.isSpecified(DESC))
{
sb.append(", Desc=").append(this.getAlternateName());
}
return sb.toString();
| 1,000
| 140
| 1,140
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public boolean isSpecified(java.lang.String) <variables>protected static final float UNSPECIFIED
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/taggedpdf/PDTableAttributeObject.java
|
PDTableAttributeObject
|
toString
|
class PDTableAttributeObject extends PDStandardAttributeObject
{
/**
* standard attribute owner: Table
*/
public static final String OWNER_TABLE = "Table";
protected static final String ROW_SPAN = "RowSpan";
protected static final String COL_SPAN = "ColSpan";
protected static final String HEADERS = "Headers";
protected static final String SCOPE = "Scope";
protected static final String SUMMARY = "Summary";
/**
* Scope: Both
*/
public static final String SCOPE_BOTH = "Both";
/**
* Scope: Column
*/
public static final String SCOPE_COLUMN = "Column";
/**
* Scope: Row
*/
public static final String SCOPE_ROW = "Row";
/**
* Default constructor.
*/
public PDTableAttributeObject()
{
this.setOwner(OWNER_TABLE);
}
/**
* Creates a new Table attribute object with a given dictionary.
*
* @param dictionary the dictionary
*/
public PDTableAttributeObject(COSDictionary dictionary)
{
super(dictionary);
}
/**
* Gets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan). The default value is 1.
*
* @return the row span
*/
public int getRowSpan()
{
return this.getInteger(ROW_SPAN, 1);
}
/**
* Sets the number of rows in the enclosing table that shall be spanned by
* the cell (RowSpan).
*
* @param rowSpan the row span
*/
public void setRowSpan(int rowSpan)
{
this.setInteger(ROW_SPAN, rowSpan);
}
/**
* Gets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan). The default value is 1.
*
* @return the column span
*/
public int getColSpan()
{
return this.getInteger(COL_SPAN, 1);
}
/**
* Sets the number of columns in the enclosing table that shall be spanned
* by the cell (ColSpan).
*
* @param colSpan the column span
*/
public void setColSpan(int colSpan)
{
this.setInteger(COL_SPAN, colSpan);
}
/**
* Gets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
*
* @return the headers.
*/
public String[] getHeaders()
{
return this.getArrayOfString(HEADERS);
}
/**
* Sets the headers (Headers). An array of byte strings, where each string
* shall be the element identifier (see the
* {@link org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement#getElementIdentifier()}) for a TH structure
* element that shall be used as a header associated with this cell.
*
* @param headers the headers
*/
public void setHeaders(String[] headers)
{
this.setArrayOfString(HEADERS, headers);
}
/**
* Gets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it.
*
* @return the scope
*/
public String getScope()
{
return this.getName(SCOPE);
}
/**
* Sets the scope (Scope). It shall reflect whether the header cell applies
* to the rest of the cells in the row that contains it, the column that
* contains it, or both the row and the column that contain it. The value
* shall be one of the following:
* <ul>
* <li>{@link #SCOPE_ROW},</li>
* <li>{@link #SCOPE_COLUMN}, or</li>
* <li>{@link #SCOPE_BOTH}.</li>
* </ul>
*
* @param scope the scope
*/
public void setScope(String scope)
{
this.setName(SCOPE, scope);
}
/**
* Gets the summary of the table’s purpose and structure.
*
* @return the summary
*/
public String getSummary()
{
return this.getString(SUMMARY);
}
/**
* Sets the summary of the table’s purpose and structure.
*
* @param summary the summary
*/
public void setSummary(String summary)
{
this.setString(SUMMARY, summary);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder().append(super.toString());
if (this.isSpecified(ROW_SPAN))
{
sb.append(", RowSpan=").append(this.getRowSpan());
}
if (this.isSpecified(COL_SPAN))
{
sb.append(", ColSpan=").append(this.getColSpan());
}
if (this.isSpecified(HEADERS))
{
sb.append(", Headers=").append(arrayToString(this.getHeaders()));
}
if (this.isSpecified(SCOPE))
{
sb.append(", Scope=").append(this.getScope());
}
if (this.isSpecified(SUMMARY))
{
sb.append(", Summary=").append(this.getSummary());
}
return sb.toString();
| 1,338
| 221
| 1,559
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public boolean isSpecified(java.lang.String) <variables>protected static final float UNSPECIFIED
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/MessageDigests.java
|
MessageDigests
|
getSHA256
|
class MessageDigests
{
private MessageDigests()
{
}
/**
* @return MD5 message digest
*/
static MessageDigest getMD5()
{
try
{
return MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e)
{
// should never happen
throw new RuntimeException(e);
}
}
/**
* @return SHA-1 message digest
*/
static MessageDigest getSHA1()
{
try
{
return MessageDigest.getInstance("SHA-1");
}
catch (NoSuchAlgorithmException e)
{
// should never happen
throw new RuntimeException(e);
}
}
/**
* @return SHA-256 message digest
*/
static MessageDigest getSHA256()
{<FILL_FUNCTION_BODY>}
}
|
try
{
return MessageDigest.getInstance("SHA-256");
}
catch (NoSuchAlgorithmException e)
{
// should never happen
throw new RuntimeException(e);
}
| 246
| 60
| 306
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDCryptFilterDictionary.java
|
PDCryptFilterDictionary
|
isEncryptMetaData
|
class PDCryptFilterDictionary implements COSObjectable
{
/**
* COS crypt filter dictionary.
*/
protected COSDictionary cryptFilterDictionary = null;
/**
* creates a new empty crypt filter dictionary.
*/
public PDCryptFilterDictionary()
{
cryptFilterDictionary = new COSDictionary();
}
/**
* creates a new crypt filter dictionary from the low level dictionary provided.
* @param d the low level dictionary that will be managed by the newly created object
*/
public PDCryptFilterDictionary(COSDictionary d)
{
cryptFilterDictionary = d;
}
/**
* This will get the dictionary associated with this crypt filter dictionary.
*
* @return The COS dictionary that this object wraps.
*/
@Override
public COSDictionary getCOSObject()
{
return cryptFilterDictionary;
}
/**
* This will set the number of bits to use for the crypt filter algorithm.
*
* @param length The new key length.
*/
public void setLength(int length)
{
cryptFilterDictionary.setInt(COSName.LENGTH, length);
}
/**
* This will return the Length entry of the crypt filter dictionary.<br><br>
* The length in <b>bits</b> for the crypt filter algorithm. This will return a multiple of 8.
*
* @return The length in bits for the encryption algorithm
*/
public int getLength()
{
return cryptFilterDictionary.getInt( COSName.LENGTH, 40 );
}
/**
* This will set the crypt filter method.
* Allowed values are: NONE, V2, AESV2, AESV3
*
* @param cfm name of the crypt filter method.
*
*/
public void setCryptFilterMethod(COSName cfm)
{
cryptFilterDictionary.setItem( COSName.CFM, cfm );
}
/**
* This will return the crypt filter method.
* Allowed values are: NONE, V2, AESV2, AESV3
*
* @return the name of the crypt filter method.
*/
public COSName getCryptFilterMethod()
{
return cryptFilterDictionary.getCOSName(COSName.CFM);
}
/**
* Will get the EncryptMetaData dictionary info.
*
* @return true if EncryptMetaData is explicitly set (the default is true)
*/
public boolean isEncryptMetaData()
{<FILL_FUNCTION_BODY>}
/**
* Set the EncryptMetaData dictionary info.
*
* @param encryptMetaData true if EncryptMetaData shall be set.
*/
public void setEncryptMetaData(boolean encryptMetaData)
{
getCOSObject().setBoolean(COSName.ENCRYPT_META_DATA, encryptMetaData);
}
}
|
COSBase value = getCOSObject().getDictionaryObject(COSName.ENCRYPT_META_DATA);
if (value instanceof COSBoolean)
{
return ((COSBoolean) value).getValue();
}
// default is true (see 7.6.3.2 Standard Encryption Dictionary PDF 32000-1:2008)
return true;
| 764
| 102
| 866
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/ProtectionPolicy.java
|
ProtectionPolicy
|
setEncryptionKeyLength
|
class ProtectionPolicy
{
private static final short DEFAULT_KEY_LENGTH = 40;
private short encryptionKeyLength = DEFAULT_KEY_LENGTH;
private boolean preferAES = false;
/**
* set the length in (bits) of the secret key that will be
* used to encrypt document data.
* The default value is 40 bits, which provides a low security level
* but is compatible with old versions of Acrobat Reader.
*
* @param l the length in bits (must be 40, 128 or 256)
*/
public void setEncryptionKeyLength(int l)
{<FILL_FUNCTION_BODY>}
/**
* Get the length of the secrete key that will be used to encrypt
* document data.
*
* @return The length (in bits) of the encryption key.
*/
public int getEncryptionKeyLength()
{
return encryptionKeyLength;
}
/**
* Tell whether AES encryption is preferred when several encryption methods are available for
* the chosen key length. The default is false. This setting is only relevant if the key length
* is 128 bits.
*
* @return true if AES encryption is preferred
*/
public boolean isPreferAES()
{
return this.preferAES;
}
/**
* Set whether AES encryption is preferred when several encryption methods are available for the chosen key length.
* The default is false. This setting is only relevant if the key length is 128 bits.
*
* @param preferAES indicates whether AES encryption is preferred or not
*/
public void setPreferAES(boolean preferAES)
{
this.preferAES = preferAES;
}
}
|
if(l!=40 && l!=128 && l!=256)
{
throw new IllegalArgumentException("Invalid key length '" + l + "' value must be 40, 128 or 256!");
}
encryptionKeyLength = (short) l;
| 453
| 77
| 530
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeyDecryptionMaterial.java
|
PublicKeyDecryptionMaterial
|
getPrivateKey
|
class PublicKeyDecryptionMaterial extends DecryptionMaterial
{
private final String password;
private final KeyStore keyStore;
private final String alias;
/**
* Create a new public key decryption material.
*
* @param keystore The keystore were the private key and the certificate are
* @param a The alias of the private key and the certificate.
* If the keystore contains only 1 entry, this parameter can be left null.
* @param pwd The password to extract the private key from the keystore.
*/
public PublicKeyDecryptionMaterial(KeyStore keystore, String a, String pwd)
{
keyStore = keystore;
alias = a;
password = pwd;
}
/**
* Returns the certificate contained in the keystore.
*
* @return The certificate that will be used to try to open the document.
*
* @throws KeyStoreException If there is an error accessing the certificate.
*/
public X509Certificate getCertificate() throws KeyStoreException
{
if(keyStore.size() == 1)
{
Enumeration<String> aliases = keyStore.aliases();
String keyStoreAlias = aliases.nextElement();
return (X509Certificate)keyStore.getCertificate(keyStoreAlias);
}
else
{
if(keyStore.containsAlias(alias))
{
return (X509Certificate)keyStore.getCertificate(alias);
}
throw new KeyStoreException("the keystore does not contain the given alias");
}
}
/**
* Returns the password given by the user and that will be used
* to open the private key.
*
* @return The password.
*/
public String getPassword()
{
return password;
}
/**
* returns The private key that will be used to open the document protection.
* @return The private key.
* @throws KeyStoreException If there is an error accessing the key.
*/
public Key getPrivateKey() throws KeyStoreException
{<FILL_FUNCTION_BODY>}
}
|
try
{
if(keyStore.size() == 1)
{
Enumeration<String> aliases = keyStore.aliases();
String keyStoreAlias = aliases.nextElement();
return keyStore.getKey(keyStoreAlias, password.toCharArray());
}
else
{
if(keyStore.containsAlias(alias))
{
return keyStore.getKey(alias, password.toCharArray());
}
throw new KeyStoreException("the keystore does not contain the given alias");
}
}
catch(UnrecoverableKeyException ex)
{
throw new KeyStoreException("the private key is not recoverable", ex);
}
catch(NoSuchAlgorithmException ex)
{
throw new KeyStoreException("the algorithm necessary to recover the key is not available", ex);
}
| 551
| 219
| 770
|
<methods>public non-sealed void <init>() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/RC4Cipher.java
|
RC4Cipher
|
setKey
|
class RC4Cipher
{
private final int[] salt;
private int b;
private int c;
/**
* Constructor.
*/
RC4Cipher()
{
salt = new int[256];
}
/**
* This will reset the key to be used.
*
* @param key The RC4 key used during encryption.
*/
public void setKey( byte[] key )
{<FILL_FUNCTION_BODY>}
/**
* This will ensure that the value for a byte >=0.
*
* @param aByte The byte to test against.
*
* @return A value >=0 and < 256
*/
private static int fixByte( byte aByte )
{
return aByte < 0 ? 256 + aByte : aByte;
}
/**
* This will swap two values in an array.
*
* @param data The array to swap from.
* @param firstIndex The index of the first element to swap.
* @param secondIndex The index of the second element to swap.
*/
private static void swap( int[] data, int firstIndex, int secondIndex )
{
int tmp = data[ firstIndex ];
data[ firstIndex ] = data[ secondIndex ];
data[ secondIndex ] = tmp;
}
/**
* This will encrypt and write the next byte.
*
* @param aByte The byte to encrypt.
* @param output The stream to write to.
*
* @throws IOException If there is an error writing to the output stream.
*/
public void write( byte aByte, OutputStream output ) throws IOException
{
b = (b + 1) % 256;
c = (salt[b] + c) % 256;
swap( salt, b, c );
int saltIndex = (salt[b] + salt[c]) % 256;
output.write(aByte ^ (byte)salt[saltIndex]);
}
/**
* This will encrypt and write the data.
*
* @param data The data to encrypt.
* @param output The stream to write to.
*
* @throws IOException If there is an error writing to the output stream.
*/
public void write( byte[] data, OutputStream output ) throws IOException
{
for (byte aData : data)
{
write(aData, output);
}
}
/**
* This will encrypt and write the data.
*
* @param data The data to encrypt.
* @param output The stream to write to.
*
* @throws IOException If there is an error writing to the output stream.
*/
public void write( InputStream data, OutputStream output ) throws IOException
{
byte[] buffer = new byte[1024];
int amountRead;
while( (amountRead = data.read( buffer )) != -1 )
{
write( buffer, 0, amountRead, output );
}
}
/**
* This will encrypt and write the data.
*
* @param data The data to encrypt.
* @param offset The offset into the array to start reading data from.
* @param len The number of bytes to attempt to read.
* @param output The stream to write to.
*
* @throws IOException If there is an error writing to the output stream.
*/
public void write( byte[] data, int offset, int len, OutputStream output) throws IOException
{
for( int i = offset; i < offset + len; i++ )
{
write( data[i], output );
}
}
}
|
b = 0;
c = 0;
if(key.length < 1 || key.length > 32)
{
throw new IllegalArgumentException("number of bytes must be between 1 and 32");
}
for(int i = 0; i < salt.length; i++)
{
salt[i] = i;
}
int keyIndex = 0;
int saltIndex = 0;
for( int i = 0; i < salt.length; i++)
{
saltIndex = (fixByte(key[keyIndex]) + salt[i] + saltIndex) % 256;
swap( salt, i, saltIndex );
keyIndex = (keyIndex + 1) % key.length;
}
| 951
| 190
| 1,141
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandlerFactory.java
|
SecurityHandlerFactory
|
newSecurityHandler
|
class SecurityHandlerFactory
{
/** Singleton instance */
public static final SecurityHandlerFactory INSTANCE = new SecurityHandlerFactory();
private final Map<String, Class<? extends SecurityHandler>> nameToHandler = new HashMap<>();
private final Map<Class<? extends ProtectionPolicy>,
Class<? extends SecurityHandler>> policyToHandler = new HashMap<>();
private SecurityHandlerFactory()
{
registerHandler(StandardSecurityHandler.FILTER,
StandardSecurityHandler.class,
StandardProtectionPolicy.class);
registerHandler(PublicKeySecurityHandler.FILTER,
PublicKeySecurityHandler.class,
PublicKeyProtectionPolicy.class);
}
/**
* Registers a security handler.
*
* If the security handler was already registered an exception is thrown.
* If another handler was previously registered for the same filter name or
* for the same policy name, an exception is thrown
*
* @param name the name of the filter
* @param securityHandler security handler class to register
* @param protectionPolicy protection policy class to register
*/
public void registerHandler(String name,
Class<? extends SecurityHandler> securityHandler,
Class<? extends ProtectionPolicy> protectionPolicy)
{
if (nameToHandler.containsKey(name))
{
throw new IllegalStateException("The security handler name is already registered");
}
nameToHandler.put(name, securityHandler);
policyToHandler.put(protectionPolicy, securityHandler);
}
/**
* Returns a new security handler for the given protection policy, or null none is available.
* @param policy the protection policy for which to create a security handler
* @return a new SecurityHandler instance, or null if none is available
*/
public SecurityHandler<ProtectionPolicy> newSecurityHandlerForPolicy(ProtectionPolicy policy)
{
Class<? extends SecurityHandler> handlerClass = policyToHandler.get(policy.getClass());
if (handlerClass == null)
{
return null;
}
Class<?>[] argsClasses = { policy.getClass() };
Object[] args = { policy };
return newSecurityHandler(handlerClass, argsClasses, args);
}
/**
* Returns a new security handler for the given Filter name, or null none is available.
* @param name the Filter name from the PDF encryption dictionary
* @return a new SecurityHandler instance, or null if none is available
*/
public SecurityHandler<ProtectionPolicy> newSecurityHandlerForFilter(String name)
{
Class<? extends SecurityHandler> handlerClass = nameToHandler.get(name);
if (handlerClass == null)
{
return null;
}
Class<?>[] argsClasses = { };
Object[] args = { };
return newSecurityHandler(handlerClass, argsClasses, args);
}
/* Returns a new security handler for the given parameters, or null none is available.
*
* @param handlerClass the handler class.
* @param argsClasses the parameter array.
* @param args array of objects to be passed as arguments to the constructor call.
* @return a new SecurityHandler instance, or null if none is available.
*/
private SecurityHandler<ProtectionPolicy> newSecurityHandler(Class<? extends SecurityHandler> handlerClass,
Class<?>[] argsClasses, Object[] args)
{<FILL_FUNCTION_BODY>}
}
|
try
{
Constructor<? extends SecurityHandler> ctor =
handlerClass.getDeclaredConstructor(argsClasses);
return ctor.newInstance(args);
}
catch(NoSuchMethodException | IllegalAccessException | InstantiationException |
InvocationTargetException e)
{
// should not happen in normal operation
throw new RuntimeException(e);
}
| 850
| 99
| 949
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityProvider.java
|
SecurityProvider
|
getProvider
|
class SecurityProvider
{
private static Provider provider = null;
private SecurityProvider()
{
}
/**
* Returns the provider to be used for advanced encrypting/decrypting. Default is the BouncyCastleProvider.
*
* @return the security provider
*/
public static Provider getProvider()
{<FILL_FUNCTION_BODY>}
/**
* Set the provider to be used for advanced encrypting/decrypting.
*
* @param provider the security provider
*/
public static void setProvider(Provider provider)
{
SecurityProvider.provider = provider;
}
}
|
// TODO synchronize access
if (provider == null)
{
provider = new BouncyCastleProvider();
}
return provider;
| 168
| 41
| 209
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationCaret.java
|
FDFAnnotationCaret
|
initFringe
|
class FDFAnnotationCaret extends FDFAnnotation
{
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Caret";
/**
* Default constructor.
*/
public FDFAnnotationCaret()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationCaret(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationCaret(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
initFringe(element);
String symbol = element.getAttribute("symbol");
if (symbol != null && !symbol.isEmpty())
{
setSymbol(symbol);
}
}
private void initFringe(Element element) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* This will set the fringe rectangle. Giving the difference between the annotations rectangle and where the drawing
* occurs.
*
* @param fringe the fringe
*/
public final void setFringe(PDRectangle fringe)
{
annot.setItem(COSName.RD, fringe);
}
/**
* This will retrieve the fringe. Giving the difference between the annotations rectangle and where the drawing
* occurs.
*
* @return the rectangle difference
*/
public PDRectangle getFringe()
{
COSArray rd = annot.getCOSArray(COSName.RD);
return rd != null ? new PDRectangle(rd) : null;
}
/**
* This will set the symbol that shall be associated with the caret.
*
* @param symbol the symbol
*/
public final void setSymbol(String symbol)
{
String newSymbol = "None";
if ("paragraph".equals(symbol))
{
newSymbol = "P";
}
annot.setString(COSName.SY, newSymbol);
}
/**
* This will retrieve the symbol that shall be associated with the caret.
*
* @return the symbol
*/
public String getSymbol()
{
return annot.getString(COSName.SY);
}
}
|
String fringe = element.getAttribute("fringe");
if (fringe != null && !fringe.isEmpty())
{
String[] fringeValues = fringe.split(",");
if (fringeValues.length != 4)
{
throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
}
PDRectangle rect = new PDRectangle();
rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
setFringe(rect);
}
| 689
| 204
| 893
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationCircle.java
|
FDFAnnotationCircle
|
initFringe
|
class FDFAnnotationCircle extends FDFAnnotation
{
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Circle";
/**
* Default constructor.
*/
public FDFAnnotationCircle()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationCircle(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationCircle(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
String color = element.getAttribute("interior-color");
if (color != null && color.length() == 7 && color.charAt(0) == '#')
{
int colorValue = Integer.parseInt(color.substring(1, 7), 16);
setInteriorColor(new Color(colorValue));
}
initFringe(element);
}
private void initFringe(Element element) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* This will set interior color of the drawn area.
*
* @param color The interior color of the circle.
*/
public final void setInteriorColor(Color color)
{
COSArray array = null;
if (color != null)
{
array = COSArray.of(color.getRGBColorComponents(null));
}
annot.setItem(COSName.IC, array);
}
/**
* This will retrieve the interior color of the drawn area.
*
* @return object representing the color.
*/
public Color getInteriorColor()
{
Color retval = null;
COSArray array = annot.getCOSArray(COSName.IC);
if (array != null)
{
float[] rgb = array.toFloatArray();
if (rgb.length >= 3)
{
retval = new Color(rgb[0], rgb[1], rgb[2]);
}
}
return retval;
}
/**
* This will set the fringe rectangle. Giving the difference between the annotations rectangle and where the drawing
* occurs. (To take account of any effects applied through the BE entry for example)
*
* @param fringe the fringe
*/
public final void setFringe(PDRectangle fringe)
{
annot.setItem(COSName.RD, fringe);
}
/**
* This will get the fringe. Giving the difference between the annotations rectangle and where the drawing occurs.
* (To take account of any effects applied through the BE entry for example)
*
* @return the rectangle difference
*/
public PDRectangle getFringe()
{
COSArray rd = annot.getCOSArray(COSName.RD);
return rd != null ? new PDRectangle(rd) : null;
}
}
|
String fringe = element.getAttribute("fringe");
if (fringe != null && !fringe.isEmpty())
{
String[] fringeValues = fringe.split(",");
if (fringeValues.length != 4)
{
throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
}
PDRectangle rect = new PDRectangle();
rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
setFringe(rect);
}
| 868
| 204
| 1,072
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationInk.java
|
FDFAnnotationInk
|
setInkList
|
class FDFAnnotationInk extends FDFAnnotation
{
private static final Logger LOG = LogManager.getLogger(FDFAnnotationInk.class);
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Ink";
/**
* Default constructor.
*/
public FDFAnnotationInk()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationInk(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationInk(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
XPath xpath = XPathFactory.newInstance().newXPath();
try
{
NodeList gestures = (NodeList) xpath.evaluate("inklist/gesture", element,
XPathConstants.NODESET);
if (gestures.getLength() == 0)
{
throw new IOException("Error: missing element 'gesture'");
}
List<float[]> inklist = new ArrayList<>();
for (int i = 0; i < gestures.getLength(); i++)
{
Node node = gestures.item(i);
if (node instanceof Element)
{
String gesture = node.getFirstChild().getNodeValue();
String[] gestureValues = gesture.split(",|;");
float[] values = new float[gestureValues.length];
for (int j = 0; j < gestureValues.length; j++)
{
values[j] = Float.parseFloat(gestureValues[j]);
}
inklist.add(values);
}
}
setInkList(inklist);
}
catch (XPathExpressionException e)
{
LOG.debug("Error while evaluating XPath expression for inklist gestures", e);
}
}
/**
* Set the paths making up the freehand "scribble".
*
* The ink annotation is made up of one ore more disjoint paths. Each array entry is an array representing a stroked
* path, being a series of alternating horizontal and vertical coordinates in default user space.
*
* @param inklist the List of arrays representing the paths.
*/
public final void setInkList(List<float[]> inklist)
{<FILL_FUNCTION_BODY>}
/**
* Get the paths making up the freehand "scribble".
*
* @see #setInkList(List)
* @return the List of arrays representing the paths.
*/
public List<float[]> getInkList()
{
COSArray array = annot.getCOSArray(COSName.INKLIST);
if (array != null)
{
List<float[]> retval = new ArrayList<>();
for (COSBase entry : array)
{
retval.add(((COSArray) entry).toFloatArray());
}
return retval;
}
else
{
return null; // Should never happen as this is a required item
}
}
}
|
COSArray newInklist = new COSArray();
for (float[] array : inklist)
{
newInklist.add(COSArray.of(array));
}
annot.setItem(COSName.INKLIST, newInklist);
| 886
| 72
| 958
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationPolygon.java
|
FDFAnnotationPolygon
|
initVertices
|
class FDFAnnotationPolygon extends FDFAnnotation
{
private static final Logger LOG = LogManager.getLogger(FDFAnnotationPolygon.class);
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Polygon";
/**
* Default constructor.
*/
public FDFAnnotationPolygon()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationPolygon(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationPolygon(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
initVertices(element);
String color = element.getAttribute("interior-color");
if (color != null && color.length() == 7 && color.charAt(0) == '#')
{
int colorValue = Integer.parseInt(color.substring(1, 7), 16);
setInteriorColor(new Color(colorValue));
}
}
private void initVertices(Element element) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* This will set the coordinates of the vertices.
*
* @param vertices array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
*/
public final void setVertices(float[] vertices)
{
annot.setItem(COSName.VERTICES, COSArray.of(vertices));
}
/**
* This will get the coordinates of the vertices.
*
* @return array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
*/
public float[] getVertices()
{
COSArray array = annot.getCOSArray(COSName.VERTICES);
return array != null ? array.toFloatArray() : null;
}
/**
* This will set interior color of the drawn area.
*
* @param color The interior color of the drawn area.
*/
public final void setInteriorColor(Color color)
{
COSArray array = null;
if (color != null)
{
array = COSArray.of(color.getRGBColorComponents(null));
}
annot.setItem(COSName.IC, array);
}
/**
* This will get interior color of the drawn area.
*
* @return object representing the color.
*/
public Color getInteriorColor()
{
Color retval = null;
COSArray array = annot.getCOSArray(COSName.IC);
if (array != null)
{
float[] rgb = array.toFloatArray();
if (rgb.length >= 3)
{
retval = new Color(rgb[0], rgb[1], rgb[2]);
}
}
return retval;
}
}
|
XPath xpath = XPathFactory.newInstance().newXPath();
try
{
String vertices = xpath.evaluate("vertices", element);
if (vertices == null || vertices.isEmpty())
{
throw new IOException("Error: missing element 'vertices'");
}
String[] verticesValues = vertices.split(",|;");
float[] values = new float[verticesValues.length];
for (int i = 0; i < verticesValues.length; i++)
{
values[i] = Float.parseFloat(verticesValues[i]);
}
setVertices(values);
}
catch (XPathExpressionException e)
{
LOG.debug("Error while evaluating XPath expression for polygon vertices", e);
}
| 862
| 196
| 1,058
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationPolyline.java
|
FDFAnnotationPolyline
|
setStartPointEndingStyle
|
class FDFAnnotationPolyline extends FDFAnnotation
{
private static final Logger LOG = LogManager.getLogger(FDFAnnotationPolyline.class);
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Polyline";
/**
* Default constructor.
*/
public FDFAnnotationPolyline()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationPolyline(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationPolyline(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
initVertices(element);
initStyles(element);
}
private void initVertices(Element element) throws IOException
{
XPath xpath = XPathFactory.newInstance().newXPath();
try
{
String vertices = xpath.evaluate("vertices[1]", element);
if (vertices == null || vertices.isEmpty())
{
throw new IOException("Error: missing element 'vertices'");
}
String[] verticesValues = vertices.split(",|;");
float[] values = new float[verticesValues.length];
for (int i = 0; i < verticesValues.length; i++)
{
values[i] = Float.parseFloat(verticesValues[i]);
}
setVertices(values);
}
catch (XPathExpressionException e)
{
LOG.debug("Error while evaluating XPath expression for polyline vertices", e);
}
}
private void initStyles(Element element)
{
String startStyle = element.getAttribute("head");
if (startStyle != null && !startStyle.isEmpty())
{
setStartPointEndingStyle(startStyle);
}
String endStyle = element.getAttribute("tail");
if (endStyle != null && !endStyle.isEmpty())
{
setEndPointEndingStyle(endStyle);
}
String color = element.getAttribute("interior-color");
if (color != null && color.length() == 7 && color.charAt(0) == '#')
{
int colorValue = Integer.parseInt(color.substring(1, 7), 16);
setInteriorColor(new Color(colorValue));
}
}
/**
* This will set the coordinates of the the vertices.
*
* @param vertices array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
*/
public void setVertices(float[] vertices)
{
annot.setItem(COSName.VERTICES, COSArray.of(vertices));
}
/**
* This will get the coordinates of the the vertices.
*
* @return array of floats [x1, y1, x2, y2, ...] vertex coordinates in default user space.
*/
public float[] getVertices()
{
COSArray array = annot.getCOSArray(COSName.VERTICES);
return array != null ? array.toFloatArray() : null;
}
/**
* This will set the line ending style for the start point, see the LE_ constants for the possible values.
*
* @param style The new style.
*/
public void setStartPointEndingStyle(String style)
{<FILL_FUNCTION_BODY>}
/**
* This will retrieve the line ending style for the start point, possible values shown in the LE_ constants section.
*
* @return The ending style for the start point.
*/
public String getStartPointEndingStyle()
{
COSArray array = annot.getCOSArray(COSName.LE);
return array != null ? array.getName(0) : PDAnnotationLine.LE_NONE;
}
/**
* This will set the line ending style for the end point, see the LE_ constants for the possible values.
*
* @param style The new style.
*/
public void setEndPointEndingStyle(String style)
{
String actualStyle = style == null ? PDAnnotationLine.LE_NONE : style;
COSArray array = annot.getCOSArray(COSName.LE);
if (array == null)
{
array = new COSArray();
array.add(COSName.getPDFName(PDAnnotationLine.LE_NONE));
array.add(COSName.getPDFName(actualStyle));
annot.setItem(COSName.LE, array);
}
else
{
array.setName(1, actualStyle);
}
}
/**
* This will retrieve the line ending style for the end point, possible values shown in the LE_ constants section.
*
* @return The ending style for the end point.
*/
public String getEndPointEndingStyle()
{
COSArray array = annot.getCOSArray(COSName.LE);
return array != null ? array.getName(1) : PDAnnotationLine.LE_NONE;
}
/**
* This will set interior color of the line endings defined in the LE entry.
*
* @param color The interior color of the line endings.
*/
public void setInteriorColor(Color color)
{
COSArray array = null;
if (color != null)
{
array = COSArray.of(color.getRGBColorComponents(null));
}
annot.setItem(COSName.IC, array);
}
/**
* This will retrieve the interior color of the line endings defined in the LE entry.
*
* @return object representing the color.
*/
public Color getInteriorColor()
{
Color retval = null;
COSArray array = annot.getCOSArray(COSName.IC);
if (array != null)
{
float[] rgb = array.toFloatArray();
if (rgb.length >= 3)
{
retval = new Color(rgb[0], rgb[1], rgb[2]);
}
}
return retval;
}
}
|
String actualStyle = style == null ? PDAnnotationLine.LE_NONE : style;
COSArray array = annot.getCOSArray(COSName.LE);
if (array == null)
{
array = new COSArray();
array.add(COSName.getPDFName(actualStyle));
array.add(COSName.getPDFName(PDAnnotationLine.LE_NONE));
annot.setItem(COSName.LE, array);
}
else
{
array.setName(0, actualStyle);
}
| 1,691
| 144
| 1,835
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationSquare.java
|
FDFAnnotationSquare
|
getInteriorColor
|
class FDFAnnotationSquare extends FDFAnnotation
{
/**
* COS Model value for SubType entry.
*/
public static final String SUBTYPE = "Square";
/**
* Default constructor.
*/
public FDFAnnotationSquare()
{
super();
annot.setName(COSName.SUBTYPE, SUBTYPE);
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationSquare(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationSquare(Element element) throws IOException
{
super(element);
annot.setName(COSName.SUBTYPE, SUBTYPE);
String color = element.getAttribute("interior-color");
if (color != null && color.length() == 7 && color.charAt(0) == '#')
{
int colorValue = Integer.parseInt(color.substring(1, 7), 16);
setInteriorColor(new Color(colorValue));
}
initFringe(element);
}
private void initFringe(Element element) throws IOException
{
String fringe = element.getAttribute("fringe");
if (fringe != null && !fringe.isEmpty())
{
String[] fringeValues = fringe.split(",");
if (fringeValues.length != 4)
{
throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
}
PDRectangle rect = new PDRectangle();
rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
setFringe(rect);
}
}
/**
* This will set interior color of the drawn area.
*
* @param color The interior color of the circle.
*/
public final void setInteriorColor(Color color)
{
COSArray array = null;
if (color != null)
{
array = COSArray.of(color.getRGBColorComponents(null));
}
annot.setItem(COSName.IC, array);
}
/**
* This will retrieve the interior color of the drawn area.
*
* @return object representing the color.
*/
public Color getInteriorColor()
{<FILL_FUNCTION_BODY>}
/**
* This will set the fringe rectangle. Giving the difference between the annotations rectangle and where the drawing
* occurs. (To take account of any effects applied through the BE entry for example)
*
* @param fringe the fringe
*/
public final void setFringe(PDRectangle fringe)
{
annot.setItem(COSName.RD, fringe);
}
/**
* This will get the fringe. Giving the difference between the annotations rectangle and where the drawing occurs.
* (To take account of any effects applied through the BE entry for example)
*
* @return the rectangle difference
*/
public PDRectangle getFringe()
{
COSArray rd = annot.getCOSArray(COSName.RD);
return rd != null ? new PDRectangle(rd) : null;
}
}
|
Color retval = null;
COSArray array = annot.getCOSArray(COSName.IC);
if (array != null)
{
float[] rgb = array.toFloatArray();
if (rgb.length >= 3)
{
retval = new Color(rgb[0], rgb[1], rgb[2]);
}
}
return retval;
| 966
| 105
| 1,071
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTextMarkup.java
|
FDFAnnotationTextMarkup
|
getCoords
|
class FDFAnnotationTextMarkup extends FDFAnnotation
{
/**
* Default constructor.
*/
public FDFAnnotationTextMarkup()
{
super();
}
/**
* Constructor.
*
* @param a An existing FDF Annotation.
*/
public FDFAnnotationTextMarkup(COSDictionary a)
{
super(a);
}
/**
* Constructor.
*
* @param element An XFDF element.
*
* @throws IOException If there is an error extracting information from the element.
*/
public FDFAnnotationTextMarkup(Element element) throws IOException
{
super(element);
String coords = element.getAttribute("coords");
if (coords == null || coords.isEmpty())
{
throw new IOException("Error: missing attribute 'coords'");
}
String[] coordsValues = coords.split(",");
if (coordsValues.length < 8)
{
throw new IOException("Error: too little numbers in attribute 'coords'");
}
float[] values = new float[coordsValues.length];
for (int i = 0; i < coordsValues.length; i++)
{
values[i] = Float.parseFloat(coordsValues[i]);
}
setCoords(values);
}
/**
* Set the coordinates of individual words or group of words.
*
* The quadliterals shall encompasses a word or group of contiguous words in the text underlying the annotation. The
* coordinates for each quadrilateral shall be given in the order x1 y1 x2 y2 x3 y3 x4 y4.
*
* @param coords an array of 8 n numbers specifying the coordinates of n quadrilaterals.
*/
public void setCoords(float[] coords)
{
annot.setItem(COSName.QUADPOINTS, COSArray.of(coords));
}
/**
* Get the coordinates of individual words or group of words.
*
* @see #setCoords(float[])
* @return the array of 8 n numbers specifying the coordinates of n quadrilaterals.
*/
public float[] getCoords()
{<FILL_FUNCTION_BODY>}
}
|
COSArray quadPoints = annot.getCOSArray(COSName.QUADPOINTS);
if (quadPoints != null)
{
return quadPoints.toFloatArray();
}
else
{
return null; // Should never happen as this is a required item
}
| 603
| 78
| 681
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public void <init>(org.w3c.dom.Element) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.fdf.FDFAnnotation create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary getBorderEffect() ,public org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary getBorderStyle() ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public java.awt.Color getColor() ,public java.lang.String getContents() ,public java.util.Calendar getCreationDate() throws java.io.IOException,public java.lang.String getDate() ,public java.lang.String getIntent() ,public java.lang.String getName() ,public float getOpacity() ,public java.lang.Integer getPage() ,public org.apache.pdfbox.pdmodel.common.PDRectangle getRectangle() ,public java.lang.String getRichContents() ,public java.lang.String getSubject() ,public java.lang.String getTitle() ,public boolean isHidden() ,public boolean isInvisible() ,public boolean isLocked() ,public boolean isLockedContents() ,public boolean isNoRotate() ,public boolean isNoView() ,public boolean isNoZoom() ,public boolean isPrinted() ,public boolean isReadOnly() ,public boolean isToggleNoView() ,public final void setBorderEffect(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary) ,public final void setBorderStyle(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) ,public final void setColor(java.awt.Color) ,public final void setContents(java.lang.String) ,public final void setCreationDate(java.util.Calendar) ,public final void setDate(java.lang.String) ,public final void setHidden(boolean) ,public final void setIntent(java.lang.String) ,public final void setInvisible(boolean) ,public final void setLocked(boolean) ,public void setLockedContents(boolean) ,public final void setName(java.lang.String) ,public final void setNoRotate(boolean) ,public final void setNoView(boolean) ,public final void setNoZoom(boolean) ,public final void setOpacity(float) ,public final void setPage(int) ,public final void setPrinted(boolean) ,public final void setReadOnly(boolean) ,public final void setRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) ,public final void setRichContents(java.lang.String) ,public final void setSubject(java.lang.String) ,public final void setTitle(java.lang.String) ,public final void setToggleNoView(boolean) <variables>private static final int FLAG_HIDDEN,private static final int FLAG_INVISIBLE,private static final int FLAG_LOCKED,private static final int FLAG_LOCKED_CONTENTS,private static final int FLAG_NO_ROTATE,private static final int FLAG_NO_VIEW,private static final int FLAG_NO_ZOOM,private static final int FLAG_PRINTED,private static final int FLAG_READ_ONLY,private static final int FLAG_TOGGLE_NO_VIEW,private static final Logger LOG,protected final non-sealed org.apache.pdfbox.cos.COSDictionary annot
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
|
FDFDocument
|
getCatalog
|
class FDFDocument implements Closeable
{
private final COSDocument document;
/**
* Constructor, creates a new FDF document.
*
*/
public FDFDocument()
{
document = new COSDocument();
document.getDocumentState().setParsing(false);
document.setVersion(1.2f);
// First we need a trailer
document.setTrailer(new COSDictionary());
// Next we need the root dictionary.
FDFCatalog catalog = new FDFCatalog();
setCatalog(catalog);
}
/**
* Constructor that uses an existing document. The COSDocument that is passed in must be valid.
*
* @param doc The COSDocument that this document wraps.
*/
public FDFDocument(COSDocument doc)
{
document = doc;
document.getDocumentState().setParsing(false);
}
/**
* This will create an FDF document from an XFDF XML document.
*
* @param doc The XML document that contains the XFDF data.
* @throws IOException If there is an error reading from the dom.
*/
public FDFDocument(Document doc) throws IOException
{
this();
Element xfdf = doc.getDocumentElement();
if (!xfdf.getNodeName().equals("xfdf"))
{
throw new IOException("Error while importing xfdf document, "
+ "root should be 'xfdf' and not '" + xfdf.getNodeName() + "'");
}
FDFCatalog cat = new FDFCatalog(xfdf);
setCatalog(cat);
}
/**
* This will write this element as an XML document.
*
* @param output The stream to write the xml to.
*
* @throws IOException If there is an error writing the XML.
*/
public void writeXML(Writer output) throws IOException
{
output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
output.write("<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\n");
getCatalog().writeXML(output);
output.write("</xfdf>\n");
}
/**
* This will get the low level document.
*
* @return The document that this layer sits on top of.
*/
public COSDocument getDocument()
{
return document;
}
/**
* This will get the FDF Catalog. This is guaranteed to not return null.
*
* @return The documents /Root dictionary
*/
public FDFCatalog getCatalog()
{<FILL_FUNCTION_BODY>}
/**
* This will set the FDF catalog for this FDF document.
*
* @param cat The FDF catalog.
*/
public final void setCatalog(FDFCatalog cat)
{
COSDictionary trailer = document.getTrailer();
trailer.setItem(COSName.ROOT, cat);
}
/**
* This will save this document to the filesystem.
*
* @param fileName The file to save as.
*
* @throws IOException If there is an error saving the document.
*/
public void save(File fileName) throws IOException
{
try (FileOutputStream fos = new FileOutputStream(fileName))
{
save(fos);
}
}
/**
* This will save this document to the filesystem.
*
* @param fileName The file to save as.
*
* @throws IOException If there is an error saving the document.
*/
public void save(String fileName) throws IOException
{
save(new File(fileName));
}
/**
* This will save the document to an output stream.
*
* @param output The stream to write to.
*
* @throws IOException If there is an error writing the document.
*/
public void save(OutputStream output) throws IOException
{
COSWriter writer = new COSWriter(output);
writer.write(this);
}
/**
* This will save this document to the filesystem.
*
* @param fileName The file to save as.
*
* @throws IOException If there is an error saving the document.
*/
public void saveXFDF(File fileName) throws IOException
{
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8)))
{
saveXFDF(writer);
}
}
/**
* This will save this document to the filesystem.
*
* @param fileName The file to save as.
*
* @throws IOException If there is an error saving the document.
*/
public void saveXFDF(String fileName) throws IOException
{
saveXFDF(new File(fileName));
}
/**
* This will save the document to an output stream and close the stream.
*
* @param output The stream to write to.
*
* @throws IOException If there is an error writing the document.
*/
public void saveXFDF(Writer output) throws IOException
{
try
{
writeXML(output);
}
finally
{
if (output != null)
{
output.close();
}
}
}
/**
* This will close the underlying COSDocument object.
*
* @throws IOException If there is an error releasing resources.
*/
@Override
public void close() throws IOException
{
document.close();
}
}
|
FDFCatalog retval = null;
COSDictionary trailer = document.getTrailer();
COSDictionary root = trailer.getCOSDictionary(COSName.ROOT);
if (root == null)
{
retval = new FDFCatalog();
setCatalog(retval);
}
else
{
retval = new FDFCatalog(root);
}
return retval;
| 1,465
| 110
| 1,575
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFIconFit.java
|
FDFIconFit
|
getFractionalSpaceToAllocate
|
class FDFIconFit implements COSObjectable
{
private final COSDictionary fit;
/**
* A scale option.
*/
public static final String SCALE_OPTION_ALWAYS = "A";
/**
* A scale option.
*/
public static final String SCALE_OPTION_ONLY_WHEN_ICON_IS_BIGGER = "B";
/**
* A scale option.
*/
public static final String SCALE_OPTION_ONLY_WHEN_ICON_IS_SMALLER = "S";
/**
* A scale option.
*/
public static final String SCALE_OPTION_NEVER = "N";
/**
* Scale to fill with of annotation, disregarding aspect ratio.
*/
public static final String SCALE_TYPE_ANAMORPHIC = "A";
/**
* Scale to fit width or height, smaller of two, while retaining aspect ration.
*/
public static final String SCALE_TYPE_PROPORTIONAL = "P";
/**
* Default constructor.
*/
public FDFIconFit()
{
fit = new COSDictionary();
}
/**
* Constructor.
*
* @param f The icon fit dictionary.
*/
public FDFIconFit(COSDictionary f)
{
fit = f;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSDictionary getCOSObject()
{
return fit;
}
/**
* This will get the scale option. See the SCALE_OPTION_XXX constants. This is guaranteed to never return null.
* Default: Always
*
* @return The scale option.
*/
public String getScaleOption()
{
String retval = fit.getNameAsString(COSName.SW);
if (retval == null)
{
retval = SCALE_OPTION_ALWAYS;
}
return retval;
}
/**
* This will set the scale option for the icon. Set the SCALE_OPTION_XXX constants.
*
* @param option The scale option.
*/
public void setScaleOption(String option)
{
fit.setName(COSName.SW, option);
}
/**
* This will get the scale type. See the SCALE_TYPE_XXX constants. This is guaranteed to never return null. Default:
* Proportional
*
* @return The scale type.
*/
public String getScaleType()
{
String retval = fit.getNameAsString(COSName.S);
if (retval == null)
{
retval = SCALE_TYPE_PROPORTIONAL;
}
return retval;
}
/**
* This will set the scale type. See the SCALE_TYPE_XXX constants.
*
* @param scale The scale type.
*/
public void setScaleType(String scale)
{
fit.setName(COSName.S, scale);
}
/**
* This is guaranteed to never return null.<br>
*
* To quote the PDF Spec "An array of two numbers between 0.0 and 1.0 indicating the fraction of leftover space to
* allocate at the left and bottom of the icon. A value of [0.0 0.0] positions the icon at the bottom-left corner of
* the annotation rectangle; a value of [0.5 0.5] centers it within the rectangle. This entry is used only if the
* icon is scaled proportionally. Default value: [0.5 0.5]."
*
* @return The fractional space to allocate.
*/
public PDRange getFractionalSpaceToAllocate()
{<FILL_FUNCTION_BODY>}
/**
* This will set frational space to allocate.
*
* @param space The space to allocate.
*/
public void setFractionalSpaceToAllocate(PDRange space)
{
fit.setItem(COSName.A, space);
}
/**
* This will tell if the icon should scale to fit the annotation bounds. Default: false
*
* @return A flag telling if the icon should scale.
*/
public boolean shouldScaleToFitAnnotation()
{
return fit.getBoolean(COSName.FB, false);
}
/**
* This will tell the icon to scale.
*
* @param value The flag value.
*/
public void setScaleToFitAnnotation(boolean value)
{
fit.setBoolean(COSName.FB, value);
}
}
|
PDRange retval = null;
COSArray array = fit.getCOSArray(COSName.A);
if (array == null)
{
retval = new PDRange();
retval.setMin(.5f);
retval.setMax(.5f);
setFractionalSpaceToAllocate(retval);
}
else
{
retval = new PDRange(array);
}
return retval;
| 1,247
| 120
| 1,367
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java
|
FDFJavaScript
|
getDoc
|
class FDFJavaScript implements COSObjectable
{
private final COSDictionary dictionary;
/**
* Default constructor.
*/
public FDFJavaScript()
{
dictionary = new COSDictionary();
}
/**
* Constructor.
*
* @param javaScript The FDF java script.
*/
public FDFJavaScript(COSDictionary javaScript)
{
dictionary = javaScript;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSDictionary getCOSObject()
{
return dictionary;
}
/**
* This will get the javascript that is executed before the import.
*
* @return Some javascript code.
*/
public String getBefore()
{
COSBase base = dictionary.getDictionaryObject(COSName.BEFORE);
if (base instanceof COSString)
{
return ((COSString) base).getString();
}
else if (base instanceof COSStream)
{
return ((COSStream) base).toTextString();
}
else
{
return null;
}
}
/**
* This will set the javascript code the will get execute before the import.
*
* @param before A reference to some javascript code.
*/
public void setBefore(String before)
{
dictionary.setItem(COSName.BEFORE, new COSString(before));
}
/**
* This will get the javascript that is executed after the import.
*
* @return Some javascript code.
*/
public String getAfter()
{
COSBase base = dictionary.getDictionaryObject(COSName.AFTER);
if (base instanceof COSString)
{
return ((COSString) base).getString();
}
else if (base instanceof COSStream)
{
return ((COSStream) base).toTextString();
}
else
{
return null;
}
}
/**
* This will set the javascript code the will get execute after the import.
*
* @param after A reference to some javascript code.
*/
public void setAfter(String after)
{
dictionary.setItem(COSName.AFTER, new COSString(after));
}
/**
* Returns the dictionary's "Doc" entry, that is, a map of key value pairs to be added to the document's JavaScript
* name tree.
*
* @return Map of named "JavaScript" dictionaries.
*/
public Map<String, PDActionJavaScript> getDoc()
{<FILL_FUNCTION_BODY>}
/**
* Sets the dictionary's "Doc" entry.
*
* @param map Map of named "JavaScript" dictionaries.
*/
public void setDoc(Map<String, PDActionJavaScript> map)
{
COSArray array = new COSArray();
map.forEach((key, value) ->
{
array.add(new COSString(key));
array.add(value);
});
dictionary.setItem(COSName.DOC, array);
}
}
|
COSArray array = dictionary.getCOSArray(COSName.DOC);
if (array == null)
{
return null;
}
Map<String, PDActionJavaScript> map = new LinkedHashMap<>();
for (int i = 0; i + 1 < array.size(); i += 2)
{
String name = array.getName(i);
if (name != null)
{
COSBase base = array.getObject(i + 1);
if (base instanceof COSDictionary)
{
PDAction action = PDActionFactory.createAction((COSDictionary) base);
if (action instanceof PDActionJavaScript)
{
map.put(name, (PDActionJavaScript) action);
}
}
}
}
return map;
| 842
| 208
| 1,050
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFPage.java
|
FDFPage
|
getPageInfo
|
class FDFPage implements COSObjectable
{
private final COSDictionary page;
/**
* Default constructor.
*/
public FDFPage()
{
page = new COSDictionary();
}
/**
* Constructor.
*
* @param p The FDF page.
*/
public FDFPage(COSDictionary p)
{
page = p;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSDictionary getCOSObject()
{
return page;
}
/**
* This will get a list of FDFTemplage objects that describe the named pages that serve as templates.
*
* @return A list of templates.
*/
public List<FDFTemplate> getTemplates()
{
COSArray array = page.getCOSArray(COSName.TEMPLATES);
if (array != null)
{
List<FDFTemplate> objects = new ArrayList<>(array.size());
for (int i = 0; i < array.size(); i++)
{
objects.add(new FDFTemplate((COSDictionary) array.getObject(i)));
}
return new COSArrayList<>(objects, array);
}
return null;
}
/**
* A list of FDFTemplate objects.
*
* @param templates A list of templates for this Page.
*/
public void setTemplates(List<FDFTemplate> templates)
{
page.setItem(COSName.TEMPLATES, new COSArray(templates));
}
/**
* This will get the FDF page info object.
*
* @return The Page info.
*/
public FDFPageInfo getPageInfo()
{<FILL_FUNCTION_BODY>}
/**
* This will set the page info.
*
* @param info The new page info dictionary.
*/
public void setPageInfo(FDFPageInfo info)
{
page.setItem(COSName.INFO, info);
}
}
|
FDFPageInfo retval = null;
COSDictionary dict = page.getCOSDictionary(COSName.INFO);
if (dict != null)
{
retval = new FDFPageInfo(dict);
}
return retval;
| 565
| 68
| 633
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFTemplate.java
|
FDFTemplate
|
getFields
|
class FDFTemplate implements COSObjectable
{
private final COSDictionary template;
/**
* Default constructor.
*/
public FDFTemplate()
{
template = new COSDictionary();
}
/**
* Constructor.
*
* @param t The FDF page template.
*/
public FDFTemplate(COSDictionary t)
{
template = t;
}
/**
* Convert this standard java object to a COS object.
*
* @return The cos object that matches this Java object.
*/
@Override
public COSDictionary getCOSObject()
{
return template;
}
/**
* This is the template reference.
*
* @return The template reference.
*/
public FDFNamedPageReference getTemplateReference()
{
COSDictionary dict = template.getCOSDictionary(COSName.TREF);
return dict != null ? new FDFNamedPageReference(dict) : null;
}
/**
* This will set the template reference.
*
* @param tRef The template reference.
*/
public void setTemplateReference(FDFNamedPageReference tRef)
{
template.setItem(COSName.TREF, tRef);
}
/**
* This will get a list of fields that are part of this template.
*
* @return A list of fields.
*/
public List<FDFField> getFields()
{<FILL_FUNCTION_BODY>}
/**
* This will set a list of fields for this template.
*
* @param fields The list of fields to set for this template.
*/
public void setFields(List<FDFField> fields)
{
template.setItem(COSName.FIELDS, new COSArray(fields));
}
/**
* A flag telling if the fields imported from the template may be renamed if there are conflicts.
*
* @return A flag telling if the fields can be renamed.
*/
public boolean shouldRename()
{
return template.getBoolean(COSName.RENAME, false);
}
/**
* This will set if the fields can be renamed.
*
* @param value The flag value.
*/
public void setRename(boolean value)
{
template.setBoolean(COSName.RENAME, value);
}
}
|
COSArray array = template.getCOSArray(COSName.FIELDS);
if (array != null)
{
List<FDFField> fields = new ArrayList<>();
for (int i = 0; i < array.size(); i++)
{
fields.add(new FDFField((COSDictionary) array.getObject(i)));
}
return new COSArrayList<>(fields, array);
}
return null;
| 624
| 119
| 743
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fixup/AcroFormDefaultFixup.java
|
AcroFormDefaultFixup
|
apply
|
class AcroFormDefaultFixup extends AbstractFixup
{
public AcroFormDefaultFixup(PDDocument document)
{
super(document);
}
@Override
public void apply() {<FILL_FUNCTION_BODY>}
}
|
new AcroFormDefaultsProcessor(document).process();
/*
* Get the AcroForm in it's current state.
*
* Also note: getAcroForm() applies a default fixup which this processor
* is part of. So keep the null parameter otherwise this will end
* in an endless recursive call
*/
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(null);
// PDFBOX-4985
// build the visual appearance as there is none for the widgets
if (acroForm != null && acroForm.getNeedAppearances())
{
if (acroForm.getFields().isEmpty())
{
new AcroFormOrphanWidgetsProcessor(document).process();
}
// PDFBOX-4985
// build the visual appearance as there is none for the widgets
new AcroFormGenerateAppearancesProcessor(document).process();
}
| 70
| 247
| 317
|
<methods><variables>protected final non-sealed org.apache.pdfbox.pdmodel.PDDocument document
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fixup/processor/AcroFormDefaultsProcessor.java
|
AcroFormDefaultsProcessor
|
verifyOrCreateDefaults
|
class AcroFormDefaultsProcessor extends AbstractProcessor
{
public AcroFormDefaultsProcessor(PDDocument document)
{
super(document);
}
@Override
public void process() {
/*
* Get the AcroForm in it's current state.
*
* Also note: getAcroForm() applies a default fixup which this processor
* is part of. So keep the null parameter otherwise this will end
* in an endless recursive call
*/
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(null);
if (acroForm != null)
{
verifyOrCreateDefaults(acroForm);
}
}
/*
* Verify that there are default entries for required
* properties.
*
* If these are missing create default entries similar to
* Adobe Reader / Adobe Acrobat
*
*/
private void verifyOrCreateDefaults(PDAcroForm acroForm)
{<FILL_FUNCTION_BODY>}
}
|
final String adobeDefaultAppearanceString = "/Helv 0 Tf 0 g ";
// DA entry is required
if (acroForm.getDefaultAppearance().isEmpty())
{
acroForm.setDefaultAppearance(adobeDefaultAppearanceString);
acroForm.getCOSObject().setNeedToBeUpdated(true);
}
// DR entry is required
PDResources defaultResources = acroForm.getDefaultResources();
if (defaultResources == null)
{
defaultResources = new PDResources();
acroForm.setDefaultResources(defaultResources);
acroForm.getCOSObject().setNeedToBeUpdated(true);
}
// PDFBOX-3732: Adobe Acrobat uses Helvetica as a default font and
// stores that under the name '/Helv' in the resources dictionary
// Zapf Dingbats is included per default for check boxes and
// radio buttons as /ZaDb.
// PDFBOX-4393: the two fonts are added by Adobe when signing
// and this breaks a previous signature. (Might be an Adobe bug)
COSDictionary fontDict = defaultResources.getCOSObject().getCOSDictionary(COSName.FONT);
if (fontDict == null)
{
fontDict = new COSDictionary();
defaultResources.getCOSObject().setItem(COSName.FONT, fontDict);
}
if (!fontDict.containsKey(COSName.HELV))
{
defaultResources.put(COSName.HELV, new PDType1Font(FontName.HELVETICA));
defaultResources.getCOSObject().setNeedToBeUpdated(true);
fontDict.setNeedToBeUpdated(true);
}
if (!fontDict.containsKey(COSName.ZA_DB))
{
defaultResources.put(COSName.ZA_DB, new PDType1Font(FontName.ZAPF_DINGBATS));
defaultResources.getCOSObject().setNeedToBeUpdated(true);
fontDict.setNeedToBeUpdated(true);
}
| 304
| 593
| 897
|
<methods><variables>protected final non-sealed org.apache.pdfbox.pdmodel.PDDocument document
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fixup/processor/AcroFormGenerateAppearancesProcessor.java
|
AcroFormGenerateAppearancesProcessor
|
process
|
class AcroFormGenerateAppearancesProcessor extends AbstractProcessor
{
private static final Logger LOG = LogManager.getLogger(AcroFormGenerateAppearancesProcessor.class);
public AcroFormGenerateAppearancesProcessor(PDDocument document)
{
super(document);
}
@Override
public void process() {<FILL_FUNCTION_BODY>}
}
|
/*
* Get the AcroForm in it's current state.
*
* Also note: getAcroForm() applies a default fixup which this processor
* is part of. So keep the null parameter otherwise this will end
* in an endless recursive call
*/
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(null);
if (acroForm != null)
{
try
{
LOG.debug("trying to generate appearance streams for fields as NeedAppearances is true()");
acroForm.refreshAppearances();
acroForm.setNeedAppearances(false);
}
catch (IOException | IllegalArgumentException ex)
{
LOG.debug("couldn't generate appearance stream for some fields - check output");
LOG.debug(ex.getMessage());
}
}
| 107
| 223
| 330
|
<methods><variables>protected final non-sealed org.apache.pdfbox.pdmodel.PDDocument document
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/CIDSystemInfo.java
|
CIDSystemInfo
|
toString
|
class CIDSystemInfo
{
private final String registry;
private final String ordering;
private final int supplement;
public CIDSystemInfo(String registry, String ordering, int supplement)
{
this.registry = registry;
this.ordering = ordering;
this.supplement = supplement;
}
public String getRegistry()
{
return registry;
}
public String getOrdering()
{
return ordering;
}
public int getSupplement()
{
return supplement;
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return getRegistry() + "-" + getOrdering() + "-" + getSupplement();
| 169
| 25
| 194
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/CMapManager.java
|
CMapManager
|
parseCMap
|
class CMapManager
{
private static final Map<String, CMap> CMAP_CACHE = new ConcurrentHashMap<>();
private CMapManager()
{
}
/**
* Fetches the predefined CMap from disk (or cache).
*
* @param cMapName CMap name
* @return The predefined CMap, never null.
* @throws IOException
*/
public static CMap getPredefinedCMap(String cMapName) throws IOException
{
CMap cmap = CMAP_CACHE.get(cMapName);
if (cmap != null)
{
return cmap;
}
CMap targetCmap = new CMapParser().parsePredefined(cMapName);
// limit the cache to predefined CMaps
CMAP_CACHE.put(targetCmap.getName(), targetCmap);
return targetCmap;
}
/**
* Parse the given CMap.
*
* @param randomAccessRead the source of the CMap to be read
* @return the parsed CMap
*/
public static CMap parseCMap(RandomAccessRead randomAccessRead) throws IOException
{<FILL_FUNCTION_BODY>}
}
|
CMap targetCmap = null;
if (randomAccessRead != null)
{
targetCmap = new CMapParser().parse(randomAccessRead);
}
return targetCmap;
| 360
| 61
| 421
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontInfo.java
|
FontInfo
|
getWeightClassAsPanose
|
class FontInfo
{
/**
* Returns the PostScript name of the font.
*
* @return the PostScript name of the font
*/
public abstract String getPostScriptName();
/**
* Returns the font's format.
*
* @return the format of the font
*/
public abstract FontFormat getFormat();
/**
* Returns the CIDSystemInfo associated with the font, if present.
*
* @return the CIDSystemInof of the font if any
*/
public abstract CIDSystemInfo getCIDSystemInfo();
/**
* Returns a new FontBox font instance for the font. Implementors of this method must not cache the return value of
* this method unless doing so via the current {@link FontCache}.
*
* @return a new FontBox instance of the font
*/
public abstract FontBoxFont getFont();
/**
* Returns the sFamilyClass field of the "OS/2" table, or -1.
*
* @return the FamilyClass of the font
*/
public abstract int getFamilyClass();
/**
* Returns the usWeightClass field of the "OS/2" table, or -1.
*
* @return the WeightClass of the font
*/
public abstract int getWeightClass();
/**
* Returns the usWeightClass field as a Panose Weight.
*
* @return the WeightClass of the font as Panose weight
*/
final int getWeightClassAsPanose()
{<FILL_FUNCTION_BODY>}
/**
* Returns the ulCodePageRange1 field of the "OS/2" table, or 0.
*
* @return the CodePageRange1 of the font if present
*/
public abstract int getCodePageRange1();
/**
* Returns the ulCodePageRange2 field of the "OS/2" table, or 0.
*
* @return the CodePageRange2 of the font if present
*/
public abstract int getCodePageRange2();
/**
* Returns the ulCodePageRange1 and ulCodePageRange1 field of the "OS/2" table, or 0.
*
* @return the CodePageRange of the font
*/
final long getCodePageRange()
{
long range1 = getCodePageRange1() & 0x00000000ffffffffL;
long range2 = getCodePageRange2() & 0x00000000ffffffffL;
return range2 << 32 | range1;
}
/**
* Returns the macStyle field of the "head" table, or -1.
*
* @return the MacStyle of the font
*/
public abstract int getMacStyle();
/**
* Returns the Panose classification of the font, if any.
*
* @return the PanoseClassification of the font
*/
public abstract PDPanoseClassification getPanose();
// todo: 'post' table for Italic. Also: OS/2 fsSelection for italic/bold.
// todo: ulUnicodeRange too?
@Override
public String toString()
{
return getPostScriptName() + " (" + getFormat() +
", mac: 0x" + Integer.toHexString(getMacStyle()) +
", os/2: 0x" + Integer.toHexString(getFamilyClass()) +
", cid: " + getCIDSystemInfo() + ")";
}
}
|
int usWeightClass = getWeightClass();
switch (usWeightClass)
{
case -1: return 0;
case 0: return 0;
case 100: return 2;
case 200: return 3;
case 300: return 4;
case 400: return 5;
case 500: return 6;
case 600: return 7;
case 700: return 8;
case 800: return 9;
case 900: return 10;
default: return 0;
}
| 899
| 165
| 1,064
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMappers.java
|
DefaultFontMapper
|
instance
|
class DefaultFontMapper
{
private static final FontMapper INSTANCE = new FontMapperImpl();
}
/**
* Returns the singleton FontMapper instance.
*
* @return a singleton FontMapper instance
*/
public static FontMapper instance()
{<FILL_FUNCTION_BODY>
|
if (instance == null)
{
instance = DefaultFontMapper.INSTANCE;
}
return instance;
| 83
| 33
| 116
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
|
PDCIDSystemInfo
|
toString
|
class PDCIDSystemInfo implements COSObjectable
{
private final COSDictionary dictionary;
PDCIDSystemInfo(String registry, String ordering, int supplement)
{
dictionary = new COSDictionary();
dictionary.setString(COSName.REGISTRY, registry);
dictionary.setString(COSName.ORDERING, ordering);
dictionary.setInt(COSName.SUPPLEMENT, supplement);
}
PDCIDSystemInfo(COSDictionary dictionary)
{
this.dictionary = dictionary;
}
public String getRegistry()
{
return dictionary.getNameAsString(COSName.REGISTRY);
}
public String getOrdering()
{
return dictionary.getNameAsString(COSName.ORDERING);
}
public int getSupplement()
{
return dictionary.getInt(COSName.SUPPLEMENT);
}
@Override
public COSBase getCOSObject()
{
return dictionary;
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return getRegistry() + "-" + getOrdering() + "-" + getSupplement();
| 290
| 25
| 315
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDPanoseClassification.java
|
PDPanoseClassification
|
toString
|
class PDPanoseClassification
{
/**
* Length.
*/
public static final int LENGTH = 10;
private final byte[] bytes;
public PDPanoseClassification(byte[] bytes)
{
this.bytes = bytes;
}
public int getFamilyKind()
{
return bytes[0];
}
public int getSerifStyle()
{
return bytes[1];
}
public int getWeight()
{
return bytes[2];
}
public int getProportion()
{
return bytes[3];
}
public int getContrast()
{
return bytes[4];
}
public int getStrokeVariation()
{
return bytes[5];
}
public int getArmStyle()
{
return bytes[6];
}
public int getLetterform()
{
return bytes[7];
}
public int getMidline()
{
return bytes[8];
}
public int getXHeight()
{
return bytes[9];
}
public byte[] getBytes()
{
return bytes;
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
return "{ FamilyKind = " + getFamilyKind() + ", " +
"SerifStyle = " + getSerifStyle() + ", " +
"Weight = " + getWeight() + ", " +
"Proportion = " + getProportion() + ", " +
"Contrast = " + getContrast() + ", " +
"StrokeVariation = " + getStrokeVariation() + ", " +
"ArmStyle = " + getArmStyle() + ", " +
"Letterform = " + getLetterform() + ", " +
"Midline = " + getMidline() + ", " +
"XHeight = " + getXHeight() + "}";
| 352
| 175
| 527
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java
|
PDTrueTypeFontEmbedder
|
setWidths
|
class PDTrueTypeFontEmbedder extends TrueTypeEmbedder
{
private final Encoding fontEncoding;
/**
* Creates a new TrueType font embedder for the given TTF as a PDTrueTypeFont.
*
* @param document The parent document
* @param dict Font dictionary
* @param ttf TrueType font
* @param encoding The PostScript encoding vector to be used for embedding.
* @throws IOException if the TTF could not be read
*/
PDTrueTypeFontEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf,
Encoding encoding) throws IOException
{
super(document, dict, ttf, false);
dict.setItem(COSName.SUBTYPE, COSName.TRUE_TYPE);
GlyphList glyphList = GlyphList.getAdobeGlyphList();
this.fontEncoding = encoding;
dict.setItem(COSName.ENCODING, encoding.getCOSObject());
fontDescriptor.setSymbolic(false);
fontDescriptor.setNonSymbolic(true);
// add the font descriptor
dict.setItem(COSName.FONT_DESC, fontDescriptor);
// set the glyph widths
setWidths(dict, glyphList);
}
/**
* Sets the glyph widths in the font dictionary.
*/
private void setWidths(COSDictionary font, GlyphList glyphList) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* Returns the font's encoding.
*/
public Encoding getFontEncoding()
{
return fontEncoding;
}
@Override
protected void buildSubset(InputStream ttfSubset, String tag,
Map<Integer, Integer> gidToCid) throws IOException
{
// use PDType0Font instead
throw new UnsupportedOperationException();
}
}
|
float scaling = 1000f / ttf.getHeader().getUnitsPerEm();
HorizontalMetricsTable hmtx = ttf.getHorizontalMetrics();
Map<Integer, String> codeToName = getFontEncoding().getCodeToNameMap();
int firstChar = Collections.min(codeToName.keySet());
int lastChar = Collections.max(codeToName.keySet());
List<Integer> widths = new ArrayList<>(lastChar - firstChar + 1);
for (int i = 0; i < lastChar - firstChar + 1; i++)
{
widths.add(0);
}
// a character code is mapped to a glyph name via the provided font encoding
// afterwards, the glyph name is translated to a glyph ID.
for (Map.Entry<Integer, String> entry : codeToName.entrySet())
{
int code = entry.getKey();
String name = entry.getValue();
if (code >= firstChar && code <= lastChar)
{
String uni = glyphList.toUnicode(name);
int charCode = uni.codePointAt(0);
int gid = cmapLookup.getGlyphId(charCode);
widths.set(entry.getKey() - firstChar,
Math.round(hmtx.getAdvanceWidth(gid) * scaling));
}
}
font.setInt(COSName.FIRST_CHAR, firstChar);
font.setInt(COSName.LAST_CHAR, lastChar);
font.setItem(COSName.WIDTHS, COSArray.ofCOSIntegers(widths));
| 540
| 455
| 995
|
<methods>public void addGlyphIds(Set<java.lang.Integer>) ,public void addToSubset(int) ,public final void buildFontFile2(java.io.InputStream) throws java.io.IOException,public org.apache.pdfbox.pdmodel.font.PDFontDescriptor getFontDescriptor() ,public java.lang.String getTag(Map<java.lang.Integer,java.lang.Integer>) ,public boolean needsSubset() ,public void subset() throws java.io.IOException<variables>private static final java.lang.String BASE25,private static final int ITALIC,private static final int OBLIQUE,private final Set<java.lang.Integer> allGlyphIds,protected final non-sealed org.apache.fontbox.ttf.CmapLookup cmapLookup,private final non-sealed org.apache.pdfbox.pdmodel.PDDocument document,private final non-sealed boolean embedSubset,protected org.apache.pdfbox.pdmodel.font.PDFontDescriptor fontDescriptor,private final Set<java.lang.Integer> subsetCodePoints,protected org.apache.fontbox.ttf.TrueTypeFont ttf
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1FontEmbedder.java
|
PDType1FontEmbedder
|
buildFontDescriptor
|
class PDType1FontEmbedder
{
private final Encoding fontEncoding;
private final Type1Font type1;
/**
* This will load a PFB to be embedded into a document.
*
* @param doc The PDF document that will hold the embedded font.
* @param dict The Font dictionary to write to.
* @param pfbStream The pfb input.
* @throws IOException If there is an error loading the data.
*/
PDType1FontEmbedder(PDDocument doc, COSDictionary dict, InputStream pfbStream,
Encoding encoding) throws IOException
{
dict.setItem(COSName.SUBTYPE, COSName.TYPE1);
// read the pfb
byte[] pfbBytes = pfbStream.readAllBytes();
PfbParser pfbParser = new PfbParser(pfbBytes);
type1 = Type1Font.createWithPFB(pfbBytes);
if (encoding == null)
{
fontEncoding = Type1Encoding.fromFontBox(type1.getEncoding());
}
else
{
fontEncoding = encoding;
}
// build font descriptor
PDFontDescriptor fd = buildFontDescriptor(type1);
PDStream fontStream = new PDStream(doc, pfbParser.getInputStream(), COSName.FLATE_DECODE);
fontStream.getCOSObject().setInt("Length", pfbParser.size());
for (int i = 0; i < pfbParser.getLengths().length; i++)
{
fontStream.getCOSObject().setInt("Length" + (i + 1), pfbParser.getLengths()[i]);
}
fd.setFontFile(fontStream);
// set the values
dict.setItem(COSName.FONT_DESC, fd);
dict.setName(COSName.BASE_FONT, type1.getName());
// widths
List<Integer> widths = new ArrayList<>(256);
for (int code = 0; code <= 255; code++)
{
String name = fontEncoding.getName(code);
int width = Math.round(type1.getWidth(name));
widths.add(width);
}
dict.setInt(COSName.FIRST_CHAR, 0);
dict.setInt(COSName.LAST_CHAR, 255);
dict.setItem(COSName.WIDTHS, COSArray.ofCOSIntegers(widths));
dict.setItem(COSName.ENCODING, encoding);
}
/**
* Returns a PDFontDescriptor for the given PFB.
*
* @throws IOException if the font bounding box isn't available
*/
static PDFontDescriptor buildFontDescriptor(Type1Font type1) throws IOException
{
boolean isSymbolic = type1.getEncoding() instanceof BuiltInEncoding;
BoundingBox bbox = type1.getFontBBox();
PDFontDescriptor fd = new PDFontDescriptor();
fd.setFontName(type1.getName());
fd.setFontFamily(type1.getFamilyName());
fd.setNonSymbolic(!isSymbolic);
fd.setSymbolic(isSymbolic);
fd.setFontBoundingBox(new PDRectangle(bbox));
fd.setItalicAngle(type1.getItalicAngle());
fd.setAscent(bbox.getUpperRightY());
fd.setDescent(bbox.getLowerLeftY());
fd.setCapHeight(type1.getBlueValues().get(2).floatValue());
fd.setStemV(0); // for PDF/A
return fd;
}
/**
* Returns a PDFontDescriptor for the given AFM. Used only for Standard 14 fonts.
*
* @param metrics AFM
*/
static PDFontDescriptor buildFontDescriptor(FontMetrics metrics)
{<FILL_FUNCTION_BODY>}
/**
* Returns the font's encoding.
*/
public Encoding getFontEncoding()
{
return fontEncoding;
}
/**
* Returns the font's glyph list.
*/
public GlyphList getGlyphList()
{
return GlyphList.getAdobeGlyphList();
}
/**
* Returns the Type 1 font.
*/
public Type1Font getType1Font()
{
return type1;
}
}
|
boolean isSymbolic = metrics.getEncodingScheme().equals("FontSpecific");
PDFontDescriptor fd = new PDFontDescriptor();
fd.setFontName(metrics.getFontName());
fd.setFontFamily(metrics.getFamilyName());
fd.setNonSymbolic(!isSymbolic);
fd.setSymbolic(isSymbolic);
fd.setFontBoundingBox(new PDRectangle(metrics.getFontBBox()));
fd.setItalicAngle(metrics.getItalicAngle());
fd.setAscent(metrics.getAscender());
fd.setDescent(metrics.getDescender());
fd.setCapHeight(metrics.getCapHeight());
fd.setXHeight(metrics.getXHeight());
fd.setAverageWidth(metrics.getAverageCharacterWidth());
fd.setCharacterSet(metrics.getCharacterSet());
fd.setStemV(0); // for PDF/A
return fd;
| 1,275
| 285
| 1,560
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java
|
PDType3CharProc
|
getGlyphBBox
|
class PDType3CharProc implements COSObjectable, PDContentStream
{
private static final Logger LOG = LogManager.getLogger(PDType3CharProc.class);
private final PDType3Font font;
private final COSStream charStream;
public PDType3CharProc(PDType3Font font, COSStream charStream)
{
this.font = font;
this.charStream = charStream;
}
@Override
public COSStream getCOSObject()
{
return charStream;
}
public PDType3Font getFont()
{
return font;
}
public PDStream getContentStream()
{
return new PDStream(charStream);
}
@Override
public InputStream getContents() throws IOException
{
return new RandomAccessInputStream(getContentsForRandomAccess());
}
@Override
public RandomAccessRead getContentsForRandomAccess() throws IOException
{
return charStream.createView();
}
@Override
public PDResources getResources()
{
if (charStream.containsKey(COSName.RESOURCES))
{
// PDFBOX-5294
LOG.warn("Using resources dictionary found in charproc entry");
LOG.warn("This should have been in the font or in the page dictionary");
return new PDResources((COSDictionary) charStream.getDictionaryObject(COSName.RESOURCES));
}
return font.getResources();
}
@Override
public PDRectangle getBBox()
{
return font.getFontBBox();
}
/**
* Calculate the bounding box of this glyph. This will work only if the first operator in the
* stream is d1.
*
* @return the bounding box of this glyph, or null if the first operator is not d1.
* @throws IOException If an io error occurs while parsing the stream.
*/
public PDRectangle getGlyphBBox() throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public Matrix getMatrix()
{
return font.getFontMatrix();
}
/**
* Get the width from a type3 charproc stream.
*
* @return the glyph width.
* @throws IOException if the stream could not be read, or did not have d0 or d1 as first
* operator, or if their first argument was not a number.
*/
public float getWidth() throws IOException
{
List<COSBase> arguments = new ArrayList<>();
PDFStreamParser parser = new PDFStreamParser(this);
Object token = parser.parseNextToken();
while (token != null)
{
if (token instanceof Operator)
{
return parseWidth((Operator) token, arguments);
}
else
{
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
throw new IOException("Unexpected end of stream");
}
private float parseWidth(Operator operator, List<COSBase> arguments) throws IOException
{
if (operator.getName().equals("d0") || operator.getName().equals("d1"))
{
COSBase obj = arguments.get(0);
if (obj instanceof COSNumber)
{
return ((COSNumber) obj).floatValue();
}
throw new IOException("Unexpected argument type: " + obj.getClass().getName());
}
else
{
throw new IOException("First operator must be d0 or d1");
}
}
}
|
List<COSBase> arguments = new ArrayList<>();
PDFStreamParser parser = new PDFStreamParser(this);
Object token = parser.parseNextToken();
while (token != null)
{
if (token instanceof Operator)
{
if (((Operator) token).getName().equals("d1") && arguments.size() == 6)
{
for (int i = 0; i < 6; ++i)
{
if (!(arguments.get(i) instanceof COSNumber))
{
return null;
}
}
float x = ((COSNumber) arguments.get(2)).floatValue();
float y = ((COSNumber) arguments.get(3)).floatValue();
return new PDRectangle(
x,
y,
((COSNumber) arguments.get(4)).floatValue() - x,
((COSNumber) arguments.get(5)).floatValue() - y);
}
else
{
return null;
}
}
else
{
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
return null;
| 923
| 294
| 1,217
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ToUnicodeWriter.java
|
ToUnicodeWriter
|
allowCodeRange
|
class ToUnicodeWriter
{
private final Map<Integer, String> cidToUnicode = new TreeMap<>();
private int wMode;
/**
* To test corner case of PDFBOX-4302.
*/
static final int MAX_ENTRIES_PER_OPERATOR = 100;
/**
* Creates a new ToUnicode CMap writer.
*/
ToUnicodeWriter()
{
this.wMode = 0;
}
/**
* Sets the WMode (writing mode) of this CMap.
*
* @param wMode 1 for vertical, 0 for horizontal (default)
*/
public void setWMode(int wMode)
{
this.wMode = wMode;
}
/**
* Adds the given CID to Unicode mapping.
*
* @param cid CID
* @param text Unicode text, up to 512 bytes.
*/
public void add(int cid, String text)
{
if (cid < 0 || cid > 0xFFFF)
{
throw new IllegalArgumentException("CID is not valid");
}
if (text == null || text.isEmpty())
{
throw new IllegalArgumentException("Text is null or empty");
}
cidToUnicode.put(cid, text);
}
/**
* Writes the CMap as ASCII to the given output stream.
*
* @param out ASCII output stream
* @throws IOException if the stream could not be written
*/
public void writeTo(OutputStream out) throws IOException
{
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.US_ASCII));
writeLine(writer, "/CIDInit /ProcSet findresource begin");
writeLine(writer, "12 dict begin\n");
writeLine(writer, "begincmap");
writeLine(writer, "/CIDSystemInfo");
writeLine(writer, "<< /Registry (Adobe)");
writeLine(writer, "/Ordering (UCS)");
writeLine(writer, "/Supplement 0");
writeLine(writer, ">> def\n");
writeLine(writer, "/CMapName /Adobe-Identity-UCS" + " def");
writeLine(writer, "/CMapType 2 def\n"); // 2 = ToUnicode
if (wMode != 0)
{
writeLine(writer, "/WMode /" + wMode + " def");
}
// ToUnicode always uses 16-bit CIDs
writeLine(writer, "1 begincodespacerange");
writeLine(writer, "<0000> <FFFF>");
writeLine(writer, "endcodespacerange\n");
// CID -> Unicode mappings, we use ranges to generate a smaller CMap
List<Integer> srcFrom = new ArrayList<>();
List<Integer> srcTo = new ArrayList<>();
List<String> dstString = new ArrayList<>();
Map.Entry<Integer, String> prev = null;
for (Map.Entry<Integer, String> next : cidToUnicode.entrySet())
{
if (allowCIDToUnicodeRange(prev, next))
{
// extend range
srcTo.set(srcTo.size() - 1, next.getKey());
}
else
{
// begin range
srcFrom.add(next.getKey());
srcTo.add(next.getKey());
dstString.add(next.getValue());
}
prev = next;
}
// limit entries per operator
int batchCount = (int) Math.ceil(srcFrom.size() /
(double) MAX_ENTRIES_PER_OPERATOR);
for (int batch = 0; batch < batchCount; batch++)
{
int count = batch == batchCount - 1 ?
srcFrom.size() - MAX_ENTRIES_PER_OPERATOR * batch :
MAX_ENTRIES_PER_OPERATOR;
writer.write(count + " beginbfrange\n");
for (int j = 0; j < count; j++)
{
int index = batch * MAX_ENTRIES_PER_OPERATOR + j;
writer.write('<');
writer.write(Hex.getChars(srcFrom.get(index).shortValue()));
writer.write("> ");
writer.write('<');
writer.write(Hex.getChars(srcTo.get(index).shortValue()));
writer.write("> ");
writer.write('<');
writer.write(Hex.getCharsUTF16BE(dstString.get(index)));
writer.write(">\n");
}
writeLine(writer, "endbfrange\n");
}
// footer
writeLine(writer, "endcmap");
writeLine(writer, "CMapName currentdict /CMap defineresource pop");
writeLine(writer, "end");
writeLine(writer, "end");
writer.flush();
}
private void writeLine(BufferedWriter writer, String text) throws IOException
{
writer.write(text);
writer.write('\n');
}
// allowCIDToUnicodeRange returns true if the CID and Unicode destination string are allowed to follow one another
// according to the Adobe 1.7 specification as described in Section 5.9, Example 5.16.
static boolean allowCIDToUnicodeRange(Map.Entry<Integer, String> prev,
Map.Entry<Integer, String> next)
{
if (prev == null || next == null)
{
return false;
}
return allowCodeRange(prev.getKey(), next.getKey())
&& allowDestinationRange(prev.getValue(), next.getValue());
}
// allowCodeRange returns true if the 16-bit values are sequential and differ only in the low-order byte.
static boolean allowCodeRange(int prev, int next)
{<FILL_FUNCTION_BODY>}
// allowDestinationRange returns true if the code points represented by the strings are sequential and differ
// only in the low-order byte.
static boolean allowDestinationRange(String prev, String next)
{
if (prev.isEmpty() || next.isEmpty())
{
return false;
}
int prevCode = prev.codePointAt(0);
int nextCode = next.codePointAt(0);
// Allow the new destination string if:
// 1. It is sequential with the previous one and differs only in the low-order byte
// 2. The previous string does not contain any UTF-16 surrogates
return allowCodeRange(prevCode, nextCode) && prev.codePointCount(0, prev.length()) == 1;
}
}
|
if ((prev + 1) != next)
{
return false;
}
int prevH = (prev >> 8) & 0xFF;
int prevL = prev & 0xFF;
int nextH = (next >> 8) & 0xFF;
int nextL = next & 0xFF;
return prevH == nextH && prevL < nextL;
| 1,749
| 104
| 1,853
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/UniUtil.java
|
UniUtil
|
getUniNameOfCodePoint
|
class UniUtil
{
private UniUtil()
{
}
// faster than String.format("uni%04X", codePoint)
static String getUniNameOfCodePoint(int codePoint)
{<FILL_FUNCTION_BODY>}
}
|
String hex = Integer.toString(codePoint, 16).toUpperCase(Locale.US);
switch (hex.length())
{
case 1:
return "uni000" + hex;
case 2:
return "uni00" + hex;
case 3:
return "uni0" + hex;
default:
return "uni" + hex;
}
| 72
| 107
| 179
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java
|
DictionaryEncoding
|
getEncodingName
|
class DictionaryEncoding extends Encoding
{
private final COSDictionary encoding;
private final Encoding baseEncoding;
private final Map<Integer, String> differences = new HashMap<>();
/**
* Creates a new DictionaryEncoding for embedding.
*
* @param baseEncoding the base encoding of this encoding
* @param differences the differences of this encoding with regard to the base encoding
*/
public DictionaryEncoding(COSName baseEncoding, COSArray differences)
{
encoding = new COSDictionary();
encoding.setItem(COSName.NAME, COSName.ENCODING);
encoding.setItem(COSName.DIFFERENCES, differences);
if (baseEncoding != COSName.STANDARD_ENCODING)
{
encoding.setItem(COSName.BASE_ENCODING, baseEncoding);
this.baseEncoding = Encoding.getInstance(baseEncoding);
}
else
{
this.baseEncoding = Encoding.getInstance(baseEncoding);
}
if (this.baseEncoding == null)
{
throw new IllegalArgumentException("Invalid encoding: " + baseEncoding);
}
codeToName.putAll(this.baseEncoding.codeToName);
inverted.putAll(this.baseEncoding.inverted);
applyDifferences();
}
/**
* Creates a new DictionaryEncoding for a Type 3 font from a PDF.
*
* @param fontEncoding The Type 3 encoding dictionary.
*/
public DictionaryEncoding(COSDictionary fontEncoding)
{
encoding = fontEncoding;
baseEncoding = null;
applyDifferences();
}
/**
* Creates a new DictionaryEncoding from a PDF.
*
* @param fontEncoding The encoding dictionary.
* @param isNonSymbolic True if the font is non-symbolic. False for Type 3 fonts.
* @param builtIn The font's built-in encoding. Null for Type 3 fonts.
*/
public DictionaryEncoding(COSDictionary fontEncoding, boolean isNonSymbolic, Encoding builtIn)
{
encoding = fontEncoding;
Encoding base = null;
boolean hasBaseEncoding = encoding.containsKey(COSName.BASE_ENCODING);
if (hasBaseEncoding)
{
COSName name = encoding.getCOSName(COSName.BASE_ENCODING);
base = Encoding.getInstance(name); // null when the name is invalid
}
if (base == null)
{
if (isNonSymbolic)
{
// Otherwise, for a nonsymbolic font, it is StandardEncoding
base = StandardEncoding.INSTANCE;
}
else
{
// and for a symbolic font, it is the font's built-in encoding.
if (builtIn != null)
{
base = builtIn;
}
else
{
// triggering this error indicates a bug in PDFBox. Every font should always have
// a built-in encoding, if not, we parsed it incorrectly.
throw new IllegalArgumentException("Symbolic fonts must have a built-in " +
"encoding");
}
}
}
baseEncoding = base;
codeToName.putAll(baseEncoding.codeToName);
inverted.putAll(baseEncoding.inverted);
applyDifferences();
}
private void applyDifferences()
{
// now replace with the differences
COSArray diffArray = encoding.getCOSArray(COSName.DIFFERENCES);
if (diffArray == null)
{
return;
}
int currentIndex = -1;
for (int i = 0; i < diffArray.size(); i++)
{
COSBase next = diffArray.getObject(i);
if( next instanceof COSNumber)
{
currentIndex = ((COSNumber)next).intValue();
}
else if( next instanceof COSName )
{
COSName name = (COSName)next;
overwrite(currentIndex, name.getName());
this.differences.put(currentIndex, name.getName());
currentIndex++;
}
}
}
/**
* Returns the base encoding. Will be null for Type 3 fonts.
*
* @return the base encoding or null
*/
public Encoding getBaseEncoding()
{
return baseEncoding;
}
/**
* Returns the Differences array.
*
* @return a map containing all differences
*/
public Map<Integer, String> getDifferences()
{
return differences;
}
@Override
public COSBase getCOSObject()
{
return encoding;
}
@Override
public String getEncodingName()
{<FILL_FUNCTION_BODY>}
}
|
if (baseEncoding == null)
{
// In type 3 the /Differences array shall specify the complete character encoding
return "differences";
}
return baseEncoding.getEncodingName() + " with differences";
| 1,224
| 58
| 1,282
|
<methods>public non-sealed void <init>() ,public boolean contains(java.lang.String) ,public boolean contains(int) ,public Map<java.lang.Integer,java.lang.String> getCodeToNameMap() ,public abstract java.lang.String getEncodingName() ,public static org.apache.pdfbox.pdmodel.font.encoding.Encoding getInstance(org.apache.pdfbox.cos.COSName) ,public java.lang.String getName(int) ,public Map<java.lang.String,java.lang.Integer> getNameToCodeMap() <variables>protected static final int CHAR_CODE,protected static final int CHAR_NAME,protected final Map<java.lang.Integer,java.lang.String> codeToName,protected final Map<java.lang.String,java.lang.Integer> inverted
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java
|
Encoding
|
overwrite
|
class Encoding implements COSObjectable
{
protected static final int CHAR_CODE = 0;
protected static final int CHAR_NAME = 1;
/**
* This will get an encoding by name. May return null.
*
* @param name The name of the encoding to get.
* @return The encoding that matches the name.
*/
public static Encoding getInstance(COSName name)
{
if (COSName.STANDARD_ENCODING.equals(name))
{
return StandardEncoding.INSTANCE;
}
else if (COSName.WIN_ANSI_ENCODING.equals(name))
{
return WinAnsiEncoding.INSTANCE;
}
else if (COSName.MAC_ROMAN_ENCODING.equals(name))
{
return MacRomanEncoding.INSTANCE;
}
else if (COSName.MAC_EXPERT_ENCODING.equals(name))
{
return MacExpertEncoding.INSTANCE;
}
else
{
return null;
}
}
/**
* code-to-name map. Derived classes should not modify the map after class construction.
*/
protected final Map<Integer, String> codeToName = new HashMap<>(250);
/**
* name-to-code map. Derived classes should not modify the map after class construction.
*/
protected final Map<String, Integer> inverted = new HashMap<>(250);
/**
* Returns an unmodifiable view of the code -> name mapping.
*
* @return the code -> name map
*/
public Map<Integer, String> getCodeToNameMap()
{
return Collections.unmodifiableMap(codeToName);
}
/**
* Returns an unmodifiable view of the name -> code mapping. More than one name may map to
* the same code.
*
* @return the name -> code map
*/
public Map<String, Integer> getNameToCodeMap()
{
return Collections.unmodifiableMap(inverted);
}
/**
* This will add a character encoding. An already existing mapping is preserved when creating
* the reverse mapping. Should only be used during construction of the class.
*
* @see #overwrite(int, String)
*
* @param code character code
* @param name PostScript glyph name
*/
protected void add(int code, String name)
{
codeToName.put(code, name);
inverted.putIfAbsent(name, code);
}
/**
* This will add a character encoding. An already existing mapping is overwritten when creating
* the reverse mapping. Should only be used during construction of the class.
*
* @see Encoding#add(int, String)
*
* @param code character code
* @param name PostScript glyph name
*/
protected void overwrite(int code, String name)
{<FILL_FUNCTION_BODY>}
/**
* Determines if the encoding has a mapping for the given name value.
*
* @param name PostScript glyph name
* @return true if the encoding has a mapping for the given name value
*/
public boolean contains(String name)
{
return inverted.containsKey(name);
}
/**
* Determines if the encoding has a mapping for the given code value.
*
* @param code character code
* @return if the encoding has a mapping for the given code value
*
*/
public boolean contains(int code)
{
return codeToName.containsKey(code);
}
/**
* This will take a character code and get the name from the code.
*
* @param code character code
* @return PostScript glyph name
*/
public String getName(int code)
{
return codeToName.getOrDefault(code, ".notdef");
}
/**
* Returns the name of this encoding.
*
* @return the name of the encoding
*/
public abstract String getEncodingName();
}
|
// remove existing reverse mapping first
String oldName = codeToName.get(code);
if (oldName != null)
{
Integer oldCode = inverted.get(oldName);
if (oldCode != null && oldCode == code)
{
inverted.remove(oldName);
}
}
inverted.put(name, code);
codeToName.put(code, name);
| 1,072
| 109
| 1,181
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Type1Encoding.java
|
Type1Encoding
|
fromFontBox
|
class Type1Encoding extends Encoding
{
/**
* Creates an encoding from the given FontBox encoding.
*
* @param encoding FontBox encoding
* @return the encoding created from the given FontBox encoding
*/
public static Type1Encoding fromFontBox(org.apache.fontbox.encoding.Encoding encoding)
{<FILL_FUNCTION_BODY>}
/**
* Creates an empty encoding.
*/
public Type1Encoding()
{
}
/**
* Creates an encoding from the given AFM font metrics.
*
* @param fontMetrics AFM font metrics.
*/
public Type1Encoding(FontMetrics fontMetrics)
{
for (CharMetric nextMetric : fontMetrics.getCharMetrics())
{
add(nextMetric.getCharacterCode(), nextMetric.getName());
}
}
@Override
public COSBase getCOSObject()
{
return null;
}
@Override
public String getEncodingName()
{
return "built-in (Type 1)";
}
}
|
// todo: could optimise this by looking for specific subclasses
Map<Integer,String> codeToName = encoding.getCodeToNameMap();
Type1Encoding enc = new Type1Encoding();
codeToName.forEach(enc::add);
return enc;
| 281
| 67
| 348
|
<methods>public non-sealed void <init>() ,public boolean contains(java.lang.String) ,public boolean contains(int) ,public Map<java.lang.Integer,java.lang.String> getCodeToNameMap() ,public abstract java.lang.String getEncodingName() ,public static org.apache.pdfbox.pdmodel.font.encoding.Encoding getInstance(org.apache.pdfbox.cos.COSName) ,public java.lang.String getName(int) ,public Map<java.lang.String,java.lang.Integer> getNameToCodeMap() <variables>protected static final int CHAR_CODE,protected static final int CHAR_NAME,protected final Map<java.lang.Integer,java.lang.String> codeToName,protected final Map<java.lang.String,java.lang.Integer> inverted
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDFontSetting.java
|
PDFontSetting
|
getFont
|
class PDFontSetting implements COSObjectable
{
private COSArray fontSetting = null;
/**
* Creates a blank font setting, font will be null, size will be 1.
*/
public PDFontSetting()
{
fontSetting = new COSArray();
fontSetting.add( null );
fontSetting.add( new COSFloat( 1 ) );
}
/**
* Constructs a font setting from an existing array.
*
* @param fs The new font setting value.
*/
public PDFontSetting( COSArray fs )
{
fontSetting = fs;
}
/**
* {@inheritDoc}
*/
@Override
public COSBase getCOSObject()
{
return fontSetting;
}
/**
* This will get the font for this font setting.
*
* @return The font for this setting of null if one was not found.
*
* @throws IOException If there is an error getting the font.
*/
public PDFont getFont() throws IOException
{<FILL_FUNCTION_BODY>}
/**
* This will set the font for this font setting.
*
* @param font The new font.
*/
public void setFont( PDFont font )
{
fontSetting.set( 0, font );
}
/**
* This will get the size of the font.
*
* @return The size of the font.
*/
public float getFontSize()
{
COSNumber size = (COSNumber)fontSetting.get( 1 );
return size.floatValue();
}
/**
* This will set the size of the font.
*
* @param size The new size of the font.
*/
public void setFontSize( float size )
{
fontSetting.set( 1, new COSFloat( size ) );
}
}
|
PDFont retval = null;
COSBase font = fontSetting.getObject(0);
if( font instanceof COSDictionary )
{
retval = PDFontFactory.createFont( (COSDictionary)font );
}
return retval;
| 493
| 68
| 561
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDLineDashPattern.java
|
PDLineDashPattern
|
getCOSObject
|
class PDLineDashPattern implements COSObjectable
{
private final int phase;
private final float[] array;
/**
* Creates a new line dash pattern, with no dashes and a phase of 0.
*/
public PDLineDashPattern()
{
array = new float[] { };
phase = 0;
}
/**
* Creates a new line dash pattern from a dash array and phase.
* @param array the dash array
* @param phase the phase
*/
public PDLineDashPattern(COSArray array, int phase)
{
this.array = array.toFloatArray();
// PDF 2.0 specification, 8.4.3.6 Line dash pattern:
// "If the dash phase is negative, it shall be incremented by twice the sum of all
// lengths in the dash array until it is positive"
if (phase < 0)
{
float sum2 = 0;
for (float f : this.array)
{
sum2 += f;
}
sum2 *= 2;
if (sum2 > 0)
{
phase += (-phase < sum2) ? sum2 : (Math.floor(-phase / sum2) + 1) * sum2;
}
else
{
phase = 0;
}
}
this.phase = phase;
}
@Override
public COSBase getCOSObject()
{<FILL_FUNCTION_BODY>}
/**
* Returns the dash phase.
* This specifies the distance into the dash pattern at which to start the dash.
* @return the dash phase
*/
public int getPhase()
{
return phase;
}
/**
* Returns the dash array.
* @return the dash array, never null.
*/
public float[] getDashArray()
{
return array.clone();
}
@Override
public String toString()
{
return "PDLineDashPattern{array=" + Arrays.toString(array) + ", phase=" + phase + "}";
}
}
|
COSArray cos = new COSArray();
cos.add(COSArray.of(array));
cos.add(COSInteger.get(phase));
return cos;
| 541
| 48
| 589
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDXObject.java
|
PDXObject
|
createXObject
|
class PDXObject implements COSObjectable
{
private final PDStream stream;
/**
* Creates a new XObject instance of the appropriate type for the COS stream.
*
* @param base The stream which is wrapped by this XObject.
* @param resources the resources of this XObject
* @return A new XObject instance.
* @throws java.io.IOException if there is an error creating the XObject.
*/
public static PDXObject createXObject(COSBase base, PDResources resources) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* Creates a new XObject from the given stream and subtype.
*
* @param stream The stream to read.
* @param subtype the subtype to be used for this XObject
*/
protected PDXObject(COSStream stream, COSName subtype)
{
this.stream = new PDStream(stream);
// could be used for writing:
stream.setName(COSName.TYPE, COSName.XOBJECT.getName());
stream.setName(COSName.SUBTYPE, subtype.getName());
}
/**
* Creates a new XObject from the given stream and subtype.
*
* @param stream The stream to read.
* @param subtype the subtype to be used for this XObject
*/
protected PDXObject(PDStream stream, COSName subtype)
{
this.stream = stream;
// could be used for writing:
stream.getCOSObject().setName(COSName.TYPE, COSName.XOBJECT.getName());
stream.getCOSObject().setName(COSName.SUBTYPE, subtype.getName());
}
/**
* Creates a new XObject of the given subtype for writing.
* @param document The document in which to create the XObject.
* @param subtype The subtype of the new XObject.
*/
protected PDXObject(PDDocument document, COSName subtype)
{
stream = new PDStream(document);
stream.getCOSObject().setName(COSName.TYPE, COSName.XOBJECT.getName());
stream.getCOSObject().setName(COSName.SUBTYPE, subtype.getName());
}
/**
* Returns the stream.
* {@inheritDoc}
*/
@Override
public final COSStream getCOSObject()
{
return stream.getCOSObject();
}
/**
* Returns the stream.
* @return The stream for this object.
*/
public final PDStream getStream()
{
return stream;
}
}
|
if (base == null)
{
// TODO throw an exception?
return null;
}
if (!(base instanceof COSStream))
{
throw new IOException("Unexpected object type: " + base.getClass().getName());
}
COSStream stream = (COSStream)base;
String subtype = stream.getNameAsString(COSName.SUBTYPE);
if (COSName.IMAGE.getName().equals(subtype))
{
return new PDImageXObject(new PDStream(stream), resources);
}
else if (COSName.FORM.getName().equals(subtype))
{
ResourceCache cache = resources != null ? resources.getResourceCache() : null;
COSDictionary group = stream.getCOSDictionary(COSName.GROUP);
if (group != null && COSName.TRANSPARENCY.equals(group.getCOSName(COSName.S)))
{
return new PDTransparencyGroup(stream, cache);
}
return new PDFormXObject(stream, cache);
}
else if (COSName.PS.getName().equals(subtype))
{
return new PDPostScriptXObject(stream);
}
else
{
throw new IOException("Invalid XObject Subtype: " + subtype);
}
| 762
| 380
| 1,142
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCIEBasedColorSpace.java
|
PDCIEBasedColorSpace
|
toRGBImage
|
class PDCIEBasedColorSpace extends PDColorSpace
{
//
// WARNING: this method is performance sensitive, modify with care!
//
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public BufferedImage toRawImage(WritableRaster raster) throws IOException
{
// There is no direct equivalent of a CIE colorspace in Java. So we can
// not do anything here.
return null;
}
@Override
public String toString()
{
return getName(); // TODO return more info
}
}
|
// This method calls toRGB to convert images one pixel at a time. For matrix-based
// CIE color spaces this is fast enough. However, it should not be used with any
// color space which uses an ICC Profile as it will be far too slow.
int width = raster.getWidth();
int height = raster.getHeight();
BufferedImage rgbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster rgbRaster = rgbImage.getRaster();
// always three components: ABC
float[] abc = new float[3];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
raster.getPixel(x, y, abc);
// 0..255 -> 0..1
abc[0] /= 255;
abc[1] /= 255;
abc[2] /= 255;
float[] rgb = toRGB(abc);
// 0..1 -> 0..255
rgb[0] *= 255;
rgb[1] *= 255;
rgb[2] *= 255;
rgbRaster.setPixel(x, y, rgb);
}
}
return rgbImage;
| 171
| 365
| 536
|
<methods>public non-sealed void <init>() ,public static org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace create(org.apache.pdfbox.cos.COSBase) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace create(org.apache.pdfbox.cos.COSBase, org.apache.pdfbox.pdmodel.PDResources) throws java.io.IOException,public static org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace create(org.apache.pdfbox.cos.COSBase, org.apache.pdfbox.pdmodel.PDResources, boolean) throws java.io.IOException,public org.apache.pdfbox.cos.COSBase getCOSObject() ,public abstract float[] getDefaultDecode(int) ,public abstract org.apache.pdfbox.pdmodel.graphics.color.PDColor getInitialColor() ,public abstract java.lang.String getName() ,public abstract int getNumberOfComponents() ,public abstract float[] toRGB(float[]) throws java.io.IOException,public abstract java.awt.image.BufferedImage toRGBImage(java.awt.image.WritableRaster) throws java.io.IOException,public abstract java.awt.image.BufferedImage toRawImage(java.awt.image.WritableRaster) throws java.io.IOException<variables>protected org.apache.pdfbox.cos.COSArray array,private final java.awt.image.ColorConvertOp colorConvertOp
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCIEDictionaryBasedColorSpace.java
|
PDCIEDictionaryBasedColorSpace
|
convXYZtoRGB
|
class PDCIEDictionaryBasedColorSpace extends PDCIEBasedColorSpace
{
protected final COSDictionary dictionary;
private static final ColorSpace CIEXYZ = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
// we need to cache whitepoint values, because using getWhitePoint()
// would create a new default object for each pixel conversion if the original
// PDF didn't have a whitepoint array
protected float wpX = 1;
protected float wpY = 1;
protected float wpZ = 1;
protected PDCIEDictionaryBasedColorSpace(COSName cosName)
{
array = new COSArray();
dictionary = new COSDictionary();
array.add(cosName);
array.add(dictionary);
fillWhitepointCache(getWhitepoint());
}
/**
* Creates a new CalRGB color space using the given COS array.
*
* @param rgb the cos array which represents this color space
*/
protected PDCIEDictionaryBasedColorSpace(COSArray rgb)
{
array = rgb;
dictionary = (COSDictionary) array.getObject(1);
fillWhitepointCache(getWhitepoint());
}
/**
* Tests if the current point is the white point.
*
* @return true if the current point is the white point.
*/
protected boolean isWhitePoint()
{
return Float.compare(wpX, 1) == 0 &&
Float.compare(wpY, 1) == 0 &&
Float.compare(wpZ, 1) == 0;
}
private void fillWhitepointCache(PDTristimulus whitepoint)
{
wpX = whitepoint.getX();
wpY = whitepoint.getY();
wpZ = whitepoint.getZ();
}
protected float[] convXYZtoRGB(float x, float y, float z)
{<FILL_FUNCTION_BODY>}
/**
* This will return the whitepoint tristimulus. As this is a required field
* this will never return null. A default of 1,1,1 will be returned if the
* pdf does not have any values yet.
*
* @return the whitepoint tristimulus
*/
public final PDTristimulus getWhitepoint()
{
COSArray wp = dictionary.getCOSArray(COSName.WHITE_POINT);
if (wp == null)
{
wp = new COSArray();
wp.add(COSFloat.ONE);
wp.add(COSFloat.ONE);
wp.add(COSFloat.ONE);
}
return new PDTristimulus(wp);
}
/**
* This will return the BlackPoint tristimulus. This is an optional field
* but has defaults so this will never return null. A default of 0,0,0 will
* be returned if the pdf does not have any values yet.
*
* @return the blackpoint tristimulus
*/
public final PDTristimulus getBlackPoint()
{
COSArray bp = dictionary.getCOSArray(COSName.BLACK_POINT);
if (bp == null)
{
bp = new COSArray();
bp.add(COSFloat.ZERO);
bp.add(COSFloat.ZERO);
bp.add(COSFloat.ZERO);
}
return new PDTristimulus(bp);
}
/**
* This will set the whitepoint tristimulus. As this is a required field, null should not be
* passed into this function.
*
* @param whitepoint the whitepoint tristimulus.
* @throws IllegalArgumentException if null is passed as argument.
*/
public void setWhitePoint(PDTristimulus whitepoint)
{
if (whitepoint == null)
{
throw new IllegalArgumentException("Whitepoint may not be null");
}
dictionary.setItem(COSName.WHITE_POINT, whitepoint);
fillWhitepointCache(whitepoint);
}
/**
* This will set the BlackPoint tristimulus.
*
* @param blackpoint the BlackPoint tristimulus
*/
public void setBlackPoint(PDTristimulus blackpoint)
{
dictionary.setItem(COSName.BLACK_POINT, blackpoint);
}
}
|
// toRGB() malfunctions with negative values
// XYZ must be non-negative anyway:
// http://ninedegreesbelow.com/photography/icc-profile-negative-tristimulus.html
if (x < 0)
{
x = 0;
}
if (y < 0)
{
y = 0;
}
if (z < 0)
{
z = 0;
}
return CIEXYZ.toRGB(new float[]
{
x, y, z
});
| 1,146
| 146
| 1,292
|
<methods>public non-sealed void <init>() ,public java.awt.image.BufferedImage toRGBImage(java.awt.image.WritableRaster) throws java.io.IOException,public java.awt.image.BufferedImage toRawImage(java.awt.image.WritableRaster) throws java.io.IOException,public java.lang.String toString() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalGray.java
|
PDCalGray
|
toRGB
|
class PDCalGray extends PDCIEDictionaryBasedColorSpace
{
private final PDColor initialColor = new PDColor(new float[] { 0 }, this);
// PDFBOX-4119: cache the results for much improved performance
// cached values MUST be cloned, because they are modified by the caller.
// this can be observed in rendering of PDFBOX-1724
private final Map<Float, float[]> map1 = new HashMap<>();
/**
* Create a new CalGray color space.
*/
public PDCalGray()
{
super(COSName.CALGRAY);
}
/**
* Creates a new CalGray color space using the given COS array.
*
* @param array the COS array which represents this color space
*/
public PDCalGray(COSArray array)
{
super(array);
}
@Override
public String getName()
{
return COSName.CALGRAY.getName();
}
@Override
public int getNumberOfComponents()
{
return 1;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
return new float[] { 0, 1 };
}
@Override
public PDColor getInitialColor()
{
return initialColor;
}
@Override
public float[] toRGB(float[] value)
{<FILL_FUNCTION_BODY>}
/**
* This will get the gamma value. If none is present then the default of 1
* will be returned.
*
* @return The gamma value.
*/
public float getGamma()
{
return dictionary.getFloat(COSName.GAMMA, 1.0f);
}
/**
* Set the gamma value.
*
* @param value The new gamma value.
*/
public void setGamma(float value)
{
dictionary.setItem(COSName.GAMMA, new COSFloat(value));
}
}
|
// see implementation of toRGB in PDCalRGB, and PDFBOX-2971
if (isWhitePoint())
{
float a = value[0];
float[] result = map1.get(a);
if (result != null)
{
return result.clone();
}
float gamma = getGamma();
float powAG = (float) Math.pow(a, gamma);
result = convXYZtoRGB(powAG, powAG, powAG);
map1.put(a, result.clone());
return result;
}
else
{
return new float[] { value[0], value[0], value[0] };
}
| 543
| 178
| 721
|
<methods>public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getBlackPoint() ,public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getWhitepoint() ,public void setBlackPoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) ,public void setWhitePoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) <variables>private static final java.awt.color.ColorSpace CIEXYZ,protected final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary,protected float wpX,protected float wpY,protected float wpZ
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java
|
PDCalRGB
|
toRGB
|
class PDCalRGB extends PDCIEDictionaryBasedColorSpace
{
private final PDColor initialColor = new PDColor(new float[] { 0, 0, 0 }, this);
/**
* Creates a new CalRGB color space.
*/
public PDCalRGB()
{
super(COSName.CALRGB);
}
/**
* Creates a new CalRGB color space using the given COS array.
* @param rgb the cos array which represents this color space
*/
public PDCalRGB(COSArray rgb)
{
super(rgb);
}
@Override
public String getName()
{
return COSName.CALRGB.getName();
}
@Override
public int getNumberOfComponents()
{
return 3;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
return new float[] { 0, 1, 0, 1, 0, 1 };
}
@Override
public PDColor getInitialColor()
{
return initialColor;
}
@Override
public float[] toRGB(float[] value)
{<FILL_FUNCTION_BODY>}
/**
* Returns the gamma value.
* If none is present then the default of 1,1,1 will be returned.
* @return the gamma value
*/
public final PDGamma getGamma()
{
COSArray gammaArray = dictionary.getCOSArray(COSName.GAMMA);
if (gammaArray == null)
{
gammaArray = new COSArray();
gammaArray.add(COSFloat.ONE);
gammaArray.add(COSFloat.ONE);
gammaArray.add(COSFloat.ONE);
dictionary.setItem(COSName.GAMMA, gammaArray);
}
return new PDGamma(gammaArray);
}
/**
* Returns the linear interpretation matrix, which is an array of nine numbers.
* If the underlying dictionary contains null then the identity matrix will be returned.
* @return the linear interpretation matrix
*/
public final float[] getMatrix()
{
COSArray matrix = dictionary.getCOSArray(COSName.MATRIX);
if (matrix == null)
{
return new float[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
}
else
{
return matrix.toFloatArray();
}
}
/**
* Sets the gamma value.
* @param gamma the new gamma value
*/
public final void setGamma(PDGamma gamma)
{
COSArray gammaArray = null;
if(gamma != null)
{
gammaArray = gamma.getCOSArray();
}
dictionary.setItem(COSName.GAMMA, gammaArray);
}
/**
* Sets the linear interpretation matrix.
* Passing in null will clear the matrix.
* @param matrix the new linear interpretation matrix, or null
*/
public final void setMatrix(Matrix matrix)
{
COSArray matrixArray = null;
if(matrix != null)
{
// We can't use matrix.toCOSArray(), as it only returns a subset of the matrix
float[][] values = matrix.getValues();
matrixArray = new COSArray();
matrixArray.add(new COSFloat(values[0][0]));
matrixArray.add(new COSFloat(values[0][1]));
matrixArray.add(new COSFloat(values[0][2]));
matrixArray.add(new COSFloat(values[1][0]));
matrixArray.add(new COSFloat(values[1][1]));
matrixArray.add(new COSFloat(values[1][2]));
matrixArray.add(new COSFloat(values[2][0]));
matrixArray.add(new COSFloat(values[2][1]));
matrixArray.add(new COSFloat(values[2][2]));
}
dictionary.setItem(COSName.MATRIX, matrixArray);
}
}
|
if (isWhitePoint())
{
float a = value[0];
float b = value[1];
float c = value[2];
PDGamma gamma = getGamma();
float powAR = (float)Math.pow(a, gamma.getR());
float powBG = (float)Math.pow(b, gamma.getG());
float powCB = (float)Math.pow(c, gamma.getB());
float[] matrix = getMatrix();
float mXA = matrix[0];
float mYA = matrix[1];
float mZA = matrix[2];
float mXB = matrix[3];
float mYB = matrix[4];
float mZB = matrix[5];
float mXC = matrix[6];
float mYC = matrix[7];
float mZC = matrix[8];
float x = mXA * powAR + mXB * powBG + mXC * powCB;
float y = mYA * powAR + mYB * powBG + mYC * powCB;
float z = mZA * powAR + mZB * powBG + mZC * powCB;
return convXYZtoRGB(x, y, z);
}
else
{
// this is a hack, we simply skip CIE calibration of the RGB value
// this works only with whitepoint D65 (0.9505 1.0 1.089)
// see PDFBOX-2553
return new float[] { value[0], value[1], value[2] };
}
| 1,083
| 412
| 1,495
|
<methods>public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getBlackPoint() ,public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getWhitepoint() ,public void setBlackPoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) ,public void setWhitePoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) <variables>private static final java.awt.color.ColorSpace CIEXYZ,protected final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary,protected float wpX,protected float wpY,protected float wpZ
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColor.java
|
PDColor
|
getComponents
|
class PDColor
{
private static final Logger LOG = LogManager.getLogger(PDColor.class);
private final float[] components;
private final COSName patternName;
private final PDColorSpace colorSpace;
/**
* Creates a PDColor containing the given color value.
* @param array a COS array containing the color value
* @param colorSpace color space in which the color value is defined
*/
public PDColor(COSArray array, PDColorSpace colorSpace)
{
if (!array.isEmpty() && array.get(array.size() - 1) instanceof COSName)
{
// color components (optional), for the color of an uncoloured tiling pattern
components = new float[array.size() - 1];
initComponents(array);
// pattern name (required)
COSBase base = array.get(array.size() - 1);
if (base instanceof COSName)
{
patternName = (COSName) base;
}
else
{
LOG.warn("pattern name in {} isn't a name, ignored", array);
patternName = COSName.getPDFName("Unknown");
}
}
else
{
// color components only
components = new float[array.size()];
initComponents(array);
patternName = null;
}
this.colorSpace = colorSpace;
}
private void initComponents(COSArray array)
{
for (int i = 0; i < components.length; i++)
{
COSBase base = array.get(i);
if (base instanceof COSNumber)
{
components[i] = ((COSNumber) base).floatValue();
}
else
{
LOG.warn("color component {} in {} isn't a number, ignored", i, array);
}
}
}
/**
* Creates a PDColor containing the given color component values.
* @param components array of color component values
* @param colorSpace color space in which the components are defined
*/
public PDColor(float[] components, PDColorSpace colorSpace)
{
this.components = components.clone();
this.patternName = null;
this.colorSpace = colorSpace;
}
/**
* Creates a PDColor containing the given pattern name.
* @param patternName the name of a pattern in a pattern dictionary
* @param colorSpace color space in which the pattern is defined
*/
public PDColor(COSName patternName, PDColorSpace colorSpace)
{
this.components = new float[0];
this.patternName = patternName;
this.colorSpace = colorSpace;
}
/**
* Creates a PDColor containing the given color component values and pattern name.
* @param components array of color component values
* @param patternName the name of a pattern in a pattern dictionary
* @param colorSpace color space in which the pattern/components are defined
*/
public PDColor(float[] components, COSName patternName, PDColorSpace colorSpace)
{
this.components = components.clone();
this.patternName = patternName;
this.colorSpace = colorSpace;
}
/**
* Returns the components of this color value.
* @return the components of this color value, never null.
*/
public float[] getComponents()
{<FILL_FUNCTION_BODY>}
/**
* Returns the pattern name from this color value.
* @return the pattern name from this color value
*/
public COSName getPatternName()
{
return patternName;
}
/**
* Returns true if this color value is a pattern.
* @return true if this color value is a pattern
*/
public boolean isPattern()
{
return patternName != null;
}
/**
* Returns the packed RGB value for this color, if any.
* @return RGB
* @throws IOException if the color conversion fails
* @throws UnsupportedOperationException if this color value is a pattern.
*/
public int toRGB() throws IOException
{
float[] floats = colorSpace.toRGB(components);
int r = Math.round(floats[0] * 255);
int g = Math.round(floats[1] * 255);
int b = Math.round(floats[2] * 255);
int rgb = r;
rgb = (rgb << 8) + g;
rgb = (rgb << 8) + b;
return rgb;
}
/**
* Returns the color component values as a COS array
* @return the color component values as a COS array
*/
public COSArray toCOSArray()
{
COSArray array = COSArray.of(components);
if (patternName != null)
{
array.add(patternName);
}
return array;
}
/**
* Returns the color space in which this color value is defined.
*
* @return the color space in which this color value is defined
*/
public PDColorSpace getColorSpace()
{
return colorSpace;
}
@Override
public String toString()
{
return "PDColor{components=" + Arrays.toString(components) + ", patternName=" + patternName + ", colorSpace=" + colorSpace + '}';
}
}
|
if (colorSpace instanceof PDPattern || colorSpace == null)
{
// colorspace of the pattern color isn't known, so just clone
// null colorspace can happen with empty annotation color
// see PDFBOX-3351-538928-p4.pdf
return components.clone();
}
// PDFBOX-4279: copyOf instead of clone in case array is too small
return Arrays.copyOf(components, colorSpace.getNumberOfComponents());
| 1,567
| 138
| 1,705
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
|
PDDeviceCMYK
|
toRawImage
|
class PDDeviceCMYK extends PDDeviceColorSpace
{
/** The single instance of this class. */
public static PDDeviceCMYK INSTANCE;
static
{
INSTANCE = new PDDeviceCMYK();
}
private final PDColor initialColor = new PDColor(new float[] { 0, 0, 0, 1 }, this);
private ICC_ColorSpace awtColorSpace;
private volatile boolean initDone = false;
private boolean usePureJavaCMYKConversion = false;
protected PDDeviceCMYK()
{
}
/**
* Lazy load the ICC profile, because it's slow.
*
* @throws IOException if the ICC profile could not be initialized
*/
protected void init() throws IOException
{
// no need to synchronize this check as it is atomic
if (initDone)
{
return;
}
synchronized (this)
{
// we might have been waiting for another thread, so check again
if (initDone)
{
return;
}
// loads the ICC color profile for CMYK
ICC_Profile iccProfile = getICCProfile();
if (iccProfile == null)
{
throw new IOException("Default CMYK color profile could not be loaded");
}
awtColorSpace = new ICC_ColorSpace(iccProfile);
// there is a JVM bug which results in a CMMException which appears to be a race
// condition caused by lazy initialization of the color transform, so we perform
// an initial color conversion while we're still in a static context, see PDFBOX-2184
awtColorSpace.toRGB(new float[] { 0, 0, 0, 0 });
usePureJavaCMYKConversion = System
.getProperty("org.apache.pdfbox.rendering.UsePureJavaCMYKConversion") != null;
// Assignment to volatile must be the LAST statement in this block!
initDone = true;
}
}
protected ICC_Profile getICCProfile() throws IOException
{
// Adobe Acrobat uses "U.S. Web Coated (SWOP) v2" as the default
// CMYK profile, however it is not available under an open license.
// Instead, the "CGATS001Compat-v2-micro" is used, which is an open
// alternative to the "U.S. Web Coated (SWOP) v2" profile.
// https://github.com/saucecontrol/Compact-ICC-Profiles#cmyk
String resourceName = "/org/apache/pdfbox/resources/icc/CGATS001Compat-v2-micro.icc";
InputStream resourceAsStream = PDDeviceCMYK.class.getResourceAsStream(resourceName);
if (resourceAsStream == null)
{
throw new IOException("resource '" + resourceName + "' not found");
}
try (InputStream is = new BufferedInputStream(resourceAsStream))
{
return ICC_Profile.getInstance(is);
}
}
@Override
public String getName()
{
return COSName.DEVICECMYK.getName();
}
@Override
public int getNumberOfComponents()
{
return 4;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
return new float[] { 0, 1, 0, 1, 0, 1, 0, 1 };
}
@Override
public PDColor getInitialColor()
{
return initialColor;
}
@Override
public float[] toRGB(float[] value) throws IOException
{
init();
return awtColorSpace.toRGB(value);
}
@Override
public BufferedImage toRawImage(WritableRaster raster) throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
init();
return toRGBImageAWT(raster, awtColorSpace);
}
@Override
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
if (usePureJavaCMYKConversion)
{
BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
BufferedImage.TYPE_INT_RGB);
ColorSpace destCS = dest.getColorModel().getColorSpace();
WritableRaster destRaster = dest.getRaster();
float[] srcValues = new float[4];
float[] lastValues = { -1.0f, -1.0f, -1.0f, -1.0f };
float[] destValues = new float[3];
int startX = raster.getMinX();
int startY = raster.getMinY();
int endX = raster.getWidth() + startX;
int endY = raster.getHeight() + startY;
for (int x = startX; x < endX; x++)
{
for (int y = startY; y < endY; y++)
{
raster.getPixel(x, y, srcValues);
// check if the last value can be reused
if (!Arrays.equals(lastValues, srcValues))
{
lastValues[0] = srcValues[0];
srcValues[0] = srcValues[0] / 255f;
lastValues[1] = srcValues[1];
srcValues[1] = srcValues[1] / 255f;
lastValues[2] = srcValues[2];
srcValues[2] = srcValues[2] / 255f;
lastValues[3] = srcValues[3];
srcValues[3] = srcValues[3] / 255f;
// use CIEXYZ as intermediate format to optimize the color conversion
destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues));
for (int k = 0; k < destValues.length; k++)
{
destValues[k] = destValues[k] * 255f;
}
}
destRaster.setPixel(x, y, destValues);
}
}
return dest;
}
else
{
return super.toRGBImageAWT(raster, colorSpace);
}
}
}
|
// Device CMYK is not specified, as its the colors of whatever device you use.
// The user should fallback to the RGB image
return null;
| 1,687
| 41
| 1,728
|
<methods>public non-sealed void <init>() ,public org.apache.pdfbox.cos.COSBase getCOSObject() ,public java.lang.String toString() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceGray.java
|
PDDeviceGray
|
toRGBImage
|
class PDDeviceGray extends PDDeviceColorSpace
{
/** The single instance of this class. */
public static final PDDeviceGray INSTANCE = new PDDeviceGray();
private final PDColor initialColor = new PDColor(new float[] { 0 }, this);
private PDDeviceGray()
{
}
@Override
public String getName()
{
return COSName.DEVICEGRAY.getName();
}
@Override
public int getNumberOfComponents()
{
return 1;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
return new float[] { 0, 1 };
}
@Override
public PDColor getInitialColor()
{
return initialColor;
}
@Override
public float[] toRGB(float[] value)
{
return new float[] { value[0], value[0], value[0] };
}
@Override
public BufferedImage toRawImage(WritableRaster raster) throws IOException
{
// DeviceGray is whatever the output device chooses. We have no Java colorspace
// for this.
return null;
}
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{<FILL_FUNCTION_BODY>}
}
|
int width = raster.getWidth();
int height = raster.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int[] gray = new int[1];
int[] rgb = new int[3];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
raster.getPixel(x, y, gray);
rgb[0] = gray[0];
rgb[1] = gray[0];
rgb[2] = gray[0];
image.getRaster().setPixel(x, y, rgb);
}
}
return image;
| 366
| 194
| 560
|
<methods>public non-sealed void <init>() ,public org.apache.pdfbox.cos.COSBase getCOSObject() ,public java.lang.String toString() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
|
PDDeviceNAttributes
|
toString
|
class PDDeviceNAttributes
{
/**
* Log instance.
*/
private static final Logger LOG = LogManager.getLogger(PDDeviceNAttributes.class);
private final COSDictionary dictionary;
/**
* Creates a new DeviceN colour space attributes dictionary.
*/
public PDDeviceNAttributes()
{
dictionary = new COSDictionary();
}
/**
* Creates a new DeviceN colour space attributes dictionary from the given dictionary.
* @param attributes a dictionary that has all of the attributes
*/
public PDDeviceNAttributes(COSDictionary attributes)
{
dictionary = attributes;
}
/**
* Returns the underlying COS dictionary.
* @return the dictionary that this object wraps
*/
public COSDictionary getCOSDictionary()
{
return dictionary;
}
/**
* Returns a map of colorants and their associated Separation color space.
* @return map of colorants to color spaces, never null.
* @throws IOException If there is an error reading a color space
*/
public Map<String, PDSeparation> getColorants() throws IOException
{
Map<String,PDSeparation> actuals = new HashMap<>();
COSDictionary colorants = dictionary.getCOSDictionary(COSName.COLORANTS);
if(colorants == null)
{
colorants = new COSDictionary();
dictionary.setItem(COSName.COLORANTS, colorants);
}
else
{
for (COSName name : colorants.keySet())
{
COSBase value = colorants.getDictionaryObject(name);
actuals.put(name.getName(), (PDSeparation) PDColorSpace.create(value));
}
}
return new COSDictionaryMap<>(actuals, colorants);
}
/**
* Returns the DeviceN Process Dictionary, or null if it is missing.
* @return the DeviceN Process Dictionary, or null if it is missing.
*/
public PDDeviceNProcess getProcess()
{
COSDictionary process = dictionary.getCOSDictionary(COSName.PROCESS);
if (process == null)
{
return null;
}
return new PDDeviceNProcess(process);
}
/**
* Returns true if this is an NChannel (PDF 1.6) color space.
* @return true if this is an NChannel color space.
*/
public boolean isNChannel()
{
return "NChannel".equals(dictionary.getNameAsString(COSName.SUBTYPE));
}
/**
* Sets the colorant map.
* @param colorants the map of colorants
*/
public void setColorants(Map<String, PDColorSpace> colorants)
{
COSDictionary colorantDict = null;
if(colorants != null)
{
colorantDict = COSDictionaryMap.convert(colorants);
}
dictionary.setItem(COSName.COLORANTS, colorantDict);
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder(dictionary.getNameAsString(COSName.SUBTYPE));
sb.append('{');
PDDeviceNProcess process = getProcess();
if (process != null)
{
sb.append(process);
sb.append(' ');
}
Map<String, PDSeparation> colorants;
try
{
colorants = getColorants();
sb.append("Colorants{");
for (Map.Entry<String, PDSeparation> col : colorants.entrySet())
{
sb.append('\"');
sb.append(col.getKey());
sb.append("\": ");
sb.append(col.getValue());
sb.append(' ');
}
sb.append('}');
}
catch (IOException e)
{
LOG.debug("Couldn't get the colorants information - returning 'ERROR' instead'", e);
sb.append("ERROR");
}
sb.append('}');
return sb.toString();
| 813
| 265
| 1,078
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNProcess.java
|
PDDeviceNProcess
|
toString
|
class PDDeviceNProcess
{
/**
* Log instance.
*/
private static final Logger LOG = LogManager.getLogger(PDDeviceNProcess.class);
private final COSDictionary dictionary;
/**
* Creates a new DeviceN Process Dictionary.
*/
public PDDeviceNProcess()
{
dictionary = new COSDictionary();
}
/**
* Creates a new DeviceN Process Dictionary from the given attributes.
* @param attributes a DeviceN attributes dictionary
*/
public PDDeviceNProcess(COSDictionary attributes)
{
dictionary = attributes;
}
/**
* Returns the underlying COS dictionary.
* @return the underlying COS dictionary.
*/
public COSDictionary getCOSDictionary()
{
return dictionary;
}
/**
* Returns the process color space
* @return the process color space
* @throws IOException if the color space cannot be read
*/
public PDColorSpace getColorSpace() throws IOException
{
COSBase cosColorSpace = dictionary.getDictionaryObject(COSName.COLORSPACE);
if (cosColorSpace == null)
{
return null; // TODO: return a default?
}
return PDColorSpace.create(cosColorSpace);
}
/**
* Returns the names of the color components.
* @return the names of the color components
*/
public List<String> getComponents()
{
COSArray cosComponents = dictionary.getCOSArray(COSName.COMPONENTS);
if (cosComponents == null)
{
return new ArrayList<>(0);
}
List<String> components = new ArrayList<>(cosComponents.size());
for (COSBase name : cosComponents)
{
components.add(((COSName)name).getName());
}
return components;
}
@Override
public String toString()
{<FILL_FUNCTION_BODY>}
}
|
StringBuilder sb = new StringBuilder("Process{");
try
{
sb.append(getColorSpace());
for (String component : getComponents())
{
sb.append(" \"");
sb.append(component);
sb.append('\"');
}
}
catch (IOException e)
{
LOG.debug("Couldn't get the colorants information - returning 'ERROR' instead'", e);
sb.append("ERROR");
}
sb.append('}');
return sb.toString();
| 515
| 137
| 652
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
|
PDDeviceRGB
|
toRGBImage
|
class PDDeviceRGB extends PDDeviceColorSpace
{
/** This is the single instance of this class. */
public static final PDDeviceRGB INSTANCE = new PDDeviceRGB();
private final PDColor initialColor = new PDColor(new float[] { 0, 0, 0 }, this);
private PDDeviceRGB()
{
}
@Override
public String getName()
{
return COSName.DEVICERGB.getName();
}
/**
* {@inheritDoc}
*/
@Override
public int getNumberOfComponents()
{
return 3;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
return new float[] { 0, 1, 0, 1, 0, 1 };
}
@Override
public PDColor getInitialColor()
{
return initialColor;
}
@Override
public float[] toRGB(float[] value)
{
return value;
}
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public BufferedImage toRawImage(WritableRaster raster) throws IOException
{
// Device RGB is not specified, as its the colors of whatever device you use. The user
// should use the toRGBImage().
return null;
}
}
|
//
// WARNING: this method is performance sensitive, modify with care!
//
// Please read PDFBOX-3854 and PDFBOX-2092 and look at the related commits first.
// The current code returns TYPE_INT_RGB images which prevents slowness due to threads
// blocking each other when TYPE_CUSTOM images are used.
BufferedImage image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB);
image.setData(raster);
return image;
| 392
| 143
| 535
|
<methods>public non-sealed void <init>() ,public org.apache.pdfbox.cos.COSBase getCOSObject() ,public java.lang.String toString() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java
|
PDLab
|
getBRange
|
class PDLab extends PDCIEDictionaryBasedColorSpace
{
private PDColor initialColor;
/**
* Creates a new Lab color space.
*/
public PDLab()
{
super(COSName.LAB);
}
/**
* Creates a new Lab color space from a PDF array.
* @param lab the color space array
*/
public PDLab(COSArray lab)
{
super(lab);
}
@Override
public String getName()
{
return COSName.LAB.getName();
}
//
// WARNING: this method is performance sensitive, modify with care!
//
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
int width = raster.getWidth();
int height = raster.getHeight();
BufferedImage rgbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster rgbRaster = rgbImage.getRaster();
PDRange aRange = getARange();
PDRange bRange = getBRange();
float minA = aRange.getMin();
float maxA = aRange.getMax();
float minB = bRange.getMin();
float maxB = bRange.getMax();
float deltaA = maxA - minA;
float deltaB = maxB - minB;
// always three components: ABC
float[] abc = new float[3];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
raster.getPixel(x, y, abc);
// 0..255 -> 0..1
abc[0] /= 255;
abc[1] /= 255;
abc[2] /= 255;
// scale to range
abc[0] *= 100;
abc[1] = minA + abc[1] * deltaA;
abc[2] = minB + abc[2] * deltaB;
float[] rgb = toRGB(abc);
// 0..1 -> 0..255
rgb[0] *= 255;
rgb[1] *= 255;
rgb[2] *= 255;
rgbRaster.setPixel(x, y, rgb);
}
}
return rgbImage;
}
@Override
public BufferedImage toRawImage(WritableRaster raster)
{
// Not handled at the moment.
return null;
}
@Override
public float[] toRGB(float[] value)
{
// CIE LAB to RGB, see http://en.wikipedia.org/wiki/Lab_color_space
// L*
float lstar = (value[0] + 16f) * (1f / 116f);
// TODO: how to use the blackpoint? scale linearly between black & white?
// XYZ
float x = wpX * inverse(lstar + value[1] * (1f / 500f));
float y = wpY * inverse(lstar);
float z = wpZ * inverse(lstar - value[2] * (1f / 200f));
return convXYZtoRGB(x, y, z);
}
// reverse transformation (f^-1)
private float inverse(float x)
{
if (x > 6.0 / 29.0)
{
return x * x * x;
}
else
{
return (108f / 841f) * (x - (4f / 29f));
}
}
@Override
public int getNumberOfComponents()
{
return 3;
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
PDRange a = getARange();
PDRange b = getBRange();
return new float[] { 0, 100, a.getMin(), a.getMax(), b.getMin(), b.getMax() };
}
@Override
public PDColor getInitialColor()
{
if (initialColor == null)
{
initialColor = new PDColor(new float[] {
0,
Math.max(0, getARange().getMin()),
Math.max(0, getBRange().getMin()) },
this);
}
return initialColor;
}
/**
* creates a range array with default values (-100..100 -100..100).
* @return the new range array.
*/
private COSArray getDefaultRangeArray()
{
COSArray range = new COSArray();
range.add(new COSFloat(-100));
range.add(new COSFloat(100));
range.add(new COSFloat(-100));
range.add(new COSFloat(100));
return range;
}
/**
* This will get the valid range for the "a" component.
* If none is found then the default will be returned, which is -100..100.
* @return the "a" range.
*/
public PDRange getARange()
{
COSArray rangeArray = dictionary.getCOSArray(COSName.RANGE);
if (rangeArray == null)
{
rangeArray = getDefaultRangeArray();
}
return new PDRange(rangeArray, 0);
}
/**
* This will get the valid range for the "b" component.
* If none is found then the default will be returned, which is -100..100.
* @return the "b" range.
*/
public PDRange getBRange()
{<FILL_FUNCTION_BODY>}
/**
* This will set the a range for the "a" component.
* @param range the new range for the "a" component,
* or null if defaults (-100..100) are to be set.
*/
public void setARange(PDRange range)
{
setComponentRangeArray(range, 0);
}
/**
* This will set the "b" range for this color space.
* @param range the new range for the "b" component,
* or null if defaults (-100..100) are to be set.
*/
public void setBRange(PDRange range)
{
setComponentRangeArray(range, 2);
}
private void setComponentRangeArray(PDRange range, int index)
{
COSArray rangeArray = dictionary.getCOSArray(COSName.RANGE);
if (rangeArray == null)
{
rangeArray = getDefaultRangeArray();
}
if (range == null)
{
// reset to defaults
rangeArray.set(index, new COSFloat(-100));
rangeArray.set(index + 1, new COSFloat(100));
}
else
{
rangeArray.set(index, new COSFloat(range.getMin()));
rangeArray.set(index + 1, new COSFloat(range.getMax()));
}
dictionary.setItem(COSName.RANGE, rangeArray);
initialColor = null;
}
}
|
COSArray rangeArray = dictionary.getCOSArray(COSName.RANGE);
if (rangeArray == null)
{
rangeArray = getDefaultRangeArray();
}
return new PDRange(rangeArray, 1);
| 1,956
| 64
| 2,020
|
<methods>public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getBlackPoint() ,public final org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus getWhitepoint() ,public void setBlackPoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) ,public void setWhitePoint(org.apache.pdfbox.pdmodel.graphics.color.PDTristimulus) <variables>private static final java.awt.color.ColorSpace CIEXYZ,protected final non-sealed org.apache.pdfbox.cos.COSDictionary dictionary,protected float wpX,protected float wpY,protected float wpZ
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDOutputIntent.java
|
PDOutputIntent
|
configureOutputProfile
|
class PDOutputIntent implements COSObjectable
{
private final COSDictionary dictionary;
public PDOutputIntent(PDDocument doc, InputStream colorProfile) throws IOException
{
dictionary = new COSDictionary();
dictionary.setItem(COSName.TYPE, COSName.OUTPUT_INTENT);
dictionary.setItem(COSName.S, COSName.GTS_PDFA1);
PDStream destOutputIntent = configureOutputProfile(doc, colorProfile);
dictionary.setItem(COSName.DEST_OUTPUT_PROFILE, destOutputIntent);
}
public PDOutputIntent(COSDictionary dictionary)
{
this.dictionary = dictionary;
}
@Override
public COSDictionary getCOSObject()
{
return dictionary;
}
public COSStream getDestOutputIntent()
{
return dictionary.getCOSStream(COSName.DEST_OUTPUT_PROFILE);
}
public String getInfo()
{
return dictionary.getString(COSName.INFO);
}
public void setInfo(String value)
{
dictionary.setString(COSName.INFO, value);
}
public String getOutputCondition()
{
return dictionary.getString(COSName.OUTPUT_CONDITION);
}
public void setOutputCondition(String value)
{
dictionary.setString(COSName.OUTPUT_CONDITION, value);
}
public String getOutputConditionIdentifier()
{
return dictionary.getString(COSName.OUTPUT_CONDITION_IDENTIFIER);
}
public void setOutputConditionIdentifier(String value)
{
dictionary.setString(COSName.OUTPUT_CONDITION_IDENTIFIER, value);
}
public String getRegistryName()
{
return dictionary.getString(COSName.REGISTRY_NAME);
}
public void setRegistryName(String value)
{
dictionary.setString(COSName.REGISTRY_NAME, value);
}
private PDStream configureOutputProfile(PDDocument doc, InputStream colorProfile)
throws IOException
{<FILL_FUNCTION_BODY>}
}
|
ICC_Profile icc = ICC_Profile.getInstance(colorProfile);
PDStream stream = new PDStream(doc, new ByteArrayInputStream(icc.getData()), COSName.FLATE_DECODE);
stream.getCOSObject().setInt(COSName.N, icc.getNumComponents());
return stream;
| 640
| 93
| 733
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDPattern.java
|
PDPattern
|
getPattern
|
class PDPattern extends PDSpecialColorSpace
{
/** A pattern which leaves no marks on the page. */
private static final PDColor EMPTY_PATTERN = new PDColor(new float[] { }, null);
private final PDResources resources;
private PDColorSpace underlyingColorSpace;
/**
* Creates a new pattern color space.
*
* @param resources The current resources.
*/
public PDPattern(PDResources resources)
{
this.resources = resources;
array = new COSArray();
array.add(COSName.PATTERN);
}
/**
* Creates a new uncolored tiling pattern color space.
*
* @param resources The current resources.
* @param colorSpace The underlying color space.
*/
public PDPattern(PDResources resources, PDColorSpace colorSpace)
{
this.resources = resources;
this.underlyingColorSpace = colorSpace;
array = new COSArray();
array.add(COSName.PATTERN);
array.add(colorSpace);
}
@Override
public String getName()
{
return COSName.PATTERN.getName();
}
@Override
public int getNumberOfComponents()
{
throw new UnsupportedOperationException();
}
@Override
public float[] getDefaultDecode(int bitsPerComponent)
{
throw new UnsupportedOperationException();
}
@Override
public PDColor getInitialColor()
{
return EMPTY_PATTERN;
}
@Override
public float[] toRGB(float[] value)
{
throw new UnsupportedOperationException();
}
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
throw new UnsupportedOperationException();
}
@Override
public BufferedImage toRawImage(WritableRaster raster) throws IOException
{
throw new UnsupportedOperationException();
}
/**
* Returns the pattern for the given color.
*
* @param color color containing a pattern name
* @return pattern for the given color
* @throws java.io.IOException if the pattern name was not found.
*/
public PDAbstractPattern getPattern(PDColor color) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* Returns the underlying color space, if this is an uncolored tiling pattern, otherwise null.
*
* @return the underlying color space or null
*/
public PDColorSpace getUnderlyingColorSpace()
{
return underlyingColorSpace;
}
@Override
public String toString()
{
return "Pattern";
}
}
|
PDAbstractPattern pattern = resources.getPattern(color.getPatternName());
if (pattern == null)
{
throw new IOException("pattern " + color.getPatternName() + " was not found");
}
else
{
return pattern;
}
| 711
| 71
| 782
|
<methods>public non-sealed void <init>() <variables>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java
|
PDFormXObject
|
getGroup
|
class PDFormXObject extends PDXObject implements PDContentStream
{
private PDTransparencyGroupAttributes group;
private final ResourceCache cache;
/**
* Creates a Form XObject for reading.
* @param stream The XObject stream
*/
public PDFormXObject(PDStream stream)
{
super(stream, COSName.FORM);
cache = null;
}
/**
* Creates a Form XObject for reading.
* @param stream The XObject stream
*/
public PDFormXObject(COSStream stream)
{
super(stream, COSName.FORM);
cache = null;
}
/**
* Creates a Form XObject for reading.
*
* @param stream The XObject stream
* @param cache the cache to be used for the resources
*/
public PDFormXObject(COSStream stream, ResourceCache cache)
{
super(stream, COSName.FORM);
this.cache = cache;
}
/**
* Creates a Form Image XObject for writing, in the given document.
* @param document The current document
*/
public PDFormXObject(PDDocument document)
{
super(document, COSName.FORM);
cache = null;
}
/**
* This will get the form type, currently 1 is the only form type.
* @return The form type.
*/
public int getFormType()
{
return getCOSObject().getInt(COSName.FORMTYPE, 1);
}
/**
* Set the form type.
* @param formType The new form type.
*/
public void setFormType(int formType)
{
getCOSObject().setInt(COSName.FORMTYPE, formType);
}
/**
* Returns the group attributes dictionary.
*
* @return the group attributes dictionary
*/
public PDTransparencyGroupAttributes getGroup()
{<FILL_FUNCTION_BODY>}
public PDStream getContentStream()
{
return new PDStream(getCOSObject());
}
@Override
public InputStream getContents() throws IOException
{
return new RandomAccessInputStream(getContentsForRandomAccess());
}
@Override
public RandomAccessRead getContentsForRandomAccess() throws IOException
{
return getCOSObject().createView();
}
/**
* This will get the resources for this Form XObject.
* This will return null if no resources are available.
*
* @return The resources for this Form XObject.
*/
@Override
public PDResources getResources()
{
COSDictionary resources = getCOSObject().getCOSDictionary(COSName.RESOURCES);
if (resources != null)
{
return new PDResources(resources, cache);
}
if (getCOSObject().containsKey(COSName.RESOURCES))
{
// PDFBOX-4372 if the resource key exists but has nothing, return empty resources,
// to avoid a self-reference (xobject form Fm0 contains "/Fm0 Do")
// See also the mention of PDFBOX-1359 in PDFStreamEngine
return new PDResources();
}
return null;
}
/**
* This will set the resources for this page.
* @param resources The new resources for this page.
*/
public void setResources(PDResources resources)
{
getCOSObject().setItem(COSName.RESOURCES, resources);
}
/**
* An array of four numbers in the form coordinate system (see below),
* giving the coordinates of the left, bottom, right, and top edges, respectively,
* of the form XObject's bounding box.
* These boundaries are used to clip the form XObject and to determine its size for caching.
* @return The BBox of the form.
*/
@Override
public PDRectangle getBBox()
{
COSArray array = getCOSObject().getCOSArray(COSName.BBOX);
return array != null ? new PDRectangle(array) : null;
}
/**
* This will set the BBox (bounding box) for this form.
* @param bbox The new BBox for this form.
*/
public void setBBox(PDRectangle bbox)
{
if (bbox == null)
{
getCOSObject().removeItem(COSName.BBOX);
}
else
{
getCOSObject().setItem(COSName.BBOX, bbox.getCOSArray());
}
}
/**
* This will get the optional matrix of an XObjectForm. It maps the form space to user space.
* @return the form matrix if available, or the identity matrix.
*/
@Override
public Matrix getMatrix()
{
return Matrix.createMatrix(getCOSObject().getDictionaryObject(COSName.MATRIX));
}
/**
* Sets the optional Matrix entry for the form XObject.
* @param transform the transformation matrix
*/
public void setMatrix(AffineTransform transform)
{
COSArray matrix = new COSArray();
double[] values = new double[6];
transform.getMatrix(values);
for (double v : values)
{
matrix.add(new COSFloat((float) v));
}
getCOSObject().setItem(COSName.MATRIX, matrix);
}
/**
* This will get the key of this XObjectForm in the structural parent tree. Required if the form
* XObject contains marked-content sequences that are structural content items.
*
* @return the integer key of the XObjectForm's entry in the structural parent tree or -1 if
* there isn't any.
*/
public int getStructParents()
{
return getCOSObject().getInt(COSName.STRUCT_PARENTS);
}
/**
* This will set the key for this XObjectForm in the structural parent tree.
* @param structParent The new key for this XObjectForm.
*/
public void setStructParents(int structParent)
{
getCOSObject().setInt(COSName.STRUCT_PARENTS, structParent);
}
/**
* This will get the optional content group or optional content membership dictionary.
*
* @return The optional content group or optional content membership dictionary or null if there
* is none.
*/
public PDPropertyList getOptionalContent()
{
COSDictionary optionalContent = getCOSObject().getCOSDictionary(COSName.OC);
return optionalContent != null ? PDPropertyList.create(optionalContent) : null;
}
/**
* Sets the optional content group or optional content membership dictionary.
*
* @param oc The optional content group or optional content membership dictionary.
*/
public void setOptionalContent(PDPropertyList oc)
{
getCOSObject().setItem(COSName.OC, oc);
}
}
|
if( group == null )
{
COSDictionary dic = getCOSObject().getCOSDictionary(COSName.GROUP);
if( dic != null )
{
group = new PDTransparencyGroupAttributes(dic);
}
}
return group;
| 1,836
| 76
| 1,912
|
<methods>public static org.apache.pdfbox.pdmodel.graphics.PDXObject createXObject(org.apache.pdfbox.cos.COSBase, org.apache.pdfbox.pdmodel.PDResources) throws java.io.IOException,public final org.apache.pdfbox.cos.COSStream getCOSObject() ,public final org.apache.pdfbox.pdmodel.common.PDStream getStream() <variables>private final non-sealed org.apache.pdfbox.pdmodel.common.PDStream stream
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDTransparencyGroupAttributes.java
|
PDTransparencyGroupAttributes
|
getColorSpace
|
class PDTransparencyGroupAttributes implements COSObjectable
{
private final COSDictionary dictionary;
private PDColorSpace colorSpace;
/**
* Creates a group object with /Transparency subtype entry.
*/
public PDTransparencyGroupAttributes()
{
dictionary = new COSDictionary();
dictionary.setItem(COSName.S, COSName.TRANSPARENCY);
}
/**
* Creates a group object from a given dictionary
* @param dic {@link COSDictionary} object
*/
public PDTransparencyGroupAttributes(COSDictionary dic)
{
dictionary = dic;
}
@Override
public COSDictionary getCOSObject()
{
return dictionary;
}
/**
* Returns the group color space or null if it isn't defined.
*
* @return the group color space.
* @throws IOException if the colorspace could not be created
*/
public PDColorSpace getColorSpace() throws IOException
{
return getColorSpace(null);
}
/**
* Returns the group color space or null if it isn't defined.
*
* @param resources useful for its cache. Can be null.
* @return the group color space.
* @throws IOException if the colorspace could not be created
*/
public PDColorSpace getColorSpace(PDResources resources) throws IOException
{<FILL_FUNCTION_BODY>}
/**
* Returns true if this group is isolated. Isolated groups begin with the fully transparent image, non-isolated
* begin with the current backdrop.
*
* @return true if this group is isolated
*/
public boolean isIsolated()
{
return getCOSObject().getBoolean(COSName.I, false);
}
/**
* Returns true if this group is a knockout. A knockout group blends with original backdrop, a non-knockout group
* blends with the current backdrop.
*
* @return true if this group is a knockout
*/
public boolean isKnockout()
{
return getCOSObject().getBoolean(COSName.K, false);
}
}
|
if (colorSpace == null && getCOSObject().containsKey(COSName.CS))
{
colorSpace = PDColorSpace.create(getCOSObject().getDictionaryObject(COSName.CS), resources);
}
return colorSpace;
| 564
| 67
| 631
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PNGConverter.java
|
PNGConverterState
|
parsePNGChunks
|
class PNGConverterState
{
List<Chunk> IDATs = new ArrayList<>();
@SuppressWarnings("SpellCheckingInspection") Chunk IHDR;
@SuppressWarnings("SpellCheckingInspection") Chunk PLTE;
Chunk iCCP;
Chunk tRNS;
Chunk sRGB;
Chunk gAMA;
Chunk cHRM;
// Parsed header fields
int width;
int height;
int bitsPerComponent;
}
private static int readInt(byte[] data, int offset)
{
int b1 = (data[offset] & 0xFF) << 24;
int b2 = (data[offset + 1] & 0xFF) << 16;
int b3 = (data[offset + 2] & 0xFF) << 8;
int b4 = (data[offset + 3] & 0xFF);
return b1 | b2 | b3 | b4;
}
private static float readPNGFloat(byte[] bytes, int offset)
{
int v = readInt(bytes, offset);
return v / 100000f;
}
/**
* Parse the PNG structure into the PNGConverterState. If we can't handle
* something, this method will return null.
*
* @param imageData the byte array with the PNG data
* @return null or the converter state with all relevant chunks
*/
private static PNGConverterState parsePNGChunks(byte[] imageData)
{<FILL_FUNCTION_BODY>
|
if (imageData.length < 20)
{
LOG.error("ByteArray way to small: {}", imageData.length);
return null;
}
PNGConverterState state = new PNGConverterState();
int ptr = 8;
int firstChunkType = readInt(imageData, ptr + 4);
if (firstChunkType != CHUNK_IHDR)
{
LOG.error(String.format("First Chunktype was %08X, not IHDR", firstChunkType));
return null;
}
while (ptr + 12 <= imageData.length)
{
int chunkLength = readInt(imageData, ptr);
int chunkType = readInt(imageData, ptr + 4);
ptr += 8;
if (ptr + chunkLength + 4 > imageData.length)
{
LOG.error(
"Not enough bytes. At offset {} are {} bytes expected. Overall length is {}",
ptr, chunkLength, imageData.length);
return null;
}
Chunk chunk = new Chunk();
chunk.chunkType = chunkType;
chunk.bytes = imageData;
chunk.start = ptr;
chunk.length = chunkLength;
switch (chunkType)
{
case CHUNK_IHDR:
if (state.IHDR != null)
{
LOG.error("Two IHDR chunks? There is something wrong.");
return null;
}
state.IHDR = chunk;
break;
case CHUNK_IDAT:
// The image data itself
state.IDATs.add(chunk);
break;
case CHUNK_PLTE:
// For indexed images the palette table
if (state.PLTE != null)
{
LOG.error("Two PLTE chunks? There is something wrong.");
return null;
}
state.PLTE = chunk;
break;
case CHUNK_IEND:
// We are done, return the state
return state;
case CHUNK_TRNS:
// For indexed images the alpha transparency table
if (state.tRNS != null)
{
LOG.error("Two tRNS chunks? There is something wrong.");
return null;
}
state.tRNS = chunk;
break;
case CHUNK_GAMA:
// Gama
state.gAMA = chunk;
break;
case CHUNK_CHRM:
// Chroma
state.cHRM = chunk;
break;
case CHUNK_ICCP:
// ICC Profile
state.iCCP = chunk;
break;
case CHUNK_SBIT:
LOG.debug("Can't convert PNGs with sBIT chunk.");
break;
case CHUNK_SRGB:
// We use the rendering intent from the chunk
state.sRGB = chunk;
break;
case CHUNK_TEXT:
case CHUNK_ZTXT:
case CHUNK_ITXT:
// We don't care about this text infos / metadata
break;
case CHUNK_KBKG:
// As we can handle transparency we don't need the background color information.
break;
case CHUNK_HIST:
// We don't need the color histogram
break;
case CHUNK_PHYS:
// The PDImageXObject will be placed by the user however he wants,
// so we can not enforce the physical dpi information stored here.
// We just ignore it.
break;
case CHUNK_SPLT:
// This palette stuff seems editor related, we don't need it.
break;
case CHUNK_TIME:
// We don't need the last image change time either
break;
default:
LOG.debug(String.format("Unknown chunk type %08X, skipping.", chunkType));
break;
}
ptr += chunkLength;
// Read the CRC
chunk.crc = readInt(imageData, ptr);
ptr += 4;
}
LOG.error("No IEND chunk found.");
return null;
| 416
| 1,085
| 1,501
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java
|
PDOptionalContentGroup
|
getRenderState
|
class PDOptionalContentGroup extends PDPropertyList
{
/**
* Creates a new optional content group (OCG).
* @param name the name of the content group
*/
public PDOptionalContentGroup(String name)
{
this.dict.setItem(COSName.TYPE, COSName.OCG);
setName(name);
}
/**
* Creates a new instance based on a given {@link COSDictionary}.
* @param dict the dictionary
*/
public PDOptionalContentGroup(COSDictionary dict)
{
super(dict);
if (!dict.getDictionaryObject(COSName.TYPE).equals(COSName.OCG))
{
throw new IllegalArgumentException(
"Provided dictionary is not of type '" + COSName.OCG + "'");
}
}
/**
* Enumeration for the renderState dictionary entry on the "Export", "View"
* and "Print" dictionary.
*/
public enum RenderState
{
/** The "ON" value. */
ON(COSName.ON),
/** The "OFF" value. */
OFF(COSName.OFF);
private final COSName name;
private RenderState(COSName value)
{
this.name = value;
}
/**
* Returns the base state represented by the given {@link COSName}.
*
* @param state the state name
* @return the state enum value
*/
public static RenderState valueOf(COSName state)
{
if (state == null)
{
return null;
}
return RenderState.valueOf(state.getName().toUpperCase());
}
/**
* Returns the PDF name for the state.
*
* @return the name of the state
*/
public COSName getName()
{
return this.name;
}
}
/**
* Returns the name of the optional content group.
* @return the name
*/
public String getName()
{
return dict.getString(COSName.NAME);
}
/**
* Sets the name of the optional content group.
* @param name the name
*/
public final void setName(String name)
{
dict.setString(COSName.NAME, name);
}
//TODO Add support for "Intent"
/**
* @param destination to be rendered
* @return state or null if undefined
*/
public RenderState getRenderState(RenderDestination destination)
{<FILL_FUNCTION_BODY>}
@Override
public String toString()
{
return super.toString() + " (" + getName() + ")";
}
}
|
COSName state = null;
COSDictionary usage = dict.getCOSDictionary(COSName.USAGE);
if (usage != null)
{
if (RenderDestination.PRINT == destination)
{
COSDictionary print = usage.getCOSDictionary(COSName.PRINT);
state = print == null ? null : print.getCOSName(COSName.PRINT_STATE);
}
else if (RenderDestination.VIEW == destination)
{
COSDictionary view = usage.getCOSDictionary(COSName.VIEW);
state = view == null ? null : view.getCOSName(COSName.VIEW_STATE);
}
// Fallback to export
if (state == null)
{
COSDictionary export = usage.getCOSDictionary(COSName.EXPORT);
state = export == null ? null : export.getCOSName(COSName.EXPORT_STATE);
}
}
return state == null ? null : RenderState.valueOf(state);
| 714
| 267
| 981
|
<methods>public static org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() <variables>protected final non-sealed org.apache.pdfbox.cos.COSDictionary dict
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentMembershipDictionary.java
|
PDOptionalContentMembershipDictionary
|
getOCGs
|
class PDOptionalContentMembershipDictionary extends PDPropertyList
{
/**
* Creates a new optional content membership dictionary (OCMD).
*/
public PDOptionalContentMembershipDictionary()
{
this.dict.setItem(COSName.TYPE, COSName.OCMD);
}
/**
* Creates a new instance based on a given {@link COSDictionary}.
* @param dict the dictionary
*/
public PDOptionalContentMembershipDictionary(COSDictionary dict)
{
super(dict);
if (!dict.getDictionaryObject(COSName.TYPE).equals(COSName.OCMD))
{
throw new IllegalArgumentException(
"Provided dictionary is not of type '" + COSName.OCMD + "'");
}
}
/**
* Get a list of optional content groups.
*
* @return List of optional content groups, never null.
*/
public List<PDPropertyList> getOCGs()
{<FILL_FUNCTION_BODY>}
/**
* Set optional content groups as a list.
*
* @param ocgs list of optional content groups to set.
*/
public void setOCGs(List<PDPropertyList> ocgs)
{
COSArray ar = new COSArray();
for (PDPropertyList prop : ocgs)
{
ar.add(prop);
}
dict.setItem(COSName.OCGS, ar);
}
/**
* Get the visibility policy name. Valid names are AllOff, AllOn, AnyOff, AnyOn (default).
*
* @return the visibility policy, never null.
*/
public COSName getVisibilityPolicy()
{
return dict.getCOSName(COSName.P, COSName.ANY_ON);
}
/**
* Sets the visibility policy name. Valid names are AllOff, AllOn, AnyOff, AnyOn (default).
*
* @param visibilityPolicy the visibility policy name
*/
public void setVisibilityPolicy(COSName visibilityPolicy)
{
dict.setItem(COSName.P, visibilityPolicy);
}
//TODO support /VE some day
}
|
COSBase base = dict.getDictionaryObject(COSName.OCGS);
if (base instanceof COSDictionary)
{
return Collections.singletonList(PDPropertyList.create((COSDictionary) base));
}
if (base instanceof COSArray)
{
List<PDPropertyList> list = new ArrayList<>();
COSArray ar = (COSArray) base;
for (int i = 0; i < ar.size(); ++i)
{
COSBase elem = ar.getObject(i);
if (elem instanceof COSDictionary)
{
list.add(PDPropertyList.create((COSDictionary) elem));
}
}
return list;
}
return Collections.emptyList();
| 572
| 193
| 765
|
<methods>public static org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList create(org.apache.pdfbox.cos.COSDictionary) ,public org.apache.pdfbox.cos.COSDictionary getCOSObject() <variables>protected final non-sealed org.apache.pdfbox.cos.COSDictionary dict
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDAbstractPattern.java
|
PDAbstractPattern
|
setMatrix
|
class PDAbstractPattern implements COSObjectable
{
/** Tiling pattern type. */
public static final int TYPE_TILING_PATTERN = 1;
/** Shading pattern type. */
public static final int TYPE_SHADING_PATTERN = 2;
/**
* Create the correct PD Model pattern based on the COS base pattern.
* @param dictionary the COS pattern dictionary
* @param resourceCache the resource cache, may be null, useful for tiling patterns.
* @return the newly created pattern object
* @throws IOException If we are unable to create the PDPattern object.
*/
public static PDAbstractPattern create(COSDictionary dictionary, ResourceCache resourceCache) throws IOException
{
PDAbstractPattern pattern;
int patternType = dictionary.getInt(COSName.PATTERN_TYPE, 0);
switch (patternType)
{
case TYPE_TILING_PATTERN:
pattern = new PDTilingPattern(dictionary, resourceCache);
break;
case TYPE_SHADING_PATTERN:
pattern = new PDShadingPattern(dictionary);
break;
default:
throw new IOException("Error: Unknown pattern type " + patternType);
}
return pattern;
}
private final COSDictionary patternDictionary;
/**
* Creates a new Pattern dictionary.
*/
public PDAbstractPattern()
{
patternDictionary = new COSDictionary();
patternDictionary.setName(COSName.TYPE, COSName.PATTERN.getName());
}
/**
* Creates a new Pattern dictionary from the given COS dictionary.
* @param dictionary The COSDictionary for this pattern.
*/
public PDAbstractPattern(COSDictionary dictionary)
{
patternDictionary = dictionary;
}
/**
* This will get the underlying dictionary.
* @return The dictionary for this pattern.
*/
@Override
public COSDictionary getCOSObject()
{
return patternDictionary;
}
/**
* This will set the paint type.
* @param paintType The new paint type.
*/
public void setPaintType(int paintType)
{
patternDictionary.setInt(COSName.PAINT_TYPE, paintType);
}
/**
* This will return the paint type.
* @return The type of object that this is.
*/
public String getType()
{
return COSName.PATTERN.getName();
}
/**
* This will set the pattern type.
* @param patternType The new pattern type.
*/
public void setPatternType(int patternType)
{
patternDictionary.setInt(COSName.PATTERN_TYPE, patternType);
}
/**
* This will return the pattern type.
* @return The pattern type
*/
public abstract int getPatternType();
/**
* Returns the pattern matrix, or the identity matrix is none is available.
*
* @return the pattern matrix
*/
public Matrix getMatrix()
{
return Matrix.createMatrix(getCOSObject().getDictionaryObject(COSName.MATRIX));
}
/**
* Sets the optional Matrix entry for the Pattern.
* @param transform the transformation matrix
*/
public void setMatrix(AffineTransform transform)
{<FILL_FUNCTION_BODY>}
}
|
COSArray matrix = new COSArray();
double[] values = new double[6];
transform.getMatrix(values);
for (double v : values)
{
matrix.add(new COSFloat((float)v));
}
getCOSObject().setItem(COSName.MATRIX, matrix);
| 872
| 86
| 958
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDShadingPattern.java
|
PDShadingPattern
|
getExtendedGraphicsState
|
class PDShadingPattern extends PDAbstractPattern
{
private PDExtendedGraphicsState extendedGraphicsState;
private PDShading shading;
/**
* Creates a new shading pattern.
*/
public PDShadingPattern()
{
getCOSObject().setInt(COSName.PATTERN_TYPE, PDAbstractPattern.TYPE_SHADING_PATTERN);
}
/**
* Creates a new shading pattern from the given COS dictionary.
* @param resourceDictionary The COSDictionary for this pattern resource.
*/
public PDShadingPattern(COSDictionary resourceDictionary)
{
super(resourceDictionary);
}
@Override
public int getPatternType()
{
return PDAbstractPattern.TYPE_SHADING_PATTERN;
}
/**
* This will get the external graphics state for this pattern.
* @return The extended graphics state for this pattern.
*/
public PDExtendedGraphicsState getExtendedGraphicsState()
{<FILL_FUNCTION_BODY>}
/**
* This will set the external graphics state for this pattern.
* @param extendedGraphicsState The new extended graphics state for this pattern.
*/
public void setExtendedGraphicsState(PDExtendedGraphicsState extendedGraphicsState)
{
this.extendedGraphicsState = extendedGraphicsState;
getCOSObject().setItem(COSName.EXT_G_STATE, extendedGraphicsState);
}
/**
* This will get the shading resources for this pattern.
* @return The shading resources for this pattern.
* @throws IOException if something went wrong
*/
public PDShading getShading() throws IOException
{
if (shading == null)
{
COSDictionary base = getCOSObject().getCOSDictionary(COSName.SHADING);
if (base != null)
{
shading = PDShading.create(base);
}
}
return shading;
}
/**
* This will set the shading resources for this pattern.
* @param shadingResources The new shading resources for this pattern.
*/
public void setShading( PDShading shadingResources )
{
shading = shadingResources;
getCOSObject().setItem(COSName.SHADING, shadingResources);
}
}
|
if (extendedGraphicsState == null)
{
COSDictionary base = getCOSObject().getCOSDictionary(COSName.EXT_G_STATE);
if (base != null)
{
extendedGraphicsState = new PDExtendedGraphicsState(base);
}
}
return extendedGraphicsState;
| 606
| 85
| 691
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public static org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern create(org.apache.pdfbox.cos.COSDictionary, org.apache.pdfbox.pdmodel.ResourceCache) throws java.io.IOException,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.util.Matrix getMatrix() ,public abstract int getPatternType() ,public java.lang.String getType() ,public void setMatrix(java.awt.geom.AffineTransform) ,public void setPaintType(int) ,public void setPatternType(int) <variables>public static final int TYPE_SHADING_PATTERN,public static final int TYPE_TILING_PATTERN,private final non-sealed org.apache.pdfbox.cos.COSDictionary patternDictionary
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java
|
PDTilingPattern
|
getContents
|
class PDTilingPattern extends PDAbstractPattern implements PDContentStream
{
/** paint type 1 = colored tiling pattern. */
public static final int PAINT_COLORED = 1;
/** paint type 2 = uncolored tiling pattern. */
public static final int PAINT_UNCOLORED = 2;
/** tiling type 1 = constant spacing.*/
public static final int TILING_CONSTANT_SPACING = 1;
/** tiling type 2 = no distortion. */
public static final int TILING_NO_DISTORTION = 2;
/** tiling type 3 = constant spacing and faster tiling. */
public static final int TILING_CONSTANT_SPACING_FASTER_TILING = 3;
private final ResourceCache resourceCache;
/**
* Creates a new tiling pattern.
*/
public PDTilingPattern()
{
super(new COSStream());
getCOSObject().setName(COSName.TYPE, COSName.PATTERN.getName());
getCOSObject().setInt(COSName.PATTERN_TYPE, PDAbstractPattern.TYPE_TILING_PATTERN);
// Resources required per PDF specification; when missing, pattern is not displayed in Adobe Reader
setResources(new PDResources());
resourceCache = null;
}
/**
* Creates a new tiling pattern from the given COS dictionary.
* @param dictionary The COSDictionary for this pattern.
*/
public PDTilingPattern(COSDictionary dictionary)
{
this(dictionary, null);
}
/**
* Creates a new tiling pattern from the given COS dictionary.
* @param dictionary The COSDictionary for this pattern.
* @param resourceCache The resource cache, may be null
*/
public PDTilingPattern(COSDictionary dictionary, ResourceCache resourceCache)
{
super(dictionary);
this.resourceCache = resourceCache;
}
@Override
public int getPatternType()
{
return PDAbstractPattern.TYPE_TILING_PATTERN;
}
/**
* This will set the paint type.
* @param paintType The new paint type.
*/
@Override
public void setPaintType(int paintType)
{
getCOSObject().setInt(COSName.PAINT_TYPE, paintType);
}
/**
* This will return the paint type.
* @return The paint type
*/
public int getPaintType()
{
return getCOSObject().getInt( COSName.PAINT_TYPE, 0 );
}
/**
* This will set the tiling type.
* @param tilingType The new tiling type.
*/
public void setTilingType(int tilingType)
{
getCOSObject().setInt(COSName.TILING_TYPE, tilingType);
}
/**
* This will return the tiling type.
* @return The tiling type
*/
public int getTilingType()
{
return getCOSObject().getInt( COSName.TILING_TYPE, 0 );
}
/**
* This will set the XStep value.
* @param xStep The new XStep value.
*/
public void setXStep(float xStep)
{
getCOSObject().setFloat(COSName.X_STEP, xStep);
}
/**
* This will return the XStep value.
* @return The XStep value
*/
public float getXStep()
{
return getCOSObject().getFloat(COSName.X_STEP, 0);
}
/**
* This will set the YStep value.
* @param yStep The new YStep value.
*/
public void setYStep(float yStep)
{
getCOSObject().setFloat(COSName.Y_STEP, yStep);
}
/**
* This will return the YStep value.
* @return The YStep value
*/
public float getYStep()
{
return getCOSObject().getFloat(COSName.Y_STEP, 0);
}
public PDStream getContentStream()
{
return new PDStream((COSStream)getCOSObject());
}
@Override
public InputStream getContents() throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public RandomAccessRead getContentsForRandomAccess() throws IOException
{
COSDictionary dict = getCOSObject();
if (dict instanceof COSStream)
{
return ((COSStream) getCOSObject()).createView();
}
return null;
}
/**
* This will get the resources for this pattern.
* This will return null if no resources are available at this level.
* @return The resources for this pattern.
*/
@Override
public PDResources getResources()
{
COSDictionary resources = getCOSObject().getCOSDictionary(COSName.RESOURCES);
return resources != null ? new PDResources(resources, resourceCache) : null;
}
/**
* This will set the resources for this pattern.
* @param resources The new resources for this pattern.
*/
public final void setResources( PDResources resources )
{
getCOSObject().setItem(COSName.RESOURCES, resources);
}
/**
* An array of four numbers in the form coordinate system (see
* below), giving the coordinates of the left, bottom, right, and top edges,
* respectively, of the pattern's bounding box.
*
* @return The BBox of the pattern.
*/
@Override
public PDRectangle getBBox()
{
COSArray bbox = getCOSObject().getCOSArray(COSName.BBOX);
return bbox != null ? new PDRectangle(bbox) : null;
}
/**
* This will set the BBox (bounding box) for this Pattern.
* @param bbox The new BBox for this Pattern.
*/
public void setBBox(PDRectangle bbox)
{
if( bbox == null )
{
getCOSObject().removeItem( COSName.BBOX );
}
else
{
getCOSObject().setItem( COSName.BBOX, bbox.getCOSArray() );
}
}
}
|
RandomAccessRead contentsForRandomAccess = getContentsForRandomAccess();
return contentsForRandomAccess != null
? new RandomAccessInputStream(contentsForRandomAccess) : null;
| 1,686
| 45
| 1,731
|
<methods>public void <init>() ,public void <init>(org.apache.pdfbox.cos.COSDictionary) ,public static org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern create(org.apache.pdfbox.cos.COSDictionary, org.apache.pdfbox.pdmodel.ResourceCache) throws java.io.IOException,public org.apache.pdfbox.cos.COSDictionary getCOSObject() ,public org.apache.pdfbox.util.Matrix getMatrix() ,public abstract int getPatternType() ,public java.lang.String getType() ,public void setMatrix(java.awt.geom.AffineTransform) ,public void setPaintType(int) ,public void setPatternType(int) <variables>public static final int TYPE_SHADING_PATTERN,public static final int TYPE_TILING_PATTERN,private final non-sealed org.apache.pdfbox.cos.COSDictionary patternDictionary
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingPaint.java
|
AxialShadingPaint
|
createContext
|
class AxialShadingPaint extends ShadingPaint<PDShadingType2>
{
private static final Logger LOG = LogManager.getLogger(AxialShadingPaint.class);
/**
* Constructor.
*
* @param shadingType2 the shading resources
* @param matrix the pattern matrix concatenated with that of the parent content stream
*/
AxialShadingPaint(PDShadingType2 shadingType2, Matrix matrix)
{
super(shadingType2, matrix);
}
@Override
public int getTransparency()
{
return 0;
}
@Override
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
AffineTransform xform, RenderingHints hints)
{<FILL_FUNCTION_BODY>}
}
|
try
{
return new AxialShadingContext(shading, cm, xform, matrix, deviceBounds);
}
catch (IOException e)
{
LOG.error("An error occurred while painting", e);
return new Color(0, 0, 0, 0).createContext(cm, deviceBounds, userBounds, xform, hints);
}
| 249
| 106
| 355
|
<methods>public org.apache.pdfbox.util.Matrix getMatrix() ,public org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType2 getShading() <variables>protected final non-sealed org.apache.pdfbox.util.Matrix matrix,protected final non-sealed org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType2 shading
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CubicBezierCurve.java
|
CubicBezierCurve
|
getPoints
|
class CubicBezierCurve
{
private final Point2D[] controlPoints;
private final int level;
private final Point2D[] curve;
/**
* Constructor of CubicBezierCurve
*
* @param ctrlPnts 4 control points [p0, p1, p2, p3]
* @param l dividing level, if l = 0, one cubic Bezier curve is divided
* into 2^0 = 1 segments, if l = n, one cubic Bezier curve is divided into
* 2^n segments
*/
CubicBezierCurve(Point2D[] ctrlPnts, int l)
{
controlPoints = ctrlPnts.clone();
level = l;
curve = getPoints(level);
}
/**
* Get level parameter
*
* @return level
*/
int getLevel()
{
return level;
}
// calculate sampled points on the cubic Bezier curve defined by the 4 given control points
private Point2D[] getPoints(int l)
{<FILL_FUNCTION_BODY>}
/**
* Get sampled points of this cubic Bezier curve.
*
* @return sampled points
*/
Point2D[] getCubicBezierCurve()
{
return curve;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
for (Point2D p : controlPoints)
{
if (sb.length() > 0)
{
sb.append(' ');
}
sb.append(p);
}
return "Cubic Bezier curve{control points p0, p1, p2, p3: " + sb + "}";
}
}
|
if (l < 0)
{
l = 0;
}
int sz = (1 << l) + 1;
Point2D[] res = new Point2D[sz];
double step = (double) 1 / (sz - 1);
double t = -step;
for (int i = 0; i < sz; i++)
{
t += step;
double tmpX = (1 - t) * (1 - t) * (1 - t) * controlPoints[0].getX()
+ 3 * t * (1 - t) * (1 - t) * controlPoints[1].getX()
+ 3 * t * t * (1 - t) * controlPoints[2].getX()
+ t * t * t * controlPoints[3].getX();
double tmpY = (1 - t) * (1 - t) * (1 - t) * controlPoints[0].getY()
+ 3 * t * (1 - t) * (1 - t) * controlPoints[1].getY()
+ 3 * t * t * (1 - t) * controlPoints[2].getY()
+ t * t * t * controlPoints[3].getY();
res[i] = new Point2D.Double(tmpX, tmpY);
}
return res;
| 455
| 331
| 786
|
<no_super_class>
|
apache_pdfbox
|
pdfbox/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java
|
GouraudShadingContext
|
calcPixelTable
|
class GouraudShadingContext extends TriangleBasedShadingContext
{
/**
* triangle list.
*/
private List<ShadedTriangle> triangleList = new ArrayList<>();
/**
* Constructor creates an instance to be used for fill operations.
*
* @param shading the shading type to be used
* @param colorModel the color model to be used
* @param xform transformation for user to device space
* @param matrix the pattern matrix concatenated with that of the parent content stream
* @throws IOException if something went wrong
*/
protected GouraudShadingContext(PDShading shading, ColorModel colorModel, AffineTransform xform,
Matrix matrix) throws IOException
{
super(shading, colorModel, xform, matrix);
}
final void setTriangleList(List<ShadedTriangle> triangleList)
{
this.triangleList = triangleList;
}
@Override
protected Map<Point, Integer> calcPixelTable(Rectangle deviceBounds) throws IOException
{<FILL_FUNCTION_BODY>}
@Override
public void dispose()
{
triangleList = null;
super.dispose();
}
@Override
protected boolean isDataEmpty()
{
return triangleList.isEmpty();
}
}
|
Map<Point, Integer> map = new HashMap<>();
super.calcPixelTable(triangleList, map, deviceBounds);
return map;
| 334
| 41
| 375
|
<methods>public final java.awt.image.Raster getRaster(int, int, int, int) <variables>private Map<java.awt.Point,java.lang.Integer> pixelTable
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.