writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ##############################################################################
2
3
  #
3
4
  # Format - A class for defining Excel formatting.
@@ -10,7 +11,6 @@
10
11
  # original written in Perl by John McNamara
11
12
  # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
13
  #
13
- require 'nkf'
14
14
 
15
15
  #
16
16
  # Format - A class for defining Excel formatting.
@@ -40,7 +40,6 @@ class Format
40
40
  'white' => 0x09,
41
41
  'yellow' => 0x0D,
42
42
  } # :nodoc:
43
- NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/ # :nodoc:
44
43
 
45
44
  ###############################################################################
46
45
  #
@@ -196,7 +195,7 @@ def copy(other)
196
195
  @diag_border = other.diag_border
197
196
 
198
197
  @font_only = other.font_only
199
- end
198
+ end
200
199
 
201
200
  ###############################################################################
202
201
  #
@@ -351,7 +350,7 @@ def get_xf # :nodoc:
351
350
  data = [ifnt, ifmt, style, align, indent,
352
351
  border1, border2, border3, icv].pack("vvvvvvvVv")
353
352
 
354
- return header + data
353
+ header + data
355
354
  end
356
355
 
357
356
  ###############################################################################
@@ -389,13 +388,15 @@ def get_font # :nodoc:
389
388
  rgch = @font
390
389
  encoding = @font_encoding
391
390
 
391
+ rgch = convert_to_ascii_if_ascii(rgch)
392
+
392
393
  # Handle utf8 strings
393
- if rgch =~ NonAscii
394
- rgch = NKF.nkf('-w16B0 -m0 -W', rgch)
394
+ if rgch.encoding == Encoding::UTF_8
395
+ rgch = rgch.encode('UTF-16BE')
395
396
  encoding = 1
396
397
  end
397
398
 
398
- cch = rgch.length
399
+ cch = rgch.bytesize
399
400
  #
400
401
  # Handle Unicode font names.
401
402
  if (encoding == 1)
@@ -405,7 +406,7 @@ def get_font # :nodoc:
405
406
  end
406
407
 
407
408
  record = 0x31
408
- length = 0x10 + rgch.length
409
+ length = 0x10 + rgch.bytesize
409
410
  reserved = 0x00
410
411
 
411
412
  grbit = 0x00
@@ -420,7 +421,7 @@ def get_font # :nodoc:
420
421
  sss, uls, bFamily,
421
422
  bCharSet, reserved, cch, encoding].pack('vvvvvCCCCCC')
422
423
 
423
- return header + data + rgch
424
+ header + data + rgch
424
425
  end
425
426
 
426
427
  ###############################################################################
@@ -436,9 +437,7 @@ def get_font_key # :nodoc:
436
437
 
437
438
  key = "#{@font}#{@size}#{@font_script}#{@underline}#{@font_strikeout}#{@bold}#{@font_outline}"
438
439
  key += "#{@font_family}#{@font_charset}#{@font_shadow}#{@color}#{@italic}#{@font_encoding}"
439
- result = key.gsub(' ', '_') # Convert the key to a single word
440
-
441
- return result
440
+ key.gsub(' ', '_') # Convert the key to a single word
442
441
  end
443
442
 
444
443
  ###############################################################################
@@ -448,7 +447,7 @@ def get_font_key # :nodoc:
448
447
  # Returns the used by Worksheet->_XF()
449
448
  #
450
449
  def xf_index # :nodoc:
451
- return @xf_index
450
+ @xf_index
452
451
  end
453
452
 
454
453
  def used_merge # :nodoc:
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # Formula - A class for generating Excel formulas.
@@ -10,13 +11,12 @@
10
11
  # original written in Perl by John McNamara
11
12
  # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
13
  #
13
- require 'nkf'
14
14
  require 'strscan'
15
15
  require 'writeexcel/excelformulaparser'
16
16
 
17
17
  class Formula < ExcelFormulaParser #:nodoc:
18
-
19
- NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/
18
+ require 'writeexcel/helper'
19
+ private :convert_to_ascii_if_ascii
20
20
 
