class PDF::Reader::Content

def walk_resources(resources)

###############################################################################
def walk_resources(resources)
  resources = resolve_references(resources)
  
  # extract any procset information
  if resources['ProcSet']
    callback(:resource_procset, resources['ProcSet'])
  end
  # extract any xobject information
  if resources['XObject']
    @xref.object(resources['XObject']).each do |name, val|
      obj, stream = @xref.object(val)
      callback(:resource_xobject, [name, obj, stream])
    end
  end
  # extract any extgstate information
  if resources['ExtGState']
    @xref.object(resources['ExtGState']).each do |name, val|
      callback(:resource_extgstate, [name, @xref.object(val)])
    end
  end
  # extract any colorspace information
  if resources['ColorSpace']
    @xref.object(resources['ColorSpace']).each do |name, val|
      callback(:resource_colorspace, [name, @xref.object(val)])
    end
  end
  # extract any pattern information
  if resources['Pattern']
    @xref.object(resources['Pattern']).each do |name, val|
      callback(:resource_pattern, [name, @xref.object(val)])
    end
  end
  # extract any font information
  if resources['Font']
    @xref.object(resources['Font']).each do |label, desc|
      desc = @xref.object(desc)
      @fonts[label] = PDF::Reader::Font.new
      @fonts[label].label = label
      @fonts[label].subtype = desc['Subtype'] if desc['Subtype']
      @fonts[label].basefont = desc['BaseFont'] if desc['BaseFont']
      @fonts[label].encoding = PDF::Reader::Encoding.factory(@xref.object(desc['Encoding']))
      @fonts[label].descendantfonts = desc['DescendantFonts'] if desc['DescendantFonts']
      if desc['ToUnicode']
        obj, cmap = @xref.object(desc['ToUnicode'])
        
        # this stream is a cmap
        begin
          @fonts[label].tounicode = PDF::Reader::CMap.new(cmap)
        rescue
          # if the CMap fails to parse, don't worry too much. Means we can't translate the text properly
        end
      end
      callback(:resource_font, [label, @fonts[label]])
    end
  end
end