ASF Bugzilla – Attachment 2865 Details for
Bug 11010
I have crosschecked the changes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Unicode support for sheet name, format records and "print titles" of namerecord
unicode_and_namerecord_patch.patch (text/plain), 22.90 KB, created by
Sergei Kozello
on 2002-08-29 08:34:27 UTC
(
hide
)
Description:
Unicode support for sheet name, format records and "print titles" of namerecord
Filename:
MIME Type:
Creator:
Sergei Kozello
Created:
2002-08-29 08:34:27 UTC
Size:
22.90 KB
patch
obsolete
>Python is not available ! >CVSROOT: anoncvs@cvs.apache.org:/home/cvspublic (password authentication) >TCL is available, shell is enabled : help (select and press enter) >cvs diff src\java\org\apache\poi\hssf\dev\BiffViewer.java src\java\org\apache\poi\hssf\record\FormatRecord.java src\java\org\apache\poi\hssf\eventmodel\HSSFEventFactory.java src\java\org\apache\poi\hssf\usermodel\HSSFWorkbook.java src\java\org\apache\poi\hssf\record\NameRecord.java src\java\org\apache\poi\util\StringUtil.java src\testcases\org\apache\poi\util\TestStringUtil.java (in directory E:\Projects\jakarta-poi\) >Index: src/java/org/apache/poi/hssf/dev/BiffViewer.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/dev/BiffViewer.java,v >retrieving revision 1.27 >diff -r1.27 BiffViewer.java >626a627,629 >> case NameRecord.sid: >> retval = new NameRecord( rectype, size, data ); >> break; >Index: src/java/org/apache/poi/hssf/record/FormatRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/FormatRecord.java,v >retrieving revision 1.4 >diff -r1.4 FormatRecord.java >76c76,77 >< private short field_3_zero; // undocumented 2 bytes of 0 >--- >> private short field_3_unicode_len; // unicode string length >> private boolean field_3_unicode_flag; // it is not undocumented - it is unicode flag >121,124c122,134 >< field_2_formatstring_len = data[ 2 + offset ]; >< field_3_zero = LittleEndian.getShort(data, 3 + offset); >< field_4_formatstring = new String(data, 5 + offset, >< LittleEndian.ubyteToInt(field_2_formatstring_len)); >--- >> // field_2_formatstring_len = data[ 2 + offset ]; >> field_3_unicode_len = LittleEndian.getShort( data, 2 + offset ); >> field_3_unicode_flag = ( data[ 4 + offset ] & (byte)0x01 ) != 0; >> >> >> if ( field_3_unicode_flag ) { >> // unicode >> field_4_formatstring = StringUtil.getFromUnicodeHigh( data, 5 + offset, field_3_unicode_len ); >> } >> else { >> // not unicode >> field_4_formatstring = new String(data, 5 + offset, field_3_unicode_len ); >> } >145c155 >< >--- >> >205a216 >> /* >209,210c220,224 >< buffer.append(" .zero = ") >< .append(Integer.toHexString(field_3_zero)).append("\n"); >--- >> */ >> buffer.append(" .unicode length = ") >> .append(Integer.toHexString(field_3_unicode_len)).append("\n"); >> buffer.append(" .isUnicode = ") >> .append( field_3_unicode_flag ).append("\n"); >220,223c234,237 >< LittleEndian.putShort(data, 2 + offset, >< ( short ) (5 + getFormatStringLength())); >< >< // 9 - 4(len/sid) + format string length >--- >> LittleEndian.putShort(data, 2 + offset, (short)( 2 + 2 + 1 + ( (field_3_unicode_flag) >> ? 2 * field_3_unicode_len >> : field_3_unicode_len ) ) ); >> // index + len + flag + format string length >225,227c239,250 >< data[ 6 + offset ] = getFormatStringLength(); >< LittleEndian.putShort(data, 7 + offset, ( short ) 0); >< StringUtil.putCompressedUnicode(getFormatString(), data, 9 + offset); >--- >> LittleEndian.putShort(data, 6 + offset, field_3_unicode_len); >> data[ 8 + offset ] = (byte)( (field_3_unicode_flag) ? 0x01 : 0x00 ); >> >> if ( field_3_unicode_flag ) { >> // unicode >> StringUtil.putUncompressedUnicode( getFormatString(), data, 9 + offset ); >> } >> else { >> // not unicode >> StringUtil.putCompressedUnicode( getFormatString(), data, 9 + offset ); >> } >> >233c256 >< return 9 + getFormatStringLength(); >--- >> return 9 + ( ( field_3_unicode_flag ) ? 2 * field_3_unicode_len : field_3_unicode_len ); >Index: src/java/org/apache/poi/hssf/record/NameRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/NameRecord.java,v >retrieving revision 1.4 >diff -r1.4 NameRecord.java >57a58 >> import org.apache.poi.util.HexDump; >72a74 >> * @author Sergei Kozello (sergeikozello at mail.ru) >90a93 >> private byte field_12_builtIn_name; >93c96 >< private byte[] field_13_raw_name_definition = null; // raw data >--- >> private byte[] field_13_raw_name_definition; // raw data >381c384 >< LittleEndian.putShort(data, 2 + offset, (short)( 15 + getTextsLength())); >--- >> // size defined below >393,417c396,432 >< >< StringUtil.putCompressedUnicode(getNameText(), data , 19 + offset); >< >< int start_of_name_definition = 19 + field_3_length_name_text; >< if (this.field_13_name_definition != null) { >< serializePtgs(data, start_of_name_definition + offset); >< } else { >< System.arraycopy(field_13_raw_name_definition,0,data >< ,start_of_name_definition + offset,field_13_raw_name_definition.length); >< } >< >< int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; >< StringUtil.putCompressedUnicode(getCustomMenuText(), data , start_of_custom_menu_text + offset); >< >< int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; >< StringUtil.putCompressedUnicode(getDescriptionText(), data , start_of_description_text + offset); >< >< int start_of_help_topic_text = start_of_description_text + field_9_length_help_topic_text; >< StringUtil.putCompressedUnicode(getHelpTopicText(), data , start_of_help_topic_text + offset); >< >< int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; >< StringUtil.putCompressedUnicode(getStatusBarText(), data , start_of_status_bar_text + offset); >< >< >< return getRecordSize(); >--- >> >> if ( ( field_1_option_flag & (short)0x20 ) != 0 ) { >> LittleEndian.putShort(data, 2 + offset, (short)( 16 + field_13_raw_name_definition.length )); >> >> data [19 + offset] = field_12_builtIn_name; >> System.arraycopy( field_13_raw_name_definition, 0, data, 20 + offset, field_13_raw_name_definition.length ); >> >> return 20 + field_13_raw_name_definition.length; >> } >> else { >> LittleEndian.putShort(data, 2 + offset, (short)( 15 + getTextsLength())); >> >> >> StringUtil.putCompressedUnicode(getNameText(), data , 19 + offset); >> >> int start_of_name_definition = 19 + field_3_length_name_text; >> if (this.field_13_name_definition != null) { >> serializePtgs(data, start_of_name_definition + offset); >> } else { >> System.arraycopy(field_13_raw_name_definition,0,data >> ,start_of_name_definition + offset,field_13_raw_name_definition.length); >> } >> >> int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; >> StringUtil.putCompressedUnicode(getCustomMenuText(), data , start_of_custom_menu_text + offset); >> >> int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; >> StringUtil.putCompressedUnicode(getDescriptionText(), data , start_of_description_text + offset); >> >> int start_of_help_topic_text = start_of_description_text + field_9_length_help_topic_text; >> StringUtil.putCompressedUnicode(getHelpTopicText(), data , start_of_help_topic_text + offset); >> >> int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; >> StringUtil.putCompressedUnicode(getStatusBarText(), data , start_of_status_bar_text + offset); >> >> return getRecordSize(); >> } >582,605c597,643 >< field_11_compressed_unicode_flag= data [14 + offset]; >< field_12_name_text = new String(data, 15 + offset, >< LittleEndian.ubyteToInt(field_3_length_name_text)); >< >< int start_of_name_definition = 15 + field_3_length_name_text; >< field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition, >< offset, start_of_name_definition); >< >< int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; >< field_14_custom_menu_text = new String(data, start_of_custom_menu_text + offset, >< LittleEndian.ubyteToInt(field_7_length_custom_menu)); >< >< int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; >< field_15_description_text = new String(data, start_of_description_text + offset, >< LittleEndian.ubyteToInt(field_8_length_description_text)); >< >< int start_of_help_topic_text = start_of_description_text + field_9_length_help_topic_text; >< field_16_help_topic_text = new String(data, start_of_help_topic_text + offset, >< LittleEndian.ubyteToInt(field_9_length_help_topic_text)); >< >< int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; >< field_17_status_bar_text = new String(data, start_of_status_bar_text + offset, >< LittleEndian.ubyteToInt(field_10_length_status_bar_text)); >< >--- >> >> if ( ( field_1_option_flag & (short)0x20 ) != 0 ) { >> // DEBUG >> // System.out.println( "Built-in name" ); >> >> field_11_compressed_unicode_flag = data[ 14 + offset ]; >> field_12_builtIn_name = data[ 15 + offset ]; >> >> if ( (field_12_builtIn_name & (short)0x07) != 0 ) { >> field_12_name_text = "Print_Titles"; >> >> // DEBUG >> // System.out.println( field_12_name_text ); >> >> field_13_raw_name_definition = new byte[ field_4_length_name_definition ]; >> System.arraycopy( data, 16 + offset, field_13_raw_name_definition, 0, field_13_raw_name_definition.length ); >> >> // DEBUG >> // System.out.println( HexDump.toHex( field_13_raw_name_definition ) ); >> } >> } >> else { >> >> field_11_compressed_unicode_flag= data [14 + offset]; >> field_12_name_text = new String(data, 15 + offset, >> LittleEndian.ubyteToInt(field_3_length_name_text)); >> >> int start_of_name_definition = 15 + field_3_length_name_text; >> field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition, >> offset, start_of_name_definition); >> >> int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; >> field_14_custom_menu_text = new String(data, start_of_custom_menu_text + offset, >> LittleEndian.ubyteToInt(field_7_length_custom_menu)); >> >> int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; >> field_15_description_text = new String(data, start_of_description_text + offset, >> LittleEndian.ubyteToInt(field_8_length_description_text)); >> >> int start_of_help_topic_text = start_of_description_text + field_9_length_help_topic_text; >> field_16_help_topic_text = new String(data, start_of_help_topic_text + offset, >> LittleEndian.ubyteToInt(field_9_length_help_topic_text)); >> >> int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; >> field_17_status_bar_text = new String(data, start_of_status_bar_text + offset, >> LittleEndian.ubyteToInt(field_10_length_status_bar_text)); >> } >636a675,770 >> } >> /* >> 20 00 >> 00 >> 01 >> 1A 00 // sz = 0x1A = 26 >> 00 00 >> 01 00 >> 00 >> 00 >> 00 >> 00 >> 00 // unicode flag >> 07 // name >> >> 29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26 >> 00 07 00 07 00 00 00 FF 00 10 // } >> >> >> >> 20 00 >> 00 >> 01 >> 0B 00 // sz = 0xB = 11 >> 00 00 >> 01 00 >> 00 >> 00 >> 00 >> 00 >> 00 // unicode flag >> 07 // name >> >> 3B 00 00 07 00 07 00 00 00 FF 00 // { 11 } >> */ >> /* >> 18, 00, >> 1B, 00, >> >> 20, 00, >> 00, >> 01, >> 0B, 00, >> 00, >> 00, >> 00, >> 00, >> 00, >> 07, >> 3B 00 00 07 00 07 00 00 00 FF 00 ] >> */ >> >> /** >> * @see Object#toString() >> */ >> public String toString() { >> StringBuffer buffer = new StringBuffer(); >> >> buffer.append("[NAME]\n"); >> buffer.append(" .option flags = ").append( HexDump.toHex( field_1_option_flag ) ) >> .append("\n"); >> buffer.append(" .keyboard shortcut = ").append( HexDump.toHex( field_2_keyboard_shortcut ) ) >> .append("\n"); >> buffer.append(" .length of the name = ").append( field_3_length_name_text ) >> .append("\n"); >> buffer.append(" .size of the formula data = ").append( field_4_length_name_definition ) >> .append("\n"); >> buffer.append(" .unused = ").append( field_5_index_to_sheet ) >> .append("\n"); >> buffer.append(" .( 0 = Global name, otherwise index to sheet (one-based) ) = ").append( field_6_equals_to_index_to_sheet ) >> .append("\n"); >> buffer.append(" .Length of menu text (character count) = ").append( field_7_length_custom_menu ) >> .append("\n"); >> buffer.append(" .Length of description text (character count) = ").append( field_8_length_description_text ) >> .append("\n"); >> buffer.append(" .Length of help topic text (character count) = ").append( field_9_length_help_topic_text ) >> .append("\n"); >> buffer.append(" .Length of status bar text (character count) = ").append( field_10_length_status_bar_text ) >> .append("\n"); >> buffer.append(" .Name (Unicode flag) = ").append( field_11_compressed_unicode_flag ) >> .append("\n"); >> buffer.append(" .Name (Unicode text) = ").append( field_12_name_text ) >> .append("\n"); >> buffer.append(" .Formula data (RPN token array without size field) = ").append( HexDump.toHex( field_13_raw_name_definition ) ) >> .append("\n"); >> buffer.append(" .Menu text (Unicode string without length field) = ").append( field_14_custom_menu_text ) >> .append("\n"); >> buffer.append(" .Description text (Unicode string without length field) = ").append( field_15_description_text ) >> .append("\n"); >> buffer.append(" .Help topic text (Unicode string without length field) = ").append( field_16_help_topic_text ) >> .append("\n"); >> buffer.append(" .Status bar text (Unicode string without length field) = ").append( field_17_status_bar_text ) >> .append("\n"); >> buffer.append("[/NAME]\n"); >> >> return buffer.toString(); >Index: src/java/org/apache/poi/hssf/eventmodel/HSSFEventFactory.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/eventmodel/HSSFEventFactory.java,v >retrieving revision 1.7 >diff -r1.7 HSSFEventFactory.java >187a188,205 >> >> // >> // for some reasons we have to make the workbook to be at least 4096 bytes >> // but if we have such workbook we fill the end of it with zeros (many zeros) >> // >> // it is not good: >> // if the length( all zero records ) % 4 = 1 >> // e.g.: any zero record would be readed as 4 bytes at once ( 2 - id and 2 - size ). >> // And the last 1 byte will be readed WRONG ( the id must be 2 bytes ) >> // >> // So we should better to check if the sid is zero and not to read more data >> // The zero sid shows us that rest of the stream data is a fake to make workbook >> // certain size >> // >> if ( sid == 0 ) >> break; >> >> >Index: src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v >retrieving revision 1.11 >diff -r1.11 HSSFWorkbook.java >204a205,207 >> public final static byte ENCODING_COMPRESSED_UNICODE = 0; >> public final static byte ENCODING_UTF_16 = 1; >> >212a216,220 >> workbook.setSheetName( sheet, name, ENCODING_COMPRESSED_UNICODE ); >> } >> >> public void setSheetName( int sheet, String name, short encoding ) >> { >217c225,236 >< workbook.setSheetName(sheet, name); >--- >> >> switch ( encoding ) { >> case ENCODING_COMPRESSED_UNICODE: >> case ENCODING_UTF_16: >> break; >> >> default: >> // TODO java.io.UnsupportedEncodingException >> throw new RuntimeException( "Unsupported encoding" ); >> } >> >> workbook.setSheetName( sheet, name, encoding ); >Index: src/java/org/apache/poi/util/StringUtil.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/util/StringUtil.java,v >retrieving revision 1.4 >diff -r1.4 StringUtil.java >64a65,69 >> * >> * Now it is quite confusing: the method pairs, in which >> * one of them write data and other read written data are: >> * putUncompressedUnicodeHigh and getFromUnicode >> * putUncompressedUnicode and getFromUnicodeHigh >66a72 >> *@author Sergei Kozello (sergeikozello at mail.ru) >81a88,89 >> * { 0x16, 0x00 } -> 0x16 >> * >106,112c114,118 >< byte[] bstring = new byte[len]; >< int index = offset; >< // start with high bits. >< >< for (int k = 0; k < len; k++) { >< bstring[k] = string[index]; >< index += 2; >--- >> >> char[] chars = new char[ len ]; >> for ( int i = 0; i < chars.length; i++ ) { >> chars[i] = (char)( string[ offset + ( 2*i ) ] + >> ( string[ offset + ( 2*i+1 ) ] << 8 ) ); >114c120,121 >< return new String(bstring); >--- >> >> return new String( chars ); >117a125,138 >> /** >> * given a byte array of 16-bit unicode characters, compress to 8-bit and >> * return a string >> * >> * { 0x16, 0x00 } -> 0x16 >> * >> *@param string the byte array to be converted >> *@return the converted string >> */ >> >> public static String getFromUnicodeHigh( final byte[] string ) { >> return getFromUnicodeHigh( string, 0, string.length / 2 ); >> } >> >121a143,144 >> * >> * { 0x00, 0x16 } -> 0x16 >147,153c170,175 >< byte[] bstring = new byte[len]; >< int index = offset + 1; >< // start with low bits. >< >< for (int k = 0; k < len; k++) { >< bstring[k] = string[index]; >< index += 2; >--- >> >> >> char[] chars = new char[ len ]; >> for ( int i = 0; i < chars.length; i++ ) { >> chars[i] = (char)( ( string[ offset + ( 2*i ) ] << 8 ) + >> string[ offset + ( 2*i+1 ) ] ); >155c177,178 >< return new String(bstring); >--- >> >> return new String( chars ); >161a185,186 >> * >> * { 0x00, 0x16 } -> 0x16 >Index: src/testcases/org/apache/poi/util/TestStringUtil.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/util/TestStringUtil.java,v >retrieving revision 1.4 >diff -r1.4 TestStringUtil.java >66a67 >> * @author Sergei Kozello (sergeikozello at mail.ru) >99a101,142 >> } >> >> /** >> * test simple form of getFromUnicode with symbols with code below and more 127 >> */ >> >> public void testGetFromUnicodeSymbolsWithCodesMoreThan127() >> { >> byte[] test_data = new byte[] { 0x04, 0x22, >> 0x04, 0x35, >> 0x04, 0x41, >> 0x04, 0x42, >> 0x00, 0x20, >> 0x00, 0x74, >> 0x00, 0x65, >> 0x00, 0x73, >> 0x00, 0x74, >> }; >> >> assertEquals("\u0422\u0435\u0441\u0442 test", >> StringUtil.getFromUnicode(test_data)); >> } >> >> /** >> * test getFromUnicodeHigh for symbols with code below and more 127 >> */ >> >> public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127() >> { >> byte[] test_data = new byte[] { 0x22, 0x04, >> 0x35, 0x04, >> 0x41, 0x04, >> 0x42, 0x04, >> 0x20, 0x00, >> 0x74, 0x00, >> 0x65, 0x00, >> 0x73, 0x00, >> 0x74, 0x00, >> }; >> >> assertEquals("\u0422\u0435\u0441\u0442 test", >> StringUtil.getFromUnicodeHigh( test_data ) ); > > >*****CVS exited normally with code 1***** >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 11010
:
2427
|
2490
|
2519
| 2865