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 . PHRASE : case Element . SECTION : case Element . ANCHOR : case Element . CHAPTER : case Element . LISTITEM : case Element . PARAGRAPH : for ( i = ( ( ArrayList ) element ) . iterator ( ) ; i . hasNext ( ) ; ) { processActions ( ( Element ) i . next ( ) , action , allActions ) ; } break ; case Element . CHUNK : allActions . add ( action ) ; break ; case Element . LIST : for ( i = ( ( List ) element ) . getItems ( ) . iterator ( ) ; i . hasNext ( ) ; ) { processActions ( ( Element ) i . next ( ) , action , allActions ) ; } break ; default : int n = element . getChunks ( ) . size ( ) ; while ( n -- > 0 ) allActions . add ( action ) ; break ; } }
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 . LOCALGOTO ) ; if ( value != null ) { chunk . setLocalGoto ( value ) ; } value = attributes . getProperty ( ElementTags . REMOTEGOTO ) ; if ( value != null ) { String page = attributes . getProperty ( ElementTags . PAGE ) ; if ( page != null ) { chunk . setRemoteGoto ( value , Integer . parseInt ( page ) ) ; } else { String destination = attributes . getProperty ( ElementTags . DESTINATION ) ; if ( destination != null ) { chunk . setRemoteGoto ( value , destination ) ; } } } value = attributes . getProperty ( ElementTags . LOCALDESTINATION ) ; if ( value != null ) { chunk . setLocalDestination ( value ) ; } value = attributes . getProperty ( ElementTags . SUBSUPSCRIPT ) ; if ( value != null ) { chunk . setTextRise ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( Markup . CSS_KEY_VERTICALALIGN ) ; if ( value != null && value . endsWith ( "%" ) ) { float p = Float . parseFloat ( value . substring ( 0 , value . length ( ) - 1 ) + "f" ) / 100f ; chunk . setTextRise ( p * chunk . getFont ( ) . getSize ( ) ) ; } value = attributes . getProperty ( ElementTags . GENERICTAG ) ; if ( value != null ) { chunk . setGenericTag ( value ) ; } value = attributes . getProperty ( ElementTags . BACKGROUNDCOLOR ) ; if ( value != null ) { chunk . setBackground ( Markup . decodeColor ( value ) ) ; } return chunk ; }
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 = attributes . getProperty ( Markup . CSS_KEY_LINEHEIGHT ) ; if ( value != null ) { phrase . setLeading ( Markup . parseLength ( value , Markup . DEFAULT_FONT_SIZE ) ) ; } value = attributes . getProperty ( ElementTags . ITEXT ) ; if ( value != null ) { Chunk chunk = new Chunk ( value ) ; if ( ( value = attributes . getProperty ( ElementTags . GENERICTAG ) ) != null ) { chunk . setGenericTag ( value ) ; } phrase . add ( chunk ) ; } return phrase ; }
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 ( value != null ) { anchor . setReference ( value ) ; } return anchor ; }
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 . INDENTATIONLEFT ) ; if ( value != null ) { paragraph . setIndentationLeft ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( ElementTags . INDENTATIONRIGHT ) ; if ( value != null ) { paragraph . setIndentationRight ( Float . parseFloat ( value + "f" ) ) ; } return paragraph ; }
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 ( attributes , ElementTags . LOWERCASE ) ) ; list . setAutoindent ( Utilities . checkTrueOrFalse ( attributes , ElementTags . AUTO_INDENT_ITEMS ) ) ; list . setAlignindent ( Utilities . checkTrueOrFalse ( attributes , ElementTags . ALIGN_INDENTATION_ITEMS ) ) ; String value ; value = attributes . getProperty ( ElementTags . FIRST ) ; if ( value != null ) { char character = value . charAt ( 0 ) ; if ( Character . isLetter ( character ) ) { list . setFirst ( character ) ; } else { list . setFirst ( Integer . parseInt ( value ) ) ; } } value = attributes . getProperty ( ElementTags . LISTSYMBOL ) ; if ( value != null ) { list . setListSymbol ( new Chunk ( value , FontFactory . getFont ( attributes ) ) ) ; } value = attributes . getProperty ( ElementTags . INDENTATIONLEFT ) ; if ( value != null ) { list . setIndentationLeft ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( ElementTags . INDENTATIONRIGHT ) ; if ( value != null ) { list . setIndentationRight ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( ElementTags . SYMBOLINDENT ) ; if ( value != null ) { list . setSymbolIndent ( Float . parseFloat ( value ) ) ; } return list ; }
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 ( ElementTags . WIDTH ) ; if ( value != null ) { cell . setWidth ( value ) ; } value = attributes . getProperty ( ElementTags . COLSPAN ) ; if ( value != null ) { cell . setColspan ( Integer . parseInt ( value ) ) ; } value = attributes . getProperty ( ElementTags . ROWSPAN ) ; if ( value != null ) { cell . setRowspan ( Integer . parseInt ( value ) ) ; } value = attributes . getProperty ( ElementTags . LEADING ) ; if ( value != null ) { cell . setLeading ( Float . parseFloat ( value + "f" ) ) ; } cell . setHeader ( Utilities . checkTrueOrFalse ( attributes , ElementTags . HEADER ) ) ; if ( Utilities . checkTrueOrFalse ( attributes , ElementTags . NOWRAP ) ) { cell . setMaxLines ( 1 ) ; } setRectangleProperties ( cell , attributes ) ; return cell ; }
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 . getInstance ( value ) ; value = attributes . getProperty ( ElementTags . ALIGN ) ; int align = 0 ; if ( value != null ) { if ( ElementTags . ALIGN_LEFT . equalsIgnoreCase ( value ) ) align |= Image . LEFT ; else if ( ElementTags . ALIGN_RIGHT . equalsIgnoreCase ( value ) ) align |= Image . RIGHT ; else if ( ElementTags . ALIGN_MIDDLE . equalsIgnoreCase ( value ) ) align |= Image . MIDDLE ; } if ( "true" . equalsIgnoreCase ( attributes . getProperty ( ElementTags . UNDERLYING ) ) ) align |= Image . UNDERLYING ; if ( "true" . equalsIgnoreCase ( attributes . getProperty ( ElementTags . TEXTWRAP ) ) ) align |= Image . TEXTWRAP ; image . setAlignment ( align ) ; value = attributes . getProperty ( ElementTags . ALT ) ; if ( value != null ) { image . setAlt ( value ) ; } String x = attributes . getProperty ( ElementTags . ABSOLUTEX ) ; String y = attributes . getProperty ( ElementTags . ABSOLUTEY ) ; if ( ( x != null ) && ( y != null ) ) { image . setAbsolutePosition ( Float . parseFloat ( x + "f" ) , Float . parseFloat ( y + "f" ) ) ; } value = attributes . getProperty ( ElementTags . PLAINWIDTH ) ; if ( value != null ) { image . scaleAbsoluteWidth ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( ElementTags . PLAINHEIGHT ) ; if ( value != null ) { image . scaleAbsoluteHeight ( Float . parseFloat ( value + "f" ) ) ; } value = attributes . getProperty ( ElementTags . ROTATION ) ; if ( value != null ) { image . setRotation ( Float . parseFloat ( value + "f" ) ) ; } return image ; }
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 != null ) { lly = Float . parseFloat ( value + "f" ) ; } value = attributes . getProperty ( ElementTags . URX ) ; if ( value != null ) { urx = Float . parseFloat ( value + "f" ) ; } value = attributes . getProperty ( ElementTags . URY ) ; if ( value != null ) { ury = Float . parseFloat ( value + "f" ) ; } String title = attributes . getProperty ( ElementTags . TITLE ) ; String text = attributes . getProperty ( ElementTags . CONTENT ) ; if ( title != null || text != null ) { return new Annotation ( title , text , llx , lly , urx , ury ) ; } value = attributes . getProperty ( ElementTags . URL ) ; if ( value != null ) { return new Annotation ( llx , lly , urx , ury , value ) ; } value = attributes . getProperty ( ElementTags . NAMED ) ; if ( value != null ) { return new Annotation ( llx , lly , urx , ury , Integer . parseInt ( value ) ) ; } String file = attributes . getProperty ( ElementTags . FILE ) ; String destination = attributes . getProperty ( ElementTags . DESTINATION ) ; String page = ( String ) attributes . remove ( ElementTags . PAGE ) ; if ( file != null ) { if ( destination != null ) { return new Annotation ( llx , lly , urx , ury , file , destination ) ; } if ( page != null ) { return new Annotation ( llx , lly , urx , ury , file , Integer . parseInt ( page ) ) ; } } return new Annotation ( "" , "" , llx , lly , urx , ury ) ; }
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 ) return 0 ; else return 20000 - line . widthLeft ( ) ; }
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 . write ( COLON ) ; }
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 pos = 0 ; while ( true ) { RomanDigit dig = roman [ pos ] ; while ( index >= dig . value ) { buf . append ( dig . digit ) ; index -= dig . value ; } if ( index <= 0 ) { break ; } int j = pos ; while ( ! roman [ ++ j ] . pre ) ; if ( index + roman [ j ] . value >= dig . value ) { buf . append ( roman [ j ] . digit ) . append ( dig . digit ) ; index -= dig . value - roman [ j ] . value ; } pos ++ ; } return buf . toString ( ) ; }
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 ) [ index ] ; case TIFF_SLONG : return ( ( int [ ] ) data ) [ index ] ; default : throw new ClassCastException ( ) ; } }
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 ) [ index ] ; case TIFF_SLONG : return ( ( int [ ] ) data ) [ index ] ; case TIFF_LONG : return ( ( long [ ] ) data ) [ index ] ; default : throw new ClassCastException ( ) ; } }
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_SLONG : return ( ( int [ ] ) data ) [ index ] ; case TIFF_LONG : return ( ( long [ ] ) data ) [ index ] ; case TIFF_FLOAT : return ( ( float [ ] ) data ) [ index ] ; case TIFF_DOUBLE : return ( float ) ( ( double [ ] ) data ) [ index ] ; case TIFF_SRATIONAL : int [ ] ivalue = getAsSRational ( index ) ; return ( float ) ( ( double ) ivalue [ 0 ] / ivalue [ 1 ] ) ; case TIFF_RATIONAL : long [ ] lvalue = getAsRational ( index ) ; return ( float ) ( ( double ) lvalue [ 0 ] / lvalue [ 1 ] ) ; default : throw new ClassCastException ( ) ; } }
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 ( ) != PRTokeniser . TK_NAME ) throw new IOException ( "Dictionary key is not a name." ) ; PdfName name = new PdfName ( tokeniser . getStringValue ( ) , false ) ; PdfObject obj = readPRObject ( ) ; int type = obj . type ( ) ; if ( - type == PRTokeniser . TK_END_DIC ) throw new IOException ( "Unexpected '>>'" ) ; if ( - type == PRTokeniser . TK_END_ARRAY ) throw new IOException ( "Unexpected ']'" ) ; dic . put ( name , obj ) ; } return dic ; }
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 ( obj ) ; } return array ; }
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 PRTokeniser . TK_STRING : PdfString str = new PdfString ( tokeniser . getStringValue ( ) , null ) . setHexWriting ( tokeniser . isHexString ( ) ) ; return str ; case PRTokeniser . TK_NAME : return new PdfName ( tokeniser . getStringValue ( ) , false ) ; case PRTokeniser . TK_NUMBER : return new PdfNumber ( tokeniser . getStringValue ( ) ) ; case PRTokeniser . TK_OTHER : return new PdfLiteral ( COMMAND_TYPE , tokeniser . getStringValue ( ) ) ; default : return new PdfLiteral ( - type , tokeniser . getStringValue ( ) ) ; } }
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 attribute = getName ( attrs . getQName ( i ) ) ; attributes . setProperty ( attribute , attrs . getValue ( i ) ) ; } } return attributes ; }
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 if ( this . displayAt == DISPLAY_LEFT_PAGES ) { result . write ( HEADER_LEFT ) ; } else if ( this . displayAt == DISPLAY_RIGHT_PAGES ) { result . write ( HEADER_RIGHT ) ; } } else { if ( this . displayAt == DISPLAY_ALL_PAGES ) { result . write ( FOOTER_ALL ) ; } else if ( this . displayAt == DISPLAY_FIRST_PAGE ) { result . write ( FOOTER_FIRST ) ; } else if ( this . displayAt == DISPLAY_LEFT_PAGES ) { result . write ( FOOTER_LEFT ) ; } else if ( this . displayAt == DISPLAY_RIGHT_PAGES ) { result . write ( FOOTER_RIGHT ) ; } } result . write ( DELIMITER ) ; for ( int i = 0 ; i < this . content . length ; i ++ ) { if ( this . content [ i ] instanceof RtfBasicElement ) { RtfBasicElement rbe = ( RtfBasicElement ) this . content [ i ] ; rbe . writeContent ( result ) ; } } result . write ( CLOSE_GROUP ) ; }
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 ) { ( ( Table ) this . content [ i ] ) . setAlignment ( alignment ) ; } else if ( this . content [ i ] instanceof Image ) { ( ( Image ) this . content [ i ] ) . setAlignment ( alignment ) ; } } }
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 = new RtfDiskCache ( ) ; break ; default : throw new RuntimeException ( "unknown" ) ; } } catch ( IOException ioe ) { System . err . println ( "Could not initialize disk cache. Using memory cache." ) ; ioe . printStackTrace ( ) ; this . data = new RtfMemoryCache ( ) ; } }
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 . getOutputStream ( ) ) ; this . lastElementWritten = element ; } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } }
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 . markupAttributes ; return mo ; }
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 ) attributekey = attributekey . toLowerCase ( ) ; break ; case QUOTE : case ATTRIBUTE_VALUE : attributevalue = text . toString ( ) ; attributes . put ( attributekey , attributevalue ) ; break ; default : } text . setLength ( 0 ) ; }
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;" ) ; break ; case '&' : sb . append ( "&amp;" ) ; break ; case '"' : sb . append ( "&quot;" ) ; break ; case '\'' : sb . append ( "&apos;" ) ; break ; default : if ( ( c == 0x9 ) || ( c == 0xA ) || ( c == 0xD ) || ( ( c >= 0x20 ) && ( c <= 0xD7FF ) ) || ( ( c >= 0xE000 ) && ( c <= 0xFFFD ) ) || ( ( c >= 0x10000 ) && ( c <= 0x10FFFF ) ) ) { if ( onlyASCII && c > 127 ) sb . append ( "&#" ) . append ( c ) . append ( ';' ) ; else sb . append ( ( char ) c ) ; } } } return sb . toString ( ) ; }
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 (T42UV)\n" + "/Supplement 0\n" + ">> def\n" + "/CMapName /TTX+0 def\n" + "/CMapType 2 def\n" + "1 begincodespacerange\n" + "<0000><FFFF>\n" + "endcodespacerange\n" ) ; int size = 0 ; for ( int k = 0 ; k < metrics . length ; ++ k ) { if ( size == 0 ) { if ( k != 0 ) { buf . append ( "endbfrange\n" ) ; } size = Math . min ( 100 , metrics . length - k ) ; buf . append ( size ) . append ( " beginbfrange\n" ) ; } -- size ; int metric [ ] = ( int [ ] ) metrics [ k ] ; String fromTo = toHex ( metric [ 0 ] ) ; buf . append ( fromTo ) . append ( fromTo ) . append ( toHex ( metric [ 2 ] ) ) . append ( '\n' ) ; } buf . append ( "endbfrange\n" + "endcmap\n" + "CMapName currentdict /CMap defineresource pop\n" + "end end\n" ) ; String s = buf . toString ( ) ; PdfStream stream = new PdfStream ( PdfEncodings . convertToBytes ( s , null ) ) ; stream . flateCompress ( compressionLevel ) ; return stream ; }
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 + fontName + "-" + encoding ) ) ; } else { dic . put ( PdfName . SUBTYPE , PdfName . CIDFONTTYPE2 ) ; dic . put ( PdfName . BASEFONT , new PdfName ( subsetPrefix + fontName ) ) ; } dic . put ( PdfName . FONTDESCRIPTOR , fontDescriptor ) ; if ( ! cff ) dic . put ( PdfName . CIDTOGIDMAP , PdfName . IDENTITY ) ; PdfDictionary cdic = new PdfDictionary ( ) ; cdic . put ( PdfName . REGISTRY , new PdfString ( "Adobe" ) ) ; cdic . put ( PdfName . ORDERING , new PdfString ( "Identity" ) ) ; cdic . put ( PdfName . SUPPLEMENT , new PdfNumber ( 0 ) ) ; dic . put ( PdfName . CIDSYSTEMINFO , cdic ) ; if ( ! vertical ) { dic . put ( PdfName . DW , new PdfNumber ( 1000 ) ) ; StringBuffer buf = new StringBuffer ( "[" ) ; int lastNumber = - 10 ; boolean firstTime = true ; for ( int k = 0 ; k < metrics . length ; ++ k ) { int metric [ ] = ( int [ ] ) metrics [ k ] ; if ( metric [ 1 ] == 1000 ) continue ; int m = metric [ 0 ] ; if ( m == lastNumber + 1 ) { buf . append ( ' ' ) . append ( metric [ 1 ] ) ; } else { if ( ! firstTime ) { buf . append ( ']' ) ; } firstTime = false ; buf . append ( m ) . append ( '[' ) . append ( metric [ 1 ] ) ; } lastNumber = m ; } if ( buf . length ( ) > 1 ) { buf . append ( "]]" ) ; dic . put ( PdfName . W , new PdfLiteral ( buf . toString ( ) ) ) ; } } return dic ; }
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 + fontName + "-" + encoding ) ) ; else dic . put ( PdfName . BASEFONT , new PdfName ( subsetPrefix + fontName ) ) ; dic . put ( PdfName . ENCODING , new PdfName ( encoding ) ) ; dic . put ( PdfName . DESCENDANTFONTS , new PdfArray ( descendant ) ) ; if ( toUnicode != null ) dic . put ( PdfName . TOUNICODE , toUnicode ) ; return dic ; }
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 ) { PdfChunk original = ( PdfChunk ) ( chunks . get ( currentChunkMarker ) ) ; total = original . toString ( ) ; currentStandbyChunk = line . add ( original ) ; if ( currentStandbyChunk != null ) { splittedChunkText = original . toString ( ) ; original . setValue ( total ) ; return line ; } } return line ; }
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 , currentStandbyChunk ) ; for ( int j = currentChunkMarker - 1 ; j >= 0 ; -- j ) chunks . remove ( j ) ; }
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 = 0 ; try { this . tokenise ( ) ; } catch ( RuntimeException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
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 ( RtfDestinationMgr . DESTINATION_NULL ) ; this . groupLevel = 0 ; try { this . tokenise ( ) ; } catch ( RuntimeException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
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 ( importMappings ) ; this . setCurrentDestination ( RtfDestinationMgr . DESTINATION_DOCUMENT ) ; this . groupLevel = 1 ; setParserState ( RtfParser . PARSER_IN_DOCUMENT ) ; this . tokenise ( ) ; }
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 ( ) ; this . stackState = new Stack ( ) ; this . setParserState ( PARSER_STARTSTOP ) ; this . importMgr = new RtfImportMgr ( this . rtfDoc , this . document ) ; this . destinationMgr = RtfDestinationMgr . getInstance ( this ) ; RtfDestinationMgr . setParser ( this ) ; this . rtfKeywordMgr = new RtfCtrlWordMgr ( this , this . pbReader ) ; Object listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = iterator . next ( ) ; if ( listener instanceof RtfCtrlWordListener ) { this . rtfKeywordMgr . addRtfCtrlWordListener ( ( RtfCtrlWordListener ) listener ) ; } } }
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 ( fontNr ) ) ; } it = importMappings . getColorMappings ( ) . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { String colorNr = ( String ) it . next ( ) ; this . importMgr . importColor ( colorNr , ( Color ) importMappings . getColorMappings ( ) . get ( colorNr ) ) ; } it = importMappings . getListMappings ( ) . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { String listNr = ( String ) it . next ( ) ; this . importMgr . importList ( listNr , ( String ) importMappings . getListMappings ( ) . get ( listNr ) ) ; } it = importMappings . getStylesheetListMappings ( ) . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { String stylesheetListNr = ( String ) it . next ( ) ; this . importMgr . importStylesheetList ( stylesheetListNr , ( List ) importMappings . getStylesheetListMappings ( ) . get ( stylesheetListNr ) ) ; } }
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 ( ) == TOKENISER_SKIP_GROUP ) { this . ctrlWordSkippedCount ++ ; if ( debugParser ) { RtfParser . outputDebug ( this . rtfDoc , groupLevel , "DEBUG: SKIPPED" ) ; } return result ; } result = this . rtfKeywordMgr . handleKeyword ( ctrlWordData , this . groupLevel ) ; if ( result == errOK ) { this . ctrlWordHandledCount ++ ; } else { this . ctrlWordNotHandledCount ++ ; result = errOK ; } return result ; }
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 ( nextChar ) { case '{' : this . handleOpenGroup ( ) ; break ; case '}' : this . handleCloseGroup ( ) ; break ; case 0x0a : case 0x0d : break ; case '\\' : if ( parseCtrlWord ( pbReader ) != errOK ) { return ; } break ; default : if ( groupLevel == 0 ) { break ; } if ( this . getTokeniserState ( ) == TOKENISER_HEX ) { StringBuffer hexChars = new StringBuffer ( ) ; hexChars . append ( nextChar ) ; if ( ( nextChar = pbReader . read ( ) ) == - 1 ) { return ; } this . byteCount ++ ; hexChars . append ( nextChar ) ; try { nextChar = Integer . parseInt ( hexChars . toString ( ) , 16 ) ; } catch ( NumberFormatException e ) { return ; } this . setTokeniserState ( TOKENISER_NORMAL ) ; } if ( parseChar ( nextChar ) != errOK ) { return ; } break ; } } } RtfDestination dest = this . getCurrentDestination ( ) ; if ( dest != null ) { dest . closeDestination ( ) ; } }
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 ( nextChar ) ; }
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 ( ) ; RtfCtrlWordData ctrlWordParam = new RtfCtrlWordData ( ) ; if ( ! Character . isLetterOrDigit ( ( char ) nextChar ) ) { parsedCtrlWord . append ( ( char ) nextChar ) ; ctrlWordParam . ctrlWord = parsedCtrlWord . toString ( ) ; result = this . handleCtrlWord ( ctrlWordParam ) ; lastCtrlWordParam = ctrlWordParam ; return result ; } do { parsedCtrlWord . append ( ( char ) nextChar ) ; nextChar = reader . read ( ) ; this . byteCount ++ ; } while ( Character . isLetter ( ( char ) nextChar ) ) ; ctrlWordParam . ctrlWord = parsedCtrlWord . toString ( ) ; if ( nextChar == '-' ) { ctrlWordParam . isNeg = true ; if ( ( nextChar = reader . read ( ) ) == - 1 ) { return errEndOfFile ; } this . byteCount ++ ; } if ( Character . isDigit ( ( char ) nextChar ) ) { ctrlWordParam . hasParam = true ; do { parsedParam . append ( ( char ) nextChar ) ; nextChar = reader . read ( ) ; this . byteCount ++ ; } while ( Character . isDigit ( ( char ) nextChar ) ) ; ctrlWordParam . param = parsedParam . toString ( ) ; } if ( nextChar != ' ' ) { reader . unread ( nextChar ) ; } if ( debugParser ) { } result = this . handleCtrlWord ( ctrlWordParam ) ; lastCtrlWordParam = ctrlWordParam ; return result ; }
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" ) ; } else if ( tag . equals ( "fields" ) ) { fields = new HashMap ( ) ; listFields = new HashMap ( ) ; } else if ( tag . equals ( "field" ) ) { String fName = ( String ) h . get ( "name" ) ; fieldNames . push ( fName ) ; } else if ( tag . equals ( "value" ) ) { fieldValues . push ( "" ) ; } }
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 ) ; } String fNameString = fName . toString ( ) ; String fVal = ( String ) fieldValues . pop ( ) ; String old = ( String ) fields . put ( fNameString , fVal ) ; if ( old != null ) { List l = ( List ) listFields . get ( fNameString ) ; if ( l == null ) { l = new ArrayList ( ) ; l . add ( old ) ; } l . add ( fVal ) ; listFields . put ( fNameString , l ) ; } } else if ( "field" . equals ( tag ) ) { if ( ! fieldNames . isEmpty ( ) ) { fieldNames . pop ( ) ; } } }
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 digestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder ( ) ; DigestCalculatorProvider digestCalculatorProvider = digestCalculatorProviderBuilder . build ( ) ; DigestCalculator digestCalculator = digestCalculatorProvider . get ( CertificateID . HASH_SHA1 ) ; CertificateID id = new CertificateID ( digestCalculator , new JcaX509CertificateHolder ( issuerCert ) , serialNumber ) ; OCSPReqBuilder gen = new OCSPReqBuilder ( ) ; gen . addRequest ( id ) ; Extension ext = new Extension ( OCSPObjectIdentifiers . id_pkix_ocsp_nonce , false , new DEROctetString ( new DEROctetString ( PdfEncryption . createDocumentId ( ) ) . getEncoded ( ) ) ) ; gen . setRequestExtensions ( new Extensions ( new Extension [ ] { ext } ) ) ; return gen . build ( ) ; }
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 . setVerticalAlignment ( verticalAlignment ) ; cell . setHorizontalAlignment ( horizontalAlignment ) ; cell . setColspan ( colspan ) ; cell . setUseBorderPadding ( useBorderPadding ) ; cell . setUseDescender ( useDescender ) ; cell . setLeading ( getLeading ( ) , 0 ) ; cell . cloneNonPositionParameters ( this ) ; cell . setNoWrap ( getMaxLines ( ) == 1 ) ; for ( Iterator i = getElements ( ) ; i . hasNext ( ) ; ) { Element e = ( Element ) i . next ( ) ; if ( e . type ( ) == Element . PHRASE || e . type ( ) == Element . PARAGRAPH ) { Paragraph p = new Paragraph ( ( Phrase ) e ) ; p . setAlignment ( horizontalAlignment ) ; e = p ; } cell . addElement ( e ) ; } return cell ; }
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 ( ) , e . getTag ( ) ) ; } else { e . addPageNumberAndTag ( e . getPageNumber ( ) , e . getTag ( ) ) ; grouped . put ( key , e ) ; } } List sorted = new ArrayList ( grouped . values ( ) ) ; Collections . sort ( sorted , comparator ) ; return sorted ; }
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 ( ) . getMarginRight ( ) ; this . width = ( int ) ( this . width * this . parentTable . getTableWidthPercent ( ) / 100 ) ; int cellRight = 0 ; int cellWidth = 0 ; for ( int i = 0 ; i < row . getColumns ( ) ; i ++ ) { cellWidth = ( int ) ( this . width * this . parentTable . getProportionalWidths ( ) [ i ] / 100 ) ; cellRight = cellRight + cellWidth ; Cell cell = ( Cell ) row . getCell ( i ) ; RtfCell rtfCell = new RtfCell ( this . document , this , cell ) ; rtfCell . setCellRight ( cellRight ) ; rtfCell . setCellWidth ( cellWidth ) ; this . cells . add ( rtfCell ) ; } }
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 ( ) . getMarginRight ( ) ; this . width = ( int ) ( this . width * this . parentTable . getTableWidthPercent ( ) / 100 ) ; int cellRight = 0 ; int cellWidth = 0 ; PdfPCell [ ] cells = row . getCells ( ) ; for ( int i = 0 ; i < cells . length ; i ++ ) { cellWidth = ( int ) ( this . width * this . parentTable . getProportionalWidths ( ) [ i ] / 100 ) ; cellRight = cellRight + cellWidth ; PdfPCell cell = cells [ i ] ; RtfCell rtfCell = new RtfCell ( this . document , this , cell ) ; rtfCell . setCellRight ( cellRight ) ; rtfCell . setCellWidth ( cellWidth ) ; this . cells . add ( rtfCell ) ; } }
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 . getDocumentSettings ( ) . isOutputTableRowDefinitionAfter ( ) ) { writeRowDefinition ( result ) ; } result . write ( ROW_END ) ; this . document . outputDebugLinebreak ( result ) ; }
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 ( ) , tempStyle ) ; }
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 ( ) ) ) { registerParagraphStyle ( RtfParagraphStyle . STYLE_HEADING_1 ) ; } if ( ! this . styleMap . containsKey ( RtfParagraphStyle . STYLE_HEADING_2 . getStyleName ( ) ) ) { registerParagraphStyle ( RtfParagraphStyle . STYLE_HEADING_2 ) ; } if ( ! this . styleMap . containsKey ( RtfParagraphStyle . STYLE_HEADING_3 . getStyleName ( ) ) ) { registerParagraphStyle ( RtfParagraphStyle . STYLE_HEADING_3 ) ; } }
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 . styleMap . values ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { RtfParagraphStyle rps = ( RtfParagraphStyle ) it . next ( ) ; rps . writeDefinition ( result ) ; } result . write ( DocWriter . getISOBytes ( "}" ) ) ; this . document . outputDebugLinebreak ( result ) ; }
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 . writeDefinition ( result ) ; this . document . outputDebugLinebreak ( result ) ; } for ( int i = 0 ; i < lists . size ( ) ; i ++ ) { RtfList l = ( RtfList ) lists . get ( i ) ; l . setID ( document . getRandomInt ( ) ) ; l . writeDefinition ( result ) ; this . document . outputDebugLinebreak ( result ) ; } result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; result . write ( OPEN_GROUP ) ; result . write ( LIST_OVERRIDE_TABLE ) ; this . document . outputDebugLinebreak ( result ) ; for ( int i = 0 ; i < lists . size ( ) ; i ++ ) { result . write ( OPEN_GROUP ) ; result . write ( LIST_OVERRIDE ) ; result . write ( RtfList . LIST_ID ) ; result . write ( intToByteArray ( ( ( RtfList ) lists . get ( i ) ) . getID ( ) ) ) ; result . write ( LIST_OVERRIDE_COUNT ) ; result . write ( intToByteArray ( 0 ) ) ; result . write ( RtfList . LIST_NUMBER ) ; result . write ( intToByteArray ( ( ( RtfList ) lists . get ( i ) ) . getListNumber ( ) ) ) ; result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; } result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; }
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 false ; hist . add ( map ) ; hist . add ( s ) ; if ( tk . hasMoreTokens ( ) ) { if ( obj instanceof HashMap ) map = ( HashMap ) obj ; else return false ; } else { if ( obj instanceof HashMap ) return false ; else break ; } } for ( int k = hist . size ( ) - 2 ; k >= 0 ; k -= 2 ) { map = ( HashMap ) hist . get ( k ) ; String s = ( String ) hist . get ( k + 1 ) ; map . remove ( s ) ; if ( ! map . isEmpty ( ) ) break ; } return true ; }
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 .