Sha256: 38241dd548254ed2504e82c3ff1dbbc6a9b70603170e373b69e57d741f218391

Contents?: true

Size: 851 Bytes

Versions: 9

Compression:

Stored size: 851 Bytes

Contents

# coding: utf-8

class PDF::Reader
  module WidthCalculator
    # Calculates the width of a glyph in a Type One or Type Three
    class TypeOneOrThree

      def initialize(font)
        @font = font

        if @font.font_descriptor
          @missing_width = @font.font_descriptor.missing_width
        else
          @missing_width = 0
        end
      end

      def glyph_width(code_point)
        return 0 if code_point.nil? || code_point < 0
        return 0 if @font.widths.nil? || @font.widths.count == 0

        # in ruby a negative index is valid, and will go from the end of the array
        # which is undesireable in this case.
        if @font.first_char <= code_point
          @font.widths.fetch(code_point - @font.first_char, @missing_width).to_f
        else
          @missing_width.to_f
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pdf-reader-2.1.0 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-2.0.0 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-2.0.0.beta1 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.4.1 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.4.0 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.3.3 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.3.2 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.3.1 lib/pdf/reader/width_calculator/type_one_or_three.rb
pdf-reader-1.3.0 lib/pdf/reader/width_calculator/type_one_or_three.rb