21
21
  attr_accessor :byte_order, :workbook, :ext_sheets, :ext_refs, :ext_ref_count
22
22
 
@@ -151,7 +151,7 @@ def parse_tokens(tokens)
151
151
  end
152
152
  end
153
153
 
154
- return parse_str
154
+ parse_str
155
155
  end
156
156
 
157
157
  def scan(formula)
@@ -239,7 +239,7 @@ def reverse(expression)
239
239
  def check_volatile(tokens)
240
240
  volatile = 0
241
241
 
242
- (0..tokens.size-1).each do |i|
242
+ (0..tokens.size - 1).each do |i|
243
243
  # If the next token is a function check if it is volatile.
244
244
  if tokens[i] == '_func' and @functions[tokens[i+1]][3] != 0
245
245
  volatile = 1
@@ -247,7 +247,7 @@ def check_volatile(tokens)
247
247
  end
248
248
  end
249
249
 
250
- return volatile
250
+ volatile
251
251
  end
252
252
 
253
253
  ###############################################################################
@@ -269,7 +269,7 @@ def convert_volatile
269
269
  # Convert a boolean token to ptgBool
270
270
  #
271
271
  def convert_bool(bool)
272
- return [@ptg['ptgBool'], bool.to_i].pack("CC")
272
+ [@ptg['ptgBool'], bool.to_i].pack("CC")
273
273
  end
274
274
 
275
275
 
@@ -297,23 +297,25 @@ def convert_number(num)
297
297
  # Convert a string to a ptg Str.
298
298
  #
299
299
  def convert_string(str)
300
+ str = convert_to_ascii_if_ascii(str)
301
+
300
302
  encoding = 0
301
303
 
