idx
int64 0
41.2k
| question
stringlengths 73
5.81k
| target
stringlengths 5
918
|
|---|---|---|
4,700
|
static public ContentHandleFactory newFactory ( Class < ? > ... pojoClasses ) throws JAXBException { if ( pojoClasses == null || pojoClasses . length == 0 ) return null ; return new JAXBHandleFactory ( pojoClasses ) ; }
|
Creates a factory to create a JAXBHandle instance for POJO instances of the specified classes .
|
4,701
|
public < T > T get ( Class < T > as ) { if ( content == null ) { return null ; } if ( as == null ) { throw new IllegalArgumentException ( "Cannot cast content to null class" ) ; } if ( ! as . isAssignableFrom ( content . getClass ( ) ) ) { throw new IllegalArgumentException ( "Cannot cast " + content . getClass ( ) . getName ( ) + " to " + as . getName ( ) ) ; } @ SuppressWarnings ( "unchecked" ) T content = ( T ) get ( ) ; return content ; }
|
Returns the root object of the JAXB structure for the content cast to a more specific class .
|
4,702
|
public Unmarshaller getUnmarshaller ( boolean reuse ) throws JAXBException { if ( ! reuse || unmarshaller == null ) { unmarshaller = context . createUnmarshaller ( ) ; } return unmarshaller ; }
|
Returns the unmarshaller that converts a tree data structure from XML to Java objects .
|
4,703
|
public Marshaller getMarshaller ( boolean reuse ) throws JAXBException { if ( ! reuse || this . marshaller == null ) { Marshaller marshaller = context . createMarshaller ( ) ; marshaller . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , Boolean . TRUE ) ; marshaller . setProperty ( Marshaller . JAXB_ENCODING , "UTF-8" ) ; this . marshaller = marshaller ; } return this . marshaller ; }
|
Returns the marshaller that converts a tree data structure from Java objects to XML .
|
4,704
|
public static void tearDownExample ( DatabaseClient client ) { XMLDocumentManager docMgr = client . newXMLDocumentManager ( ) ; for ( String filename : filenames ) { docMgr . delete ( "/example/" + filename ) ; } }
|
clean up by deleting the documents used in the example query
|
4,705
|
static public ContentHandleFactory newFactory ( ) { return new ContentHandleFactory ( ) { public Class < ? > [ ] getHandledClasses ( ) { return new Class < ? > [ ] { JsonElement . class } ; } public boolean isHandled ( Class < ? > type ) { return JsonElement . class . isAssignableFrom ( type ) ; } public < C > ContentHandle < C > newHandle ( Class < C > type ) { @ SuppressWarnings ( "unchecked" ) ContentHandle < C > handle = isHandled ( type ) ? ( ContentHandle < C > ) new GSONHandle ( ) : null ; return handle ; } } ; }
|
Creates a factory to create a GSONHandle instance for a JsonElement node .
|
4,706
|
private void writeTextHandleTransformAs ( String transformName , ExtensionMetadata metadata , Object source , String transformType ) throws ResourceNotFoundException , ResourceNotResendableException , ForbiddenUserException , FailedRequestException { if ( source == null ) { throw new IllegalArgumentException ( "no source to write" ) ; } Class < ? > as = source . getClass ( ) ; TextWriteHandle sourceHandle = null ; if ( TextWriteHandle . class . isAssignableFrom ( as ) ) { sourceHandle = ( TextWriteHandle ) source ; } else { ContentHandle < ? > handle = getHandleRegistry ( ) . makeHandle ( as ) ; if ( ! TextWriteHandle . class . isAssignableFrom ( handle . getClass ( ) ) ) { throw new IllegalArgumentException ( "Handle " + handle . getClass ( ) . getName ( ) + " cannot be used to write transform source as " + as . getName ( ) ) ; } Utilities . setHandleContent ( handle , source ) ; sourceHandle = ( TextWriteHandle ) handle ; } if ( transformType . equals ( "javascript" ) ) { writeJavascriptTransform ( transformName , sourceHandle , metadata ) ; } else if ( transformType . equals ( "xquery" ) ) { writeXQueryTransform ( transformName , sourceHandle , metadata ) ; } }
|
This method used by writeJavascriptTransformAs and writeXQueryTransformAs
|
4,707
|
static public ContentHandleFactory newFactory ( ) { return new ContentHandleFactory ( ) { public Class < ? > [ ] getHandledClasses ( ) { return new Class < ? > [ ] { Source . class } ; } public boolean isHandled ( Class < ? > type ) { return Source . class . isAssignableFrom ( type ) ; } public < C > ContentHandle < C > newHandle ( Class < C > type ) { @ SuppressWarnings ( "unchecked" ) ContentHandle < C > handle = isHandled ( type ) ? ( ContentHandle < C > ) new SourceHandle ( ) : null ; return handle ; } } ; }
|
Creates a factory to create a SourceHandle instance for a Transformer Source .
|
4,708
|
public void transform ( Result result ) { if ( logger . isInfoEnabled ( ) ) logger . info ( "Transforming source into result" ) ; try { if ( content == null ) { throw new IllegalStateException ( "No source to transform" ) ; } Transformer transformer = null ; if ( this . transformer != null ) { transformer = getTransformer ( ) ; } else { if ( logger . isWarnEnabled ( ) ) logger . warn ( "No transformer, so using identity transform" ) ; transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; } transformer . transform ( content , result ) ; } catch ( TransformerException e ) { logger . error ( "Failed to transform source into result" , e ) ; throw new MarkLogicIOException ( e ) ; } }
|
Transforms the source for the content output to the result . If the transformer is not specified an identity transform sends the source to the result . When writing the result is stored in the database
|
4,709
|
public < T extends BinaryReadHandle > T read ( String uri , T contentHandle , long start , long length ) { return read ( uri , null , contentHandle , null , start , length , null ) ; }
|
strongly typed readers
|
4,710
|
public static Emoji getEmoji ( String code ) { Matcher m = shortCodePattern . matcher ( code ) ; if ( m . find ( ) ) { code = m . group ( 1 ) ; } Emoji emoji = selectFirst ( EmojiManager . data ( ) , having ( on ( Emoji . class ) . getEmoji ( ) , Matchers . equalTo ( code ) ) . or ( having ( on ( Emoji . class ) . getEmoji ( ) , Matchers . equalTo ( code ) ) ) . or ( having ( on ( Emoji . class ) . getHexHtml ( ) , Matchers . equalToIgnoringCase ( code ) ) ) . or ( having ( on ( Emoji . class ) . getDecimalHtml ( ) , Matchers . equalToIgnoringCase ( code ) ) ) . or ( having ( on ( Emoji . class ) . getDecimalSurrogateHtml ( ) , Matchers . equalToIgnoringCase ( code ) ) ) . or ( having ( on ( Emoji . class ) . getHexHtmlShort ( ) , Matchers . equalToIgnoringCase ( code ) ) ) . or ( having ( on ( Emoji . class ) . getDecimalHtmlShort ( ) , Matchers . equalToIgnoringCase ( code ) ) ) . or ( having ( on ( Emoji . class ) . getAliases ( ) , Matchers . hasItem ( code ) ) ) . or ( having ( on ( Emoji . class ) . getEmoticons ( ) , Matchers . hasItem ( code ) ) ) ) ; return emoji ; }
|
Get emoji by unicode short code decimal html entity or hexadecimal html entity
|
4,711
|
private static String processStringWithRegex ( String text , Pattern pattern , int startIndex , boolean recurseEmojify ) { Matcher matcher = pattern . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; int resetIndex = 0 ; if ( startIndex > 0 ) { matcher . region ( startIndex , text . length ( ) ) ; } while ( matcher . find ( ) ) { String emojiCode = matcher . group ( ) ; Emoji emoji = getEmoji ( emojiCode ) ; if ( emoji != null ) { matcher . appendReplacement ( sb , emoji . getEmoji ( ) ) ; } else { if ( htmlSurrogateEntityPattern2 . matcher ( emojiCode ) . matches ( ) ) { String highSurrogate1 = matcher . group ( "H1" ) ; String highSurrogate2 = matcher . group ( "H2" ) ; String lowSurrogate1 = matcher . group ( "L1" ) ; String lowSurrogate2 = matcher . group ( "L2" ) ; matcher . appendReplacement ( sb , processStringWithRegex ( highSurrogate1 + highSurrogate2 , shortCodeOrHtmlEntityPattern , 0 , false ) ) ; if ( sb . toString ( ) . endsWith ( highSurrogate2 ) ) { resetIndex = sb . length ( ) - highSurrogate2 . length ( ) ; } else { resetIndex = sb . length ( ) ; } sb . append ( lowSurrogate1 ) ; sb . append ( lowSurrogate2 ) ; break ; } else if ( htmlSurrogateEntityPattern . matcher ( emojiCode ) . matches ( ) ) { String highSurrogate = matcher . group ( "H" ) ; String lowSurrogate = matcher . group ( "L" ) ; matcher . appendReplacement ( sb , processStringWithRegex ( highSurrogate , htmlEntityPattern , 0 , true ) ) ; resetIndex = sb . length ( ) ; sb . append ( lowSurrogate ) ; break ; } else { matcher . appendReplacement ( sb , emojiCode ) ; } } } matcher . appendTail ( sb ) ; if ( recurseEmojify && resetIndex > 0 ) { return emojify ( sb . toString ( ) , resetIndex ) ; } return sb . toString ( ) ; }
|
Common method used for processing the string to replace with emojis
|
4,712
|
public static int countEmojis ( String text ) { String htmlifiedText = htmlify ( text ) ; Matcher matcher = htmlEntityPattern . matcher ( htmlifiedText ) ; int counter = 0 ; while ( matcher . find ( ) ) { String emojiCode = matcher . group ( ) ; if ( isEmoji ( emojiCode ) ) { counter ++ ; } } return counter ; }
|
Counts valid emojis passed string
|
4,713
|
public static String htmlify ( String text ) { String emojifiedStr = emojify ( text ) ; return htmlifyHelper ( emojifiedStr , false , false ) ; }
|
Converts unicode characters in text to corresponding decimal html entities
|
4,714
|
public static String hexHtmlify ( String text ) { String emojifiedStr = emojify ( text ) ; return htmlifyHelper ( emojifiedStr , true , false ) ; }
|
Converts unicode characters in text to corresponding hexadecimal html entities
|
4,715
|
public static String shortCodify ( String text ) { String emojifiedText = emojify ( text ) ; for ( Emoji emoji : EmojiManager . data ( ) ) { StringBuilder shortCodeBuilder = new StringBuilder ( ) ; shortCodeBuilder . append ( ":" ) . append ( emoji . getAliases ( ) . get ( 0 ) ) . append ( ":" ) ; emojifiedText = emojifiedText . replace ( emoji . getEmoji ( ) , shortCodeBuilder . toString ( ) ) ; } return emojifiedText ; }
|
Converts emojis hex decimal htmls emoticons in a string to short codes
|
4,716
|
public static String removeAllEmojis ( String emojiText ) { for ( Emoji emoji : EmojiManager . data ( ) ) { emojiText = emojiText . replace ( emoji . getEmoji ( ) , "" ) ; } return emojiText ; }
|
Removes all emoji characters from the passed string . This method does not remove html characters shortcodes . To remove all shortcodes html characters emojify and then pass the emojified string to this method .
|
4,717
|
protected static String htmlifyHelper ( String text , boolean isHex , boolean isSurrogate ) { StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { int ch = text . codePointAt ( i ) ; if ( ch <= 128 ) { sb . appendCodePoint ( ch ) ; } else if ( ch > 128 && ( ch < 159 || ( ch >= 55296 && ch <= 57343 ) ) ) { continue ; } else { if ( isHex ) { sb . append ( "&#x" + Integer . toHexString ( ch ) + ";" ) ; } else { if ( isSurrogate ) { double H = Math . floor ( ( ch - 0x10000 ) / 0x400 ) + 0xD800 ; double L = ( ( ch - 0x10000 ) % 0x400 ) + 0xDC00 ; sb . append ( "&#" + String . format ( "%.0f" , H ) + ";&#" + String . format ( "%.0f" , L ) + ";" ) ; } else { sb . append ( "&#" + ch + ";" ) ; } } } } return sb . toString ( ) ; }
|
Helper to convert emoji characters to html entities in a string
|
4,718
|
private static void processEmoticonsToRegex ( ) { List < String > emoticons = new ArrayList < String > ( ) ; for ( Emoji e : emojiData ) { if ( e . getEmoticons ( ) != null ) { emoticons . addAll ( e . getEmoticons ( ) ) ; } } for ( int i = 0 ; i < emoticons . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < emoticons . size ( ) ; j ++ ) { String o1 = emoticons . get ( i ) ; String o2 = emoticons . get ( j ) ; if ( o2 . contains ( o1 ) ) { String temp = o2 ; emoticons . remove ( j ) ; emoticons . add ( i , temp ) ; } } } StringBuilder sb = new StringBuilder ( ) ; for ( String emoticon : emoticons ) { if ( sb . length ( ) != 0 ) { sb . append ( "|" ) ; } sb . append ( Pattern . quote ( emoticon ) ) ; } emoticonRegexPattern = Pattern . compile ( sb . toString ( ) ) ; }
|
Processes the Emoji data to emoticon regex
|
4,719
|
public void exportAsFdf ( FdfWriter writer ) { for ( Iterator it = fields . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) it . next ( ) ; Item item = ( Item ) entry . getValue ( ) ; String name = ( String ) entry . getKey ( ) ; PdfObject v = item . getMerged ( 0 ) . get ( PdfName . V ) ; if ( v == null ) continue ; String value = getField ( name ) ; if ( lastWasString ) writer . setFieldAsString ( name , value ) ; else writer . setFieldAsName ( name , value ) ; } }
|
Export the fields as a FDF .
|
4,720
|
public boolean renameField ( String oldName , String newName ) { int idx1 = oldName . lastIndexOf ( '.' ) + 1 ; int idx2 = newName . lastIndexOf ( '.' ) + 1 ; if ( idx1 != idx2 ) return false ; if ( ! oldName . substring ( 0 , idx1 ) . equals ( newName . substring ( 0 , idx2 ) ) ) return false ; if ( fields . containsKey ( newName ) ) return false ; Item item = ( Item ) fields . get ( oldName ) ; if ( item == null ) return false ; newName = newName . substring ( idx2 ) ; PdfString ss = new PdfString ( newName , PdfObject . TEXT_UNICODE ) ; item . writeToAll ( PdfName . T , ss , Item . WRITE_VALUE | Item . WRITE_MERGED ) ; item . markUsed ( this , Item . WRITE_VALUE ) ; fields . remove ( oldName ) ; fields . put ( newName , item ) ; return true ; }
|
Renames a field . Only the last part of the name can be renamed . For example if the original field is ab . cd . ef only the ef part can be renamed .
|
4,721
|
public String [ ] getListSelection ( String name ) { String [ ] ret ; String s = getField ( name ) ; if ( s == null ) { ret = new String [ ] { } ; } else { ret = new String [ ] { s } ; } Item item = ( Item ) fields . get ( name ) ; if ( item == null ) return ret ; PdfArray values = item . getMerged ( 0 ) . getAsArray ( PdfName . I ) ; if ( values == null ) return ret ; ret = new String [ values . size ( ) ] ; String [ ] options = getListOptionExport ( name ) ; PdfNumber n ; int idx = 0 ; for ( Iterator i = values . listIterator ( ) ; i . hasNext ( ) ; ) { n = ( PdfNumber ) i . next ( ) ; ret [ idx ++ ] = options [ n . intValue ( ) ] ; } return ret ; }
|
Gets the field values of a Choice field .
|
4,722
|
public void mergeXfaData ( Node n ) throws IOException , DocumentException { XfaForm . Xml2SomDatasets data = new XfaForm . Xml2SomDatasets ( n ) ; for ( Iterator it = data . getOrder ( ) . iterator ( ) ; it . hasNext ( ) ; ) { String name = ( String ) it . next ( ) ; String text = XfaForm . getNodeText ( ( Node ) data . getName2Node ( ) . get ( name ) ) ; setField ( name , text ) ; } }
|
Merges an XML data structure into this form .
|
4,723
|
public void setFields ( FdfReader fdf ) throws IOException , DocumentException { HashMap fd = fdf . getFields ( ) ; for ( Iterator i = fd . keySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { String f = ( String ) i . next ( ) ; String v = fdf . getFieldValue ( f ) ; if ( v != null ) setField ( f , v ) ; } }
|
Sets the fields by FDF merging .
|
4,724
|
public void setFields ( XfdfReader xfdf ) throws IOException , DocumentException { HashMap fd = xfdf . getFields ( ) ; for ( Iterator i = fd . keySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { String f = ( String ) i . next ( ) ; String v = xfdf . getFieldValue ( f ) ; if ( v != null ) setField ( f , v ) ; List l = xfdf . getListValues ( f ) ; if ( l != null ) setListSelection ( v , ( String [ ] ) l . toArray ( new String [ l . size ( ) ] ) ) ; } }
|
Sets the fields by XFDF merging .
|
4,725
|
public boolean setListSelection ( String name , String [ ] value ) throws IOException , DocumentException { Item item = getFieldItem ( name ) ; if ( item == null ) return false ; PdfName type = item . getMerged ( 0 ) . getAsName ( PdfName . FT ) ; if ( ! PdfName . CH . equals ( type ) ) { return false ; } String [ ] options = getListOptionExport ( name ) ; PdfArray array = new PdfArray ( ) ; for ( int i = 0 ; i < value . length ; i ++ ) { for ( int j = 0 ; j < options . length ; j ++ ) { if ( options [ j ] . equals ( value [ i ] ) ) { array . add ( new PdfNumber ( j ) ) ; } } } item . writeToAll ( PdfName . I , array , Item . WRITE_MERGED | Item . WRITE_VALUE ) ; item . writeToAll ( PdfName . V , null , Item . WRITE_MERGED | Item . WRITE_VALUE ) ; item . writeToAll ( PdfName . AP , null , Item . WRITE_MERGED | Item . WRITE_WIDGET ) ; item . markUsed ( this , Item . WRITE_VALUE | Item . WRITE_WIDGET ) ; return true ; }
|
Sets different values in a list selection . No appearance is generated yet ; nor does the code check if multiple select is allowed .
|
4,726
|
public Item getFieldItem ( String name ) { if ( xfa . isXfaPresent ( ) ) { name = xfa . findFieldName ( name , this ) ; if ( name == null ) return null ; } return ( Item ) fields . get ( name ) ; }
|
Gets the field structure .
|
4,727
|
public String getTranslatedFieldName ( String name ) { if ( xfa . isXfaPresent ( ) ) { String namex = xfa . findFieldName ( name , this ) ; if ( namex != null ) name = namex ; } return name ; }
|
Gets the long XFA translated name .
|
4,728
|
public ArrayList getSignatureNames ( ) { if ( sigNames != null ) return new ArrayList ( sigNames . keySet ( ) ) ; sigNames = new HashMap ( ) ; ArrayList sorter = new ArrayList ( ) ; for ( Iterator it = fields . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) it . next ( ) ; Item item = ( Item ) entry . getValue ( ) ; PdfDictionary merged = item . getMerged ( 0 ) ; if ( ! PdfName . SIG . equals ( merged . get ( PdfName . FT ) ) ) continue ; PdfDictionary v = merged . getAsDict ( PdfName . V ) ; if ( v == null ) continue ; PdfString contents = v . getAsString ( PdfName . CONTENTS ) ; if ( contents == null ) continue ; PdfArray ro = v . getAsArray ( PdfName . BYTERANGE ) ; if ( ro == null ) continue ; int rangeSize = ro . size ( ) ; if ( rangeSize < 2 ) continue ; int lengthOfSignedBlocks = 0 ; for ( int i = rangeSize - 1 ; i > 0 ; i = i - 2 ) { lengthOfSignedBlocks += ro . getAsNumber ( i ) . intValue ( ) ; } int unsignedBlock = contents . getOriginalBytes ( ) . length * 2 + 2 ; int length = lengthOfSignedBlocks + unsignedBlock ; sorter . add ( new Object [ ] { entry . getKey ( ) , new int [ ] { length , 0 } } ) ; } Collections . sort ( sorter , new AcroFields . SorterComparator ( ) ) ; if ( ! sorter . isEmpty ( ) ) { if ( ( ( int [ ] ) ( ( Object [ ] ) sorter . get ( sorter . size ( ) - 1 ) ) [ 1 ] ) [ 0 ] == reader . getFileLength ( ) ) totalRevisions = sorter . size ( ) ; else totalRevisions = sorter . size ( ) + 1 ; for ( int k = 0 ; k < sorter . size ( ) ; ++ k ) { Object objs [ ] = ( Object [ ] ) sorter . get ( k ) ; String name = ( String ) objs [ 0 ] ; int p [ ] = ( int [ ] ) objs [ 1 ] ; p [ 1 ] = k + 1 ; sigNames . put ( name , p ) ; } } return new ArrayList ( sigNames . keySet ( ) ) ; }
|
Gets the field names that have signatures and are signed .
|
4,729
|
public ArrayList getBlankSignatureNames ( ) { getSignatureNames ( ) ; ArrayList sigs = new ArrayList ( ) ; for ( Iterator it = fields . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) it . next ( ) ; Item item = ( Item ) entry . getValue ( ) ; PdfDictionary merged = item . getMerged ( 0 ) ; if ( ! PdfName . SIG . equals ( merged . getAsName ( PdfName . FT ) ) ) continue ; if ( sigNames . containsKey ( entry . getKey ( ) ) ) continue ; sigs . add ( entry . getKey ( ) ) ; } return sigs ; }
|
Gets the field names that have blank signatures .
|
4,730
|
public boolean signatureCoversWholeDocument ( String name ) { getSignatureNames ( ) ; name = getTranslatedFieldName ( name ) ; if ( ! sigNames . containsKey ( name ) ) return false ; return ( ( int [ ] ) sigNames . get ( name ) ) [ 0 ] == reader . getFileLength ( ) ; }
|
Checks is the signature covers the entire document or just part of it .
|
4,731
|
public InputStream extractRevision ( String field ) throws IOException { getSignatureNames ( ) ; field = getTranslatedFieldName ( field ) ; if ( ! sigNames . containsKey ( field ) ) return null ; int length = ( ( int [ ] ) sigNames . get ( field ) ) [ 0 ] ; RandomAccessFileOrArray raf = reader . getSafeFile ( ) ; raf . reOpen ( ) ; raf . seek ( 0 ) ; return new RevisionStream ( raf , length ) ; }
|
Extracts a revision from the document .
|
4,732
|
public void addSubstitutionFont ( BaseFont font ) { if ( substitutionFonts == null ) substitutionFonts = new ArrayList ( ) ; substitutionFonts . add ( font ) ; }
|
Adds a substitution font to the list . The fonts in this list will be used if the original font doesn t contain the needed glyphs .
|
4,733
|
public static final String getString ( int index , boolean lowercase ) { if ( index < 1 ) return "" ; index -- ; int bytes = 1 ; int start = 0 ; int symbols = 24 ; while ( index >= symbols + start ) { bytes ++ ; start += symbols ; symbols *= 24 ; } int c = index - start ; char [ ] value = new char [ bytes ] ; while ( bytes > 0 ) { bytes -- ; value [ bytes ] = ( char ) ( c % 24 ) ; if ( value [ bytes ] > 16 ) value [ bytes ] ++ ; value [ bytes ] += ( lowercase ? 945 : 913 ) ; value [ bytes ] = SpecialSymbol . getCorrespondingSymbol ( value [ bytes ] ) ; c /= 24 ; } return String . valueOf ( value ) ; }
|
Changes an int into a Greek letter combination .
|
4,734
|
public void writeContent ( final OutputStream result ) throws IOException { result . write ( OPEN_GROUP ) ; result . write ( GENERATOR ) ; result . write ( DELIMITER ) ; result . write ( DocWriter . getISOBytes ( Document . getVersion ( ) ) ) ; result . write ( CLOSE_GROUP ) ; this . document . outputDebugLinebreak ( result ) ; }
|
Writes the RTF generator group .
|
4,735
|
public static String getCode39Ex ( String text ) { String out = "" ; for ( int k = 0 ; k < text . length ( ) ; ++ k ) { char c = text . charAt ( k ) ; if ( c > 127 ) throw new IllegalArgumentException ( "The character '" + c + "' is illegal in code 39 extended." ) ; char c1 = EXTENDED . charAt ( c * 2 ) ; char c2 = EXTENDED . charAt ( c * 2 + 1 ) ; if ( c1 != ' ' ) out += c1 ; out += c2 ; } return out ; }
|
Converts the extended text into a normal escaped text ready to generate bars .
|
4,736
|
public String lookup ( byte [ ] code , int offset , int length ) { String result = null ; Integer key = null ; if ( length == 1 ) { key = Integer . valueOf ( code [ offset ] & 0xff ) ; result = ( String ) singleByteMappings . get ( key ) ; } else if ( length == 2 ) { int intKey = code [ offset ] & 0xff ; intKey <<= 8 ; intKey += code [ offset + 1 ] & 0xff ; key = Integer . valueOf ( intKey ) ; result = ( String ) doubleByteMappings . get ( key ) ; } return result ; }
|
This will perform a lookup into the map .
|
4,737
|
public void addMapping ( byte [ ] src , String dest ) throws IOException { if ( src . length == 1 ) { singleByteMappings . put ( Integer . valueOf ( src [ 0 ] & 0xff ) , dest ) ; } else if ( src . length == 2 ) { int intSrc = src [ 0 ] & 0xFF ; intSrc <<= 8 ; intSrc |= ( src [ 1 ] & 0xFF ) ; doubleByteMappings . put ( Integer . valueOf ( intSrc ) , dest ) ; } else { throw new IOException ( "Mapping code should be 1 or two bytes and not " + src . length ) ; } }
|
This will add a mapping .
|
4,738
|
public void normalizeIndentation ( ) { float max = 0 ; Element o ; for ( Iterator i = list . iterator ( ) ; i . hasNext ( ) ; ) { o = ( Element ) i . next ( ) ; if ( o instanceof ListItem ) { max = Math . max ( max , ( ( ListItem ) o ) . getIndentationLeft ( ) ) ; } } for ( Iterator i = list . iterator ( ) ; i . hasNext ( ) ; ) { o = ( Element ) i . next ( ) ; if ( o instanceof ListItem ) { ( ( ListItem ) o ) . setIndentationLeft ( max ) ; } } }
|
Makes sure all the items in the list have the same indentation .
|
4,739
|
public float getTotalLeading ( ) { if ( list . size ( ) < 1 ) { return - 1 ; } ListItem item = ( ListItem ) list . get ( 0 ) ; return item . getTotalLeading ( ) ; }
|
Gets the leading of the first listitem .
|
4,740
|
public float trimLastSpace ( ) { BaseFont ft = font . getFont ( ) ; if ( ft . getFontType ( ) == BaseFont . FONT_TYPE_CJK && ft . getUnicodeEquivalent ( ' ' ) != ' ' ) { if ( value . length ( ) > 1 && value . endsWith ( "\u0001" ) ) { value = value . substring ( 0 , value . length ( ) - 1 ) ; return font . width ( '\u0001' ) ; } } else { if ( value . length ( ) > 1 && value . endsWith ( " " ) ) { value = value . substring ( 0 , value . length ( ) - 1 ) ; return font . width ( ' ' ) ; } } return 0 ; }
|
Trims the last space .
|
4,741
|
boolean isAttribute ( String name ) { if ( attributes . containsKey ( name ) ) return true ; return noStroke . containsKey ( name ) ; }
|
Checks if the attribute exists .
|
4,742
|
void adjustLeft ( float newValue ) { Object [ ] o = ( Object [ ] ) attributes . get ( Chunk . TAB ) ; if ( o != null ) { attributes . put ( Chunk . TAB , new Object [ ] { o [ 0 ] , o [ 1 ] , o [ 2 ] , new Float ( newValue ) } ) ; } }
|
Correction for the tab position based on the left starting position .
|
4,743
|
private byte [ ] [ ] getImageData ( Image image ) throws DocumentException { final int WMF_PLACEABLE_HEADER_SIZE = 22 ; final RtfByteArrayBuffer bab = new RtfByteArrayBuffer ( ) ; try { if ( imageType == Image . ORIGINAL_BMP ) { bab . append ( MetaDo . wrapBMP ( image ) ) ; } else { final byte [ ] iod = image . getOriginalData ( ) ; if ( iod == null ) { final InputStream imageIn = image . getUrl ( ) . openStream ( ) ; if ( imageType == Image . ORIGINAL_WMF ) { for ( int k = 0 ; k < WMF_PLACEABLE_HEADER_SIZE ; k ++ ) { if ( imageIn . read ( ) < 0 ) throw new EOFException ( "while removing wmf placeable header" ) ; } } bab . write ( imageIn ) ; imageIn . close ( ) ; } else { if ( imageType == Image . ORIGINAL_WMF ) { bab . write ( iod , WMF_PLACEABLE_HEADER_SIZE , iod . length - WMF_PLACEABLE_HEADER_SIZE ) ; } else { bab . append ( iod ) ; } } } return bab . toByteArrayArray ( ) ; } catch ( IOException ioe ) { throw new DocumentException ( ioe . getMessage ( ) ) ; } }
|
Extracts the image data from the Image .
|
4,744
|
private void writeImageDataHexEncoded ( final OutputStream bab ) throws IOException { int cnt = 0 ; for ( int k = 0 ; k < imageData . length ; k ++ ) { final byte [ ] chunk = imageData [ k ] ; for ( int x = 0 ; x < chunk . length ; x ++ ) { bab . write ( byte2charLUT , ( chunk [ x ] & 0xff ) * 2 , 2 ) ; if ( ++ cnt == 64 ) { bab . write ( '\n' ) ; cnt = 0 ; } } } if ( cnt > 0 ) bab . write ( '\n' ) ; }
|
Writes the image data to the given buffer as hex encoded text .
|
4,745
|
private int imageDataSize ( ) { int size = 0 ; for ( int k = 0 ; k < imageData . length ; k ++ ) { size += imageData [ k ] . length ; } return size ; }
|
Returns the image raw data size in bytes .
|
4,746
|
public void addAlias ( String name , String alias ) { attributeAliases . put ( alias . toLowerCase ( ) , name ) ; }
|
Sets an alias for an attribute .
|
4,747
|
public PdfContentByte defineGlyph ( char c , float wx , float llx , float lly , float urx , float ury ) { if ( c == 0 || c > 255 ) throw new IllegalArgumentException ( "The char " + ( int ) c + " doesn't belong in this Type3 font" ) ; usedSlot [ c ] = true ; Integer ck = Integer . valueOf ( c ) ; Type3Glyph glyph = ( Type3Glyph ) char2glyph . get ( ck ) ; if ( glyph != null ) return glyph ; widths3 . put ( c , ( int ) wx ) ; if ( ! colorized ) { if ( Float . isNaN ( this . llx ) ) { this . llx = llx ; this . lly = lly ; this . urx = urx ; this . ury = ury ; } else { this . llx = Math . min ( this . llx , llx ) ; this . lly = Math . min ( this . lly , lly ) ; this . urx = Math . max ( this . urx , urx ) ; this . ury = Math . max ( this . ury , ury ) ; } } glyph = new Type3Glyph ( writer , pageResources , wx , llx , lly , urx , ury , colorized ) ; char2glyph . put ( ck , glyph ) ; return glyph ; }
|
Defines a glyph . If the character was already defined it will return the same content
|
4,748
|
private static String split ( String s ) { int i = s . lastIndexOf ( '.' ) ; if ( i < 0 ) return s ; else return s . substring ( i + 1 ) ; }
|
Removes everything in a String that comes before a .
|
4,749
|
public void setSignInfo ( PrivateKey privKey , Certificate [ ] certChain , CRL [ ] crlList ) { try { pkcs = new PdfPKCS7 ( privKey , certChain , crlList , hashAlgorithm , provider , PdfName . ADBE_PKCS7_SHA1 . equals ( get ( PdfName . SUBFILTER ) ) ) ; pkcs . setExternalDigest ( externalDigest , externalRSAdata , digestEncryptionAlgorithm ) ; if ( PdfName . ADBE_X509_RSA_SHA1 . equals ( get ( PdfName . SUBFILTER ) ) ) { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; for ( int k = 0 ; k < certChain . length ; ++ k ) { bout . write ( certChain [ k ] . getEncoded ( ) ) ; } bout . close ( ) ; setCert ( bout . toByteArray ( ) ) ; setContents ( pkcs . getEncodedPKCS1 ( ) ) ; } else setContents ( pkcs . getEncodedPKCS7 ( ) ) ; name = PdfPKCS7 . getSubjectFields ( pkcs . getSigningCertificate ( ) ) . getField ( "CN" ) ; if ( name != null ) put ( PdfName . NAME , new PdfString ( name , PdfObject . TEXT_UNICODE ) ) ; pkcs = new PdfPKCS7 ( privKey , certChain , crlList , hashAlgorithm , provider , PdfName . ADBE_PKCS7_SHA1 . equals ( get ( PdfName . SUBFILTER ) ) ) ; pkcs . setExternalDigest ( externalDigest , externalRSAdata , digestEncryptionAlgorithm ) ; } catch ( Exception e ) { throw new ExceptionConverter ( e ) ; } }
|
Sets the crypto information to sign .
|
4,750
|
private int removeExplicitCodes ( ) { int w = 0 ; for ( int i = 0 ; i < textLength ; ++ i ) { byte t = initialTypes [ i ] ; if ( ! ( t == LRE || t == RLE || t == LRO || t == RLO || t == PDF || t == BN ) ) { embeddings [ w ] = embeddings [ i ] ; resultTypes [ w ] = resultTypes [ i ] ; resultLevels [ w ] = resultLevels [ i ] ; w ++ ; } } return w ; }
|
Rules X9 . Remove explicit codes so that they may be ignored during the remainder of the main portion of the algorithm . The length of the resulting text is returned .
|
4,751
|
private int reinsertExplicitCodes ( int textLength ) { for ( int i = initialTypes . length ; -- i >= 0 ; ) { byte t = initialTypes [ i ] ; if ( t == LRE || t == RLE || t == LRO || t == RLO || t == PDF || t == BN ) { embeddings [ i ] = 0 ; resultTypes [ i ] = t ; resultLevels [ i ] = - 1 ; } else { -- textLength ; embeddings [ i ] = embeddings [ textLength ] ; resultTypes [ i ] = resultTypes [ textLength ] ; resultLevels [ i ] = resultLevels [ textLength ] ; } } if ( resultLevels [ 0 ] == - 1 ) { resultLevels [ 0 ] = paragraphEmbeddingLevel ; } for ( int i = 1 ; i < initialTypes . length ; ++ i ) { if ( resultLevels [ i ] == - 1 ) { resultLevels [ i ] = resultLevels [ i - 1 ] ; } } return initialTypes . length ; }
|
Reinsert levels information for explicit codes . This is for ease of relating the level information to the original input data . Note that the levels assigned to these codes are arbitrary they re chosen so as to avoid breaking level runs .
|
4,752
|
private static byte [ ] processEmbeddings ( byte [ ] resultTypes , byte paragraphEmbeddingLevel ) { final int EXPLICIT_LEVEL_LIMIT = 62 ; int textLength = resultTypes . length ; byte [ ] embeddings = new byte [ textLength ] ; byte [ ] embeddingValueStack = new byte [ EXPLICIT_LEVEL_LIMIT ] ; int stackCounter = 0 ; int overflowAlmostCounter = 0 ; int overflowCounter = 0 ; byte currentEmbeddingLevel = paragraphEmbeddingLevel ; byte currentEmbeddingValue = paragraphEmbeddingLevel ; for ( int i = 0 ; i < textLength ; ++ i ) { embeddings [ i ] = currentEmbeddingValue ; byte t = resultTypes [ i ] ; switch ( t ) { case RLE : case LRE : case RLO : case LRO : if ( overflowCounter == 0 ) { byte newLevel ; if ( t == RLE || t == RLO ) { newLevel = ( byte ) ( ( currentEmbeddingLevel + 1 ) | 1 ) ; } else { newLevel = ( byte ) ( ( currentEmbeddingLevel + 2 ) & ~ 1 ) ; } if ( newLevel < EXPLICIT_LEVEL_LIMIT ) { embeddingValueStack [ stackCounter ] = currentEmbeddingValue ; stackCounter ++ ; currentEmbeddingLevel = newLevel ; if ( t == LRO || t == RLO ) { currentEmbeddingValue = ( byte ) ( newLevel | 0x80 ) ; } else { currentEmbeddingValue = newLevel ; } embeddings [ i ] = currentEmbeddingValue ; break ; } if ( currentEmbeddingLevel == 60 ) { overflowAlmostCounter ++ ; break ; } } overflowCounter ++ ; break ; case PDF : if ( overflowCounter > 0 ) { -- overflowCounter ; } else if ( overflowAlmostCounter > 0 && currentEmbeddingLevel != 61 ) { -- overflowAlmostCounter ; } else if ( stackCounter > 0 ) { -- stackCounter ; currentEmbeddingValue = embeddingValueStack [ stackCounter ] ; currentEmbeddingLevel = ( byte ) ( currentEmbeddingValue & 0x7f ) ; } break ; case B : stackCounter = 0 ; overflowCounter = 0 ; overflowAlmostCounter = 0 ; currentEmbeddingLevel = paragraphEmbeddingLevel ; currentEmbeddingValue = paragraphEmbeddingLevel ; embeddings [ i ] = paragraphEmbeddingLevel ; break ; default : break ; } } return embeddings ; }
|
2 ) determining explicit levels Rules X1 - X8
|
4,753
|
private void resolveNeutralTypes ( int start , int limit , byte level , byte sor , byte eor ) { for ( int i = start ; i < limit ; ++ i ) { byte t = resultTypes [ i ] ; if ( t == WS || t == ON || t == B || t == S ) { int runstart = i ; int runlimit = findRunLimit ( runstart , limit , new byte [ ] { B , S , WS , ON } ) ; byte leadingType ; byte trailingType ; if ( runstart == start ) { leadingType = sor ; } else { leadingType = resultTypes [ runstart - 1 ] ; if ( leadingType == L || leadingType == R ) { } else if ( leadingType == AN ) { leadingType = R ; } else if ( leadingType == EN ) { leadingType = R ; } } if ( runlimit == limit ) { trailingType = eor ; } else { trailingType = resultTypes [ runlimit ] ; if ( trailingType == L || trailingType == R ) { } else if ( trailingType == AN ) { trailingType = R ; } else if ( trailingType == EN ) { trailingType = R ; } } byte resolvedType ; if ( leadingType == trailingType ) { resolvedType = leadingType ; } else { resolvedType = typeForLevel ( level ) ; } setTypes ( runstart , runlimit , resolvedType ) ; i = runlimit ; } } }
|
6 ) resolving neutral types Rules N1 - N2 .
|
4,754
|
private void resolveImplicitLevels ( int start , int limit , byte level , byte sor , byte eor ) { if ( ( level & 1 ) == 0 ) { for ( int i = start ; i < limit ; ++ i ) { byte t = resultTypes [ i ] ; if ( t == L ) { } else if ( t == R ) { resultLevels [ i ] += 1 ; } else { resultLevels [ i ] += 2 ; } } } else { for ( int i = start ; i < limit ; ++ i ) { byte t = resultTypes [ i ] ; if ( t == R ) { } else { resultLevels [ i ] += 1 ; } } } }
|
7 ) resolving implicit embedding levels Rules I1 I2 .
|
4,755
|
private static int [ ] computeMultilineReordering ( byte [ ] levels , int [ ] linebreaks ) { int [ ] result = new int [ levels . length ] ; int start = 0 ; for ( int i = 0 ; i < linebreaks . length ; ++ i ) { int limit = linebreaks [ i ] ; byte [ ] templevels = new byte [ limit - start ] ; System . arraycopy ( levels , start , templevels , 0 , templevels . length ) ; int [ ] temporder = computeReordering ( templevels ) ; for ( int j = 0 ; j < temporder . length ; ++ j ) { result [ start + j ] = temporder [ j ] + start ; } start = limit ; } return result ; }
|
Return multiline reordering array for a given level array . Reordering does not occur across a line break .
|
4,756
|
private static boolean isWhitespace ( byte biditype ) { switch ( biditype ) { case LRE : case RLE : case LRO : case RLO : case PDF : case BN : case WS : return true ; default : return false ; } }
|
Return true if the type is considered a whitespace type for the line break rules .
|
4,757
|
private int findRunLimit ( int index , int limit , byte [ ] validSet ) { -- index ; loop : while ( ++ index < limit ) { byte t = resultTypes [ index ] ; for ( int i = 0 ; i < validSet . length ; ++ i ) { if ( t == validSet [ i ] ) { continue loop ; } } return index ; } return limit ; }
|
Return the limit of the run starting at index that includes only resultTypes in validSet . This checks the value at index and will return index if that value is not in validSet .
|
4,758
|
private static void validateTypes ( byte [ ] types ) { if ( types == null ) { throw new IllegalArgumentException ( "types is null" ) ; } for ( int i = 0 ; i < types . length ; ++ i ) { if ( types [ i ] < TYPE_MIN || types [ i ] > TYPE_MAX ) { throw new IllegalArgumentException ( "illegal type value at " + i + ": " + types [ i ] ) ; } } for ( int i = 0 ; i < types . length - 1 ; ++ i ) { if ( types [ i ] == B ) { throw new IllegalArgumentException ( "B type before end of paragraph at index: " + i ) ; } } }
|
Throw exception if type array is invalid .
|
4,759
|
private static void validateLineBreaks ( int [ ] linebreaks , int textLength ) { int prev = 0 ; for ( int i = 0 ; i < linebreaks . length ; ++ i ) { int next = linebreaks [ i ] ; if ( next <= prev ) { throw new IllegalArgumentException ( "bad linebreak: " + next + " at index: " + i ) ; } prev = next ; } if ( prev != textLength ) { throw new IllegalArgumentException ( "last linebreak must be at " + textLength ) ; } }
|
Throw exception if line breaks array is invalid .
|
4,760
|
private void processToUnicode ( ) { PdfObject toUni = fontDic . get ( PdfName . TOUNICODE ) ; if ( toUni != null ) { try { byte [ ] touni = PdfReader . getStreamBytes ( ( PRStream ) PdfReader . getPdfObjectRelease ( toUni ) ) ; CMapParser cmapParser = new CMapParser ( ) ; toUnicodeCmap = cmapParser . parse ( new ByteArrayInputStream ( touni ) ) ; } catch ( IOException e ) { throw new Error ( "Unable to process ToUnicode map - " + e . getMessage ( ) , e ) ; } } }
|
Parses the ToUnicode entry if present and constructs a CMap for it
|
4,761
|
private void processUni2Byte ( ) { IntHashtable uni2byte = getUni2Byte ( ) ; int e [ ] = uni2byte . toOrderedKeys ( ) ; cidbyte2uni = new char [ 256 ] ; for ( int k = 0 ; k < e . length ; ++ k ) { int n = uni2byte . get ( e [ k ] ) ; if ( cidbyte2uni [ n ] == 0 ) cidbyte2uni [ n ] = ( char ) e [ k ] ; } }
|
Inverts DocumentFont s uni2byte mapping to obtain a cid - to - unicode mapping based on the font s encoding
|
4,762
|
public static String getAlignment ( int alignment ) { switch ( alignment ) { case Element . ALIGN_LEFT : return HtmlTags . ALIGN_LEFT ; case Element . ALIGN_CENTER : return HtmlTags . ALIGN_CENTER ; case Element . ALIGN_RIGHT : return HtmlTags . ALIGN_RIGHT ; case Element . ALIGN_JUSTIFIED : case Element . ALIGN_JUSTIFIED_ALL : return HtmlTags . ALIGN_JUSTIFIED ; case Element . ALIGN_TOP : return HtmlTags . ALIGN_TOP ; case Element . ALIGN_MIDDLE : return HtmlTags . ALIGN_MIDDLE ; case Element . ALIGN_BOTTOM : return HtmlTags . ALIGN_BOTTOM ; case Element . ALIGN_BASELINE : return HtmlTags . ALIGN_BASELINE ; default : return "" ; } }
|
Translates the alignment value .
|
4,763
|
void makePackage ( PdfCollection collection ) { PdfDictionary catalog = reader . getCatalog ( ) ; catalog . put ( PdfName . COLLECTION , collection ) ; }
|
Adds or replaces the Collection Dictionary in the Catalog .
|
4,764
|
public void addViewerPreference ( PdfName key , PdfObject value ) { useVp = true ; this . viewerPreferences . addViewerPreference ( key , value ) ; }
|
Adds a viewer preference
|
4,765
|
void setTransition ( PdfTransition transition , int page ) { PdfDictionary pg = reader . getPageN ( page ) ; if ( transition == null ) pg . remove ( PdfName . TRANS ) ; else pg . put ( PdfName . TRANS , transition . getTransitionDictionary ( ) ) ; markUsed ( pg ) ; }
|
Sets the transition for the page
|
4,766
|
protected void readOCProperties ( ) { if ( ! documentOCG . isEmpty ( ) ) { return ; } PdfDictionary dict = reader . getCatalog ( ) . getAsDict ( PdfName . OCPROPERTIES ) ; if ( dict == null ) { return ; } PdfArray ocgs = dict . getAsArray ( PdfName . OCGS ) ; PdfIndirectReference ref ; PdfLayer layer ; HashMap ocgmap = new HashMap ( ) ; for ( Iterator i = ocgs . listIterator ( ) ; i . hasNext ( ) ; ) { ref = ( PdfIndirectReference ) i . next ( ) ; layer = new PdfLayer ( null ) ; layer . setRef ( ref ) ; layer . setOnPanel ( false ) ; layer . merge ( ( PdfDictionary ) PdfReader . getPdfObject ( ref ) ) ; ocgmap . put ( ref . toString ( ) , layer ) ; } PdfDictionary d = dict . getAsDict ( PdfName . D ) ; PdfArray off = d . getAsArray ( PdfName . OFF ) ; if ( off != null ) { for ( Iterator i = off . listIterator ( ) ; i . hasNext ( ) ; ) { ref = ( PdfIndirectReference ) i . next ( ) ; layer = ( PdfLayer ) ocgmap . get ( ref . toString ( ) ) ; layer . setOn ( false ) ; } } PdfArray order = d . getAsArray ( PdfName . ORDER ) ; if ( order != null ) { addOrder ( null , order , ocgmap ) ; } documentOCG . addAll ( ocgmap . values ( ) ) ; OCGRadioGroup = d . getAsArray ( PdfName . RBGROUPS ) ; OCGLocked = d . getAsArray ( PdfName . LOCKED ) ; if ( OCGLocked == null ) OCGLocked = new PdfArray ( ) ; }
|
Reads the OCProperties dictionary from the catalog of the existing document and fills the documentOCG documentOCGorder and OCGRadioGroup variables in PdfWriter . Note that the original OCProperties of the existing document can contain more information .
|
4,767
|
private void addOrder ( PdfLayer parent , PdfArray arr , Map ocgmap ) { PdfObject obj ; PdfLayer layer ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { obj = arr . getPdfObject ( i ) ; if ( obj . isIndirect ( ) ) { layer = ( PdfLayer ) ocgmap . get ( obj . toString ( ) ) ; layer . setOnPanel ( true ) ; registerLayer ( layer ) ; if ( parent != null ) { parent . addChild ( layer ) ; } if ( arr . size ( ) > i + 1 && arr . getPdfObject ( i + 1 ) . isArray ( ) ) { i ++ ; addOrder ( layer , ( PdfArray ) arr . getPdfObject ( i ) , ocgmap ) ; } } else if ( obj . isArray ( ) ) { PdfArray sub = ( PdfArray ) obj ; if ( sub . isEmpty ( ) ) return ; obj = sub . getPdfObject ( 0 ) ; if ( obj . isString ( ) ) { layer = new PdfLayer ( obj . toString ( ) ) ; layer . setOnPanel ( true ) ; registerLayer ( layer ) ; if ( parent != null ) { parent . addChild ( layer ) ; } PdfArray array = new PdfArray ( ) ; for ( Iterator j = sub . listIterator ( ) ; j . hasNext ( ) ; ) { array . add ( ( PdfObject ) j . next ( ) ) ; } addOrder ( layer , array , ocgmap ) ; } else { addOrder ( parent , ( PdfArray ) obj , ocgmap ) ; } } } }
|
Recursive method to reconstruct the documentOCGorder variable in the writer .
|
4,768
|
public void writeContent ( final OutputStream result ) throws IOException { if ( this . mode == MODE_SINGLE ) { headerAll . writeContent ( result ) ; } else if ( this . mode == MODE_MULTIPLE ) { if ( headerFirst != null ) { headerFirst . writeContent ( result ) ; } if ( headerLeft != null ) { headerLeft . writeContent ( result ) ; } if ( headerRight != null ) { headerRight . writeContent ( result ) ; } if ( headerAll != null ) { headerAll . writeContent ( result ) ; } } }
|
Write the content of this RtfHeaderFooterGroup .
|
4,769
|
public void setHeaderFooter ( RtfHeaderFooter headerFooter , int displayAt ) { this . mode = MODE_MULTIPLE ; headerFooter . setRtfDocument ( this . document ) ; headerFooter . setType ( this . type ) ; headerFooter . setDisplayAt ( displayAt ) ; switch ( displayAt ) { case RtfHeaderFooter . DISPLAY_ALL_PAGES : headerAll = headerFooter ; break ; case RtfHeaderFooter . DISPLAY_FIRST_PAGE : headerFirst = headerFooter ; break ; case RtfHeaderFooter . DISPLAY_LEFT_PAGES : headerLeft = headerFooter ; break ; case RtfHeaderFooter . DISPLAY_RIGHT_PAGES : headerRight = headerFooter ; break ; } }
|
Set a RtfHeaderFooter to be displayed at a certain position
|
4,770
|
public void setHeaderFooter ( HeaderFooter headerFooter , int displayAt ) { this . mode = MODE_MULTIPLE ; switch ( displayAt ) { case RtfHeaderFooter . DISPLAY_ALL_PAGES : headerAll = new RtfHeaderFooter ( this . document , headerFooter , this . type , displayAt ) ; break ; case RtfHeaderFooter . DISPLAY_FIRST_PAGE : headerFirst = new RtfHeaderFooter ( this . document , headerFooter , this . type , displayAt ) ; break ; case RtfHeaderFooter . DISPLAY_LEFT_PAGES : headerLeft = new RtfHeaderFooter ( this . document , headerFooter , this . type , displayAt ) ; break ; case RtfHeaderFooter . DISPLAY_RIGHT_PAGES : headerRight = new RtfHeaderFooter ( this . document , headerFooter , this . type , displayAt ) ; break ; } }
|
Set a HeaderFooter to be displayed at a certain position
|
4,771
|
public void setType ( int type ) { this . type = type ; if ( headerAll != null ) { headerAll . setType ( this . type ) ; } if ( headerFirst != null ) { headerFirst . setType ( this . type ) ; } if ( headerLeft != null ) { headerLeft . setType ( this . type ) ; } if ( headerRight != null ) { headerRight . setType ( this . type ) ; } }
|
Set the type of this RtfHeaderFooterGroup . RtfHeaderFooter . TYPE_HEADER or RtfHeaderFooter . TYPE_FOOTER . Also sets the type for all RtfHeaderFooters of this RtfHeaderFooterGroup .
|
4,772
|
public void addMember ( PdfLayer layer ) { if ( ! layers . contains ( layer ) ) { members . add ( layer . getRef ( ) ) ; layers . add ( layer ) ; } }
|
Adds a new member to the layer .
|
4,773
|
public int registerDirectory ( String dir , boolean scanSubdirectories ) { int count = 0 ; try { File file = new File ( dir ) ; if ( ! file . exists ( ) || ! file . isDirectory ( ) ) return 0 ; String files [ ] = file . list ( ) ; if ( files == null ) return 0 ; for ( int k = 0 ; k < files . length ; ++ k ) { try { file = new File ( dir , files [ k ] ) ; if ( file . isDirectory ( ) ) { if ( scanSubdirectories ) { count += registerDirectory ( file . getAbsolutePath ( ) , true ) ; } } else { String name = file . getPath ( ) ; String suffix = name . length ( ) < 4 ? null : name . substring ( name . length ( ) - 4 ) . toLowerCase ( ) ; if ( ".afm" . equals ( suffix ) || ".pfm" . equals ( suffix ) ) { File pfb = new File ( name . substring ( 0 , name . length ( ) - 4 ) + ".pfb" ) ; if ( pfb . exists ( ) ) { register ( name , null ) ; ++ count ; } } else if ( ".ttf" . equals ( suffix ) || ".otf" . equals ( suffix ) || ".ttc" . equals ( suffix ) ) { register ( name , null ) ; ++ count ; } } } catch ( Exception e ) { } } } catch ( Exception e ) { } return count ; }
|
Register all the fonts in a directory and possibly its subdirectories .
|
4,774
|
public int registerDirectories ( ) { int count = 0 ; count += registerDirectory ( "c:/windows/fonts" ) ; count += registerDirectory ( "c:/winnt/fonts" ) ; count += registerDirectory ( "d:/windows/fonts" ) ; count += registerDirectory ( "d:/winnt/fonts" ) ; count += registerDirectory ( "/usr/share/X11/fonts" , true ) ; count += registerDirectory ( "/usr/X/lib/X11/fonts" , true ) ; count += registerDirectory ( "/usr/openwin/lib/X11/fonts" , true ) ; count += registerDirectory ( "/usr/share/fonts" , true ) ; count += registerDirectory ( "/usr/X11R6/lib/X11/fonts" , true ) ; count += registerDirectory ( "/Library/Fonts" ) ; count += registerDirectory ( "/System/Library/Fonts" ) ; return count ; }
|
Register fonts in some probable directories . It usually works in Windows Linux and Solaris .
|
4,775
|
public void writeContent ( final OutputStream result ) throws IOException { result . write ( RtfParagraph . PARAGRAPH ) ; if ( this . title != null ) { this . title . writeContent ( result ) ; } for ( int i = 0 ; i < items . size ( ) ; i ++ ) { RtfBasicElement rbe = ( RtfBasicElement ) items . get ( i ) ; rbe . writeContent ( result ) ; } }
|
Write this RtfSection and its contents
|
4,776
|
public void setInTable ( boolean inTable ) { super . setInTable ( inTable ) ; for ( int i = 0 ; i < this . items . size ( ) ; i ++ ) { ( ( RtfBasicElement ) this . items . get ( i ) ) . setInTable ( inTable ) ; } }
|
Sets whether this RtfSection is in a table . Sets the correct inTable setting for all child elements .
|
4,777
|
public void setInHeader ( boolean inHeader ) { super . setInHeader ( inHeader ) ; for ( int i = 0 ; i < this . items . size ( ) ; i ++ ) { ( ( RtfBasicElement ) this . items . get ( i ) ) . setInHeader ( inHeader ) ; } }
|
Sets whether this RtfSection is in a header . Sets the correct inTable setting for all child elements .
|
4,778
|
private void updateIndentation ( float indentLeft , float indentRight , float indentContent ) { if ( this . title != null ) { this . title . setIndentLeft ( ( int ) ( this . title . getIndentLeft ( ) + indentLeft * RtfElement . TWIPS_FACTOR ) ) ; this . title . setIndentRight ( ( int ) ( this . title . getIndentRight ( ) + indentRight * RtfElement . TWIPS_FACTOR ) ) ; } for ( int i = 0 ; i < this . items . size ( ) ; i ++ ) { RtfBasicElement rtfElement = ( RtfBasicElement ) this . items . get ( i ) ; if ( rtfElement instanceof RtfSection ) { ( ( RtfSection ) rtfElement ) . updateIndentation ( indentLeft + indentContent , indentRight , 0 ) ; } else if ( rtfElement instanceof RtfParagraph ) { ( ( RtfParagraph ) rtfElement ) . setIndentLeft ( ( int ) ( ( ( RtfParagraph ) rtfElement ) . getIndentLeft ( ) + ( indentLeft + indentContent ) * RtfElement . TWIPS_FACTOR ) ) ; ( ( RtfParagraph ) rtfElement ) . setIndentRight ( ( int ) ( ( ( RtfParagraph ) rtfElement ) . getIndentRight ( ) + indentRight * RtfElement . TWIPS_FACTOR ) ) ; } } }
|
Updates the left right and content indentation of all RtfParagraph and RtfSection elements that this RtfSection contains .
|
4,779
|
protected void doAttributes ( AttributedCharacterIterator iter ) { underline = false ; Set set = iter . getAttributes ( ) . keySet ( ) ; for ( Iterator iterator = set . iterator ( ) ; iterator . hasNext ( ) ; ) { AttributedCharacterIterator . Attribute attribute = ( AttributedCharacterIterator . Attribute ) iterator . next ( ) ; if ( ! ( attribute instanceof TextAttribute ) ) { continue ; } TextAttribute textattribute = ( TextAttribute ) attribute ; if ( textattribute . equals ( TextAttribute . FONT ) ) { Font font = ( Font ) iter . getAttributes ( ) . get ( textattribute ) ; setFont ( font ) ; } else if ( textattribute . equals ( TextAttribute . UNDERLINE ) ) { if ( TextAttribute . UNDERLINE_ON . equals ( iter . getAttributes ( ) . get ( textattribute ) ) ) { underline = true ; } } else if ( textattribute . equals ( TextAttribute . SIZE ) ) { Object obj = iter . getAttributes ( ) . get ( textattribute ) ; if ( obj instanceof Integer ) { int i = ( ( Integer ) obj ) . intValue ( ) ; setFont ( getFont ( ) . deriveFont ( getFont ( ) . getStyle ( ) , i ) ) ; } else if ( obj instanceof Float ) { float f = ( ( Float ) obj ) . floatValue ( ) ; setFont ( getFont ( ) . deriveFont ( getFont ( ) . getStyle ( ) , f ) ) ; } } else if ( textattribute . equals ( TextAttribute . FOREGROUND ) ) { setColor ( ( Color ) iter . getAttributes ( ) . get ( textattribute ) ) ; } else if ( textattribute . equals ( TextAttribute . FAMILY ) ) { Font font = getFont ( ) ; Map fontAttributes = font . getAttributes ( ) ; fontAttributes . put ( TextAttribute . FAMILY , iter . getAttributes ( ) . get ( textattribute ) ) ; setFont ( font . deriveFont ( fontAttributes ) ) ; } else if ( textattribute . equals ( TextAttribute . POSTURE ) ) { Font font = getFont ( ) ; Map fontAttributes = font . getAttributes ( ) ; fontAttributes . put ( TextAttribute . POSTURE , iter . getAttributes ( ) . get ( textattribute ) ) ; setFont ( font . deriveFont ( fontAttributes ) ) ; } else if ( textattribute . equals ( TextAttribute . WEIGHT ) ) { Font font = getFont ( ) ; Map fontAttributes = font . getAttributes ( ) ; fontAttributes . put ( TextAttribute . WEIGHT , iter . getAttributes ( ) . get ( textattribute ) ) ; setFont ( font . deriveFont ( fontAttributes ) ) ; } } }
|
This routine goes through the attributes and sets the font before calling the actual string drawing routine
|
4,780
|
public void setRenderingHint ( Key arg0 , Object arg1 ) { if ( arg1 != null ) { rhints . put ( arg0 , arg1 ) ; } else { if ( arg0 instanceof HyperLinkKey ) { rhints . put ( arg0 , HyperLinkKey . VALUE_HYPERLINKKEY_OFF ) ; } else { rhints . remove ( arg0 ) ; } } }
|
Sets a rendering hint
|
4,781
|
public void setFont ( Font f ) { if ( f == null ) return ; if ( onlyShapes ) { font = f ; return ; } if ( f == font ) return ; font = f ; fontSize = f . getSize2D ( ) ; baseFont = getCachedBaseFont ( f ) ; }
|
Sets the current font .
|
4,782
|
float indentLeft ( ) { if ( isRTL ) { switch ( alignment ) { case Element . ALIGN_LEFT : return left + width ; case Element . ALIGN_CENTER : return left + ( width / 2f ) ; default : return left ; } } else if ( this . getSeparatorCount ( ) == 0 ) { switch ( alignment ) { case Element . ALIGN_RIGHT : return left + width ; case Element . ALIGN_CENTER : return left + ( width / 2f ) ; } } return left ; }
|
Returns the left indentation of the line taking the alignment of the line into account .
|
4,783
|
int numberOfSpaces ( ) { String string = toString ( ) ; int length = string . length ( ) ; int numberOfSpaces = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( string . charAt ( i ) == ' ' ) { numberOfSpaces ++ ; } } return numberOfSpaces ; }
|
Returns the number of space - characters in this line .
|
4,784
|
public int GetLineLengthUtf32 ( ) { int total = 0 ; for ( Iterator i = line . iterator ( ) ; i . hasNext ( ) ; ) { total += ( ( PdfChunk ) i . next ( ) ) . lengthUtf32 ( ) ; } return total ; }
|
Returns the length of a line in UTF32 characters
|
4,785
|
int getSeparatorCount ( ) { int s = 0 ; PdfChunk ck ; for ( Iterator i = line . iterator ( ) ; i . hasNext ( ) ; ) { ck = ( PdfChunk ) i . next ( ) ; if ( ck . isTab ( ) ) { return 0 ; } if ( ck . isHorizontalSeparator ( ) ) { s ++ ; } } return s ; }
|
Gets the number of separators in the line .
|
4,786
|
public float getWidthCorrected ( float charSpacing , float wordSpacing ) { float total = 0 ; for ( int k = 0 ; k < line . size ( ) ; ++ k ) { PdfChunk ck = ( PdfChunk ) line . get ( k ) ; total += ck . getWidthCorrected ( charSpacing , wordSpacing ) ; } return total ; }
|
Gets a width corrected with a charSpacing and wordSpacing .
|
4,787
|
public float getAscender ( ) { float ascender = 0 ; for ( int k = 0 ; k < line . size ( ) ; ++ k ) { PdfChunk ck = ( PdfChunk ) line . get ( k ) ; if ( ck . isImage ( ) ) ascender = Math . max ( ascender , ck . getImage ( ) . getScaledHeight ( ) + ck . getImageOffsetY ( ) ) ; else { PdfFont font = ck . font ( ) ; ascender = Math . max ( ascender , font . getFont ( ) . getFontDescriptor ( BaseFont . ASCENT , font . size ( ) ) ) ; } } return ascender ; }
|
Gets the maximum size of the ascender for all the fonts used in this line .
|
4,788
|
public float getDescender ( ) { float descender = 0 ; for ( int k = 0 ; k < line . size ( ) ; ++ k ) { PdfChunk ck = ( PdfChunk ) line . get ( k ) ; if ( ck . isImage ( ) ) descender = Math . min ( descender , ck . getImageOffsetY ( ) ) ; else { PdfFont font = ck . font ( ) ; descender = Math . min ( descender , font . getFont ( ) . getFontDescriptor ( BaseFont . DESCENT , font . size ( ) ) ) ; } } return descender ; }
|
Gets the biggest descender for all the fonts used in this line . Note that this is a negative number .
|
4,789
|
public void insert ( String key , char val ) { int len = key . length ( ) + 1 ; if ( freenode + len > eq . length ) { redimNodeArrays ( eq . length + BLOCK_SIZE ) ; } char strkey [ ] = new char [ len -- ] ; key . getChars ( 0 , len , strkey , 0 ) ; strkey [ len ] = 0 ; root = insert ( root , strkey , 0 , val ) ; }
|
Branches are initially compressed needing one node per key plus the size of the string key . They are decompressed as needed when another key with same prefix is inserted . This saves a lot of space specially for long keys .
|
4,790
|
private char insert ( char p , char [ ] key , int start , char val ) { int len = strlen ( key , start ) ; if ( p == 0 ) { p = freenode ++ ; eq [ p ] = val ; length ++ ; hi [ p ] = 0 ; if ( len > 0 ) { sc [ p ] = 0xFFFF ; lo [ p ] = ( char ) kv . alloc ( len + 1 ) ; strcpy ( kv . getArray ( ) , lo [ p ] , key , start ) ; } else { sc [ p ] = 0 ; lo [ p ] = 0 ; } return p ; } if ( sc [ p ] == 0xFFFF ) { char pp = freenode ++ ; lo [ pp ] = lo [ p ] ; eq [ pp ] = eq [ p ] ; lo [ p ] = 0 ; if ( len > 0 ) { sc [ p ] = kv . get ( lo [ pp ] ) ; eq [ p ] = pp ; lo [ pp ] ++ ; if ( kv . get ( lo [ pp ] ) == 0 ) { lo [ pp ] = 0 ; sc [ pp ] = 0 ; hi [ pp ] = 0 ; } else { sc [ pp ] = 0xFFFF ; } } else { sc [ pp ] = 0xFFFF ; hi [ p ] = pp ; sc [ p ] = 0 ; eq [ p ] = val ; length ++ ; return p ; } } char s = key [ start ] ; if ( s < sc [ p ] ) { lo [ p ] = insert ( lo [ p ] , key , start , val ) ; } else if ( s == sc [ p ] ) { if ( s != 0 ) { eq [ p ] = insert ( eq [ p ] , key , start + 1 , val ) ; } else { eq [ p ] = val ; } } else { hi [ p ] = insert ( hi [ p ] , key , start , val ) ; } return p ; }
|
The actual insertion function recursive version .
|
4,791
|
public static int strcmp ( char [ ] a , int startA , char [ ] b , int startB ) { for ( ; a [ startA ] == b [ startB ] ; startA ++ , startB ++ ) { if ( a [ startA ] == 0 ) { return 0 ; } } return a [ startA ] - b [ startB ] ; }
|
Compares 2 null terminated char arrays
|
4,792
|
public static int strcmp ( String str , char [ ] a , int start ) { int i , d , len = str . length ( ) ; for ( i = 0 ; i < len ; i ++ ) { d = str . charAt ( i ) - a [ start + i ] ; if ( d != 0 ) { return d ; } if ( a [ start + i ] == 0 ) { return d ; } } if ( a [ start + i ] != 0 ) { return - a [ start + i ] ; } return 0 ; }
|
Compares a string with null terminated char array
|
4,793
|
private void redimNodeArrays ( int newsize ) { int len = newsize < lo . length ? newsize : lo . length ; char [ ] na = new char [ newsize ] ; System . arraycopy ( lo , 0 , na , 0 , len ) ; lo = na ; na = new char [ newsize ] ; System . arraycopy ( hi , 0 , na , 0 , len ) ; hi = na ; na = new char [ newsize ] ; System . arraycopy ( eq , 0 , na , 0 , len ) ; eq = na ; na = new char [ newsize ] ; System . arraycopy ( sc , 0 , na , 0 , len ) ; sc = na ; }
|
redimension the arrays
|
4,794
|
protected void insertBalanced ( String [ ] k , char [ ] v , int offset , int n ) { int m ; if ( n < 1 ) { return ; } m = n >> 1 ; insert ( k [ m + offset ] , v [ m + offset ] ) ; insertBalanced ( k , v , offset , m ) ; insertBalanced ( k , v , offset + m + 1 , n - m - 1 ) ; }
|
Recursively insert the median first and then the median of the lower and upper halves and so on in order to get a balanced tree . The array of keys is assumed to be sorted in ascending order .
|
4,795
|
public void balance ( ) { int i = 0 , n = length ; String [ ] k = new String [ n ] ; char [ ] v = new char [ n ] ; Iterator iter = new Iterator ( ) ; while ( iter . hasMoreElements ( ) ) { v [ i ] = iter . getValue ( ) ; k [ i ++ ] = ( String ) iter . nextElement ( ) ; } init ( ) ; insertBalanced ( k , v , 0 , n ) ; }
|
Balance the tree for best search performance
|
4,796
|
public void setDimensions ( float llx , float lly , float urx , float ury ) { this . llx = llx ; this . lly = lly ; this . urx = urx ; this . ury = ury ; }
|
Sets the dimensions of this annotation .
|
4,797
|
protected int packValues ( String values ) { int i , n = values . length ( ) ; int m = ( n & 1 ) == 1 ? ( n >> 1 ) + 2 : ( n >> 1 ) + 1 ; int offset = vspace . alloc ( m ) ; byte [ ] va = vspace . getArray ( ) ; for ( i = 0 ; i < n ; i ++ ) { int j = i >> 1 ; byte v = ( byte ) ( ( values . charAt ( i ) - '0' + 1 ) & 0x0f ) ; if ( ( i & 1 ) == 1 ) { va [ j + offset ] = ( byte ) ( va [ j + offset ] | v ) ; } else { va [ j + offset ] = ( byte ) ( v << 4 ) ; } } va [ m - 1 + offset ] = 0 ; return offset ; }
|
Packs the values by storing them in 4 bits two values into a byte Values range is from 0 to 9 . We use zero as terminator so we ll add 1 to the value .
|
4,798
|
protected int hstrcmp ( char [ ] s , int si , char [ ] t , int ti ) { for ( ; s [ si ] == t [ ti ] ; si ++ , ti ++ ) { if ( s [ si ] == 0 ) { return 0 ; } } if ( t [ ti ] == 0 ) { return 0 ; } return s [ si ] - t [ ti ] ; }
|
String compare returns 0 if equal or t is a substring of s
|
4,799
|
public Hyphenation hyphenate ( String word , int remainCharCount , int pushCharCount ) { char [ ] w = word . toCharArray ( ) ; return hyphenate ( w , 0 , w . length , remainCharCount , pushCharCount ) ; }
|
Hyphenate word and return a Hyphenation object .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.