lib/prawn/font_metric_cache.rb in prawn-2.0.1 vs lib/prawn/font_metric_cache.rb in prawn-2.0.2

- old
+ new

@@ -6,41 +6,37 @@ # # This is free software. Please see the LICENSE and COPYING files for details. # module Prawn - # Cache used internally by Prawn::Document instances to calculate the width # of various strings for layout purposes. # # @private class FontMetricCache + CacheEntry = Struct.new(:font, :options, :string) - CacheEntry = Struct.new( :font, :options, :string ) - - def initialize( document ) + def initialize(document) @document = document @cache = {} end - def width_of( string, options ) + def width_of(string, options) f = if options[:style] # override style with :style => :bold @document.find_font(@document.font.family, :style => options[:style]) else @document.font end - key = CacheEntry.new( f, options, string ) + key = CacheEntry.new(f, options, string) unless length = @cache[ key ] length = @cache[ key ] = f.compute_width_of(string, options) end length + (@document.character_spacing * @document.font.character_count(string)) end - end - end