def prepare_drawings #:nodoc:
      chart_ref_id = 0
      image_ref_id = 0
      drawing_id   = 0
      @worksheets.each do |sheet|
        chart_count = sheet.charts.size
        image_count = sheet.images.size
        shape_count = sheet.shapes.size
        header_image_count = sheet.header_images.size
        footer_image_count = sheet.footer_images.size
        has_drawing = false

        # Check that some image or drawing needs to be processed.
        next if chart_count + image_count + shape_count + header_image_count + footer_image_count == 0

        # Don't increase the drawing_id header/footer images.
        if chart_count + image_count + shape_count > 0
          drawing_id += 1
          has_drawing = true
        end

        # Prepare the worksheet charts.
        sheet.charts.each_with_index do |chart, index|
          chart_ref_id += 1
          sheet.prepare_chart(index, chart_ref_id, drawing_id)
        end

        # Prepare the worksheet images.
        sheet.images.each_with_index do |image, index|
          type, width, height, name, x_dpi, y_dpi = get_image_properties(image[2])
          image_ref_id += 1
          sheet.prepare_image(index, image_ref_id, drawing_id, width, height, name, type, x_dpi, y_dpi)
        end

        # Prepare the worksheet shapes.
        sheet.shapes.each_with_index do |shape, index|
          sheet.prepare_shape(index, drawing_id)
        end

        # Prepare the header images.
        header_image_count.times do |index|
          filename = sheet.header_images[index][0]
          position = sheet.header_images[index][1]

          type, width, height, name, x_dpi, y_dpi =
            get_image_properties(filename)

          image_ref_id += 1

          sheet.prepare_header_image(image_ref_id, width, height,
                                     name, type, position, x_dpi, y_dpi)
        end

        # Prepare the footer images.
        footer_image_count.times do |index|
          filename = sheet.footer_images[index][0]
          position = sheet.footer_images[index][1]

          type, width, height, name, x_dpi, y_dpi =
            get_image_properties(filename)

          image_ref_id += 1

          sheet.prepare_header_image(image_ref_id, width, height,
                                     name, type, position, x_dpi, y_dpi)
        end

        if has_drawing
          drawing = sheet.drawing
          @drawings << drawing
        end
      end

      # Sort the workbook charts references into the order that the were
      # written from the worksheets above.
      @charts = @charts.select { |chart| chart.id != -1 }.
        sort_by { |chart| chart.id }

      @drawing_count = drawing_id
    end
def prepare_drawings #:nodoc:
      chart_ref_id = 0
      image_ref_id = 0
      drawing_id   = 0
      @worksheets.each do |sheet|
        chart_count = sheet.charts.size
        image_count = sheet.images.size
        shape_count = sheet.shapes.size
        header_image_count = sheet.header_images.size
        footer_image_count = sheet.footer_images.size
        has_drawing = false

        # Check that some image or drawing needs to be processed.
        next if chart_count + image_count + shape_count + header_image_count + footer_image_count == 0

        # Don't increase the drawing_id header/footer images.
        if chart_count + image_count + shape_count > 0
          drawing_id += 1
          has_drawing = true
        end

        # Prepare the worksheet charts.
        sheet.charts.each_with_index do |chart, index|
          chart_ref_id += 1
          sheet.prepare_chart(index, chart_ref_id, drawing_id)
        end

        # Prepare the worksheet images.
        sheet.images.each_with_index do |image, index|
          type, width, height, name, x_dpi, y_dpi = get_image_properties(image[2])
          image_ref_id += 1
          sheet.prepare_image(index, image_ref_id, drawing_id, width, height, name, type, x_dpi, y_dpi)
        end

        # Prepare the worksheet shapes.
        sheet.shapes.each_with_index do |shape, index|
          sheet.prepare_shape(index, drawing_id)
        end

        # Prepare the header images.
        header_image_count.times do |index|
          filename = sheet.header_images[index][0]
          position = sheet.header_images[index][1]

          type, width, height, name, x_dpi, y_dpi =
            get_image_properties(filename)

          image_ref_id += 1

          sheet.prepare_header_image(image_ref_id, width, height,
                                     name, type, position, x_dpi, y_dpi)
        end

        # Prepare the footer images.
        footer_image_count.times do |index|
          filename = sheet.footer_images[index][0]
          position = sheet.footer_images[index][1]

          type, width, height, name, x_dpi, y_dpi =
            get_image_properties(filename)

          image_ref_id += 1

          sheet.prepare_header_image(image_ref_id, width, height,
                                     name, type, position, x_dpi, y_dpi)
        end

        if has_drawing
          drawing = sheet.drawing
          @drawings << drawing
        end
      end

      # Sort the workbook charts references into the order that the were
      # written from the worksheets above.
      @charts = @charts.select { |chart| chart.id != -1 }.
        sort_by { |chart| chart.id }

      @drawing_count = drawing_id
    end
Iterate through the worksheets and set up any chart or image drawings.