lib/prawn/font_metric_cache.rb in prawn-2.2.2 vs lib/prawn/font_metric_cache.rb in prawn-2.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # font_metric_cache.rb : The Prawn font class # # Copyright Dec 2012, Kenneth Kalmer. All Rights Reserved. # # This is free software. Please see the LICENSE and COPYING files for details. @@ -33,11 +35,14 @@ @cache[key] ||= f.compute_width_of(encoded_string, options) length = @cache[key] - length + - (@document.character_spacing * - @document.font.character_count(encoded_string)) + character_count = @document.font.character_count(encoded_string) + if character_count.positive? + length += @document.character_spacing * (character_count - 1) + end + + length end end end