def register_font_from_pdf_object(font_name, font_object)
      # FIXME:
      # - add stream deflation for the CMap file.
      # - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
      # - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.

      # first, create cmap, as it will be used to correctly create the widths directory.

      # find the CMap from one of the two systems (TrueType vs. Type0 fonts)
      # at the moment doen't suppot :Encoding cmaps...
      cmap = {}
      if font_object[:ToUnicode]
        to_unicode = font_object[:ToUnicode]
        to_unicode = to_unicode[:referenced_object] if to_unicode[:is_reference_only]
        # deflate the cmap file stream before parsing
        to_unicode = create_deep_copy to_unicode
        CombinePDF::PDFFilter.inflate_object to_unicode
        # parse the deflated stream
        cmap = parse_cmap to_unicode[:raw_stream_content]
      else
        warn "didn't find ToUnicode object for #{font_object}"
        return false
      end

      # second, create the metrics directory.
      metrics = {}
      old_widths = font_object
      if font_object[:DescendantFonts]
        old_widths = font_object[:DescendantFonts]
        old_widths = old_widths[:referenced_object][:indirect_without_dictionary] if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
        old_widths = old_widths[0][:referenced_object]
        avrg_height = 360
        avrg_height = old_widths[:XHeight] if old_widths[:XHeight]
        avrg_height = (avrg_height + old_widths[:CapHeight]) / 2 if old_widths[:CapHeight]
        avrg_width = old_widths[:AvgWidth] || 0
        avarage_bbox = [0, 0, avrg_width, avrg_height] # data is missing for full box metrics, just ignore
      end

      # compute the metrics values using the appropiate system (TrueType vs. Type0 fonts)
      cmap_inverted = {}
      cmap.each { |k, v| cmap_inverted[v.hex] = k }
      if old_widths[:W]
        old_widths = old_widths[:W]
        if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
          old_widths = old_widths[:referenced_object][:indirect_without_dictionary]
        end
        old_widths = create_deep_copy old_widths
        while old_widths[0]
          a = old_widths.shift
          b = old_widths.shift
          if b.is_a?(Array)
            b.each_index { |i| metrics[cmap_inverted[(a + i)] || (a + i)] = { wx: b[i], boundingbox: avarage_bbox } }
          else
            c = old_widths.shift
            (b - a).times { |i| metrics[cmap_inverted[(a + i)] || (a + i)] = { wx: c[0], boundingbox: avarage_bbox } }
          end

        end
      elsif old_widths[:Widths]
        first_char = old_widths[:FirstChar]
        old_widths = old_widths[:Widths]
        if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
          old_widths = old_widths[:referenced_object][:indirect_without_dictionary]
        end
        old_widths.each_index { |i| metrics[cmap_inverted[(i + first_char)] || (i + first_char)] = { wx: old_widths[i], boundingbox: avarage_bbox } }
      else
        warn "didn't find widths object for #{old_widths}"
        return false
      end
      # register the font and return the font object
      cmap = nil if cmap.empty?
      CombinePDF::Fonts.register_font font_name, metrics, font_object, cmap
    end
def register_font_from_pdf_object(font_name, font_object)
      # FIXME:
      # - add stream deflation for the CMap file.
      # - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
      # - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.

      # first, create cmap, as it will be used to correctly create the widths directory.

      # find the CMap from one of the two systems (TrueType vs. Type0 fonts)
      # at the moment doen't suppot :Encoding cmaps...
      cmap = {}
      if font_object[:ToUnicode]
        to_unicode = font_object[:ToUnicode]
        to_unicode = to_unicode[:referenced_object] if to_unicode[:is_reference_only]
        # deflate the cmap file stream before parsing
        to_unicode = create_deep_copy to_unicode
        CombinePDF::PDFFilter.inflate_object to_unicode
        # parse the deflated stream
        cmap = parse_cmap to_unicode[:raw_stream_content]
      else
        warn "didn't find ToUnicode object for #{font_object}"
        return false
      end

      # second, create the metrics directory.
      metrics = {}
      old_widths = font_object
      if font_object[:DescendantFonts]
        old_widths = font_object[:DescendantFonts]
        old_widths = old_widths[:referenced_object][:indirect_without_dictionary] if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
        old_widths = old_widths[0][:referenced_object]
        avrg_height = 360
        avrg_height = old_widths[:XHeight] if old_widths[:XHeight]
        avrg_height = (avrg_height + old_widths[:CapHeight]) / 2 if old_widths[:CapHeight]
        avrg_width = old_widths[:AvgWidth] || 0
        avarage_bbox = [0, 0, avrg_width, avrg_height] # data is missing for full box metrics, just ignore
      end

      # compute the metrics values using the appropiate system (TrueType vs. Type0 fonts)
      cmap_inverted = {}
      cmap.each { |k, v| cmap_inverted[v.hex] = k }
      if old_widths[:W]
        old_widths = old_widths[:W]
        if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
          old_widths = old_widths[:referenced_object][:indirect_without_dictionary]
        end
        old_widths = create_deep_copy old_widths
        while old_widths[0]
          a = old_widths.shift
          b = old_widths.shift
          if b.is_a?(Array)
            b.each_index { |i| metrics[cmap_inverted[(a + i)] || (a + i)] = { wx: b[i], boundingbox: avarage_bbox } }
          else
            c = old_widths.shift
            (b - a).times { |i| metrics[cmap_inverted[(a + i)] || (a + i)] = { wx: c[0], boundingbox: avarage_bbox } }
          end

        end
      elsif old_widths[:Widths]
        first_char = old_widths[:FirstChar]
        old_widths = old_widths[:Widths]
        if old_widths.is_a?(Hash) && old_widths[:is_reference_only]
          old_widths = old_widths[:referenced_object][:indirect_without_dictionary]
        end
        old_widths.each_index { |i| metrics[cmap_inverted[(i + first_char)] || (i + first_char)] = { wx: old_widths[i], boundingbox: avarage_bbox } }
      else
        warn "didn't find widths object for #{old_widths}"
        return false
      end
      # register the font and return the font object
      cmap = nil if cmap.empty?
      CombinePDF::Fonts.register_font font_name, metrics, font_object, cmap
    end
Register a font that already exists in a pdf object into the font library.

 The implementation is experimental, but this function attempts to deconstruct a font object in order to
 extract it's cmap and metric data, allowing it's use in the CombinePDF library.