lib/writeexcel/format.rb in writeexcel-0.3.5 vs lib/writeexcel/format.rb in writeexcel-0.4.0

- old
+ new

@@ -1,5 +1,6 @@ +# -*- coding: utf-8 -*- ############################################################################## # # Format - A class for defining Excel formatting. # # @@ -8,11 +9,10 @@ # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org # # original written in Perl by John McNamara # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp # -require 'nkf' # # Format - A class for defining Excel formatting. # # See CELL FORMATTING, FORMAT METHODS, COLOURS IN EXCEL in WriteExcel's rdoc. @@ -38,11 +38,10 @@ 'red' => 0x0A, 'silver' => 0x16, 'white' => 0x09, 'yellow' => 0x0D, } # :nodoc: - NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/ # :nodoc: ############################################################################### # # initialize(xf_index=0, properties = {}) # xf_index : @@ -194,11 +193,11 @@ @diag_type = other.diag_type @diag_color = other.diag_color @diag_border = other.diag_border @font_only = other.font_only -end + end ############################################################################### # # get_xf($style) # @@ -349,11 +348,11 @@ header = [record, length].pack("vv") data = [ifnt, ifmt, style, align, indent, border1, border2, border3, icv].pack("vvvvvvvVv") - return header + data + header + data end ############################################################################### # # get_font() @@ -387,27 +386,29 @@ bFamily = @font_family bCharSet = @font_charset rgch = @font encoding = @font_encoding + rgch = convert_to_ascii_if_ascii(rgch) + # Handle utf8 strings - if rgch =~ NonAscii - rgch = NKF.nkf('-w16B0 -m0 -W', rgch) + if rgch.encoding == Encoding::UTF_8 + rgch = rgch.encode('UTF-16BE') encoding = 1 end - cch = rgch.length + cch = rgch.bytesize # # Handle Unicode font names. if (encoding == 1) raise "Uneven number of bytes in Unicode font name" if cch % 2 != 0 cch /= 2 if encoding !=0 rgch = rgch.unpack('n*').pack('v*') end record = 0x31 - length = 0x10 + rgch.length + length = 0x10 + rgch.bytesize reserved = 0x00 grbit = 0x00 grbit |= 0x02 if @italic != 0 grbit |= 0x08 if @font_strikeout != 0 @@ -418,11 +419,11 @@ header = [record, length].pack("vv") data = [dyHeight, grbit, icv, bls, sss, uls, bFamily, bCharSet, reserved, cch, encoding].pack('vvvvvCCCCCC') - return header + data + rgch + header + data + rgch end ############################################################################### # # get_font_key() @@ -434,22 +435,20 @@ # generating a unique key. Elements that hold a large range of numbers # e.g. _color are placed between two binary elements such as _italic key = "#{@font}#{@size}#{@font_script}#{@underline}#{@font_strikeout}#{@bold}#{@font_outline}" key += "#{@font_family}#{@font_charset}#{@font_shadow}#{@color}#{@italic}#{@font_encoding}" - result = key.gsub(' ', '_') # Convert the key to a single word - - return result + key.gsub(' ', '_') # Convert the key to a single word end ############################################################################### # # xf_index() # # Returns the used by Worksheet->_XF() # def xf_index # :nodoc: - return @xf_index + @xf_index end def used_merge # :nodoc: @used_merge end