<commit_before># Taken from pdfminer, in turn extracted from AFM files at:
#
#   http://www.ctan.org/tex-archive/fonts/adobe/afm/
#

###  BEGIN Verbatim copy of the license part

#
# Adobe Core 35 AFM Files with 229 Glyph Entries - ReadMe
#
# This file and the 35 PostScript(R) AFM files it accompanies may be
# used, copied, and distributed for any purpose and without charge,
# with or without modification, provided that all copyright notices
# are retained; that the AFM files are not distributed without this
# file; that all modifications to this file or any of the AFM files
# are prominently noted in the modified file(s); and that this
# paragraph is not modified. Adobe Systems has no responsibility or
# obligation to support the use of the AFM files.
#

###  END Verbatim copy of the license part

module PdfExtract
  class FontMetrics

    attr_accessor :ascent, :descent, :bbox

    def initialize font
      @ascent = 0
      @descent = 0
      @bbox = [0, 0, 0, 0]

      base_font = font.basefont.to_s
      if @@base_fonts.key? base_font
        @ascent = @@base_fonts[base_font][:Ascent]
        @descent = @@base_fonts[base_font][:Descent]
        @bbox = @@base_fonts[base_font][:FontBBox]
        @glyph_width_lookup = proc { |c|
          @@base_fonts[base_font][:Widths].fetch(c.codepoints.first, 0)
        }
      else
        font_descriptor = font.font_descriptor
        @ascent = font_descriptor.ascent
        @descent = font_descriptor.descent
        @bbox = font_descriptor.font_bounding_box
        @glyph_width_lookup = proc do |c|
          begin
            font.glyph_width(c.codepoints.first) || 0
          rescue TypeError => e
            # It seems some fonts don't have a first char attribute in their
            # descriptor and this causes problems for pdf-reader.
            0
          end
        end
      end

      if not @bbox.nil?
        @ascent = @bbox[3] if @ascent.nil? || @ascent.zero?
        @descent = @bbox[1] if @descent.nil? || @descent.zero?
      end
    end

    def glyph_width c
      @glyph_width_lookup.call c
    end

    @@base_fonts = {
      'Courier-Oblique' => {
        :FontName => 'Courier-Oblique',
        :Descent => -194.0,<commit_msg>fix error handling for nil font_descriptor, which is assigned by pdf-reader for CID fonts<commit_after># Taken from pdfminer, in turn extracted from AFM files at:
#
#   http://www.ctan.org/tex-archive/fonts/adobe/afm/
#

###  BEGIN Verbatim copy of the license part

#
# Adobe Core 35 AFM Files with 229 Glyph Entries - ReadMe
#
# This file and the 35 PostScript(R) AFM files it accompanies may be
# used, copied, and distributed for any purpose and without charge,
# with or without modification, provided that all copyright notices
# are retained; that the AFM files are not distributed without this
# file; that all modifications to this file or any of the AFM files
# are prominently noted in the modified file(s); and that this
# paragraph is not modified. Adobe Systems has no responsibility or
# obligation to support the use of the AFM files.
#

###  END Verbatim copy of the license part

module PdfExtract
  class FontMetrics

    attr_accessor :ascent, :descent, :bbox

    def initialize font
      @ascent = 0
      @descent = 0
      @bbox = [0, 0, 0, 0]

      base_font = font.basefont.to_s
      if @@base_fonts.key? base_font
        @ascent = @@base_fonts[base_font][:Ascent]
        @descent = @@base_fonts[base_font][:Descent]
        @bbox = @@base_fonts[base_font][:FontBBox]
        @glyph_width_lookup = proc { |c|
          @@base_fonts[base_font][:Widths].fetch(c.codepoints.first, 0)
        }
      else
        font_descriptor = font.font_descriptor
        unless font_descriptor.nil?
          @ascent = font_descriptor.ascent
          @descent = font_descriptor.descent
          @bbox = font_descriptor.font_bounding_box
        else
          # pdf-reader will initialize new Font objects with font_descriptor = nil
          # if the font is a CID font. So "ascent", etc. throws a NoMethodError.
          0
        end
        @glyph_width_lookup = proc do |c|
          begin
            font.glyph_width(c.codepoints.first) || 0
          rescue TypeError => e
            # It seems some fonts don't have a first char attribute in their
            # descriptor and this causes problems for pdf-reader.
            0
          end
        end
      end

      if not @bbox.nil?
        @ascent = @bbox[3] if @ascent.nil? || @ascent.zero?
        @descent = @bbox[1] if @descent.nil? || @descent.zero?
      end
    end

    def glyph_width c
      @glyph_width_lookup.call c
    end

    @@base_fonts = {
      'Courier-Oblique' => {
        :FontName => 'Courier-Oblique',
        :Descent => -194.0,
{'fraction_non_alphanumeric': 0.08856243441762854, 'fraction_numerical': 0.00944386149003148, 'mean_word_length': 2.5147492625368733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6622748', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1433, 'n_words': 489}