diff options
| author | Randy Morgan <[email protected]> | 2012-04-16 13:19:50 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-16 13:19:50 +0900 |
| commit | 0f1cd35054ca9f914638dbfe5eb3594b71a2c0e6 (patch) | |
| tree | 4b708fab2a129dff36c7bd57851b3346901ad16f /lib | |
| parent | e03b79e8f83f943f7caa01dd15fa6c5c87bcc4a2 (diff) | |
| download | caxlsx-0f1cd35054ca9f914638dbfe5eb3594b71a2c0e6.tar.gz caxlsx-0f1cd35054ca9f914638dbfe5eb3594b71a2c0e6.zip | |
use class variable for counting string
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index f185c9e7..8bb430a2 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -81,6 +81,10 @@ module Axlsx end + def self.thin_chars + @thin_chars ||= "^.acefijklrstxyzFIJL()-" + end + # Creates a new worksheet. # @note the recommended way to manage worksheets is Workbook#add_worksheet # @see Workbook#add_worksheet @@ -88,7 +92,6 @@ module Axlsx # @option options [Hash] page_margins A hash containing page margins for this worksheet. @see PageMargins # @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet. def initialize(wb, options={}) - @thin_chars = ".acefijklrstxyzFIJL()-" self.workbook = wb @workbook.worksheets << self @@ -447,7 +450,6 @@ module Axlsx # assigns the owner workbook for this worksheet def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end - def update_column_info(cells, widths=[], style=[]) styles = self.workbook.styles cellXfs, fonts = styles.cellXfs, styles.fonts @@ -469,17 +471,11 @@ module Axlsx end end - def calculate_width(text, sz) mdw_count = 0 mdw = 1.78 font_scale = sz/10.0 - text.scan(/./mu).each do |char| - #TODO generate < mdw lists for other fonts and calculate widths based on the font in use. - # this is all arial for now. I need to workout the width of all characters in 10px font and remove any characters that are equal to or greater than the largest of 0 thru 9 - mdw_count +=1 unless @thin_chars.include?(char) - end - ((mdw_count * mdw + 5) / mdw * 256) / 256.0 * font_scale + ((text.count(Worksheet.thin_chars) * mdw + 5) / mdw * 256) / 256.0 * font_scale end end end |
