idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
5,100
public int getNextCode ( ) { try { nextData = ( nextData << 8 ) | ( data [ bytePointer ++ ] & 0xff ) ; nextBits += 8 ; if ( nextBits < bitsToGet ) { nextData = ( nextData << 8 ) | ( data [ bytePointer ++ ] & 0xff ) ; nextBits += 8 ; } int code = ( nextData >> ( nextBits - bitsToGet ) ) & andTable [ bitsToGet - 9 ] ; nextBits -= bitsToGet ; return code ; } catch ( ArrayIndexOutOfBoundsException e ) { return 257 ; } }
Returns the next 9 10 11 or 12 bits
5,101
public static Set getKeySet ( Hashtable table ) { return ( table == null ) ? Collections . EMPTY_SET : table . keySet ( ) ; }
Gets the keys of a Hashtable
5,102
public static Object [ ] [ ] addToArray ( Object original [ ] [ ] , Object item [ ] ) { if ( original == null ) { original = new Object [ 1 ] [ ] ; original [ 0 ] = item ; return original ; } else { Object original2 [ ] [ ] = new Object [ original . length + 1 ] [ ] ; System . arraycopy ( original , 0 , original2 , 0 , original . length ) ; original2 [ original . length ] = item ; return original2 ; } }
Utility method to extend an array .
5,103
public static String unEscapeURL ( String src ) { StringBuffer bf = new StringBuffer ( ) ; char [ ] s = src . toCharArray ( ) ; for ( int k = 0 ; k < s . length ; ++ k ) { char c = s [ k ] ; if ( c == '%' ) { if ( k + 2 >= s . length ) { bf . append ( c ) ; continue ; } int a0 = PRTokeniser . getHex ( s [ k + 1 ] ) ; int a1 = PRTokeniser . getHex ( s [ k + 2 ] ) ; if ( a0 < 0 || a1 < 0 ) { bf . append ( c ) ; continue ; } bf . append ( ( char ) ( a0 * 16 + a1 ) ) ; k += 2 ; } else bf . append ( c ) ; } return bf . toString ( ) ; }
Unescapes an URL . All the %xx are replaced by the xx hex char value .
5,104
public static int convertToUtf32 ( String text , int idx ) { return ( ( ( text . charAt ( idx ) - 0xd800 ) * 0x400 ) + ( text . charAt ( idx + 1 ) - 0xdc00 ) ) + 0x10000 ; }
Converts a unicode character in a String to a UTF32 code point value
5,105
public static String getPermissionsVerbose ( int permissions ) { StringBuffer buf = new StringBuffer ( "Allowed:" ) ; if ( ( PdfWriter . ALLOW_PRINTING & permissions ) == PdfWriter . ALLOW_PRINTING ) buf . append ( " Printing" ) ; if ( ( PdfWriter . ALLOW_MODIFY_CONTENTS & permissions ) == PdfWriter . ALLOW_MODIFY_CONTENTS ) buf . append ( " Modify contents" ) ; if ( ( PdfWriter . ALLOW_COPY & permissions ) == PdfWriter . ALLOW_COPY ) buf . append ( " Copy" ) ; if ( ( PdfWriter . ALLOW_MODIFY_ANNOTATIONS & permissions ) == PdfWriter . ALLOW_MODIFY_ANNOTATIONS ) buf . append ( " Modify annotations" ) ; if ( ( PdfWriter . ALLOW_FILL_IN & permissions ) == PdfWriter . ALLOW_FILL_IN ) buf . append ( " Fill in" ) ; if ( ( PdfWriter . ALLOW_SCREENREADERS & permissions ) == PdfWriter . ALLOW_SCREENREADERS ) buf . append ( " Screen readers" ) ; if ( ( PdfWriter . ALLOW_ASSEMBLY & permissions ) == PdfWriter . ALLOW_ASSEMBLY ) buf . append ( " Assembly" ) ; if ( ( PdfWriter . ALLOW_DEGRADED_PRINTING & permissions ) == PdfWriter . ALLOW_DEGRADED_PRINTING ) buf . append ( " Degraded printing" ) ; return buf . toString ( ) ; }
Give you a verbose analysis of the permissions .
5,106
public void flateCompress ( int compressionLevel ) { if ( ! Document . compress ) return ; if ( compressed ) { return ; } this . compressionLevel = compressionLevel ; if ( inputStream != null ) { compressed = true ; return ; } PdfObject filter = PdfReader . getPdfObject ( get ( PdfName . FILTER ) ) ; if ( filter != null ) { if ( filter . isName ( ) ) { if ( PdfName . FLATEDECODE . equals ( filter ) ) return ; } else if ( filter . isArray ( ) ) { if ( ( ( PdfArray ) filter ) . contains ( PdfName . FLATEDECODE ) ) return ; } else { throw new RuntimeException ( "Stream could not be compressed: filter is not a name or array." ) ; } } try { ByteArrayOutputStream stream = new ByteArrayOutputStream ( ) ; Deflater deflater = new Deflater ( compressionLevel ) ; DeflaterOutputStream zip = new DeflaterOutputStream ( stream , deflater ) ; if ( streamBytes != null ) streamBytes . writeTo ( zip ) ; else zip . write ( bytes ) ; zip . close ( ) ; deflater . end ( ) ; streamBytes = stream ; bytes = null ; put ( PdfName . LENGTH , new PdfNumber ( streamBytes . size ( ) ) ) ; if ( filter == null ) { put ( PdfName . FILTER , PdfName . FLATEDECODE ) ; } else { PdfArray filters = new PdfArray ( filter ) ; filters . add ( PdfName . FLATEDECODE ) ; put ( PdfName . FILTER , filters ) ; } compressed = true ; } catch ( IOException ioe ) { throw new ExceptionConverter ( ioe ) ; } }
Compresses the stream .
5,107
public static char decodeEntity ( String name ) { if ( name . startsWith ( "#x" ) ) { try { return ( char ) Integer . parseInt ( name . substring ( 2 ) , 16 ) ; } catch ( NumberFormatException nfe ) { return '\0' ; } } if ( name . startsWith ( "#" ) ) { try { return ( char ) Integer . parseInt ( name . substring ( 1 ) ) ; } catch ( NumberFormatException nfe ) { return '\0' ; } } Character c = ( Character ) map . get ( name ) ; if ( c == null ) return '\0' ; else return c . charValue ( ) ; }
Translates an entity to a unicode character .
5,108
int CountCharset ( int Offset , int NumofGlyphs ) { int format ; int Length = 0 ; seek ( Offset ) ; format = getCard8 ( ) ; switch ( format ) { case 0 : Length = 1 + 2 * NumofGlyphs ; break ; case 1 : Length = 1 + 3 * CountRange ( NumofGlyphs , 1 ) ; break ; case 2 : Length = 1 + 4 * CountRange ( NumofGlyphs , 2 ) ; break ; default : break ; } return Length ; }
Calculates the length of the charset according to its format
5,109
int CountRange ( int NumofGlyphs , int Type ) { int num = 0 ; @ SuppressWarnings ( "unused" ) char Sid ; int i = 1 , nLeft ; while ( i < NumofGlyphs ) { num ++ ; Sid = getCard16 ( ) ; if ( Type == 1 ) nLeft = getCard8 ( ) ; else nLeft = getCard16 ( ) ; i += nLeft + 1 ; } return num ; }
Function calculates the number of ranges in the Charset
5,110
protected void readFDSelect ( int Font ) { int NumOfGlyphs = fonts [ Font ] . nglyphs ; int [ ] FDSelect = new int [ NumOfGlyphs ] ; seek ( fonts [ Font ] . fdselectOffset ) ; fonts [ Font ] . FDSelectFormat = getCard8 ( ) ; switch ( fonts [ Font ] . FDSelectFormat ) { case 0 : for ( int i = 0 ; i < NumOfGlyphs ; i ++ ) { FDSelect [ i ] = getCard8 ( ) ; } fonts [ Font ] . FDSelectLength = fonts [ Font ] . nglyphs + 1 ; break ; case 3 : int nRanges = getCard16 ( ) ; int l = 0 ; int first = getCard16 ( ) ; for ( int i = 0 ; i < nRanges ; i ++ ) { int fd = getCard8 ( ) ; int last = getCard16 ( ) ; int steps = last - first ; for ( int k = 0 ; k < steps ; k ++ ) { FDSelect [ l ] = fd ; l ++ ; } first = last ; } fonts [ Font ] . FDSelectLength = 1 + 2 + nRanges * 3 + 2 ; break ; default : break ; } fonts [ Font ] . FDSelect = FDSelect ; }
Read the FDSelect of the font and compute the array and its length
5,111
protected void BuildFDArrayUsed ( int Font ) { int [ ] FDSelect = fonts [ Font ] . FDSelect ; for ( int i = 0 ; i < glyphsInList . size ( ) ; i ++ ) { int glyph = ( ( Integer ) glyphsInList . get ( i ) ) . intValue ( ) ; int FD = FDSelect [ glyph ] ; FDArrayUsed . put ( Integer . valueOf ( FD ) , null ) ; } }
Function reads the FDSelect and builds the FDArrayUsed HashMap According to the glyphs used
5,112
protected void ReadFDArray ( int Font ) { seek ( fonts [ Font ] . fdarrayOffset ) ; fonts [ Font ] . FDArrayCount = getCard16 ( ) ; fonts [ Font ] . FDArrayOffsize = getCard8 ( ) ; if ( fonts [ Font ] . FDArrayOffsize < 4 ) fonts [ Font ] . FDArrayOffsize ++ ; fonts [ Font ] . FDArrayOffsets = getIndex ( fonts [ Font ] . fdarrayOffset ) ; }
Read the FDArray count offsize and Offset array
5,113
public byte [ ] Process ( String fontName ) throws IOException { try { buf . reOpen ( ) ; int j ; for ( j = 0 ; j < fonts . length ; j ++ ) if ( fontName . equals ( fonts [ j ] . name ) ) break ; if ( j == fonts . length ) return null ; if ( gsubrIndexOffset >= 0 ) GBias = CalcBias ( gsubrIndexOffset , j ) ; BuildNewCharString ( j ) ; BuildNewLGSubrs ( j ) ; byte [ ] Ret = BuildNewFile ( j ) ; return Ret ; } finally { try { buf . close ( ) ; } catch ( Exception e ) { } } }
The Process function extracts one font out of the CFF file and returns a subset version of the original .
5,114
protected int CalcBias ( int Offset , int Font ) { seek ( Offset ) ; int nSubrs = getCard16 ( ) ; if ( fonts [ Font ] . CharstringType == 1 ) return 0 ; else if ( nSubrs < 1240 ) return 107 ; else if ( nSubrs < 33900 ) return 1131 ; else return 32768 ; }
Function calcs bias according to the CharString type and the count of the subrs
5,115
protected void BuildNewCharString ( int FontIndex ) throws IOException { NewCharStringsIndex = BuildNewIndex ( fonts [ FontIndex ] . charstringsOffsets , GlyphsUsed , ENDCHAR_OP ) ; }
Function uses BuildNewIndex to create the new index of the subset charstrings
5,116
protected void BuildNewLGSubrs ( int Font ) throws IOException { if ( fonts [ Font ] . isCID ) { hSubrsUsed = new HashMap [ fonts [ Font ] . fdprivateOffsets . length ] ; lSubrsUsed = new ArrayList [ fonts [ Font ] . fdprivateOffsets . length ] ; NewLSubrsIndex = new byte [ fonts [ Font ] . fdprivateOffsets . length ] [ ] ; fonts [ Font ] . PrivateSubrsOffset = new int [ fonts [ Font ] . fdprivateOffsets . length ] ; fonts [ Font ] . PrivateSubrsOffsetsArray = new int [ fonts [ Font ] . fdprivateOffsets . length ] [ ] ; ArrayList FDInList = new ArrayList ( FDArrayUsed . keySet ( ) ) ; for ( int j = 0 ; j < FDInList . size ( ) ; j ++ ) { int FD = ( ( Integer ) FDInList . get ( j ) ) . intValue ( ) ; hSubrsUsed [ FD ] = new HashMap ( ) ; lSubrsUsed [ FD ] = new ArrayList ( ) ; BuildFDSubrsOffsets ( Font , FD ) ; if ( fonts [ Font ] . PrivateSubrsOffset [ FD ] >= 0 ) { BuildSubrUsed ( Font , FD , fonts [ Font ] . PrivateSubrsOffset [ FD ] , fonts [ Font ] . PrivateSubrsOffsetsArray [ FD ] , hSubrsUsed [ FD ] , lSubrsUsed [ FD ] ) ; NewLSubrsIndex [ FD ] = BuildNewIndex ( fonts [ Font ] . PrivateSubrsOffsetsArray [ FD ] , hSubrsUsed [ FD ] , RETURN_OP ) ; } } } else if ( fonts [ Font ] . privateSubrs >= 0 ) { fonts [ Font ] . SubrsOffsets = getIndex ( fonts [ Font ] . privateSubrs ) ; BuildSubrUsed ( Font , - 1 , fonts [ Font ] . privateSubrs , fonts [ Font ] . SubrsOffsets , hSubrsUsedNonCID , lSubrsUsedNonCID ) ; } BuildGSubrsUsed ( Font ) ; if ( fonts [ Font ] . privateSubrs >= 0 ) NewSubrsIndexNonCID = BuildNewIndex ( fonts [ Font ] . SubrsOffsets , hSubrsUsedNonCID , RETURN_OP ) ; NewGSubrsIndex = BuildNewIndex ( gsubrOffsets , hGSubrsUsed , RETURN_OP ) ; }
Function builds the new local & global subsrs indices . IF CID then All of the FD Array lsubrs will be subsetted .
5,117
protected void BuildFDSubrsOffsets ( int Font , int FD ) { fonts [ Font ] . PrivateSubrsOffset [ FD ] = - 1 ; seek ( fonts [ Font ] . fdprivateOffsets [ FD ] ) ; while ( getPosition ( ) < fonts [ Font ] . fdprivateOffsets [ FD ] + fonts [ Font ] . fdprivateLengths [ FD ] ) { getDictItem ( ) ; if ( key == "Subrs" ) fonts [ Font ] . PrivateSubrsOffset [ FD ] = ( ( Integer ) args [ 0 ] ) . intValue ( ) + fonts [ Font ] . fdprivateOffsets [ FD ] ; } if ( fonts [ Font ] . PrivateSubrsOffset [ FD ] >= 0 ) fonts [ Font ] . PrivateSubrsOffsetsArray [ FD ] = getIndex ( fonts [ Font ] . PrivateSubrsOffset [ FD ] ) ; }
The function finds for the FD array processed the local subr offset and its offset array .
5,118
protected void BuildGSubrsUsed ( int Font ) { int LBias = 0 ; int SizeOfNonCIDSubrsUsed = 0 ; if ( fonts [ Font ] . privateSubrs >= 0 ) { LBias = CalcBias ( fonts [ Font ] . privateSubrs , Font ) ; SizeOfNonCIDSubrsUsed = lSubrsUsedNonCID . size ( ) ; } for ( int i = 0 ; i < lGSubrsUsed . size ( ) ; i ++ ) { int Subr = ( ( Integer ) lGSubrsUsed . get ( i ) ) . intValue ( ) ; if ( Subr < gsubrOffsets . length - 1 && Subr >= 0 ) { int Start = gsubrOffsets [ Subr ] ; int End = gsubrOffsets [ Subr + 1 ] ; if ( fonts [ Font ] . isCID ) ReadASubr ( Start , End , GBias , 0 , hGSubrsUsed , lGSubrsUsed , null ) ; else { ReadASubr ( Start , End , GBias , LBias , hSubrsUsedNonCID , lSubrsUsedNonCID , fonts [ Font ] . SubrsOffsets ) ; if ( SizeOfNonCIDSubrsUsed < lSubrsUsedNonCID . size ( ) ) { for ( int j = SizeOfNonCIDSubrsUsed ; j < lSubrsUsedNonCID . size ( ) ; j ++ ) { int LSubr = ( ( Integer ) lSubrsUsedNonCID . get ( j ) ) . intValue ( ) ; if ( LSubr < fonts [ Font ] . SubrsOffsets . length - 1 && LSubr >= 0 ) { int LStart = fonts [ Font ] . SubrsOffsets [ LSubr ] ; int LEnd = fonts [ Font ] . SubrsOffsets [ LSubr + 1 ] ; ReadASubr ( LStart , LEnd , GBias , LBias , hSubrsUsedNonCID , lSubrsUsedNonCID , fonts [ Font ] . SubrsOffsets ) ; } } SizeOfNonCIDSubrsUsed = lSubrsUsedNonCID . size ( ) ; } } } } }
Function scans the Glsubr used ArrayList to find recursive calls to Gsubrs and adds to Hashmap & ArrayList
5,119
protected void HandelStack ( ) { int StackHandel = StackOpp ( ) ; if ( StackHandel < 2 ) { if ( StackHandel == 1 ) PushStack ( ) ; else { StackHandel *= - 1 ; for ( int i = 0 ; i < StackHandel ; i ++ ) PopStack ( ) ; } } else EmptyStack ( ) ; }
Function Checks how the current operator effects the run time stack after being run An operator may increase or decrease the stack size
5,120
protected int StackOpp ( ) { if ( key == "ifelse" ) return - 3 ; if ( key == "roll" || key == "put" ) return - 2 ; if ( key == "callsubr" || key == "callgsubr" || key == "add" || key == "sub" || key == "div" || key == "mul" || key == "drop" || key == "and" || key == "or" || key == "eq" ) return - 1 ; if ( key == "abs" || key == "neg" || key == "sqrt" || key == "exch" || key == "index" || key == "get" || key == "not" || key == "return" ) return 0 ; if ( key == "random" || key == "dup" ) return 1 ; return 2 ; }
Function checks the key and return the change to the stack after the operator
5,121
protected void ReadCommand ( ) { key = null ; boolean gotKey = false ; while ( ! gotKey ) { char b0 = getCard8 ( ) ; if ( b0 == 28 ) { int first = getCard8 ( ) ; int second = getCard8 ( ) ; args [ arg_count ] = Integer . valueOf ( first << 8 | second ) ; arg_count ++ ; continue ; } if ( b0 >= 32 && b0 <= 246 ) { args [ arg_count ] = Integer . valueOf ( b0 - 139 ) ; arg_count ++ ; continue ; } if ( b0 >= 247 && b0 <= 250 ) { int w = getCard8 ( ) ; args [ arg_count ] = Integer . valueOf ( ( b0 - 247 ) * 256 + w + 108 ) ; arg_count ++ ; continue ; } if ( b0 >= 251 && b0 <= 254 ) { int w = getCard8 ( ) ; args [ arg_count ] = Integer . valueOf ( - ( b0 - 251 ) * 256 - w - 108 ) ; arg_count ++ ; continue ; } if ( b0 == 255 ) { int first = getCard8 ( ) ; int second = getCard8 ( ) ; int third = getCard8 ( ) ; int fourth = getCard8 ( ) ; args [ arg_count ] = Integer . valueOf ( first << 24 | second << 16 | third << 8 | fourth ) ; arg_count ++ ; continue ; } if ( b0 <= 31 && b0 != 28 ) { gotKey = true ; if ( b0 == 12 ) { int b1 = getCard8 ( ) ; if ( b1 > SubrsEscapeFuncs . length - 1 ) b1 = SubrsEscapeFuncs . length - 1 ; key = SubrsEscapeFuncs [ b1 ] ; } else key = SubrsFunctions [ b0 ] ; continue ; } } }
The function reads the next command after the file pointer is set
5,122
protected int CalcHints ( int begin , int end , int LBias , int GBias , int [ ] LSubrsOffsets ) { seek ( begin ) ; while ( getPosition ( ) < end ) { ReadCommand ( ) ; int pos = getPosition ( ) ; Object TopElement = null ; if ( arg_count > 0 ) TopElement = args [ arg_count - 1 ] ; int NumOfArgs = arg_count ; HandelStack ( ) ; if ( key == "callsubr" ) { if ( NumOfArgs > 0 ) { int Subr = ( ( Integer ) TopElement ) . intValue ( ) + LBias ; CalcHints ( LSubrsOffsets [ Subr ] , LSubrsOffsets [ Subr + 1 ] , LBias , GBias , LSubrsOffsets ) ; seek ( pos ) ; } } else if ( key == "callgsubr" ) { if ( NumOfArgs > 0 ) { int Subr = ( ( Integer ) TopElement ) . intValue ( ) + GBias ; CalcHints ( gsubrOffsets [ Subr ] , gsubrOffsets [ Subr + 1 ] , LBias , GBias , LSubrsOffsets ) ; seek ( pos ) ; } } else if ( key == "hstem" || key == "vstem" || key == "hstemhm" || key == "vstemhm" ) NumOfHints += NumOfArgs / 2 ; else if ( key == "hintmask" || key == "cntrmask" ) { int SizeOfMask = NumOfHints / 8 ; if ( NumOfHints % 8 != 0 || SizeOfMask == 0 ) SizeOfMask ++ ; for ( int i = 0 ; i < SizeOfMask ; i ++ ) getCard8 ( ) ; } } return NumOfHints ; }
The function reads the subroutine and returns the number of the hint in it . If a call to another subroutine is found the function calls recursively .
5,123
protected byte [ ] BuildNewIndex ( int [ ] Offsets , HashMap Used , byte OperatorForUnusedEntries ) throws IOException { int unusedCount = 0 ; int Offset = 0 ; int [ ] NewOffsets = new int [ Offsets . length ] ; for ( int i = 0 ; i < Offsets . length ; ++ i ) { NewOffsets [ i ] = Offset ; if ( Used . containsKey ( Integer . valueOf ( i ) ) ) { Offset += Offsets [ i + 1 ] - Offsets [ i ] ; } else { unusedCount ++ ; } } byte [ ] NewObjects = new byte [ Offset + unusedCount ] ; int unusedOffset = 0 ; for ( int i = 0 ; i < Offsets . length - 1 ; ++ i ) { int start = NewOffsets [ i ] ; int end = NewOffsets [ i + 1 ] ; NewOffsets [ i ] = start + unusedOffset ; if ( start != end ) { buf . seek ( Offsets [ i ] ) ; buf . readFully ( NewObjects , start + unusedOffset , end - start ) ; } else { NewObjects [ start + unusedOffset ] = OperatorForUnusedEntries ; unusedOffset ++ ; } } NewOffsets [ Offsets . length - 1 ] += unusedOffset ; return AssembleIndex ( NewOffsets , NewObjects ) ; }
Function builds the new offset array object array and assembles the index . used for creating the glyph and subrs subsetted index
5,124
protected byte [ ] AssembleIndex ( int [ ] NewOffsets , byte [ ] NewObjects ) { char Count = ( char ) ( NewOffsets . length - 1 ) ; int Size = NewOffsets [ NewOffsets . length - 1 ] ; byte Offsize ; if ( Size <= 0xff ) Offsize = 1 ; else if ( Size <= 0xffff ) Offsize = 2 ; else if ( Size <= 0xffffff ) Offsize = 3 ; else Offsize = 4 ; byte [ ] NewIndex = new byte [ 2 + 1 + Offsize * ( Count + 1 ) + NewObjects . length ] ; int Place = 0 ; NewIndex [ Place ++ ] = ( byte ) ( ( Count >>> 8 ) & 0xff ) ; NewIndex [ Place ++ ] = ( byte ) ( ( Count >>> 0 ) & 0xff ) ; NewIndex [ Place ++ ] = Offsize ; for ( int i = 0 ; i < NewOffsets . length ; i ++ ) { int Num = NewOffsets [ i ] - NewOffsets [ 0 ] + 1 ; switch ( Offsize ) { case 4 : NewIndex [ Place ++ ] = ( byte ) ( ( Num >>> 24 ) & 0xff ) ; case 3 : NewIndex [ Place ++ ] = ( byte ) ( ( Num >>> 16 ) & 0xff ) ; case 2 : NewIndex [ Place ++ ] = ( byte ) ( ( Num >>> 8 ) & 0xff ) ; case 1 : NewIndex [ Place ++ ] = ( byte ) ( ( Num >>> 0 ) & 0xff ) ; } } for ( int i = 0 ; i < NewObjects . length ; i ++ ) { NewIndex [ Place ++ ] = NewObjects [ i ] ; } return NewIndex ; }
Function creates the new index inserting the count offsetsize offset array and object array .
5,125
protected void CopyHeader ( ) { seek ( 0 ) ; @ SuppressWarnings ( "unused" ) int major = getCard8 ( ) ; @ SuppressWarnings ( "unused" ) int minor = getCard8 ( ) ; int hdrSize = getCard8 ( ) ; @ SuppressWarnings ( "unused" ) int offSize = getCard8 ( ) ; nextIndexOffset = hdrSize ; OutputList . addLast ( new RangeItem ( buf , 0 , hdrSize ) ) ; }
Function Copies the header from the original fileto the output list
5,126
protected void BuildIndexHeader ( int Count , int Offsize , int First ) { OutputList . addLast ( new UInt16Item ( ( char ) Count ) ) ; OutputList . addLast ( new UInt8Item ( ( char ) Offsize ) ) ; switch ( Offsize ) { case 1 : OutputList . addLast ( new UInt8Item ( ( char ) First ) ) ; break ; case 2 : OutputList . addLast ( new UInt16Item ( ( char ) First ) ) ; break ; case 3 : OutputList . addLast ( new UInt24Item ( ( char ) First ) ) ; break ; case 4 : OutputList . addLast ( new UInt32Item ( ( char ) First ) ) ; break ; default : break ; } }
Function Build the header of an index
5,127
protected void CreateKeys ( OffsetItem fdarrayRef , OffsetItem fdselectRef , OffsetItem charsetRef , OffsetItem charstringsRef ) { OutputList . addLast ( fdarrayRef ) ; OutputList . addLast ( new UInt8Item ( ( char ) 12 ) ) ; OutputList . addLast ( new UInt8Item ( ( char ) 36 ) ) ; OutputList . addLast ( fdselectRef ) ; OutputList . addLast ( new UInt8Item ( ( char ) 12 ) ) ; OutputList . addLast ( new UInt8Item ( ( char ) 37 ) ) ; OutputList . addLast ( charsetRef ) ; OutputList . addLast ( new UInt8Item ( ( char ) 15 ) ) ; OutputList . addLast ( charstringsRef ) ; OutputList . addLast ( new UInt8Item ( ( char ) 17 ) ) ; }
Function adds the keys into the TopDict
5,128
protected void CreateNewStringIndex ( int Font ) { String fdFontName = fonts [ Font ] . name + "-OneRange" ; if ( fdFontName . length ( ) > 127 ) fdFontName = fdFontName . substring ( 0 , 127 ) ; String extraStrings = "Adobe" + "Identity" + fdFontName ; int origStringsLen = stringOffsets [ stringOffsets . length - 1 ] - stringOffsets [ 0 ] ; int stringsBaseOffset = stringOffsets [ 0 ] - 1 ; byte stringsIndexOffSize ; if ( origStringsLen + extraStrings . length ( ) <= 0xff ) stringsIndexOffSize = 1 ; else if ( origStringsLen + extraStrings . length ( ) <= 0xffff ) stringsIndexOffSize = 2 ; else if ( origStringsLen + extraStrings . length ( ) <= 0xffffff ) stringsIndexOffSize = 3 ; else stringsIndexOffSize = 4 ; OutputList . addLast ( new UInt16Item ( ( char ) ( ( stringOffsets . length - 1 ) + 3 ) ) ) ; OutputList . addLast ( new UInt8Item ( ( char ) stringsIndexOffSize ) ) ; for ( int i = 0 ; i < stringOffsets . length ; i ++ ) OutputList . addLast ( new IndexOffsetItem ( stringsIndexOffSize , stringOffsets [ i ] - stringsBaseOffset ) ) ; int currentStringsOffset = stringOffsets [ stringOffsets . length - 1 ] - stringsBaseOffset ; currentStringsOffset += "Adobe" . length ( ) ; OutputList . addLast ( new IndexOffsetItem ( stringsIndexOffSize , currentStringsOffset ) ) ; currentStringsOffset += "Identity" . length ( ) ; OutputList . addLast ( new IndexOffsetItem ( stringsIndexOffSize , currentStringsOffset ) ) ; currentStringsOffset += fdFontName . length ( ) ; OutputList . addLast ( new IndexOffsetItem ( stringsIndexOffSize , currentStringsOffset ) ) ; OutputList . addLast ( new RangeItem ( buf , stringOffsets [ 0 ] , origStringsLen ) ) ; OutputList . addLast ( new StringItem ( extraStrings ) ) ; }
Function takes the original string item and adds the new strings to accommodate the CID rules
5,129
int CalcSubrOffsetSize ( int Offset , int Size ) { int OffsetSize = 0 ; seek ( Offset ) ; while ( getPosition ( ) < Offset + Size ) { int p1 = getPosition ( ) ; getDictItem ( ) ; int p2 = getPosition ( ) ; if ( key == "Subrs" ) { OffsetSize = p2 - p1 - 1 ; } } return OffsetSize ; }
Calculates how many byte it took to write the offset for the subrs in a specific private dict .
5,130
protected int countEntireIndexRange ( int indexOffset ) { seek ( indexOffset ) ; int count = getCard16 ( ) ; if ( count == 0 ) return 2 ; else { int indexOffSize = getCard8 ( ) ; seek ( indexOffset + 2 + 1 + count * indexOffSize ) ; int size = getOffset ( indexOffSize ) - 1 ; return 2 + 1 + ( count + 1 ) * indexOffSize + size ; } }
Function computes the size of an index
5,131
void CreateNonCIDPrivate ( int Font , OffsetItem Subr ) { seek ( fonts [ Font ] . privateOffset ) ; while ( getPosition ( ) < fonts [ Font ] . privateOffset + fonts [ Font ] . privateLength ) { int p1 = getPosition ( ) ; getDictItem ( ) ; int p2 = getPosition ( ) ; if ( key == "Subrs" ) { OutputList . addLast ( Subr ) ; OutputList . addLast ( new UInt8Item ( ( char ) 19 ) ) ; } else OutputList . addLast ( new RangeItem ( buf , p1 , p2 - p1 ) ) ; } }
The function creates a private dict for a font that was not CID All the keys are copied as is except for the subrs key
5,132
void CreateNonCIDSubrs ( int Font , IndexBaseItem PrivateBase , OffsetItem Subrs ) { OutputList . addLast ( new SubrMarkerItem ( Subrs , PrivateBase ) ) ; OutputList . addLast ( new RangeItem ( new RandomAccessFileOrArray ( NewSubrsIndexNonCID ) , 0 , NewSubrsIndexNonCID . length ) ) ; }
the function marks the beginning of the subrs index and adds the subsetted subrs index to the output list .
5,133
public float getWidthPoint ( ) { if ( getImage ( ) != null ) { return getImage ( ) . getScaledWidth ( ) ; } return font . getCalculatedBaseFont ( true ) . getWidthPoint ( getContent ( ) , font . getCalculatedSize ( ) ) * getHorizontalScaling ( ) ; }
Gets the width of the Chunk in points .
5,134
private Chunk setAttribute ( String name , Object obj ) { if ( attributes == null ) attributes = new HashMap ( ) ; attributes . put ( name , obj ) ; return this ; }
Sets an arbitrary attribute .
5,135
public float getHorizontalScaling ( ) { if ( attributes == null ) return 1f ; Float f = ( Float ) attributes . get ( HSCALE ) ; if ( f == null ) return 1f ; return f . floatValue ( ) ; }
Gets the horizontal scaling .
5,136
public Chunk setTextRenderMode ( int mode , float strokeWidth , Color strokeColor ) { return setAttribute ( TEXTRENDERMODE , new Object [ ] { Integer . valueOf ( mode ) , new Float ( strokeWidth ) , strokeColor } ) ; }
Sets the text rendering mode . It can outline text simulate bold and make text invisible .
5,137
public Image getImage ( ) { if ( attributes == null ) return null ; Object obj [ ] = ( Object [ ] ) attributes . get ( Chunk . IMAGE ) ; if ( obj == null ) return null ; else { return ( Image ) obj [ 0 ] ; } }
Returns the image .
5,138
public void decode1D ( byte [ ] buffer , byte [ ] compData , int startX , int height ) { this . data = compData ; int lineOffset = 0 ; int scanlineStride = ( w + 7 ) / 8 ; bitPointer = 0 ; bytePointer = 0 ; for ( int i = 0 ; i < height ; i ++ ) { decodeNextScanline ( buffer , lineOffset , startX ) ; lineOffset += scanlineStride ; } }
One - dimensional decoding methods
5,139
private void updatePointer ( int bitsToMoveBack ) { int i = bitPointer - bitsToMoveBack ; if ( i < 0 ) { bytePointer -- ; bitPointer = 8 + i ; } else { bitPointer = i ; } }
Move pointer backwards by given amount of bits
5,140
public void writeHeader ( OutputStreamCounter os ) throws IOException { if ( appendmode ) { os . write ( HEADER [ 0 ] ) ; } else { os . write ( HEADER [ 1 ] ) ; os . write ( getVersionAsByteArray ( header_version ) ) ; os . write ( HEADER [ 2 ] ) ; headerWasWritten = true ; } }
Writes the header to the OutputStreamCounter .
5,141
public PdfName getVersionAsName ( char version ) { switch ( version ) { case PdfWriter . VERSION_1_2 : return PdfWriter . PDF_VERSION_1_2 ; case PdfWriter . VERSION_1_3 : return PdfWriter . PDF_VERSION_1_3 ; case PdfWriter . VERSION_1_4 : return PdfWriter . PDF_VERSION_1_4 ; case PdfWriter . VERSION_1_5 : return PdfWriter . PDF_VERSION_1_5 ; case PdfWriter . VERSION_1_6 : return PdfWriter . PDF_VERSION_1_6 ; case PdfWriter . VERSION_1_7 : return PdfWriter . PDF_VERSION_1_7 ; default : return PdfWriter . PDF_VERSION_1_4 ; } }
Returns the PDF version as a name .
5,142
public void addToCatalog ( PdfDictionary catalog ) { if ( catalog_version != null ) { catalog . put ( PdfName . VERSION , catalog_version ) ; } if ( extensions != null ) { catalog . put ( PdfName . EXTENSIONS , extensions ) ; } }
Adds the version to the Catalog dictionary .
5,143
public void setIsolated ( boolean isolated ) { if ( isolated ) put ( PdfName . I , PdfBoolean . PDFTRUE ) ; else remove ( PdfName . I ) ; }
Determining the initial backdrop against which its stack is composited .
5,144
public void setKnockout ( boolean knockout ) { if ( knockout ) put ( PdfName . K , PdfBoolean . PDFTRUE ) ; else remove ( PdfName . K ) ; }
Determining whether the objects within the stack are composited with one another or only with the group s backdrop .
5,145
public int getFontNumber ( RtfFont font ) { if ( font instanceof RtfParagraphStyle ) { font = new RtfFont ( this . document , font ) ; } int fontIndex = - 1 ; for ( int i = 0 ; i < fontList . size ( ) ; i ++ ) { if ( fontList . get ( i ) . equals ( font ) ) { fontIndex = i ; } } if ( fontIndex == - 1 ) { fontIndex = fontList . size ( ) ; fontList . add ( font ) ; } return fontIndex ; }
Gets the index of the font in the list of fonts . If the font does not exist in the list it is added .
5,146
public void writeDefinition ( final OutputStream result ) throws IOException { result . write ( DEFAULT_FONT ) ; result . write ( intToByteArray ( 0 ) ) ; result . write ( OPEN_GROUP ) ; result . write ( FONT_TABLE ) ; for ( int i = 0 ; i < fontList . size ( ) ; i ++ ) { result . write ( OPEN_GROUP ) ; result . write ( FONT_NUMBER ) ; result . write ( intToByteArray ( i ) ) ; RtfFont rf = ( RtfFont ) fontList . get ( i ) ; rf . writeDefinition ( result ) ; result . write ( COMMA_DELIMITER ) ; result . write ( CLOSE_GROUP ) ; } result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; }
Writes the definition of the font list
5,147
private static final int marker ( int marker ) { for ( int i = 0 ; i < VALID_MARKERS . length ; i ++ ) { if ( marker == VALID_MARKERS [ i ] ) { return VALID_MARKER ; } } for ( int i = 0 ; i < NOPARAM_MARKERS . length ; i ++ ) { if ( marker == NOPARAM_MARKERS [ i ] ) { return NOPARAM_MARKER ; } } for ( int i = 0 ; i < UNSUPPORTED_MARKERS . length ; i ++ ) { if ( marker == UNSUPPORTED_MARKERS [ i ] ) { return UNSUPPORTED_MARKER ; } } return NOT_A_MARKER ; }
Returns a type of marker .
5,148
public BaseFont awtToPdf ( Font font ) { try { BaseFontParameters p = getBaseFontParameters ( font . getFontName ( ) ) ; if ( p != null ) return BaseFont . createFont ( p . fontName , p . encoding , p . embedded , p . cached , p . ttfAfm , p . pfb ) ; String fontKey = null ; String logicalName = font . getName ( ) ; if ( logicalName . equalsIgnoreCase ( "DialogInput" ) || logicalName . equalsIgnoreCase ( "Monospaced" ) || logicalName . equalsIgnoreCase ( "Courier" ) ) { if ( font . isItalic ( ) ) { if ( font . isBold ( ) ) { fontKey = BaseFont . COURIER_BOLDOBLIQUE ; } else { fontKey = BaseFont . COURIER_OBLIQUE ; } } else { if ( font . isBold ( ) ) { fontKey = BaseFont . COURIER_BOLD ; } else { fontKey = BaseFont . COURIER ; } } } else if ( logicalName . equalsIgnoreCase ( "Serif" ) || logicalName . equalsIgnoreCase ( "TimesRoman" ) ) { if ( font . isItalic ( ) ) { if ( font . isBold ( ) ) { fontKey = BaseFont . TIMES_BOLDITALIC ; } else { fontKey = BaseFont . TIMES_ITALIC ; } } else { if ( font . isBold ( ) ) { fontKey = BaseFont . TIMES_BOLD ; } else { fontKey = BaseFont . TIMES_ROMAN ; } } } else { if ( font . isItalic ( ) ) { if ( font . isBold ( ) ) { fontKey = BaseFont . HELVETICA_BOLDOBLIQUE ; } else { fontKey = BaseFont . HELVETICA_OBLIQUE ; } } else { if ( font . isBold ( ) ) { fontKey = BaseFont . HELVETICA_BOLD ; } else { fontKey = BaseFont . HELVETICA ; } } } return BaseFont . createFont ( fontKey , BaseFont . CP1252 , false ) ; } catch ( Exception e ) { throw new ExceptionConverter ( e ) ; } }
Returns a BaseFont which can be used to represent the given AWT Font
5,149
public Font pdfToAwt ( BaseFont font , int size ) { String names [ ] [ ] = font . getFullFontName ( ) ; if ( names . length == 1 ) return new Font ( names [ 0 ] [ 3 ] , 0 , size ) ; String name10 = null ; String name3x = null ; for ( int k = 0 ; k < names . length ; ++ k ) { String name [ ] = names [ k ] ; if ( name [ 0 ] . equals ( "1" ) && name [ 1 ] . equals ( "0" ) ) name10 = name [ 3 ] ; else if ( name [ 2 ] . equals ( "1033" ) ) { name3x = name [ 3 ] ; break ; } } String finalName = name3x ; if ( finalName == null ) finalName = name10 ; if ( finalName == null ) finalName = names [ 0 ] [ 3 ] ; return new Font ( finalName , 0 , size ) ; }
Returns an AWT Font which can be used to represent the given BaseFont
5,150
public BaseFontParameters getBaseFontParameters ( String name ) { String alias = ( String ) aliases . get ( name ) ; if ( alias == null ) return ( BaseFontParameters ) mapper . get ( name ) ; BaseFontParameters p = ( BaseFontParameters ) mapper . get ( alias ) ; if ( p == null ) return ( BaseFontParameters ) mapper . get ( name ) ; else return p ; }
Looks for a BaseFont parameter associated with a name .
5,151
public void insertNames ( Object allNames [ ] , String path ) { String names [ ] [ ] = ( String [ ] [ ] ) allNames [ 2 ] ; String main = null ; for ( int k = 0 ; k < names . length ; ++ k ) { String name [ ] = names [ k ] ; if ( name [ 2 ] . equals ( "1033" ) ) { main = name [ 3 ] ; break ; } } if ( main == null ) main = names [ 0 ] [ 3 ] ; BaseFontParameters p = new BaseFontParameters ( path ) ; mapper . put ( main , p ) ; for ( int k = 0 ; k < names . length ; ++ k ) { aliases . put ( names [ k ] [ 3 ] , main ) ; } aliases . put ( allNames [ 0 ] , main ) ; }
Inserts the names in this map .
5,152
public void setPrefix ( String key , String prefix ) { PdfName fieldname = new PdfName ( key ) ; PdfObject o = get ( fieldname ) ; if ( o == null ) throw new IllegalArgumentException ( "You must set a value before adding a prefix." ) ; PdfDictionary dict = new PdfDictionary ( PdfName . COLLECTIONSUBITEM ) ; dict . put ( PdfName . D , o ) ; dict . put ( PdfName . P , new PdfString ( prefix , PdfObject . TEXT_UNICODE ) ) ; put ( fieldname , dict ) ; }
Adds a prefix for the Collection item . You can only use this method after you have set the value of the item .
5,153
public TIFFField getField ( int tag ) { Integer i = ( Integer ) fieldIndex . get ( Integer . valueOf ( tag ) ) ; if ( i == null ) { return null ; } else { return fields [ i . intValue ( ) ] ; } }
Returns the value of a given tag as a TIFFField or null if the tag is not present .
5,154
public int [ ] getTags ( ) { int [ ] tags = new int [ fieldIndex . size ( ) ] ; Enumeration e = fieldIndex . keys ( ) ; int i = 0 ; while ( e . hasMoreElements ( ) ) { tags [ i ++ ] = ( ( Integer ) e . nextElement ( ) ) . intValue ( ) ; } return tags ; }
Returns an ordered array of ints indicating the tag values .
5,155
public byte getFieldAsByte ( int tag , int index ) { Integer i = ( Integer ) fieldIndex . get ( Integer . valueOf ( tag ) ) ; byte [ ] b = fields [ i . intValue ( ) ] . getAsBytes ( ) ; return b [ index ] ; }
Returns the value of a particular index of a given tag as a byte . The caller is responsible for ensuring that the tag is present and has type TIFFField . TIFF_SBYTE TIFF_BYTE or TIFF_UNDEFINED .
5,156
public long getFieldAsLong ( int tag , int index ) { Integer i = ( Integer ) fieldIndex . get ( Integer . valueOf ( tag ) ) ; return fields [ i . intValue ( ) ] . getAsLong ( index ) ; }
Returns the value of a particular index of a given tag as a long . The caller is responsible for ensuring that the tag is present and has type TIFF_BYTE TIFF_SBYTE TIFF_UNDEFINED TIFF_SHORT TIFF_SSHORT TIFF_SLONG or TIFF_LONG .
5,157
public String getFamilyname ( ) { String tmp = "unknown" ; switch ( getFamily ( ) ) { case Font . COURIER : return FontFactory . COURIER ; case Font . HELVETICA : return FontFactory . HELVETICA ; case Font . TIMES_ROMAN : return FontFactory . TIMES_ROMAN ; case Font . SYMBOL : return FontFactory . SYMBOL ; case Font . ZAPFDINGBATS : return FontFactory . ZAPFDINGBATS ; default : if ( baseFont != null ) { String [ ] [ ] names = baseFont . getFamilyFontName ( ) ; for ( int i = 0 ; i < names . length ; i ++ ) { if ( "0" . equals ( names [ i ] [ 2 ] ) ) { return names [ i ] [ 3 ] ; } if ( "1033" . equals ( names [ i ] [ 2 ] ) ) { tmp = names [ i ] [ 3 ] ; } if ( "" . equals ( names [ i ] [ 2 ] ) ) { tmp = names [ i ] [ 3 ] ; } } } } return tmp ; }
Gets the familyname as a String .
5,158
public boolean canBeInObjStm ( ) { switch ( type ) { case NULL : case BOOLEAN : case NUMBER : case STRING : case NAME : case ARRAY : case DICTIONARY : return true ; case STREAM : case INDIRECT : default : return false ; } }
Whether this object can be contained in an object stream .
5,159
protected void init ( ) { this . codePage = new RtfCodePage ( this . document ) ; this . colorList = new RtfColorList ( this . document ) ; this . fontList = new RtfFontList ( this . document ) ; this . listTable = new RtfListTable ( this . document ) ; this . stylesheetList = new RtfStylesheetList ( this . document ) ; this . infoGroup = new RtfInfoGroup ( this . document ) ; this . protectionSetting = new RtfProtectionSetting ( this . document ) ; this . pageSetting = new RtfPageSetting ( this . document ) ; this . header = new RtfHeaderFooterGroup ( this . document , RtfHeaderFooter . TYPE_HEADER ) ; this . footer = new RtfHeaderFooterGroup ( this . document , RtfHeaderFooter . TYPE_FOOTER ) ; this . generator = new RtfGenerator ( this . document ) ; }
initializes the RtfDocumentHeader .
5,160
public void writeContent ( final OutputStream result ) throws IOException { try { writeSectionDefinition ( new RtfNilOutputStream ( ) ) ; this . codePage . writeDefinition ( result ) ; this . fontList . writeDefinition ( result ) ; this . colorList . writeDefinition ( result ) ; this . stylesheetList . writeDefinition ( result ) ; this . listTable . writeDefinition ( result ) ; this . generator . writeContent ( result ) ; this . infoGroup . writeContent ( result ) ; this . protectionSetting . writeDefinition ( result ) ; this . pageSetting . writeDefinition ( result ) ; writeSectionDefinition ( result ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
Writes the contents of the document header area .
5,161
public void writeSectionDefinition ( final OutputStream result ) { try { RtfHeaderFooterGroup header = convertHeaderFooter ( this . header , RtfHeaderFooter . TYPE_HEADER ) ; RtfHeaderFooterGroup footer = convertHeaderFooter ( this . footer , RtfHeaderFooter . TYPE_FOOTER ) ; if ( header . hasTitlePage ( ) || footer . hasTitlePage ( ) ) { result . write ( TITLE_PAGE ) ; header . setHasTitlePage ( ) ; footer . setHasTitlePage ( ) ; } if ( header . hasFacingPages ( ) || footer . hasFacingPages ( ) ) { result . write ( FACING_PAGES ) ; header . setHasFacingPages ( ) ; footer . setHasFacingPages ( ) ; } footer . writeContent ( result ) ; header . writeContent ( result ) ; pageSetting . writeSectionDefinition ( result ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
Writes the section definition data
5,162
private RtfHeaderFooterGroup convertHeaderFooter ( HeaderFooter hf , int type ) { if ( hf != null ) { if ( hf instanceof RtfHeaderFooterGroup ) { return new RtfHeaderFooterGroup ( this . document , ( RtfHeaderFooterGroup ) hf , type ) ; } else if ( hf instanceof RtfHeaderFooter ) { return new RtfHeaderFooterGroup ( this . document , ( RtfHeaderFooter ) hf , type ) ; } else { return new RtfHeaderFooterGroup ( this . document , hf , type ) ; } } else { return new RtfHeaderFooterGroup ( this . document , type ) ; } }
Converts a HeaderFooter into a RtfHeaderFooterGroup . Depending on which class the HeaderFooter is the correct RtfHeaderFooterGroup is created .
5,163
public void write ( final int b ) { buffer [ pos ] = ( byte ) b ; size ++ ; if ( ++ pos == buffer . length ) flushBuffer ( ) ; }
Copies the given byte to the internal buffer .
5,164
public void write ( final byte [ ] src ) { if ( src == null ) throw new NullPointerException ( ) ; if ( src . length < buffer . length - pos ) { System . arraycopy ( src , 0 , buffer , pos , src . length ) ; pos += src . length ; size += src . length ; return ; } writeLoop ( src , 0 , src . length ) ; }
Copies the given array to the internal buffer .
5,165
public void write ( final byte [ ] src , int off , int len ) { if ( src == null ) throw new NullPointerException ( ) ; if ( ( off < 0 ) || ( off > src . length ) || ( len < 0 ) || ( ( off + len ) > src . length ) || ( ( off + len ) < 0 ) ) throw new IndexOutOfBoundsException ( ) ; writeLoop ( src , off , len ) ; }
Copies len bytes starting at position off from the array src to the internal buffer .
5,166
public long write ( final InputStream in ) throws IOException { if ( in == null ) throw new NullPointerException ( ) ; final long sizeStart = size ; while ( true ) { final int n = in . read ( buffer , pos , buffer . length - pos ) ; if ( n < 0 ) break ; pos += n ; size += n ; if ( pos == buffer . length ) flushBuffer ( ) ; } return ( size - sizeStart ) ; }
Writes all bytes available in the given inputstream to this buffer .
5,167
public byte [ ] toByteArray ( ) { final byte [ ] r = new byte [ size ] ; int off = 0 ; final int n = arrays . size ( ) ; for ( int k = 0 ; k < n ; k ++ ) { byte [ ] src = ( byte [ ] ) arrays . get ( k ) ; System . arraycopy ( src , 0 , r , off , src . length ) ; off += src . length ; } if ( pos > 0 ) System . arraycopy ( buffer , 0 , r , off , pos ) ; return r ; }
Allocates a new array and copies all data that has been written to this buffer to the newly allocated array .
5,168
public void writeTo ( final OutputStream out ) throws IOException { if ( out == null ) throw new NullPointerException ( ) ; final int n = arrays . size ( ) ; for ( int k = 0 ; k < n ; k ++ ) { byte [ ] src = ( byte [ ] ) arrays . get ( k ) ; out . write ( src ) ; } if ( pos > 0 ) out . write ( buffer , 0 , pos ) ; }
Writes all data that has been written to this buffer to the given output stream .
5,169
public void characters ( char [ ] ch , int start , int length ) { if ( ignore ) return ; String content = new String ( ch , start , length ) ; if ( content . trim ( ) . length ( ) == 0 && content . indexOf ( ' ' ) < 0 ) { return ; } StringBuffer buf = new StringBuffer ( ) ; int len = content . length ( ) ; char character ; boolean newline = false ; for ( int i = 0 ; i < len ; i ++ ) { switch ( character = content . charAt ( i ) ) { case ' ' : if ( ! newline ) { buf . append ( character ) ; } break ; case '\n' : if ( i > 0 ) { newline = true ; buf . append ( ' ' ) ; } break ; case '\r' : break ; case '\t' : break ; default : newline = false ; buf . append ( character ) ; } } if ( currentChunk == null ) { if ( bf == null ) { currentChunk = new Chunk ( buf . toString ( ) ) ; } else { currentChunk = new Chunk ( buf . toString ( ) , new Font ( this . bf ) ) ; } } else { currentChunk . append ( buf . toString ( ) ) ; } }
This method gets called when characters are encountered .
5,170
public float getTotalLeading ( ) { float m = font == null ? Font . DEFAULTSIZE * multipliedLeading : font . getCalculatedLeading ( multipliedLeading ) ; if ( m > 0 && ! hasLeading ( ) ) { return m ; } return getLeading ( ) + m ; }
Gets the total leading . This method is based on the assumption that the font of the Paragraph is the font of all the elements that make part of the paragraph . This isn t necessarily true .
5,171
public void setOverPrintStroking ( boolean ov ) { put ( PdfName . OP , ov ? PdfBoolean . PDFTRUE : PdfBoolean . PDFFALSE ) ; }
Sets the flag whether to apply overprint for stroking .
5,172
public void setOverPrintNonStroking ( boolean ov ) { put ( PdfName . op , ov ? PdfBoolean . PDFTRUE : PdfBoolean . PDFFALSE ) ; }
Sets the flag whether to apply overprint for non stroking painting operations .
5,173
public void setTextKnockout ( boolean v ) { put ( PdfName . TK , v ? PdfBoolean . PDFTRUE : PdfBoolean . PDFFALSE ) ; }
Determines the behavior of overlapping glyphs within a text object in the transparent imaging model .
5,174
private void writeText ( String value ) { if ( this . rtfParser . isNewGroup ( ) ) { this . rtfDoc . add ( new RtfDirectContent ( "{" ) ) ; this . rtfParser . setNewGroup ( false ) ; } if ( value . length ( ) > 0 ) { this . rtfDoc . add ( new RtfDirectContent ( value ) ) ; } }
Write the string value to the destination . Used for direct content
5,175
public static float parseLength ( String string ) { int pos = 0 ; int length = string . length ( ) ; boolean ok = true ; while ( ok && pos < length ) { switch ( string . charAt ( pos ) ) { case '+' : case '-' : case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : case '.' : pos ++ ; break ; default : ok = false ; } } if ( pos == 0 ) return 0f ; if ( pos == length ) return Float . parseFloat ( string + "f" ) ; float f = Float . parseFloat ( string . substring ( 0 , pos ) + "f" ) ; string = string . substring ( pos ) ; if ( string . startsWith ( "in" ) ) { return f * 72f ; } if ( string . startsWith ( "cm" ) ) { return ( f / 2.54f ) * 72f ; } if ( string . startsWith ( "mm" ) ) { return ( f / 25.4f ) * 72f ; } if ( string . startsWith ( "pc" ) ) { return f * 12f ; } return f ; }
Parses a length .
5,176
public static Properties parseAttributes ( String string ) { Properties result = new Properties ( ) ; if ( string == null ) return result ; StringTokenizer keyValuePairs = new StringTokenizer ( string , ";" ) ; StringTokenizer keyValuePair ; String key ; String value ; while ( keyValuePairs . hasMoreTokens ( ) ) { keyValuePair = new StringTokenizer ( keyValuePairs . nextToken ( ) , ":" ) ; if ( keyValuePair . hasMoreTokens ( ) ) key = keyValuePair . nextToken ( ) . trim ( ) ; else continue ; if ( keyValuePair . hasMoreTokens ( ) ) value = keyValuePair . nextToken ( ) . trim ( ) ; else continue ; if ( value . startsWith ( "\"" ) ) value = value . substring ( 1 ) ; if ( value . endsWith ( "\"" ) ) value = value . substring ( 0 , value . length ( ) - 1 ) ; result . setProperty ( key . toLowerCase ( ) , value ) ; } return result ; }
This method parses a String with attributes and returns a Properties object .
5,177
public static String removeComment ( String string , String startComment , String endComment ) { StringBuffer result = new StringBuffer ( ) ; int pos = 0 ; int end = endComment . length ( ) ; int start = string . indexOf ( startComment , pos ) ; while ( start > - 1 ) { result . append ( string . substring ( pos , start ) ) ; pos = string . indexOf ( endComment , start ) + end ; start = string . indexOf ( startComment , pos ) ; } result . append ( string . substring ( pos ) ) ; return result . toString ( ) ; }
Removes the comments sections of a String .
5,178
PdfDictionary getDictionary ( PdfWriter writer ) { try { return PdfNumberTree . writeTree ( map , writer ) ; } catch ( IOException e ) { throw new ExceptionConverter ( e ) ; } }
Gets the page label dictionary to insert into the document .
5,179
public static String [ ] getPageLabels ( PdfReader reader ) { int n = reader . getNumberOfPages ( ) ; PdfDictionary dict = reader . getCatalog ( ) ; PdfDictionary labels = ( PdfDictionary ) PdfReader . getPdfObjectRelease ( dict . get ( PdfName . PAGELABELS ) ) ; if ( labels == null ) return null ; String [ ] labelstrings = new String [ n ] ; HashMap numberTree = PdfNumberTree . readTree ( labels ) ; int pagecount = 1 ; Integer current ; String prefix = "" ; char type = 'D' ; for ( int i = 0 ; i < n ; i ++ ) { current = Integer . valueOf ( i ) ; if ( numberTree . containsKey ( current ) ) { PdfDictionary d = ( PdfDictionary ) PdfReader . getPdfObjectRelease ( ( PdfObject ) numberTree . get ( current ) ) ; if ( d . contains ( PdfName . ST ) ) { pagecount = ( ( PdfNumber ) d . get ( PdfName . ST ) ) . intValue ( ) ; } else { pagecount = 1 ; } if ( d . contains ( PdfName . P ) ) { prefix = ( ( PdfString ) d . get ( PdfName . P ) ) . toUnicodeString ( ) ; } if ( d . contains ( PdfName . S ) ) { type = ( ( PdfName ) d . get ( PdfName . S ) ) . toString ( ) . charAt ( 1 ) ; } } switch ( type ) { default : labelstrings [ i ] = prefix + pagecount ; break ; case 'R' : labelstrings [ i ] = prefix + RomanNumberFactory . getUpperCaseString ( pagecount ) ; break ; case 'r' : labelstrings [ i ] = prefix + RomanNumberFactory . getLowerCaseString ( pagecount ) ; break ; case 'A' : labelstrings [ i ] = prefix + RomanAlphabetFactory . getUpperCaseString ( pagecount ) ; break ; case 'a' : labelstrings [ i ] = prefix + RomanAlphabetFactory . getLowerCaseString ( pagecount ) ; break ; } pagecount ++ ; } return labelstrings ; }
Retrieves the page labels from a PDF as an array of String objects .
5,180
public void setToDefault ( ) { setToDefault ( COLOR ) ; setToDefault ( CHARACTER ) ; setToDefault ( PARAGRAPH ) ; setToDefault ( SECTION ) ; setToDefault ( DOCUMENT ) ; }
Set all property objects to default values .
5,181
public void setToDefault ( String propertyGroup ) { if ( COLOR . equals ( propertyGroup ) ) { setProperty ( COLOR_FG , new Color ( 0 , 0 , 0 ) ) ; setProperty ( COLOR_BG , new Color ( 255 , 255 , 255 ) ) ; return ; } if ( CHARACTER . equals ( propertyGroup ) ) { setProperty ( CHARACTER_BOLD , 0 ) ; setProperty ( CHARACTER_UNDERLINE , 0 ) ; setProperty ( CHARACTER_ITALIC , 0 ) ; setProperty ( CHARACTER_SIZE , 24 ) ; setProperty ( CHARACTER_FONT , 0 ) ; return ; } if ( PARAGRAPH . equals ( propertyGroup ) ) { setProperty ( PARAGRAPH_INDENT_LEFT , 0 ) ; setProperty ( PARAGRAPH_INDENT_RIGHT , 0 ) ; setProperty ( PARAGRAPH_INDENT_FIRST_LINE , 0 ) ; setProperty ( PARAGRAPH_JUSTIFICATION , JUSTIFY_LEFT ) ; setProperty ( PARAGRAPH_BORDER , PARAGRAPH_BORDER_NIL ) ; setProperty ( PARAGRAPH_BORDER_CELL , PARAGRAPH_BORDER_NIL ) ; return ; } if ( SECTION . equals ( propertyGroup ) ) { setProperty ( SECTION_NUMBER_OF_COLUMNS , 0 ) ; setProperty ( SECTION_BREAK_TYPE , SBK_NONE ) ; setProperty ( SECTION_PAGE_NUMBER_POSITION_X , 0 ) ; setProperty ( SECTION_PAGE_NUMBER_POSITION_Y , 0 ) ; setProperty ( SECTION_PAGE_NUMBER_FORMAT , PGN_DECIMAL ) ; return ; } if ( DOCUMENT . equals ( propertyGroup ) ) { setProperty ( DOCUMENT_PAGE_WIDTH_TWIPS , 12240 ) ; setProperty ( DOCUMENT_PAGE_HEIGHT_TWIPS , 15480 ) ; setProperty ( DOCUMENT_MARGIN_LEFT_TWIPS , 1800 ) ; setProperty ( DOCUMENT_MARGIN_TOP_TWIPS , 1440 ) ; setProperty ( DOCUMENT_MARGIN_RIGHT_TWIPS , 1800 ) ; setProperty ( DOCUMENT_MARGIN_BOTTOM_TWIPS , 1440 ) ; setProperty ( DOCUMENT_PAGE_NUMBER_START , 1 ) ; setProperty ( DOCUMENT_ENABLE_FACING_PAGES , 1 ) ; setProperty ( DOCUMENT_PAGE_ORIENTATION , PAGE_PORTRAIT ) ; setProperty ( DOCUMENT_DEFAULT_FONT_NUMER , 0 ) ; return ; } }
Set individual property group to default values .
5,182
public HashMap getProperties ( String propertyGroup ) { HashMap props = new HashMap ( ) ; for ( Map . Entry < String , Object > entry : properties . entrySet ( ) ) { String key = entry . getKey ( ) ; Object value = entry . getValue ( ) ; if ( key . startsWith ( propertyGroup ) ) { props . put ( key , value ) ; } } return props ; }
Get a group of properties .
5,183
PdfIndirectReference writePageTree ( ) throws IOException { if ( pages . isEmpty ( ) ) throw new IOException ( "The document has no pages." ) ; int leaf = 1 ; ArrayList tParents = parents ; ArrayList tPages = pages ; ArrayList nextParents = new ArrayList ( ) ; while ( true ) { leaf *= leafSize ; int stdCount = leafSize ; int rightCount = tPages . size ( ) % leafSize ; if ( rightCount == 0 ) rightCount = leafSize ; for ( int p = 0 ; p < tParents . size ( ) ; ++ p ) { int count ; int thisLeaf = leaf ; if ( p == tParents . size ( ) - 1 ) { count = rightCount ; thisLeaf = pages . size ( ) % leaf ; if ( thisLeaf == 0 ) thisLeaf = leaf ; } else count = stdCount ; PdfDictionary top = new PdfDictionary ( PdfName . PAGES ) ; top . put ( PdfName . COUNT , new PdfNumber ( thisLeaf ) ) ; PdfArray kids = new PdfArray ( ) ; ArrayList internal = kids . getArrayList ( ) ; internal . addAll ( tPages . subList ( p * stdCount , p * stdCount + count ) ) ; top . put ( PdfName . KIDS , kids ) ; if ( tParents . size ( ) > 1 ) { if ( ( p % leafSize ) == 0 ) nextParents . add ( writer . getPdfIndirectReference ( ) ) ; top . put ( PdfName . PARENT , ( PdfIndirectReference ) nextParents . get ( p / leafSize ) ) ; } else { top . put ( PdfName . ITXT , new PdfString ( Document . getRelease ( ) ) ) ; } writer . addToBody ( top , ( PdfIndirectReference ) tParents . get ( p ) ) ; } if ( tParents . size ( ) == 1 ) { topParent = ( PdfIndirectReference ) tParents . get ( 0 ) ; return topParent ; } tPages = tParents ; tParents = nextParents ; nextParents = new ArrayList ( ) ; } }
returns the top parent to include in the catalog
5,184
public static String getDigest ( String oid ) { String ret = ( String ) digestNames . get ( oid ) ; if ( ret == null ) return oid ; else return ret ; }
Gets the digest name for a certain id
5,185
public static String getAlgorithm ( String oid ) { String ret = ( String ) algorithmNames . get ( oid ) ; if ( ret == null ) return oid ; else return ret ; }
Gets the algorithm name for a certain id .
5,186
public Calendar getTimeStampDate ( ) { if ( timeStampToken == null ) return null ; Calendar cal = new GregorianCalendar ( ) ; Date date = timeStampToken . getTimeStampInfo ( ) . getGenTime ( ) ; cal . setTime ( date ) ; return cal ; }
Gets the timestamp date
5,187
public void update ( byte [ ] buf , int off , int len ) throws SignatureException { if ( RSAdata != null || digestAttr != null ) messageDigest . update ( buf , off , len ) ; else sig . update ( buf , off , len ) ; }
Update the digest with the specified bytes . This method is used both for signing and verifying
5,188
public boolean verify ( ) throws SignatureException { if ( verified ) return verifyResult ; if ( sigAttr != null ) { sig . update ( sigAttr ) ; if ( RSAdata != null ) { byte msd [ ] = messageDigest . digest ( ) ; messageDigest . update ( msd ) ; } verifyResult = ( Arrays . equals ( messageDigest . digest ( ) , digestAttr ) && sig . verify ( digest ) ) ; } else { if ( RSAdata != null ) sig . update ( messageDigest . digest ( ) ) ; verifyResult = sig . verify ( digest ) ; } verified = true ; return verifyResult ; }
Verify the digest .
5,189
public boolean verifyTimestampImprint ( ) throws NoSuchAlgorithmException { if ( timeStampToken == null ) return false ; MessageImprint imprint = timeStampToken . getTimeStampInfo ( ) . toASN1Structure ( ) . getMessageImprint ( ) ; byte [ ] md = MessageDigest . getInstance ( "SHA-1" ) . digest ( digest ) ; byte [ ] imphashed = imprint . getHashedMessage ( ) ; boolean res = Arrays . equals ( md , imphashed ) ; return res ; }
Checks if the timestamp refers to this document .
5,190
public String getDigestAlgorithm ( ) { String dea = getAlgorithm ( digestEncryptionAlgorithm ) ; if ( dea == null ) dea = digestEncryptionAlgorithm ; return getHashAlgorithm ( ) + "with" + dea ; }
Get the algorithm used to calculate the message digest
5,191
public static String verifyCertificate ( X509Certificate cert , Collection crls , Calendar calendar ) { if ( calendar == null ) calendar = new GregorianCalendar ( ) ; if ( cert . hasUnsupportedCriticalExtension ( ) ) return "Has unsupported critical extension" ; try { cert . checkValidity ( calendar . getTime ( ) ) ; } catch ( Exception e ) { return e . getMessage ( ) ; } if ( crls != null ) { for ( Iterator it = crls . iterator ( ) ; it . hasNext ( ) ; ) { if ( ( ( CRL ) it . next ( ) ) . isRevoked ( cert ) ) return "Certificate revoked" ; } } return null ; }
Verifies a single certificate .
5,192
public static Object [ ] verifyCertificates ( Certificate certs [ ] , KeyStore keystore , Collection crls , Calendar calendar ) { if ( calendar == null ) calendar = new GregorianCalendar ( ) ; for ( int k = 0 ; k < certs . length ; ++ k ) { X509Certificate cert = ( X509Certificate ) certs [ k ] ; String err = verifyCertificate ( cert , crls , calendar ) ; if ( err != null ) return new Object [ ] { cert , err } ; try { for ( Enumeration aliases = keystore . aliases ( ) ; aliases . hasMoreElements ( ) ; ) { try { String alias = ( String ) aliases . nextElement ( ) ; if ( ! keystore . isCertificateEntry ( alias ) ) continue ; X509Certificate certStoreX509 = ( X509Certificate ) keystore . getCertificate ( alias ) ; if ( verifyCertificate ( certStoreX509 , crls , calendar ) != null ) continue ; try { cert . verify ( certStoreX509 . getPublicKey ( ) ) ; return null ; } catch ( Exception e ) { continue ; } } catch ( Exception ex ) { } } } catch ( Exception e ) { } int j ; for ( j = 0 ; j < certs . length ; ++ j ) { if ( j == k ) continue ; X509Certificate certNext = ( X509Certificate ) certs [ j ] ; try { cert . verify ( certNext . getPublicKey ( ) ) ; break ; } catch ( Exception e ) { } } if ( j == certs . length ) return new Object [ ] { cert , "Cannot be verified against the KeyStore or the certificate chain" } ; } return new Object [ ] { null , "Invalid state. Possible circular certificate chain" } ; }
Verifies a certificate chain against a KeyStore .
5,193
public static boolean verifyOcspCertificates ( BasicOCSPResp ocsp , KeyStore keystore , String provider ) { if ( provider == null ) provider = "BC" ; try { for ( Enumeration aliases = keystore . aliases ( ) ; aliases . hasMoreElements ( ) ; ) { try { String alias = ( String ) aliases . nextElement ( ) ; if ( ! keystore . isCertificateEntry ( alias ) ) continue ; X509Certificate certStoreX509 = ( X509Certificate ) keystore . getCertificate ( alias ) ; if ( ocsp . isSignatureValid ( new JcaContentVerifierProviderBuilder ( ) . setProvider ( provider ) . build ( certStoreX509 . getPublicKey ( ) ) ) ) return true ; } catch ( Exception ex ) { } } } catch ( Exception e ) { } return false ; }
Verifies an OCSP response against a KeyStore .
5,194
public static boolean verifyTimestampCertificates ( TimeStampToken ts , KeyStore keystore , String provider ) { if ( provider == null ) provider = "BC" ; try { for ( Enumeration aliases = keystore . aliases ( ) ; aliases . hasMoreElements ( ) ; ) { try { String alias = ( String ) aliases . nextElement ( ) ; if ( ! keystore . isCertificateEntry ( alias ) ) continue ; X509Certificate certStoreX509 = ( X509Certificate ) keystore . getCertificate ( alias ) ; SignerInformationVerifier siv = new JcaSimpleSignerInfoVerifierBuilder ( ) . setProvider ( provider ) . build ( certStoreX509 ) ; ts . validate ( siv ) ; return true ; } catch ( Exception ex ) { } } } catch ( Exception e ) { } return false ; }
Verifies a timestamp against a KeyStore .
5,195
public static String getOCSPURL ( X509Certificate certificate ) throws CertificateParsingException { try { ASN1Primitive obj = getExtensionValue ( certificate , Extension . authorityInfoAccess . getId ( ) ) ; if ( obj == null ) { return null ; } ASN1Sequence AccessDescriptions = ( ASN1Sequence ) obj ; for ( int i = 0 ; i < AccessDescriptions . size ( ) ; i ++ ) { ASN1Sequence AccessDescription = ( ASN1Sequence ) AccessDescriptions . getObjectAt ( i ) ; if ( AccessDescription . size ( ) != 2 ) { continue ; } else { if ( ( AccessDescription . getObjectAt ( 0 ) instanceof ASN1ObjectIdentifier ) && ( ( ASN1ObjectIdentifier ) AccessDescription . getObjectAt ( 0 ) ) . getId ( ) . equals ( "1.3.6.1.5.5.7.48.1" ) ) { String AccessLocation = getStringFromGeneralName ( ( ASN1Primitive ) AccessDescription . getObjectAt ( 1 ) ) ; if ( AccessLocation == null ) { return "" ; } else { return AccessLocation ; } } } } } catch ( Exception e ) { } return null ; }
Retrieves the OCSP URL from the given certificate .
5,196
public boolean isRevocationValid ( ) { if ( basicResp == null ) return false ; if ( signCerts . size ( ) < 2 ) return false ; try { X509Certificate [ ] cs = ( X509Certificate [ ] ) getSignCertificateChain ( ) ; SingleResp sr = basicResp . getResponses ( ) [ 0 ] ; CertificateID cid = sr . getCertID ( ) ; X509Certificate sigcer = getSigningCertificate ( ) ; X509Certificate isscer = cs [ 1 ] ; CertificateID tis = new CertificateID ( new JcaDigestCalculatorProviderBuilder ( ) . build ( ) . get ( CertificateID . HASH_SHA1 ) , new JcaX509CertificateHolder ( isscer ) , sigcer . getSerialNumber ( ) ) ; return tis . equals ( cid ) ; } catch ( Exception ex ) { } return false ; }
Checks if OCSP revocation refers to the document signing certificate .
5,197
private static ASN1Primitive getIssuer ( byte [ ] enc ) { try { ASN1InputStream in = new ASN1InputStream ( new ByteArrayInputStream ( enc ) ) ; ASN1Sequence seq = ( ASN1Sequence ) in . readObject ( ) ; return ( ASN1Primitive ) seq . getObjectAt ( seq . getObjectAt ( 0 ) instanceof DERTaggedObject ? 3 : 2 ) ; } catch ( IOException e ) { throw new ExceptionConverter ( e ) ; } }
Get the issuer from the TBSCertificate bytes that are passed in
5,198
public static X509Name getIssuerFields ( X509Certificate cert ) { try { return new X509Name ( ( ASN1Sequence ) getIssuer ( cert . getTBSCertificate ( ) ) ) ; } catch ( Exception e ) { throw new ExceptionConverter ( e ) ; } }
Get the issuer fields from an X509 Certificate
5,199
public static X509Name getSubjectFields ( X509Certificate cert ) { try { return new X509Name ( ( ASN1Sequence ) getSubject ( cert . getTBSCertificate ( ) ) ) ; } catch ( Exception e ) { throw new ExceptionConverter ( e ) ; } }
Get the subject fields from an X509 Certificate