Sha256: fc5fbc53a5be7c688df1e1da97d7e90cffb88a8753e1160dc9fa3f33c9cb649a

Contents?: true

Size: 814 Bytes

Versions: 5

Compression:

Stored size: 814 Bytes

Contents

# frozen_string_literal: true

module Thinreports
  module BasicReport
    module Generator
      module PrawnExt
        module WidthOf
          # This patch fixes the character_spacing effect on text width calculation.
          #
          # The original #width_of:
          #
          #   width_of('abcd') #=> 4 + 4 = 8
          #
          # The #width_of in this patch:
          #
          #   width_of('abcd') #=> 4 + 3 = 7
          #
          def width_of(*)
            width = super - character_spacing
            width > 0 ? width : 0
          end
        end
      end
    end
  end
end

# Prawn v2.3 and later includes this patch by https://github.com/prawnpdf/prawn/pull/1117.
if Prawn::VERSION < '2.3.0'
  Prawn::Document.prepend Thinreports::BasicReport::Generator::PrawnExt::WidthOf
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thinreports-0.14.2 lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb
thinreports-0.14.1 lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb
thinreports-0.14.0 lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb
thinreports-0.13.1 lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb
thinreports-0.13.0 lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb