private PdfStream getToUnicode ( Object metrics [ ] ) { metrics = filterCmapMetrics ( metrics ) ; if ( metrics . length == 0 ) return null ; StringBuffer buf = new StringBuffer ( "/CIDInit /ProcSet findresource begin\n" + "12 dict begin\n" + "begincmap\n" + "/CIDSystemInfo\n" + "<< /Registry (TTX+0)\n" + "/Ordering (T42UV)\n" + "/Supplement 0\n" + ">> def\n" + "/CMapName /TTX+0 def\n" + "/CMapType 2 def\n" + "1 begincodespacerange\n" + "<0000><FFFF>\n" + "endcodespacerange\n" ) ; int size = 0 ; for ( int k = 0 ; k < metrics . length ; ++ k ) { if ( size == 0 ) { if ( k != 0 ) { buf . append ( "endbfrange\n" ) ; } size = Math . min ( 100 , metrics . length - k ) ; buf . append ( size ) . append ( " beginbfrange\n" ) ; } -- size ; int metric [ ] = ( int [ ] ) metrics [ k ] ; String fromTo = toHex ( metric [ 0 ] ) ; buf . append ( fromTo ) . append ( fromTo ) . append ( toHex ( metric [ 2 ] ) ) . append ( ' ' ) ; } buf . append ( "endbfrange\n" + "endcmap\n" + "CMapName currentdict /CMap defineresource pop\n" + "end end\n" ) ; String s = buf . toString ( ) ; PdfStream stream = new PdfStream ( PdfEncodings . convertToBytes ( s , null ) ) ; stream . flateCompress ( compressionLevel ) ; return stream ; }
Creates a ToUnicode CMap to allow copy and paste from Acrobat .