302
304
  str.sub!(/^"/,'') # Remove leading "
303
305
  str.sub!(/"$/,'') # Remove trailing "
304
306
  str.gsub!(/""/,'"') # Substitute Excel's escaped double quote "" for "
305
307
 
306
- length = str.length
308
+ length = str.bytesize
307
309
 
308
310
  # Handle utf8 strings
309
- if str =~ NonAscii
310
- str = NKF.nkf('-w16L0 -m0 -W', str)
311
+ if str.encoding == Encoding::UTF_8
312
+ str = str.encode('UTF-16LE')
311
313
  encoding = 1
312
314
  end
313
315
 
314
316
  exit "String in formula has more than 255 chars\n" if length > 255
315
317
 
316
- return [@ptg['ptgStr'], length, encoding].pack("CCC") + str
318
+ [@ptg['ptgStr'], length, encoding].pack("CCC") + str.encode('BINARY')
317
319
  end
318
320
 
319
321
  ###############################################################################
@@ -337,7 +339,7 @@ def convert_ref2d(cell, _class)
337
339
  exit "Unknown function class in formula\n"
338
340
  end
339
341
 
340
- return ptgref + row + col
342
+ ptgref + row + col
341
343
  end
342
344
 
343
345
  ###############################################################################
@@ -368,7 +370,7 @@ def convert_ref3d(token, _class)
368
370
  exit "Unknown function class in formula\n"
369
371
  end
370
372
 
371
- return ptgref + ext_ref + row + col
373
+ ptgref + ext_ref + row + col
372
374
  end
373
375
 
374
376
  ###############################################################################
@@ -382,8 +384,8 @@ def convert_range2d(range, _class)
382
384
  cell1, cell2 = range.split(':')
383
385
 
384
386
  # A range such as A:D is equivalent to A1:D65536, so add rows as required
385
- cell1 = cell1 + '1' unless cell1 =~ /\d/
386
- cell2 = cell2 + '65536' unless cell2 =~ /\d/
387
+ cell1 += '1' unless cell1 =~ /\d/
388
+ cell2 += '65536' unless cell2 =~ /\d/
387
389
 
388
390
  # Convert the cell references
389
391
  row1, col1 = cell_to_packed_rowcol(cell1)
@@ -400,7 +402,7 @@ def convert_range2d(range, _class)
400
402
  exit "Unknown function class in formula\n"
401
403
  end
402
404
 
403
- return ptgarea + row1 + row2 + col1 + col2
405
+ ptgarea + row1 + row2 + col1 + col2
404
406
  end
405
407
 
406
408
  ###############################################################################
@@ -421,8 +423,8 @@ def convert_range3d(token, _class)
421
423
  cell1, cell2 = range.split(':')
422
424
 
423
425
  # A range such as A:D is equivalent to A1:D65536, so add rows as required
424
- cell1 = cell1 + '1' unless cell1 =~ /\d/
425
- cell2 = cell2 + '65536' unless cell2 =~ /\d/
426
+ cell1 += '1' unless cell1 =~ /\d/
427
+ cell2 += '65536' unless cell2 =~ /\d/
426
428
 
427
429
  # Convert the cell references
428
430
  row1, col1 = cell_to_packed_rowcol(cell1)
@@ -439,7 +441,7 @@ def convert_range3d(token, _class)
439
441
  exit "Unknown function class in formula\n"
440
442
  end
441
443
 
442
- return ptgarea + ext_ref + row1 + row2 + col1+ col2
444
+ ptgarea + ext_ref + row1 + row2 + col1+ col2
443
445
  end
444
446
 
445
447
  ###############################################################################
@@ -482,7 +484,7 @@ def pack_ext_ref(ext_ref)
482
484
  index = @ext_refs[key]
483
485
  end
484
486
 
485
- return [index].pack("v")
487
+ [index].pack("v")
486
488
  end
487
489
 
488
490
  ###############################################################################
@@ -493,9 +495,11 @@ def pack_ext_ref(ext_ref)
493
495
  # sheet names is updated by the add_worksheet() method of the Workbook class.
494
496
  #
495
497
  def get_sheet_index(sheet_name)
498
+ sheet_name = convert_to_ascii_if_ascii(sheet_name)
499
+
496
500
  # Handle utf8 sheetnames
497
- if sheet_name =~ NonAscii
498
- sheet_name = NKF.nkf('-w16B0 -m0 -W', sheet_name)
501
+ if sheet_name.encoding == Encoding::UTF_8
502
+ sheet_name = sheet_name.encode('UTF-16BE')
499
503
  end
500
504
 
501
505
  if @ext_sheets[sheet_name].nil?
@@ -540,7 +544,7 @@ def get_ext_sheets
540
544
  # updated by the add_worksheet() method of the Workbook class.
541
545
  #
542
546
  def get_ext_ref_count
543
- return @ext_ref_count
547
+ @ext_ref_count
544
548
  end
545
549
 
546
550
  ###############################################################################
@@ -645,14 +649,14 @@ def cell_to_rowcol(cell)
645
649
 
646
650
  while (!chars.empty?)
647
651
  char = chars.pop # LS char first
648
- col = col + (char[0] - "A"[0] + 1) * (26**expn)
652
+ col += (char.ord - "A".ord + 1) * (26 ** expn)
649
653
  expn += 1
650
654
  end
651
655
  # Convert 1-index to zero-index
652
656
  row -= 1
653
657
  col -= 1
654
658
 
655
- return [row, col, row_rel, col_rel]
659
+ [row, col, row_rel, col_rel]
656
660
  end
657
661
 
658
662
  ###############################################################################
@@ -674,7 +678,7 @@ def cell_to_packed_rowcol(cell)
674
678
  row = [row].pack('v')
675
679
  col = [col].pack('v')
676
680
 
677
- return [row, col]
681
+ [row, col]
678
682
  end
679
683
 
680
684
  ###############################################################################
@@ -1025,8 +1029,6 @@ def initialize_hashes
1025
1029
  }
1026
1030
 
1027
1031
  end
1028
-
1029
-
1030
1032
  end
1031
1033
 
1032
1034
  if $0 ==__FILE__
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # helper.rb
4
+ #
5
+ # Convert to US_ASCII encoding if ascii characters only.
6
+ def convert_to_ascii_if_ascii(str)
7
+ return nil if str.nil?
8
+ ruby_18 do
9
+ enc = str.encoding
10
+ begin
11
+ str = str.encode('ASCII')
12
+ rescue
13
+ str.force_encoding(enc)
14
+ end
15
+ end ||
16
+ ruby_19 do
17
+ if !str.nil? && str.ascii_only?
18
+ str = [str].pack('a*')
19
+ end
20
+ end
21
+ str
22
+ end
23
+ private :convert_to_ascii_if_ascii
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # BIFFwriter - An abstract base class for Excel workbooks and worksheets.
@@ -31,7 +32,7 @@ def initialize(arg)
31
32
  else
32
33
  @io = arg
33
34
  end
34
- @io.binmode
35
+ @io.binmode if @io.respond_to?(:binmode)
35
36
 
36
37
  @filehandle = ""
37
38
  @fileclosed = false
@@ -92,13 +93,8 @@ def self.open(arg)
92
93
  # Write BIFF data to OLE file.
93
94
  #
94
95
  def write(data)
95
- #print "ole write\n"
96
- #print data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ') + "\n\n"
97
96
  @io.write(data)
98
97
  end
99
- # def print(data)
100
- # @io.print(data)
101
- # end
102
98
 
103
99
  ###############################################################################
104
100
  #
@@ -148,11 +144,8 @@ def calculate_sizes
148
144
  #
149
145
  def close
150
146
  if @size_allowed == true
151
- #print "write_padding"
152
147
  write_padding if @biff_only == 0
153
- #print "write_property_storage"
154
148
  write_property_storage if @biff_only == 0
155
- #print "write_big_block_depot"
156
149
  write_big_block_depot if @biff_only == 0
157
150
  end
158
151
  @io.close
@@ -262,7 +255,7 @@ def write_pps(name, type, dir, start, size)
262
255
  unless name.empty?
263
256
  name = name + "\0"
264
257
  ord_name = name.unpack("c*")
265
- length = name.length * 2
258
+ length = name.bytesize * 2
266
259
  end
267
260
 
268
261
  rawname = ord_name.pack("v*")
@@ -284,17 +277,13 @@ def write_pps(name, type, dir, start, size)
284
277
  pps_size = [size].pack("V") #0x78
285
278
 
286
279
  write(rawname)
287
- for n in 1..64-length
288
- write(zero)
289
- end
280
+ write(zero * (64 - length)) if 64 - length >= 1
290
281
  write(pps_sizeofname)
291
282
  write(pps_type)
292
283
  write(pps_prev)
293
284
  write(pps_next)
294
285
  write(pps_dir)
295
- for n in 1..5
296
- write(unknown)
297
- end
286
+ write(unknown * 5)
298
287
  write(pps_ts1s)
299
288
  write(pps_ts1d)
300
289
  write(pps_ts2s)
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # Properties - A module for creating Excel property sets.
@@ -36,25 +37,25 @@ def create_summary_property_set(properties) #:nodoc:
36
37
  property_data, offsets = pack_property_data(properties)
37
38
 
38
39
  # Create the property type and offsets based on the previous calculation.
39
- 0.upto(properties.size-1) do |i|
40
- property_offsets = property_offsets + [properties[i][0], offsets[i]].pack('VV')
40
+ 0.upto(properties.size - 1) do |i|
41
+ property_offsets += [properties[i][0], offsets[i]].pack('VV')
41
42
  end
42
43
 
43
44
  # Size of size (4 bytes) + num_property (4 bytes) + the data structures.
44
- size = 8 + (property_offsets).length + property_data.length
45
+ size = 8 + (property_offsets).bytesize + property_data.bytesize
45
46
  size = [size].pack('V')
46
47
 
47
- return byte_order +
48
- version +
49
- system_id +
50
- class_id +
51
- num_property_sets +
52
- format_id +
53
- offset +
54
- size +
55
- num_property +
56
- property_offsets +
57
- property_data
48
+ byte_order +
49
+ version +
50
+ system_id +
51
+ class_id +
52
+ num_property_sets +
53
+ format_id +
54
+ offset +
55
+ size +
56
+ num_property +
57
+ property_offsets +
58
+ property_data
58
59
  end
59
60
 
60
61
 
@@ -84,11 +85,11 @@ def create_doc_summary_property_set(properties) #:nodoc:
84
85
 
85
86
  # Create the property type and offsets based on the previous calculation.
86
87
  0.upto(properties.size-1) do |i|
87
- property_offsets_0 = property_offsets_0 + [properties[i][0], offsets[i]].pack('VV')
88
+ property_offsets_0 += [properties[i][0], offsets[i]].pack('VV')
88
89
  end
89
90
 
90
91
  # Size of size (4 bytes) + num_property (4 bytes) + the data structures.
91
- data_len = 8 + (property_offsets_0).length + property_data_0.length
92
+ data_len = 8 + (property_offsets_0).bytesize + property_data_0.bytesize
92
93
  size_0 = [data_len].pack('V')
93
94
 
94
95
  # The second property set offset is at the end of the first property set.
@@ -108,22 +109,20 @@ def create_doc_summary_property_set(properties) #:nodoc:
108
109
  7D 00 00 00 00 00 00 00 2D 00 39 00 30 00 33 00
109
110
  ).join('')].pack('H*')
