idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
5,000
private float remainingLinesHeight ( ) { if ( lines . isEmpty ( ) ) return 0 ; float result = 0 ; int size = lines . size ( ) ; PdfLine line ; for ( int i = 0 ; i < size ; i ++ ) { line = ( PdfLine ) lines . get ( i ) ; result += line . height ( ) ; } return result ; }
Returns the total height of all the lines in the cell .
5,001
public float remainingHeight ( ) { float result = 0f ; for ( Iterator i = images . iterator ( ) ; i . hasNext ( ) ; ) { Image image = ( Image ) i . next ( ) ; result += image . getScaledHeight ( ) ; } return remainingLinesHeight ( ) + cellspacing + 2 * cellpadding + result ; }
Returns the height needed to draw the remaining text .
5,002
protected void processActions ( Element element , PdfAction action , ArrayList allActions ) { if ( element . type ( ) == Element . ANCHOR ) { String url = ( ( Anchor ) element ) . getReference ( ) ; if ( url != null ) { action = new PdfAction ( url ) ; } } Iterator i ; switch ( element . type ( ) ) { case Element . PHR...
Processes all actions contained in the cell .
5,003
public void toPdf ( int midSize , OutputStream os ) throws IOException { os . write ( ( byte ) type ) ; while ( -- midSize >= 0 ) os . write ( ( byte ) ( ( offset >>> ( 8 * midSize ) ) & 0xff ) ) ; os . write ( ( byte ) ( ( generation >>> 8 ) & 0xff ) ) ; os . write ( ( byte ) ( generation & 0xff ) ) ; }
Writes PDF syntax to the OutputStream
5,004
public PdfTemplate createTemplateWithBarcode ( PdfContentByte cb , Color barColor , Color textColor ) { PdfTemplate tp = cb . createTemplate ( 0 , 0 ) ; Rectangle rect = placeBarcode ( tp , barColor , textColor ) ; tp . setBoundingBox ( rect ) ; return tp ; }
Creates a template with the barcode .
5,005
public static Chunk getChunk ( Properties attributes ) { Chunk chunk = new Chunk ( ) ; chunk . setFont ( FontFactory . getFont ( attributes ) ) ; String value ; value = attributes . getProperty ( ElementTags . ITEXT ) ; if ( value != null ) { chunk . append ( value ) ; } value = attributes . getProperty ( ElementTags ....
Creates a Chunk object based on a list of properties .
5,006
public static Phrase getPhrase ( Properties attributes ) { Phrase phrase = new Phrase ( ) ; phrase . setFont ( FontFactory . getFont ( attributes ) ) ; String value ; value = attributes . getProperty ( ElementTags . LEADING ) ; if ( value != null ) { phrase . setLeading ( Float . parseFloat ( value + "f" ) ) ; } value ...
Creates a Phrase object based on a list of properties .
5,007
public static Anchor getAnchor ( Properties attributes ) { Anchor anchor = new Anchor ( getPhrase ( attributes ) ) ; String value ; value = attributes . getProperty ( ElementTags . NAME ) ; if ( value != null ) { anchor . setName ( value ) ; } value = ( String ) attributes . remove ( ElementTags . REFERENCE ) ; if ( va...
Creates an Anchor object based on a list of properties .
5,008
public static Paragraph getParagraph ( Properties attributes ) { Paragraph paragraph = new Paragraph ( getPhrase ( attributes ) ) ; String value ; value = attributes . getProperty ( ElementTags . ALIGN ) ; if ( value != null ) { paragraph . setAlignment ( value ) ; } value = attributes . getProperty ( ElementTags . IND...
Creates a Paragraph object based on a list of properties .
5,009
public static ListItem getListItem ( Properties attributes ) { ListItem item = new ListItem ( getParagraph ( attributes ) ) ; return item ; }
Creates a ListItem object based on a list of properties .
5,010
public static List getList ( Properties attributes ) { List list = new List ( ) ; list . setNumbered ( Utilities . checkTrueOrFalse ( attributes , ElementTags . NUMBERED ) ) ; list . setLettered ( Utilities . checkTrueOrFalse ( attributes , ElementTags . LETTERED ) ) ; list . setLowercase ( Utilities . checkTrueOrFalse...
Creates a List object based on a list of properties .
5,011
public static Cell getCell ( Properties attributes ) { Cell cell = new Cell ( ) ; String value ; cell . setHorizontalAlignment ( attributes . getProperty ( ElementTags . HORIZONTALALIGN ) ) ; cell . setVerticalAlignment ( attributes . getProperty ( ElementTags . VERTICALALIGN ) ) ; value = attributes . getProperty ( El...
Creates a Cell object based on a list of properties .
5,012
public static ChapterAutoNumber getChapter ( Properties attributes ) { ChapterAutoNumber chapter = new ChapterAutoNumber ( "" ) ; setSectionParameters ( chapter , attributes ) ; return chapter ; }
Creates a ChapterAutoNumber object based on a list of properties .
5,013
public static Section getSection ( Section parent , Properties attributes ) { Section section = parent . addSection ( "" ) ; setSectionParameters ( section , attributes ) ; return section ; }
Creates a Section object based on a list of properties .
5,014
public static Image getImage ( Properties attributes ) throws BadElementException , MalformedURLException , IOException { String value ; value = attributes . getProperty ( ElementTags . URL ) ; if ( value == null ) throw new MalformedURLException ( "The URL of the image is missing." ) ; Image image = Image . getInstanc...
Creates an Image object based on a list of properties .
5,015
public static Annotation getAnnotation ( Properties attributes ) { float llx = 0 , lly = 0 , urx = 0 , ury = 0 ; String value ; value = attributes . getProperty ( ElementTags . LLX ) ; if ( value != null ) { llx = Float . parseFloat ( value + "f" ) ; } value = attributes . getProperty ( ElementTags . LLY ) ; if ( value...
Creates an Annotation object based on a list of properties .
5,016
public void setRunDirection ( int runDirection ) { if ( runDirection < PdfWriter . RUN_DIRECTION_DEFAULT || runDirection > PdfWriter . RUN_DIRECTION_RTL ) throw new RuntimeException ( "Invalid run direction: " + runDirection ) ; this . runDirection = runDirection ; }
Sets the run direction .
5,017
public static float getWidth ( Phrase phrase , int runDirection , int arabicOptions ) { ColumnText ct = new ColumnText ( null ) ; ct . addText ( phrase ) ; ct . addWaitingPhrase ( ) ; PdfLine line = ct . bidiLine . processLine ( 0 , 20000 , Element . ALIGN_LEFT , runDirection , arabicOptions ) ; if ( line == null ) ret...
Gets the width that the line will occupy after writing . Only the width of the first line is returned .
5,018
public void setCanvas ( PdfContentByte canvas ) { this . canvas = canvas ; this . canvases = null ; if ( compositeColumn != null ) compositeColumn . setCanvas ( canvas ) ; }
Sets the canvas . If before a set of four canvases was set it is being unset .
5,019
public void setCanvases ( PdfContentByte [ ] canvases ) { this . canvases = canvases ; this . canvas = canvases [ PdfPTable . TEXTCANVAS ] ; if ( compositeColumn != null ) compositeColumn . setCanvases ( canvases ) ; }
Sets the canvases .
5,020
public boolean zeroHeightElement ( ) { return composite && ! compositeElements . isEmpty ( ) && ( ( Element ) compositeElements . getFirst ( ) ) . type ( ) == Element . YMARK ; }
Checks if the element has a height of 0 .
5,021
public void writeDefinition ( final OutputStream result ) throws IOException { result . write ( COLOR_RED ) ; result . write ( intToByteArray ( red ) ) ; result . write ( COLOR_GREEN ) ; result . write ( intToByteArray ( green ) ) ; result . write ( COLOR_BLUE ) ; result . write ( intToByteArray ( blue ) ) ; result . w...
Write the definition part of this RtfColor .
5,022
public void writeBegin ( final OutputStream result ) { try { result . write ( COLOR_NUMBER ) ; result . write ( intToByteArray ( colorNumber ) ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
Writes the beginning of this RtfColor
5,023
public void setRtfDocument ( RtfDocument doc ) { super . setRtfDocument ( doc ) ; if ( document != null ) { this . colorNumber = document . getDocumentHeader ( ) . getColorNumber ( this ) ; } }
Sets the RtfDocument this RtfColor belongs to
5,024
public static final String getString ( int index ) { StringBuffer buf = new StringBuffer ( ) ; if ( index < 0 ) { buf . append ( '-' ) ; index = - index ; } if ( index > 3000 ) { buf . append ( '|' ) ; buf . append ( getString ( index / 1000 ) ) ; buf . append ( '|' ) ; index = index - ( index / 1000 ) * 1000 ; } int p...
Changes an int into a lower case roman number .
5,025
protected void process ( StringBuffer buf , Object p ) { buf . append ( '<' ) ; buf . append ( p ) ; buf . append ( '>' ) ; buf . append ( this . get ( p ) ) ; buf . append ( "</" ) ; buf . append ( p ) ; buf . append ( '>' ) ; }
Processes a property
5,026
public static void convert ( RandomAccessFileOrArray in , OutputStream out ) throws IOException { Pfm2afm p = new Pfm2afm ( in , out ) ; p . openpfm ( ) ; p . putheader ( ) ; p . putchartab ( ) ; p . putkerntab ( ) ; p . puttrailer ( ) ; p . out . flush ( ) ; }
Converts a PFM file into an AFM file .
5,027
public int getAsInt ( int index ) { switch ( type ) { case TIFF_BYTE : case TIFF_UNDEFINED : return ( ( byte [ ] ) data ) [ index ] & 0xff ; case TIFF_SBYTE : return ( ( byte [ ] ) data ) [ index ] ; case TIFF_SHORT : return ( ( char [ ] ) data ) [ index ] & 0xffff ; case TIFF_SSHORT : return ( ( short [ ] ) data ) [ i...
Returns data in TIFF_BYTE TIFF_SBYTE TIFF_UNDEFINED TIFF_SHORT TIFF_SSHORT or TIFF_SLONG format as an int .
5,028
public long getAsLong ( int index ) { switch ( type ) { case TIFF_BYTE : case TIFF_UNDEFINED : return ( ( byte [ ] ) data ) [ index ] & 0xff ; case TIFF_SBYTE : return ( ( byte [ ] ) data ) [ index ] ; case TIFF_SHORT : return ( ( char [ ] ) data ) [ index ] & 0xffff ; case TIFF_SSHORT : return ( ( short [ ] ) data ) [...
Returns data in TIFF_BYTE TIFF_SBYTE TIFF_UNDEFINED TIFF_SHORT TIFF_SSHORT TIFF_SLONG or TIFF_LONG format as a long .
5,029
public float getAsFloat ( int index ) { switch ( type ) { case TIFF_BYTE : return ( ( byte [ ] ) data ) [ index ] & 0xff ; case TIFF_SBYTE : return ( ( byte [ ] ) data ) [ index ] ; case TIFF_SHORT : return ( ( char [ ] ) data ) [ index ] & 0xffff ; case TIFF_SSHORT : return ( ( short [ ] ) data ) [ index ] ; case TIFF...
Returns data in any numerical format as a float . Data in TIFF_SRATIONAL or TIFF_RATIONAL format are evaluated by dividing the numerator into the denominator using double - precision arithmetic and then truncating to single precision . Data in TIFF_SLONG TIFF_LONG or TIFF_DOUBLE format may suffer from truncation .
5,030
public ArrayList parse ( ArrayList ls ) throws IOException { if ( ls == null ) ls = new ArrayList ( ) ; else ls . clear ( ) ; PdfObject ob = null ; while ( ( ob = readPRObject ( ) ) != null ) { ls . add ( ob ) ; if ( ob . type ( ) == COMMAND_TYPE ) break ; } return ls ; }
Parses a single command from the content . Each command is output as an array of arguments having the command itself as the last element . The returned array will be empty if the end of content was reached .
5,031
public PdfDictionary readDictionary ( ) throws IOException { PdfDictionary dic = new PdfDictionary ( ) ; while ( true ) { if ( ! nextValidToken ( ) ) throw new IOException ( "Unexpected end of file." ) ; if ( tokeniser . getTokenType ( ) == PRTokeniser . TK_END_DIC ) break ; if ( tokeniser . getTokenType ( ) != PRToken...
Reads a dictionary . The tokeniser must be positioned past the &lt ; &lt ; token .
5,032
public PdfArray readArray ( ) throws IOException { PdfArray array = new PdfArray ( ) ; while ( true ) { PdfObject obj = readPRObject ( ) ; int type = obj . type ( ) ; if ( - type == PRTokeniser . TK_END_ARRAY ) break ; if ( - type == PRTokeniser . TK_END_DIC ) throw new IOException ( "Unexpected '>>'" ) ; array . add (...
Reads an array . The tokeniser must be positioned past the [ token .
5,033
public PdfObject readPRObject ( ) throws IOException { if ( ! nextValidToken ( ) ) return null ; int type = tokeniser . getTokenType ( ) ; switch ( type ) { case PRTokeniser . TK_START_DIC : { PdfDictionary dic = readDictionary ( ) ; return dic ; } case PRTokeniser . TK_START_ARRAY : return readArray ( ) ; case PRToken...
Reads a pdf object .
5,034
public boolean nextValidToken ( ) throws IOException { while ( tokeniser . nextToken ( ) ) { if ( tokeniser . getTokenType ( ) == PRTokeniser . TK_COMMENT ) continue ; return true ; } return false ; }
Reads the next token skipping over the comments .
5,035
public Properties getAttributes ( Attributes attrs ) { Properties attributes = new Properties ( ) ; attributes . putAll ( attributeValues ) ; if ( defaultContent != null ) { attributes . put ( ElementTags . ITEXT , defaultContent ) ; } if ( attrs != null ) { for ( int i = 0 ; i < attrs . getLength ( ) ; i ++ ) { String...
Gets the list of attributes of the peer .
5,036
public String getName ( String name ) { String value ; if ( ( value = attributeAliases . getProperty ( name ) ) != null ) { return value ; } return name ; }
Returns the iText attribute name .
5,037
public void writeContent ( final OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; if ( this . type == TYPE_HEADER ) { if ( this . displayAt == DISPLAY_ALL_PAGES ) { result . write ( HEADER_ALL ) ; } else if ( this . displayAt == DISPLAY_FIRST_PAGE ) { result . write ( HEADER_FIRST ) ; } else i...
Writes the content of this RtfHeaderFooter
5,038
public void setAlignment ( int alignment ) { super . setAlignment ( alignment ) ; for ( int i = 0 ; i < this . content . length ; i ++ ) { if ( this . content [ i ] instanceof Paragraph ) { ( ( Paragraph ) this . content [ i ] ) . setAlignment ( alignment ) ; } else if ( this . content [ i ] instanceof Table ) { ( ( Ta...
Set the alignment of this RtfHeaderFooter . Passes the setting on to the contained element .
5,039
public void writeDocument ( OutputStream out ) { try { out . write ( OPEN_GROUP ) ; out . write ( RtfDocument . RTF_DOCUMENT ) ; this . documentHeader . writeContent ( out ) ; this . data . writeTo ( out ) ; out . write ( CLOSE_GROUP ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
Writes the document
5,040
public void open ( ) { try { switch ( this . documentSettings . getDataCacheStyle ( ) ) { case RtfDataCache . CACHE_MEMORY_EFFICIENT : this . data = new RtfEfficientMemoryCache ( ) ; break ; case RtfDataCache . CACHE_MEMORY : this . data = new RtfMemoryCache ( ) ; break ; case RtfDataCache . CACHE_DISK : this . data = ...
Opens the RtfDocument and initializes the data cache . If the data cache is set to CACHE_DISK but the cache cannot be initialized then the memory cache is used .
5,041
public void add ( RtfBasicElement element ) { try { if ( element instanceof RtfInfoElement ) { this . documentHeader . addInfoElement ( ( RtfInfoElement ) element ) ; } else { if ( element instanceof RtfImage ) { ( ( RtfImage ) element ) . setTopLevelElement ( true ) ; } element . writeContent ( this . data . getOutput...
Adds an element to the rtf document
5,042
public int getRandomInt ( ) { Integer newInt = null ; do { newInt = randomGenerator . nextInt ( ) ; } while ( this . previousRandomInts . contains ( newInt ) ) ; this . previousRandomInts . add ( newInt ) ; return newInt . intValue ( ) ; }
Generates a random integer that is unique with respect to the document . Will not return a number between - 1 and - 5 because some values in that range are invalid .
5,043
public MarkedObject getTitle ( ) { Paragraph result = Section . constructTitle ( ( Paragraph ) title . element , ( ( Section ) element ) . numbers , ( ( Section ) element ) . numberDepth , ( ( Section ) element ) . numberStyle ) ; MarkedObject mo = new MarkedObject ( result ) ; mo . markupAttributes = title . markupAtt...
Gets the title of this MarkedSection .
5,044
private void flush ( ) { switch ( state ) { case TEXT : case CDATA : if ( text . length ( ) > 0 ) { doc . text ( text . toString ( ) ) ; } break ; case COMMENT : if ( comment != null ) { comment . comment ( text . toString ( ) ) ; } break ; case ATTRIBUTE_KEY : attributekey = text . toString ( ) ; if ( html ) attribute...
Flushes the text that is currently in the buffer . The text can be ignored added to the document as content or as comment ... depending on the current state .
5,045
private void doTag ( ) { if ( tag == null ) tag = text . toString ( ) ; if ( html ) tag = tag . toLowerCase ( ) ; text . setLength ( 0 ) ; }
Sets the name of the tag .
5,046
private void processTag ( boolean start ) { if ( start ) { nested ++ ; doc . startElement ( tag , attributes ) ; } else { nested -- ; doc . endElement ( tag ) ; } }
processes the tag .
5,047
public static String escapeXML ( String s , boolean onlyASCII ) { char cc [ ] = s . toCharArray ( ) ; int len = cc . length ; StringBuffer sb = new StringBuffer ( ) ; for ( int k = 0 ; k < len ; ++ k ) { int c = cc [ k ] ; switch ( c ) { case '<' : sb . append ( "&lt;" ) ; break ; case '>' : sb . append ( "&gt;" ) ; br...
Escapes a string with the appropriated XML codes .
5,048
private PdfStream getToUnicode ( Object metrics [ ] ) { metrics = filterCmapMetrics ( metrics ) ; if ( metrics . length == 0 ) return null ; StringBuffer buf = new StringBuffer ( "/CIDInit /ProcSet findresource begin\n" + "12 dict begin\n" + "begincmap\n" + "/CIDSystemInfo\n" + "<< /Registry (TTX+0)\n" + "/Ordering (T4...
Creates a ToUnicode CMap to allow copy and paste from Acrobat .
5,049
static String toHex ( int n ) { if ( n < 0x10000 ) return "<" + toHex4 ( n ) + ">" ; n -= 0x10000 ; int high = ( n / 0x400 ) + 0xd800 ; int low = ( n % 0x400 ) + 0xdc00 ; return "[<" + toHex4 ( high ) + toHex4 ( low ) + ">]" ; }
Gets an hex string in the format &lt ; HHHH&gt ; .
5,050
private PdfDictionary getCIDFontType2 ( PdfIndirectReference fontDescriptor , String subsetPrefix , Object metrics [ ] ) { PdfDictionary dic = new PdfDictionary ( PdfName . FONT ) ; if ( cff ) { dic . put ( PdfName . SUBTYPE , PdfName . CIDFONTTYPE0 ) ; dic . put ( PdfName . BASEFONT , new PdfName ( subsetPrefix + font...
Generates the CIDFontTyte2 dictionary .
5,051
private PdfDictionary getFontBaseType ( PdfIndirectReference descendant , String subsetPrefix , PdfIndirectReference toUnicode ) { PdfDictionary dic = new PdfDictionary ( PdfName . FONT ) ; dic . put ( PdfName . SUBTYPE , PdfName . TYPE0 ) ; if ( cff ) dic . put ( PdfName . BASEFONT , new PdfName ( subsetPrefix + fontN...
Generates the font dictionary .
5,052
public int compare ( Object o1 , Object o2 ) { int m1 = ( ( int [ ] ) o1 ) [ 0 ] ; int m2 = ( ( int [ ] ) o2 ) [ 0 ] ; if ( m1 < m2 ) return - 1 ; if ( m1 == m2 ) return 0 ; return 1 ; }
The method used to sort the metrics array .
5,053
public void addLanguage ( String language , String value ) { setProperty ( language , XmpSchema . escape ( value ) ) ; }
Add a language .
5,054
protected void process ( StringBuffer buf , Object lang ) { buf . append ( "<rdf:li xml:lang=\"" ) ; buf . append ( lang ) ; buf . append ( "\" >" ) ; buf . append ( get ( lang ) ) ; buf . append ( "</rdf:li>" ) ; }
Process a property .
5,055
protected PdfLine createLine ( float width ) { if ( chunks . isEmpty ( ) ) return null ; splittedChunkText = null ; currentStandbyChunk = null ; PdfLine line = new PdfLine ( 0 , width , alignment , 0 ) ; String total ; for ( currentChunkMarker = 0 ; currentChunkMarker < chunks . size ( ) ; ++ currentChunkMarker ) { Pdf...
Creates a line from the chunk array .
5,056
protected void shortenChunkArray ( ) { if ( currentChunkMarker < 0 ) return ; if ( currentChunkMarker >= chunks . size ( ) ) { chunks . clear ( ) ; return ; } PdfChunk split = ( PdfChunk ) ( chunks . get ( currentChunkMarker ) ) ; split . setValue ( splittedChunkText ) ; chunks . set ( currentChunkMarker , currentStand...
Normalizes the list of chunks when the line is accepted .
5,057
public void setPatternMatrix ( float a , float b , float c , float d , float e , float f ) { setMatrix ( a , b , c , d , e , f ) ; }
Sets the transformation matrix for the pattern .
5,058
public void importRtfDocument ( InputStream readerIn , RtfDocument rtfDoc ) throws IOException { if ( readerIn == null || rtfDoc == null ) return ; this . init ( TYPE_IMPORT_FULL , rtfDoc , readerIn , this . document , null ) ; this . setCurrentDestination ( RtfDestinationMgr . DESTINATION_NULL ) ; this . groupLevel = ...
Imports a complete RTF document .
5,059
public void importRtfDocumentIntoElement ( Element elem , InputStream readerIn , RtfDocument rtfDoc ) throws IOException { if ( readerIn == null || rtfDoc == null || elem == null ) return ; this . init ( TYPE_IMPORT_INTO_ELEMENT , rtfDoc , readerIn , this . document , elem ) ; this . setCurrentDestination ( RtfDestinat...
Imports a complete RTF document into an Element i . e . Chapter section Table Cell etc .
5,060
public void convertRtfDocument ( InputStream readerIn , Document doc ) throws IOException { if ( readerIn == null || doc == null ) return ; this . init ( TYPE_CONVERT , null , readerIn , doc , null ) ; this . setCurrentDestination ( RtfDestinationMgr . DESTINATION_DOCUMENT ) ; this . groupLevel = 0 ; this . tokenise ( ...
Converts an RTF document to an iText document .
5,061
public void importRtfFragment ( InputStream readerIn , RtfDocument rtfDoc , RtfImportMappings importMappings ) throws IOException { if ( readerIn == null || rtfDoc == null || importMappings == null ) return ; this . init ( TYPE_IMPORT_FRAGMENT , rtfDoc , readerIn , null , null ) ; this . handleImportMappings ( importMa...
Imports an RTF fragment .
5,062
private void init ( int type , RtfDocument rtfDoc , InputStream readerIn , Document doc , Element elem ) { init_stats ( ) ; this . pbReader = init_Reader ( readerIn ) ; this . conversionType = type ; this . rtfDoc = rtfDoc ; this . document = doc ; this . elem = elem ; this . currentState = new RtfParserState ( ) ; thi...
Initialize the parser object values .
5,063
protected void init_stats ( ) { byteCount = 0 ; ctrlWordCount = 0 ; openGroupCount = 0 ; closeGroupCount = 0 ; characterCount = 0 ; ctrlWordHandledCount = 0 ; ctrlWordNotHandledCount = 0 ; ctrlWordSkippedCount = 0 ; groupSkippedCount = 0 ; }
Initialize the statistics values .
5,064
private PushbackInputStream init_Reader ( InputStream readerIn ) { if ( ! ( readerIn instanceof BufferedInputStream ) ) { readerIn = new BufferedInputStream ( readerIn ) ; } if ( ! ( readerIn instanceof PushbackInputStream ) ) { readerIn = new PushbackInputStream ( readerIn ) ; } return ( PushbackInputStream ) readerIn...
Casts the input reader to a PushbackReader or creates a new PushbackReader from the Reader passed in . The reader is also transformed into a BufferedReader if necessary .
5,065
private void handleImportMappings ( RtfImportMappings importMappings ) { Iterator it = importMappings . getFontMappings ( ) . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { String fontNr = ( String ) it . next ( ) ; this . importMgr . importFont ( fontNr , ( String ) importMappings . getFontMappings ( ) . get...
Imports the mappings defined in the RtfImportMappings into the RtfImportHeader of this RtfParser2 .
5,066
public int handleCtrlWord ( RtfCtrlWordData ctrlWordData ) { int result = errOK ; this . ctrlWordCount ++ ; if ( debugParser ) { RtfParser . outputDebug ( this . rtfDoc , groupLevel , "DEBUG: handleCtrlWord=" + ctrlWordData . ctrlWord + " param=[" + ctrlWordData . param + "]" ) ; } if ( this . getTokeniserState ( ) == ...
Handles control word tokens . Depending on the current state a control word can lead to a state change . When parsing the actual document contents certain tabled values are remapped . i . e . colors fonts styles etc .
5,067
public boolean setCurrentDestination ( String destination ) { RtfDestination dest = RtfDestinationMgr . getDestination ( destination ) ; if ( dest != null ) { this . currentState . destination = dest ; return false ; } else { this . setTokeniserStateSkipGroup ( ) ; return false ; } }
Set the current destination object for the current state .
5,068
public void tokenise ( ) throws IOException { int nextChar = 0 ; this . setTokeniserState ( TOKENISER_NORMAL ) ; while ( ( nextChar = this . pbReader . read ( ) ) != - 1 ) { this . byteCount ++ ; if ( this . getTokeniserState ( ) == TOKENISER_BINARY ) { if ( parseChar ( nextChar ) != errOK ) return ; } else { switch ( ...
Read through the input file and parse the data stream into tokens .
5,069
private int parseChar ( int nextChar ) { if ( this . getTokeniserState ( ) == TOKENISER_BINARY && -- binByteCount <= 0 ) this . setTokeniserStateNormal ( ) ; if ( this . getTokeniserState ( ) == TOKENISER_SKIP_BYTES && -- binSkipByteCount <= 0 ) this . setTokeniserStateNormal ( ) ; return this . handleCharacter ( nextC...
Process the character and send it to the current destination .
5,070
private int parseCtrlWord ( PushbackInputStream reader ) throws IOException { int nextChar = 0 ; int result = errOK ; if ( ( nextChar = reader . read ( ) ) == - 1 ) { return errEndOfFile ; } this . byteCount ++ ; StringBuffer parsedCtrlWord = new StringBuffer ( ) ; StringBuffer parsedParam = new StringBuffer ( ) ; RtfC...
Parses a keyword and it s parameter if one exists
5,071
public void startElement ( String tag , HashMap h ) { if ( ! foundRoot ) { if ( ! tag . equals ( "xfdf" ) ) { throw new RuntimeException ( "Root element is not Bookmark." ) ; } else { foundRoot = true ; } } if ( tag . equals ( "xfdf" ) ) { } else if ( tag . equals ( "f" ) ) { fileSpec = ( String ) h . get ( "href" ) ; ...
Called when a start tag is found .
5,072
public void endElement ( String tag ) { if ( "value" . equals ( tag ) ) { StringBuilder fName = new StringBuilder ( ) ; for ( int k = 0 ; k < fieldNames . size ( ) ; ++ k ) { fName . append ( "." ) . append ( ( String ) fieldNames . elementAt ( k ) ) ; } if ( fName . charAt ( 0 ) == '.' ) { fName . deleteCharAt ( 0 ) ;...
Called when an end tag is found .
5,073
public void text ( String str ) { if ( fieldNames . isEmpty ( ) || fieldValues . isEmpty ( ) ) return ; String val = ( String ) fieldValues . pop ( ) ; val += str ; fieldValues . push ( val ) ; }
Called when a text element is found .
5,074
private static OCSPReq generateOCSPRequest ( X509Certificate issuerCert , BigInteger serialNumber ) throws OCSPException , IOException , OperatorException , CertificateEncodingException { Security . addProvider ( new org . bouncycastle . jce . provider . BouncyCastleProvider ( ) ) ; JcaDigestCalculatorProviderBuilder d...
Generates an OCSP request using BouncyCastle .
5,075
public static final RuntimeException convertException ( Exception ex ) { if ( ex instanceof RuntimeException ) { return ( RuntimeException ) ex ; } return new ExceptionConverter ( ex ) ; }
Convert an Exception into an unchecked exception . Return the exception if it is already an unchecked exception or return an ExceptionConverter wrapper otherwise
5,076
public void setOutput ( OutputStream stream , String encoding ) throws UnsupportedEncodingException { if ( encoding == null ) { encoding = "UTF8" ; } java . io . Writer writer = new OutputStreamWriter ( stream , encoding ) ; fOut = new PrintWriter ( writer ) ; }
Sets the output stream for printing .
5,077
public void setWidth ( String value ) { if ( value . endsWith ( "%" ) ) { value = value . substring ( 0 , value . length ( ) - 1 ) ; percentage = true ; } width = Integer . parseInt ( value ) ; }
Sets the width . It can be an absolute value 100 or a percentage 20%
5,078
public String getWidthAsString ( ) { String w = String . valueOf ( width ) ; if ( w . endsWith ( ".0" ) ) w = w . substring ( 0 , w . length ( ) - 2 ) ; if ( percentage ) w += "%" ; return w ; }
Gets the width as a String .
5,079
private static Cell getDummyCell ( ) { Cell cell = new Cell ( true ) ; cell . setColspan ( 3 ) ; cell . setBorder ( NO_BORDER ) ; return cell ; }
Get dummy cell used when merging inner tables .
5,080
public PdfPCell createPdfPCell ( ) throws BadElementException { if ( rowspan > 1 ) throw new BadElementException ( "PdfPCells can't have a rowspan > 1" ) ; if ( isTable ( ) ) return new PdfPCell ( ( ( Table ) arrayList . get ( 0 ) ) . createPdfPTable ( ) ) ; PdfPCell cell = new PdfPCell ( ) ; cell . setVerticalAlignmen...
Creates a PdfPCell based on this Cell object .
5,081
public void onGenericTag ( PdfWriter writer , Document document , Rectangle rect , String text ) { indextag . put ( text , Integer . valueOf ( writer . getPageNumber ( ) ) ) ; }
All the text that is passed to this event gets registered in the indexentry .
5,082
public List getSortedEntries ( ) { Map grouped = new HashMap ( ) ; for ( int i = 0 ; i < indexentry . size ( ) ; i ++ ) { Entry e = ( Entry ) indexentry . get ( i ) ; String key = e . getKey ( ) ; Entry master = ( Entry ) grouped . get ( key ) ; if ( master != null ) { master . addPageNumberAndTag ( e . getPageNumber (...
Returns the sorted list with the entries and the collected page numbers .
5,083
private void importRow ( Row row ) { this . cells = new ArrayList ( ) ; this . width = this . document . getDocumentHeader ( ) . getPageSetting ( ) . getPageWidth ( ) - this . document . getDocumentHeader ( ) . getPageSetting ( ) . getMarginLeft ( ) - this . document . getDocumentHeader ( ) . getPageSetting ( ) . getMa...
Imports a Row and copies all settings
5,084
private void importRow ( PdfPRow row ) { this . cells = new ArrayList ( ) ; this . width = this . document . getDocumentHeader ( ) . getPageSetting ( ) . getPageWidth ( ) - this . document . getDocumentHeader ( ) . getPageSetting ( ) . getMarginLeft ( ) - this . document . getDocumentHeader ( ) . getPageSetting ( ) . g...
Imports a PdfPRow and copies all settings
5,085
protected void cleanRow ( ) { int i = 0 ; while ( i < this . cells . size ( ) ) { if ( ( ( RtfCell ) this . cells . get ( i ) ) . isDeleted ( ) ) { this . cells . remove ( i ) ; } else { i ++ ; } } }
Cleans the deleted RtfCells from the total RtfCells .
5,086
public void writeContent ( final OutputStream result ) throws IOException { writeRowDefinition ( result ) ; for ( int i = 0 ; i < this . cells . size ( ) ; i ++ ) { RtfCell rtfCell = ( RtfCell ) this . cells . get ( i ) ; rtfCell . writeContent ( result ) ; } result . write ( DELIMITER ) ; if ( this . document . getDoc...
Writes the content of this RtfRow
5,087
public void registerParagraphStyle ( RtfParagraphStyle rtfParagraphStyle ) { RtfParagraphStyle tempStyle = new RtfParagraphStyle ( this . document , rtfParagraphStyle ) ; tempStyle . handleInheritance ( ) ; tempStyle . setStyleNumber ( this . styleMap . size ( ) ) ; this . styleMap . put ( tempStyle . getStyleName ( ) ...
Register a RtfParagraphStyle with this RtfStylesheetList .
5,088
private void registerDefaultStyles ( ) { defaultsLoaded = true ; if ( ! this . styleMap . containsKey ( RtfParagraphStyle . STYLE_NORMAL . getStyleName ( ) ) ) { registerParagraphStyle ( RtfParagraphStyle . STYLE_NORMAL ) ; } if ( ! this . styleMap . containsKey ( RtfParagraphStyle . STYLE_HEADING_1 . getStyleName ( ) ...
Registers all default styles . If styles with the given name have already been registered then they are NOT overwritten .
5,089
public RtfParagraphStyle getRtfParagraphStyle ( String styleName ) { if ( ! defaultsLoaded ) { registerDefaultStyles ( ) ; } if ( this . styleMap . containsKey ( styleName ) ) { return ( RtfParagraphStyle ) this . styleMap . get ( styleName ) ; } else { return null ; } }
Gets the RtfParagraphStyle with the given name . Makes sure that the defaults have been loaded .
5,090
public void writeDefinition ( final OutputStream result ) throws IOException { result . write ( DocWriter . getISOBytes ( "{" ) ) ; result . write ( DocWriter . getISOBytes ( "\\stylesheet" ) ) ; result . write ( RtfBasicElement . DELIMITER ) ; this . document . outputDebugLinebreak ( result ) ; Iterator it = this . st...
Writes the definition of the stylesheet list .
5,091
public static void fillCache ( int decimals ) { int step = 1 ; switch ( decimals ) { case 0 : step = 100 ; break ; case 1 : step = 10 ; break ; } for ( int i = 1 ; i < byteCacheSize ; i += step ) { if ( byteCache [ i ] != null ) continue ; byteCache [ i ] = convertToBytes ( i ) ; } }
You can fill the cache in advance if you want to .
5,092
public void writeDefinition ( final OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( LIST_TABLE ) ; this . document . outputDebugLinebreak ( result ) ; for ( int i = 0 ; i < picturelists . size ( ) ; i ++ ) { RtfPictureList l = ( RtfPictureList ) picturelists . get ( i ) ; l ....
Writes the list and list override tables .
5,093
public int getListNumber ( RtfList list ) { if ( lists . contains ( list ) ) { return lists . indexOf ( list ) ; } else { lists . add ( list ) ; return lists . size ( ) ; } }
Gets the id of the specified RtfList . If the RtfList is not yet in the list of RtfList then it is added .
5,094
public void freeListNumber ( RtfList list ) { int i = lists . indexOf ( list ) ; if ( i >= 0 ) { lists . remove ( i ) ; } }
Remove a RtfList from the list of RtfList
5,095
public void writeTo ( OutputStream os ) throws IOException { Wrt wrt = new Wrt ( os , this ) ; wrt . writeTo ( ) ; }
Writes the content to a stream .
5,096
public boolean removeField ( String field ) { HashMap map = fields ; StringTokenizer tk = new StringTokenizer ( field , "." ) ; if ( ! tk . hasMoreTokens ( ) ) return false ; ArrayList hist = new ArrayList ( ) ; while ( true ) { String s = tk . nextToken ( ) ; Object obj = map . get ( s ) ; if ( obj == null ) return fa...
Removes the field value .
5,097
public boolean setFieldAsString ( String field , String value ) { return setField ( field , new PdfString ( value , PdfObject . TEXT_UNICODE ) ) ; }
Sets the field value as a string .
5,098
public void initializeStringTable ( ) { stringTable = new byte [ 4096 ] [ ] ; for ( int i = 0 ; i < 256 ; i ++ ) { stringTable [ i ] = new byte [ 1 ] ; stringTable [ i ] [ 0 ] = ( byte ) i ; } tableIndex = 258 ; bitsToGet = 9 ; }
Initialize the string table .
5,099
public void writeString ( byte string [ ] ) { int max = uncompData . length - dstIndex ; if ( string . length < max ) max = string . length ; System . arraycopy ( string , 0 , uncompData , dstIndex , max ) ; dstIndex += max ; }
Write out the string just uncompressed .