Sha256: 49031e0f6470478a63047281c55e45a5c20fd33278f7b14071edb4a181d599ac

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# coding: utf-8

module PDF
  class Wrapper
    class TextCell

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

      def initialize(str)
        @data = str.to_s
        @options = {}
      end

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

        wrapper.cell(self.data, x, y, self.width, self.height, self.options)
      end

      def calculate_width_range(wrapper)
        @wrapper = wrapper

        padding = options[:padding] || 3
        if options[:markup] == :pango
          str = self.data.dup.gsub(/<.+?>/,"").gsub("&amp;","&").gsub("&lt;","<").gsub("&gt;",">")
        else
          str = self.data.dup
        end
        @min_width  = wrapper.text_width(str.gsub(/\b|\B/,"\n"), text_options) + (padding * 4)
        @natural_width = wrapper.text_width(str, text_options) + (padding * 4)
      end

      def calculate_height(wrapper)
        raise "Cannot calculate height until cell width is set" if self.width.nil?

        @wrapper = wrapper

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

      def options
        @options ||= {}
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pdf-wrapper-0.3.0 lib/pdf/wrapper/text_cell.rb