110
111
 
111
- return byte_order +
112
- version +
113
- system_id +
114
- class_id +
115
- num_property_sets +
116
- format_id_0 +
117
- offset_0 +
118
- format_id_1 +
119
- offset_1 +
120
-
121
- size_0 +
122
- num_property_0 +
123
- property_offsets_0 +
124
- property_data_0 +
125
-
126
- property_data_1
112
+ byte_order +
113
+ version +
114
+ system_id +
115
+ class_id +
116
+ num_property_sets +
117
+ format_id_0 +
118
+ offset_0 +
119
+ format_id_1 +
120
+ offset_1 +
121
+ size_0 +
122
+ num_property_0 +
123
+ property_offsets_0 +
124
+ property_data_0 +
125
+ property_data_1
127
126
  end
128
127
 
129
128
 
@@ -164,11 +163,11 @@ def pack_property_data(properties, offset = 0) #:nodoc:
164
163
  raise "Unknown property type: '#{property_type}'\n"
165
164
  end
166
165
 
167
- offset += packed_property.length
168
- data = data + packed_property
166
+ offset += packed_property.bytesize
167
+ data += packed_property
169
168
  end
170
169
 
171
- return [data, offsets]
170
+ [data, offsets]
172
171
  end
173
172
 
174
173
  ###############################################################################
