idx
int64 0
41.2k
| question
stringlengths 73
5.81k
| target
stringlengths 5
918
|
|---|---|---|
5,200
|
public void writeContent ( final OutputStream result ) throws IOException { result . write ( PARAGRAPH_DEFAULTS ) ; result . write ( PLAIN ) ; if ( inTable ) { result . write ( IN_TABLE ) ; } if ( this . paragraphStyle != null ) { this . paragraphStyle . writeBegin ( result ) ; } result . write ( DocWriter . getISOBytes ( "\\plain" ) ) ; for ( int i = 0 ; i < chunks . size ( ) ; i ++ ) { RtfBasicElement rbe = ( RtfBasicElement ) chunks . get ( i ) ; rbe . writeContent ( result ) ; } if ( this . paragraphStyle != null ) { this . paragraphStyle . writeEnd ( result ) ; } if ( ! inTable ) { result . write ( PARAGRAPH ) ; } this . document . outputDebugLinebreak ( result ) ; }
|
Writes the content of this RtfParagraph . First paragraph specific data is written and then the RtfChunks of this RtfParagraph are added .
|
5,201
|
private void writeFieldBegin ( OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( FIELD ) ; if ( fieldDirty ) result . write ( FIELD_DIRTY ) ; if ( fieldEdit ) result . write ( FIELD_EDIT ) ; if ( fieldLocked ) result . write ( FIELD_LOCKED ) ; if ( fieldPrivate ) result . write ( FIELD_PRIVATE ) ; }
|
Writes the field beginning . Also writes field properties .
|
5,202
|
private void writeFieldInstBegin ( OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( FIELD_INSTRUCTIONS ) ; result . write ( DELIMITER ) ; }
|
Writes the beginning of the field instruction area .
|
5,203
|
private void writeFieldInstEnd ( OutputStream result ) throws IOException { if ( fieldAlt ) { result . write ( DELIMITER ) ; result . write ( FIELD_ALT ) ; } result . write ( CLOSE_GROUP ) ; }
|
Writes the end of the field instruction area .
|
5,204
|
private void writeFieldResultBegin ( final OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( FIELD_RESULT ) ; result . write ( DELIMITER ) ; }
|
Writes the beginning of the field result area
|
5,205
|
private void writeFieldResultEnd ( final OutputStream result ) throws IOException { result . write ( DELIMITER ) ; result . write ( CLOSE_GROUP ) ; }
|
Writes the end of the field result area
|
5,206
|
public void writeContent ( final OutputStream result ) throws IOException { result . write ( DocWriter . getISOBytes ( "\\shpleft" ) ) ; result . write ( intToByteArray ( this . left ) ) ; result . write ( DocWriter . getISOBytes ( "\\shptop" ) ) ; result . write ( intToByteArray ( this . top ) ) ; result . write ( DocWriter . getISOBytes ( "\\shpright" ) ) ; result . write ( intToByteArray ( this . right ) ) ; result . write ( DocWriter . getISOBytes ( "\\shpbottom" ) ) ; result . write ( intToByteArray ( this . bottom ) ) ; result . write ( DocWriter . getISOBytes ( "\\shpz" ) ) ; result . write ( intToByteArray ( this . zOrder ) ) ; switch ( this . xRelativePos ) { case POSITION_X_RELATIVE_PAGE : result . write ( DocWriter . getISOBytes ( "\\shpbxpage" ) ) ; break ; case POSITION_X_RELATIVE_MARGIN : result . write ( DocWriter . getISOBytes ( "\\shpbxmargin" ) ) ; break ; case POSITION_X_RELATIVE_COLUMN : result . write ( DocWriter . getISOBytes ( "\\shpbxcolumn" ) ) ; break ; } if ( this . ignoreXRelative ) { result . write ( DocWriter . getISOBytes ( "\\shpbxignore" ) ) ; } switch ( this . yRelativePos ) { case POSITION_Y_RELATIVE_PAGE : result . write ( DocWriter . getISOBytes ( "\\shpbypage" ) ) ; break ; case POSITION_Y_RELATIVE_MARGIN : result . write ( DocWriter . getISOBytes ( "\\shpbymargin" ) ) ; break ; case POSITION_Y_RELATIVE_PARAGRAPH : result . write ( DocWriter . getISOBytes ( "\\shpbypara" ) ) ; break ; } if ( this . ignoreYRelative ) { result . write ( DocWriter . getISOBytes ( "\\shpbyignore" ) ) ; } if ( this . shapeBelowText ) { result . write ( DocWriter . getISOBytes ( "\\shpfblwtxt1" ) ) ; } else { result . write ( DocWriter . getISOBytes ( "\\shpfblwtxt0" ) ) ; } }
|
Write this RtfShapePosition .
|
5,207
|
public void writeListBeginning ( final OutputStream result ) throws IOException { result . write ( RtfParagraph . PARAGRAPH_DEFAULTS ) ; if ( this . inTable ) { result . write ( RtfParagraph . IN_TABLE ) ; } switch ( this . alignment ) { case Element . ALIGN_LEFT : result . write ( RtfParagraphStyle . ALIGN_LEFT ) ; break ; case Element . ALIGN_RIGHT : result . write ( RtfParagraphStyle . ALIGN_RIGHT ) ; break ; case Element . ALIGN_CENTER : result . write ( RtfParagraphStyle . ALIGN_CENTER ) ; break ; case Element . ALIGN_JUSTIFIED : case Element . ALIGN_JUSTIFIED_ALL : result . write ( RtfParagraphStyle . ALIGN_JUSTIFY ) ; break ; } writeIndentation ( result ) ; result . write ( RtfFont . FONT_SIZE ) ; result . write ( intToByteArray ( fontNumber . getFontSize ( ) * 2 ) ) ; if ( this . symbolIndent > 0 ) { result . write ( LIST_LEVEL_SYMBOL_INDENT ) ; result . write ( intToByteArray ( this . leftIndent ) ) ; } }
|
Writes the initialization part of the RtfList
|
5,208
|
public void writeContent ( final OutputStream result ) throws IOException { for ( int i = 0 ; i < this . tabs . size ( ) ; i ++ ) { RtfTab rt = ( RtfTab ) this . tabs . get ( i ) ; rt . writeContent ( result ) ; } }
|
Combines the tab output form all grouped tabs .
|
5,209
|
PdfRectangle rotateMediaBox ( ) { this . mediaBox = mediaBox . rotate ( ) ; put ( PdfName . MEDIABOX , this . mediaBox ) ; return this . mediaBox ; }
|
Rotates the mediabox but not the text in it .
|
5,210
|
public void fax4Encode ( byte [ ] data , int offset , int size ) { dataBp = data ; offsetData = offset ; sizeData = size ; while ( sizeData > 0 ) { Fax3Encode2DRow ( ) ; System . arraycopy ( dataBp , offsetData , refline , 0 , rowbytes ) ; offsetData += rowbytes ; sizeData -= rowbytes ; } }
|
Encodes a number of lines .
|
5,211
|
public static byte [ ] compress ( byte [ ] data , int width , int height ) { CCITTG4Encoder g4 = new CCITTG4Encoder ( width ) ; g4 . fax4Encode ( data , 0 , g4 . rowbytes * height ) ; return g4 . close ( ) ; }
|
Encodes a full image .
|
5,212
|
public void displayText ( String text , Matrix endingTextMatrix ) { boolean hardReturn = false ; if ( lastTextLineMatrix != null && lastTextLineMatrix . get ( Matrix . I32 ) != getCurrentTextLineMatrix ( ) . get ( Matrix . I32 ) ) { hardReturn = true ; } float currentX = getCurrentTextMatrix ( ) . get ( Matrix . I31 ) ; if ( hardReturn ) { result . append ( '\n' ) ; } else if ( lastEndingTextMatrix != null ) { float lastEndX = lastEndingTextMatrix . get ( Matrix . I31 ) ; float spaceGlyphWidth = gs ( ) . font . getWidth ( ' ' ) / 1000f ; float spaceWidth = ( spaceGlyphWidth * gs ( ) . fontSize + gs ( ) . characterSpacing + gs ( ) . wordSpacing ) * gs ( ) . horizontalScaling ; Matrix scaled = new Matrix ( spaceWidth , 0 ) . multiply ( getCurrentTextMatrix ( ) ) ; float scaledSpaceWidth = scaled . get ( Matrix . I31 ) - getCurrentTextMatrix ( ) . get ( Matrix . I31 ) ; if ( currentX - lastEndX > scaledSpaceWidth / 2f ) { result . append ( ' ' ) ; } } if ( text != null && result != null ) { result . append ( text ) ; } lastTextLineMatrix = getCurrentTextLineMatrix ( ) ; lastEndingTextMatrix = endingTextMatrix ; }
|
Writes text to the result .
|
5,213
|
public Cell createCell ( SimpleCell rowAttributes ) throws BadElementException { Cell cell = new Cell ( ) ; cell . cloneNonPositionParameters ( rowAttributes ) ; cell . softCloneNonPositionParameters ( this ) ; cell . setColspan ( colspan ) ; cell . setHorizontalAlignment ( horizontalAlignment ) ; cell . setVerticalAlignment ( verticalAlignment ) ; cell . setUseAscender ( useAscender ) ; cell . setUseBorderPadding ( useBorderPadding ) ; cell . setUseDescender ( useDescender ) ; Element element ; for ( Iterator i = content . iterator ( ) ; i . hasNext ( ) ; ) { element = ( Element ) i . next ( ) ; cell . addElement ( element ) ; } return cell ; }
|
Creates a Cell with these attributes .
|
5,214
|
public PdfPCell createPdfPCell ( SimpleCell rowAttributes ) { PdfPCell cell = new PdfPCell ( ) ; cell . setBorder ( NO_BORDER ) ; SimpleCell tmp = new SimpleCell ( CELL ) ; tmp . setSpacing_left ( spacing_left ) ; tmp . setSpacing_right ( spacing_right ) ; tmp . setSpacing_top ( spacing_top ) ; tmp . setSpacing_bottom ( spacing_bottom ) ; tmp . cloneNonPositionParameters ( rowAttributes ) ; tmp . softCloneNonPositionParameters ( this ) ; cell . setCellEvent ( tmp ) ; cell . setHorizontalAlignment ( rowAttributes . horizontalAlignment ) ; cell . setVerticalAlignment ( rowAttributes . verticalAlignment ) ; cell . setUseAscender ( rowAttributes . useAscender ) ; cell . setUseBorderPadding ( rowAttributes . useBorderPadding ) ; cell . setUseDescender ( rowAttributes . useDescender ) ; cell . setColspan ( colspan ) ; if ( horizontalAlignment != Element . ALIGN_UNDEFINED ) cell . setHorizontalAlignment ( horizontalAlignment ) ; if ( verticalAlignment != Element . ALIGN_UNDEFINED ) cell . setVerticalAlignment ( verticalAlignment ) ; if ( useAscender ) cell . setUseAscender ( useAscender ) ; if ( useBorderPadding ) cell . setUseBorderPadding ( useBorderPadding ) ; if ( useDescender ) cell . setUseDescender ( useDescender ) ; float p ; float sp_left = spacing_left ; if ( Float . isNaN ( sp_left ) ) sp_left = 0f ; float sp_right = spacing_right ; if ( Float . isNaN ( sp_right ) ) sp_right = 0f ; float sp_top = spacing_top ; if ( Float . isNaN ( sp_top ) ) sp_top = 0f ; float sp_bottom = spacing_bottom ; if ( Float . isNaN ( sp_bottom ) ) sp_bottom = 0f ; p = padding_left ; if ( Float . isNaN ( p ) ) p = 0f ; cell . setPaddingLeft ( p + sp_left ) ; p = padding_right ; if ( Float . isNaN ( p ) ) p = 0f ; cell . setPaddingRight ( p + sp_right ) ; p = padding_top ; if ( Float . isNaN ( p ) ) p = 0f ; cell . setPaddingTop ( p + sp_top ) ; p = padding_bottom ; if ( Float . isNaN ( p ) ) p = 0f ; cell . setPaddingBottom ( p + sp_bottom ) ; Element element ; for ( Iterator i = content . iterator ( ) ; i . hasNext ( ) ; ) { element = ( Element ) i . next ( ) ; cell . addElement ( element ) ; } return cell ; }
|
Creates a PdfPCell with these attributes .
|
5,215
|
public void setPadding ( float padding ) { if ( Float . isNaN ( padding_right ) ) { setPadding_right ( padding ) ; } if ( Float . isNaN ( padding_left ) ) { setPadding_left ( padding ) ; } if ( Float . isNaN ( padding_top ) ) { setPadding_top ( padding ) ; } if ( Float . isNaN ( padding_bottom ) ) { setPadding_bottom ( padding ) ; } }
|
Sets the padding parameters if they are undefined .
|
5,216
|
public void writeContent ( final OutputStream result ) throws IOException { if ( this . paragraphStyle . getSpacingBefore ( ) > 0 ) { result . write ( RtfParagraphStyle . SPACING_BEFORE ) ; result . write ( intToByteArray ( paragraphStyle . getSpacingBefore ( ) ) ) ; } if ( this . paragraphStyle . getSpacingAfter ( ) > 0 ) { result . write ( RtfParagraphStyle . SPACING_AFTER ) ; result . write ( intToByteArray ( this . paragraphStyle . getSpacingAfter ( ) ) ) ; } if ( this . paragraphStyle . getLineLeading ( ) > 0 ) { result . write ( RtfParagraph . LINE_SPACING ) ; result . write ( intToByteArray ( this . paragraphStyle . getLineLeading ( ) ) ) ; } for ( int i = 0 ; i < chunks . size ( ) ; i ++ ) { RtfBasicElement rtfElement = ( RtfBasicElement ) chunks . get ( i ) ; if ( rtfElement instanceof RtfChunk ) { ( ( RtfChunk ) rtfElement ) . setSoftLineBreaks ( true ) ; } else if ( rtfElement instanceof RtfList ) { result . write ( RtfParagraph . PARAGRAPH ) ; this . containsInnerList = true ; } rtfElement . writeContent ( result ) ; if ( rtfElement instanceof RtfList ) { switch ( this . parentList . getLevelFollowValue ( ) ) { case RtfListLevel . LIST_LEVEL_FOLLOW_NOTHING : break ; case RtfListLevel . LIST_LEVEL_FOLLOW_TAB : this . parentList . writeListBeginning ( result ) ; result . write ( RtfList . TAB ) ; break ; case RtfListLevel . LIST_LEVEL_FOLLOW_SPACE : this . parentList . writeListBeginning ( result ) ; result . write ( DocWriter . getISOBytes ( " " ) ) ; break ; } } } }
|
Writes the content of this RtfListItem .
|
5,217
|
public void inheritListSettings ( int listNumber , int listLevel ) { for ( int i = 0 ; i < chunks . size ( ) ; i ++ ) { RtfBasicElement rtfElement = ( RtfBasicElement ) chunks . get ( i ) ; if ( rtfElement instanceof RtfList ) { ( ( RtfList ) rtfElement ) . setListNumber ( listNumber ) ; setLevel ( listLevel ) ; } } }
|
Inherit the list settings from the parent list to RtfLists that are contained in this RtfListItem .
|
5,218
|
public int getColorNumber ( RtfColor color ) { int colorIndex = - 1 ; for ( int i = 0 ; i < colorList . size ( ) ; i ++ ) { if ( colorList . get ( i ) . equals ( color ) ) { colorIndex = i ; } } if ( colorIndex == - 1 ) { colorIndex = colorList . size ( ) ; colorList . add ( color ) ; } return colorIndex ; }
|
Returns the index of the given RtfColor in the color list . If the RtfColor is not in the list of colors then it is added .
|
5,219
|
public void writeDefinition ( final OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( COLOR_TABLE ) ; for ( int i = 0 ; i < colorList . size ( ) ; i ++ ) { RtfColor color = ( RtfColor ) colorList . get ( i ) ; color . writeDefinition ( result ) ; } result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; }
|
Write the definition part of the color list . Calls the writeDefinition methods of the RtfColors in the color list .
|
5,220
|
protected void writeHeader ( Meta meta ) throws IOException { addTabs ( 2 ) ; writeStart ( HtmlTags . META ) ; switch ( meta . type ( ) ) { case Element . HEADER : write ( HtmlTags . NAME , ( ( Header ) meta ) . getName ( ) ) ; break ; case Element . SUBJECT : write ( HtmlTags . NAME , HtmlTags . SUBJECT ) ; break ; case Element . KEYWORDS : write ( HtmlTags . NAME , HtmlTags . KEYWORDS ) ; break ; case Element . AUTHOR : write ( HtmlTags . NAME , HtmlTags . AUTHOR ) ; break ; } write ( HtmlTags . CONTENT , HtmlEncoder . encode ( meta . getContent ( ) ) ) ; writeEnd ( ) ; }
|
Writes a Metatag in the header .
|
5,221
|
protected void writeLink ( Header header ) throws IOException { addTabs ( 2 ) ; writeStart ( HtmlTags . LINK ) ; write ( HtmlTags . REL , header . getName ( ) ) ; write ( HtmlTags . TYPE , HtmlTags . TEXT_CSS ) ; write ( HtmlTags . REFERENCE , header . getContent ( ) ) ; writeEnd ( ) ; }
|
Writes a link in the header .
|
5,222
|
protected void writeJavaScript ( Header header ) throws IOException { addTabs ( 2 ) ; writeStart ( HtmlTags . SCRIPT ) ; write ( HtmlTags . LANGUAGE , HtmlTags . JAVASCRIPT ) ; if ( markup . size ( ) > 0 ) { writeMarkupAttributes ( markup ) ; os . write ( GT ) ; writeEnd ( HtmlTags . SCRIPT ) ; } else { write ( HtmlTags . TYPE , Markup . HTML_VALUE_JAVASCRIPT ) ; os . write ( GT ) ; addTabs ( 2 ) ; write ( new String ( BEGINCOMMENT ) + "\n" ) ; write ( header . getContent ( ) ) ; addTabs ( 2 ) ; write ( "//" + new String ( ENDCOMMENT ) ) ; addTabs ( 2 ) ; writeEnd ( HtmlTags . SCRIPT ) ; } }
|
Writes a JavaScript section or if the markup attribute HtmlTags . URL is set a JavaScript reference in the header .
|
5,223
|
public boolean isOtherFont ( Font font ) { try { Font cFont = ( Font ) currentfont . peek ( ) ; if ( cFont . compareTo ( font ) == 0 ) return false ; return true ; } catch ( EmptyStackException ese ) { if ( standardfont . compareTo ( font ) == 0 ) return false ; return true ; } }
|
Checks if a given font is the same as the font that was last used .
|
5,224
|
protected void writeSection ( Section section , int indent ) throws IOException { if ( section . getTitle ( ) != null ) { int depth = section . getDepth ( ) - 1 ; if ( depth > 5 ) { depth = 5 ; } Properties styleAttributes = new Properties ( ) ; if ( section . getTitle ( ) . hasLeading ( ) ) styleAttributes . setProperty ( Markup . CSS_KEY_LINEHEIGHT , section . getTitle ( ) . getTotalLeading ( ) + "pt" ) ; addTabs ( indent ) ; writeStart ( HtmlTags . H [ depth ] ) ; write ( section . getTitle ( ) . getFont ( ) , styleAttributes ) ; String alignment = HtmlEncoder . getAlignment ( section . getTitle ( ) . getAlignment ( ) ) ; if ( ! "" . equals ( alignment ) ) { write ( HtmlTags . ALIGN , alignment ) ; } writeMarkupAttributes ( markup ) ; os . write ( GT ) ; currentfont . push ( section . getTitle ( ) . getFont ( ) ) ; for ( Iterator i = section . getTitle ( ) . iterator ( ) ; i . hasNext ( ) ; ) { write ( ( Element ) i . next ( ) , indent + 1 ) ; } addTabs ( indent ) ; writeEnd ( HtmlTags . H [ depth ] ) ; currentfont . pop ( ) ; } for ( Iterator i = section . iterator ( ) ; i . hasNext ( ) ; ) { write ( ( Element ) i . next ( ) , indent ) ; } }
|
Writes the HTML representation of a section .
|
5,225
|
protected void writeCssProperty ( String prop , String value ) throws IOException { write ( new StringBuffer ( prop ) . append ( ": " ) . append ( value ) . append ( "; " ) . toString ( ) ) ; }
|
Writes out a CSS property .
|
5,226
|
public static byte [ ] getBarsInter25 ( String text ) { text = keepNumbers ( text ) ; if ( ( text . length ( ) & 1 ) != 0 ) throw new IllegalArgumentException ( "The text length must be even." ) ; byte bars [ ] = new byte [ text . length ( ) * 5 + 7 ] ; int pb = 0 ; bars [ pb ++ ] = 0 ; bars [ pb ++ ] = 0 ; bars [ pb ++ ] = 0 ; bars [ pb ++ ] = 0 ; int len = text . length ( ) / 2 ; for ( int k = 0 ; k < len ; ++ k ) { int c1 = text . charAt ( k * 2 ) - '0' ; int c2 = text . charAt ( k * 2 + 1 ) - '0' ; byte b1 [ ] = BARS [ c1 ] ; byte b2 [ ] = BARS [ c2 ] ; for ( int j = 0 ; j < 5 ; ++ j ) { bars [ pb ++ ] = b1 [ j ] ; bars [ pb ++ ] = b2 [ j ] ; } } bars [ pb ++ ] = 1 ; bars [ pb ++ ] = 0 ; bars [ pb ++ ] = 0 ; return bars ; }
|
Creates the bars for the barcode .
|
5,227
|
private void init ( FileChannel channel , FileChannel . MapMode mapMode ) throws IOException { this . channel = channel ; this . mappedByteBuffer = channel . map ( mapMode , 0L , channel . size ( ) ) ; mappedByteBuffer . load ( ) ; }
|
initializes the channel and mapped bytebuffer
|
5,228
|
public static boolean clean ( final java . nio . ByteBuffer buffer ) { if ( buffer == null || ! buffer . isDirect ( ) ) { return false ; } if ( cleanJava9 ( buffer ) ) { return true ; } return cleanOldsJDK ( buffer ) ; }
|
invokes the clean method on the ByteBuffer s cleaner
|
5,229
|
public static PdfAppearance createAppearance ( PdfWriter writer , float width , float height ) { return createAppearance ( writer , width , height , null ) ; }
|
Creates a new appearance to be used with form fields .
|
5,230
|
public MarkedSection addMarkedSection ( ) { MarkedSection section = new MarkedSection ( new Section ( null , numberDepth + 1 ) ) ; add ( section ) ; return section ; }
|
Adds a marked section . For use in class MarkedSection only!
|
5,231
|
public static Paragraph constructTitle ( Paragraph title , ArrayList numbers , int numberDepth , int numberStyle ) { if ( title == null ) { return null ; } int depth = Math . min ( numbers . size ( ) , numberDepth ) ; if ( depth < 1 ) { return title ; } StringBuffer buf = new StringBuffer ( " " ) ; for ( int i = 0 ; i < depth ; i ++ ) { buf . insert ( 0 , "." ) ; buf . insert ( 0 , ( ( Integer ) numbers . get ( i ) ) . intValue ( ) ) ; } if ( numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT ) { buf . deleteCharAt ( buf . length ( ) - 2 ) ; } Paragraph result = new Paragraph ( title ) ; result . add ( 0 , new Chunk ( buf . toString ( ) , title . getFont ( ) ) ) ; return result ; }
|
Constructs a Paragraph that will be used as title for a Section or Chapter .
|
5,232
|
public void setChapterNumber ( int number ) { numbers . set ( numbers . size ( ) - 1 , Integer . valueOf ( number ) ) ; Object s ; for ( Iterator i = iterator ( ) ; i . hasNext ( ) ; ) { s = i . next ( ) ; if ( s instanceof Section ) { ( ( Section ) s ) . setChapterNumber ( number ) ; } } }
|
Changes the Chapter number .
|
5,233
|
private void setNumbers ( int number , ArrayList numbers ) { this . numbers = new ArrayList ( ) ; this . numbers . add ( Integer . valueOf ( number ) ) ; this . numbers . addAll ( numbers ) ; }
|
Sets the number of this section .
|
5,234
|
public void setViewerPreferences ( int preferences ) { this . pageLayoutAndMode |= preferences ; if ( ( preferences & viewerPreferencesMask ) != 0 ) { pageLayoutAndMode = ~ viewerPreferencesMask & pageLayoutAndMode ; if ( ( preferences & PdfWriter . HideToolbar ) != 0 ) viewerPreferences . put ( PdfName . HIDETOOLBAR , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . HideMenubar ) != 0 ) viewerPreferences . put ( PdfName . HIDEMENUBAR , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . HideWindowUI ) != 0 ) viewerPreferences . put ( PdfName . HIDEWINDOWUI , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . FitWindow ) != 0 ) viewerPreferences . put ( PdfName . FITWINDOW , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . CenterWindow ) != 0 ) viewerPreferences . put ( PdfName . CENTERWINDOW , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . DisplayDocTitle ) != 0 ) viewerPreferences . put ( PdfName . DISPLAYDOCTITLE , PdfBoolean . PDFTRUE ) ; if ( ( preferences & PdfWriter . NonFullScreenPageModeUseNone ) != 0 ) viewerPreferences . put ( PdfName . NONFULLSCREENPAGEMODE , PdfName . USENONE ) ; else if ( ( preferences & PdfWriter . NonFullScreenPageModeUseOutlines ) != 0 ) viewerPreferences . put ( PdfName . NONFULLSCREENPAGEMODE , PdfName . USEOUTLINES ) ; else if ( ( preferences & PdfWriter . NonFullScreenPageModeUseThumbs ) != 0 ) viewerPreferences . put ( PdfName . NONFULLSCREENPAGEMODE , PdfName . USETHUMBS ) ; else if ( ( preferences & PdfWriter . NonFullScreenPageModeUseOC ) != 0 ) viewerPreferences . put ( PdfName . NONFULLSCREENPAGEMODE , PdfName . USEOC ) ; if ( ( preferences & PdfWriter . DirectionL2R ) != 0 ) viewerPreferences . put ( PdfName . DIRECTION , PdfName . L2R ) ; else if ( ( preferences & PdfWriter . DirectionR2L ) != 0 ) viewerPreferences . put ( PdfName . DIRECTION , PdfName . R2L ) ; if ( ( preferences & PdfWriter . PrintScalingNone ) != 0 ) viewerPreferences . put ( PdfName . PRINTSCALING , PdfName . NONE ) ; } }
|
Sets the viewer preferences as the sum of several constants .
|
5,235
|
private boolean isPossibleValue ( PdfName value , PdfName [ ] accepted ) { for ( int i = 0 ; i < accepted . length ; i ++ ) { if ( accepted [ i ] . equals ( value ) ) { return true ; } } return false ; }
|
Checks if some value is valid for a certain key .
|
5,236
|
public void addViewerPreference ( PdfName key , PdfObject value ) { switch ( getIndex ( key ) ) { case 0 : case 1 : case 2 : case 3 : case 4 : case 5 : case 14 : if ( value instanceof PdfBoolean ) { viewerPreferences . put ( key , value ) ; } break ; case 6 : if ( value instanceof PdfName && isPossibleValue ( ( PdfName ) value , NONFULLSCREENPAGEMODE_PREFERENCES ) ) { viewerPreferences . put ( key , value ) ; } break ; case 7 : if ( value instanceof PdfName && isPossibleValue ( ( PdfName ) value , DIRECTION_PREFERENCES ) ) { viewerPreferences . put ( key , value ) ; } break ; case 8 : case 9 : case 10 : case 11 : if ( value instanceof PdfName && isPossibleValue ( ( PdfName ) value , PAGE_BOUNDARIES ) ) { viewerPreferences . put ( key , value ) ; } break ; case 12 : if ( value instanceof PdfName && isPossibleValue ( ( PdfName ) value , PRINTSCALING_PREFERENCES ) ) { viewerPreferences . put ( key , value ) ; } break ; case 13 : if ( value instanceof PdfName && isPossibleValue ( ( PdfName ) value , DUPLEX_PREFERENCES ) ) { viewerPreferences . put ( key , value ) ; } break ; case 15 : if ( value instanceof PdfArray ) { viewerPreferences . put ( key , value ) ; } break ; case 16 : if ( value instanceof PdfNumber ) { viewerPreferences . put ( key , value ) ; } break ; } }
|
Sets the viewer preferences for printing .
|
5,237
|
public void addTitle ( String title ) { XmpArray array = new XmpArray ( XmpArray . ALTERNATIVE ) ; array . add ( title ) ; setProperty ( TITLE , array ) ; }
|
Adds a title .
|
5,238
|
public void addDescription ( String desc ) { XmpArray array = new XmpArray ( XmpArray . ALTERNATIVE ) ; array . add ( desc ) ; setProperty ( DESCRIPTION , array ) ; }
|
Adds a description .
|
5,239
|
public void addSubject ( String [ ] subject ) { XmpArray array = new XmpArray ( XmpArray . UNORDERED ) ; for ( int i = 0 ; i < subject . length ; i ++ ) { array . add ( subject [ i ] ) ; } setProperty ( SUBJECT , array ) ; }
|
Adds a subject .
|
5,240
|
public void addAuthor ( String author ) { XmpArray array = new XmpArray ( XmpArray . ORDERED ) ; array . add ( author ) ; setProperty ( CREATOR , array ) ; }
|
Adds a single author .
|
5,241
|
public void addPublisher ( String publisher ) { XmpArray array = new XmpArray ( XmpArray . ORDERED ) ; array . add ( publisher ) ; setProperty ( PUBLISHER , array ) ; }
|
Adds a single publisher .
|
5,242
|
protected char getCurrentCharacter ( int current , char [ ] cc , PdfChunk [ ] ck ) { if ( ck == null ) { return cc [ current ] ; } return ( char ) ck [ Math . min ( current , ck . length - 1 ) ] . getUnicodeEquivalent ( cc [ current ] ) ; }
|
Returns the current character
|
5,243
|
public void addElement ( Element element ) { if ( table != null ) { table = null ; column . setText ( null ) ; } column . addElement ( element ) ; }
|
Adds an iText element to the cell .
|
5,244
|
public void setImage ( Image image ) { column . setText ( null ) ; table = null ; this . image = image ; }
|
Setter for property image .
|
5,245
|
public void setCellEvent ( PdfPCellEvent cellEvent ) { if ( cellEvent == null ) this . cellEvent = null ; else if ( this . cellEvent == null ) this . cellEvent = cellEvent ; else if ( this . cellEvent instanceof PdfPCellEventForwarder ) ( ( PdfPCellEventForwarder ) this . cellEvent ) . addCellEvent ( cellEvent ) ; else { PdfPCellEventForwarder forward = new PdfPCellEventForwarder ( ) ; forward . addCellEvent ( this . cellEvent ) ; forward . addCellEvent ( cellEvent ) ; this . cellEvent = forward ; } }
|
Sets the cell event for this cell .
|
5,246
|
void consumeHeight ( float height ) { float rightLimit = getRight ( ) - getEffectivePaddingRight ( ) ; float leftLimit = getLeft ( ) + getEffectivePaddingLeft ( ) ; float bry = height - getEffectivePaddingTop ( ) - getEffectivePaddingBottom ( ) ; if ( getRotation ( ) != 90 && getRotation ( ) != 270 ) { column . setSimpleColumn ( leftLimit , bry + 0.001f , rightLimit , 0 ) ; } else { column . setSimpleColumn ( 0 , leftLimit , bry + 0.001f , rightLimit ) ; } try { column . go ( true ) ; } catch ( DocumentException e ) { } }
|
Consumes part of the content of the cell .
|
5,247
|
public float getMaxHeight ( ) { boolean pivoted = ( getRotation ( ) == 90 || getRotation ( ) == 270 ) ; Image img = getImage ( ) ; if ( img != null ) { img . scalePercent ( 100 ) ; float refWidth = pivoted ? img . getScaledHeight ( ) : img . getScaledWidth ( ) ; float scale = ( getRight ( ) - getEffectivePaddingRight ( ) - getEffectivePaddingLeft ( ) - getLeft ( ) ) / refWidth ; img . scalePercent ( scale * 100 ) ; float refHeight = pivoted ? img . getScaledWidth ( ) : img . getScaledHeight ( ) ; setBottom ( getTop ( ) - getEffectivePaddingTop ( ) - getEffectivePaddingBottom ( ) - refHeight ) ; } else { if ( ( pivoted && hasFixedHeight ( ) ) || getColumn ( ) == null ) setBottom ( getTop ( ) - getFixedHeight ( ) ) ; else { ColumnText ct = ColumnText . duplicate ( getColumn ( ) ) ; float right , top , left , bottom ; if ( pivoted ) { right = PdfPRow . RIGHT_LIMIT ; top = getRight ( ) - getEffectivePaddingRight ( ) ; left = 0 ; bottom = getLeft ( ) + getEffectivePaddingLeft ( ) ; } else { right = isNoWrap ( ) ? PdfPRow . RIGHT_LIMIT : getRight ( ) - getEffectivePaddingRight ( ) ; top = getTop ( ) - getEffectivePaddingTop ( ) ; left = getLeft ( ) + getEffectivePaddingLeft ( ) ; bottom = hasFixedHeight ( ) ? getTop ( ) + getEffectivePaddingBottom ( ) - getFixedHeight ( ) : PdfPRow . BOTTOM_LIMIT ; } PdfPRow . setColumn ( ct , left , bottom , right , top ) ; try { ct . go ( true ) ; } catch ( DocumentException e ) { throw new ExceptionConverter ( e ) ; } if ( pivoted ) setBottom ( getTop ( ) - getEffectivePaddingTop ( ) - getEffectivePaddingBottom ( ) - ct . getFilledWidth ( ) ) ; else { float yLine = ct . getYLine ( ) ; if ( isUseDescender ( ) ) yLine += ct . getDescender ( ) ; setBottom ( yLine - getEffectivePaddingBottom ( ) ) ; } } } float height = getHeight ( ) ; if ( hasFixedHeight ( ) ) height = getFixedHeight ( ) ; else if ( height < getMinimumHeight ( ) ) height = getMinimumHeight ( ) ; return height ; }
|
Returns the height of the cell .
|
5,248
|
public Image getImage ( int frame ) { GifFrame gf = ( GifFrame ) frames . get ( frame - 1 ) ; return gf . image ; }
|
Gets the image from a frame . The first frame is 1 .
|
5,249
|
protected void readLSD ( ) throws IOException { width = readShort ( ) ; height = readShort ( ) ; int packed = in . read ( ) ; gctFlag = ( packed & 0x80 ) != 0 ; m_gbpc = ( packed & 7 ) + 1 ; bgIndex = in . read ( ) ; pixelAspect = in . read ( ) ; }
|
Reads Logical Screen Descriptor
|
5,250
|
protected void readImage ( ) throws IOException { ix = readShort ( ) ; iy = readShort ( ) ; iw = readShort ( ) ; ih = readShort ( ) ; int packed = in . read ( ) ; lctFlag = ( packed & 0x80 ) != 0 ; interlace = ( packed & 0x40 ) != 0 ; lctSize = 2 << ( packed & 7 ) ; m_bpc = newBpc ( m_gbpc ) ; if ( lctFlag ) { m_curr_table = readColorTable ( ( packed & 7 ) + 1 ) ; m_bpc = newBpc ( ( packed & 7 ) + 1 ) ; } else { m_curr_table = m_global_table ; } if ( transparency && transIndex >= m_curr_table . length / 3 ) { transparency = false ; } if ( transparency && m_bpc == 1 ) { byte tp [ ] = new byte [ 12 ] ; System . arraycopy ( m_curr_table , 0 , tp , 0 , 6 ) ; m_curr_table = tp ; m_bpc = 2 ; } boolean skipZero = decodeImageData ( ) ; if ( ! skipZero ) skip ( ) ; Image img = null ; try { img = new ImgRaw ( iw , ih , 1 , m_bpc , m_out ) ; PdfArray colorspace = new PdfArray ( ) ; colorspace . add ( PdfName . INDEXED ) ; colorspace . add ( PdfName . DEVICERGB ) ; int len = m_curr_table . length ; colorspace . add ( new PdfNumber ( len / 3 - 1 ) ) ; colorspace . add ( new PdfString ( m_curr_table ) ) ; PdfDictionary ad = new PdfDictionary ( ) ; ad . put ( PdfName . COLORSPACE , colorspace ) ; img . setAdditional ( ad ) ; if ( transparency ) { img . setTransparency ( new int [ ] { transIndex , transIndex } ) ; } } catch ( Exception e ) { throw new ExceptionConverter ( e ) ; } img . setOriginalType ( Image . ORIGINAL_GIF ) ; img . setOriginalData ( fromData ) ; img . setUrl ( fromUrl ) ; GifFrame gf = new GifFrame ( ) ; gf . image = img ; gf . ix = ix ; gf . iy = iy ; frames . add ( gf ) ; }
|
Reads next frame image
|
5,251
|
protected void readGraphicControlExt ( ) throws IOException { in . read ( ) ; int packed = in . read ( ) ; dispose = ( packed & 0x1c ) >> 2 ; if ( dispose == 0 ) { dispose = 1 ; } transparency = ( packed & 1 ) != 0 ; delay = readShort ( ) * 10 ; transIndex = in . read ( ) ; in . read ( ) ; }
|
Reads Graphics Control Extension values
|
5,252
|
public void mapRole ( PdfName used , PdfName standard ) { PdfDictionary rm = ( PdfDictionary ) get ( PdfName . ROLEMAP ) ; if ( rm == null ) { rm = new PdfDictionary ( ) ; put ( PdfName . ROLEMAP , rm ) ; } rm . put ( used , standard ) ; }
|
Maps the user tags to the standard tags . The mapping will allow a standard application to make some sense of the tagged document whatever the user tags may be .
|
5,253
|
private byte [ ] getContentBytesForPage ( int pageNum ) throws IOException { RandomAccessFileOrArray f = reader . getSafeFile ( ) ; byte [ ] contentBytes = reader . getPageContent ( pageNum , f ) ; f . close ( ) ; return contentBytes ; }
|
Gets the content stream of a page .
|
5,254
|
public String getTextFromPage ( int page ) throws IOException { int totalPages = reader . getNumberOfPages ( ) ; if ( totalPages < page ) { throw new IOException ( "indicated page does not exists, requested page " + page + " document pages " + totalPages ) ; } if ( page <= 0 ) { throw new IOException ( "page number must be postive:" + page ) ; } PdfDictionary pageDic = reader . getPageN ( page ) ; if ( pageDic == null ) { return "" ; } PdfDictionary resourcesDic = pageDic . getAsDict ( PdfName . RESOURCES ) ; extractionProcessor . processContent ( getContentBytesForPage ( page ) , resourcesDic ) ; return extractionProcessor . getResultantText ( ) ; }
|
Gets the text from a page .
|
5,255
|
public void readAcroForm ( PdfDictionary root ) { if ( root == null ) return ; hashMap = root . hashMap ; pushAttrib ( root ) ; PdfArray fieldlist = ( PdfArray ) PdfReader . getPdfObjectRelease ( root . get ( PdfName . FIELDS ) ) ; iterateFields ( fieldlist , null , null ) ; }
|
Read and comprehend the acroform
|
5,256
|
protected void iterateFields ( PdfArray fieldlist , PRIndirectReference fieldDict , String title ) { for ( Iterator it = fieldlist . listIterator ( ) ; it . hasNext ( ) ; ) { PRIndirectReference ref = ( PRIndirectReference ) it . next ( ) ; PdfDictionary dict = ( PdfDictionary ) PdfReader . getPdfObjectRelease ( ref ) ; PRIndirectReference myFieldDict = fieldDict ; String myTitle = title ; PdfString tField = ( PdfString ) dict . get ( PdfName . T ) ; boolean isFieldDict = tField != null ; if ( isFieldDict ) { myFieldDict = ref ; if ( title == null ) myTitle = tField . toString ( ) ; else myTitle = title + '.' + tField . toString ( ) ; } PdfArray kids = ( PdfArray ) dict . get ( PdfName . KIDS ) ; if ( kids != null ) { pushAttrib ( dict ) ; iterateFields ( kids , myFieldDict , myTitle ) ; stack . remove ( stack . size ( ) - 1 ) ; } else { if ( myFieldDict != null ) { PdfDictionary mergedDict = ( PdfDictionary ) stack . get ( stack . size ( ) - 1 ) ; if ( isFieldDict ) mergedDict = mergeAttrib ( mergedDict , dict ) ; mergedDict . put ( PdfName . T , new PdfString ( myTitle ) ) ; FieldInformation fi = new FieldInformation ( myTitle , mergedDict , myFieldDict ) ; fields . add ( fi ) ; fieldByName . put ( myTitle , fi ) ; } } } }
|
After reading we index all of the fields . Recursive .
|
5,257
|
protected PdfDictionary mergeAttrib ( PdfDictionary parent , PdfDictionary child ) { PdfDictionary targ = new PdfDictionary ( ) ; if ( parent != null ) targ . putAll ( parent ) ; for ( Iterator it = child . getKeys ( ) . iterator ( ) ; it . hasNext ( ) ; ) { PdfName key = ( PdfName ) it . next ( ) ; if ( key . equals ( PdfName . DR ) || key . equals ( PdfName . DA ) || key . equals ( PdfName . Q ) || key . equals ( PdfName . FF ) || key . equals ( PdfName . DV ) || key . equals ( PdfName . V ) || key . equals ( PdfName . FT ) || key . equals ( PdfName . F ) ) { targ . put ( key , child . get ( key ) ) ; } } return targ ; }
|
merge field attributes from two dictionaries
|
5,258
|
protected void pushAttrib ( PdfDictionary dict ) { PdfDictionary dic = null ; if ( ! stack . isEmpty ( ) ) { dic = ( PdfDictionary ) stack . get ( stack . size ( ) - 1 ) ; } dic = mergeAttrib ( dic , dict ) ; stack . add ( dic ) ; }
|
stack a level of dictionary . Merge in a dictionary from this level
|
5,259
|
PdfStream getFormXObject ( int pageNumber , int compressionLevel ) throws IOException { PdfDictionary page = reader . getPageNRelease ( pageNumber ) ; PdfObject contents = PdfReader . getPdfObjectRelease ( page . get ( PdfName . CONTENTS ) ) ; PdfDictionary dic = new PdfDictionary ( ) ; byte bout [ ] = null ; if ( contents != null ) { if ( contents . isStream ( ) ) dic . putAll ( ( PRStream ) contents ) ; else bout = reader . getPageContent ( pageNumber , file ) ; } else bout = new byte [ 0 ] ; dic . put ( PdfName . RESOURCES , PdfReader . getPdfObjectRelease ( page . get ( PdfName . RESOURCES ) ) ) ; dic . put ( PdfName . TYPE , PdfName . XOBJECT ) ; dic . put ( PdfName . SUBTYPE , PdfName . FORM ) ; PdfImportedPage impPage = ( PdfImportedPage ) importedPages . get ( Integer . valueOf ( pageNumber ) ) ; dic . put ( PdfName . BBOX , new PdfRectangle ( impPage . getBoundingBox ( ) ) ) ; PdfArray matrix = impPage . getMatrix ( ) ; if ( matrix == null ) dic . put ( PdfName . MATRIX , IDENTITYMATRIX ) ; else dic . put ( PdfName . MATRIX , matrix ) ; dic . put ( PdfName . FORMTYPE , ONE ) ; PRStream stream ; if ( bout == null ) { stream = new PRStream ( ( PRStream ) contents , dic ) ; } else { stream = new PRStream ( reader , bout , compressionLevel ) ; stream . putAll ( dic ) ; } return stream ; }
|
Gets the content stream of a page as a PdfStream object .
|
5,260
|
static public String getDictionaryDetail ( PdfDictionary dic , int depth ) { StringBuffer builder = new StringBuffer ( ) ; builder . append ( '(' ) ; List subDictionaries = new ArrayList ( ) ; for ( Iterator i = dic . getKeys ( ) . iterator ( ) ; i . hasNext ( ) ; ) { PdfName key = ( PdfName ) i . next ( ) ; PdfObject val = dic . getDirectObject ( key ) ; if ( val . isDictionary ( ) ) subDictionaries . add ( key ) ; builder . append ( key ) ; builder . append ( '=' ) ; builder . append ( val ) ; builder . append ( ", " ) ; } builder . setLength ( builder . length ( ) - 2 ) ; builder . append ( ')' ) ; PdfName pdfSubDictionaryName ; for ( Iterator it = subDictionaries . iterator ( ) ; it . hasNext ( ) ; ) { pdfSubDictionaryName = ( PdfName ) it . next ( ) ; builder . append ( '\n' ) ; for ( int i = 0 ; i < depth + 1 ; i ++ ) { builder . append ( '\t' ) ; } builder . append ( "Subdictionary " ) ; builder . append ( pdfSubDictionaryName ) ; builder . append ( " = " ) ; builder . append ( getDictionaryDetail ( dic . getAsDict ( pdfSubDictionaryName ) , depth + 1 ) ) ; } return builder . toString ( ) ; }
|
Shows the detail of a dictionary .
|
5,261
|
static public void listContentStreamForPage ( PdfReader reader , int pageNum , PrintWriter out ) throws IOException { out . println ( "==============Page " + pageNum + "====================" ) ; out . println ( "- - - - - Dictionary - - - - - -" ) ; PdfDictionary pageDictionary = reader . getPageN ( pageNum ) ; out . println ( getDictionaryDetail ( pageDictionary ) ) ; out . println ( "- - - - - Content Stream - - - - - -" ) ; RandomAccessFileOrArray f = reader . getSafeFile ( ) ; byte [ ] contentBytes = reader . getPageContent ( pageNum , f ) ; f . close ( ) ; InputStream is = new ByteArrayInputStream ( contentBytes ) ; int ch ; while ( ( ch = is . read ( ) ) != - 1 ) { out . print ( ( char ) ch ) ; } out . println ( "- - - - - Text Extraction - - - - - -" ) ; PdfTextExtractor extractor = new PdfTextExtractor ( reader ) ; String extractedText = extractor . getTextFromPage ( pageNum ) ; if ( extractedText . length ( ) != 0 ) out . println ( extractedText ) ; else out . println ( "No text found on page " + pageNum ) ; out . println ( ) ; }
|
Writes information about a specific page from PdfReader to the specified output stream .
|
5,262
|
static public void listContentStream ( File pdfFile , PrintWriter out ) throws IOException { PdfReader reader = new PdfReader ( pdfFile . getCanonicalPath ( ) ) ; int maxPageNum = reader . getNumberOfPages ( ) ; for ( int pageNum = 1 ; pageNum <= maxPageNum ; pageNum ++ ) { listContentStreamForPage ( reader , pageNum , out ) ; } }
|
Writes information about each page in a PDF file to the specified output stream .
|
5,263
|
public static void main ( String [ ] args ) { try { if ( args . length < 1 || args . length > 3 ) { System . out . println ( "Usage: PdfContentReaderTool <pdf file> [<output file>|stdout] [<page num>]" ) ; return ; } PrintWriter writer = new PrintWriter ( System . out ) ; if ( args . length >= 2 ) { if ( args [ 1 ] . compareToIgnoreCase ( "stdout" ) != 0 ) { System . out . println ( "Writing PDF content to " + args [ 1 ] ) ; writer = new PrintWriter ( new FileOutputStream ( new File ( args [ 1 ] ) ) ) ; } } int pageNum = - 1 ; if ( args . length >= 3 ) { pageNum = Integer . parseInt ( args [ 2 ] ) ; } if ( pageNum == - 1 ) { listContentStream ( new File ( args [ 0 ] ) , writer ) ; } else { listContentStream ( new File ( args [ 0 ] ) , pageNum , writer ) ; } writer . flush ( ) ; if ( args . length >= 2 ) { writer . close ( ) ; System . out . println ( "Finished writing content to " + args [ 1 ] ) ; } } catch ( Exception e ) { e . printStackTrace ( System . err ) ; } }
|
Writes information about each page in a PDF file to the specified file or System . out .
|
5,264
|
public static Image getInstance ( int width , int height , byte [ ] data , byte [ ] globals ) { Image img = new ImgJBIG2 ( width , height , data , globals ) ; return img ; }
|
Creates a JBIG2 Image .
|
5,265
|
public static Image getInstance ( PRIndirectReference ref ) throws BadElementException { PdfDictionary dic = ( PdfDictionary ) PdfReader . getPdfObjectRelease ( ref ) ; int width = ( ( PdfNumber ) PdfReader . getPdfObjectRelease ( dic . get ( PdfName . WIDTH ) ) ) . intValue ( ) ; int height = ( ( PdfNumber ) PdfReader . getPdfObjectRelease ( dic . get ( PdfName . HEIGHT ) ) ) . intValue ( ) ; Image imask = null ; PdfObject obj = dic . get ( PdfName . SMASK ) ; if ( obj != null && obj . isIndirect ( ) ) { imask = getInstance ( ( PRIndirectReference ) obj ) ; } else { obj = dic . get ( PdfName . MASK ) ; if ( obj != null && obj . isIndirect ( ) ) { PdfObject obj2 = PdfReader . getPdfObjectRelease ( obj ) ; if ( obj2 instanceof PdfDictionary ) imask = getInstance ( ( PRIndirectReference ) obj ) ; } } Image img = new ImgRaw ( width , height , 1 , 1 , null ) ; img . imageMask = imask ; img . directReference = ref ; return img ; }
|
Reuses an existing image .
|
5,266
|
public void scaleAbsolute ( float newWidth , float newHeight ) { plainWidth = newWidth ; plainHeight = newHeight ; float [ ] matrix = matrix ( ) ; scaledWidth = matrix [ DX ] - matrix [ CX ] ; scaledHeight = matrix [ DY ] - matrix [ CY ] ; setWidthPercentage ( 0 ) ; }
|
Scale the image to an absolute width and an absolute height .
|
5,267
|
public void scaleAbsoluteWidth ( float newWidth ) { plainWidth = newWidth ; float [ ] matrix = matrix ( ) ; scaledWidth = matrix [ DX ] - matrix [ CX ] ; scaledHeight = matrix [ DY ] - matrix [ CY ] ; setWidthPercentage ( 0 ) ; }
|
Scale the image to an absolute width .
|
5,268
|
public void scaleAbsoluteHeight ( float newHeight ) { plainHeight = newHeight ; float [ ] matrix = matrix ( ) ; scaledWidth = matrix [ DX ] - matrix [ CX ] ; scaledHeight = matrix [ DY ] - matrix [ CY ] ; setWidthPercentage ( 0 ) ; }
|
Scale the image to an absolute height .
|
5,269
|
public void scalePercent ( float percentX , float percentY ) { plainWidth = ( getWidth ( ) * percentX ) / 100f ; plainHeight = ( getHeight ( ) * percentY ) / 100f ; float [ ] matrix = matrix ( ) ; scaledWidth = matrix [ DX ] - matrix [ CX ] ; scaledHeight = matrix [ DY ] - matrix [ CY ] ; setWidthPercentage ( 0 ) ; }
|
Scale the width and height of an image to a certain percentage .
|
5,270
|
public void scaleToFit ( float fitWidth , float fitHeight ) { scalePercent ( 100 ) ; float percentX = ( fitWidth * 100 ) / getScaledWidth ( ) ; float percentY = ( fitHeight * 100 ) / getScaledHeight ( ) ; scalePercent ( percentX < percentY ? percentX : percentY ) ; setWidthPercentage ( 0 ) ; }
|
Scales the image so that it fits a certain width and height .
|
5,271
|
public float [ ] matrix ( ) { float [ ] matrix = new float [ 8 ] ; float cosX = ( float ) Math . cos ( rotationRadians ) ; float sinX = ( float ) Math . sin ( rotationRadians ) ; matrix [ AX ] = plainWidth * cosX ; matrix [ AY ] = plainWidth * sinX ; matrix [ BX ] = ( - plainHeight ) * sinX ; matrix [ BY ] = plainHeight * cosX ; if ( rotationRadians < Math . PI / 2f ) { matrix [ CX ] = matrix [ BX ] ; matrix [ CY ] = 0 ; matrix [ DX ] = matrix [ AX ] ; matrix [ DY ] = matrix [ AY ] + matrix [ BY ] ; } else if ( rotationRadians < Math . PI ) { matrix [ CX ] = matrix [ AX ] + matrix [ BX ] ; matrix [ CY ] = matrix [ BY ] ; matrix [ DX ] = 0 ; matrix [ DY ] = matrix [ AY ] ; } else if ( rotationRadians < Math . PI * 1.5f ) { matrix [ CX ] = matrix [ AX ] ; matrix [ CY ] = matrix [ AY ] + matrix [ BY ] ; matrix [ DX ] = matrix [ BX ] ; matrix [ DY ] = 0 ; } else { matrix [ CX ] = 0 ; matrix [ CY ] = matrix [ AY ] ; matrix [ DX ] = matrix [ AX ] + matrix [ BX ] ; matrix [ DY ] = matrix [ BY ] ; } return matrix ; }
|
Returns the transformation matrix of the image .
|
5,272
|
public float getImageRotation ( ) { double d = 2.0 * Math . PI ; float rot = ( float ) ( ( rotationRadians - initialRotation ) % d ) ; if ( rot < 0 ) { rot += d ; } return rot ; }
|
Gets the current image rotation in radians .
|
5,273
|
public void setRotation ( float r ) { double d = 2.0 * Math . PI ; rotationRadians = ( float ) ( ( r + initialRotation ) % d ) ; if ( rotationRadians < 0 ) { rotationRadians += d ; } float [ ] matrix = matrix ( ) ; scaledWidth = matrix [ DX ] - matrix [ CX ] ; scaledHeight = matrix [ DY ] - matrix [ CY ] ; }
|
Sets the rotation of the image in radians .
|
5,274
|
public void simplifyColorspace ( ) { if ( additional == null ) return ; PdfArray value = additional . getAsArray ( PdfName . COLORSPACE ) ; if ( value == null ) return ; PdfObject cs = simplifyColorspace ( value ) ; PdfObject newValue ; if ( cs . isName ( ) ) newValue = cs ; else { newValue = value ; PdfName first = value . getAsName ( 0 ) ; if ( PdfName . INDEXED . equals ( first ) ) { if ( value . size ( ) >= 2 ) { PdfArray second = value . getAsArray ( 1 ) ; if ( second != null ) { value . set ( 1 , simplifyColorspace ( second ) ) ; } } } } additional . put ( PdfName . COLORSPACE , newValue ) ; }
|
Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray .
|
5,275
|
private PdfObject simplifyColorspace ( PdfArray obj ) { if ( obj == null ) return obj ; PdfName first = obj . getAsName ( 0 ) ; if ( PdfName . CALGRAY . equals ( first ) ) return PdfName . DEVICEGRAY ; else if ( PdfName . CALRGB . equals ( first ) ) return PdfName . DEVICERGB ; else return obj ; }
|
Gets a PDF Name from an array or returns the object that was passed .
|
5,276
|
public void setImageMask ( Image mask ) throws DocumentException { if ( this . mask ) throw new DocumentException ( "An image mask cannot contain another image mask." ) ; if ( ! mask . mask ) throw new DocumentException ( "The image mask is not a mask. Did you do makeMask()?" ) ; imageMask = mask ; smask = ( mask . bpc > 1 && mask . bpc <= 8 ) ; }
|
Sets the explicit masking .
|
5,277
|
public void writeContent ( final OutputStream out ) throws IOException { final byte [ ] contentBytes = DocWriter . getISOBytes ( this . directContent ) ; out . write ( contentBytes ) ; }
|
Writes the element content to the given output stream .
|
5,278
|
public void setParser ( RtfParser parser ) { if ( this . rtfParser != null && this . rtfParser . equals ( parser ) ) return ; this . rtfParser = parser ; }
|
Set the parser to use with the RtfDestination object .
|
5,279
|
protected void writeFieldResultContent ( final OutputStream out ) throws IOException { document . filterSpecialChar ( out , defaultText , true , true ) ; }
|
Writes the field result content
|
5,280
|
public void writeContent ( final OutputStream result ) throws IOException { if ( this . background != null ) { result . write ( OPEN_GROUP ) ; } this . font . writeBegin ( result ) ; if ( superSubScript < 0 ) { result . write ( FONT_SUBSCRIPT ) ; } else if ( superSubScript > 0 ) { result . write ( FONT_SUPERSCRIPT ) ; } if ( this . background != null ) { result . write ( BACKGROUND_COLOR ) ; result . write ( intToByteArray ( this . background . getColorNumber ( ) ) ) ; } result . write ( DELIMITER ) ; document . filterSpecialChar ( result , content , false , softLineBreaks || this . document . getDocumentSettings ( ) . isAlwaysGenerateSoftLinebreaks ( ) ) ; if ( superSubScript != 0 ) { result . write ( FONT_END_SUPER_SUBSCRIPT ) ; } this . font . writeEnd ( result ) ; if ( this . background != null ) { result . write ( CLOSE_GROUP ) ; } }
|
Writes the content of this RtfChunk . First the font information is written then the content and then more font information
|
5,281
|
public void setHeader ( HeaderFooter header ) { this . header = header ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . setHeader ( header ) ; } }
|
Changes the header of this document .
|
5,282
|
public void resetHeader ( ) { this . header = null ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . resetHeader ( ) ; } }
|
Resets the header of this document .
|
5,283
|
public void setFooter ( HeaderFooter footer ) { this . footer = footer ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . setFooter ( footer ) ; } }
|
Changes the footer of this document .
|
5,284
|
public void resetFooter ( ) { this . footer = null ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . resetFooter ( ) ; } }
|
Resets the footer of this document .
|
5,285
|
public void resetPageCount ( ) { pageN = 0 ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . resetPageCount ( ) ; } }
|
Sets the page number to 0 .
|
5,286
|
public void setPageCount ( int pageN ) { this . pageN = pageN ; DocListener listener ; for ( Iterator iterator = listeners . iterator ( ) ; iterator . hasNext ( ) ; ) { listener = ( DocListener ) iterator . next ( ) ; listener . setPageCount ( pageN ) ; } }
|
Sets the page number .
|
5,287
|
public boolean addHeader ( String name , String content ) { try { return add ( new Header ( name , content ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds a user defined header to the document .
|
5,288
|
public boolean addTitle ( String title ) { try { return add ( new Meta ( Element . TITLE , title ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the title to a Document .
|
5,289
|
public boolean addSubject ( String subject ) { try { return add ( new Meta ( Element . SUBJECT , subject ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the subject to a Document .
|
5,290
|
public boolean addKeywords ( String keywords ) { try { return add ( new Meta ( Element . KEYWORDS , keywords ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the keywords to a Document .
|
5,291
|
public boolean addAuthor ( String author ) { try { return add ( new Meta ( Element . AUTHOR , author ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the author to a Document .
|
5,292
|
public boolean addCreator ( String creator ) { try { return add ( new Meta ( Element . CREATOR , creator ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the creator to a Document .
|
5,293
|
public boolean addProducer ( ) { try { return add ( new Meta ( Element . PRODUCER , getVersion ( ) ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the producer to a Document .
|
5,294
|
public boolean addCreationDate ( ) { try { final SimpleDateFormat sdf = new SimpleDateFormat ( "EEE MMM dd HH:mm:ss zzz yyyy" ) ; return add ( new Meta ( Element . CREATIONDATE , sdf . format ( new Date ( ) ) ) ) ; } catch ( DocumentException de ) { throw new ExceptionConverter ( de ) ; } }
|
Adds the current date and time to a Document .
|
5,295
|
public static byte [ ] getBarsPostnet ( String text ) { int total = 0 ; for ( int k = text . length ( ) - 1 ; k >= 0 ; -- k ) { int n = text . charAt ( k ) - '0' ; total += n ; } text += ( char ) ( ( ( 10 - ( total % 10 ) ) % 10 ) + '0' ) ; byte bars [ ] = new byte [ text . length ( ) * 5 + 2 ] ; bars [ 0 ] = 1 ; bars [ bars . length - 1 ] = 1 ; for ( int k = 0 ; k < text . length ( ) ; ++ k ) { int c = text . charAt ( k ) - '0' ; System . arraycopy ( BARS [ c ] , 0 , bars , k * 5 + 1 , 5 ) ; } return bars ; }
|
Creates the bars for Postnet .
|
5,296
|
public PdfAppearance getAppearance ( boolean isRadio , boolean on ) throws IOException , DocumentException { if ( isRadio && checkType == TYPE_CIRCLE ) return getAppearanceRadioCircle ( on ) ; PdfAppearance app = getBorderAppearance ( ) ; if ( ! on ) return app ; BaseFont ufont = getRealFont ( ) ; boolean borderExtra = borderStyle == PdfBorderDictionary . STYLE_BEVELED || borderStyle == PdfBorderDictionary . STYLE_INSET ; float h = box . getHeight ( ) - borderWidth * 2 ; float bw2 = borderWidth ; if ( borderExtra ) { h -= borderWidth * 2 ; bw2 *= 2 ; } float offsetX = ( borderExtra ? 2 * borderWidth : borderWidth ) ; offsetX = Math . max ( offsetX , 1 ) ; float offX = Math . min ( bw2 , offsetX ) ; float wt = box . getWidth ( ) - 2 * offX ; float ht = box . getHeight ( ) - 2 * offX ; float fsize = fontSize ; if ( fsize == 0 ) { float bw = ufont . getWidthPoint ( text , 1 ) ; if ( bw == 0 ) fsize = 12 ; else fsize = wt / bw ; float nfsize = h / ( ufont . getFontDescriptor ( BaseFont . ASCENT , 1 ) ) ; fsize = Math . min ( fsize , nfsize ) ; } app . saveState ( ) ; app . rectangle ( offX , offX , wt , ht ) ; app . clip ( ) ; app . newPath ( ) ; if ( textColor == null ) app . resetGrayFill ( ) ; else app . setColorFill ( textColor ) ; app . beginText ( ) ; app . setFontAndSize ( ufont , fsize ) ; app . setTextMatrix ( ( box . getWidth ( ) - ufont . getWidthPoint ( text , fsize ) ) / 2 , ( box . getHeight ( ) - ufont . getAscentPoint ( text , fsize ) ) / 2 ) ; app . showText ( text ) ; app . endText ( ) ; app . restoreState ( ) ; return app ; }
|
Gets the field appearance .
|
5,297
|
public PdfAppearance getAppearanceRadioCircle ( boolean on ) { PdfAppearance app = PdfAppearance . createAppearance ( writer , box . getWidth ( ) , box . getHeight ( ) ) ; switch ( rotation ) { case 90 : app . setMatrix ( 0 , 1 , - 1 , 0 , box . getHeight ( ) , 0 ) ; break ; case 180 : app . setMatrix ( - 1 , 0 , 0 , - 1 , box . getWidth ( ) , box . getHeight ( ) ) ; break ; case 270 : app . setMatrix ( 0 , - 1 , 1 , 0 , 0 , box . getWidth ( ) ) ; break ; } Rectangle box = new Rectangle ( app . getBoundingBox ( ) ) ; float cx = box . getWidth ( ) / 2 ; float cy = box . getHeight ( ) / 2 ; float r = ( Math . min ( box . getWidth ( ) , box . getHeight ( ) ) - borderWidth ) / 2 ; if ( r <= 0 ) return app ; if ( backgroundColor != null ) { app . setColorFill ( backgroundColor ) ; app . circle ( cx , cy , r + borderWidth / 2 ) ; app . fill ( ) ; } if ( borderWidth > 0 && borderColor != null ) { app . setLineWidth ( borderWidth ) ; app . setColorStroke ( borderColor ) ; app . circle ( cx , cy , r ) ; app . stroke ( ) ; } if ( on ) { if ( textColor == null ) app . resetGrayFill ( ) ; else app . setColorFill ( textColor ) ; app . circle ( cx , cy , r / 2 ) ; app . fill ( ) ; } return app ; }
|
Gets the special field appearance for the radio circle .
|
5,298
|
protected PdfFormField getField ( boolean isRadio ) throws IOException , DocumentException { PdfFormField field = null ; if ( isRadio ) field = PdfFormField . createEmpty ( writer ) ; else field = PdfFormField . createCheckBox ( writer ) ; field . setWidget ( box , PdfAnnotation . HIGHLIGHT_INVERT ) ; if ( ! isRadio ) { field . setFieldName ( fieldName ) ; if ( ( options & READ_ONLY ) != 0 ) field . setFieldFlags ( PdfFormField . FF_READ_ONLY ) ; if ( ( options & REQUIRED ) != 0 ) field . setFieldFlags ( PdfFormField . FF_REQUIRED ) ; field . setValueAsName ( checked ? onValue : "Off" ) ; } if ( text != null ) field . setMKNormalCaption ( text ) ; if ( rotation != 0 ) field . setMKRotation ( rotation ) ; field . setBorderStyle ( new PdfBorderDictionary ( borderWidth , borderStyle , new PdfDashPattern ( 3 ) ) ) ; PdfAppearance tpon = getAppearance ( isRadio , true ) ; PdfAppearance tpoff = getAppearance ( isRadio , false ) ; field . setAppearance ( PdfAnnotation . APPEARANCE_NORMAL , onValue , tpon ) ; field . setAppearance ( PdfAnnotation . APPEARANCE_NORMAL , "Off" , tpoff ) ; field . setAppearanceState ( checked ? onValue : "Off" ) ; PdfAppearance da = ( PdfAppearance ) tpon . getDuplicate ( ) ; da . setFontAndSize ( getRealFont ( ) , fontSize ) ; if ( textColor == null ) da . setGrayFill ( 0 ) ; else da . setColorFill ( textColor ) ; field . setDefaultAppearanceString ( da ) ; if ( borderColor != null ) field . setMKBorderColor ( borderColor ) ; if ( backgroundColor != null ) field . setMKBackgroundColor ( backgroundColor ) ; switch ( visibility ) { case HIDDEN : field . setFlags ( PdfAnnotation . FLAGS_PRINT | PdfAnnotation . FLAGS_HIDDEN ) ; break ; case VISIBLE_BUT_DOES_NOT_PRINT : break ; case HIDDEN_BUT_PRINTABLE : field . setFlags ( PdfAnnotation . FLAGS_PRINT | PdfAnnotation . FLAGS_NOVIEW ) ; break ; default : field . setFlags ( PdfAnnotation . FLAGS_PRINT ) ; break ; } return field ; }
|
Gets a radio or check field .
|
5,299
|
private void populateOperators ( ) { operators = new HashMap ( ) ; registerContentOperator ( "q" , new PushGraphicsState ( ) ) ; registerContentOperator ( "Q" , new PopGraphicsState ( ) ) ; registerContentOperator ( "cm" , new ModifyCurrentTransformationMatrix ( ) ) ; registerContentOperator ( "gs" , new ProcessGraphicsStateResource ( ) ) ; registerContentOperator ( "Tc" , new SetTextCharacterSpacing ( ) ) ; registerContentOperator ( "Tw" , new SetTextWordSpacing ( ) ) ; registerContentOperator ( "Tz" , new SetTextHorizontalScaling ( ) ) ; registerContentOperator ( "TL" , new SetTextLeading ( ) ) ; registerContentOperator ( "Tf" , new SetTextFont ( ) ) ; registerContentOperator ( "Tr" , new SetTextRenderMode ( ) ) ; registerContentOperator ( "Ts" , new SetTextRise ( ) ) ; registerContentOperator ( "BT" , new BeginText ( ) ) ; registerContentOperator ( "ET" , new EndText ( ) ) ; registerContentOperator ( "Td" , new TextMoveStartNextLine ( ) ) ; registerContentOperator ( "TD" , new TextMoveStartNextLineWithLeading ( ) ) ; registerContentOperator ( "Tm" , new TextSetTextMatrix ( ) ) ; registerContentOperator ( "T*" , new TextMoveNextLine ( ) ) ; registerContentOperator ( "Tj" , new ShowText ( ) ) ; registerContentOperator ( "'" , new MoveNextLineAndShowText ( ) ) ; registerContentOperator ( "\"" , new MoveNextLineAndShowTextWithSpacing ( ) ) ; registerContentOperator ( "TJ" , new ShowTextArray ( ) ) ; registerContentOperator ( "Do" , new Do ( ) ) ; }
|
Loads all the supported graphics and text state operators in a map .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.