Sha256: 1e58f8e8dc6580ff8f223b9f4a9ea55ea7d001a082974d83143f7c20d32693a5

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

# coding: utf-8

module PDF
  class Wrapper
    class TextImageCell

      attr_reader :text, :min_width, :natural_width, :max_width, :wrapper
      attr_accessor :width, :height
      attr_writer :options

      def initialize(str, filename, width, height)
        @text = str.to_s
        @filename = filename
        @min_width = width
        @natural_width = width
        @max_width = width
        @height = height
        @options = {}
      end

      def draw(wrapper, x, y)
        @wrapper = wrapper

        wrapper.cell(self.text, x, y, self.width, self.height, self.options)
        wrapper.image(@filename, image_options(x,y))
      end

      def calculate_width_range(wrapper)
        # nothing required, width range set in constructor
      end

      def calculate_height(wrapper)
        # nothing required, height set in constructor
      end

      def options
        @options ||= {}
      end

      private

      def image_offset
        @image_offset ||= text_height + 4
      end

      def image_options(x, y)
        {
          :left => x,
          :top  => y + image_offset,
          :width => self.width,
          :height => self.height - image_offset,
          :proportional => true,
          :position => :center
        }
      end

      def text_height
        padding = options[:padding] || 3
        wrapper.text_height(self.text, self.width - (padding * 2), text_options) + (padding * 2)
      end

      def text_options
        self.options.only(wrapper.default_text_options.keys)
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pdf-wrapper-0.4.5 lib/pdf/wrapper/text_image_cell.rb
pdf-wrapper-0.4.4 lib/pdf/wrapper/text_image_cell.rb
pdf-wrapper-0.4.1 lib/pdf/wrapper/text_image_cell.rb
pdf-wrapper-0.4.0 lib/pdf/wrapper/text_image_cell.rb