@@ -191,37 +190,27 @@ def pack_VT_I2(value) #:nodoc:
191
190
  #
192
191
  def pack_VT_LPSTR(str, codepage) #:nodoc:
193
192
  type = 0x001E
194
- string = str + "\0"
193
+ string = str.force_encoding('BINARY') + "\0".encode('BINARY')
195
194
 
196
195
  if codepage == 0x04E4
197
196
  # Latin1
198
- byte_string = string
199
- length = byte_string.length
197
+ length = string.bytesize
200
198
  elsif codepage == 0xFDE9
201
- # UTF-8
202
- nonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/
203
- if string =~ nonAscii
204
- # $KCODE = 'u'
205
- require 'jcode'
206
- byte_string = string
207
- length = byte_string.jlength
208
- else
209
- byte_string = string
210
- length = byte_string.length
211
- end
199
+ # utf8
200
+ length = string.bytesize
212
201
  else
213
- raise "Unknown codepage: codepage\n"
202
+ raise "Unknown codepage: #{codepage}\n"
214
203
  end
215
204
 
216
205
  # Pack the data.
217
- data = [type, length].pack('VV')
218
- data = data + byte_string
206
+ data = [type, length].pack('VV')
207
+ data += string
219
208
 
220
209
  # The packed data has to null padded to a 4 byte boundary.
221
210
  if (extra = length % 4) != 0
222
- data = data + "\0" * (4 - extra)
211
+ data += "\0" * (4 - extra)
223
212
  end
224
- return data
213
+ data
225
214
  end
226
215
 
227
216
  ###############################################################################